@visulima/email 1.0.0-alpha.13 → 1.0.0-alpha.14

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.
Files changed (82) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/crypto/index.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/packem_shared/{DkimSigner-CT2DSHD1.js → DkimSigner-C8HEBBSb.js} +5 -5
  5. package/dist/packem_shared/EmailError-C4nx6TgJ.js +1 -0
  6. package/dist/packem_shared/{Mail-e4KlaSct.js → Mail-CKWWPQ3P.js} +1 -1
  7. package/dist/packem_shared/{MailMessage-CeVZvVfv.js → MailMessage-DCfFM4wk.js} +1 -1
  8. package/dist/packem_shared/{RequiredOptionError-CevW3u2K.js → RequiredOptionError-BeTzeno6.js} +1 -1
  9. package/dist/packem_shared/{SmimeEncrypter-ZhHEgDwY.js → SmimeEncrypter-CM_gM2Cd.js} +2 -2
  10. package/dist/packem_shared/{SmimeSigner-CYSVF6ez.js → SmimeSigner-vQF8_2ZJ.js} +2 -2
  11. package/dist/packem_shared/{ahaSendProvider-Cni1nzIr.js → ahaSendProvider-CsjoaREy.js} +1 -1
  12. package/dist/packem_shared/{attachment-processor-DsmIomKc.js → attachment-processor-BREe8fDh.js} +1 -1
  13. package/dist/packem_shared/{awsSesProvider-D9idlOm1.js → awsSesProvider-E4SEMNvy.js} +1 -1
  14. package/dist/packem_shared/{azureProvider-OU6Gu-cD.js → azureProvider-Cg5Gd9_y.js} +1 -1
  15. package/dist/packem_shared/{brevoProvider-Bmpg3VT_.js → brevoProvider-B4SXxP2v.js} +1 -1
  16. package/dist/packem_shared/{build-mime-message-6xstxaUV.js → build-mime-message-Bv456sHf.js} +1 -1
  17. package/dist/packem_shared/detectMimeType-Dv28wXZ-.js +1 -0
  18. package/dist/packem_shared/{failoverProvider-W5ctAhdC.js → failoverProvider-B7U843uf.js} +1 -1
  19. package/dist/packem_shared/{httpProvider-OX9_yKF0.js → httpProvider-DWSay7yF.js} +1 -1
  20. package/dist/packem_shared/{infobipProvider-Bx4A4p4A.js → infobipProvider-D0PP2gJ-.js} +1 -1
  21. package/dist/packem_shared/{mailCrabProvider-B7H6HwWu.js → mailCrabProvider-P7zKlhLH.js} +1 -1
  22. package/dist/packem_shared/{mailPaceProvider-DWptkW9x.js → mailPaceProvider-Cy21ZI6Y.js} +1 -1
  23. package/dist/packem_shared/{mailerSendProvider-FiR_X5Be.js → mailerSendProvider-DbrHbsEa.js} +1 -1
  24. package/dist/packem_shared/{mailgunProvider-B18_T6SA.js → mailgunProvider-CFgoweOi.js} +1 -1
  25. package/dist/packem_shared/{mailjetProvider-C737SQmw.js → mailjetProvider-DlgNw-e8.js} +1 -1
  26. package/dist/packem_shared/{mailomatProvider-D5HPTJrq.js → mailomatProvider-BHMXyltf.js} +1 -1
  27. package/dist/packem_shared/{mailtrapProvider-4fyjVZrA.js → mailtrapProvider-Ks3cdXZM.js} +1 -1
  28. package/dist/packem_shared/{make-request--BdZNxIl.js → make-request-C7fcsalD.js} +1 -1
  29. package/dist/packem_shared/{mandrillProvider-DPXMdbPI.js → mandrillProvider-o7hdsxCF.js} +1 -1
  30. package/dist/packem_shared/{mockProvider-C0P1lKOy.js → mockProvider-Yf0VAcNU.js} +1 -1
  31. package/dist/packem_shared/{nodemailerProvider-DFcvoVFv.js → nodemailerProvider-DUo4vHDF.js} +1 -1
  32. package/dist/packem_shared/{opentelemetryProvider-Dwv88G3O.js → opentelemetryProvider-PYtcqHES.js} +1 -1
  33. package/dist/packem_shared/{plunkProvider-CmR0bUei.js → plunkProvider-QEN0FObd.js} +1 -1
  34. package/dist/packem_shared/{postalProvider-vf5vjbef.js → postalProvider-C-423Isy.js} +1 -1
  35. package/dist/packem_shared/{postmarkProvider-uCLyHARt.js → postmarkProvider-D6Kj-kpI.js} +1 -1
  36. package/dist/packem_shared/{provider-base-Cmzx6BTO.js → provider-base-8LBAorjm.js} +1 -1
  37. package/dist/packem_shared/readFile-Iz7kvCCk-CVf9zS6c.js +1 -0
  38. package/dist/packem_shared/{resendProvider-9X-wmOFy.js → resendProvider-Brz2S5fS.js} +1 -1
  39. package/dist/packem_shared/{roundRobinProvider-FvZQKl6n.js → roundRobinProvider-DBGbQHjJ.js} +1 -1
  40. package/dist/packem_shared/{scalewayProvider-Bdh-7QY6.js → scalewayProvider-gR0hyLK7.js} +1 -1
  41. package/dist/packem_shared/{sendGridProvider-UrH61D8C.js → sendGridProvider-Daf7dZ35.js} +1 -1
  42. package/dist/packem_shared/{smtpProvider-Unjao_fn.js → smtpProvider-BPNpC2T2.js} +1 -1
  43. package/dist/packem_shared/{sweegoProvider-B_yTn1gT.js → sweegoProvider-C8hI47F6.js} +1 -1
  44. package/dist/packem_shared/{zeptomailProvider-skowg799.js → zeptomailProvider-ClKCD8EJ.js} +1 -1
  45. package/dist/providers/ahasend/index.js +1 -1
  46. package/dist/providers/aws-ses/index.js +1 -1
  47. package/dist/providers/azure/index.js +1 -1
  48. package/dist/providers/brevo/index.js +1 -1
  49. package/dist/providers/failover/index.js +1 -1
  50. package/dist/providers/http/index.js +1 -1
  51. package/dist/providers/infobip/index.js +1 -1
  52. package/dist/providers/mailcrab/index.js +1 -1
  53. package/dist/providers/mailersend/index.js +1 -1
  54. package/dist/providers/mailgun/index.js +1 -1
  55. package/dist/providers/mailjet/index.js +1 -1
  56. package/dist/providers/mailomat/index.js +1 -1
  57. package/dist/providers/mailpace/index.js +1 -1
  58. package/dist/providers/mailtrap/index.js +1 -1
  59. package/dist/providers/mandrill/index.js +1 -1
  60. package/dist/providers/mock/index.js +1 -1
  61. package/dist/providers/nodemailer/index.js +1 -1
  62. package/dist/providers/opentelemetry/index.js +1 -1
  63. package/dist/providers/plunk/index.js +1 -1
  64. package/dist/providers/postal/index.js +1 -1
  65. package/dist/providers/postmark/index.js +1 -1
  66. package/dist/providers/resend/index.js +1 -1
  67. package/dist/providers/roundrobin/index.js +1 -1
  68. package/dist/providers/scaleway/index.js +1 -1
  69. package/dist/providers/sendgrid/index.js +1 -1
  70. package/dist/providers/smtp/index.js +1 -1
  71. package/dist/providers/sweego/index.js +1 -1
  72. package/dist/providers/zeptomail/index.js +1 -1
  73. package/dist/template-engines/handlebars.js +1 -1
  74. package/dist/template-engines/html-to-text.js +1 -1
  75. package/dist/template-engines/mjml.js +1 -1
  76. package/dist/template-engines/react-email.js +1 -1
  77. package/dist/template-engines/vue-email.js +1 -1
  78. package/dist/utils/format-email-address.js +1 -1
  79. package/package.json +8 -8
  80. package/dist/packem_shared/EmailError-zm2ffVav.js +0 -1
  81. package/dist/packem_shared/detectMimeType-iprkVO8e.js +0 -1
  82. package/dist/packem_shared/readFile-BAVMZg5e-C4whBIPd.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## @visulima/email [1.0.0-alpha.14](https://github.com/visulima/visulima/compare/@visulima/email@1.0.0-alpha.13...@visulima/email@1.0.0-alpha.14) (2026-04-22)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **email:** resolve eslint and formatting issues ([50c6fb1](https://github.com/visulima/visulima/commit/50c6fb14a6f72e40d168fcb57908fa9489417e9a))
