@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
@@ -0,0 +1,16 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+
3
+ export class Migration20260617141327_webhooks extends Migration {
4
+
5
+ override up(): void | Promise<void> {
6
+ this.addSql(`create table "webhook_inbound_configs" ("id" uuid not null default gen_random_uuid(), "source_key" text not null, "is_active" boolean not null default true, "integration_id" text null, "organization_id" uuid not null, "tenant_id" uuid not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, primary key ("id"));`);
7
+ this.addSql(`create index "webhook_inbound_configs_source_key_is_active_index" on "webhook_inbound_configs" ("source_key", "is_active");`);
8
+ this.addSql(`alter table "webhook_inbound_configs" add constraint "webhook_inbound_configs_source_scope_unique" unique ("source_key", "organization_id", "tenant_id");`);
9
+
10
+ this.addSql(`create table "webhook_ingestions" ("id" uuid not null default gen_random_uuid(), "source_key" text not null, "event_type" text not null, "external_message_id" text null, "payload" jsonb not null, "headers" jsonb null, "status" text not null default 'received', "error_message" text null, "processed_at" timestamptz null, "handler_count" int not null default 0, "handler_results" jsonb null, "duration_ms" int null, "organization_id" uuid not null, "tenant_id" uuid not null, "created_at" timestamptz not null, "updated_at" timestamptz not null, primary key ("id"));`);
11
+ this.addSql(`create index "webhook_ingestions_external_message_id_index" on "webhook_ingestions" ("external_message_id");`);
12
+ this.addSql(`create index "webhook_ingestions_organization_id_tenant_id_created_at_index" on "webhook_ingestions" ("organization_id", "tenant_id", "created_at");`);
13
+ this.addSql(`create index "webhook_ingestions_source_key_status_created_at_index" on "webhook_ingestions" ("source_key", "status", "created_at");`);
14
+ }
15
+
16
+ }
@@ -0,0 +1,31 @@
1
+ import type { EntityManager } from '@mikro-orm/postgresql'
2
+ import { createLogger } from '@open-mercato/shared/lib/logger'
3
+ import { processInboundDispatchJob, type InboundDispatchJob } from '../lib/inbound-dispatch'
4
+
5
+ const logger = createLogger('webhooks')
6
+
7
+ export const metadata = {
8
+ queue: 'webhook-inbound-dispatch',
9
+ id: 'webhooks:inbound-dispatch-worker',
10
+ concurrency: 5,
11
+ }
12
+
13
+ export default async function handler(
14
+ job: { data: InboundDispatchJob },
15
+ ctx: { resolve: <T = unknown>(name: string) => T },
16
+ ) {
17
+ const em = (ctx.resolve('em') as EntityManager).fork()
18
+ try {
19
+ await processInboundDispatchJob(em, job.data, {
20
+ resolve: <T,>(name: string) => ctx.resolve(name) as T,
21
+ })
22
+ } catch (error) {
23
+ logger.error('Inbound dispatch job processing failed', {
24
+ ingestionId: job.data.ingestionId,
25
+ sourceKey: job.data.sourceKey,
26
+ tenantId: job.data.tenantId,
27
+ err: error,
28
+ })
29
+ throw error
30
+ }
31
+ }