"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var OutboundWebhookController_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.OutboundWebhookController = void 0; const common_1 = require("@nestjs/common"); const better_auth_identity_service_1 = require("../auth/better-auth-identity.service"); const outbound_webhook_service_1 = require("./outbound-webhook.service"); let OutboundWebhookController = OutboundWebhookController_1 = class OutboundWebhookController { service; betterAuthService; logger = new common_1.Logger(OutboundWebhookController_1.name); constructor(service, betterAuthService) { this.service = service; this.betterAuthService = betterAuthService; } async registerEndpoint(req, body) { const userId = await this.getUserId(req); if (!userId) { throw new common_1.UnauthorizedException("Authentication required"); } const endpoint = await this.service.registerEndpoint(body.workspaceId, body.url, body.events || []); const { secret, ...safeEndpoint } = endpoint; return { ...safeEndpoint, secret }; } async listEndpoints(req, workspaceId) { const userId = await this.getUserId(req); if (!userId) { throw new common_1.UnauthorizedException("Authentication required"); } if (!workspaceId) { throw new common_1.UnauthorizedException("workspaceId is required"); } return this.service.listEndpoints(workspaceId); } async deleteEndpoint(req, endpointId) { const userId = await this.getUserId(req); if (!userId) { throw new common_1.UnauthorizedException("Authentication required"); } await this.service.deleteEndpoint(endpointId); return { success: true }; } async getUserId(req) { const auth = req.headers.authorization; if (!auth?.startsWith("Bearer ")) return null; const identity = await this.betterAuthService.getSessionFromBearer(auth); return identity?.userId ?? null; } }; exports.OutboundWebhookController = OutboundWebhookController; __decorate([ (0, common_1.Post)("endpoints"), __param(0, (0, common_1.Req)()), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], OutboundWebhookController.prototype, "registerEndpoint", null); __decorate([ (0, common_1.Get)("endpoints"), __param(0, (0, common_1.Req)()), __param(1, (0, common_1.Query)("workspaceId")), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String]), __metadata("design:returntype", Promise) ], OutboundWebhookController.prototype, "listEndpoints", null); __decorate([ (0, common_1.Delete)("endpoints/:id"), __param(0, (0, common_1.Req)()), __param(1, (0, common_1.Param)("id")), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, String]), __metadata("design:returntype", Promise) ], OutboundWebhookController.prototype, "deleteEndpoint", null); exports.OutboundWebhookController = OutboundWebhookController = OutboundWebhookController_1 = __decorate([ (0, common_1.Controller)("webhooks"), __metadata("design:paramtypes", [outbound_webhook_service_1.OutboundWebhookService, better_auth_identity_service_1.BetterAuthService]) ], OutboundWebhookController); //# sourceMappingURL=outbound-webhook.controller.js.map