import { Buffer } from 'node:buffer'; /** * Utility type for values that can be promises */ type MaybePromise = T | Promise; /** * Feature flags indicating what capabilities a provider supports */ interface FeatureFlags { attachments?: boolean; batchSending?: boolean; customHeaders?: boolean; html?: boolean; /** * The provider sends `idempotencyKey` upstream, so a repeated send with the same key is not duplicated. */ idempotency?: boolean; replyTo?: boolean; scheduling?: boolean; tagging?: boolean; templates?: boolean; tracking?: boolean; } /** * Base configuration for all providers */ interface BaseConfig { debug?: boolean; logger?: Console; retries?: number; timeout?: number; } /** * Email address with optional name */ interface EmailAddress { email: string; name?: string; } /** * Email attachment */ interface Attachment { /** * Content-ID for inline attachments (used in HTML with cid:) */ cid?: string; /** * Attachment content (string, Buffer, or Promise<Uint8Array> for async loading) * Required if path, href, or raw are not provided */ content?: string | Buffer | Promise; /** * Content disposition: 'attachment' (default) or 'inline' */ contentDisposition?: "attachment" | "inline"; /** * MIME type of the attachment */ contentType?: string; /** * Content transfer encoding (e.g., 'base64', '7bit', 'quoted-printable') */ encoding?: string; /** * Filename for the attachment */ filename: string; /** * Custom headers for this attachment */ headers?: Record; /** * URL to fetch attachment from * Alternative to content or path */ href?: string; /** * HTTP headers to use when fetching from href */ httpHeaders?: Record; /** * File path to read attachment from * Alternative to content */ path?: string; /** * Raw attachment data (alternative to content) * Can be used for pre-encoded content */ raw?: string | Buffer; } /** * Email tag for categorization */ interface EmailTag { name: string; value: string; } /** * Priority levels for email messages */ type Priority = "high" | "normal" | "low"; /** * Represents the headers of an email message. * This type is a supertype of the standard `Headers` class, which is used to manage HTTP headers. * Note that this type does not include methods for modifying the headers, * such as `append`, `delete`, or `set`. It is intended to be used for * read-only access to the headers of an email message. */ type ImmutableHeaders = Omit; /** * Email headers can be either a plain object or an ImmutableHeaders instance */ type EmailHeaders = Record | ImmutableHeaders; /** * Options for calendar event attachments */ interface CalendarEventOptions { /** * Alternative text for the calendar event */ alternativeText?: string; /** * Method for the calendar event (e.g., 'REQUEST', 'CANCEL', 'REPLY') */ method?: string; } /** * Common email options that all providers support */ interface EmailOptions { attachments?: Attachment[]; bcc?: EmailAddress | EmailAddress[]; cc?: EmailAddress | EmailAddress[]; from: EmailAddress; headers?: EmailHeaders; html?: string; icalEvent?: CalendarEventOptions & { content?: string; href?: string; path?: string; }; /** * Caller-chosen key that lets the provider recognise a repeated send of the same message, so a * retry after an ambiguous failure does not deliver twice. Only providers that declare * `features.idempotency` act on it; it is never written into the message headers or the MIME body. */ idempotencyKey?: string; priority?: Priority; replyTo?: EmailAddress; /** * The message stream this email belongs to. Used by `Mail.mount` to route the message to a * mounted provider (e.g. a Postmark broadcast stream). Providers that don't support streams ignore it. */ stream?: string; subject: string; tags?: string[]; text?: string; to: EmailAddress | EmailAddress[]; } /** * Result of sending an email */ interface EmailResult { messageId: string; provider?: string; response?: unknown; sent: boolean; timestamp: Date; } /** * Receipt type for email sending results * Uses discriminated union for type safety */ type Receipt = { /** * The unique identifier for the message that was sent */ readonly messageId: string; /** * Optional provider name */ readonly provider?: string; /** * Optional response data from provider */ readonly response?: unknown; /** * Indicates that the email was sent successfully */ readonly successful: true; /** * Timestamp when email was sent */ readonly timestamp: Date; } | { /** * An array of error messages that occurred during the sending process */ readonly errorMessages: ReadonlyArray; /** * Optional provider name */ readonly provider?: string; /** * Indicates that the email failed to send */ readonly successful: false; }; /** * Generic result type */ interface Result { data?: T; error?: Error | unknown; success: boolean; } export { Attachment as A, BaseConfig as B, CalendarEventOptions as C, EmailOptions as E, FeatureFlags as F, ImmutableHeaders as I, MaybePromise as M, Priority as P, Result as R, EmailResult as a, Receipt as b, EmailAddress as c, EmailTag as d, EmailHeaders as e };