6
+ * **email:** resolve eslint and formatting issues ([ad82020](https://github.com/visulima/visulima/commit/ad82020ded7fffdbba89b6befd2522a908cffe81))
7
+ * **email:** resolve eslint issues and format code ([8fd689c](https://github.com/visulima/visulima/commit/8fd689c12e9c21f7222597bbf99a6fe431b5f0d4))
8
+ * Remove JSR configuration generation script and generated jsr.json files ([#616](https://github.com/visulima/visulima/issues/616)) ([533744b](https://github.com/visulima/visulima/commit/533744b103b74896941db5b727173e617a27a63b))
9
+
10
+ ### Miscellaneous Chores
11
+
12
+ * bump engines.node to ^22.14.0 || >=24.10.0 ([c3d0931](https://github.com/visulima/visulima/commit/c3d0931d1504e4f21ebf50ea680cfa7ce4ba15ce))
13
+ * **email:** apply formatter and lint fixes across providers ([addf346](https://github.com/visulima/visulima/commit/addf346653b0400de7a944b1d5573efc9654fe30))
14
+ * **email:** apply pending changes ([002c978](https://github.com/visulima/visulima/commit/002c9781033e9b2eae08257867b136dccdd11160))
15
+ * **email:** enforce curly braces and apply lint fixes ([2d82544](https://github.com/visulima/visulima/commit/2d82544bd769eef2935565a4df2c0c98b2cb8262))
16
+ * fixed jsr.json ([5d85e51](https://github.com/visulima/visulima/commit/5d85e5179de38e284ec433b14d77c71a1619c8d6))
17
+
18
+ ### Code Refactoring
19
+
20
+ * replace inline import() types with top-level imports ([4569a4c](https://github.com/visulima/visulima/commit/4569a4ca04723da069f985855dcfab292f7347e1))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * **@visulima/disposable-email-domains:** upgraded to 1.0.0-alpha.13
26
+
1
27
  ## @visulima/email [1.0.0-alpha.13](https://github.com/visulima/visulima/compare/@visulima/email@1.0.0-alpha.12...@visulima/email@1.0.0-alpha.13) (2026-04-08)
2
28
 
3
29
  ### Bug Fixes
@@ -1 +1 @@
1
- import{DkimSigner as m,createDkimSigner as i}from"../packem_shared/DkimSigner-CT2DSHD1.js";import{SmimeEncrypter as S,createSmimeEncrypter as n}from"../packem_shared/SmimeEncrypter-ZhHEgDwY.js";import{SmimeSigner as c,createSmimeSigner as p}from"../packem_shared/SmimeSigner-CYSVF6ez.js";export{m as DkimSigner,S as SmimeEncrypter,c as SmimeSigner,i as createDkimSigner,n as createSmimeEncrypter,p as createSmimeSigner};
1
+ import{DkimSigner as m,createDkimSigner as i}from"../packem_shared/DkimSigner-C8HEBBSb.js";import{SmimeEncrypter as S,createSmimeEncrypter as n}from"../packem_shared/SmimeEncrypter-CM_gM2Cd.js";import{SmimeSigner as c,createSmimeSigner as p}from"../packem_shared/SmimeSigner-vQF8_2ZJ.js";export{m as DkimSigner,S as SmimeEncrypter,c as SmimeSigner,i as createDkimSigner,n as createSmimeEncrypter,p as createSmimeSigner};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{detectMimeType as o,generateContentId as t,readFileAsBuffer as a}from"./packem_shared/detectMimeType-iprkVO8e.js";import{default as i}from"./packem_shared/EmailError-zm2ffVav.js";import{default as m}from"./packem_shared/RequiredOptionError-CevW3u2K.js";import{Mail as l,createMail as x}from"./packem_shared/Mail-e4KlaSct.js";import{MailMessage as s}from"./packem_shared/MailMessage-CeVZvVfv.js";import{defineProvider as u}from"./packem_shared/defineProvider-CtLH0VBE.js";export{i as EmailError,l as Mail,s as MailMessage,m as RequiredOptionError,x as createMail,u as defineProvider,o as detectMimeType,t as generateContentId,a as readFileAsBuffer};
1
+ import{detectMimeType as o,generateContentId as t,readFileAsBuffer as a}from"./packem_shared/detectMimeType-Dv28wXZ-.js";import{default as i}from"./packem_shared/EmailError-C4nx6TgJ.js";import{default as m}from"./packem_shared/RequiredOptionError-BeTzeno6.js";import{Mail as l,createMail as x}from"./packem_shared/Mail-CKWWPQ3P.js";import{MailMessage as s}from"./packem_shared/MailMessage-DCfFM4wk.js";import{defineProvider as u}from"./packem_shared/defineProvider-CtLH0VBE.js";export{i as EmailError,l as Mail,s as MailMessage,m as RequiredOptionError,x as createMail,u as defineProvider,o as detectMimeType,t as generateContentId,a as readFileAsBuffer};
@@ -1,4 +1,4 @@
1
- var v=Object.defineProperty;var m=(o,e)=>v(o,"name",{value:e,configurable:!0});import{createRequire as w}from"node:module";import{B as x}from"./readFile-BAVMZg5e-C4whBIPd.js";import{i as z}from"./headers-to-record-Qo124ImV.js";const C=w(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=m(o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[e,t]=p.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return p.getBuiltinModule(o)}return C(o)},"__cjs_getBuiltinModule"),{createHash:M,createSign:S,createPrivateKey:_}=T("node:crypto");var H=Object.defineProperty,d=m((o,e)=>H(o,"name",{value:e,configurable:!0}),"l");const I=d((o,e="simple")=>{const t=[];for(const[r,a]of Object.entries(o)){const n=e==="relaxed"?r.toLowerCase().trim():r,s=e==="relaxed"?a.replaceAll(/\s+/g," ").trim():a;t.push(`${n}:${s}`)}return t.join(`\r
1
+ var v=Object.defineProperty;var m=(o,e)=>v(o,"name",{value:e,configurable:!0});import{createRequire as w}from"node:module";import{i as _}from"./headers-to-record-Qo124ImV.js";import{z as x}from"./readFile-Iz7kvCCk-CVf9zS6c.js";const C=w(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=m(o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[e,t]=p.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return p.getBuiltinModule(o)}return C(o)},"__cjs_getBuiltinModule"),{createHash:z,createSign:M,createPrivateKey:S}=T("node:crypto");var H=Object.defineProperty,d=m((o,e)=>H(o,"name",{value:e,configurable:!0}),"l");const I=d((o,e="simple")=>{const t=[];for(const[r,a]of Object.entries(o)){const n=e==="relaxed"?r.toLowerCase().trim():r,s=e==="relaxed"?a.replaceAll(/\s+/g," ").trim():a;t.push(`${n}:${s}`)}return t.join(`\r
2
2
  `)},"canonicalizeHeaders"),K=d((o,e="simple")=>{if(e==="simple"){const n=o.replace(/(\r\n|\r|\n)$/,`
3
3
  `);let s=n.length;for(;s>0&&n[s-1]===`
4
4
  `;)s-=1;const c=n.slice(0,s);return c?`${c}
@@ -11,8 +11,8 @@ var v=Object.defineProperty;var m=(o,e)=>v(o,"name",{value:e,configurable:!0});i
11
11
  `);let r=t.length;for(;r>0&&t[r-1]===`
12
12
  `;)r-=1;const a=t.slice(0,r);return a?`${a}
13
13
  `:`
14
- `},"canonicalizeBody"),B=d((o,e,t)=>{const r=e.headerCanon??"simple",a=e.bodyCanon??"simple",n=Object.keys(o).filter(s=>!e.headersToIgnore?.some(c=>c.toLowerCase()===s.toLowerCase())).map(s=>s.toLowerCase()).join(":");return["v=1","a=rsa-sha256",`c=${r}/${a}`,`d=${e.domainName}`,`s=${e.keySelector}`,`h=${n}`,`bh=${t}`,"b="].join("; ")},"createDkimSignatureHeader");class i{static{m(this,"DkimSigner")}static{d(this,"DkimSigner")}static sanitizeDisplayName(e){let t=e.replaceAll(/[\r\n\t]+/g," ");t=[...t].filter(n=>{const s=n.codePointAt(0);return s===void 0?!1:s>=32&&s<=126||s>159}).join("");const r="\\",a='"';return t=t.replaceAll(r,r+r).replaceAll(a,r+a),t=t.trim().replaceAll(/\s+/g," "),t}static formatAddress(e){if(e.name){const t=i.sanitizeDisplayName(e.name);return t?`"${t}" <${e.email}>`:e.email}return e.email}static formatAddresses(e){return(Array.isArray(e)?e:[e]).map(t=>i.formatAddress(t)).join(", ")}options;constructor(e){this.options=e}async sign(e){let t=this.options.privateKey;if(t.startsWith("file://")){const l=t.slice(7);t=await x(l,{encoding:"utf8"})}const r={...e.headers?z(e.headers):{},From:i.formatAddress(e.from),To:i.formatAddresses(e.to)};e.cc&&(r.Cc=i.formatAddresses(e.cc)),e.replyTo&&(r["Reply-To"]=i.formatAddress(e.replyTo)),r.Subject=e.subject,r["MIME-Version"]="1.0";const a=[];e.text&&a.push(e.text),e.html&&a.push(e.html);const n=a.join(`
14
+ `},"canonicalizeBody"),D=d((o,e,t)=>{const r=e.headerCanon??"simple",a=e.bodyCanon??"simple",n=Object.keys(o).filter(s=>!e.headersToIgnore?.some(c=>c.toLowerCase()===s.toLowerCase())).map(s=>s.toLowerCase()).join(":");return["v=1","a=rsa-sha256",`c=${r}/${a}`,`d=${e.domainName}`,`s=${e.keySelector}`,`h=${n}`,`bh=${t}`,"b="].join("; ")},"createDkimSignatureHeader");class i{static{m(this,"DkimSigner")}static{d(this,"DkimSigner")}static sanitizeDisplayName(e){let t=e.replaceAll(/[\r\n\t]+/g," ");t=[...t].filter(n=>{const s=n.codePointAt(0);return s===void 0?!1:s>=32&&s<=126||s>159}).join("");const r="\\",a='"';return t=t.replaceAll(r,r+r).replaceAll(a,r+a),t=t.trim().replaceAll(/\s+/g," "),t}static formatAddress(e){if(e.name){const t=i.sanitizeDisplayName(e.name);return t?`"${t}" <${e.email}>`:e.email}return e.email}static formatAddresses(e){return(Array.isArray(e)?e:[e]).map(t=>i.formatAddress(t)).join(", ")}options;constructor(e){this.options=e}async sign(e){let t=this.options.privateKey;if(t.startsWith("file://")){const l=t.slice(7);t=await x(l,{encoding:"utf8"})}const r={...e.headers?_(e.headers):{},From:i.formatAddress(e.from),To:i.formatAddresses(e.to)};e.cc&&(r.Cc=i.formatAddresses(e.cc)),e.replyTo&&(r["Reply-To"]=i.formatAddress(e.replyTo)),r.Subject=e.subject,r["MIME-Version"]="1.0";const a=[];e.text&&a.push(e.text),e.html&&a.push(e.html);const n=a.join(`
15
15
 
16
- `),s=this.options.headerCanon??"simple",c=this.options.bodyCanon??"simple",g=I(r,s),y=K(n,c),A=M("sha256").update(y).digest("base64"),h=B(r,this.options,A),$=`${g}\r
17
- DKIM-Signature: ${h}`,f=S("RSA-SHA256");f.update($);let u;try{const l=_({key:t,passphrase:this.options.passphrase});u=f.sign(l,"base64")}catch(l){throw new Error(`Failed to create DKIM signature: ${l.message}`)}const j=u.match(/.{1,72}/g)?.join(`\r
18
- `)??u,b={...r,"DKIM-Signature":`${h}${j}`};return{...e,headers:b}}}const R=d(o=>new i(o),"createDkimSigner");export{i as DkimSigner,R as createDkimSigner};
16
+ `),s=this.options.headerCanon??"simple",c=this.options.bodyCanon??"simple",g=I(r,s),y=K(n,c),$=z("sha256").update(y).digest("base64"),h=D(r,this.options,$),A=`${g}\r
17
+ DKIM-Signature: ${h}`,f=M("RSA-SHA256");f.update(A);let u;try{const l=S({key:t,passphrase:this.options.passphrase});u=f.sign(l,"base64")}catch(l){throw new Error(`Failed to create DKIM signature: ${l.message}`)}const j=u.match(/.{1,72}/g)?.join(`\r
18
+ `)??u,b={...r,"DKIM-Signature":`${h}${j}`};return{...e,headers:b}}}const q=d(o=>new i(o),"createDkimSigner");export{i as DkimSigner,q as createDkimSigner};
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var i=(e,t)=>m(e,"name",{value:t,configurable:!0});var h=Object.defineProperty,r=i((e,t)=>h(e,"name",{value:t,configurable:!0}),"i");r(e=>e instanceof Error&&e.type==="VisulimaError","isVisulimaError");class u extends Error{static{i(this,"m")}static{r(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor({cause:t,hint:a,location:s,message:o,name:c,stack:n,title:l}){super(o,{cause:t}),this.title=l,this.name=c,this.stack=n??this.stack,this.loc=s,this.hint=a}setLocation(t){this.loc=t}setName(t){this.name=t}setMessage(t){this.message=t}setHint(t){this.hint=t}}var E=Object.defineProperty,p=i((e,t)=>E(e,"name",{value:t,configurable:!0}),"s");class v extends u{static{i(this,"l")}static{p(this,"EmailError")}component;code;constructor(t,a,s){super({cause:s?.cause,hint:s?.hint,message:`[@visulima/email] [${t}] ${a}`,name:"EmailError",title:`Email ${t} Error`}),this.component=t,this.code=s?.code}}export{v as default};
@@ -1 +1 @@
1
- var p=Object.defineProperty;var l=(o,e)=>p(o,"name",{value:e,configurable:!0});import{MailMessage as f}from"./MailMessage-CeVZvVfv.js";import{z as b}from"./build-mime-message-6xstxaUV.js";import{c as m}from"./create-logger-BiWdqFNg.js";import{i as n}from"./headers-to-record-Qo124ImV.js";var y=Object.defineProperty,C=l((o,e)=>y(o,"name",{value:e,configurable:!0}),"s");class h extends f{static{l(this,"DraftMailMessage")}static{C(this,"DraftMailMessage")}constructor(){super(),this.header("X-Unsent","1")}}var M=Object.defineProperty,c=l((o,e)=>M(o,"name",{value:e,configurable:!0}),"n");const v=c((o,e,s)=>{e.success&&e.data?o&&o.info("Email sent successfully",{messageId:e.data.messageId,provider:e.data.provider}):o&&o.error("Email send failed",{error:e.error,provider:s})},"logSendResult");class d{static{l(this,"Mail")}static{c(this,"Mail")}static extractErrorMessages(e){return e instanceof Error?[e.message]:[String(e??"Unknown error")]}provider;logger;loggerInstance;globalConfig;constructor(e){this.provider=e}setLogger(e){return this.loggerInstance=e,this.logger=m("Mail",e),this}setFrom(e){return this.globalConfig??={},this.globalConfig.from=e,this.logger&&this.logger.debug("Default from address updated",{from:e.email}),this}setReplyTo(e){return this.globalConfig??={},this.globalConfig.replyTo=e,this.logger&&this.logger.debug("Default reply-to address updated",{replyTo:e.email}),this}setHeaders(e){if(this.globalConfig??={},this.globalConfig.headers=e,this.logger){const s=n(e);this.logger.debug("Default headers updated",{count:Object.keys(s).length,headers:Object.keys(s)})}return this}async draft(e){let s=e instanceof f||e instanceof h?await this.buildDraftFromMessage(e):await this.buildDraftFromOptions(e);s=this.applyGlobalConfig(s);const t=s.headers?n(s.headers):{};s.headers={...t,"X-Unsent":"1"};const r=await b(s);return this.logger&&this.logger.debug("Draft created successfully in EML format",{from:s.from.email,size:r.length,subject:s.subject,to:Array.isArray(s.to)?s.to.length:1}),r}async send(e){if(e instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");let s;if(e instanceof f)this.logger&&this.logger.debug("Sending MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),s=await e.build();else{const r=e;this.logger&&this.logger.debug("Sending email with options",{subject:r.subject,to:Array.isArray(r.to)?r.to.length:1}),s=r}s=this.applyGlobalConfig(s);const t=await this.provider.sendEmail(s);return v(this.logger,t,this.provider.name??"unknown"),t}async*sendMany(e,s){const t=this.provider.name;let r=0,g=0,i=0;this.logger&&this.logger.debug("Starting batch email send",{provider:t});for await(const u of e){if(u instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");if(s?.signal?.aborted){this.logger&&this.logger.warn("Batch send operation was aborted",{failed:i,processed:r,successful:g}),yield{errorMessages:["Send operation was aborted"],provider:t,successful:!1};return}r+=1;try{const a=await this.send(u);a.success&&a.data?(g+=1,this.logger&&this.logger.debug(`Email ${r} sent successfully`,{messageId:a.data.messageId}),yield{messageId:a.data.messageId,provider:a.data.provider??t,response:a.data.response,successful:!0,timestamp:a.data.timestamp}):(i+=1,this.logger&&this.logger.error(`Email ${r} send failed`,{error:a.error}),yield{errorMessages:d.extractErrorMessages(a.error),provider:t,successful:!1})}catch(a){i+=1,this.logger&&this.logger.error(`Email ${r} send failed with exception`,a),yield{errorMessages:d.extractErrorMessages(a),provider:t,successful:!1}}}this.logger&&this.logger.debug("Batch email send completed",{failureCount:i,processedCount:r,provider:t,successCount:g})}async buildDraftFromMessage(e){return this.logger&&this.logger.debug("Creating draft from MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),this.applyGlobalConfigToMessage(e),await e.build()}async buildDraftFromOptions(e){return this.logger&&this.logger.debug("Creating draft from email options",{subject:e.subject,to:Array.isArray(e.to)?e.to.length:1}),e}applyGlobalConfigToMessage(e){const s=this.globalConfig?.from;s&&!e.getFrom()&&e.from(s);const t=this.globalConfig?.replyTo;if(t&&!e.getReplyTo()&&e.replyTo(t),this.globalConfig?.headers){const r=n(this.globalConfig.headers);Object.entries(r).forEach(([g,i])=>{e.header(g,i)})}}applyGlobalConfig(e){if(!this.globalConfig)return e;const s={...e};if(!s.from&&this.globalConfig.from&&(s.from=this.globalConfig.from,this.logger&&this.logger.debug("Applied global from address",{from:this.globalConfig.from.email})),!s.replyTo&&this.globalConfig.replyTo&&(s.replyTo=this.globalConfig.replyTo,this.logger&&this.logger.debug("Applied global reply-to address",{replyTo:this.globalConfig.replyTo.email})),this.globalConfig.headers){const t=n(this.globalConfig.headers),r=s.headers?n(s.headers):{};s.headers={...t,...r},this.logger&&this.logger.debug("Merged global headers",{globalCount:Object.keys(t).length,messageCount:Object.keys(r).length})}return s}}const D=c(o=>new d(o),"createMail");export{d as Mail,D as createMail};
1
+ var p=Object.defineProperty;var l=(o,e)=>p(o,"name",{value:e,configurable:!0});import{MailMessage as f}from"./MailMessage-DCfFM4wk.js";import{z as b}from"./build-mime-message-Bv456sHf.js";import{c as m}from"./create-logger-BiWdqFNg.js";import{i as n}from"./headers-to-record-Qo124ImV.js";var y=Object.defineProperty,C=l((o,e)=>y(o,"name",{value:e,configurable:!0}),"s");class h extends f{static{l(this,"DraftMailMessage")}static{C(this,"DraftMailMessage")}constructor(){super(),this.header("X-Unsent","1")}}var M=Object.defineProperty,c=l((o,e)=>M(o,"name",{value:e,configurable:!0}),"n");const v=c((o,e,s)=>{e.success&&e.data?o&&o.info("Email sent successfully",{messageId:e.data.messageId,provider:e.data.provider}):o&&o.error("Email send failed",{error:e.error,provider:s})},"logSendResult");class d{static{l(this,"Mail")}static{c(this,"Mail")}static extractErrorMessages(e){return e instanceof Error?[e.message]:[String(e??"Unknown error")]}provider;logger;loggerInstance;globalConfig;constructor(e){this.provider=e}setLogger(e){return this.loggerInstance=e,this.logger=m("Mail",e),this}setFrom(e){return this.globalConfig??={},this.globalConfig.from=e,this.logger&&this.logger.debug("Default from address updated",{from:e.email}),this}setReplyTo(e){return this.globalConfig??={},this.globalConfig.replyTo=e,this.logger&&this.logger.debug("Default reply-to address updated",{replyTo:e.email}),this}setHeaders(e){if(this.globalConfig??={},this.globalConfig.headers=e,this.logger){const s=n(e);this.logger.debug("Default headers updated",{count:Object.keys(s).length,headers:Object.keys(s)})}return this}async draft(e){let s=e instanceof f||e instanceof h?await this.buildDraftFromMessage(e):await this.buildDraftFromOptions(e);s=this.applyGlobalConfig(s);const t=s.headers?n(s.headers):{};s.headers={...t,"X-Unsent":"1"};const r=await b(s);return this.logger&&this.logger.debug("Draft created successfully in EML format",{from:s.from.email,size:r.length,subject:s.subject,to:Array.isArray(s.to)?s.to.length:1}),r}async send(e){if(e instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");let s;if(e instanceof f)this.logger&&this.logger.debug("Sending MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),s=await e.build();else{const r=e;this.logger&&this.logger.debug("Sending email with options",{subject:r.subject,to:Array.isArray(r.to)?r.to.length:1}),s=r}s=this.applyGlobalConfig(s);const t=await this.provider.sendEmail(s);return v(this.logger,t,this.provider.name??"unknown"),t}async*sendMany(e,s){const t=this.provider.name;let r=0,g=0,i=0;this.logger&&this.logger.debug("Starting batch email send",{provider:t});for await(const u of e){if(u instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");if(s?.signal?.aborted){this.logger&&this.logger.warn("Batch send operation was aborted",{failed:i,processed:r,successful:g}),yield{errorMessages:["Send operation was aborted"],provider:t,successful:!1};return}r+=1;try{const a=await this.send(u);a.success&&a.data?(g+=1,this.logger&&this.logger.debug(`Email ${r} sent successfully`,{messageId:a.data.messageId}),yield{messageId:a.data.messageId,provider:a.data.provider??t,response:a.data.response,successful:!0,timestamp:a.data.timestamp}):(i+=1,this.logger&&this.logger.error(`Email ${r} send failed`,{error:a.error}),yield{errorMessages:d.extractErrorMessages(a.error),provider:t,successful:!1})}catch(a){i+=1,this.logger&&this.logger.error(`Email ${r} send failed with exception`,a),yield{errorMessages:d.extractErrorMessages(a),provider:t,successful:!1}}}this.logger&&this.logger.debug("Batch email send completed",{failureCount:i,processedCount:r,provider:t,successCount:g})}async buildDraftFromMessage(e){return this.logger&&this.logger.debug("Creating draft from MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),this.applyGlobalConfigToMessage(e),await e.build()}async buildDraftFromOptions(e){return this.logger&&this.logger.debug("Creating draft from email options",{subject:e.subject,to:Array.isArray(e.to)?e.to.length:1}),e}applyGlobalConfigToMessage(e){const s=this.globalConfig?.from;s&&!e.getFrom()&&e.from(s);const t=this.globalConfig?.replyTo;if(t&&!e.getReplyTo()&&e.replyTo(t),this.globalConfig?.headers){const r=n(this.globalConfig.headers);Object.entries(r).forEach(([g,i])=>{e.header(g,i)})}}applyGlobalConfig(e){if(!this.globalConfig)return e;const s={...e};if(!s.from&&this.globalConfig.from&&(s.from=this.globalConfig.from,this.logger&&this.logger.debug("Applied global from address",{from:this.globalConfig.from.email})),!s.replyTo&&this.globalConfig.replyTo&&(s.replyTo=this.globalConfig.replyTo,this.logger&&this.logger.debug("Applied global reply-to address",{replyTo:this.globalConfig.replyTo.email})),this.globalConfig.headers){const t=n(this.globalConfig.headers),r=s.headers?n(s.headers):{};s.headers={...t,...r},this.logger&&this.logger.debug("Merged global headers",{globalCount:Object.keys(t).length,messageCount:Object.keys(r).length})}return s}}const D=c(o=>new d(o),"createMail");export{d as Mail,D as createMail};
@@ -1 +1 @@
1
- var A=Object.defineProperty;var d=(n,e)=>A(n,"name",{value:e,configurable:!0});import{createRequire as b}from"node:module";import C from"ical-generator";import{readFileAsBuffer as u,detectMimeType as g,generateContentId as m}from"./detectMimeType-iprkVO8e.js";import p from"../template-engines/html-to-text.js";import{c as E}from"./create-logger-BiWdqFNg.js";import{i as l}from"./headers-to-record-Qo124ImV.js";const T=b(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=d(n=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,t]=a.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return a.getBuiltinModule(n)}return T(n)},"__cjs_getBuiltinModule"),{basename:c}=f("node:path"),{fileURLToPath:x}=f("node:url");var w=Object.defineProperty,y=d((n,e)=>w(n,"name",{value:e,configurable:!0}),"l");const o=y(n=>Array.isArray(n)?n.map(e=>typeof e=="string"?{email:e}:e):typeof n=="string"?[{email:n}]:[n],"normalizeAddresses");class M{static{d(this,"MailMessage")}static{y(this,"MailMessage")}fromAddress;toAddresses=[];ccAddresses=[];bccAddresses=[];subjectText="";textContent;textCharset="utf8";autoTextEnabled=!0;htmlContent;htmlCharset="utf8";dateValue;returnPathAddress;senderAddress;headers={};attachments=[];replyToAddress;priorityValue;tagsValue=[];signer;encrypter;logger;icalEventData;from(e){return this.fromAddress=typeof e=="string"?{email:e}:e,this}to(e){return this.toAddresses.length=0,this.toAddresses.push(...o(e)),this}cc(e){return this.ccAddresses.length=0,this.ccAddresses.push(...o(e)),this}bcc(e){return this.bccAddresses.length=0,this.bccAddresses.push(...o(e)),this}subject(e){return this.subjectText=e,this}text(e,t="utf8"){return this.textContent=e,this.textCharset=t,this}html(e,t="utf8"){return this.htmlContent=e,this.htmlCharset=t,this}header(e,t){return this.headers[e]=t,this}setHeaders(e){const t=l(e);return Object.assign(this.headers,t),this}async attachFromPath(e,t){try{const s=await u(e),i=t?.filename??(c(e)||"attachment"),r=t?.contentType??g(i);this.attachments.push({cid:t?.cid,content:s,contentDisposition:t?.contentDisposition??"attachment",contentType:r,encoding:t?.encoding,filename:i,headers:t?.headers}),this.logger&&this.logger.debug(`Attachment added from path: ${e}`,{contentType:r,filename:i})}catch(s){throw this.logger&&this.logger.error(`Failed to attach file from path: ${e}`,s),s}return this}attachData(e,t){const s=t.contentType??g(t.filename);return this.attachments.push({cid:t.cid,content:e,contentDisposition:t.contentDisposition??"attachment",contentType:s,encoding:t.encoding,filename:t.filename,headers:t.headers}),this.logger&&this.logger.debug("Attachment added from data",{contentType:s,filename:t.filename}),this}async embedFromPath(e,t){try{const s=await u(e),i=t?.filename??(c(e)||"inline"),r=t?.contentType??g(i),h=m(i);return this.attachments.push({cid:h,content:s,contentDisposition:"inline",contentType:r,filename:i}),this.logger&&this.logger.debug(`Inline attachment embedded from path: ${e}`,{cid:h,contentType:r,filename:i}),h}catch(s){throw this.logger&&this.logger.error(`Failed to embed file from path: ${e}`,s),s}}embedData(e,t,s){const i=s?.contentType??g(t),r=m(t);return this.attachments.push({cid:r,content:e,contentDisposition:"inline",contentType:i,filename:t}),this.logger&&this.logger.debug("Inline attachment embedded from data",{cid:r,contentType:i,filename:t}),r}replyTo(e){return this.replyToAddress=typeof e=="string"?{email:e}:e,this}date(e){return this.dateValue=typeof e=="string"?new Date(e):e,this.logger&&this.logger.debug("Date header set",{date:this.dateValue.toISOString()}),this}returnPath(e){return this.returnPathAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Return-path address set",{returnPath:this.returnPathAddress.email}),this}sender(e){return this.senderAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Sender address set",{sender:this.senderAddress.email}),this}addTo(e){return this.toAddresses.push(...o(e)),this}addCc(e){return this.ccAddresses.push(...o(e)),this}addBcc(e){return this.bccAddresses.push(...o(e)),this}addReplyTo(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.replyToAddress=typeof s=="string"?{email:s}:s}return this}addFrom(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.fromAddress=typeof s=="string"?{email:s}:s}return this}priority(e){return this.priorityValue=e,this}tags(e){return this.tagsValue=Array.isArray(e)?e:[e],this}sign(e){return this.signer=e,this.logger&&this.logger.debug("Email signer configured"),this}encrypt(e){return this.encrypter=e,this.logger&&this.logger.debug("Email encrypter configured"),this}setLogger(e){return this.logger=E("MailMessage",e),this}icalEvent(e,t){if(typeof e=="function"){const s=C();e(s),this.icalEventData={content:s.toString(),...t}}else this.icalEventData={content:e,...t};return this.logger&&this.logger.debug("Calendar event attached",{method:t?.method}),this}icalEventFromFile(e,t){const s=typeof e=="string"?e:x(e);return this.icalEventData={path:s,...t},this.logger&&this.logger.debug(`Calendar event attached from file: ${s}`,{method:t?.method}),this}icalEventFromUrl(e,t){return this.icalEventData={href:e,...t},this.logger&&this.logger.debug(`Calendar event attached from URL: ${e}`,{method:t?.method}),this}async view(e,t,s,i){try{const r=i?.autoText!==!1;this.autoTextEnabled=r,this.logger&&this.logger.debug("Rendering template",{autoText:r});const h=await e(t,s,i);this.html(h),r&&h&&this.tryAutoGenerateText(h),this.logger&&this.logger.debug("Template rendered successfully")}catch(r){throw this.logger&&this.logger.error("Failed to render template",r),new Error(`Failed to render template: ${r.message}`)}return this}async viewText(e,t,s,i){try{this.logger&&this.logger.debug("Rendering text template");const r=await e(t,s,i);if(typeof r=="string")this.text(r),this.logger&&this.logger.debug("Text template rendered successfully");else throw new TypeError("Text renderer must return a string")}catch(r){throw this.logger&&this.logger.error("Failed to render text template",r),new Error(`Failed to render text template: ${r.message}`)}return this}async build(){if(this.logger&&this.logger.debug("Building email message"),this.fromAddress||this.throwAndLogError("From address is required","Build failed: from address is required"),this.toAddresses.length===0&&this.throwAndLogError("At least one recipient is required","Build failed: at least one recipient is required"),this.subjectText||this.throwAndLogError("Subject is required","Build failed: subject is required"),this.htmlContent&&!this.textContent&&this.autoTextEnabled)try{this.textContent=p(this.htmlContent),this.logger&&this.logger.debug("Auto-generated text content from HTML")}catch{this.logger&&this.logger.debug("Failed to convert HTML to text; proceeding without text content.")}!this.textContent&&!this.htmlContent&&this.throwAndLogError("Either text or html content is required","Build failed: either text or html content is required");let e={from:this.fromAddress,html:this.htmlContent,subject:this.subjectText,text:this.textContent,to:this.toAddresses.length===1?this.toAddresses[0]:this.toAddresses};return this.ccAddresses.length>0&&(e.cc=this.ccAddresses.length===1?this.ccAddresses[0]:this.ccAddresses),this.bccAddresses.length>0&&(e.bcc=this.bccAddresses.length===1?this.bccAddresses[0]:this.bccAddresses),Object.keys(this.headers).length>0&&(e.headers=this.headers),this.attachments.length>0&&(e.attachments=this.attachments,this.logger&&this.logger.debug(`Email includes ${this.attachments.length} attachment(s)`)),this.replyToAddress&&(e.replyTo=this.replyToAddress),this.priorityValue&&(e.priority=this.priorityValue),this.tagsValue.length>0&&(e.tags=this.tagsValue),this.icalEventData&&(e.icalEvent=this.icalEventData,this.logger&&this.logger.debug("Email includes calendar event")),this.dateValue&&(e.headers={...l(e.headers??{}),Date:this.dateValue.toUTCString()}),this.returnPathAddress&&(e.headers={...l(e.headers??{}),"Return-Path":this.returnPathAddress.email}),this.senderAddress&&(e.headers={...l(e.headers??{}),Sender:this.senderAddress.email}),this.signer&&(this.logger&&this.logger.debug("Signing email message"),e=await this.signer.sign(e),this.logger&&this.logger.debug("Email message signed successfully")),this.encrypter&&(this.logger&&this.logger.debug("Encrypting email message"),e=await this.encrypter.encrypt(e),this.logger&&this.logger.debug("Email message encrypted successfully")),this.logger&&this.logger.debug("Email message built successfully",{bcc:this.bccAddresses.length,cc:this.ccAddresses.length,hasHtml:!!this.htmlContent,hasText:!!this.textContent,to:this.toAddresses.length}),e}getSubject(){return this.subjectText}getFrom(){return this.fromAddress}getTo(){return[...this.toAddresses]}getCc(){return[...this.ccAddresses]}getBcc(){return[...this.bccAddresses]}getReplyTo(){return this.replyToAddress}getSender(){return this.senderAddress}getReturnPath(){return this.returnPathAddress}getDate(){return this.dateValue}getPriority(){return this.priorityValue}getTextBody(){return this.textContent}getTextCharset(){return this.textCharset}getHtmlBody(){return this.htmlContent}getHtmlCharset(){return this.htmlCharset}getAttachments(){return[...this.attachments]}tryAutoGenerateText(e){try{const t=p(e);t&&!this.textContent&&this.text(t),this.logger&&this.logger.debug("Auto-generated text content from HTML template")}catch(t){this.logger&&this.logger.warn("Failed to auto-generate text from HTML template",t)}}throwAndLogError(e,t){const s=new Error(e);throw this.logger&&this.logger.error(t??e),s}}export{M as MailMessage,M as default};
1
+ var A=Object.defineProperty;var d=(n,e)=>A(n,"name",{value:e,configurable:!0});import{createRequire as b}from"node:module";import C from"ical-generator";import{readFileAsBuffer as u,detectMimeType as g,generateContentId as m}from"./detectMimeType-Dv28wXZ-.js";import p from"../template-engines/html-to-text.js";import{c as E}from"./create-logger-BiWdqFNg.js";import{i as l}from"./headers-to-record-Qo124ImV.js";const T=b(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=d(n=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,t]=a.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return a.getBuiltinModule(n)}return T(n)},"__cjs_getBuiltinModule"),{basename:c}=f("node:path"),{fileURLToPath:x}=f("node:url");var w=Object.defineProperty,y=d((n,e)=>w(n,"name",{value:e,configurable:!0}),"l");const o=y(n=>Array.isArray(n)?n.map(e=>typeof e=="string"?{email:e}:e):typeof n=="string"?[{email:n}]:[n],"normalizeAddresses");class M{static{d(this,"MailMessage")}static{y(this,"MailMessage")}fromAddress;toAddresses=[];ccAddresses=[];bccAddresses=[];subjectText="";textContent;textCharset="utf8";autoTextEnabled=!0;htmlContent;htmlCharset="utf8";dateValue;returnPathAddress;senderAddress;headers={};attachments=[];replyToAddress;priorityValue;tagsValue=[];signer;encrypter;logger;icalEventData;from(e){return this.fromAddress=typeof e=="string"?{email:e}:e,this}to(e){return this.toAddresses.length=0,this.toAddresses.push(...o(e)),this}cc(e){return this.ccAddresses.length=0,this.ccAddresses.push(...o(e)),this}bcc(e){return this.bccAddresses.length=0,this.bccAddresses.push(...o(e)),this}subject(e){return this.subjectText=e,this}text(e,t="utf8"){return this.textContent=e,this.textCharset=t,this}html(e,t="utf8"){return this.htmlContent=e,this.htmlCharset=t,this}header(e,t){return this.headers[e]=t,this}setHeaders(e){const t=l(e);return Object.assign(this.headers,t),this}async attachFromPath(e,t){try{const s=await u(e),i=t?.filename??(c(e)||"attachment"),r=t?.contentType??g(i);this.attachments.push({cid:t?.cid,content:s,contentDisposition:t?.contentDisposition??"attachment",contentType:r,encoding:t?.encoding,filename:i,headers:t?.headers}),this.logger&&this.logger.debug(`Attachment added from path: ${e}`,{contentType:r,filename:i})}catch(s){throw this.logger&&this.logger.error(`Failed to attach file from path: ${e}`,s),s}return this}attachData(e,t){const s=t.contentType??g(t.filename);return this.attachments.push({cid:t.cid,content:e,contentDisposition:t.contentDisposition??"attachment",contentType:s,encoding:t.encoding,filename:t.filename,headers:t.headers}),this.logger&&this.logger.debug("Attachment added from data",{contentType:s,filename:t.filename}),this}async embedFromPath(e,t){try{const s=await u(e),i=t?.filename??(c(e)||"inline"),r=t?.contentType??g(i),h=m(i);return this.attachments.push({cid:h,content:s,contentDisposition:"inline",contentType:r,filename:i}),this.logger&&this.logger.debug(`Inline attachment embedded from path: ${e}`,{cid:h,contentType:r,filename:i}),h}catch(s){throw this.logger&&this.logger.error(`Failed to embed file from path: ${e}`,s),s}}embedData(e,t,s){const i=s?.contentType??g(t),r=m(t);return this.attachments.push({cid:r,content:e,contentDisposition:"inline",contentType:i,filename:t}),this.logger&&this.logger.debug("Inline attachment embedded from data",{cid:r,contentType:i,filename:t}),r}replyTo(e){return this.replyToAddress=typeof e=="string"?{email:e}:e,this}date(e){return this.dateValue=typeof e=="string"?new Date(e):e,this.logger&&this.logger.debug("Date header set",{date:this.dateValue.toISOString()}),this}returnPath(e){return this.returnPathAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Return-path address set",{returnPath:this.returnPathAddress.email}),this}sender(e){return this.senderAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Sender address set",{sender:this.senderAddress.email}),this}addTo(e){return this.toAddresses.push(...o(e)),this}addCc(e){return this.ccAddresses.push(...o(e)),this}addBcc(e){return this.bccAddresses.push(...o(e)),this}addReplyTo(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.replyToAddress=typeof s=="string"?{email:s}:s}return this}addFrom(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.fromAddress=typeof s=="string"?{email:s}:s}return this}priority(e){return this.priorityValue=e,this}tags(e){return this.tagsValue=Array.isArray(e)?e:[e],this}sign(e){return this.signer=e,this.logger&&this.logger.debug("Email signer configured"),this}encrypt(e){return this.encrypter=e,this.logger&&this.logger.debug("Email encrypter configured"),this}setLogger(e){return this.logger=E("MailMessage",e),this}icalEvent(e,t){if(typeof e=="function"){const s=C();e(s),this.icalEventData={content:s.toString(),...t}}else this.icalEventData={content:e,...t};return this.logger&&this.logger.debug("Calendar event attached",{method:t?.method}),this}icalEventFromFile(e,t){const s=typeof e=="string"?e:x(e);return this.icalEventData={path:s,...t},this.logger&&this.logger.debug(`Calendar event attached from file: ${s}`,{method:t?.method}),this}icalEventFromUrl(e,t){return this.icalEventData={href:e,...t},this.logger&&this.logger.debug(`Calendar event attached from URL: ${e}`,{method:t?.method}),this}async view(e,t,s,i){try{const r=i?.autoText!==!1;this.autoTextEnabled=r,this.logger&&this.logger.debug("Rendering template",{autoText:r});const h=await e(t,s,i);this.html(h),r&&h&&this.tryAutoGenerateText(h),this.logger&&this.logger.debug("Template rendered successfully")}catch(r){throw this.logger&&this.logger.error("Failed to render template",r),new Error(`Failed to render template: ${r.message}`)}return this}async viewText(e,t,s,i){try{this.logger&&this.logger.debug("Rendering text template");const r=await e(t,s,i);if(typeof r=="string")this.text(r),this.logger&&this.logger.debug("Text template rendered successfully");else throw new TypeError("Text renderer must return a string")}catch(r){throw this.logger&&this.logger.error("Failed to render text template",r),new Error(`Failed to render text template: ${r.message}`)}return this}async build(){if(this.logger&&this.logger.debug("Building email message"),this.fromAddress||this.throwAndLogError("From address is required","Build failed: from address is required"),this.toAddresses.length===0&&this.throwAndLogError("At least one recipient is required","Build failed: at least one recipient is required"),this.subjectText||this.throwAndLogError("Subject is required","Build failed: subject is required"),this.htmlContent&&!this.textContent&&this.autoTextEnabled)try{this.textContent=p(this.htmlContent),this.logger&&this.logger.debug("Auto-generated text content from HTML")}catch{this.logger&&this.logger.debug("Failed to convert HTML to text; proceeding without text content.")}!this.textContent&&!this.htmlContent&&this.throwAndLogError("Either text or html content is required","Build failed: either text or html content is required");let e={from:this.fromAddress,html:this.htmlContent,subject:this.subjectText,text:this.textContent,to:this.toAddresses.length===1?this.toAddresses[0]:this.toAddresses};return this.ccAddresses.length>0&&(e.cc=this.ccAddresses.length===1?this.ccAddresses[0]:this.ccAddresses),this.bccAddresses.length>0&&(e.bcc=this.bccAddresses.length===1?this.bccAddresses[0]:this.bccAddresses),Object.keys(this.headers).length>0&&(e.headers=this.headers),this.attachments.length>0&&(e.attachments=this.attachments,this.logger&&this.logger.debug(`Email includes ${this.attachments.length} attachment(s)`)),this.replyToAddress&&(e.replyTo=this.replyToAddress),this.priorityValue&&(e.priority=this.priorityValue),this.tagsValue.length>0&&(e.tags=this.tagsValue),this.icalEventData&&(e.icalEvent=this.icalEventData,this.logger&&this.logger.debug("Email includes calendar event")),this.dateValue&&(e.headers={...l(e.headers??{}),Date:this.dateValue.toUTCString()}),this.returnPathAddress&&(e.headers={...l(e.headers??{}),"Return-Path":this.returnPathAddress.email}),this.senderAddress&&(e.headers={...l(e.headers??{}),Sender:this.senderAddress.email}),this.signer&&(this.logger&&this.logger.debug("Signing email message"),e=await this.signer.sign(e),this.logger&&this.logger.debug("Email message signed successfully")),this.encrypter&&(this.logger&&this.logger.debug("Encrypting email message"),e=await this.encrypter.encrypt(e),this.logger&&this.logger.debug("Email message encrypted successfully")),this.logger&&this.logger.debug("Email message built successfully",{bcc:this.bccAddresses.length,cc:this.ccAddresses.length,hasHtml:!!this.htmlContent,hasText:!!this.textContent,to:this.toAddresses.length}),e}getSubject(){return this.subjectText}getFrom(){return this.fromAddress}getTo(){return[...this.toAddresses]}getCc(){return[...this.ccAddresses]}getBcc(){return[...this.bccAddresses]}getReplyTo(){return this.replyToAddress}getSender(){return this.senderAddress}getReturnPath(){return this.returnPathAddress}getDate(){return this.dateValue}getPriority(){return this.priorityValue}getTextBody(){return this.textContent}getTextCharset(){return this.textCharset}getHtmlBody(){return this.htmlContent}getHtmlCharset(){return this.htmlCharset}getAttachments(){return[...this.attachments]}tryAutoGenerateText(e){try{const t=p(e);t&&!this.textContent&&this.text(t),this.logger&&this.logger.debug("Auto-generated text content from HTML template")}catch(t){this.logger&&this.logger.warn("Failed to auto-generate text from HTML template",t)}}throwAndLogError(e,t){const s=new Error(e);throw this.logger&&this.logger.error(t??e),s}}export{M as MailMessage,M as default};
@@ -1 +1 @@
1
- var n=Object.defineProperty;var t=(i,r)=>n(i,"name",{value:r,configurable:!0});import a from"./EmailError-zm2ffVav.js";var p=Object.defineProperty,d=t((i,r)=>p(i,"name",{value:r,configurable:!0}),"s");class c extends a{static{t(this,"d")}static{d(this,"RequiredOptionError")}constructor(r,e){const s=Array.isArray(e)?`Missing required options: ${e.map(o=>`'${o}'`).join(", ")}`:`Missing required option: '${e}'`;super(r,s,{hint:Array.isArray(e)?`Please provide the following required options: ${e.map(o=>`'${o}'`).join(", ")}`:`Please provide the required option: '${e}'`}),this.name="RequiredOptionError"}}export{c as default};
1
+ var n=Object.defineProperty;var t=(i,r)=>n(i,"name",{value:r,configurable:!0});import a from"./EmailError-C4nx6TgJ.js";var p=Object.defineProperty,d=t((i,r)=>p(i,"name",{value:r,configurable:!0}),"s");class c extends a{static{t(this,"d")}static{d(this,"RequiredOptionError")}constructor(r,e){const s=Array.isArray(e)?`Missing required options: ${e.map(o=>`'${o}'`).join(", ")}`:`Missing required option: '${e}'`;super(r,s,{hint:Array.isArray(e)?`Please provide the following required options: ${e.map(o=>`'${o}'`).join(", ")}`:`Please provide the required option: '${e}'`}),this.name="RequiredOptionError"}}export{c as default};
@@ -1,6 +1,6 @@
1
- var K=Object.defineProperty;var g=(s,e)=>K(s,"name",{value:e,configurable:!0});import{createRequire as U}from"node:module";import{B as S}from"./readFile-BAVMZg5e-C4whBIPd.js";import{fromBER as $,OctetString as T}from"asn1js";import{Certificate as j,EnvelopedData as z,EncryptedContentInfo as J,id_ContentType_Data as Q,RecipientInfo as W,KeyTransRecipientInfo as X,IssuerAndSerialNumber as Y,AlgorithmIdentifier as x,ContentInfo as Z,id_ContentType_EnvelopedData as ee}from"pkijs";const q=U(import.meta.url),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,H=g(s=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,t]=h.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return h.getBuiltinModule(s)}return q(s)},"__cjs_getBuiltinModule"),{randomBytes:I,createCipheriv:L,createPublicKey:G,publicEncrypt:V}=H("node:crypto");var te=Object.defineProperty,y=g((s,e)=>te(s,"name",{value:e,configurable:!0}),"l");const w=globalThis.Buffer!==void 0,N=y(s=>{const e=s.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(w)return Buffer.from(e,"base64");const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n},"pemToDer"),R=y((s,e)=>{let t;if(w)t=Buffer.from(s).toString("base64");else{const r=new Uint8Array(s);let u="";const o=8192;for(let i=0;i<r.length;i+=o){const m=r.subarray(i,Math.min(i+o,r.length));u+=String.fromCharCode(...m)}t=btoa(u)}const n=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
1
+ var K=Object.defineProperty;var g=(s,e)=>K(s,"name",{value:e,configurable:!0});import{createRequire as U}from"node:module";import{fromBER as S,OctetString as T}from"asn1js";import{Certificate as $,EnvelopedData as V,EncryptedContentInfo as J,id_ContentType_Data as Q,RecipientInfo as W,KeyTransRecipientInfo as X,IssuerAndSerialNumber as Y,AlgorithmIdentifier as j,ContentInfo as Z,id_ContentType_EnvelopedData as ee}from"pkijs";import{z as x}from"./readFile-Iz7kvCCk-CVf9zS6c.js";const q=U(import.meta.url),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,H=g(s=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,t]=h.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return h.getBuiltinModule(s)}return q(s)},"__cjs_getBuiltinModule"),{randomBytes:B,createCipheriv:L,createPublicKey:G,publicEncrypt:z}=H("node:crypto");var te=Object.defineProperty,y=g((s,e)=>te(s,"name",{value:e,configurable:!0}),"l");const w=globalThis.Buffer!==void 0,N=y(s=>{const e=s.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(w)return Buffer.from(e,"base64");const t=atob(e),n=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)n[r]=t.charCodeAt(r);return n},"pemToDer"),R=y((s,e)=>{let t;if(w)t=Buffer.from(s).toString("base64");else{const r=new Uint8Array(s);let u="";const o=8192;for(let i=0;i<r.length;i+=o){const m=r.subarray(i,Math.min(i+o,r.length));u+=String.fromCharCode(...m)}t=btoa(u)}const n=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
2
2
  ${n.join(`
3
3
  `)}
4
4
  -----END ${e}-----
5
- `},"derToPem");class a{static{g(this,"SmimeEncrypter")}static{y(this,"SmimeEncrypter")}static collectRecipients(e){const t=[],n=y(r=>{if(!r)return;const u=Array.isArray(r)?r:[r];for(const o of u){const i=typeof o=="string"?o:o.email;i&&t.push(i)}},"extractEmails");return n(e.to),n(e.cc),n(e.bcc),[...new Set(t)]}static formatAddress(e){return typeof e=="string"?e:e.name?`"${e.name}" <${e.email}>`:e.email}static formatAddresses(e){return(Array.isArray(e)?e:[e]).map(t=>a.formatAddress(t)).join(", ")}options;constructor(e){this.options=e}async encrypt(e){const t=a.collectRecipients(e),n=[];if(typeof this.options.certificates=="string"){const c=await S(this.options.certificates,{encoding:"utf8"}),f=N(c),l=$(f);if(l.offset===-1)throw new Error("Failed to parse certificate: Invalid ASN.1 structure");n.push(new j({schema:l.result}))}else{const c=t.map(async f=>{const l=this.options.certificates[f];if(!l)throw new Error(`No certificate found for recipient: ${f}`);const E=await S(l,{encoding:"utf8"}),v=N(E),p=$(v);if(p.offset===-1)throw new Error(`Failed to parse certificate for ${f}: Invalid ASN.1 structure`);return new j({schema:p.result})});n.push(...await Promise.all(c))}const r=await this.buildMessage(e),u=new TextEncoder().encode(r),o=new z({version:0});o.encryptedContentInfo=new J({contentType:Q});const i=(this.options.algorithm??"aes-256-cbc").toLowerCase();if(i==="3des"||i==="des-ede3-cbc")throw new Error("3DES/DES-EDE3-CBC is deprecated and insecure (Sweet32 vulnerability). Please use AES-256-CBC, AES-192-CBC, or AES-128-CBC instead.");let m,d;switch(i){case"aes128":case"aes-128-cbc":{m="2.16.840.1.101.3.4.1.2",d=16;break}case"aes192":case"aes-192-cbc":{m="2.16.840.1.101.3.4.1.22",d=24;break}default:{m="2.16.840.1.101.3.4.1.42",d=32;break}}const A=I(d),D=w?A:new Uint8Array(A),C=I(16),P=w?C:new Uint8Array(C),B=L(`aes-${d*8}-cbc`,A,C),_=Buffer.from(u),k=[B.update(_),B.final()],b=Buffer.concat(k);o.encryptedContentInfo.encryptedContent=new T({valueHex:b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength)});const M=await Promise.all(n.map(async c=>{const f=c.toSchema().toBER(!1),l=R(f,"CERTIFICATE"),E=G(l),v=Buffer.from(D),p=V({key:E,padding:1},v);return new W({value:new X({encryptedKey:new T({valueHex:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength)}),keyEncryptionAlgorithm:new x({algorithmId:"1.2.840.113549.1.1.1"}),rid:new Y({issuer:c.issuer,serialNumber:c.serialNumber}),version:0}),variant:0})}));o.recipientInfos.push(...M),o.encryptedContentInfo.contentEncryptionAlgorithm=new x({algorithmId:m,algorithmParams:new T({valueHex:P.buffer})});const O=new Z({content:o.toSchema(),contentType:ee}).toSchema().toBER(!1),F=R(O,"PKCS7");return{...e,headers:{...e.headers,"Content-Disposition":"attachment; filename=smime.p7m","Content-Transfer-Encoding":"base64","Content-Type":"application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m"},html:void 0,text:F}}async buildMessage(e){const t=[`From: ${a.formatAddress(e.from)}`,`To: ${a.formatAddresses(e.to)}`,...e.cc?[`Cc: ${a.formatAddresses(e.cc)}`]:[]];if(e.replyTo&&t.push(`Reply-To: ${a.formatAddress(e.replyTo)}`),t.push(`Subject: ${e.subject}`,"MIME-Version: 1.0"),e.headers)for(const[n,r]of Object.entries(e.headers))t.push(`${n}: ${r}`);return e.html?t.push("Content-Type: text/html; charset=utf-8"):e.text&&t.push("Content-Type: text/plain; charset=utf-8"),t.push(""),e.html?t.push(e.html):e.text&&t.push(e.text),t.join(`\r
5
+ `},"derToPem");class a{static{g(this,"SmimeEncrypter")}static{y(this,"SmimeEncrypter")}static collectRecipients(e){const t=[],n=y(r=>{if(!r)return;const u=Array.isArray(r)?r:[r];for(const o of u){const i=typeof o=="string"?o:o.email;i&&t.push(i)}},"extractEmails");return n(e.to),n(e.cc),n(e.bcc),[...new Set(t)]}static formatAddress(e){return typeof e=="string"?e:e.name?`"${e.name}" <${e.email}>`:e.email}static formatAddresses(e){return(Array.isArray(e)?e:[e]).map(t=>a.formatAddress(t)).join(", ")}options;constructor(e){this.options=e}async encrypt(e){const t=a.collectRecipients(e),n=[];if(typeof this.options.certificates=="string"){const c=await x(this.options.certificates,{encoding:"utf8"}),f=N(c),l=S(f);if(l.offset===-1)throw new Error("Failed to parse certificate: Invalid ASN.1 structure");n.push(new $({schema:l.result}))}else{const c=t.map(async f=>{const l=this.options.certificates[f];if(!l)throw new Error(`No certificate found for recipient: ${f}`);const E=await x(l,{encoding:"utf8"}),v=N(E),p=S(v);if(p.offset===-1)throw new Error(`Failed to parse certificate for ${f}: Invalid ASN.1 structure`);return new $({schema:p.result})});n.push(...await Promise.all(c))}const r=await this.buildMessage(e),u=new TextEncoder().encode(r),o=new V({version:0});o.encryptedContentInfo=new J({contentType:Q});const i=(this.options.algorithm??"aes-256-cbc").toLowerCase();if(i==="3des"||i==="des-ede3-cbc")throw new Error("3DES/DES-EDE3-CBC is deprecated and insecure (Sweet32 vulnerability). Please use AES-256-CBC, AES-192-CBC, or AES-128-CBC instead.");let m,d;switch(i){case"aes128":case"aes-128-cbc":{m="2.16.840.1.101.3.4.1.2",d=16;break}case"aes192":case"aes-192-cbc":{m="2.16.840.1.101.3.4.1.22",d=24;break}default:{m="2.16.840.1.101.3.4.1.42",d=32;break}}const A=B(d),D=w?A:new Uint8Array(A),C=B(16),P=w?C:new Uint8Array(C),I=L(`aes-${d*8}-cbc`,A,C),_=Buffer.from(u),k=[I.update(_),I.final()],b=Buffer.concat(k);o.encryptedContentInfo.encryptedContent=new T({valueHex:b.buffer.slice(b.byteOffset,b.byteOffset+b.byteLength)});const M=await Promise.all(n.map(async c=>{const f=c.toSchema().toBER(!1),l=R(f,"CERTIFICATE"),E=G(l),v=Buffer.from(D),p=z({key:E,padding:1},v);return new W({value:new X({encryptedKey:new T({valueHex:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength)}),keyEncryptionAlgorithm:new j({algorithmId:"1.2.840.113549.1.1.1"}),rid:new Y({issuer:c.issuer,serialNumber:c.serialNumber}),version:0}),variant:0})}));o.recipientInfos.push(...M),o.encryptedContentInfo.contentEncryptionAlgorithm=new j({algorithmId:m,algorithmParams:new T({valueHex:P.buffer})});const O=new Z({content:o.toSchema(),contentType:ee}).toSchema().toBER(!1),F=R(O,"PKCS7");return{...e,headers:{...e.headers,"Content-Disposition":"attachment; filename=smime.p7m","Content-Transfer-Encoding":"base64","Content-Type":"application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m"},html:void 0,text:F}}async buildMessage(e){const t=[`From: ${a.formatAddress(e.from)}`,`To: ${a.formatAddresses(e.to)}`,...e.cc?[`Cc: ${a.formatAddresses(e.cc)}`]:[]];if(e.replyTo&&t.push(`Reply-To: ${a.formatAddress(e.replyTo)}`),t.push(`Subject: ${e.subject}`,"MIME-Version: 1.0"),e.headers)for(const[n,r]of Object.entries(e.headers))t.push(`${n}: ${r}`);return e.html?t.push("Content-Type: text/html; charset=utf-8"):e.text&&t.push("Content-Type: text/plain; charset=utf-8"),t.push(""),e.html?t.push(e.html):e.text&&t.push(e.text),t.join(`\r
6
6
  `)}}const ae=y(s=>new a(s),"createSmimeEncrypter");export{a as SmimeEncrypter,ae as createSmimeEncrypter};
@@ -1,8 +1,8 @@
1
- var L=Object.defineProperty;var g=(n,e)=>L(n,"name",{value:e,configurable:!0});import{createRequire as V}from"node:module";import{B as b}from"./readFile-BAVMZg5e-C4whBIPd.js";import{fromBER as B,ObjectIdentifier as Y,OctetString as E,UTCTime as Z}from"asn1js";import{Certificate as N,SignedData as ee,EncapsulatedContentInfo as te,id_ContentType_Data as D,SignerInfo as re,AlgorithmIdentifier as P,IssuerAndSerialNumber as ne,id_sha256 as se,SignedAndUnsignedAttributes as oe,Attribute as A,ContentInfo as ie,id_ContentType_SignedData as ae}from"pkijs";import{a as ce}from"./generate-boundary-Cx8nXYS0.js";const z=V(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,J=g(n=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,t]=u.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return u.getBuiltinModule(n)}return z(n)},"__cjs_getBuiltinModule"),{createPrivateKey:x,createHash:Q,createSign:W,randomBytes:X}=J("node:crypto");var le=Object.defineProperty,y=g((n,e)=>le(n,"name",{value:e,configurable:!0}),"u");const pe="1.2.840.113549.1.9.3",ue="1.2.840.113549.1.9.4",fe="1.2.840.113549.1.9.5",me="1.2.840.113549.1.1.1",de={v1:1},he={v1:1},f=globalThis.Buffer!==void 0,M=y(n=>{const e=n.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(f)return Buffer.from(e,"base64");const t=atob(e),o=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)o[r]=t.codePointAt(r);return o},"pemToDer"),ge=y((n,e)=>{let t;if(f)t=Buffer.from(n).toString("base64");else{const r=new Uint8Array(n);let s="";const a=8192;for(let i=0;i<r.length;i+=a){const d=r.subarray(i,Math.min(i+a,r.length));s+=String.fromCharCode(...d)}t=btoa(s)}const o=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
1
+ var z=Object.defineProperty;var g=(n,e)=>z(n,"name",{value:e,configurable:!0});import{createRequire as L}from"node:module";import{fromBER as E,ObjectIdentifier as Y,OctetString as B,UTCTime as Z}from"asn1js";import{Certificate as N,SignedData as ee,EncapsulatedContentInfo as te,id_ContentType_Data as D,SignerInfo as re,AlgorithmIdentifier as P,IssuerAndSerialNumber as ne,id_sha256 as se,SignedAndUnsignedAttributes as oe,Attribute as b,ContentInfo as ie,id_ContentType_SignedData as ae}from"pkijs";import{a as ce}from"./generate-boundary-Cx8nXYS0.js";import{z as A}from"./readFile-Iz7kvCCk-CVf9zS6c.js";const V=L(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,J=g(n=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,t]=u.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return u.getBuiltinModule(n)}return V(n)},"__cjs_getBuiltinModule"),{createPrivateKey:x,createHash:Q,createSign:W,randomBytes:X}=J("node:crypto");var le=Object.defineProperty,y=g((n,e)=>le(n,"name",{value:e,configurable:!0}),"u");const pe="1.2.840.113549.1.9.3",ue="1.2.840.113549.1.9.4",fe="1.2.840.113549.1.9.5",me="1.2.840.113549.1.1.1",de={v1:1},he={v1:1},f=globalThis.Buffer!==void 0,M=y(n=>{const e=n.replaceAll(/-----BEGIN[^-]+-----/g,"").replaceAll(/-----END[^-]+-----/g,"").replaceAll(/\s/g,"");if(f)return Buffer.from(e,"base64");const t=atob(e),o=new Uint8Array(t.length);for(let r=0;r<t.length;r+=1)o[r]=t.codePointAt(r);return o},"pemToDer"),ge=y((n,e)=>{let t;if(f)t=Buffer.from(n).toString("base64");else{const r=new Uint8Array(n);let s="";const a=8192;for(let i=0;i<r.length;i+=a){const d=r.subarray(i,Math.min(i+a,r.length));s+=String.fromCharCode(...d)}t=btoa(s)}const o=t.match(/.{1,64}/g)??[];return`-----BEGIN ${e}-----
2
2
  ${o.join(`
3
3
  `)}
4
4
  -----END ${e}-----
5
- `},"derToPem");class m{static{g(this,"SmimeSigner")}static{y(this,"SmimeSigner")}static formatAddress(e){return e.name?`"${e.name.replaceAll("\\","\\\\").replaceAll('"',String.raw`\"`)}" <${e.email}>`:e.email}options;constructor(e){this.options=e}async sign(e){const t=await b(this.options.certificate,{encoding:"utf8"}),o=await b(this.options.privateKey,{encoding:"utf8"}),r=M(t),s=B(r);if(s.offset===-1)throw new Error("Failed to parse certificate: Invalid ASN.1 structure");const a=new N({schema:s.result});let i;try{i=this.options.passphrase?x({key:o,passphrase:this.options.passphrase}):x(o)}catch(c){throw new Error(`Failed to parse private key: ${c.message}`)}const d=[];if(this.options.intermediateCerts){const c=this.options.intermediateCerts.map(async j=>{const q=await b(j,{encoding:"utf8"}),G=M(q),I=B(G);if(I.offset===-1)throw new Error(`Failed to parse intermediate certificate ${j}: Invalid ASN.1 structure`);return new N({schema:I.result})});d.push(...await Promise.all(c))}const v=this.buildMessage(e),$=new TextEncoder().encode(v),h=new ee({version:de.v1});h.encapContentInfo=new te({eContentType:D});const w=new re({digestAlgorithm:new P({algorithmId:se}),sid:new ne({issuer:a.issuer,serialNumber:a.serialNumber}),signatureAlgorithm:new P({algorithmId:me}),version:he.v1}),C=Q("sha256");C.update(f?Buffer.from($):$);const R=C.digest(),U=new Uint8Array(R),T=new oe({attributes:[new A({type:pe,values:[new Y({value:D})]}),new A({type:ue,values:[new E({valueHex:U.buffer.slice(0)})]}),new A({type:fe,values:[new Z({valueDate:new Date})]})]});w.signedAttrs=T;const S=T.toSchema().toBER(!1),k=f?Buffer.from(S):new Uint8Array(S),_=W("RSA-SHA256");_.update(k);const l=_.sign(i),O=f?l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength):l.buffer;w.signature=new E({valueHex:O}),h.signerInfos.push(w),h.certificates=[a,...d];const F=new ie({content:h.toSchema(),contentType:ae}).toSchema().toBER(!1),H=ge(F,"PKCS7"),p=`----_=_NextPart_${Date.now()}_${X(8).toString("hex")}`,K=[`Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="${p}"`,"",`--${p}`,v,`--${p}`,"Content-Type: application/pkcs7-signature; name=smime.p7s","Content-Transfer-Encoding: base64","Content-Disposition: attachment; filename=smime.p7s","",H.split(`
5
+ `},"derToPem");class m{static{g(this,"SmimeSigner")}static{y(this,"SmimeSigner")}static formatAddress(e){return e.name?`"${e.name.replaceAll("\\","\\\\").replaceAll('"',String.raw`\"`)}" <${e.email}>`:e.email}options;constructor(e){this.options=e}async sign(e){const t=await A(this.options.certificate,{encoding:"utf8"}),o=await A(this.options.privateKey,{encoding:"utf8"}),r=M(t),s=E(r);if(s.offset===-1)throw new Error("Failed to parse certificate: Invalid ASN.1 structure");const a=new N({schema:s.result});let i;try{i=this.options.passphrase?x({key:o,passphrase:this.options.passphrase}):x(o)}catch(c){throw new Error(`Failed to parse private key: ${c.message}`)}const d=[];if(this.options.intermediateCerts){const c=this.options.intermediateCerts.map(async j=>{const q=await A(j,{encoding:"utf8"}),G=M(q),I=E(G);if(I.offset===-1)throw new Error(`Failed to parse intermediate certificate ${j}: Invalid ASN.1 structure`);return new N({schema:I.result})});d.push(...await Promise.all(c))}const v=this.buildMessage(e),$=new TextEncoder().encode(v),h=new ee({version:de.v1});h.encapContentInfo=new te({eContentType:D});const w=new re({digestAlgorithm:new P({algorithmId:se}),sid:new ne({issuer:a.issuer,serialNumber:a.serialNumber}),signatureAlgorithm:new P({algorithmId:me}),version:he.v1}),C=Q("sha256");C.update(f?Buffer.from($):$);const R=C.digest(),U=new Uint8Array(R),T=new oe({attributes:[new b({type:pe,values:[new Y({value:D})]}),new b({type:ue,values:[new B({valueHex:U.buffer.slice(0)})]}),new b({type:fe,values:[new Z({valueDate:new Date})]})]});w.signedAttrs=T;const S=T.toSchema().toBER(!1),k=f?Buffer.from(S):new Uint8Array(S),_=W("RSA-SHA256");_.update(k);const l=_.sign(i),O=f?l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength):l.buffer;w.signature=new B({valueHex:O}),h.signerInfos.push(w),h.certificates=[a,...d];const F=new ie({content:h.toSchema(),contentType:ae}).toSchema().toBER(!1),H=ge(F,"PKCS7"),p=`----_=_NextPart_${Date.now()}_${X(8).toString("hex")}`,K=[`Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="${p}"`,"",`--${p}`,v,`--${p}`,"Content-Type: application/pkcs7-signature; name=smime.p7s","Content-Transfer-Encoding: base64","Content-Disposition: attachment; filename=smime.p7s","",H.split(`
6
6
  `).filter(c=>c.trim()&&!c.includes("-----")).join(""),`--${p}--`].join(`\r
7
7
  `);return{...e,headers:{...e.headers,"Content-Type":`multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="${p}"`},html:void 0,text:K}}buildMessage(e){const t=[`From: ${m.formatAddress(e.from)}`,`To: ${this.formatAddresses(e.to)}`];if(e.cc&&t.push(`Cc: ${this.formatAddresses(e.cc)}`),e.replyTo&&t.push(`Reply-To: ${m.formatAddress(e.replyTo)}`),t.push(`Subject: ${e.subject}`,"MIME-Version: 1.0"),e.headers)for(const[a,i]of Object.entries(e.headers))t.push(`${a}: ${i}`);const o=!!e.text,r=!!e.html;let s;return o&&r?(s=ce(),t.push(`Content-Type: multipart/alternative; boundary="${s}"`)):r?t.push("Content-Type: text/html; charset=utf-8"):t.push("Content-Type: text/plain; charset=utf-8"),t.push(""),o&&r&&s?t.push(`--${s}`,"Content-Type: text/plain; charset=utf-8","",e.text,"",`--${s}`,"Content-Type: text/html; charset=utf-8","",e.html,"",`--${s}--`):o?t.push(e.text):r&&t.push(e.html),t.join(`\r
8
8
  `)}formatAddresses(e){return(Array.isArray(e)?e:[e]).map(t=>m.formatAddress(t)).join(", ")}}const Ce=y(n=>new m(n),"createSmimeSigner");export{m as SmimeSigner,Ce as createSmimeSigner};
@@ -1 +1 @@
1
- var P=Object.defineProperty;var y=(i,r)=>P(i,"name",{value:r,configurable:!0});import{createRequire as I}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request--BdZNxIl.js";import{c as z,u as b,h as w,P as k}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{f as p,a as B}from"./address-formatter-Cm_E_ZMa.js";const T=I(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,u]=m.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return m.getBuiltinModule(i)}return T(i)},"__cjs_getBuiltinModule"),{Buffer:j}=$("node:buffer"),s="ahasend",C="https://api.ahasend.com",x=3e4,G=3,Q=K((i={})=>{if(!i.apiKey)throw new S(s,"apiKey");const r={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??C,retries:i.retries??G,timeout:i.timeout??x,...i.logger&&{logger:i.logger}},u=new k,n=z(s,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(s,"Email ID is required to retrieve email details"),success:!1};await this.initialize();const o={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>f(`${r.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:r.timeout}),r.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(s,"retrieve email",o,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(s,"AhaSend API not available or invalid API key");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{return n.debug("Checking AhaSend API availability"),!!(await f(`${r.endpoint}/v2/ping`,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"GET",timeout:r.timeout})).success}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=q(e);if(o.length>0)return{error:new c(s,`Invalid email options: ${o.join(", ")}`),success:!1};await this.initialize();const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=B(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const a=E(e.headers);t.headers=a}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async a=>{let d;if(a.content)if(typeof a.content=="string")d=a.content;else if(a.content instanceof Promise){const A=await a.content;d=j.from(A).toString("base64")}else d=a.content.toString("base64");else if(a.raw)d=typeof a.raw=="string"?a.raw:a.raw.toString("base64");else throw new c(s,`Attachment ${a.filename} has no content`);return{content:d,contentType:a.contentType??"application/octet-stream",filename:a.filename,...a.cid&&{cid:a.cid}}}))),n.debug("Sending email via AhaSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},l=await b(async()=>f(`${r.endpoint}/send`,{headers:v,method:"POST",timeout:r.timeout},JSON.stringify(t)),r.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error??new c(s,"Failed to send email"),success:!1};const g=l.data?.body,h=g?.messageId??g?.id??_();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(s,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
1
+ var P=Object.defineProperty;var y=(i,r)=>P(i,"name",{value:r,configurable:!0});import{createRequire as I}from"node:module";import c from"./EmailError-C4nx6TgJ.js";import S from"./RequiredOptionError-BeTzeno6.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-C7fcsalD.js";import{c as z,u as b,h as w,P as k}from"./provider-base-8LBAorjm.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{f as p,a as B}from"./address-formatter-Cm_E_ZMa.js";const T=I(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,u]=m.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return m.getBuiltinModule(i)}return T(i)},"__cjs_getBuiltinModule"),{Buffer:j}=$("node:buffer"),s="ahasend",C="https://api.ahasend.com",x=3e4,G=3,Q=K((i={})=>{if(!i.apiKey)throw new S(s,"apiKey");const r={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??C,retries:i.retries??G,timeout:i.timeout??x,...i.logger&&{logger:i.logger}},u=new k,n=z(s,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(s,"Email ID is required to retrieve email details"),success:!1};await this.initialize();const o={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>f(`${r.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:r.timeout}),r.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(s,"retrieve email",o,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(s,"AhaSend API not available or invalid API key");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{return n.debug("Checking AhaSend API availability"),!!(await f(`${r.endpoint}/v2/ping`,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"GET",timeout:r.timeout})).success}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=q(e);if(o.length>0)return{error:new c(s,`Invalid email options: ${o.join(", ")}`),success:!1};await this.initialize();const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=B(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const a=E(e.headers);t.headers=a}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async a=>{let d;if(a.content)if(typeof a.content=="string")d=a.content;else if(a.content instanceof Promise){const A=await a.content;d=j.from(A).toString("base64")}else d=a.content.toString("base64");else if(a.raw)d=typeof a.raw=="string"?a.raw:a.raw.toString("base64");else throw new c(s,`Attachment ${a.filename} has no content`);return{content:d,contentType:a.contentType??"application/octet-stream",filename:a.filename,...a.cid&&{cid:a.cid}}}))),n.debug("Sending email via AhaSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},l=await b(async()=>f(`${r.endpoint}/send`,{headers:v,method:"POST",timeout:r.timeout},JSON.stringify(t)),r.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error??new c(s,"Failed to send email"),success:!1};const g=l.data?.body,h=g?.messageId??g?.id??_();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(s,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
@@ -1 +1 @@
1
- var r=Object.defineProperty;var i=(e,t)=>r(e,"name",{value:t,configurable:!0});import{createRequire as m}from"node:module";import d from"./EmailError-zm2ffVav.js";const p=m(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=i(e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[t,n]=a.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return a.getBuiltinModule(e)}return p(e)},"__cjs_getBuiltinModule"),{Buffer:l}=f("node:buffer");var u=Object.defineProperty,o=i((e,t)=>u(e,"name",{value:t,configurable:!0}),"o");const c=o(async(e,t)=>{let n;if(e.content)if(typeof e.content=="string")n=e.content;else if(e.content instanceof Promise){const s=await e.content;n=l.from(s).toString("base64")}else n=e.content.toString("base64");else if(e.raw)n=typeof e.raw=="string"?e.raw:e.raw.toString("base64");else throw new d(t,`Attachment ${e.filename} has no content`);return n},"processAttachmentContent");o(async(e,t)=>({content:await c(e,t),contentType:e.contentType??"application/octet-stream",disposition:e.contentDisposition??"attachment",filename:e.filename,...e.cid&&{contentId:e.cid}}),"createStandardAttachment");const _=o(async(e,t)=>({content:await c(e,t),disposition:e.contentDisposition??"attachment",filename:e.filename,type:e.contentType??"application/octet-stream",...e.cid&&{content_id:e.cid}}),"createSendGridAttachment"),b=o(async(e,t)=>({Content:await c(e,t),ContentType:e.contentType??"application/octet-stream",Name:e.filename,...e.cid&&{ContentID:e.cid}}),"createPostmarkAttachment"),w=o(async(e,t,n)=>({content:await c(e,t),key:`attachment[${n}]`}),"createMailgunAttachment");export{w as a,b,_ as c};
1
+ var r=Object.defineProperty;var i=(e,t)=>r(e,"name",{value:t,configurable:!0});import{createRequire as m}from"node:module";import d from"./EmailError-C4nx6TgJ.js";const p=m(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=i(e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[t,n]=a.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return a.getBuiltinModule(e)}return p(e)},"__cjs_getBuiltinModule"),{Buffer:l}=f("node:buffer");var u=Object.defineProperty,o=i((e,t)=>u(e,"name",{value:t,configurable:!0}),"o");const c=o(async(e,t)=>{let n;if(e.content)if(typeof e.content=="string")n=e.content;else if(e.content instanceof Promise){const s=await e.content;n=l.from(s).toString("base64")}else n=e.content.toString("base64");else if(e.raw)n=typeof e.raw=="string"?e.raw:e.raw.toString("base64");else throw new d(t,`Attachment ${e.filename} has no content`);return n},"processAttachmentContent");o(async(e,t)=>({content:await c(e,t),contentType:e.contentType??"application/octet-stream",disposition:e.contentDisposition??"attachment",filename:e.filename,...e.cid&&{contentId:e.cid}}),"createStandardAttachment");const _=o(async(e,t)=>({content:await c(e,t),disposition:e.contentDisposition??"attachment",filename:e.filename,type:e.contentType??"application/octet-stream",...e.cid&&{content_id:e.cid}}),"createSendGridAttachment"),b=o(async(e,t)=>({Content:await c(e,t),ContentType:e.contentType??"application/octet-stream",Name:e.filename,...e.cid&&{ContentID:e.cid}}),"createPostmarkAttachment"),w=o(async(e,t,n)=>({content:await c(e,t),key:`attachment[${n}]`}),"createMailgunAttachment");export{w as a,b,_ as c};
@@ -1,4 +1,4 @@
1
- var L=Object.defineProperty;var j=(m,a)=>L(m,"name",{value:a,configurable:!0});import{createRequire as V}from"node:module";import T from"./EmailError-zm2ffVav.js";import Q from"./RequiredOptionError-CevW3u2K.js";import{c as X}from"./create-logger-BiWdqFNg.js";import S from"../utils/format-email-address.js";import{i as J}from"./headers-to-record-Qo124ImV.js";import{m as Y}from"./make-request--BdZNxIl.js";import{s as k,a as Z}from"./sanitize-header-wWav-Scu.js";import{d as ee}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as te}from"./defineProvider-CtLH0VBE.js";const F=V(import.meta.url),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=j(m=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[a,d]=$.versions.node.split(".").map(Number);if(a>22||a===22&&d>=3||a===20&&d>=16)return $.getBuiltinModule(m)}return F(m)},"__cjs_getBuiltinModule"),{randomUUID:q,createHash:P,createHmac:w}=G("node:crypto");var re=Object.defineProperty,p=j((m,a)=>re(m,"name",{value:a,configurable:!0}),"S");const se=globalThis.Buffer!==void 0,M=p(()=>{if(!se)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},"getBuffer"),y="aws-ses",C={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},fe=te((m={})=>{const a={...C,...m},d=X("AWS-SES",m.logger),W=p((e,i,t,s,n)=>{const u=Object.keys(t).toSorted().map(c=>{const l=t[c];return l===void 0?"":`${encodeURIComponent(c)}=${encodeURIComponent(l)}`}).filter(Boolean).join("&"),r=`${Object.keys(s).toSorted().map(c=>`${c.toLowerCase()}:${s[c]}`).join(`
1
+ var L=Object.defineProperty;var j=(m,a)=>L(m,"name",{value:a,configurable:!0});import{createRequire as V}from"node:module";import T from"./EmailError-C4nx6TgJ.js";import Q from"./RequiredOptionError-BeTzeno6.js";import{c as X}from"./create-logger-BiWdqFNg.js";import S from"../utils/format-email-address.js";import{i as J}from"./headers-to-record-Qo124ImV.js";import{m as Y}from"./make-request-C7fcsalD.js";import{s as k,a as Z}from"./sanitize-header-wWav-Scu.js";import{d as ee}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as te}from"./defineProvider-CtLH0VBE.js";const F=V(import.meta.url),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=j(m=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[a,d]=$.versions.node.split(".").map(Number);if(a>22||a===22&&d>=3||a===20&&d>=16)return $.getBuiltinModule(m)}return F(m)},"__cjs_getBuiltinModule"),{randomUUID:q,createHash:P,createHmac:w}=G("node:crypto");var re=Object.defineProperty,p=j((m,a)=>re(m,"name",{value:a,configurable:!0}),"S");const se=globalThis.Buffer!==void 0,M=p(()=>{if(!se)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},"getBuffer"),y="aws-ses",C={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},fe=te((m={})=>{const a={...C,...m},d=X("AWS-SES",m.logger),W=p((e,i,t,s,n)=>{const u=Object.keys(t).toSorted().map(c=>{const l=t[c];return l===void 0?"":`${encodeURIComponent(c)}=${encodeURIComponent(l)}`}).filter(Boolean).join("&"),r=`${Object.keys(s).toSorted().map(c=>`${c.toLowerCase()}:${s[c]}`).join(`
2
2
  `)}
3
3
  `,o=Object.keys(s).toSorted().map(c=>c.toLowerCase()).join(";"),g=P("sha256").update(n).digest("hex");return[e,i,u,r,o,g].join(`
4
4
  `)},"createCanonicalRequest"),_=p((e,i,t)=>{const s=e.slice(0,8),n=P("sha256").update(t).digest("hex");return["AWS4-HMAC-SHA256",e,`${s}/${i}/ses/aws4_request`,n].join(`
@@ -1 +1 @@
1
- var k=Object.defineProperty;var w=(n,l)=>k(n,"name",{value:l,configurable:!0});import{createRequire as z}from"node:module";import u from"./EmailError-zm2ffVav.js";import v from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request--BdZNxIl.js";import{c as B,P as C,u as T,h as S}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{j as y,k as x}from"./address-formatter-Cm_E_ZMa.js";const I=z(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=w(n=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[l,t]=f.versions.node.split(".").map(Number);if(l>22||l===22&&t>=3||l===20&&t>=16)return f.getBuiltinModule(n)}return I(n)},"__cjs_getBuiltinModule"),{Buffer:p}=P("node:buffer"),i="azure",O=3e4,R=3,Q=q((n={})=>{if(!n.region)throw new v(i,"region");if(!n.connectionString&&!n.accessToken)throw new v(i,"connectionString or accessToken");const l=n.endpoint??`https://${n.region}.communication.azure.com`,t={debug:n.debug??!1,endpoint:l,region:n.region,retries:n.retries??R,timeout:n.timeout??O,...n.connectionString&&{connectionString:n.connectionString},...n.accessToken&&{accessToken:n.accessToken},...n.logger&&{logger:n.logger}},g=new C,a=B(i,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new u(i,"Email ID is required to retrieve email details"),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const o={"Content-Type":"application/json"};if(t.accessToken)o.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);c&&(o.Authorization=`Bearer ${c[2]}`)}a.debug("Retrieving email details",{id:e});const r=await T(async()=>h(`${t.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:t.timeout}),t.retries);return r.success?(a.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(a.debug("API request failed when retrieving email",r.error),{error:new u(i,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:S(i,"retrieve email",o,a),success:!1}}},async initialize(){await g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(i,"Azure Communication Services API not available or invalid credentials");a.debug("Provider initialized successfully")},i)},async isAvailable(){try{const e={"Content-Type":"application/json"};if(t.accessToken)e.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(c)e.Authorization=`Bearer ${c[2]}`;else return!1}else return!1;a.debug("Checking Azure Communication Services API availability");const o=await h(`${t.endpoint}/emails:send`,{headers:e,method:"POST",timeout:t.timeout},JSON.stringify({}));if(o.success)return!0;const r=o.data?.statusCode;return r===401||r===403?!1:r===400}catch(e){if(a.debug("Error checking availability:",e),e instanceof Error){const o=e.message;if(o.includes("401")||o.includes("403"))return!1}return!1}},name:i,options:t,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new u(i,`Invalid email options: ${o.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const r={content:{subject:e.subject},recipients:{to:y(e.to)},senderAddress:e.from.email};if(e.html&&(r.content.html=e.html),e.text&&(r.content.plainText=e.text),e.cc&&(r.recipients.cc=y(e.cc)),e.bcc&&(r.recipients.bcc=y(e.bcc)),e.replyTo&&(r.replyTo=x(e.replyTo).email),e.importance&&(r.importance=e.importance),e.headers){const s=_(e.headers);r.headers=s}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async s=>{let d;if(s.content)if(typeof s.content=="string")d=p.from(s.content,"utf8").toString("base64");else if(s.content&&typeof s.content.then=="function"){const A=await s.content;d=p.from(A).toString("base64")}else d=s.content.toString("base64");else if(s.raw)d=typeof s.raw=="string"?p.from(s.raw,"utf8").toString("base64"):s.raw.toString("base64");else throw new u(i,`Attachment ${s.filename} has no content`);return{contentInBase64:d,contentType:s.contentType??"application/octet-stream",name:s.filename}}))),a.debug("Sending email via Azure Communication Services API",{subject:r.content.subject,to:r.recipients.to});const c={"Content-Type":"application/json"};if(t.accessToken)c.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const s=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(s)c.Authorization=`Bearer ${s[2]}`;else return{error:new u(i,"Invalid connection string format"),success:!1}}const m=await T(async()=>h(`${t.endpoint}/emails:send`,{headers:c,method:"POST",timeout:t.timeout},JSON.stringify(r)),t.retries);if(!m.success)return a.debug("API request failed when sending email",m.error),{error:m.error??new u(i,"Failed to send email"),success:!1};const b=m.data?.body?.messageId??j();return a.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:i,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:S(i,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
1
+ var k=Object.defineProperty;var w=(n,l)=>k(n,"name",{value:l,configurable:!0});import{createRequire as z}from"node:module";import u from"./EmailError-C4nx6TgJ.js";import v from"./RequiredOptionError-BeTzeno6.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request-C7fcsalD.js";import{c as B,P as C,u as T,h as S}from"./provider-base-8LBAorjm.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{j as y,k as x}from"./address-formatter-Cm_E_ZMa.js";const I=z(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=w(n=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[l,t]=f.versions.node.split(".").map(Number);if(l>22||l===22&&t>=3||l===20&&t>=16)return f.getBuiltinModule(n)}return I(n)},"__cjs_getBuiltinModule"),{Buffer:p}=P("node:buffer"),i="azure",O=3e4,R=3,Q=q((n={})=>{if(!n.region)throw new v(i,"region");if(!n.connectionString&&!n.accessToken)throw new v(i,"connectionString or accessToken");const l=n.endpoint??`https://${n.region}.communication.azure.com`,t={debug:n.debug??!1,endpoint:l,region:n.region,retries:n.retries??R,timeout:n.timeout??O,...n.connectionString&&{connectionString:n.connectionString},...n.accessToken&&{accessToken:n.accessToken},...n.logger&&{logger:n.logger}},g=new C,a=B(i,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new u(i,"Email ID is required to retrieve email details"),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const o={"Content-Type":"application/json"};if(t.accessToken)o.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);c&&(o.Authorization=`Bearer ${c[2]}`)}a.debug("Retrieving email details",{id:e});const r=await T(async()=>h(`${t.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:t.timeout}),t.retries);return r.success?(a.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(a.debug("API request failed when retrieving email",r.error),{error:new u(i,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:S(i,"retrieve email",o,a),success:!1}}},async initialize(){await g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(i,"Azure Communication Services API not available or invalid credentials");a.debug("Provider initialized successfully")},i)},async isAvailable(){try{const e={"Content-Type":"application/json"};if(t.accessToken)e.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(c)e.Authorization=`Bearer ${c[2]}`;else return!1}else return!1;a.debug("Checking Azure Communication Services API availability");const o=await h(`${t.endpoint}/emails:send`,{headers:e,method:"POST",timeout:t.timeout},JSON.stringify({}));if(o.success)return!0;const r=o.data?.statusCode;return r===401||r===403?!1:r===400}catch(e){if(a.debug("Error checking availability:",e),e instanceof Error){const o=e.message;if(o.includes("401")||o.includes("403"))return!1}return!1}},name:i,options:t,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new u(i,`Invalid email options: ${o.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const r={content:{subject:e.subject},recipients:{to:y(e.to)},senderAddress:e.from.email};if(e.html&&(r.content.html=e.html),e.text&&(r.content.plainText=e.text),e.cc&&(r.recipients.cc=y(e.cc)),e.bcc&&(r.recipients.bcc=y(e.bcc)),e.replyTo&&(r.replyTo=x(e.replyTo).email),e.importance&&(r.importance=e.importance),e.headers){const s=_(e.headers);r.headers=s}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async s=>{let d;if(s.content)if(typeof s.content=="string")d=p.from(s.content,"utf8").toString("base64");else if(s.content&&typeof s.content.then=="function"){const A=await s.content;d=p.from(A).toString("base64")}else d=s.content.toString("base64");else if(s.raw)d=typeof s.raw=="string"?p.from(s.raw,"utf8").toString("base64"):s.raw.toString("base64");else throw new u(i,`Attachment ${s.filename} has no content`);return{contentInBase64:d,contentType:s.contentType??"application/octet-stream",name:s.filename}}))),a.debug("Sending email via Azure Communication Services API",{subject:r.content.subject,to:r.recipients.to});const c={"Content-Type":"application/json"};if(t.accessToken)c.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const s=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(s)c.Authorization=`Bearer ${s[2]}`;else return{error:new u(i,"Invalid connection string format"),success:!1}}const m=await T(async()=>h(`${t.endpoint}/emails:send`,{headers:c,method:"POST",timeout:t.timeout},JSON.stringify(r)),t.retries);if(!m.success)return a.debug("API request failed when sending email",m.error),{error:m.error??new u(i,"Failed to send email"),success:!1};const b=m.data?.body?.messageId??j();return a.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:i,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:S(i,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
@@ -1 +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--BdZNxIl.js";import{c as B,P as K,u as T,h as A}from"./provider-base-Cmzx6BTO.js";import{d as x}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as D}from"./defineProvider-CtLH0VBE.js";import{f as g,a as h}from"./address-formatter-Cm_E_ZMa.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,X=D((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 K,n=B(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=x(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{X as default};
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-C4nx6TgJ.js";import k from"./RequiredOptionError-BeTzeno6.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-C7fcsalD.js";import{c as B,P as K,u as T,h as A}from"./provider-base-8LBAorjm.js";import{d as x}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as D}from"./defineProvider-CtLH0VBE.js";import{f as g,a as h}from"./address-formatter-Cm_E_ZMa.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,X=D((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 K,n=B(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=x(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{X as default};
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty;var u=(e,o)=>v(e,"name",{value:o,configurable:!0});import C from"./EmailError-zm2ffVav.js";import m from"../utils/format-email-address.js";import{a as w}from"./generate-boundary-Cx8nXYS0.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{s as h,a as b}from"./sanitize-header-wWav-Scu.js";var x=Object.defineProperty,E=u((e,o)=>x(e,"name",{value:o,configurable:!0}),"m");const l=E(e=>Array.isArray(e)?e.map(o=>m(o)).join(", "):m(e),"formatEmailAddresses");var B=Object.defineProperty,M=u((e,o)=>B(e,"name",{value:o,configurable:!0}),"g$1");const d=globalThis.Buffer!==void 0,g=M(e=>{if(typeof e=="string"){if(d)return Buffer.from(e,"utf8").toString("base64");const t=new TextEncoder().encode(e);let r="";const s=8192;for(let a=0;a<t.length;a+=s){const f=t.subarray(a,Math.min(a+s,t.length));r+=String.fromCharCode(...f)}return btoa(r)}if(d&&e instanceof Buffer)return e.toString("base64");const o=e instanceof Uint8Array?e:new Uint8Array(e);if(d)return Buffer.from(o).toString("base64");let n="";const c=8192;for(let t=0;t<o.length;t+=c){const r=o.subarray(t,Math.min(t+c,o.length));n+=String.fromCharCode(...r)}return btoa(n)},"toBase64");var S=Object.defineProperty,A=u((e,o)=>S(e,"name",{value:o,configurable:!0}),"h");const O=globalThis.Buffer!==void 0,H=A(async e=>{const o=w(),n=[`From: ${m(e.from)}`,`To: ${l(e.to)}`];if(e.cc&&n.push(`Cc: ${l(e.cc)}`),e.bcc&&n.push(`Bcc: ${l(e.bcc)}`),e.replyTo&&n.push(`Reply-To: ${m(e.replyTo)}`),n.push(`Subject: ${h(e.subject)}`,"MIME-Version: 1.0"),e.headers){const c=j(e.headers);Object.entries(c).forEach(([t,r])=>{const s=b(t),a=h(r);n.push(`${s}: ${a}`)})}if(n.push(`Content-Type: multipart/mixed; boundary="${o}"`,""),e.text&&n.push(`--${o}`,"Content-Type: text/plain; charset=UTF-8","Content-Transfer-Encoding: 7bit","",e.text,""),e.html&&n.push(`--${o}`,"Content-Type: text/html; charset=UTF-8","Content-Transfer-Encoding: 7bit","",e.html,""),e.attachments&&e.attachments.length>0){const c=await Promise.all(e.attachments.map(async t=>{let r;if(t.raw!==void 0)r=t.raw;else{if(t.content===void 0)throw new C("attachment",`Attachment '${t.filename}' must have content, raw, or be resolved from path/href before building MIME message`);r=t.content instanceof Promise?await t.content:t.content}return{...t,resolvedContent:r}}));for(const t of c){n.push(`--${o}`);const r=t.contentType??"application/octet-stream",s=h(t.filename);n.push(`Content-Type: ${r}; name="${s}"`);const a=t.contentDisposition??"attachment";n.push(`Content-Disposition: ${a}; filename="${s}"`),t.cid&&n.push(`Content-ID: <${t.cid}>`),t.headers&&Object.entries(t.headers).forEach(([p,$])=>{const y=b(p),T=h($);n.push(`${y}: ${T}`)});const f=t.encoding??"base64";n.push(`Content-Transfer-Encoding: ${f}`,"");const i=t.resolvedContent;if(f==="base64")n.push(g(i));else if(f==="7bit"||f==="8bit")if(typeof i=="string")n.push(i);else if(O&&i instanceof Buffer)n.push(i.toString("utf8"));else{const p=new TextDecoder;n.push(p.decode(i))}else n.push(g(i));n.push("")}}return n.push(`--${o}--`),n.join(`\r
1
+ var v=Object.defineProperty;var u=(e,o)=>v(e,"name",{value:o,configurable:!0});import C from"./EmailError-C4nx6TgJ.js";import m from"../utils/format-email-address.js";import{a as w}from"./generate-boundary-Cx8nXYS0.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{s as h,a as b}from"./sanitize-header-wWav-Scu.js";var x=Object.defineProperty,E=u((e,o)=>x(e,"name",{value:o,configurable:!0}),"m");const l=E(e=>Array.isArray(e)?e.map(o=>m(o)).join(", "):m(e),"formatEmailAddresses");var B=Object.defineProperty,M=u((e,o)=>B(e,"name",{value:o,configurable:!0}),"g$1");const d=globalThis.Buffer!==void 0,g=M(e=>{if(typeof e=="string"){if(d)return Buffer.from(e,"utf8").toString("base64");const t=new TextEncoder().encode(e);let r="";const s=8192;for(let a=0;a<t.length;a+=s){const f=t.subarray(a,Math.min(a+s,t.length));r+=String.fromCharCode(...f)}return btoa(r)}if(d&&e instanceof Buffer)return e.toString("base64");const o=e instanceof Uint8Array?e:new Uint8Array(e);if(d)return Buffer.from(o).toString("base64");let n="";const c=8192;for(let t=0;t<o.length;t+=c){const r=o.subarray(t,Math.min(t+c,o.length));n+=String.fromCharCode(...r)}return btoa(n)},"toBase64");var S=Object.defineProperty,A=u((e,o)=>S(e,"name",{value:o,configurable:!0}),"h");const O=globalThis.Buffer!==void 0,H=A(async e=>{const o=w(),n=[`From: ${m(e.from)}`,`To: ${l(e.to)}`];if(e.cc&&n.push(`Cc: ${l(e.cc)}`),e.bcc&&n.push(`Bcc: ${l(e.bcc)}`),e.replyTo&&n.push(`Reply-To: ${m(e.replyTo)}`),n.push(`Subject: ${h(e.subject)}`,"MIME-Version: 1.0"),e.headers){const c=j(e.headers);Object.entries(c).forEach(([t,r])=>{const s=b(t),a=h(r);n.push(`${s}: ${a}`)})}if(n.push(`Content-Type: multipart/mixed; boundary="${o}"`,""),e.text&&n.push(`--${o}`,"Content-Type: text/plain; charset=UTF-8","Content-Transfer-Encoding: 7bit","",e.text,""),e.html&&n.push(`--${o}`,"Content-Type: text/html; charset=UTF-8","Content-Transfer-Encoding: 7bit","",e.html,""),e.attachments&&e.attachments.length>0){const c=await Promise.all(e.attachments.map(async t=>{let r;if(t.raw!==void 0)r=t.raw;else{if(t.content===void 0)throw new C("attachment",`Attachment '${t.filename}' must have content, raw, or be resolved from path/href before building MIME message`);r=t.content instanceof Promise?await t.content:t.content}return{...t,resolvedContent:r}}));for(const t of c){n.push(`--${o}`);const r=t.contentType??"application/octet-stream",s=h(t.filename);n.push(`Content-Type: ${r}; name="${s}"`);const a=t.contentDisposition??"attachment";n.push(`Content-Disposition: ${a}; filename="${s}"`),t.cid&&n.push(`Content-ID: <${t.cid}>`),t.headers&&Object.entries(t.headers).forEach(([p,$])=>{const y=b(p),T=h($);n.push(`${y}: ${T}`)});const f=t.encoding??"base64";n.push(`Content-Transfer-Encoding: ${f}`,"");const i=t.resolvedContent;if(f==="base64")n.push(g(i));else if(f==="7bit"||f==="8bit")if(typeof i=="string")n.push(i);else if(O&&i instanceof Buffer)n.push(i.toString("utf8"));else{const p=new TextDecoder;n.push(p.decode(i))}else n.push(g(i));n.push("")}}return n.push(`--${o}--`),n.join(`\r
2
2
  `)},"buildMimeMessage");export{H as z};
@@ -0,0 +1 @@
1
+ var l=Object.defineProperty;var a=(e,r)=>l(e,"name",{value:r,configurable:!0});import n from"mime";import{z as i}from"./readFile-Iz7kvCCk-CVf9zS6c.js";var c=Object.defineProperty,t=a((e,r)=>c(e,"name",{value:r,configurable:!0}),"e");const d=t(e=>n.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=>i(e,{buffer:!0}),"readFileAsBuffer");export{d as detectMimeType,g as generateContentId,s as readFileAsBuffer};
@@ -1 +1 @@
1
- var w=Object.defineProperty;var b=(e,l)=>w(e,"name",{value:l,configurable:!0});import u from"./EmailError-zm2ffVav.js";import $ from"./RequiredOptionError-CevW3u2K.js";import{c as E}from"./create-logger-BiWdqFNg.js";import{s as A}from"./generate-message-id-D4uA8gkj.js";import{defineProvider as z}from"./defineProvider-CtLH0VBE.js";var P=Object.defineProperty,p=b((e,l)=>P(e,"name",{value:l,configurable:!0}),"v");const F=p(e=>typeof e=="function","isProviderFactory"),k=p(e=>e!==null&&typeof e=="object"&&"sendEmail"in e&&"initialize"in e&&"isAvailable"in e,"isProvider"),o="failover",C=z((e={})=>{if(!e.mailers||e.mailers.length===0)throw new $(o,"mailers");const l={debug:e.debug??!1,mailers:e.mailers,retryAfter:e.retryAfter??60};let h=!1;const t=[],n=E(o,e.logger);let g;const m=p(async()=>g||(g=(async()=>{t.length=0;for(const a of l.mailers)try{let r;if(F(a))r=a({});else if(k(a))r=a;else{n.debug(`Skipping invalid mailer: ${a}`);continue}try{await r.initialize(),t.push(r),n.debug(`Initialized provider: ${r.name??"unknown"}`)}catch(c){n.debug(`Failed to initialize provider ${r.name??"unknown"}:`,c)}}catch(r){n.debug("Error processing mailer:",r)}if(t.length===0)throw new u(o,"No providers could be initialized")})(),g),"initializeProviders");return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!h)try{await m(),h=!0,n.debug(`Failover provider initialized with ${t.length} provider(s)`)}catch(a){throw new u(o,`Failed to initialize: ${a.message}`,{cause:a})}},async isAvailable(){try{t.length===0&&await m();for(const a of t)try{if(await a.isAvailable())return!0}catch{}return!1}catch{return!1}},name:o,options:l,async sendEmail(a){try{if(t.length===0&&await m(),t.length===0)return{error:new u(o,"No providers available"),success:!1};const r=[];let c;for(let s=0;s<t.length;s+=1){const f=t[s];if(!f)continue;const d=f.name??`provider-${s+1}`;n.debug(`Attempting to send email via ${d} (${s+1}/${t.length})`);try{if(!await f.isAvailable()){n.debug(`Provider ${d} is not available, skipping`),r.push(new u(o,`Provider ${d} is not available`));continue}const i=await f.sendEmail(a);if(i.success&&i.data)return n.debug(`Email sent successfully via ${d}`),{data:{...i.data,messageId:i.data.messageId||A(),provider:`${o}(${d})`},success:!0};if(i.error){c=i.error,r.push(i.error);const v=i.error instanceof Error?i.error.message:String(i.error);n.debug(`Failed to send via ${d}:`,v)}}catch(i){c=i instanceof Error?i:new Error(String(i)),r.push(c);const v=c instanceof Error?c.message:String(c);n.debug(`Exception sending via ${d}:`,v)}s<t.length-1&&l.retryAfter>0&&(n.debug(`Waiting ${l.retryAfter}ms before trying next provider`),await new Promise(i=>{setTimeout(()=>{i()},l.retryAfter)}))}const y=r.map(s=>s instanceof Error?s.message:String(s)).join("; ");return{error:new u(o,`All providers failed. Errors: ${y}`,{cause:c}),success:!1}}catch(r){return{error:new u(o,`Failed to send email: ${r.message}`,{cause:r}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{C as default};
1
+ var w=Object.defineProperty;var b=(e,l)=>w(e,"name",{value:l,configurable:!0});import u from"./EmailError-C4nx6TgJ.js";import $ from"./RequiredOptionError-BeTzeno6.js";import{c as E}from"./create-logger-BiWdqFNg.js";import{s as A}from"./generate-message-id-D4uA8gkj.js";import{defineProvider as z}from"./defineProvider-CtLH0VBE.js";var P=Object.defineProperty,p=b((e,l)=>P(e,"name",{value:l,configurable:!0}),"v");const F=p(e=>typeof e=="function","isProviderFactory"),k=p(e=>e!==null&&typeof e=="object"&&"sendEmail"in e&&"initialize"in e&&"isAvailable"in e,"isProvider"),o="failover",C=z((e={})=>{if(!e.mailers||e.mailers.length===0)throw new $(o,"mailers");const l={debug:e.debug??!1,mailers:e.mailers,retryAfter:e.retryAfter??60};let h=!1;const t=[],n=E(o,e.logger);let g;const m=p(async()=>g||(g=(async()=>{t.length=0;for(const a of l.mailers)try{let r;if(F(a))r=a({});else if(k(a))r=a;else{n.debug(`Skipping invalid mailer: ${a}`);continue}try{await r.initialize(),t.push(r),n.debug(`Initialized provider: ${r.name??"unknown"}`)}catch(c){n.debug(`Failed to initialize provider ${r.name??"unknown"}:`,c)}}catch(r){n.debug("Error processing mailer:",r)}if(t.length===0)throw new u(o,"No providers could be initialized")})(),g),"initializeProviders");return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!h)try{await m(),h=!0,n.debug(`Failover provider initialized with ${t.length} provider(s)`)}catch(a){throw new u(o,`Failed to initialize: ${a.message}`,{cause:a})}},async isAvailable(){try{t.length===0&&await m();for(const a of t)try{if(await a.isAvailable())return!0}catch{}return!1}catch{return!1}},name:o,options:l,async sendEmail(a){try{if(t.length===0&&await m(),t.length===0)return{error:new u(o,"No providers available"),success:!1};const r=[];let c;for(let s=0;s<t.length;s+=1){const f=t[s];if(!f)continue;const d=f.name??`provider-${s+1}`;n.debug(`Attempting to send email via ${d} (${s+1}/${t.length})`);try{if(!await f.isAvailable()){n.debug(`Provider ${d} is not available, skipping`),r.push(new u(o,`Provider ${d} is not available`));continue}const i=await f.sendEmail(a);if(i.success&&i.data)return n.debug(`Email sent successfully via ${d}`),{data:{...i.data,messageId:i.data.messageId||A(),provider:`${o}(${d})`},success:!0};if(i.error){c=i.error,r.push(i.error);const v=i.error instanceof Error?i.error.message:String(i.error);n.debug(`Failed to send via ${d}:`,v)}}catch(i){c=i instanceof Error?i:new Error(String(i)),r.push(c);const v=c instanceof Error?c.message:String(c);n.debug(`Exception sending via ${d}:`,v)}s<t.length-1&&l.retryAfter>0&&(n.debug(`Waiting ${l.retryAfter}ms before trying next provider`),await new Promise(i=>{setTimeout(()=>{i()},l.retryAfter)}))}const y=r.map(s=>s instanceof Error?s.message:String(s)).join("; ");return{error:new u(o,`All providers failed. Errors: ${y}`,{cause:c}),success:!1}}catch(r){return{error:new u(o,`Failed to send email: ${r.message}`,{cause:r}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{C as default};
@@ -1 +1 @@
1
- var v=Object.defineProperty;var p=(r,a)=>v(r,"name",{value:a,configurable:!0});import c from"./EmailError-zm2ffVav.js";import A from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{m as u}from"./make-request--BdZNxIl.js";import{d as O}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as P}from"./defineProvider-CtLH0VBE.js";var C=Object.defineProperty,h=p((r,a)=>C(r,"name",{value:a,configurable:!0}),"f");const n="http",I="POST",f=3e4,z=P((r={})=>{if(!r.endpoint)throw new A(n,"endpoint");const a={apiKey:r.apiKey??"",endpoint:r.endpoint,headers:r.headers??{},method:r.method??I},d=h(()=>{const e={"Content-Type":"application/json",...a.headers};return a.apiKey&&(e.Authorization=`Bearer ${a.apiKey}`),e},"getStandardHeaders"),y=h(e=>{const t={from:e.from.email,from_name:e.from.name,html:e.html,subject:e.subject,text:e.text,to:Array.isArray(e.to)?e.to.map(s=>s.email):e.to.email};return e.cc&&(t.cc=Array.isArray(e.cc)?e.cc.map(s=>s.email):e.cc.email),e.bcc&&(t.bcc=Array.isArray(e.bcc)?e.bcc.map(s=>s.email):e.bcc.email),e.customParams&&Object.assign(t,e.customParams),t},"formatRequest");let m=!1;return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!m){if(!await this.isAvailable())throw new c(n,"API endpoint not available");m=!0}},async isAvailable(){try{return!!(await u(a.endpoint,{headers:d(),method:"OPTIONS",timeout:f})).success}catch(e){if(e instanceof Error){const t=e.message;if(t.includes("401")||t.includes("403"))return!1}return!1}},name:n,options:a,async sendEmail(e){try{const t=O(e);if(t.length>0)return{error:new c(n,`Invalid email options: ${t.join(", ")}`),success:!1};m||await this.initialize();const s=d();e.headers&&Object.assign(s,e.headers);const b=y(e),g=e.endpointOverride??a.endpoint,w=e.methodOverride??a.method,o=await u(g,{headers:s,method:w,timeout:f},JSON.stringify(b));if(!o.success)return{error:new c(n,`Failed to send email: ${o.error?.message||"Unknown error"}`,{cause:o.error}),success:!1};let l;const i=o.data?.body;return i&&typeof i=="object"&&(l=i.id??i.messageId??(i.data&&typeof i.data=="object"&&(i.data.id??i.data.messageId))),l??=j(),{data:{messageId:l,provider:n,response:o.data?.body,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new c(n,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){try{const e=await u(a.endpoint,{headers:d(),method:"GET",timeout:f});return!!(e.data&&typeof e.data=="object"&&"statusCode"in e.data&&typeof e.data.statusCode=="number"&&e.data.statusCode>=200&&e.data.statusCode<300)}catch{return!1}}}});export{z as default};
1
+ var v=Object.defineProperty;var p=(r,a)=>v(r,"name",{value:a,configurable:!0});import c from"./EmailError-C4nx6TgJ.js";import A from"./RequiredOptionError-BeTzeno6.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{m as u}from"./make-request-C7fcsalD.js";import{d as O}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as P}from"./defineProvider-CtLH0VBE.js";var C=Object.defineProperty,h=p((r,a)=>C(r,"name",{value:a,configurable:!0}),"f");const n="http",I="POST",f=3e4,z=P((r={})=>{if(!r.endpoint)throw new A(n,"endpoint");const a={apiKey:r.apiKey??"",endpoint:r.endpoint,headers:r.headers??{},method:r.method??I},d=h(()=>{const e={"Content-Type":"application/json",...a.headers};return a.apiKey&&(e.Authorization=`Bearer ${a.apiKey}`),e},"getStandardHeaders"),y=h(e=>{const t={from:e.from.email,from_name:e.from.name,html:e.html,subject:e.subject,text:e.text,to:Array.isArray(e.to)?e.to.map(s=>s.email):e.to.email};return e.cc&&(t.cc=Array.isArray(e.cc)?e.cc.map(s=>s.email):e.cc.email),e.bcc&&(t.bcc=Array.isArray(e.bcc)?e.bcc.map(s=>s.email):e.bcc.email),e.customParams&&Object.assign(t,e.customParams),t},"formatRequest");let m=!1;return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!m){if(!await this.isAvailable())throw new c(n,"API endpoint not available");m=!0}},async isAvailable(){try{return!!(await u(a.endpoint,{headers:d(),method:"OPTIONS",timeout:f})).success}catch(e){if(e instanceof Error){const t=e.message;if(t.includes("401")||t.includes("403"))return!1}return!1}},name:n,options:a,async sendEmail(e){try{const t=O(e);if(t.length>0)return{error:new c(n,`Invalid email options: ${t.join(", ")}`),success:!1};m||await this.initialize();const s=d();e.headers&&Object.assign(s,e.headers);const b=y(e),g=e.endpointOverride??a.endpoint,w=e.methodOverride??a.method,o=await u(g,{headers:s,method:w,timeout:f},JSON.stringify(b));if(!o.success)return{error:new c(n,`Failed to send email: ${o.error?.message||"Unknown error"}`,{cause:o.error}),success:!1};let l;const i=o.data?.body;return i&&typeof i=="object"&&(l=i.id??i.messageId??(i.data&&typeof i.data=="object"&&(i.data.id??i.data.messageId))),l??=j(),{data:{messageId:l,provider:n,response:o.data?.body,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new c(n,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){try{const e=await u(a.endpoint,{headers:d(),method:"GET",timeout:f});return!!(e.data&&typeof e.data=="object"&&"statusCode"in e.data&&typeof e.data.statusCode=="number"&&e.data.statusCode>=200&&e.data.statusCode<300)}catch{return!1}}}});export{z as default};
@@ -1 +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--BdZNxIl.js";import{c as k,P as S,u as w,h as v}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{l as y}from"./address-formatter-Cm_E_ZMa.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,Q=K((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 S,o=k(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=q(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{Q as default};
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-C4nx6TgJ.js";import z from"./RequiredOptionError-BeTzeno6.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-C7fcsalD.js";import{c as k,P as S,u as w,h as v}from"./provider-base-8LBAorjm.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{l as y}from"./address-formatter-Cm_E_ZMa.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,Q=K((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 S,o=k(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=q(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{Q as default};
@@ -1 +1 @@
1
- import{defineProvider as o}from"./defineProvider-CtLH0VBE.js";import l from"./smtpProvider-Unjao_fn.js";const s="mailcrab",u="localhost",n=1025,g=o((t={})=>{const e={debug:t.debug??!1,host:t.host??u,logger:t.logger,port:t.port??n,retries:t.retries,secure:t.secure??!1,timeout:t.timeout},a=l({debug:e.debug,host:e.host,logger:e.logger,port:e.port,retries:e.retries,secure:e.secure,timeout:e.timeout});return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await a.initialize()},async isAvailable(){return a.isAvailable()},name:s,options:e,async sendEmail(i){const r=await a.sendEmail(i);return r.success&&r.data?{data:{...r.data,provider:s},success:!0}:r},async validateCredentials(){return a.validateCredentials?.()??!1}}});export{g as default};
1
+ import{defineProvider as o}from"./defineProvider-CtLH0VBE.js";import l from"./smtpProvider-BPNpC2T2.js";const s="mailcrab",u="localhost",n=1025,g=o((t={})=>{const e={debug:t.debug??!1,host:t.host??u,logger:t.logger,port:t.port??n,retries:t.retries,secure:t.secure??!1,timeout:t.timeout},a=l({debug:e.debug,host:e.host,logger:e.logger,port:e.port,retries:e.retries,secure:e.secure,timeout:e.timeout});return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await a.initialize()},async isAvailable(){return a.isAvailable()},name:s,options:e,async sendEmail(i){const r=await a.sendEmail(i);return r.success&&r.data?{data:{...r.data,provider:s},success:!0}:r},async validateCredentials(){return a.validateCredentials?.()??!1}}});export{g as default};
@@ -1 +1 @@
1
- import c from"./EmailError-zm2ffVav.js";import P from"./RequiredOptionError-CevW3u2K.js";import{s as I}from"./generate-message-id-D4uA8gkj.js";import{i as T}from"./headers-to-record-Qo124ImV.js";import{m as d}from"./make-request--BdZNxIl.js";import{c as A,P as k,u as g,h as f}from"./provider-base-Cmzx6BTO.js";import{a as $,s as z}from"./sanitize-header-wWav-Scu.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as j}from"./defineProvider-CtLH0VBE.js";import{n as u,c as h}from"./address-formatter-Cm_E_ZMa.js";const r="mailpace",C="https://app.mailpace.com/api/v1",M=3e4,S=3,G=j(((n={})=>{if(!n.apiToken)throw new P(r,"apiToken");const s={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??C,retries:n.retries??S,timeout:n.timeout??M,...n.logger&&{logger:n.logger}},l=new k,i=A(r,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[$(v)]=z(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},o=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const m=o.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}}));export{G as default};
1
+ import c from"./EmailError-C4nx6TgJ.js";import P from"./RequiredOptionError-BeTzeno6.js";import{s as I}from"./generate-message-id-D4uA8gkj.js";import{i as T}from"./headers-to-record-Qo124ImV.js";import{m as d}from"./make-request-C7fcsalD.js";import{c as A,P as k,u as g,h as f}from"./provider-base-8LBAorjm.js";import{a as $,s as z}from"./sanitize-header-wWav-Scu.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as j}from"./defineProvider-CtLH0VBE.js";import{n as u,c as h}from"./address-formatter-Cm_E_ZMa.js";const r="mailpace",C="https://app.mailpace.com/api/v1",M=3e4,S=3,G=j(((n={})=>{if(!n.apiToken)throw new P(r,"apiToken");const s={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??C,retries:n.retries??S,timeout:n.timeout??M,...n.logger&&{logger:n.logger}},l=new k,i=A(r,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[$(v)]=z(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},o=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const m=o.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}}));export{G as default};
@@ -1 +1 @@
1
- var T=Object.defineProperty;var h=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request--BdZNxIl.js";import{c as S,P as $,u as b,h as y}from"./provider-base-Cmzx6BTO.js";import{d as C}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as E}from"./defineProvider-CtLH0VBE.js";import{f,a as q}from"./address-formatter-Cm_E_ZMa.js";const I=A(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=h(o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,c]=m.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return m.getBuiltinModule(o)}return I(o)},"__cjs_getBuiltinModule"),{Buffer:_}=P("node:buffer"),s="mailersend",M="https://api.mailersend.com",B=3e4,R=3,K=E((o={})=>{if(!o.apiToken)throw new k(s,"apiToken");const a={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??R,timeout:o.timeout??B,...o.logger&&{logger:o.logger}},c=new $,n=S(s,o.logger);return{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 l(s,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const r={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>p(`${a.endpoint}/v1/activity/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new l(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:y(s,"retrieve email",r,n),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"MailerSend API not available or invalid API token");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Checking MailerSend API availability");const r=await p(`${a.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:a.timeout});return n.debug("MailerSend API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const r=C(e);if(r.length>0)return{error:new l(s,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.reply_to=q(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(t.personalization=e.personalization),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.scheduledAt&&(t.send_at=e.scheduledAt),e.domainId&&(t.domain_id=e.domainId),e.headers){const i=j(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 w=await i.content;u=_.from(w).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 l(s,`Attachment ${i.filename} has no content`);return{content:u,filename:i.filename,...i.contentType&&{type:i.contentType},...i.cid&&{id:i.cid}}}))),n.debug("Sending email via MailerSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"},d=await b(async()=>p(`${a.endpoint}/v1/email`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new l(s,"Failed to send email"),success:!1};const g=d.data?.body?.message_id??z();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:y(s,"send email",r,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{K as default};
1
+ var T=Object.defineProperty;var h=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-C4nx6TgJ.js";import k from"./RequiredOptionError-BeTzeno6.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request-C7fcsalD.js";import{c as S,P as $,u as b,h as y}from"./provider-base-8LBAorjm.js";import{d as C}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as E}from"./defineProvider-CtLH0VBE.js";import{f,a as q}from"./address-formatter-Cm_E_ZMa.js";const I=A(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=h(o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,c]=m.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return m.getBuiltinModule(o)}return I(o)},"__cjs_getBuiltinModule"),{Buffer:_}=P("node:buffer"),s="mailersend",M="https://api.mailersend.com",B=3e4,R=3,K=E((o={})=>{if(!o.apiToken)throw new k(s,"apiToken");const a={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??R,timeout:o.timeout??B,...o.logger&&{logger:o.logger}},c=new $,n=S(s,o.logger);return{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 l(s,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const r={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>p(`${a.endpoint}/v1/activity/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new l(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:y(s,"retrieve email",r,n),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"MailerSend API not available or invalid API token");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Checking MailerSend API availability");const r=await p(`${a.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:a.timeout});return n.debug("MailerSend API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const r=C(e);if(r.length>0)return{error:new l(s,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.reply_to=q(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(t.personalization=e.personalization),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.scheduledAt&&(t.send_at=e.scheduledAt),e.domainId&&(t.domain_id=e.domainId),e.headers){const i=j(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 w=await i.content;u=_.from(w).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 l(s,`Attachment ${i.filename} has no content`);return{content:u,filename:i.filename,...i.contentType&&{type:i.contentType},...i.cid&&{id:i.cid}}}))),n.debug("Sending email via MailerSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"},d=await b(async()=>p(`${a.endpoint}/v1/email`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new l(s,"Failed to send email"),success:!1};const g=d.data?.body?.message_id??z();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:y(s,"send email",r,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{K as default};
@@ -1 +1 @@
1
- var A=Object.defineProperty;var y=(i,r)=>A(i,"name",{value:r,configurable:!0});import{createRequire as P}from"node:module";import m from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as R}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request--BdZNxIl.js";import{c as _,P as z,u as j,h as I}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{a as U}from"./attachment-processor-DsmIomKc.js";import{b as v,c as k}from"./address-formatter-Cm_E_ZMa.js";const C=P(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,n]=u.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return u.getBuiltinModule(i)}return C(i)},"__cjs_getBuiltinModule"),{Buffer:b}=$("node:buffer");var M=Object.defineProperty,K=y((i,r)=>M(i,"name",{value:r,configurable:!0}),"T");const s="mailgun",B="https://api.mailgun.net",O=3e4,x=3,D=K(i=>{const r=[];for(const[n,o]of Object.entries(i))if(o!=null)if(Array.isArray(o))for(const e of o)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof o=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(o))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(o))}`);return r.join("&")},"objectToFormData"),ee=q((i={})=>{if(!i.apiKey)throw new T(s,"apiKey");if(!i.domain)throw new T(s,"domain");const r={apiKey:i.apiKey,debug:i.debug??!1,domain:i.domain,endpoint:i.endpoint??B,retries:i.retries??x,timeout:i.timeout??O,...i.logger&&{logger:i.logger}},n=new z,o=_(s,i.logger);return{endpoint:r.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 m(s,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const a={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:a,method:"GET",timeout:r.timeout}),r.retries);if(!t.success)return o.debug("API request failed when retrieving email",t.error),{error:new m(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1};o.debug("Email details retrieved successfully");const p=t.data?.items??[],g=p.length>0?p[0]:void 0;return{data:g?.message?.headers??g?.storage??void 0,success:!0}}catch(a){return{error:I(s,"retrieve email",a,o),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(s,"Mailgun API not available or invalid API key/domain");o.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailgun API availability");const a=await h(`${r.endpoint}/v3/domains/${r.domain}`,{headers:e,method:"GET",timeout:r.timeout});if(o.debug("Mailgun API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!a.success||!a.data||typeof a.data!="object")return!1;const{statusCode:t}=a.data;return typeof t=="number"&&t>=200&&t<300}catch(e){return o.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new m(s,`Invalid email options: ${a.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={from:k(e.from),to:v(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=v(e.cc).join(",")),e.bcc&&(t.bcc=v(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=k(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[d,c]of Object.entries(e.templateVariables))t[`v:${d}`]=c;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const d=S(e.headers);for(const[c,f]of Object.entries(d))t[`h:${c}`]=f}if(e.attachments&&e.attachments.length>0){const d=await Promise.all(e.attachments.map((c,f)=>U(c,s,f)));for(const c of d)t[c.key]=c.content}o.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const p={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=D(t),l=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/messages`,{headers:p,method:"POST",timeout:r.timeout},g),r.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new m(s,"Failed to send email"),success:!1};const w=l.data?.body?.id??R();return o.debug("Email sent successfully",{messageId:w}),{data:{messageId:w,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:I(s,"send email",a,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{ee as default};
1
+ var A=Object.defineProperty;var y=(i,r)=>A(i,"name",{value:r,configurable:!0});import{createRequire as P}from"node:module";import m from"./EmailError-C4nx6TgJ.js";import T from"./RequiredOptionError-BeTzeno6.js";import{s as R}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request-C7fcsalD.js";import{c as _,P as z,u as j,h as I}from"./provider-base-8LBAorjm.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{b as v,c as k}from"./address-formatter-Cm_E_ZMa.js";import{a as U}from"./attachment-processor-BREe8fDh.js";const C=P(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,n]=u.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return u.getBuiltinModule(i)}return C(i)},"__cjs_getBuiltinModule"),{Buffer:b}=$("node:buffer");var M=Object.defineProperty,K=y((i,r)=>M(i,"name",{value:r,configurable:!0}),"T");const s="mailgun",B="https://api.mailgun.net",O=3e4,x=3,D=K(i=>{const r=[];for(const[n,o]of Object.entries(i))if(o!=null)if(Array.isArray(o))for(const e of o)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof o=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(o))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(o))}`);return r.join("&")},"objectToFormData"),ee=q((i={})=>{if(!i.apiKey)throw new T(s,"apiKey");if(!i.domain)throw new T(s,"domain");const r={apiKey:i.apiKey,debug:i.debug??!1,domain:i.domain,endpoint:i.endpoint??B,retries:i.retries??x,timeout:i.timeout??O,...i.logger&&{logger:i.logger}},n=new z,o=_(s,i.logger);return{endpoint:r.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 m(s,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const a={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:a,method:"GET",timeout:r.timeout}),r.retries);if(!t.success)return o.debug("API request failed when retrieving email",t.error),{error:new m(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1};o.debug("Email details retrieved successfully");const p=t.data?.items??[],g=p.length>0?p[0]:void 0;return{data:g?.message?.headers??g?.storage??void 0,success:!0}}catch(a){return{error:I(s,"retrieve email",a,o),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(s,"Mailgun API not available or invalid API key/domain");o.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailgun API availability");const a=await h(`${r.endpoint}/v3/domains/${r.domain}`,{headers:e,method:"GET",timeout:r.timeout});if(o.debug("Mailgun API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!a.success||!a.data||typeof a.data!="object")return!1;const{statusCode:t}=a.data;return typeof t=="number"&&t>=200&&t<300}catch(e){return o.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new m(s,`Invalid email options: ${a.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={from:k(e.from),to:v(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=v(e.cc).join(",")),e.bcc&&(t.bcc=v(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=k(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[d,c]of Object.entries(e.templateVariables))t[`v:${d}`]=c;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const d=S(e.headers);for(const[c,f]of Object.entries(d))t[`h:${c}`]=f}if(e.attachments&&e.attachments.length>0){const d=await Promise.all(e.attachments.map((c,f)=>U(c,s,f)));for(const c of d)t[c.key]=c.content}o.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const p={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=D(t),l=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/messages`,{headers:p,method:"POST",timeout:r.timeout},g),r.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new m(s,"Failed to send email"),success:!1};const w=l.data?.body?.id??R();return o.debug("Email sent successfully",{messageId:w}),{data:{messageId:w,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:I(s,"send email",a,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{ee as default};