Spaces:
Sleeping
Sleeping
Download apps/api/dist/integrations/integrations.router.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 19 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/integrations/integrations.router.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/integrations/integrations.router.js
-
curl -L -o integrations.router.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/integrations/integrations.router.js
19 kB
| ; | |
| 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); | |
| }; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.IntegrationsRouter = void 0; | |
| const common_1 = require("@nestjs/common"); | |
| const zod_1 = require("zod"); | |
| const trpc_init_1 = require("../trpc/trpc.init"); | |
| const subscription_features_1 = require("../billing/subscription-features"); | |
| const integrations_service_1 = require("./integrations.service"); | |
| const integration_health_service_1 = require("./integration-health.service"); | |
| const shared_types_1 = require("@micprotocol/shared-types"); | |
| const ALL_PROVIDERS = [ | |
| "google_calendar", | |
| "google_mail", | |
| "outlook", | |
| "riverside", | |
| "zoom", | |
| "cloudflare_r2", | |
| "calcom", | |
| "chatwoot", | |
| "documenso", | |
| "formbricks", | |
| "listmonk", | |
| "pretix", | |
| ]; | |
| const SELF_HOSTED_PROVIDERS = [ | |
| "calcom", | |
| "chatwoot", | |
| "documenso", | |
| "formbricks", | |
| "listmonk", | |
| "pretix", | |
| ]; | |
| const workspaceIdInput = zod_1.z.object({ workspaceId: zod_1.z.string().uuid() }); | |
| const providerInput = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(ALL_PROVIDERS), | |
| }); | |
| const selfHostedCredentialsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(["calcom", "chatwoot", "documenso", "formbricks", "listmonk", "pretix"]), | |
| apiKey: zod_1.z.string().min(1, "API key is required"), | |
| baseUrl: zod_1.z.string().url().optional(), | |
| webhookSecret: zod_1.z.string().optional(), | |
| }); | |
| const r2CredentialsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| accessKeyId: zod_1.z.string().min(1, "Access Key ID is required"), | |
| secretAccessKey: zod_1.z.string().min(1, "Secret Access Key is required"), | |
| accountId: zod_1.z.string().optional(), | |
| }); | |
| const syncCalendarSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(["google_calendar", "outlook"]), | |
| }); | |
| const calendarEventSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(["google_calendar", "outlook"]), | |
| eventData: zod_1.z.object({ | |
| title: zod_1.z.string().min(1).max(500), | |
| description: zod_1.z.string().max(5000).optional(), | |
| startTime: zod_1.z.string().datetime(), | |
| endTime: zod_1.z.string().datetime(), | |
| timezone: zod_1.z.string().optional(), | |
| location: zod_1.z.string().max(500).optional(), | |
| meetLink: zod_1.z.string().url().optional(), | |
| attendees: zod_1.z | |
| .array(zod_1.z.object({ | |
| email: zod_1.z.string().email(), | |
| name: zod_1.z.string().optional(), | |
| })) | |
| .optional(), | |
| }), | |
| }); | |
| const getEventsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(["google_calendar", "outlook"]), | |
| timeMin: zod_1.z.string().datetime().optional(), | |
| timeMax: zod_1.z.string().datetime().optional(), | |
| }); | |
| const chatwootConversationSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| conversationId: zod_1.z.number(), | |
| }); | |
| const chatwootMessageSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| conversationId: zod_1.z.number(), | |
| content: zod_1.z.string().min(1).max(5000), | |
| }); | |
| const chatwootCreateConversationSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| inboxId: zod_1.z.number(), | |
| contactName: zod_1.z.string().min(1), | |
| contactEmail: zod_1.z.string().email(), | |
| contactPhone: zod_1.z.string().optional(), | |
| message: zod_1.z.string().min(1).max(5000), | |
| customAttributes: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(), | |
| }); | |
| const webhookSecretSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| provider: zod_1.z.enum(["calcom", "chatwoot", "documenso", "formbricks", "listmonk", "pretix"]), | |
| secret: zod_1.z.string().min(1, "Webhook secret is required"), | |
| }); | |
| const pretixEventsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| organizer: zod_1.z.string().min(1, "Organizer slug is required"), | |
| }); | |
| const pretixItemsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| organizer: zod_1.z.string().min(1, "Organizer slug is required"), | |
| event: zod_1.z.string().min(1, "Event slug is required"), | |
| }); | |
| const pretixOrdersSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| organizer: zod_1.z.string().min(1, "Organizer slug is required"), | |
| event: zod_1.z.string().min(1, "Event slug is required"), | |
| }); | |
| const pretixOrderPositionsSchema = zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| organizer: zod_1.z.string().min(1, "Organizer slug is required"), | |
| event: zod_1.z.string().min(1, "Event slug is required"), | |
| order: zod_1.z.string().min(1, "Order code is required"), | |
| }); | |
| let IntegrationsRouter = class IntegrationsRouter { | |
| integrationsService; | |
| healthService; | |
| constructor(integrationsService, healthService) { | |
| this.integrationsService = integrationsService; | |
| this.healthService = healthService; | |
| } | |
| get router() { | |
| return (0, trpc_init_1.router)({ | |
| getAllProviders: trpc_init_1.protectedProcedure.query(async () => { | |
| return this.integrationsService.getAllProviders(); | |
| }), | |
| list: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listIntegrations(input.workspaceId, ctx.userId); | |
| }), | |
| get: trpc_init_1.workspaceProcedure | |
| .input(providerInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getIntegration(input.workspaceId, input.provider, ctx.userId); | |
| }), | |
| disconnect: trpc_init_1.workspaceProcedure | |
| .input(providerInput) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.disconnectIntegration(input.workspaceId, input.provider, ctx.userId); | |
| }), | |
| getAuthUrl: trpc_init_1.workspaceProcedure | |
| .input(providerInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getAuthUrl(input.workspaceId, input.provider, ctx.userId); | |
| }), | |
| handleCallback: trpc_init_1.protectedProcedure | |
| .input(zod_1.z.object({ | |
| code: zod_1.z.string(), | |
| state: zod_1.z.string(), | |
| })) | |
| .mutation(async ({ input }) => { | |
| return this.integrationsService.handleOAuthCallback(input.code, input.state); | |
| }), | |
| updateR2Integration: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.API_WEBHOOKS) | |
| .input(r2CredentialsSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.updateApiKeyIntegration(input.workspaceId, "cloudflare_r2", ctx.userId, { | |
| accessKeyId: input.accessKeyId, | |
| secretAccessKey: input.secretAccessKey, | |
| accountId: input.accountId, | |
| }); | |
| }), | |
| updateSelfHostedIntegration: (0, trpc_init_1.requireFeature)(subscription_features_1.SubscriptionFeature.SELF_HOSTED_INTEGRATIONS) | |
| .input(selfHostedCredentialsSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.updateApiKeyIntegration(input.workspaceId, input.provider, ctx.userId, { | |
| apiKey: input.apiKey, | |
| baseUrl: input.baseUrl, | |
| webhookSecret: input.webhookSecret, | |
| }); | |
| }), | |
| checkHealth: trpc_init_1.workspaceProcedure | |
| .input(providerInput) | |
| .query(async ({ ctx, input }) => { | |
| const integration = await this.integrationsService.getIntegration(input.workspaceId, input.provider, ctx.userId); | |
| if (!integration) { | |
| return { alive: false, error: "Not connected" }; | |
| } | |
| const selfHosted = integration.metadata?.baseUrl; | |
| if (!selfHosted) { | |
| return { alive: false, error: "No endpoint configured" }; | |
| } | |
| try { | |
| const res = await fetch(`${selfHosted}/health`, { | |
| signal: AbortSignal.timeout(5000), | |
| }); | |
| return { alive: res.ok, status: res.status }; | |
| } | |
| catch (e) { | |
| return { alive: false, error: e.message }; | |
| } | |
| }), | |
| syncCalendar: trpc_init_1.workspaceProcedure | |
| .input(syncCalendarSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.syncCalendarEvents(input.workspaceId, ctx.userId, input.provider); | |
| }), | |
| getSyncedEvents: trpc_init_1.workspaceProcedure | |
| .input(getEventsSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getSyncedEvents(input.workspaceId, input.provider, ctx.userId, input.timeMin, input.timeMax); | |
| }), | |
| createCalendarEvent: trpc_init_1.workspaceProcedure | |
| .input(calendarEventSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.createCalendarEvent(input.workspaceId, ctx.userId, input.provider, input.eventData); | |
| }), | |
| listCalComEventTypes: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listCalComEventTypes(input.workspaceId, ctx.userId); | |
| }), | |
| createCalComBooking: trpc_init_1.workspaceProcedure | |
| .input(shared_types_1.calComBookingSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.createCalComBooking(input.workspaceId, ctx.userId, { | |
| eventTypeId: input.eventTypeId, | |
| start: input.start, | |
| attendee: input.attendee, | |
| meetingUrl: input.meetingUrl, | |
| }); | |
| }), | |
| sendDocumensoDocument: trpc_init_1.workspaceProcedure | |
| .input(shared_types_1.documensoSendDocumentSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.sendDocument(input.workspaceId, { | |
| title: input.document.title, | |
| recipients: (input.document.recipients ?? []).map((r) => ({ | |
| email: r.email, | |
| name: r.name ?? "", | |
| })), | |
| }); | |
| }), | |
| getDocumensoDocumentStatus: trpc_init_1.workspaceProcedure | |
| .input(shared_types_1.documensoDocumentStatusSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getDocumensoDocumentStatus(input.workspaceId, Number(input.documentId)); | |
| }), | |
| listListmonkLists: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listListmonkLists(input.workspaceId); | |
| }), | |
| createListmonkList: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| name: zod_1.z.string().min(1), | |
| type: zod_1.z.enum(["public", "private", "optin"]).optional(), | |
| })) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.createListmonkList(input.workspaceId, { | |
| name: input.name, | |
| type: input.type ?? "public", | |
| }); | |
| }), | |
| subscribeListmonkSubscriber: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| listId: zod_1.z.number(), | |
| email: zod_1.z.string().email(), | |
| name: zod_1.z.string().optional(), | |
| attrs: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(), | |
| })) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.subscribeListmonkSubscriber(input.workspaceId, { | |
| listId: input.listId, | |
| email: input.email, | |
| name: input.name, | |
| attrs: input.attrs, | |
| }); | |
| }), | |
| sendListmonkTransactional: trpc_init_1.workspaceProcedure | |
| .input(zod_1.z.object({ | |
| workspaceId: zod_1.z.string().uuid(), | |
| to: zod_1.z.string().email(), | |
| subject: zod_1.z.string().min(1), | |
| body: zod_1.z.string().min(1), | |
| type: zod_1.z.enum(["html", "plain"]).optional(), | |
| })) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.sendListmonkEmail(input.workspaceId, { | |
| to: input.to, | |
| subject: input.subject, | |
| body: input.body, | |
| type: input.type, | |
| }); | |
| }), | |
| getChatwootConversations: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getChatwootConversations(input.workspaceId, ctx.userId); | |
| }), | |
| getChatwootMessages: trpc_init_1.workspaceProcedure | |
| .input(chatwootConversationSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getChatwootMessages(input.workspaceId, ctx.userId, input.conversationId); | |
| }), | |
| sendChatwootMessage: trpc_init_1.workspaceProcedure | |
| .input(chatwootMessageSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.sendChatwootMessage(input.workspaceId, ctx.userId, { | |
| conversationId: input.conversationId, | |
| content: input.content, | |
| }); | |
| }), | |
| createChatwootConversation: trpc_init_1.workspaceProcedure | |
| .input(chatwootCreateConversationSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.createChatwootConversation(input.workspaceId, ctx.userId, { | |
| inboxId: input.inboxId, | |
| contactName: input.contactName, | |
| contactEmail: input.contactEmail, | |
| contactPhone: input.contactPhone, | |
| message: input.message, | |
| customAttributes: input.customAttributes, | |
| }); | |
| }), | |
| listPretixEvents: trpc_init_1.workspaceProcedure | |
| .input(pretixEventsSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listPretixEvents(input.workspaceId, ctx.userId, input.organizer); | |
| }), | |
| listPretixItems: trpc_init_1.workspaceProcedure | |
| .input(pretixItemsSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listPretixItems(input.workspaceId, ctx.userId, input.organizer, input.event); | |
| }), | |
| listPretixOrders: trpc_init_1.workspaceProcedure | |
| .input(pretixOrdersSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listPretixOrders(input.workspaceId, ctx.userId, input.organizer, input.event); | |
| }), | |
| listPretixOrderPositions: trpc_init_1.workspaceProcedure | |
| .input(pretixOrderPositionsSchema) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listPretixOrderPositions(input.workspaceId, ctx.userId, input.organizer, input.event, input.order); | |
| }), | |
| getHealth: trpc_init_1.protectedProcedure.query(async () => { | |
| return this.healthService.getHealthResults(); | |
| }), | |
| getWebhookDeliveries: trpc_init_1.protectedProcedure | |
| .input(zod_1.z.object({ limit: zod_1.z.number().int().min(1).max(500).optional() })) | |
| .query(async ({ input }) => { | |
| return this.healthService.getWebhookDeliveries(input.limit ?? 50); | |
| }), | |
| listSelfHosted: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.listSelfHostedIntegrations(input.workspaceId, ctx.userId); | |
| }), | |
| updateWebhookSecret: trpc_init_1.workspaceProcedure | |
| .input(webhookSecretSchema) | |
| .mutation(async ({ ctx, input }) => { | |
| return this.integrationsService.updateWebhookSecret(input.workspaceId, input.provider, input.secret, ctx.userId); | |
| }), | |
| getMetrics: trpc_init_1.protectedProcedure.query(async () => { | |
| return this.integrationsService.getProviderMetrics(); | |
| }), | |
| getStats: trpc_init_1.workspaceProcedure | |
| .input(workspaceIdInput) | |
| .query(async ({ ctx, input }) => { | |
| return this.integrationsService.getIntegrationStats(input.workspaceId, ctx.userId); | |
| }), | |
| }); | |
| } | |
| }; | |
| exports.IntegrationsRouter = IntegrationsRouter; | |
| exports.IntegrationsRouter = IntegrationsRouter = __decorate([ | |
| (0, common_1.Injectable)(), | |
| __metadata("design:paramtypes", [integrations_service_1.IntegrationsService, | |
| integration_health_service_1.IntegrationHealthService]) | |
| ], IntegrationsRouter); | |
| //# sourceMappingURL=integrations.router.js.map |