@open-mercato/webhooks 0.6.7 → 0.6.8-develop.6874.1.982d6097d8
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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/webhooks/__integration__/TC-WEBHOOK-003.spec.js +15 -0
- package/dist/modules/webhooks/__integration__/TC-WEBHOOK-003.spec.js.map +2 -2
- package/dist/modules/webhooks/api/inbound/[endpointId]/route.js +152 -7
- package/dist/modules/webhooks/api/inbound/[endpointId]/route.js.map +3 -3
- package/dist/modules/webhooks/backend/webhooks/[id]/page.js +5 -4
- package/dist/modules/webhooks/backend/webhooks/[id]/page.js.map +2 -2
- package/dist/modules/webhooks/backend/webhooks/page.js +3 -2
- package/dist/modules/webhooks/backend/webhooks/page.js.map +2 -2
- package/dist/modules/webhooks/components/WebhookSecretPanel.js +3 -3
- package/dist/modules/webhooks/components/WebhookSecretPanel.js.map +2 -2
- package/dist/modules/webhooks/components/webhook-form-config.js +6 -6
- package/dist/modules/webhooks/components/webhook-form-config.js.map +2 -2
- package/dist/modules/webhooks/data/entities.js +101 -1
- package/dist/modules/webhooks/data/entities.js.map +2 -2
- package/dist/modules/webhooks/encryption.js +7 -0
- package/dist/modules/webhooks/encryption.js.map +2 -2
- package/dist/modules/webhooks/events.js +2 -0
- package/dist/modules/webhooks/events.js.map +2 -2
- package/dist/modules/webhooks/extension-points.js +15 -0
- package/dist/modules/webhooks/extension-points.js.map +7 -0
- package/dist/modules/webhooks/generators.js +57 -0
- package/dist/modules/webhooks/generators.js.map +7 -0
- package/dist/modules/webhooks/lib/inbound-dispatch.js +105 -0
- package/dist/modules/webhooks/lib/inbound-dispatch.js.map +7 -0
- package/dist/modules/webhooks/lib/inbound-registry.js +76 -0
- package/dist/modules/webhooks/lib/inbound-registry.js.map +7 -0
- package/dist/modules/webhooks/lib/module-webhook-registry.js +12 -0
- package/dist/modules/webhooks/lib/module-webhook-registry.js.map +7 -0
- package/dist/modules/webhooks/lib/queue.js +47 -0
- package/dist/modules/webhooks/lib/queue.js.map +2 -2
- package/dist/modules/webhooks/migrations/Migration20260617141327_webhooks.js +16 -0
- package/dist/modules/webhooks/migrations/Migration20260617141327_webhooks.js.map +7 -0
- package/dist/modules/webhooks/widgets/injection/integration-deliveries/widget.client.js +2 -1
- package/dist/modules/webhooks/widgets/injection/integration-deliveries/widget.client.js.map +2 -2
- package/dist/modules/webhooks/workers/inbound-dispatch.js +29 -0
- package/dist/modules/webhooks/workers/inbound-dispatch.js.map +7 -0
- package/generated/entities/inbound_endpoint_config_entity/index.ts +8 -0
- package/generated/entities/webhook_ingestion_entity/index.ts +16 -0
- package/generated/entities.ids.generated.ts +3 -1
- package/generated/entity-fields-registry.ts +28 -0
- package/package.json +12 -11
- package/src/modules/webhooks/__integration__/TC-WEBHOOK-003.spec.ts +16 -0
- package/src/modules/webhooks/api/inbound/[endpointId]/__tests__/route.test.ts +99 -1
- package/src/modules/webhooks/api/inbound/[endpointId]/__tests__/route.unify.test.ts +149 -0
- package/src/modules/webhooks/api/inbound/[endpointId]/route.ts +178 -7
- package/src/modules/webhooks/backend/webhooks/[id]/page.tsx +5 -4
- package/src/modules/webhooks/backend/webhooks/page.tsx +3 -2
- package/src/modules/webhooks/components/WebhookSecretPanel.tsx +3 -3
- package/src/modules/webhooks/components/webhook-form-config.tsx +6 -6
- package/src/modules/webhooks/data/entities.ts +84 -0
- package/src/modules/webhooks/encryption.ts +7 -0
- package/src/modules/webhooks/events.ts +2 -0
- package/src/modules/webhooks/extension-points.ts +12 -0
- package/src/modules/webhooks/generators.ts +57 -0
- package/src/modules/webhooks/i18n/de.json +1 -1
- package/src/modules/webhooks/i18n/en.json +1 -1
- package/src/modules/webhooks/i18n/es.json +1 -1
- package/src/modules/webhooks/i18n/ko.json +161 -0
- package/src/modules/webhooks/i18n/pl.json +1 -1
- package/src/modules/webhooks/lib/__tests__/inbound-dispatch.test.ts +186 -0
- package/src/modules/webhooks/lib/__tests__/inbound-registry.test.ts +102 -0
- package/src/modules/webhooks/lib/__tests__/module-webhook-registry.test.ts +53 -0
- package/src/modules/webhooks/lib/inbound-dispatch.ts +147 -0
- package/src/modules/webhooks/lib/inbound-registry.ts +92 -0
- package/src/modules/webhooks/lib/module-webhook-registry.ts +33 -0
- package/src/modules/webhooks/lib/queue.ts +60 -0
- package/src/modules/webhooks/migrations/.snapshot-open-mercato.json +907 -338
- package/src/modules/webhooks/migrations/Migration20260617141327_webhooks.ts +16 -0
- package/src/modules/webhooks/widgets/injection/integration-deliveries/widget.client.tsx +2 -1
- package/src/modules/webhooks/workers/inbound-dispatch.ts +31 -0
|
@@ -2,8 +2,11 @@ import { createModuleQueue } from "@open-mercato/queue";
|
|
|
2
2
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
3
3
|
const logger = createLogger("webhooks");
|
|
4
4
|
const queues = /* @__PURE__ */ new Map();
|
|
5
|
+
const inboundQueues = /* @__PURE__ */ new Map();
|
|
5
6
|
const LOCAL_WORKER_PROMISE_KEY = "__openMercatoWebhookLocalWorkerPromise__";
|
|
7
|
+
const LOCAL_INBOUND_WORKER_PROMISE_KEY = "__openMercatoWebhookLocalInboundWorkerPromise__";
|
|
6
8
|
const WEBHOOK_DELIVERIES_QUEUE = "webhook-deliveries";
|
|
9
|
+
const WEBHOOK_INBOUND_DISPATCH_QUEUE = "webhook-inbound-dispatch";
|
|
7
10
|
function getWebhookQueue(queueName = WEBHOOK_DELIVERIES_QUEUE) {
|
|
8
11
|
const existing = queues.get(queueName);
|
|
9
12
|
if (existing) return existing;
|
|
@@ -43,9 +46,53 @@ async function enqueueWebhookDelivery(job, delayMs) {
|
|
|
43
46
|
await ensureLocalWebhookQueueWorkerStarted();
|
|
44
47
|
return jobId;
|
|
45
48
|
}
|
|
49
|
+
function getInboundDispatchQueue(queueName = WEBHOOK_INBOUND_DISPATCH_QUEUE) {
|
|
50
|
+
const existing = inboundQueues.get(queueName);
|
|
51
|
+
if (existing) return existing;
|
|
52
|
+
const concurrency = Math.max(1, Number.parseInt(process.env.WEBHOOK_INBOUND_QUEUE_CONCURRENCY ?? "5", 10) || 5);
|
|
53
|
+
const created = createModuleQueue(queueName, { concurrency });
|
|
54
|
+
inboundQueues.set(queueName, created);
|
|
55
|
+
return created;
|
|
56
|
+
}
|
|
57
|
+
async function ensureLocalInboundQueueWorkerStarted() {
|
|
58
|
+
if (process.env.QUEUE_STRATEGY === "async") return;
|
|
59
|
+
const globalStore = globalThis;
|
|
60
|
+
if (globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY]) {
|
|
61
|
+
await globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY];
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY] = (async () => {
|
|
65
|
+
const queue = getInboundDispatchQueue();
|
|
66
|
+
await queue.process(async (job) => {
|
|
67
|
+
const [{ createRequestContainer }, { processInboundDispatchJob }] = await Promise.all([
|
|
68
|
+
import("@open-mercato/shared/lib/di/container"),
|
|
69
|
+
import("./inbound-dispatch.js")
|
|
70
|
+
]);
|
|
71
|
+
const container = await createRequestContainer();
|
|
72
|
+
const em = container.resolve("em").fork();
|
|
73
|
+
await processInboundDispatchJob(em, job.payload, {
|
|
74
|
+
resolve: (name) => container.resolve(name)
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
})().catch((error) => {
|
|
78
|
+
delete globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY];
|
|
79
|
+
logger.error("Failed to start local inbound dispatch worker", { err: error });
|
|
80
|
+
throw error;
|
|
81
|
+
});
|
|
82
|
+
await globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY];
|
|
83
|
+
}
|
|
84
|
+
async function enqueueInboundDispatch(job) {
|
|
85
|
+
const queue = getInboundDispatchQueue();
|
|
86
|
+
const jobId = await queue.enqueue(job);
|
|
87
|
+
await ensureLocalInboundQueueWorkerStarted();
|
|
88
|
+
return jobId;
|
|
89
|
+
}
|
|
46
90
|
export {
|
|
47
91
|
WEBHOOK_DELIVERIES_QUEUE,
|
|
92
|
+
WEBHOOK_INBOUND_DISPATCH_QUEUE,
|
|
93
|
+
enqueueInboundDispatch,
|
|
48
94
|
enqueueWebhookDelivery,
|
|
95
|
+
getInboundDispatchQueue,
|
|
49
96
|
getWebhookQueue
|
|
50
97
|
};
|
|
51
98
|
//# sourceMappingURL=queue.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/webhooks/lib/queue.ts"],
|
|
4
|
-
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { createModuleQueue, type Queue } from '@open-mercato/queue'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport type { WebhookDeliveryJob } from './delivery'\n\nconst logger = createLogger('webhooks')\n\nconst queues = new Map<string, Queue<WebhookDeliveryJob>>()\nconst LOCAL_WORKER_PROMISE_KEY = '__openMercatoWebhookLocalWorkerPromise__'\n\nexport const WEBHOOK_DELIVERIES_QUEUE = 'webhook-deliveries'\n\nexport function getWebhookQueue(queueName: string = WEBHOOK_DELIVERIES_QUEUE): Queue<WebhookDeliveryJob> {\n const existing = queues.get(queueName)\n if (existing) return existing\n\n const concurrency = Math.max(1, Number.parseInt(process.env.WEBHOOK_QUEUE_CONCURRENCY ?? '10', 10) || 10)\n const created = createModuleQueue<WebhookDeliveryJob>(queueName, { concurrency })\n\n queues.set(queueName, created)\n return created\n}\n\nasync function ensureLocalWebhookQueueWorkerStarted(): Promise<void> {\n if (process.env.QUEUE_STRATEGY === 'async') return\n\n const globalStore = globalThis as typeof globalThis & {\n [LOCAL_WORKER_PROMISE_KEY]?: Promise<void>\n }\n\n if (globalStore[LOCAL_WORKER_PROMISE_KEY]) {\n await globalStore[LOCAL_WORKER_PROMISE_KEY]\n return\n }\n\n globalStore[LOCAL_WORKER_PROMISE_KEY] = (async () => {\n const queue = getWebhookQueue()\n\n await queue.process(async (job) => {\n const [{ createRequestContainer }, { processWebhookDeliveryJob }] = await Promise.all([\n import('@open-mercato/shared/lib/di/container'),\n import('./delivery'),\n ])\n\n const container = await createRequestContainer()\n const em = (container.resolve('em') as EntityManager).fork()\n await processWebhookDeliveryJob(em, job.payload)\n })\n })().catch((error) => {\n delete globalStore[LOCAL_WORKER_PROMISE_KEY]\n logger.error('Failed to start local delivery worker', { err: error })\n throw error\n })\n\n await globalStore[LOCAL_WORKER_PROMISE_KEY]\n}\n\nexport async function enqueueWebhookDelivery(job: WebhookDeliveryJob, delayMs?: number): Promise<string> {\n const queue = getWebhookQueue()\n const jobId = await queue.enqueue(job, delayMs && delayMs > 0 ? { delayMs } : undefined)\n await ensureLocalWebhookQueueWorkerStarted()\n return jobId\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,yBAAqC;AAC9C,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { createModuleQueue, type Queue } from '@open-mercato/queue'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport type { WebhookDeliveryJob } from './delivery'\nimport type { InboundDispatchJob } from './inbound-dispatch'\n\nconst logger = createLogger('webhooks')\n\nconst queues = new Map<string, Queue<WebhookDeliveryJob>>()\nconst inboundQueues = new Map<string, Queue<InboundDispatchJob>>()\nconst LOCAL_WORKER_PROMISE_KEY = '__openMercatoWebhookLocalWorkerPromise__'\nconst LOCAL_INBOUND_WORKER_PROMISE_KEY = '__openMercatoWebhookLocalInboundWorkerPromise__'\n\nexport const WEBHOOK_DELIVERIES_QUEUE = 'webhook-deliveries'\nexport const WEBHOOK_INBOUND_DISPATCH_QUEUE = 'webhook-inbound-dispatch'\n\nexport function getWebhookQueue(queueName: string = WEBHOOK_DELIVERIES_QUEUE): Queue<WebhookDeliveryJob> {\n const existing = queues.get(queueName)\n if (existing) return existing\n\n const concurrency = Math.max(1, Number.parseInt(process.env.WEBHOOK_QUEUE_CONCURRENCY ?? '10', 10) || 10)\n const created = createModuleQueue<WebhookDeliveryJob>(queueName, { concurrency })\n\n queues.set(queueName, created)\n return created\n}\n\nasync function ensureLocalWebhookQueueWorkerStarted(): Promise<void> {\n if (process.env.QUEUE_STRATEGY === 'async') return\n\n const globalStore = globalThis as typeof globalThis & {\n [LOCAL_WORKER_PROMISE_KEY]?: Promise<void>\n }\n\n if (globalStore[LOCAL_WORKER_PROMISE_KEY]) {\n await globalStore[LOCAL_WORKER_PROMISE_KEY]\n return\n }\n\n globalStore[LOCAL_WORKER_PROMISE_KEY] = (async () => {\n const queue = getWebhookQueue()\n\n await queue.process(async (job) => {\n const [{ createRequestContainer }, { processWebhookDeliveryJob }] = await Promise.all([\n import('@open-mercato/shared/lib/di/container'),\n import('./delivery'),\n ])\n\n const container = await createRequestContainer()\n const em = (container.resolve('em') as EntityManager).fork()\n await processWebhookDeliveryJob(em, job.payload)\n })\n })().catch((error) => {\n delete globalStore[LOCAL_WORKER_PROMISE_KEY]\n logger.error('Failed to start local delivery worker', { err: error })\n throw error\n })\n\n await globalStore[LOCAL_WORKER_PROMISE_KEY]\n}\n\nexport async function enqueueWebhookDelivery(job: WebhookDeliveryJob, delayMs?: number): Promise<string> {\n const queue = getWebhookQueue()\n const jobId = await queue.enqueue(job, delayMs && delayMs > 0 ? { delayMs } : undefined)\n await ensureLocalWebhookQueueWorkerStarted()\n return jobId\n}\n\nexport function getInboundDispatchQueue(\n queueName: string = WEBHOOK_INBOUND_DISPATCH_QUEUE,\n): Queue<InboundDispatchJob> {\n const existing = inboundQueues.get(queueName)\n if (existing) return existing\n\n const concurrency = Math.max(1, Number.parseInt(process.env.WEBHOOK_INBOUND_QUEUE_CONCURRENCY ?? '5', 10) || 5)\n const created = createModuleQueue<InboundDispatchJob>(queueName, { concurrency })\n\n inboundQueues.set(queueName, created)\n return created\n}\n\nasync function ensureLocalInboundQueueWorkerStarted(): Promise<void> {\n if (process.env.QUEUE_STRATEGY === 'async') return\n\n const globalStore = globalThis as typeof globalThis & {\n [LOCAL_INBOUND_WORKER_PROMISE_KEY]?: Promise<void>\n }\n\n if (globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY]) {\n await globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY]\n return\n }\n\n globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY] = (async () => {\n const queue = getInboundDispatchQueue()\n\n await queue.process(async (job) => {\n const [{ createRequestContainer }, { processInboundDispatchJob }] = await Promise.all([\n import('@open-mercato/shared/lib/di/container'),\n import('./inbound-dispatch'),\n ])\n\n const container = await createRequestContainer()\n const em = (container.resolve('em') as EntityManager).fork()\n await processInboundDispatchJob(em, job.payload, {\n resolve: <T,>(name: string) => container.resolve(name) as T,\n })\n })\n })().catch((error) => {\n delete globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY]\n logger.error('Failed to start local inbound dispatch worker', { err: error })\n throw error\n })\n\n await globalStore[LOCAL_INBOUND_WORKER_PROMISE_KEY]\n}\n\nexport async function enqueueInboundDispatch(job: InboundDispatchJob): Promise<string> {\n const queue = getInboundDispatchQueue()\n const jobId = await queue.enqueue(job)\n await ensureLocalInboundQueueWorkerStarted()\n return jobId\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,yBAAqC;AAC9C,SAAS,oBAAoB;AAI7B,MAAM,SAAS,aAAa,UAAU;AAEtC,MAAM,SAAS,oBAAI,IAAuC;AAC1D,MAAM,gBAAgB,oBAAI,IAAuC;AACjE,MAAM,2BAA2B;AACjC,MAAM,mCAAmC;AAElC,MAAM,2BAA2B;AACjC,MAAM,iCAAiC;AAEvC,SAAS,gBAAgB,YAAoB,0BAAqD;AACvG,QAAM,WAAW,OAAO,IAAI,SAAS;AACrC,MAAI,SAAU,QAAO;AAErB,QAAM,cAAc,KAAK,IAAI,GAAG,OAAO,SAAS,QAAQ,IAAI,6BAA6B,MAAM,EAAE,KAAK,EAAE;AACxG,QAAM,UAAU,kBAAsC,WAAW,EAAE,YAAY,CA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AAI,WAAW,OAAO;AACpC,SAAO;AACT;AAEA,eAAe,uCAAsD;AACnE,MAAI,QAAQ,IAAI,mBAAmB,QAAS;AAE5C,QAAM,cAAc;AAIpB,MAAI,YAAY,gCAAgC,GAAG;AACjD,UAAM,YAAY,gCAAgC;AAClD;AAAA,EACF;AAEA,cAAY,gCAAgC,KAAK,YAAY;AAC3D,UAAM,QAAQ,wBAAwB;AAEtC,UAAM,MAAM,QAAQ,OAAO,QAAQ;AACjC,YAAM,CAAC,EAAE,uBAAuB,GAAG,EAAE,0BAA0B,CAAC,IAAI,MAAM,QAAQ,IAAI;AAAA,QACpF,OAAO,uCAAuC;AAAA,QAC9C,OAAO,oBAAoB;AAAA,MAC7B,CAAC;AAED,YAAM,YAAY,MAAM,uBAAuB;AAC/C,YAAM,KAAM,UAAU,QAAQ,IAAI,EAAoB,KAAK;AAC3D,YAAM,0BAA0B,IAAI,IAAI,SAAS;AAAA,QAC/C,SAAS,CAAK,SAAiB,UAAU,QAAQ,IAAI;AAAA,MACvD,CAAC;AAAA,IACH,CAAC;AAAA,EACH,GAAG,EAAE,MAAM,CAAC,UAAU;AACpB,WAAO,YAAY,gCAAgC;AACnD,WAAO,MAAM,iDAAiD,EAAE,KAAK,MAAM,CAAC;AAC5E,UAAM;AAAA,EACR,CAAC;AAED,QAAM,YAAY,gCAAgC;AACpD;AAEA,eAAsB,uBAAuB,KAA0C;AACrF,QAAM,QAAQ,wBAAwB;AACtC,QAAM,QAAQ,MAAM,MAAM,QAAQ,GAAG;AACrC,QAAM,qCAAqC;AAC3C,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations";
|
|
2
|
+
class Migration20260617141327_webhooks extends Migration {
|
|
3
|
+
up() {
|
|
4
|
+
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"));`);
|
|
5
|
+
this.addSql(`create index "webhook_inbound_configs_source_key_is_active_index" on "webhook_inbound_configs" ("source_key", "is_active");`);
|
|
6
|
+
this.addSql(`alter table "webhook_inbound_configs" add constraint "webhook_inbound_configs_source_scope_unique" unique ("source_key", "organization_id", "tenant_id");`);
|
|
7
|
+
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"));`);
|
|
8
|
+
this.addSql(`create index "webhook_ingestions_external_message_id_index" on "webhook_ingestions" ("external_message_id");`);
|
|
9
|
+
this.addSql(`create index "webhook_ingestions_organization_id_tenant_id_created_at_index" on "webhook_ingestions" ("organization_id", "tenant_id", "created_at");`);
|
|
10
|
+
this.addSql(`create index "webhook_ingestions_source_key_status_created_at_index" on "webhook_ingestions" ("source_key", "status", "created_at");`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
Migration20260617141327_webhooks
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=Migration20260617141327_webhooks.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/webhooks/migrations/Migration20260617141327_webhooks.ts"],
|
|
4
|
+
"sourcesContent": ["import { Migration } from '@mikro-orm/migrations';\n\nexport class Migration20260617141327_webhooks extends Migration {\n\n override up(): void | Promise<void> {\n 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\"));`);\n this.addSql(`create index \"webhook_inbound_configs_source_key_is_active_index\" on \"webhook_inbound_configs\" (\"source_key\", \"is_active\");`);\n this.addSql(`alter table \"webhook_inbound_configs\" add constraint \"webhook_inbound_configs_source_scope_unique\" unique (\"source_key\", \"organization_id\", \"tenant_id\");`);\n\n 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\"));`);\n this.addSql(`create index \"webhook_ingestions_external_message_id_index\" on \"webhook_ingestions\" (\"external_message_id\");`);\n this.addSql(`create index \"webhook_ingestions_organization_id_tenant_id_created_at_index\" on \"webhook_ingestions\" (\"organization_id\", \"tenant_id\", \"created_at\");`);\n this.addSql(`create index \"webhook_ingestions_source_key_status_created_at_index\" on \"webhook_ingestions\" (\"source_key\", \"status\", \"created_at\");`);\n }\n\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,yCAAyC,UAAU;AAAA,EAErD,KAA2B;AAClC,SAAK,OAAO,iVAAiV;AAC7V,SAAK,OAAO,6HAA6H;AACzI,SAAK,OAAO,2JAA2J;AAEvK,SAAK,OAAO,ujBAAujB;AACnkB,SAAK,OAAO,8GAA8G;AAC1H,SAAK,OAAO,sJAAsJ;AAClK,SAAK,OAAO,sIAAsI;AAAA,EACpJ;AAEF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
|
+
import { extensionPoints } from "@open-mercato/webhooks/modules/webhooks/extension-points";
|
|
4
5
|
import Link from "next/link";
|
|
5
6
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
7
|
import { DataTable } from "@open-mercato/ui/backend/DataTable";
|
|
@@ -166,7 +167,7 @@ function IntegrationDeliveriesWidget(_props) {
|
|
|
166
167
|
),
|
|
167
168
|
/* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => reload(), children: t("common.refresh", "Refresh") })
|
|
168
169
|
] }),
|
|
169
|
-
perspective: { tableId:
|
|
170
|
+
perspective: { tableId: extensionPoints.hosts.integrationDeliveriesTable.tableId },
|
|
170
171
|
pagination: {
|
|
171
172
|
page,
|
|
172
173
|
pageSize: 20,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/modules/webhooks/widgets/injection/integration-deliveries/widget.client.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport Link from 'next/link'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { JsonDisplay } from '@open-mercato/ui/backend/JsonDisplay'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { Badge } from '@open-mercato/ui/primitives/badge'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\ntype DeliveryRow = {\n id: string\n webhookId: string\n webhookName: string | null\n eventType: string\n messageId: string\n status: string\n responseStatus: number | null\n errorMessage: string | null\n attemptNumber: number\n maxAttempts: number\n durationMs: number | null\n targetUrl: string\n enqueuedAt: string\n lastAttemptAt: string | null\n deliveredAt: string | null\n createdAt: string\n}\n\ntype DeliveryResponse = {\n items: DeliveryRow[]\n total: number\n page: number\n pageSize: number\n totalPages: number\n}\n\ntype DeliveryDetail = DeliveryRow & {\n payload: Record<string, unknown>\n responseBody: string | null\n responseHeaders: Record<string, string> | null\n nextRetryAt: string | null\n updatedAt: string\n}\n\nconst statusVariantMap: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {\n delivered: 'default',\n pending: 'secondary',\n sending: 'outline',\n failed: 'destructive',\n expired: 'destructive',\n}\n\nexport default function IntegrationDeliveriesWidget(_props: InjectionWidgetComponentProps) {\n const t = useT()\n const [items, setItems] = React.useState<DeliveryRow[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [status, setStatus] = React.useState('')\n const [isLoading, setIsLoading] = React.useState(true)\n const [selectedRow, setSelectedRow] = React.useState<DeliveryRow | null>(null)\n const [selectedDelivery, setSelectedDelivery] = React.useState<DeliveryDetail | null>(null)\n const [selectedDeliveryLoading, setSelectedDeliveryLoading] = React.useState(false)\n const [refreshToken, setRefreshToken] = React.useState(0)\n\n const reload = React.useCallback(() => {\n setRefreshToken((current) => current + 1)\n }, [])\n\n React.useEffect(() => {\n let cancelled = false\n\n async function loadDeliveries() {\n setIsLoading(true)\n\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: '20',\n })\n if (status) params.set('status', status)\n\n const call = await apiCall<DeliveryResponse>(\n `/api/webhooks/deliveries?${params.toString()}`,\n undefined,\n {\n fallback: {\n items: [],\n total: 0,\n page,\n pageSize: 20,\n totalPages: 1,\n },\n },\n )\n\n if (!cancelled && call.ok && call.result) {\n setItems(call.result.items)\n setTotal(call.result.total)\n setTotalPages(call.result.totalPages)\n }\n } catch {\n if (!cancelled) {\n flash(t('webhooks.integrationDeliveries.loadError', 'Failed to load webhook deliveries.'), 'error')\n }\n } finally {\n if (!cancelled) setIsLoading(false)\n }\n }\n\n void loadDeliveries()\n\n return () => {\n cancelled = true\n }\n }, [page, refreshToken, status, t])\n\n const handleDeliveryOpen = React.useCallback(async (row: DeliveryRow) => {\n setSelectedRow(row)\n setSelectedDeliveryLoading(true)\n\n try {\n const call = await apiCall<DeliveryDetail>(\n `/api/webhooks/deliveries/${encodeURIComponent(row.id)}`,\n undefined,\n { fallback: null },\n )\n\n if (!call.ok || !call.result) {\n flash(t('webhooks.deliveries.loadError'), 'error')\n return\n }\n\n setSelectedDelivery(call.result)\n } catch {\n flash(t('webhooks.deliveries.loadError'), 'error')\n } finally {\n setSelectedDeliveryLoading(false)\n }\n }, [t])\n\n const columns = React.useMemo<ColumnDef<DeliveryRow>[]>(() => [\n {\n accessorKey: 'webhookName',\n header: t('webhooks.integrationDeliveries.columns.webhook', 'Webhook'),\n cell: ({ row }) => (\n <Link href={`/backend/webhooks/${row.original.webhookId}`} className=\"font-medium hover:underline\">\n {row.original.webhookName ?? row.original.webhookId}\n </Link>\n ),\n },\n {\n accessorKey: 'eventType',\n header: t('webhooks.deliveries.columns.event'),\n },\n {\n accessorKey: 'status',\n header: t('webhooks.deliveries.columns.status'),\n cell: ({ row }) => (\n <Badge variant={statusVariantMap[row.original.status] ?? 'secondary'}>\n {t(`webhooks.deliveries.status.${row.original.status}` as Parameters<typeof t>[0])}\n </Badge>\n ),\n },\n {\n accessorKey: 'responseStatus',\n header: t('webhooks.deliveries.columns.responseStatus'),\n cell: ({ row }) => row.original.responseStatus ?? '\u2014',\n },\n {\n accessorKey: 'attemptNumber',\n header: t('webhooks.deliveries.columns.attempts'),\n cell: ({ row }) => `${row.original.attemptNumber}/${row.original.maxAttempts}`,\n },\n {\n accessorKey: 'enqueuedAt',\n header: t('webhooks.deliveries.columns.enqueuedAt'),\n cell: ({ row }) => {\n try {\n return new Date(row.original.enqueuedAt).toLocaleString()\n } catch {\n return '\u2014'\n }\n },\n },\n ], [t])\n\n return (\n <div className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">\n {t(\n 'webhooks.integrationDeliveries.summary',\n 'Review delivery attempts across every configured webhook endpoint. Open a row to inspect the request and response payloads.',\n )}\n </p>\n\n <DataTable\n title={t('webhooks.deliveries.title')}\n columns={columns}\n data={items}\n onRowClick={(row) => { void handleDeliveryOpen(row) }}\n toolbar={(\n <div className=\"flex flex-wrap items-center gap-3\">\n <select\n className=\"h-10 rounded-md border border-input bg-background px-3 text-sm\"\n value={status}\n onChange={(event) => {\n setPage(1)\n setStatus(event.target.value)\n }}\n >\n <option value=\"\">{t('webhooks.integrationDeliveries.filters.allStatuses', 'All statuses')}</option>\n <option value=\"pending\">{t('webhooks.deliveries.status.pending')}</option>\n <option value=\"sending\">{t('webhooks.deliveries.status.sending')}</option>\n <option value=\"delivered\">{t('webhooks.deliveries.status.delivered')}</option>\n <option value=\"failed\">{t('webhooks.deliveries.status.failed')}</option>\n <option value=\"expired\">{t('webhooks.deliveries.status.expired')}</option>\n </select>\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => reload()}>\n {t('common.refresh', 'Refresh')}\n </Button>\n </div>\n )}\n perspective={{ tableId: 'webhooks.integration-deliveries' }}\n pagination={{\n page,\n pageSize: 20,\n total,\n totalPages,\n onPageChange: setPage,\n }}\n isLoading={isLoading}\n />\n\n {selectedRow || selectedDeliveryLoading ? (\n <div className=\"rounded-lg border bg-card p-4\">\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <h2 className=\"text-sm font-semibold\">{t('webhooks.deliveries.detailTitle')}</h2>\n {selectedRow ? (\n <Button asChild type=\"button\" variant=\"outline\" size=\"sm\">\n <Link href={`/backend/webhooks/${selectedRow.webhookId}`}>\n {t('webhooks.integrationDeliveries.actions.openWebhook', 'Open webhook')}\n </Link>\n </Button>\n ) : null}\n </div>\n {selectedDeliveryLoading || !selectedDelivery ? (\n <div className=\"mt-3 flex items-center gap-2 text-sm text-muted-foreground\">\n <Spinner className=\"h-4 w-4\" />\n <span>{t('common.loading')}</span>\n </div>\n ) : (\n <div className=\"mt-3 space-y-4 text-sm\">\n <div className=\"grid gap-2 md:grid-cols-2\">\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.integrationDeliveries.columns.webhook', 'Webhook')}:</span>\n <span className=\"ml-2\">{selectedRow?.webhookName ?? selectedDelivery.webhookId}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.status')}:</span>\n <span className=\"ml-2\">{selectedDelivery.status}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.responseStatus')}:</span>\n <span className=\"ml-2\">{selectedDelivery.responseStatus ?? '\u2014'}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.duration')}:</span>\n <span className=\"ml-2\">{selectedDelivery.durationMs != null ? `${selectedDelivery.durationMs}ms` : '\u2014'}</span>\n </div>\n <div className=\"md:col-span-2\">\n <span className=\"text-muted-foreground\">{t('webhooks.integrationDeliveries.errorMessage', 'Error message')}:</span>\n <span className=\"ml-2\">{selectedDelivery.errorMessage ?? '\u2014'}</span>\n </div>\n </div>\n\n <JsonDisplay\n data={selectedDelivery.payload}\n title={t('webhooks.deliveries.requestBody')}\n defaultExpanded\n maxInitialDepth={2}\n theme=\"dark\"\n className=\"p-4\"\n />\n\n <div className=\"rounded-lg border bg-muted/30 p-4\">\n <div className=\"mb-2 text-sm font-medium\">{t('webhooks.deliveries.responseBody')}</div>\n <pre className=\"overflow-auto whitespace-pre-wrap break-words text-xs\">\n {selectedDelivery.responseBody ?? '\u2014'}\n </pre>\n </div>\n\n <JsonDisplay\n data={selectedDelivery.responseHeaders ?? {}}\n title={t('webhooks.deliveries.responseHeaders')}\n defaultExpanded\n maxInitialDepth={1}\n theme=\"dark\"\n className=\"p-4\"\n />\n </div>\n )}\n </div>\n ) : null}\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { extensionPoints } from '@open-mercato/webhooks/modules/webhooks/extension-points'\nimport Link from 'next/link'\nimport type { ColumnDef } from '@tanstack/react-table'\nimport type { InjectionWidgetComponentProps } from '@open-mercato/shared/modules/widgets/injection'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { DataTable } from '@open-mercato/ui/backend/DataTable'\nimport { JsonDisplay } from '@open-mercato/ui/backend/JsonDisplay'\nimport { flash } from '@open-mercato/ui/backend/FlashMessages'\nimport { apiCall } from '@open-mercato/ui/backend/utils/apiCall'\nimport { Badge } from '@open-mercato/ui/primitives/badge'\nimport { Button } from '@open-mercato/ui/primitives/button'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\ntype DeliveryRow = {\n id: string\n webhookId: string\n webhookName: string | null\n eventType: string\n messageId: string\n status: string\n responseStatus: number | null\n errorMessage: string | null\n attemptNumber: number\n maxAttempts: number\n durationMs: number | null\n targetUrl: string\n enqueuedAt: string\n lastAttemptAt: string | null\n deliveredAt: string | null\n createdAt: string\n}\n\ntype DeliveryResponse = {\n items: DeliveryRow[]\n total: number\n page: number\n pageSize: number\n totalPages: number\n}\n\ntype DeliveryDetail = DeliveryRow & {\n payload: Record<string, unknown>\n responseBody: string | null\n responseHeaders: Record<string, string> | null\n nextRetryAt: string | null\n updatedAt: string\n}\n\nconst statusVariantMap: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {\n delivered: 'default',\n pending: 'secondary',\n sending: 'outline',\n failed: 'destructive',\n expired: 'destructive',\n}\n\nexport default function IntegrationDeliveriesWidget(_props: InjectionWidgetComponentProps) {\n const t = useT()\n const [items, setItems] = React.useState<DeliveryRow[]>([])\n const [page, setPage] = React.useState(1)\n const [total, setTotal] = React.useState(0)\n const [totalPages, setTotalPages] = React.useState(1)\n const [status, setStatus] = React.useState('')\n const [isLoading, setIsLoading] = React.useState(true)\n const [selectedRow, setSelectedRow] = React.useState<DeliveryRow | null>(null)\n const [selectedDelivery, setSelectedDelivery] = React.useState<DeliveryDetail | null>(null)\n const [selectedDeliveryLoading, setSelectedDeliveryLoading] = React.useState(false)\n const [refreshToken, setRefreshToken] = React.useState(0)\n\n const reload = React.useCallback(() => {\n setRefreshToken((current) => current + 1)\n }, [])\n\n React.useEffect(() => {\n let cancelled = false\n\n async function loadDeliveries() {\n setIsLoading(true)\n\n try {\n const params = new URLSearchParams({\n page: String(page),\n pageSize: '20',\n })\n if (status) params.set('status', status)\n\n const call = await apiCall<DeliveryResponse>(\n `/api/webhooks/deliveries?${params.toString()}`,\n undefined,\n {\n fallback: {\n items: [],\n total: 0,\n page,\n pageSize: 20,\n totalPages: 1,\n },\n },\n )\n\n if (!cancelled && call.ok && call.result) {\n setItems(call.result.items)\n setTotal(call.result.total)\n setTotalPages(call.result.totalPages)\n }\n } catch {\n if (!cancelled) {\n flash(t('webhooks.integrationDeliveries.loadError', 'Failed to load webhook deliveries.'), 'error')\n }\n } finally {\n if (!cancelled) setIsLoading(false)\n }\n }\n\n void loadDeliveries()\n\n return () => {\n cancelled = true\n }\n }, [page, refreshToken, status, t])\n\n const handleDeliveryOpen = React.useCallback(async (row: DeliveryRow) => {\n setSelectedRow(row)\n setSelectedDeliveryLoading(true)\n\n try {\n const call = await apiCall<DeliveryDetail>(\n `/api/webhooks/deliveries/${encodeURIComponent(row.id)}`,\n undefined,\n { fallback: null },\n )\n\n if (!call.ok || !call.result) {\n flash(t('webhooks.deliveries.loadError'), 'error')\n return\n }\n\n setSelectedDelivery(call.result)\n } catch {\n flash(t('webhooks.deliveries.loadError'), 'error')\n } finally {\n setSelectedDeliveryLoading(false)\n }\n }, [t])\n\n const columns = React.useMemo<ColumnDef<DeliveryRow>[]>(() => [\n {\n accessorKey: 'webhookName',\n header: t('webhooks.integrationDeliveries.columns.webhook', 'Webhook'),\n cell: ({ row }) => (\n <Link href={`/backend/webhooks/${row.original.webhookId}`} className=\"font-medium hover:underline\">\n {row.original.webhookName ?? row.original.webhookId}\n </Link>\n ),\n },\n {\n accessorKey: 'eventType',\n header: t('webhooks.deliveries.columns.event'),\n },\n {\n accessorKey: 'status',\n header: t('webhooks.deliveries.columns.status'),\n cell: ({ row }) => (\n <Badge variant={statusVariantMap[row.original.status] ?? 'secondary'}>\n {t(`webhooks.deliveries.status.${row.original.status}` as Parameters<typeof t>[0])}\n </Badge>\n ),\n },\n {\n accessorKey: 'responseStatus',\n header: t('webhooks.deliveries.columns.responseStatus'),\n cell: ({ row }) => row.original.responseStatus ?? '\u2014',\n },\n {\n accessorKey: 'attemptNumber',\n header: t('webhooks.deliveries.columns.attempts'),\n cell: ({ row }) => `${row.original.attemptNumber}/${row.original.maxAttempts}`,\n },\n {\n accessorKey: 'enqueuedAt',\n header: t('webhooks.deliveries.columns.enqueuedAt'),\n cell: ({ row }) => {\n try {\n return new Date(row.original.enqueuedAt).toLocaleString()\n } catch {\n return '\u2014'\n }\n },\n },\n ], [t])\n\n return (\n <div className=\"space-y-4\">\n <p className=\"text-sm text-muted-foreground\">\n {t(\n 'webhooks.integrationDeliveries.summary',\n 'Review delivery attempts across every configured webhook endpoint. Open a row to inspect the request and response payloads.',\n )}\n </p>\n\n <DataTable\n title={t('webhooks.deliveries.title')}\n columns={columns}\n data={items}\n onRowClick={(row) => { void handleDeliveryOpen(row) }}\n toolbar={(\n <div className=\"flex flex-wrap items-center gap-3\">\n <select\n className=\"h-10 rounded-md border border-input bg-background px-3 text-sm\"\n value={status}\n onChange={(event) => {\n setPage(1)\n setStatus(event.target.value)\n }}\n >\n <option value=\"\">{t('webhooks.integrationDeliveries.filters.allStatuses', 'All statuses')}</option>\n <option value=\"pending\">{t('webhooks.deliveries.status.pending')}</option>\n <option value=\"sending\">{t('webhooks.deliveries.status.sending')}</option>\n <option value=\"delivered\">{t('webhooks.deliveries.status.delivered')}</option>\n <option value=\"failed\">{t('webhooks.deliveries.status.failed')}</option>\n <option value=\"expired\">{t('webhooks.deliveries.status.expired')}</option>\n </select>\n <Button type=\"button\" variant=\"outline\" size=\"sm\" onClick={() => reload()}>\n {t('common.refresh', 'Refresh')}\n </Button>\n </div>\n )}\n perspective={{ tableId: extensionPoints.hosts.integrationDeliveriesTable.tableId }}\n pagination={{\n page,\n pageSize: 20,\n total,\n totalPages,\n onPageChange: setPage,\n }}\n isLoading={isLoading}\n />\n\n {selectedRow || selectedDeliveryLoading ? (\n <div className=\"rounded-lg border bg-card p-4\">\n <div className=\"flex flex-wrap items-center justify-between gap-3\">\n <h2 className=\"text-sm font-semibold\">{t('webhooks.deliveries.detailTitle')}</h2>\n {selectedRow ? (\n <Button asChild type=\"button\" variant=\"outline\" size=\"sm\">\n <Link href={`/backend/webhooks/${selectedRow.webhookId}`}>\n {t('webhooks.integrationDeliveries.actions.openWebhook', 'Open webhook')}\n </Link>\n </Button>\n ) : null}\n </div>\n {selectedDeliveryLoading || !selectedDelivery ? (\n <div className=\"mt-3 flex items-center gap-2 text-sm text-muted-foreground\">\n <Spinner className=\"h-4 w-4\" />\n <span>{t('common.loading')}</span>\n </div>\n ) : (\n <div className=\"mt-3 space-y-4 text-sm\">\n <div className=\"grid gap-2 md:grid-cols-2\">\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.integrationDeliveries.columns.webhook', 'Webhook')}:</span>\n <span className=\"ml-2\">{selectedRow?.webhookName ?? selectedDelivery.webhookId}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.status')}:</span>\n <span className=\"ml-2\">{selectedDelivery.status}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.responseStatus')}:</span>\n <span className=\"ml-2\">{selectedDelivery.responseStatus ?? '\u2014'}</span>\n </div>\n <div>\n <span className=\"text-muted-foreground\">{t('webhooks.deliveries.columns.duration')}:</span>\n <span className=\"ml-2\">{selectedDelivery.durationMs != null ? `${selectedDelivery.durationMs}ms` : '\u2014'}</span>\n </div>\n <div className=\"md:col-span-2\">\n <span className=\"text-muted-foreground\">{t('webhooks.integrationDeliveries.errorMessage', 'Error message')}:</span>\n <span className=\"ml-2\">{selectedDelivery.errorMessage ?? '\u2014'}</span>\n </div>\n </div>\n\n <JsonDisplay\n data={selectedDelivery.payload}\n title={t('webhooks.deliveries.requestBody')}\n defaultExpanded\n maxInitialDepth={2}\n theme=\"dark\"\n className=\"p-4\"\n />\n\n <div className=\"rounded-lg border bg-muted/30 p-4\">\n <div className=\"mb-2 text-sm font-medium\">{t('webhooks.deliveries.responseBody')}</div>\n <pre className=\"overflow-auto whitespace-pre-wrap break-words text-xs\">\n {selectedDelivery.responseBody ?? '\u2014'}\n </pre>\n </div>\n\n <JsonDisplay\n data={selectedDelivery.responseHeaders ?? {}}\n title={t('webhooks.deliveries.responseHeaders')}\n defaultExpanded\n maxInitialDepth={1}\n theme=\"dark\"\n className=\"p-4\"\n />\n </div>\n )}\n </div>\n ) : null}\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAyJQ,cAyDI,YAzDJ;AAvJR,YAAY,WAAW;AACvB,SAAS,uBAAuB;AAChC,OAAO,UAAU;AAGjB,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,aAAa;AACtB,SAAS,eAAe;AACxB,SAAS,aAAa;AACtB,SAAS,cAAc;AACvB,SAAS,eAAe;AAqCxB,MAAM,mBAAwF;AAAA,EAC5F,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AACX;AAEe,SAAR,4BAA6C,QAAuC;AACzF,QAAM,IAAI,KAAK;AACf,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAwB,CAAC,CAAC;AAC1D,QAAM,CAAC,MAAM,OAAO,IAAI,MAAM,SAAS,CAAC;AACxC,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,CAAC;AAC1C,QAAM,CAAC,YAAY,aAAa,IAAI,MAAM,SAAS,CAAC;AACpD,QAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,S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
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
2
|
+
import { processInboundDispatchJob } from "../lib/inbound-dispatch.js";
|
|
3
|
+
const logger = createLogger("webhooks");
|
|
4
|
+
const metadata = {
|
|
5
|
+
queue: "webhook-inbound-dispatch",
|
|
6
|
+
id: "webhooks:inbound-dispatch-worker",
|
|
7
|
+
concurrency: 5
|
|
8
|
+
};
|
|
9
|
+
async function handler(job, ctx) {
|
|
10
|
+
const em = ctx.resolve("em").fork();
|
|
11
|
+
try {
|
|
12
|
+
await processInboundDispatchJob(em, job.data, {
|
|
13
|
+
resolve: (name) => ctx.resolve(name)
|
|
14
|
+
});
|
|
15
|
+
} catch (error) {
|
|
16
|
+
logger.error("Inbound dispatch job processing failed", {
|
|
17
|
+
ingestionId: job.data.ingestionId,
|
|
18
|
+
sourceKey: job.data.sourceKey,
|
|
19
|
+
tenantId: job.data.tenantId,
|
|
20
|
+
err: error
|
|
21
|
+
});
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
handler as default,
|
|
27
|
+
metadata
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=inbound-dispatch.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/webhooks/workers/inbound-dispatch.ts"],
|
|
4
|
+
"sourcesContent": ["import type { EntityManager } from '@mikro-orm/postgresql'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { processInboundDispatchJob, type InboundDispatchJob } from '../lib/inbound-dispatch'\n\nconst logger = createLogger('webhooks')\n\nexport const metadata = {\n queue: 'webhook-inbound-dispatch',\n id: 'webhooks:inbound-dispatch-worker',\n concurrency: 5,\n}\n\nexport default async function handler(\n job: { data: InboundDispatchJob },\n ctx: { resolve: <T = unknown>(name: string) => T },\n) {\n const em = (ctx.resolve('em') as EntityManager).fork()\n try {\n await processInboundDispatchJob(em, job.data, {\n resolve: <T,>(name: string) => ctx.resolve(name) as T,\n })\n } catch (error) {\n logger.error('Inbound dispatch job processing failed', {\n ingestionId: job.data.ingestionId,\n sourceKey: job.data.sourceKey,\n tenantId: job.data.tenantId,\n err: error,\n })\n throw error\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,oBAAoB;AAC7B,SAAS,iCAA0D;AAEnE,MAAM,SAAS,aAAa,UAAU;AAE/B,MAAM,WAAW;AAAA,EACtB,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,aAAa;AACf;AAEA,eAAO,QACL,KACA,KACA;AACA,QAAM,KAAM,IAAI,QAAQ,IAAI,EAAoB,KAAK;AACrD,MAAI;AACF,UAAM,0BAA0B,IAAI,IAAI,MAAM;AAAA,MAC5C,SAAS,CAAK,SAAiB,IAAI,QAAQ,IAAI;AAAA,IACjD,CAAC;AAAA,EACH,SAAS,OAAO;AACd,WAAO,MAAM,0CAA0C;AAAA,MACrD,aAAa,IAAI,KAAK;AAAA,MACtB,WAAW,IAAI,KAAK;AAAA,MACpB,UAAU,IAAI,KAAK;AAAA,MACnB,KAAK;AAAA,IACP,CAAC;AACD,UAAM;AAAA,EACR;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const id = "id";
|
|
2
|
+
export const source_key = "source_key";
|
|
3
|
+
export const is_active = "is_active";
|
|
4
|
+
export const integration_id = "integration_id";
|
|
5
|
+
export const organization_id = "organization_id";
|
|
6
|
+
export const tenant_id = "tenant_id";
|
|
7
|
+
export const created_at = "created_at";
|
|
8
|
+
export const updated_at = "updated_at";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const id = "id";
|
|
2
|
+
export const source_key = "source_key";
|
|
3
|
+
export const event_type = "event_type";
|
|
4
|
+
export const external_message_id = "external_message_id";
|
|
5
|
+
export const payload = "payload";
|
|
6
|
+
export const headers = "headers";
|
|
7
|
+
export const status = "status";
|
|
8
|
+
export const error_message = "error_message";
|
|
9
|
+
export const processed_at = "processed_at";
|
|
10
|
+
export const handler_count = "handler_count";
|
|
11
|
+
export const handler_results = "handler_results";
|
|
12
|
+
export const duration_ms = "duration_ms";
|
|
13
|
+
export const organization_id = "organization_id";
|
|
14
|
+
export const tenant_id = "tenant_id";
|
|
15
|
+
export const created_at = "created_at";
|
|
16
|
+
export const updated_at = "updated_at";
|
|
@@ -5,7 +5,9 @@ export const M = {
|
|
|
5
5
|
"webhooks": {
|
|
6
6
|
"webhook_entity": "webhooks:webhook_entity",
|
|
7
7
|
"webhook_delivery_entity": "webhooks:webhook_delivery_entity",
|
|
8
|
-
"webhook_inbound_receipt_entity": "webhooks:webhook_inbound_receipt_entity"
|
|
8
|
+
"webhook_inbound_receipt_entity": "webhooks:webhook_inbound_receipt_entity",
|
|
9
|
+
"webhook_ingestion_entity": "webhooks:webhook_ingestion_entity",
|
|
10
|
+
"inbound_endpoint_config_entity": "webhooks:inbound_endpoint_config_entity"
|
|
9
11
|
}
|
|
10
12
|
} as const;
|
|
11
13
|
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// AUTO-GENERATED by mercato generate entity-ids
|
|
2
2
|
// Static registry for entity fields - eliminates dynamic imports for Turbopack compatibility
|
|
3
3
|
export const entityFieldsRegistry: Record<string, Record<string, string>> = {
|
|
4
|
+
"inbound_endpoint_config_entity": {
|
|
5
|
+
"id": "id",
|
|
6
|
+
"source_key": "source_key",
|
|
7
|
+
"is_active": "is_active",
|
|
8
|
+
"integration_id": "integration_id",
|
|
9
|
+
"organization_id": "organization_id",
|
|
10
|
+
"tenant_id": "tenant_id",
|
|
11
|
+
"created_at": "created_at",
|
|
12
|
+
"updated_at": "updated_at"
|
|
13
|
+
},
|
|
4
14
|
"webhook_delivery_entity": {
|
|
5
15
|
"id": "id",
|
|
6
16
|
"webhook_id": "webhook_id",
|
|
@@ -62,6 +72,24 @@ export const entityFieldsRegistry: Record<string, Record<string, string>> = {
|
|
|
62
72
|
"organization_id": "organization_id",
|
|
63
73
|
"tenant_id": "tenant_id",
|
|
64
74
|
"created_at": "created_at"
|
|
75
|
+
},
|
|
76
|
+
"webhook_ingestion_entity": {
|
|
77
|
+
"id": "id",
|
|
78
|
+
"source_key": "source_key",
|
|
79
|
+
"event_type": "event_type",
|
|
80
|
+
"external_message_id": "external_message_id",
|
|
81
|
+
"payload": "payload",
|
|
82
|
+
"headers": "headers",
|
|
83
|
+
"status": "status",
|
|
84
|
+
"error_message": "error_message",
|
|
85
|
+
"processed_at": "processed_at",
|
|
86
|
+
"handler_count": "handler_count",
|
|
87
|
+
"handler_results": "handler_results",
|
|
88
|
+
"duration_ms": "duration_ms",
|
|
89
|
+
"organization_id": "organization_id",
|
|
90
|
+
"tenant_id": "tenant_id",
|
|
91
|
+
"created_at": "created_at",
|
|
92
|
+
"updated_at": "updated_at"
|
|
65
93
|
}
|
|
66
94
|
};
|
|
67
95
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/webhooks",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8-develop.6874.1.982d6097d8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Webhooks module for Open Mercato — Standard Webhooks compliant outbound/inbound delivery",
|
|
6
6
|
"type": "module",
|
|
@@ -70,28 +70,28 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@open-mercato/core": "0.6.
|
|
74
|
-
"@open-mercato/queue": "0.6.
|
|
75
|
-
"@open-mercato/ui": "0.6.
|
|
76
|
-
"svix": "^1.
|
|
73
|
+
"@open-mercato/core": "0.6.8-develop.6874.1.982d6097d8",
|
|
74
|
+
"@open-mercato/queue": "0.6.8-develop.6874.1.982d6097d8",
|
|
75
|
+
"@open-mercato/ui": "0.6.8-develop.6874.1.982d6097d8",
|
|
76
|
+
"svix": "^1.99.1"
|
|
77
77
|
},
|
|
78
78
|
"peerDependencies": {
|
|
79
79
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
80
|
-
"@open-mercato/shared": "0.6.
|
|
80
|
+
"@open-mercato/shared": "0.6.8-develop.6874.1.982d6097d8",
|
|
81
81
|
"react": "^19.0.0",
|
|
82
82
|
"react-dom": "^19.0.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@open-mercato/shared": "0.6.
|
|
85
|
+
"@open-mercato/shared": "0.6.8-develop.6874.1.982d6097d8",
|
|
86
86
|
"@types/jest": "^30.0.0",
|
|
87
87
|
"@types/react": "^19.2.17",
|
|
88
88
|
"@types/react-dom": "^19.2.3",
|
|
89
89
|
"esbuild": "^0.28.1",
|
|
90
90
|
"glob": "^13.0.6",
|
|
91
91
|
"jest": "^30.4.2",
|
|
92
|
-
"react": "19.2.
|
|
93
|
-
"react-dom": "19.2.
|
|
94
|
-
"ts-jest": "^29.4.
|
|
92
|
+
"react": "19.2.8",
|
|
93
|
+
"react-dom": "19.2.8",
|
|
94
|
+
"ts-jest": "^29.4.12",
|
|
95
95
|
"typescript": "7.0.2"
|
|
96
96
|
},
|
|
97
97
|
"publishConfig": {
|
|
@@ -101,5 +101,6 @@
|
|
|
101
101
|
"type": "git",
|
|
102
102
|
"url": "https://github.com/open-mercato/open-mercato",
|
|
103
103
|
"directory": "packages/webhooks"
|
|
104
|
-
}
|
|
104
|
+
},
|
|
105
|
+
"stableVersion": "0.6.7"
|
|
105
106
|
}
|
|
@@ -83,6 +83,22 @@ test.describe('TC-WEBHOOK-003: Inbound webhook receiver', () => {
|
|
|
83
83
|
expect(replayWithoutMessageIdDuplicateResponse.status()).toBe(200);
|
|
84
84
|
await expect(replayWithoutMessageIdDuplicateResponse.json()).resolves.toEqual({ ok: true, duplicate: true });
|
|
85
85
|
|
|
86
|
+
const staleTimestampResponse = await request.fetch(`${BASE_URL}/api/webhooks/inbound/mock_inbound`, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: {
|
|
89
|
+
'content-type': 'application/json',
|
|
90
|
+
'x-mock-webhook-signature': validSignature,
|
|
91
|
+
'webhook-id': `stale-${Date.now()}`,
|
|
92
|
+
'webhook-timestamp': String(Math.floor(Date.now() / 1000) - 10 * 60),
|
|
93
|
+
'webhook-signature': 'v1,mock',
|
|
94
|
+
},
|
|
95
|
+
data: rawBody,
|
|
96
|
+
});
|
|
97
|
+
expect(staleTimestampResponse.status()).toBe(400);
|
|
98
|
+
await expect(staleTimestampResponse.json()).resolves.toEqual({
|
|
99
|
+
error: 'Webhook timestamp is outside the allowed replay window',
|
|
100
|
+
});
|
|
101
|
+
|
|
86
102
|
const invalidSignatureResponse = await request.fetch(`${BASE_URL}/api/webhooks/inbound/mock_inbound`, {
|
|
87
103
|
method: 'POST',
|
|
88
104
|
headers: {
|
|
@@ -62,12 +62,13 @@ import { POST, buildInboundRateLimitKey, resolveInboundReceiptMessageId } from '
|
|
|
62
62
|
|
|
63
63
|
const routeContext = { params: Promise.resolve({ endpointId: 'mock_inbound' }) }
|
|
64
64
|
|
|
65
|
-
function createRequest(body: string = '{"ok":true}') {
|
|
65
|
+
function createRequest(body: string = '{"ok":true}', headers: Record<string, string> = {}) {
|
|
66
66
|
return new Request('http://localhost/api/webhooks/inbound/mock_inbound', {
|
|
67
67
|
method: 'POST',
|
|
68
68
|
headers: {
|
|
69
69
|
'content-type': 'application/json',
|
|
70
70
|
'webhook-id': 'msg-1',
|
|
71
|
+
...headers,
|
|
71
72
|
},
|
|
72
73
|
body,
|
|
73
74
|
})
|
|
@@ -95,6 +96,103 @@ describe('POST', () => {
|
|
|
95
96
|
translate: (_key: string, fallback?: string) => fallback ?? '',
|
|
96
97
|
})
|
|
97
98
|
mockIsWebhookIntegrationEnabled.mockResolvedValue(true)
|
|
99
|
+
mockGetWebhookEndpointAdapter.mockReturnValue(createAdapter(
|
|
100
|
+
{
|
|
101
|
+
eventType: 'mock.inbound.received',
|
|
102
|
+
payload: { ok: true },
|
|
103
|
+
},
|
|
104
|
+
{ allowUnscopedInbound: true },
|
|
105
|
+
))
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('rejects stale Standard Webhooks timestamps before persisting a fresh message id', async () => {
|
|
109
|
+
const staleTimestamp = String(Math.floor(Date.now() / 1000) - 10 * 60)
|
|
110
|
+
|
|
111
|
+
const response = await POST(createRequest('{"ok":true}', {
|
|
112
|
+
'webhook-id': 'fresh-message-id',
|
|
113
|
+
'webhook-timestamp': staleTimestamp,
|
|
114
|
+
'webhook-signature': 'v1,mock',
|
|
115
|
+
}), routeContext)
|
|
116
|
+
|
|
117
|
+
expect(response.status).toBe(400)
|
|
118
|
+
await expect(response.json()).resolves.toEqual({ error: 'Webhook timestamp is outside the allowed replay window' })
|
|
119
|
+
expect(mockRouteEm.persist).not.toHaveBeenCalled()
|
|
120
|
+
expect(mockRouteEm.flush).not.toHaveBeenCalled()
|
|
121
|
+
expect(mockEmitWebhooksEvent).not.toHaveBeenCalled()
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('rejects when any present Standard or Svix timestamp header is stale', async () => {
|
|
125
|
+
const now = Math.floor(Date.now() / 1000)
|
|
126
|
+
|
|
127
|
+
const response = await POST(createRequest('{"ok":true}', {
|
|
128
|
+
'webhook-id': 'fresh-message-id',
|
|
129
|
+
'webhook-timestamp': String(now),
|
|
130
|
+
'webhook-signature': 'v1,mock',
|
|
131
|
+
'svix-timestamp': String(now - 10 * 60),
|
|
132
|
+
}), routeContext)
|
|
133
|
+
|
|
134
|
+
expect(response.status).toBe(400)
|
|
135
|
+
await expect(response.json()).resolves.toEqual({ error: 'Webhook timestamp is outside the allowed replay window' })
|
|
136
|
+
expect(mockRouteEm.persist).not.toHaveBeenCalled()
|
|
137
|
+
expect(mockRouteEm.flush).not.toHaveBeenCalled()
|
|
138
|
+
expect(mockEmitWebhooksEvent).not.toHaveBeenCalled()
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it.each(['', 'not-a-number'])('rejects malformed Standard Webhooks timestamps: %j', async (timestamp) => {
|
|
142
|
+
const response = await POST(createRequest('{"ok":true}', {
|
|
143
|
+
'webhook-id': 'fresh-message-id',
|
|
144
|
+
'webhook-timestamp': timestamp,
|
|
145
|
+
'webhook-signature': 'v1,mock',
|
|
146
|
+
}), routeContext)
|
|
147
|
+
|
|
148
|
+
expect(response.status).toBe(400)
|
|
149
|
+
await expect(response.json()).resolves.toEqual({ error: 'Webhook timestamp is outside the allowed replay window' })
|
|
150
|
+
expect(mockRouteEm.persist).not.toHaveBeenCalled()
|
|
151
|
+
expect(mockRouteEm.flush).not.toHaveBeenCalled()
|
|
152
|
+
expect(mockEmitWebhooksEvent).not.toHaveBeenCalled()
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('accepts fresh Standard Webhooks timestamps', async () => {
|
|
156
|
+
mockGetWebhookEndpointAdapter.mockReturnValue(createAdapter(
|
|
157
|
+
{
|
|
158
|
+
eventType: 'mock.inbound.received',
|
|
159
|
+
payload: { ok: true },
|
|
160
|
+
},
|
|
161
|
+
{ allowUnscopedInbound: true },
|
|
162
|
+
))
|
|
163
|
+
const freshTimestamp = String(Math.floor(Date.now() / 1000))
|
|
164
|
+
|
|
165
|
+
const response = await POST(createRequest('{"ok":true}', {
|
|
166
|
+
'webhook-id': 'fresh-message-id',
|
|
167
|
+
'webhook-timestamp': freshTimestamp,
|
|
168
|
+
'webhook-signature': 'v1,mock',
|
|
169
|
+
}), routeContext)
|
|
170
|
+
|
|
171
|
+
expect(response.status).toBe(200)
|
|
172
|
+
await expect(response.json()).resolves.toEqual({ ok: true })
|
|
173
|
+
expect(mockRouteEm.persist).toHaveBeenCalledTimes(1)
|
|
174
|
+
expect(mockRouteEm.flush).toHaveBeenCalledTimes(1)
|
|
175
|
+
expect(mockEmitWebhooksEvent).toHaveBeenCalledTimes(1)
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('rejects an oversized declared body before adapter verification', async () => {
|
|
179
|
+
const adapter = createAdapter({
|
|
180
|
+
eventType: 'mock.inbound.received',
|
|
181
|
+
payload: { ok: true },
|
|
182
|
+
tenantId: 'tenant-1',
|
|
183
|
+
organizationId: 'org-1',
|
|
184
|
+
})
|
|
185
|
+
mockGetWebhookEndpointAdapter.mockReturnValue(adapter)
|
|
186
|
+
const request = new Request('http://localhost/api/webhooks/inbound/mock_inbound', {
|
|
187
|
+
method: 'POST',
|
|
188
|
+
headers: { 'content-length': String(1024 * 1024 + 1) },
|
|
189
|
+
body: '{}',
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const response = await POST(request, routeContext)
|
|
193
|
+
|
|
194
|
+
expect(response.status).toBe(413)
|
|
195
|
+
expect(adapter.verifyWebhook).not.toHaveBeenCalled()
|
|
98
196
|
})
|
|
99
197
|
|
|
100
198
|
it('rejects verified inbound webhooks without tenant and organization scope before side effects', async () => {
|