UNPKG

unemail

Version:

A modern TypeScript email library with zero dependencies, supporting multiple providers including AWS SES, Resend, MailCrab, and HTTP APIs

66 lines (63 loc) 2.35 kB
import { Provider, ProviderFactory } from './providers/base.mjs'; export { defineProvider } from './providers/base.mjs'; import { EmailOptions, BaseConfig, EmailServiceConfig, Result, EmailResult } from 'unemail/types'; /** * Provider options - can be a provider factory, instance, or config with a provider name */ type ProviderOption<ConfigT = any, InstanceT = any, OptsT extends EmailOptions = EmailOptions> = Provider<ConfigT, InstanceT, OptsT> | ProviderFactory<ConfigT, InstanceT, OptsT> | { name: string; options?: Record<string, any>; }; interface EmailServiceOptions<ConfigT = any, InstanceT = any, OptsT extends EmailOptions = EmailOptions> extends BaseConfig { provider?: ProviderOption<ConfigT, InstanceT, OptsT>; config?: EmailServiceConfig; } /** * Main email service class */ declare class EmailService<OptsT extends EmailOptions = EmailOptions> { private provider; private options; private initialized; /** * Creates a new email service instance * * @param options Configuration options for the email service */ constructor(options?: EmailServiceOptions<any, any, OptsT>); /** * Get the provider instance */ private getProvider; /** * Initializes the email service and underlying provider */ initialize(): Promise<void>; /** * Checks if the configured provider is available * * @returns Promise resolving to a boolean indicating availability */ isAvailable(): Promise<boolean>; /** * Sends an email using the configured provider * * @param options Email sending options * @returns Promise resolving to email result */ sendEmail(options: OptsT): Promise<Result<EmailResult>>; /** * Validates credentials for the current provider * * @returns Promise resolving to a boolean indicating if credentials are valid */ validateCredentials(): Promise<boolean>; } /** * Creates an email service with the given configuration * * @param options Configuration options for the email service * @returns Configured email service instance */ declare function createEmailService<OptsT extends EmailOptions = EmailOptions>(options?: EmailServiceOptions<any, any, OptsT>): EmailService<OptsT>; export { EmailService, Provider, ProviderFactory, createEmailService };