UNPKG

alepha

Version:

Alepha is a convention-driven TypeScript framework for building robust, end-to-end type-safe applications, from serverless APIs to full-stack React apps.

144 lines (143 loc) 4.22 kB
import * as _alepha_core1 from "alepha"; import * as _alepha_logger0 from "alepha/logger"; import { Transporter } from "nodemailer"; //#region src/providers/EmailProvider.d.ts /** * Email provider interface. * * All methods are asynchronous and return promises. */ declare abstract class EmailProvider { /** * Send an email. * * @return Promise that resolves when the email is sent. */ abstract send(options: EmailSendOptions): Promise<void>; } type EmailSendOptions = { to: string | string[]; subject: string; body: string; }; //#endregion //#region src/errors/EmailError.d.ts declare class EmailError extends Error { constructor(message: string, cause?: Error); } //#endregion //#region src/providers/LocalEmailProvider.d.ts interface LocalEmailProviderOptions { /** * Directory to save email files. * @default "node_modules/.email" (relative to project root) */ directory?: string; } declare class LocalEmailProvider implements EmailProvider { protected readonly log: _alepha_logger0.Logger; protected readonly directory: string; constructor(options?: LocalEmailProviderOptions); send(options: EmailSendOptions): Promise<void>; createEmailHtml(options: { to: string; subject: string; body: string; }): string; escapeHtml(text: string): string; } //#endregion //#region src/providers/MemoryEmailProvider.d.ts interface EmailRecord { to: string; subject: string; body: string; sentAt: Date; } declare class MemoryEmailProvider implements EmailProvider { protected readonly log: _alepha_logger0.Logger; records: EmailRecord[]; send(options: EmailSendOptions): Promise<void>; /** * Get the last email sent (for testing purposes). */ get last(): EmailRecord | undefined; } //#endregion //#region src/providers/NodemailerEmailProvider.d.ts interface NodemailerEmailProviderOptions { /** * Custom transporter configuration. * If provided, will override environment variables. */ transporter?: Transporter; /** * Custom from email address. * If not provided, will use EMAIL_FROM from environment. */ from?: string; /** * Additional nodemailer options. */ options?: { pool?: boolean; maxConnections?: number; maxMessages?: number; rateDelta?: number; rateLimit?: number; }; } declare class NodemailerEmailProvider implements EmailProvider { protected readonly env: { EMAIL_HOST: string; EMAIL_PORT: number; EMAIL_USER: string; EMAIL_PASS: string; EMAIL_FROM: string; EMAIL_SECURE: boolean; }; protected readonly log: _alepha_logger0.Logger; protected transporter: Transporter; protected fromAddress: string; readonly options: NodemailerEmailProviderOptions; constructor(); send(options: EmailSendOptions): Promise<void>; protected createTransporter(): Transporter; /** * Verify the connection to the email server. */ verify(): Promise<boolean>; /** * Close the transporter connection. */ close(): void; protected readonly onStart: _alepha_core1.HookDescriptor<"start">; protected readonly onStop: _alepha_core1.HookDescriptor<"stop">; } //#endregion //#region src/index.d.ts declare module "alepha" { interface Hooks { "email:sending": { to: string | string[]; template: string; variables: Record<string, unknown>; provider: EmailProvider; abort(): void; }; } } /** * Provides email sending capabilities for Alepha applications with multiple provider backends. * * The email module enables declarative email sending through the `$email` descriptor, allowing you to send * emails through different providers: memory (for testing), local file system, or SMTP via Nodemailer. * It supports HTML email content and automatic provider selection based on environment configuration. * * @see {@link EmailProvider} * @module alepha.email */ declare const AlephaEmail: _alepha_core1.Service<_alepha_core1.Module<{}>>; //#endregion export { AlephaEmail, EmailError, EmailProvider, EmailRecord, EmailSendOptions, LocalEmailProvider, LocalEmailProviderOptions, MemoryEmailProvider, NodemailerEmailProvider, NodemailerEmailProviderOptions }; //# sourceMappingURL=index.d.ts.map