@open-mercato/webhooks 0.10.1-develop.7811.1.66050c1838 → 0.10.1-develop.7814.1.406b1b1de7
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-014.spec.js +77 -0
- package/dist/modules/webhooks/__integration__/TC-WEBHOOK-014.spec.js.map +7 -0
- package/dist/modules/webhooks/data/entities.js +5 -1
- package/dist/modules/webhooks/data/entities.js.map +2 -2
- package/dist/modules/webhooks/migrations/Migration20261027193000_receipt_scope.js +11 -0
- package/dist/modules/webhooks/migrations/Migration20261027193000_receipt_scope.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/webhooks/__integration__/TC-WEBHOOK-014.spec.ts +82 -0
- package/src/modules/webhooks/api/inbound/[endpointId]/__tests__/route.unify.test.ts +28 -2
- package/src/modules/webhooks/data/__tests__/receipt-scope.test.ts +34 -0
- package/src/modules/webhooks/data/entities.ts +5 -1
- package/src/modules/webhooks/migrations/.snapshot-open-mercato.json +6 -3
- package/src/modules/webhooks/migrations/Migration20261027193000_receipt_scope.ts +8 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
[build:webhooks] found
|
|
1
|
+
[build:webhooks] found 81 entry points
|
|
2
2
|
[build:webhooks] built successfully
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { expect, test } from "@playwright/test";
|
|
3
|
+
import { withClient } from "@open-mercato/core/helpers/integration/dbFixtures";
|
|
4
|
+
import { Migration20261027193000_receipt_scope } from "../migrations/Migration20261027193000_receipt_scope.js";
|
|
5
|
+
test("TC-WEBHOOK-014: receipt deduplication isolates tenant, organization, and unscoped namespaces", async () => {
|
|
6
|
+
await withClient(async (client) => {
|
|
7
|
+
await client.query("create temporary table receipt_scope_test (like webhook_inbound_receipts including all)");
|
|
8
|
+
try {
|
|
9
|
+
const tenantId = randomUUID();
|
|
10
|
+
const organizationId = randomUUID();
|
|
11
|
+
const scopes = [
|
|
12
|
+
[tenantId, organizationId],
|
|
13
|
+
[tenantId, randomUUID()],
|
|
14
|
+
[randomUUID(), organizationId],
|
|
15
|
+
[null, null],
|
|
16
|
+
[tenantId, null],
|
|
17
|
+
[null, organizationId]
|
|
18
|
+
];
|
|
19
|
+
for (const scope of scopes) {
|
|
20
|
+
const insert = () => client.query(
|
|
21
|
+
`insert into receipt_scope_test (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)
|
|
22
|
+
values ('shared-source', 'shared-message', 'shared-source', $1, $2, now())
|
|
23
|
+
on conflict do nothing returning id`,
|
|
24
|
+
scope
|
|
25
|
+
);
|
|
26
|
+
expect((await insert()).rowCount).toBe(1);
|
|
27
|
+
expect((await insert()).rowCount).toBe(0);
|
|
28
|
+
}
|
|
29
|
+
expect((await client.query("select id from receipt_scope_test")).rowCount).toBe(scopes.length);
|
|
30
|
+
} finally {
|
|
31
|
+
await client.query("drop table receipt_scope_test");
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
test("TC-WEBHOOK-014: migrating historic receipts preserves their identity and replay protection", async () => {
|
|
36
|
+
await withClient(async (client) => {
|
|
37
|
+
await client.query("create temporary table webhook_inbound_receipts (like public.webhook_inbound_receipts including defaults)");
|
|
38
|
+
try {
|
|
39
|
+
await client.query("alter table webhook_inbound_receipts add constraint webhook_inbound_receipts_endpoint_message_unique unique (endpoint_id, message_id)");
|
|
40
|
+
const tenantId = randomUUID();
|
|
41
|
+
const organizationId = randomUUID();
|
|
42
|
+
const insert = (messageId, scope) => client.query(
|
|
43
|
+
`insert into webhook_inbound_receipts (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)
|
|
44
|
+
values ('shared-source', $1, 'shared-source', $2, $3, now())
|
|
45
|
+
on conflict on constraint webhook_inbound_receipts_endpoint_message_unique do nothing returning id`,
|
|
46
|
+
[messageId, ...scope]
|
|
47
|
+
);
|
|
48
|
+
const scopedReceipt = await insert("historic-scoped", [tenantId, organizationId]);
|
|
49
|
+
const unscopedReceipt = await insert("historic-unscoped", [null, null]);
|
|
50
|
+
const otherOrganizationId = randomUUID();
|
|
51
|
+
expect((await insert("historic-scoped", [tenantId, otherOrganizationId])).rowCount).toBe(0);
|
|
52
|
+
const migration = Object.create(Migration20261027193000_receipt_scope.prototype);
|
|
53
|
+
const statements = [];
|
|
54
|
+
Object.defineProperty(migration, "addSql", { value: (sql) => statements.push(sql) });
|
|
55
|
+
await migration.up();
|
|
56
|
+
await client.query("begin");
|
|
57
|
+
try {
|
|
58
|
+
for (const statement of statements) await client.query(statement);
|
|
59
|
+
await client.query("commit");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
await client.query("rollback");
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
const preserved = await client.query("select id from webhook_inbound_receipts");
|
|
65
|
+
expect(preserved.rows.map((receipt) => receipt.id).sort()).toEqual([
|
|
66
|
+
scopedReceipt.rows[0].id,
|
|
67
|
+
unscopedReceipt.rows[0].id
|
|
68
|
+
].sort());
|
|
69
|
+
expect((await insert("historic-scoped", [tenantId, otherOrganizationId])).rowCount).toBe(1);
|
|
70
|
+
expect((await insert("historic-scoped", [tenantId, organizationId])).rowCount).toBe(0);
|
|
71
|
+
expect((await insert("historic-unscoped", [null, null])).rowCount).toBe(0);
|
|
72
|
+
} finally {
|
|
73
|
+
await client.query("drop table pg_temp.webhook_inbound_receipts");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=TC-WEBHOOK-014.spec.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/webhooks/__integration__/TC-WEBHOOK-014.spec.ts"],
|
|
4
|
+
"sourcesContent": ["import { randomUUID } from 'node:crypto'\nimport { expect, test } from '@playwright/test'\nimport { withClient } from '@open-mercato/core/helpers/integration/dbFixtures'\nimport { Migration20261027193000_receipt_scope } from '../migrations/Migration20261027193000_receipt_scope'\n\ntest('TC-WEBHOOK-014: receipt deduplication isolates tenant, organization, and unscoped namespaces', async () => {\n await withClient(async (client) => {\n await client.query('create temporary table receipt_scope_test (like webhook_inbound_receipts including all)')\n try {\n const tenantId = randomUUID()\n const organizationId = randomUUID()\n const scopes = [\n [tenantId, organizationId],\n [tenantId, randomUUID()],\n [randomUUID(), organizationId],\n [null, null],\n [tenantId, null],\n [null, organizationId],\n ]\n\n for (const scope of scopes) {\n const insert = () => client.query<{ id: string }>(\n `insert into receipt_scope_test (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)\n values ('shared-source', 'shared-message', 'shared-source', $1, $2, now())\n on conflict do nothing returning id`,\n scope,\n )\n expect((await insert()).rowCount).toBe(1)\n expect((await insert()).rowCount).toBe(0)\n }\n\n expect((await client.query('select id from receipt_scope_test')).rowCount).toBe(scopes.length)\n } finally {\n await client.query('drop table receipt_scope_test')\n }\n })\n})\n\ntest('TC-WEBHOOK-014: migrating historic receipts preserves their identity and replay protection', async () => {\n await withClient(async (client) => {\n await client.query('create temporary table webhook_inbound_receipts (like public.webhook_inbound_receipts including defaults)')\n try {\n await client.query('alter table webhook_inbound_receipts add constraint webhook_inbound_receipts_endpoint_message_unique unique (endpoint_id, message_id)')\n const tenantId = randomUUID()\n const organizationId = randomUUID()\n const insert = (messageId: string, scope: [string | null, string | null]) => client.query<{ id: string }>(\n `insert into webhook_inbound_receipts (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)\n values ('shared-source', $1, 'shared-source', $2, $3, now())\n on conflict on constraint webhook_inbound_receipts_endpoint_message_unique do nothing returning id`,\n [messageId, ...scope],\n )\n const scopedReceipt = await insert('historic-scoped', [tenantId, organizationId])\n const unscopedReceipt = await insert('historic-unscoped', [null, null])\n const otherOrganizationId = randomUUID()\n expect((await insert('historic-scoped', [tenantId, otherOrganizationId])).rowCount).toBe(0)\n\n const migration = Object.create(Migration20261027193000_receipt_scope.prototype) as Migration20261027193000_receipt_scope\n const statements: string[] = []\n Object.defineProperty(migration, 'addSql', { value: (sql: string) => statements.push(sql) })\n await migration.up()\n await client.query('begin')\n try {\n for (const statement of statements) await client.query(statement)\n await client.query('commit')\n } catch (error) {\n await client.query('rollback')\n throw error\n }\n\n const preserved = await client.query<{ id: string }>('select id from webhook_inbound_receipts')\n expect(preserved.rows.map((receipt) => receipt.id).sort()).toEqual([\n scopedReceipt.rows[0].id,\n unscopedReceipt.rows[0].id,\n ].sort())\n expect((await insert('historic-scoped', [tenantId, otherOrganizationId])).rowCount).toBe(1)\n expect((await insert('historic-scoped', [tenantId, organizationId])).rowCount).toBe(0)\n expect((await insert('historic-unscoped', [null, null])).rowCount).toBe(0)\n } finally {\n await client.query('drop table pg_temp.webhook_inbound_receipts')\n }\n })\n})\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B,SAAS,QAAQ,YAAY;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,6CAA6C;AAEtD,KAAK,gGAAgG,YAAY;AAC/G,QAAM,WAAW,OAAO,WAAW;AACjC,UAAM,OAAO,MAAM,yFAAyF;AAC5G,QAAI;AACF,YAAM,WAAW,WAAW;AAC5B,YAAM,iBAAiB,WAAW;AAClC,YAAM,SAAS;AAAA,QACb,CAAC,UAAU,cAAc;AAAA,QACzB,CAAC,UAAU,WAAW,CAAC;AAAA,QACvB,CAAC,WAAW,GAAG,cAAc;AAAA,QAC7B,CAAC,MAAM,IAAI;AAAA,QACX,CAAC,UAAU,IAAI;AAAA,QACf,CAAC,MAAM,cAAc;AAAA,MACvB;AAEA,iBAAW,SAAS,QAAQ;AAC1B,cAAM,SAAS,MAAM,OAAO;AAAA,UAC1B;AAAA;AAAA;AAAA,UAGA;AAAA,QACF;AACA,gBAAQ,MAAM,OAAO,GAAG,QAAQ,EAAE,KAAK,CAAC;AACxC,gBAAQ,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AI,CAAC,YAAY,QAAQ,EAAE,EAAE,KAAK,CAAC,EAAE,QAAQ;AAAA,QACjE,cAAc,KAAK,CAAC,EAAE;AAAA,QACtB,gBAAgB,KAAK,CAAC,EAAE;AAAA,MAC1B,EAAE,KAAK,CAAC;AACR,cAAQ,MAAM,OAAO,mBAAmB,CAAC,UAAU,mBAAmB,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC;AAC1F,cAAQ,MAAM,OAAO,mBAAmB,CAAC,UAAU,cAAc,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC;AACrF,cAAQ,MAAM,OAAO,qBAAqB,CAAC,MAAM,IAAI,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC;AAAA,IAC3E,UAAE;AACA,YAAM,OAAO,MAAM,6CAA6C;AAAA,IAClE;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -220,7 +220,11 @@ __decorateClass([
|
|
|
220
220
|
], WebhookInboundReceiptEntity.prototype, "createdAt", 2);
|
|
221
221
|
WebhookInboundReceiptEntity = __decorateClass([
|
|
222
222
|
Entity({ tableName: "webhook_inbound_receipts" }),
|
|
223
|
-
Unique({
|
|
223
|
+
Unique({
|
|
224
|
+
name: "webhook_inbound_receipts_endpoint_message_unique",
|
|
225
|
+
properties: ["endpointId", "messageId", "tenantId", "organizationId"],
|
|
226
|
+
expression: 'alter table "webhook_inbound_receipts" add constraint "webhook_inbound_receipts_endpoint_message_unique" unique nulls not distinct ("endpoint_id", "message_id", "tenant_id", "organization_id")'
|
|
227
|
+
}),
|
|
224
228
|
Index({ properties: ["providerKey", "createdAt"] })
|
|
225
229
|
], WebhookInboundReceiptEntity);
|
|
226
230
|
let WebhookIngestionEntity = class {
|
|
@@ -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'\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({
|
|
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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,GA9ClC,sBA+CX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,MAAM,UAAU,KAAK,CAAC;AAAA,GAjDtD,sBAkDX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,gBAAgB,MAAM,MAAM,UAAU,KAAK,CAAC;AAAA,GApDnD,sBAqDX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAvDxC,sBAwDX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GA1DlC,sBA2DX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GA7D7D,sBA8DX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GAhE7D,sBAiEX;AAjEW,wBAAN;AAAA,EALN,OAAO,EAAE,WAAW,qBAAqB,CAAC;AAAA,EAC1C,MAAM,EAAE,YAAY,CAAC,aAAa,QAAQ,EAAE,CAAC;AAAA,EAC7C,MAAM,EAAE,YAAY,CAAC,kBAAkB,YAAY,WAAW,EAAE,CAAC;AAAA,EACjE,MAAM,EAAE,YAAY,CAAC,aAAa,WAAW,EAAE,CAAC;AAAA,EAChD,MAAM,EAAE,YAAY,CAAC,aAAa,gBAAgB,EAAE,CAAC;AAAA,GACzC;
|
|
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({\n name: 'webhook_inbound_receipts_endpoint_message_unique',\n properties: ['endpointId', 'messageId', 'tenantId', 'organizationId'],\n expression: 'alter table \"webhook_inbound_receipts\" add constraint \"webhook_inbound_receipts_endpoint_message_unique\" unique nulls not distinct (\"endpoint_id\", \"message_id\", \"tenant_id\", \"organization_id\")',\n})\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;A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;AAAA,EADC,SAAS,EAAE,MAAM,kBAAkB,MAAM,QAAQ,UAAU,KAAK,CAAC;AAAA,GAVvD,4BAWX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,mBAAmB,MAAM,OAAO,CAAC;AAAA,GAbxC,4BAcX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,aAAa,MAAM,OAAO,CAAC;AAAA,GAhBlC,4BAiBX;AAGA;AAAA,EADC,SAAS,EAAE,MAAM,cAAc,MAAM,MAAM,UAAU,MAAM,oBAAI,KAAK,EAAE,CAAC;AAAA,GAnB7D,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,0BAA0B,CAAC;AAAA,EAC/C,OAAO,EAAE,MAAM,+CAA+C,YAAY,CAAC,aAAa,kBAAkB,UAAU,EAAE,CAAC;AAAA,EACvH,MAAM,EAAE,YAAY,CAAC,aAAa,UAAU,EAAE,CAAC;AAAA,GACnC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Migration } from "@mikro-orm/migrations";
|
|
2
|
+
class Migration20261027193000_receipt_scope extends Migration {
|
|
3
|
+
async up() {
|
|
4
|
+
this.addSql('alter table "webhook_inbound_receipts" drop constraint "webhook_inbound_receipts_endpoint_message_unique";');
|
|
5
|
+
this.addSql('alter table "webhook_inbound_receipts" add constraint "webhook_inbound_receipts_endpoint_message_unique" unique nulls not distinct ("endpoint_id", "message_id", "tenant_id", "organization_id");');
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
Migration20261027193000_receipt_scope
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=Migration20261027193000_receipt_scope.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/modules/webhooks/migrations/Migration20261027193000_receipt_scope.ts"],
|
|
4
|
+
"sourcesContent": ["import { Migration } from '@mikro-orm/migrations'\n\nexport class Migration20261027193000_receipt_scope extends Migration {\n override async up(): Promise<void> {\n this.addSql('alter table \"webhook_inbound_receipts\" drop constraint \"webhook_inbound_receipts_endpoint_message_unique\";')\n this.addSql('alter table \"webhook_inbound_receipts\" add constraint \"webhook_inbound_receipts_endpoint_message_unique\" unique nulls not distinct (\"endpoint_id\", \"message_id\", \"tenant_id\", \"organization_id\");')\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAEnB,MAAM,8CAA8C,UAAU;AAAA,EACnE,MAAe,KAAoB;AACjC,SAAK,OAAO,4GAA4G;AACxH,SAAK,OAAO,mMAAmM;AAAA,EACjN;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/webhooks",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7814.1.406b1b1de7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Webhooks module for Open Mercato — Standard Webhooks compliant outbound/inbound delivery",
|
|
6
6
|
"type": "module",
|
|
@@ -70,20 +70,20 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@open-mercato/cache": "0.10.1-develop.
|
|
74
|
-
"@open-mercato/core": "0.10.1-develop.
|
|
75
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
76
|
-
"@open-mercato/ui": "0.10.1-develop.
|
|
73
|
+
"@open-mercato/cache": "0.10.1-develop.7814.1.406b1b1de7",
|
|
74
|
+
"@open-mercato/core": "0.10.1-develop.7814.1.406b1b1de7",
|
|
75
|
+
"@open-mercato/queue": "0.10.1-develop.7814.1.406b1b1de7",
|
|
76
|
+
"@open-mercato/ui": "0.10.1-develop.7814.1.406b1b1de7",
|
|
77
77
|
"svix": "^1.99.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@mikro-orm/postgresql": "^7.0.14",
|
|
81
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.10.1-develop.7814.1.406b1b1de7",
|
|
82
82
|
"react": "^19.0.0",
|
|
83
83
|
"react-dom": "^19.0.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
86
|
+
"@open-mercato/shared": "0.10.1-develop.7814.1.406b1b1de7",
|
|
87
87
|
"@types/jest": "^30.0.0",
|
|
88
88
|
"@types/react": "^19.2.18",
|
|
89
89
|
"@types/react-dom": "^19.2.5",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import { expect, test } from '@playwright/test'
|
|
3
|
+
import { withClient } from '@open-mercato/core/helpers/integration/dbFixtures'
|
|
4
|
+
import { Migration20261027193000_receipt_scope } from '../migrations/Migration20261027193000_receipt_scope'
|
|
5
|
+
|
|
6
|
+
test('TC-WEBHOOK-014: receipt deduplication isolates tenant, organization, and unscoped namespaces', async () => {
|
|
7
|
+
await withClient(async (client) => {
|
|
8
|
+
await client.query('create temporary table receipt_scope_test (like webhook_inbound_receipts including all)')
|
|
9
|
+
try {
|
|
10
|
+
const tenantId = randomUUID()
|
|
11
|
+
const organizationId = randomUUID()
|
|
12
|
+
const scopes = [
|
|
13
|
+
[tenantId, organizationId],
|
|
14
|
+
[tenantId, randomUUID()],
|
|
15
|
+
[randomUUID(), organizationId],
|
|
16
|
+
[null, null],
|
|
17
|
+
[tenantId, null],
|
|
18
|
+
[null, organizationId],
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
for (const scope of scopes) {
|
|
22
|
+
const insert = () => client.query<{ id: string }>(
|
|
23
|
+
`insert into receipt_scope_test (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)
|
|
24
|
+
values ('shared-source', 'shared-message', 'shared-source', $1, $2, now())
|
|
25
|
+
on conflict do nothing returning id`,
|
|
26
|
+
scope,
|
|
27
|
+
)
|
|
28
|
+
expect((await insert()).rowCount).toBe(1)
|
|
29
|
+
expect((await insert()).rowCount).toBe(0)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
expect((await client.query('select id from receipt_scope_test')).rowCount).toBe(scopes.length)
|
|
33
|
+
} finally {
|
|
34
|
+
await client.query('drop table receipt_scope_test')
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('TC-WEBHOOK-014: migrating historic receipts preserves their identity and replay protection', async () => {
|
|
40
|
+
await withClient(async (client) => {
|
|
41
|
+
await client.query('create temporary table webhook_inbound_receipts (like public.webhook_inbound_receipts including defaults)')
|
|
42
|
+
try {
|
|
43
|
+
await client.query('alter table webhook_inbound_receipts add constraint webhook_inbound_receipts_endpoint_message_unique unique (endpoint_id, message_id)')
|
|
44
|
+
const tenantId = randomUUID()
|
|
45
|
+
const organizationId = randomUUID()
|
|
46
|
+
const insert = (messageId: string, scope: [string | null, string | null]) => client.query<{ id: string }>(
|
|
47
|
+
`insert into webhook_inbound_receipts (endpoint_id, message_id, provider_key, tenant_id, organization_id, created_at)
|
|
48
|
+
values ('shared-source', $1, 'shared-source', $2, $3, now())
|
|
49
|
+
on conflict on constraint webhook_inbound_receipts_endpoint_message_unique do nothing returning id`,
|
|
50
|
+
[messageId, ...scope],
|
|
51
|
+
)
|
|
52
|
+
const scopedReceipt = await insert('historic-scoped', [tenantId, organizationId])
|
|
53
|
+
const unscopedReceipt = await insert('historic-unscoped', [null, null])
|
|
54
|
+
const otherOrganizationId = randomUUID()
|
|
55
|
+
expect((await insert('historic-scoped', [tenantId, otherOrganizationId])).rowCount).toBe(0)
|
|
56
|
+
|
|
57
|
+
const migration = Object.create(Migration20261027193000_receipt_scope.prototype) as Migration20261027193000_receipt_scope
|
|
58
|
+
const statements: string[] = []
|
|
59
|
+
Object.defineProperty(migration, 'addSql', { value: (sql: string) => statements.push(sql) })
|
|
60
|
+
await migration.up()
|
|
61
|
+
await client.query('begin')
|
|
62
|
+
try {
|
|
63
|
+
for (const statement of statements) await client.query(statement)
|
|
64
|
+
await client.query('commit')
|
|
65
|
+
} catch (error) {
|
|
66
|
+
await client.query('rollback')
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const preserved = await client.query<{ id: string }>('select id from webhook_inbound_receipts')
|
|
71
|
+
expect(preserved.rows.map((receipt) => receipt.id).sort()).toEqual([
|
|
72
|
+
scopedReceipt.rows[0].id,
|
|
73
|
+
unscopedReceipt.rows[0].id,
|
|
74
|
+
].sort())
|
|
75
|
+
expect((await insert('historic-scoped', [tenantId, otherOrganizationId])).rowCount).toBe(1)
|
|
76
|
+
expect((await insert('historic-scoped', [tenantId, organizationId])).rowCount).toBe(0)
|
|
77
|
+
expect((await insert('historic-unscoped', [null, null])).rowCount).toBe(0)
|
|
78
|
+
} finally {
|
|
79
|
+
await client.query('drop table pg_temp.webhook_inbound_receipts')
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -3,7 +3,7 @@ import type { WebhookSourceConfig } from '@open-mercato/shared/lib/webhooks'
|
|
|
3
3
|
const enqueueInboundDispatch = jest.fn(async () => 'job-1')
|
|
4
4
|
const emitWebhooksEvent = jest.fn(async () => undefined)
|
|
5
5
|
const findWithDecryption = jest.fn()
|
|
6
|
-
const credentialsResolve = jest.fn(async () => ({ webhookSigningSecret: 'whsec' }))
|
|
6
|
+
const credentialsResolve = jest.fn(async (_integrationId: string, _scope: { tenantId: string; organizationId: string }) => ({ webhookSigningSecret: 'whsec' }))
|
|
7
7
|
|
|
8
8
|
const flush = jest.fn(async () => undefined)
|
|
9
9
|
const persist = jest.fn()
|
|
@@ -72,7 +72,8 @@ beforeEach(() => {
|
|
|
72
72
|
flush.mockResolvedValue(undefined)
|
|
73
73
|
findWithDecryption.mockReset()
|
|
74
74
|
findWithDecryption.mockResolvedValue([{ organizationId: 'o1', tenantId: 't1', sourceKey: 'stripe', isActive: true }])
|
|
75
|
-
credentialsResolve.
|
|
75
|
+
credentialsResolve.mockReset()
|
|
76
|
+
credentialsResolve.mockResolvedValue({ webhookSigningSecret: 'whsec' })
|
|
76
77
|
})
|
|
77
78
|
|
|
78
79
|
it('returns 404 when neither a source nor an adapter matches the segment', async () => {
|
|
@@ -147,3 +148,28 @@ it('returns duplicate when the receipt unique constraint is violated', async ()
|
|
|
147
148
|
await expect(res.json()).resolves.toEqual({ ok: true, duplicate: true })
|
|
148
149
|
expect(enqueueInboundDispatch).not.toHaveBeenCalled()
|
|
149
150
|
})
|
|
151
|
+
|
|
152
|
+
it('persists the scope selected by each source delivery own credentials', async () => {
|
|
153
|
+
const scopes = [
|
|
154
|
+
{ tenantId: 'tenant-1', organizationId: 'org-1' },
|
|
155
|
+
{ tenantId: 'tenant-1', organizationId: 'org-2' },
|
|
156
|
+
{ tenantId: 'tenant-2', organizationId: 'org-1' },
|
|
157
|
+
]
|
|
158
|
+
findWithDecryption.mockResolvedValue(scopes.map((scope) => ({ ...scope, sourceKey: 'stripe', isActive: true })))
|
|
159
|
+
credentialsResolve.mockImplementation(async (_integrationId: string, scope: { tenantId: string; organizationId: string }) => ({
|
|
160
|
+
webhookSigningSecret: `${scope.tenantId}:${scope.organizationId}`,
|
|
161
|
+
}))
|
|
162
|
+
registerWebhookSource(makeSource({
|
|
163
|
+
verifier: async (request, credentials) => request.headers['x-test-signature'] === credentials.webhookSigningSecret,
|
|
164
|
+
}))
|
|
165
|
+
|
|
166
|
+
for (const scope of scopes) {
|
|
167
|
+
const response = await postTo('stripe', undefined, {
|
|
168
|
+
'x-test-signature': `${scope.tenantId}:${scope.organizationId}`,
|
|
169
|
+
})
|
|
170
|
+
await expect(response.json()).resolves.toEqual({ ok: true })
|
|
171
|
+
expect(persist).toHaveBeenCalledWith(expect.objectContaining({ endpointId: 'stripe', messageId: 'evt_1', ...scope }))
|
|
172
|
+
expect(enqueueInboundDispatch).toHaveBeenLastCalledWith(expect.objectContaining(scope))
|
|
173
|
+
}
|
|
174
|
+
expect(enqueueInboundDispatch).toHaveBeenCalledTimes(scopes.length)
|
|
175
|
+
})
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MetadataStorage } from '@mikro-orm/core'
|
|
2
|
+
import { WebhookInboundReceiptEntity } from '../entities'
|
|
3
|
+
import { Migration20261027193000_receipt_scope } from '../../migrations/Migration20261027193000_receipt_scope'
|
|
4
|
+
|
|
5
|
+
it('keeps the named receipt constraint scoped and null-safe in metadata and migration', async () => {
|
|
6
|
+
const metadata = Object.values(MetadataStorage.getMetadata()).find(
|
|
7
|
+
(candidate) => candidate.className === WebhookInboundReceiptEntity.name,
|
|
8
|
+
)
|
|
9
|
+
const receiptConstraint = metadata?.uniques.find(
|
|
10
|
+
(constraint) => constraint.name === 'webhook_inbound_receipts_endpoint_message_unique',
|
|
11
|
+
)
|
|
12
|
+
expect(receiptConstraint?.properties).toEqual(['endpointId', 'messageId', 'tenantId', 'organizationId'])
|
|
13
|
+
expect(receiptConstraint?.expression).toContain('unique nulls not distinct')
|
|
14
|
+
|
|
15
|
+
const migration = Object.create(Migration20261027193000_receipt_scope.prototype) as Migration20261027193000_receipt_scope
|
|
16
|
+
const statements: string[] = []
|
|
17
|
+
Object.defineProperty(migration, 'addSql', { value: (sql: string) => statements.push(sql) })
|
|
18
|
+
await migration.up()
|
|
19
|
+
|
|
20
|
+
expect(migration.isTransactional()).toBe(true)
|
|
21
|
+
expect(statements).toEqual([
|
|
22
|
+
'alter table "webhook_inbound_receipts" drop constraint "webhook_inbound_receipts_endpoint_message_unique";',
|
|
23
|
+
`${receiptConstraint?.expression};`,
|
|
24
|
+
])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('refuses an automatic rollback that could discard legitimate cross-scope receipts', () => {
|
|
28
|
+
const migration = Object.create(Migration20261027193000_receipt_scope.prototype) as Migration20261027193000_receipt_scope
|
|
29
|
+
const addSql = jest.fn()
|
|
30
|
+
Object.defineProperty(migration, 'addSql', { value: addSql })
|
|
31
|
+
|
|
32
|
+
expect(() => migration.down()).toThrow('This migration cannot be reverted')
|
|
33
|
+
expect(addSql).not.toHaveBeenCalled()
|
|
34
|
+
})
|
|
@@ -158,7 +158,11 @@ export class WebhookDeliveryEntity {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
@Entity({ tableName: 'webhook_inbound_receipts' })
|
|
161
|
-
@Unique({
|
|
161
|
+
@Unique({
|
|
162
|
+
name: 'webhook_inbound_receipts_endpoint_message_unique',
|
|
163
|
+
properties: ['endpointId', 'messageId', 'tenantId', 'organizationId'],
|
|
164
|
+
expression: 'alter table "webhook_inbound_receipts" add constraint "webhook_inbound_receipts_endpoint_message_unique" unique nulls not distinct ("endpoint_id", "message_id", "tenant_id", "organization_id")',
|
|
165
|
+
})
|
|
162
166
|
@Index({ properties: ['providerKey', 'createdAt'] })
|
|
163
167
|
export class WebhookInboundReceiptEntity {
|
|
164
168
|
@PrimaryKey({ type: 'uuid', defaultRaw: 'gen_random_uuid()' })
|
|
@@ -771,13 +771,16 @@
|
|
|
771
771
|
{
|
|
772
772
|
"columnNames": [
|
|
773
773
|
"endpoint_id",
|
|
774
|
-
"message_id"
|
|
774
|
+
"message_id",
|
|
775
|
+
"tenant_id",
|
|
776
|
+
"organization_id"
|
|
775
777
|
],
|
|
776
778
|
"composite": true,
|
|
777
779
|
"constraint": true,
|
|
778
780
|
"keyName": "webhook_inbound_receipts_endpoint_message_unique",
|
|
779
781
|
"primary": false,
|
|
780
|
-
"unique": true
|
|
782
|
+
"unique": true,
|
|
783
|
+
"expression": "alter table \"webhook_inbound_receipts\" add constraint \"webhook_inbound_receipts_endpoint_message_unique\" unique nulls not distinct (\"endpoint_id\", \"message_id\", \"tenant_id\", \"organization_id\")"
|
|
781
784
|
},
|
|
782
785
|
{
|
|
783
786
|
"columnNames": [
|
|
@@ -1625,4 +1628,4 @@
|
|
|
1625
1628
|
],
|
|
1626
1629
|
"views": [],
|
|
1627
1630
|
"nativeEnums": {}
|
|
1628
|
-
}
|
|
1631
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Migration } from '@mikro-orm/migrations'
|
|
2
|
+
|
|
3
|
+
export class Migration20261027193000_receipt_scope extends Migration {
|
|
4
|
+
override async up(): Promise<void> {
|
|
5
|
+
this.addSql('alter table "webhook_inbound_receipts" drop constraint "webhook_inbound_receipts_endpoint_message_unique";')
|
|
6
|
+
this.addSql('alter table "webhook_inbound_receipts" add constraint "webhook_inbound_receipts_endpoint_message_unique" unique nulls not distinct ("endpoint_id", "message_id", "tenant_id", "organization_id");')
|
|
7
|
+
}
|
|
8
|
+
}
|