@visulima/email 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +57 -1
- package/dist/deliverability/dmarc-report.js +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1 -1
- package/dist/middleware/index.js +1 -1
- package/dist/packem_chunks/index.js +5 -5
- package/dist/packem_shared/EmailError-SXEFQEyA.js +1 -0
- package/dist/packem_shared/{Mail-DmYNQ0KK.js → Mail-0cxS6jre.js} +1 -1
- package/dist/packem_shared/{RequiredOptionError-ctDEEB1s.js → RequiredOptionError-C2wWqmiE.js} +1 -1
- package/dist/packem_shared/{ahaSendProvider-D95-pwFh.js → ahaSendProvider-Ci_a_O8d.js} +1 -1
- package/dist/packem_shared/{attachment-processor-BJFDS343.js → attachment-processor-AB1m-n9T.js} +1 -1
- package/dist/packem_shared/{autoSendProvider-yxUx3sEj.js → autoSendProvider-DG3pNJML.js} +1 -1
- package/dist/packem_shared/{awsSesProvider-DnZo9X_g.js → awsSesProvider-C4b5kuL4.js} +1 -1
- package/dist/packem_shared/{azureProvider-D6Z4c1yT.js → azureProvider-CEnz3uy_.js} +1 -1
- package/dist/packem_shared/{brevoProvider-D1yTSs0l.js → brevoProvider-BsbInXjw.js} +1 -1
- package/dist/packem_shared/{build-mime-message-BCFKPqaW.js → build-mime-message-D45WdgfP.js} +1 -1
- package/dist/packem_shared/{circuitBreakerMiddleware-DcBN7K6H.js → circuitBreakerMiddleware-Cm0m75qi.js} +1 -1
- package/dist/packem_shared/{cloudflareEmailProvider-DZbs35NL.js → cloudflareEmailProvider-CnpH5R5p.js} +1 -1
- package/dist/packem_shared/{createTestEmail-gr512snl.js → createTestEmail-DWimjf0F.js} +1 -1
- package/dist/packem_shared/createWorker-ChrQvLUF.js +1 -0
- package/dist/packem_shared/extractLinks-BwE1SjNF.js +1 -0
- package/dist/packem_shared/{failoverProvider-IED1M0M5.js → failoverProvider-DsBqMOfK.js} +1 -1
- package/dist/packem_shared/fileProvider-BnDeaSqA.js +1 -0
- package/dist/packem_shared/{httpProvider-CpdWJoRq.js → httpProvider-BuA00407.js} +1 -1
- package/dist/packem_shared/{infobipProvider-DTqFu5pM.js → infobipProvider-DVUg9jKC.js} +1 -1
- package/dist/packem_shared/{isValidSigningCertUrl-CK1t2a7x.js → isValidSigningCertUrl-gnYr3oyD.js} +1 -1
- package/dist/packem_shared/{loopsProvider-PiE2HxoW.js → loopsProvider-BJUNQ2rR.js} +1 -1
- package/dist/packem_shared/{mailCrabProvider-BSapw_mS.js → mailCrabProvider-CFKRofS5.js} +1 -1
- package/dist/packem_shared/{mailPaceProvider-BugIutTw.js → mailPaceProvider-DBQd6NYt.js} +1 -1
- package/dist/packem_shared/{mailchannelsProvider-Dn24mI8D.js → mailchannelsProvider-CPVW3wlH.js} +1 -1
- package/dist/packem_shared/{mailerSendProvider-B6X4Lhsf.js → mailerSendProvider-B2H6BtoV.js} +1 -1
- package/dist/packem_shared/{mailgunProvider-4sMtcQcW.js → mailgunProvider-JRVH70PB.js} +1 -1
- package/dist/packem_shared/{mailjetProvider-DvrHwipw.js → mailjetProvider-BzBovF5M.js} +1 -1
- package/dist/packem_shared/{mailomatProvider-CrkNQGfL.js → mailomatProvider-x6IHKuWU.js} +1 -1
- package/dist/packem_shared/{mailtrapProvider-DTgvCUrs.js → mailtrapProvider-CJTJoDcV.js} +1 -1
- package/dist/packem_shared/make-request-mszP240P.js +1 -0
- package/dist/packem_shared/{mandrillProvider-BaK0GEj7.js → mandrillProvider-BcztgKkr.js} +1 -1
- package/dist/packem_shared/{mockProvider-CTxxbT0d.js → mockProvider-DVtl5Jjy.js} +1 -1
- package/dist/packem_shared/{netcoreProvider-BZJ0noQ2.js → netcoreProvider-YWEpa-wi.js} +1 -1
- package/dist/packem_shared/{nodemailerProvider-DqJh8ghN.js → nodemailerProvider-WNNtLE2s.js} +1 -1
- package/dist/packem_shared/{opentelemetryProvider-s0gvh05u.js → opentelemetryProvider-ddbILMeS.js} +1 -1
- package/dist/packem_shared/{outlook365Provider-DQUSFy2d.js → outlook365Provider-D5eETMZq.js} +1 -1
- package/dist/packem_shared/{plunkProvider-WMi1yPya.js → plunkProvider-TrBBoX7_.js} +1 -1
- package/dist/packem_shared/{postalProvider-DpBFGpoX.js → postalProvider-CU53hX0R.js} +1 -1
- package/dist/packem_shared/{postmarkProvider-ClUaHPvw.js → postmarkProvider-DEYQp8Gv.js} +1 -1
- package/dist/packem_shared/{provider-base-BEz00m9R.js → provider-base-G22b4a87.js} +1 -1
- package/dist/packem_shared/{resendProvider-DtaB7sk0.js → resendProvider-DC7Op5Gr.js} +1 -1
- package/dist/packem_shared/{retry-aghj7y8m.js → retry-ByPJFAtq.js} +1 -1
- package/dist/packem_shared/{roundRobinProvider-Dr1DdT2L.js → roundRobinProvider-CfuNY7We.js} +1 -1
- package/dist/packem_shared/{scalewayProvider-BhbDUEah.js → scalewayProvider-x6S2ZSPd.js} +1 -1
- package/dist/packem_shared/{sendGridProvider-DBZHhxd6.js → sendGridProvider-8Po3P-ia.js} +1 -1
- package/dist/packem_shared/{smtpProvider-CjcOEiAh.js → smtpProvider-BPamDNuv.js} +1 -1
- package/dist/packem_shared/{sparkpostProvider-B19lU9D5.js → sparkpostProvider-BVu1KeNz.js} +1 -1
- package/dist/packem_shared/{sweegoProvider-H8KWGDff.js → sweegoProvider-DHISjS9s.js} +1 -1
- package/dist/packem_shared/{verifySendGridWebhook-csuRasH3.js → verifySendGridWebhook-0_3qKQA1.js} +1 -1
- package/dist/packem_shared/{withSuppression-B0eZ2xNQ.js → withSuppression-COCHL9Zx.js} +1 -1
- package/dist/packem_shared/{zeptomailProvider-L7nkdn0L.js → zeptomailProvider-IhCIl_2a.js} +1 -1
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/autosend/index.js +1 -1
- package/dist/providers/aws-ses/index.js +1 -1
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/cloudflare-email/index.js +1 -1
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/file/index.d.ts +23 -0
- package/dist/providers/file/index.js +1 -0
- package/dist/providers/http/index.js +1 -1
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/loops/index.js +1 -1
- package/dist/providers/mailchannels/index.js +1 -1
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/netcore/index.js +1 -1
- package/dist/providers/nodemailer/index.js +1 -1
- package/dist/providers/opentelemetry/index.js +1 -1
- package/dist/providers/outlook365/index.js +1 -1
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/roundrobin/index.js +1 -1
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sparkpost/index.js +1 -1
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/queue/index.d.ts +2 -1
- package/dist/queue/index.js +1 -1
- package/dist/render/css-inline.js +1 -1
- package/dist/template-engines/handlebars.js +1 -1
- package/dist/template-engines/html-to-text.js +1 -1
- package/dist/template-engines/i18n.js +1 -1
- package/dist/template-engines/jsx-email.js +1 -1
- package/dist/template-engines/liquid.js +1 -1
- package/dist/template-engines/locale-files.d.ts +66 -0
- package/dist/template-engines/locale-files.js +1 -0
- package/dist/template-engines/mjml.js +1 -1
- package/dist/template-engines/react-email.js +1 -1
- package/dist/template-engines/vue-email.js +1 -1
- package/dist/test/index.d.ts +19 -2
- package/dist/test/index.js +1 -1
- package/dist/utils/format-email-address.js +1 -1
- package/dist/utils/result.js +1 -1
- package/dist/webhooks/index.js +1 -1
- package/package.json +9 -1
- package/dist/packem_shared/EmailError-BIaHK1Uw.js +0 -1
- package/dist/packem_shared/createWorker-ChuTgETP.js +0 -1
- package/dist/packem_shared/make-request-Cyz5_yu8.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-
|
|
1
|
+
import d from"./EmailError-SXEFQEyA.js";import _ from"./RequiredOptionError-C2wWqmiE.js";import{h as N}from"./headers-to-record-ZOZ7Dubo.js";import{m as k}from"./make-request-mszP240P.js";import{r as D}from"./retry-ByPJFAtq.js";import{s as M,a as j}from"./sanitize-header-CW0f3IT7.js";import{v as C}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as H}from"./defineProvider-C9q-7iwt.js";import{c as P,h as L,P as U}from"./provider-base-G22b4a87.js";import{a as b,f as y}from"./address-formatter-w36S9ZYj.js";import{c as z}from"./attachment-processor-AB1m-n9T.js";const n="autosend",G="https://api.autosend.com/v1",x=3e4,B=3,p=50,v=20,T=40*1024*1024,w=20,$=1e3,I=998,F=/^[A-Z0-9-]{1,76}$/i,K="^[A-Za-z0-9-]{1,76}$",X="Either text or html content is required",h=t=>[t].flat(),q=async t=>{const s=await z(t,n);return{content:s.content,contentType:s.contentType,fileName:s.filename}},V=(t,s)=>{const c=h(t.to);if(c.length!==1)return`AutoSend's send endpoint takes exactly one 'to' recipient, but ${String(c.length)} were given — use 'cc'/'bcc', or send one message per recipient`;const o=c.length+(t.cc?h(t.cc).length:0)+(t.bcc?h(t.bcc).length:0);if(o>p)return`AutoSend allows at most ${String(p)} recipients across to/cc/bcc, but ${String(o)} were given`;if(t.attachments&&t.attachments.length>v)return`AutoSend allows at most ${String(v)} attachments, but ${String(t.attachments.length)} were given`;const e=t.attachments?.find(r=>r.cid);if(e)return`AutoSend does not support inline (cid) attachments, but '${e.filename}' sets one — host the image and reference it by URL instead`;if(t.subject.length>I)return`AutoSend allows a subject of at most ${String(I)} characters, but ${String(t.subject.length)} were given`;const a=Object.keys(s);if(a.length>w)return`AutoSend allows at most ${String(w)} custom headers, but ${String(a.length)} were given`;const i=a.find(r=>!F.test(r));if(i!==void 0)return`AutoSend header names must match ${K}, but '${i}' does not`;const l=a.find(r=>s[r].length>$);if(l!==void 0)return`AutoSend allows header values of at most ${String($)} characters, but '${l}' is longer`},J=t=>{if(typeof t!="object"||t===null)return{};const s=t;if(s.success===!0)return{emailId:typeof s.data?.emailId=="string"?s.data.emailId:void 0};const c=[s.message,s.error].find(o=>typeof o=="string");return{reason:typeof c=="string"?c:void 0}},ce=H((t={})=>{if(!t.apiKey)throw new _(n,"apiKey");const s={apiKey:t.apiKey,debug:t.debug??!1,endpoint:t.endpoint??G,logger:t.logger,retries:t.retries??B,timeout:t.timeout??x},c=new U,o=P(n,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){c.setInitialized()},async isAvailable(){return s.apiKey.length>0},name:n,options:s,async sendEmail(e){try{const a=C(e).filter(u=>!(e.templateId!==void 0&&u===X));if(a.length>0)return{error:new d(n,`Invalid email options: ${a.join(", ")}`),success:!1};const i=e.headers?N(e.headers):{},l=V(e,i);if(l)return{error:new d(n,l),success:!1};const r={from:b(e.from),subject:e.subject,to:b(h(e.to)[0])};if(e.templateId?r.templateId=e.templateId:(e.html&&(r.html=e.html),e.text&&(r.text=e.text)),e.cc&&(r.cc=y(e.cc)),e.bcc&&(r.bcc=y(e.bcc)),e.replyTo&&(r.replyTo=b(e.replyTo)),e.dynamicData&&(r.dynamicData=e.dynamicData),e.unsubscribeGroupId&&(r.unsubscribeGroupId=e.unsubscribeGroupId),e.trackingClick!==void 0&&(r.trackingClick=e.trackingClick),e.trackingOpen!==void 0&&(r.trackingOpen=e.trackingOpen),e.bypassSuppressions!==void 0&&(r.bypassSuppressions=e.bypassSuppressions),Object.keys(i).length>0&&(r.headers=Object.fromEntries(Object.entries(i).map(([u,m])=>[M(u),j(m)]))),e.attachments&&e.attachments.length>0){const u=await Promise.all(e.attachments.map(async A=>q(A))),m=u.reduce((A,R)=>A+R.content.length,0);if(m>T)return{error:new d(n,`AutoSend allows at most ${String(T)} bytes of attachments after Base64 encoding, but this message carries ${String(m)}`),success:!1};r.attachments=u}const g=await D(async()=>k(`${s.endpoint}/mails/send`,{headers:{Authorization:`Bearer ${s.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries),S=g.data?.body,{emailId:E,reason:f}=J(S);return g.success?f?{error:new d(n,`Failed to send email: ${f}`),success:!1}:E?(o.debug(`Email queued successfully: ${E}`),{data:{messageId:E,provider:n,response:S,sent:!0,timestamp:new Date},success:!0}):{error:new d(n,"AutoSend accepted the message but returned no emailId"),success:!1}:{error:f?new d(n,`Failed to send email: ${f}`):g.error??new d(n,"Failed to send email"),success:!1}}catch(a){return{error:L(n,"send email",a,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{ce as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as V}from"node:module";import E from"./EmailError-
|
|
1
|
+
import{createRequire as V}from"node:module";import E from"./EmailError-SXEFQEyA.js";import X from"./RequiredOptionError-C2wWqmiE.js";import{a as J}from"./apply-message-id-nFsQiH5j.js";import{c as Y}from"./create-logger-CazqtXcL.js";import m from"../utils/format-email-address.js";import{m as Z}from"./make-request-mszP240P.js";import{a as x,s as O}from"./sanitize-header-CW0f3IT7.js";import{v as ee}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as re}from"./defineProvider-C9q-7iwt.js";let F;const L=l=>(F??=V(import.meta.url))(l),A=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Q=l=>{if(typeof A<"u"&&A.versions&&A.versions.node){const[o,i]=A.versions.node.split(".").map(Number);if(o>22||o===22&&i>=3||o===20&&i>=16)return A.getBuiltinModule(l)}return L(l)},{randomUUID:G,createHash:q,createHmac:w}=Q("node:crypto"),te=globalThis.Buffer!==void 0,T=()=>{if(!te)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},y="aws-ses",I={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},Se=re((l={})=>{const o={...I,...l},i=Y("AWS-SES",l.logger),_=(e,c,r,s,n)=>{const t=Object.keys(r).toSorted().map(u=>{const f=r[u];return f===void 0?"":`${encodeURIComponent(u)}=${encodeURIComponent(f)}`}).filter(Boolean).join("&"),a=`${Object.keys(s).toSorted().map(u=>`${u.toLowerCase()}:${s[u]}`).join(`
|
|
2
2
|
`)}
|
|
3
3
|
`,d=Object.keys(s).toSorted().map(u=>u.toLowerCase()).join(";"),g=q("sha256").update(n).digest("hex");return[e,c,t,a,d,g].join(`
|
|
4
4
|
`)},k=(e,c,r)=>{const s=e.slice(0,8),n=q("sha256").update(r).digest("hex");return["AWS4-HMAC-SHA256",e,`${s}/${c}/ses/aws4_request`,n].join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as A}from"node:module";import u from"./EmailError-
|
|
1
|
+
import{createRequire as A}from"node:module";import u from"./EmailError-SXEFQEyA.js";import v from"./RequiredOptionError-C2wWqmiE.js";import{g as I}from"./generate-message-id-C5AM6DFE.js";import{h as _}from"./headers-to-record-ZOZ7Dubo.js";import{m as h}from"./make-request-mszP240P.js";import{r as T}from"./retry-ByPJFAtq.js";import{v as P}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as j}from"./defineProvider-C9q-7iwt.js";import{c as $,P as B,h as w}from"./provider-base-G22b4a87.js";import{b as y,c as R}from"./address-formatter-w36S9ZYj.js";let E;const z=s=>(E??=A(import.meta.url))(s),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=s=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[l,r]=m.versions.node.split(".").map(Number);if(l>22||l===22&&r>=3||l===20&&r>=16)return m.getBuiltinModule(s)}return z(s)},{Buffer:p}=k("node:buffer"),o="azure",C=3e4,q=3,Q=j((s={})=>{if(!s.region)throw new v(o,"region");if(!s.connectionString&&!s.accessToken)throw new v(o,"connectionString or accessToken");const l=s.endpoint??`https://${s.region}.communication.azure.com`,r={debug:s.debug??!1,endpoint:l,region:s.region,retries:s.retries??q,timeout:s.timeout??C,...s.connectionString&&{connectionString:s.connectionString},...s.accessToken&&{accessToken:s.accessToken},...s.logger&&{logger:s.logger}},g=new B,a=$(o,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new u(o,"Email ID is required to retrieve email details"),success:!1};await g.ensureInitialized(()=>this.initialize(),o);const i={"Content-Type":"application/json"};if(r.accessToken)i.Authorization=`Bearer ${r.accessToken}`;else if(r.connectionString){const c=r.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);c&&(i.Authorization=`Bearer ${c[2]}`)}a.debug("Retrieving email details",{id:e});const t=await T(async()=>h(`${r.endpoint}/emails/${e}`,{headers:i,method:"GET",timeout:r.timeout}),r.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 u(o,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(i){return{error:w(o,"retrieve email",i,a),success:!1}}},async initialize(){await g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(o,"Azure Communication Services API not available or invalid credentials");a.debug("Provider initialized successfully")},o)},async isAvailable(){try{const e={"Content-Type":"application/json"};if(r.accessToken)e.Authorization=`Bearer ${r.accessToken}`;else if(r.connectionString){const c=r.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(c)e.Authorization=`Bearer ${c[2]}`;else return!1}else return!1;a.debug("Checking Azure Communication Services API availability");const i=await h(`${r.endpoint}/emails:send`,{headers:e,method:"POST",timeout:r.timeout},JSON.stringify({}));if(i.success)return!0;const t=i.data?.statusCode;return t===401||t===403?!1:t===400}catch(e){if(a.debug("Error checking availability:",e),e instanceof Error){const i=e.message;if(i.includes("401")||i.includes("403"))return!1}return!1}},name:o,options:r,async sendEmail(e){try{const i=P(e);if(i.length>0)return{error:new u(o,`Invalid email options: ${i.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),o);const t={content:{subject:e.subject},recipients:{to:y(e.to)},senderAddress:e.from.email};if(e.html&&(t.content.html=e.html),e.text&&(t.content.plainText=e.text),e.cc&&(t.recipients.cc=y(e.cc)),e.bcc&&(t.recipients.bcc=y(e.bcc)),e.replyTo&&(t.replyTo=R(e.replyTo).email),e.importance&&(t.importance=e.importance),e.headers){const n=_(e.headers);t.headers=n}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async n=>{let f;if(n.content)if(typeof n.content=="string")f=p.from(n.content,"utf8").toString("base64");else if(n.content&&typeof n.content.then=="function"){const S=await n.content;f=p.from(S).toString("base64")}else f=n.content.toString("base64");else if(n.raw)f=typeof n.raw=="string"?p.from(n.raw,"utf8").toString("base64"):n.raw.toString("base64");else throw new u(o,`Attachment ${n.filename} has no content`);return{contentInBase64:f,contentType:n.contentType??"application/octet-stream",name:n.filename}}))),a.debug("Sending email via Azure Communication Services API",{subject:t.content.subject,to:t.recipients.to});const c={"Content-Type":"application/json"};if(r.accessToken)c.Authorization=`Bearer ${r.accessToken}`;else if(r.connectionString){const n=r.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(n)c.Authorization=`Bearer ${n[2]}`;else return{error:new u(o,"Invalid connection string format"),success:!1}}const d=await T(async()=>h(`${r.endpoint}/emails:send`,{headers:c,method:"POST",timeout:r.timeout},JSON.stringify(t)),r.retries);if(!d.success)return a.debug("API request failed when sending email",d.error),{error:d.error??new u(o,"Failed to send email"),success:!1};const b=d.data?.body?.messageId??I();return a.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:o,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(i){return{error:w(o,"send email",i,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./EmailError-
|
|
1
|
+
import c from"./EmailError-SXEFQEyA.js";import w from"./RequiredOptionError-C2wWqmiE.js";import{g as A}from"./generate-message-id-C5AM6DFE.js";import{h as I}from"./headers-to-record-ZOZ7Dubo.js";import{m as y}from"./make-request-mszP240P.js";import{r as g}from"./retry-ByPJFAtq.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{c as C,P as R,h as b}from"./provider-base-G22b4a87.js";import{f,a as m}from"./address-formatter-w36S9ZYj.js";import{p as S}from"./attachment-processor-AB1m-n9T.js";const t="brevo",k="https://api.brevo.com/v3",j=3e4,z=3,M=P((d={})=>{if(!d.apiKey)throw new w(t,"apiKey");const v=d.endpoint??k,s={apiKey:d.apiKey,debug:d.debug??!1,endpoint:v,hardValidation:d.hardValidation??!1,retries:d.retries??z,timeout:d.timeout??j,...d.logger&&{logger:d.logger}},l=new R,o=C(t,d.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(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={"api-key":s.apiKey,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const i=await g(async()=>y(`${s.endpoint}/smtp/emails/${e}`,{headers:r,method:"GET",timeout:s.timeout}),s.retries);return i.success?(o.debug("Email details retrieved successfully"),{data:i.data?.body,success:!0}):(o.debug("API request failed when retrieving email",i.error),{error:new c(t,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1})}catch(r){return{error:b(t,"retrieve email",r,o),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(t,"Brevo API not available or invalid API key");o.debug("Provider initialized successfully")},t)},async isAvailable(){try{const e={"api-key":s.apiKey,"Content-Type":"application/json"};o.debug("Checking Brevo API availability");const r=await y(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return o.debug("Brevo API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:t,options:s,async sendEmail(e){try{let r;Array.isArray(e.replyTo)?r=e.replyTo.length>0?e.replyTo[0]:void 0:r=e.replyTo;const i={...e,replyTo:r},h=E(i);if(h.length>0)return{error:new c(t,`Invalid email options: ${h.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const a={sender:m(e.from),subject:e.subject,to:f(e.to)};if(e.html&&(a.htmlContent=e.html),e.text&&(a.textContent=e.text),e.cc&&(a.cc=f(e.cc)),e.bcc&&(a.bcc=f(e.bcc)),e.replyTo)if(Array.isArray(e.replyTo)){if(s.hardValidation)return{error:new c(t,"Only one replyTo address is allowed"),success:!1};if(e.replyTo.length===0)return{error:new c(t,"replyTo array cannot be empty"),success:!1};const n=e.replyTo[0];if(!n)return{error:new c(t,"replyTo array cannot be empty"),success:!1};a.replyTo=m(n)}else a.replyTo=m(e.replyTo);if(e.templateId&&(a.templateId=e.templateId,e.templateParams&&(a.params=e.templateParams)),e.tags&&e.tags.length>0&&(a.tags=e.tags),e.scheduledAt){const n=typeof e.scheduledAt=="number"?new Date(e.scheduledAt*1e3).toISOString():e.scheduledAt;a.scheduledAt=n}if(e.batchId&&(a.batchId=e.batchId),e.headers){const n=I(e.headers);a.headers=n}e.attachments&&e.attachments.length>0&&(a.attachment=await Promise.all(e.attachments.map(async n=>({content:await S(n,t),name:n.filename,...n.contentType&&{type:n.contentType}})))),o.debug("Sending email via Brevo API",{subject:a.subject,to:a.to});const T={"api-key":s.apiKey,"Content-Type":"application/json"},u=await g(async()=>y(`${s.endpoint}/smtp/email`,{headers:T,method:"POST",timeout:s.timeout},JSON.stringify(a)),s.retries);if(!u.success)return o.debug("API request failed when sending email",u.error),{error:u.error??new c(t,"Failed to send email"),success:!1};const p=u.data?.body?.messageId??A();return o.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:t,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:b(t,"send email",r,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{M as default};
|
package/dist/packem_shared/{build-mime-message-BCFKPqaW.js → build-mime-message-D45WdgfP.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import M from"./EmailError-
|
|
1
|
+
import M from"./EmailError-SXEFQEyA.js";import m from"../utils/format-email-address.js";import{g as y}from"./generate-boundary-BCSUEi6x.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{e as z}from"./quoted-printable-BgiHOYdV.js";import{s as T,a as u}from"./sanitize-header-CW0f3IT7.js";const g=globalThis.Buffer!==void 0,b=e=>{if(typeof e=="string"){if(g)return Buffer.from(e,"utf8").toString("base64");const s=new TextEncoder().encode(e);let r="";const n=8192;for(let o=0;o<s.length;o+=n){const c=s.subarray(o,Math.min(o+n,s.length));r+=String.fromCharCode(...c)}return btoa(r)}if(g&&e instanceof Buffer)return e.toString("base64");const i=e instanceof Uint8Array?e:new Uint8Array(e);if(g)return Buffer.from(i).toString("base64");let l="";const a=8192;for(let t=0;t<i.length;t+=a){const s=i.subarray(t,Math.min(t+a,i.length));l+=String.fromCharCode(...s)}return btoa(l)},I=globalThis.Buffer!==void 0,N=/[^\u0000-\u007F]/,j=e=>!N.test(e),k=e=>{if(j(e))return e;const i=45,l=new TextDecoder,a=I?Buffer.from(e,"utf8"):new TextEncoder().encode(e),t=[];let s=0;for(;s<a.length;){let r=Math.min(s+i,a.length);if(r<a.length)for(;r>s&&(a[r]&192)===128;)r-=1;const n=a.subarray(s,r),o=l.decode(n);t.push(`=?UTF-8?B?${b(o)}?=`),s=r}return t.join(" ")},$=e=>Array.isArray(e)?e.map(i=>m(i)).join(", "):m(e),B=/[^ -~\r\n\t]/,E=e=>k(u(e)),R=globalThis.Buffer!==void 0,C=e=>e.replaceAll(/.{1,76}/g,`$&\r
|
|
2
2
|
`).trimEnd(),_=/\r\n|\r|\n/,w=e=>e.split(_),U=async(e,i={})=>{const{includeBcc:l=!1}=i,a=y(),t=[`From: ${m(e.from)}`,`To: ${$(e.to)}`];if(e.cc&&t.push(`Cc: ${$(e.cc)}`),l&&e.bcc&&t.push(`Bcc: ${$(e.bcc)}`),e.replyTo&&t.push(`Reply-To: ${m(e.replyTo)}`),t.push(`Subject: ${E(e.subject)}`,"MIME-Version: 1.0"),e.headers){const r=v(e.headers);Object.entries(r).forEach(([n,o])=>{const c=T(n),p=u(o);t.push(`${c}: ${p}`)})}t.push(`Content-Type: multipart/mixed; boundary="${a}"`,"");const s=(r,n)=>{const o=B.test(n)?z(n):n,c=B.test(n)?"quoted-printable":"7bit";return[`Content-Type: ${r}; charset=UTF-8`,`Content-Transfer-Encoding: ${c}`,"",...w(o),""]};if(e.text&&e.html){const r=y();t.push(`--${a}`,`Content-Type: multipart/alternative; boundary="${r}"`,"",`--${r}`,...s("text/plain",e.text),`--${r}`,...s("text/html",e.html),`--${r}--`,"")}else e.text?t.push(`--${a}`,...s("text/plain",e.text)):e.html&&t.push(`--${a}`,...s("text/html",e.html));if(e.attachments&&e.attachments.length>0){const r=await Promise.all(e.attachments.map(async n=>{let o;if(n.raw!==void 0)o=n.raw;else{if(n.content===void 0)throw new M("attachment",`Attachment '${n.filename}' must have content, raw, or be resolved from path/href before building MIME message`);o=n.content instanceof Promise?await n.content:n.content}return{...n,resolvedContent:o}}));for(const n of r){t.push(`--${a}`);const o=u(n.contentType??"application/octet-stream"),c=E(n.filename);t.push(`Content-Type: ${o}; name="${c}"`);const p=u(n.contentDisposition??"attachment");t.push(`Content-Disposition: ${p}; filename="${c}"`),n.cid&&t.push(`Content-ID: <${u(n.cid)}>`),n.headers&&Object.entries(n.headers).forEach(([h,x])=>{const A=T(h),S=u(x);t.push(`${A}: ${S}`)});const d=u(n.encoding??"base64");t.push(`Content-Transfer-Encoding: ${d}`,"");const f=n.resolvedContent;if(d==="base64")t.push(C(b(f)));else if(d==="7bit"||d==="8bit"){let h;typeof f=="string"?h=f:R&&f instanceof Buffer?h=f.toString("utf8"):h=new TextDecoder().decode(f),t.push(...w(h))}else t.push(C(b(f)));t.push("")}}return t.push(`--${a}--`),t.join(`\r
|
|
3
3
|
`)};export{U as b};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import w from"./EmailError-
|
|
1
|
+
import w from"./EmailError-SXEFQEyA.js";const C=(u={})=>{const{failureThreshold:c=5,now:s=Date.now,onStateChange:p,resetTimeout:d=3e4}=u;let e="closed",n=0,l=0,t=!1;const i=r=>{e!==r&&(e=r,p?.(r))},a=()=>({error:new w("middleware","Circuit breaker is open",{code:"CIRCUIT_OPEN"}),success:!1});return async(r,h)=>{if(e==="open"&&s()-l>=d&&(i("half-open"),t=!1),e==="open")return a();let f=!1;if(e==="half-open"){if(t)return a();t=!0,f=!0}let o;try{o=await h(r)}finally{f&&(t=!1)}return o.success?(n=0,i("closed"),o):(n+=1,(e==="half-open"||n>=c)&&(l=s(),i("open")),o)}};export{C as circuitBreakerMiddleware};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createTransportDkimSigner as u}from"./DkimSigner-CCxFKitN.js";import i from"./EmailError-
|
|
1
|
+
import{createTransportDkimSigner as u}from"./DkimSigner-CCxFKitN.js";import i from"./EmailError-SXEFQEyA.js";import m from"./RequiredOptionError-C2wWqmiE.js";import{a as f}from"./apply-message-id-nFsQiH5j.js";import{b as p}from"./build-mime-message-D45WdgfP.js";import{v as g}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as v}from"./defineProvider-C9q-7iwt.js";import{c as h,h as y}from"./provider-base-G22b4a87.js";const r="cloudflare-email",I=v((t={})=>{if(typeof t.send!="function")throw new m(r,"send");const c=h(r,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await Promise.resolve()},async isAvailable(){return typeof t.send=="function"},name:r,async sendEmail(e){try{const a=g(e);if(a.length>0)return{error:new i(r,`Invalid email options: ${a.join(", ")}`),success:!1};const o=Array.isArray(e.to)?e.to:[e.to];if(o.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new i(r,"Cloudflare Email supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[n]=o;if(!n)return{error:new i(r,"A single `to` recipient is required"),success:!1};const{headers:l,messageId:d}=f(e);let s=await p({...e,headers:l});return t.dkim&&e.useDkim!==!1&&(s=await u(t.dkim).signMimeMessage(s)),await t.send(e.from.email,n.email,s),{data:{messageId:d,provider:r,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:y(r,"send email",a,c),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{I as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createMail as d}from"./Mail-
|
|
1
|
+
import{createMail as d}from"./Mail-0cxS6jre.js";import w from"./mockProvider-DVtl5Jjy.js";const l=(t,o,e,n)=>{const r=Date.now()+e;return new Promise((i,s)=>{const a=()=>{const c=t.find(m=>o(m));if(c){i(c);return}if(Date.now()>=r){s(new Error("waitFor timed out before a matching message was captured"));return}setTimeout(a,n)};a()})},h=()=>{const t=w(),o=d(t),e=t.getInstance?.();if(!e)throw new Error("mockProvider() did not expose getInstance(); cannot create a test harness");return{mail:o,reset:()=>{e.length=0},sent:()=>e,waitFor:(n,r={})=>l(e,n,r.timeout??1e3,r.interval??10)}};export{h as createTestEmail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const k=c=>1e3*2**(c-1),g=c=>{const{error:t}=c;return typeof t=="object"&&t!==null&&"permanent"in t&&t.permanent===!0},S=c=>{const{backoff:t=k,concurrency:m=1,maxAttempts:p=3,onDeadLetter:y,onError:f,onReserveError:v,pollInterval:h=1e3,queue:a,send:E}=c;let s=!1,o=0,i;const u=async(r,e)=>{try{await e()}catch(n){f?.(r,{error:n instanceof Error?n:new Error(String(n)),success:!1})}},w=async r=>{let e;try{e=await E(r.message)}catch(l){e={error:l instanceof Error?l:new Error(String(l)),success:!1}}if(e.success){await u(r,()=>a.ack(r.id));return}f?.(r,e);const n=r.attempts+1;if(n>=p||g(e)){await u(r,()=>a.ack(r.id)),y?.(r,e);return}await u(r,()=>a.retry(r.id,t(n)))},d=async()=>{if(s){try{for(;o<m;){const r=await a.reserve();if(!r)break;o+=1,w(r).finally(()=>{o-=1}).catch(()=>{})}}catch(r){v?.(r instanceof Error?r:new Error(String(r)))}s&&(i=setTimeout(()=>{d().catch(()=>{})},h))}};return{drain:async()=>{let r=await a.reserve();for(;r;)await w(r),r=await a.reserve()},start:()=>{s||(s=!0,d().catch(()=>{}))},stop:()=>{s=!1,i&&(clearTimeout(i),i=void 0)}}};export{S as createWorker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const E=/\shref\s*=\s*(?:"([^"]*)"|'([^']*)')/i,p=/^\/?([a-z][\da-z]*)/i,h=/https?:\/\/[^\s"'<>]+/gi,u=/&(#x[\da-f]+|#\d+|amp|apos|gt|lt|quot);/gi,A={amp:"&",apos:"'",gt:">",lt:"<",quot:'"'},N=new Set(["a","area"]),x=new Set(["script","style"]),_=1114111,g=".,;:!?)]",l=t=>t.replaceAll(u,(e,s)=>{if(!s.startsWith("#"))return A[s.toLowerCase()]??e;const o=s.charAt(1).toLowerCase()==="x"?Number.parseInt(s.slice(2),16):Number(s.slice(1));return o<=_?String.fromCodePoint(o):e}),R=t=>{let e=t.length;for(;e>0&&g.includes(t.charAt(e-1));)e-=1;return t.slice(0,e)},L=t=>{const e=E.exec(t);return e?e[1]??e[2]??"":void 0},w=(t,e)=>{const s=t.indexOf("-->",e+4);return s===-1?t.length:s+3},I=(t,e,s)=>{const o=t.indexOf(`</${e}`,s),n=o===-1?-1:t.indexOf(">",o);return n===-1?t.length:n+1},C=t=>{const e=t.toLowerCase(),s=[];let o="",n=0;for(;n<t.length;){const c=t.indexOf("<",n);if(c===-1){o+=t.slice(n);break}if(o+=`${t.slice(n,c)} `,t.startsWith("<!--",c)){n=w(t,c);continue}const i=t.indexOf(">",c+1);if(i===-1)break;const r=t.slice(c+1,i),a=p.exec(r)?.[1]?.toLowerCase()??"",f=!r.startsWith("/");n=i+1;const T=f&&N.has(a)?L(r):void 0;T!==void 0&&s.push(T),f&&x.has(a)&&(n=I(e,a,n))}return{hrefs:s,visibleText:o}},d=(t,e)=>{for(const s of e.matchAll(h))t.add(R(s[0]))},O=t=>{const{html:e,text:s}=typeof t=="string"?{text:t}:t,o=new Set;if(e!==void 0){const{hrefs:n,visibleText:c}=C(e);for(const i of n)o.add(l(i));d(o,l(c))}return s!==void 0&&d(o,s),[...o].filter(n=>{try{const{protocol:c}=new URL(n);return c==="http:"||c==="https:"}catch{return!1}})};export{O as default,O as extractLinks};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import g from"./EmailError-
|
|
1
|
+
import g from"./EmailError-SXEFQEyA.js";import w from"./RequiredOptionError-C2wWqmiE.js";import{c as y}from"./create-logger-CazqtXcL.js";import{g as $}from"./generate-message-id-C5AM6DFE.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{a as A}from"./aggregate-features-Bst55u8k.js";const P=r=>typeof r=="function",z=r=>r!==null&&typeof r=="object"&&"sendEmail"in r&&"initialize"in r&&"isAvailable"in r,n="failover",x=E((r={})=>{if(!r.mailers||r.mailers.length===0)throw new w(n,"mailers");const c={debug:r.debug??!1,mailers:r.mailers,retryAfter:r.retryAfter??60};let v=!1;const i=[],s=y(n,r.logger);let m;const p=async()=>m||(m=(async()=>{i.length=0;for(const t of c.mailers)try{let e;if(P(t))e=t({});else if(z(t))e=t;else{s.debug(`Skipping invalid mailer: ${t}`);continue}try{await e.initialize(),i.push(e),s.debug(`Initialized provider: ${e.name??"unknown"}`)}catch(l){s.debug(`Failed to initialize provider ${e.name??"unknown"}:`,l)}}catch(e){s.debug("Error processing mailer:",e)}if(i.length===0)throw new g(n,"No providers could be initialized")})(),m);return{features:A(c.mailers),async initialize(){if(!v)try{await p(),v=!0,s.debug(`Failover provider initialized with ${i.length} provider(s)`)}catch(t){throw new g(n,`Failed to initialize: ${t.message}`,{cause:t})}},async isAvailable(){try{i.length===0&&await p();for(const t of i)try{if(await t.isAvailable())return!0}catch{}return!1}catch{return!1}},name:n,options:c,async sendEmail(t){try{if(i.length===0&&await p(),i.length===0)return{error:new g(n,"No providers available"),success:!1};const e=[];let l;for(let o=0;o<i.length;o+=1){const f=i[o];if(!f)continue;const d=f.name??`provider-${o+1}`;s.debug(`Attempting to send email via ${d} (${o+1}/${i.length})`);try{if(!await f.isAvailable()){s.debug(`Provider ${d} is not available, skipping`),e.push(new g(n,`Provider ${d} is not available`));continue}const a=await f.sendEmail(t);if(a.success&&a.data)return s.debug(`Email sent successfully via ${d}`),{data:{...a.data,messageId:a.data.messageId||$(),provider:`${n}(${d})`},success:!0};if(a.error){l=a.error,e.push(a.error);const b=a.error instanceof Error?a.error.message:String(a.error);s.debug(`Failed to send via ${d}:`,b)}}catch(u){l=u instanceof Error?u:new Error(String(u)),e.push(l);const a=l instanceof Error?l.message:String(l);s.debug(`Exception sending via ${d}:`,a)}o<i.length-1&&c.retryAfter>0&&(s.debug(`Waiting ${c.retryAfter}ms before trying next provider`),await new Promise(u=>{setTimeout(()=>{u()},c.retryAfter)}))}const h=e.map(o=>o instanceof Error?o.message:String(o)).join("; ");return{error:new g(n,`All providers failed. Errors: ${h}`,{cause:l}),success:!1}}catch(e){return{error:new g(n,`Failed to send email: ${e.message}`,{cause:e}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{x as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as w}from"node:module";import d from"./EmailError-SXEFQEyA.js";import S from"./RequiredOptionError-C2wWqmiE.js";import{a as q}from"./apply-message-id-nFsQiH5j.js";import{b as A}from"./build-mime-message-D45WdgfP.js";import{v as P}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as D}from"./defineProvider-C9q-7iwt.js";let y;const v=r=>(y??=w(import.meta.url))(r),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,a=r=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[e,t]=i.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return i.getBuiltinModule(r)}return v(r)},{randomUUID:E}=a("node:crypto"),{constants:M}=a("node:fs"),{mkdir:u,writeFile:b,link:j,rm:T,access:I}=a("node:fs/promises"),{resolve:g,dirname:$,join:R}=a("node:path"),o="file",k=100,x=r=>r.replaceAll(/[<>]/g,"").replaceAll(/[^\w.@+-]/g,"_").slice(0,k),z=D(r=>{if(!r?.directory)throw new S(o,"directory");const e=g(r.directory);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await u(e,{recursive:!0})},async isAvailable(){try{return await u(e,{recursive:!0}),await I(e,M.W_OK),!0}catch{return!1}},name:o,options:r,async sendEmail(t){const m=P(t);if(m.length>0)return{error:new d(o,`Invalid email options: ${m.join(", ")}`),success:!1};const{headers:_,messageId:f}=q(t),p=new Date,n=`${String(p.getTime())}-${x(f)}.eml`,c=g(e,n);if($(c)!==e)return{error:new d(o,"Message-ID resolves outside the output directory"),success:!1};const l=R(e,`.${n}.${E()}.tmp`);try{const s=await A({...t,headers:_},{includeBcc:!0});await u(e,{recursive:!0}),await b(l,s,{encoding:"utf8",flag:"wx",mode:384}),await j(l,c)}catch(s){const h=s instanceof Error&&"code"in s&&s.code==="EEXIST"?"a file with this name already exists":String(s);return{error:new d(o,`Failed to write ${n}: ${h}`),success:!1}}finally{await T(l,{force:!0})}return{data:{messageId:f,provider:o,response:{path:c},sent:!0,timestamp:p},success:!0}}}});export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./EmailError-
|
|
1
|
+
import c from"./EmailError-SXEFQEyA.js";import p from"./RequiredOptionError-C2wWqmiE.js";import{g as w}from"./generate-message-id-C5AM6DFE.js";import{m}from"./make-request-mszP240P.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as v}from"./defineProvider-C9q-7iwt.js";const o="http",A="POST",l=3e4,M=v((n={})=>{if(!n.endpoint)throw new p(o,"endpoint");const a={apiKey:n.apiKey??"",endpoint:n.endpoint,headers:n.headers??{},method:n.method??A},i=()=>{const e={"Content-Type":"application/json",...a.headers};return a.apiKey&&(e.Authorization=`Bearer ${a.apiKey}`),e},h=e=>{const t={from:e.from.email,from_name:e.from.name,html:e.html,subject:e.subject,text:e.text,to:Array.isArray(e.to)?e.to.map(r=>r.email):e.to.email};return e.cc&&(t.cc=Array.isArray(e.cc)?e.cc.map(r=>r.email):e.cc.email),e.bcc&&(t.bcc=Array.isArray(e.bcc)?e.bcc.map(r=>r.email):e.bcc.email),e.customParams&&Object.assign(t,e.customParams),t};let u=!1;return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!u){if(!await this.isAvailable())throw new c(o,"API endpoint not available");u=!0}},async isAvailable(){try{const e=await m(a.endpoint,{headers:i(),method:"OPTIONS",timeout:l});if(e.success)return!0;const t=e.data?.statusCode;return!1}catch(e){if(e instanceof Error){const t=e.message;if(t.includes("401")||t.includes("403"))return!1}return!1}},name:o,options:a,async sendEmail(e){try{const t=E(e);if(t.length>0)return{error:new c(o,`Invalid email options: ${t.join(", ")}`),success:!1};u||await this.initialize();const r=i();e.headers&&Object.assign(r,e.headers);const y=h(e),g=e.endpointOverride??a.endpoint,b=e.methodOverride??a.method,d=await m(g,{headers:r,method:b,timeout:l},JSON.stringify(y));if(!d.success)return{error:new c(o,`Failed to send email: ${d.error?.message||"Unknown error"}`,{cause:d.error}),success:!1};let f;const s=d.data?.body;return s&&typeof s=="object"&&(f=s.id??s.messageId??(s.data&&typeof s.data=="object"&&(s.data.id??s.data.messageId))),f??=w(),{data:{messageId:f,provider:o,response:d.data?.body,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new c(o,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){try{const e=await m(a.endpoint,{headers:i(),method:"GET",timeout:l});return!!(e.data&&typeof e.data=="object"&&"statusCode"in e.data&&typeof e.data.statusCode=="number"&&e.data.statusCode>=200&&e.data.statusCode<300)}catch{return!1}}}});export{M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-
|
|
1
|
+
import d from"./EmailError-SXEFQEyA.js";import v from"./RequiredOptionError-C2wWqmiE.js";import{g as A}from"./generate-message-id-C5AM6DFE.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as u}from"./make-request-mszP240P.js";import{r as y}from"./retry-ByPJFAtq.js";import{v as I}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as T,P,h}from"./provider-base-G22b4a87.js";import{d as m}from"./address-formatter-w36S9ZYj.js";import{p as U}from"./attachment-processor-AB1m-n9T.js";const t="infobip",R="https://api.infobip.com",z=3e4,k=3,V=w((i={})=>{if(!i.apiKey)throw new v(t,"apiKey");const f=i.baseUrl??R,g=i.endpoint??`${f}/email/3/send`,a={apiKey:i.apiKey,baseUrl:f,debug:i.debug??!1,endpoint:g,retries:i.retries??k,timeout:i.timeout??z,...i.logger&&{logger:i.logger}},l=new P,s=T(t,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const o={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};s.debug("Retrieving email details",{id:e});const r=await y(async()=>u(`${a.baseUrl}/email/3/reports/${e}`,{headers:o,method:"GET",timeout:a.timeout}),a.retries);return r.success?(s.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(s.debug("API request failed when retrieving email",r.error),{error:new d(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,s),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(t,"Infobip API not available or invalid API key");s.debug("Provider initialized successfully")},t)},async isAvailable(){try{s.debug("Checking Infobip API availability");const e={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"};return(await u(`${a.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:a.timeout})).success}catch(e){return s.debug("Error checking availability:",e),!1}},name:t,options:a,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new d(t,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateData=e.templateVariables)),e.trackingUrl&&(r.trackingUrl=e.trackingUrl),e.notifyUrl&&(r.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(r.intermediateReport=e.intermediateReport),e.sendAt&&(r.sendAt=e.sendAt),e.headers){const c=E(e.headers);r.headers=c}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async c=>({content:await U(c,t),contentType:c.contentType??"application/octet-stream",name:c.filename})))),s.debug("Sending email via Infobip API",{subject:r.subject,to:r.to});const b={Authorization:`App ${a.apiKey}`,"Content-Type":"application/json"},n=await y(async()=>u(a.endpoint,{headers:b,method:"POST",timeout:a.timeout},JSON.stringify(r)),a.retries);if(!n.success)return s.debug("API request failed when sending email",n.error),{error:n.error??new d(t,"Failed to send email"),success:!1};const p=n.data?.body?.messages?.[0]?.messageId??A();return s.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:t,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,s),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
|
package/dist/packem_shared/{isValidSigningCertUrl-CK1t2a7x.js → isValidSigningCertUrl-gnYr3oyD.js}
RENAMED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{createRequire as g}from"node:module";import o from"./EmailError-
|
|
1
|
+
import{createRequire as g}from"node:module";import o from"./EmailError-SXEFQEyA.js";let p;const d=e=>(p??=g(import.meta.url))(e),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[t,r]=s.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return s.getBuiltinModule(e)}return d(e)},{Buffer:S}=u("node:buffer"),{X509Certificate:m,createVerify:T}=u("node:crypto"),_={Notification:["Message","MessageId","Subject","Timestamp","TopicArn","Type"],SubscriptionConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"],UnsubscribeConfirmation:["Message","MessageId","SubscribeURL","Timestamp","Token","TopicArn","Type"]},y=/^sns\.[a-z0-9-]+\.amazonaws\.com(?:\.cn)?$/,b=/\.$/,h=e=>{let t;try{t=new URL(e)}catch{return!1}if(t.protocol!=="https:"||t.username!==""||t.password!==""||t.port!=="")return!1;const r=t.hostname.toLowerCase().replace(b,"");return y.test(r)},w=async e=>{if(!h(e))throw new o("webhooks",`Refusing to fetch SNS signing certificate from untrusted URL: ${e}`);const t=await fetch(e,{signal:AbortSignal.timeout(5e3)});if(!t.ok)throw new o("webhooks",`Failed to fetch SNS signing certificate (status ${String(t.status)})`);return await t.text()},v=e=>{const t=_[e.Type??""];if(!t)return;let r="";for(const i of t){const n=e[i];typeof n=="string"&&(r+=`${i}
|
|
2
2
|
${n}
|
|
3
3
|
`)}return r},N=async(e,t={})=>{const{certificateResolver:r=w}=t;if(!e.Signature||!e.SigningCertURL)return{reason:"missing-signature",valid:!1};const i=v(e);if(i===void 0)return{reason:"unknown-message-type",valid:!1};let n;if(e.SignatureVersion==="1")n="RSA-SHA1";else if(e.SignatureVersion==="2")n="RSA-SHA256";else return{reason:"unknown-signature-version",valid:!1};const f=await r(e.SigningCertURL);let a;try{a=new m(f).publicKey}catch(l){throw new o("webhooks","Failed to parse SNS signing certificate",{cause:l})}let c;try{c=T(n).update(i,"utf8").verify(a,S.from(e.Signature,"base64"))}catch{return{reason:"signature-malformed",valid:!1}}return c?{valid:!0}:{reason:"signature-mismatch",valid:!1}};export{h as isValidSigningCertUrl,N as verifySnsMessage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import n from"./EmailError-
|
|
1
|
+
import n from"./EmailError-SXEFQEyA.js";import f from"./RequiredOptionError-C2wWqmiE.js";import{g as y}from"./generate-message-id-C5AM6DFE.js";import{m as h}from"./make-request-mszP240P.js";import{r as g}from"./retry-ByPJFAtq.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{c as E,h as I,P as v}from"./provider-base-G22b4a87.js";import{c as A}from"./attachment-processor-AB1m-n9T.js";const t="loops",w="https://app.loops.so/api/v1/transactional",b=3e4,P=3,U=T((r={})=>{if(!r.apiKey)throw new f(t,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,defaultTransactionalId:r.defaultTransactionalId,endpoint:r.endpoint??w,logger:r.logger,retries:r.retries??P,timeout:r.timeout??b},u=new v,p=E(t,r.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!1,html:!1,replyTo:!1,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async initialize(){u.setInitialized()},async isAvailable(){return a.apiKey.length>0},name:t,options:a,async sendEmail(e){try{const s=e.transactionalId??a.defaultTransactionalId;if(!s)return{error:new n(t,"Loops requires a `transactionalId` (on the message or as `defaultTransactionalId`)"),success:!1};const d=Array.isArray(e.to)?e.to:[e.to];if(d.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new n(t,"Loops supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[l]=d;if(!l)return{error:new n(t,"A `to` recipient is required"),success:!1};const o={email:l.email,transactionalId:s};e.dataVariables&&(o.dataVariables=e.dataVariables),e.addToAudience&&(o.addToAudience=!0),e.attachments&&e.attachments.length>0&&(o.attachments=await Promise.all(e.attachments.map(async m=>{const c=await A(m,t);return{contentType:c.contentType,data:c.content,filename:c.filename}})));const i=await g(async()=>h(a.endpoint,{headers:{Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},method:"POST",timeout:a.timeout},JSON.stringify(o)),a.retries);return i.success?{data:{messageId:y(),provider:t,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new n(t,"Failed to send email"),success:!1}}catch(s){return{error:I(t,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import o from"./smtpProvider-
|
|
1
|
+
import{defineProvider as l}from"./defineProvider-C9q-7iwt.js";import o from"./smtpProvider-BPamDNuv.js";const a="mailcrab",u="localhost",n=1025,m=l((t={})=>{const e={debug:t.debug??!1,host:t.host??u,logger:t.logger,port:t.port??n,retries:t.retries,secure:t.secure??!1,timeout:t.timeout},r=o({debug:e.debug,host:e.host,logger:e.logger,port:e.port,retries:e.retries,secure:e.secure,timeout:e.timeout});return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await r.initialize()},async isAvailable(){return r.isAvailable()},name:a,options:e,async sendEmail(i){const s=await r.sendEmail(i);return s.success&&s.data?{data:{...s.data,provider:a},success:!0}:s},async validateCredentials(){return r.validateCredentials?.()??!1}}});export{m as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./EmailError-
|
|
1
|
+
import c from"./EmailError-SXEFQEyA.js";import T from"./RequiredOptionError-C2wWqmiE.js";import{g as P}from"./generate-message-id-C5AM6DFE.js";import{h as w}from"./headers-to-record-ZOZ7Dubo.js";import{m as u}from"./make-request-mszP240P.js";import{r as h}from"./retry-ByPJFAtq.js";import{s as I,a as A}from"./sanitize-header-CW0f3IT7.js";import{v as k}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as z}from"./defineProvider-C9q-7iwt.js";import{c as j,P as C,h as g}from"./provider-base-G22b4a87.js";import{j as l,g as b}from"./address-formatter-w36S9ZYj.js";const a="mailpace",R="https://app.mailpace.com/api/v1",$=3e4,M=3,G=z((o={})=>{if(!o.apiToken)throw new T(a,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??R,retries:o.retries??M,timeout:o.timeout??$,...o.logger&&{logger:o.logger}},d=new C,i=j(a,o.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const t={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await h(async()=>u(`${s.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new c(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:g(a,"retrieve email",t,i),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const t=await u(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=k(e);if(t.length>0)return{error:new c(a,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),a);const r={from:b(e.from),subject:e.subject,to:l(e.to)};if(e.html&&(r.htmlbody=e.html),e.text&&(r.textbody=e.text),e.cc&&(r.cc=l(e.cc)),e.bcc&&(r.bcc=l(e.bcc)),e.replyTo&&(r.replyto=b(e.replyTo)),e.templateId&&(r.template_id=e.templateId,e.templateVariables&&(r.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.listUnsubscribe&&(r.list_unsubscribe=e.listUnsubscribe),e.headers){const y=w(e.headers),f={};Object.entries(y).forEach(([v,E])=>{f[I(v)]=A(E)}),r.headers=f}e.attachments&&e.attachments.length>0&&(r.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:r.subject,to:r.to});const p={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},n=await h(async()=>u(`${s.endpoint}/send`,{headers:p,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new c(a,"Failed to send email"),success:!1};const m=n.data?.body?.id??P();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:a,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:g(a,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
|
package/dist/packem_shared/{mailchannelsProvider-Dn24mI8D.js → mailchannelsProvider-CPVW3wlH.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"./EmailError-
|
|
1
|
+
import u from"./EmailError-SXEFQEyA.js";import g from"./RequiredOptionError-C2wWqmiE.js";import{g as v}from"./generate-message-id-C5AM6DFE.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as T}from"./make-request-mszP240P.js";import{r as b}from"./retry-ByPJFAtq.js";import{v as A}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{c as w,h as I,P as S}from"./provider-base-G22b4a87.js";import{f as l,a as f}from"./address-formatter-w36S9ZYj.js";import{c as K}from"./attachment-processor-AB1m-n9T.js";const r="mailchannels",R="https://api.mailchannels.net/tx/v1/send",_=3e4,x=3,H=P((t={})=>{if(!t.apiKey)throw new g(r,"apiKey");const a={apiKey:t.apiKey,debug:t.debug??!1,endpoint:t.endpoint??R,logger:t.logger,retries:t.retries??x,timeout:t.timeout??_},h=new S,p=w(r,t.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){h.setInitialized()},async isAvailable(){return a.apiKey.length>0},name:r,options:a,async sendEmail(e){try{const s=A(e);if(s.length>0)return{error:new u(r,`Invalid email options: ${s.join(", ")}`),success:!1};const c=[];e.text&&c.push({type:"text/plain",value:e.text}),e.html&&c.push({type:"text/html",value:e.html});const i={to:l(e.to)};e.cc&&(i.cc=l(e.cc)),e.bcc&&(i.bcc=l(e.bcc));const n={content:c,from:f(e.from),personalizations:[i],subject:e.subject};e.replyTo&&(n.reply_to=f(e.replyTo)),e.headers&&(n.headers=E(e.headers)),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async y=>{const d=await K(y,r);return{content:d.content,filename:d.filename,type:d.contentType}})));const o=await b(async()=>T(a.endpoint,{headers:{"Content-Type":"application/json","X-Api-Key":a.apiKey},method:"POST",timeout:a.timeout},JSON.stringify(n)),a.retries);if(!o.success)return{error:o.error??new u(r,"Failed to send email"),success:!1};const{body:m}=o.data;return{data:{messageId:m?.message_id??m?.request_id??v(),provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(s){return{error:I(r,"send email",s,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
|
package/dist/packem_shared/{mailerSendProvider-B6X4Lhsf.js → mailerSendProvider-B2H6BtoV.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import c from"./EmailError-
|
|
1
|
+
import c from"./EmailError-SXEFQEyA.js";import p from"./RequiredOptionError-C2wWqmiE.js";import{g as v}from"./generate-message-id-C5AM6DFE.js";import{h as b}from"./headers-to-record-ZOZ7Dubo.js";import{m as l}from"./make-request-mszP240P.js";import{r as g}from"./retry-ByPJFAtq.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{c as w,P as A,h}from"./provider-base-G22b4a87.js";import{f as m,a as I}from"./address-formatter-w36S9ZYj.js";import{p as P}from"./attachment-processor-AB1m-n9T.js";const a="mailersend",k="https://api.mailersend.com",z=3e4,S=3,L=E((i={})=>{if(!i.apiToken)throw new p(a,"apiToken");const s={apiToken:i.apiToken,debug:i.debug??!1,endpoint:i.endpoint??k,retries:i.retries??S,timeout:i.timeout??z,...i.logger&&{logger:i.logger}},u=new A,o=w(a,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const r=await g(async()=>l(`${s.endpoint}/v1/activity/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(o.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(o.debug("API request failed when retrieving email",r.error),{error:new c(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:h(a,"retrieve email",t,o),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"MailerSend API not available or invalid API token");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};o.debug("Checking MailerSend API availability");const t=await l(`${s.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:s.timeout});return o.debug("MailerSend API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new c(a,`Invalid email options: ${t.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.reply_to=I(e.replyTo)),e.templateId&&(r.template_id=e.templateId,e.templateVariables&&(r.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(r.personalization=e.personalization),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.scheduledAt&&(r.send_at=e.scheduledAt),e.domainId&&(r.domain_id=e.domainId),e.headers){const n=b(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,a),filename:n.filename,...n.contentType&&{type:n.contentType},...n.cid&&{id:n.cid}})))),o.debug("Sending email via MailerSend API",{subject:r.subject,to:r.to});const y={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},d=await g(async()=>l(`${s.endpoint}/v1/email`,{headers:y,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!d.success)return o.debug("API request failed when sending email",d.error),{error:d.error??new c(a,"Failed to send email"),success:!1};const f=d.data?.body?.message_id??v();return o.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:h(a,"send email",t,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as j}from"node:module";import f from"./EmailError-
|
|
1
|
+
import{createRequire as j}from"node:module";import f from"./EmailError-SXEFQEyA.js";import w from"./RequiredOptionError-C2wWqmiE.js";import{g as P}from"./generate-message-id-C5AM6DFE.js";import{h as _}from"./headers-to-record-ZOZ7Dubo.js";import{m as p}from"./make-request-mszP240P.js";import{r as I}from"./retry-ByPJFAtq.js";import{v as C}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as D}from"./defineProvider-C9q-7iwt.js";import{c as S,P as U,h as k}from"./provider-base-G22b4a87.js";import{e as v,g as E}from"./address-formatter-w36S9ZYj.js";import{a as q}from"./attachment-processor-AB1m-n9T.js";let $;const A=o=>($??=j(import.meta.url))(o),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,n]=m.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return m.getBuiltinModule(o)}return A(o)},{Buffer:y}=R("node:buffer"),s="mailgun",M="https://api.mailgun.net",z=3e4,B=3,K=o=>{const r=[];for(const[n,a]of Object.entries(o))if(a!=null)if(Array.isArray(a))for(const e of a)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof a=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(a))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(a))}`);return r.join("&")},O=D((o={})=>{if(!o.apiKey)throw new w(s,"apiKey");if(!o.domain)throw new w(s,"domain");const r={apiKey:o.apiKey,debug:o.debug??!1,domain:o.domain,endpoint:o.endpoint??M,retries:o.retries??B,timeout:o.timeout??z,...o.logger&&{logger:o.logger}},n=new U,a=S(s,o.logger);return{endpoint:r.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new f(s,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};a.debug("Retrieving email details",{id:e});const i=await I(async()=>p(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);if(!i.success)return a.debug("API request failed when retrieving email",i.error),{error:new f(s,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1};a.debug("Email details retrieved successfully");const g=i.data?.items??[],u=g.length>0?g[0]:void 0;return{data:u?.message?.headers??u?.storage??void 0,success:!0}}catch(c){return{error:k(s,"retrieve email",c,a),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new f(s,"Mailgun API not available or invalid API key/domain");a.debug("Provider initialized successfully")},s)},async isAvailable(){try{const c={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};a.debug("Checking Mailgun API availability");const t=await p(`${r.endpoint}/v3/domains/${r.domain}`,{headers:c,method:"GET",timeout:r.timeout});if(a.debug("Mailgun API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!t.success||!t.data||typeof t.data!="object")return!1;const{statusCode:i}=t.data;return typeof i=="number"&&i>=200&&i<300}catch(e){return a.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const c=C(e);if(c.length>0)return{error:new f(s,`Invalid email options: ${c.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={from:E(e.from),to:v(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=v(e.cc).join(",")),e.bcc&&(t.bcc=v(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=E(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[l,d]of Object.entries(e.templateVariables))t[`v:${l}`]=d;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const l=_(e.headers);for(const[d,h]of Object.entries(l))t[`h:${d}`]=h}if(e.attachments&&e.attachments.length>0){const l=await Promise.all(e.attachments.map((d,h)=>q(d,s,h)));for(const d of l)t[d.key]=d.content}a.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const b={Authorization:`Basic ${y.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=K(t),u=await I(async()=>p(`${r.endpoint}/v3/${r.domain}/messages`,{headers:b,method:"POST",timeout:r.timeout},g),r.retries);if(!u.success)return a.debug("API request failed when sending email",u.error),{error:u.error??new f(s,"Failed to send email"),success:!1};const T=u.data?.body?.id??P();return a.debug("Email sent successfully",{messageId:T}),{data:{messageId:T,provider:s,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:k(s,"send email",c,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as S}from"node:module";import g from"./EmailError-
|
|
1
|
+
import{createRequire as S}from"node:module";import g from"./EmailError-SXEFQEyA.js";import v from"./RequiredOptionError-C2wWqmiE.js";import{g as _}from"./generate-message-id-C5AM6DFE.js";import{h as R}from"./headers-to-record-ZOZ7Dubo.js";import{m as p}from"./make-request-mszP240P.js";import{r as b}from"./retry-ByPJFAtq.js";import{v as M}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as $}from"./defineProvider-C9q-7iwt.js";import{c as D,P as B,h as T}from"./provider-base-G22b4a87.js";import{h as y,i as E}from"./address-formatter-w36S9ZYj.js";import{p as z}from"./attachment-processor-AB1m-n9T.js";let P;const C=a=>(P??=S(import.meta.url))(a),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,A=a=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[r,u]=l.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return l.getBuiltinModule(a)}return C(a)},{Buffer:f}=A("node:buffer"),s="mailjet",q="https://api.mailjet.com",L=3e4,k=3,O=$((a={})=>{if(!a.apiKey)throw new v(s,"apiKey");if(!a.apiSecret)throw new v(s,"apiSecret");const r={apiKey:a.apiKey,apiSecret:a.apiSecret,debug:a.debug??!1,endpoint:a.endpoint??q,retries:a.retries??k,timeout:a.timeout??L,...a.logger&&{logger:a.logger}},u=new B,i=D(s,a.logger);return{endpoint:r.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new g(s,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const n=await b(async()=>p(`${r.endpoint}/v3.1/REST/message/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return n.success?(i.debug("Email details retrieved successfully"),{data:n.data?.body,success:!0}):(i.debug("API request failed when retrieving email",n.error),{error:new g(s,`Failed to retrieve email: ${n.error instanceof Error?n.error.message:"Unknown error"}`,{cause:n.error}),success:!1})}catch(o){return{error:T(s,"retrieve email",o,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new g(s,"Mailjet API not available or invalid API credentials");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{const o={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};i.debug("Checking Mailjet API availability");const t=await p(`${r.endpoint}/v3.1/REST/user`,{headers:o,method:"GET",timeout:r.timeout});return i.debug("Mailjet API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=M(e);if(o.length>0)return{error:new g(s,`Invalid email options: ${o.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const t={From:E(e.from),Subject:e.subject,To:y(e.to)};if(e.html&&(t.HTMLPart=e.html),e.text&&(t.TextPart=e.text),e.cc&&(t.Cc=y(e.cc)),e.bcc&&(t.Bcc=y(e.bcc)),e.replyTo&&(t.ReplyTo=E(e.replyTo)),e.templateId&&(t.TemplateID=e.templateId,t.TemplateLanguage=e.templateLanguage??!0,e.templateVariables&&(t.Variables=e.templateVariables)),e.customId&&(t.CustomID=e.customId),e.eventPayload&&(t.EventPayload=e.eventPayload),e.campaign&&(t.Campaign=e.campaign),e.deduplicateCampaign!==void 0&&(t.DeduplicateCampaign=e.deduplicateCampaign),e.deliveryTime&&(t.Deliverytime=new Date(e.deliveryTime*1e3).toISOString()),e.priority!==void 0&&(t.Priority=e.priority),e.urlTags&&(t.URLTags=e.urlTags),e.tags&&e.tags.length>0&&(t.CustomCampaign=e.tags.join(",")),e.headers){const c=R(e.headers),m=[];for(const[j,w]of Object.entries(c))m.push({Name:j,Value:String(w)});m.length>0&&(t.Headers=m)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async c=>({Base64Content:await z(c,s),ContentType:c.contentType??"application/octet-stream",Filename:c.filename,...c.cid&&{ContentID:c.cid}}))));const n={Messages:[t]};i.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const I={Authorization:`Basic ${f.from(`${r.apiKey}:${r.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},d=await b(async()=>p(`${r.endpoint}/v3.1/send`,{headers:I,method:"POST",timeout:r.timeout},JSON.stringify(n)),r.retries);if(!d.success)return i.debug("API request failed when sending email",d.error),{error:d.error??new g(s,"Failed to send email"),success:!1};const h=d.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??_();return i.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:T(s,"send email",o,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{O as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-
|
|
1
|
+
import d from"./EmailError-SXEFQEyA.js";import b from"./RequiredOptionError-C2wWqmiE.js";import{g as v}from"./generate-message-id-C5AM6DFE.js";import{h as E}from"./headers-to-record-ZOZ7Dubo.js";import{m as g}from"./make-request-mszP240P.js";import{r as y}from"./retry-ByPJFAtq.js";import{v as I}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as P,P as A,h}from"./provider-base-G22b4a87.js";import{f as u,a as T}from"./address-formatter-w36S9ZYj.js";import{p as R}from"./attachment-processor-AB1m-n9T.js";const t="mailomat",S="https://api.mailomat.com",K=3e4,j=3,V=w((s={})=>{if(!s.apiKey)throw new b(t,"apiKey");const i={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??S,retries:s.retries??j,timeout:s.timeout??K,...s.logger&&{logger:s.logger}},l=new A,a=P(t,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const o={"Content-Type":"application/json","X-API-Key":i.apiKey};a.debug("Retrieving email details",{id:e});const r=await y(async()=>g(`${i.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:i.timeout}),i.retries);return r.success?(a.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(a.debug("API request failed when retrieving email",r.error),{error:new d(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,a),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(t,"Mailomat API not available or invalid API key");a.debug("Provider initialized successfully")},t)},async isAvailable(){try{return a.debug("Checking Mailomat API availability"),!0}catch(e){return a.debug("Error checking availability:",e),!1}},name:t,options:i,async sendEmail(e){try{const o=I(e);if(o.length>0)return{error:new d(t,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=u(e.cc)),e.bcc&&(r.bcc=u(e.bcc)),e.replyTo&&(r.replyTo=T(e.replyTo)),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.headers){const n=E(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await R(n,t),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),a.debug("Sending email via Mailomat API",{subject:r.subject,to:r.to});const p={"Content-Type":"application/json","X-API-Key":i.apiKey},c=await y(async()=>g(`${i.endpoint}/send`,{headers:p,method:"POST",timeout:i.timeout},JSON.stringify(r)),i.retries);if(!c.success)return a.debug("API request failed when sending email",c.error),{error:c.error??new d(t,"Failed to send email"),success:!1};const m=c.data?.body,f=m?.messageId??m?.id??v();return a.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:t,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-
|
|
1
|
+
import d from"./EmailError-SXEFQEyA.js";import y from"./RequiredOptionError-C2wWqmiE.js";import{g as b}from"./generate-message-id-C5AM6DFE.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{m as l}from"./make-request-mszP240P.js";import{r as p}from"./retry-ByPJFAtq.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as E}from"./defineProvider-C9q-7iwt.js";import{c as w,P as A,h as g}from"./provider-base-G22b4a87.js";import{f as m,a as I}from"./address-formatter-w36S9ZYj.js";import{p as P}from"./attachment-processor-AB1m-n9T.js";const a="mailtrap",k="https://send.api.mailtrap.io",C=3e4,j=3,L=E((o={})=>{if(!o.apiToken)throw new y(a,"apiToken");const s={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??k,retries:o.retries??j,timeout:o.timeout??C,...o.logger&&{logger:o.logger}},u=new A,i=w(a,o.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(a,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const t={"Api-Token":s.apiToken,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await p(async()=>l(`${s.endpoint}/api/send/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new d(a,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:g(a,"retrieve email",t,i),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(a,"Mailtrap API not available or invalid API token");i.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"Api-Token":s.apiToken,"Content-Type":"application/json"};i.debug("Checking Mailtrap API availability");const t=await l(`${s.endpoint}/api/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("Mailtrap API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new d(a,`Invalid email options: ${t.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),a);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:m(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=m(e.cc)),e.bcc&&(r.bcc=m(e.bcc)),e.replyTo&&(r.reply_to=I(e.replyTo)),e.templateUuid&&(r.template_uuid=e.templateUuid,e.templateVariables&&(r.template_variables=e.templateVariables)),e.category&&(r.category=e.category),e.customVariables&&(r.custom_variables=e.customVariables),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.headers){const n=v(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await P(n,a),filename:n.filename,type:n.contentType??"application/octet-stream",...n.cid&&{cid:n.cid}})))),i.debug("Sending email via Mailtrap API",{subject:r.subject,to:r.to});const h={"Api-Token":s.apiToken,"Content-Type":"application/json"},c=await p(async()=>l(`${s.endpoint}/api/send`,{headers:h,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new d(a,"Failed to send email"),success:!1};const f=c.data?.body?.message_ids?.[0]??b();return i.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:a,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:g(a,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import f from"./EmailError-SXEFQEyA.js";const y=globalThis.Buffer!==void 0,w=new Set([408,409,429]),S="ETIMEDOUT",b=s=>s>=400&&s<500&&!w.has(s),p=async(s,o={},t)=>{const m=typeof s=="string"?new URL(s):s;try{const r=new Headers;o.headers&&Object.entries(o.headers).forEach(([e,u])=>{r.set(e,u)});const n={headers:r,method:o.method??(t?"POST":"GET")};t&&(typeof t=="string"||t instanceof Uint8Array?n.body=t:y&&t instanceof globalThis.Buffer?n.body=new Uint8Array(t):n.body=new Uint8Array(t));let a,c;o.timeout&&(a=new AbortController,c=setTimeout(()=>{a?.abort()},o.timeout),n.signal=a.signal);try{const e=await fetch(m.toString(),n);c&&clearTimeout(c);const d=(e.headers.get("content-type")??"").includes("application/json");let i;if(d)try{i=await e.json()}catch{i=await e.text()}else i=await e.text();const h=e.status>=200&&e.status<300,l={};return e.headers.forEach((E,T)=>{l[T]=E}),{data:{body:i,headers:l,statusCode:e.status},error:h?void 0:new f("http",`Request failed with status ${String(e.status)}`,{code:e.status.toString(),permanent:b(e.status)}),success:h}}catch(e){if(c&&clearTimeout(c),e instanceof Error&&e.name==="AbortError")return{error:new f("http",`Request timed out after ${o.timeout}ms`,{code:S}),success:!1};throw e}}catch(r){return{error:new f("http",`Request failed: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))}),success:!1}}};export{S as R,p as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"./EmailError-
|
|
1
|
+
import u from"./EmailError-SXEFQEyA.js";import T from"./RequiredOptionError-C2wWqmiE.js";import{g as w}from"./generate-message-id-C5AM6DFE.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m as g}from"./make-request-mszP240P.js";import{r as h}from"./retry-ByPJFAtq.js";import{a as b,s as I}from"./sanitize-header-CW0f3IT7.js";import{v as _}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as C}from"./defineProvider-C9q-7iwt.js";import{c as j,P as k,h as p}from"./provider-base-G22b4a87.js";import{k as y}from"./address-formatter-w36S9ZYj.js";import{p as S}from"./attachment-processor-AB1m-n9T.js";const t="mandrill",z="https://mandrillapp.com/api/1.0",M=3e4,R=3,G=C((i={})=>{if(!i.apiKey)throw new T(t,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??z,retries:i.retries??R,timeout:i.timeout??M,...i.logger&&{logger:i.logger}},m=new k,o=j(t,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new u(t,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),t),o.debug("Retrieving email details",{id:e});const c={id:e,key:s.apiKey},r={"Content-Type":"application/json"},n=await h(async()=>g(`${s.endpoint}/messages/info.json`,{headers:r,method:"POST",timeout:s.timeout},JSON.stringify(c)),s.retries);return n.success?(o.debug("Email details retrieved successfully"),{data:n.data?.body,success:!0}):(o.debug("API request failed when retrieving email",n.error),{error:new u(t,`Failed to retrieve email: ${n.error instanceof Error?n.error.message:"Unknown error"}`,{cause:n.error}),success:!1})}catch(c){return{error:p(t,"retrieve email",c,o),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(t,"Mandrill API not available or invalid API key");o.debug("Provider initialized successfully")},t)},async isAvailable(){try{o.debug("Checking Mandrill API availability");const e={key:s.apiKey},c={"Content-Type":"application/json"},r=await g(`${s.endpoint}/users/info.json`,{headers:c,method:"POST",timeout:s.timeout},JSON.stringify(e));return o.debug("Mandrill API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:t,options:s,async sendEmail(e){try{const c=_(e);if(c.length>0)return{error:new u(t,`Invalid email options: ${c.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),t);const r={from_email:e.from.email,html:e.html??"",subject:e.subject,text:e.text??"",...e.from.name&&{from_name:e.from.name},to:y(e.to,"to")};if(e.cc){const a=y(e.cc,"cc");for(const d of a)d.type="cc";r.to=[...r.to,...a]}if(e.bcc){const a=y(e.bcc,"bcc");for(const d of a)d.type="bcc";r.to=[...r.to,...a]}if(e.replyTo){const a=e.replyTo.name?`${b(e.replyTo.name)} <${e.replyTo.email}>`:e.replyTo.email;r.headers={"Reply-To":a}}if(e.headers){const a=P(e.headers),d={};Object.entries(a).forEach(([A,E])=>{d[I(A)]=b(E)}),r.headers={...r.headers,...d}}e.tags&&e.tags.length>0&&(r.tags=e.tags),e.metadata&&(r.metadata=e.metadata),(e.googleAnalyticsDomains||e.googleAnalyticsCampaign)&&(r.google_analytics_domains=e.googleAnalyticsDomains,r.google_analytics_campaign=e.googleAnalyticsCampaign),e.subaccount&&(r.subaccount=e.subaccount),e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async a=>({content:await S(a,t),name:a.filename,type:a.contentType??"application/octet-stream"}))));const n={key:s.apiKey,message:r};e.templateName&&(n.template_name=e.templateName,e.templateContent&&(n.template_content=e.templateContent),e.templateVariables&&(n.template_vars=e.templateVariables)),e.globalMergeVars&&(r.global_merge_vars=e.globalMergeVars),e.mergeVars&&(r.merge_vars=e.mergeVars),e.sendAt&&(n.send_at=e.sendAt),o.debug("Sending email via Mandrill API",{subject:r.subject,to:r.to});const v={"Content-Type":"application/json"},l=await h(async()=>g(`${s.endpoint}/messages/send.json`,{headers:v,method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new u(t,"Failed to send email"),success:!1};const f=l.data?.body?.[0]?.id??w();return o.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:t,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:p(t,"send email",c,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-
|
|
1
|
+
import d from"./EmailError-SXEFQEyA.js";import{c as I}from"./create-logger-CazqtXcL.js";import{g as D}from"./generate-message-id-C5AM6DFE.js";import{v as A}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as x}from"./defineProvider-C9q-7iwt.js";const i="mock",p=new Map,M=()=>({debug:!1,delay:0,failureRate:0,randomDelayRange:{max:0,min:0},retries:0,simulateFailure:!1,timeout:0}),j=x((f={})=>{const g=`mock-${Date.now()}-${Math.random().toString(36).slice(2,9)}`;p.has(g)||p.set(g,[]);const r=p.get(g);if(!r)throw new Error(`Storage not found for instance: ${g}`);let y=!1,m;const s={...M(),defaultResponse:f.defaultResponse,logger:f.logger,randomDelayRange:f.randomDelayRange??{max:0,min:0},...f},a=I(i,s.logger);return{clearSentMessages(){r.length=0,a.debug("Cleared all sent messages")},features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!1,tracking:!1},findMessageBy(e){return r.find(t=>e(t))},findMessagesBy(e){return r.filter(t=>e(t))},async getEmail(e){try{if(!e)return{error:new d(i,"Email ID is required to retrieve email details"),success:!1};const t=r.find(o=>o.id===e);return t?(a.debug("Retrieved email",{id:e}),{data:t,success:!0}):{error:new d(i,`Email with ID ${e} not found`),success:!1}}catch(t){return a.debug("Exception retrieving email",t),{error:new d(i,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},getInstance(){return r},getLastSentMessage(){return r.at(-1)},getMessagesBySubject(e){return r.filter(t=>t.options.subject===e)},getMessagesTo(e){return r.filter(t=>{const o=Array.isArray(t.options.to)?t.options.to:[t.options.to];let l=[];t.options.cc&&(l=Array.isArray(t.options.cc)?t.options.cc:[t.options.cc]);let u=[];return t.options.bcc&&(u=Array.isArray(t.options.bcc)?t.options.bcc:[t.options.bcc]),[...o,...l,...u].some(R=>R.email===e)})},getSentEmails(){return[...r]},getSentMessages(){return[...r]},getSentMessagesCount(){return r.length},async initialize(){y||(s.delay>0&&await new Promise(e=>{setTimeout(e,s.delay)}),y=!0,a.debug("Mock provider initialized"))},async isAvailable(){return!0},name:i,options:s,reset(){r.length=0,m=void 0;const e=M();s.debug=e.debug,s.delay=e.delay,s.failureRate=e.failureRate,s.retries=e.retries,s.simulateFailure=e.simulateFailure,s.timeout=e.timeout,s.randomDelayRange={max:0,min:0},s.defaultResponse=void 0,a.debug("Mock provider reset to initial state")},async sendEmail(e){try{const t=A(e);if(t.length>0)return{error:new d(i,`Invalid email options: ${t.join(", ")}`),success:!1};y||await this.initialize();let o=s.delay;if(s.randomDelayRange&&s.randomDelayRange.max>0){const{max:n,min:c}=s.randomDelayRange;o=Math.floor(Math.random()*(n-c+1))+c}if(o>0&&await new Promise(n=>{setTimeout(n,o)}),m!==void 0){const n=m;if(m=void 0,!n.successful)return a.debug("Using next response (failure)",n),{error:new d(i,n.errorMessages.join(", ")),success:!1};const c=n.messageId||D(),b=n.timestamp||new Date,v={messageId:c,provider:n.provider??i,response:n.response,sent:!0,timestamp:b},S={id:c,options:e,result:v,timestamp:b};return r.push(S),a.debug("Email stored using next response",{messageId:c}),{data:v,success:!0}}if(s.simulateFailure||s.failureRate>0&&Math.random()<s.failureRate)return a.debug("Simulating email send failure"),{error:new d(i,"Simulated failure"),success:!1};const u=s.defaultResponse?.successful?s.defaultResponse.messageId:D(),w=s.defaultResponse?.successful&&s.defaultResponse.timestamp?s.defaultResponse.timestamp:new Date,R=s.defaultResponse&&"response"in s.defaultResponse?s.defaultResponse.response:void 0,h={messageId:u,provider:i,response:R??{mock:!0,stored:!0},sent:!0,timestamp:w},E={id:u,options:e,result:h,timestamp:w};return r.push(E),a.debug("Email stored in mock provider",{messageId:u,subject:e.subject,to:Array.isArray(e.to)?e.to.map(n=>n.email):e.to.email}),{data:h,success:!0}}catch(t){return a.debug("Exception sending email",t),{error:new d(i,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},setDefaultResponse(e){s.defaultResponse=e,a.debug("Set default response",{receipt:e})},setDelay(e){if(e<0)throw new RangeError("Delay must be non-negative");s.delay=e,s.randomDelayRange={max:0,min:0},a.debug("Set fixed delay",{milliseconds:e})},setFailureRate(e){if(e<0||e>1)throw new RangeError("Failure rate must be between 0.0 and 1.0");s.failureRate=e,a.debug("Set failure rate",{rate:e})},setNextResponse(e){m=e,a.debug("Set next response",{receipt:e})},setRandomDelay(e,t){if(e<0||t<0||e>t)throw new RangeError("Invalid delay range");s.delay=0,s.randomDelayRange={max:t,min:e},a.debug("Set random delay range",{max:t,min:e})},async shutdown(){r.length=0,p.delete(g),a.debug("Mock provider shutdown")},async validateCredentials(){return!0},async waitForMessage(e,t=5e3){const o=Date.now();for(;;){const l=r.find(u=>e(u));if(l)return l;if(Date.now()-o>t)throw new Error("Timeout waiting for message");await new Promise(u=>{setTimeout(u,10)})}},async waitForMessageCount(e,t=5e3){const o=Date.now();for(;r.length<e;){if(Date.now()-o>t)throw new Error(`Timeout waiting for ${e} messages (got ${r.length})`);await new Promise(l=>{setTimeout(l,10)})}}}});export{j as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import m from"./EmailError-
|
|
1
|
+
import m from"./EmailError-SXEFQEyA.js";import y from"./RequiredOptionError-C2wWqmiE.js";import{g}from"./generate-message-id-C5AM6DFE.js";import{m as v}from"./make-request-mszP240P.js";import{r as E}from"./retry-ByPJFAtq.js";import{v as b}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as I,P,h as T}from"./provider-base-G22b4a87.js";import{a as d}from"./address-formatter-w36S9ZYj.js";import{c as A}from"./attachment-processor-AB1m-n9T.js";const r="netcore",_="https://emailapi.netcorecloud.net/v5.1",D=3e4,S=3,l=a=>[a].flat(),q=w((a={})=>{if(!a.apiKey)throw new y(r,"apiKey");const s={apiKey:a.apiKey,debug:a.debug??!1,endpoint:a.endpoint??_,logger:a.logger,retries:a.retries??S,timeout:a.timeout??D},u=new P,p=I(r,a.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(r,"Netcore API not available or invalid API key");p.debug("Provider initialized successfully")},r)},async isAvailable(){return s.apiKey.length>0},name:r,options:s,async sendEmail(e){try{const o=b(e);if(o.length>0)return{error:new m(r,`Invalid email options: ${o.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),r);const i={to:l(e.to).map(t=>d(t))};e.cc&&(i.cc=l(e.cc).map(t=>d(t))),e.bcc&&(i.bcc=l(e.bcc).map(t=>d(t)));const n={from:d(e.from),personalizations:[i],subject:e.subject};if(e.templateId)n.template_id=e.templateId,e.templateData&&(i.attributes=e.templateData);else{const t=[];e.html&&t.push({type:"html",value:e.html}),e.text&&t.push({type:"plain",value:e.text}),t.length>0&&(n.content=t)}if(e.replyTo){const t=l(e.replyTo)[0];t&&(n.reply_to=t.email)}e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async t=>{const h=await A(t,r);return{content:h.content,name:h.filename}})));const c=await E(async()=>v(`${s.endpoint}/mail/send`,{headers:{api_key:s.apiKey,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify(n)),s.retries);if(!c.success)return{error:c.error??new m(r,"Failed to send email"),success:!1};const{body:f}=c.data;return{data:{messageId:f?.data?.message_id??f?.message_id??g(),provider:r,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:T(r,"send email",o,p),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{q as default};
|
package/dist/packem_shared/{nodemailerProvider-DqJh8ghN.js → nodemailerProvider-WNNtLE2s.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import p from"nodemailer";import l from"./EmailError-
|
|
1
|
+
import p from"nodemailer";import l from"./EmailError-SXEFQEyA.js";import w from"./RequiredOptionError-C2wWqmiE.js";import{g as v}from"./generate-message-id-C5AM6DFE.js";import{h as g}from"./headers-to-record-ZOZ7Dubo.js";import{v as h}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";const s="nodemailer",x=T((c={})=>{if(!c.transport)throw new w(s,"transport");let o;const f=r=>{const a=r??c.transport;return p.createTransport(a)};let d=!1;const y=async()=>{if(!d)try{o=f(),await o.verify(),d=!0}catch(r){throw new l(s,`Failed to initialize nodemailer transport: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))})}},m=r=>{const a=e=>e.name?`${e.name} <${e.email}>`:e.email,t=e=>e.name?`${e.name} <${e.email}>`:e.email,u=c.defaultFrom??r.from,n={from:a(u),subject:r.subject,to:Array.isArray(r.to)?r.to.map(e=>t(e)):t(r.to)};return r.text&&(n.text=r.text),r.html&&(n.html=r.html),r.cc&&(n.cc=Array.isArray(r.cc)?r.cc.map(e=>t(e)):t(r.cc)),r.bcc&&(n.bcc=Array.isArray(r.bcc)?r.bcc.map(e=>t(e)):t(r.bcc)),r.replyTo&&(n.replyTo=r.replyTo.name?`${r.replyTo.name} <${r.replyTo.email}>`:r.replyTo.email),r.headers&&(n.headers=g(r.headers)),r.attachments&&r.attachments.length>0&&(n.attachments=r.attachments.map(e=>{const i={filename:e.filename};return e.raw!==void 0?i.content=e.raw:e.content!==void 0?i.content=e.content:e.path&&(i.path=e.path),e.contentType&&(i.contentType=e.contentType),e.contentDisposition&&(i.contentDisposition=e.contentDisposition),e.cid&&(i.cid=e.cid),e.encoding&&(i.encoding=e.encoding),e.headers&&(i.headers=e.headers),e.href&&(i.href=e.href),e.httpHeaders&&(i.httpHeaders=e.httpHeaders),i})),n};return{features:{attachments:!0,customHeaders:!0,html:!0,replyTo:!0},initialize:y,isAvailable:async()=>{try{return o??=f(),await o.verify(),!0}catch{return!1}},name:s,options:c,sendEmail:async r=>{const a=h(r);if(a.length>0)return{error:new l(s,`Validation failed: ${a.join(", ")}`),success:!1};try{if(d||await y(),!o)throw new l(s,"Transporter not initialized. Call initialize() first.");const t=r.transportOverride?f(r.transportOverride):o,u=m(r),n=await t.sendMail(u);return{data:{messageId:n.messageId??v(),provider:s,response:n,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new l(s,`Failed to send email: ${t instanceof Error?t.message:String(t)}`,{cause:t instanceof Error?t:new Error(String(t))}),success:!1}}},shutdown:async()=>{o&&typeof o.close=="function"&&o.close(),o=void 0,d=!1},validateCredentials:async()=>{try{return o??=f(),await o.verify(),!0}catch{return!1}}}});export{x as default};
|