/** * SMTP client implementation. * * Uses the native SMTP plugin type from @superblocksteam/types. * Sends emails with support for CC, BCC, reply-to, and attachments. */ import type { PartialMessage } from "@bufbuild/protobuf"; import type { Plugin as SmtpPlugin } from "@superblocksteam/types/dist/src/plugins/smtp/v1/plugin_pb"; import { IntegrationError } from "../../runtime/errors.js"; import type { QueryExecutor, TraceMetadata } from "../registry.js"; import type { IntegrationConfig, IntegrationClientImpl } from "../types.js"; import type { SmtpClient, SmtpSendOptions } from "./types.js"; /** * SMTP request type derived from proto definition. */ type SmtpRequest = PartialMessage; /** * Internal implementation of SmtpClient. * * Constructs SMTP plugin requests matching the proto schema * and executes them via the orchestrator. */ export class SmtpClientImpl implements SmtpClient, IntegrationClientImpl { readonly config: IntegrationConfig; private readonly executeQuery: QueryExecutor; constructor(config: IntegrationConfig, executeQuery: QueryExecutor) { this.config = config; this.executeQuery = executeQuery; } get name(): string { return this.config.name; } get pluginId(): string { return this.config.pluginId; } async send( options: SmtpSendOptions, metadata?: TraceMetadata, ): Promise { const request: SmtpRequest = { from: options.from, to: options.to, subject: options.subject, body: options.body, cc: options.cc ?? "", bcc: options.bcc ?? "", replyTo: options.replyTo ?? "", attachments: options.attachments ?? "", }; try { return await this.executeQuery( request as Record, undefined, metadata, ); } catch (error) { if (error instanceof IntegrationError) { throw error; } throw new IntegrationError(this.config.name, "send", error); } } }