@visulima/email 2.1.7 → 2.1.8

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 (120) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/crypto/index.js +1 -1
  3. package/dist/deliverability/dmarc-report.js +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/middleware/index.js +1 -1
  7. package/dist/packem_shared/{DkimSigner-sLcIw9bp.js → DkimSigner-udCl3JXO.js} +1 -1
  8. package/dist/packem_shared/{DraftMailMessage-C3YTXqWo.js → DraftMailMessage-BgP1OF1G.js} +1 -1
  9. package/dist/packem_shared/EmailError-2CCyVX1S.js +1 -0
  10. package/dist/packem_shared/Mail-DduRntbB.js +1 -0
  11. package/dist/packem_shared/{MailMessage-DuEXJiCg.js → MailMessage-BRBT4Jea.js} +1 -1
  12. package/dist/packem_shared/{RequiredOptionError-DU2lxzk3.js → RequiredOptionError-BmpC5whN.js} +1 -1
  13. package/dist/packem_shared/{SmimeEncrypter-CzTbQM-z.js → SmimeEncrypter-Dm9McVTQ.js} +1 -1
  14. package/dist/packem_shared/{SmimeSigner-DjLShaOw.js → SmimeSigner-B6hkacNk.js} +1 -1
  15. package/dist/packem_shared/{address-formatter-BWR2Dddx.js → address-formatter-bfmGfQ83.js} +1 -1
  16. package/dist/packem_shared/{ahaSendProvider-br1yB2un.js → ahaSendProvider-C6nBGCCa.js} +1 -1
  17. package/dist/packem_shared/{arcMessageSignatureBase-D54jQIWu.js → arcMessageSignatureBase-B2uArM48.js} +1 -1
  18. package/dist/packem_shared/{attachment-processor-D1cbAhQi.js → attachment-processor-DjbjtJ6H.js} +1 -1
  19. package/dist/packem_shared/{autoSendProvider-BSP8ueOC.js → autoSendProvider-Dhig--Zo.js} +1 -1
  20. package/dist/packem_shared/{awsSesProvider-zRICW1pH.js → awsSesProvider-CMqAmU5N.js} +1 -1
  21. package/dist/packem_shared/{azureProvider-DwN4c5dC.js → azureProvider-C-bNOOil.js} +1 -1
  22. package/dist/packem_shared/{brevoProvider-C491beE_.js → brevoProvider-CkOjDyir.js} +1 -1
  23. package/dist/packem_shared/build-mime-message-t8KYiQkO.js +3 -0
  24. package/dist/packem_shared/{circuitBreakerMiddleware-N0CKF90q.js → circuitBreakerMiddleware-BSCPR72q.js} +1 -1
  25. package/dist/packem_shared/{cloudflareEmailProvider-8JxzLbpX.js → cloudflareEmailProvider-RCixPWnY.js} +1 -1
  26. package/dist/packem_shared/{createTestEmail-D_ksEez3.js → createTestEmail-XiF5E8vJ.js} +1 -1
  27. package/dist/packem_shared/{detectMimeType-CmYmWDXE.js → detectMimeType-B9_7ujpC.js} +1 -1
  28. package/dist/packem_shared/{failoverProvider-6qwE_HSJ.js → failoverProvider-BkOOP7pt.js} +1 -1
  29. package/dist/packem_shared/{httpProvider-BqrdZhGw.js → httpProvider-6idLfv-f.js} +1 -1
  30. package/dist/packem_shared/index-y0s2wQdc.js +11 -0
  31. package/dist/packem_shared/{infobipProvider-C2FU6VMP.js → infobipProvider-CHHsqRXy.js} +1 -1
  32. package/dist/packem_shared/{isValidSigningCertUrl-DNxPA0Q-.js → isValidSigningCertUrl-D7PuiRW4.js} +1 -1
  33. package/dist/packem_shared/{loopsProvider-Bz63so6m.js → loopsProvider-Cl-dOuCN.js} +1 -1
  34. package/dist/packem_shared/{mail.d-xKtvoKMK.d.ts → mail.d-B9JyPxzq.d.ts} +1 -0
  35. package/dist/packem_shared/{mailCrabProvider-bkQy-2a1.js → mailCrabProvider-De2YxPlF.js} +1 -1
  36. package/dist/packem_shared/{mailPaceProvider-S1AB-AYq.js → mailPaceProvider-DwNTuFb2.js} +1 -1
  37. package/dist/packem_shared/{mailchannelsProvider-B_K6X4VY.js → mailchannelsProvider-Dwl0Typz.js} +1 -1
  38. package/dist/packem_shared/{mailerSendProvider-DPEww2H1.js → mailerSendProvider-CyMIbqGq.js} +1 -1
  39. package/dist/packem_shared/{mailgunProvider-DKxzVbDW.js → mailgunProvider-DWKJYRKT.js} +1 -1
  40. package/dist/packem_shared/{mailjetProvider-C2TQcujL.js → mailjetProvider-DXPJQO1G.js} +1 -1
  41. package/dist/packem_shared/{mailomatProvider-B8-5bQsu.js → mailomatProvider-DopZk27y.js} +1 -1
  42. package/dist/packem_shared/{mailtrapProvider-DW7TLOdG.js → mailtrapProvider-CTg4z3GN.js} +1 -1
  43. package/dist/packem_shared/{make-request-CylyuRaN.js → make-request-CDhxj-9b.js} +1 -1
  44. package/dist/packem_shared/{mandrillProvider-S-0lKNGd.js → mandrillProvider-CAQeMtU_.js} +1 -1
  45. package/dist/packem_shared/{mockProvider-BAl292mW.js → mockProvider-EcpYlg-_.js} +1 -1
  46. package/dist/packem_shared/{netcoreProvider-DajMprlo.js → netcoreProvider-ua1avx07.js} +1 -1
  47. package/dist/packem_shared/{nodemailerProvider-DRo0lJ6g.js → nodemailerProvider-BZmQfKlM.js} +1 -1
  48. package/dist/packem_shared/{opentelemetryProvider-C6spx2CD.js → opentelemetryProvider-CAfWpywa.js} +1 -1
  49. package/dist/packem_shared/{outlook365Provider-B0o7UZBW.js → outlook365Provider-SFYELGDr.js} +1 -1
  50. package/dist/packem_shared/{plunkProvider-DJzEUEtU.js → plunkProvider-9amwuQri.js} +1 -1
  51. package/dist/packem_shared/{postalProvider-DHFjFE3Y.js → postalProvider-CeF3TOIW.js} +1 -1
  52. package/dist/packem_shared/{postmarkProvider-Dt1EGGBA.js → postmarkProvider-BPgKEkgF.js} +1 -1
  53. package/dist/packem_shared/{provider-base-DjPzWncP.js → provider-base-B-xhQSqE.js} +1 -1
  54. package/dist/packem_shared/{resendProvider-qjI86j_d.js → resendProvider-C9_sM8bH.js} +1 -1
  55. package/dist/packem_shared/{retry-CG9iT2wF.js → retry-D1Rh-6Z4.js} +1 -1
  56. package/dist/packem_shared/{roundRobinProvider-CO5YvhgR.js → roundRobinProvider-BPzLWZf-.js} +1 -1
  57. package/dist/packem_shared/{scalewayProvider-CihQKhw6.js → scalewayProvider-DfC7275i.js} +1 -1
  58. package/dist/packem_shared/{sendGridProvider-Dkc5AKlC.js → sendGridProvider-CUBBHBzs.js} +1 -1
  59. package/dist/packem_shared/smtpProvider-9nBSGtQl.js +27 -0
  60. package/dist/packem_shared/{sparkpostProvider-CKxQhpyB.js → sparkpostProvider-Be_d7S8o.js} +1 -1
  61. package/dist/packem_shared/{sweegoProvider-DjmAs6La.js → sweegoProvider-CP1cNC-d.js} +1 -1
  62. package/dist/packem_shared/{verifySendGridWebhook-1l9bqIMw.js → verifySendGridWebhook-DtFMgBRP.js} +1 -1
  63. package/dist/packem_shared/{withSuppression-BoaO4Qdz.js → withSuppression-wDl4NTb-.js} +1 -1
  64. package/dist/packem_shared/{zeptomailProvider-DSTC9pUi.js → zeptomailProvider-BZ0fK0Lk.js} +1 -1
  65. package/dist/providers/ahasend/index.js +1 -1
  66. package/dist/providers/autosend/index.js +1 -1
  67. package/dist/providers/aws-ses/index.js +1 -1
  68. package/dist/providers/azure/index.js +1 -1
  69. package/dist/providers/brevo/index.js +1 -1
  70. package/dist/providers/cloudflare-email/index.js +1 -1
  71. package/dist/providers/failover/index.js +1 -1
  72. package/dist/providers/http/index.js +1 -1
  73. package/dist/providers/infobip/index.js +1 -1
  74. package/dist/providers/loops/index.js +1 -1
  75. package/dist/providers/mailchannels/index.js +1 -1
  76. package/dist/providers/mailcrab/index.js +1 -1
  77. package/dist/providers/mailersend/index.js +1 -1
  78. package/dist/providers/mailgun/index.js +1 -1
  79. package/dist/providers/mailjet/index.js +1 -1
  80. package/dist/providers/mailomat/index.js +1 -1
  81. package/dist/providers/mailpace/index.js +1 -1
  82. package/dist/providers/mailtrap/index.js +1 -1
  83. package/dist/providers/mandrill/index.js +1 -1
  84. package/dist/providers/mock/index.js +1 -1
  85. package/dist/providers/netcore/index.js +1 -1
  86. package/dist/providers/nodemailer/index.js +1 -1
  87. package/dist/providers/opentelemetry/index.js +1 -1
  88. package/dist/providers/outlook365/index.js +1 -1
  89. package/dist/providers/plunk/index.js +1 -1
  90. package/dist/providers/postal/index.js +1 -1
  91. package/dist/providers/postmark/index.js +1 -1
  92. package/dist/providers/resend/index.js +1 -1
  93. package/dist/providers/roundrobin/index.js +1 -1
  94. package/dist/providers/scaleway/index.js +1 -1
  95. package/dist/providers/sendgrid/index.js +1 -1
  96. package/dist/providers/smtp/index.js +1 -1
  97. package/dist/providers/sparkpost/index.js +1 -1
  98. package/dist/providers/sweego/index.js +1 -1
  99. package/dist/providers/zeptomail/index.js +1 -1
  100. package/dist/render/css-inline.js +1 -1
  101. package/dist/template-engines/handlebars.js +1 -1
  102. package/dist/template-engines/html-to-text.js +1 -1
  103. package/dist/template-engines/i18n.js +1 -1
  104. package/dist/template-engines/jsx-email.js +1 -1
  105. package/dist/template-engines/liquid.js +1 -1
  106. package/dist/template-engines/mjml.js +1 -1
  107. package/dist/template-engines/react-email.js +1 -1
  108. package/dist/template-engines/vue-email.js +1 -1
  109. package/dist/test/index.d.ts +1 -1
  110. package/dist/test/index.js +1 -1
  111. package/dist/utils/format-email-address.js +1 -1
  112. package/dist/utils/parse-eml.js +3 -3
  113. package/dist/utils/result.js +1 -1
  114. package/dist/webhooks/index.js +1 -1
  115. package/package.json +1 -1
  116. package/dist/packem_shared/EmailError-CDvYwuqz.js +0 -1
  117. package/dist/packem_shared/Mail-CIyxkmxu.js +0 -1
  118. package/dist/packem_shared/build-mime-message-DT67qfMp.js +0 -3
  119. package/dist/packem_shared/index-Gd7m-UQA.js +0 -11
  120. package/dist/packem_shared/smtpProvider-CIXMxPu-.js +0 -25
