@visulima/email 2.1.8 → 2.1.9

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 (273) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.md +159 -19
  3. package/dist/crypto/index.js +1 -1
  4. package/dist/deliverability/dmarc-report.js +1 -1
  5. package/dist/deliverability/index.js +1 -1
  6. package/dist/events/index.js +1 -1
  7. package/dist/inbound/index.js +1 -1
  8. package/dist/index.d.ts +1 -2
  9. package/dist/index.js +1 -1
  10. package/dist/middleware/index.js +1 -1
  11. package/dist/packem_shared/ALL_EVENTS-CSpGgYbV.js +1 -0
  12. package/dist/packem_shared/DkimSigner-B_pEwGCS.js +18 -0
  13. package/dist/packem_shared/DraftMailMessage-Tj3sH8nn.js +1 -0
  14. package/dist/packem_shared/EmailError-BIaHK1Uw.js +1 -0
  15. package/dist/packem_shared/Mail-Cm24B3w0.js +1 -0
  16. package/dist/packem_shared/MailMessage-BtI4qMU1.js +1 -0
  17. package/dist/packem_shared/MemorySuppressionStore-D_bge6rS.js +1 -0
  18. package/dist/packem_shared/RATE_LIMIT_PRESETS-BIFmRuh2.js +1 -0
  19. package/dist/packem_shared/RequiredOptionError-ctDEEB1s.js +1 -0
  20. package/dist/packem_shared/SmimeEncrypter-BjBwjaTg.js +6 -0
  21. package/dist/packem_shared/SmimeSigner-CK5TITxI.js +8 -0
  22. package/dist/packem_shared/address-formatter-CXZ1aWBX.js +1 -0
  23. package/dist/packem_shared/aggregate-features-Bst55u8k.js +1 -0
  24. package/dist/packem_shared/ahaSendProvider-DY559XjD.js +1 -0
  25. package/dist/packem_shared/arcMessageSignatureBase-B0Qi-724.js +17 -0
  26. package/dist/packem_shared/attachment-processor-BJFDS343.js +1 -0
  27. package/dist/packem_shared/autoSendProvider-BgdWf422.js +1 -0
  28. package/dist/packem_shared/awsSesProvider-DTnLwAbE.js +32 -0
  29. package/dist/packem_shared/azureProvider-Bs4BGYR1.js +1 -0
  30. package/dist/packem_shared/brevoProvider-xoRTeFIx.js +1 -0
  31. package/dist/packem_shared/build-mime-message-QNCMA6oQ.js +3 -0
  32. package/dist/packem_shared/buildListUnsubscribe-g1CoihSv.js +1 -0
  33. package/dist/packem_shared/buildMtaStsPolicy-BA2YXL72.js +6 -0
  34. package/dist/packem_shared/circuitBreakerMiddleware-DcBN7K6H.js +1 -0
  35. package/dist/packem_shared/cloudflareEmailProvider-BkR-P0YD.js +1 -0
  36. package/dist/packem_shared/composeMiddleware-B3RCDFsy.js +1 -0
  37. package/dist/packem_shared/create-logger-CazqtXcL.js +1 -0
  38. package/dist/packem_shared/create-token-cache-BdMsMzf7.js +1 -0
  39. package/dist/packem_shared/createSuppressionStore-DbocihI8.js +1 -0
  40. package/dist/packem_shared/createTestEmail-CPnHNKBT.js +1 -0
  41. package/dist/packem_shared/createWorker-ChuTgETP.js +1 -0
  42. package/dist/packem_shared/dedupeMiddleware-BTo8Qjje.js +1 -0
  43. package/dist/packem_shared/defineInboundHandler-CnYn10ex.js +1 -0
  44. package/dist/packem_shared/detectMimeType-DVC9Uvy9.js +1 -0
  45. package/dist/packem_shared/emailMatchers-DpwItmkN.js +1 -0
  46. package/dist/packem_shared/extractReply-CLoWMY97.js +5 -0
  47. package/dist/packem_shared/failoverProvider-DSsuXHYK.js +1 -0
  48. package/dist/packem_shared/format-address-BDKhXcXV.js +1 -0
  49. package/dist/packem_shared/{generate-boundary-0xGe9GqK.js → generate-boundary-BCSUEi6x.js} +1 -1
  50. package/dist/packem_shared/generate-message-id-B2n2yqR6.js +1 -0
  51. package/dist/packem_shared/headers-to-record-ZOZ7Dubo.js +1 -0
  52. package/dist/packem_shared/httpProvider-CdoJ-tL7.js +1 -0
  53. package/dist/packem_shared/index-B8wiKJdh.js +1 -0
  54. package/dist/packem_shared/infobipProvider-mEYgfWJ7.js +1 -0
  55. package/dist/packem_shared/isValidSigningCertUrl-CK1t2a7x.js +3 -0
  56. package/dist/packem_shared/loggingMiddleware-DNVf8O1B.js +1 -0
  57. package/dist/packem_shared/loopsProvider-CKJ_rzLq.js +1 -0
  58. package/dist/packem_shared/{mail.d-B9JyPxzq.d.ts → mail.d-8M9NjOr0.d.ts} +1 -2
  59. package/dist/packem_shared/mailCrabProvider-Cx9rnuyE.js +1 -0
  60. package/dist/packem_shared/mailPaceProvider-DvSlan-v.js +1 -0
  61. package/dist/packem_shared/mailchannelsProvider-Cgb8el7C.js +1 -0
  62. package/dist/packem_shared/mailerSendProvider-BvRIjuVE.js +1 -0
  63. package/dist/packem_shared/mailgunProvider-kNcvF_z6.js +1 -0
  64. package/dist/packem_shared/mailjetProvider-DqJUhLuH.js +1 -0
  65. package/dist/packem_shared/mailomatProvider-BBOqRhV_.js +1 -0
  66. package/dist/packem_shared/mailtrapProvider-CeBW2Gzg.js +1 -0
  67. package/dist/packem_shared/make-request-Cyz5_yu8.js +1 -0
  68. package/dist/packem_shared/mandrillProvider-Dab8i0gF.js +1 -0
  69. package/dist/packem_shared/mockProvider-Bf5eJ_rl.js +1 -0
  70. package/dist/packem_shared/netcoreProvider-DMJsQ8IM.js +1 -0
  71. package/dist/packem_shared/nodemailerProvider-CJ4zkTPF.js +1 -0
  72. package/dist/packem_shared/normalizeMessageId-0yB1zeyC.js +1 -0
  73. package/dist/packem_shared/oauth2Middleware-DbKGd7Z9.js +1 -0
  74. package/dist/packem_shared/opentelemetryProvider-s0gvh05u.js +1 -0
  75. package/dist/packem_shared/outlook365Provider-DKMz0Vvh.js +1 -0
  76. package/dist/packem_shared/parseAddress-DW9suGjV.js +1 -0
  77. package/dist/packem_shared/parseArfReport-VbQeofN4.js +6 -0
  78. package/dist/packem_shared/parseCloudflareInbound-BKZzk0De.js +1 -0
  79. package/dist/packem_shared/parseDmarcRecord-9B3Qhba8.js +1 -0
  80. package/dist/packem_shared/parseMailgunInbound-nY-DXZrK.js +1 -0
  81. package/dist/packem_shared/parsePostmarkInbound-0zG71J7F.js +1 -0
  82. package/dist/packem_shared/parseSendGridInbound-BzEhN-gd.js +4 -0
  83. package/dist/packem_shared/parseSesInbound-C4cRtAUq.js +1 -0
  84. package/dist/packem_shared/parseTlsReport-DSiCaKFH.js +1 -0
  85. package/dist/packem_shared/plunkProvider-B-JtCJQy.js +1 -0
  86. package/dist/packem_shared/postalProvider-COVY4T94.js +1 -0
  87. package/dist/packem_shared/postmarkProvider-Cj64C4dc.js +1 -0
  88. package/dist/packem_shared/provider-base-BEz00m9R.js +1 -0
  89. package/dist/packem_shared/quoted-printable-BgiHOYdV.js +7 -0
  90. package/dist/packem_shared/resendProvider-Da5r7dMe.js +1 -0
  91. package/dist/packem_shared/retry-aghj7y8m.js +1 -0
  92. package/dist/packem_shared/retryMiddleware-CaTv0UIm.js +1 -0
  93. package/dist/packem_shared/roundRobinProvider-Dr1DdT2L.js +1 -0
  94. package/dist/packem_shared/sanitize-header-CW0f3IT7.js +1 -0
  95. package/dist/packem_shared/scalewayProvider-CDjpYmJc.js +1 -0
  96. package/dist/packem_shared/sendGridProvider-C1rp9hpg.js +1 -0
  97. package/dist/packem_shared/smtpProvider-Dr2XAFQu.js +27 -0
  98. package/dist/packem_shared/sparkpostProvider-DKon_hyx.js +1 -0
  99. package/dist/packem_shared/sweegoProvider-BclZuNBf.js +1 -0
  100. package/dist/packem_shared/toEmailSnapshot-BOhTn44E.js +1 -0
  101. package/dist/packem_shared/utils-CDV8xy3e.js +1 -0
  102. package/dist/packem_shared/validate-email-options-DxdAVLlu.js +1 -0
  103. package/dist/packem_shared/{verifyMailgunWebhook-DNk080BF.js → verifyMailgunWebhook-DS4o0kZL.js} +1 -1
  104. package/dist/packem_shared/{verifyPostmarkWebhook-B4OIEHQF.js → verifyPostmarkWebhook-pLwWmeOl.js} +1 -1
  105. package/dist/packem_shared/verifyResendWebhook-D3GuwWjv.js +1 -0
  106. package/dist/packem_shared/verifySendGridWebhook-csuRasH3.js +1 -0
  107. package/dist/packem_shared/withEvents-BinK2hMw.js +1 -0
  108. package/dist/packem_shared/withMetrics-i3mZVfeE.js +1 -0
  109. package/dist/packem_shared/withRender-Ce6leoYE.js +1 -0
  110. package/dist/packem_shared/withSuppression-B0eZ2xNQ.js +1 -0
  111. package/dist/packem_shared/{withTelemetry-DL2qo0Hp.js → withTelemetry-DEKTis1I.js} +1 -1
  112. package/dist/packem_shared/zeptomailProvider-D5B3kqFm.js +1 -0
  113. package/dist/providers/ahasend/index.js +1 -1
  114. package/dist/providers/autosend/index.js +1 -1
  115. package/dist/providers/aws-ses/index.js +1 -1
  116. package/dist/providers/azure/index.js +1 -1
  117. package/dist/providers/brevo/index.js +1 -1
  118. package/dist/providers/cloudflare-email/index.js +1 -1
  119. package/dist/providers/failover/index.js +1 -1
  120. package/dist/providers/http/index.js +1 -1
  121. package/dist/providers/infobip/index.js +1 -1
  122. package/dist/providers/loops/index.js +1 -1
  123. package/dist/providers/mailchannels/index.js +1 -1
  124. package/dist/providers/mailcrab/index.js +1 -1
  125. package/dist/providers/mailersend/index.js +1 -1
  126. package/dist/providers/mailgun/index.js +1 -1
  127. package/dist/providers/mailjet/index.js +1 -1
  128. package/dist/providers/mailomat/index.js +1 -1
  129. package/dist/providers/mailpace/index.js +1 -1
  130. package/dist/providers/mailtrap/index.js +1 -1
  131. package/dist/providers/mandrill/index.js +1 -1
  132. package/dist/providers/mock/index.js +1 -1
  133. package/dist/providers/netcore/index.js +1 -1
  134. package/dist/providers/nodemailer/index.js +1 -1
  135. package/dist/providers/opentelemetry/index.d.ts +1 -1
  136. package/dist/providers/opentelemetry/index.js +1 -1
  137. package/dist/providers/outlook365/index.js +1 -1
  138. package/dist/providers/plunk/index.js +1 -1
  139. package/dist/providers/postal/index.js +1 -1
  140. package/dist/providers/postmark/index.js +1 -1
  141. package/dist/providers/resend/index.js +1 -1
  142. package/dist/providers/roundrobin/index.js +1 -1
  143. package/dist/providers/scaleway/index.js +1 -1
  144. package/dist/providers/sendgrid/index.js +1 -1
  145. package/dist/providers/smtp/index.js +1 -1
  146. package/dist/providers/sparkpost/index.js +1 -1
  147. package/dist/providers/sweego/index.js +1 -1
  148. package/dist/providers/zeptomail/index.js +1 -1
  149. package/dist/queue/bullmq-queue.js +1 -1
  150. package/dist/queue/index.js +1 -1
  151. package/dist/queue/pg-boss-queue.js +1 -1
  152. package/dist/queue/sqs-queue.js +1 -1
  153. package/dist/queue/unstorage-queue.js +1 -1
  154. package/dist/render/cid.js +1 -1
  155. package/dist/render/css-inline.js +1 -1
  156. package/dist/render/dark-mode.js +1 -1
  157. package/dist/render/preheader.js +1 -1
  158. package/dist/template-engines/handlebars.js +1 -1
  159. package/dist/template-engines/html-to-text.js +1 -1
  160. package/dist/template-engines/i18n.js +1 -1
  161. package/dist/template-engines/jsx-email.js +1 -1
  162. package/dist/template-engines/liquid.js +1 -1
  163. package/dist/template-engines/mjml.js +1 -1
  164. package/dist/template-engines/react-email.js +1 -1
  165. package/dist/template-engines/vue-email.js +1 -1
  166. package/dist/test/index.d.ts +2 -3
  167. package/dist/test/index.js +1 -1
  168. package/dist/utils/cache.js +1 -1
  169. package/dist/utils/format-email-address.js +1 -1
  170. package/dist/utils/parse-address.js +1 -1
  171. package/dist/utils/parse-eml.js +4 -4
  172. package/dist/utils/result.js +1 -1
  173. package/dist/utils/validation/check-feature-support.js +1 -1
  174. package/dist/utils/validation/validate-email.js +1 -1
  175. package/dist/webhooks/index.js +1 -1
  176. package/package.json +6 -6
  177. package/dist/packem_shared/ALL_EVENTS-3kwh5CBE.js +0 -1
  178. package/dist/packem_shared/DkimSigner-udCl3JXO.js +0 -18
  179. package/dist/packem_shared/DraftMailMessage-BgP1OF1G.js +0 -1
  180. package/dist/packem_shared/EmailError-2CCyVX1S.js +0 -1
  181. package/dist/packem_shared/Mail-DduRntbB.js +0 -1
  182. package/dist/packem_shared/MailMessage-BRBT4Jea.js +0 -1
  183. package/dist/packem_shared/MemorySuppressionStore-DZnbz-_B.js +0 -1
  184. package/dist/packem_shared/RATE_LIMIT_PRESETS-BPADLgcA.js +0 -1
  185. package/dist/packem_shared/RequiredOptionError-BmpC5whN.js +0 -1
  186. package/dist/packem_shared/SmimeEncrypter-Dm9McVTQ.js +0 -6
  187. package/dist/packem_shared/SmimeSigner-B6hkacNk.js +0 -8
  188. package/dist/packem_shared/address-formatter-bfmGfQ83.js +0 -1
  189. package/dist/packem_shared/aggregate-features-BqEjPd42.js +0 -1
  190. package/dist/packem_shared/ahaSendProvider-C6nBGCCa.js +0 -1
  191. package/dist/packem_shared/arcMessageSignatureBase-B2uArM48.js +0 -17
  192. package/dist/packem_shared/attachment-processor-DjbjtJ6H.js +0 -1
  193. package/dist/packem_shared/autoSendProvider-Dhig--Zo.js +0 -1
  194. package/dist/packem_shared/awsSesProvider-CMqAmU5N.js +0 -32
  195. package/dist/packem_shared/azureProvider-C-bNOOil.js +0 -1
  196. package/dist/packem_shared/brevoProvider-CkOjDyir.js +0 -1
  197. package/dist/packem_shared/build-mime-message-t8KYiQkO.js +0 -3
  198. package/dist/packem_shared/buildListUnsubscribe-Cdr8MvR_.js +0 -1
  199. package/dist/packem_shared/buildMtaStsPolicy-oEQg8y_C.js +0 -6
  200. package/dist/packem_shared/circuitBreakerMiddleware-BSCPR72q.js +0 -1
  201. package/dist/packem_shared/cloudflareEmailProvider-RCixPWnY.js +0 -1
  202. package/dist/packem_shared/composeMiddleware-BHwLLEzK.js +0 -1
  203. package/dist/packem_shared/create-logger-BQTS3f-I.js +0 -1
  204. package/dist/packem_shared/create-token-cache-D56KQGVQ.js +0 -1
  205. package/dist/packem_shared/createSuppressionStore-CeAZKCbY.js +0 -1
  206. package/dist/packem_shared/createTestEmail-XiF5E8vJ.js +0 -1
  207. package/dist/packem_shared/createWorker-_-yMWcNQ.js +0 -1
  208. package/dist/packem_shared/dedupeMiddleware-CYYI_O7S.js +0 -1
  209. package/dist/packem_shared/defineInboundHandler-CnL2BzlL.js +0 -1
  210. package/dist/packem_shared/detectMimeType-B9_7ujpC.js +0 -1
  211. package/dist/packem_shared/emailMatchers-DZDkrZ_3.js +0 -1
  212. package/dist/packem_shared/extractReply-BUjIBt9A.js +0 -5
  213. package/dist/packem_shared/failoverProvider-BkOOP7pt.js +0 -1
  214. package/dist/packem_shared/format-address-DTl-9O70.js +0 -1
  215. package/dist/packem_shared/generate-message-id-gXAuMz4g.js +0 -1
  216. package/dist/packem_shared/headers-to-record-De1Eg951.js +0 -1
  217. package/dist/packem_shared/httpProvider-6idLfv-f.js +0 -1
  218. package/dist/packem_shared/index-y0s2wQdc.js +0 -11
  219. package/dist/packem_shared/infobipProvider-CHHsqRXy.js +0 -1
  220. package/dist/packem_shared/isValidSigningCertUrl-D7PuiRW4.js +0 -3
  221. package/dist/packem_shared/loggingMiddleware-CZIiVMVp.js +0 -1
  222. package/dist/packem_shared/loopsProvider-Cl-dOuCN.js +0 -1
  223. package/dist/packem_shared/mailCrabProvider-De2YxPlF.js +0 -1
  224. package/dist/packem_shared/mailPaceProvider-DwNTuFb2.js +0 -1
  225. package/dist/packem_shared/mailchannelsProvider-Dwl0Typz.js +0 -1
  226. package/dist/packem_shared/mailerSendProvider-CyMIbqGq.js +0 -1
  227. package/dist/packem_shared/mailgunProvider-DWKJYRKT.js +0 -1
  228. package/dist/packem_shared/mailjetProvider-DXPJQO1G.js +0 -1
  229. package/dist/packem_shared/mailomatProvider-DopZk27y.js +0 -1
  230. package/dist/packem_shared/mailtrapProvider-CTg4z3GN.js +0 -1
  231. package/dist/packem_shared/make-request-CDhxj-9b.js +0 -1
  232. package/dist/packem_shared/mandrillProvider-CAQeMtU_.js +0 -1
  233. package/dist/packem_shared/mockProvider-EcpYlg-_.js +0 -1
  234. package/dist/packem_shared/netcoreProvider-ua1avx07.js +0 -1
  235. package/dist/packem_shared/nodemailerProvider-BZmQfKlM.js +0 -1
  236. package/dist/packem_shared/normalizeMessageId-DAx2pGe2.js +0 -1
  237. package/dist/packem_shared/oauth2Middleware-DQh-hIkv.js +0 -1
  238. package/dist/packem_shared/opentelemetryProvider-CAfWpywa.js +0 -1
  239. package/dist/packem_shared/outlook365Provider-SFYELGDr.js +0 -1
  240. package/dist/packem_shared/parseAddress-DdbViBAJ.js +0 -1
  241. package/dist/packem_shared/parseArfReport-Ds6S3c4J.js +0 -6
  242. package/dist/packem_shared/parseCloudflareInbound-C__j-oNa.js +0 -1
  243. package/dist/packem_shared/parseDmarcRecord-DXZ-_rF0.js +0 -1
  244. package/dist/packem_shared/parseMailgunInbound-BpC6uPNe.js +0 -1
  245. package/dist/packem_shared/parsePostmarkInbound-Co3_c6-9.js +0 -1
  246. package/dist/packem_shared/parseSendGridInbound-DsALoijO.js +0 -4
  247. package/dist/packem_shared/parseSesInbound-CH5tHIjp.js +0 -1
  248. package/dist/packem_shared/parseTlsReport-wPe1lIDs.js +0 -1
  249. package/dist/packem_shared/plunkProvider-9amwuQri.js +0 -1
  250. package/dist/packem_shared/postalProvider-CeF3TOIW.js +0 -1
  251. package/dist/packem_shared/postmarkProvider-BPgKEkgF.js +0 -1
  252. package/dist/packem_shared/provider-base-B-xhQSqE.js +0 -1
  253. package/dist/packem_shared/quoted-printable-nSGDA1tA.js +0 -7
  254. package/dist/packem_shared/resendProvider-C9_sM8bH.js +0 -1
  255. package/dist/packem_shared/retry-D1Rh-6Z4.js +0 -1
  256. package/dist/packem_shared/retryMiddleware-DbViDX4r.js +0 -1
  257. package/dist/packem_shared/roundRobinProvider-BPzLWZf-.js +0 -1
  258. package/dist/packem_shared/sanitize-header-DtQwAnzg.js +0 -1
  259. package/dist/packem_shared/scalewayProvider-DfC7275i.js +0 -1
  260. package/dist/packem_shared/sendGridProvider-CUBBHBzs.js +0 -1
  261. package/dist/packem_shared/smtpProvider-9nBSGtQl.js +0 -27
  262. package/dist/packem_shared/sparkpostProvider-Be_d7S8o.js +0 -1
  263. package/dist/packem_shared/sweegoProvider-CP1cNC-d.js +0 -1
  264. package/dist/packem_shared/toEmailSnapshot-DeRqM5SJ.js +0 -1
  265. package/dist/packem_shared/utils-DjEtR3qT.js +0 -1
  266. package/dist/packem_shared/validate-email-options-mCM9dVug.js +0 -1
  267. package/dist/packem_shared/verifyResendWebhook-C7E32LZ1.js +0 -1
  268. package/dist/packem_shared/verifySendGridWebhook-DtFMgBRP.js +0 -1
  269. package/dist/packem_shared/withEvents-CytsykaK.js +0 -1
  270. package/dist/packem_shared/withMetrics-DWywX_6M.js +0 -1
  271. package/dist/packem_shared/withRender-VP9wE5Yr.js +0 -1
  272. package/dist/packem_shared/withSuppression-wDl4NTb-.js +0 -1
  273. package/dist/packem_shared/zeptomailProvider-BZ0fK0Lk.js +0 -1
