diff --git a/.changeset/provider-neutral-dedup-log.md b/.changeset/provider-neutral-dedup-log.md new file mode 100644 index 0000000..21e6370 --- /dev/null +++ b/.changeset/provider-neutral-dedup-log.md @@ -0,0 +1,5 @@ +--- +"@dashcommerce/core": patch +--- + +The log line for a skipped duplicate webhook now reads "Webhook deduped" and names the provider, instead of "Stripe webhook deduped" for every provider. Its fields are now `providerId`, `eventId` (was `stripeEventId`) and `type`. diff --git a/packages/core/src/routes/webhook.ts b/packages/core/src/routes/webhook.ts index 3d043e2..13619a7 100644 --- a/packages/core/src/routes/webhook.ts +++ b/packages/core/src/routes/webhook.ts @@ -89,6 +89,7 @@ async function recordStripeEvent( ctx: PluginContext, stripeEventId: string, type: string, + providerId: string, ): Promise { try { const id = randomId(); @@ -101,7 +102,7 @@ async function recordStripeEvent( return id; } catch (err) { if (isUniqueViolation(err)) { - ctx.log.info("Stripe webhook deduped", { stripeEventId, type }); + ctx.log.info("Webhook deduped", { providerId, eventId: stripeEventId, type }); return null; } throw err; @@ -879,7 +880,12 @@ export const webhookRoutes = { // the same resource. `providerEventId` is Stripe `event.id`. let dedupRowId: string | null = null; if (providerEventId) { - dedupRowId = await recordStripeEvent(ctx, providerEventId, eventTypeForDedup); + dedupRowId = await recordStripeEvent( + ctx, + providerEventId, + eventTypeForDedup, + provider.id, + ); if (!dedupRowId) { return new Response(JSON.stringify({ received: true, duplicate: true }), { status: 200, diff --git a/packages/core/test/webhook-retry-after-confirmation-failure.test.ts b/packages/core/test/webhook-retry-after-confirmation-failure.test.ts index aa208f7..60266ac 100644 --- a/packages/core/test/webhook-retry-after-confirmation-failure.test.ts +++ b/packages/core/test/webhook-retry-after-confirmation-failure.test.ts @@ -89,7 +89,7 @@ describe("webhook retry after a failed confirmation", () => { it("still skips an exact repeat once the event was processed", async () => { registerPaymentProvider(scriptedProvider([paid]), { override: true }); - const { ctx, getCol } = makeRouteContext(mockSettings); + const { ctx, getCol, logs } = makeRouteContext(mockSettings); const draftId = await startCheckout(ctx, "sess_repeat"); const payload = chargeSucceeded(draftId); @@ -97,6 +97,14 @@ describe("webhook retry after a failed confirmation", () => { const repeat = await deliverWebhook(ctx, payload, headers); expect(((await repeat.json()) as { duplicate?: boolean }).duplicate).toBe(true); expect(getCol("orders").size).toBe(1); + // The log names the provider that sent the event, not Stripe. + expect(logs).toContainEqual( + expect.objectContaining({ + level: "info", + msg: "Webhook deduped", + meta: expect.objectContaining({ providerId: "mock", type: "charge.succeeded" }), + }), + ); }); it("keeps the record for failures other than confirmation, as before", async () => {