@open-mercato/webhooks 0.6.7-develop.6726.1.983ae8a07e → 0.6.7-develop.6749.1.6b54c56dfe

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/modules/webhooks/api/inbound/[endpointId]/route.js +113 -4
  3. package/dist/modules/webhooks/api/inbound/[endpointId]/route.js.map +3 -3
  4. package/dist/modules/webhooks/data/entities.js +101 -1
  5. package/dist/modules/webhooks/data/entities.js.map +2 -2
  6. package/dist/modules/webhooks/encryption.js +7 -0
  7. package/dist/modules/webhooks/encryption.js.map +2 -2
  8. package/dist/modules/webhooks/events.js +2 -0
  9. package/dist/modules/webhooks/events.js.map +2 -2
  10. package/dist/modules/webhooks/generators.js +57 -0
  11. package/dist/modules/webhooks/generators.js.map +7 -0
  12. package/dist/modules/webhooks/lib/inbound-dispatch.js +105 -0
  13. package/dist/modules/webhooks/lib/inbound-dispatch.js.map +7 -0
  14. package/dist/modules/webhooks/lib/inbound-registry.js +76 -0
  15. package/dist/modules/webhooks/lib/inbound-registry.js.map +7 -0
  16. package/dist/modules/webhooks/lib/module-webhook-registry.js +12 -0
  17. package/dist/modules/webhooks/lib/module-webhook-registry.js.map +7 -0
  18. package/dist/modules/webhooks/lib/queue.js +47 -0
  19. package/dist/modules/webhooks/lib/queue.js.map +2 -2
  20. package/dist/modules/webhooks/migrations/Migration20260617141327_webhooks.js +16 -0
  21. package/dist/modules/webhooks/migrations/Migration20260617141327_webhooks.js.map +7 -0
  22. package/dist/modules/webhooks/workers/inbound-dispatch.js +29 -0
  23. package/dist/modules/webhooks/workers/inbound-dispatch.js.map +7 -0
  24. package/generated/entities/inbound_endpoint_config_entity/index.ts +8 -0
  25. package/generated/entities/webhook_ingestion_entity/index.ts +16 -0
  26. package/generated/entities.ids.generated.ts +3 -1
  27. package/generated/entity-fields-registry.ts +28 -0
  28. package/package.json +6 -6
  29. package/src/modules/webhooks/api/inbound/[endpointId]/__tests__/route.unify.test.ts +108 -0
  30. package/src/modules/webhooks/api/inbound/[endpointId]/route.ts +136 -4
  31. package/src/modules/webhooks/data/entities.ts +84 -0
  32. package/src/modules/webhooks/encryption.ts +7 -0
  33. package/src/modules/webhooks/events.ts +2 -0
  34. package/src/modules/webhooks/generators.ts +57 -0
  35. package/src/modules/webhooks/lib/__tests__/inbound-dispatch.test.ts +186 -0
  36. package/src/modules/webhooks/lib/__tests__/inbound-registry.test.ts +102 -0
  37. package/src/modules/webhooks/lib/__tests__/module-webhook-registry.test.ts +53 -0
  38. package/src/modules/webhooks/lib/inbound-dispatch.ts +147 -0
  39. package/src/modules/webhooks/lib/inbound-registry.ts +92 -0
  40. package/src/modules/webhooks/lib/module-webhook-registry.ts +33 -0
  41. package/src/modules/webhooks/lib/queue.ts +60 -0
  42. package/src/modules/webhooks/migrations/.snapshot-open-mercato.json +907 -338
  43. package/src/modules/webhooks/migrations/Migration20260617141327_webhooks.ts +16 -0
  44. package/src/modules/webhooks/workers/inbound-dispatch.ts +31 -0
@@ -1,2 +1,2 @@
1
- [build:webhooks] found 68 entry points
1
+ [build:webhooks] found 74 entry points
2
2
  [build:webhooks] built successfully
@@ -3,11 +3,22 @@ import { createHash } from "node:crypto";
3
3
  import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
4
4
  import { resolveTranslations } from "@open-mercato/shared/lib/i18n/server";
5
5
  import { checkRateLimit, getClientIp, RATE_LIMIT_ERROR_FALLBACK, RATE_LIMIT_ERROR_KEY } from "@open-mercato/shared/lib/ratelimit/helpers";
6
+ import { findWithDecryption } from "@open-mercato/shared/lib/encryption/find";
6
7
  import { emitWebhooksEvent } from "../../../events.js";
7
8
  import { getWebhookEndpointAdapter } from "../../../lib/adapter-registry.js";
9
+ import { getWebhookSource } from "../../../lib/inbound-registry.js";
10
+ import { enqueueInboundDispatch } from "../../../lib/queue.js";
8
11
  import { isWebhookIntegrationEnabled, WEBHOOK_INTEGRATION_DISABLED_MESSAGE } from "../../../lib/integration-state.js";
9
12
  import { json } from "../../helpers.js";
10
- import { WebhookInboundReceiptEntity } from "../../../data/entities.js";
13
+ import { InboundEndpointConfigEntity, WebhookIngestionEntity, WebhookInboundReceiptEntity } from "../../../data/entities.js";
14
+ function toStringCredentials(credentials) {
15
+ const result = {};
16
+ if (!credentials) return result;
17
+ for (const [key, value] of Object.entries(credentials)) {
18
+ if (typeof value === "string") result[key] = value;
19
+ }
20
+ return result;
21
+ }
11
22
  const metadata = {
12
23
  POST: { requireAuth: false }
13
24
  };