@@ -1 +1 @@
1
- import c from"./EmailError-CDvYwuqz.js";import v from"./RequiredOptionError-DU2lxzk3.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as A}from"./headers-to-record-De1Eg951.js";import{m as d}from"./make-request-CylyuRaN.js";import{i as g}from"./retry-CG9iT2wF.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as T,h as y,c as U}from"./provider-base-DjPzWncP.js";import{d as u}from"./address-formatter-BWR2Dddx.js";import{p as z}from"./attachment-processor-D1cbAhQi.js";const r="infobip",E="https://api.infobip.com",k=3e4,j=3,H=P((s={})=>{if(!s.apiKey)throw new v(r,"apiKey");const p=s.baseUrl??E,h=s.endpoint??`${p}/email/3/send`,a={apiKey:s.apiKey,baseUrl:p,debug:s.debug??!1,endpoint:h,retries:s.retries??j,timeout:s.timeout??k,...s.logger&&{logger:s.logger}},m=new T,i=U(r,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const n={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${a.baseUrl}/email/3/reports/${e}`,{headers:n,method:"GET",timeout:a.timeout}),a.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(n){return{error:y(r,"retrieve email",n,i),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"Infobip API not available or invalid API key");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{i.debug("Checking Infobip API availability");const e={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};return(await d(`${a.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:a.timeout})).success}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:a,async sendEmail(e){try{const n=I(e);if(n.length>0)return{error:new c(r,`Invalid email options: ${n.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateData=e.templateVariables)),e.trackingUrl&&(t.trackingUrl=e.trackingUrl),e.notifyUrl&&(t.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(t.intermediateReport=e.intermediateReport),e.sendAt&&(t.sendAt=e.sendAt),e.headers){const l=A(e.headers);t.headers=l}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async l=>({content:await z(l,r),contentType:l.contentType??"application/octet-stream",name:l.filename})))),i.debug("Sending email via Infobip API",{subject:t.subject,to:t.to});const b={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"},o=await g(async()=>d(a.endpoint,{headers:b,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const f=o.data?.body?.messages?.[0]?.messageId??w();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:y(r,"send email",n,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
1
+ import c from"./EmailError-2CCyVX1S.js";import v from"./RequiredOptionError-BmpC5whN.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as A}from"./headers-to-record-De1Eg951.js";import{m as d}from"./make-request-CDhxj-9b.js";import{i as g}from"./retry-D1Rh-6Z4.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as T,h as y,c as U}from"./provider-base-B-xhQSqE.js";import{d as u}from"./address-formatter-bfmGfQ83.js";import{p as z}from"./attachment-processor-DjbjtJ6H.js";const r="infobip",E="https://api.infobip.com",k=3e4,j=3,H=P((s={})=>{if(!s.apiKey)throw new v(r,"apiKey");const p=s.baseUrl??E,h=s.endpoint??`${p}/email/3/send`,a={apiKey:s.apiKey,baseUrl:p,debug:s.debug??!1,endpoint:h,retries:s.retries??j,timeout:s.timeout??k,...s.logger&&{logger:s.logger}},m=new T,i=U(r,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const n={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${a.baseUrl}/email/3/reports/${e}`,{headers:n,method:"GET",timeout:a.timeout}),a.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(n){return{error:y(r,"retrieve email",n,i),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"Infobip API not available or invalid API key");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{i.debug("Checking Infobip API availability");const e={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};return(await d(`${a.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:a.timeout})).success}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:a,async sendEmail(e){try{const n=I(e);if(n.length>0)return{error:new c(r,`Invalid email options: ${n.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateData=e.templateVariables)),e.trackingUrl&&(t.trackingUrl=e.trackingUrl),e.notifyUrl&&(t.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(t.intermediateReport=e.intermediateReport),e.sendAt&&(t.sendAt=e.sendAt),e.headers){const l=A(e.headers);t.headers=l}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async l=>({content:await z(l,r),contentType:l.contentType??"application/octet-stream",name:l.filename})))),i.debug("Sending email via Infobip API",{subject:t.subject,to:t.to});const b={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"},o=await g(async()=>d(a.endpoint,{headers:b,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const f=o.data?.body?.messages?.[0]?.messageId??w();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:y(r,"send email",n,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
@@ -1,3 +1,3 @@
1
- import{createRequire as g}from"node:module";import o from"./EmailError-CDvYwuqz.js";let p;const m=e=>(p??=g(import.meta.url))(e),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,s]=n.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return n.getBuiltinModule(e)}return m(e)},{Buffer:d}=u("node:buffer"),{X509Certificate:S,createVerify:y}=u("node:crypto"),b={Notification:["Message","MessageId","Subject","Timestamp","TopicArn","Type"],SubscriptionConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"],UnsubscribeConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"]},h=/^sns\.[a-z0-9-]+\.amazonaws\.com(?:\.cn)?$/,w=/\.$/,T=e=>{let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:"||t.username!==""||t.password!==""||t.port!=="")return!1;const s=t.hostname.toLowerCase().replace(w,"");return h.test(s)},_=async e=>{if(!T(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=b[e.Type??""];if(!t)return;let s="";for(const i of t){const r=e[i];typeof r=="string"&&(s+=`${i}
1
+ import{createRequire as g}from"node:module";import o from"./EmailError-2CCyVX1S.js";let p;const m=e=>(p??=g(import.meta.url))(e),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,s]=n.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return n.getBuiltinModule(e)}return m(e)},{Buffer:d}=u("node:buffer"),{X509Certificate:S,createVerify:y}=u("node:crypto"),b={Notification:["Message","MessageId","Subject","Timestamp","TopicArn","Type"],SubscriptionConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"],UnsubscribeConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"]},h=/^sns\.[a-z0-9-]+\.amazonaws\.com(?:\.cn)?$/,w=/\.$/,T=e=>{let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:"||t.username!==""||t.password!==""||t.port!=="")return!1;const s=t.hostname.toLowerCase().replace(w,"");return h.test(s)},_=async e=>{if(!T(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=b[e.Type??""];if(!t)return;let s="";for(const i of t){const r=e[i];typeof r=="string"&&(s+=`${i}
2
2
  ${r}
3
3
  `)}return s},k=async(e,t={})=>{const{certificateResolver:s=_}=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 r;if(e.SignatureVersion==="1")r="RSA-SHA1";else if(e.SignatureVersion==="2")r="RSA-SHA256";else return{reason:"unknown-signature-version",valid:!1};const f=await s(e.SigningCertURL);let a;try{a=new S(f).publicKey}catch(l){throw new o("webhooks","Failed to parse SNS signing certificate",{cause:l})}let c;try{c=y(r).update(i,"utf8").verify(a,d.from(e.Signature,"base64"))}catch{return{reason:"signature-malformed",valid:!1}}return c?{valid:!0}:{reason:"signature-mismatch",valid:!1}};export{T as isValidSigningCertUrl,k as verifySnsMessage};
@@ -1 +1 @@
1
- import o from"./EmailError-CDvYwuqz.js";import f from"./RequiredOptionError-DU2lxzk3.js";import{e as g}from"./generate-message-id-gXAuMz4g.js";import{m as h}from"./make-request-CylyuRaN.js";import{i as y}from"./retry-CG9iT2wF.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{c as v}from"./attachment-processor-D1cbAhQi.js";import{h as w,P as T,c as A}from"./provider-base-DjPzWncP.js";const t="loops",I="https://app.loops.so/api/v1/transactional",P=3e4,K=3,E=b((a={})=>{if(!a.apiKey)throw new f(t,"apiKey");const r={apiKey:a.apiKey,debug:a.debug??!1,defaultTransactionalId:a.defaultTransactionalId,endpoint:a.endpoint??I,logger:a.logger,retries:a.retries??K,timeout:a.timeout??P},m=new T,p=A(t,a.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!1,html:!1,replyTo:!1,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){m.setInitialized()},async isAvailable(){return r.apiKey.length>0},name:t,options:r,async sendEmail(e){try{const s=e.transactionalId??r.defaultTransactionalId;if(!s)return{error:new o(t,"Loops requires a `transactionalId` (on the message or as `defaultTransactionalId`)"),success:!1};const l=Array.isArray(e.to)?e.to:[e.to];if(l.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new o(t,"Loops supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[d]=l;if(!d)return{error:new o(t,"A `to` recipient is required"),success:!1};const n={email:d.email,transactionalId:s};e.dataVariables&&(n.dataVariables=e.dataVariables),e.addToAudience&&(n.addToAudience=!0),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async u=>{const c=await v(u,t);return{contentType:c.contentType,data:c.content,filename:c.filename}})));const i=await y(async()=>h(r.endpoint,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);return i.success?{data:{messageId:g(),provider:t,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new o(t,"Failed to send email"),success:!1}}catch(s){return{error:w(t,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{E as default};
1
+ import o from"./EmailError-2CCyVX1S.js";import f from"./RequiredOptionError-BmpC5whN.js";import{e as g}from"./generate-message-id-gXAuMz4g.js";import{m as h}from"./make-request-CDhxj-9b.js";import{i as y}from"./retry-D1Rh-6Z4.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{c as v}from"./attachment-processor-DjbjtJ6H.js";import{h as w,P as T,c as A}from"./provider-base-B-xhQSqE.js";const t="loops",I="https://app.loops.so/api/v1/transactional",P=3e4,K=3,E=b((a={})=>{if(!a.apiKey)throw new f(t,"apiKey");const r={apiKey:a.apiKey,debug:a.debug??!1,defaultTransactionalId:a.defaultTransactionalId,endpoint:a.endpoint??I,logger:a.logger,retries:a.retries??K,timeout:a.timeout??P},m=new T,p=A(t,a.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!1,html:!1,replyTo:!1,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){m.setInitialized()},async isAvailable(){return r.apiKey.length>0},name:t,options:r,async sendEmail(e){try{const s=e.transactionalId??r.defaultTransactionalId;if(!s)return{error:new o(t,"Loops requires a `transactionalId` (on the message or as `defaultTransactionalId`)"),success:!1};const l=Array.isArray(e.to)?e.to:[e.to];if(l.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new o(t,"Loops supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[d]=l;if(!d)return{error:new o(t,"A `to` recipient is required"),success:!1};const n={email:d.email,transactionalId:s};e.dataVariables&&(n.dataVariables=e.dataVariables),e.addToAudience&&(n.addToAudience=!0),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async u=>{const c=await v(u,t);return{contentType:c.contentType,data:c.content,filename:c.filename}})));const i=await y(async()=>h(r.endpoint,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);return i.success?{data:{messageId:g(),provider:t,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new o(t,"Failed to send email"),success:!1}}catch(s){return{error:w(t,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{E as default};
@@ -857,6 +857,7 @@ declare class Mail {
857
857
  /**
858
858
  * Runs the fail-fast capability guard for the configured {@link FeatureCheckMode}.
859
859
  * @param emailOptions The fully-resolved email options about to be sent.
860
+ * @param provider The provider that will actually handle the message (mounted stream provider or default).
860
861
  * @returns An {@link EmailError} when the send should be rejected, otherwise undefined.
861
862
  * @private
862
863
  */
@@ -1 +1 @@
1
- import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import o from"./smtpProvider-CIXMxPu-.js";const s="mailcrab",u="localhost",n=1025,g=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},a=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 a.initialize()},async isAvailable(){return a.isAvailable()},name:s,options:e,async sendEmail(i){const r=await a.sendEmail(i);return r.success&&r.data?{data:{...r.data,provider:s},success:!0}:r},async validateCredentials(){return a.validateCredentials?.()??!1}}});export{g as default};
1
+ import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import o from"./smtpProvider-9nBSGtQl.js";const s="mailcrab",u="localhost",n=1025,g=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},a=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 a.initialize()},async isAvailable(){return a.isAvailable()},name:s,options:e,async sendEmail(i){const r=await a.sendEmail(i);return r.success&&r.data?{data:{...r.data,provider:s},success:!0}:r},async validateCredentials(){return a.validateCredentials?.()??!1}}});export{g as default};
@@ -1 +1 @@
1
- import c from"./EmailError-CDvYwuqz.js";import P from"./RequiredOptionError-DU2lxzk3.js";import{e as I}from"./generate-message-id-gXAuMz4g.js";import{s as T}from"./headers-to-record-De1Eg951.js";import{m as d}from"./make-request-CylyuRaN.js";import{i as g}from"./retry-CG9iT2wF.js";import{s as A,a as k}from"./sanitize-header-DtQwAnzg.js";import{f as z}from"./validate-email-options-mCM9dVug.js";import{defineProvider as j}from"./defineProvider-C9q-7iwt.js";import{P as E,h as f,c as C}from"./provider-base-DjPzWncP.js";import{j as u,g as h}from"./address-formatter-BWR2Dddx.js";const r="mailpace",M="https://app.mailpace.com/api/v1",S=3e4,q=3,R=j((o={})=>{if(!o.apiToken)throw new P(r,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??q,timeout:o.timeout??S,...o.logger&&{logger:o.logger}},l=new E,i=C(r,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(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=z(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[A(v)]=k(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},n=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new c(r,"Failed to send email"),success:!1};const m=n.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
1
+ import c from"./EmailError-2CCyVX1S.js";import P from"./RequiredOptionError-BmpC5whN.js";import{e as I}from"./generate-message-id-gXAuMz4g.js";import{s as T}from"./headers-to-record-De1Eg951.js";import{m as d}from"./make-request-CDhxj-9b.js";import{i as g}from"./retry-D1Rh-6Z4.js";import{s as A,a as k}from"./sanitize-header-DtQwAnzg.js";import{f as z}from"./validate-email-options-mCM9dVug.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{P as j,h as f,c as C}from"./provider-base-B-xhQSqE.js";import{m as u,g as h}from"./address-formatter-bfmGfQ83.js";const r="mailpace",M="https://app.mailpace.com/api/v1",S=3e4,q=3,R=E((o={})=>{if(!o.apiToken)throw new P(r,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??q,timeout:o.timeout??S,...o.logger&&{logger:o.logger}},l=new j,i=C(r,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(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=z(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[A(v)]=k(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},n=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new c(r,"Failed to send email"),success:!1};const m=n.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
@@ -1 +1 @@
1
- import p from"./EmailError-CDvYwuqz.js";import g from"./RequiredOptionError-DU2lxzk3.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{s as b}from"./headers-to-record-De1Eg951.js";import{m as w}from"./make-request-CylyuRaN.js";import{i as K}from"./retry-CG9iT2wF.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{f as l,a as u}from"./address-formatter-BWR2Dddx.js";import{c as x}from"./attachment-processor-D1cbAhQi.js";import{h as A,P as T,c as j}from"./provider-base-DjPzWncP.js";const a="mailchannels",I="https://api.mailchannels.net/tx/v1/send",_=3e4,z=3,N=P((t={})=>{if(!t.apiKey)throw new g(a,"apiKey");const r={apiKey:t.apiKey,debug:t.debug??!1,endpoint:t.endpoint??I,logger:t.logger,retries:t.retries??z,timeout:t.timeout??_},f=new T,h=j(a,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){f.setInitialized()},async isAvailable(){return r.apiKey.length>0},name:a,options:r,async sendEmail(e){try{const s=S(e);if(s.length>0)return{error:new p(a,`Invalid email options: ${s.join(", ")}`),success:!1};const o=[];e.text&&o.push({type:"text/plain",value:e.text}),e.html&&o.push({type:"text/html",value:e.html});const c={to:l(e.to)};e.cc&&(c.cc=l(e.cc)),e.bcc&&(c.bcc=l(e.bcc));const n={content:o,from:u(e.from),personalizations:[c],subject:e.subject};e.replyTo&&(n.reply_to=u(e.replyTo)),e.headers&&(n.headers=b(e.headers)),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async y=>{const m=await x(y,a);return{content:m.content,filename:m.filename,type:m.contentType}})));const i=await K(async()=>w(r.endpoint,{headers:{"Content-Type":"application/json","X-Api-Key":r.apiKey},method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);if(!i.success)return{error:i.error??new p(a,"Failed to send email"),success:!1};const{body:d}=i.data;return{data:{messageId:d?.message_id??d?.request_id??v(),provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:A(a,"send email",s,h),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{N as default};
1
+ import p from"./EmailError-2CCyVX1S.js";import g from"./RequiredOptionError-BmpC5whN.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{s as b}from"./headers-to-record-De1Eg951.js";import{m as w}from"./make-request-CDhxj-9b.js";import{i as K}from"./retry-D1Rh-6Z4.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{f as l,a as u}from"./address-formatter-bfmGfQ83.js";import{c as x}from"./attachment-processor-DjbjtJ6H.js";import{h as A,P as T,c as j}from"./provider-base-B-xhQSqE.js";const a="mailchannels",I="https://api.mailchannels.net/tx/v1/send",_=3e4,z=3,N=P((t={})=>{if(!t.apiKey)throw new g(a,"apiKey");const r={apiKey:t.apiKey,debug:t.debug??!1,endpoint:t.endpoint??I,logger:t.logger,retries:t.retries??z,timeout:t.timeout??_},f=new T,h=j(a,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){f.setInitialized()},async isAvailable(){return r.apiKey.length>0},name:a,options:r,async sendEmail(e){try{const s=S(e);if(s.length>0)return{error:new p(a,`Invalid email options: ${s.join(", ")}`),success:!1};const o=[];e.text&&o.push({type:"text/plain",value:e.text}),e.html&&o.push({type:"text/html",value:e.html});const c={to:l(e.to)};e.cc&&(c.cc=l(e.cc)),e.bcc&&(c.bcc=l(e.bcc));const n={content:o,from:u(e.from),personalizations:[c],subject:e.subject};e.replyTo&&(n.reply_to=u(e.replyTo)),e.headers&&(n.headers=b(e.headers)),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async y=>{const m=await x(y,a);return{content:m.content,filename:m.filename,type:m.contentType}})));const i=await K(async()=>w(r.endpoint,{headers:{"Content-Type":"application/json","X-Api-Key":r.apiKey},method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);if(!i.success)return{error:i.error??new p(a,"Failed to send email"),success:!1};const{body:d}=i.data;return{data:{messageId:d?.message_id??d?.request_id??v(),provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:A(a,"send email",s,h),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{N as default};
@@ -1 +1 @@
1
- import l from"./EmailError-CDvYwuqz.js";import y from"./RequiredOptionError-DU2lxzk3.js";import{e as b}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CylyuRaN.js";import{i as g}from"./retry-CG9iT2wF.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{P as A,h as f,c as T}from"./provider-base-DjPzWncP.js";import{f as u,a as k}from"./address-formatter-BWR2Dddx.js";import{p as P}from"./attachment-processor-D1cbAhQi.js";const r="mailersend",z="https://api.mailersend.com",C=3e4,S=3,O=I((n={})=>{if(!n.apiToken)throw new y(r,"apiToken");const i={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??z,retries:n.retries??S,timeout:n.timeout??C,...n.logger&&{logger:n.logger}},c=new A,s=T(r,n.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(r,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const t=await g(async()=>m(`${i.endpoint}/v1/activity/${e}`,{headers:a,method:"GET",timeout:i.timeout}),i.retries);return t.success?(s.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(s.debug("API request failed when retrieving email",t.error),{error:new l(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,s),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(r,"MailerSend API not available or invalid API token");s.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"};s.debug("Checking MailerSend API availability");const a=await m(`${i.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:i.timeout});return s.debug("MailerSend API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return s.debug("Error checking availability:",e),!1}},name:r,options:i,async sendEmail(e){try{const a=w(e);if(a.length>0)return{error:new l(r,`Invalid email options: ${a.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),r);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.reply_to=k(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(t.personalization=e.personalization),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.scheduledAt&&(t.send_at=e.scheduledAt),e.domainId&&(t.domain_id=e.domainId),e.headers){const o=v(e.headers);t.headers=o}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async o=>({content:await P(o,r),filename:o.filename,...o.contentType&&{type:o.contentType},...o.cid&&{id:o.cid}})))),s.debug("Sending email via MailerSend API",{subject:t.subject,to:t.to});const h={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"},d=await g(async()=>m(`${i.endpoint}/v1/email`,{headers:h,method:"POST",timeout:i.timeout},JSON.stringify(t)),i.retries);if(!d.success)return s.debug("API request failed when sending email",d.error),{error:d.error??new l(r,"Failed to send email"),success:!1};const p=d.data?.body?.message_id??b();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:r,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
1
+ import l from"./EmailError-2CCyVX1S.js";import y from"./RequiredOptionError-BmpC5whN.js";import{e as b}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CDhxj-9b.js";import{i as g}from"./retry-D1Rh-6Z4.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{P as A,h as f,c as T}from"./provider-base-B-xhQSqE.js";import{f as u,a as k}from"./address-formatter-bfmGfQ83.js";import{p as P}from"./attachment-processor-DjbjtJ6H.js";const r="mailersend",z="https://api.mailersend.com",C=3e4,S=3,O=I((n={})=>{if(!n.apiToken)throw new y(r,"apiToken");const i={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??z,retries:n.retries??S,timeout:n.timeout??C,...n.logger&&{logger:n.logger}},c=new A,s=T(r,n.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(r,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const t=await g(async()=>m(`${i.endpoint}/v1/activity/${e}`,{headers:a,method:"GET",timeout:i.timeout}),i.retries);return t.success?(s.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(s.debug("API request failed when retrieving email",t.error),{error:new l(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,s),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(r,"MailerSend API not available or invalid API token");s.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"};s.debug("Checking MailerSend API availability");const a=await m(`${i.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:i.timeout});return s.debug("MailerSend API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return s.debug("Error checking availability:",e),!1}},name:r,options:i,async sendEmail(e){try{const a=w(e);if(a.length>0)return{error:new l(r,`Invalid email options: ${a.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),r);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.reply_to=k(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(t.personalization=e.personalization),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.scheduledAt&&(t.send_at=e.scheduledAt),e.domainId&&(t.domain_id=e.domainId),e.headers){const o=v(e.headers);t.headers=o}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async o=>({content:await P(o,r),filename:o.filename,...o.contentType&&{type:o.contentType},...o.cid&&{id:o.cid}})))),s.debug("Sending email via MailerSend API",{subject:t.subject,to:t.to});const h={Authorization:`Bearer ${i.apiToken}`,"Content-Type":"application/json"},d=await g(async()=>m(`${i.endpoint}/v1/email`,{headers:h,method:"POST",timeout:i.timeout},JSON.stringify(t)),i.retries);if(!d.success)return s.debug("API request failed when sending email",d.error),{error:d.error??new l(r,"Failed to send email"),success:!1};const p=d.data?.body?.message_id??b();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:r,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
@@ -1 +1 @@
1
- import{createRequire as I}from"node:module";import m from"./EmailError-CDvYwuqz.js";import w from"./RequiredOptionError-DU2lxzk3.js";import{e as _}from"./generate-message-id-gXAuMz4g.js";import{s as R}from"./headers-to-record-De1Eg951.js";import{m as h}from"./make-request-CylyuRaN.js";import{i as T}from"./retry-CG9iT2wF.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{P as E,h as j,c as q}from"./provider-base-DjPzWncP.js";import{e as b,g as k}from"./address-formatter-BWR2Dddx.js";import{a as U}from"./attachment-processor-D1cbAhQi.js";let A;const C=o=>(A??=I(import.meta.url))(o),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=o=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,n]=u.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return u.getBuiltinModule(o)}return C(o)},{Buffer:y}=P("node:buffer"),a="mailgun",M="https://api.mailgun.net",K=3e4,B=3,x=o=>{const r=[];for(const[n,i]of Object.entries(o))if(i!=null)if(Array.isArray(i))for(const e of i)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof i=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(i))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(i))}`);return r.join("&")},Y=z((o={})=>{if(!o.apiKey)throw new w(a,"apiKey");if(!o.domain)throw new w(a,"domain");const r={apiKey:o.apiKey,debug:o.debug??!1,domain:o.domain,endpoint:o.endpoint??M,retries:o.retries??B,timeout:o.timeout??K,...o.logger&&{logger:o.logger}},n=new E,i=q(a,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 m(a,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),a);const s={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await T(async()=>h(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:s,method:"GET",timeout:r.timeout}),r.retries);if(!t.success)return i.debug("API request failed when retrieving email",t.error),{error:new m(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1};i.debug("Email details retrieved successfully");const p=t.data?.items??[],g=p.length>0?p[0]:void 0;return{data:g?.message?.headers??g?.storage??void 0,success:!0}}catch(s){return{error:j(a,"retrieve email",s,i),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(a,"Mailgun API not available or invalid API key/domain");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Checking Mailgun API availability");const s=await h(`${r.endpoint}/v3/domains/${r.domain}`,{headers:e,method:"GET",timeout:r.timeout});if(i.debug("Mailgun API availability check response:",{error:s.error instanceof Error?s.error.message:void 0,statusCode:s.data?.statusCode,success:s.success}),!s.success||!s.data||typeof s.data!="object")return!1;const{statusCode:t}=s.data;return typeof t=="number"&&t>=200&&t<300}catch(e){return i.debug("Error checking availability:",e),!1}},name:a,options:r,async sendEmail(e){try{const s=S(e);if(s.length>0)return{error:new m(a,`Invalid email options: ${s.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),a);const t={from:k(e.from),to:b(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=b(e.cc).join(",")),e.bcc&&(t.bcc=b(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=k(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[d,c]of Object.entries(e.templateVariables))t[`v:${d}`]=c;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const d=R(e.headers);for(const[c,f]of Object.entries(d))t[`h:${c}`]=f}if(e.attachments&&e.attachments.length>0){const d=await Promise.all(e.attachments.map((c,f)=>U(c,a,f)));for(const c of d)t[c.key]=c.content}i.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const p={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=x(t),l=await T(async()=>h(`${r.endpoint}/v3/${r.domain}/messages`,{headers:p,method:"POST",timeout:r.timeout},g),r.retries);if(!l.success)return i.debug("API request failed when sending email",l.error),{error:l.error??new m(a,"Failed to send email"),success:!1};const v=l.data?.body?.id??_();return i.debug("Email sent successfully",{messageId:v}),{data:{messageId:v,provider:a,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:j(a,"send email",s,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
1
+ import{createRequire as I}from"node:module";import m from"./EmailError-2CCyVX1S.js";import w from"./RequiredOptionError-BmpC5whN.js";import{e as _}from"./generate-message-id-gXAuMz4g.js";import{s as R}from"./headers-to-record-De1Eg951.js";import{m as h}from"./make-request-CDhxj-9b.js";import{i as T}from"./retry-D1Rh-6Z4.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{P as E,h as j,c as q}from"./provider-base-B-xhQSqE.js";import{e as b,g as k}from"./address-formatter-bfmGfQ83.js";import{a as U}from"./attachment-processor-DjbjtJ6H.js";let A;const C=o=>(A??=I(import.meta.url))(o),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=o=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,n]=u.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return u.getBuiltinModule(o)}return C(o)},{Buffer:y}=P("node:buffer"),a="mailgun",M="https://api.mailgun.net",K=3e4,B=3,x=o=>{const r=[];for(const[n,i]of Object.entries(o))if(i!=null)if(Array.isArray(i))for(const e of i)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof i=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(i))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(i))}`);return r.join("&")},Y=z((o={})=>{if(!o.apiKey)throw new w(a,"apiKey");if(!o.domain)throw new w(a,"domain");const r={apiKey:o.apiKey,debug:o.debug??!1,domain:o.domain,endpoint:o.endpoint??M,retries:o.retries??B,timeout:o.timeout??K,...o.logger&&{logger:o.logger}},n=new E,i=q(a,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 m(a,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),a);const s={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await T(async()=>h(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:s,method:"GET",timeout:r.timeout}),r.retries);if(!t.success)return i.debug("API request failed when retrieving email",t.error),{error:new m(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1};i.debug("Email details retrieved successfully");const p=t.data?.items??[],g=p.length>0?p[0]:void 0;return{data:g?.message?.headers??g?.storage??void 0,success:!0}}catch(s){return{error:j(a,"retrieve email",s,i),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(a,"Mailgun API not available or invalid API key/domain");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Checking Mailgun API availability");const s=await h(`${r.endpoint}/v3/domains/${r.domain}`,{headers:e,method:"GET",timeout:r.timeout});if(i.debug("Mailgun API availability check response:",{error:s.error instanceof Error?s.error.message:void 0,statusCode:s.data?.statusCode,success:s.success}),!s.success||!s.data||typeof s.data!="object")return!1;const{statusCode:t}=s.data;return typeof t=="number"&&t>=200&&t<300}catch(e){return i.debug("Error checking availability:",e),!1}},name:a,options:r,async sendEmail(e){try{const s=S(e);if(s.length>0)return{error:new m(a,`Invalid email options: ${s.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),a);const t={from:k(e.from),to:b(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=b(e.cc).join(",")),e.bcc&&(t.bcc=b(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=k(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[d,c]of Object.entries(e.templateVariables))t[`v:${d}`]=c;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const d=R(e.headers);for(const[c,f]of Object.entries(d))t[`h:${c}`]=f}if(e.attachments&&e.attachments.length>0){const d=await Promise.all(e.attachments.map((c,f)=>U(c,a,f)));for(const c of d)t[c.key]=c.content}i.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const p={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=x(t),l=await T(async()=>h(`${r.endpoint}/v3/${r.domain}/messages`,{headers:p,method:"POST",timeout:r.timeout},g),r.retries);if(!l.success)return i.debug("API request failed when sending email",l.error),{error:l.error??new m(a,"Failed to send email"),success:!1};const v=l.data?.body?.id??_();return i.debug("Email sent successfully",{messageId:v}),{data:{messageId:v,provider:a,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:j(a,"send email",s,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
@@ -1 +1 @@
1
- import{createRequire as S}from"node:module";import u from"./EmailError-CDvYwuqz.js";import h from"./RequiredOptionError-DU2lxzk3.js";import{e as E}from"./generate-message-id-gXAuMz4g.js";import{s as M}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CylyuRaN.js";import{i as b}from"./retry-CG9iT2wF.js";import{f as z}from"./validate-email-options-mCM9dVug.js";import{defineProvider as D}from"./defineProvider-C9q-7iwt.js";import{P as R,h as v,c as q}from"./provider-base-DjPzWncP.js";import{h as f,i as T}from"./address-formatter-BWR2Dddx.js";import{p as B}from"./attachment-processor-D1cbAhQi.js";let P;const A=i=>(P??=S(import.meta.url))(i),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=i=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[a,c]=d.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return d.getBuiltinModule(i)}return A(i)},{Buffer:p}=_("node:buffer"),s="mailjet",k="https://api.mailjet.com",K=3e4,L=3,Y=D((i={})=>{if(!i.apiKey)throw new h(s,"apiKey");if(!i.apiSecret)throw new h(s,"apiSecret");const a={apiKey:i.apiKey,apiSecret:i.apiSecret,debug:i.debug??!1,endpoint:i.endpoint??k,retries:i.retries??L,timeout:i.timeout??K,...i.logger&&{logger:i.logger}},c=new R,o=q(s,i.logger);return{endpoint:a.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 c.ensureInitialized(()=>this.initialize(),s);const r={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await b(async()=>g(`${a.endpoint}/v3.1/REST/message/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new u(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:v(s,"retrieve email",r,o),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(s,"Mailjet API not available or invalid API credentials");o.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailjet API availability");const r=await g(`${a.endpoint}/v3.1/REST/user`,{headers:e,method:"GET",timeout:a.timeout});return o.debug("Mailjet 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:s,options:a,async sendEmail(e){try{const r=z(e);if(r.length>0)return{error:new u(s,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const t={From:T(e.from),Subject:e.subject,To:f(e.to)};if(e.html&&(t.HTMLPart=e.html),e.text&&(t.TextPart=e.text),e.cc&&(t.Cc=f(e.cc)),e.bcc&&(t.Bcc=f(e.bcc)),e.replyTo&&(t.ReplyTo=T(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 n=M(e.headers),m=[];for(const[C,I]of Object.entries(n))m.push({Name:C,Value:String(I)});m.length>0&&(t.Headers=m)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async n=>({Base64Content:await B(n,s),ContentType:n.contentType??"application/octet-stream",Filename:n.filename,...n.cid&&{ContentID:n.cid}}))));const j={Messages:[t]};o.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const w={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},l=await b(async()=>g(`${a.endpoint}/v3.1/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(j)),a.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new u(s,"Failed to send email"),success:!1};const y=l.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??E();return o.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:v(s,"send email",r,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
1
+ import{createRequire as S}from"node:module";import u from"./EmailError-2CCyVX1S.js";import h from"./RequiredOptionError-BmpC5whN.js";import{e as E}from"./generate-message-id-gXAuMz4g.js";import{s as M}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CDhxj-9b.js";import{i as b}from"./retry-D1Rh-6Z4.js";import{f as z}from"./validate-email-options-mCM9dVug.js";import{defineProvider as D}from"./defineProvider-C9q-7iwt.js";import{P as R,h as v,c as q}from"./provider-base-B-xhQSqE.js";import{h as f,i as T}from"./address-formatter-bfmGfQ83.js";import{p as B}from"./attachment-processor-DjbjtJ6H.js";let P;const A=i=>(P??=S(import.meta.url))(i),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=i=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[a,c]=d.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return d.getBuiltinModule(i)}return A(i)},{Buffer:p}=_("node:buffer"),s="mailjet",k="https://api.mailjet.com",K=3e4,L=3,Y=D((i={})=>{if(!i.apiKey)throw new h(s,"apiKey");if(!i.apiSecret)throw new h(s,"apiSecret");const a={apiKey:i.apiKey,apiSecret:i.apiSecret,debug:i.debug??!1,endpoint:i.endpoint??k,retries:i.retries??L,timeout:i.timeout??K,...i.logger&&{logger:i.logger}},c=new R,o=q(s,i.logger);return{endpoint:a.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 c.ensureInitialized(()=>this.initialize(),s);const r={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await b(async()=>g(`${a.endpoint}/v3.1/REST/message/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new u(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:v(s,"retrieve email",r,o),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(s,"Mailjet API not available or invalid API credentials");o.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailjet API availability");const r=await g(`${a.endpoint}/v3.1/REST/user`,{headers:e,method:"GET",timeout:a.timeout});return o.debug("Mailjet 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:s,options:a,async sendEmail(e){try{const r=z(e);if(r.length>0)return{error:new u(s,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const t={From:T(e.from),Subject:e.subject,To:f(e.to)};if(e.html&&(t.HTMLPart=e.html),e.text&&(t.TextPart=e.text),e.cc&&(t.Cc=f(e.cc)),e.bcc&&(t.Bcc=f(e.bcc)),e.replyTo&&(t.ReplyTo=T(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 n=M(e.headers),m=[];for(const[C,I]of Object.entries(n))m.push({Name:C,Value:String(I)});m.length>0&&(t.Headers=m)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async n=>({Base64Content:await B(n,s),ContentType:n.contentType??"application/octet-stream",Filename:n.filename,...n.cid&&{ContentID:n.cid}}))));const j={Messages:[t]};o.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const w={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},l=await b(async()=>g(`${a.endpoint}/v3.1/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(j)),a.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new u(s,"Failed to send email"),success:!1};const y=l.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??E();return o.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:v(s,"send email",r,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
@@ -1 +1 @@
1
- import c from"./EmailError-CDvYwuqz.js";import b from"./RequiredOptionError-DU2lxzk3.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{s as w}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CylyuRaN.js";import{i as f}from"./retry-CG9iT2wF.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as A,h,c as T}from"./provider-base-DjPzWncP.js";import{f as d,a as E}from"./address-formatter-BWR2Dddx.js";import{p as K}from"./attachment-processor-D1cbAhQi.js";const a="mailomat",S="https://api.mailomat.com",j=3e4,k=3,X=P((i={})=>{if(!i.apiKey)throw new b(a,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??S,retries:i.retries??k,timeout:i.timeout??j,...i.logger&&{logger:i.logger}},m=new A,r=T(a,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),a);const o={"Content-Type":"application/json","X-API-Key":s.apiKey};r.debug("Retrieving email details",{id:e});const t=await f(async()=>g(`${s.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:s.timeout}),s.retries);return t.success?(r.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(r.debug("API request failed when retrieving email",t.error),{error:new c(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:h(a,"retrieve email",o,r),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Mailomat API not available or invalid API key");r.debug("Provider initialized successfully")},a)},async isAvailable(){try{return r.debug("Checking Mailomat API availability"),!0}catch(e){return r.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new c(a,`Invalid email options: ${o.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),a);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:d(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=d(e.cc)),e.bcc&&(t.bcc=d(e.bcc)),e.replyTo&&(t.replyTo=E(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const n=w(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>({content:await K(n,a),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),r.debug("Sending email via Mailomat API",{subject:t.subject,to:t.to});const y={"Content-Type":"application/json","X-API-Key":s.apiKey},l=await f(async()=>g(`${s.endpoint}/send`,{headers:y,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!l.success)return r.debug("API request failed when sending email",l.error),{error:l.error??new c(a,"Failed to send email"),success:!1};const u=l.data?.body,p=u?.messageId??u?.id??v();return r.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:a,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(a,"send email",o,r),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{X as default};
1
+ import c from"./EmailError-2CCyVX1S.js";import b from"./RequiredOptionError-BmpC5whN.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{s as w}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CDhxj-9b.js";import{i as f}from"./retry-D1Rh-6Z4.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as A,h,c as T}from"./provider-base-B-xhQSqE.js";import{f as d,a as E}from"./address-formatter-bfmGfQ83.js";import{p as K}from"./attachment-processor-DjbjtJ6H.js";const a="mailomat",S="https://api.mailomat.com",j=3e4,k=3,X=P((i={})=>{if(!i.apiKey)throw new b(a,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??S,retries:i.retries??k,timeout:i.timeout??j,...i.logger&&{logger:i.logger}},m=new A,r=T(a,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),a);const o={"Content-Type":"application/json","X-API-Key":s.apiKey};r.debug("Retrieving email details",{id:e});const t=await f(async()=>g(`${s.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:s.timeout}),s.retries);return t.success?(r.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(r.debug("API request failed when retrieving email",t.error),{error:new c(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:h(a,"retrieve email",o,r),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Mailomat API not available or invalid API key");r.debug("Provider initialized successfully")},a)},async isAvailable(){try{return r.debug("Checking Mailomat API availability"),!0}catch(e){return r.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new c(a,`Invalid email options: ${o.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),a);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:d(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=d(e.cc)),e.bcc&&(t.bcc=d(e.bcc)),e.replyTo&&(t.replyTo=E(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const n=w(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>({content:await K(n,a),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),r.debug("Sending email via Mailomat API",{subject:t.subject,to:t.to});const y={"Content-Type":"application/json","X-API-Key":s.apiKey},l=await f(async()=>g(`${s.endpoint}/send`,{headers:y,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!l.success)return r.debug("API request failed when sending email",l.error),{error:l.error??new c(a,"Failed to send email"),success:!1};const u=l.data?.body,p=u?.messageId??u?.id??v();return r.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:a,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(a,"send email",o,r),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{X as default};
@@ -1 +1 @@
1
- import l from"./EmailError-CDvYwuqz.js";import b from"./RequiredOptionError-DU2lxzk3.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CylyuRaN.js";import{i as g}from"./retry-CG9iT2wF.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{P as k,h as f,c as A}from"./provider-base-DjPzWncP.js";import{f as u,a as I}from"./address-formatter-BWR2Dddx.js";import{p as P}from"./attachment-processor-D1cbAhQi.js";const r="mailtrap",C="https://send.api.mailtrap.io",E=3e4,j=3,F=T((o={})=>{if(!o.apiToken)throw new b(r,"apiToken");const i={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??C,retries:o.retries??j,timeout:o.timeout??E,...o.logger&&{logger:o.logger}},d=new k,s=A(r,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 l(r,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),r);const a={"Api-Token":i.apiToken,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const t=await g(async()=>m(`${i.endpoint}/api/send/${e}`,{headers:a,method:"GET",timeout:i.timeout}),i.retries);return t.success?(s.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(s.debug("API request failed when retrieving email",t.error),{error:new l(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,s),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(r,"Mailtrap API not available or invalid API token");s.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={"Api-Token":i.apiToken,"Content-Type":"application/json"};s.debug("Checking Mailtrap API availability");const a=await m(`${i.endpoint}/api/account`,{headers:e,method:"GET",timeout:i.timeout});return s.debug("Mailtrap API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return s.debug("Error checking availability:",e),!1}},name:r,options:i,async sendEmail(e){try{const a=w(e);if(a.length>0)return{error:new l(r,`Invalid email options: ${a.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),r);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.reply_to=I(e.replyTo)),e.templateUuid&&(t.template_uuid=e.templateUuid,e.templateVariables&&(t.template_variables=e.templateVariables)),e.category&&(t.category=e.category),e.customVariables&&(t.custom_variables=e.customVariables),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const n=v(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,r),filename:n.filename,type:n.contentType??"application/octet-stream",...n.cid&&{cid:n.cid}})))),s.debug("Sending email via Mailtrap API",{subject:t.subject,to:t.to});const h={"Api-Token":i.apiToken,"Content-Type":"application/json"},c=await g(async()=>m(`${i.endpoint}/api/send`,{headers:h,method:"POST",timeout:i.timeout},JSON.stringify(t)),i.retries);if(!c.success)return s.debug("API request failed when sending email",c.error),{error:c.error??new l(r,"Failed to send email"),success:!1};const p=c.data?.body?.message_ids?.[0]??y();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{F as default};
1
+ import l from"./EmailError-2CCyVX1S.js";import b from"./RequiredOptionError-BmpC5whN.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CDhxj-9b.js";import{i as g}from"./retry-D1Rh-6Z4.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{P as k,h as f,c as A}from"./provider-base-B-xhQSqE.js";import{f as u,a as I}from"./address-formatter-bfmGfQ83.js";import{p as P}from"./attachment-processor-DjbjtJ6H.js";const r="mailtrap",C="https://send.api.mailtrap.io",E=3e4,j=3,F=T((o={})=>{if(!o.apiToken)throw new b(r,"apiToken");const i={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??C,retries:o.retries??j,timeout:o.timeout??E,...o.logger&&{logger:o.logger}},d=new k,s=A(r,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 l(r,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),r);const a={"Api-Token":i.apiToken,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const t=await g(async()=>m(`${i.endpoint}/api/send/${e}`,{headers:a,method:"GET",timeout:i.timeout}),i.retries);return t.success?(s.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(s.debug("API request failed when retrieving email",t.error),{error:new l(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,s),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(r,"Mailtrap API not available or invalid API token");s.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={"Api-Token":i.apiToken,"Content-Type":"application/json"};s.debug("Checking Mailtrap API availability");const a=await m(`${i.endpoint}/api/account`,{headers:e,method:"GET",timeout:i.timeout});return s.debug("Mailtrap API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return s.debug("Error checking availability:",e),!1}},name:r,options:i,async sendEmail(e){try{const a=w(e);if(a.length>0)return{error:new l(r,`Invalid email options: ${a.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),r);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.reply_to=I(e.replyTo)),e.templateUuid&&(t.template_uuid=e.templateUuid,e.templateVariables&&(t.template_variables=e.templateVariables)),e.category&&(t.category=e.category),e.customVariables&&(t.custom_variables=e.customVariables),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const n=v(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,r),filename:n.filename,type:n.contentType??"application/octet-stream",...n.cid&&{cid:n.cid}})))),s.debug("Sending email via Mailtrap API",{subject:t.subject,to:t.to});const h={"Api-Token":i.apiToken,"Content-Type":"application/json"},c=await g(async()=>m(`${i.endpoint}/api/send`,{headers:h,method:"POST",timeout:i.timeout},JSON.stringify(t)),i.retries);if(!c.success)return s.debug("API request failed when sending email",c.error),{error:c.error??new l(r,"Failed to send email"),success:!1};const p=c.data?.body?.message_ids?.[0]??y();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{F as default};
@@ -1 +1 @@
1
- import d from"./EmailError-CDvYwuqz.js";const y=globalThis.Buffer!==void 0,E="ETIMEDOUT",T=async(i,s={},r)=>{const l=typeof i=="string"?new URL(i):i;try{const e=new Headers;s.headers&&Object.entries(s.headers).forEach(([t,u])=>{e.set(t,u)});const o={headers:e,method:s.method??(r?"POST":"GET")};r&&(typeof r=="string"||r instanceof Uint8Array?o.body=r:y&&r instanceof globalThis.Buffer?o.body=new Uint8Array(r):o.body=new Uint8Array(r));let c,a;s.timeout&&(c=new AbortController,a=setTimeout(()=>{c?.abort()},s.timeout),o.signal=c.signal);try{const t=await fetch(l.toString(),o);a&&clearTimeout(a);const u=(t.headers.get("content-type")??"").includes("application/json");let n;if(u)try{n=await t.json()}catch{n=await t.text()}else n=await t.text();const f=t.status>=200&&t.status<300,h={};return t.headers.forEach((m,w)=>{h[w]=m}),{data:{body:n,headers:h,statusCode:t.status},error:f?void 0:new d("http",`Request failed with status ${t.status}`,{code:t.status.toString()}),success:f}}catch(t){if(a&&clearTimeout(a),t instanceof Error&&t.name==="AbortError")return{error:new d("http",`Request timed out after ${s.timeout}ms`,{code:E}),success:!1};throw t}}catch(e){return{error:new d("http",`Request failed: ${e instanceof Error?e.message:String(e)}`,{cause:e instanceof Error?e:new Error(String(e))}),success:!1}}};export{E as R,T as m};
1
+ import d from"./EmailError-2CCyVX1S.js";const y=globalThis.Buffer!==void 0,E="ETIMEDOUT",T=async(i,s={},r)=>{const l=typeof i=="string"?new URL(i):i;try{const e=new Headers;s.headers&&Object.entries(s.headers).forEach(([t,u])=>{e.set(t,u)});const o={headers:e,method:s.method??(r?"POST":"GET")};r&&(typeof r=="string"||r instanceof Uint8Array?o.body=r:y&&r instanceof globalThis.Buffer?o.body=new Uint8Array(r):o.body=new Uint8Array(r));let c,a;s.timeout&&(c=new AbortController,a=setTimeout(()=>{c?.abort()},s.timeout),o.signal=c.signal);try{const t=await fetch(l.toString(),o);a&&clearTimeout(a);const u=(t.headers.get("content-type")??"").includes("application/json");let n;if(u)try{n=await t.json()}catch{n=await t.text()}else n=await t.text();const f=t.status>=200&&t.status<300,h={};return t.headers.forEach((m,w)=>{h[w]=m}),{data:{body:n,headers:h,statusCode:t.status},error:f?void 0:new d("http",`Request failed with status ${t.status}`,{code:t.status.toString()}),success:f}}catch(t){if(a&&clearTimeout(a),t instanceof Error&&t.name==="AbortError")return{error:new d("http",`Request timed out after ${s.timeout}ms`,{code:E}),success:!1};throw t}}catch(e){return{error:new d("http",`Request failed: ${e instanceof Error?e.message:String(e)}`,{cause:e instanceof Error?e:new Error(String(e))}),success:!1}}};export{E as R,T as m};
@@ -1 +1 @@
1
- import d from"./EmailError-CDvYwuqz.js";import P from"./RequiredOptionError-DU2lxzk3.js";import{e as C}from"./generate-message-id-gXAuMz4g.js";import{s as j}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CylyuRaN.js";import{i as y}from"./retry-CG9iT2wF.js";import{a as h,s as I}from"./sanitize-header-DtQwAnzg.js";import{f as T}from"./validate-email-options-mCM9dVug.js";import{defineProvider as _}from"./defineProvider-C9q-7iwt.js";import{P as k,h as b,c as z}from"./provider-base-DjPzWncP.js";import{k as p}from"./address-formatter-BWR2Dddx.js";import{p as E}from"./attachment-processor-D1cbAhQi.js";const a="mandrill",S="https://mandrillapp.com/api/1.0",K=3e4,M=3,B=_((l={})=>{if(!l.apiKey)throw new P(a,"apiKey");const s={apiKey:l.apiKey,debug:l.debug??!1,endpoint:l.endpoint??S,retries:l.retries??M,timeout:l.timeout??K,...l.logger&&{logger:l.logger}},u=new k,i=z(a,l.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 d(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a),i.debug("Retrieving email details",{id:e});const n={id:e,key:s.apiKey},t={"Content-Type":"application/json"},o=await y(async()=>g(`${s.endpoint}/messages/info.json`,{headers:t,method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);return o.success?(i.debug("Email details retrieved successfully"),{data:o.data?.body,success:!0}):(i.debug("API request failed when retrieving email",o.error),{error:new d(a,`Failed to retrieve email: ${o.error instanceof Error?o.error.message:"Unknown error"}`,{cause:o.error}),success:!1})}catch(n){return{error:b(a,"retrieve email",n,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(a,"Mandrill API not available or invalid API key");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{i.debug("Checking Mandrill API availability");const e={key:s.apiKey},n={"Content-Type":"application/json"},t=await g(`${s.endpoint}/users/info.json`,{headers:n,method:"POST",timeout:s.timeout},JSON.stringify(e));return i.debug("Mandrill 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 n=T(e);if(n.length>0)return{error:new d(a,`Invalid email options: ${n.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={from_email:e.from.email,html:e.html??"",subject:e.subject,text:e.text??"",...e.from.name&&{from_name:e.from.name},to:p(e.to,"to")};if(e.cc){const r=p(e.cc,"cc");for(const c of r)c.type="cc";t.to=[...t.to,...r]}if(e.bcc){const r=p(e.bcc,"bcc");for(const c of r)c.type="bcc";t.to=[...t.to,...r]}if(e.replyTo){const r=e.replyTo.name?`${h(e.replyTo.name)} <${e.replyTo.email}>`:e.replyTo.email;t.headers={"Reply-To":r}}if(e.headers){const r=j(e.headers),c={};Object.entries(r).forEach(([w,A])=>{c[I(w)]=h(A)}),t.headers={...t.headers,...c}}e.tags&&e.tags.length>0&&(t.tags=e.tags),e.metadata&&(t.metadata=e.metadata),(e.googleAnalyticsDomains||e.googleAnalyticsCampaign)&&(t.google_analytics_domains=e.googleAnalyticsDomains,t.google_analytics_campaign=e.googleAnalyticsCampaign),e.subaccount&&(t.subaccount=e.subaccount),e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async r=>({content:await E(r,a),name:r.filename,type:r.contentType??"application/octet-stream"}))));const o={key:s.apiKey,message:t};e.templateName&&(o.template_name=e.templateName,e.templateContent&&(o.template_content=e.templateContent),e.templateVariables&&(o.template_vars=e.templateVariables)),e.globalMergeVars&&(t.global_merge_vars=e.globalMergeVars),e.mergeVars&&(t.merge_vars=e.mergeVars),e.sendAt&&(o.send_at=e.sendAt),i.debug("Sending email via Mandrill API",{subject:t.subject,to:t.to});const v={"Content-Type":"application/json"},m=await y(async()=>g(`${s.endpoint}/messages/send.json`,{headers:v,method:"POST",timeout:s.timeout},JSON.stringify(o)),s.retries);if(!m.success)return i.debug("API request failed when sending email",m.error),{error:m.error??new d(a,"Failed to send email"),success:!1};const f=m.data?.body?.[0]?.id??C();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:b(a,"send email",n,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{B as default};
1
+ import d from"./EmailError-2CCyVX1S.js";import P from"./RequiredOptionError-BmpC5whN.js";import{e as C}from"./generate-message-id-gXAuMz4g.js";import{s as j}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-CDhxj-9b.js";import{i as y}from"./retry-D1Rh-6Z4.js";import{a as h,s as I}from"./sanitize-header-DtQwAnzg.js";import{f as T}from"./validate-email-options-mCM9dVug.js";import{defineProvider as _}from"./defineProvider-C9q-7iwt.js";import{P as k,h as b,c as z}from"./provider-base-B-xhQSqE.js";import{j as p}from"./address-formatter-bfmGfQ83.js";import{p as E}from"./attachment-processor-DjbjtJ6H.js";const a="mandrill",S="https://mandrillapp.com/api/1.0",K=3e4,M=3,B=_((l={})=>{if(!l.apiKey)throw new P(a,"apiKey");const s={apiKey:l.apiKey,debug:l.debug??!1,endpoint:l.endpoint??S,retries:l.retries??M,timeout:l.timeout??K,...l.logger&&{logger:l.logger}},u=new k,i=z(a,l.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 d(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a),i.debug("Retrieving email details",{id:e});const n={id:e,key:s.apiKey},t={"Content-Type":"application/json"},o=await y(async()=>g(`${s.endpoint}/messages/info.json`,{headers:t,method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);return o.success?(i.debug("Email details retrieved successfully"),{data:o.data?.body,success:!0}):(i.debug("API request failed when retrieving email",o.error),{error:new d(a,`Failed to retrieve email: ${o.error instanceof Error?o.error.message:"Unknown error"}`,{cause:o.error}),success:!1})}catch(n){return{error:b(a,"retrieve email",n,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(a,"Mandrill API not available or invalid API key");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{i.debug("Checking Mandrill API availability");const e={key:s.apiKey},n={"Content-Type":"application/json"},t=await g(`${s.endpoint}/users/info.json`,{headers:n,method:"POST",timeout:s.timeout},JSON.stringify(e));return i.debug("Mandrill 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 n=T(e);if(n.length>0)return{error:new d(a,`Invalid email options: ${n.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={from_email:e.from.email,html:e.html??"",subject:e.subject,text:e.text??"",...e.from.name&&{from_name:e.from.name},to:p(e.to,"to")};if(e.cc){const r=p(e.cc,"cc");for(const c of r)c.type="cc";t.to=[...t.to,...r]}if(e.bcc){const r=p(e.bcc,"bcc");for(const c of r)c.type="bcc";t.to=[...t.to,...r]}if(e.replyTo){const r=e.replyTo.name?`${h(e.replyTo.name)} <${e.replyTo.email}>`:e.replyTo.email;t.headers={"Reply-To":r}}if(e.headers){const r=j(e.headers),c={};Object.entries(r).forEach(([w,A])=>{c[I(w)]=h(A)}),t.headers={...t.headers,...c}}e.tags&&e.tags.length>0&&(t.tags=e.tags),e.metadata&&(t.metadata=e.metadata),(e.googleAnalyticsDomains||e.googleAnalyticsCampaign)&&(t.google_analytics_domains=e.googleAnalyticsDomains,t.google_analytics_campaign=e.googleAnalyticsCampaign),e.subaccount&&(t.subaccount=e.subaccount),e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async r=>({content:await E(r,a),name:r.filename,type:r.contentType??"application/octet-stream"}))));const o={key:s.apiKey,message:t};e.templateName&&(o.template_name=e.templateName,e.templateContent&&(o.template_content=e.templateContent),e.templateVariables&&(o.template_vars=e.templateVariables)),e.globalMergeVars&&(t.global_merge_vars=e.globalMergeVars),e.mergeVars&&(t.merge_vars=e.mergeVars),e.sendAt&&(o.send_at=e.sendAt),i.debug("Sending email via Mandrill API",{subject:t.subject,to:t.to});const v={"Content-Type":"application/json"},m=await y(async()=>g(`${s.endpoint}/messages/send.json`,{headers:v,method:"POST",timeout:s.timeout},JSON.stringify(o)),s.retries);if(!m.success)return i.debug("API request failed when sending email",m.error),{error:m.error??new d(a,"Failed to send email"),success:!1};const f=m.data?.body?.[0]?.id??C();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:b(a,"send email",n,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{B as default};
@@ -1 +1 @@
1
- import d from"./EmailError-CDvYwuqz.js";import{c as E}from"./create-logger-BQTS3f-I.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";const u="mock",p=new Map,D=()=>({debug:!1,delay:0,failureRate:0,randomDelayRange:{max:0,min:0},retries:0,simulateFailure:!1,timeout:0}),C=I((f={})=>{const c=`mock-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;p.has(c)||p.set(c,[]);const a=p.get(c);if(!a)throw new Error(`Storage not found for instance: ${c}`);let y=!1,g;const s={...D(),defaultResponse:f.defaultResponse,logger:f.logger,randomDelayRange:f.randomDelayRange??{max:0,min:0},...f},r=E(u,s.logger);return{clearSentMessages(){a.length=0,r.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 a.find(t=>e(t))},findMessagesBy(e){return a.filter(t=>e(t))},async getEmail(e){try{if(!e)return{error:new d(u,"Email ID is required to retrieve email details"),success:!1};const t=a.find(o=>o.id===e);return t?(r.debug("Retrieved email",{id:e}),{data:t,success:!0}):{error:new d(u,`Email with ID ${e} not found`),success:!1}}catch(t){return r.debug("Exception retrieving email",t),{error:new d(u,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},getInstance(){return a},getLastSentMessage(){return a.at(-1)},getMessagesBySubject(e){return a.filter(t=>t.options.subject===e)},getMessagesTo(e){return a.filter(t=>{const o=Array.isArray(t.options.to)?t.options.to:[t.options.to];let i=[];t.options.cc&&(i=Array.isArray(t.options.cc)?t.options.cc:[t.options.cc]);let l=[];return t.options.bcc&&(l=Array.isArray(t.options.bcc)?t.options.bcc:[t.options.bcc]),[...o,...i,...l].some(w=>w.email===e)})},getSentEmails(){return[...a]},getSentMessages(){return[...a]},getSentMessagesCount(){return a.length},async initialize(){y||(s.delay>0&&await new Promise(e=>{setTimeout(e,s.delay)}),y=!0,r.debug("Mock provider initialized"))},async isAvailable(){return!0},name:u,options:s,reset(){a.length=0,g=void 0;const e=D();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,r.debug("Mock provider reset to initial state")},async sendEmail(e){try{const t=S(e);if(t.length>0)return{error:new d(u,`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:m}=s.randomDelayRange;o=Math.floor(Math.random()*(n-m+1))+m}if(o>0&&await new Promise(n=>{setTimeout(n,o)}),g!==void 0){const n=g;if(g=void 0,!n.successful)return r.debug("Using next response (failure)",n),{error:new d(u,n.errorMessages.join(", ")),success:!1};const m=n.messageId||v(),b=n.timestamp||new Date,h={messageId:m,provider:n.provider??u,response:n.response,sent:!0,timestamp:b},x={id:m,options:e,result:h,timestamp:b};return a.push(x),r.debug("Email stored using next response",{messageId:m}),{data:h,success:!0}}if(s.simulateFailure||s.failureRate>0&&Math.random()<s.failureRate)return r.debug("Simulating email send failure"),{error:new d(u,"Simulated failure"),success:!1};const i=s.defaultResponse?.successful?s.defaultResponse.messageId:v(),l=s.defaultResponse?.successful&&s.defaultResponse.timestamp?s.defaultResponse.timestamp:new Date,w=s.defaultResponse&&"response"in s.defaultResponse?s.defaultResponse.response:void 0,R={messageId:i,provider:u,response:w??{mock:!0,stored:!0},sent:!0,timestamp:l},M={id:i,options:e,result:R,timestamp:l};return a.push(M),r.debug("Email stored in mock provider",{messageId:i,subject:e.subject,to:Array.isArray(e.to)?e.to.map(n=>n.email):e.to.email}),{data:R,success:!0}}catch(t){return r.debug("Exception sending email",t),{error:new d(u,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},setDefaultResponse(e){s.defaultResponse=e,r.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},r.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,r.debug("Set failure rate",{rate:e})},setNextResponse(e){g=e,r.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},r.debug("Set random delay range",{max:t,min:e})},async shutdown(){a.length=0,p.delete(c),r.debug("Mock provider shutdown")},async validateCredentials(){return!0},async waitForMessage(e,t=5e3){const o=Date.now();for(;;){const i=a.find(l=>e(l));if(i)return i;if(Date.now()-o>t)throw new Error("Timeout waiting for message");await new Promise(l=>{setTimeout(l,10)})}},async waitForMessageCount(e,t=5e3){const o=Date.now();for(;a.length<e;){if(Date.now()-o>t)throw new Error(`Timeout waiting for ${e} messages (got ${a.length})`);await new Promise(i=>{setTimeout(i,10)})}}}});export{C as default};
1
+ import d from"./EmailError-2CCyVX1S.js";import{c as E}from"./create-logger-BQTS3f-I.js";import{e as v}from"./generate-message-id-gXAuMz4g.js";import{f as S}from"./validate-email-options-mCM9dVug.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";const u="mock",p=new Map,D=()=>({debug:!1,delay:0,failureRate:0,randomDelayRange:{max:0,min:0},retries:0,simulateFailure:!1,timeout:0}),C=I((f={})=>{const c=`mock-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;p.has(c)||p.set(c,[]);const a=p.get(c);if(!a)throw new Error(`Storage not found for instance: ${c}`);let y=!1,g;const s={...D(),defaultResponse:f.defaultResponse,logger:f.logger,randomDelayRange:f.randomDelayRange??{max:0,min:0},...f},r=E(u,s.logger);return{clearSentMessages(){a.length=0,r.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 a.find(t=>e(t))},findMessagesBy(e){return a.filter(t=>e(t))},async getEmail(e){try{if(!e)return{error:new d(u,"Email ID is required to retrieve email details"),success:!1};const t=a.find(o=>o.id===e);return t?(r.debug("Retrieved email",{id:e}),{data:t,success:!0}):{error:new d(u,`Email with ID ${e} not found`),success:!1}}catch(t){return r.debug("Exception retrieving email",t),{error:new d(u,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},getInstance(){return a},getLastSentMessage(){return a.at(-1)},getMessagesBySubject(e){return a.filter(t=>t.options.subject===e)},getMessagesTo(e){return a.filter(t=>{const o=Array.isArray(t.options.to)?t.options.to:[t.options.to];let i=[];t.options.cc&&(i=Array.isArray(t.options.cc)?t.options.cc:[t.options.cc]);let l=[];return t.options.bcc&&(l=Array.isArray(t.options.bcc)?t.options.bcc:[t.options.bcc]),[...o,...i,...l].some(w=>w.email===e)})},getSentEmails(){return[...a]},getSentMessages(){return[...a]},getSentMessagesCount(){return a.length},async initialize(){y||(s.delay>0&&await new Promise(e=>{setTimeout(e,s.delay)}),y=!0,r.debug("Mock provider initialized"))},async isAvailable(){return!0},name:u,options:s,reset(){a.length=0,g=void 0;const e=D();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,r.debug("Mock provider reset to initial state")},async sendEmail(e){try{const t=S(e);if(t.length>0)return{error:new d(u,`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:m}=s.randomDelayRange;o=Math.floor(Math.random()*(n-m+1))+m}if(o>0&&await new Promise(n=>{setTimeout(n,o)}),g!==void 0){const n=g;if(g=void 0,!n.successful)return r.debug("Using next response (failure)",n),{error:new d(u,n.errorMessages.join(", ")),success:!1};const m=n.messageId||v(),b=n.timestamp||new Date,h={messageId:m,provider:n.provider??u,response:n.response,sent:!0,timestamp:b},x={id:m,options:e,result:h,timestamp:b};return a.push(x),r.debug("Email stored using next response",{messageId:m}),{data:h,success:!0}}if(s.simulateFailure||s.failureRate>0&&Math.random()<s.failureRate)return r.debug("Simulating email send failure"),{error:new d(u,"Simulated failure"),success:!1};const i=s.defaultResponse?.successful?s.defaultResponse.messageId:v(),l=s.defaultResponse?.successful&&s.defaultResponse.timestamp?s.defaultResponse.timestamp:new Date,w=s.defaultResponse&&"response"in s.defaultResponse?s.defaultResponse.response:void 0,R={messageId:i,provider:u,response:w??{mock:!0,stored:!0},sent:!0,timestamp:l},M={id:i,options:e,result:R,timestamp:l};return a.push(M),r.debug("Email stored in mock provider",{messageId:i,subject:e.subject,to:Array.isArray(e.to)?e.to.map(n=>n.email):e.to.email}),{data:R,success:!0}}catch(t){return r.debug("Exception sending email",t),{error:new d(u,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},setDefaultResponse(e){s.defaultResponse=e,r.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},r.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,r.debug("Set failure rate",{rate:e})},setNextResponse(e){g=e,r.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},r.debug("Set random delay range",{max:t,min:e})},async shutdown(){a.length=0,p.delete(c),r.debug("Mock provider shutdown")},async validateCredentials(){return!0},async waitForMessage(e,t=5e3){const o=Date.now();for(;;){const i=a.find(l=>e(l));if(i)return i;if(Date.now()-o>t)throw new Error("Timeout waiting for message");await new Promise(l=>{setTimeout(l,10)})}},async waitForMessageCount(e,t=5e3){const o=Date.now();for(;a.length<e;){if(Date.now()-o>t)throw new Error(`Timeout waiting for ${e} messages (got ${a.length})`);await new Promise(i=>{setTimeout(i,10)})}}}});export{C as default};
@@ -1 +1 @@
1
- import p from"./EmailError-CDvYwuqz.js";import g from"./RequiredOptionError-DU2lxzk3.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as v}from"./make-request-CylyuRaN.js";import{i as b}from"./retry-CG9iT2wF.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as I,h as A,c as z}from"./provider-base-DjPzWncP.js";import{a as l}from"./address-formatter-BWR2Dddx.js";import{c as K}from"./attachment-processor-D1cbAhQi.js";const a="netcore",S="https://emailapi.netcorecloud.net/v5.1",T=3e4,_=3,m=r=>[r].flat(),F=P((r={})=>{if(!r.apiKey)throw new g(a,"apiKey");const i={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??S,logger:r.logger,retries:r.retries??_,timeout:r.timeout??T},d=new I,u=z(a,r.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new p(a,"Netcore API not available or invalid API key");u.debug("Provider initialized successfully")},a)},async isAvailable(){return i.apiKey.length>0},name:a,options:i,async sendEmail(t){try{const n=w(t);if(n.length>0)return{error:new p(a,`Invalid email options: ${n.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const o={to:m(t.to).map(e=>l(e))};t.cc&&(o.cc=m(t.cc).map(e=>l(e))),t.bcc&&(o.bcc=m(t.bcc).map(e=>l(e)));const s={from:l(t.from),personalizations:[o],subject:t.subject};if(t.templateId)s.template_id=t.templateId,t.templateData&&(o.attributes=t.templateData);else{const e=[];t.html&&e.push({type:"html",value:t.html}),t.text&&e.push({type:"plain",value:t.text}),e.length>0&&(s.content=e)}if(t.replyTo){const e=m(t.replyTo)[0];e&&(s.reply_to=e.email)}t.attachments&&t.attachments.length>0&&(s.attachments=await Promise.all(t.attachments.map(async e=>{const h=await K(e,a);return{content:h.content,name:h.filename}})));const c=await b(async()=>v(`${i.endpoint}/mail/send`,{headers:{api_key:i.apiKey,"Content-Type":"application/json"},method:"POST",timeout:i.timeout},JSON.stringify(s)),i.retries);if(!c.success)return{error:c.error??new p(a,"Failed to send email"),success:!1};const{body:f}=c.data;return{data:{messageId:f?.data?.message_id??f?.message_id??y(),provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:A(a,"send email",n,u),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{F as default};
1
+ import p from"./EmailError-2CCyVX1S.js";import g from"./RequiredOptionError-BmpC5whN.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as v}from"./make-request-CDhxj-9b.js";import{i as b}from"./retry-D1Rh-6Z4.js";import{f as w}from"./validate-email-options-mCM9dVug.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{P as I,h as A,c as z}from"./provider-base-B-xhQSqE.js";import{a as l}from"./address-formatter-bfmGfQ83.js";import{c as K}from"./attachment-processor-DjbjtJ6H.js";const a="netcore",S="https://emailapi.netcorecloud.net/v5.1",T=3e4,_=3,m=r=>[r].flat(),F=P((r={})=>{if(!r.apiKey)throw new g(a,"apiKey");const i={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??S,logger:r.logger,retries:r.retries??_,timeout:r.timeout??T},d=new I,u=z(a,r.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new p(a,"Netcore API not available or invalid API key");u.debug("Provider initialized successfully")},a)},async isAvailable(){return i.apiKey.length>0},name:a,options:i,async sendEmail(t){try{const n=w(t);if(n.length>0)return{error:new p(a,`Invalid email options: ${n.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const o={to:m(t.to).map(e=>l(e))};t.cc&&(o.cc=m(t.cc).map(e=>l(e))),t.bcc&&(o.bcc=m(t.bcc).map(e=>l(e)));const s={from:l(t.from),personalizations:[o],subject:t.subject};if(t.templateId)s.template_id=t.templateId,t.templateData&&(o.attributes=t.templateData);else{const e=[];t.html&&e.push({type:"html",value:t.html}),t.text&&e.push({type:"plain",value:t.text}),e.length>0&&(s.content=e)}if(t.replyTo){const e=m(t.replyTo)[0];e&&(s.reply_to=e.email)}t.attachments&&t.attachments.length>0&&(s.attachments=await Promise.all(t.attachments.map(async e=>{const h=await K(e,a);return{content:h.content,name:h.filename}})));const c=await b(async()=>v(`${i.endpoint}/mail/send`,{headers:{api_key:i.apiKey,"Content-Type":"application/json"},method:"POST",timeout:i.timeout},JSON.stringify(s)),i.retries);if(!c.success)return{error:c.error??new p(a,"Failed to send email"),success:!1};const{body:f}=c.data;return{data:{messageId:f?.data?.message_id??f?.message_id??y(),provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:A(a,"send email",n,u),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{F as default};
@@ -1 +1 @@
1
- import u from"nodemailer";import p from"./EmailError-CDvYwuqz.js";import y from"./RequiredOptionError-DU2lxzk3.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as g}from"./headers-to-record-De1Eg951.js";import{f as $}from"./validate-email-options-mCM9dVug.js";import{defineProvider as v}from"./defineProvider-C9q-7iwt.js";const i="nodemailer",H=v((c={})=>{if(!c.transport)throw new y(i,"transport");let r;const m=t=>{const s=t??c.transport;return u.createTransport(s)};let l=!1;const f=async()=>{if(!l)try{r=m(),await r.verify(),l=!0}catch(t){throw new p(i,`Failed to initialize nodemailer transport: ${t instanceof Error?t.message:String(t)}`,{cause:t instanceof Error?t:new Error(String(t))})}},h=t=>{const s=e=>e.name?`${e.name} <${e.email}>`:e.email,a=e=>e.name?`${e.name} <${e.email}>`:e.email,d=c.defaultFrom??t.from,n={from:s(d),subject:t.subject,to:Array.isArray(t.to)?t.to.map(e=>a(e)):a(t.to)};return t.text&&(n.text=t.text),t.html&&(n.html=t.html),t.cc&&(n.cc=Array.isArray(t.cc)?t.cc.map(e=>a(e)):a(t.cc)),t.bcc&&(n.bcc=Array.isArray(t.bcc)?t.bcc.map(e=>a(e)):a(t.bcc)),t.replyTo&&(n.replyTo=t.replyTo.name?`${t.replyTo.name} <${t.replyTo.email}>`:t.replyTo.email),t.headers&&(n.headers=g(t.headers)),t.attachments&&t.attachments.length>0&&(n.attachments=t.attachments.map(e=>{const o={filename:e.filename};return e.raw!==void 0?o.content=e.raw:e.content!==void 0?o.content=e.content:e.path&&(o.path=e.path),e.contentType&&(o.contentType=e.contentType),e.contentDisposition&&(o.contentDisposition=e.contentDisposition),e.cid&&(o.cid=e.cid),e.encoding&&(o.encoding=e.encoding),e.headers&&(o.headers=e.headers),e.href&&(o.href=e.href),e.httpHeaders&&(o.httpHeaders=e.httpHeaders),o})),n};return{features:{attachments:!0,customHeaders:!0,html:!0,replyTo:!0},initialize:f,isAvailable:async()=>{try{return r??=m(),await r.verify(),!0}catch{return!1}},name:i,options:c,sendEmail:async t=>{const s=$(t);if(s.length>0)return{error:new p(i,`Validation failed: ${s.join(", ")}`),success:!1};try{if(l||await f(),!r)throw new p(i,"Transporter not initialized. Call initialize() first.");const a=t.transportOverride?m(t.transportOverride):r,d=h(t),n=await a.sendMail(d);return{data:{messageId:n.messageId||w(),provider:i,response:n,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:new p(i,`Failed to send email: ${a instanceof Error?a.message:String(a)}`,{cause:a instanceof Error?a:new Error(String(a))}),success:!1}}},shutdown:async()=>{r&&typeof r.close=="function"&&r.close(),r=void 0,l=!1},validateCredentials:async()=>{try{return r??=m(),await r.verify(),!0}catch{return!1}}}});export{H as default};
1
+ import u from"nodemailer";import p from"./EmailError-2CCyVX1S.js";import y from"./RequiredOptionError-BmpC5whN.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as g}from"./headers-to-record-De1Eg951.js";import{f as $}from"./validate-email-options-mCM9dVug.js";import{defineProvider as v}from"./defineProvider-C9q-7iwt.js";const i="nodemailer",H=v((c={})=>{if(!c.transport)throw new y(i,"transport");let r;const m=t=>{const s=t??c.transport;return u.createTransport(s)};let l=!1;const f=async()=>{if(!l)try{r=m(),await r.verify(),l=!0}catch(t){throw new p(i,`Failed to initialize nodemailer transport: ${t instanceof Error?t.message:String(t)}`,{cause:t instanceof Error?t:new Error(String(t))})}},h=t=>{const s=e=>e.name?`${e.name} <${e.email}>`:e.email,a=e=>e.name?`${e.name} <${e.email}>`:e.email,d=c.defaultFrom??t.from,n={from:s(d),subject:t.subject,to:Array.isArray(t.to)?t.to.map(e=>a(e)):a(t.to)};return t.text&&(n.text=t.text),t.html&&(n.html=t.html),t.cc&&(n.cc=Array.isArray(t.cc)?t.cc.map(e=>a(e)):a(t.cc)),t.bcc&&(n.bcc=Array.isArray(t.bcc)?t.bcc.map(e=>a(e)):a(t.bcc)),t.replyTo&&(n.replyTo=t.replyTo.name?`${t.replyTo.name} <${t.replyTo.email}>`:t.replyTo.email),t.headers&&(n.headers=g(t.headers)),t.attachments&&t.attachments.length>0&&(n.attachments=t.attachments.map(e=>{const o={filename:e.filename};return e.raw!==void 0?o.content=e.raw:e.content!==void 0?o.content=e.content:e.path&&(o.path=e.path),e.contentType&&(o.contentType=e.contentType),e.contentDisposition&&(o.contentDisposition=e.contentDisposition),e.cid&&(o.cid=e.cid),e.encoding&&(o.encoding=e.encoding),e.headers&&(o.headers=e.headers),e.href&&(o.href=e.href),e.httpHeaders&&(o.httpHeaders=e.httpHeaders),o})),n};return{features:{attachments:!0,customHeaders:!0,html:!0,replyTo:!0},initialize:f,isAvailable:async()=>{try{return r??=m(),await r.verify(),!0}catch{return!1}},name:i,options:c,sendEmail:async t=>{const s=$(t);if(s.length>0)return{error:new p(i,`Validation failed: ${s.join(", ")}`),success:!1};try{if(l||await f(),!r)throw new p(i,"Transporter not initialized. Call initialize() first.");const a=t.transportOverride?m(t.transportOverride):r,d=h(t),n=await a.sendMail(d);return{data:{messageId:n.messageId||w(),provider:i,response:n,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:new p(i,`Failed to send email: ${a instanceof Error?a.message:String(a)}`,{cause:a instanceof Error?a:new Error(String(a))}),success:!1}}},shutdown:async()=>{r&&typeof r.close=="function"&&r.close(),r=void 0,l=!1},validateCredentials:async()=>{try{return r??=m(),await r.verify(),!0}catch{return!1}}}});export{H as default};
@@ -1 +1 @@
1
- import{context as f,trace as h,SpanStatusCode as p}from"@opentelemetry/api";import m from"./EmailError-CDvYwuqz.js";import y from"./RequiredOptionError-DU2lxzk3.js";import{c as b}from"./create-logger-BQTS3f-I.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";const A=t=>typeof t=="function",S=t=>t!==null&&typeof t=="object"&&"sendEmail"in t&&"initialize"in t&&"isAvailable"in t,s="opentelemetry",x="email",z="email.send",d=t=>t?typeof t=="string"?t:Array.isArray(t)?t.map(i=>typeof i=="string"?i:i.email).join(", "):t.email:"",C=(t,i)=>{const a={"email.from":d(t.from),"email.subject":t.subject};return t.to&&(a["email.to"]=d(t.to)),t.cc&&(a["email.cc"]=d(t.cc)),t.bcc&&(a["email.bcc"]=d(t.bcc)),t.replyTo&&(a["email.reply_to"]=d(t.replyTo)),t.priority&&(a["email.priority"]=t.priority),t.tags&&t.tags.length>0&&(a["email.tags"]=t.tags.join(", ")),t.attachments&&t.attachments.length>0&&(a["email.attachments.count"]=t.attachments.length),i?(t.text&&(a["email.text.length"]=t.text.length),t.html&&(a["email.html.length"]=t.html.length)):(t.text&&(a["email.has_text"]=!0),t.html&&(a["email.has_html"]=!0)),a},F=E(t=>{if(!t?.provider)throw new y(s,"provider");const i={debug:t.debug??!1,logger:t.logger,provider:t.provider,recordContent:t.recordContent??!1,retries:t.retries??3,serviceName:t.serviceName??x,timeout:t.timeout??3e4,tracer:t.tracer};let a=!1,e;const c=b(s,t.logger),w=()=>i.tracer?i.tracer:h.getTracer(i.serviceName),u=async()=>{try{if(A(i.provider))e=i.provider({});else if(S(i.provider))e=i.provider;else throw new m(s,"Invalid provider: must be a Provider instance or ProviderFactory function");await e.initialize(),c.debug(`Initialized wrapped provider: ${e.name??"unknown"}`)}catch(o){throw new m(s,`Failed to initialize wrapped provider: ${o.message}`,{cause:o})}},v=()=>e?.features?e.features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1};return{get features(){return v()},getInstance(){if(!e)throw new m(s,"Provider not initialized. Call initialize() first.");return e},async initialize(){if(!a)try{await u(),a=!0,c.debug("OpenTelemetry provider initialized")}catch(o){throw new m(s,`Failed to initialize: ${o.message}`,{cause:o})}},async isAvailable(){try{return e||await u(),await e.isAvailable()}catch{return!1}},name:s,options:i,async sendEmail(o){const n=w().startSpan(z);try{e||await u();const l=C(o,i.recordContent);n.setAttributes(l),e.name&&n.setAttribute("email.provider",e.name);const r=await f.with(h.setSpan(f.active(),n),async()=>await e.sendEmail(o));if(r.success&&r.data)return n.setStatus({code:p.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()),c.debug(`Email sent successfully via ${e.name??"unknown"}`),{data:{...r.data,provider:`${s}(${e.name??"unknown"})`},success:!0};const g=r.error instanceof Error?r.error.message:String(r.error??"Unknown error");return n.setStatus({code:p.ERROR,message:g}),n.setAttribute("email.sent",!1),n.recordException(r.error instanceof Error?r.error:new Error(g)),c.debug(`Failed to send email via ${e.name??"unknown"}:`,g),r}catch(l){const r=l instanceof Error?l.message:String(l);return n.setStatus({code:p.ERROR,message:r}),n.setAttribute("email.sent",!1),n.recordException(l instanceof Error?l:new Error(r)),c.debug("Exception sending email:",r),{error:new m(s,`Failed to send email: ${r}`,{cause:l}),success:!1}}finally{n.end()}},async shutdown(){e?.shutdown&&await e.shutdown(),a=!1},async validateCredentials(){try{return e||await u(),e.validateCredentials?await e.validateCredentials():await e.isAvailable()}catch{return!1}}}});export{F as default};
1
+ import{context as f,trace as h,SpanStatusCode as p}from"@opentelemetry/api";import m from"./EmailError-2CCyVX1S.js";import y from"./RequiredOptionError-BmpC5whN.js";import{c as b}from"./create-logger-BQTS3f-I.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";const A=t=>typeof t=="function",S=t=>t!==null&&typeof t=="object"&&"sendEmail"in t&&"initialize"in t&&"isAvailable"in t,s="opentelemetry",x="email",z="email.send",d=t=>t?typeof t=="string"?t:Array.isArray(t)?t.map(i=>typeof i=="string"?i:i.email).join(", "):t.email:"",C=(t,i)=>{const a={"email.from":d(t.from),"email.subject":t.subject};return t.to&&(a["email.to"]=d(t.to)),t.cc&&(a["email.cc"]=d(t.cc)),t.bcc&&(a["email.bcc"]=d(t.bcc)),t.replyTo&&(a["email.reply_to"]=d(t.replyTo)),t.priority&&(a["email.priority"]=t.priority),t.tags&&t.tags.length>0&&(a["email.tags"]=t.tags.join(", ")),t.attachments&&t.attachments.length>0&&(a["email.attachments.count"]=t.attachments.length),i?(t.text&&(a["email.text.length"]=t.text.length),t.html&&(a["email.html.length"]=t.html.length)):(t.text&&(a["email.has_text"]=!0),t.html&&(a["email.has_html"]=!0)),a},F=E(t=>{if(!t?.provider)throw new y(s,"provider");const i={debug:t.debug??!1,logger:t.logger,provider:t.provider,recordContent:t.recordContent??!1,retries:t.retries??3,serviceName:t.serviceName??x,timeout:t.timeout??3e4,tracer:t.tracer};let a=!1,e;const c=b(s,t.logger),w=()=>i.tracer?i.tracer:h.getTracer(i.serviceName),u=async()=>{try{if(A(i.provider))e=i.provider({});else if(S(i.provider))e=i.provider;else throw new m(s,"Invalid provider: must be a Provider instance or ProviderFactory function");await e.initialize(),c.debug(`Initialized wrapped provider: ${e.name??"unknown"}`)}catch(o){throw new m(s,`Failed to initialize wrapped provider: ${o.message}`,{cause:o})}},v=()=>e?.features?e.features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1};return{get features(){return v()},getInstance(){if(!e)throw new m(s,"Provider not initialized. Call initialize() first.");return e},async initialize(){if(!a)try{await u(),a=!0,c.debug("OpenTelemetry provider initialized")}catch(o){throw new m(s,`Failed to initialize: ${o.message}`,{cause:o})}},async isAvailable(){try{return e||await u(),await e.isAvailable()}catch{return!1}},name:s,options:i,async sendEmail(o){const n=w().startSpan(z);try{e||await u();const l=C(o,i.recordContent);n.setAttributes(l),e.name&&n.setAttribute("email.provider",e.name);const r=await f.with(h.setSpan(f.active(),n),async()=>await e.sendEmail(o));if(r.success&&r.data)return n.setStatus({code:p.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()),c.debug(`Email sent successfully via ${e.name??"unknown"}`),{data:{...r.data,provider:`${s}(${e.name??"unknown"})`},success:!0};const g=r.error instanceof Error?r.error.message:String(r.error??"Unknown error");return n.setStatus({code:p.ERROR,message:g}),n.setAttribute("email.sent",!1),n.recordException(r.error instanceof Error?r.error:new Error(g)),c.debug(`Failed to send email via ${e.name??"unknown"}:`,g),r}catch(l){const r=l instanceof Error?l.message:String(l);return n.setStatus({code:p.ERROR,message:r}),n.setAttribute("email.sent",!1),n.recordException(l instanceof Error?l:new Error(r)),c.debug("Exception sending email:",r),{error:new m(s,`Failed to send email: ${r}`,{cause:l}),success:!1}}finally{n.end()}},async shutdown(){e?.shutdown&&await e.shutdown(),a=!1},async validateCredentials(){try{return e||await u(),e.validateCredentials?await e.validateCredentials():await e.isAvailable()}catch{return!1}}}});export{F as default};
@@ -1 +1 @@
1
- import m from"./EmailError-CDvYwuqz.js";import{e as _}from"./generate-message-id-gXAuMz4g.js";import{m as S}from"./make-request-CylyuRaN.js";import{i as v}from"./retry-CG9iT2wF.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import p from"./RequiredOptionError-DU2lxzk3.js";import{d as x}from"./create-token-cache-D56KQGVQ.js";import{c as M}from"./attachment-processor-D1cbAhQi.js";import{h as P,P as R,c as j}from"./provider-base-DjPzWncP.js";const b="https://login.microsoftonline.com",E=6e4,O=3e4,L=3,q=300,z="https://graph.microsoft.com/.default",D=["https://graph.microsoft.com/Mail.Send","offline_access"],F={accessToken:["clientId","clientSecret","refreshToken","tenantId"],clientCredentials:["refreshToken"],getAccessToken:["accessToken","clientId","clientSecret","refreshToken","tenantId"],refreshToken:[]},N=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},U=(e,t)=>{if(e.getAccessToken)return"getAccessToken";if(e.accessToken)return"accessToken";if(e.refreshToken)return"refreshToken";if(e.clientSecret)return"clientCredentials";throw new p(t,["accessToken","getAccessToken","clientSecret","refreshToken"])},B=(e,t,i)=>{const n=e.authMode??U(e,t),h=F[n].filter(a=>e[a]!==void 0);if(h.length>0&&i.warn(`The '${n}' auth mode ignores these configured options: ${h.join(", ")}. Set 'authMode' to pin the intended flow.`),n==="getAccessToken"){const{getAccessToken:a}=e;if(!a)throw new p(t,"getAccessToken");return{getToken:async()=>a(),mode:n}}if(n==="accessToken"){const{accessToken:a}=e;if(!a)throw new p(t,"accessToken");return{getToken:()=>Promise.resolve(a),mode:n}}const{clientId:f,clientSecret:r,refreshToken:c,tenantId:d}=e,o=[];if(d||o.push("tenantId"),f||o.push("clientId"),n==="clientCredentials"&&!r&&o.push("clientSecret"),n==="refreshToken"&&!c&&o.push("refreshToken"),!d||!f)throw new p(t,o);if(n==="clientCredentials"){if(!r)throw new p(t,o);return{clientId:f,clientSecret:r,mode:n,tenantId:d}}if(!c)throw new p(t,o);return{clientId:f,clientSecret:r,mode:n,refreshToken:c,tenantId:d}},H=(e,t,i)=>{if(typeof e!="object"||e===null)throw new m(t,`Token endpoint returned a non-JSON response (status ${String(i)})`);const n=e;if(typeof n.error=="string"){const h=typeof n.error_description=="string"?n.error_description:"no description provided";throw new m(t,`Token request failed: ${n.error} — ${h}`,{code:n.error,hint:"Check the tenantId, clientId and client secret / refresh token in the Azure app registration."})}if(typeof n.access_token!="string")throw new m(t,`Token endpoint response did not contain an access_token (status ${String(i)})`);return{accessToken:n.access_token,expiresIn:typeof n.expires_in=="number"?n.expires_in:q,refreshToken:typeof n.refresh_token=="string"?n.refresh_token:void 0}},J=e=>e===0||e===408||e===429||e>=500,$=(e,t,i,n)=>{if(e.mode==="accessToken"||e.mode==="getAccessToken")return e.getToken;const h=`${N(t.authority??b)}/${e.tenantId}/oauth2/v2.0/token`,f=t.timeout??O,r=t.retries??L,c=t.now??Date.now;let d=e.mode==="refreshToken"?e.refreshToken:void 0;const o=()=>{const s=new URLSearchParams({client_id:e.clientId,scope:(t.scopes??(e.mode==="clientCredentials"?[z]:D)).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",d)),s.toString()},a=s=>s.data?.statusCode??0,k=async()=>{const s=await S(h,{headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:f},o());return!s.success&&J(a(s))?s:{data:s.data,success:!0}},T=async s=>{if(d=s,!!t.onRefreshToken)try{await t.onRefreshToken(s)}catch(u){n.error(`Failed to persist the rotated refresh token — the stored token is stale and sending will fail after a restart: ${u instanceof Error?u.message:String(u)}`)}},g=x(async()=>{const s=await v(k,r),u=s.data?.body;if(!s.success&&(typeof u!="object"||u===null))throw s.error instanceof Error?s.error:new m(i,"Token request failed");const w=H(u,i,a(s));return w.refreshToken&&w.refreshToken!==d&&await T(w.refreshToken),{accessToken:w.accessToken,expiresAt:c()+w.expiresIn*1e3}},{now:c,skewMs:t.tokenRefreshSkewMs??E});return async()=>(await g()).accessToken},l="outlook365",G="https://graph.microsoft.com/v1.0",K=3e4,Q=3,y=e=>[e].flat(),I=e=>e.map(t=>({emailAddress:{address:t.email,...t.name?{name:t.name}:{}}})),V=e=>{if(e instanceof m)return e;const t=e instanceof Error?e.message:String(e);return new m(l,`Failed to obtain access token: ${t}`,{cause:e})},ae=C((e={})=>{const t=j(l,e.logger),i=B(e,l,t);if(i.mode==="clientCredentials"&&(e.userId===void 0||e.userId==="me"))throw new m(l,"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 n={authMode:i.mode,authority:e.authority??b,clientId:e.clientId,debug:e.debug??!1,endpoint:e.endpoint??G,logger:e.logger,now:e.now,retries:e.retries??Q,saveToSentItems:e.saveToSentItems??!0,scopes:e.scopes,tenantId:e.tenantId,timeout:e.timeout??K,tokenRefreshSkewMs:e.tokenRefreshSkewMs,userId:e.userId??"me"},h=new R,f=$(i,e,l,t);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!0},name:l,options:n,async sendEmail(r){try{const c=A(r);if(c.length>0)return{error:new m(l,`Invalid email options: ${c.join(", ")}`),success:!1};let d;try{d=await f()}catch(T){return{error:V(T),success:!1}}const o={body:{content:r.html??r.text??"",contentType:r.html?"HTML":"Text"},subject:r.subject,toRecipients:I(y(r.to))};r.cc&&(o.ccRecipients=I(y(r.cc))),r.bcc&&(o.bccRecipients=I(y(r.bcc))),r.replyTo&&(o.replyTo=I(y(r.replyTo))),r.importance&&(o.importance=r.importance),r.attachments&&r.attachments.length>0&&(o.attachments=await Promise.all(r.attachments.map(async T=>{const g=await M(T,l);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:g.content,contentType:g.contentType,name:g.filename}})));const a=n.userId==="me"?"me":`users/${n.userId}`,k=await v(async()=>S(`${n.endpoint}/${a}/sendMail`,{headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},method:"POST",timeout:n.timeout},JSON.stringify({message:o,saveToSentItems:n.saveToSentItems})),n.retries);return k.success?{data:{messageId:_(),provider:l,response:k.data,sent:!0,timestamp:new Date},success:!0}:{error:k.error??new m(l,"Failed to send email"),success:!1}}catch(c){return{error:P(l,"send email",c,t),success:!1}}},async validateCredentials(){try{return await f(),!0}catch(r){return t.warn(`Credential validation failed: ${r instanceof Error?r.message:String(r)}`),!1}}}});export{ae as default};
1
+ import m from"./EmailError-2CCyVX1S.js";import{e as _}from"./generate-message-id-gXAuMz4g.js";import{m as S}from"./make-request-CDhxj-9b.js";import{i as v}from"./retry-D1Rh-6Z4.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import p from"./RequiredOptionError-BmpC5whN.js";import{d as x}from"./create-token-cache-D56KQGVQ.js";import{c as M}from"./attachment-processor-DjbjtJ6H.js";import{h as P,P as R,c as j}from"./provider-base-B-xhQSqE.js";const b="https://login.microsoftonline.com",E=6e4,O=3e4,L=3,q=300,z="https://graph.microsoft.com/.default",D=["https://graph.microsoft.com/Mail.Send","offline_access"],F={accessToken:["clientId","clientSecret","refreshToken","tenantId"],clientCredentials:["refreshToken"],getAccessToken:["accessToken","clientId","clientSecret","refreshToken","tenantId"],refreshToken:[]},N=e=>{let t=e.length;for(;t>0&&e[t-1]==="/";)t-=1;return e.slice(0,t)},U=(e,t)=>{if(e.getAccessToken)return"getAccessToken";if(e.accessToken)return"accessToken";if(e.refreshToken)return"refreshToken";if(e.clientSecret)return"clientCredentials";throw new p(t,["accessToken","getAccessToken","clientSecret","refreshToken"])},B=(e,t,i)=>{const n=e.authMode??U(e,t),h=F[n].filter(a=>e[a]!==void 0);if(h.length>0&&i.warn(`The '${n}' auth mode ignores these configured options: ${h.join(", ")}. Set 'authMode' to pin the intended flow.`),n==="getAccessToken"){const{getAccessToken:a}=e;if(!a)throw new p(t,"getAccessToken");return{getToken:async()=>a(),mode:n}}if(n==="accessToken"){const{accessToken:a}=e;if(!a)throw new p(t,"accessToken");return{getToken:()=>Promise.resolve(a),mode:n}}const{clientId:f,clientSecret:r,refreshToken:c,tenantId:d}=e,o=[];if(d||o.push("tenantId"),f||o.push("clientId"),n==="clientCredentials"&&!r&&o.push("clientSecret"),n==="refreshToken"&&!c&&o.push("refreshToken"),!d||!f)throw new p(t,o);if(n==="clientCredentials"){if(!r)throw new p(t,o);return{clientId:f,clientSecret:r,mode:n,tenantId:d}}if(!c)throw new p(t,o);return{clientId:f,clientSecret:r,mode:n,refreshToken:c,tenantId:d}},H=(e,t,i)=>{if(typeof e!="object"||e===null)throw new m(t,`Token endpoint returned a non-JSON response (status ${String(i)})`);const n=e;if(typeof n.error=="string"){const h=typeof n.error_description=="string"?n.error_description:"no description provided";throw new m(t,`Token request failed: ${n.error} — ${h}`,{code:n.error,hint:"Check the tenantId, clientId and client secret / refresh token in the Azure app registration."})}if(typeof n.access_token!="string")throw new m(t,`Token endpoint response did not contain an access_token (status ${String(i)})`);return{accessToken:n.access_token,expiresIn:typeof n.expires_in=="number"?n.expires_in:q,refreshToken:typeof n.refresh_token=="string"?n.refresh_token:void 0}},J=e=>e===0||e===408||e===429||e>=500,$=(e,t,i,n)=>{if(e.mode==="accessToken"||e.mode==="getAccessToken")return e.getToken;const h=`${N(t.authority??b)}/${e.tenantId}/oauth2/v2.0/token`,f=t.timeout??O,r=t.retries??L,c=t.now??Date.now;let d=e.mode==="refreshToken"?e.refreshToken:void 0;const o=()=>{const s=new URLSearchParams({client_id:e.clientId,scope:(t.scopes??(e.mode==="clientCredentials"?[z]:D)).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",d)),s.toString()},a=s=>s.data?.statusCode??0,k=async()=>{const s=await S(h,{headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",timeout:f},o());return!s.success&&J(a(s))?s:{data:s.data,success:!0}},T=async s=>{if(d=s,!!t.onRefreshToken)try{await t.onRefreshToken(s)}catch(u){n.error(`Failed to persist the rotated refresh token — the stored token is stale and sending will fail after a restart: ${u instanceof Error?u.message:String(u)}`)}},g=x(async()=>{const s=await v(k,r),u=s.data?.body;if(!s.success&&(typeof u!="object"||u===null))throw s.error instanceof Error?s.error:new m(i,"Token request failed");const w=H(u,i,a(s));return w.refreshToken&&w.refreshToken!==d&&await T(w.refreshToken),{accessToken:w.accessToken,expiresAt:c()+w.expiresIn*1e3}},{now:c,skewMs:t.tokenRefreshSkewMs??E});return async()=>(await g()).accessToken},l="outlook365",G="https://graph.microsoft.com/v1.0",K=3e4,Q=3,y=e=>[e].flat(),I=e=>e.map(t=>({emailAddress:{address:t.email,...t.name?{name:t.name}:{}}})),V=e=>{if(e instanceof m)return e;const t=e instanceof Error?e.message:String(e);return new m(l,`Failed to obtain access token: ${t}`,{cause:e})},ae=C((e={})=>{const t=j(l,e.logger),i=B(e,l,t);if(i.mode==="clientCredentials"&&(e.userId===void 0||e.userId==="me"))throw new m(l,"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 n={authMode:i.mode,authority:e.authority??b,clientId:e.clientId,debug:e.debug??!1,endpoint:e.endpoint??G,logger:e.logger,now:e.now,retries:e.retries??Q,saveToSentItems:e.saveToSentItems??!0,scopes:e.scopes,tenantId:e.tenantId,timeout:e.timeout??K,tokenRefreshSkewMs:e.tokenRefreshSkewMs,userId:e.userId??"me"},h=new R,f=$(i,e,l,t);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!0},name:l,options:n,async sendEmail(r){try{const c=A(r);if(c.length>0)return{error:new m(l,`Invalid email options: ${c.join(", ")}`),success:!1};let d;try{d=await f()}catch(T){return{error:V(T),success:!1}}const o={body:{content:r.html??r.text??"",contentType:r.html?"HTML":"Text"},subject:r.subject,toRecipients:I(y(r.to))};r.cc&&(o.ccRecipients=I(y(r.cc))),r.bcc&&(o.bccRecipients=I(y(r.bcc))),r.replyTo&&(o.replyTo=I(y(r.replyTo))),r.importance&&(o.importance=r.importance),r.attachments&&r.attachments.length>0&&(o.attachments=await Promise.all(r.attachments.map(async T=>{const g=await M(T,l);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:g.content,contentType:g.contentType,name:g.filename}})));const a=n.userId==="me"?"me":`users/${n.userId}`,k=await v(async()=>S(`${n.endpoint}/${a}/sendMail`,{headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},method:"POST",timeout:n.timeout},JSON.stringify({message:o,saveToSentItems:n.saveToSentItems})),n.retries);return k.success?{data:{messageId:_(),provider:l,response:k.data,sent:!0,timestamp:new Date},success:!0}:{error:k.error??new m(l,"Failed to send email"),success:!1}}catch(c){return{error:P(l,"send email",c,t),success:!1}}},async validateCredentials(){try{return await f(),!0}catch(r){return t.warn(`Credential validation failed: ${r instanceof Error?r.message:String(r)}`),!1}}}});export{ae as default};
@@ -1 +1 @@
1
- import m from"./EmailError-CDvYwuqz.js";import P from"./RequiredOptionError-DU2lxzk3.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{s as A}from"./headers-to-record-De1Eg951.js";import{m as b}from"./make-request-CylyuRaN.js";import{i as g}from"./retry-CG9iT2wF.js";import{s as k,a as z}from"./sanitize-header-DtQwAnzg.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{P as T,h,c as K}from"./provider-base-DjPzWncP.js";import{p as x}from"./attachment-processor-D1cbAhQi.js";const r="plunk",_="https://api.useplunk.com/v1",S=3e4,q=3,U=E((n={})=>{if(!n.apiKey)throw new P(r,"apiKey");const a={apiKey:n.apiKey,debug:n.debug??!1,endpoint:n.endpoint??_,logger:n.logger,retries:n.retries??q,timeout:n.timeout??S},p=new T,i=K(r,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 m(r,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),r);const l={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const s=await g(async()=>b(`${a.endpoint}/emails/${e}`,{headers:l,method:"GET",timeout:a.timeout}),a.retries);return s.success?(i.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(i.debug("API request failed when retrieving email",s.error),{error:new m(r,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(l){return{error:h(r,"retrieve email",l,i),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(r,"Plunk API not available or invalid API key");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{return a.apiKey&&a.apiKey.length>0?(i.debug("API key exists, assuming Plunk is available"),!0):!1}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:a,async sendEmail(e){try{const l=j(e);if(l.length>0)return{error:new m(r,`Invalid email options: ${l.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),r);const s=o=>Array.isArray(o)?o.map(d=>d.email):[o.email],t={to:e.subscriber??(Array.isArray(e.to)?e.to[0]?.email:e.to.email)};if(e.from&&(t.from=e.from.email,e.from.name&&(t.from_name=e.from.name)),e.subject&&(t.subject=e.subject),e.html?t.body=e.html:e.text&&(t.body=e.text),e.html&&e.text&&(t.text=e.text),e.cc&&(t.cc=s(e.cc)),e.bcc&&(t.bcc=s(e.bcc)),e.replyTo&&(t.reply_to=e.replyTo.email,e.replyTo.name&&(t.reply_to_name=e.replyTo.name)),e.templateId&&(t.template=e.templateId),e.data&&(t.data=e.data),e.subscriberId&&(t.subscriber_id=e.subscriberId),e.headers){const o=A(e.headers),d={};Object.entries(o).forEach(([w,I])=>{d[k(w)]=z(I)}),t.headers=d}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async o=>({content:await x(o,r),filename:o.filename,type:o.contentType??"application/octet-stream"})))),i.debug("Sending email via Plunk API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},c=await g(async()=>b(`${a.endpoint}/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new m(r,"Failed to send email"),success:!1};const u=c.data,f=u?.body&&typeof u.body=="object"?u.body.id??u.body.messageId??y():y();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(l){return{error:h(r,"send email",l,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
1
+ import m from"./EmailError-2CCyVX1S.js";import P from"./RequiredOptionError-BmpC5whN.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{s as A}from"./headers-to-record-De1Eg951.js";import{m as b}from"./make-request-CDhxj-9b.js";import{i as g}from"./retry-D1Rh-6Z4.js";import{s as k,a as z}from"./sanitize-header-DtQwAnzg.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{P as T,h,c as K}from"./provider-base-B-xhQSqE.js";import{p as x}from"./attachment-processor-DjbjtJ6H.js";const r="plunk",_="https://api.useplunk.com/v1",S=3e4,q=3,U=E((n={})=>{if(!n.apiKey)throw new P(r,"apiKey");const a={apiKey:n.apiKey,debug:n.debug??!1,endpoint:n.endpoint??_,logger:n.logger,retries:n.retries??q,timeout:n.timeout??S},p=new T,i=K(r,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 m(r,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),r);const l={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const s=await g(async()=>b(`${a.endpoint}/emails/${e}`,{headers:l,method:"GET",timeout:a.timeout}),a.retries);return s.success?(i.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(i.debug("API request failed when retrieving email",s.error),{error:new m(r,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(l){return{error:h(r,"retrieve email",l,i),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(r,"Plunk API not available or invalid API key");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{return a.apiKey&&a.apiKey.length>0?(i.debug("API key exists, assuming Plunk is available"),!0):!1}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:a,async sendEmail(e){try{const l=j(e);if(l.length>0)return{error:new m(r,`Invalid email options: ${l.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),r);const s=o=>Array.isArray(o)?o.map(d=>d.email):[o.email],t={to:e.subscriber??(Array.isArray(e.to)?e.to[0]?.email:e.to.email)};if(e.from&&(t.from=e.from.email,e.from.name&&(t.from_name=e.from.name)),e.subject&&(t.subject=e.subject),e.html?t.body=e.html:e.text&&(t.body=e.text),e.html&&e.text&&(t.text=e.text),e.cc&&(t.cc=s(e.cc)),e.bcc&&(t.bcc=s(e.bcc)),e.replyTo&&(t.reply_to=e.replyTo.email,e.replyTo.name&&(t.reply_to_name=e.replyTo.name)),e.templateId&&(t.template=e.templateId),e.data&&(t.data=e.data),e.subscriberId&&(t.subscriber_id=e.subscriberId),e.headers){const o=A(e.headers),d={};Object.entries(o).forEach(([w,I])=>{d[k(w)]=z(I)}),t.headers=d}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async o=>({content:await x(o,r),filename:o.filename,type:o.contentType??"application/octet-stream"})))),i.debug("Sending email via Plunk API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},c=await g(async()=>b(`${a.endpoint}/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new m(r,"Failed to send email"),success:!1};const u=c.data,f=u?.body&&typeof u.body=="object"?u.body.id??u.body.messageId??y():y();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(l){return{error:h(r,"send email",l,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
@@ -1 +1 @@
1
- import l from"./EmailError-CDvYwuqz.js";import g from"./RequiredOptionError-DU2lxzk3.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as P}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CylyuRaN.js";import{i as f}from"./retry-CG9iT2wF.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as A}from"./defineProvider-C9q-7iwt.js";import{P as C,c as E}from"./provider-base-DjPzWncP.js";import{l as u,m as h}from"./address-formatter-BWR2Dddx.js";import{p as T}from"./attachment-processor-D1cbAhQi.js";const a="postal",j=3e4,K=3,R=A((r={})=>{if(!r.host)throw new g(a,"host");if(!r.apiKey)throw new g(a,"apiKey");const y=r.endpoint??`https://${r.host}/api/v1`,i={apiKey:r.apiKey,debug:r.debug??!1,endpoint:y,host:r.host,retries:r.retries??K,timeout:r.timeout??j,...r.logger&&{logger:r.logger}},d=new C,o=E(a,r.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 l(a,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const t={"Content-Type":"application/json","X-Server-API-Key":i.apiKey};o.debug("Retrieving email details",{id:e});const s=await f(async()=>m(`${i.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:i.timeout}),i.retries);return s.success?(o.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(o.debug("API request failed when retrieving email",s.error),{error:new l(a,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(t){return o.debug("Exception retrieving email",t),{error:new l(a,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(a,"Postal API not available or invalid API key");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Server-API-Key":i.apiKey};o.debug("Checking Postal API availability");const t=await m(`${i.endpoint}/server`,{headers:e,method:"GET",timeout:i.timeout});return o.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 o.debug("Error checking availability:",e),!1}},name:a,options:i,async sendEmail(e){try{const t=I(e);if(t.length>0)return{error:new l(a,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const s={from:h(e.from).address,subject:e.subject,to:u(e.to).map(n=>n.address)};if(e.html&&(s.html_body=e.html),e.text&&(s.plain_body=e.text),e.cc&&(s.cc=u(e.cc).map(n=>n.address)),e.bcc&&(s.bcc=u(e.bcc).map(n=>n.address)),e.replyTo&&(s.reply_to=h(e.replyTo).address),e.templateId&&(s.template_id=e.templateId,e.templateVariables&&(s.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(s.tag=e.tags.join(",")),e.headers){const n=P(e.headers);s.headers=n}e.attachments&&e.attachments.length>0&&(s.attachments=await Promise.all(e.attachments.map(async n=>{const v=await T(n,a);return{content_type:n.contentType??"application/octet-stream",data:v,name:n.filename}}))),o.debug("Sending email via Postal API",{subject:s.subject,to:s.to});const b={"Content-Type":"application/json","X-Server-API-Key":i.apiKey},c=await f(async()=>m(`${i.endpoint}/send/message`,{headers:b,method:"POST",timeout:i.timeout},JSON.stringify(s)),i.retries);if(!c.success)return o.debug("API request failed when sending email",c.error),{error:c.error??new l(a,"Failed to send email"),success:!1};const p=c.data?.body?.message_id?.toString()??w();return o.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return o.debug("Exception sending email",t),{error:new l(a,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
1
+ import l from"./EmailError-2CCyVX1S.js";import g from"./RequiredOptionError-BmpC5whN.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as P}from"./headers-to-record-De1Eg951.js";import{m}from"./make-request-CDhxj-9b.js";import{i as f}from"./retry-D1Rh-6Z4.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as A}from"./defineProvider-C9q-7iwt.js";import{P as C,c as E}from"./provider-base-B-xhQSqE.js";import{k as u,l as h}from"./address-formatter-bfmGfQ83.js";import{p as T}from"./attachment-processor-DjbjtJ6H.js";const a="postal",j=3e4,K=3,R=A((r={})=>{if(!r.host)throw new g(a,"host");if(!r.apiKey)throw new g(a,"apiKey");const y=r.endpoint??`https://${r.host}/api/v1`,i={apiKey:r.apiKey,debug:r.debug??!1,endpoint:y,host:r.host,retries:r.retries??K,timeout:r.timeout??j,...r.logger&&{logger:r.logger}},d=new C,o=E(a,r.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 l(a,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const t={"Content-Type":"application/json","X-Server-API-Key":i.apiKey};o.debug("Retrieving email details",{id:e});const s=await f(async()=>m(`${i.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:i.timeout}),i.retries);return s.success?(o.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(o.debug("API request failed when retrieving email",s.error),{error:new l(a,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(t){return o.debug("Exception retrieving email",t),{error:new l(a,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(a,"Postal API not available or invalid API key");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Server-API-Key":i.apiKey};o.debug("Checking Postal API availability");const t=await m(`${i.endpoint}/server`,{headers:e,method:"GET",timeout:i.timeout});return o.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 o.debug("Error checking availability:",e),!1}},name:a,options:i,async sendEmail(e){try{const t=I(e);if(t.length>0)return{error:new l(a,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const s={from:h(e.from).address,subject:e.subject,to:u(e.to).map(n=>n.address)};if(e.html&&(s.html_body=e.html),e.text&&(s.plain_body=e.text),e.cc&&(s.cc=u(e.cc).map(n=>n.address)),e.bcc&&(s.bcc=u(e.bcc).map(n=>n.address)),e.replyTo&&(s.reply_to=h(e.replyTo).address),e.templateId&&(s.template_id=e.templateId,e.templateVariables&&(s.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(s.tag=e.tags.join(",")),e.headers){const n=P(e.headers);s.headers=n}e.attachments&&e.attachments.length>0&&(s.attachments=await Promise.all(e.attachments.map(async n=>{const v=await T(n,a);return{content_type:n.contentType??"application/octet-stream",data:v,name:n.filename}}))),o.debug("Sending email via Postal API",{subject:s.subject,to:s.to});const b={"Content-Type":"application/json","X-Server-API-Key":i.apiKey},c=await f(async()=>m(`${i.endpoint}/send/message`,{headers:b,method:"POST",timeout:i.timeout},JSON.stringify(s)),i.retries);if(!c.success)return o.debug("API request failed when sending email",c.error),{error:c.error??new l(a,"Failed to send email"),success:!1};const p=c.data?.body?.message_id?.toString()??w();return o.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return o.debug("Exception sending email",t),{error:new l(a,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
@@ -1 +1 @@
1
- import d from"./EmailError-CDvYwuqz.js";import T from"./RequiredOptionError-DU2lxzk3.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{s as w}from"./headers-to-record-De1Eg951.js";import{m as u}from"./make-request-CylyuRaN.js";import{i as f}from"./retry-CG9iT2wF.js";import{a as I,s as A}from"./sanitize-header-DtQwAnzg.js";import{f as C}from"./validate-email-options-mCM9dVug.js";import{defineProvider as S}from"./defineProvider-C9q-7iwt.js";import{P as j,h,c as E}from"./provider-base-DjPzWncP.js";import{e as p,g as v}from"./address-formatter-BWR2Dddx.js";import{b as z}from"./attachment-processor-D1cbAhQi.js";const r="postmark",M="https://api.postmarkapp.com",O=3e4,H=3,U=S((o={})=>{if(!o.serverToken)throw new T(r,"serverToken");const s={debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??H,serverToken:o.serverToken,timeout:o.timeout??O,...o.logger&&{logger:o.logger}},m=new j,i=E(r,o.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 d(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const a={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Retrieving email details",{id:e});const t=await f(async()=>u(`${s.endpoint}/messages/outbound/${e}/details`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new d(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:h(r,"retrieve email",a,i),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(r,"Postmark API not available or invalid server token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Checking Postmark API availability");const a=await u(`${s.endpoint}/server`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("Postmark API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=C(e);if(a.length>0)return{error:new d(r,`Invalid email options: ${a.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={From:v(e.from),Subject:e.subject,To:p(e.to).join(",")};if(e.html&&(t.HtmlBody=e.html),e.text&&(t.TextBody=e.text),e.cc&&(t.Cc=p(e.cc).join(",")),e.bcc&&(t.Bcc=p(e.bcc).join(",")),e.replyTo&&(t.ReplyTo=v(e.replyTo)),e.templateId?(t.TemplateId=e.templateId,e.templateModel&&(t.TemplateModel=e.templateModel)):e.templateAlias&&(t.TemplateAlias=e.templateAlias,e.templateModel&&(t.TemplateModel=e.templateModel)),e.trackOpens!==void 0&&(t.TrackOpens=e.trackOpens),e.trackLinks!==void 0&&(t.TrackLinks=e.trackLinks),e.inlineCss!==void 0&&(t.InlineCss=e.inlineCss),e.messageStream&&(t.MessageStream=e.messageStream),e.metadata&&(t.Metadata=e.metadata),e.tags&&e.tags.length>0){const[l]=e.tags;t.Tag=l}if(e.headers){const l=w(e.headers),c=[];for(const[b,y]of Object.entries(l))c.push({Name:A(b),Value:I(String(y))});c.length>0&&(t.Headers=c)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async l=>z(l,r)))),i.debug("Sending email via Postmark API",{subject:t.Subject,to:t.To});const k={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken},n=await f(async()=>u(`${s.endpoint}/email`,{headers:k,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new d(r,"Failed to send email"),success:!1};const g=n.data?.body?.MessageID??P();return i.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:r,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:h(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
1
+ import d from"./EmailError-2CCyVX1S.js";import T from"./RequiredOptionError-BmpC5whN.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{s as w}from"./headers-to-record-De1Eg951.js";import{m as u}from"./make-request-CDhxj-9b.js";import{i as f}from"./retry-D1Rh-6Z4.js";import{a as I,s as A}from"./sanitize-header-DtQwAnzg.js";import{f as C}from"./validate-email-options-mCM9dVug.js";import{defineProvider as S}from"./defineProvider-C9q-7iwt.js";import{P as j,h,c as E}from"./provider-base-B-xhQSqE.js";import{e as p,g as v}from"./address-formatter-bfmGfQ83.js";import{b as z}from"./attachment-processor-DjbjtJ6H.js";const r="postmark",M="https://api.postmarkapp.com",O=3e4,H=3,U=S((o={})=>{if(!o.serverToken)throw new T(r,"serverToken");const s={debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??H,serverToken:o.serverToken,timeout:o.timeout??O,...o.logger&&{logger:o.logger}},m=new j,i=E(r,o.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 d(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const a={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Retrieving email details",{id:e});const t=await f(async()=>u(`${s.endpoint}/messages/outbound/${e}/details`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new d(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:h(r,"retrieve email",a,i),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(r,"Postmark API not available or invalid server token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Checking Postmark API availability");const a=await u(`${s.endpoint}/server`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("Postmark API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=C(e);if(a.length>0)return{error:new d(r,`Invalid email options: ${a.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={From:v(e.from),Subject:e.subject,To:p(e.to).join(",")};if(e.html&&(t.HtmlBody=e.html),e.text&&(t.TextBody=e.text),e.cc&&(t.Cc=p(e.cc).join(",")),e.bcc&&(t.Bcc=p(e.bcc).join(",")),e.replyTo&&(t.ReplyTo=v(e.replyTo)),e.templateId?(t.TemplateId=e.templateId,e.templateModel&&(t.TemplateModel=e.templateModel)):e.templateAlias&&(t.TemplateAlias=e.templateAlias,e.templateModel&&(t.TemplateModel=e.templateModel)),e.trackOpens!==void 0&&(t.TrackOpens=e.trackOpens),e.trackLinks!==void 0&&(t.TrackLinks=e.trackLinks),e.inlineCss!==void 0&&(t.InlineCss=e.inlineCss),e.messageStream&&(t.MessageStream=e.messageStream),e.metadata&&(t.Metadata=e.metadata),e.tags&&e.tags.length>0){const[l]=e.tags;t.Tag=l}if(e.headers){const l=w(e.headers),c=[];for(const[b,y]of Object.entries(l))c.push({Name:A(b),Value:I(String(y))});c.length>0&&(t.Headers=c)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async l=>z(l,r)))),i.debug("Sending email via Postmark API",{subject:t.Subject,to:t.To});const k={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken},n=await f(async()=>u(`${s.endpoint}/email`,{headers:k,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new d(r,"Failed to send email"),success:!1};const g=n.data?.body?.MessageID??P();return i.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:r,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:h(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
@@ -1 +1 @@
1
- import r from"./EmailError-CDvYwuqz.js";import{c as n}from"./create-logger-BQTS3f-I.js";class l{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 r(e,`Failed to initialize: ${t.message}`,{cause:t})}}}const c=(a,i)=>n(a,i),z=(a,i,e,t)=>{const s=`Failed to ${i}: ${e.message}`;return t&&t.debug(`Exception ${i}`,e),new r(a,s,{cause:e})};export{l as P,c,z as h};
1
+ import r from"./EmailError-2CCyVX1S.js";import{c as n}from"./create-logger-BQTS3f-I.js";class l{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 r(e,`Failed to initialize: ${t.message}`,{cause:t})}}}const c=(a,i)=>n(a,i),z=(a,i,e,t)=>{const s=`Failed to ${i}: ${e.message}`;return t&&t.debug(`Exception ${i}`,e),new r(a,s,{cause:e})};export{l as P,c,z as h};
@@ -1 +1 @@
1
- import c from"./EmailError-CDvYwuqz.js";import w from"./RequiredOptionError-DU2lxzk3.js";import{e as I}from"./generate-message-id-gXAuMz4g.js";import{s as P}from"./headers-to-record-De1Eg951.js";import{m as p}from"./make-request-CylyuRaN.js";import{i as y}from"./retry-CG9iT2wF.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import{P as E,h as f,c as T}from"./provider-base-DjPzWncP.js";import{e as z,g as b,d as v}from"./address-formatter-BWR2Dddx.js";import{p as k}from"./attachment-processor-D1cbAhQi.js";const i="resend",S="https://api.resend.com",K=3e4,R=3,_=r=>{const a=[],d=/^[\w-]+$/;return d.test(r.name)||a.push(`Tag name '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r.name.length>256&&a.push(`Tag name '${r.name}' exceeds maximum length of 256 characters`),d.test(r.value)||a.push(`Tag value '${r.value}' for tag '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),a},U=C((r={})=>{if(!r.apiKey)throw new w(i,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??S,logger:r.logger,retries:r.retries??R,timeout:r.timeout??K},d=new E,n=T(i,r.logger);return{endpoint:a.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(i,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),i);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const s=await y(async()=>p(`${a.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.retries);return s.success?(n.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(n.debug("API request failed when retrieving email",s.error),{error:new c(i,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(t){return{error:f(i,"retrieve email",t,n),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(i,"Resend API not available or invalid API key");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("re_"))return n.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Checking Resend API availability");const t=await p(`${a.endpoint}/domains`,{headers:e,method:"GET",timeout:a.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:i,options:a,async sendEmail(e){try{const t=j(e);if(t.length>0)return{error:new c(i,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),i);const s={from:b(e.from),headers:e.headers?P(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:z(e.to)};if(e.cc&&(s.cc=v(e.cc)),e.bcc&&(s.bcc=v(e.bcc)),e.replyTo&&(s.reply_to=b(e.replyTo)),e.templateId&&(s.template=e.templateId,e.templateData&&(s.data=e.templateData)),e.scheduledAt&&(s.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const o=[];if(e.tags.forEach(m=>{const g=_(m);g.length>0&&o.push(...g)}),o.length>0)return{error:new c(i,`Invalid email tags: ${o.join(", ")}`),success:!1};s.tags=e.tags.map(m=>({name:m.name,value:m.value}))}e.attachments&&e.attachments.length>0&&(s.attachments=await Promise.all(e.attachments.map(async o=>({content:await k(o,i),content_type:o.contentType,filename:o.filename,...o.path&&{path:o.path}})))),n.debug("Sending email via Resend API",{subject:s.subject,to:s.to});const A={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},l=await y(async()=>p(`${a.endpoint}/emails`,{headers:A,method:"POST",timeout:a.timeout},JSON.stringify(s)),a.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error??new c(i,"Failed to send email"),success:!1};const u=l.data,h=u?.body&&typeof u.body=="object"&&u.body.id?u.body.id:I();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:i,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:f(i,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
1
+ import c from"./EmailError-2CCyVX1S.js";import w from"./RequiredOptionError-BmpC5whN.js";import{e as I}from"./generate-message-id-gXAuMz4g.js";import{s as P}from"./headers-to-record-De1Eg951.js";import{m as p}from"./make-request-CDhxj-9b.js";import{i as y}from"./retry-D1Rh-6Z4.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import{P as E,h as f,c as T}from"./provider-base-B-xhQSqE.js";import{e as z,g as b,d as v}from"./address-formatter-bfmGfQ83.js";import{p as k}from"./attachment-processor-DjbjtJ6H.js";const i="resend",S="https://api.resend.com",K=3e4,R=3,_=r=>{const a=[],d=/^[\w-]+$/;return d.test(r.name)||a.push(`Tag name '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r.name.length>256&&a.push(`Tag name '${r.name}' exceeds maximum length of 256 characters`),d.test(r.value)||a.push(`Tag value '${r.value}' for tag '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),a},U=C((r={})=>{if(!r.apiKey)throw new w(i,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??S,logger:r.logger,retries:r.retries??R,timeout:r.timeout??K},d=new E,n=T(i,r.logger);return{endpoint:a.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(i,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),i);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const s=await y(async()=>p(`${a.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.retries);return s.success?(n.debug("Email details retrieved successfully"),{data:s.data?.body,success:!0}):(n.debug("API request failed when retrieving email",s.error),{error:new c(i,`Failed to retrieve email: ${s.error instanceof Error?s.error.message:"Unknown error"}`,{cause:s.error}),success:!1})}catch(t){return{error:f(i,"retrieve email",t,n),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(i,"Resend API not available or invalid API key");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("re_"))return n.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Checking Resend API availability");const t=await p(`${a.endpoint}/domains`,{headers:e,method:"GET",timeout:a.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:i,options:a,async sendEmail(e){try{const t=j(e);if(t.length>0)return{error:new c(i,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),i);const s={from:b(e.from),headers:e.headers?P(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:z(e.to)};if(e.cc&&(s.cc=v(e.cc)),e.bcc&&(s.bcc=v(e.bcc)),e.replyTo&&(s.reply_to=b(e.replyTo)),e.templateId&&(s.template=e.templateId,e.templateData&&(s.data=e.templateData)),e.scheduledAt&&(s.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const o=[];if(e.tags.forEach(m=>{const g=_(m);g.length>0&&o.push(...g)}),o.length>0)return{error:new c(i,`Invalid email tags: ${o.join(", ")}`),success:!1};s.tags=e.tags.map(m=>({name:m.name,value:m.value}))}e.attachments&&e.attachments.length>0&&(s.attachments=await Promise.all(e.attachments.map(async o=>({content:await k(o,i),content_type:o.contentType,filename:o.filename,...o.path&&{path:o.path}})))),n.debug("Sending email via Resend API",{subject:s.subject,to:s.to});const A={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},l=await y(async()=>p(`${a.endpoint}/emails`,{headers:A,method:"POST",timeout:a.timeout},JSON.stringify(s)),a.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error??new c(i,"Failed to send email"),success:!1};const u=l.data,h=u?.body&&typeof u.body=="object"&&u.body.id?u.body.id:I();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:i,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:f(i,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
@@ -1 +1 @@
1
- import c from"./EmailError-CDvYwuqz.js";import{R as i}from"./make-request-CylyuRaN.js";const m=new Set([408,429,503]),u=r=>{const{statusCode:t}=r.data??{};return t!==void 0?m.has(t):!(r.error instanceof c&&r.error.code===i)},a=async(r,t=3,s=300,e=u)=>{try{const o=await r();return o.success||t<=0||!e(o)?o:(await new Promise(n=>{setTimeout(()=>{n()},s)}),a(r,t-1,s*2,e))}catch(o){return t<=0?{error:o instanceof Error?o:new Error(String(o)),success:!1}:(await new Promise(n=>{setTimeout(()=>{n()},s)}),a(r,t-1,s*2,e))}};export{a as i};
1
+ import c from"./EmailError-2CCyVX1S.js";import{R as i}from"./make-request-CDhxj-9b.js";const m=new Set([408,429,503]),u=r=>{const{statusCode:t}=r.data??{};return t!==void 0?m.has(t):!(r.error instanceof c&&r.error.code===i)},a=async(r,t=3,s=300,e=u)=>{try{const o=await r();return o.success||t<=0||!e(o)?o:(await new Promise(n=>{setTimeout(()=>{n()},s)}),a(r,t-1,s*2,e))}catch(o){return t<=0?{error:o instanceof Error?o:new Error(String(o)),success:!1}:(await new Promise(n=>{setTimeout(()=>{n()},s)}),a(r,t-1,s*2,e))}};export{a as i};
@@ -1 +1 @@
1
- import g from"./EmailError-CDvYwuqz.js";import y from"./RequiredOptionError-DU2lxzk3.js";import{c as $}from"./create-logger-BQTS3f-I.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{d as A}from"./aggregate-features-BqEjPd42.js";const k=i=>typeof i=="function",z=i=>i!=null&&typeof i=="object"&&"sendEmail"in i&&"initialize"in i&&"isAvailable"in i,o="roundrobin",R=E((i={})=>{if(!i.mailers||i.mailers.length===0)throw new y(o,"mailers");const f={debug:i.debug??!1,logger:i.logger,mailers:i.mailers,retries:i.retries??3,retryAfter:i.retryAfter??60,timeout:i.timeout??3e4};let v=!1;const r=[];let a=0;const n=$(o,i.logger),m=async()=>{r.length=0;for(const t of f.mailers)try{let e;if(k(t))e=t({});else if(z(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 g(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"})`)},p=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 d=s.name??`provider-${a+1}`;try{if(await s.isAvailable())return a=(a+1)%r.length,n.debug(`Selected provider: ${d} (index ${a===0?r.length-1:a-1})`),s}catch{}a=(a+1)%r.length,e+=1,e<r.length&&f.retryAfter>0&&await new Promise(l=>{setTimeout(()=>{l(void 0)},f.retryAfter)})}return n.debug(`No available providers found, using provider at index ${t}`),r[t]??void 0};return{features:A(f.mailers),async initialize(){if(!v)try{await m(),v=!0,n.debug(`Round robin provider initialized with ${r.length} provider(s)`)}catch(t){throw new g(o,`Failed to initialize: ${t.message}`,{cause:t})}},async isAvailable(){try{return r.length===0&&await m(),(await Promise.allSettled(r.map(t=>t.isAvailable()))).some(t=>t.status==="fulfilled"&&t.value)}catch{return!1}},name:o,options:f,async sendEmail(t){try{if(r.length===0&&await m(),r.length===0)return{error:new g(o,"No providers available"),success:!1};const e=await p();if(!e)return{error:new g(o,"No available providers found"),success:!1};const s=e.name??"unknown";n.debug(`Sending email via ${s}`);const d=await e.sendEmail(t);if(d.success)return n.debug(`Email sent successfully via ${s}`),{data:{...d.data,provider:`${o}(${s})`},success:!0};n.debug(`Failed to send via ${s}, trying next provider`);const l=[];d.error&&l.push(d.error);let w=0;for(;w<r.length-1;){const u=await p();if(!u||u===e)break;const h=u.name??"unknown";n.debug(`Retrying with ${h}`);try{const c=await u.sendEmail(t);if(c.success)return n.debug(`Email sent successfully via ${h} (after retry)`),{data:{...c.data,provider:`${o}(${h})`},success:!0};c.error&&l.push(c.error)}catch(c){l.push(c instanceof Error?c:new Error(String(c)))}w+=1}const b=l.map(u=>u instanceof Error?u.message:String(u)).join("; ");return{error:new g(o,`Failed to send email via all providers. Errors: ${b}`,{cause:l[0]instanceof Error?l[0]:new Error(String(l[0]))}),success:!1}}catch(e){return{error:new g(o,`Failed to send email: ${e.message}`,{cause:e}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
1
+ import g from"./EmailError-2CCyVX1S.js";import y from"./RequiredOptionError-BmpC5whN.js";import{c as $}from"./create-logger-BQTS3f-I.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{d as A}from"./aggregate-features-BqEjPd42.js";const k=i=>typeof i=="function",z=i=>i!=null&&typeof i=="object"&&"sendEmail"in i&&"initialize"in i&&"isAvailable"in i,o="roundrobin",R=E((i={})=>{if(!i.mailers||i.mailers.length===0)throw new y(o,"mailers");const f={debug:i.debug??!1,logger:i.logger,mailers:i.mailers,retries:i.retries??3,retryAfter:i.retryAfter??60,timeout:i.timeout??3e4};let v=!1;const r=[];let a=0;const n=$(o,i.logger),m=async()=>{r.length=0;for(const t of f.mailers)try{let e;if(k(t))e=t({});else if(z(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 g(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"})`)},p=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 d=s.name??`provider-${a+1}`;try{if(await s.isAvailable())return a=(a+1)%r.length,n.debug(`Selected provider: ${d} (index ${a===0?r.length-1:a-1})`),s}catch{}a=(a+1)%r.length,e+=1,e<r.length&&f.retryAfter>0&&await new Promise(l=>{setTimeout(()=>{l(void 0)},f.retryAfter)})}return n.debug(`No available providers found, using provider at index ${t}`),r[t]??void 0};return{features:A(f.mailers),async initialize(){if(!v)try{await m(),v=!0,n.debug(`Round robin provider initialized with ${r.length} provider(s)`)}catch(t){throw new g(o,`Failed to initialize: ${t.message}`,{cause:t})}},async isAvailable(){try{return r.length===0&&await m(),(await Promise.allSettled(r.map(t=>t.isAvailable()))).some(t=>t.status==="fulfilled"&&t.value)}catch{return!1}},name:o,options:f,async sendEmail(t){try{if(r.length===0&&await m(),r.length===0)return{error:new g(o,"No providers available"),success:!1};const e=await p();if(!e)return{error:new g(o,"No available providers found"),success:!1};const s=e.name??"unknown";n.debug(`Sending email via ${s}`);const d=await e.sendEmail(t);if(d.success)return n.debug(`Email sent successfully via ${s}`),{data:{...d.data,provider:`${o}(${s})`},success:!0};n.debug(`Failed to send via ${s}, trying next provider`);const l=[];d.error&&l.push(d.error);let w=0;for(;w<r.length-1;){const u=await p();if(!u||u===e)break;const h=u.name??"unknown";n.debug(`Retrying with ${h}`);try{const c=await u.sendEmail(t);if(c.success)return n.debug(`Email sent successfully via ${h} (after retry)`),{data:{...c.data,provider:`${o}(${h})`},success:!0};c.error&&l.push(c.error)}catch(c){l.push(c instanceof Error?c:new Error(String(c)))}w+=1}const b=l.map(u=>u instanceof Error?u.message:String(u)).join("; ");return{error:new g(o,`Failed to send email via all providers. Errors: ${b}`,{cause:l[0]instanceof Error?l[0]:new Error(String(l[0]))}),success:!1}}catch(e){return{error:new g(o,`Failed to send email: ${e.message}`,{cause:e}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};