Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions libs/growth/src/lib/webhooks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,41 @@ describe('processVerifiedResendWebhook', () => {
}
});

it('accepts the documented Resend payload shape: message_id present and null optional ids', async () => {
// Resend's wire payload gained `message_id` after SDK 6.10 pinned its
// types, and transactional mail carries null broadcast/template ids.
// Both must parse, or every real event answers 400 and delivery state
// never leaves "submitted".
const harness = webhookHarness();

await expect(
processVerifiedResendWebhook(
harness.executor,
{
providerEventId: 'msg_documented_shape',
payload: event('email.delivered', {
broadcast_id: null,
template_id: null,
message_id: '<111-222-333@email.example.com>',
}),
},
harness.dependencies
)
).resolves.toMatchObject({ applied: true });
});

it('still rejects unknown data keys so the closed schema stays enforced', async () => {
const harness = executorWith({});

await expect(
processVerifiedResendWebhook(harness.executor, {
providerEventId: 'msg_unknown_key',
payload: event('email.delivered', { headers: [] }),
})
).rejects.toThrow(/Invalid Resend webhook payload/u);
expect(harness.runTransaction).not.toHaveBeenCalled();
});

it('marks only a permanent bounce as a hard-bounce stop', async () => {
const hard = webhookHarness();
await processVerifiedResendWebhook(
Expand Down
14 changes: 11 additions & 3 deletions libs/growth/src/lib/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ const DELIVERY_STATUS_PRECEDENCE: Readonly<
suppressed: 3,
complained: 4,
};
// Resend's wire payload gained `message_id` after the pinned SDK types were
// written, and transactional mail carries null broadcast/template ids.
const BASE_DATA_KEYS = new Set([
'broadcast_id',
'created_at',
'email_id',
'from',
'message_id',
'subject',
'tags',
'template_id',
Expand Down Expand Up @@ -184,9 +187,14 @@ function validateProviderBaseData(data: Record<string, unknown>): void {
throw new Error('Invalid Resend webhook payload');
}
for (const recipient of data['to']) boundedText(recipient, 254);
if (data['broadcast_id'] !== undefined)
boundedText(data['broadcast_id'], 256);
if (data['template_id'] !== undefined) boundedText(data['template_id'], 256);
for (const key of ['broadcast_id', 'template_id'] as const) {
if (data[key] !== undefined && data[key] !== null) {
boundedText(data[key], 256);
}
}
if (data['message_id'] !== undefined && data['message_id'] !== null) {
boundedText(data['message_id'], 998);
}
}

function validateClosedDetails(
Expand Down
Loading