@lastshotlabs/slingshot-mail
npm install @lastshotlabs/slingshot-mail
Functions
Section titled “Functions”createBullMQMailQueue
Section titled “createBullMQMailQueue”Creates a durable, Redis-backed mail queue powered by BullMQ.
Requires bullmq and ioredis as installed dependencies — both are optional peers.
The queue tests the Redis connection eagerly on start() to surface misconfiguration
at startup rather than at first delivery attempt.
Non-retryable failures (e.g. provider-rejected messages) are wrapped in
BullMQ.UnrecoverableError so they bypass BullMQ’s built-in retry backoff and are
dead-lettered immediately. The original MailSendError context (statusCode,
providerError) is preserved and forwarded to onDeadLetter.
function createBullMQMailQueue(config: BullMQMailQueueConfig): MailQueueSource: packages/slingshot-mail/src/queues/bullmq.ts
createMailPlugin
Section titled “createMailPlugin”Creates the slingshot-mail plugin for event-driven transactional email delivery.
Validates the config and adapter shapes at construction time (fail-fast). Mail delivery
is entirely event-driven — subscribe to SlingshotEventMap keys via config.subscriptions
and the plugin dispatches templated emails automatically when those events fire.
function createMailPlugin(rawConfig: MailPluginConfig): SlingshotPluginSource: packages/slingshot-mail/src/plugin.ts
createMemoryQueue
Section titled “createMemoryQueue”Creates an in-process, non-durable mail queue for development and testing.
Jobs are held in memory and processed inline - no external dependencies required.
This queue is not suitable for production: all pending jobs are lost on process
restart. Use createBullMQMailQueue for durable, Redis-backed delivery.
Remarks: Prints a startup warning to console.warn to make the non-durable nature visible. The warning is intentional and should not be suppressed.
function createMemoryQueue(config?: MailQueueConfig): MailQueueSource: packages/slingshot-mail/src/queues/memory.ts
createPostmarkProvider
Section titled “createPostmarkProvider”Maximum milliseconds a single HTTP send may run before the request is aborted with a retryable timeout error. Default: 30000.
function createPostmarkProvider(config: PostmarkConfig): MailProviderSource: packages/slingshot-mail/src/providers/postmark.ts
createRawHtmlRenderer
Section titled “createRawHtmlRenderer”A static HTML template with optional {{variable}} interpolation placeholders.
Variable syntax: {{key}} - all values are coerced to strings safely.
Missing keys render as empty strings rather than throwing.
function createRawHtmlRenderer(config: RawHtmlRendererConfig): MailRendererSource: packages/slingshot-mail/src/renderers/rawHtml.ts
createReactEmailRenderer
Section titled “createReactEmailRenderer”Creates a MailRenderer backed by @react-email/render.
Components are plain React functional components that receive the dataMapper output as
props. @react-email/render is loaded lazily on first render - install it as a peer
dependency. Plain-text extraction is attempted via render(..., { plainText: true });
if it fails the text body is omitted with a warning.
Remarks: Components must be synchronous. Async server components are not supported by @react-email/render.
function createReactEmailRenderer(config: ReactEmailRendererConfig): MailRendererSource: packages/slingshot-mail/src/renderers/reactEmail.ts
createResendProvider
Section titled “createResendProvider”Maximum milliseconds a single HTTP send may run before the request is aborted with a retryable timeout error. Default: 30000.
function createResendProvider(config: ResendConfig): MailProviderSource: packages/slingshot-mail/src/providers/resend.ts
createSendgridProvider
Section titled “createSendgridProvider”Maximum milliseconds a single HTTP send may run before the request is aborted with a retryable timeout error. Default: 30000.
function createSendgridProvider(config: SendgridConfig): MailProviderSource: packages/slingshot-mail/src/providers/sendgrid.ts
createSesProvider
Section titled “createSesProvider”Maximum milliseconds a single SDK send may run before the request is aborted with a retryable timeout error. Default: 30000.
function createSesProvider(config: SesConfig): MailProviderSource: packages/slingshot-mail/src/providers/ses.ts
mailPluginConfigSchema
Section titled “mailPluginConfigSchema”Declarative binding from a bus event to a mail template.
When the bus emits event, the plugin resolves the recipient via recipientMapper,
renders template with data from dataMapper, and enqueues a delivery.
Source: packages/slingshot-mail/src/types/config.ts
validateSubscriptionTemplates
Section titled “validateSubscriptionTemplates”Thrown at plugin startup when a subscription’s template cannot be found in the configured renderer. Lets callers fail fast instead of waiting for the first matching event to fire at runtime.
async function validateSubscriptionTemplates(config: MailPluginConfig): Promise<void>Source: packages/slingshot-mail/src/lib/subscriptionWiring.ts
Classes
Section titled “Classes”MailCircuitOpenError
Section titled “MailCircuitOpenError”Consecutive-failure circuit breaker for outbound mail provider calls.
Mirrors the shape of slingshot-search’s typesense breaker and the
slingshot-assets S3 breaker so operational behaviour stays uniform across
production-track packages. The intent is to fail fast during sustained
provider outages rather than let queue workers thrash against a degraded
upstream.
Source: packages/slingshot-mail/src/lib/circuitBreaker.ts
MailSendError
Section titled “MailSendError”An email address, expressed either as a bare address string or a structured object.
Source: packages/slingshot-mail/src/types/provider.ts
MailTemplateNotFoundError
Section titled “MailTemplateNotFoundError”Thrown at plugin startup when a subscription’s template cannot be found in the configured renderer. Lets callers fail fast instead of waiting for the first matching event to fire at runtime.
Source: packages/slingshot-mail/src/lib/subscriptionWiring.ts
Interfaces
Section titled “Interfaces”MailCircuitBreaker
Section titled “MailCircuitBreaker”Consecutive-failure circuit breaker for outbound mail provider calls.
Mirrors the shape of slingshot-search’s typesense breaker and the
slingshot-assets S3 breaker so operational behaviour stays uniform across
production-track packages. The intent is to fail fast during sustained
provider outages rather than let queue workers thrash against a degraded
upstream.
Source: packages/slingshot-mail/src/lib/circuitBreaker.ts
MailCircuitBreakerHealth
Section titled “MailCircuitBreakerHealth”Consecutive-failure circuit breaker for outbound mail provider calls.
Mirrors the shape of slingshot-search’s typesense breaker and the
slingshot-assets S3 breaker so operational behaviour stays uniform across
production-track packages. The intent is to fail fast during sustained
provider outages rather than let queue workers thrash against a degraded
upstream.
Source: packages/slingshot-mail/src/lib/circuitBreaker.ts
MailCircuitBreakerOptions
Section titled “MailCircuitBreakerOptions”Consecutive-failure circuit breaker for outbound mail provider calls.
Mirrors the shape of slingshot-search’s typesense breaker and the
slingshot-assets S3 breaker so operational behaviour stays uniform across
production-track packages. The intent is to fail fast during sustained
provider outages rather than let queue workers thrash against a degraded
upstream.
Source: packages/slingshot-mail/src/lib/circuitBreaker.ts
MailJob
Section titled “MailJob”A single mail delivery job tracked by the queue.
Exposed to onDeadLetter callbacks so callers can inspect what failed and why.
Source: packages/slingshot-mail/src/types/queue.ts
MailMessage
Section titled “MailMessage”An email address, expressed either as a bare address string or a structured object.
Source: packages/slingshot-mail/src/types/provider.ts
MailProvider
Section titled “MailProvider”An email address, expressed either as a bare address string or a structured object.
Source: packages/slingshot-mail/src/types/provider.ts
MailQueue
Section titled “MailQueue”A single mail delivery job tracked by the queue.
Exposed to onDeadLetter callbacks so callers can inspect what failed and why.
Source: packages/slingshot-mail/src/types/queue.ts
MailQueueConfig
Section titled “MailQueueConfig”A single mail delivery job tracked by the queue.
Exposed to onDeadLetter callbacks so callers can inspect what failed and why.
Source: packages/slingshot-mail/src/types/queue.ts
MailSubscription
Section titled “MailSubscription”Declarative binding from a bus event to a mail template.
When the bus emits event, the plugin resolves the recipient via recipientMapper,
renders template with data from dataMapper, and enqueues a delivery.
Source: packages/slingshot-mail/src/types/config.ts
RawHtmlTemplate
Section titled “RawHtmlTemplate”A static HTML template with optional {{variable}} interpolation placeholders.
Variable syntax: {{key}} - all values are coerced to strings safely.
Missing keys render as empty strings rather than throwing.
Source: packages/slingshot-mail/src/renderers/rawHtml.ts
SendResult
Section titled “SendResult”An email address, expressed either as a bare address string or a structured object.
Source: packages/slingshot-mail/src/types/provider.ts
MailAddress
Section titled “MailAddress”An email address, expressed either as a bare address string or a structured object.
Source: packages/slingshot-mail/src/types/provider.ts
MailPluginConfig
Section titled “MailPluginConfig”Declarative binding from a bus event to a mail template.
When the bus emits event, the plugin resolves the recipient via recipientMapper,
renders template with data from dataMapper, and enqueues a delivery.
Source: packages/slingshot-mail/src/types/config.ts