@visulima/email
Version:
A comprehensive email library with multi-provider support, crypto utilities, and template engines
70 lines (69 loc) • 2.74 kB
TypeScript
import EmailError from "../../errors/email-error.d.ts";
import type { MaybePromise } from "../../types.d.ts";
/**
* Logger interface with debug, error, info, and warn methods
*/
type Logger = {
debug: (message: string, ...args: unknown[]) => void;
error: (message: string, ...args: unknown[]) => void;
info: (message: string, ...args: unknown[]) => void;
warn: (message: string, ...args: unknown[]) => void;
};
/**
* Common provider configuration interface
*/
export interface BaseProviderConfig {
debug?: boolean;
logger?: Console;
timeout?: number;
}
/**
* Provider initialization state management
*/
export declare class ProviderState {
private isInitialized;
/**
* Checks if the provider has been initialized.
* @returns True if the provider is initialized, false otherwise.
*/
get initialized(): boolean;
/**
* Marks the provider as initialized.
*/
setInitialized(): void;
/**
* Ensures the provider is initialized, initializing it if not already done.
* @param initializeFunction The function to call for initialization.
* @param providerName The name of the provider (for error messages).
* @throws {EmailError} When initialization fails.
*/
ensureInitialized(initializeFunction: () => MaybePromise<void>, providerName: string): Promise<void>;
}
/**
* Creates a logger instance for a provider.
* @param providerName The name of the provider (used as prefix in log messages).
* @param customLogger Optional Console instance for logging output.
* @returns A logger instance with debug, error, info, and warn methods.
*/
export declare const createProviderLogger: (providerName: string, customLogger?: Console) => Logger;
/**
* Checks if an HTTP response indicates success (2xx status codes).
* @param result The result object containing response data and success status.
* @param result.data The response data object.
* @param result.success The success flag indicating if the request was successful.
* @returns True if the response indicates success, false otherwise.
*/
export declare const isSuccessfulResponse: (result: {
data?: unknown;
success: boolean;
}) => boolean;
/**
* Handles errors from provider operations and converts them to EmailError instances.
* @param providerName The name of the provider where the error occurred.
* @param operation The operation that failed.
* @param error The error that occurred.
* @param logger Optional logger instance for debug messages.
* @returns An EmailError instance with appropriate error information.
*/
export declare const handleProviderError: (providerName: string, operation: string, error: unknown, logger?: Logger) => EmailError;
export {};