@@ -0,0 +1,6 @@
1
+ const c=new Set(["enforce","none","testing"]),d=o=>{const t=[];let s,e,i;for(const m of o.replaceAll(`\r
2
+ `,`
3
+ `).split(`
4
+ `)){const a=m.indexOf(":");if(a===-1)continue;const r=m.slice(0,a).trim().toLowerCase(),n=m.slice(a+1).trim();if(r==="version")s=n;else if(r==="mode"&&(n==="enforce"||n==="testing"||n==="none"))e=n;else if(r==="max_age"){const l=Number.parseInt(n,10);i=Number.isNaN(l)?void 0:l}else r==="mx"&&n.length>0&&t.push(n)}return{maxAge:i,mode:e,mx:t,valid:s==="STSv1"&&e!==void 0&&i!==void 0,version:s}},g=o=>{if(!c.has(o.mode))throw new TypeError('buildMtaStsPolicy: `mode` must be one of "enforce", "testing", or "none"');if(!Number.isInteger(o.maxAge)||o.maxAge<0)throw new TypeError("buildMtaStsPolicy: `maxAge` must be a non-negative integer");const t=o.mx.map(e=>e.trim());if(t.length===0||t.some(e=>e.length===0))throw new TypeError("buildMtaStsPolicy: `mx` must contain at least one non-empty host");return`${["version: STSv1",`mode: ${o.mode}`,...t.map(e=>`mx: ${e}`),`max_age: ${String(o.maxAge)}`].join(`\r
5
+ `)}\r
6
+ `};export{g as buildMtaStsPolicy,d as parseMtaStsPolicy};
@@ -0,0 +1 @@
1
+ import w from"./EmailError-BIaHK1Uw.js";const C=(u={})=>{const{failureThreshold:c=5,now:s=Date.now,onStateChange:p,resetTimeout:d=3e4}=u;let e="closed",n=0,l=0,t=!1;const i=r=>{e!==r&&(e=r,p?.(r))},a=()=>({error:new w("middleware","Circuit breaker is open",{code:"CIRCUIT_OPEN"}),success:!1});return async(r,h)=>{if(e==="open"&&s()-l>=d&&(i("half-open"),t=!1),e==="open")return a();let f=!1;if(e==="half-open"){if(t)return a();t=!0,f=!0}let o;try{o=await h(r)}finally{f&&(t=!1)}return o.success?(n=0,i("closed"),o):(n+=1,(e==="half-open"||n>=c)&&(l=s(),i("open")),o)}};export{C as circuitBreakerMiddleware};
@@ -0,0 +1 @@
1
+ import a from"./EmailError-BIaHK1Uw.js";import l from"./RequiredOptionError-ctDEEB1s.js";import{b as u}from"./build-mime-message-QNCMA6oQ.js";import{g as f}from"./generate-message-id-B2n2yqR6.js";import{h as m}from"./headers-to-record-ZOZ7Dubo.js";import{v as g}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as p}from"./defineProvider-C9q-7iwt.js";import{c as h,h as v}from"./provider-base-BEz00m9R.js";const r="cloudflare-email",R=p((s={})=>{if(typeof s.send!="function")throw new l(r,"send");const c=h(r,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await Promise.resolve()},async isAvailable(){return typeof s.send=="function"},name:r,async sendEmail(e){try{const t=g(e);if(t.length>0)return{error:new a(r,`Invalid email options: ${t.join(", ")}`),success:!1};const o=Array.isArray(e.to)?e.to:[e.to];if(o.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new a(r,"Cloudflare Email supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[i]=o;if(!i)return{error:new a(r,"A single `to` recipient is required"),success:!1};const n=f(),d=await u({...e,headers:{...e.headers?m(e.headers):{},"Message-ID":n}});return await s.send(e.from.email,i.email,d),{data:{messageId:n,provider:r,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(r,"send email",t,c),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
@@ -0,0 +1 @@
1
+ const d=(o,t)=>{let e=t;for(const r of o.toReversed()){const n=e;e=c=>r(c,n)}return e};export{d as composeMiddleware};
@@ -0,0 +1 @@
1
+ const c=(o,$)=>{const t=()=>{};return $?{debug:(n,...r)=>{$.log(`[${o}] ${n}`,...r)},error:(n,...r)=>{$.error(`[${o}] ${n}`,...r)},info:(n,...r)=>{$.info(`[${o}] ${n}`,...r)},warn:(n,...r)=>{$.warn(`[${o}] ${n}`,...r)}}:{debug:t,error:t,info:t,warn:t}};export{c};
@@ -0,0 +1 @@
1
+ const w=(c,r={})=>{const{now:o=Date.now,skewMs:a=6e4}=r,i=Math.max(0,a);let e,t;const h=n=>n.expiresAt===void 0||n.expiresAt-i>o();return async()=>e&&h(e)?e:(t??=c().then(s=>(e=s,s)).finally(()=>{t=void 0}),await t)};export{w as c};
@@ -0,0 +1 @@
1
+ import n from"./MemorySuppressionStore-D_bge6rS.js";const c=async(s,t)=>{const p=Array.isArray(s)?s:[s],e=[],o=[];for(const r of p)await t.has(r.email)?o.push(r):e.push(r);return{allowed:e,suppressed:o}},i=s=>new n(s);export{n as MemorySuppressionStore,i as createSuppressionStore,c as filterSuppressed};
@@ -0,0 +1 @@
1
+ import{createMail as d}from"./Mail-Cm24B3w0.js";import w from"./mockProvider-Bf5eJ_rl.js";const l=(t,o,e,n)=>{const r=Date.now()+e;return new Promise((i,s)=>{const a=()=>{const c=t.find(m=>o(m));if(c){i(c);return}if(Date.now()>=r){s(new Error("waitFor timed out before a matching message was captured"));return}setTimeout(a,n)};a()})},h=()=>{const t=w(),o=d(t),e=t.getInstance?.();if(!e)throw new Error("mockProvider() did not expose getInstance(); cannot create a test harness");return{mail:o,reset:()=>{e.length=0},sent:()=>e,waitFor:(n,r={})=>l(e,n,r.timeout??1e3,r.interval??10)}};export{h as createTestEmail};
@@ -0,0 +1 @@
1
+ const k=n=>1e3*2**(n-1),g=n=>{const{backoff:d=k,concurrency:v=1,maxAttempts:y=3,onDeadLetter:h,onError:u,onReserveError:m,pollInterval:p=1e3,queue:t,send:E}=n;let c=!1,i=0,s;const o=async(r,e)=>{try{await e()}catch(a){u?.(r,{error:a instanceof Error?a:new Error(String(a)),success:!1})}},l=async r=>{let e;try{e=await E(r.message)}catch(f){e={error:f instanceof Error?f:new Error(String(f)),success:!1}}if(e.success){await o(r,()=>t.ack(r.id));return}u?.(r,e);const a=r.attempts+1;if(a>=y){await o(r,()=>t.ack(r.id)),h?.(r,e);return}await o(r,()=>t.retry(r.id,d(a)))},w=async()=>{if(c){try{for(;i<v;){const r=await t.reserve();if(!r)break;i+=1,l(r).finally(()=>{i-=1}).catch(()=>{})}}catch(r){m?.(r instanceof Error?r:new Error(String(r)))}c&&(s=setTimeout(()=>{w().catch(()=>{})},p))}};return{drain:async()=>{let r=await t.reserve();for(;r;)await l(r),r=await t.reserve()},start:()=>{c||(c=!0,w().catch(()=>{}))},stop:()=>{c=!1,s&&(clearTimeout(s),s=void 0)}}};export{g as createWorker};
@@ -0,0 +1 @@
1
+ import{createRequire as _}from"node:module";let f;const y=t=>(f??=_(import.meta.url))(t),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=t=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[e,r]=s.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return s.getBuiltinModule(t)}return y(t)},{createHash:m}=h("node:crypto"),d=t=>t?(Array.isArray(t)?t:[t]).map(e=>e.email.toLowerCase()).toSorted((e,r)=>e.localeCompare(r)).join(","):"",g=t=>{const e=m("sha256");return e.update(d(t.to)),e.update("\0"),e.update(d(t.cc)),e.update("\0"),e.update(t.subject),e.update("\0"),e.update(t.text??t.html??""),e.digest("hex")},w=(t={})=>{const{keyFn:e=g,now:r=Date.now,ttl:p=6e4}=t,o=new Map;return async(a,l)=>{const u=e(a),i=r(),n=o.get(u);if(n&&n.expires>i)return n.result;const c=await l(a);return c.success&&o.set(u,{expires:i+p,result:c}),c}};export{w as dedupeMiddleware};
@@ -0,0 +1 @@
1
+ import o from"./parseCloudflareInbound-BKZzk0De.js";import s from"./parseMailgunInbound-nY-DXZrK.js";import u from"./parsePostmarkInbound-0zG71J7F.js";import a from"./parseSendGridInbound-BzEhN-gd.js";import i from"./parseSesInbound-C4cRtAUq.js";import{extractReply as m}from"./extractReply-CLoWMY97.js";const c=(n,r)=>{switch(n){case"cloudflare":return o(r);case"mailgun":return s(r);case"sendgrid":return a(r);case"ses":return i(r);default:return u(r)}},x=n=>({handle:async(r,t)=>{try{const e=c(r,t);return n.stripReply&&e.text!==void 0&&(e.text=m(e.text)),await n.onMessage(e),e}catch(e){if(n.onError){await n.onError(e,r,t);return}throw e}}});export{x as defineInboundHandler,c as parseInbound};
@@ -0,0 +1 @@
1
+ import{z as o}from"./index-B8wiKJdh.js";import a from"mime";const c=e=>a.getType(e)??"application/octet-stream",m=e=>{const t=e.replaceAll(/[^a-z0-9]/gi,"-").replaceAll(/-+/g,"-").replaceAll(/^-|-$/g,"").toLowerCase(),r=Math.random().toString(36).slice(2,9);return`${t}-${r}@email`},i=e=>o(e,{buffer:!0});export{c as detectMimeType,m as generateContentId,i as readFileAsBuffer};
@@ -0,0 +1 @@
1
+ const c=t=>"sent"in t?t.sent():t,i=t=>t?(Array.isArray(t)?t:[t]).map(e=>e.email.toLowerCase()):[],m=t=>[...i(t.to),...i(t.cc),...i(t.bcc)],h=(t,e)=>{const s=e.toLowerCase(),n=c(t).some(o=>m(o.options).includes(s));return{message:()=>`expected ${n?"no ":""}email to have been sent to ${e}`,pass:n}},u=(t,e)=>{const s=c(t).some(n=>typeof e=="string"?n.options.subject===e:e.test(n.options.subject));return{message:()=>`expected ${s?"no ":""}email to have been sent with subject ${String(e)}`,pass:s}},p=(t,e)=>{const s=c(t).some(n=>{const o=n.options.attachments??[];return e===void 0?o.length>0:o.some(r=>r.filename===e)});return{message:()=>`expected ${s?"no ":""}email to have been sent with attachment${e?` "${e}"`:""}`,pass:s}},b=(t,e)=>{const s=typeof e=="function"?e:o=>Object.entries(e).every(([r,a])=>o[r]===a),n=c(t).some(o=>s(o.options));return{message:()=>`expected ${n?"no ":""}email to have been sent matching the given condition`,pass:n}},g={toHaveSentMatching:b,toHaveSentTo:h,toHaveSentWithAttachment:p,toHaveSentWithSubject:u},v=t=>{t.extend(g)};export{g as emailMatchers,v as registerEmailMatchers,b as toHaveSentMatching,h as toHaveSentTo,p as toHaveSentWithAttachment,u as toHaveSentWithSubject};
@@ -0,0 +1,5 @@
1
+ const c=[/^On .*wrote:$/i,/^Am .*schrieb.*:$/i,/^Le .*a écrit ?:$/i,/^El .*escribió:$/i,/^.+\btarihinde\b.+yazdı:$/i],a=[/^-{2,}\s*Original Message\s*-{2,}/i,/^-{2,}\s*Forwarded message\s*-{2,}/i,/^_{5,}$/],l=/^--\s?$/,u=/^(?:from|von):\s/i,f=/^(?:to|an|cc|sent|gesendet|date|datum|subject|betreff|reply-to):\s/i,A=t=>t.startsWith(">")||a.some(r=>r.test(t))?!0:c.some(r=>r.test(t)),R=(t,r)=>{if(!u.test((t[r]??"").trim()))return!1;let n=0;for(let s=r+1;s<t.length&&n<3;s+=1){const e=t[s].trim();if(e!==""&&(n+=1,f.test(e)))return!0}return!1},p=(t,r={})=>{const{stripSignature:n=!0}=r,s=t.replaceAll(`\r
2
+ `,`
3
+ `).split(`
4
+ `),e=[];for(let i=0;i<s.length;i+=1){const o=s[i];if(A(o.trim())||R(s,i)||n&&l.test(o))break;e.push(o)}for(;e.length>0&&e[e.length-1].trim()==="";)e.pop();return e.join(`
5
+ `).trim()};export{p as extractReply};
@@ -0,0 +1 @@
1
+ import g from"./EmailError-BIaHK1Uw.js";import w from"./RequiredOptionError-ctDEEB1s.js";import{c as y}from"./create-logger-CazqtXcL.js";import{g as $}from"./generate-message-id-B2n2yqR6.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{a as A}from"./aggregate-features-Bst55u8k.js";const P=r=>typeof r=="function",z=r=>r!==null&&typeof r=="object"&&"sendEmail"in r&&"initialize"in r&&"isAvailable"in r,n="failover",x=E((r={})=>{if(!r.mailers||r.mailers.length===0)throw new w(n,"mailers");const c={debug:r.debug??!1,mailers:r.mailers,retryAfter:r.retryAfter??60};let v=!1;const i=[],s=y(n,r.logger);let m;const p=async()=>m||(m=(async()=>{i.length=0;for(const t of c.mailers)try{let e;if(P(t))e=t({});else if(z(t))e=t;else{s.debug(`Skipping invalid mailer: ${t}`);continue}try{await e.initialize(),i.push(e),s.debug(`Initialized provider: ${e.name??"unknown"}`)}catch(l){s.debug(`Failed to initialize provider ${e.name??"unknown"}:`,l)}}catch(e){s.debug("Error processing mailer:",e)}if(i.length===0)throw new g(n,"No providers could be initialized")})(),m);return{features:A(c.mailers),async initialize(){if(!v)try{await p(),v=!0,s.debug(`Failover provider initialized with ${i.length} provider(s)`)}catch(t){throw new g(n,`Failed to initialize: ${t.message}`,{cause:t})}},async isAvailable(){try{i.length===0&&await p();for(const t of i)try{if(await t.isAvailable())return!0}catch{}return!1}catch{return!1}},name:n,options:c,async sendEmail(t){try{if(i.length===0&&await p(),i.length===0)return{error:new g(n,"No providers available"),success:!1};const e=[];let l;for(let o=0;o<i.length;o+=1){const f=i[o];if(!f)continue;const d=f.name??`provider-${o+1}`;s.debug(`Attempting to send email via ${d} (${o+1}/${i.length})`);try{if(!await f.isAvailable()){s.debug(`Provider ${d} is not available, skipping`),e.push(new g(n,`Provider ${d} is not available`));continue}const a=await f.sendEmail(t);if(a.success&&a.data)return s.debug(`Email sent successfully via ${d}`),{data:{...a.data,messageId:a.data.messageId||$(),provider:`${n}(${d})`},success:!0};if(a.error){l=a.error,e.push(a.error);const b=a.error instanceof Error?a.error.message:String(a.error);s.debug(`Failed to send via ${d}:`,b)}}catch(u){l=u instanceof Error?u:new Error(String(u)),e.push(l);const a=l instanceof Error?l.message:String(l);s.debug(`Exception sending via ${d}:`,a)}o<i.length-1&&c.retryAfter>0&&(s.debug(`Waiting ${c.retryAfter}ms before trying next provider`),await new Promise(u=>{setTimeout(()=>{u()},c.retryAfter)}))}const h=e.map(o=>o instanceof Error?o.message:String(o)).join("; ");return{error:new g(n,`All providers failed. Errors: ${h}`,{cause:l}),success:!1}}catch(e){return{error:new g(n,`Failed to send email: ${e.message}`,{cause:e}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{x as default};
@@ -0,0 +1 @@
1
+ const l=/[\r\n<>]/,o=t=>{let r=t.replaceAll(/[\r\n\t]+/g," ");r=[...r].filter(i=>{const a=i.codePointAt(0);return a===void 0?!1:a>=32&&a<=126||a>159}).join("");const e="\\",n='"';return r=r.replaceAll(e,e+e).replaceAll(n,e+n),r.trim().replaceAll(/\s+/g," ")},s=t=>{if(l.test(t.email))throw new Error("Invalid email address for header formatting");if(t.name){const r=o(t.name);if(r)return`"${r}" <${t.email}>`}return t.email},c=t=>(Array.isArray(t)?t:[t]).map(e=>s(e)).join(", ");export{s as a,c as f,o as s};
@@ -1 +1 @@
1
- import{createRequire as t}from"node:module";let n;const i=r=>(n??=t(import.meta.url))(r),e=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,c=r=>{if(typeof e<"u"&&e.versions&&e.versions.node){const[o,s]=e.versions.node.split(".").map(Number);if(o>22||o===22&&s>=3||o===20&&s>=16)return e.getBuiltinModule(r)}return i(r)},{randomBytes:_}=c("node:crypto"),a=()=>`----_=_NextPart_${_(16).toString("hex")}`;export{a as r};
1
+ import{createRequire as t}from"node:module";let n;const i=r=>(n??=t(import.meta.url))(r),e=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,c=r=>{if(typeof e<"u"&&e.versions&&e.versions.node){const[o,s]=e.versions.node.split(".").map(Number);if(o>22||o===22&&s>=3||o===20&&s>=16)return e.getBuiltinModule(r)}return i(r)},{randomBytes:_}=c("node:crypto"),a=()=>`----_=_NextPart_${_(16).toString("hex")}`;export{a as g};
@@ -0,0 +1 @@
1
+ const o=()=>{const t="visulima.local",a=Date.now(),n=Math.random().toString(36).slice(2,10);return`<${a}.${n}@${t}>`};export{o as g};
@@ -0,0 +1 @@
1
+ const n=r=>{if(!(r instanceof Headers))return r;const o={};return r.forEach((c,e)=>{o[e]=c}),o};export{n as h};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import p from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-B2n2yqR6.js";import{m}from"./make-request-Cyz5_yu8.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as v}from"./defineProvider-C9q-7iwt.js";const o="http",A="POST",l=3e4,M=v((n={})=>{if(!n.endpoint)throw new p(o,"endpoint");const a={apiKey:n.apiKey??"",endpoint:n.endpoint,headers:n.headers??{},method:n.method??A},i=()=>{const e={"Content-Type":"application/json",...a.headers};return a.apiKey&&(e.Authorization=`Bearer ${a.apiKey}`),e},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(r=>r.email):e.to.email};return e.cc&&(t.cc=Array.isArray(e.cc)?e.cc.map(r=>r.email):e.cc.email),e.bcc&&(t.bcc=Array.isArray(e.bcc)?e.bcc.map(r=>r.email):e.bcc.email),e.customParams&&Object.assign(t,e.customParams),t};let u=!1;return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!u){if(!await this.isAvailable())throw new c(o,"API endpoint not available");u=!0}},async isAvailable(){try{const e=await m(a.endpoint,{headers:i(),method:"OPTIONS",timeout:l});if(e.success)return!0;const t=e.data?.statusCode;return!1}catch(e){if(e instanceof Error){const t=e.message;if(t.includes("401")||t.includes("403"))return!1}return!1}},name:o,options:a,async sendEmail(e){try{const t=E(e);if(t.length>0)return{error:new c(o,`Invalid email options: ${t.join(", ")}`),success:!1};u||await this.initialize();const r=i();e.headers&&Object.assign(r,e.headers);const y=h(e),g=e.endpointOverride??a.endpoint,b=e.methodOverride??a.method,d=await m(g,{headers:r,method:b,timeout:l},JSON.stringify(y));if(!d.success)return{error:new c(o,`Failed to send email: ${d.error?.message||"Unknown error"}`,{cause:d.error}),success:!1};let f;const s=d.data?.body;return s&&typeof s=="object"&&(f=s.id??s.messageId??(s.data&&typeof s.data=="object"&&(s.data.id??s.data.messageId))),f??=w(),{data:{messageId:f,provider:o,response:d.data?.body,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new c(o,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){try{const e=await m(a.endpoint,{headers:i(),method:"GET",timeout:l});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{M as default};
@@ -0,0 +1 @@
1
+ import{createRequire as k}from"node:module";let T;const C=e=>(T??=k(import.meta.url))(e),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,N=e=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[t,r]=m.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return m.getBuiltinModule(e)}return C(e)},{createRequire:x}=N("node:module"),S=/^[A-Z]:\//i,P=(e="")=>e&&e.replaceAll("\\","/").replace(S,t=>t.toUpperCase());let R;const M=e=>(R??=x(import.meta.url))(e),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,F=e=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[t,r]=u.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return u.getBuiltinModule(e)}return M(e)},{fileURLToPath:O}=F("node:url");function q(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var z,_;function U(){return _||(_=1,z=["3dm","3ds","3g2","3gp","7z","a","aac","adp","afdesign","afphoto","afpub","ai","aif","aiff","alz","ape","apk","appimage","ar","arj","asf","au","avi","bak","baml","bh","bin","bk","bmp","btif","bz2","bzip2","cab","caf","cgm","class","cmx","cpio","cr2","cr3","cur","dat","dcm","deb","dex","djvu","dll","dmg","dng","doc","docm","docx","dot","dotm","dra","DS_Store","dsk","dts","dtshd","dvb","dwg","dxf","ecelp4800","ecelp7470","ecelp9600","egg","eol","eot","epub","exe","f4v","fbs","fh","fla","flac","flatpak","fli","flv","fpx","fst","fvt","g3","gh","gif","graffle","gz","gzip","h261","h263","h264","icns","ico","ief","img","ipa","iso","jar","jpeg","jpg","jpgv","jpm","jxr","key","ktx","lha","lib","lvp","lz","lzh","lzma","lzo","m3u","m4a","m4v","mar","mdi","mht","mid","midi","mj2","mka","mkv","mmr","mng","mobi","mov","movie","mp3","mp4","mp4a","mpeg","mpg","mpga","mxu","nef","npx","numbers","nupkg","o","odp","ods","odt","oga","ogg","ogv","otf","ott","pages","pbm","pcx","pdb","pdf","pea","pgm","pic","png","pnm","pot","potm","potx","ppa","ppam","ppm","pps","ppsm","ppsx","ppt","pptm","pptx","psd","pya","pyc","pyo","pyv","qt","rar","ras","raw","resources","rgb","rip","rlc","rmf","rmvb","rpm","rtf","rz","s3m","s7z","scpt","sgi","shar","snap","sil","sketch","slk","smv","snk","so","stl","suo","sub","swf","tar","tbz","tbz2","tga","tgz","thmx","tif","tiff","tlz","ttc","ttf","txz","udf","uvh","uvi","uvm","uvp","uvs","uvu","viv","vob","war","wav","wax","wbmp","wdp","weba","webm","webp","whl","wim","wm","wma","wmv","wmx","woff","woff2","wrm","wvx","xbm","xif","xla","xlam","xls","xlsb","xlsm","xlsx","xlt","xltm","xltx","xm","xmind","xpi","xpm","xwd","xz","z","zip","zipx"]),z}var B=U();const D=q(B);new Set(D);const L=e=>P(e instanceof URL?O(e):e),A=e=>{if(!e||!(e instanceof URL)&&typeof e!="string")throw new TypeError("Path must be a non-empty string or URL.")};let W=class extends Error{constructor(t){super(`ENOENT: ${t}`)}get code(){return"ENOENT"}set code(t){throw new Error("Cannot overwrite code ENOENT")}get name(){return"NotFoundError"}set name(t){throw new Error("Cannot overwrite name of NotFoundError")}};class V extends Error{constructor(t){super(`EPERM: Operation not permitted, ${t}`)}get code(){return"EPERM"}set code(t){throw new Error("Cannot overwrite code EPERM")}get name(){return"PermissionError"}set name(t){throw new Error("Cannot overwrite name of PermissionError")}}const Z=(e,t)=>{const r=e?.code;return r==="ENOENT"?new W(`no such file or directory, open '${t}'`):r==="EACCES"||r==="EPERM"?new V(`unable to read the non-readable file: ${t}`):e};let G;const H=e=>(G??=x(import.meta.url))(e),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=e=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,r]=f.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return f.getBuiltinModule(e)}return H(e)},{readFile:I}=$("node:fs/promises"),{unzip:J,brotliDecompress:K}=$("node:zlib"),Q={brotli:K,gzip:J,none:(e,t)=>{t(null,e)}},ae=async(e,t)=>{A(e),e=L(e);const{buffer:r,compression:b,encoding:v,flag:l}=t??{};let p;try{p=await I(e,l?{flag:l}:{})}catch(c){throw Z(c,e)}return await new Promise((c,w)=>{Q[b??"none"](p,(g,o)=>{g?w(g):c(r?o:o.toString(v??"utf8"))})})};let X;const Y=e=>(X??=x(import.meta.url))(e),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=e=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[t,r]=d.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return d.getBuiltinModule(e)}return Y(e)},ee=y("fs"),te=y("os"),re=y("path");var h={},j;function oe(){if(j)return h;j=1;var e=Object.defineProperty,t=(o,s)=>e(o,"name",{value:s,configurable:!0}),r=ee,b=te,v=re;const l=t(o=>{let s="";for(let n=0;n<o.length;n+=1){const i=o[n],a=i.toUpperCase();s+=i===a?i.toLowerCase():a}return s},"invertCase"),p=new Map,c=t((o,s)=>{const n=v.join(o,`.is-fs-case-sensitive-test-${process.pid}`);try{return s.writeFileSync(n,""),!s.existsSync(l(n))}finally{try{s.unlinkSync(n)}catch{}}},"checkDirectoryCaseWithWrite"),w=t((o,s,n)=>{try{return c(o,n)}catch(i){if(s===void 0)return c(b.tmpdir(),n);throw i}},"checkDirectoryCaseWithFallback"),g=t((o,s=r,n=!0)=>{const i=o??process.cwd();if(n&&p.has(i))return p.get(i);let a;const E=l(i);return E!==i&&s.existsSync(i)?a=!s.existsSync(E):a=w(i,o,s),n&&p.set(i,a),a},"isFsCaseSensitive");return h.isFsCaseSensitive=g,h}var se=oe();se.isFsCaseSensitive;export{ae as z};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-BIaHK1Uw.js";import v from"./RequiredOptionError-ctDEEB1s.js";import{g as A}from"./generate-message-id-B2n2yqR6.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as u}from"./make-request-Cyz5_yu8.js";import{r as y}from"./retry-aghj7y8m.js";import{v as I}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as T,P,h}from"./provider-base-BEz00m9R.js";import{d as m}from"./address-formatter-CXZ1aWBX.js";import{p as U}from"./attachment-processor-BJFDS343.js";const t="infobip",R="https://api.infobip.com",z=3e4,k=3,V=w((i={})=>{if(!i.apiKey)throw new v(t,"apiKey");const f=i.baseUrl??R,g=i.endpoint??`${f}/email/3/send`,a={apiKey:i.apiKey,baseUrl:f,debug:i.debug??!1,endpoint:g,retries:i.retries??k,timeout:i.timeout??z,...i.logger&&{logger:i.logger}},l=new P,s=T(t,i.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 d(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const o={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const r=await y(async()=>u(`${a.baseUrl}/email/3/reports/${e}`,{headers:o,method:"GET",timeout:a.timeout}),a.retries);return r.success?(s.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(s.debug("API request failed when retrieving email",r.error),{error:new d(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,s),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(t,"Infobip API not available or invalid API key");s.debug("Provider initialized successfully")},t)},async isAvailable(){try{s.debug("Checking Infobip API availability");const e={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};return(await u(`${a.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:a.timeout})).success}catch(e){return s.debug("Error checking availability:",e),!1}},name:t,options:a,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new d(t,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateData=e.templateVariables)),e.trackingUrl&&(r.trackingUrl=e.trackingUrl),e.notifyUrl&&(r.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(r.intermediateReport=e.intermediateReport),e.sendAt&&(r.sendAt=e.sendAt),e.headers){const c=E(e.headers);r.headers=c}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async c=>({content:await U(c,t),contentType:c.contentType??"application/octet-stream",name:c.filename})))),s.debug("Sending email via Infobip API",{subject:r.subject,to:r.to});const b={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"},n=await y(async()=>u(a.endpoint,{headers:b,method:"POST",timeout:a.timeout},JSON.stringify(r)),a.retries);if(!n.success)return s.debug("API request failed when sending email",n.error),{error:n.error??new d(t,"Failed to send email"),success:!1};const p=n.data?.body?.messages?.[0]?.messageId??A();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:t,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
@@ -0,0 +1,3 @@
1
+ import{createRequire as g}from"node:module";import o from"./EmailError-BIaHK1Uw.js";let p;const d=e=>(p??=g(import.meta.url))(e),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[t,r]=s.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return s.getBuiltinModule(e)}return d(e)},{Buffer:S}=u("node:buffer"),{X509Certificate:m,createVerify:T}=u("node:crypto"),_={Notification:["Message","MessageId","Subject","Timestamp","TopicArn","Type"],SubscriptionConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"],UnsubscribeConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"]},y=/^sns\.[a-z0-9-]+\.amazonaws\.com(?:\.cn)?$/,b=/\.$/,h=e=>{let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:"||t.username!==""||t.password!==""||t.port!=="")return!1;const r=t.hostname.toLowerCase().replace(b,"");return y.test(r)},w=async e=>{if(!h(e))throw new o("webhooks",`Refusing to fetch SNS signing certificate from untrusted URL: ${e}`);const t=await fetch(e,{signal:AbortSignal.timeout(5e3)});if(!t.ok)throw new o("webhooks",`Failed to fetch SNS signing certificate (status ${String(t.status)})`);return await t.text()},v=e=>{const t=_[e.Type??""];if(!t)return;let r="";for(const i of t){const n=e[i];typeof n=="string"&&(r+=`${i}
2
+ ${n}
3
+ `)}return r},N=async(e,t={})=>{const{certificateResolver:r=w}=t;if(!e.Signature||!e.SigningCertURL)return{reason:"missing-signature",valid:!1};const i=v(e);if(i===void 0)return{reason:"unknown-message-type",valid:!1};let n;if(e.SignatureVersion==="1")n="RSA-SHA1";else if(e.SignatureVersion==="2")n="RSA-SHA256";else return{reason:"unknown-signature-version",valid:!1};const f=await r(e.SigningCertURL);let a;try{a=new m(f).publicKey}catch(l){throw new o("webhooks","Failed to parse SNS signing certificate",{cause:l})}let c;try{c=T(n).update(i,"utf8").verify(a,S.from(e.Signature,"base64"))}catch{return{reason:"signature-malformed",valid:!1}}return c?{valid:!0}:{reason:"signature-mismatch",valid:!1}};export{h as isValidSigningCertUrl,N as verifySnsMessage};
@@ -0,0 +1 @@
1
+ const a=e=>{const r=e.indexOf("@");if(r<=0)return"•••";const t=e.slice(0,r),s=e.slice(r+1);return`${t.slice(0,1)}${"•".repeat(Math.max(1,t.length-1))}@${s}`},c=(e,r)=>(Array.isArray(e)?e:[e]).map(s=>r?a(s.email):s.email),l=(e={})=>{const{logger:r=console,redact:t=!0}=e;return async(s,o)=>{const i=c(s.to,t);r.info("[@visulima/email] sending",{subject:t?void 0:s.subject,to:i});const n=await o(s);return n.success?r.info("[@visulima/email] sent",{messageId:n.data?.messageId,to:i}):r.error("[@visulima/email] send failed",{error:n.error instanceof Error?n.error.message:n.error,to:i}),n}};export{l as loggingMiddleware};
@@ -0,0 +1 @@
1
+ import n from"./EmailError-BIaHK1Uw.js";import f from"./RequiredOptionError-ctDEEB1s.js";import{g as y}from"./generate-message-id-B2n2yqR6.js";import{m as h}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{c as E,h as I,P as v}from"./provider-base-BEz00m9R.js";import{c as A}from"./attachment-processor-BJFDS343.js";const t="loops",w="https://app.loops.so/api/v1/transactional",b=3e4,P=3,U=T((r={})=>{if(!r.apiKey)throw new f(t,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,defaultTransactionalId:r.defaultTransactionalId,endpoint:r.endpoint??w,logger:r.logger,retries:r.retries??P,timeout:r.timeout??b},u=new v,p=E(t,r.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!1,html:!1,replyTo:!1,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){u.setInitialized()},async isAvailable(){return a.apiKey.length>0},name:t,options:a,async sendEmail(e){try{const s=e.transactionalId??a.defaultTransactionalId;if(!s)return{error:new n(t,"Loops requires a `transactionalId` (on the message or as `defaultTransactionalId`)"),success:!1};const d=Array.isArray(e.to)?e.to:[e.to];if(d.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new n(t,"Loops supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[l]=d;if(!l)return{error:new n(t,"A `to` recipient is required"),success:!1};const o={email:l.email,transactionalId:s};e.dataVariables&&(o.dataVariables=e.dataVariables),e.addToAudience&&(o.addToAudience=!0),e.attachments&&e.attachments.length>0&&(o.attachments=await Promise.all(e.attachments.map(async m=>{const c=await A(m,t);return{contentType:c.contentType,data:c.content,filename:c.filename}})));const i=await g(async()=>h(a.endpoint,{headers:{Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:a.timeout},JSON.stringify(o)),a.retries);return i.success?{data:{messageId:y(),provider:t,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new n(t,"Failed to send email"),success:!1}}catch(s){return{error:I(t,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
@@ -1,9 +1,8 @@
1
1
  import { ICalCalendar } from 'ical-generator';
2
2
  import { Buffer as Buffer$1 } from 'node:buffer';
3
- import 'node:crypto';
3
+ import { T as TemplateRenderer } from "./types.d-I-KeZ5w2.js";
4
4
  import { c as EmailAddress, e as EmailHeaders, P as Priority, C as CalendarEventOptions, E as EmailOptions, A as Attachment, M as MaybePromise, a as EmailResult, R as Result, b as Receipt } from "./types.d-B9295M4_.js";
5
5
  import { E as EmailSigner, a as EmailEncrypter } from "./types.d-B0t3PQ3t.js";
6
- import { T as TemplateRenderer } from "./types.d-I-KeZ5w2.js";
7
6
  import { M as Middleware } from "./types.d-GKqPNk0I.js";
8
7
  import { a as Provider } from "./provider.d-Cx5YQJdP.js";
9
8
  /**
@@ -0,0 +1 @@
1
+ import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import o from"./smtpProvider-Dr2XAFQu.js";const a="mailcrab",u="localhost",n=1025,m=l((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},r=o({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 r.initialize()},async isAvailable(){return r.isAvailable()},name:a,options:e,async sendEmail(i){const s=await r.sendEmail(i);return s.success&&s.data?{data:{...s.data,provider:a},success:!0}:s},async validateCredentials(){return r.validateCredentials?.()??!1}}});export{m as default};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import T from"./RequiredOptionError-ctDEEB1s.js";import{g as P}from"./generate-message-id-B2n2yqR6.js";import{h as w}from"./headers-to-record-ZOZ7Dubo.js";import{m as u}from"./make-request-Cyz5_yu8.js";import{r as h}from"./retry-aghj7y8m.js";import{s as I,a as A}from"./sanitize-header-CW0f3IT7.js";import{v as k}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{c as j,P as C,h as g}from"./provider-base-BEz00m9R.js";import{j as l,g as b}from"./address-formatter-CXZ1aWBX.js";const a="mailpace",R="https://app.mailpace.com/api/v1",$=3e4,M=3,G=z((o={})=>{if(!o.apiToken)throw new T(a,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??R,retries:o.retries??M,timeout:o.timeout??$,...o.logger&&{logger:o.logger}},d=new C,i=j(a,o.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(a,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const t={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await h(async()=>u(`${s.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new c(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:g(a,"retrieve email",t,i),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const t=await u(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace 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 i.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=k(e);if(t.length>0)return{error:new c(a,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const r={from:b(e.from),subject:e.subject,to:l(e.to)};if(e.html&&(r.htmlbody=e.html),e.text&&(r.textbody=e.text),e.cc&&(r.cc=l(e.cc)),e.bcc&&(r.bcc=l(e.bcc)),e.replyTo&&(r.replyto=b(e.replyTo)),e.templateId&&(r.template_id=e.templateId,e.templateVariables&&(r.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.listUnsubscribe&&(r.list_unsubscribe=e.listUnsubscribe),e.headers){const y=w(e.headers),f={};Object.entries(y).forEach(([v,E])=>{f[I(v)]=A(E)}),r.headers=f}e.attachments&&e.attachments.length>0&&(r.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:r.subject,to:r.to});const p={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},n=await h(async()=>u(`${s.endpoint}/send`,{headers:p,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new c(a,"Failed to send email"),success:!1};const m=n.data?.body?.id??P();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:a,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:g(a,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
@@ -0,0 +1 @@
1
+ import u from"./EmailError-BIaHK1Uw.js";import g from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-B2n2yqR6.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as T}from"./make-request-Cyz5_yu8.js";import{r as b}from"./retry-aghj7y8m.js";import{v as A}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{c as w,h as I,P as S}from"./provider-base-BEz00m9R.js";import{f as l,a as f}from"./address-formatter-CXZ1aWBX.js";import{c as K}from"./attachment-processor-BJFDS343.js";const r="mailchannels",R="https://api.mailchannels.net/tx/v1/send",_=3e4,x=3,H=P((t={})=>{if(!t.apiKey)throw new g(r,"apiKey");const a={apiKey:t.apiKey,debug:t.debug??!1,endpoint:t.endpoint??R,logger:t.logger,retries:t.retries??x,timeout:t.timeout??_},h=new S,p=w(r,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){h.setInitialized()},async isAvailable(){return a.apiKey.length>0},name:r,options:a,async sendEmail(e){try{const s=A(e);if(s.length>0)return{error:new u(r,`Invalid email options: ${s.join(", ")}`),success:!1};const c=[];e.text&&c.push({type:"text/plain",value:e.text}),e.html&&c.push({type:"text/html",value:e.html});const i={to:l(e.to)};e.cc&&(i.cc=l(e.cc)),e.bcc&&(i.bcc=l(e.bcc));const n={content:c,from:f(e.from),personalizations:[i],subject:e.subject};e.replyTo&&(n.reply_to=f(e.replyTo)),e.headers&&(n.headers=E(e.headers)),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async y=>{const d=await K(y,r);return{content:d.content,filename:d.filename,type:d.contentType}})));const o=await b(async()=>T(a.endpoint,{headers:{"Content-Type":"application/json","X-Api-Key":a.apiKey},method:"POST",timeout:a.timeout},JSON.stringify(n)),a.retries);if(!o.success)return{error:o.error??new u(r,"Failed to send email"),success:!1};const{body:m}=o.data;return{data:{messageId:m?.message_id??m?.request_id??v(),provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:I(r,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import p from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-B2n2yqR6.js";import{h as b}from"./headers-to-record-ZOZ7Dubo.js";import{m as l}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{c as w,P as A,h}from"./provider-base-BEz00m9R.js";import{f as m,a as I}from"./address-formatter-CXZ1aWBX.js";import{p as P}from"./attachment-processor-BJFDS343.js";const a="mailersend",k="https://api.mailersend.com",z=3e4,S=3,L=E((i={})=>{if(!i.apiToken)throw new p(a,"apiToken");const s={apiToken:i.apiToken,debug:i.debug??!1,endpoint:i.endpoint??k,retries:i.retries??S,timeout:i.timeout??z,...i.logger&&{logger:i.logger}},u=new A,o=w(a,i.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 c(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const r=await g(async()=>l(`${s.endpoint}/v1/activity/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(o.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(o.debug("API request failed when retrieving email",r.error),{error:new c(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:h(a,"retrieve email",t,o),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"MailerSend API not available or invalid API token");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};o.debug("Checking MailerSend API availability");const t=await l(`${s.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:s.timeout});return o.debug("MailerSend 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 o.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new c(a,`Invalid email options: ${t.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.reply_to=I(e.replyTo)),e.templateId&&(r.template_id=e.templateId,e.templateVariables&&(r.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(r.personalization=e.personalization),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.scheduledAt&&(r.send_at=e.scheduledAt),e.domainId&&(r.domain_id=e.domainId),e.headers){const n=b(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,a),filename:n.filename,...n.contentType&&{type:n.contentType},...n.cid&&{id:n.cid}})))),o.debug("Sending email via MailerSend API",{subject:r.subject,to:r.to});const y={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},d=await g(async()=>l(`${s.endpoint}/v1/email`,{headers:y,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!d.success)return o.debug("API request failed when sending email",d.error),{error:d.error??new c(a,"Failed to send email"),success:!1};const f=d.data?.body?.message_id??v();return o.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:h(a,"send email",t,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
@@ -0,0 +1 @@
1
+ import{createRequire as j}from"node:module";import f from"./EmailError-BIaHK1Uw.js";import w from"./RequiredOptionError-ctDEEB1s.js";import{g as P}from"./generate-message-id-B2n2yqR6.js";import{h as _}from"./headers-to-record-ZOZ7Dubo.js";import{m as p}from"./make-request-Cyz5_yu8.js";import{r as I}from"./retry-aghj7y8m.js";import{v as C}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as D}from"./defineProvider-C9q-7iwt.js";import{c as S,P as U,h as k}from"./provider-base-BEz00m9R.js";import{e as v,g as E}from"./address-formatter-CXZ1aWBX.js";import{a as q}from"./attachment-processor-BJFDS343.js";let $;const A=o=>($??=j(import.meta.url))(o),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,n]=m.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return m.getBuiltinModule(o)}return A(o)},{Buffer:y}=R("node:buffer"),s="mailgun",M="https://api.mailgun.net",z=3e4,B=3,K=o=>{const r=[];for(const[n,a]of Object.entries(o))if(a!=null)if(Array.isArray(a))for(const e of a)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof a=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(a))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(a))}`);return r.join("&")},O=D((o={})=>{if(!o.apiKey)throw new w(s,"apiKey");if(!o.domain)throw new w(s,"domain");const r={apiKey:o.apiKey,debug:o.debug??!1,domain:o.domain,endpoint:o.endpoint??M,retries:o.retries??B,timeout:o.timeout??z,...o.logger&&{logger:o.logger}},n=new U,a=S(s,o.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 f(s,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};a.debug("Retrieving email details",{id:e});const i=await I(async()=>p(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);if(!i.success)return a.debug("API request failed when retrieving email",i.error),{error:new f(s,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1};a.debug("Email details retrieved successfully");const g=i.data?.items??[],u=g.length>0?g[0]:void 0;return{data:u?.message?.headers??u?.storage??void 0,success:!0}}catch(c){return{error:k(s,"retrieve email",c,a),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new f(s,"Mailgun API not available or invalid API key/domain");a.debug("Provider initialized successfully")},s)},async isAvailable(){try{const c={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};a.debug("Checking Mailgun API availability");const t=await p(`${r.endpoint}/v3/domains/${r.domain}`,{headers:c,method:"GET",timeout:r.timeout});if(a.debug("Mailgun 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")return!1;const{statusCode:i}=t.data;return typeof i=="number"&&i>=200&&i<300}catch(e){return a.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const c=C(e);if(c.length>0)return{error:new f(s,`Invalid email options: ${c.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={from:E(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"]=E(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[l,d]of Object.entries(e.templateVariables))t[`v:${l}`]=d;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 l=_(e.headers);for(const[d,h]of Object.entries(l))t[`h:${d}`]=h}if(e.attachments&&e.attachments.length>0){const l=await Promise.all(e.attachments.map((d,h)=>q(d,s,h)));for(const d of l)t[d.key]=d.content}a.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const b={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=K(t),u=await I(async()=>p(`${r.endpoint}/v3/${r.domain}/messages`,{headers:b,method:"POST",timeout:r.timeout},g),r.retries);if(!u.success)return a.debug("API request failed when sending email",u.error),{error:u.error??new f(s,"Failed to send email"),success:!1};const T=u.data?.body?.id??P();return a.debug("Email sent successfully",{messageId:T}),{data:{messageId:T,provider:s,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:k(s,"send email",c,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
@@ -0,0 +1 @@
1
+ import{createRequire as S}from"node:module";import g from"./EmailError-BIaHK1Uw.js";import v from"./RequiredOptionError-ctDEEB1s.js";import{g as _}from"./generate-message-id-B2n2yqR6.js";import{h as R}from"./headers-to-record-ZOZ7Dubo.js";import{m as p}from"./make-request-Cyz5_yu8.js";import{r as b}from"./retry-aghj7y8m.js";import{v as M}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as $}from"./defineProvider-C9q-7iwt.js";import{c as D,P as B,h as T}from"./provider-base-BEz00m9R.js";import{h as y,i as E}from"./address-formatter-CXZ1aWBX.js";import{p as z}from"./attachment-processor-BJFDS343.js";let P;const C=a=>(P??=S(import.meta.url))(a),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,A=a=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[r,u]=l.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return l.getBuiltinModule(a)}return C(a)},{Buffer:f}=A("node:buffer"),s="mailjet",q="https://api.mailjet.com",L=3e4,k=3,O=$((a={})=>{if(!a.apiKey)throw new v(s,"apiKey");if(!a.apiSecret)throw new v(s,"apiSecret");const r={apiKey:a.apiKey,apiSecret:a.apiSecret,debug:a.debug??!1,endpoint:a.endpoint??q,retries:a.retries??k,timeout:a.timeout??L,...a.logger&&{logger:a.logger}},u=new B,i=D(s,a.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 g(s,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const n=await b(async()=>p(`${r.endpoint}/v3.1/REST/message/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return n.success?(i.debug("Email details retrieved successfully"),{data:n.data?.body,success:!0}):(i.debug("API request failed when retrieving email",n.error),{error:new g(s,`Failed to retrieve email: ${n.error instanceof Error?n.error.message:"Unknown error"}`,{cause:n.error}),success:!1})}catch(o){return{error:T(s,"retrieve email",o,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new g(s,"Mailjet API not available or invalid API credentials");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{const o={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Checking Mailjet API availability");const t=await p(`${r.endpoint}/v3.1/REST/user`,{headers:o,method:"GET",timeout:r.timeout});return i.debug("Mailjet 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 i.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=M(e);if(o.length>0)return{error:new g(s,`Invalid email options: ${o.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const t={From:E(e.from),Subject:e.subject,To:y(e.to)};if(e.html&&(t.HTMLPart=e.html),e.text&&(t.TextPart=e.text),e.cc&&(t.Cc=y(e.cc)),e.bcc&&(t.Bcc=y(e.bcc)),e.replyTo&&(t.ReplyTo=E(e.replyTo)),e.templateId&&(t.TemplateID=e.templateId,t.TemplateLanguage=e.templateLanguage??!0,e.templateVariables&&(t.Variables=e.templateVariables)),e.customId&&(t.CustomID=e.customId),e.eventPayload&&(t.EventPayload=e.eventPayload),e.campaign&&(t.Campaign=e.campaign),e.deduplicateCampaign!==void 0&&(t.DeduplicateCampaign=e.deduplicateCampaign),e.deliveryTime&&(t.Deliverytime=new Date(e.deliveryTime*1e3).toISOString()),e.priority!==void 0&&(t.Priority=e.priority),e.urlTags&&(t.URLTags=e.urlTags),e.tags&&e.tags.length>0&&(t.CustomCampaign=e.tags.join(",")),e.headers){const c=R(e.headers),m=[];for(const[j,w]of Object.entries(c))m.push({Name:j,Value:String(w)});m.length>0&&(t.Headers=m)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async c=>({Base64Content:await z(c,s),ContentType:c.contentType??"application/octet-stream",Filename:c.filename,...c.cid&&{ContentID:c.cid}}))));const n={Messages:[t]};i.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const I={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},d=await b(async()=>p(`${r.endpoint}/v3.1/send`,{headers:I,method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);if(!d.success)return i.debug("API request failed when sending email",d.error),{error:d.error??new g(s,"Failed to send email"),success:!1};const h=d.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??_();return i.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:T(s,"send email",o,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-BIaHK1Uw.js";import b from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-B2n2yqR6.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as g}from"./make-request-Cyz5_yu8.js";import{r as y}from"./retry-aghj7y8m.js";import{v as I}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as P,P as A,h}from"./provider-base-BEz00m9R.js";import{f as u,a as T}from"./address-formatter-CXZ1aWBX.js";import{p as R}from"./attachment-processor-BJFDS343.js";const t="mailomat",S="https://api.mailomat.com",K=3e4,j=3,V=w((s={})=>{if(!s.apiKey)throw new b(t,"apiKey");const i={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??S,retries:s.retries??j,timeout:s.timeout??K,...s.logger&&{logger:s.logger}},l=new A,a=P(t,s.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 d(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const o={"Content-Type":"application/json","X-API-Key":i.apiKey};a.debug("Retrieving email details",{id:e});const r=await y(async()=>g(`${i.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:i.timeout}),i.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 d(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,a),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(t,"Mailomat API not available or invalid API key");a.debug("Provider initialized successfully")},t)},async isAvailable(){try{return a.debug("Checking Mailomat API availability"),!0}catch(e){return a.debug("Error checking availability:",e),!1}},name:t,options:i,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new d(t,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=u(e.cc)),e.bcc&&(r.bcc=u(e.bcc)),e.replyTo&&(r.replyTo=T(e.replyTo)),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.headers){const n=E(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await R(n,t),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),a.debug("Sending email via Mailomat API",{subject:r.subject,to:r.to});const p={"Content-Type":"application/json","X-API-Key":i.apiKey},c=await y(async()=>g(`${i.endpoint}/send`,{headers:p,method:"POST",timeout:i.timeout},JSON.stringify(r)),i.retries);if(!c.success)return a.debug("API request failed when sending email",c.error),{error:c.error??new d(t,"Failed to send email"),success:!1};const m=c.data?.body,f=m?.messageId??m?.id??v();return a.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:t,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-BIaHK1Uw.js";import y from"./RequiredOptionError-ctDEEB1s.js";import{g as b}from"./generate-message-id-B2n2yqR6.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{m as l}from"./make-request-Cyz5_yu8.js";import{r as p}from"./retry-aghj7y8m.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{c as w,P as A,h as g}from"./provider-base-BEz00m9R.js";import{f as m,a as I}from"./address-formatter-CXZ1aWBX.js";import{p as P}from"./attachment-processor-BJFDS343.js";const a="mailtrap",k="https://send.api.mailtrap.io",C=3e4,j=3,L=E((o={})=>{if(!o.apiToken)throw new y(a,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??k,retries:o.retries??j,timeout:o.timeout??C,...o.logger&&{logger:o.logger}},u=new A,i=w(a,o.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 d(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={"Api-Token":s.apiToken,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await p(async()=>l(`${s.endpoint}/api/send/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new d(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:g(a,"retrieve email",t,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(a,"Mailtrap API not available or invalid API token");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Api-Token":s.apiToken,"Content-Type":"application/json"};i.debug("Checking Mailtrap API availability");const t=await l(`${s.endpoint}/api/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("Mailtrap 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 i.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new d(a,`Invalid email options: ${t.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.reply_to=I(e.replyTo)),e.templateUuid&&(r.template_uuid=e.templateUuid,e.templateVariables&&(r.template_variables=e.templateVariables)),e.category&&(r.category=e.category),e.customVariables&&(r.custom_variables=e.customVariables),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.headers){const n=v(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,a),filename:n.filename,type:n.contentType??"application/octet-stream",...n.cid&&{cid:n.cid}})))),i.debug("Sending email via Mailtrap API",{subject:r.subject,to:r.to});const h={"Api-Token":s.apiToken,"Content-Type":"application/json"},c=await p(async()=>l(`${s.endpoint}/api/send`,{headers:h,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new d(a,"Failed to send email"),success:!1};const f=c.data?.body?.message_ids?.[0]??b();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:g(a,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
@@ -0,0 +1 @@
1
+ import f from"./EmailError-BIaHK1Uw.js";const w=globalThis.Buffer!==void 0,T="ETIMEDOUT",g=async(i,s={},t)=>{const d=typeof i=="string"?new URL(i):i;try{const r=new Headers;s.headers&&Object.entries(s.headers).forEach(([e,u])=>{r.set(e,u)});const o={headers:r,method:s.method??(t?"POST":"GET")};t&&(typeof t=="string"||t instanceof Uint8Array?o.body=t:w&&t instanceof globalThis.Buffer?o.body=new Uint8Array(t):o.body=new Uint8Array(t));let a,n;s.timeout&&(a=new AbortController,n=setTimeout(()=>{a?.abort()},s.timeout),o.signal=a.signal);try{const e=await fetch(d.toString(),o);n&&clearTimeout(n);const m=(e.headers.get("content-type")??"").includes("application/json");let c;if(m)try{c=await e.json()}catch{c=await e.text()}else c=await e.text();const l=e.status>=200&&e.status<300,h={};return e.headers.forEach((y,E)=>{h[E]=y}),{data:{body:c,headers:h,statusCode:e.status},error:l?void 0:new f("http",`Request failed with status ${e.status}`,{code:e.status.toString()}),success:l}}catch(e){if(n&&clearTimeout(n),e instanceof Error&&e.name==="AbortError")return{error:new f("http",`Request timed out after ${s.timeout}ms`,{code:T}),success:!1};throw e}}catch(r){return{error:new f("http",`Request failed: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))}),success:!1}}};export{T as R,g as m};
@@ -0,0 +1 @@
1
+ import u from"./EmailError-BIaHK1Uw.js";import T from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-B2n2yqR6.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m as g}from"./make-request-Cyz5_yu8.js";import{r as h}from"./retry-aghj7y8m.js";import{a as b,s as I}from"./sanitize-header-CW0f3IT7.js";import{v as _}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import{c as j,P as k,h as p}from"./provider-base-BEz00m9R.js";import{k as y}from"./address-formatter-CXZ1aWBX.js";import{p as S}from"./attachment-processor-BJFDS343.js";const t="mandrill",z="https://mandrillapp.com/api/1.0",M=3e4,R=3,G=C((i={})=>{if(!i.apiKey)throw new T(t,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??z,retries:i.retries??R,timeout:i.timeout??M,...i.logger&&{logger:i.logger}},m=new k,o=j(t,i.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 u(t,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),t),o.debug("Retrieving email details",{id:e});const c={id:e,key:s.apiKey},r={"Content-Type":"application/json"},n=await h(async()=>g(`${s.endpoint}/messages/info.json`,{headers:r,method:"POST",timeout:s.timeout},JSON.stringify(c)),s.retries);return n.success?(o.debug("Email details retrieved successfully"),{data:n.data?.body,success:!0}):(o.debug("API request failed when retrieving email",n.error),{error:new u(t,`Failed to retrieve email: ${n.error instanceof Error?n.error.message:"Unknown error"}`,{cause:n.error}),success:!1})}catch(c){return{error:p(t,"retrieve email",c,o),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(t,"Mandrill API not available or invalid API key");o.debug("Provider initialized successfully")},t)},async isAvailable(){try{o.debug("Checking Mandrill API availability");const e={key:s.apiKey},c={"Content-Type":"application/json"},r=await g(`${s.endpoint}/users/info.json`,{headers:c,method:"POST",timeout:s.timeout},JSON.stringify(e));return o.debug("Mandrill 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 o.debug("Error checking availability:",e),!1}},name:t,options:s,async sendEmail(e){try{const c=_(e);if(c.length>0)return{error:new u(t,`Invalid email options: ${c.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),t);const r={from_email:e.from.email,html:e.html??"",subject:e.subject,text:e.text??"",...e.from.name&&{from_name:e.from.name},to:y(e.to,"to")};if(e.cc){const a=y(e.cc,"cc");for(const d of a)d.type="cc";r.to=[...r.to,...a]}if(e.bcc){const a=y(e.bcc,"bcc");for(const d of a)d.type="bcc";r.to=[...r.to,...a]}if(e.replyTo){const a=e.replyTo.name?`${b(e.replyTo.name)} <${e.replyTo.email}>`:e.replyTo.email;r.headers={"Reply-To":a}}if(e.headers){const a=P(e.headers),d={};Object.entries(a).forEach(([A,E])=>{d[I(A)]=b(E)}),r.headers={...r.headers,...d}}e.tags&&e.tags.length>0&&(r.tags=e.tags),e.metadata&&(r.metadata=e.metadata),(e.googleAnalyticsDomains||e.googleAnalyticsCampaign)&&(r.google_analytics_domains=e.googleAnalyticsDomains,r.google_analytics_campaign=e.googleAnalyticsCampaign),e.subaccount&&(r.subaccount=e.subaccount),e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async a=>({content:await S(a,t),name:a.filename,type:a.contentType??"application/octet-stream"}))));const n={key:s.apiKey,message:r};e.templateName&&(n.template_name=e.templateName,e.templateContent&&(n.template_content=e.templateContent),e.templateVariables&&(n.template_vars=e.templateVariables)),e.globalMergeVars&&(r.global_merge_vars=e.globalMergeVars),e.mergeVars&&(r.merge_vars=e.mergeVars),e.sendAt&&(n.send_at=e.sendAt),o.debug("Sending email via Mandrill API",{subject:r.subject,to:r.to});const v={"Content-Type":"application/json"},l=await h(async()=>g(`${s.endpoint}/messages/send.json`,{headers:v,method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new u(t,"Failed to send email"),success:!1};const f=l.data?.body?.[0]?.id??w();return o.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:t,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:p(t,"send email",c,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-BIaHK1Uw.js";import{c as I}from"./create-logger-CazqtXcL.js";import{g as D}from"./generate-message-id-B2n2yqR6.js";import{v as A}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as x}from"./defineProvider-C9q-7iwt.js";const i="mock",p=new Map,M=()=>({debug:!1,delay:0,failureRate:0,randomDelayRange:{max:0,min:0},retries:0,simulateFailure:!1,timeout:0}),j=x((f={})=>{const g=`mock-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;p.has(g)||p.set(g,[]);const r=p.get(g);if(!r)throw new Error(`Storage not found for instance: ${g}`);let y=!1,m;const s={...M(),defaultResponse:f.defaultResponse,logger:f.logger,randomDelayRange:f.randomDelayRange??{max:0,min:0},...f},a=I(i,s.logger);return{clearSentMessages(){r.length=0,a.debug("Cleared all sent messages")},features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!1,tracking:!1},findMessageBy(e){return r.find(t=>e(t))},findMessagesBy(e){return r.filter(t=>e(t))},async getEmail(e){try{if(!e)return{error:new d(i,"Email ID is required to retrieve email details"),success:!1};const t=r.find(o=>o.id===e);return t?(a.debug("Retrieved email",{id:e}),{data:t,success:!0}):{error:new d(i,`Email with ID ${e} not found`),success:!1}}catch(t){return a.debug("Exception retrieving email",t),{error:new d(i,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},getInstance(){return r},getLastSentMessage(){return r.at(-1)},getMessagesBySubject(e){return r.filter(t=>t.options.subject===e)},getMessagesTo(e){return r.filter(t=>{const o=Array.isArray(t.options.to)?t.options.to:[t.options.to];let l=[];t.options.cc&&(l=Array.isArray(t.options.cc)?t.options.cc:[t.options.cc]);let u=[];return t.options.bcc&&(u=Array.isArray(t.options.bcc)?t.options.bcc:[t.options.bcc]),[...o,...l,...u].some(R=>R.email===e)})},getSentEmails(){return[...r]},getSentMessages(){return[...r]},getSentMessagesCount(){return r.length},async initialize(){y||(s.delay>0&&await new Promise(e=>{setTimeout(e,s.delay)}),y=!0,a.debug("Mock provider initialized"))},async isAvailable(){return!0},name:i,options:s,reset(){r.length=0,m=void 0;const e=M();s.debug=e.debug,s.delay=e.delay,s.failureRate=e.failureRate,s.retries=e.retries,s.simulateFailure=e.simulateFailure,s.timeout=e.timeout,s.randomDelayRange={max:0,min:0},s.defaultResponse=void 0,a.debug("Mock provider reset to initial state")},async sendEmail(e){try{const t=A(e);if(t.length>0)return{error:new d(i,`Invalid email options: ${t.join(", ")}`),success:!1};y||await this.initialize();let o=s.delay;if(s.randomDelayRange&&s.randomDelayRange.max>0){const{max:n,min:c}=s.randomDelayRange;o=Math.floor(Math.random()*(n-c+1))+c}if(o>0&&await new Promise(n=>{setTimeout(n,o)}),m!==void 0){const n=m;if(m=void 0,!n.successful)return a.debug("Using next response (failure)",n),{error:new d(i,n.errorMessages.join(", ")),success:!1};const c=n.messageId||D(),b=n.timestamp||new Date,v={messageId:c,provider:n.provider??i,response:n.response,sent:!0,timestamp:b},S={id:c,options:e,result:v,timestamp:b};return r.push(S),a.debug("Email stored using next response",{messageId:c}),{data:v,success:!0}}if(s.simulateFailure||s.failureRate>0&&Math.random()<s.failureRate)return a.debug("Simulating email send failure"),{error:new d(i,"Simulated failure"),success:!1};const u=s.defaultResponse?.successful?s.defaultResponse.messageId:D(),w=s.defaultResponse?.successful&&s.defaultResponse.timestamp?s.defaultResponse.timestamp:new Date,R=s.defaultResponse&&"response"in s.defaultResponse?s.defaultResponse.response:void 0,h={messageId:u,provider:i,response:R??{mock:!0,stored:!0},sent:!0,timestamp:w},E={id:u,options:e,result:h,timestamp:w};return r.push(E),a.debug("Email stored in mock provider",{messageId:u,subject:e.subject,to:Array.isArray(e.to)?e.to.map(n=>n.email):e.to.email}),{data:h,success:!0}}catch(t){return a.debug("Exception sending email",t),{error:new d(i,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},setDefaultResponse(e){s.defaultResponse=e,a.debug("Set default response",{receipt:e})},setDelay(e){if(e<0)throw new RangeError("Delay must be non-negative");s.delay=e,s.randomDelayRange={max:0,min:0},a.debug("Set fixed delay",{milliseconds:e})},setFailureRate(e){if(e<0||e>1)throw new RangeError("Failure rate must be between 0.0 and 1.0");s.failureRate=e,a.debug("Set failure rate",{rate:e})},setNextResponse(e){m=e,a.debug("Set next response",{receipt:e})},setRandomDelay(e,t){if(e<0||t<0||e>t)throw new RangeError("Invalid delay range");s.delay=0,s.randomDelayRange={max:t,min:e},a.debug("Set random delay range",{max:t,min:e})},async shutdown(){r.length=0,p.delete(g),a.debug("Mock provider shutdown")},async validateCredentials(){return!0},async waitForMessage(e,t=5e3){const o=Date.now();for(;;){const l=r.find(u=>e(u));if(l)return l;if(Date.now()-o>t)throw new Error("Timeout waiting for message");await new Promise(u=>{setTimeout(u,10)})}},async waitForMessageCount(e,t=5e3){const o=Date.now();for(;r.length<e;){if(Date.now()-o>t)throw new Error(`Timeout waiting for ${e} messages (got ${r.length})`);await new Promise(l=>{setTimeout(l,10)})}}}});export{j as default};
@@ -0,0 +1 @@
1
+ import m from"./EmailError-BIaHK1Uw.js";import y from"./RequiredOptionError-ctDEEB1s.js";import{g}from"./generate-message-id-B2n2yqR6.js";import{m as v}from"./make-request-Cyz5_yu8.js";import{r as E}from"./retry-aghj7y8m.js";import{v as b}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as I,P,h as T}from"./provider-base-BEz00m9R.js";import{a as d}from"./address-formatter-CXZ1aWBX.js";import{c as A}from"./attachment-processor-BJFDS343.js";const r="netcore",_="https://emailapi.netcorecloud.net/v5.1",D=3e4,S=3,l=a=>[a].flat(),q=w((a={})=>{if(!a.apiKey)throw new y(r,"apiKey");const s={apiKey:a.apiKey,debug:a.debug??!1,endpoint:a.endpoint??_,logger:a.logger,retries:a.retries??S,timeout:a.timeout??D},u=new P,p=I(r,a.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(r,"Netcore API not available or invalid API key");p.debug("Provider initialized successfully")},r)},async isAvailable(){return s.apiKey.length>0},name:r,options:s,async sendEmail(e){try{const o=b(e);if(o.length>0)return{error:new m(r,`Invalid email options: ${o.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),r);const i={to:l(e.to).map(t=>d(t))};e.cc&&(i.cc=l(e.cc).map(t=>d(t))),e.bcc&&(i.bcc=l(e.bcc).map(t=>d(t)));const n={from:d(e.from),personalizations:[i],subject:e.subject};if(e.templateId)n.template_id=e.templateId,e.templateData&&(i.attributes=e.templateData);else{const t=[];e.html&&t.push({type:"html",value:e.html}),e.text&&t.push({type:"plain",value:e.text}),t.length>0&&(n.content=t)}if(e.replyTo){const t=l(e.replyTo)[0];t&&(n.reply_to=t.email)}e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async t=>{const h=await A(t,r);return{content:h.content,name:h.filename}})));const c=await E(async()=>v(`${s.endpoint}/mail/send`,{headers:{api_key:s.apiKey,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);if(!c.success)return{error:c.error??new m(r,"Failed to send email"),success:!1};const{body:f}=c.data;return{data:{messageId:f?.data?.message_id??f?.message_id??g(),provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:T(r,"send email",o,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{q as default};
@@ -0,0 +1 @@
1
+ import p from"nodemailer";import l from"./EmailError-BIaHK1Uw.js";import w from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-B2n2yqR6.js";import{h as g}from"./headers-to-record-ZOZ7Dubo.js";import{v as h}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";const s="nodemailer",x=T((c={})=>{if(!c.transport)throw new w(s,"transport");let o;const f=r=>{const a=r??c.transport;return p.createTransport(a)};let d=!1;const y=async()=>{if(!d)try{o=f(),await o.verify(),d=!0}catch(r){throw new l(s,`Failed to initialize nodemailer transport: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))})}},m=r=>{const a=e=>e.name?`${e.name} <${e.email}>`:e.email,t=e=>e.name?`${e.name} <${e.email}>`:e.email,u=c.defaultFrom??r.from,n={from:a(u),subject:r.subject,to:Array.isArray(r.to)?r.to.map(e=>t(e)):t(r.to)};return r.text&&(n.text=r.text),r.html&&(n.html=r.html),r.cc&&(n.cc=Array.isArray(r.cc)?r.cc.map(e=>t(e)):t(r.cc)),r.bcc&&(n.bcc=Array.isArray(r.bcc)?r.bcc.map(e=>t(e)):t(r.bcc)),r.replyTo&&(n.replyTo=r.replyTo.name?`${r.replyTo.name} <${r.replyTo.email}>`:r.replyTo.email),r.headers&&(n.headers=g(r.headers)),r.attachments&&r.attachments.length>0&&(n.attachments=r.attachments.map(e=>{const i={filename:e.filename};return e.raw!==void 0?i.content=e.raw:e.content!==void 0?i.content=e.content:e.path&&(i.path=e.path),e.contentType&&(i.contentType=e.contentType),e.contentDisposition&&(i.contentDisposition=e.contentDisposition),e.cid&&(i.cid=e.cid),e.encoding&&(i.encoding=e.encoding),e.headers&&(i.headers=e.headers),e.href&&(i.href=e.href),e.httpHeaders&&(i.httpHeaders=e.httpHeaders),i})),n};return{features:{attachments:!0,customHeaders:!0,html:!0,replyTo:!0},initialize:y,isAvailable:async()=>{try{return o??=f(),await o.verify(),!0}catch{return!1}},name:s,options:c,sendEmail:async r=>{const a=h(r);if(a.length>0)return{error:new l(s,`Validation failed: ${a.join(", ")}`),success:!1};try{if(d||await y(),!o)throw new l(s,"Transporter not initialized. Call initialize() first.");const t=r.transportOverride?f(r.transportOverride):o,u=m(r),n=await t.sendMail(u);return{data:{messageId:n.messageId||v(),provider:s,response:n,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new l(s,`Failed to send email: ${t instanceof Error?t.message:String(t)}`,{cause:t instanceof Error?t:new Error(String(t))}),success:!1}}},shutdown:async()=>{o&&typeof o.close=="function"&&o.close(),o=void 0,d=!1},validateCredentials:async()=>{try{return o??=f(),await o.verify(),!0}catch{return!1}}}});export{x as default};
@@ -0,0 +1 @@
1
+ const h=["re","fwd","fw","aw","wg","sv","vs"];class p{parent=new Map;find(t){if(!this.parent.has(t))return this.parent.set(t,t),t;let n=t,r=this.parent.get(n);for(;r!==void 0&&r!==n;)n=r,r=this.parent.get(n);return this.parent.set(t,n),n}union(t,n){const r=this.find(t),i=this.find(n);r!==i&&this.parent.set(r,i)}}const u=s=>s.replaceAll(/[<>]/g,"").trim(),d=s=>{let t=s.trim(),n=!0;for(;n;){n=!1;for(const r of h){if(!t.toLowerCase().startsWith(r))continue;const e=t.slice(r.length).trimStart();if(e.startsWith(":")){t=e.slice(1).trimStart(),n=!0;break}}}return t.replaceAll(/\s+/g," ").trim().toLowerCase()},w=s=>{const t=new p,n=new Map,r=(e,c)=>{if(e.messageId){const o=u(e.messageId);if(o!=="")return o}return`__index_${String(c)}`};s.forEach((e,c)=>{const o=r(e,c),a=[e.inReplyTo,...e.references].filter(l=>l!==void 0);for(const l of a)t.union(o,u(l));if(a.length===0&&e.subject){const l=d(e.subject);if(l){const f=n.get(l);f?t.union(o,f):n.set(l,o)}}});const i=new Map;return s.forEach((e,c)=>{const o=t.find(r(e,c)),a=i.get(o);a?a.push(e):i.set(o,[e])}),[...i.entries()].map(([e,c])=>({id:e,messages:c}))};export{u as normalizeMessageId,d as normalizeSubject,w as stitchThreads};
@@ -0,0 +1 @@
1
+ import{c as T}from"./create-token-cache-BdMsMzf7.js";import{h as u}from"./headers-to-record-ZOZ7Dubo.js";const i=o=>{const{fetchToken:r,headerName:a="Authorization",now:t=Date.now,onToken:n,scheme:s="Bearer",skewMs:c=6e4}=o,h=T(async()=>{const e=await r();return n?.(e),e},{now:t,skewMs:c});return async(e,d)=>{const k=await h(),w=e.headers?u(e.headers):{};return d({...e,headers:{...w,[a]:`${s} ${k.accessToken}`}})}};export{i as oauth2Middleware};
@@ -0,0 +1 @@
1
+ import{context as h,trace as w,SpanStatusCode as g}from"@opentelemetry/api";import u from"./EmailError-BIaHK1Uw.js";import p from"./RequiredOptionError-ctDEEB1s.js";import{c as b}from"./create-logger-CazqtXcL.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";const A=e=>typeof e=="function",S=e=>e!==null&&typeof e=="object"&&"sendEmail"in e&&"initialize"in e&&"isAvailable"in e,s="opentelemetry",z="email",P="email.send",d=e=>e?typeof e=="string"?e:Array.isArray(e)?e.map(i=>typeof i=="string"?i:i.email).join(", "):e.email:"",x=(e,i)=>{const a={"email.from":d(e.from),"email.subject":e.subject};return e.to&&(a["email.to"]=d(e.to)),e.cc&&(a["email.cc"]=d(e.cc)),e.bcc&&(a["email.bcc"]=d(e.bcc)),e.replyTo&&(a["email.reply_to"]=d(e.replyTo)),e.priority&&(a["email.priority"]=e.priority),e.tags&&e.tags.length>0&&(a["email.tags"]=e.tags.join(", ")),e.attachments&&e.attachments.length>0&&(a["email.attachments.count"]=e.attachments.length),i?(e.text&&(a["email.text.length"]=e.text.length),e.html&&(a["email.html.length"]=e.html.length)):(e.text&&(a["email.has_text"]=!0),e.html&&(a["email.has_html"]=!0)),a},$=E(e=>{if(!e?.provider)throw new p(s,"provider");const i={debug:e.debug??!1,logger:e.logger,provider:e.provider,recordContent:e.recordContent??!1,retries:e.retries??3,serviceName:e.serviceName??z,timeout:e.timeout??3e4,tracer:e.tracer};let a=!1,t;const l=b(s,e.logger),v=()=>i.tracer?i.tracer:w.getTracer(i.serviceName),m=async()=>{try{if(A(i.provider))t=i.provider({});else if(S(i.provider))t=i.provider;else throw new u(s,"Invalid provider: must be a Provider instance or ProviderFactory function");await t.initialize(),l.debug(`Initialized wrapped provider: ${t.name??"unknown"}`)}catch(o){throw new u(s,`Failed to initialize wrapped provider: ${o.message}`,{cause:o})}},y=()=>t?.features?t.features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1};return{get features(){return y()},getInstance(){if(!t)throw new u(s,"Provider not initialized. Call initialize() first.");return t},async initialize(){if(!a)try{await m(),a=!0,l.debug("OpenTelemetry provider initialized")}catch(o){throw new u(s,`Failed to initialize: ${o.message}`,{cause:o})}},async isAvailable(){try{return t||await m(),await t.isAvailable()}catch{return!1}},name:s,options:i,async sendEmail(o){const n=v().startSpan(P);try{t||await m();const c=x(o,i.recordContent);n.setAttributes(c),t.name&&n.setAttribute("email.provider",t.name);const r=await h.with(w.setSpan(h.active(),n),async()=>await t.sendEmail(o));if(r.success&&r.data)return n.setStatus({code:g.OK}),n.setAttribute("email.message_id",r.data.messageId),n.setAttribute("email.sent",!0),r.data.timestamp&&n.setAttribute("email.timestamp",r.data.timestamp.toISOString()),l.debug(`Email sent successfully via ${t.name??"unknown"}`),{data:{...r.data,provider:`${s}(${t.name??"unknown"})`},success:!0};const f=r.error instanceof Error?r.error.message:String(r.error??"Unknown error");return n.setStatus({code:g.ERROR,message:f}),n.setAttribute("email.sent",!1),n.recordException(r.error instanceof Error?r.error:new Error(f)),l.debug(`Failed to send email via ${t.name??"unknown"}:`,f),r}catch(c){const r=c instanceof Error?c.message:String(c);return n.setStatus({code:g.ERROR,message:r}),n.setAttribute("email.sent",!1),n.recordException(c instanceof Error?c:new Error(r)),l.debug("Exception sending email:",r),{error:new u(s,`Failed to send email: ${r}`,{cause:c}),success:!1}}finally{n.end()}},async shutdown(){t?.shutdown&&await t.shutdown(),a=!1},async validateCredentials(){try{return t||await m(),t.validateCredentials?await t.validateCredentials():await t.isAvailable()}catch{return!1}}}});export{$ as default};
@@ -0,0 +1 @@
1
+ import u from"./EmailError-BIaHK1Uw.js";import{g as R}from"./generate-message-id-B2n2yqR6.js";import{m as E}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{v}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import m from"./RequiredOptionError-ctDEEB1s.js";import{c as b}from"./create-token-cache-BdMsMzf7.js";import{c as $,h as D,P as M}from"./provider-base-BEz00m9R.js";import{c as L}from"./attachment-processor-BJFDS343.js";const _="https://login.microsoftonline.com",C=6e4,x=3e4,U=3,F=300,j="https://graph.microsoft.com/.default",q=["https://graph.microsoft.com/Mail.Send","offline_access"],B={accessToken:["clientId","clientSecret","refreshToken","tenantId"],clientCredentials:["refreshToken"],getAccessToken:["accessToken","clientId","clientSecret","refreshToken","tenantId"],refreshToken:[]},z=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},G=(e,t)=>{if(e.getAccessToken)return"getAccessToken";if(e.accessToken)return"accessToken";if(e.refreshToken)return"refreshToken";if(e.clientSecret)return"clientCredentials";throw new m(t,["accessToken","getAccessToken","clientSecret","refreshToken"])},H=(e,t,c)=>{const r=e.authMode??G(e,t),T=B[r].filter(a=>e[a]!==void 0);if(T.length>0&&c.warn(`The '${r}' auth mode ignores these configured options: ${T.join(", ")}. Set 'authMode' to pin the intended flow.`),r==="getAccessToken"){const{getAccessToken:a}=e;if(!a)throw new m(t,"getAccessToken");return{getToken:async()=>a(),mode:r}}if(r==="accessToken"){const{accessToken:a}=e;if(!a)throw new m(t,"accessToken");return{getToken:()=>Promise.resolve(a),mode:r}}const{clientId:h,clientSecret:n,refreshToken:d,tenantId:l}=e,o=[];if(l||o.push("tenantId"),h||o.push("clientId"),r==="clientCredentials"&&!n&&o.push("clientSecret"),r==="refreshToken"&&!d&&o.push("refreshToken"),!l||!h)throw new m(t,o);if(r==="clientCredentials"){if(!n)throw new m(t,o);return{clientId:h,clientSecret:n,mode:r,tenantId:l}}if(!d)throw new m(t,o);return{clientId:h,clientSecret:n,mode:r,refreshToken:d,tenantId:l}},Y=(e,t,c)=>{if(typeof e!="object"||e===null)throw new u(t,`Token endpoint returned a non-JSON response (status ${String(c)})`);const r=e;if(typeof r.error=="string"){const T=typeof r.error_description=="string"?r.error_description:"no description provided";throw new u(t,`Token request failed: ${r.error} — ${T}`,{code:r.error,hint:"Check the tenantId, clientId and client secret / refresh token in the Azure app registration."})}if(typeof r.access_token!="string")throw new u(t,`Token endpoint response did not contain an access_token (status ${String(c)})`);return{accessToken:r.access_token,expiresIn:typeof r.expires_in=="number"?r.expires_in:F,refreshToken:typeof r.refresh_token=="string"?r.refresh_token:void 0}},J=e=>e===0||e===408||e===429||e>=500,K=(e,t,c,r)=>{if(e.mode==="accessToken"||e.mode==="getAccessToken")return e.getToken;const h=`${z(t.authority??_)}/${e.tenantId}/oauth2/v2.0/token`,n=t.timeout??x,d=t.retries??U,l=t.now??Date.now;let o=e.mode==="refreshToken"?e.refreshToken:void 0;const a=()=>{const s=new URLSearchParams({client_id:e.clientId,scope:(t.scopes??(e.mode==="clientCredentials"?[j]:q)).join(" ")});return e.clientSecret&&s.set("client_secret",e.clientSecret),e.mode==="clientCredentials"?s.set("grant_type","client_credentials"):(s.set("grant_type","refresh_token"),s.set("refresh_token",o)),s.toString()},k=s=>s.data?.statusCode??0,p=async()=>{const s=await E(h,{headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:n},a());return!s.success&&J(k(s))?s:{data:s.data,success:!0}},w=async s=>{if(o=s,!!t.onRefreshToken)try{await t.onRefreshToken(s)}catch(f){r.error(`Failed to persist the rotated refresh token — the stored token is stale and sending will fail after a restart: ${f instanceof Error?f.message:String(f)}`)}},A=b(async()=>{const s=await g(p,d),f=s.data?.body;if(!s.success&&(typeof f!="object"||f===null))throw s.error instanceof Error?s.error:new u(c,"Token request failed");const y=Y(f,c,k(s));return y.refreshToken&&y.refreshToken!==o&&await w(y.refreshToken),{accessToken:y.accessToken,expiresAt:l()+y.expiresIn*1e3}},{now:l,skewMs:t.tokenRefreshSkewMs??C});return async()=>(await A()).accessToken},i="outlook365",N="https://graph.microsoft.com/v1.0",O=3e4,V=3,S=e=>[e].flat(),I=e=>e.map(t=>({emailAddress:{address:t.email,...t.name?{name:t.name}:{}}})),W=e=>{if(e instanceof u)return e;const t=e instanceof Error?e.message:String(e);return new u(i,`Failed to obtain access token: ${t}`,{cause:e})},ie=P((e={})=>{const t=$(i,e.logger),c=H(e,i,t);if(c.mode==="clientCredentials"&&(e.userId===void 0||e.userId==="me"))throw new u(i,"The app-only (client credentials) flow requires an explicit 'userId'",{hint:"Set 'userId' to the sender's mailbox id or UPN — app-only tokens have no 'me' mailbox."});const r={authMode:c.mode,authority:e.authority??_,clientId:e.clientId,debug:e.debug??!1,endpoint:e.endpoint??N,logger:e.logger,now:e.now,retries:e.retries??V,saveToSentItems:e.saveToSentItems??!0,scopes:e.scopes,tenantId:e.tenantId,timeout:e.timeout??O,tokenRefreshSkewMs:e.tokenRefreshSkewMs,userId:e.userId??"me"},T=new M,h=K(c,e,i,t);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){T.setInitialized()},async isAvailable(){return!0},name:i,options:r,async sendEmail(n){try{const d=v(n);if(d.length>0)return{error:new u(i,`Invalid email options: ${d.join(", ")}`),success:!1};let l;try{l=await h()}catch(p){return{error:W(p),success:!1}}const o={body:{content:n.html??n.text??"",contentType:n.html?"HTML":"Text"},subject:n.subject,toRecipients:I(S(n.to))};n.cc&&(o.ccRecipients=I(S(n.cc))),n.bcc&&(o.bccRecipients=I(S(n.bcc))),n.replyTo&&(o.replyTo=I(S(n.replyTo))),n.importance&&(o.importance=n.importance),n.attachments&&n.attachments.length>0&&(o.attachments=await Promise.all(n.attachments.map(async p=>{const w=await L(p,i);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:w.content,contentType:w.contentType,name:w.filename}})));const a=r.userId==="me"?"me":`users/${r.userId}`,k=await g(async()=>E(`${r.endpoint}/${a}/sendMail`,{headers:{Authorization:`Bearer ${l}`,"Content-Type":"application/json"},method:"POST",timeout:r.timeout},JSON.stringify({message:o,saveToSentItems:r.saveToSentItems})),r.retries);return k.success?{data:{messageId:R(),provider:i,response:k.data,sent:!0,timestamp:new Date},success:!0}:{error:k.error??new u(i,"Failed to send email"),success:!1}}catch(d){return{error:D(i,"send email",d,t),success:!1}}},async validateCredentials(){try{return await h(),!0}catch(n){return t.warn(`Credential validation failed: ${n instanceof Error?n.message:String(n)}`),!1}}}});export{ie as default};
@@ -0,0 +1 @@
1
+ const i=/<[^<>]+>/g,c=/\s+/,f=/^"|"$/g,a=r=>{if(!(r===void 0||r.length===0))return r},l=r=>{if(!r)return;const e=r.trim();if(e.length===0)return;const t=e.lastIndexOf("<"),n=e.lastIndexOf(">");if(t!==-1&&n>t){const s=e.slice(t+1,n).trim(),o=e.slice(0,t).trim().replaceAll(f,"").trim();return o?{email:s,name:o}:{email:s}}return{email:e}},m=r=>{if(!r)return[];const e=[];let t="",n=!1;for(const s of r)s==='"'?(n=!n,t+=s):s===","&&!n?(e.push(t),t=""):t+=s;return t.trim()&&e.push(t),e.map(s=>l(s)).filter(s=>s!==void 0)},p=r=>{if(!r)return[];const e=r.match(i);return e?e.map(t=>t.trim()):r.split(c).map(t=>t.trim()).filter(t=>t.length>0)},u=r=>{const e={};if(!r)return e;for(const[t,n]of Object.entries(r))typeof n=="string"?e[t.toLowerCase()]=n:(typeof n=="number"||typeof n=="boolean")&&(e[t.toLowerCase()]=String(n));return e};export{u as lowercaseHeaders,a as nonEmpty,l as parseAddress,m as parseAddressList,p as parseReferences};
@@ -0,0 +1,6 @@
1
+ const l="message/feedback-report",f=o=>{const e=o.replaceAll(`\r
2
+ `,`
3
+ `);let t=e;const s=e.toLowerCase().indexOf(l);if(s!==-1){const n=e.slice(s),r=n.indexOf(`
4
+
5
+ `);t=r===-1?n:n.slice(r+2)}const i={};for(const n of t.split(`
6
+ `)){if(n.trim()===""){if(Object.keys(i).length>0)break;continue}const r=n.indexOf(":");if(r===-1)continue;const a=n.slice(0,r).trim().toLowerCase(),c=n.slice(r+1).trim();a&&(i[a]=c)}return i},d=o=>{const e=f(o);return{arrivalDate:e["arrival-date"],feedbackType:e["feedback-type"],fields:e,originalMailFrom:e["original-mail-from"],originalRcptTo:e["original-rcpt-to"],reportedDomain:e["reported-domain"],sourceIp:e["source-ip"]}};export{d as parseArfReport};
@@ -0,0 +1 @@
1
+ import{lowercaseHeaders as a,parseAddressList as t,nonEmpty as o,parseAddress as c,parseReferences as n}from"./parseAddress-DW9suGjV.js";const f=r=>{const e=r.headers instanceof Headers?Object.fromEntries([...r.headers].map(([s,d])=>[s.toLowerCase(),d])):a(r.headers);return{attachments:[],bcc:[],cc:t(e.cc),from:c(r.from??e.from),headers:e,html:o(r.html),inReplyTo:e["in-reply-to"],messageId:e["message-id"],provider:"cloudflare",raw:r,references:n(e.references),replyTo:c(e["reply-to"]),subject:e.subject,text:o(r.text),to:t(r.to??e.to)}};export{f as default};
@@ -0,0 +1 @@
1
+ const s=r=>{if(r)return r.split(",").map(t=>t.trim()).filter(t=>t.length>0)},c=r=>{if(r==="s")return"s";if(r==="r")return"r"},a=r=>{if(r==="none"||r==="quarantine"||r==="reject")return r},d=r=>{const t={},p=r.split(";").map(i=>i.trim()).find(i=>i.length>0);for(const i of r.split(";")){const o=i.indexOf("=");if(o===-1)continue;const e=i.slice(0,o).trim().toLowerCase(),f=i.slice(o+1).trim();e&&(t[e]=f)}const n=t.pct===void 0?void 0:Number.parseInt(t.pct,10);return{adkim:c(t.adkim),aspf:c(t.aspf),fo:t.fo,percent:n===void 0||Number.isNaN(n)?void 0:n,policy:a(t.p),rua:s(t.rua),ruf:s(t.ruf),subdomainPolicy:a(t.sp),tags:t,valid:p?.toLowerCase()==="v=dmarc1"}};export{d as parseDmarcRecord};
@@ -0,0 +1 @@
1
+ import{parseAddressList as n,nonEmpty as i,parseAddress as c,parseReferences as m}from"./parseAddress-DW9suGjV.js";const f=e=>{const s={};if(!e)return s;let r;if(typeof e=="string")try{r=JSON.parse(e)}catch{return s}else r=e;for(const[t,o]of r)t&&(s[t.toLowerCase()]=o);return s},u=e=>{if(!e)return;const s=e.trim();return s.startsWith("<")&&s.endsWith(">")?s:`<${s}>`},g=e=>{const s=f(e["message-headers"]);return{attachments:[],bcc:[],cc:n(e.cc),from:c(e.from??e.sender),headers:s,html:i(e["body-html"]),inReplyTo:s["in-reply-to"],messageId:u(e["Message-Id"]??s["message-id"]),provider:"mailgun",raw:e,references:m(s.references),replyTo:c(s["reply-to"]),subject:e.subject,text:i(e["stripped-text"]??e["body-plain"]),to:n(e.To??e.recipient)}};export{g as default};
@@ -0,0 +1 @@
1
+ import{nonEmpty as r}from"./parseAddress-DW9suGjV.js";const o=e=>{if(e?.Email)return e.Name?{email:e.Email,name:e.Name}:{email:e.Email}},s=e=>(e??[]).map(t=>o(t)).filter(t=>t!==void 0),u=e=>{const t={};for(const n of e.Headers??[])n.Name&&(t[n.Name.toLowerCase()]=n.Value??"");const m=(t.references??"").match(/<[^<>]+>/g)??[];return{attachments:(e.Attachments??[]).map(n=>({cid:n.ContentID,content:n.Content,contentType:n.ContentType,filename:n.Name??"attachment",size:n.ContentLength})),bcc:s(e.BccFull),cc:s(e.CcFull),from:o(e.FromFull),headers:t,html:r(e.HtmlBody),inReplyTo:t["in-reply-to"],messageId:t["message-id"]??(e.MessageID?`<${e.MessageID}>`:void 0),provider:"postmark",raw:e,references:m,replyTo:e.ReplyTo?{email:e.ReplyTo}:void 0,subject:e.Subject,text:r(e.TextBody),to:s(e.ToFull)}};export{u as default};
@@ -0,0 +1,4 @@
1
+ import{parseAddressList as i,nonEmpty as c,parseAddress as o,parseReferences as m}from"./parseAddress-DW9suGjV.js";const d=e=>{const r={};if(!e)return r;let s;for(const t of e.replaceAll(`\r
2
+ `,`
3
+ `).split(`
4
+ `)){if((t.startsWith(" ")||t.startsWith(" "))&&s!==void 0){r[s]=`${r[s]??""} ${t.trim()}`.trim();continue}const n=t.indexOf(":");n>0&&(s=t.slice(0,n).trim().toLowerCase(),r[s]=t.slice(n+1).trim())}return r},l=e=>{const r=d(e.headers);return{attachments:[],bcc:[],cc:i(e.cc),from:o(e.from),headers:r,html:c(e.html),inReplyTo:r["in-reply-to"],messageId:r["message-id"],provider:"sendgrid",raw:e,references:m(r.references),replyTo:o(r["reply-to"]),subject:e.subject,text:c(e.text),to:i(e.to)}};export{l as default};
@@ -0,0 +1 @@
1
+ import{parseAddressList as a,nonEmpty as m,parseAddress as c,parseReferences as n}from"./parseAddress-DW9suGjV.js";const f=o=>{const r=o.mail??{},s=r.commonHeaders??{},t={};for(const e of r.headers??[])e.name&&(t[e.name.toLowerCase()]=e.value??"");return{attachments:[],bcc:[],cc:(s.cc??[]).flatMap(e=>a(e)),from:c(s.from?.[0]??r.source),headers:t,html:m(o.html),inReplyTo:t["in-reply-to"],messageId:s.messageId??t["message-id"]??(r.messageId?`<${r.messageId}>`:void 0),provider:"ses",raw:o,references:n(t.references),replyTo:c(s.replyTo?.[0]),subject:s.subject,text:m(o.text),to:(s.to??[]).flatMap(e=>a(e))}};export{f as default};
@@ -0,0 +1 @@
1
+ const i=o=>{const t={};for(const e of o.split(";")){const s=e.indexOf("=");if(s===-1)continue;const a=e.slice(0,s).trim().toLowerCase();a&&(t[a]=e.slice(s+1).trim())}return{rua:(t.rua??"").split(",").map(e=>e.trim()).filter(e=>e.length>0),valid:(t.v??"")==="TLSRPTv1",version:t.v}},n=o=>{const t=typeof o=="string"?JSON.parse(o):o,r=t.policies??[];let e=0,s=0;for(const a of r)e+=a.summary?.["total-successful-session-count"]??0,s+=a.summary?.["total-failure-session-count"]??0;return{endDate:t["date-range"]?.["end-datetime"],organizationName:t["organization-name"],policies:r,reportId:t["report-id"],startDate:t["date-range"]?.["start-datetime"],totalFailure:s,totalSuccessful:e}};export{n as parseTlsReport,i as parseTlsRptRecord};
@@ -0,0 +1 @@
1
+ import l from"./EmailError-BIaHK1Uw.js";import w from"./RequiredOptionError-ctDEEB1s.js";import{g as b}from"./generate-message-id-B2n2yqR6.js";import{h as A}from"./headers-to-record-ZOZ7Dubo.js";import{m as h}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{s as P,a as T}from"./sanitize-header-CW0f3IT7.js";import{v as k}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{c as j,P as R,h as p}from"./provider-base-BEz00m9R.js";import{p as _}from"./attachment-processor-BJFDS343.js";const t="plunk",D="https://api.useplunk.com/v1",K=3e4,x=3,G=z((n={})=>{if(!n.apiKey)throw new w(t,"apiKey");const a={apiKey:n.apiKey,debug:n.debug??!1,endpoint:n.endpoint??D,logger:n.logger,retries:n.retries??x,timeout:n.timeout??K},f=new R,s=j(t,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(t,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),t);const c={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const i=await g(async()=>h(`${a.endpoint}/emails/${e}`,{headers:c,method:"GET",timeout:a.timeout}),a.retries);return i.success?(s.debug("Email details retrieved successfully"),{data:i.data?.body,success:!0}):(s.debug("API request failed when retrieving email",i.error),{error:new l(t,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1})}catch(c){return{error:p(t,"retrieve email",c,s),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(t,"Plunk API not available or invalid API key");s.debug("Provider initialized successfully")},t)},async isAvailable(){try{return a.apiKey&&a.apiKey.length>0?(s.debug("API key exists, assuming Plunk is available"),!0):!1}catch(e){return s.debug("Error checking availability:",e),!1}},name:t,options:a,async sendEmail(e){try{const c=k(e);if(c.length>0)return{error:new l(t,`Invalid email options: ${c.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),t);const i=o=>Array.isArray(o)?o.map(d=>d.email):[o.email],r={to:e.subscriber??(Array.isArray(e.to)?e.to[0]?.email:e.to.email)};if(e.from&&(r.from=e.from.email,e.from.name&&(r.from_name=e.from.name)),e.subject&&(r.subject=e.subject),e.html?r.body=e.html:e.text&&(r.body=e.text),e.html&&e.text&&(r.text=e.text),e.cc&&(r.cc=i(e.cc)),e.bcc&&(r.bcc=i(e.bcc)),e.replyTo&&(r.reply_to=e.replyTo.email,e.replyTo.name&&(r.reply_to_name=e.replyTo.name)),e.templateId&&(r.template=e.templateId),e.data&&(r.data=e.data),e.subscriberId&&(r.subscriber_id=e.subscriberId),e.headers){const o=A(e.headers),d={};Object.entries(o).forEach(([E,I])=>{d[P(E)]=T(I)}),r.headers=d}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async o=>({content:await _(o,t),filename:o.filename,type:o.contentType??"application/octet-stream"})))),s.debug("Sending email via Plunk API",{subject:r.subject,to:r.to});const v={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},u=await g(async()=>h(`${a.endpoint}/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(r)),a.retries);if(!u.success)return s.debug("API request failed when sending email",u.error),{error:u.error??new l(t,"Failed to send email"),success:!1};const m=u.data,y=m?.body&&typeof m.body=="object"?m.body.id??m.body.messageId??b():b();return s.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:t,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:p(t,"send email",c,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-BIaHK1Uw.js";import p from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-B2n2yqR6.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m as u}from"./make-request-Cyz5_yu8.js";import{r as y}from"./retry-aghj7y8m.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{c as A,P as T}from"./provider-base-BEz00m9R.js";import{l as m,m as h}from"./address-formatter-CXZ1aWBX.js";import{p as C}from"./attachment-processor-BJFDS343.js";const a="postal",S=3e4,j=3,L=I((s={})=>{if(!s.host)throw new p(a,"host");if(!s.apiKey)throw new p(a,"apiKey");const f=s.endpoint??`https://${s.host}/api/v1`,o={apiKey:s.apiKey,debug:s.debug??!1,endpoint:f,host:s.host,retries:s.retries??j,timeout:s.timeout??S,...s.logger&&{logger:s.logger}},l=new T,i=A(a,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(a,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),a);const t={"Content-Type":"application/json","X-Server-API-Key":o.apiKey};i.debug("Retrieving email details",{id:e});const r=await y(async()=>u(`${o.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:o.timeout}),o.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new d(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return i.debug("Exception retrieving email",t),{error:new d(a,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(a,"Postal API not available or invalid API key");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Server-API-Key":o.apiKey};i.debug("Checking Postal API availability");const t=await u(`${o.endpoint}/server`,{headers:e,method:"GET",timeout:o.timeout});return i.debug("Postal 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 i.debug("Error checking availability:",e),!1}},name:a,options:o,async sendEmail(e){try{const t=E(e);if(t.length>0)return{error:new d(a,`Invalid email options: ${t.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),a);const r={from:h(e.from).address,subject:e.subject,to:m(e.to).map(n=>n.address)};if(e.html&&(r.html_body=e.html),e.text&&(r.plain_body=e.text),e.cc&&(r.cc=m(e.cc).map(n=>n.address)),e.bcc&&(r.bcc=m(e.bcc).map(n=>n.address)),e.replyTo&&(r.reply_to=h(e.replyTo).address),e.templateId&&(r.template_id=e.templateId,e.templateVariables&&(r.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tag=e.tags.join(",")),e.headers){const n=P(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>{const v=await C(n,a);return{content_type:n.contentType??"application/octet-stream",data:v,name:n.filename}}))),i.debug("Sending email via Postal API",{subject:r.subject,to:r.to});const b={"Content-Type":"application/json","X-Server-API-Key":o.apiKey},c=await y(async()=>u(`${o.endpoint}/send/message`,{headers:b,method:"POST",timeout:o.timeout},JSON.stringify(r)),o.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new d(a,"Failed to send email"),success:!1};const g=c.data?.body?.message_id?.toString()??w();return i.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return i.debug("Exception sending email",t),{error:new d(a,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import p from"./RequiredOptionError-ctDEEB1s.js";import{g as E}from"./generate-message-id-B2n2yqR6.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m}from"./make-request-Cyz5_yu8.js";import{r as h}from"./retry-aghj7y8m.js";import{a as I,s as w}from"./sanitize-header-CW0f3IT7.js";import{v as A}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as S}from"./defineProvider-C9q-7iwt.js";import{c as C,P as j,h as v}from"./provider-base-BEz00m9R.js";import{e as f,g as T}from"./address-formatter-CXZ1aWBX.js";import{b as M}from"./attachment-processor-BJFDS343.js";const a="postmark",R="https://api.postmarkapp.com",z=3e4,D=3,J=S((n={})=>{if(!n.serverToken)throw new p(a,"serverToken");const s={debug:n.debug??!1,endpoint:n.endpoint??R,retries:n.retries??D,serverToken:n.serverToken,timeout:n.timeout??z,...n.logger&&{logger:n.logger}},u=new j,o=C(a,n.logger);return{endpoint:s.endpoint,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(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};o.debug("Retrieving email details",{id:e});const r=await h(async()=>m(`${s.endpoint}/messages/outbound/${e}/details`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(o.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(o.debug("API request failed when retrieving email",r.error),{error:new c(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:v(a,"retrieve email",t,o),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Postmark API not available or invalid server token");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};o.debug("Checking Postmark API availability");const t=await m(`${s.endpoint}/server`,{headers:e,method:"GET",timeout:s.timeout});return o.debug("Postmark 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 o.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=A(e);if(t.length>0)return{error:new c(a,`Invalid email options: ${t.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const r={From:T(e.from),Subject:e.subject,To:f(e.to).join(",")};if(e.html&&(r.HtmlBody=e.html),e.text&&(r.TextBody=e.text),e.cc&&(r.Cc=f(e.cc).join(",")),e.bcc&&(r.Bcc=f(e.bcc).join(",")),e.replyTo&&(r.ReplyTo=T(e.replyTo)),e.templateId?(r.TemplateId=e.templateId,e.templateModel&&(r.TemplateModel=e.templateModel)):e.templateAlias&&(r.TemplateAlias=e.templateAlias,e.templateModel&&(r.TemplateModel=e.templateModel)),e.trackOpens!==void 0&&(r.TrackOpens=e.trackOpens),e.trackLinks!==void 0&&(r.TrackLinks=e.trackLinks),e.inlineCss!==void 0&&(r.InlineCss=e.inlineCss),e.messageStream&&(r.MessageStream=e.messageStream),e.metadata&&(r.Metadata=e.metadata),e.tags&&e.tags.length>0){const[d]=e.tags;r.Tag=d}if(e.headers){const d=P(e.headers),l=[];for(const[y,b]of Object.entries(d))l.push({Name:w(y),Value:I(String(b))});l.length>0&&(r.Headers=l)}e.attachments&&e.attachments.length>0&&(r.Attachments=await Promise.all(e.attachments.map(async d=>M(d,a)))),o.debug("Sending email via Postmark API",{subject:r.Subject,to:r.To});const k={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken},i=await h(async()=>m(`${s.endpoint}/email`,{headers:k,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!i.success)return o.debug("API request failed when sending email",i.error),{error:i.error??new c(a,"Failed to send email"),success:!1};const g=i.data?.body?.MessageID??E();return o.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(a,"send email",t,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{J as default};
@@ -0,0 +1 @@
1
+ import s from"./EmailError-BIaHK1Uw.js";import{c as n}from"./create-logger-CazqtXcL.js";class c{isInitialized=!1;get initialized(){return this.isInitialized}setInitialized(){this.isInitialized=!0}async ensureInitialized(i,e){if(!this.isInitialized)try{await i(),this.isInitialized=!0}catch(t){throw new s(e,`Failed to initialize: ${t.message}`,{cause:t})}}}const l=(a,i)=>n(a,i),z=(a,i,e,t)=>{const r=`Failed to ${i}: ${e.message}`;return t&&t.debug(`Exception ${i}`,e),new s(a,r,{cause:e})};export{c as P,l as c,z as h};
@@ -0,0 +1,7 @@
1
+ const f=globalThis.Buffer!==void 0,i=/^[\da-f]{2}$/i,l=t=>f?Uint8Array.from(Buffer.from(t,"utf8")):new TextEncoder().encode(t),u=t=>f?Buffer.from(t).toString("utf8"):new TextDecoder().decode(t),c=t=>`=${t.toString(16).toUpperCase().padStart(2,"0")}`,a=t=>{const n=[];for(let r=0;r<t.length;r+=1){const e=t[r],o=r===t.length-1;e===9||e===32?n.push(o?c(e):String.fromCodePoint(e)):e>=33&&e<=126&&e!==61?n.push(String.fromCodePoint(e)):n.push(c(e))}return n},d=t=>{let n="";const r=[];for(const e of t)n.length+e.length>75&&(r.push(`${n}=`),n=""),n+=e;return r.push(n),r.join(`\r
2
+ `)},h=t=>t.replaceAll(`\r
3
+ `,`
4
+ `).replaceAll("\r",`
5
+ `).split(`
6
+ `).map(r=>d(a(l(r)))).join(`\r
7
+ `),p=t=>{const n=t.replaceAll(/=\r?\n/g,""),r=[];for(let e=0;e<n.length;e+=1){const o=n[e];if(o==="="&&e+2<n.length){const s=n.slice(e+1,e+3);i.test(s)?(r.push(Number.parseInt(s,16)),e+=2):r.push(o.charCodeAt(0))}else r.push(o.charCodeAt(0))}return u(Uint8Array.from(r))};export{p as d,h as e};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import E from"./RequiredOptionError-ctDEEB1s.js";import{g as I}from"./generate-message-id-B2n2yqR6.js";import{h as w}from"./headers-to-record-ZOZ7Dubo.js";import{m as f}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{c as $,P as C,h as p}from"./provider-base-BEz00m9R.js";import{e as j,g as b,d as v}from"./address-formatter-CXZ1aWBX.js";import{p as R}from"./attachment-processor-BJFDS343.js";const o="resend",S="https://api.resend.com",k=3e4,z=3,D=s=>{const r=[],d=/^[\w-]+$/;return d.test(s.name)||r.push(`Tag name '${s.name}' must only contain ASCII letters, numbers, underscores, or dashes`),s.name.length>256&&r.push(`Tag name '${s.name}' exceeds maximum length of 256 characters`),d.test(s.value)||r.push(`Tag value '${s.value}' for tag '${s.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r},V=P((s={})=>{if(!s.apiKey)throw new E(o,"apiKey");const r={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??S,logger:s.logger,retries:s.retries??z,timeout:s.timeout??k},d=new C,n=$(o,s.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 c(o,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),o);const t={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const a=await g(async()=>f(`${r.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return a.success?(n.debug("Email details retrieved successfully"),{data:a.data?.body,success:!0}):(n.debug("API request failed when retrieving email",a.error),{error:new c(o,`Failed to retrieve email: ${a.error instanceof Error?a.error.message:"Unknown error"}`,{cause:a.error}),success:!1})}catch(t){return{error:p(o,"retrieve email",t,n),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(o,"Resend API not available or invalid API key");n.debug("Provider initialized successfully")},o)},async isAvailable(){try{if(r.apiKey&&r.apiKey.startsWith("re_"))return n.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Checking Resend API availability");const t=await f(`${r.endpoint}/domains`,{headers:e,method:"GET",timeout:r.timeout});return t.data&&typeof t.data=="object"&&"body"in t.data&&t.data.body&&typeof t.data.body=="object"&&"name"in t.data.body&&t.data.body.name==="restricted_api_key"?(n.debug("API key is valid but restricted to only sending emails"),!0):(n.debug("Resend 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:o,options:r,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new c(o,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),o);const a={from:b(e.from),headers:e.headers?w(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:j(e.to)};if(e.cc&&(a.cc=v(e.cc)),e.bcc&&(a.bcc=v(e.bcc)),e.replyTo&&(a.reply_to=b(e.replyTo)),e.templateId&&(a.template=e.templateId,e.templateData&&(a.data=e.templateData)),e.scheduledAt&&(a.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const i=[];if(e.tags.forEach(l=>{const y=D(l);y.length>0&&i.push(...y)}),i.length>0)return{error:new c(o,`Invalid email tags: ${i.join(", ")}`),success:!1};a.tags=e.tags.map(l=>({name:l.name,value:l.value}))}e.attachments&&e.attachments.length>0&&(a.attachments=await Promise.all(e.attachments.map(async i=>({content:await R(i,o),content_type:i.contentType,filename:i.filename,...i.path&&{path:i.path}})))),n.debug("Sending email via Resend API",{subject:a.subject,to:a.to});const A={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},u=await g(async()=>f(`${r.endpoint}/emails`,{headers:A,method:"POST",timeout:r.timeout},JSON.stringify(a)),r.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(o,"Failed to send email"),success:!1};const m=u.data,h=m?.body&&typeof m.body=="object"&&m.body.id?m.body.id:I();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:o,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:p(o,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-BIaHK1Uw.js";import{R as i}from"./make-request-Cyz5_yu8.js";const E=new Set([408,429,503]),m=r=>{const{statusCode:t}=r.data??{};return t!==void 0?E.has(t):!(r.error instanceof c&&r.error.code===i)},a=async(r,t=3,e=300,s=m)=>{try{const o=await r();return o.success||t<=0||!s(o)?o:(await new Promise(n=>{setTimeout(()=>{n()},e)}),a(r,t-1,e*2,s))}catch(o){return t<=0?{error:o instanceof Error?o:new Error(String(o)),success:!1}:(await new Promise(n=>{setTimeout(()=>{n()},e)}),a(r,t-1,e*2,s))}};export{a as r};
@@ -0,0 +1 @@
1
+ const w=t=>new Promise(a=>{setTimeout(a,t)}),f=(t={})=>{const{baseDelay:a=200,onDeadLetter:s,retries:o=3,shouldRetry:n=()=>!0,sleep:i=w}=t;return async(l,c)=>{let e={error:new Error("retry middleware ran with retries < 1"),success:!1};for(let r=0;r<o;r+=1){if(e=await c(l),e.success)return e;if(!n(e)||r===o-1)break;const u=a*2**r,d=Math.floor(Math.random()*u);await i(d)}return s&&await s(l,e),e}};export{f as retryMiddleware};
@@ -0,0 +1 @@
1
+ import m from"./EmailError-BIaHK1Uw.js";import y from"./RequiredOptionError-ctDEEB1s.js";import{c as $}from"./create-logger-CazqtXcL.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{a as A}from"./aggregate-features-Bst55u8k.js";const P=i=>typeof i=="function",x=i=>i!=null&&typeof i=="object"&&"sendEmail"in i&&"initialize"in i&&"isAvailable"in i,o="roundrobin",S=E((i={})=>{if(!i.mailers||i.mailers.length===0)throw new y(o,"mailers");const g={debug:i.debug??!1,logger:i.logger,mailers:i.mailers,retries:i.retries??3,retryAfter:i.retryAfter??60,timeout:i.timeout??3e4};let p=!1;const r=[];let a=0;const n=$(o,i.logger),v=async()=>{r.length=0;for(const t of g.mailers)try{let e;if(P(t))e=t({});else if(x(t))e=t;else{n.debug(`Skipping invalid mailer: ${t}`);continue}try{await e.initialize(),r.push(e),n.debug(`Initialized provider: ${e.name??"unknown"}`)}catch(s){n.debug(`Failed to initialize provider ${e.name??"unknown"}:`,s)}}catch(e){n.debug("Error processing mailer:",e)}if(r.length===0)throw new m(o,"No providers could be initialized");a=Math.floor(Math.random()*r.length),n.debug(`Round robin starting at index ${a} (${r[a]?.name??"unknown"})`)},h=async()=>{if(r.length===0)return;const t=a;let e=0;for(;e<r.length;){const s=r[a];if(!s){a=(a+1)%r.length,e+=1;continue}const c=s.name??`provider-${a+1}`;try{if(await s.isAvailable())return a=(a+1)%r.length,n.debug(`Selected provider: ${c} (index ${a===0?r.length-1:a-1})`),s}catch{}a=(a+1)%r.length,e+=1,e<r.length&&g.retryAfter>0&&await new Promise(l=>{setTimeout(()=>{l(void 0)},g.retryAfter)})}return n.debug(`No available providers found, using provider at index ${t}`),r[t]??void 0};return{features:A(g.mailers),async initialize(){if(!p)try{await v(),p=!0,n.debug(`Round robin provider initialized with ${r.length} provider(s)`)}catch(t){throw new m(o,`Failed to initialize: ${t.message}`,{cause:t})}},async isAvailable(){try{return r.length===0&&await v(),(await Promise.allSettled(r.map(e=>e.isAvailable()))).some(e=>e.status==="fulfilled"&&e.value)}catch{return!1}},name:o,options:g,async sendEmail(t){try{if(r.length===0&&await v(),r.length===0)return{error:new m(o,"No providers available"),success:!1};const e=await h();if(!e)return{error:new m(o,"No available providers found"),success:!1};const s=e.name??"unknown";n.debug(`Sending email via ${s}`);const c=await e.sendEmail(t);if(c.success)return n.debug(`Email sent successfully via ${s}`),{data:{...c.data,provider:`${o}(${s})`},success:!0};n.debug(`Failed to send via ${s}, trying next provider`);const l=[];c.error&&l.push(c.error);let b=0;for(;b<r.length-1;){const d=await h();if(!d||d===e)break;const f=d.name??"unknown";n.debug(`Retrying with ${f}`);try{const u=await d.sendEmail(t);if(u.success)return n.debug(`Email sent successfully via ${f} (after retry)`),{data:{...u.data,provider:`${o}(${f})`},success:!0};u.error&&l.push(u.error)}catch(u){l.push(u instanceof Error?u:new Error(String(u)))}b+=1}const w=l.map(d=>d instanceof Error?d.message:String(d)).join("; ");return{error:new m(o,`Failed to send email via all providers. Errors: ${w}`,{cause:l[0]instanceof Error?l[0]:new Error(String(l[0]))}),success:!1}}catch(e){return{error:new m(o,`Failed to send email: ${e.message}`,{cause:e}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{S as default};
@@ -0,0 +1 @@
1
+ const a=/[\r\n]/,n=e=>{const s=e.search(a);return s===-1?e:e.slice(0,s)},r=e=>e.replaceAll(/[\r\n]/g,"");export{n as a,r as s};
@@ -0,0 +1 @@
1
+ import l from"./EmailError-BIaHK1Uw.js";import f from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-B2n2yqR6.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{m as y}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{c as T,P as A,h}from"./provider-base-BEz00m9R.js";import{f as u,a as P}from"./address-formatter-CXZ1aWBX.js";import{p as S}from"./attachment-processor-BJFDS343.js";const t="scaleway",j="https://api.scaleway.com/transactional-email/v1alpha1",R=3e4,k=3,G=I((a={})=>{if(!a.apiKey)throw new f(t,"apiKey");if(!a.region)throw new f(t,"region");const p=a.endpoint??j,s={apiKey:a.apiKey,debug:a.debug??!1,endpoint:p,region:a.region,retries:a.retries??k,timeout:a.timeout??R,...a.logger&&{logger:a.logger}},d=new A,i=T(t,a.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 l(t,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),t);const o={"Content-Type":"application/json","X-Auth-Token":s.apiKey};i.debug("Retrieving email details",{id:e});const r=await g(async()=>y(`${s.endpoint}/regions/${s.region}/emails/${e}`,{headers:o,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new l(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,i),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(t,"Scaleway API not available or invalid API key");i.debug("Provider initialized successfully")},t)},async isAvailable(){try{return i.debug("Checking Scaleway API availability"),!0}catch(e){return i.debug("Error checking availability:",e),!1}},name:t,options:s,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new l(t,`Invalid email options: ${o.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),t);const r={from:{email:e.from.email,...e.from.name&&{name:e.from.name}},subject:e.subject,to:u(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=u(e.cc)),e.bcc&&(r.bcc=u(e.bcc)),e.replyTo&&(r.replyTo=P(e.replyTo)),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateVariables=e.templateVariables)),e.projectId&&(r.projectId=e.projectId),e.headers){const c=v(e.headers);r.headers=c}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async c=>({content:await S(c,t),name:c.filename,type:c.contentType??"application/octet-stream"})))),i.debug("Sending email via Scaleway API",{subject:r.subject,to:r.to});const b={"Content-Type":"application/json","X-Auth-Token":s.apiKey},n=await g(async()=>y(`${s.endpoint}/regions/${s.region}/emails`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new l(t,"Failed to send email"),success:!1};const m=n.data?.body?.id??w();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:t,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
@@ -0,0 +1 @@
1
+ import u from"./EmailError-BIaHK1Uw.js";import E from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-B2n2yqR6.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m as h}from"./make-request-Cyz5_yu8.js";import{r as p}from"./retry-aghj7y8m.js";import{v as S}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{c as G,P as _,h as v}from"./provider-base-BEz00m9R.js";import{f as y,a as I}from"./address-formatter-CXZ1aWBX.js";import{d as j}from"./attachment-processor-BJFDS343.js";const s="sendgrid",z="https://api.sendgrid.com/v3",k=3e4,C=3,H=T((o={})=>{if(!o.apiKey)throw new E(s,"apiKey");const r={apiKey:o.apiKey,debug:o.debug??!1,endpoint:o.endpoint??z,...o.logger&&{logger:o.logger},retries:o.retries??C,timeout:o.timeout??k},f=new _,i=G(s,o.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 u(s,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const a=await p(async()=>h(`${r.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return a.success?(i.debug("Email details retrieved successfully"),{data:a.data?.body,success:!0}):(i.debug("API request failed when retrieving email",a.error),{error:new u(s,`Failed to retrieve email: ${a.error instanceof Error?a.error.message:"Unknown error"}`,{cause:a.error}),success:!1})}catch(t){return{error:v(s,"retrieve email",t,i),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(s,"SendGrid API not available or invalid API key");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{if(r.apiKey&&r.apiKey.startsWith("SG."))return i.debug("API key format is valid, assuming SendGrid is available"),!0;const e={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};i.debug("Checking SendGrid API availability");const t=await h(`${r.endpoint}/user/profile`,{headers:e,method:"GET",timeout:r.timeout});return i.debug("SendGrid 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 i.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const t=S(e);if(t.length>0)return{error:new u(s,`Invalid email options: ${t.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),s);const a={to:y(e.to)};if(e.cc&&(a.cc=y(e.cc)),e.bcc&&(a.bcc=y(e.bcc)),e.subject&&(a.subject=e.subject),e.tags&&e.tags.length>0){const n={};for(let g=0;g<e.tags.length;g+=1)n[`tag_${g}`]=e.tags[g];a.customArgs=n}const d={from:I(e.from),personalizations:[a]},l=[];if(e.html&&l.push({type:"text/html",value:e.html}),e.text&&l.push({type:"text/plain",value:e.text}),l.length>0&&(d.content=l),e.replyTo&&(d.reply_to=I(e.replyTo)),e.subject&&(d.subject=e.subject),e.templateId&&(d.template_id=e.templateId,e.templateData&&(a.dynamicTemplateData=e.templateData)),e.sendAt&&(a.send_at=e.sendAt),e.batchId&&(d.batch_id=e.batchId),e.asmGroupId&&(d.asm={group_id:e.asmGroupId}),e.ipPoolName&&(d.ip_pool_name=e.ipPoolName),e.mailSettings&&(d.mail_settings=e.mailSettings),e.trackingSettings&&(d.tracking_settings=e.trackingSettings),e.headers){const n=P(e.headers);d.headers=n}e.attachments&&e.attachments.length>0&&(d.attachments=await Promise.all(e.attachments.map(async n=>j(n,s)))),i.debug("Sending email via SendGrid API",{subject:d.subject,to:a.to});const A={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},c=await p(async()=>h(`${r.endpoint}/mail/send`,{headers:A,method:"POST",timeout:r.timeout},JSON.stringify(d)),r.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new u(s,"Failed to send email"),success:!1};const m=c.data?.headers,b=(m&&m instanceof Headers?m.get("X-Message-Id"):void 0)??w();return i.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:s,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(s,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};