export interface SendEmailInput { to: string; subject: string; text: string; } export interface EmailTransport { send(input: SendEmailInput): Promise; } export function createEmailTransport(config: { provider: string; from: string; apiKey: string; }): EmailTransport { if (config.provider === "example") { return { async send(input) { console.log( JSON.stringify({ service: "email", provider: config.provider, mode: "debug_redacted", from: config.from, to: input.to, subject: input.subject, textPreview: redactEmailText(input.text), }), ); }, }; } throw new Error(`Unsupported email provider: ${config.provider}`); } function redactEmailText(text: string): string { return text.replace(/([?&]token=)[^&\s]+/gi, "$1[REDACTED]"); }