feat(events): accept idempotencyKey on events.send

Merged
NI
2d ago
+32-1

Why

resend.events.send should accept an idempotencyKey option, the same way resend.emails.send does.

Today resend.events.send(payload, { idempotencyKey }) fails to compile with 'idempotencyKey' does not exist in type 'RequestOptions'.

What changed

  • New SendEventRequestOptions extends PostOptions and IdempotentRequest, the same shape as CreateEmailRequestOptions and SendInboxDraftRequestOptions. The package root exports it through src/events/interfaces.
  • events.send takes SendEventRequestOptions instead of RequestOptions. Resend.post already turns idempotencyKey into the Idempotency-Key header, so no runtime code changes.
await resend.events.send(
	{ event: 'order.created', email: 'ana@example.com' },
	{ idempotencyKey: 'order_created:123' },
);

Blast Radius

The change widens the type of an optional parameter. Existing calls compile and send the same request.

Verification

  • pnpm lint, pnpm typecheck, and pnpm test pass.
  • New spec in src/events/events.spec.ts checks the header on the outgoing request. With the old RequestOptions type, pnpm typecheck fails on that spec with TS2353.
  • Against the built dist/, a local HTTP server got Idempotency-Key: order_created:123 on a call with the key, and no header on a call without it.
  • A strict consumer that imports SendEventRequestOptions from resend typechecks against dist/index.d.mts. Passing { idempotencyKey: 1 } fails with TS2322.
Open in Web Open in Cursor 

Summary by cubic

Allows resend.events.send to accept an idempotencyKey option so resending POST /events/send with the same key within 24 hours returns the cached 202 instead of triggering a second automation run (MES-3033).

  • events.send now takes a SendEventRequestOptions type that mirrors CreateEmailRequestOptions; the package root exports it.
  • Passing { idempotencyKey } sends the Idempotency-Key header, which previously failed typechecking.
  • A new spec in src/events/events.spec.ts verifies the header on the outgoing request.
  • Existing calls compile and send the same request; release after the API change (MES-3036) deploys so the key has an effect.