/** * @module * RetryTransport — decorator that wraps any sently channel transport * and retries failed sends with configurable backoff. * Works with email, SMS, WhatsApp, and push transports. * * @example * ```ts * import { RetryTransport } from 'sently/transports/retry' * import { ResendTransport } from 'sently/transports/resend' * * const transport = new RetryTransport( * new ResendTransport({ apiKey }), * { maxAttempts: 3, backoff: 'exponential', retryOn: [429, 503] } * ) * ``` */ import type { DecoratedTransport } from "../core/decorated-transport.js"; import type { MailOptions, RetryConfig, SendResult, VerifyResult } from "../core/types.js"; /** * Decorator transport that retries failed sends with configurable backoff. * Defaults preserve email {@link Transport} compatibility. */ export declare class RetryTransport implements DecoratedTransport { /** Transport that performs the actual send on each attempt. */ private readonly inner; /** Injectable sleep function for testing backoff timing. */ private readonly _sleep; readonly provider = "retry"; /** Maximum send attempts including the initial try. */ private readonly maxAttempts; /** Backoff strategy between retries. */ private readonly backoff; /** Base delay in milliseconds before the first retry. */ private readonly baseDelay; /** HTTP status codes that trigger a retry. */ private readonly retryOn; /** Optional callback invoked before each retry attempt. */ private readonly onRetry; /** Additional onRetry callback wired by sender lifecycle hooks per send. */ private mailerOnRetry; /** Wraps an inner transport with retry logic and optional backoff configuration. */ constructor( /** Transport that performs the actual send on each attempt. */ inner: DecoratedTransport, config?: RetryConfig, /** Injectable sleep function for testing backoff timing. */ _sleep?: (ms: number) => Promise); /** * Register a per-send onRetry callback from sender lifecycle hooks. * Do not share one {@link RetryTransport} across multiple senders — the last * `setMailerOnRetry` wins; overwriting an active callback logs a dev warning. * @internal Cleared after each send. */ setMailerOnRetry(callback: RetryConfig["onRetry"] | undefined): void; /** Sends with retries according to configured backoff and retry rules. */ send(options: TOptions): Promise; /** Delegates to the inner transport verify or returns a default success result. */ verify(): Promise; /** Delegates close to the inner transport if available. */ close(): Promise; /** Delegates batch sends to the inner transport when available. */ sendBatch(messages: TOptions[]): Promise; }