import type { Context, Hono } from 'hono' const registry = new WeakMap, Sender>() /** Transactional email sender shared by authentication and route groups. */ export type Sender = { /** Console URL embedded in email links. Defaults to the hosted console. */ consoleUrl?: string | undefined /** Sender address for transactional emails. */ from: string /** Sends one message. */ send: (message: Message) => Promise } /** One transactional email message. */ export type Message = { /** Sender address. */ from: string /** HTML body. */ html?: string | undefined /** Subject line. */ subject: string /** Plain-text body. */ text: string /** Recipient address. */ to: string } /** Hono environment variables for transactional email delivery. */ export type Variables = { /** Transactional email sender; undefined when dispatch is disabled. */ email: Sender | undefined } /** Attaches a legacy group-level sender for `App.create` to collect on mount. */ export function attach>( app: app, sender: Sender | undefined, ): app { if (sender) registry.set(app, sender) return app } /** Returns the app's transactional email sender, when configured. */ export function get( c: Context, ): Sender | undefined { return c.get('email') } /** Returns a group-level sender attached for backward compatibility. */ export function read(app: Hono): Sender | undefined { return registry.get(app) }