@visulima/email 1.0.0-alpha.34 → 1.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +77 -0
- package/dist/crypto/index.d.ts +160 -3
- package/dist/crypto/index.js +1 -1
- package/dist/deliverability/dmarc-report.d.ts +95 -0
- package/dist/deliverability/dmarc-report.js +1 -0
- package/dist/deliverability/index.d.ts +360 -0
- package/dist/deliverability/index.js +1 -0
- package/dist/events/index.d.ts +31 -0
- package/dist/events/index.js +1 -0
- package/dist/inbound/index.d.ts +375 -0
- package/dist/inbound/index.js +1 -0
- package/dist/index.d.ts +11 -734
- package/dist/index.js +1 -1
- package/dist/middleware/index.d.ts +346 -0
- package/dist/middleware/index.js +1 -0
- package/dist/packem_shared/ALL_EVENTS-A0nTVOo0.js +1 -0
- package/dist/packem_shared/DkimSigner-dKZ45Csc.js +18 -0
- package/dist/packem_shared/Mail-B2QII2P9.js +1 -0
- package/dist/packem_shared/{MailMessage-BvaH5tZZ.js → MailMessage-DB1zaWfM.js} +1 -1
- package/dist/packem_shared/MemoryEventStore-BEKPxa-I.js +1 -0
- package/dist/packem_shared/MemoryQueue-C-CtRRG7.js +1 -0
- package/dist/packem_shared/MemorySuppressionStore-BKY1FrA1.js +1 -0
- package/dist/packem_shared/RATE_LIMIT_PRESETS-DQF78mdO.js +1 -0
- package/dist/packem_shared/{SmimeEncrypter-ZhHEgDwY.js → SmimeEncrypter-BirIsrip.js} +2 -2
- package/dist/packem_shared/{SmimeSigner-CYSVF6ez.js → SmimeSigner-CkyaShTs.js} +2 -2
- package/dist/packem_shared/addDarkModeSupport-Ys9U2-GH.js +1 -0
- package/dist/packem_shared/address-formatter-CnPg51_n.js +1 -0
- package/dist/packem_shared/ahaSendProvider-yuqYMW0n.js +1 -0
- package/dist/packem_shared/arcMessageSignatureBase-Cpdnv-H8.js +17 -0
- package/dist/packem_shared/attachment-processor-CFUC3V45.js +1 -0
- package/dist/packem_shared/azureProvider-CK_Wuw4r.js +1 -0
- package/dist/packem_shared/brevoProvider-CNwuzzBA.js +1 -0
- package/dist/packem_shared/build-mime-message-D8WEZejb.js +3 -0
- package/dist/packem_shared/buildListUnsubscribe-CIbz0rtk.js +1 -0
- package/dist/packem_shared/circuitBreakerMiddleware-B7DlzZSG.js +1 -0
- package/dist/packem_shared/cloudflareEmailProvider-C-G821Hg.js +1 -0
- package/dist/packem_shared/composeMiddleware-CkEhbDjL.js +1 -0
- package/dist/packem_shared/createTestEmail-hHdtgmUM.js +1 -0
- package/dist/packem_shared/createWorker-Nkc1GHet.js +1 -0
- package/dist/packem_shared/dedupeMiddleware-JeJbff46.js +1 -0
- package/dist/packem_shared/{detectMimeType-bo5oxfnt.js → detectMimeType-B4QMh7k8.js} +1 -1
- package/dist/packem_shared/emailMatchers-CLANeU71.js +1 -0
- package/dist/packem_shared/event-bus.d-DEl3w_EW.d.ts +104 -0
- package/dist/packem_shared/extractReply-CCWnNRWe.js +5 -0
- package/dist/packem_shared/filterSuppressed-DntqRV0q.js +1 -0
- package/dist/packem_shared/format-address-Cv6uWTS5.js +1 -0
- package/dist/packem_shared/infobipProvider-DdV62IAG.js +1 -0
- package/dist/packem_shared/injectPreheader-BxPjb0eJ.js +1 -0
- package/dist/packem_shared/inlineCss-BLaEi337.js +1 -0
- package/dist/packem_shared/isValidSigningCertUrl-CF_KuCAi.js +3 -0
- package/dist/packem_shared/loggingMiddleware-CyHzn37U.js +1 -0
- package/dist/packem_shared/loopsProvider-DSedSU3q.js +1 -0
- package/dist/packem_shared/mail.d-LmrdSngG.d.ts +861 -0
- package/dist/packem_shared/{mailCrabProvider-B7H6HwWu.js → mailCrabProvider-xSLhA1CY.js} +1 -1
- package/dist/packem_shared/mailPaceProvider-CWBIjvvJ.js +1 -0
- package/dist/packem_shared/mailchannelsProvider-zKcunGDQ.js +1 -0
- package/dist/packem_shared/mailerSendProvider-BEvPlBKB.js +1 -0
- package/dist/packem_shared/mailgunProvider-CfQAINTC.js +1 -0
- package/dist/packem_shared/mailjetProvider-DEfKptWc.js +1 -0
- package/dist/packem_shared/mailomatProvider-D5sHlxZh.js +1 -0
- package/dist/packem_shared/mailtrapProvider-DwgMKakk.js +1 -0
- package/dist/packem_shared/mandrillProvider-CdGjO3Td.js +1 -0
- package/dist/packem_shared/normalizeMessageId-B_9mXlh4.js +1 -0
- package/dist/packem_shared/oauth2Middleware-B1xz58iP.js +1 -0
- package/dist/packem_shared/parseAddress-CrYOac3K.js +1 -0
- package/dist/packem_shared/parseArfReport-CUHb8WVj.js +6 -0
- package/dist/packem_shared/parseCloudflareInbound-BGgH5u7M.js +1 -0
- package/dist/packem_shared/parseDmarcRecord-DjNqCMZc.js +1 -0
- package/dist/packem_shared/parseInbound-BP-gEjhh.js +1 -0
- package/dist/packem_shared/parseMailgunInbound-C3sZ1TiH.js +1 -0
- package/dist/packem_shared/parseMtaStsPolicy-rFOOVXXK.js +6 -0
- package/dist/packem_shared/parsePostmarkInbound-C0Ttfroo.js +1 -0
- package/dist/packem_shared/parseSendGridInbound-BkvaoYRl.js +4 -0
- package/dist/packem_shared/parseSesInbound-BFS--T8X.js +1 -0
- package/dist/packem_shared/parseTlsRptRecord-DnLwAWsk.js +1 -0
- package/dist/packem_shared/plunkProvider-BIhMU2b5.js +1 -0
- package/dist/packem_shared/postProcessHtml-C73e0b9H.js +1 -0
- package/dist/packem_shared/postalProvider-CmmbCZSi.js +1 -0
- package/dist/packem_shared/postmarkProvider-i9u0h26U.js +1 -0
- package/dist/packem_shared/provider-base-BpHE_uK8.js +1 -0
- package/dist/packem_shared/{provider.d-DcfYeGJJ.d.ts → provider.d-J-y6iogK.d.ts} +1 -1
- package/dist/packem_shared/{readFile-BAVMZg5e-C4whBIPd.js → readFile-BkNfutxp-BS8Q2183.js} +1 -1
- package/dist/packem_shared/resendProvider-BNduBn0w.js +1 -0
- package/dist/packem_shared/retry-UPd8F62N.js +1 -0
- package/dist/packem_shared/retryMiddleware-DHespsU2.js +1 -0
- package/dist/packem_shared/rewriteCidLinks-B-Sd5XHs.js +1 -0
- package/dist/packem_shared/scalewayProvider-8gb4sIOB.js +1 -0
- package/dist/packem_shared/sendGridProvider-CayLXvPO.js +1 -0
- package/dist/packem_shared/smtpProvider-DoXVsN4p.js +24 -0
- package/dist/packem_shared/sweegoProvider-C0g9Ajdn.js +1 -0
- package/dist/packem_shared/toEmailSnapshot-CYpMmnAA.js +1 -0
- package/dist/packem_shared/tracer.d-MU42G1jG.d.ts +494 -0
- package/dist/packem_shared/{types.d-CNnnk-Ya.d.ts → types.d-BId55FW2.d.ts} +6 -1
- package/dist/packem_shared/types.d-BMpI2UXj.d.ts +51 -0
- package/dist/packem_shared/types.d-CmoWvdZi.d.ts +61 -0
- package/dist/packem_shared/types.d-Mpu0HZoG.d.ts +24 -0
- package/dist/packem_shared/{types.d-wwpgA3to.d.ts → types.d-ejzh-xBP.d.ts} +6 -1
- package/dist/packem_shared/types.d-lcJZmwRK.d.ts +69 -0
- package/dist/packem_shared/utils-BwolsGlK.js +1 -0
- package/dist/packem_shared/verifyMailgunWebhook-Df7n2Quh.js +1 -0
- package/dist/packem_shared/verifyPostmarkWebhook-D_eXt_Lq.js +1 -0
- package/dist/packem_shared/verifySendGridWebhook-XOSj5yTe.js +1 -0
- package/dist/packem_shared/verifyStandardWebhook-DdUTlIVh.js +1 -0
- package/dist/packem_shared/withEvents-Q9bwpCFG.js +1 -0
- package/dist/packem_shared/withMetrics-BPs3Kdxn.js +1 -0
- package/dist/packem_shared/withRender-DQM2zbbI.js +1 -0
- package/dist/packem_shared/withSuppression-DfjV_tbI.js +1 -0
- package/dist/packem_shared/withTelemetry-CsQsv1DV.js +1 -0
- package/dist/packem_shared/zeptomailProvider-BIbHieGJ.js +1 -0
- package/dist/providers/ahasend/index.d.ts +3 -3
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/aws-ses/index.d.ts +3 -3
- package/dist/providers/azure/index.d.ts +3 -3
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.d.ts +3 -3
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/cloudflare-email/index.d.ts +36 -0
- package/dist/providers/cloudflare-email/index.js +1 -0
- package/dist/providers/failover/index.d.ts +3 -3
- package/dist/providers/http/index.d.ts +3 -3
- package/dist/providers/infobip/index.d.ts +3 -3
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/loops/index.d.ts +47 -0
- package/dist/providers/loops/index.js +1 -0
- package/dist/providers/mailchannels/index.d.ts +26 -0
- package/dist/providers/mailchannels/index.js +1 -0
- package/dist/providers/mailcrab/index.d.ts +3 -3
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.d.ts +3 -3
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.d.ts +3 -3
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.d.ts +3 -3
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.d.ts +3 -3
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.d.ts +3 -3
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.d.ts +3 -3
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.d.ts +3 -3
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/mock/index.d.ts +6 -53
- package/dist/providers/nodemailer/index.d.ts +3 -3
- package/dist/providers/opentelemetry/index.d.ts +3 -495
- package/dist/providers/plunk/index.d.ts +3 -3
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.d.ts +3 -3
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.d.ts +3 -3
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.d.ts +3 -3
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/roundrobin/index.d.ts +3 -3
- package/dist/providers/scaleway/index.d.ts +3 -3
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.d.ts +3 -3
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.d.ts +3 -3
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sweego/index.d.ts +3 -3
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.d.ts +3 -3
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/queue/bullmq-queue.d.ts +46 -0
- package/dist/queue/bullmq-queue.js +1 -0
- package/dist/queue/index.d.ts +148 -0
- package/dist/queue/index.js +1 -0
- package/dist/queue/pg-boss-queue.d.ts +41 -0
- package/dist/queue/pg-boss-queue.js +1 -0
- package/dist/queue/sqs-queue.d.ts +72 -0
- package/dist/queue/sqs-queue.js +1 -0
- package/dist/queue/unstorage-queue.d.ts +81 -0
- package/dist/queue/unstorage-queue.js +1 -0
- package/dist/render/index.d.ts +107 -0
- package/dist/render/index.js +1 -0
- package/dist/template-engines/i18n.d.ts +61 -0
- package/dist/template-engines/i18n.js +1 -0
- package/dist/template-engines/jsx-email.d.ts +11 -0
- package/dist/template-engines/jsx-email.js +1 -0
- package/dist/template-engines/liquid.d.ts +12 -0
- package/dist/template-engines/liquid.js +1 -0
- package/dist/test/index.d.ts +159 -0
- package/dist/test/index.js +1 -0
- package/dist/utils/format-email-address.d.ts +1 -1
- package/dist/utils/format-email-address.js +1 -1
- package/dist/utils/parse-address.d.ts +1 -1
- package/dist/utils/result.d.ts +49 -0
- package/dist/utils/result.js +1 -0
- package/dist/utils/validation/check-feature-support.d.ts +1 -1
- package/dist/webhooks/index.d.ts +231 -0
- package/dist/webhooks/index.js +1 -0
- package/package.json +115 -3
- package/dist/packem_shared/DkimSigner-CT2DSHD1.js +0 -18
- package/dist/packem_shared/Mail-BWSWWq6m.js +0 -1
- package/dist/packem_shared/address-formatter-Cm_E_ZMa.js +0 -1
- package/dist/packem_shared/ahaSendProvider-DOAAW65O.js +0 -1
- package/dist/packem_shared/attachment-processor-DsmIomKc.js +0 -1
- package/dist/packem_shared/azureProvider-EkNYKAiF.js +0 -1
- package/dist/packem_shared/brevoProvider-CkR4U4RD.js +0 -1
- package/dist/packem_shared/build-mime-message-6xstxaUV.js +0 -2
- package/dist/packem_shared/infobipProvider-BhTsWi7e.js +0 -1
- package/dist/packem_shared/mailPaceProvider-DRt6Z9Hr.js +0 -1
- package/dist/packem_shared/mailerSendProvider-Dx_iHInH.js +0 -1
- package/dist/packem_shared/mailgunProvider-ChkLGZZW.js +0 -1
- package/dist/packem_shared/mailjetProvider-BMRhNe6H.js +0 -1
- package/dist/packem_shared/mailomatProvider-CydV-JB6.js +0 -1
- package/dist/packem_shared/mailtrapProvider-CuAfJWDr.js +0 -1
- package/dist/packem_shared/mandrillProvider-BBeLbaw0.js +0 -1
- package/dist/packem_shared/plunkProvider-BQyjG6YT.js +0 -1
- package/dist/packem_shared/postalProvider-DPHQ620q.js +0 -1
- package/dist/packem_shared/postmarkProvider-bMTC2gdJ.js +0 -1
- package/dist/packem_shared/provider-base-Cmzx6BTO.js +0 -1
- package/dist/packem_shared/resendProvider-Cns1tvF5.js +0 -1
- package/dist/packem_shared/scalewayProvider-O1dHz7iJ.js +0 -1
- package/dist/packem_shared/sendGridProvider-DmywC-eT.js +0 -1
- package/dist/packem_shared/smtpProvider-Unjao_fn.js +0 -23
- package/dist/packem_shared/sweegoProvider-D086G6xG.js +0 -1
- package/dist/packem_shared/zeptomailProvider-DKKEpEsW.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var j=Object.defineProperty;var w=(o,d)=>j(o,"name",{value:d,configurable:!0});import{createRequire as C}from"node:module";import c from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as q}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request-CaT4d5oC.js";import{u as T}from"./retry-UPd8F62N.js";import{d as B}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{c as x,P as D,h as A}from"./provider-base-BpHE_uK8.js";import{f as g,a as h}from"./address-formatter-CnPg51_n.js";const E=C(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,S=w(o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[d,s]=p.versions.node.split(".").map(Number);if(d>22||d===22&&s>=3||d===20&&s>=16)return p.getBuiltinModule(o)}return E(o)},"__cjs_getBuiltinModule"),{Buffer:_}=S("node:buffer"),a="brevo",G="https://api.brevo.com/v3",O=3e4,R=3,Y=K((o={})=>{if(!o.apiKey)throw new k(a,"apiKey");const d=o.endpoint??G,s={apiKey:o.apiKey,debug:o.debug??!1,endpoint:d,hardValidation:o.hardValidation??!1,retries:o.retries??R,timeout:o.timeout??O,...o.logger&&{logger:o.logger}},f=new D,n=x(a,o.logger);return{endpoint:s.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const l=await T(async()=>y(`${s.endpoint}/smtp/emails/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return l.success?(n.debug("Email details retrieved successfully"),{data:l.data?.body,success:!0}):(n.debug("API request failed when retrieving email",l.error),{error:new c(a,`Failed to retrieve email: ${l.error instanceof Error?l.error.message:"Unknown error"}`,{cause:l.error}),success:!1})}catch(t){return{error:A(a,"retrieve email",t,n),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Brevo API not available or invalid API key");n.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Checking Brevo API availability");const t=await y(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return n.debug("Brevo API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{let t;Array.isArray(e.replyTo)?t=e.replyTo.length>0?e.replyTo[0]:void 0:t=e.replyTo;const l={...e,replyTo:t},b=B(l);if(b.length>0)return{error:new c(a,`Invalid email options: ${b.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const i={sender:h(e.from),subject:e.subject,to:g(e.to)};if(e.html&&(i.htmlContent=e.html),e.text&&(i.textContent=e.text),e.cc&&(i.cc=g(e.cc)),e.bcc&&(i.bcc=g(e.bcc)),e.replyTo)if(Array.isArray(e.replyTo)){if(s.hardValidation)return{error:new c(a,"Only one replyTo address is allowed"),success:!1};if(e.replyTo.length===0)return{error:new c(a,"replyTo array cannot be empty"),success:!1};const r=e.replyTo[0];if(!r)return{error:new c(a,"replyTo array cannot be empty"),success:!1};i.replyTo=h(r)}else i.replyTo=h(e.replyTo);if(e.templateId&&(i.templateId=e.templateId,e.templateParams&&(i.params=e.templateParams)),e.tags&&e.tags.length>0&&(i.tags=e.tags),e.scheduledAt){const r=typeof e.scheduledAt=="number"?new Date(e.scheduledAt*1e3).toISOString():e.scheduledAt;i.scheduledAt=r}if(e.batchId&&(i.batchId=e.batchId),e.headers){const r=q(e.headers);i.headers=r}e.attachments&&e.attachments.length>0&&(i.attachment=await Promise.all(e.attachments.map(async r=>{let m;if(r.content)if(typeof r.content=="string")m=r.content;else if(r.content instanceof Promise){const P=await r.content;m=_.from(P).toString("base64")}else m=r.content.toString("base64");else if(r.raw)m=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new c(a,`Attachment ${r.filename} has no content`);return{content:m,name:r.filename,...r.contentType&&{type:r.contentType}}}))),n.debug("Sending email via Brevo API",{subject:i.subject,to:i.to});const I={"api-key":s.apiKey,"Content-Type":"application/json"},u=await T(async()=>y(`${s.endpoint}/smtp/email`,{headers:I,method:"POST",timeout:s.timeout},JSON.stringify(i)),s.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(a,"Failed to send email"),success:!1};const v=u.data?.body?.messageId??z();return n.debug("Email sent successfully",{messageId:v}),{data:{messageId:v,provider:a,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:A(a,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var B=Object.defineProperty;var u=(t,o)=>B(t,"name",{value:o,configurable:!0});import E from"./EmailError-zm2ffVav.js";import m from"../utils/format-email-address.js";import{a as j}from"./generate-boundary-Cx8nXYS0.js";import{i as $}from"./headers-to-record-Qo124ImV.js";import{s as h,a as b}from"./sanitize-header-wWav-Scu.js";var x=Object.defineProperty,M=u((t,o)=>x(t,"name",{value:o,configurable:!0}),"m");const l=M(t=>Array.isArray(t)?t.map(o=>m(o)).join(", "):m(t),"formatEmailAddresses");var A=Object.defineProperty,S=u((t,o)=>A(t,"name",{value:o,configurable:!0}),"g$1");const d=globalThis.Buffer!==void 0,g=S(t=>{if(typeof t=="string"){if(d)return Buffer.from(t,"utf8").toString("base64");const e=new TextEncoder().encode(t);let r="";const s=8192;for(let a=0;a<e.length;a+=s){const f=e.subarray(a,Math.min(a+s,e.length));r+=String.fromCharCode(...f)}return btoa(r)}if(d&&t instanceof Buffer)return t.toString("base64");const o=t instanceof Uint8Array?t:new Uint8Array(t);if(d)return Buffer.from(o).toString("base64");let n="";const c=8192;for(let e=0;e<o.length;e+=c){const r=o.subarray(e,Math.min(e+c,o.length));n+=String.fromCharCode(...r)}return btoa(n)},"toBase64");var O=Object.defineProperty,T=u((t,o)=>O(t,"name",{value:o,configurable:!0}),"u");const P=globalThis.Buffer!==void 0,y=T(t=>t.replaceAll(/.{1,76}/g,`$&\r
|
|
2
|
+
`).trimEnd(),"wrapBase64"),V=T(async t=>{const o=j(),n=[`From: ${m(t.from)}`,`To: ${l(t.to)}`];if(t.cc&&n.push(`Cc: ${l(t.cc)}`),t.bcc&&n.push(`Bcc: ${l(t.bcc)}`),t.replyTo&&n.push(`Reply-To: ${m(t.replyTo)}`),n.push(`Subject: ${h(t.subject)}`,"MIME-Version: 1.0"),t.headers){const c=$(t.headers);Object.entries(c).forEach(([e,r])=>{const s=b(e),a=h(r);n.push(`${s}: ${a}`)})}if(n.push(`Content-Type: multipart/mixed; boundary="${o}"`,""),t.text&&n.push(`--${o}`,"Content-Type: text/plain; charset=UTF-8","Content-Transfer-Encoding: 7bit","",t.text,""),t.html&&n.push(`--${o}`,"Content-Type: text/html; charset=UTF-8","Content-Transfer-Encoding: 7bit","",t.html,""),t.attachments&&t.attachments.length>0){const c=await Promise.all(t.attachments.map(async e=>{let r;if(e.raw!==void 0)r=e.raw;else{if(e.content===void 0)throw new E("attachment",`Attachment '${e.filename}' must have content, raw, or be resolved from path/href before building MIME message`);r=e.content instanceof Promise?await e.content:e.content}return{...e,resolvedContent:r}}));for(const e of c){n.push(`--${o}`);const r=e.contentType??"application/octet-stream",s=h(e.filename);n.push(`Content-Type: ${r}; name="${s}"`);const a=e.contentDisposition??"attachment";n.push(`Content-Disposition: ${a}; filename="${s}"`),e.cid&&n.push(`Content-ID: <${e.cid}>`),e.headers&&Object.entries(e.headers).forEach(([p,v])=>{const C=b(p),w=h(v);n.push(`${C}: ${w}`)});const f=e.encoding??"base64";n.push(`Content-Transfer-Encoding: ${f}`,"");const i=e.resolvedContent;if(f==="base64")n.push(y(g(i)));else if(f==="7bit"||f==="8bit")if(typeof i=="string")n.push(i);else if(P&&i instanceof Buffer)n.push(i.toString("utf8"));else{const p=new TextDecoder;n.push(p.decode(i))}else n.push(y(g(i)));n.push("")}}return n.push(`--${o}--`),n.join(`\r
|
|
3
|
+
`)},"buildMimeMessage");export{V as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var u=(e,s)=>o(e,"name",{value:s,configurable:!0});var a=Object.defineProperty,b=u((e,s)=>a(e,"name",{value:s,configurable:!0}),"n");const p=b(e=>{const{mailto:s,mailtoSubject:i="unsubscribe",oneClick:c=!1,url:t}=e;if(!t&&!s)throw new TypeError("buildListUnsubscribe requires at least one of `url` or `mailto`");const r=[];t&&r.push(`<${t}>`),s&&(s.startsWith("mailto:")?r.push(`<${s}>`):r.push(`<mailto:${s}?subject=${encodeURIComponent(i)}>`));const n={"List-Unsubscribe":r.join(", ")};if(c){if(!t?.startsWith("https:"))throw new TypeError("One-click unsubscribe (RFC 8058) requires an https `url`");n["List-Unsubscribe-Post"]="List-Unsubscribe=One-Click"}return n},"buildListUnsubscribe"),h=b(e=>{const s=e.match(/<[^<>]+>/g);return s?s.map(i=>i.slice(1,-1).trim()):[]},"parseListUnsubscribe");export{p as buildListUnsubscribe,h as parseListUnsubscribe};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var C=Object.defineProperty;var p=(r,t)=>C(r,"name",{value:t,configurable:!0});import y from"./EmailError-zm2ffVav.js";var b=Object.defineProperty,s=p((r,t)=>b(r,"name",{value:t,configurable:!0}),"o");const T=s((r={})=>{const{failureThreshold:t=5,now:c=Date.now,onStateChange:w,resetTimeout:h=3e4}=r;let e="closed",l=0,f=0,n=!1;const i=s(a=>{e!==a&&(e=a,w?.(a))},"transition"),u=s(()=>({error:new y("middleware","Circuit breaker is open",{code:"CIRCUIT_OPEN"}),success:!1}),"openError");return async(a,m)=>{if(e==="open"&&c()-f>=h&&(i("half-open"),n=!1),e==="open")return u();let d=!1;if(e==="half-open"){if(n)return u();n=!0,d=!0}let o;try{o=await m(a)}finally{d&&(n=!1)}return o.success?(l=0,i("closed"),o):(l+=1,(e==="half-open"||l>=t)&&(f=c(),i("open")),o)}},"circuitBreakerMiddleware");export{T as circuitBreakerMiddleware};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import a from"./EmailError-zm2ffVav.js";import d from"./RequiredOptionError-CevW3u2K.js";import{z as m}from"./build-mime-message-D8WEZejb.js";import{s as f}from"./generate-message-id-D4uA8gkj.js";import{i as u}from"./headers-to-record-Qo124ImV.js";import{d as p}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as g}from"./defineProvider-CtLH0VBE.js";import{c as h,h as v}from"./provider-base-BpHE_uK8.js";const r="cloudflare-email",x=g((t={})=>{if(typeof t.send!="function")throw new d(r,"send");const c=h(r,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await Promise.resolve()},async isAvailable(){return typeof t.send=="function"},name:r,async sendEmail(e){try{const s=p(e);if(s.length>0)return{error:new a(r,`Invalid email options: ${s.join(", ")}`),success:!1};const i=Array.isArray(e.to)?e.to:[e.to];if(i.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new a(r,"Cloudflare Email supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[o]=i;if(!o)return{error:new a(r,"A single `to` recipient is required"),success:!1};const n=f(),l=await m({...e,headers:{...e.headers?u(e.headers):{},"Message-ID":n}});return await t.send(e.from.email,o.email,l),{data:{messageId:n,provider:r,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:v(r,"send email",s,c),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{x as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var d=Object.defineProperty;var t=(e,o)=>d(e,"name",{value:o,configurable:!0});var i=Object.defineProperty,n=t((e,o)=>i(e,"name",{value:o,configurable:!0}),"n");const f=n((e,o)=>{let r=o;for(const a of e.toReversed()){const c=r;r=n(s=>a(s,c),"chain")}return r},"composeMiddleware");export{f as composeMiddleware};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var w=Object.defineProperty;var c=(e,t)=>w(e,"name",{value:t,configurable:!0});import{createMail as f}from"./Mail-B2QII2P9.js";import d from"./mockProvider-C0P1lKOy.js";var p=Object.defineProperty,o=c((e,t)=>p(e,"name",{value:t,configurable:!0}),"e");const g=o((e,t,r,a)=>{const n=Date.now()+r;return new Promise((m,u)=>{const i=o(()=>{const s=e.find(l=>t(l));if(s){m(s);return}if(Date.now()>=n){u(new Error("waitFor timed out before a matching message was captured"));return}setTimeout(i,a)},"check");i()})},"pollForMatch"),F=o(()=>{const e=d(),t=f(e),r=e.getInstance?.();if(!r)throw new Error("mockProvider() did not expose getInstance(); cannot create a test harness");return{mail:t,reset:o(()=>{r.length=0},"reset"),sent:o(()=>r,"sent"),waitFor:o((a,n={})=>g(r,a,n.timeout??1e3,n.interval??10),"waitFor")}},"createTestEmail");export{F as createTestEmail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=Object.defineProperty;var p=(t,o)=>g(t,"name",{value:o,configurable:!0});var S=Object.defineProperty,e=p((t,o)=>S(t,"name",{value:o,configurable:!0}),"r");const x=e(t=>1e3*2**(t-1),"defaultBackoff"),R=e(t=>{const{backoff:o=x,concurrency:v=1,maxAttempts:k=3,onDeadLetter:E,onError:w,onReserveError:m,pollInterval:h=1e3,queue:c,send:b}=t;let n=!1,f=0,i;const u=e(async(r,a)=>{try{await a()}catch(s){w?.(r,{error:s instanceof Error?s:new Error(String(s)),success:!1})}},"guardQueueOp"),d=e(async r=>{let a;try{a=await b(r.message)}catch(l){a={error:l instanceof Error?l:new Error(String(l)),success:!1}}if(a.success){await u(r,()=>c.ack(r.id));return}w?.(r,a);const s=r.attempts+1;if(s>=k){await u(r,()=>c.ack(r.id)),E?.(r,a);return}await u(r,()=>c.retry(r.id,o(s)))},"processJob"),y=e(async()=>{if(n){try{for(;f<v;){const r=await c.reserve();if(!r)break;f+=1,d(r).finally(()=>{f-=1}).catch(()=>{})}}catch(r){m?.(r instanceof Error?r:new Error(String(r)))}n&&(i=setTimeout(()=>{y().catch(()=>{})},h))}},"tick");return{drain:e(async()=>{let r=await c.reserve();for(;r;)await d(r),r=await c.reserve()},"drain"),start:e(()=>{n||(n=!0,y().catch(()=>{}))},"start"),stop:e(()=>{n=!1,i&&(clearTimeout(i),i=void 0)},"stop")}},"createWorker");export{R as createWorker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _=Object.defineProperty;var a=(r,e)=>_(r,"name",{value:e,configurable:!0});import{createRequire as y}from"node:module";const g=y(import.meta.url),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,j=a(r=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[e,t]=s.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return s.getBuiltinModule(r)}return g(r)},"__cjs_getBuiltinModule"),{createHash:w}=j("node:crypto");var b=Object.defineProperty,i=a((r,e)=>b(r,"name",{value:e,configurable:!0}),"r");const l=i(r=>r?(Array.isArray(r)?r:[r]).map(e=>e.email.toLowerCase()).toSorted((e,t)=>e.localeCompare(t)).join(","):"","addressKey"),h=i(r=>{const e=w("sha256");return e.update(l(r.to)),e.update("\0"),e.update(l(r.cc)),e.update("\0"),e.update(r.subject),e.update("\0"),e.update(r.text??r.html??""),e.digest("hex")},"defaultKey"),M=i((r={})=>{const{keyFn:e=h,now:t=Date.now,ttl:f=6e4}=r,u=new Map;return async(c,m)=>{const d=e(c),p=t(),o=u.get(d);if(o&&o.expires>p)return o.result;const n=await m(c);return n.success&&u.set(d,{expires:p+f,result:n}),n}},"dedupeMiddleware");export{M as dedupeMiddleware};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var l=Object.defineProperty;var a=(e,r)=>l(e,"name",{value:r,configurable:!0});import{
|
|
1
|
+
var l=Object.defineProperty;var a=(e,r)=>l(e,"name",{value:r,configurable:!0});import{E as n}from"./readFile-BkNfutxp-BS8Q2183.js";import i from"mime";var c=Object.defineProperty,t=a((e,r)=>c(e,"name",{value:r,configurable:!0}),"e");const d=t(e=>i.getType(e)??"application/octet-stream","detectMimeType"),g=t(e=>{const r=e.replaceAll(/[^a-z0-9]/gi,"-").replaceAll(/-+/g,"-").replaceAll(/^-|-$/g,"").toLowerCase(),o=Math.random().toString(36).slice(2,9);return`${r}-${o}@email`},"generateContentId"),s=t(e=>n(e,{buffer:!0}),"readFileAsBuffer");export{d as detectMimeType,g as generateContentId,s as readFileAsBuffer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var v=Object.defineProperty;var m=(e,t)=>v(e,"name",{value:t,configurable:!0});var g=Object.defineProperty,a=m((e,t)=>g(e,"name",{value:t,configurable:!0}),"n");const i=a(e=>Array.isArray(e)?e:e.sent(),"toEntries"),c=a(e=>e?(Array.isArray(e)?e:[e]).map(t=>t.email.toLowerCase()):[],"addressesOf"),p=a(e=>[...c(e.to),...c(e.cc),...c(e.bcc)],"recipientsOf"),u=a((e,t)=>{const n=t.toLowerCase(),s=i(e).some(o=>p(o.options).includes(n));return{message:a(()=>`expected ${s?"no ":""}email to have been sent to ${t}`,"message"),pass:s}},"toHaveSentTo"),S=a((e,t)=>{const n=i(e).some(s=>typeof t=="string"?s.options.subject===t:t.test(s.options.subject));return{message:a(()=>`expected ${n?"no ":""}email to have been sent with subject ${String(t)}`,"message"),pass:n}},"toHaveSentWithSubject"),b=a((e,t)=>{const n=i(e).some(s=>{const o=s.options.attachments??[];return t===void 0?o.length>0:o.some(r=>r.filename===t)});return{message:a(()=>`expected ${n?"no ":""}email to have been sent with attachment${t?` "${t}"`:""}`,"message"),pass:n}},"toHaveSentWithAttachment"),l=a((e,t)=>{const n=typeof t=="function"?t:o=>Object.entries(t).every(([r,h])=>o[r]===h),s=i(e).some(o=>n(o.options));return{message:a(()=>`expected ${s?"no ":""}email to have been sent matching the given condition`,"message"),pass:s}},"toHaveSentMatching"),d={toHaveSentMatching:l,toHaveSentTo:u,toHaveSentWithAttachment:b,toHaveSentWithSubject:S},y=a(e=>{e.extend(d)},"registerEmailMatchers");export{d as emailMatchers,y as registerEmailMatchers,l as toHaveSentMatching,u as toHaveSentTo,b as toHaveSentWithAttachment,S as toHaveSentWithSubject};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lifecycle/engagement event types that converge onto a single {@link EmailEvent} shape.
|
|
3
|
+
*
|
|
4
|
+
* The first group (`queued` → `failed`) is emitted by the send pipeline; the rest typically originate
|
|
5
|
+
* from provider webhooks (delivery/engagement signals).
|
|
6
|
+
*/
|
|
7
|
+
type EmailEventType = "attempt" | "bounced" | "clicked" | "complained" | "deferred" | "delivered" | "failed" | "opened" | "queued" | "sent" | "unsubscribed";
|
|
8
|
+
/**
|
|
9
|
+
* A single, provider-agnostic email event. Both internal send-lifecycle signals and normalized
|
|
10
|
+
* webhook events use this shape so a timeline can be reconstructed from one stream.
|
|
11
|
+
*/
|
|
12
|
+
interface EmailEvent {
|
|
13
|
+
/**
|
|
14
|
+
* Arbitrary structured payload (provider response, bounce sub-type, click URL, …).
|
|
15
|
+
*/
|
|
16
|
+
data?: Record<string, unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* A unique id for this event.
|
|
19
|
+
*/
|
|
20
|
+
id: string;
|
|
21
|
+
/**
|
|
22
|
+
* The message this event concerns.
|
|
23
|
+
*/
|
|
24
|
+
messageId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The provider that produced (or will produce) the message.
|
|
27
|
+
*/
|
|
28
|
+
provider?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The recipient address this event concerns, when applicable.
|
|
31
|
+
*/
|
|
32
|
+
recipient?: string;
|
|
33
|
+
/**
|
|
34
|
+
* When the event occurred.
|
|
35
|
+
*/
|
|
36
|
+
timestamp: Date;
|
|
37
|
+
/**
|
|
38
|
+
* The kind of event.
|
|
39
|
+
*/
|
|
40
|
+
type: EmailEventType;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A listener invoked for matching {@link EmailEvent}s.
|
|
44
|
+
*/
|
|
45
|
+
type EmailEventListener = (event: EmailEvent) => void;
|
|
46
|
+
/**
|
|
47
|
+
* A persistence backend for {@link EmailEvent}s.
|
|
48
|
+
*/
|
|
49
|
+
interface EventStore {
|
|
50
|
+
/**
|
|
51
|
+
* Appends an event.
|
|
52
|
+
* @param event The event to store.
|
|
53
|
+
*/
|
|
54
|
+
append: (event: EmailEvent) => Promise<void> | void;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the full, time-ordered timeline for a message.
|
|
57
|
+
* @param messageId The message to reconstruct.
|
|
58
|
+
*/
|
|
59
|
+
timeline: (messageId: string) => EmailEvent[] | Promise<EmailEvent[]>;
|
|
60
|
+
}
|
|
61
|
+
type Selector = "*" | EmailEventType;
|
|
62
|
+
/**
|
|
63
|
+
* The wildcard selector that subscribes to every event type.
|
|
64
|
+
*/
|
|
65
|
+
declare const ALL_EVENTS: "*";
|
|
66
|
+
/**
|
|
67
|
+
* A tiny synchronous pub/sub bus for {@link EmailEvent}s.
|
|
68
|
+
*
|
|
69
|
+
* Subscribe to a specific {@link EmailEventType} or to {@link ALL_EVENTS} (`"*"`) for every event.
|
|
70
|
+
*/
|
|
71
|
+
declare class EventBus {
|
|
72
|
+
private readonly listeners;
|
|
73
|
+
/**
|
|
74
|
+
* Subscribes a listener to an event type (or all events).
|
|
75
|
+
* @param type The event type, or `"*"` for all events.
|
|
76
|
+
* @param listener The listener to invoke.
|
|
77
|
+
* @returns An unsubscribe function.
|
|
78
|
+
*/
|
|
79
|
+
on(type: Selector, listener: EmailEventListener): () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Subscribes a listener that is removed after its first invocation.
|
|
82
|
+
* @param type The event type, or `"*"` for all events.
|
|
83
|
+
* @param listener The listener to invoke once.
|
|
84
|
+
* @returns An unsubscribe function.
|
|
85
|
+
*/
|
|
86
|
+
once(type: Selector, listener: EmailEventListener): () => void;
|
|
87
|
+
/**
|
|
88
|
+
* Removes a previously-added listener.
|
|
89
|
+
* @param type The event type the listener was registered under.
|
|
90
|
+
* @param listener The listener to remove.
|
|
91
|
+
*/
|
|
92
|
+
off(type: Selector, listener: EmailEventListener): void;
|
|
93
|
+
/**
|
|
94
|
+
* Emits an event to all matching listeners (type-specific first, then wildcard).
|
|
95
|
+
* @param event The event to dispatch.
|
|
96
|
+
*/
|
|
97
|
+
emit(event: EmailEvent): void;
|
|
98
|
+
/**
|
|
99
|
+
* Removes all listeners (optionally for a single type).
|
|
100
|
+
* @param type When provided, only listeners for this type are removed.
|
|
101
|
+
*/
|
|
102
|
+
clear(type?: Selector): void;
|
|
103
|
+
}
|
|
104
|
+
export { ALL_EVENTS as A, EmailEvent as E, EventStore as a, EmailEventListener as b, EmailEventType as c, EventBus as d };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var c=Object.defineProperty;var l=(e,t)=>c(e,"name",{value:t,configurable:!0});var u=Object.defineProperty,o=l((e,t)=>u(e,"name",{value:t,configurable:!0}),"o");const f=[/^On .*wrote:$/i,/^Am .*schrieb.*:$/i,/^Le .*a écrit ?:$/i,/^El .*escribió:$/i,/^.+\btarihinde\b.+yazdı:$/i],m=[/^-{2,}\s*Original Message\s*-{2,}/i,/^-{2,}\s*Forwarded message\s*-{2,}/i,/^_{5,}$/],p=/^--\s?$/,g=/^(?:from|von):\s/i,d=/^(?:to|an|cc|sent|gesendet|date|datum|subject|betreff|reply-to):\s/i,b=o(e=>e.startsWith(">")||m.some(t=>t.test(e))?!0:f.some(t=>t.test(e)),"isQuoteBoundary"),h=o((e,t)=>{if(!g.test((e[t]??"").trim()))return!1;let i=0;for(let s=t+1;s<e.length&&i<3;s+=1){const r=e[s].trim();if(r!==""&&(i+=1,d.test(r)))return!0}return!1},"isHeaderBlock"),y=o((e,t={})=>{const{stripSignature:i=!0}=t,s=e.replaceAll(`\r
|
|
2
|
+
`,`
|
|
3
|
+
`).split(`
|
|
4
|
+
`),r=[];for(let n=0;n<s.length;n+=1){const a=s[n];if(b(a.trim())||h(s,n)||i&&p.test(a))break;r.push(a)}for(;r.length>0&&r[r.length-1].trim()==="";)r.pop();return r.join(`
|
|
5
|
+
`).trim()},"extractReply");export{y as extractReply};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=Object.defineProperty;var t=(r,e)=>i(r,"name",{value:e,configurable:!0});import u from"./MemorySuppressionStore-BKY1FrA1.js";var c=Object.defineProperty,a=t((r,e)=>c(r,"name",{value:e,configurable:!0}),"o");const l=a(async(r,e)=>{const n=Array.isArray(r)?r:[r],o=[],p=[];for(const s of n)await e.has(s.email)?p.push(s):o.push(s);return{allowed:o,suppressed:p}},"filterSuppressed"),d=a(r=>new u(r),"createSuppressionStore");export{u as MemorySuppressionStore,d as createSuppressionStore,l as filterSuppressed};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var o=Object.defineProperty;var n=(e,a)=>o(e,"name",{value:a,configurable:!0});var m=Object.defineProperty,s=n((e,a)=>m(e,"name",{value:a,configurable:!0}),"n");const d=/[\r\n<>]/,f=s(e=>{let a=e.replaceAll(/[\r\n\t]+/g," ");a=[...a].filter(l=>{const t=l.codePointAt(0);return t===void 0?!1:t>=32&&t<=126||t>159}).join("");const r="\\",i='"';return a=a.replaceAll(r,r+r).replaceAll(i,r+i),a.trim().replaceAll(/\s+/g," ")},"sanitizeDisplayName"),c=s(e=>{if(d.test(e.email))throw new Error("Invalid email address for header formatting");if(e.name){const a=f(e.name);if(a)return`"${a}" <${e.email}>`}return e.email},"formatAddress"),p=s(e=>(Array.isArray(e)?e:[e]).map(a=>c(a)).join(", "),"formatAddresses");export{p as a,c as f,f as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var T=Object.defineProperty;var b=(r,n)=>T(r,"name",{value:n,configurable:!0});import{createRequire as P}from"node:module";import c from"./EmailError-zm2ffVav.js";import z from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as U}from"./headers-to-record-Qo124ImV.js";import{m as g}from"./make-request-CaT4d5oC.js";import{u as w}from"./retry-UPd8F62N.js";import{d as k}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as S}from"./defineProvider-CtLH0VBE.js";import{c as q,P as K,h as v}from"./provider-base-BpHE_uK8.js";import{l as y}from"./address-formatter-CnPg51_n.js";const $=P(import.meta.url),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,j=b(r=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[n,p]=d.versions.node.split(".").map(Number);if(n>22||n===22&&p>=3||n===20&&p>=16)return d.getBuiltinModule(r)}return $(r)},"__cjs_getBuiltinModule"),{Buffer:_}=j("node:buffer"),a="infobip",R="https://api.infobip.com",C=3e4,x=3,W=S((r={})=>{if(!r.apiKey)throw new z(a,"apiKey");const n=r.baseUrl??R,p=r.endpoint??`${n}/email/3/send`,s={apiKey:r.apiKey,baseUrl:n,debug:r.debug??!1,endpoint:p,retries:r.retries??x,timeout:r.timeout??C,...r.logger&&{logger:r.logger}},f=new K,o=q(a,r.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const l={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await w(async()=>g(`${s.baseUrl}/email/3/reports/${e}`,{headers:l,method:"GET",timeout:s.timeout}),s.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new c(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(l){return{error:v(a,"retrieve email",l,o),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Infobip API not available or invalid API key");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{o.debug("Checking Infobip API availability");const e={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"};return(await g(`${s.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:s.timeout})).success}catch(e){return o.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const l=k(e);if(l.length>0)return{error:new c(a,`Invalid email options: ${l.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:y(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=y(e.cc)),e.bcc&&(t.bcc=y(e.bcc)),e.replyTo&&(t.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateData=e.templateVariables)),e.trackingUrl&&(t.trackingUrl=e.trackingUrl),e.notifyUrl&&(t.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(t.intermediateReport=e.intermediateReport),e.sendAt&&(t.sendAt=e.sendAt),e.headers){const i=U(e.headers);t.headers=i}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async i=>{let u;if(i.content)if(typeof i.content=="string")u=i.content;else if(i.content instanceof Promise){const A=await i.content;u=_.from(A).toString("base64")}else u=i.content.toString("base64");else if(i.raw)u=typeof i.raw=="string"?i.raw:i.raw.toString("base64");else throw new c(a,`Attachment ${i.filename} has no content`);return{content:u,contentType:i.contentType??"application/octet-stream",name:i.filename}}))),o.debug("Sending email via Infobip API",{subject:t.subject,to:t.to});const I={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"},m=await w(async()=>g(s.endpoint,{headers:I,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!m.success)return o.debug("API request failed when sending email",m.error),{error:m.error??new c(a,"Failed to send email"),success:!1};const h=m.data?.body?.messages?.[0]?.messageId??E();return o.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(l){return{error:v(a,"send email",l,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{W as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var s=Object.defineProperty;var c=(e,l)=>s(e,"name",{value:l,configurable:!0});var p=Object.defineProperty,i=c((e,l)=>p(e,"name",{value:l,configurable:!0}),"t");const d=/<body[^<>]*>/i,h=i(e=>e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',"""),"escapeHtml"),u=i((e,l,n={})=>{const o=n.spacer===!1?"":" ".repeat(120),t=`<div style="display:none;max-height:0;overflow:hidden;mso-hide:all;">${h(l)}${o}</div>`,r=d.exec(e);if(r){const a=r.index+r[0].length;return`${e.slice(0,a)}${t}${e.slice(a)}`}return`${t}${e}`},"injectPreheader");export{u as injectPreheader};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var a=Object.defineProperty;var o=(n,r)=>a(n,"name",{value:r,configurable:!0});import{createRequire as c}from"node:module";import i from"./EmailError-zm2ffVav.js";const u=c(import.meta.url),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=o(n=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[r,s]=t.versions.node.split(".").map(Number);if(r>22||r===22&&s>=3||r===20&&s>=16)return t.getBuiltinModule(n)}return u(n)},"__cjs_getBuiltinModule"),{createRequire:d}=l("node:module");var m=Object.defineProperty,p=o((n,r)=>m(n,"name",{value:r,configurable:!0}),"t");const f=d(import.meta.url),h=p((n,r)=>{let s;try{s=f("juice")}catch(e){throw e instanceof Error&&(e.code==="MODULE_NOT_FOUND"||e.message.includes("Cannot find module")||e.message.includes("Cannot find package"))?new i("render","juice is not installed. Please install it: pnpm add juice",{cause:e}):new i("render",`Failed to load juice: ${e.message}`,{cause:e})}try{return s(n,r)}catch(e){throw new i("render",`Failed to inline CSS: ${e.message}`,{cause:e})}},"inlineCss");export{h as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var d=Object.defineProperty;var a=(e,t)=>d(e,"name",{value:t,configurable:!0});import{createRequire as m}from"node:module";import c from"./EmailError-zm2ffVav.js";const S=m(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=a(e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,r]=n.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return n.getBuiltinModule(e)}return S(e)},"__cjs_getBuiltinModule"),{Buffer:b}=l("node:buffer"),{X509Certificate:y,createVerify:w}=l("node:crypto");var v=Object.defineProperty,o=a((e,t)=>v(e,"name",{value:t,configurable:!0}),"s");const h={Notification:["Message","MessageId","Subject","Timestamp","TopicArn","Type"],SubscriptionConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"],UnsubscribeConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"]},T=/^sns\.[a-z0-9-]+\.amazonaws\.com(?:\.cn)?$/,R=/\.$/,_=o(e=>{let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:"||t.username!==""||t.password!==""||t.port!=="")return!1;const r=t.hostname.toLowerCase().replace(R,"");return T.test(r)},"isValidSigningCertUrl"),M=o(async e=>{if(!_(e))throw new c("webhooks",`Refusing to fetch SNS signing certificate from untrusted URL: ${e}`);const t=await fetch(e,{signal:AbortSignal.timeout(5e3)});if(!t.ok)throw new c("webhooks",`Failed to fetch SNS signing certificate (status ${String(t.status)})`);return await t.text()},"defaultCertificateResolver"),C=o(e=>{const t=h[e.Type??""];if(!t)return;let r="";for(const i of t){const s=e[i];typeof s=="string"&&(r+=`${i}
|
|
2
|
+
${s}
|
|
3
|
+
`)}return r},"buildStringToSign"),j=o(async(e,t={})=>{const{certificateResolver:r=M}=t;if(!e.Signature||!e.SigningCertURL)return{reason:"missing-signature",valid:!1};const i=C(e);if(i===void 0)return{reason:"unknown-message-type",valid:!1};let s;if(e.SignatureVersion==="1")s="RSA-SHA1";else if(e.SignatureVersion==="2")s="RSA-SHA256";else return{reason:"unknown-signature-version",valid:!1};const g=await r(e.SigningCertURL);let u;try{u=new y(g).publicKey}catch(p){throw new c("webhooks","Failed to parse SNS signing certificate",{cause:p})}let f;try{f=w(s).update(i,"utf8").verify(u,b.from(e.Signature,"base64"))}catch{return{reason:"signature-malformed",valid:!1}}return f?{valid:!0}:{reason:"signature-mismatch",valid:!1}},"verifySnsMessage");export{_ as isValidSigningCertUrl,j as verifySnsMessage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var t=(e,r)=>l(e,"name",{value:r,configurable:!0});var d=Object.defineProperty,o=t((e,r)=>d(e,"name",{value:r,configurable:!0}),"s");const m=o(e=>{const r=e.indexOf("@");if(r<=0)return"•••";const s=e.slice(0,r),a=e.slice(r+1);return`${s.slice(0,1)}${"•".repeat(Math.max(1,s.length-1))}@${a}`},"redactAddress"),u=o((e,r)=>(Array.isArray(e)?e:[e]).map(s=>r?m(s.email):s.email),"summarizeRecipients"),f=o((e={})=>{const{logger:r=console,redact:s=!0}=e;return async(a,c)=>{const n=u(a.to,s);r.info("[@visulima/email] sending",{subject:s?void 0:a.subject,to:n});const i=await c(a);return i.success?r.info("[@visulima/email] sent",{messageId:i.data?.messageId,to:n}):r.error("[@visulima/email] send failed",{error:i.error instanceof Error?i.error.message:i.error,to:n}),i}},"loggingMiddleware");export{f as loggingMiddleware};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import o from"./EmailError-zm2ffVav.js";import f from"./RequiredOptionError-CevW3u2K.js";import{s as g}from"./generate-message-id-D4uA8gkj.js";import{m as h}from"./make-request-CaT4d5oC.js";import{u as y}from"./retry-UPd8F62N.js";import{defineProvider as b}from"./defineProvider-CtLH0VBE.js";import{c as v,h as w,P as T}from"./provider-base-BpHE_uK8.js";import{d as A}from"./attachment-processor-CFUC3V45.js";const t="loops",I="https://app.loops.so/api/v1/transactional",P=3e4,K=3,C=b((a={})=>{if(!a.apiKey)throw new f(t,"apiKey");const r={apiKey:a.apiKey,debug:a.debug??!1,defaultTransactionalId:a.defaultTransactionalId,endpoint:a.endpoint??I,logger:a.logger,retries:a.retries??K,timeout:a.timeout??P},m=new T,u=v(t,a.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!1,html:!1,replyTo:!1,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){m.setInitialized()},async isAvailable(){return r.apiKey.length>0},name:t,options:r,async sendEmail(e){try{const s=e.transactionalId??r.defaultTransactionalId;if(!s)return{error:new o(t,"Loops requires a `transactionalId` (on the message or as `defaultTransactionalId`)"),success:!1};const l=Array.isArray(e.to)?e.to:[e.to];if(l.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new o(t,"Loops supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[d]=l;if(!d)return{error:new o(t,"A `to` recipient is required"),success:!1};const n={email:d.email,transactionalId:s};e.dataVariables&&(n.dataVariables=e.dataVariables),e.addToAudience&&(n.addToAudience=!0),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async p=>{const c=await A(p,t);return{contentType:c.contentType,data:c.content,filename:c.filename}})));const i=await y(async()=>h(r.endpoint,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);return i.success?{data:{messageId:g(),provider:t,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new o(t,"Failed to send email"),success:!1}}catch(s){return{error:w(t,"send email",s,u),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{C as default};
|