@@ -18,9 +29,10 @@ const inboundResponseSchema = z.object({
18
29
  const errorSchema = z.object({ error: z.string() });
19
30
  async function POST(request, context) {
20
31
  const params = await context.params;
21
- const adapter = getWebhookEndpointAdapter(params.endpointId);
32
+ const source = getWebhookSource(params.endpointId);
33
+ const adapter = source ? void 0 : getWebhookEndpointAdapter(params.endpointId);
22
34
  const { translate } = await resolveTranslations();
23
- if (!adapter) {
35
+ if (!source && !adapter) {
24
36
  return json({ error: "Webhook endpoint not found" }, { status: 404 });
25
37
  }
26
38
  const container = await createRequestContainer();
@@ -35,6 +47,102 @@ async function POST(request, context) {
35
47
  );
36
48
  if (rateLimitResponse) return rateLimitResponse;
37
49
  }
50
+ if (source) {
51
+ const rawBody = await request.text();
52
+ const sourceHeaders = Object.fromEntries(request.headers.entries());
53
+ let parsedBody = {};
54
+ try {
55
+ const parsed = JSON.parse(rawBody);
56
+ if (parsed && typeof parsed === "object") parsedBody = parsed;
57
+ } catch {
58
+ parsedBody = {};
59
+ }
60
+ const inboundRequest = { body: rawBody, headers: sourceHeaders, parsedBody };
61
+ const credentialsService = tryResolve(container, "integrationCredentialsService");
62
+ const configs = await findWithDecryption(
63
+ em,
64
+ InboundEndpointConfigEntity,
65
+ { sourceKey: params.endpointId, isActive: true },
66
+ {}
67
+ );
68
+ let verifiedScope = null;
69
+ for (const config of configs) {
70
+ const scope = { organizationId: config.organizationId, tenantId: config.tenantId };
71
+ const credentials = credentialsService ? await credentialsService.resolve(`webhook_source_${params.endpointId}`, scope) : null;
72
+ let valid = false;
73
+ try {
74
+ valid = await source.verifier(inboundRequest, toStringCredentials(credentials));
75
+ } catch {
76
+ valid = false;
77
+ }
78
+ if (valid) {
79
+ verifiedScope = scope;
80
+ break;
81
+ }
82
+ }
83
+ if (!verifiedScope) {
84
+ return json({ error: "Signature verification failed" }, { status: 401 });
85
+ }
86
+ const eventType = source.eventTypeExtractor(parsedBody, sourceHeaders);
87
+ const messageId2 = source.messageIdExtractor?.(parsedBody, sourceHeaders) ?? resolveInboundReceiptMessageId({
88
+ endpointId: params.endpointId,
89
+ providerKey: params.endpointId,
90
+ headers: sourceHeaders,
91
+ body: rawBody
92
+ });
93
+ try {
94
+ em.persist(em.create(WebhookInboundReceiptEntity, {
95
+ endpointId: params.endpointId,
96
+ messageId: messageId2,
97
+ providerKey: params.endpointId,
98
+ eventType,
99
+ tenantId: verifiedScope.tenantId,
100
+ organizationId: verifiedScope.organizationId,
101
+ createdAt: /* @__PURE__ */ new Date()
102
+ }));
103
+ await em.flush();
104
+ } catch (error) {
105
+ if (isUniqueViolation(error)) {
106
+ return json({ ok: true, duplicate: true });
107
+ }
108
+ throw error;
109
+ }
110
+ const ingestion = em.create(WebhookIngestionEntity, {
111
+ sourceKey: params.endpointId,
112
+ eventType,
113
+ externalMessageId: messageId2,
114
+ payload: parsedBody,
115
+ headers: sourceHeaders,
116
+ status: "received",
117
+ handlerCount: 0,
118
+ organizationId: verifiedScope.organizationId,
119
+ tenantId: verifiedScope.tenantId,
120
+ createdAt: /* @__PURE__ */ new Date(),
121
+ updatedAt: /* @__PURE__ */ new Date()
122
+ });
123
+ em.persist(ingestion);
124
+ await em.flush();
125
+ await enqueueInboundDispatch({
126
+ ingestionId: ingestion.id,
127
+ sourceKey: params.endpointId,
128
+ eventType,
129
+ tenantId: verifiedScope.tenantId,
130
+ organizationId: verifiedScope.organizationId
131
+ });
132
+ await emitWebhooksEvent("webhooks.inbound.received", {
133
+ providerKey: params.endpointId,
134
+ endpointId: params.endpointId,
135
+ messageId: messageId2,
136
+ eventType,
137
+ payload: parsedBody,
138
+ tenantId: verifiedScope.tenantId,
139
+ organizationId: verifiedScope.organizationId
140
+ }, { persistent: true });
141
+ return json({ ok: true });
142
+ }
143
+ if (!adapter) {
144
+ return json({ error: "Webhook endpoint not found" }, { status: 404 });
145
+ }
38
146
  const body = await request.text();
39
147
  const headers = Object.fromEntries(request.headers.entries());
40
148
  let verified;
@@ -101,11 +209,12 @@ const openApi = {
101
209
  methods: {
102
210
  POST: {
103
211
  summary: "Receive inbound webhook",
104
- description: "Endpoint ids currently resolve to registered adapter provider keys.",
212
+ description: "The endpoint id resolves to a registered webhook source first (module-level handler dispatch), otherwise to a legacy adapter provider key.",
105
213
  pathParams: z.object({ endpointId: z.string().min(1) }),
106
214
  responses: [{ status: 200, description: "Inbound webhook accepted", schema: inboundResponseSchema }],
107
215
  errors: [
108
216
  { status: 400, description: "Verification failed", schema: errorSchema },
217
+ { status: 401, description: "Signature verification failed (source flow)", schema: errorSchema },
109
218
  { status: 404, description: "Endpoint not found", schema: errorSchema },
110
219
  { status: 429, description: "Rate limit exceeded", schema: errorSchema },
111
220
  { status: 503, description: "Webhook integration disabled", schema: errorSchema }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/webhooks/api/inbound/%5BendpointId%5D/route.ts"],
4
- "sourcesContent": ["import { z } from 'zod'\nimport { createHash } from 'node:crypto'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { checkRateLimit, getClientIp, RATE_LIMIT_ERROR_FALLBACK, RATE_LIMIT_ERROR_KEY } from '@open-mercato/shared/lib/ratelimit/helpers'\nimport type { RateLimiterService } from '@open-mercato/shared/lib/ratelimit/service'\nimport { emitWebhooksEvent } from '../../../events'\nimport { getWebhookEndpointAdapter } from '../../../lib/adapter-registry'\nimport { isWebhookIntegrationEnabled, WEBHOOK_INTEGRATION_DISABLED_MESSAGE } from '../../../lib/integration-state'\nimport { json } from '../../helpers'\nimport { WebhookInboundReceiptEntity } from '../../../data/entities'\n\nexport const metadata = {\n POST: { requireAuth: false },\n}\n\ninterface RouteContext {\n params: Promise<{ endpointId: string }>\n}\n\nconst inboundResponseSchema = z.object({\n ok: z.boolean(),\n duplicate: z.boolean().optional(),\n})\n\nconst errorSchema = z.object({ error: z.string() })\n\nexport async function POST(request: Request, context: RouteContext): Promise<Response> {\n const params = await context.params\n const adapter = getWebhookEndpointAdapter(params.endpointId)\n const { translate } = await resolveTranslations()\n\n if (!adapter) {\n return json({ error: 'Webhook endpoint not found' }, { status: 404 })\n }\n\n const container = await createRequestContainer()\n const em = (container.resolve('em') as EntityManager).fork()\n const rateLimiterService = tryResolve<RateLimiterService>(container, 'rateLimiterService')\n\n if (rateLimiterService) {\n const rateLimitResponse = await checkRateLimit(\n rateLimiterService,\n { points: 60, duration: 60, keyPrefix: `webhooks:inbound:${params.endpointId}` },\n buildInboundRateLimitKey(params.endpointId, request, rateLimiterService.trustProxyDepth),\n translate(RATE_LIMIT_ERROR_KEY, RATE_LIMIT_ERROR_FALLBACK),\n )\n\n if (rateLimitResponse) return rateLimitResponse\n }\n\n const body = await request.text()\n const headers = Object.fromEntries(request.headers.entries())\n let verified: Awaited<ReturnType<typeof adapter.verifyWebhook>>\n try {\n verified = await adapter.verifyWebhook({\n headers,\n body,\n method: request.method,\n })\n } catch {\n return json({ error: 'Verification failed' }, { status: 400 })\n }\n\n const hasTenantId = Boolean(verified.tenantId)\n const hasOrganizationId = Boolean(verified.organizationId)\n if (hasTenantId !== hasOrganizationId) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n\n const integrationScope = hasTenantId && hasOrganizationId\n ? { tenantId: verified.tenantId as string, organizationId: verified.organizationId as string }\n : null\n\n if (integrationScope) {\n const integrationEnabled = await isWebhookIntegrationEnabled(em, integrationScope)\n if (!integrationEnabled) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n } else if (!adapter.allowUnscopedInbound) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n\n const messageId = resolveInboundReceiptMessageId({\n endpointId: params.endpointId,\n providerKey: adapter.providerKey,\n headers,\n body,\n })\n try {\n em.persist(em.create(WebhookInboundReceiptEntity, {\n endpointId: params.endpointId,\n messageId,\n providerKey: adapter.providerKey,\n eventType: verified.eventType,\n tenantId: verified.tenantId ?? null,\n organizationId: verified.organizationId ?? null,\n createdAt: new Date(),\n }))\n await em.flush()\n } catch (error) {\n if (isUniqueViolation(error)) {\n return json({ ok: true, duplicate: true })\n }\n throw error\n }\n\n await emitWebhooksEvent('webhooks.inbound.received', {\n providerKey: adapter.providerKey,\n endpointId: params.endpointId,\n messageId,\n eventType: verified.eventType,\n payload: verified.payload,\n tenantId: verified.tenantId ?? null,\n organizationId: verified.organizationId ?? null,\n }, { persistent: true })\n\n return json({ ok: true })\n}\n\nexport const openApi: OpenApiRouteDoc = {\n summary: 'Receive inbound webhook',\n description: 'Verifies, rate limits, deduplicates, and processes an inbound webhook using the registered endpoint adapter.',\n methods: {\n POST: {\n summary: 'Receive inbound webhook',\n description: 'Endpoint ids currently resolve to registered adapter provider keys.',\n pathParams: z.object({ endpointId: z.string().min(1) }),\n responses: [{ status: 200, description: 'Inbound webhook accepted', schema: inboundResponseSchema }],\n errors: [\n { status: 400, description: 'Verification failed', schema: errorSchema },\n { status: 404, description: 'Endpoint not found', schema: errorSchema },\n { status: 429, description: 'Rate limit exceeded', schema: errorSchema },\n { status: 503, description: 'Webhook integration disabled', schema: errorSchema },\n ],\n },\n },\n}\n\nfunction tryResolve<T>(container: { resolve: (name: string) => unknown }, name: string): T | null {\n try {\n return container.resolve(name) as T\n } catch {\n return null\n }\n}\n\nfunction isUniqueViolation(error: unknown): boolean {\n if (!error || typeof error !== 'object') return false\n const maybeError = error as { code?: string; cause?: unknown }\n if (maybeError.code === '23505') return true\n if (!maybeError.cause || typeof maybeError.cause !== 'object') return false\n return (maybeError.cause as { code?: string }).code === '23505'\n}\n\ntype ResolveInboundReceiptMessageIdInput = {\n endpointId: string\n providerKey: string\n headers: Record<string, string>\n body: string\n}\n\nexport function buildInboundRateLimitKey(endpointId: string, request: Request, trustProxyDepth: number): string {\n const clientIp = getClientIp(request, trustProxyDepth)\n return clientIp ? `${endpointId}:ip:${clientIp}` : `${endpointId}:global`\n}\n\nexport function resolveInboundReceiptMessageId(\n input: ResolveInboundReceiptMessageIdInput\n): string {\n const explicitMessageId = input.headers['webhook-id'] ?? input.headers['svix-id'] ?? null\n if (typeof explicitMessageId === 'string' && explicitMessageId.trim().length > 0) {\n return explicitMessageId.trim()\n }\n\n const timestamp =\n input.headers['webhook-timestamp'] ??\n input.headers['svix-timestamp'] ??\n null\n\n if (typeof timestamp === 'string' && timestamp.trim().length > 0) {\n const digest = createHash('sha256')\n .update(input.providerKey)\n .update(':')\n .update(input.endpointId)\n .update(':')\n .update(timestamp.trim())\n .update(':')\n .update(input.body)\n .digest('hex')\n\n return `derived:${timestamp.trim()}:${digest}`\n }\n\n const digest = createHash('sha256')\n .update(input.providerKey)\n .update(':')\n .update(input.endpointId)\n .update(':')\n .update(input.body)\n .digest('hex')\n\n return `derived:no-timestamp:${digest}`\n}\n"],
5
- "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,kBAAkB;AAG3B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,gBAAgB,aAAa,2BAA2B,4BAA4B;AAE7F,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B,4CAA4C;AAClF,SAAS,YAAY;AACrB,SAAS,mCAAmC;AAErC,MAAM,WAAW;AAAA,EACtB,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AS,+BACd,OACQ;AACR,QAAM,oBAAoB,MAAM,QAAQ,YAAY,KAAK,MAAM,QAAQ,SAAS,KAAK;AACrF,MAAI,OAAO,sBAAsB,YAAY,kBAAkB,KAAK,EAAE,SAAS,GAAG;AAChF,WAAO,kBAAkB,KAAK;AAAA,EAChC;AAEA,QAAM,YACJ,MAAM,QAAQ,mBAAmB,KACjC,MAAM,QAAQ,gBAAgB,KAC9B;AAEF,MAAI,OAAO,cAAc,YAAY,UAAU,KAAK,EAAE,SAAS,GAAG;AAChE,UAAMA,UAAS,WAAW,QAAQ,EAC/B,OAAO,MAAM,WAAW,EACxB,OAAO,GAAG,EACV,OAAO,MAAM,UAAU,EACvB,OAAO,GAAG,EACV,OAAO,UAAU,KAAK,CAAC,EACvB,OAAO,GAAG,EACV,OAAO,MAAM,IAAI,EACjB,OAAO,KAAK;AAEf,WAAO,WAAW,UAAU,KAAK,CAAC,IAAIA,OAAM;AAAA,EAC9C;AAEA,QAAM,SAAS,WAAW,QAAQ,EAC/B,OAAO,MAAM,WAAW,EACxB,OAAO,GAAG,EACV,OAAO,MAAM,UAAU,EACvB,OAAO,GAAG,EACV,OAAO,MAAM,IAAI,EACjB,OAAO,KAAK;AAEf,SAAO,wBAAwB,MAAM;AACvC;",
6
- "names": ["digest"]
4
+ "sourcesContent": ["import { z } from 'zod'\nimport { createHash } from 'node:crypto'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport type { OpenApiRouteDoc } from '@open-mercato/shared/lib/openapi'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport { resolveTranslations } from '@open-mercato/shared/lib/i18n/server'\nimport { checkRateLimit, getClientIp, RATE_LIMIT_ERROR_FALLBACK, RATE_LIMIT_ERROR_KEY } from '@open-mercato/shared/lib/ratelimit/helpers'\nimport type { RateLimiterService } from '@open-mercato/shared/lib/ratelimit/service'\nimport { findWithDecryption } from '@open-mercato/shared/lib/encryption/find'\nimport type { InboundWebhookRequest } from '@open-mercato/shared/lib/webhooks'\nimport { emitWebhooksEvent } from '../../../events'\nimport { getWebhookEndpointAdapter } from '../../../lib/adapter-registry'\nimport { getWebhookSource } from '../../../lib/inbound-registry'\nimport { enqueueInboundDispatch } from '../../../lib/queue'\nimport { isWebhookIntegrationEnabled, WEBHOOK_INTEGRATION_DISABLED_MESSAGE } from '../../../lib/integration-state'\nimport { json } from '../../helpers'\nimport { InboundEndpointConfigEntity, WebhookIngestionEntity, WebhookInboundReceiptEntity } from '../../../data/entities'\n\ntype IntegrationCredentialsService = {\n resolve: (\n integrationId: string,\n scope: { organizationId: string; tenantId: string },\n ) => Promise<Record<string, unknown> | null>\n}\n\nfunction toStringCredentials(credentials: Record<string, unknown> | null): Record<string, string> {\n const result: Record<string, string> = {}\n if (!credentials) return result\n for (const [key, value] of Object.entries(credentials)) {\n if (typeof value === 'string') result[key] = value\n }\n return result\n}\n\nexport const metadata = {\n POST: { requireAuth: false },\n}\n\ninterface RouteContext {\n params: Promise<{ endpointId: string }>\n}\n\nconst inboundResponseSchema = z.object({\n ok: z.boolean(),\n duplicate: z.boolean().optional(),\n})\n\nconst errorSchema = z.object({ error: z.string() })\n\nexport async function POST(request: Request, context: RouteContext): Promise<Response> {\n const params = await context.params\n const source = getWebhookSource(params.endpointId)\n const adapter = source ? undefined : getWebhookEndpointAdapter(params.endpointId)\n const { translate } = await resolveTranslations()\n\n if (!source && !adapter) {\n return json({ error: 'Webhook endpoint not found' }, { status: 404 })\n }\n\n const container = await createRequestContainer()\n const em = (container.resolve('em') as EntityManager).fork()\n const rateLimiterService = tryResolve<RateLimiterService>(container, 'rateLimiterService')\n\n if (rateLimiterService) {\n const rateLimitResponse = await checkRateLimit(\n rateLimiterService,\n { points: 60, duration: 60, keyPrefix: `webhooks:inbound:${params.endpointId}` },\n buildInboundRateLimitKey(params.endpointId, request, rateLimiterService.trustProxyDepth),\n translate(RATE_LIMIT_ERROR_KEY, RATE_LIMIT_ERROR_FALLBACK),\n )\n\n if (rateLimitResponse) return rateLimitResponse\n }\n\n if (source) {\n const rawBody = await request.text()\n const sourceHeaders = Object.fromEntries(request.headers.entries())\n let parsedBody: Record<string, unknown> = {}\n try {\n const parsed = JSON.parse(rawBody)\n if (parsed && typeof parsed === 'object') parsedBody = parsed as Record<string, unknown>\n } catch {\n parsedBody = {}\n }\n const inboundRequest: InboundWebhookRequest = { body: rawBody, headers: sourceHeaders, parsedBody }\n\n const credentialsService = tryResolve<IntegrationCredentialsService>(container, 'integrationCredentialsService')\n const configs = await findWithDecryption(\n em,\n InboundEndpointConfigEntity,\n { sourceKey: params.endpointId, isActive: true },\n {},\n )\n\n let verifiedScope: { organizationId: string; tenantId: string } | null = null\n for (const config of configs) {\n const scope = { organizationId: config.organizationId, tenantId: config.tenantId }\n const credentials = credentialsService\n ? await credentialsService.resolve(`webhook_source_${params.endpointId}`, scope)\n : null\n let valid = false\n try {\n valid = await source.verifier(inboundRequest, toStringCredentials(credentials))\n } catch {\n valid = false\n }\n if (valid) {\n verifiedScope = scope\n break\n }\n }\n\n if (!verifiedScope) {\n return json({ error: 'Signature verification failed' }, { status: 401 })\n }\n\n const eventType = source.eventTypeExtractor(parsedBody, sourceHeaders)\n const messageId = source.messageIdExtractor?.(parsedBody, sourceHeaders)\n ?? resolveInboundReceiptMessageId({\n endpointId: params.endpointId,\n providerKey: params.endpointId,\n headers: sourceHeaders,\n body: rawBody,\n })\n\n try {\n em.persist(em.create(WebhookInboundReceiptEntity, {\n endpointId: params.endpointId,\n messageId,\n providerKey: params.endpointId,\n eventType,\n tenantId: verifiedScope.tenantId,\n organizationId: verifiedScope.organizationId,\n createdAt: new Date(),\n }))\n await em.flush()\n } catch (error) {\n if (isUniqueViolation(error)) {\n return json({ ok: true, duplicate: true })\n }\n throw error\n }\n\n const ingestion = em.create(WebhookIngestionEntity, {\n sourceKey: params.endpointId,\n eventType,\n externalMessageId: messageId,\n payload: parsedBody,\n headers: sourceHeaders,\n status: 'received',\n handlerCount: 0,\n organizationId: verifiedScope.organizationId,\n tenantId: verifiedScope.tenantId,\n createdAt: new Date(),\n updatedAt: new Date(),\n })\n em.persist(ingestion)\n await em.flush()\n\n await enqueueInboundDispatch({\n ingestionId: ingestion.id,\n sourceKey: params.endpointId,\n eventType,\n tenantId: verifiedScope.tenantId,\n organizationId: verifiedScope.organizationId,\n })\n\n await emitWebhooksEvent('webhooks.inbound.received', {\n providerKey: params.endpointId,\n endpointId: params.endpointId,\n messageId,\n eventType,\n payload: parsedBody,\n tenantId: verifiedScope.tenantId,\n organizationId: verifiedScope.organizationId,\n }, { persistent: true })\n\n return json({ ok: true })\n }\n\n if (!adapter) {\n return json({ error: 'Webhook endpoint not found' }, { status: 404 })\n }\n\n const body = await request.text()\n const headers = Object.fromEntries(request.headers.entries())\n let verified: Awaited<ReturnType<typeof adapter.verifyWebhook>>\n try {\n verified = await adapter.verifyWebhook({\n headers,\n body,\n method: request.method,\n })\n } catch {\n return json({ error: 'Verification failed' }, { status: 400 })\n }\n\n const hasTenantId = Boolean(verified.tenantId)\n const hasOrganizationId = Boolean(verified.organizationId)\n if (hasTenantId !== hasOrganizationId) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n\n const integrationScope = hasTenantId && hasOrganizationId\n ? { tenantId: verified.tenantId as string, organizationId: verified.organizationId as string }\n : null\n\n if (integrationScope) {\n const integrationEnabled = await isWebhookIntegrationEnabled(em, integrationScope)\n if (!integrationEnabled) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n } else if (!adapter.allowUnscopedInbound) {\n return json({ error: WEBHOOK_INTEGRATION_DISABLED_MESSAGE }, { status: 503 })\n }\n\n const messageId = resolveInboundReceiptMessageId({\n endpointId: params.endpointId,\n providerKey: adapter.providerKey,\n headers,\n body,\n })\n try {\n em.persist(em.create(WebhookInboundReceiptEntity, {\n endpointId: params.endpointId,\n messageId,\n providerKey: adapter.providerKey,\n eventType: verified.eventType,\n tenantId: verified.tenantId ?? null,\n organizationId: verified.organizationId ?? null,\n createdAt: new Date(),\n }))\n await em.flush()\n } catch (error) {\n if (isUniqueViolation(error)) {\n return json({ ok: true, duplicate: true })\n }\n throw error\n }\n\n await emitWebhooksEvent('webhooks.inbound.received', {\n providerKey: adapter.providerKey,\n endpointId: params.endpointId,\n messageId,\n eventType: verified.eventType,\n payload: verified.payload,\n tenantId: verified.tenantId ?? null,\n organizationId: verified.organizationId ?? null,\n }, { persistent: true })\n\n return json({ ok: true })\n}\n\nexport const openApi: OpenApiRouteDoc = {\n summary: 'Receive inbound webhook',\n description: 'Verifies, rate limits, deduplicates, and processes an inbound webhook using the registered endpoint adapter.',\n methods: {\n POST: {\n summary: 'Receive inbound webhook',\n description: 'The endpoint id resolves to a registered webhook source first (module-level handler dispatch), otherwise to a legacy adapter provider key.',\n pathParams: z.object({ endpointId: z.string().min(1) }),\n responses: [{ status: 200, description: 'Inbound webhook accepted', schema: inboundResponseSchema }],\n errors: [\n { status: 400, description: 'Verification failed', schema: errorSchema },\n { status: 401, description: 'Signature verification failed (source flow)', schema: errorSchema },\n { status: 404, description: 'Endpoint not found', schema: errorSchema },\n { status: 429, description: 'Rate limit exceeded', schema: errorSchema },\n { status: 503, description: 'Webhook integration disabled', schema: errorSchema },\n ],\n },\n },\n}\n\nfunction tryResolve<T>(container: { resolve: (name: string) => unknown }, name: string): T | null {\n try {\n return container.resolve(name) as T\n } catch {\n return null\n }\n}\n\nfunction isUniqueViolation(error: unknown): boolean {\n if (!error || typeof error !== 'object') return false\n const maybeError = error as { code?: string; cause?: unknown }\n if (maybeError.code === '23505') return true\n if (!maybeError.cause || typeof maybeError.cause !== 'object') return false\n return (maybeError.cause as { code?: string }).code === '23505'\n}\n\ntype ResolveInboundReceiptMessageIdInput = {\n endpointId: string\n providerKey: string\n headers: Record<string, string>\n body: string\n}\n\nexport function buildInboundRateLimitKey(endpointId: string, request: Request, trustProxyDepth: number): string {\n const clientIp = getClientIp(request, trustProxyDepth)\n return clientIp ? `${endpointId}:ip:${clientIp}` : `${endpointId}:global`\n}\n\nexport function resolveInboundReceiptMessageId(\n input: ResolveInboundReceiptMessageIdInput\n): string {\n const explicitMessageId = input.headers['webhook-id'] ?? input.headers['svix-id'] ?? null\n if (typeof explicitMessageId === 'string' && explicitMessageId.trim().length > 0) {\n return explicitMessageId.trim()\n }\n\n const timestamp =\n input.headers['webhook-timestamp'] ??\n input.headers['svix-timestamp'] ??\n null\n\n if (typeof timestamp === 'string' && timestamp.trim().length > 0) {\n const digest = createHash('sha256')\n .update(input.providerKey)\n .update(':')\n .update(input.endpointId)\n .update(':')\n .update(timestamp.trim())\n .update(':')\n .update(input.body)\n .digest('hex')\n\n return `derived:${timestamp.trim()}:${digest}`\n }\n\n const digest = createHash('sha256')\n .update(input.providerKey)\n .update(':')\n .update(input.endpointId)\n .update(':')\n .update(input.body)\n .digest('hex')\n\n return `derived:no-timestamp:${digest}`\n}\n"],
5
+ "mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,kBAAkB;AAG3B,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,gBAAgB,aAAa,2BAA2B,4BAA4B;AAE7F,SAAS,0BAA0B;AAEnC,SAAS,yBAAyB;AAClC,SAAS,iCAAiC;AAC1C,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AACvC,SAAS,6BAA6B,4CAA4C;AAClF,SAAS,YAAY;AACrB,SAAS,6BAA6B,wBAAwB,mCAAmC;AASjG,SAAS,oBAAoB,aAAqE;AAChG,QAAM,SAAiC,CAAC;AACxC,MAAI,CAAC,YAAa,QAAO;AACzB,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,WAAW,GAAG;AACtD,QAAI,OAAO,UAAU,SAAU,QAAO,GAAG,IAAI;AAAA,EAC/C;AACA,SAAO;AACT;AAEO,MAAM,WAAW;AAAA,EACtB,MAAM,EAAE,aAAa,MAAM;AAC7B;AAMA,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,IAAI,EAAE,QAA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AO,QAAQ,KAAK,GAAG,UAAU;AAClE;AAEO,SAAS,+BACd,OACQ;AACR,QAAM,oBAAoB,MAAM,QAAQ,YAAY,KAAK,MAAM,QAAQ,SAAS,KAAK;AACrF,MAAI,OAAO,sBAAsB,YAAY,kBAAkB,KAAK,EAAE,SAAS,GAAG;AAChF,WAAO,kBAAkB,KAAK;AAAA,EAChC;AAEA,QAAM,YACJ,MAAM,QAAQ,mBAAmB,KACjC,MAAM,QAAQ,gBAAgB,KAC9B;AAEF,MAAI,OAAO,cAAc,YAAY,UAAU,KAAK,EAAE,SAAS,GAAG;AAChE,UAAMC,UAAS,WAAW,QAAQ,EAC/B,OAAO,MAAM,WAAW,EACxB,OAAO,GAAG,EACV,OAAO,MAAM,UAAU,EACvB,OAAO,GAAG,EACV,OAAO,UAAU,KAAK,CAAC,EACvB,OAAO,GAAG,EACV,OAAO,MAAM,IAAI,EACjB,OAAO,KAAK;AAEf,WAAO,WAAW,UAAU,KAAK,CAAC,IAAIA,OAAM;AAAA,EAC9C;AAEA,QAAM,SAAS,WAAW,QAAQ,EAC/B,OAAO,MAAM,WAAW,EACxB,OAAO,GAAG,EACV,OAAO,MAAM,UAAU,EACvB,OAAO,GAAG,EACV,OAAO,MAAM,IAAI,EACjB,OAAO,KAAK;AAEf,SAAO,wBAAwB,MAAM;AACvC;",
6
+ "names": ["messageId", "digest"]
7
7
  }
@@ -223,9 +223,109 @@ WebhookInboundReceiptEntity = __decorateClass([
223
223
  Unique({ name: "webhook_inbound_receipts_endpoint_message_unique", properties: ["endpointId", "messageId"] }),
224
224
  Index({ properties: ["providerKey", "createdAt"] })
225
225
  ], WebhookInboundReceiptEntity);
226
+ let WebhookIngestionEntity = class {
227
+ constructor() {
228
+ this.status = "received";
229
+ this.handlerCount = 0;
230
+ this.createdAt = /* @__PURE__ */ new Date();
231
+ this.updatedAt = /* @__PURE__ */ new Date();
232
+ }
233
+ };
234
+ __decorateClass([
235
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
236
+ ], WebhookIngestionEntity.prototype, "id", 2);
237
+ __decorateClass([
238
+ Property({ name: "source_key", type: "text" })
239
+ ], WebhookIngestionEntity.prototype, "sourceKey", 2);
240
+ __decorateClass([
241
+ Property({ name: "event_type", type: "text" })
242
+ ], WebhookIngestionEntity.prototype, "eventType", 2);
243
+ __decorateClass([
244
+ Property({ name: "external_message_id", type: "text", nullable: true })
245
+ ], WebhookIngestionEntity.prototype, "externalMessageId", 2);
246
+ __decorateClass([
247
+ Property({ name: "payload", type: "json" })
248
+ ], WebhookIngestionEntity.prototype, "payload", 2);
249
+ __decorateClass([
250
+ Property({ name: "headers", type: "json", nullable: true })
251
+ ], WebhookIngestionEntity.prototype, "headers", 2);
252
+ __decorateClass([
253
+ Property({ name: "status", type: "text", default: "received" })
254
+ ], WebhookIngestionEntity.prototype, "status", 2);
255
+ __decorateClass([
256
+ Property({ name: "error_message", type: "text", nullable: true })
257
+ ], WebhookIngestionEntity.prototype, "errorMessage", 2);
258
+ __decorateClass([
259
+ Property({ name: "processed_at", type: Date, nullable: true })
260
+ ], WebhookIngestionEntity.prototype, "processedAt", 2);
261
+ __decorateClass([
262
+ Property({ name: "handler_count", type: "int", default: 0 })
263
+ ], WebhookIngestionEntity.prototype, "handlerCount", 2);
264
+ __decorateClass([
265
+ Property({ name: "handler_results", type: "json", nullable: true })
266
+ ], WebhookIngestionEntity.prototype, "handlerResults", 2);
267
+ __decorateClass([
268
+ Property({ name: "duration_ms", type: "int", nullable: true })
269
+ ], WebhookIngestionEntity.prototype, "durationMs", 2);
270
+ __decorateClass([
271
+ Property({ name: "organization_id", type: "uuid" })
272
+ ], WebhookIngestionEntity.prototype, "organizationId", 2);
273
+ __decorateClass([
274
+ Property({ name: "tenant_id", type: "uuid" })
275
+ ], WebhookIngestionEntity.prototype, "tenantId", 2);
276
+ __decorateClass([
277
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
278
+ ], WebhookIngestionEntity.prototype, "createdAt", 2);
279
+ __decorateClass([
280
+ Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
281
+ ], WebhookIngestionEntity.prototype, "updatedAt", 2);
282
+ WebhookIngestionEntity = __decorateClass([
283
+ Entity({ tableName: "webhook_ingestions" }),
284
+ Index({ properties: ["sourceKey", "status", "createdAt"] }),
285
+ Index({ properties: ["organizationId", "tenantId", "createdAt"] }),
286
+ Index({ properties: ["externalMessageId"] })
287
+ ], WebhookIngestionEntity);
288
+ let InboundEndpointConfigEntity = class {
289
+ constructor() {
290
+ this.isActive = true;
291
+ this.createdAt = /* @__PURE__ */ new Date();
292
+ this.updatedAt = /* @__PURE__ */ new Date();
293
+ }
294
+ };
295
+ __decorateClass([
296
+ PrimaryKey({ type: "uuid", defaultRaw: "gen_random_uuid()" })
297
+ ], InboundEndpointConfigEntity.prototype, "id", 2);
298
+ __decorateClass([
299
+ Property({ name: "source_key", type: "text" })
300
+ ], InboundEndpointConfigEntity.prototype, "sourceKey", 2);
301
+ __decorateClass([
302
+ Property({ name: "is_active", type: "boolean", default: true })
303
+ ], InboundEndpointConfigEntity.prototype, "isActive", 2);
304
+ __decorateClass([
305
+ Property({ name: "integration_id", type: "text", nullable: true })
306
+ ], InboundEndpointConfigEntity.prototype, "integrationId", 2);
307
+ __decorateClass([
308
+ Property({ name: "organization_id", type: "uuid" })
309
+ ], InboundEndpointConfigEntity.prototype, "organizationId", 2);
310
+ __decorateClass([
311
+ Property({ name: "tenant_id", type: "uuid" })
312
+ ], InboundEndpointConfigEntity.prototype, "tenantId", 2);
313
+ __decorateClass([
314
+ Property({ name: "created_at", type: Date, onCreate: () => /* @__PURE__ */ new Date() })
315
+ ], InboundEndpointConfigEntity.prototype, "createdAt", 2);
316
+ __decorateClass([
317
+ Property({ name: "updated_at", type: Date, onUpdate: () => /* @__PURE__ */ new Date() })
318
+ ], InboundEndpointConfigEntity.prototype, "updatedAt", 2);
319
+ InboundEndpointConfigEntity = __decorateClass([
320
+ Entity({ tableName: "webhook_inbound_configs" }),
321
+ Unique({ name: "webhook_inbound_configs_source_scope_unique", properties: ["sourceKey", "organizationId", "tenantId"] }),
322
+ Index({ properties: ["sourceKey", "isActive"] })
323
+ ], InboundEndpointConfigEntity);
226
324
  export {
325
+ InboundEndpointConfigEntity,
227
326
  WebhookDeliveryEntity,
228
327
  WebhookEntity,
229
- WebhookInboundReceiptEntity
328
+ WebhookInboundReceiptEntity,
329
+ WebhookIngestionEntity
230
330
  };
231
331
  //# sourceMappingURL=entities.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/modules/webhooks/data/entities.ts"],
4
- "sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\n\n@Entity({ tableName: 'webhooks' })\n@Index({ properties: ['organizationId', 'tenantId', 'isActive'] })\n@Index({ properties: ['organizationId', 'tenantId', 'deletedAt'] })\nexport class WebhookEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ name: 'description', type: 'text', nullable: true })\n description?: string | null\n\n @Property({ name: 'url', type: 'text' })\n url!: string\n\n @Property({ name: 'secret', type: 'text' })\n secret!: string\n\n @Property({ name: 'previous_secret', type: 'text', nullable: true })\n previousSecret?: string | null\n\n @Property({ name: 'previous_secret_set_at', type: Date, nullable: true })\n previousSecretSetAt?: Date | null\n\n @Property({ name: 'subscribed_events', type: 'json' })\n subscribedEvents!: string[]\n\n @Property({ name: 'http_method', type: 'text', default: 'POST' })\n httpMethod: string = 'POST'\n\n @Property({ name: 'custom_headers', type: 'json', nullable: true })\n customHeaders?: Record<string, string> | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'delivery_strategy', type: 'text', default: 'http' })\n deliveryStrategy: string = 'http'\n\n @Property({ name: 'strategy_config', type: 'json', nullable: true })\n strategyConfig?: Record<string, unknown> | null\n\n @Property({ name: 'max_retries', type: 'int', default: 10 })\n maxRetries: number = 10\n\n @Property({ name: 'timeout_ms', type: 'int', default: 15000 })\n timeoutMs: number = 15000\n\n @Property({ name: 'rate_limit_per_minute', type: 'int', default: 0 })\n rateLimitPerMinute: number = 0\n\n @Property({ name: 'consecutive_failures', type: 'int', default: 0 })\n consecutiveFailures: number = 0\n\n @Property({ name: 'auto_disable_threshold', type: 'int', default: 100 })\n autoDisableThreshold: number = 100\n\n @Property({ name: 'last_success_at', type: Date, nullable: true })\n lastSuccessAt?: Date | null\n\n @Property({ name: 'last_failure_at', type: Date, nullable: true })\n lastFailureAt?: Date | null\n\n @Property({ name: 'integration_id', type: 'text', nullable: true })\n integrationId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'webhook_deliveries' })\n@Index({ properties: ['webhookId', 'status'] })\n@Index({ properties: ['organizationId', 'tenantId', 'createdAt'] })\n@Index({ properties: ['webhookId', 'createdAt'] })\n@Index({ properties: ['eventType', 'organizationId'] })\nexport class WebhookDeliveryEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'webhook_id', type: 'uuid' })\n webhookId!: string\n\n @Property({ name: 'event_type', type: 'text' })\n eventType!: string\n\n @Property({ name: 'message_id', type: 'text' })\n messageId!: string\n\n @Property({ name: 'payload', type: 'json' })\n payload!: Record<string, unknown>\n\n @Property({ name: 'status', type: 'text', default: 'pending' })\n status: string = 'pending'\n\n @Property({ name: 'response_status', type: 'int', nullable: true })\n responseStatus?: number | null\n\n @Property({ name: 'response_body', type: 'text', nullable: true })\n responseBody?: string | null\n\n @Property({ name: 'response_headers', type: 'json', nullable: true })\n responseHeaders?: Record<string, string> | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'attempt_number', type: 'int', default: 0 })\n attemptNumber: number = 0\n\n @Property({ name: 'max_attempts', type: 'int', default: 10 })\n maxAttempts: number = 10\n\n @Property({ name: 'next_retry_at', type: Date, nullable: true })\n nextRetryAt?: Date | null\n\n @Property({ name: 'duration_ms', type: 'int', nullable: true })\n durationMs?: number | null\n\n @Property({ name: 'target_url', type: 'text' })\n targetUrl!: string\n\n @Property({ name: 'enqueued_at', type: Date })\n enqueuedAt: Date = new Date()\n\n @Property({ name: 'last_attempt_at', type: Date, nullable: true })\n lastAttemptAt?: Date | null\n\n @Property({ name: 'delivered_at', type: Date, nullable: true })\n deliveredAt?: Date | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'webhook_inbound_receipts' })\n@Unique({ name: 'webhook_inbound_receipts_endpoint_message_unique', properties: ['endpointId', 'messageId'] })\n@Index({ properties: ['providerKey', 'createdAt'] })\nexport class WebhookInboundReceiptEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'endpoint_id', type: 'text' })\n endpointId!: string\n\n @Property({ name: 'message_id', type: 'text' })\n messageId!: string\n\n @Property({ name: 'provider_key', type: 'text' })\n providerKey!: string\n\n @Property({ name: 'event_type', type: 'text', nullable: true })\n eventType?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n"],
5
- "mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAKrD,IAAM,gBAAN,MAAoB;AAAA,EAApB;AA0BL,sBAAqB;AAMrB,oBAAoB;AAGpB,4BAA2B;AAM3B,sBAAqB;AAGrB,qBAAoB;AAGpB,8BAA6B;AAG7B,+BAA8B;AAG9B,gCAA+B;AAkB/B,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AA5EE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,cAEX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAJf,cAKX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,eAAe,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAPpD,cAQX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,MAAM,OAAO,CAAC;AAAA,GAV5B,cAWX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,UAAU,MAAM,OAAO,CAAC;AAAA,GAb/B,cAcX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAhBxD,cAiBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,0BAA0B,MAAM,MAAM,UAAU,KAAK,CAAC;AAAA,GAnB7D,cAoBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,qBAAqB,MAAM,OAAO,CAAC;AAAA,GAtB1C,cAuBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,eAAe,MAAM,QAAQ,SAAS,OAAO,CAAC;AAAA,GAzBrD,cA0BX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,kBAAkB,MAAM,QAAQ,UAAU,KAAK,CAAC;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K,CAAC;AAAA,GAnBlD,4BAoBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GAtB7D,4BAuBX;AAvBW,8BAAN;AAAA,EAHN,OAAO,EAAE,WAAW,2BAA2B,CAAC;AAAA,EAChD,OAAO,EAAE,MAAM,oDAAoD,YAAY,CAAC,cAAc,WAAW,EAAE,CAAC;AAAA,EAC5G,MAAM,EAAE,YAAY,CAAC,eAAe,WAAW,EAAE,CAAC;AAAA,GACtC;",
4
+ "sourcesContent": ["import { Entity, Index, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'\nimport type { WebhookHandlerResult, WebhookIngestionStatus } from '@open-mercato/shared/lib/webhooks'\n\n@Entity({ tableName: 'webhooks' })\n@Index({ properties: ['organizationId', 'tenantId', 'isActive'] })\n@Index({ properties: ['organizationId', 'tenantId', 'deletedAt'] })\nexport class WebhookEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ type: 'text' })\n name!: string\n\n @Property({ name: 'description', type: 'text', nullable: true })\n description?: string | null\n\n @Property({ name: 'url', type: 'text' })\n url!: string\n\n @Property({ name: 'secret', type: 'text' })\n secret!: string\n\n @Property({ name: 'previous_secret', type: 'text', nullable: true })\n previousSecret?: string | null\n\n @Property({ name: 'previous_secret_set_at', type: Date, nullable: true })\n previousSecretSetAt?: Date | null\n\n @Property({ name: 'subscribed_events', type: 'json' })\n subscribedEvents!: string[]\n\n @Property({ name: 'http_method', type: 'text', default: 'POST' })\n httpMethod: string = 'POST'\n\n @Property({ name: 'custom_headers', type: 'json', nullable: true })\n customHeaders?: Record<string, string> | null\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'delivery_strategy', type: 'text', default: 'http' })\n deliveryStrategy: string = 'http'\n\n @Property({ name: 'strategy_config', type: 'json', nullable: true })\n strategyConfig?: Record<string, unknown> | null\n\n @Property({ name: 'max_retries', type: 'int', default: 10 })\n maxRetries: number = 10\n\n @Property({ name: 'timeout_ms', type: 'int', default: 15000 })\n timeoutMs: number = 15000\n\n @Property({ name: 'rate_limit_per_minute', type: 'int', default: 0 })\n rateLimitPerMinute: number = 0\n\n @Property({ name: 'consecutive_failures', type: 'int', default: 0 })\n consecutiveFailures: number = 0\n\n @Property({ name: 'auto_disable_threshold', type: 'int', default: 100 })\n autoDisableThreshold: number = 100\n\n @Property({ name: 'last_success_at', type: Date, nullable: true })\n lastSuccessAt?: Date | null\n\n @Property({ name: 'last_failure_at', type: Date, nullable: true })\n lastFailureAt?: Date | null\n\n @Property({ name: 'integration_id', type: 'text', nullable: true })\n integrationId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n\n @Property({ name: 'deleted_at', type: Date, nullable: true })\n deletedAt?: Date | null\n}\n\n@Entity({ tableName: 'webhook_deliveries' })\n@Index({ properties: ['webhookId', 'status'] })\n@Index({ properties: ['organizationId', 'tenantId', 'createdAt'] })\n@Index({ properties: ['webhookId', 'createdAt'] })\n@Index({ properties: ['eventType', 'organizationId'] })\nexport class WebhookDeliveryEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'webhook_id', type: 'uuid' })\n webhookId!: string\n\n @Property({ name: 'event_type', type: 'text' })\n eventType!: string\n\n @Property({ name: 'message_id', type: 'text' })\n messageId!: string\n\n @Property({ name: 'payload', type: 'json' })\n payload!: Record<string, unknown>\n\n @Property({ name: 'status', type: 'text', default: 'pending' })\n status: string = 'pending'\n\n @Property({ name: 'response_status', type: 'int', nullable: true })\n responseStatus?: number | null\n\n @Property({ name: 'response_body', type: 'text', nullable: true })\n responseBody?: string | null\n\n @Property({ name: 'response_headers', type: 'json', nullable: true })\n responseHeaders?: Record<string, string> | null\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'attempt_number', type: 'int', default: 0 })\n attemptNumber: number = 0\n\n @Property({ name: 'max_attempts', type: 'int', default: 10 })\n maxAttempts: number = 10\n\n @Property({ name: 'next_retry_at', type: Date, nullable: true })\n nextRetryAt?: Date | null\n\n @Property({ name: 'duration_ms', type: 'int', nullable: true })\n durationMs?: number | null\n\n @Property({ name: 'target_url', type: 'text' })\n targetUrl!: string\n\n @Property({ name: 'enqueued_at', type: Date })\n enqueuedAt: Date = new Date()\n\n @Property({ name: 'last_attempt_at', type: Date, nullable: true })\n lastAttemptAt?: Date | null\n\n @Property({ name: 'delivered_at', type: Date, nullable: true })\n deliveredAt?: Date | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'webhook_inbound_receipts' })\n@Unique({ name: 'webhook_inbound_receipts_endpoint_message_unique', properties: ['endpointId', 'messageId'] })\n@Index({ properties: ['providerKey', 'createdAt'] })\nexport class WebhookInboundReceiptEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'endpoint_id', type: 'text' })\n endpointId!: string\n\n @Property({ name: 'message_id', type: 'text' })\n messageId!: string\n\n @Property({ name: 'provider_key', type: 'text' })\n providerKey!: string\n\n @Property({ name: 'event_type', type: 'text', nullable: true })\n eventType?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid', nullable: true })\n organizationId?: string | null\n\n @Property({ name: 'tenant_id', type: 'uuid', nullable: true })\n tenantId?: string | null\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n}\n\n@Entity({ tableName: 'webhook_ingestions' })\n@Index({ properties: ['sourceKey', 'status', 'createdAt'] })\n@Index({ properties: ['organizationId', 'tenantId', 'createdAt'] })\n@Index({ properties: ['externalMessageId'] })\nexport class WebhookIngestionEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source_key', type: 'text' })\n sourceKey!: string\n\n @Property({ name: 'event_type', type: 'text' })\n eventType!: string\n\n @Property({ name: 'external_message_id', type: 'text', nullable: true })\n externalMessageId?: string | null\n\n @Property({ name: 'payload', type: 'json' })\n payload!: Record<string, unknown>\n\n @Property({ name: 'headers', type: 'json', nullable: true })\n headers?: Record<string, string> | null\n\n @Property({ name: 'status', type: 'text', default: 'received' })\n status: WebhookIngestionStatus = 'received'\n\n @Property({ name: 'error_message', type: 'text', nullable: true })\n errorMessage?: string | null\n\n @Property({ name: 'processed_at', type: Date, nullable: true })\n processedAt?: Date | null\n\n @Property({ name: 'handler_count', type: 'int', default: 0 })\n handlerCount: number = 0\n\n @Property({ name: 'handler_results', type: 'json', nullable: true })\n handlerResults?: WebhookHandlerResult[] | null\n\n @Property({ name: 'duration_ms', type: 'int', nullable: true })\n durationMs?: number | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n\n@Entity({ tableName: 'webhook_inbound_configs' })\n@Unique({ name: 'webhook_inbound_configs_source_scope_unique', properties: ['sourceKey', 'organizationId', 'tenantId'] })\n@Index({ properties: ['sourceKey', 'isActive'] })\nexport class InboundEndpointConfigEntity {\n @PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })\n id!: string\n\n @Property({ name: 'source_key', type: 'text' })\n sourceKey!: string\n\n @Property({ name: 'is_active', type: 'boolean', default: true })\n isActive: boolean = true\n\n @Property({ name: 'integration_id', type: 'text', nullable: true })\n integrationId?: string | null\n\n @Property({ name: 'organization_id', type: 'uuid' })\n organizationId!: string\n\n @Property({ name: 'tenant_id', type: 'uuid' })\n tenantId!: string\n\n @Property({ name: 'created_at', type: Date, onCreate: () => new Date() })\n createdAt: Date = new Date()\n\n @Property({ name: 'updated_at', type: Date, onUpdate: () => new Date() })\n updatedAt: Date = new Date()\n}\n"],
5
+ "mappings": ";;;;;;;;;;AAAA,SAAS,QAAQ,OAAO,YAAY,UAAU,cAAc;AAMrD,IAAM,gBAAN,MAAoB;AAAA,EAApB;AA0BL,sBAAqB;AAMrB,oBAAoB;AAGpB,4BAA2B;AAM3B,sBAAqB;AAGrB,qBAAoB;AAGpB,8BAA6B;AAG7B,+BAA8B;AAG9B,gCAA+B;AAkB/B,qBAAkB,oBAAI,KAAK;AAG3B,qBAAkB,oBAAI,KAAK;AAAA;AAI7B;AA5EE;AAAA,EADC,WAAW,EAAE,MAAM,QAAQ,YAAY,oBAAoB,CAAC;AAAA,GADlD,cAEX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,CAAC;AAAA,GAJf,cAKX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,eAAe,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAPpD,cAQX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,OAAO,MAAM,OAAO,CAAC;AAAA,GAV5B,cAWX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,UAAU,MAAM,OAAO,CAAC;AAAA,GAb/B,cAcX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAhBxD,cAiBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,0BAA0B,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6
6
  { field: "previous_secret" }
7
7
  ]
8
+ },
9
+ {
10
+ entityId: "webhooks:webhook_ingestion_entity",
11
+ fields: [
12
+ { field: "payload" },
13
+ { field: "headers" }
14
+ ]
8
15
  }
9
16
  ];
10
17
  var encryption_default = defaultEncryptionMaps;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/modules/webhooks/encryption.ts"],
4
- "sourcesContent": ["import type { ModuleEncryptionMap } from '@open-mercato/shared/modules/encryption'\n\nexport const defaultEncryptionMaps: ModuleEncryptionMap[] = [\n {\n entityId: 'webhooks:webhook_entity',\n fields: [\n { field: 'secret' },\n { field: 'previous_secret' },\n ],\n },\n]\n\nexport default defaultEncryptionMaps\n"],
5
- "mappings": "AAEO,MAAM,wBAA+C;AAAA,EAC1D;AAAA,IACE,UAAU;AAAA,IACV,QAAQ;AAAA,MACN,EAAE,OAAO,SAAS;AAAA,MAClB,EAAE,OAAO,kBAAkB;AAAA,IAC7B;AAAA,EACF;AACF;AAEA,IAAO,qBAAQ;",
4
+ "sourcesContent": ["import type { ModuleEncryptionMap } from '@open-mercato/shared/modules/encryption'\n\nexport const defaultEncryptionMaps: ModuleEncryptionMap[] = [\n {\n entityId: 'webhooks:webhook_entity',\n fields: [\n { field: 'secret' },\n { field: 'previous_secret' },\n ],\n },\n {\n entityId: 'webhooks:webhook_ingestion_entity',\n fields: [\n { field: 'payload' },\n { field: 'headers' },\n ],\n },\n]\n\nexport default defaultEncryptionMaps\n"],
5
+ "mappings": "AAEO,MAAM,wBAA+C;AAAA,EAC1D;AAAA,IACE,UAAU;AAAA,IACV,QAAQ;AAAA,MACN,EAAE,OAAO,SAAS;AAAA,MAClB,EAAE,OAAO,kBAAkB;AAAA,IAC7B;AAAA,EACF;AAAA,EACA;AAAA,IACE,UAAU;AAAA,IACV,QAAQ;AAAA,MACN,EAAE,OAAO,UAAU;AAAA,MACnB,EAAE,OAAO,UAAU;AAAA,IACrB;AAAA,EACF;AACF;AAEA,IAAO,qBAAQ;",
6
6
  "names": []
7
7
  }
@@ -9,6 +9,8 @@ const events = [
9
9
  { id: "webhooks.delivery.exhausted", label: "Webhook Delivery Retries Exhausted", entity: "delivery", category: "lifecycle", clientBroadcast: true },
10
10
  { id: "webhooks.webhook.disabled", label: "Webhook Auto-Disabled", entity: "webhook", category: "lifecycle", clientBroadcast: true },
11
11
  { id: "webhooks.inbound.received", label: "Inbound Webhook Received", entity: "inbound", category: "custom" },
12
+ { id: "webhooks.inbound.processed", label: "Inbound Webhook Processed", entity: "inbound", category: "lifecycle" },
13
+ { id: "webhooks.inbound.handler_failed", label: "Inbound Handler Failed", entity: "inbound", category: "lifecycle", clientBroadcast: true },
12
14
  { id: "webhooks.secret.rotated", label: "Webhook Secret Rotated", entity: "webhook", category: "lifecycle" }
13
15
  ];
14
16
  const eventsConfig = createModuleEvents({ moduleId: "webhooks", events });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/modules/webhooks/events.ts"],
4
- "sourcesContent": ["import { createModuleEvents } from '@open-mercato/shared/modules/events'\n\nconst events = [\n { id: 'webhooks.webhook.created', label: 'Webhook Created', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.webhook.updated', label: 'Webhook Updated', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.webhook.deleted', label: 'Webhook Deleted', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.delivery.enqueued', label: 'Webhook Delivery Enqueued', entity: 'delivery', category: 'lifecycle' as const },\n { id: 'webhooks.delivery.succeeded', label: 'Webhook Delivery Succeeded', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.delivery.failed', label: 'Webhook Delivery Failed', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.delivery.exhausted', label: 'Webhook Delivery Retries Exhausted', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.webhook.disabled', label: 'Webhook Auto-Disabled', entity: 'webhook', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.inbound.received', label: 'Inbound Webhook Received', entity: 'inbound', category: 'custom' as const },\n { id: 'webhooks.secret.rotated', label: 'Webhook Secret Rotated', entity: 'webhook', category: 'lifecycle' as const },\n] as const\n\nexport const eventsConfig = createModuleEvents({ moduleId: 'webhooks', events })\nexport const emitWebhooksEvent = eventsConfig.emit\nexport type WebhooksEventId = typeof events[number]['id']\nexport default eventsConfig\n"],
5
- "mappings": "AAAA,SAAS,0BAA0B;AAEnC,MAAM,SAAS;AAAA,EACb,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,8BAA8B,OAAO,6BAA6B,QAAQ,YAAY,UAAU,YAAqB;AAAA,EAC3H,EAAE,IAAI,+BAA+B,OAAO,8BAA8B,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EACpJ,EAAE,IAAI,4BAA4B,OAAO,2BAA2B,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC9I,EAAE,IAAI,+BAA+B,OAAO,sCAAsC,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC5J,EAAE,IAAI,6BAA6B,OAAO,yBAAyB,QAAQ,WAAW,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC5I,EAAE,IAAI,6BAA6B,OAAO,4BAA4B,QAAQ,WAAW,UAAU,SAAkB;AAAA,EACrH,EAAE,IAAI,2BAA2B,OAAO,0BAA0B,QAAQ,WAAW,UAAU,YAAqB;AACtH;AAEO,MAAM,eAAe,mBAAmB,EAAE,UAAU,YAAY,OAAO,CAAC;AACxE,MAAM,oBAAoB,aAAa;AAE9C,IAAO,iBAAQ;",
4
+ "sourcesContent": ["import { createModuleEvents } from '@open-mercato/shared/modules/events'\n\nconst events = [\n { id: 'webhooks.webhook.created', label: 'Webhook Created', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.webhook.updated', label: 'Webhook Updated', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.webhook.deleted', label: 'Webhook Deleted', entity: 'webhook', category: 'crud' as const },\n { id: 'webhooks.delivery.enqueued', label: 'Webhook Delivery Enqueued', entity: 'delivery', category: 'lifecycle' as const },\n { id: 'webhooks.delivery.succeeded', label: 'Webhook Delivery Succeeded', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.delivery.failed', label: 'Webhook Delivery Failed', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.delivery.exhausted', label: 'Webhook Delivery Retries Exhausted', entity: 'delivery', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.webhook.disabled', label: 'Webhook Auto-Disabled', entity: 'webhook', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.inbound.received', label: 'Inbound Webhook Received', entity: 'inbound', category: 'custom' as const },\n { id: 'webhooks.inbound.processed', label: 'Inbound Webhook Processed', entity: 'inbound', category: 'lifecycle' as const },\n { id: 'webhooks.inbound.handler_failed', label: 'Inbound Handler Failed', entity: 'inbound', category: 'lifecycle' as const, clientBroadcast: true },\n { id: 'webhooks.secret.rotated', label: 'Webhook Secret Rotated', entity: 'webhook', category: 'lifecycle' as const },\n] as const\n\nexport const eventsConfig = createModuleEvents({ moduleId: 'webhooks', events })\nexport const emitWebhooksEvent = eventsConfig.emit\nexport type WebhooksEventId = typeof events[number]['id']\nexport default eventsConfig\n"],
5
+ "mappings": "AAAA,SAAS,0BAA0B;AAEnC,MAAM,SAAS;AAAA,EACb,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,4BAA4B,OAAO,mBAAmB,QAAQ,WAAW,UAAU,OAAgB;AAAA,EACzG,EAAE,IAAI,8BAA8B,OAAO,6BAA6B,QAAQ,YAAY,UAAU,YAAqB;AAAA,EAC3H,EAAE,IAAI,+BAA+B,OAAO,8BAA8B,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EACpJ,EAAE,IAAI,4BAA4B,OAAO,2BAA2B,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC9I,EAAE,IAAI,+BAA+B,OAAO,sCAAsC,QAAQ,YAAY,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC5J,EAAE,IAAI,6BAA6B,OAAO,yBAAyB,QAAQ,WAAW,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EAC5I,EAAE,IAAI,6BAA6B,OAAO,4BAA4B,QAAQ,WAAW,UAAU,SAAkB;AAAA,EACrH,EAAE,IAAI,8BAA8B,OAAO,6BAA6B,QAAQ,WAAW,UAAU,YAAqB;AAAA,EAC1H,EAAE,IAAI,mCAAmC,OAAO,0BAA0B,QAAQ,WAAW,UAAU,aAAsB,iBAAiB,KAAK;AAAA,EACnJ,EAAE,IAAI,2BAA2B,OAAO,0BAA0B,QAAQ,WAAW,UAAU,YAAqB;AACtH;AAEO,MAAM,eAAe,mBAAmB,EAAE,UAAU,YAAY,OAAO,CAAC;AACxE,MAAM,oBAAoB,aAAa;AAE9C,IAAO,iBAAQ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,57 @@
1
+ function buildSourcesOutput({ importSection, entriesLiteral }) {
2
+ return `// AUTO-GENERATED by mercato generate registry
3
+ import type { WebhookSourceConfig } from '@open-mercato/shared/lib/webhooks'
4
+ ${importSection ? `${importSection}
5
+ ` : ""}type WebhookSourceModuleEntry = { moduleId: string; sources: WebhookSourceConfig[] }
6
+
7
+ export const webhookSourceEntries: WebhookSourceModuleEntry[] = [
8
+ ${entriesLiteral ? ` ${entriesLiteral}
9
+ ` : ""}]
10
+ `;
11
+ }
12
+ function buildHandlersOutput({ importSection, entriesLiteral }) {
13
+ return `// AUTO-GENERATED by mercato generate registry
14
+ import type { WebhookHandlerRegistryEntry } from '@open-mercato/shared/lib/webhooks'
15
+ ${importSection ? `${importSection}
16
+ ` : ""}type WebhookHandlerModuleEntry = { moduleId: string; handlers: WebhookHandlerRegistryEntry[] }
17
+
18
+ export const webhookHandlerEntries: WebhookHandlerModuleEntry[] = [
19
+ ${entriesLiteral ? ` ${entriesLiteral}
20
+ ` : ""}]
21
+ `;
22
+ }
23
+ const sourcesPlugin = {
24
+ id: "webhooks.sources",
25
+ conventionFile: "webhook-sources.ts",
26
+ importPrefix: "WEBHOOK_SOURCES",
27
+ configExpr: (importName, moduleId) => `{ moduleId: '${moduleId}', sources: ((${importName}.default ?? ${importName}.webhookSources ?? []) as WebhookSourceConfig[]) }`,
28
+ outputFileName: "webhook-sources.generated.ts",
29
+ buildOutput: buildSourcesOutput,
30
+ bootstrapRegistration: {
31
+ entriesExportName: "webhookSourceEntries",
32
+ registrationImports: [
33
+ `import { registerWebhookSourceEntries } from '@open-mercato/webhooks/modules/webhooks/lib/module-webhook-registry'`
34
+ ],
35
+ buildCall: (name) => `registerWebhookSourceEntries(${name})`
36
+ }
37
+ };
38
+ const handlersPlugin = {
39
+ id: "webhooks.handlers",
40
+ conventionFile: "webhook-handlers.ts",
41
+ importPrefix: "WEBHOOK_HANDLERS",
42
+ configExpr: (importName, moduleId) => `{ moduleId: '${moduleId}', handlers: ((${importName}.default ?? ${importName}.webhookHandlers ?? []) as WebhookHandlerRegistryEntry[]) }`,
43
+ outputFileName: "webhook-handlers.generated.ts",
44
+ buildOutput: buildHandlersOutput,
45
+ bootstrapRegistration: {
46
+ entriesExportName: "webhookHandlerEntries",
47
+ registrationImports: [
48
+ `import { registerWebhookHandlerEntries } from '@open-mercato/webhooks/modules/webhooks/lib/module-webhook-registry'`
49
+ ],
50
+ buildCall: (name) => `registerWebhookHandlerEntries(${name})`
51
+ }
52
+ };
53
+ const generatorPlugins = [sourcesPlugin, handlersPlugin];
54
+ export {
55
+ generatorPlugins
56
+ };
57
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/modules/webhooks/generators.ts"],
4
+ "sourcesContent": ["import type { GeneratorPlugin } from '@open-mercato/shared/modules/generators'\n\nfunction buildSourcesOutput({ importSection, entriesLiteral }: { importSection: string; entriesLiteral: string }): string {\n return `// AUTO-GENERATED by mercato generate registry\nimport type { WebhookSourceConfig } from '@open-mercato/shared/lib/webhooks'\n${importSection ? `${importSection}\\n` : ''}type WebhookSourceModuleEntry = { moduleId: string; sources: WebhookSourceConfig[] }\n\nexport const webhookSourceEntries: WebhookSourceModuleEntry[] = [\n${entriesLiteral ? ` ${entriesLiteral}\\n` : ''}]\n`\n}\n\nfunction buildHandlersOutput({ importSection, entriesLiteral }: { importSection: string; entriesLiteral: string }): string {\n return `// AUTO-GENERATED by mercato generate registry\nimport type { WebhookHandlerRegistryEntry } from '@open-mercato/shared/lib/webhooks'\n${importSection ? `${importSection}\\n` : ''}type WebhookHandlerModuleEntry = { moduleId: string; handlers: WebhookHandlerRegistryEntry[] }\n\nexport const webhookHandlerEntries: WebhookHandlerModuleEntry[] = [\n${entriesLiteral ? ` ${entriesLiteral}\\n` : ''}]\n`\n}\n\nconst sourcesPlugin: GeneratorPlugin = {\n id: 'webhooks.sources',\n conventionFile: 'webhook-sources.ts',\n importPrefix: 'WEBHOOK_SOURCES',\n configExpr: (importName: string, moduleId: string) =>\n `{ moduleId: '${moduleId}', sources: ((${importName}.default ?? ${importName}.webhookSources ?? []) as WebhookSourceConfig[]) }`,\n outputFileName: 'webhook-sources.generated.ts',\n buildOutput: buildSourcesOutput,\n bootstrapRegistration: {\n entriesExportName: 'webhookSourceEntries',\n registrationImports: [\n `import { registerWebhookSourceEntries } from '@open-mercato/webhooks/modules/webhooks/lib/module-webhook-registry'`,\n ],\n buildCall: (name: string) => `registerWebhookSourceEntries(${name})`,\n },\n}\n\nconst handlersPlugin: GeneratorPlugin = {\n id: 'webhooks.handlers',\n conventionFile: 'webhook-handlers.ts',\n importPrefix: 'WEBHOOK_HANDLERS',\n configExpr: (importName: string, moduleId: string) =>\n `{ moduleId: '${moduleId}', handlers: ((${importName}.default ?? ${importName}.webhookHandlers ?? []) as WebhookHandlerRegistryEntry[]) }`,\n outputFileName: 'webhook-handlers.generated.ts',\n buildOutput: buildHandlersOutput,\n bootstrapRegistration: {\n entriesExportName: 'webhookHandlerEntries',\n registrationImports: [\n `import { registerWebhookHandlerEntries } from '@open-mercato/webhooks/modules/webhooks/lib/module-webhook-registry'`,\n ],\n buildCall: (name: string) => `registerWebhookHandlerEntries(${name})`,\n },\n}\n\nexport const generatorPlugins: GeneratorPlugin[] = [sourcesPlugin, handlersPlugin]\n"],
5
+ "mappings": "AAEA,SAAS,mBAAmB,EAAE,eAAe,eAAe,GAA8D;AACxH,SAAO;AAAA;AAAA,EAEP,gBAAgB,GAAG,aAAa;AAAA,IAAO,EAAE;AAAA;AAAA;AAAA,EAGzC,iBAAiB,KAAK,cAAc;AAAA,IAAO,EAAE;AAAA;AAE/C;AAEA,SAAS,oBAAoB,EAAE,eAAe,eAAe,GAA8D;AACzH,SAAO;AAAA;AAAA,EAEP,gBAAgB,GAAG,aAAa;AAAA,IAAO,EAAE;AAAA;AAAA;AAAA,EAGzC,iBAAiB,KAAK,cAAc;AAAA,IAAO,EAAE;AAAA;AAE/C;AAEA,MAAM,gBAAiC;AAAA,EACrC,IAAI;AAAA,EACJ,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,YAAY,CAAC,YAAoB,aAC/B,gBAAgB,QAAQ,iBAAiB,UAAU,eAAe,UAAU;AAAA,EAC9E,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,uBAAuB;AAAA,IACrB,mBAAmB;AAAA,IACnB,qBAAqB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,WAAW,CAAC,SAAiB,gCAAgC,IAAI;AAAA,EACnE;AACF;AAEA,MAAM,iBAAkC;AAAA,EACtC,IAAI;AAAA,EACJ,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,YAAY,CAAC,YAAoB,aAC/B,gBAAgB,QAAQ,kBAAkB,UAAU,eAAe,UAAU;AAAA,EAC/E,gBAAgB;AAAA,EAChB,aAAa;AAAA,EACb,uBAAuB;AAAA,IACrB,mBAAmB;AAAA,IACnB,qBAAqB;AAAA,MACnB;AAAA,IACF;AAAA,IACA,WAAW,CAAC,SAAiB,iCAAiC,IAAI;AAAA,EACpE;AACF;AAEO,MAAM,mBAAsC,CAAC,eAAe,cAAc;",
6
+ "names": []
7
+ }