@visulima/email 1.0.0-alpha.43 → 1.0.0-alpha.44

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 (94) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +10 -191
  3. package/dist/index.js +1 -1
  4. package/dist/packem_shared/DraftMailMessage-BxqGSLMN.js +1 -0
  5. package/dist/packem_shared/Mail-BEuzrB00.js +1 -0
  6. package/dist/packem_shared/MailMessage-D9k5gYrd.js +1 -0
  7. package/dist/packem_shared/ahaSendProvider-D81_wUA1.js +1 -0
  8. package/dist/packem_shared/{attachment-processor-BjTNoMyb.js → attachment-processor-CMp7qqMI.js} +1 -1
  9. package/dist/packem_shared/{azureProvider-DlM6UWUv.js → azureProvider-CmcK4bsf.js} +1 -1
  10. package/dist/packem_shared/brevoProvider-C1BDXr41.js +1 -0
  11. package/dist/packem_shared/{build-mime-message-Be6TOi1T.js → build-mime-message-B6927SQy.js} +2 -2
  12. package/dist/packem_shared/{cloudflareEmailProvider-D4adkOjA.js → cloudflareEmailProvider-Bv-ty-74.js} +1 -1
  13. package/dist/packem_shared/{createTestEmail-BM3iNznm.js → createTestEmail-CF_RUjqo.js} +1 -1
  14. package/dist/packem_shared/infobipProvider-lHyGrXgZ.js +1 -0
  15. package/dist/packem_shared/{loopsProvider-BXr0KSjB.js → loopsProvider-DyloxzNC.js} +1 -1
  16. package/dist/packem_shared/{mailCrabProvider-C7Ao5H9p.js → mailCrabProvider-CPtBT6Th.js} +1 -1
  17. package/dist/packem_shared/{mailPaceProvider-DklGeGEM.js → mailPaceProvider-CJEvOFBh.js} +1 -1
  18. package/dist/packem_shared/{mailchannelsProvider-DPfQVzUd.js → mailchannelsProvider-osRkW_tz.js} +1 -1
  19. package/dist/packem_shared/mailerSendProvider-C_6LzARK.js +1 -0
  20. package/dist/packem_shared/{mailgunProvider-Ctyrs9d0.js → mailgunProvider-DkISvMPe.js} +1 -1
  21. package/dist/packem_shared/mailjetProvider-CV0i4Xzh.js +1 -0
  22. package/dist/packem_shared/mailomatProvider-B5YFonEO.js +1 -0
  23. package/dist/packem_shared/mailtrapProvider-C4ZquIPz.js +1 -0
  24. package/dist/packem_shared/mandrillProvider-DWPFh_Sj.js +1 -0
  25. package/dist/packem_shared/{netcoreProvider-XMWO_Aoa.js → netcoreProvider-C5TEciaN.js} +1 -1
  26. package/dist/packem_shared/{outlook365Provider-BoNtxqIx.js → outlook365Provider-63ggDpqV.js} +1 -1
  27. package/dist/packem_shared/plunkProvider-yTlrJVEp.js +1 -0
  28. package/dist/packem_shared/postalProvider-CRX_bMYD.js +1 -0
  29. package/dist/packem_shared/{postmarkProvider-DWQJv5_M.js → postmarkProvider-CDx85Yge.js} +1 -1
  30. package/dist/packem_shared/{provider-base-gIoUu9so.js → provider-base-C7PuopYK.js} +1 -1
  31. package/dist/packem_shared/resendProvider-CiclWxzr.js +1 -0
  32. package/dist/packem_shared/scalewayProvider-BcND48qO.js +1 -0
  33. package/dist/packem_shared/{sendGridProvider-CChhLr7s.js → sendGridProvider-D8ZLgY62.js} +1 -1
  34. package/dist/packem_shared/{smtpProvider-x4WBN-3W.js → smtpProvider-Bm0yP97W.js} +1 -1
  35. package/dist/packem_shared/{sparkpostProvider-BytvwqjP.js → sparkpostProvider-CTYfSRaV.js} +1 -1
  36. package/dist/packem_shared/sweegoProvider-DOoin_vi.js +1 -0
  37. package/dist/packem_shared/{zeptomailProvider-D3nQKXRf.js → zeptomailProvider-DKBPSHPj.js} +1 -1
  38. package/dist/providers/ahasend/index.js +1 -1
  39. package/dist/providers/azure/index.js +1 -1
  40. package/dist/providers/brevo/index.js +1 -1
  41. package/dist/providers/cloudflare-email/index.js +1 -1
  42. package/dist/providers/infobip/index.js +1 -1
  43. package/dist/providers/loops/index.js +1 -1
  44. package/dist/providers/mailchannels/index.js +1 -1
  45. package/dist/providers/mailcrab/index.js +1 -1
  46. package/dist/providers/mailersend/index.js +1 -1
  47. package/dist/providers/mailgun/index.js +1 -1
  48. package/dist/providers/mailjet/index.js +1 -1
  49. package/dist/providers/mailomat/index.js +1 -1
  50. package/dist/providers/mailpace/index.js +1 -1
  51. package/dist/providers/mailtrap/index.js +1 -1
  52. package/dist/providers/mandrill/index.js +1 -1
  53. package/dist/providers/netcore/index.js +1 -1
  54. package/dist/providers/outlook365/index.js +1 -1
  55. package/dist/providers/plunk/index.js +1 -1
  56. package/dist/providers/postal/index.js +1 -1
  57. package/dist/providers/postmark/index.js +1 -1
  58. package/dist/providers/resend/index.js +1 -1
  59. package/dist/providers/scaleway/index.js +1 -1
  60. package/dist/providers/sendgrid/index.js +1 -1
  61. package/dist/providers/smtp/index.js +1 -1
  62. package/dist/providers/sparkpost/index.js +1 -1
  63. package/dist/providers/sweego/index.js +1 -1
  64. package/dist/providers/zeptomail/index.js +1 -1
  65. package/dist/test/index.d.ts +0 -4
  66. package/dist/test/index.js +1 -1
  67. package/dist/utils/parse-eml.js +2 -2
  68. package/package.json +1 -24
  69. package/dist/packem_shared/DraftMailMessage-C9tevR8K.js +0 -1
  70. package/dist/packem_shared/Mail-DpjH0Exh.js +0 -1
  71. package/dist/packem_shared/MailMessage-L-Q9yc5v.js +0 -1
  72. package/dist/packem_shared/ahaSendProvider-Dq5mElHZ.js +0 -1
  73. package/dist/packem_shared/brevoProvider-D_Hhc0Z-.js +0 -1
  74. package/dist/packem_shared/infobipProvider-oOL-ThpP.js +0 -1
  75. package/dist/packem_shared/mailerSendProvider-B8iT5Uhb.js +0 -1
  76. package/dist/packem_shared/mailjetProvider-v55nFDsr.js +0 -1
  77. package/dist/packem_shared/mailomatProvider-BCyB4Q4B.js +0 -1
  78. package/dist/packem_shared/mailtrapProvider-DcVw3sxR.js +0 -1
  79. package/dist/packem_shared/mandrillProvider-gqMFMwgs.js +0 -1
  80. package/dist/packem_shared/plunkProvider-C0LO-1E3.js +0 -1
  81. package/dist/packem_shared/postalProvider-B26IqgxE.js +0 -1
  82. package/dist/packem_shared/resendProvider-DhvKVyCD.js +0 -1
  83. package/dist/packem_shared/scalewayProvider-D8dmHuwZ.js +0 -1
  84. package/dist/packem_shared/sweegoProvider-7xhOvagC.js +0 -1
  85. package/dist/utils/validation/check-mx-records.d.ts +0 -43
  86. package/dist/utils/validation/check-mx-records.js +0 -1
  87. package/dist/utils/validation/disposable-email-domains.d.ts +0 -1
  88. package/dist/utils/validation/disposable-email-domains.js +0 -1
  89. package/dist/utils/validation/role-accounts.d.ts +0 -21
  90. package/dist/utils/validation/role-accounts.js +0 -1
  91. package/dist/utils/validation/verify-email.d.ts +0 -50
  92. package/dist/utils/validation/verify-email.js +0 -1
  93. package/dist/utils/validation/verify-smtp.d.ts +0 -40
  94. package/dist/utils/validation/verify-smtp.js +0 -4
