UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.6 kB
{"version":3,"file":"send-external.mjs","names":["constants","emailServices.sendEmail"],"sources":["../../../src/services/email/send-external.ts"],"sourcesContent":["import constants from \"../../constants/constants.js\";\nimport type { EmailStorageConfig } from \"../../libs/email/storage/types.js\";\nimport type {\n\tEmailAttachment,\n\tEmailPriority,\n\tEmailSubject,\n} from \"../../libs/email/types.js\";\nimport { copy } from \"../../libs/i18n/index.js\";\nimport type { Email } from \"../../types/response.js\";\nimport serviceWrapper from \"../../utils/services/service-wrapper.js\";\nimport type { ServiceFn } from \"../../utils/services/types.js\";\nimport { emailServices } from \"../index.js\";\n\nconst sendExternal: ServiceFn<\n\t[\n\t\t{\n\t\t\tto: string;\n\t\t\tsubject: EmailSubject;\n\t\t\ttemplate: string;\n\t\t\tcc?: string;\n\t\t\tbcc?: string;\n\t\t\treplyTo?: string;\n\t\t\tpriority?: EmailPriority;\n\t\t\tattachments?: EmailAttachment[];\n\t\t\tdata: {\n\t\t\t\t[key: string]: unknown;\n\t\t\t};\n\t\t\tstorage?: EmailStorageConfig;\n\t\t\ttenantKey?: string | null;\n\t\t\tfrom?: {\n\t\t\t\temail?: string;\n\t\t\t\tname?: string;\n\t\t\t};\n\t\t},\n\t],\n\t{\n\t\tjobId: string;\n\t\temail: Email;\n\t}\n> = async (context, data) => {\n\tconst internalTemplate = Object.values(constants.email.templates).find(\n\t\t(template) => template.key === data.template && template.external === false,\n\t);\n\n\tif (internalTemplate) {\n\t\treturn {\n\t\t\terror: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tstatus: 400,\n\t\t\t\tmessage: copy(\"server:core.email.templates.internal.only\"),\n\t\t\t},\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\treturn serviceWrapper(emailServices.sendEmail, {\n\t\ttransaction: true,\n\t})(context, {\n\t\ttype: \"external\",\n\t\tto: data.to,\n\t\tsubject: data.subject,\n\t\ttemplate: data.template,\n\t\tcc: data.cc,\n\t\tbcc: data.bcc,\n\t\treplyTo: data.replyTo,\n\t\tpriority: data.priority,\n\t\tattachments: data.attachments,\n\t\tdata: data.data,\n\t\tstorage: data.storage,\n\t\ttenantKey: data.tenantKey,\n\t\tfrom: data.from,\n\t});\n};\n\nexport default sendExternal;\n"],"mappings":"qLAaA,MAAM,EA0BF,MAAO,EAAS,IACM,OAAO,OAAOA,EAAU,MAAM,SAAS,CAAC,CAAC,KAChE,GAAa,EAAS,MAAQ,EAAK,UAAY,EAAS,WAAa,EAGpD,EACX,CACN,MAAO,CACN,KAAM,QACN,OAAQ,IACR,QAAS,EAAK,2CAA2C,CAC1D,EACA,KAAM,IAAA,EACP,EAGM,EAAeC,EAAyB,CAC9C,YAAa,EACd,CAAC,CAAC,CAAC,EAAS,CACX,KAAM,WACN,GAAI,EAAK,GACT,QAAS,EAAK,QACd,SAAU,EAAK,SACf,GAAI,EAAK,GACT,IAAK,EAAK,IACV,QAAS,EAAK,QACd,SAAU,EAAK,SACf,YAAa,EAAK,YAClB,KAAM,EAAK,KACX,QAAS,EAAK,QACd,UAAW,EAAK,UAChB,KAAM,EAAK,IACZ,CAAC"}