import {Options} from "nodemailer/lib/mailer"; import {ParsedUrlQueryInput} from "querystring"; import MailError from "./MailError"; import MailTemplate from "./MailTemplate"; export default class Mail { private readonly options: Options = {}; public constructor( private readonly template: MailTemplate, private readonly data: ParsedUrlQueryInput = {}, ) { this.options.subject = this.template.getSubject(data); this.verifyData(); } private verifyData() { for (const forbiddenField of [ 'to', ]) { if (this.data[forbiddenField] !== undefined) { throw new MailError(`Can't use reserved data.${forbiddenField}.`); } } } public getTemplate(): MailTemplate { return this.template; } public getData(): ParsedUrlQueryInput { return {...this.data}; } public getOptions(): Options { return {...this.options}; } }