import * as _$_forinda_kickjs0 from "@forinda/kickjs"; //#region src/types.d.ts interface MailAddress { name?: string; address: string; } type MailRecipient = string | MailAddress; interface MailAttachment { filename: string; content?: string | Buffer; path?: string; contentType?: string; encoding?: string; } interface MailMessage { /** Sender address */ from?: MailRecipient; /** Recipient(s) */ to: MailRecipient | MailRecipient[]; /** CC recipient(s) */ cc?: MailRecipient | MailRecipient[]; /** BCC recipient(s) */ bcc?: MailRecipient | MailRecipient[]; /** Reply-to address */ replyTo?: MailRecipient; /** Email subject */ subject: string; /** Plain text body */ text?: string; /** HTML body */ html?: string; /** File attachments */ attachments?: MailAttachment[]; /** Custom headers */ headers?: Record; /** Provider-specific options (e.g. Resend tags, SES configuration set) */ metadata?: Record; } interface MailResult { /** Provider-assigned message ID */ messageId: string; /** Whether the send was accepted (does not guarantee delivery) */ accepted: boolean; /** Raw response from the provider */ raw?: any; } /** * Template engine for rendering email bodies. * Implement this to use EJS, Handlebars, Pug, or any template system. * * @example * ```ts * import Handlebars from 'handlebars' * * class HandlebarsEngine implements MailTemplateEngine { * private templates = new Map() * * register(name: string, source: string) { * this.templates.set(name, Handlebars.compile(source)) * } * * async render(template: string, data: any) { * const fn = this.templates.get(template) * if (!fn) throw new Error(`Template "${template}" not found`) * return fn(data) * } * } * ``` */ interface MailTemplateEngine { /** Render a named template with data. Returns HTML string. */ render(template: string, data: Record): Promise | string; } /** * Abstract mail provider. Implement this to use any email service: * SMTP (nodemailer), Resend, AWS SES, SendGrid, Postmark, Mailgun, etc. * * @example * ```ts * class ResendProvider implements MailProvider { * name = 'resend' * private client: Resend * * constructor(apiKey: string) { * this.client = new Resend(apiKey) * } * * async send(message: MailMessage): Promise { * const { data, error } = await this.client.emails.send({ * from: formatAddress(message.from), * to: formatRecipients(message.to), * subject: message.subject, * html: message.html, * text: message.text, * }) * if (error) throw error * return { messageId: data.id, accepted: true, raw: data } * } * } * ``` */ interface MailProvider { /** Provider name for logging */ name: string; /** Send an email message */ send(message: MailMessage): Promise; /** Optional cleanup (close connections, etc.) */ shutdown?(): Promise; } interface MailerOptions { /** Mail provider to use */ provider: MailProvider; /** Default "from" address for all emails */ defaultFrom?: MailRecipient; /** Optional template engine for rendering HTML from templates */ templateEngine?: MailTemplateEngine; /** Enable/disable sending (useful for testing — logs instead of sending) */ enabled?: boolean; } //#endregion //#region src/mailer.service.d.ts /** DI token for resolving MailerService from the container. */ declare const MAILER: _$_forinda_kickjs0.InjectionToken; /** * Central mail service — send emails through any provider. * * @example * ```ts * @Service() * class UserService { * constructor(@Inject(MAILER) private mailer: MailerService) {} * * async sendWelcome(user: User) { * await this.mailer.send({ * to: user.email, * subject: 'Welcome!', * html: '

Welcome to our app

', * }) * } * * // Or with templates: * async sendInvoice(user: User, invoice: Invoice) { * await this.mailer.sendTemplate('invoice', { * to: user.email, * subject: `Invoice #${invoice.number}`, * }, { user, invoice }) * } * } * ``` */ declare class MailerService { private readonly provider; private readonly defaultFrom?; private readonly templateEngine?; private readonly enabled; /** Total messages successfully accepted by the provider. */ sentCount: number; /** Total messages that threw inside provider.send(). */ failedCount: number; /** Total messages skipped because `enabled = false` (dry-run mode). */ dryRunCount: number; constructor(options: MailerOptions); /** * Send an email message. * Applies defaultFrom if no from address is set. */ send(message: MailMessage): Promise; /** * Render a template and send the resulting HTML as an email. * Requires a templateEngine to be configured. * * @param template - Template name (resolved by the engine) * @param message - Mail message (html will be overwritten by the rendered template) * @param data - Template variables */ sendTemplate(template: string, message: Omit, data: Record): Promise; /** Get the underlying provider (for advanced use) */ getProvider(): MailProvider; /** Shutdown the provider */ shutdown(): Promise; } //#endregion //#region src/adapter.d.ts /** * Mailer adapter — registers MailerService in the DI container. * * @example * ```ts * import { MailerAdapter, SmtpProvider } from '@forinda/kickjs-mailer' * * bootstrap({ * adapters: [ * MailerAdapter({ * provider: new SmtpProvider({ host: 'smtp.gmail.com', port: 587, auth: { ... } }), * defaultFrom: { name: 'My App', address: 'noreply@myapp.com' }, * }), * ], * }) * * // Multiple providers via .scoped() — e.g. transactional + marketing pipelines: * bootstrap({ * adapters: [ * MailerAdapter.scoped('transactional', { provider: new ResendProvider({ ... }) }), * MailerAdapter.scoped('marketing', { provider: new SesProvider({ ... }) }), * ], * }) * ``` */ declare const MailerAdapter: _$_forinda_kickjs0.AdapterFactory; //#endregion //#region src/providers/smtp.provider.d.ts interface SmtpOptions { /** SMTP host (e.g. 'smtp.gmail.com', 'smtp.resend.com') */ host: string; /** SMTP port (default: 587) */ port?: number; /** Use TLS (default: true for port 465, false otherwise) */ secure?: boolean; /** Authentication credentials */ auth?: { user: string; pass: string; }; /** Connection timeout in ms (default: 10000) */ connectionTimeout?: number; } /** * SMTP mail provider using nodemailer. * * Requires `nodemailer` as a peer dependency: * ```bash * pnpm add nodemailer @types/nodemailer * ``` * * @example * ```ts * // Gmail * new SmtpProvider({ * host: 'smtp.gmail.com', * port: 587, * auth: { user: 'you@gmail.com', pass: 'app-password' }, * }) * * // Resend via SMTP * new SmtpProvider({ * host: 'smtp.resend.com', * port: 465, * secure: true, * auth: { user: 'resend', pass: getEnv('RESEND_API_KEY') }, * }) * * // Mailpit (local dev) * new SmtpProvider({ host: 'localhost', port: 1025 }) * ``` */ declare class SmtpProvider implements MailProvider { private options; name: string; private transporter; constructor(options: SmtpOptions); private ensureTransporter; send(message: MailMessage): Promise; shutdown(): Promise; } //#endregion //#region src/providers/console.provider.d.ts /** * Console mail provider — logs emails instead of sending them. * Perfect for development and testing. * * @example * ```ts * MailerAdapter({ * provider: new ConsoleProvider(), * defaultFrom: 'dev@localhost', * }) * ``` */ declare class ConsoleProvider implements MailProvider { name: string; send(message: MailMessage): Promise; } //#endregion export { ConsoleProvider, MAILER, type MailAddress, type MailAttachment, type MailMessage, type MailProvider, type MailRecipient, type MailResult, type MailTemplateEngine, MailerAdapter, type MailerOptions, MailerService, type SmtpOptions, SmtpProvider }; //# sourceMappingURL=index.d.mts.map