/** * Unified `EmailEvent` stream that merges send-side events (queued, * attempt, success, error) with webhook-side events (delivered, opened, * clicked, bounced, complained, unsubscribed). * * Feeds observability dashboards and audit logs without the consumer * having to stitch webhook + send sources by hand. * * @module */ import type { EmailDriver, Middleware } from "../types.mjs"; export type EmailEventType = "send.queued" | "send.attempt" | "send.success" | "send.error" | "delivered" | "opened" | "clicked" | "bounced" | "complained" | "unsubscribed" | "spam_reported"; export interface EmailEvent { type: EmailEventType; messageId?: string; recipient?: string; provider: string; at: Date; meta?: Record; } export interface EventStore { append: (event: EmailEvent) => void | Promise; list?: (messageId: string) => EmailEvent[] | Promise; } export interface MemoryEventStoreOptions { capacity?: number; } export declare function memoryEventStore(opts?: MemoryEventStoreOptions): EventStore; /** Emit `send.*` events around a driver's send call. Pair with webhook * ingestion (which already emits delivered/opened/bounced etc.) by * piping both into the same store. */ export declare function withEvents(driver: EmailDriver, bus: { emit: (event: EmailEvent) => void; }): EmailDriver; /** Tiny event bus: emit → listeners. Plug a store as a listener. */ export declare class EventBus { private listeners; emit(event: EmailEvent): void; on(listener: (event: EmailEvent) => void): () => void; } /** Observability middleware — wires `EmailMessage` beforeSend/afterSend * into a user-supplied event bus. Alternative to `withEvents` when * you want a Middleware shape. */ export declare function eventsMiddleware(bus: EventBus): Middleware;