Skip to content
You're viewing documentation for v0.6.2. It may be out of date.Go to latest
Email SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Defaults plugin

Merge org-wide headers, tags, reply-to, and idempotency key prefixes into every send — with message values winning.

defaultsPlugin injects shared values into every message before validation, so org-wide headers, tags, and a reply-to address live in one place instead of every call site. Per-message values always take precedence over the defaults.

Options

PropType
id?string

Plugin id. Override when mounting multiple defaults layers.

Typestring
Default"defaults"
headers?Record<string, string> | EmailHeader[]

Default message headers, merged under per-message headers.

TypeRecord<string, string> | EmailHeader[]
tags?EmailTag[]

Default tags, prepended before per-message tags.

TypeEmailTag[]
metadata?Record<string, string | number | boolean | null>

Default message metadata, merged under per-message metadata.

TypeRecord<string, string | number | boolean | null>
sendMetadata?Record<string, unknown>

Default send-option metadata (flows to hooks, not the message).

TypeRecord<string, unknown>
replyTo?EmailAddress | EmailAddress[]

Default reply-to, used only when the message has none.

TypeEmailAddress | EmailAddress[]
idempotencyKey?string

Default idempotency key, used only when the message and send options have none.

Typestring
idempotencyKeyPrefix?string

Prefix prepended to the idempotency key unless it already starts with it.

Typestring

Merge semantics

Each option has an exact, predictable rule:

Option Rule
headers Merged by name; a message header with the same name wins over the default.
metadata Merged by key; message metadata wins.
sendMetadata Merged into options.metadata; per-send metadata wins.
tags Concatenated — defaults first, then message tags. Nothing is replaced.
replyTo Applied only when the message has no replyTo at all.
idempotencyKey Applied only when neither the message nor send options carry a key.
idempotencyKeyPrefix Prepended to whichever key ends up applying — unless the key already starts with the prefix, so re-runs never double-prefix.

So with the client above, a message that sets headers: { "X-Entity-Ref": "checkout" } sends checkout (message wins), while its tags gain the env tag in front of its own.

Stack layers

Mount multiple defaults plugins with distinct ids; they apply in array order, so later layers see the merged result of earlier ones:

Next

Last updated on