UNPKG

@node-notifications/transport-mailer

Version:
25 lines (24 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MailDataProvider = void 0; class MailDataProvider { prepareTransportData(notification, transportData) { var _a, _b, _c; if (!((_a = notification.recipient) === null || _a === void 0 ? void 0 : _a.email)) { throw new Error(`Undefined email for recipient: ${JSON.stringify(notification.recipient)}`); } if (notification.sender && !notification.sender.email) { throw new Error(`Undefined email for sender: ${JSON.stringify(notification.sender)}`); } const mailerData = { to: `${notification.recipient.email} ${(_b = notification.recipient.name) !== null && _b !== void 0 ? _b : ''}`, subject: typeof notification.data === 'string' ? undefined : notification.data.subject, html: typeof notification.data === 'string' ? notification.data : notification.data.body, }; if (notification.sender) { mailerData.from = `${notification.sender.email} ${(_c = notification.sender.name) !== null && _c !== void 0 ? _c : ''}`; } return Promise.resolve(Object.assign(Object.assign({}, mailerData), transportData)); } } exports.MailDataProvider = MailDataProvider;