@@ -0,0 +1 @@
1
+ import l from"./EmailError-B-sEf3bp.js";import b from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as g}from"./retry-3pnxTuNs.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-C7PuopYK.js";import{f as u,a as I}from"./address-formatter-BWR2Dddx.js";import{p as P}from"./attachment-processor-CMp7qqMI.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};
@@ -0,0 +1 @@
1
+ import d from"./EmailError-B-sEf3bp.js";import P from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as y}from"./retry-3pnxTuNs.js";import{s as h,a as I}from"./sanitize-header-DJhgZl3y.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-C7PuopYK.js";import{k as p}from"./address-formatter-BWR2Dddx.js";import{p as E}from"./attachment-processor-CMp7qqMI.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 p from"./EmailError-B-sEf3bp.js";import g from"./RequiredOptionError-DuNNY_a5.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as v}from"./make-request-BlK_B72c.js";import{u as b}from"./retry-3pnxTuNs.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-gIoUu9so.js";import{a as l}from"./address-formatter-BWR2Dddx.js";import{c as K}from"./attachment-processor-BjTNoMyb.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-B-sEf3bp.js";import g from"./RequiredOptionError-DuNNY_a5.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as v}from"./make-request-BlK_B72c.js";import{u as b}from"./retry-3pnxTuNs.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-C7PuopYK.js";import{a as l}from"./address-formatter-BWR2Dddx.js";import{c as K}from"./attachment-processor-CMp7qqMI.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"./EmailError-B-sEf3bp.js";import h from"./RequiredOptionError-DuNNY_a5.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as k}from"./make-request-BlK_B72c.js";import{u as v}from"./retry-3pnxTuNs.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{c as w}from"./attachment-processor-BjTNoMyb.js";import{h as I,P as S,c as P}from"./provider-base-gIoUu9so.js";const a="outlook365",j="https://graph.microsoft.com/v1.0",R=3e4,x=3,o=t=>[t].flat(),c=t=>t.map(s=>({emailAddress:{address:s.email,...s.name?{name:s.name}:{}}})),q=b((t={})=>{if(!t.accessToken&&!t.getAccessToken)throw new h(a,["accessToken","getAccessToken"]);const s={accessToken:t.accessToken,debug:t.debug??!1,endpoint:t.endpoint??j,getAccessToken:t.getAccessToken,logger:t.logger,retries:t.retries??x,saveToSentItems:t.saveToSentItems??!0,timeout:t.timeout??R,userId:t.userId??"me"},p=new S,f=P(a,t.logger),g=async()=>s.getAccessToken?s.getAccessToken():s.accessToken;return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){p.setInitialized()},async isAvailable(){return!!(s.accessToken??s.getAccessToken)},name:a,options:s,async sendEmail(e){try{const n=A(e);if(n.length>0)return{error:new u(a,`Invalid email options: ${n.join(", ")}`),success:!1};let d;try{d=await g()}catch(m){return{error:new u(a,"Failed to obtain access token",{cause:m}),success:!1}}const r={body:{content:e.html??e.text??"",contentType:e.html?"HTML":"Text"},subject:e.subject,toRecipients:c(o(e.to))};e.cc&&(r.ccRecipients=c(o(e.cc))),e.bcc&&(r.bccRecipients=c(o(e.bcc))),e.replyTo&&(r.replyTo=c(o(e.replyTo))),e.importance&&(r.importance=e.importance),e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async m=>{const l=await w(m,a);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:l.content,contentType:l.contentType,name:l.filename}})));const T=s.userId==="me"?"me":`users/${s.userId}`,i=await v(async()=>k(`${s.endpoint}/${T}/sendMail`,{headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify({message:r,saveToSentItems:s.saveToSentItems})),s.retries);return i.success?{data:{messageId:y(),provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new u(a,"Failed to send email"),success:!1}}catch(n){return{error:I(a,"send email",n,f),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{q as default};
1
+ import u from"./EmailError-B-sEf3bp.js";import h from"./RequiredOptionError-DuNNY_a5.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as k}from"./make-request-BlK_B72c.js";import{u as v}from"./retry-3pnxTuNs.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{c as w}from"./attachment-processor-CMp7qqMI.js";import{h as I,P as S,c as P}from"./provider-base-C7PuopYK.js";const a="outlook365",j="https://graph.microsoft.com/v1.0",R=3e4,x=3,o=t=>[t].flat(),c=t=>t.map(s=>({emailAddress:{address:s.email,...s.name?{name:s.name}:{}}})),q=b((t={})=>{if(!t.accessToken&&!t.getAccessToken)throw new h(a,["accessToken","getAccessToken"]);const s={accessToken:t.accessToken,debug:t.debug??!1,endpoint:t.endpoint??j,getAccessToken:t.getAccessToken,logger:t.logger,retries:t.retries??x,saveToSentItems:t.saveToSentItems??!0,timeout:t.timeout??R,userId:t.userId??"me"},p=new S,f=P(a,t.logger),g=async()=>s.getAccessToken?s.getAccessToken():s.accessToken;return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){p.setInitialized()},async isAvailable(){return!!(s.accessToken??s.getAccessToken)},name:a,options:s,async sendEmail(e){try{const n=A(e);if(n.length>0)return{error:new u(a,`Invalid email options: ${n.join(", ")}`),success:!1};let d;try{d=await g()}catch(m){return{error:new u(a,"Failed to obtain access token",{cause:m}),success:!1}}const r={body:{content:e.html??e.text??"",contentType:e.html?"HTML":"Text"},subject:e.subject,toRecipients:c(o(e.to))};e.cc&&(r.ccRecipients=c(o(e.cc))),e.bcc&&(r.bccRecipients=c(o(e.bcc))),e.replyTo&&(r.replyTo=c(o(e.replyTo))),e.importance&&(r.importance=e.importance),e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async m=>{const l=await w(m,a);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:l.content,contentType:l.contentType,name:l.filename}})));const T=s.userId==="me"?"me":`users/${s.userId}`,i=await v(async()=>k(`${s.endpoint}/${T}/sendMail`,{headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify({message:r,saveToSentItems:s.saveToSentItems})),s.retries);return i.success?{data:{messageId:y(),provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new u(a,"Failed to send email"),success:!1}}catch(n){return{error:I(a,"send email",n,f),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{q as default};
@@ -0,0 +1 @@
1
+ import m from"./EmailError-B-sEf3bp.js";import P from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as g}from"./retry-3pnxTuNs.js";import{a as k,s as z}from"./sanitize-header-DJhgZl3y.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-C7PuopYK.js";import{p as x}from"./attachment-processor-CMp7qqMI.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};
@@ -0,0 +1 @@
1
+ import l from"./EmailError-B-sEf3bp.js";import g from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as f}from"./retry-3pnxTuNs.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-C7PuopYK.js";import{l as u,m as h}from"./address-formatter-BWR2Dddx.js";import{p as T}from"./attachment-processor-CMp7qqMI.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-B-sEf3bp.js";import T from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as f}from"./retry-3pnxTuNs.js";import{s as I,a as A}from"./sanitize-header-DJhgZl3y.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-gIoUu9so.js";import{e as p,g as v}from"./address-formatter-BWR2Dddx.js";import{b as z}from"./attachment-processor-BjTNoMyb.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-B-sEf3bp.js";import T from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as f}from"./retry-3pnxTuNs.js";import{s as I,a as A}from"./sanitize-header-DJhgZl3y.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-C7PuopYK.js";import{e as p,g as v}from"./address-formatter-BWR2Dddx.js";import{b as z}from"./attachment-processor-CMp7qqMI.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 s from"./EmailError-B-sEf3bp.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 s(e,`Failed to initialize: ${t.message}`,{cause:t})}}}const c=(a,i)=>n(a,i),z=(a,i,e,t)=>{const r=`Failed to ${i}: ${e.message}`;return t&&t.debug(`Exception ${i}`,e),new s(a,r,{cause:e})};export{l as P,c,z as h};
1
+ import r from"./EmailError-B-sEf3bp.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};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-B-sEf3bp.js";import w from"./RequiredOptionError-DuNNY_a5.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-BlK_B72c.js";import{u as y}from"./retry-3pnxTuNs.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-C7PuopYK.js";import{e as z,g as b,d as v}from"./address-formatter-BWR2Dddx.js";import{p as k}from"./attachment-processor-CMp7qqMI.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"},u=await y(async()=>p(`${a.endpoint}/emails`,{headers:A,method:"POST",timeout:a.timeout},JSON.stringify(s)),a.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(i,"Failed to send email"),success:!1};const l=u.data,h=l?.body&&typeof l.body=="object"&&l.body.id?l.body.id:I();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:i,response:u.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};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-B-sEf3bp.js";import p from"./RequiredOptionError-DuNNY_a5.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m as f}from"./make-request-BlK_B72c.js";import{u as g}from"./retry-3pnxTuNs.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as A}from"./defineProvider-C9q-7iwt.js";import{P,h,c as j}from"./provider-base-C7PuopYK.js";import{f as d,a as T}from"./address-formatter-BWR2Dddx.js";import{p as S}from"./attachment-processor-CMp7qqMI.js";const r="scaleway",k="https://api.scaleway.com/transactional-email/v1alpha1",E=3e4,z=3,H=A((a={})=>{if(!a.apiKey)throw new p(r,"apiKey");if(!a.region)throw new p(r,"region");const y=a.endpoint??k,i={apiKey:a.apiKey,debug:a.debug??!1,endpoint:y,region:a.region,retries:a.retries??z,timeout:a.timeout??E,...a.logger&&{logger:a.logger}},m=new P,s=j(r,a.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const n={"Content-Type":"application/json","X-Auth-Token":i.apiKey};s.debug("Retrieving email details",{id:e});const t=await g(async()=>f(`${i.endpoint}/regions/${i.region}/emails/${e}`,{headers:n,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 c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(n){return{error:h(r,"retrieve email",n,s),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"Scaleway API not available or invalid API key");s.debug("Provider initialized successfully")},r)},async isAvailable(){try{return s.debug("Checking Scaleway API availability"),!0}catch(e){return s.debug("Error checking availability:",e),!1}},name:r,options:i,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:{email:e.from.email,...e.from.name&&{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=T(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.projectId&&(t.projectId=e.projectId),e.headers){const l=v(e.headers);t.headers=l}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async l=>({content:await S(l,r),name:l.filename,type:l.contentType??"application/octet-stream"})))),s.debug("Sending email via Scaleway API",{subject:t.subject,to:t.to});const b={"Content-Type":"application/json","X-Auth-Token":i.apiKey},o=await g(async()=>f(`${i.endpoint}/regions/${i.region}/emails`,{headers:b,method:"POST",timeout:i.timeout},JSON.stringify(t)),i.retries);if(!o.success)return s.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const u=o.data?.body?.id??w();return s.debug("Email sent successfully",{messageId:u}),{data:{messageId:u,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(n){return{error:h(r,"send email",n,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
@@ -1 +1 @@
1
- import l from"./EmailError-B-sEf3bp.js";import A from"./RequiredOptionError-DuNNY_a5.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{s as S}from"./headers-to-record-De1Eg951.js";import{m as h}from"./make-request-BlK_B72c.js";import{u as b}from"./retry-3pnxTuNs.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as G}from"./defineProvider-C9q-7iwt.js";import{P as k,h as v,c as z}from"./provider-base-gIoUu9so.js";import{f,a as I}from"./address-formatter-BWR2Dddx.js";import{d as C}from"./attachment-processor-BjTNoMyb.js";const s="sendgrid",E="https://api.sendgrid.com/v3",_=3e4,T=3,L=G((o={})=>{if(!o.apiKey)throw new A(s,"apiKey");const a={apiKey:o.apiKey,debug:o.debug??!1,endpoint:o.endpoint??E,...o.logger&&{logger:o.logger},retries:o.retries??T,timeout:o.timeout??_},p=new k,i=z(s,o.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 l(s,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await b(async()=>h(`${a.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new l(s,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:v(s,"retrieve email",t,i),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"SendGrid API not available or invalid API key");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("SG."))return i.debug("API key format is valid, assuming SendGrid is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Checking SendGrid API availability");const t=await h(`${a.endpoint}/user/profile`,{headers:e,method:"GET",timeout:a.timeout});return i.debug("SendGrid API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const t=j(e);if(t.length>0)return{error:new l(s,`Invalid email options: ${t.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const r={to:f(e.to)};if(e.cc&&(r.cc=f(e.cc)),e.bcc&&(r.bcc=f(e.bcc)),e.subject&&(r.subject=e.subject),e.tags&&e.tags.length>0){const d={};for(let m=0;m<e.tags.length;m+=1)d[`tag_${m}`]=e.tags[m];r.customArgs=d}const n={from:I(e.from),personalizations:[r]},u=[];if(e.html&&u.push({type:"text/html",value:e.html}),e.text&&u.push({type:"text/plain",value:e.text}),u.length>0&&(n.content=u),e.replyTo&&(n.reply_to=I(e.replyTo)),e.subject&&(n.subject=e.subject),e.templateId&&(n.template_id=e.templateId,e.templateData&&(r.dynamicTemplateData=e.templateData)),e.sendAt&&(r.send_at=e.sendAt),e.batchId&&(n.batch_id=e.batchId),e.asmGroupId&&(n.asm={group_id:e.asmGroupId}),e.ipPoolName&&(n.ip_pool_name=e.ipPoolName),e.mailSettings&&(n.mail_settings=e.mailSettings),e.trackingSettings&&(n.tracking_settings=e.trackingSettings),e.headers){const d=S(e.headers);n.headers=d}e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async d=>C(d,s)))),i.debug("Sending email via SendGrid API",{subject:n.subject,to:r.to});const w={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},c=await b(async()=>h(`${a.endpoint}/mail/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(n)),a.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new l(s,"Failed to send email"),success:!1};const g=c.data?.headers,y=(g&&g instanceof Headers?g.get("X-Message-Id"):void 0)??P();return i.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:s,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(s,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
1
+ import l from"./EmailError-B-sEf3bp.js";import A from"./RequiredOptionError-DuNNY_a5.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{s as S}from"./headers-to-record-De1Eg951.js";import{m as h}from"./make-request-BlK_B72c.js";import{u as b}from"./retry-3pnxTuNs.js";import{f as j}from"./validate-email-options-mCM9dVug.js";import{defineProvider as G}from"./defineProvider-C9q-7iwt.js";import{P as k,h as v,c as z}from"./provider-base-C7PuopYK.js";import{f,a as I}from"./address-formatter-BWR2Dddx.js";import{d as C}from"./attachment-processor-CMp7qqMI.js";const s="sendgrid",E="https://api.sendgrid.com/v3",_=3e4,T=3,L=G((o={})=>{if(!o.apiKey)throw new A(s,"apiKey");const a={apiKey:o.apiKey,debug:o.debug??!1,endpoint:o.endpoint??E,...o.logger&&{logger:o.logger},retries:o.retries??T,timeout:o.timeout??_},p=new k,i=z(s,o.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 l(s,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await b(async()=>h(`${a.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new l(s,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:v(s,"retrieve email",t,i),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"SendGrid API not available or invalid API key");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("SG."))return i.debug("API key format is valid, assuming SendGrid is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Checking SendGrid API availability");const t=await h(`${a.endpoint}/user/profile`,{headers:e,method:"GET",timeout:a.timeout});return i.debug("SendGrid API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const t=j(e);if(t.length>0)return{error:new l(s,`Invalid email options: ${t.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const r={to:f(e.to)};if(e.cc&&(r.cc=f(e.cc)),e.bcc&&(r.bcc=f(e.bcc)),e.subject&&(r.subject=e.subject),e.tags&&e.tags.length>0){const d={};for(let m=0;m<e.tags.length;m+=1)d[`tag_${m}`]=e.tags[m];r.customArgs=d}const n={from:I(e.from),personalizations:[r]},u=[];if(e.html&&u.push({type:"text/html",value:e.html}),e.text&&u.push({type:"text/plain",value:e.text}),u.length>0&&(n.content=u),e.replyTo&&(n.reply_to=I(e.replyTo)),e.subject&&(n.subject=e.subject),e.templateId&&(n.template_id=e.templateId,e.templateData&&(r.dynamicTemplateData=e.templateData)),e.sendAt&&(r.send_at=e.sendAt),e.batchId&&(n.batch_id=e.batchId),e.asmGroupId&&(n.asm={group_id:e.asmGroupId}),e.ipPoolName&&(n.ip_pool_name=e.ipPoolName),e.mailSettings&&(n.mail_settings=e.mailSettings),e.trackingSettings&&(n.tracking_settings=e.trackingSettings),e.headers){const d=S(e.headers);n.headers=d}e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async d=>C(d,s)))),i.debug("Sending email via SendGrid API",{subject:n.subject,to:r.to});const w={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},c=await b(async()=>h(`${a.endpoint}/mail/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(n)),a.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new l(s,"Failed to send email"),success:!1};const g=c.data?.headers,y=(g&&g instanceof Headers?g.get("X-Message-Id"):void 0)??P();return i.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:s,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(s,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
@@ -1,4 +1,4 @@
1
- import{createRequire as x}from"node:module";import f from"./EmailError-B-sEf3bp.js";import W from"./RequiredOptionError-DuNNY_a5.js";import{F as Q}from"./build-mime-message-Be6TOi1T.js";import{e as Z}from"./generate-message-id-gXAuMz4g.js";import{f as J}from"./validate-email-options-mCM9dVug.js";import{defineProvider as V}from"./defineProvider-C9q-7iwt.js";const G=x(import.meta.url),O=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=h=>{if(typeof O<"u"&&O.versions&&O.versions.node){const[t,A]=O.versions.node.split(".").map(Number);if(t>22||t===22&&A>=3||t===20&&A>=16)return O.getBuiltinModule(h)}return G(h)},{Buffer:I}=k("node:buffer"),{createHmac:B,createHash:X,createSign:Y}=k("node:crypto"),{Socket:q,createConnection:K}=k("node:net"),{connect:E}=k("node:tls"),ee=(h,t)=>new Promise(A=>{const w=new q,y=()=>{w.destroy(),A(!1)};w.setTimeout(1e3),w.on("error",y),w.on("timeout",y),w.connect(t,h,()=>{w.end(),A(!0)})}),l="smtp",te=25,re=465,se=1e4,oe=!1,ae=5,P=3e4,ie=/^\./,pe=V((h={})=>{if(!h.host)throw new W(l,"host");const t={authMethod:h.authMethod??"LOGIN",debug:h.debug??!1,dkim:h.dkim,host:h.host,maxConnections:h.maxConnections??ae,oauth2:h.oauth2,password:h.password,pool:h.pool??!1,port:h.port!==void 0?h.port:h.secure?re:te,rejectUnauthorized:h.rejectUnauthorized??!0,retries:h.retries??0,secure:h.secure??oe,timeout:h.timeout??se,user:h.user,...h.logger&&{logger:h.logger}};let A=!1;const w=[],y=[],S=e=>e.replaceAll(/[\r\n\t\v\f]/g," ").trim(),v=e=>{const u=e.split(`\r
1
+ import{createRequire as x}from"node:module";import f from"./EmailError-B-sEf3bp.js";import W from"./RequiredOptionError-DuNNY_a5.js";import{F as Q}from"./build-mime-message-B6927SQy.js";import{e as Z}from"./generate-message-id-gXAuMz4g.js";import{f as J}from"./validate-email-options-mCM9dVug.js";import{defineProvider as V}from"./defineProvider-C9q-7iwt.js";const G=x(import.meta.url),O=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=h=>{if(typeof O<"u"&&O.versions&&O.versions.node){const[t,A]=O.versions.node.split(".").map(Number);if(t>22||t===22&&A>=3||t===20&&A>=16)return O.getBuiltinModule(h)}return G(h)},{Buffer:I}=k("node:buffer"),{createHmac:B,createHash:X,createSign:Y}=k("node:crypto"),{Socket:q,createConnection:K}=k("node:net"),{connect:E}=k("node:tls"),ee=(h,t)=>new Promise(A=>{const w=new q,y=()=>{w.destroy(),A(!1)};w.setTimeout(1e3),w.on("error",y),w.on("timeout",y),w.connect(t,h,()=>{w.end(),A(!0)})}),l="smtp",te=25,re=465,se=1e4,oe=!1,ae=5,P=3e4,ie=/^\./,pe=V((h={})=>{if(!h.host)throw new W(l,"host");const t={authMethod:h.authMethod??"LOGIN",debug:h.debug??!1,dkim:h.dkim,host:h.host,maxConnections:h.maxConnections??ae,oauth2:h.oauth2,password:h.password,pool:h.pool??!1,port:h.port!==void 0?h.port:h.secure?re:te,rejectUnauthorized:h.rejectUnauthorized??!0,retries:h.retries??0,secure:h.secure??oe,timeout:h.timeout??se,user:h.user,...h.logger&&{logger:h.logger}};let A=!1;const w=[],y=[],S=e=>e.replaceAll(/[\r\n\t\v\f]/g," ").trim(),v=e=>{const u=e.split(`\r
2
2
  `),o={};for(const c of u)if(c.startsWith("250-")||c.startsWith("250 ")){const i=c.slice(4).trim().split(" "),n=i[0];n&&(o[n]=i.slice(1))}return o},p=async(e,u,o)=>new Promise((c,i)=>{const n=Array.isArray(o)?o:[o];let s="",a="";const d=setTimeout(()=>{g(),i(new f(l,`Command timeout after ${t.timeout}ms: ${u?.slice(0,50)}...`))},t.timeout),g=()=>{e.removeListener("data",b),e.removeListener("error",r),d&&clearTimeout(d)},b=m=>{s+=m.toString();const j=s.split(`\r
3
3
  `).filter(Boolean);if(j.length>0){const $=j.at(-1);if($){const U=$.match(/^(\d{3})[\s-]/);if(U){const[,M]=U;a=M,$[3]===" "&&(g(),n.includes(a)?c(s):i(new f(l,`Expected ${n.join(" or ")}, got ${a}: ${s.trim()}`)))}}}},r=m=>{g(),i(new f(l,`Socket error: ${m.message}`,{cause:m}))};e.on("data",b),e.on("error",r),u&&e.write(`${u}\r
4
4
  `)}),C=async()=>{if(t.pool&&w.length>0){const e=w.pop();if(e&&!e.destroyed)return e}return t.pool&&w.length+1>=t.maxConnections?new Promise((e,u)=>{const o={reject:u,resolve:e};o.timeout=setTimeout(()=>{const c=y.indexOf(o);c!==-1&&y.splice(c,1),u(new f(l,`Connection queue timeout after ${P}ms`))},P),y.push(o)}):new Promise((e,u)=>{let o,c=!1,i;const n=()=>{o&&clearTimeout(o)};o=setTimeout(()=>{c||(c=!0,i&&!i.destroyed&&i.destroy(),n(),u(new f(l,`Connection timeout to ${t.host}:${t.port} after ${t.timeout}ms`)))},t.timeout);try{i=t.secure?E({host:t.host,port:t.port,rejectUnauthorized:t.rejectUnauthorized}):K(t.port,t.host),i.on("error",s=>{c||(c=!0,n(),u(new f(l,`Connection error: ${s.message}`,{cause:s})))}),i.once("data",s=>{if(!c&&i){c=!0,n();const a=s.toString();a.slice(0,3)==="220"?e(i):(i.destroy(),u(new f(l,`Unexpected server greeting: ${a.trim()}`)))}})}catch(s){c||(c=!0,n(),u(new f(l,`Failed to create connection: ${s.message}`,{cause:s})))}})},R=async e=>new Promise((u,o)=>{let c,i=!1,n;const s=()=>{c&&clearTimeout(c)};c=setTimeout(()=>{i||(i=!0,n&&!n.destroyed&&n.destroy(),s(),o(new f(l,`TLS connection timeout after ${t.timeout}ms`)))},t.timeout);try{const a={host:t.host,rejectUnauthorized:t.rejectUnauthorized,socket:e};n=E(a),n.on("error",d=>{i||(i=!0,s(),o(new f(l,`TLS connection error: ${d.message}`,{cause:d})))}),n.once("secure",()=>{!i&&n&&(i=!0,s(),u(n))})}catch(a){i||(i=!0,s(),o(new f(l,`Failed to upgrade to TLS: ${a.message}`,{cause:a})))}}),z=e=>{if(e.destroyed||!t.pool){try{e.destroy()}catch{}return}if(y.length>0){const u=y.shift();if(u){clearTimeout(u.timeout),u.resolve(e);return}}w.push(e)},L=async(e,u=!1)=>new Promise(o=>{try{if(u){e.write(`RSET\r
@@ -1 +1 @@
1
- import h from"./EmailError-B-sEf3bp.js";import w from"./RequiredOptionError-DuNNY_a5.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{m as j}from"./make-request-BlK_B72c.js";import{u as I}from"./retry-3pnxTuNs.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as S}from"./defineProvider-C9q-7iwt.js";import{P as z,h as _,c as C}from"./provider-base-gIoUu9so.js";import{a as l}from"./address-formatter-BWR2Dddx.js";import{c as K}from"./attachment-processor-BjTNoMyb.js";const a="sparkpost",O="https://api.sparkpost.com/api/v1",T=3e4,x=3,d=r=>[r].flat(),B=S((r={})=>{if(!r.apiKey)throw new w(a,"apiKey");const n={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??O,logger:r.logger,retries:r.retries??x,timeout:r.timeout??T},g=new z,y=C(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 g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new h(a,"SparkPost API not available or invalid API key");y.debug("Provider initialized successfully")},a)},async isAvailable(){return n.apiKey.length>0},name:a,options:n,async sendEmail(t){try{const o=A(t);if(o.length>0)return{error:new h(a,`Invalid email options: ${o.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),a);const p=d(t.to),u=t.cc?d(t.cc):[],k=t.bcc?d(t.bcc):[],v=[...p.map(e=>({address:l(e)})),...u.map(e=>({address:{...l(e),header_to:p.map(i=>i.email).join(", ")}})),...k.map(e=>({address:{...l(e),header_to:p.map(i=>i.email).join(", ")}}))],s={from:l(t.from),subject:t.subject};if(t.html&&(s.html=t.html),t.text&&(s.text=t.text),t.replyTo){const e=d(t.replyTo)[0];e&&(s.reply_to=e.email)}const c={};if(u.length>0&&(c.CC=u.map(e=>e.email).join(", ")),t.headers)for(const[e,i]of Object.entries(t.headers))c[e]=String(i);Object.keys(c).length>0&&(s.headers=c),t.templateId&&(s.template_id=t.templateId),t.attachments&&t.attachments.length>0&&(s.attachments=await Promise.all(t.attachments.map(async e=>{const i=await K(e,a);return{data:i.content,name:i.filename,type:i.contentType}})));const f={content:s,recipients:v};t.campaignId&&(f.campaign_id=t.campaignId),(t.trackOpens!==void 0||t.trackClicks!==void 0)&&(f.options={click_tracking:t.trackClicks??!0,open_tracking:t.trackOpens??!0});const m=await I(async()=>j(`${n.endpoint}/transmissions`,{headers:{Authorization:n.apiKey,"Content-Type":"application/json"},method:"POST",timeout:n.timeout},JSON.stringify(f)),n.retries);if(!m.success)return{error:m.error??new h(a,"Failed to send email"),success:!1};const{body:b}=m.data;return{data:{messageId:b?.results?.id??P(),provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:_(a,"send email",o,y),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{B as default};
1
+ import h from"./EmailError-B-sEf3bp.js";import w from"./RequiredOptionError-DuNNY_a5.js";import{e as P}from"./generate-message-id-gXAuMz4g.js";import{m as j}from"./make-request-BlK_B72c.js";import{u as I}from"./retry-3pnxTuNs.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as S}from"./defineProvider-C9q-7iwt.js";import{P as z,h as _,c as C}from"./provider-base-C7PuopYK.js";import{a as l}from"./address-formatter-BWR2Dddx.js";import{c as K}from"./attachment-processor-CMp7qqMI.js";const a="sparkpost",O="https://api.sparkpost.com/api/v1",T=3e4,x=3,d=r=>[r].flat(),B=S((r={})=>{if(!r.apiKey)throw new w(a,"apiKey");const n={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??O,logger:r.logger,retries:r.retries??x,timeout:r.timeout??T},g=new z,y=C(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 g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new h(a,"SparkPost API not available or invalid API key");y.debug("Provider initialized successfully")},a)},async isAvailable(){return n.apiKey.length>0},name:a,options:n,async sendEmail(t){try{const o=A(t);if(o.length>0)return{error:new h(a,`Invalid email options: ${o.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),a);const p=d(t.to),u=t.cc?d(t.cc):[],k=t.bcc?d(t.bcc):[],v=[...p.map(e=>({address:l(e)})),...u.map(e=>({address:{...l(e),header_to:p.map(i=>i.email).join(", ")}})),...k.map(e=>({address:{...l(e),header_to:p.map(i=>i.email).join(", ")}}))],s={from:l(t.from),subject:t.subject};if(t.html&&(s.html=t.html),t.text&&(s.text=t.text),t.replyTo){const e=d(t.replyTo)[0];e&&(s.reply_to=e.email)}const c={};if(u.length>0&&(c.CC=u.map(e=>e.email).join(", ")),t.headers)for(const[e,i]of Object.entries(t.headers))c[e]=String(i);Object.keys(c).length>0&&(s.headers=c),t.templateId&&(s.template_id=t.templateId),t.attachments&&t.attachments.length>0&&(s.attachments=await Promise.all(t.attachments.map(async e=>{const i=await K(e,a);return{data:i.content,name:i.filename,type:i.contentType}})));const f={content:s,recipients:v};t.campaignId&&(f.campaign_id=t.campaignId),(t.trackOpens!==void 0||t.trackClicks!==void 0)&&(f.options={click_tracking:t.trackClicks??!0,open_tracking:t.trackOpens??!0});const m=await I(async()=>j(`${n.endpoint}/transmissions`,{headers:{Authorization:n.apiKey,"Content-Type":"application/json"},method:"POST",timeout:n.timeout},JSON.stringify(f)),n.retries);if(!m.success)return{error:m.error??new h(a,"Failed to send email"),success:!1};const{body:b}=m.data;return{data:{messageId:b?.results?.id??P(),provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:_(a,"send email",o,y),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{B as default};
@@ -0,0 +1 @@
1
+ import c from"./EmailError-B-sEf3bp.js";import b from"./RequiredOptionError-DuNNY_a5.js";import{e as w}from"./generate-message-id-gXAuMz4g.js";import{s as v}from"./headers-to-record-De1Eg951.js";import{m as g}from"./make-request-BlK_B72c.js";import{u as f}from"./retry-3pnxTuNs.js";import{f as I}from"./validate-email-options-mCM9dVug.js";import{defineProvider as A}from"./defineProvider-C9q-7iwt.js";import{P,h,c as T}from"./provider-base-C7PuopYK.js";import{f as d,a as z}from"./address-formatter-BWR2Dddx.js";import{p as S}from"./attachment-processor-CMp7qqMI.js";const r="sweego",E="https://api.sweego.com",j=3e4,k=3,H=A((i={})=>{if(!i.apiKey)throw new b(r,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??E,retries:i.retries??k,timeout:i.timeout??j,...i.logger&&{logger:i.logger}},m=new P,a=T(r,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(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const o={Authorization:`Bearer ${s.apiKey}`,"Content-Type":"application/json"};a.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?(a.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(a.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(o){return{error:h(r,"retrieve email",o,a),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"Sweego API not available or invalid API key");a.debug("Provider initialized successfully")},r)},async isAvailable(){try{return a.debug("Checking Sweego API availability"),!0}catch(e){return a.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new c(r,`Invalid email options: ${o.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);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=z(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=v(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>({content:await S(n,r),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),a.debug("Sending email via Sweego API",{subject:t.subject,to:t.to});const y={Authorization:`Bearer ${s.apiKey}`,"Content-Type":"application/json"},l=await f(async()=>g(`${s.endpoint}/send`,{headers:y,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!l.success)return a.debug("API request failed when sending email",l.error),{error:l.error??new c(r,"Failed to send email"),success:!1};const u=l.data?.body,p=u?.messageId??u?.id??w();return a.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:r,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(r,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
@@ -1 +1 @@
1
- import l from"./EmailError-B-sEf3bp.js";import y from"./RequiredOptionError-DuNNY_a5.js";import{e as b}from"./generate-message-id-gXAuMz4g.js";import{s as k}from"./headers-to-record-De1Eg951.js";import{m as v}from"./make-request-BlK_B72c.js";import{u as w}from"./retry-3pnxTuNs.js";import{a as A,s as z}from"./sanitize-header-DJhgZl3y.js";import{f as _}from"./validate-email-options-mCM9dVug.js";import{defineProvider as j}from"./defineProvider-C9q-7iwt.js";import{P,h as I,c as T}from"./provider-base-gIoUu9so.js";import{n as h}from"./address-formatter-BWR2Dddx.js";const i="zeptomail",O="https://api.zeptomail.com/v1.1",Z=3e4,E=3,L=j((s={})=>{if(!s.token)throw new y(i,"token");if(!s.token.startsWith("Zoho-enczapikey "))throw new l(i,'Token should be in the format "Zoho-enczapikey <your_api_key>"');const o={debug:s.debug??!1,endpoint:s.endpoint??O,logger:s.logger,retries:s.retries??E,timeout:s.timeout??Z,token:s.token},u=new P,n=T(i,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(i,"Zeptomail API not available or invalid token");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{return o.token&&o.token.startsWith("Zoho-enczapikey ")?(n.debug("Token format is valid, assuming Zeptomail is available"),!0):!1}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:o,async sendEmail(e){try{const m=_(e);if(m.length>0)return{error:new l(i,`Invalid email options: ${m.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),i);const a={from:h(e.from).address,subject:e.subject};if(Array.isArray(e.to)?a.to=e.to.length===1?e.to[0].email:e.to.map(t=>t.email):a.to=e.to.email,e.text&&(a.textbody=e.text),e.html&&(a.htmlbody=e.html),e.cc&&(Array.isArray(e.cc)?a.cc=e.cc.length===1?e.cc[0].email:e.cc.map(t=>t.email):a.cc=e.cc.email),e.bcc&&(Array.isArray(e.bcc)?a.bcc=e.bcc.length===1?e.bcc[0].email:e.bcc.map(t=>t.email):a.bcc=e.bcc.email),e.replyTo&&(a.reply_to=[h(e.replyTo).address]),e.trackClicks!==void 0&&(a.track_clicks=e.trackClicks),e.trackOpens!==void 0&&(a.track_opens=e.trackOpens),e.clientReference&&(a.client_reference=e.clientReference),e.mimeHeaders&&Object.keys(e.mimeHeaders).length>0){const t={};for(const[r,d]of Object.entries(e.mimeHeaders))t[r]=d;a.mime_headers=t}if(e.headers){const t=k(e.headers);Object.keys(t).length>0&&(a.mime_headers??={},Object.entries(t).forEach(([r,d])=>{a.mime_headers&&(a.mime_headers[A(r)]=z(d))}))}e.attachments&&e.attachments.length>0&&(a.attachments=e.attachments.map(t=>{const r={name:t.filename};return t.content?(r.content=typeof t.content=="string"?t.content:t.content.toString("base64"),t.contentType&&(r.mime_type=t.contentType)):t.path&&(r.file_cache_key=t.path),r})),n.debug("Sending email via Zeptomail API",{subject:a.subject,to:a.to});const g={Accept:"application/json",Authorization:o.token,"Content-Type":"application/json"},c=await w(async()=>v(`${o.endpoint}/email`,{headers:g,method:"POST",timeout:o.timeout},JSON.stringify(a)),o.retries);if(!c.success){n.debug("API request failed",c.error);let t=c.error instanceof Error?c.error.message:"Unknown error";const r=c.data;return r?.body?.message?t+=` Details: ${r.body.message}`:r?.body?.error?.message&&(t+=` Details: ${r.body.error.message}`),{error:new l(i,`Failed to send email: ${t}`,{cause:c.error}),success:!1}}const p=c.data?.body,f=p?.request_id??b();return n.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:i,response:p,sent:!0,timestamp:new Date},success:!0}}catch(m){return{error:I(i,"send email",m,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
1
+ import l from"./EmailError-B-sEf3bp.js";import y from"./RequiredOptionError-DuNNY_a5.js";import{e as b}from"./generate-message-id-gXAuMz4g.js";import{s as k}from"./headers-to-record-De1Eg951.js";import{m as v}from"./make-request-BlK_B72c.js";import{u as w}from"./retry-3pnxTuNs.js";import{a as A,s as z}from"./sanitize-header-DJhgZl3y.js";import{f as _}from"./validate-email-options-mCM9dVug.js";import{defineProvider as j}from"./defineProvider-C9q-7iwt.js";import{P,h as I,c as T}from"./provider-base-C7PuopYK.js";import{n as h}from"./address-formatter-BWR2Dddx.js";const i="zeptomail",O="https://api.zeptomail.com/v1.1",Z=3e4,E=3,L=j((s={})=>{if(!s.token)throw new y(i,"token");if(!s.token.startsWith("Zoho-enczapikey "))throw new l(i,'Token should be in the format "Zoho-enczapikey <your_api_key>"');const o={debug:s.debug??!1,endpoint:s.endpoint??O,logger:s.logger,retries:s.retries??E,timeout:s.timeout??Z,token:s.token},u=new P,n=T(i,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(i,"Zeptomail API not available or invalid token");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{return o.token&&o.token.startsWith("Zoho-enczapikey ")?(n.debug("Token format is valid, assuming Zeptomail is available"),!0):!1}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:o,async sendEmail(e){try{const m=_(e);if(m.length>0)return{error:new l(i,`Invalid email options: ${m.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),i);const a={from:h(e.from).address,subject:e.subject};if(Array.isArray(e.to)?a.to=e.to.length===1?e.to[0].email:e.to.map(t=>t.email):a.to=e.to.email,e.text&&(a.textbody=e.text),e.html&&(a.htmlbody=e.html),e.cc&&(Array.isArray(e.cc)?a.cc=e.cc.length===1?e.cc[0].email:e.cc.map(t=>t.email):a.cc=e.cc.email),e.bcc&&(Array.isArray(e.bcc)?a.bcc=e.bcc.length===1?e.bcc[0].email:e.bcc.map(t=>t.email):a.bcc=e.bcc.email),e.replyTo&&(a.reply_to=[h(e.replyTo).address]),e.trackClicks!==void 0&&(a.track_clicks=e.trackClicks),e.trackOpens!==void 0&&(a.track_opens=e.trackOpens),e.clientReference&&(a.client_reference=e.clientReference),e.mimeHeaders&&Object.keys(e.mimeHeaders).length>0){const t={};for(const[r,d]of Object.entries(e.mimeHeaders))t[r]=d;a.mime_headers=t}if(e.headers){const t=k(e.headers);Object.keys(t).length>0&&(a.mime_headers??={},Object.entries(t).forEach(([r,d])=>{a.mime_headers&&(a.mime_headers[A(r)]=z(d))}))}e.attachments&&e.attachments.length>0&&(a.attachments=e.attachments.map(t=>{const r={name:t.filename};return t.content?(r.content=typeof t.content=="string"?t.content:t.content.toString("base64"),t.contentType&&(r.mime_type=t.contentType)):t.path&&(r.file_cache_key=t.path),r})),n.debug("Sending email via Zeptomail API",{subject:a.subject,to:a.to});const g={Accept:"application/json",Authorization:o.token,"Content-Type":"application/json"},c=await w(async()=>v(`${o.endpoint}/email`,{headers:g,method:"POST",timeout:o.timeout},JSON.stringify(a)),o.retries);if(!c.success){n.debug("API request failed",c.error);let t=c.error instanceof Error?c.error.message:"Unknown error";const r=c.data;return r?.body?.message?t+=` Details: ${r.body.message}`:r?.body?.error?.message&&(t+=` Details: ${r.body.error.message}`),{error:new l(i,`Failed to send email: ${t}`,{cause:c.error}),success:!1}}const p=c.data?.body,f=p?.request_id??b();return n.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:i,response:p,sent:!0,timestamp:new Date},success:!0}}catch(m){return{error:I(i,"send email",m,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/ahaSendProvider-Dq5mElHZ.js";export{r as ahaSendProvider};
1
+ import{default as r}from"../../packem_shared/ahaSendProvider-D81_wUA1.js";export{r as ahaSendProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/azureProvider-DlM6UWUv.js";export{a as azureProvider};
1
+ import{default as a}from"../../packem_shared/azureProvider-CmcK4bsf.js";export{a as azureProvider};
@@ -1 +1 @@
1
- import{default as o}from"../../packem_shared/brevoProvider-D_Hhc0Z-.js";export{o as brevoProvider};
1
+ import{default as o}from"../../packem_shared/brevoProvider-C1BDXr41.js";export{o as brevoProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/cloudflareEmailProvider-D4adkOjA.js";export{e as cloudflareEmailProvider};
1
+ import{default as e}from"../../packem_shared/cloudflareEmailProvider-Bv-ty-74.js";export{e as cloudflareEmailProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/infobipProvider-oOL-ThpP.js";export{e as infobipProvider};
1
+ import{default as e}from"../../packem_shared/infobipProvider-lHyGrXgZ.js";export{e as infobipProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/loopsProvider-BXr0KSjB.js";export{e as loopsProvider};
1
+ import{default as e}from"../../packem_shared/loopsProvider-DyloxzNC.js";export{e as loopsProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/mailchannelsProvider-DPfQVzUd.js";export{r as mailchannelsProvider};
1
+ import{default as r}from"../../packem_shared/mailchannelsProvider-osRkW_tz.js";export{r as mailchannelsProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/mailCrabProvider-C7Ao5H9p.js";export{e as mailCrabProvider};
1
+ import{default as e}from"../../packem_shared/mailCrabProvider-CPtBT6Th.js";export{e as mailCrabProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/mailerSendProvider-B8iT5Uhb.js";export{a as mailerSendProvider};
1
+ import{default as a}from"../../packem_shared/mailerSendProvider-C_6LzARK.js";export{a as mailerSendProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/mailgunProvider-Ctyrs9d0.js";export{e as mailgunProvider};
1
+ import{default as e}from"../../packem_shared/mailgunProvider-DkISvMPe.js";export{e as mailgunProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/mailjetProvider-v55nFDsr.js";export{a as mailjetProvider};
1
+ import{default as a}from"../../packem_shared/mailjetProvider-CV0i4Xzh.js";export{a as mailjetProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/mailomatProvider-BCyB4Q4B.js";export{r as mailomatProvider};
1
+ import{default as r}from"../../packem_shared/mailomatProvider-B5YFonEO.js";export{r as mailomatProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/mailPaceProvider-DklGeGEM.js";export{r as mailPaceProvider};
1
+ import{default as r}from"../../packem_shared/mailPaceProvider-CJEvOFBh.js";export{r as mailPaceProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/mailtrapProvider-DcVw3sxR.js";export{e as mailtrapProvider};
1
+ import{default as e}from"../../packem_shared/mailtrapProvider-C4ZquIPz.js";export{e as mailtrapProvider};
@@ -1 +1 @@
1
- import{default as d}from"../../packem_shared/mandrillProvider-gqMFMwgs.js";export{d as mandrillProvider};
1
+ import{default as d}from"../../packem_shared/mandrillProvider-DWPFh_Sj.js";export{d as mandrillProvider};
@@ -1 +1 @@
1
- import{default as o}from"../../packem_shared/netcoreProvider-XMWO_Aoa.js";export{o as netcoreProvider};
1
+ import{default as o}from"../../packem_shared/netcoreProvider-C5TEciaN.js";export{o as netcoreProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/outlook365Provider-BoNtxqIx.js";export{e as outlook365Provider};
1
+ import{default as e}from"../../packem_shared/outlook365Provider-63ggDpqV.js";export{e as outlook365Provider};
@@ -1 +1 @@
1
- import{default as o}from"../../packem_shared/plunkProvider-C0LO-1E3.js";export{o as plunkProvider};
1
+ import{default as o}from"../../packem_shared/plunkProvider-yTlrJVEp.js";export{o as plunkProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/postalProvider-B26IqgxE.js";export{a as postalProvider};
1
+ import{default as a}from"../../packem_shared/postalProvider-CRX_bMYD.js";export{a as postalProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/postmarkProvider-DWQJv5_M.js";export{a as postmarkProvider};
1
+ import{default as a}from"../../packem_shared/postmarkProvider-CDx85Yge.js";export{a as postmarkProvider};
@@ -1 +1 @@
1
- import{default as d}from"../../packem_shared/resendProvider-DhvKVyCD.js";export{d as resendProvider};
1
+ import{default as d}from"../../packem_shared/resendProvider-CiclWxzr.js";export{d as resendProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/scalewayProvider-D8dmHuwZ.js";export{r as scalewayProvider};
1
+ import{default as r}from"../../packem_shared/scalewayProvider-BcND48qO.js";export{r as scalewayProvider};
@@ -1 +1 @@
1
- import{default as e}from"../../packem_shared/sendGridProvider-CChhLr7s.js";export{e as sendGridProvider};
1
+ import{default as e}from"../../packem_shared/sendGridProvider-D8ZLgY62.js";export{e as sendGridProvider};
@@ -1 +1 @@
1
- import{default as o}from"../../packem_shared/smtpProvider-x4WBN-3W.js";export{o as smtpProvider};
1
+ import{default as o}from"../../packem_shared/smtpProvider-Bm0yP97W.js";export{o as smtpProvider};
@@ -1 +1 @@
1
- import{default as a}from"../../packem_shared/sparkpostProvider-BytvwqjP.js";export{a as sparkpostProvider};
1
+ import{default as a}from"../../packem_shared/sparkpostProvider-CTYfSRaV.js";export{a as sparkpostProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/sweegoProvider-7xhOvagC.js";export{r as sweegoProvider};
1
+ import{default as r}from"../../packem_shared/sweegoProvider-DOoin_vi.js";export{r as sweegoProvider};
@@ -1 +1 @@
1
- import{default as r}from"../../packem_shared/zeptomailProvider-D3nQKXRf.js";export{r as zeptomailProvider};
1
+ import{default as r}from"../../packem_shared/zeptomailProvider-DKBPSHPj.js";export{r as zeptomailProvider};
@@ -100,10 +100,6 @@ declare const emailMatchers: {
100
100
  toHaveSentWithAttachment: typeof toHaveSentWithAttachment;
101
101
  toHaveSentWithSubject: typeof toHaveSentWithSubject;
102
102
  };
103
- /**
104
- * The shape of the {@link emailMatchers} map.
105
- */
106
-
107
103
  /**
108
104
  * A Vitest/Jest-compatible `expect` exposing `.extend(...)`.
109
105
  */
@@ -1 +1 @@
1
- import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DZDkrZ_3.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-DeRqM5SJ.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-BM3iNznm.js";export{s as createTestEmail,a as emailMatchers,o as registerEmailMatchers,c as toEmailSnapshot,r as toHaveSentMatching,i as toHaveSentTo,m as toHaveSentWithAttachment,h as toHaveSentWithSubject};
1
+ import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DZDkrZ_3.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-DeRqM5SJ.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-CF_RUjqo.js";export{s as createTestEmail,a as emailMatchers,o as registerEmailMatchers,c as toEmailSnapshot,r as toHaveSentMatching,i as toHaveSentTo,m as toHaveSentWithAttachment,h as toHaveSentWithSubject};
@@ -1,6 +1,6 @@
1
- import y from"./parse-address.js";import{p as $}from"../packem_shared/quoted-printable-nSGDA1tA.js";const T=globalThis.Buffer!==void 0,k=r=>{if(T)return Uint8Array.from(Buffer.from(r,"base64"));const t=atob(r),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n},E=r=>{const t=r.replaceAll("_"," "),n=[];for(let e=0;e<t.length;e+=1){const s=t[e];s==="="&&e+2<t.length?(n.push(Number.parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(s.charCodeAt(0))}return Uint8Array.from(n)},U=/^utf-?8$/i,j=(r,t)=>{if(T&&U.test(t))return Buffer.from(r).toString("utf8");try{return new TextDecoder(t).decode(r)}catch{return new TextDecoder().decode(r)}},D=/=\?([^?]+)\?([bq])\?([^?]*)\?=/gi,M=r=>r.includes("=?")?r.replaceAll(/(\?=)\s+(=\?)/g,"$1$2").replaceAll(D,(t,n,e,s)=>{const o=e.toUpperCase()==="B"?k(s):E(s);return j(o,n)}):r,O=globalThis.Buffer!==void 0,S=/^[ \t]/,q=/boundary=(?:"([^"]+)"|([^";]+))/i,H=/^\r?\n/,L=/[\r\n]+$/,I=/\r?\n$/,N=/\s/g,P=/high|^1|^2/i,_=/low|^4|^5/i,B=r=>{const t=r.replaceAll(`\r
1
+ import y from"./parse-address.js";import{p as v}from"../packem_shared/quoted-printable-nSGDA1tA.js";const T=globalThis.Buffer!==void 0,k=r=>{if(T)return Uint8Array.from(Buffer.from(r,"base64"));const t=atob(r),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n},E=r=>{const t=r.replaceAll("_"," "),n=[];for(let e=0;e<t.length;e+=1){const s=t[e];s==="="&&e+2<t.length?(n.push(Number.parseInt(t.slice(e+1,e+3),16)),e+=2):n.push(s.charCodeAt(0))}return Uint8Array.from(n)},U=/^utf-?8$/i,j=(r,t)=>{if(T&&U.test(t))return Buffer.from(r).toString("utf8");try{return new TextDecoder(t).decode(r)}catch{return new TextDecoder().decode(r)}},D=/=\?([^?]+)\?([bq])\?([^?]*)\?=/gi,M=r=>r.includes("=?")?r.replaceAll(/(\?=)\s+(=\?)/g,"$1$2").replaceAll(D,(t,n,e,s)=>{const o=e.toUpperCase()==="B"?k(s):E(s);return j(o,n)}):r,O=globalThis.Buffer!==void 0,S=/^[ \t]/,q=/boundary=(?:"([^"]+)"|([^";]+))/i,I=/^\r?\n/,L=/[\r\n]+$/,N=/\r?\n$/,P=/\s/g,_=/high|^1|^2/i,F=/low|^4|^5/i,B=r=>{const t=r.replaceAll(`\r
2
2
  `,`
3
3
  `),n=t.indexOf(`
4
4
 
5
5
  `),e=n===-1?t:t.slice(0,n),s=n===-1?"":t.slice(n+2),o=[],f=new Map;let i="",c="";const h=()=>{if(i){const a=M(c.trim());o.push([i,a]),f.set(i.toLowerCase(),a)}};for(const a of e.split(`
6
- `))if(S.test(a)&&i)c+=` ${a.trim()}`;else{h();const d=a.indexOf(":");d===-1?(i="",c=""):(i=a.slice(0,d).trim(),c=a.slice(d+1).trim())}return h(),{body:s,headers:{map:f,raw:o}}},b=r=>{if(!r)return[];const t=[];let n="",e=!1,s=!1;for(const o of r){switch(o){case'"':{e=!e;break}case"<":{s=!0;break}case">":{s=!1;break}}o===","&&!e&&!s?(t.push(n),n=""):n+=o}return n.trim()&&t.push(n),t.map(o=>y(o.trim())).filter(o=>o!==void 0)},F=r=>{if(!r)return;const t=q.exec(r);return t?.[1]??t?.[2]},w=(r,t)=>{const n=(t??"7bit").trim().toLowerCase();if(n==="quoted-printable")return $(r);if(n==="base64"){const e=r.replaceAll(N,"");return O?Buffer.from(e,"base64").toString("utf8"):new TextDecoder().decode(Uint8Array.from(atob(e),s=>s.codePointAt(0)))}return r},V=r=>{const{body:t,headers:n}=B(r),{map:e}=n,s=y(e.get("from")??"");if(!s)throw new Error("Cannot parse EML: missing or invalid `From` header");const o=b(e.get("to")??""),f=b(e.get("cc")??""),i=b(e.get("bcc")??"");if(o.length===0&&f.length===0&&i.length===0)throw new Error("Cannot parse EML: no recipient (`To`/`Cc`/`Bcc`) found");const c={from:s,subject:e.get("subject")??"",to:o.length===1?o[0]:o};f.length>0&&(c.cc=f.length===1?f[0]:f),i.length>0&&(c.bcc=i.length===1?i[0]:i);const h=e.get("reply-to")?y(e.get("reply-to")):void 0;h&&(c.replyTo=h);const a=e.get("content-type"),d=F(a);if(d&&a?.toLowerCase().includes("multipart")){const u=t.split(`--${d}`);for(const l of u){const p=l.replace(H,"");if(!(!p||p.startsWith("--"))){const{body:C,headers:g}=B(p),x=g.map.get("content-type")??"",A=g.map.get("content-transfer-encoding");(g.map.get("content-disposition")??"").toLowerCase().includes("attachment")||(x.toLowerCase().includes("text/plain")?c.text=w(C.replace(L,""),A):x.toLowerCase().includes("text/html")&&(c.html=w(C.replace(L,""),A)))}}}else{const u=e.get("content-transfer-encoding"),l=w(t.replace(I,""),u);a?.toLowerCase().includes("text/html")?c.html=l:l&&(c.text=l)}const v=new Set(["bcc","cc","content-transfer-encoding","content-type","from","mime-version","reply-to","subject","to"]),m={};for(const[u,l]of n.raw){const p=u.toLowerCase();(p==="x-priority"||p==="importance")&&(P.test(l)?c.priority="high":_.test(l)&&(c.priority="low")),v.has(p)||(m[u]=l)}return Object.keys(m).length>0&&(c.headers=m),c};export{V as default};
6
+ `))if(S.test(a)&&i)c+=` ${a.trim()}`;else{h();const u=a.indexOf(":");u===-1?(i="",c=""):(i=a.slice(0,u).trim(),c=a.slice(u+1).trim())}return h(),{body:s,headers:{map:f,raw:o}}},b=r=>{if(!r)return[];const t=[];let n="",e=!1,s=!1;for(const o of r){switch(o){case'"':{e=!e;break}case"<":{s=!0;break}case">":{s=!1;break}}o===","&&!e&&!s?(t.push(n),n=""):n+=o}return n.trim()&&t.push(n),t.map(o=>y(o.trim())).filter(o=>o!==void 0)},G=r=>{if(!r)return;const t=q.exec(r);return t?.[1]??t?.[2]},w=(r,t)=>{const n=(t??"7bit").trim().toLowerCase();if(n==="quoted-printable")return v(r);if(n==="base64"){const e=r.replaceAll(P,"");return O?Buffer.from(e,"base64").toString("utf8"):new TextDecoder().decode(Uint8Array.from(atob(e),s=>s.codePointAt(0)))}return r},W=r=>{const{body:t,headers:n}=B(r),{map:e}=n,s=y(e.get("from")??"");if(!s)throw new Error("Cannot parse EML: missing or invalid `From` header");const o=b(e.get("to")??""),f=b(e.get("cc")??""),i=b(e.get("bcc")??"");if(o.length===0&&f.length===0&&i.length===0)throw new Error("Cannot parse EML: no recipient (`To`/`Cc`/`Bcc`) found");const c={from:s,subject:e.get("subject")??"",to:o.length===1?o[0]:o};f.length>0&&(c.cc=f.length===1?f[0]:f),i.length>0&&(c.bcc=i.length===1?i[0]:i);const h=e.get("reply-to")?y(e.get("reply-to")):void 0;h&&(c.replyTo=h);const a=e.get("content-type"),u=G(a);if(u&&a?.toLowerCase().includes("multipart")){const d=t.split(`--${u}`);for(const l of d){const p=l.replace(I,"");if(!(!p||p.startsWith("--"))){const{body:C,headers:m}=B(p),x=m.map.get("content-type")??"",A=m.map.get("content-transfer-encoding");(m.map.get("content-disposition")??"").toLowerCase().includes("attachment")||(x.toLowerCase().includes("text/plain")?c.text=w(C.replace(L,""),A):x.toLowerCase().includes("text/html")&&(c.html=w(C.replace(L,""),A)))}}}else{const d=e.get("content-transfer-encoding"),l=w(t.replace(N,""),d);a?.toLowerCase().includes("text/html")?c.html=l:l&&(c.text=l)}const $=new Set(["bcc","cc","content-transfer-encoding","content-type","from","mime-version","reply-to","subject","to"]),g={};for(const[d,l]of n.raw){const p=d.toLowerCase();(p==="x-priority"||p==="importance")&&(_.test(l)?c.priority="high":F.test(l)&&(c.priority="low")),$.has(p)||(g[d]=l)}return Object.keys(g).length>0&&(c.headers=g),c};export{W as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/email",
3
- "version": "1.0.0-alpha.43",
3
+ "version": "1.0.0-alpha.44",
4
4
  "description": "A comprehensive email library with multi-provider support, crypto utilities, and template engines",
5
5
  "keywords": [
6
6
  "ahasend",
@@ -12,8 +12,6 @@
12
12
  "brevo",
13
13
  "crypto",
14
14
  "deliverability",
15
- "disposable-email",
16
- "disposable-email-domains",
17
15
  "dkim",
18
16
  "dmarc",
19
17
  "email",
@@ -336,30 +334,10 @@
336
334
  "types": "./dist/utils/cache.d.ts",
337
335
  "default": "./dist/utils/cache.js"
338
336
  },
339
- "./validation/disposable-email-domains": {
340
- "types": "./dist/utils/validation/disposable-email-domains.d.ts",
341
- "default": "./dist/utils/validation/disposable-email-domains.js"
342
- },
343
337
  "./validation/validate-email": {
344
338
  "types": "./dist/utils/validation/validate-email.d.ts",
345
339
  "default": "./dist/utils/validation/validate-email.js"
346
340
  },
347
- "./validation/check-mx-records": {
348
- "types": "./dist/utils/validation/check-mx-records.d.ts",
349
- "default": "./dist/utils/validation/check-mx-records.js"
350
- },
351
- "./validation/role-accounts": {
352
- "types": "./dist/utils/validation/role-accounts.d.ts",
353
- "default": "./dist/utils/validation/role-accounts.js"
354
- },
355
- "./validation/verify-smtp": {
356
- "types": "./dist/utils/validation/verify-smtp.d.ts",
357
- "default": "./dist/utils/validation/verify-smtp.js"
358
- },
359
- "./validation/verify-email": {
360
- "types": "./dist/utils/validation/verify-email.d.ts",
361
- "default": "./dist/utils/validation/verify-email.js"
362
- },
363
341
  "./validation/check-feature-support": {
364
342
  "types": "./dist/utils/validation/check-feature-support.d.ts",
365
343
  "default": "./dist/utils/validation/check-feature-support.js"
@@ -376,7 +354,6 @@
376
354
  "CHANGELOG.md"
377
355
  ],
378
356
  "dependencies": {
379
- "@visulima/disposable-email-domains": "1.0.0-alpha.17",
380
357
  "html-to-text": "^10.0.0",
381
358
  "ical-generator": "11.0.0",
382
359
  "lru-cache": "11.5.1",
@@ -1 +0,0 @@
1
- import{MailMessage as e}from"./MailMessage-L-Q9yc5v.js";class t extends e{constructor(){super(),this.header("X-Unsent","1")}}export{t as DraftMailMessage,t as default};
@@ -1 +0,0 @@
1
- import{DraftMailMessage as h}from"./DraftMailMessage-C9tevR8K.js";import v from"./EmailError-B-sEf3bp.js";import{MailMessage as f}from"./MailMessage-L-Q9yc5v.js";import{composeMiddleware as C}from"./composeMiddleware-BHwLLEzK.js";import{F as w}from"./build-mime-message-Be6TOi1T.js";import{c as M}from"./create-logger-BQTS3f-I.js";import{s as l}from"./headers-to-record-De1Eg951.js";import T from"../utils/validation/check-feature-support.js";const S=(i,e,r)=>{e.success&&e.data?i&&i.info("Email sent successfully",{messageId:e.data.messageId,provider:e.data.provider}):i&&i.error("Email send failed",{error:e.error,provider:r})},j=async(i,e,r)=>{const s={...i,to:e.to};return e.cc&&(s.cc=e.cc),e.bcc&&(s.bcc=e.bcc),e.replyTo&&(s.replyTo=e.replyTo),e.headers&&(s.headers={...l(i.headers??{}),...l(e.headers)}),s.subject=e.subject??i.subject,r&&e.data&&(s.subject=await r(s.subject,e.data),i.html!==void 0&&(s.html=await r(i.html,e.data)),i.text!==void 0&&(s.text=await r(i.text,e.data))),s};class u{static extractErrorMessages(e){return e instanceof Error?[e.message]:[String(e??"Unknown error")]}provider;logger;loggerInstance;globalConfig;featureCheck;middlewares=[];composedSend;mountedProviders=new Map;constructor(e,r){this.provider=e,this.featureCheck=r?.featureCheck??"error"}setLogger(e){return this.loggerInstance=e,this.logger=M("Mail",e),this}use(e){return this.middlewares.push(e),this.composedSend=void 0,this}mount(e,r){return this.mountedProviders.set(e,r),this}setFrom(e){return this.globalConfig??={},this.globalConfig.from=e,this.logger&&this.logger.debug("Default from address updated",{from:e.email}),this}setReplyTo(e){return this.globalConfig??={},this.globalConfig.replyTo=e,this.logger&&this.logger.debug("Default reply-to address updated",{replyTo:e.email}),this}setHeaders(e){if(this.globalConfig??={},this.globalConfig.headers=e,this.logger){const r=l(e);this.logger.debug("Default headers updated",{count:Object.keys(r).length,headers:Object.keys(r)})}return this}async draft(e){let r=e instanceof f||e instanceof h?await this.buildDraftFromMessage(e):await this.buildDraftFromOptions(e);r=this.applyGlobalConfig(r);const s=r.headers?l(r.headers):{};r.headers={...s,"X-Unsent":"1"};const t=await w(r,{includeBcc:!0});return this.logger&&this.logger.debug("Draft created successfully in EML format",{from:r.from.email,size:t.length,subject:r.subject,to:Array.isArray(r.to)?r.to.length:1}),t}async send(e){if(e instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");let r;if(e instanceof f)this.logger&&this.logger.debug("Sending MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),r=await e.build();else{const o=e;this.logger&&this.logger.debug("Sending email with options",{subject:o.subject,to:Array.isArray(o.to)?o.to.length:1}),r=o}r=this.applyGlobalConfig(r);const s=this.assertFeatureSupport(r);if(s)return{error:s,success:!1};const t=await this.dispatch(r);return S(this.logger,t,this.provider.name??"unknown"),t}sendMany(e,r){const s=Math.max(1,Math.floor(r?.concurrency??1));return s===1?this.sendManySerial(e,r?.signal):this.sendManyConcurrent(e,s,r?.signal)}sendBatch(e,r,s){const t=async function*(){const o=e instanceof f?await e.build():e;for(const a of r)yield await j(o,a,s?.render)};return this.sendMany(t(),{concurrency:s?.concurrency,signal:s?.signal})}async sendOneToReceipt(e){const r=this.provider.name;try{const s=await this.send(e);return s.success&&s.data?{messageId:s.data.messageId,provider:s.data.provider??r,response:s.data.response,successful:!0,timestamp:s.data.timestamp}:{errorMessages:u.extractErrorMessages(s.error),provider:r,successful:!1}}catch(s){return{errorMessages:u.extractErrorMessages(s),provider:r,successful:!1}}}async*sendManySerial(e,r){const s=this.provider.name;let t=0,o=0,a=0;this.logger&&this.logger.debug("Starting batch email send",{provider:s});for await(const n of e){if(n instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");if(r?.aborted){this.logger&&this.logger.warn("Batch send operation was aborted",{failed:a,processed:t,successful:o}),yield{errorMessages:["Send operation was aborted"],provider:s,successful:!1};return}t+=1;const g=await this.sendOneToReceipt(n);g.successful?o+=1:a+=1,yield g}this.logger&&this.logger.debug("Batch email send completed",{failureCount:a,processedCount:t,provider:s,successCount:o})}async*sendManyConcurrent(e,r,s){const t=this.provider.name;this.logger&&this.logger.debug("Starting concurrent batch email send",{concurrency:r,provider:t});const o=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator](),a=new Map;let n=0,g=!1,p=!1;const m=async()=>{for(;!g&&!p&&a.size<r;){const d=await o.next();if(d.done){g=!0;break}const c=d.value;if(c instanceof h)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");const b=n;n+=1,a.set(b,this.sendOneToReceipt(c).then(y=>({id:b,receipt:y})))}};for(await m();a.size>0;){if(s?.aborted){p=!0,yield{errorMessages:["Send operation was aborted"],provider:t,successful:!1};return}const{id:d,receipt:c}=await Promise.race(a.values());a.delete(d),yield c,await m()}this.logger&&this.logger.debug("Concurrent batch email send completed",{processedCount:n,provider:t})}async dispatch(e){return this.middlewares.length===0?await this.resolveProvider(e).sendEmail(e):(this.composedSend??=C(this.middlewares,r=>Promise.resolve(this.resolveProvider(r).sendEmail(r))),await this.composedSend(e))}resolveProvider(e){return e.stream!==void 0?this.mountedProviders.get(e.stream)??this.provider:this.provider}assertFeatureSupport(e){if(this.featureCheck==="off")return;const{supported:r,violations:s}=T(e,this.provider.features);if(r)return;const t=this.provider.name??"unknown",o=s.map(n=>n.field),a=s.map(n=>n.message);if(this.featureCheck==="warn"){this.logger&&this.logger.warn("Message uses capabilities the provider does not support",{fields:o,provider:t});return}return this.logger&&this.logger.error("Message rejected by capability guard",{fields:o,provider:t}),new v(t,`Provider does not support the following message fields: ${o.join(", ")}`,{code:"UNSUPPORTED_FEATURES",hint:a})}async buildDraftFromMessage(e){return this.logger&&this.logger.debug("Creating draft from MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),this.applyGlobalConfigToMessage(e),await e.build()}async buildDraftFromOptions(e){return this.logger&&this.logger.debug("Creating draft from email options",{subject:e.subject,to:Array.isArray(e.to)?e.to.length:1}),e}applyGlobalConfigToMessage(e){const r=this.globalConfig?.from;r&&!e.getFrom()&&e.from(r);const s=this.globalConfig?.replyTo;if(s&&!e.getReplyTo()&&e.replyTo(s),this.globalConfig?.headers){const t=l(this.globalConfig.headers);Object.entries(t).forEach(([o,a])=>{e.header(o,a)})}}applyGlobalConfig(e){if(!this.globalConfig)return e;const r={...e};if(!r.from&&this.globalConfig.from&&(r.from=this.globalConfig.from,this.logger&&this.logger.debug("Applied global from address",{from:this.globalConfig.from.email})),!r.replyTo&&this.globalConfig.replyTo&&(r.replyTo=this.globalConfig.replyTo,this.logger&&this.logger.debug("Applied global reply-to address",{replyTo:this.globalConfig.replyTo.email})),this.globalConfig.headers){const s=l(this.globalConfig.headers),t=r.headers?l(r.headers):{};r.headers={...s,...t},this.logger&&this.logger.debug("Merged global headers",{globalCount:Object.keys(s).length,messageCount:Object.keys(t).length})}return r}}const A=(i,e)=>new u(i,e);export{u as Mail,A as createMail};
@@ -1 +0,0 @@
1
- import{createRequire as f}from"node:module";import{readFileAsBuffer as c,detectMimeType as d,generateContentId as u}from"./detectMimeType-Dxv4MjZ7.js";import{c as b}from"./create-logger-BQTS3f-I.js";import{s as l}from"./headers-to-record-De1Eg951.js";const y=f(import.meta.url),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,p=n=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[e,t]=o.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return o.getBuiltinModule(n)}return y(n)},{basename:g}=p("node:path"),{fileURLToPath:A}=p("node:url"),m=async()=>(await import("../template-engines/html-to-text.js")).default,T=async()=>(await import("ical-generator")).default,a=n=>Array.isArray(n)?n.map(e=>typeof e=="string"?{email:e}:e):typeof n=="string"?[{email:n}]:[n];class v{fromAddress;toAddresses=[];ccAddresses=[];bccAddresses=[];subjectText="";textContent;textCharset="utf8";autoTextEnabled=!0;htmlContent;htmlCharset="utf8";dateValue;returnPathAddress;senderAddress;headers={};attachments=[];replyToAddress;priorityValue;tagsValue=[];signer;encrypter;logger;icalEventData;icalEventBuilder;from(e){return this.fromAddress=typeof e=="string"?{email:e}:e,this}to(e){return this.toAddresses.length=0,this.toAddresses.push(...a(e)),this}cc(e){return this.ccAddresses.length=0,this.ccAddresses.push(...a(e)),this}bcc(e){return this.bccAddresses.length=0,this.bccAddresses.push(...a(e)),this}subject(e){return this.subjectText=e,this}text(e,t="utf8"){return this.textContent=e,this.textCharset=t,this}html(e,t="utf8"){return this.htmlContent=e,this.htmlCharset=t,this}header(e,t){return this.headers[e]=t,this}setHeaders(e){const t=l(e);return Object.assign(this.headers,t),this}async attachFromPath(e,t){try{const s=await c(e),i=t?.filename??(g(e)||"attachment"),r=t?.contentType??d(i);this.attachments.push({cid:t?.cid,content:s,contentDisposition:t?.contentDisposition??"attachment",contentType:r,encoding:t?.encoding,filename:i,headers:t?.headers}),this.logger&&this.logger.debug(`Attachment added from path: ${e}`,{contentType:r,filename:i})}catch(s){throw this.logger&&this.logger.error(`Failed to attach file from path: ${e}`,s),s}return this}attachData(e,t){const s=t.contentType??d(t.filename);return this.attachments.push({cid:t.cid,content:e,contentDisposition:t.contentDisposition??"attachment",contentType:s,encoding:t.encoding,filename:t.filename,headers:t.headers}),this.logger&&this.logger.debug("Attachment added from data",{contentType:s,filename:t.filename}),this}async embedFromPath(e,t){try{const s=await c(e),i=t?.filename??(g(e)||"inline"),r=t?.contentType??d(i),h=u(i);return this.attachments.push({cid:h,content:s,contentDisposition:"inline",contentType:r,filename:i}),this.logger&&this.logger.debug(`Inline attachment embedded from path: ${e}`,{cid:h,contentType:r,filename:i}),h}catch(s){throw this.logger&&this.logger.error(`Failed to embed file from path: ${e}`,s),s}}embedData(e,t,s){const i=s?.contentType??d(t),r=u(t);return this.attachments.push({cid:r,content:e,contentDisposition:"inline",contentType:i,filename:t}),this.logger&&this.logger.debug("Inline attachment embedded from data",{cid:r,contentType:i,filename:t}),r}replyTo(e){return this.replyToAddress=typeof e=="string"?{email:e}:e,this}date(e){return this.dateValue=typeof e=="string"?new Date(e):e,this.logger&&this.logger.debug("Date header set",{date:this.dateValue.toISOString()}),this}returnPath(e){return this.returnPathAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Return-path address set",{returnPath:this.returnPathAddress.email}),this}sender(e){return this.senderAddress=typeof e=="string"?{email:e}:e,this.logger&&this.logger.debug("Sender address set",{sender:this.senderAddress.email}),this}addTo(e){return this.toAddresses.push(...a(e)),this}addCc(e){return this.ccAddresses.push(...a(e)),this}addBcc(e){return this.bccAddresses.push(...a(e)),this}addReplyTo(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.replyToAddress=typeof s=="string"?{email:s}:s}return this}addFrom(e){const t=Array.isArray(e)?e:[e];if(t.length>0){const s=t[0];this.fromAddress=typeof s=="string"?{email:s}:s}return this}priority(e){return this.priorityValue=e,this}tags(e){return this.tagsValue=Array.isArray(e)?e:[e],this}sign(e){return this.signer=e,this.logger&&this.logger.debug("Email signer configured"),this}encrypt(e){return this.encrypter=e,this.logger&&this.logger.debug("Email encrypter configured"),this}setLogger(e){return this.logger=b("MailMessage",e),this}icalEvent(e,t){return typeof e=="function"?(this.icalEventBuilder={build:e,options:t},this.icalEventData=void 0):(this.icalEventBuilder=void 0,this.icalEventData={content:e,...t}),this.logger&&this.logger.debug("Calendar event attached",{method:t?.method}),this}icalEventFromFile(e,t){const s=typeof e=="string"?e:A(e);return this.icalEventData={path:s,...t},this.logger&&this.logger.debug(`Calendar event attached from file: ${s}`,{method:t?.method}),this}icalEventFromUrl(e,t){return this.icalEventData={href:e,...t},this.logger&&this.logger.debug(`Calendar event attached from URL: ${e}`,{method:t?.method}),this}async view(e,t,s,i){try{const r=i?.autoText!==!1;this.autoTextEnabled=r,this.logger&&this.logger.debug("Rendering template",{autoText:r});const h=await e(t,s,i);this.html(h),r&&h&&await this.tryAutoGenerateText(h),this.logger&&this.logger.debug("Template rendered successfully")}catch(r){throw this.logger&&this.logger.error("Failed to render template",r),new Error(`Failed to render template: ${r.message}`)}return this}async viewText(e,t,s,i){try{this.logger&&this.logger.debug("Rendering text template");const r=await e(t,s,i);if(typeof r=="string")this.text(r),this.logger&&this.logger.debug("Text template rendered successfully");else throw new TypeError("Text renderer must return a string")}catch(r){throw this.logger&&this.logger.error("Failed to render text template",r),new Error(`Failed to render text template: ${r.message}`)}return this}async build(){if(this.logger&&this.logger.debug("Building email message"),this.fromAddress||this.throwAndLogError("From address is required","Build failed: from address is required"),this.toAddresses.length===0&&this.throwAndLogError("At least one recipient is required","Build failed: at least one recipient is required"),this.subjectText||this.throwAndLogError("Subject is required","Build failed: subject is required"),this.htmlContent&&!this.textContent&&this.autoTextEnabled)try{const t=await m();this.textContent=t(this.htmlContent),this.logger&&this.logger.debug("Auto-generated text content from HTML")}catch{this.logger&&this.logger.debug("Failed to convert HTML to text; proceeding without text content.")}!this.textContent&&!this.htmlContent&&this.throwAndLogError("Either text or html content is required","Build failed: either text or html content is required");let e={from:this.fromAddress,html:this.htmlContent,subject:this.subjectText,text:this.textContent,to:this.toAddresses.length===1?this.toAddresses[0]:this.toAddresses};if(this.ccAddresses.length>0&&(e.cc=this.ccAddresses.length===1?this.ccAddresses[0]:this.ccAddresses),this.bccAddresses.length>0&&(e.bcc=this.bccAddresses.length===1?this.bccAddresses[0]:this.bccAddresses),Object.keys(this.headers).length>0&&(e.headers=this.headers),this.attachments.length>0&&(e.attachments=this.attachments,this.logger&&this.logger.debug(`Email includes ${this.attachments.length} attachment(s)`)),this.replyToAddress&&(e.replyTo=this.replyToAddress),this.priorityValue&&(e.priority=this.priorityValue),this.tagsValue.length>0&&(e.tags=this.tagsValue),this.icalEventBuilder){const t=(await T())();this.icalEventBuilder.build(t),this.icalEventData={content:t.toString(),...this.icalEventBuilder.options}}return this.icalEventData&&(e.icalEvent=this.icalEventData,this.logger&&this.logger.debug("Email includes calendar event")),this.dateValue&&(e.headers={...l(e.headers??{}),Date:this.dateValue.toUTCString()}),this.returnPathAddress&&(e.headers={...l(e.headers??{}),"Return-Path":this.returnPathAddress.email}),this.senderAddress&&(e.headers={...l(e.headers??{}),Sender:this.senderAddress.email}),this.signer&&(this.logger&&this.logger.debug("Signing email message"),e=await this.signer.sign(e),this.logger&&this.logger.debug("Email message signed successfully")),this.encrypter&&(this.logger&&this.logger.debug("Encrypting email message"),e=await this.encrypter.encrypt(e),this.logger&&this.logger.debug("Email message encrypted successfully")),this.logger&&this.logger.debug("Email message built successfully",{bcc:this.bccAddresses.length,cc:this.ccAddresses.length,hasHtml:!!this.htmlContent,hasText:!!this.textContent,to:this.toAddresses.length}),e}getSubject(){return this.subjectText}getFrom(){return this.fromAddress}getTo(){return[...this.toAddresses]}getCc(){return[...this.ccAddresses]}getBcc(){return[...this.bccAddresses]}getReplyTo(){return this.replyToAddress}getSender(){return this.senderAddress}getReturnPath(){return this.returnPathAddress}getDate(){return this.dateValue}getPriority(){return this.priorityValue}getTextBody(){return this.textContent}getTextCharset(){return this.textCharset}getHtmlBody(){return this.htmlContent}getHtmlCharset(){return this.htmlCharset}getAttachments(){return[...this.attachments]}async tryAutoGenerateText(e){try{const t=(await m())(e);t&&!this.textContent&&this.text(t),this.logger&&this.logger.debug("Auto-generated text content from HTML template")}catch(t){this.logger&&this.logger.warn("Failed to auto-generate text from HTML template",t)}}throwAndLogError(e,t){const s=new Error(e);throw this.logger&&this.logger.error(t??e),s}}export{v as MailMessage,v as default};
@@ -1 +0,0 @@
1
- import{createRequire as A}from"node:module";import c from"./EmailError-B-sEf3bp.js";import j from"./RequiredOptionError-DuNNY_a5.js";import{e as S}from"./generate-message-id-gXAuMz4g.js";import{s as _}from"./headers-to-record-De1Eg951.js";import{m as f}from"./make-request-BlK_B72c.js";import{u as y}from"./retry-3pnxTuNs.js";import{f as E}from"./validate-email-options-mCM9dVug.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{f as p,a as k}from"./address-formatter-BWR2Dddx.js";import{h as b,P as q,c as K}from"./provider-base-gIoUu9so.js";const P=A(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,I=s=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,u]=m.versions.node.split(".").map(Number);if(a>22||a===22&&u>=3||a===20&&u>=16)return m.getBuiltinModule(s)}return P(s)},{Buffer:T}=I("node:buffer"),i="ahasend",B="https://api.ahasend.com",C=3e4,x=3,U=z((s={})=>{if(!s.apiKey)throw new j(i,"apiKey");const a={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??B,retries:s.retries??x,timeout:s.timeout??C,...s.logger&&{logger:s.logger}},u=new q,n=K(i,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(i,"Email ID is required to retrieve email details"),success:!1};await this.initialize();const o={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await y(async()=>f(`${a.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(i,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:b(i,"retrieve email",o,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(i,"AhaSend API not available or invalid API key");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{return n.debug("Checking AhaSend API availability"),!!(await f(`${a.endpoint}/v2/ping`,{headers:{Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},method:"GET",timeout:a.timeout})).success}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:a,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new c(i,`Invalid email options: ${o.join(", ")}`),success:!1};await this.initialize();const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=k(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 r=_(e.headers);t.headers=r}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async r=>{let d;if(r.content)if(typeof r.content=="string")d=r.content;else if(r.content instanceof Promise){const v=await r.content;d=T.from(v).toString("base64")}else d=r.content.toString("base64");else if(r.raw)d=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new c(i,`Attachment ${r.filename} has no content`);return{content:d,contentType:r.contentType??"application/octet-stream",filename:r.filename,...r.cid&&{cid:r.cid}}}))),n.debug("Sending email via AhaSend API",{subject:t.subject,to:t.to});const w={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},l=await y(async()=>f(`${a.endpoint}/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(t)),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 g=l.data?.body,h=g?.messageId??g?.id??S();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:i,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:b(i,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
@@ -1 +0,0 @@
1
- import{createRequire as P}from"node:module";import c from"./EmailError-B-sEf3bp.js";import S from"./RequiredOptionError-DuNNY_a5.js";import{e as _}from"./generate-message-id-gXAuMz4g.js";import{s as k}from"./headers-to-record-De1Eg951.js";import{m as y}from"./make-request-BlK_B72c.js";import{u as w}from"./retry-3pnxTuNs.js";import{f as z}from"./validate-email-options-mCM9dVug.js";import{defineProvider as q}from"./defineProvider-C9q-7iwt.js";import{P as B,h as T,c as K}from"./provider-base-gIoUu9so.js";import{f as g,a as h}from"./address-formatter-BWR2Dddx.js";const j=P(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,C=o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[d,s]=p.versions.node.split(".").map(Number);if(d>22||d===22&&s>=3||d===20&&s>=16)return p.getBuiltinModule(o)}return j(o)},{Buffer:E}=C("node:buffer"),a="brevo",x="https://api.brevo.com/v3",D=3e4,G=3,W=q((o={})=>{if(!o.apiKey)throw new S(a,"apiKey");const d=o.endpoint??x,s={apiKey:o.apiKey,debug:o.debug??!1,endpoint:d,hardValidation:o.hardValidation??!1,retries:o.retries??G,timeout:o.timeout??D,...o.logger&&{logger:o.logger}},f=new B,n=K(a,o.logger);return{endpoint:s.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const l=await w(async()=>y(`${s.endpoint}/smtp/emails/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return l.success?(n.debug("Email details retrieved successfully"),{data:l.data?.body,success:!0}):(n.debug("API request failed when retrieving email",l.error),{error:new c(a,`Failed to retrieve email: ${l.error instanceof Error?l.error.message:"Unknown error"}`,{cause:l.error}),success:!1})}catch(t){return{error:T(a,"retrieve email",t,n),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Brevo API not available or invalid API key");n.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Checking Brevo API availability");const t=await y(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return n.debug("Brevo API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{let t;Array.isArray(e.replyTo)?t=e.replyTo.length>0?e.replyTo[0]:void 0:t=e.replyTo;const l={...e,replyTo:t},b=z(l);if(b.length>0)return{error:new c(a,`Invalid email options: ${b.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const i={sender:h(e.from),subject:e.subject,to:g(e.to)};if(e.html&&(i.htmlContent=e.html),e.text&&(i.textContent=e.text),e.cc&&(i.cc=g(e.cc)),e.bcc&&(i.bcc=g(e.bcc)),e.replyTo)if(Array.isArray(e.replyTo)){if(s.hardValidation)return{error:new c(a,"Only one replyTo address is allowed"),success:!1};if(e.replyTo.length===0)return{error:new c(a,"replyTo array cannot be empty"),success:!1};const r=e.replyTo[0];if(!r)return{error:new c(a,"replyTo array cannot be empty"),success:!1};i.replyTo=h(r)}else i.replyTo=h(e.replyTo);if(e.templateId&&(i.templateId=e.templateId,e.templateParams&&(i.params=e.templateParams)),e.tags&&e.tags.length>0&&(i.tags=e.tags),e.scheduledAt){const r=typeof e.scheduledAt=="number"?new Date(e.scheduledAt*1e3).toISOString():e.scheduledAt;i.scheduledAt=r}if(e.batchId&&(i.batchId=e.batchId),e.headers){const r=k(e.headers);i.headers=r}e.attachments&&e.attachments.length>0&&(i.attachment=await Promise.all(e.attachments.map(async r=>{let m;if(r.content)if(typeof r.content=="string")m=r.content;else if(r.content instanceof Promise){const I=await r.content;m=E.from(I).toString("base64")}else m=r.content.toString("base64");else if(r.raw)m=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new c(a,`Attachment ${r.filename} has no content`);return{content:m,name:r.filename,...r.contentType&&{type:r.contentType}}}))),n.debug("Sending email via Brevo API",{subject:i.subject,to:i.to});const A={"api-key":s.apiKey,"Content-Type":"application/json"},u=await w(async()=>y(`${s.endpoint}/smtp/email`,{headers:A,method:"POST",timeout:s.timeout},JSON.stringify(i)),s.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(a,"Failed to send email"),success:!1};const v=u.data?.body?.messageId??_();return n.debug("Email sent successfully",{messageId:v}),{data:{messageId:v,provider:a,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:T(a,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{W as default};