// ╔═══════╗╔═══════╗╔════╗╔═╗╔═══════╗ ╔═══════╗╔═══════╗╔════╗╔═╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗ ╔═══════╗╔═══════╗ // ║ ╔═════╝║ ╔═════╝║ ╔╗ ║║ ║╚╗ ╔══╗ ║ ║ ╔╗ ╔╗ ║║ ╔═══╗ ║║ ╔╗ ║║ ║║ ╔═══╗ ║║ ╔═════╝║ ╔═════╝║ ╔═══╗ ║ ╚══╗ ╔══╝║ ╔═════╝ // ║ ╚═════╗║ ╚═════╗║ ║║ ║║ ║ ║ ║ ║ ║╔═══════╗║ ║║ ║║ ║║ ╚═══╝ ║║ ║║ ║║ ║║ ╚═══╝ ║║ ║ ╔═══╗║ ╚═════╗║ ╚═══╝ ║ ║ ║ ║ ╚═════╗ // ╚═════╗ ║║ ╔═════╝║ ║║ ║║ ║ ║ ║ ║ ║╚═══════╝║ ║║ ║║ ║║ ╔═══╗ ║║ ║║ ║║ ║║ ╔═══╗ ║║ ║ ╚═╗ ║║ ╔═════╝║ ╔═╗ ╔═╝ ║ ║ ╚═════╗ ║ // ╔═════╝ ║║ ╚═════╗║ ║║ ╚╝ ║╔╝ ╚══╝ ║ ║ ║║ ║║ ║║ ║ ║ ║║ ║║ ╚╝ ║║ ║ ║ ║║ ╚═══╝ ║║ ╚═════╗║ ║ ║ ╚═╗╔═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═══════╝╚═╝╚════╝╚═══════╝ ╚═╝╚═╝╚═╝╚═╝ ╚═╝╚═╝╚════╝╚═╝ ╚═╝╚═══════╝╚═══════╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═══════╝ // ╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗ // ╚══╗ ╔══╝║ ╔╗ ╔╗ ║║ ╔═══╗ ║║ ╔═══╗ ║║ ╔═══╗ ║╚══╗ ╔══╝║ ╔═════╝ // ║ ║ ║ ║║ ║║ ║║ ╚═══╝ ║║ ║ ║ ║║ ╚═══╝ ║ ║ ║ ║ ╚═════╗ // ║ ║ ║ ║║ ║║ ║║ ╔═════╝║ ║ ║ ║║ ╔═╗ ╔═╝ ║ ║ ╚═════╗ ║ // ╔══╝ ╚══╗║ ║║ ║║ ║║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═╝╚═╝╚═╝╚═╝ ╚═══════╝╚═╝ ╚═══╝ ╚═╝ ╚═══════╝ import * as messageValidators from '../../validators/message-validators.js'; import * as messageTypings from '../../typings/message-typings.js'; import * as apiKeyEngine from '../../../api-key-engine/api-key-engine.js'; import * as regionEngine from '../../../region-engine/region-engine.js'; import * as domainEngine from '../../../domain-engine/domain-engine.js'; import * as utilityEngine from '@xyz.warpmatter.com/utility-engine'; // ╔═══════╗╔════╗╔═╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗╔═══════╗ // ║ ╔═════╝╚══╗ ║║ ║║ ╔═══╗ ║║ ╔═══╗ ║║ ╔═══╗ ║╚══╗ ╔══╝║ ╔═════╝ // ║ ╚═════╗╔══╝ ╚╝ ║║ ╚═══╝ ║║ ║ ║ ║║ ╚═══╝ ║ ║ ║ ║ ╚═════╗ // ║ ╔═════╝║ ╔╗ ╔══╝║ ╔═════╝║ ║ ║ ║║ ╔═╗ ╔═╝ ║ ║ ╚═════╗ ║ // ║ ╚═════╗║ ║║ ╚══╗║ ║ ║ ╚═══╝ ║║ ║ ║ ╚═╗ ║ ║ ╔═════╝ ║ // ╚═══════╝╚═╝╚════╝╚═╝ ╚═══════╝╚═╝ ╚═══╝ ╚═╝ ╚═══════╝ export * from './template/template-sender.js'; import fetchHelper from 'node-fetch'; // ╔═══════╗╔═══════╗╔════╗╔═╗╔═══════╗ // ║ ╔═════╝║ ╔═════╝║ ╔╗ ║║ ║╚╗ ╔══╗ ║ // ║ ╚═════╗║ ╚═════╗║ ║║ ║║ ║ ║ ║ ║ ║ // ╚═════╗ ║║ ╔═════╝║ ║║ ║║ ║ ║ ║ ║ ║ // ╔═════╝ ║║ ╚═════╗║ ║║ ╚╝ ║╔╝ ╚══╝ ║ // ╚═══════╝╚═══════╝╚═╝╚════╝╚═══════╝ export async function sendMessage(parameters: messageTypings.SendMessageParameters) { let { apiKey, region, domain, to = [], cc = [], bcc = [], from, subject, } = parameters; to = utilityEngine.isArray(to) ? to : [to]; cc = utilityEngine.isArray(cc) ? cc : [cc]; bcc = utilityEngine.isArray(bcc) ? bcc : [bcc]; apiKeyEngine.validateApiKey(apiKey); domainEngine.validateDomainName(domain); regionEngine.validateRegionName(region); messageValidators.validateFromSender(from); messageValidators.validateToRecipients(to); messageValidators.validateCcRecipients(cc); messageValidators.validateBccRecipients(bcc); messageValidators.validateMessageSubject(subject); const authorization = `Basic ${Buffer.from(`api:${apiKey}`).toString('base64')}`; const url = `https://${region}/v3/${domain}/messages`; const response = await fetchHelper(url, { method: 'post', headers: { authorization, 'Cache-Control': 'no-cache', 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams(Object.entries(parameters)), }); return response?.status === 200; }