import type { IntegrationAccountRequirement, TriggerDefinition } from "../types" export interface ConvexEventEndpointOptions { appOrigin: string automationId: string hookSlot: number scopePath?: readonly number[] } /** * Returns the public endpoint for one signed Convex semantic-event trigger. * * @param options - Public origin and trigger identity. */ export function getConvexEventEndpoint(options: ConvexEventEndpointOptions) { return new URL( `/api/v1/events/convex/${encodeURIComponent(getConvexEventEndpointKey(options))}`, options.appOrigin, ).toString() } /** * Returns the stable source key for one Convex semantic-event trigger. * * @param options - Trigger identity without the public origin. */ export function getConvexEventEndpointKey( options: Omit, ) { return `${options.automationId}:${[ ...(options.scopePath ?? []), options.hookSlot, ].join(".")}` } const CONVEX_ACCOUNT = { connectionOptions: [ { connectionMethodId: "oauth", requiredScopes: [] }, { connectionMethodId: "deployment-key", requiredScopes: [] }, ], serviceId: "convex", } as const satisfies IntegrationAccountRequirement const CONVEX_DEPLOYMENT_KEY_ACCOUNT = { connectionOptions: [ { connectionMethodId: "deployment-key", requiredScopes: [] }, ], serviceId: "convex", } as const satisfies IntegrationAccountRequirement export const convexTriggerDefinitions = { convexDocumentCreated: { account: CONVEX_ACCOUNT, type: "convex.document.created", }, convexDocumentDeleted: { account: CONVEX_ACCOUNT, type: "convex.document.deleted", }, convexDocumentEvent: { account: CONVEX_ACCOUNT, type: "convex.document.event", }, convexDocumentUpdated: { account: CONVEX_ACCOUNT, type: "convex.document.updated", }, convexEvent: { account: CONVEX_DEPLOYMENT_KEY_ACCOUNT, getPrimary: ({ appOrigin, automationId, hookSlot, scopePath }) => ({ copyable: true, value: getConvexEventEndpoint({ appOrigin, automationId, hookSlot, scopePath, }), }), name: "Convex event", type: "convex.event.received", }, } as const satisfies Record