@visulima/email 1.0.0-alpha.19 → 1.0.0-alpha.20
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 +13 -0
- package/LICENSE.md +36 -0
- package/dist/packem_shared/{ahaSendProvider-Cni1nzIr.js → ahaSendProvider-DOAAW65O.js} +1 -1
- package/dist/packem_shared/{awsSesProvider-D9idlOm1.js → awsSesProvider-DX1630Ms.js} +1 -1
- package/dist/packem_shared/{azureProvider-OU6Gu-cD.js → azureProvider-EkNYKAiF.js} +1 -1
- package/dist/packem_shared/{brevoProvider-Bmpg3VT_.js → brevoProvider-CkR4U4RD.js} +1 -1
- package/dist/packem_shared/{httpProvider-OX9_yKF0.js → httpProvider-DUg1AQfO.js} +1 -1
- package/dist/packem_shared/{infobipProvider-Bx4A4p4A.js → infobipProvider-BhTsWi7e.js} +1 -1
- package/dist/packem_shared/mailPaceProvider-DRt6Z9Hr.js +1 -0
- package/dist/packem_shared/{mailerSendProvider-FiR_X5Be.js → mailerSendProvider-Dx_iHInH.js} +1 -1
- package/dist/packem_shared/{mailgunProvider-BAg_jpfi.js → mailgunProvider-ChkLGZZW.js} +1 -1
- package/dist/packem_shared/mailjetProvider-BMRhNe6H.js +1 -0
- package/dist/packem_shared/{mailomatProvider-D5HPTJrq.js → mailomatProvider-CydV-JB6.js} +1 -1
- package/dist/packem_shared/{mailtrapProvider-4fyjVZrA.js → mailtrapProvider-CuAfJWDr.js} +1 -1
- package/dist/packem_shared/{make-request--BdZNxIl.js → make-request-CaT4d5oC.js} +1 -1
- package/dist/packem_shared/{mandrillProvider-DPXMdbPI.js → mandrillProvider-BBeLbaw0.js} +1 -1
- package/dist/packem_shared/{plunkProvider-CmR0bUei.js → plunkProvider-BQyjG6YT.js} +1 -1
- package/dist/packem_shared/{postalProvider-vf5vjbef.js → postalProvider-DPHQ620q.js} +1 -1
- package/dist/packem_shared/{postmarkProvider-Ddr-1xR4.js → postmarkProvider-bMTC2gdJ.js} +1 -1
- package/dist/packem_shared/resendProvider-Cns1tvF5.js +1 -0
- package/dist/packem_shared/{scalewayProvider-Bdh-7QY6.js → scalewayProvider-O1dHz7iJ.js} +1 -1
- package/dist/packem_shared/{sendGridProvider-UrH61D8C.js → sendGridProvider-DmywC-eT.js} +1 -1
- package/dist/packem_shared/{sweegoProvider-B_yTn1gT.js → sweegoProvider-D086G6xG.js} +1 -1
- package/dist/packem_shared/{zeptomailProvider-skowg799.js → zeptomailProvider-DKKEpEsW.js} +1 -1
- package/dist/providers/ahasend/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/http/index.js +1 -1
- package/dist/providers/infobip/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/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/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.js +1 -1
- package/package.json +16 -16
- package/dist/packem_shared/mailPaceProvider-DWptkW9x.js +0 -1
- package/dist/packem_shared/mailjetProvider-C737SQmw.js +0 -1
- package/dist/packem_shared/resendProvider-9X-wmOFy.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## @visulima/email [1.0.0-alpha.20](https://github.com/visulima/visulima/compare/@visulima/email@1.0.0-alpha.19...@visulima/email@1.0.0-alpha.20) (2026-05-06)
|
|
2
|
+
|
|
3
|
+
### Miscellaneous Chores
|
|
4
|
+
|
|
5
|
+
* **email:** apply prettier and eslint quote-style auto-fix ([ba38e00](https://github.com/visulima/visulima/commit/ba38e009085d304e7810ee9dd63bc1fd22b53ae8))
|
|
6
|
+
* **email:** housekeeping cleanup ([fac388e](https://github.com/visulima/visulima/commit/fac388edbb3073d912b65c6ad1716dc57257dccf))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Dependencies
|
|
10
|
+
|
|
11
|
+
* **@visulima/error:** upgraded to 6.0.0-alpha.16
|
|
12
|
+
* **@visulima/fs:** upgraded to 5.0.0-alpha.14
|
|
13
|
+
|
|
1
14
|
## @visulima/email [1.0.0-alpha.19](https://github.com/visulima/visulima/compare/@visulima/email@1.0.0-alpha.18...@visulima/email@1.0.0-alpha.19) (2026-05-04)
|
|
2
15
|
|
|
3
16
|
|
package/LICENSE.md
CHANGED
|
@@ -57,11 +57,14 @@ Repository: git+https://github.com/visulima/visulima.git
|
|
|
57
57
|
>
|
|
58
58
|
>
|
|
59
59
|
> # Licenses of bundled dependencies
|
|
60
|
+
>
|
|
60
61
|
> The published @visulima/error artifact additionally contains code with the following licenses:
|
|
61
62
|
> MIT
|
|
62
63
|
>
|
|
63
64
|
> # Bundled dependencies:
|
|
65
|
+
>
|
|
64
66
|
> ## is-plain-obj
|
|
67
|
+
>
|
|
65
68
|
> License: MIT
|
|
66
69
|
> By: Sindre Sorhus
|
|
67
70
|
> Repository: sindresorhus/is-plain-obj
|
|
@@ -169,11 +172,14 @@ Repository: git+https://github.com/visulima/visulima.git
|
|
|
169
172
|
> >
|
|
170
173
|
> >
|
|
171
174
|
> > # Licenses of bundled dependencies
|
|
175
|
+
> >
|
|
172
176
|
> > The published @visulima/error artifact additionally contains code with the following licenses:
|
|
173
177
|
> > MIT
|
|
174
178
|
> >
|
|
175
179
|
> > # Bundled dependencies:
|
|
180
|
+
> >
|
|
176
181
|
> > ## is-plain-obj
|
|
182
|
+
> >
|
|
177
183
|
> > License: MIT
|
|
178
184
|
> > By: Sindre Sorhus
|
|
179
185
|
> > Repository: sindresorhus/is-plain-obj
|
|
@@ -187,6 +193,33 @@ Repository: git+https://github.com/visulima/visulima.git
|
|
|
187
193
|
> > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
188
194
|
> > >
|
|
189
195
|
> > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
196
|
+
> >
|
|
197
|
+
> >
|
|
198
|
+
> >
|
|
199
|
+
> >
|
|
200
|
+
> >
|
|
201
|
+
> > # Licenses of bundled types
|
|
202
|
+
> > The published @visulima/error artifact additionally contains code with the following licenses:
|
|
203
|
+
> > Apache-2.0
|
|
204
|
+
> >
|
|
205
|
+
> > # Bundled types:
|
|
206
|
+
> > ## ai
|
|
207
|
+
> > License: Apache-2.0
|
|
208
|
+
> > Repository: https://github.com/vercel/ai
|
|
209
|
+
> >
|
|
210
|
+
> > > Copyright 2023 Vercel, Inc.
|
|
211
|
+
> > >
|
|
212
|
+
> > > Licensed under the Apache License, Version 2.0 (the "License");
|
|
213
|
+
> > > you may not use this file except in compliance with the License.
|
|
214
|
+
> > > You may obtain a copy of the License at
|
|
215
|
+
> > >
|
|
216
|
+
> > > http://www.apache.org/licenses/LICENSE-2.0
|
|
217
|
+
> > >
|
|
218
|
+
> > > Unless required by applicable law or agreed to in writing, software
|
|
219
|
+
> > > distributed under the License is distributed on an "AS IS" BASIS,
|
|
220
|
+
> > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
221
|
+
> > > See the License for the specific language governing permissions and
|
|
222
|
+
> > > limitations under the License.
|
|
190
223
|
>
|
|
191
224
|
> ---------------------------------------
|
|
192
225
|
>
|
|
@@ -818,11 +851,14 @@ Repository: git+https://github.com/visulima/visulima.git
|
|
|
818
851
|
> <!-- DEPENDENCIES -->
|
|
819
852
|
>
|
|
820
853
|
> # Licenses of bundled dependencies
|
|
854
|
+
>
|
|
821
855
|
> The published @visulima/error artifact additionally contains code with the following licenses:
|
|
822
856
|
> MIT
|
|
823
857
|
>
|
|
824
858
|
> # Bundled dependencies:
|
|
859
|
+
>
|
|
825
860
|
> ## is-plain-obj
|
|
861
|
+
>
|
|
826
862
|
> License: MIT
|
|
827
863
|
> By: Sindre Sorhus
|
|
828
864
|
> Repository: sindresorhus/is-plain-obj
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var y=(i,r)=>P(i,"name",{value:r,configurable:!0});import{createRequire as I}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request
|
|
1
|
+
var P=Object.defineProperty;var y=(i,r)=>P(i,"name",{value:r,configurable:!0});import{createRequire as I}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-CaT4d5oC.js";import{c as z,u as b,h as w,P as k}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{f as p,a as B}from"./address-formatter-Cm_E_ZMa.js";const T=I(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[r,u]=m.versions.node.split(".").map(Number);if(r>22||r===22&&u>=3||r===20&&u>=16)return m.getBuiltinModule(i)}return T(i)},"__cjs_getBuiltinModule"),{Buffer:j}=$("node:buffer"),s="ahasend",C="https://api.ahasend.com",x=3e4,G=3,Q=K((i={})=>{if(!i.apiKey)throw new S(s,"apiKey");const r={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??C,retries:i.retries??G,timeout:i.timeout??x,...i.logger&&{logger:i.logger}},u=new k,n=z(s,i.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(s,"Email ID is required to retrieve email details"),success:!1};await this.initialize();const o={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>f(`${r.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:r.timeout}),r.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(s,"retrieve email",o,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(s,"AhaSend API not available or invalid API key");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{return n.debug("Checking AhaSend API availability"),!!(await f(`${r.endpoint}/v2/ping`,{headers:{Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},method:"GET",timeout:r.timeout})).success}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const o=q(e);if(o.length>0)return{error:new c(s,`Invalid email options: ${o.join(", ")}`),success:!1};await this.initialize();const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=B(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const a=E(e.headers);t.headers=a}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async a=>{let d;if(a.content)if(typeof a.content=="string")d=a.content;else if(a.content instanceof Promise){const A=await a.content;d=j.from(A).toString("base64")}else d=a.content.toString("base64");else if(a.raw)d=typeof a.raw=="string"?a.raw:a.raw.toString("base64");else throw new c(s,`Attachment ${a.filename} has no content`);return{content:d,contentType:a.contentType??"application/octet-stream",filename:a.filename,...a.cid&&{cid:a.cid}}}))),n.debug("Sending email via AhaSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},l=await b(async()=>f(`${r.endpoint}/send`,{headers:v,method:"POST",timeout:r.timeout},JSON.stringify(t)),r.retries);if(!l.success)return n.debug("API request failed when sending email",l.error),{error:l.error??new c(s,"Failed to send email"),success:!1};const g=l.data?.body,h=g?.messageId??g?.id??_();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(s,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var L=Object.defineProperty;var j=(m,a)=>L(m,"name",{value:a,configurable:!0});import{createRequire as V}from"node:module";import T from"./EmailError-zm2ffVav.js";import Q from"./RequiredOptionError-CevW3u2K.js";import{c as X}from"./create-logger-BiWdqFNg.js";import S from"../utils/format-email-address.js";import{i as J}from"./headers-to-record-Qo124ImV.js";import{m as Y}from"./make-request
|
|
1
|
+
var L=Object.defineProperty;var j=(m,a)=>L(m,"name",{value:a,configurable:!0});import{createRequire as V}from"node:module";import T from"./EmailError-zm2ffVav.js";import Q from"./RequiredOptionError-CevW3u2K.js";import{c as X}from"./create-logger-BiWdqFNg.js";import S from"../utils/format-email-address.js";import{i as J}from"./headers-to-record-Qo124ImV.js";import{m as Y}from"./make-request-CaT4d5oC.js";import{s as k,a as Z}from"./sanitize-header-wWav-Scu.js";import{d as ee}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as te}from"./defineProvider-CtLH0VBE.js";const F=V(import.meta.url),$=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=j(m=>{if(typeof $<"u"&&$.versions&&$.versions.node){const[a,d]=$.versions.node.split(".").map(Number);if(a>22||a===22&&d>=3||a===20&&d>=16)return $.getBuiltinModule(m)}return F(m)},"__cjs_getBuiltinModule"),{randomUUID:q,createHash:P,createHmac:w}=G("node:crypto");var re=Object.defineProperty,p=j((m,a)=>re(m,"name",{value:a,configurable:!0}),"S");const se=globalThis.Buffer!==void 0,M=p(()=>{if(!se)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},"getBuffer"),y="aws-ses",C={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},fe=te((m={})=>{const a={...C,...m},d=X("AWS-SES",m.logger),W=p((e,i,t,s,n)=>{const u=Object.keys(t).toSorted().map(c=>{const l=t[c];return l===void 0?"":`${encodeURIComponent(c)}=${encodeURIComponent(l)}`}).filter(Boolean).join("&"),r=`${Object.keys(s).toSorted().map(c=>`${c.toLowerCase()}:${s[c]}`).join(`
|
|
2
2
|
`)}
|
|
3
3
|
`,o=Object.keys(s).toSorted().map(c=>c.toLowerCase()).join(";"),g=P("sha256").update(n).digest("hex");return[e,i,u,r,o,g].join(`
|
|
4
4
|
`)},"createCanonicalRequest"),_=p((e,i,t)=>{const s=e.slice(0,8),n=P("sha256").update(t).digest("hex");return["AWS4-HMAC-SHA256",e,`${s}/${i}/ses/aws4_request`,n].join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var k=Object.defineProperty;var w=(n,l)=>k(n,"name",{value:l,configurable:!0});import{createRequire as z}from"node:module";import u from"./EmailError-zm2ffVav.js";import v from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request
|
|
1
|
+
var k=Object.defineProperty;var w=(n,l)=>k(n,"name",{value:l,configurable:!0});import{createRequire as z}from"node:module";import u from"./EmailError-zm2ffVav.js";import v from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request-CaT4d5oC.js";import{c as B,P as C,u as T,h as S}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{j as y,k as R}from"./address-formatter-Cm_E_ZMa.js";const I=z(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=w(n=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[l,t]=f.versions.node.split(".").map(Number);if(l>22||l===22&&t>=3||l===20&&t>=16)return f.getBuiltinModule(n)}return I(n)},"__cjs_getBuiltinModule"),{Buffer:p}=P("node:buffer"),i="azure",x=3e4,O=3,Q=q((n={})=>{if(!n.region)throw new v(i,"region");if(!n.connectionString&&!n.accessToken)throw new v(i,"connectionString or accessToken");const l=n.endpoint??`https://${n.region}.communication.azure.com`,t={debug:n.debug??!1,endpoint:l,region:n.region,retries:n.retries??O,timeout:n.timeout??x,...n.connectionString&&{connectionString:n.connectionString},...n.accessToken&&{accessToken:n.accessToken},...n.logger&&{logger:n.logger}},g=new C,a=B(i,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new u(i,"Email ID is required to retrieve email details"),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const o={"Content-Type":"application/json"};if(t.accessToken)o.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);c&&(o.Authorization=`Bearer ${c[2]}`)}a.debug("Retrieving email details",{id:e});const r=await T(async()=>h(`${t.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:t.timeout}),t.retries);return r.success?(a.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(a.debug("API request failed when retrieving email",r.error),{error:new u(i,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:S(i,"retrieve email",o,a),success:!1}}},async initialize(){await g.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(i,"Azure Communication Services API not available or invalid credentials");a.debug("Provider initialized successfully")},i)},async isAvailable(){try{const e={"Content-Type":"application/json"};if(t.accessToken)e.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const c=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(c)e.Authorization=`Bearer ${c[2]}`;else return!1}else return!1;a.debug("Checking Azure Communication Services API availability");const o=await h(`${t.endpoint}/emails:send`,{headers:e,method:"POST",timeout:t.timeout},JSON.stringify({}));if(o.success)return!0;const r=o.data?.statusCode;return r===401||r===403?!1:r===400}catch(e){if(a.debug("Error checking availability:",e),e instanceof Error){const o=e.message;if(o.includes("401")||o.includes("403"))return!1}return!1}},name:i,options:t,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new u(i,`Invalid email options: ${o.join(", ")}`),success:!1};await g.ensureInitialized(()=>this.initialize(),i);const r={content:{subject:e.subject},recipients:{to:y(e.to)},senderAddress:e.from.email};if(e.html&&(r.content.html=e.html),e.text&&(r.content.plainText=e.text),e.cc&&(r.recipients.cc=y(e.cc)),e.bcc&&(r.recipients.bcc=y(e.bcc)),e.replyTo&&(r.replyTo=R(e.replyTo).email),e.importance&&(r.importance=e.importance),e.headers){const s=_(e.headers);r.headers=s}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async s=>{let d;if(s.content)if(typeof s.content=="string")d=p.from(s.content,"utf8").toString("base64");else if(s.content&&typeof s.content.then=="function"){const A=await s.content;d=p.from(A).toString("base64")}else d=s.content.toString("base64");else if(s.raw)d=typeof s.raw=="string"?p.from(s.raw,"utf8").toString("base64"):s.raw.toString("base64");else throw new u(i,`Attachment ${s.filename} has no content`);return{contentInBase64:d,contentType:s.contentType??"application/octet-stream",name:s.filename}}))),a.debug("Sending email via Azure Communication Services API",{subject:r.content.subject,to:r.recipients.to});const c={"Content-Type":"application/json"};if(t.accessToken)c.Authorization=`Bearer ${t.accessToken}`;else if(t.connectionString){const s=t.connectionString.match(/endpoint=([^;]+);accesskey=([^;]+)/);if(s)c.Authorization=`Bearer ${s[2]}`;else return{error:new u(i,"Invalid connection string format"),success:!1}}const m=await T(async()=>h(`${t.endpoint}/emails:send`,{headers:c,method:"POST",timeout:t.timeout},JSON.stringify(r)),t.retries);if(!m.success)return a.debug("API request failed when sending email",m.error),{error:m.error??new u(i,"Failed to send email"),success:!1};const b=m.data?.body?.messageId??j();return a.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:i,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:S(i,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var j=Object.defineProperty;var w=(o,d)=>j(o,"name",{value:d,configurable:!0});import{createRequire as C}from"node:module";import c from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as q}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request
|
|
1
|
+
var j=Object.defineProperty;var w=(o,d)=>j(o,"name",{value:d,configurable:!0});import{createRequire as C}from"node:module";import c from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as q}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request-CaT4d5oC.js";import{c as B,P as K,u as T,h as A}from"./provider-base-Cmzx6BTO.js";import{d as x}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as D}from"./defineProvider-CtLH0VBE.js";import{f as g,a as h}from"./address-formatter-Cm_E_ZMa.js";const E=C(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,S=w(o=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[d,s]=p.versions.node.split(".").map(Number);if(d>22||d===22&&s>=3||d===20&&s>=16)return p.getBuiltinModule(o)}return E(o)},"__cjs_getBuiltinModule"),{Buffer:_}=S("node:buffer"),a="brevo",G="https://api.brevo.com/v3",O=3e4,R=3,X=D((o={})=>{if(!o.apiKey)throw new k(a,"apiKey");const d=o.endpoint??G,s={apiKey:o.apiKey,debug:o.debug??!1,endpoint:d,hardValidation:o.hardValidation??!1,retries:o.retries??R,timeout:o.timeout??O,...o.logger&&{logger:o.logger}},f=new K,n=B(a,o.logger);return{endpoint:s.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const l=await T(async()=>y(`${s.endpoint}/smtp/emails/${e}`,{headers:t,method:"GET",timeout:s.timeout}),s.retries);return l.success?(n.debug("Email details retrieved successfully"),{data:l.data?.body,success:!0}):(n.debug("API request failed when retrieving email",l.error),{error:new c(a,`Failed to retrieve email: ${l.error instanceof Error?l.error.message:"Unknown error"}`,{cause:l.error}),success:!1})}catch(t){return{error:A(a,"retrieve email",t,n),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Brevo API not available or invalid API key");n.debug("Provider initialized successfully")},a)},async isAvailable(){try{const e={"api-key":s.apiKey,"Content-Type":"application/json"};n.debug("Checking Brevo API availability");const t=await y(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return n.debug("Brevo API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{let t;Array.isArray(e.replyTo)?t=e.replyTo.length>0?e.replyTo[0]:void 0:t=e.replyTo;const l={...e,replyTo:t},b=x(l);if(b.length>0)return{error:new c(a,`Invalid email options: ${b.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const i={sender:h(e.from),subject:e.subject,to:g(e.to)};if(e.html&&(i.htmlContent=e.html),e.text&&(i.textContent=e.text),e.cc&&(i.cc=g(e.cc)),e.bcc&&(i.bcc=g(e.bcc)),e.replyTo)if(Array.isArray(e.replyTo)){if(s.hardValidation)return{error:new c(a,"Only one replyTo address is allowed"),success:!1};if(e.replyTo.length===0)return{error:new c(a,"replyTo array cannot be empty"),success:!1};const r=e.replyTo[0];if(!r)return{error:new c(a,"replyTo array cannot be empty"),success:!1};i.replyTo=h(r)}else i.replyTo=h(e.replyTo);if(e.templateId&&(i.templateId=e.templateId,e.templateParams&&(i.params=e.templateParams)),e.tags&&e.tags.length>0&&(i.tags=e.tags),e.scheduledAt){const r=typeof e.scheduledAt=="number"?new Date(e.scheduledAt*1e3).toISOString():e.scheduledAt;i.scheduledAt=r}if(e.batchId&&(i.batchId=e.batchId),e.headers){const r=q(e.headers);i.headers=r}e.attachments&&e.attachments.length>0&&(i.attachment=await Promise.all(e.attachments.map(async r=>{let m;if(r.content)if(typeof r.content=="string")m=r.content;else if(r.content instanceof Promise){const P=await r.content;m=_.from(P).toString("base64")}else m=r.content.toString("base64");else if(r.raw)m=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new c(a,`Attachment ${r.filename} has no content`);return{content:m,name:r.filename,...r.contentType&&{type:r.contentType}}}))),n.debug("Sending email via Brevo API",{subject:i.subject,to:i.to});const I={"api-key":s.apiKey,"Content-Type":"application/json"},u=await T(async()=>y(`${s.endpoint}/smtp/email`,{headers:I,method:"POST",timeout:s.timeout},JSON.stringify(i)),s.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(a,"Failed to send email"),success:!1};const v=u.data?.body?.messageId??z();return n.debug("Email sent successfully",{messageId:v}),{data:{messageId:v,provider:a,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:A(a,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{X as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var v=Object.defineProperty;var p=(r,a)=>v(r,"name",{value:a,configurable:!0});import c from"./EmailError-zm2ffVav.js";import A from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{m as u}from"./make-request
|
|
1
|
+
var v=Object.defineProperty;var p=(r,a)=>v(r,"name",{value:a,configurable:!0});import c from"./EmailError-zm2ffVav.js";import A from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{m as u}from"./make-request-CaT4d5oC.js";import{d as O}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as P}from"./defineProvider-CtLH0VBE.js";var C=Object.defineProperty,h=p((r,a)=>C(r,"name",{value:a,configurable:!0}),"f");const n="http",I="POST",f=3e4,z=P((r={})=>{if(!r.endpoint)throw new A(n,"endpoint");const a={apiKey:r.apiKey??"",endpoint:r.endpoint,headers:r.headers??{},method:r.method??I},d=h(()=>{const e={"Content-Type":"application/json",...a.headers};return a.apiKey&&(e.Authorization=`Bearer ${a.apiKey}`),e},"getStandardHeaders"),y=h(e=>{const t={from:e.from.email,from_name:e.from.name,html:e.html,subject:e.subject,text:e.text,to:Array.isArray(e.to)?e.to.map(s=>s.email):e.to.email};return e.cc&&(t.cc=Array.isArray(e.cc)?e.cc.map(s=>s.email):e.cc.email),e.bcc&&(t.bcc=Array.isArray(e.bcc)?e.bcc.map(s=>s.email):e.bcc.email),e.customParams&&Object.assign(t,e.customParams),t},"formatRequest");let m=!1;return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!m){if(!await this.isAvailable())throw new c(n,"API endpoint not available");m=!0}},async isAvailable(){try{return!!(await u(a.endpoint,{headers:d(),method:"OPTIONS",timeout:f})).success}catch(e){if(e instanceof Error){const t=e.message;if(t.includes("401")||t.includes("403"))return!1}return!1}},name:n,options:a,async sendEmail(e){try{const t=O(e);if(t.length>0)return{error:new c(n,`Invalid email options: ${t.join(", ")}`),success:!1};m||await this.initialize();const s=d();e.headers&&Object.assign(s,e.headers);const b=y(e),g=e.endpointOverride??a.endpoint,w=e.methodOverride??a.method,o=await u(g,{headers:s,method:w,timeout:f},JSON.stringify(b));if(!o.success)return{error:new c(n,`Failed to send email: ${o.error?.message||"Unknown error"}`,{cause:o.error}),success:!1};let l;const i=o.data?.body;return i&&typeof i=="object"&&(l=i.id??i.messageId??(i.data&&typeof i.data=="object"&&(i.data.id??i.data.messageId))),l??=j(),{data:{messageId:l,provider:n,response:o.data?.body,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:new c(n,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){try{const e=await u(a.endpoint,{headers:d(),method:"GET",timeout:f});return!!(e.data&&typeof e.data=="object"&&"statusCode"in e.data&&typeof e.data.statusCode=="number"&&e.data.statusCode>=200&&e.data.statusCode<300)}catch{return!1}}}});export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var b=(r,n)=>T(r,"name",{value:n,configurable:!0});import{createRequire as P}from"node:module";import c from"./EmailError-zm2ffVav.js";import z from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as U}from"./headers-to-record-Qo124ImV.js";import{m as g}from"./make-request
|
|
1
|
+
var T=Object.defineProperty;var b=(r,n)=>T(r,"name",{value:n,configurable:!0});import{createRequire as P}from"node:module";import c from"./EmailError-zm2ffVav.js";import z from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as U}from"./headers-to-record-Qo124ImV.js";import{m as g}from"./make-request-CaT4d5oC.js";import{c as k,P as S,u as w,h as v}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{l as y}from"./address-formatter-Cm_E_ZMa.js";const $=P(import.meta.url),d=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,j=b(r=>{if(typeof d<"u"&&d.versions&&d.versions.node){const[n,p]=d.versions.node.split(".").map(Number);if(n>22||n===22&&p>=3||n===20&&p>=16)return d.getBuiltinModule(r)}return $(r)},"__cjs_getBuiltinModule"),{Buffer:_}=j("node:buffer"),a="infobip",R="https://api.infobip.com",C=3e4,x=3,Q=K((r={})=>{if(!r.apiKey)throw new z(a,"apiKey");const n=r.baseUrl??R,p=r.endpoint??`${n}/email/3/send`,s={apiKey:r.apiKey,baseUrl:n,debug:r.debug??!1,endpoint:p,retries:r.retries??x,timeout:r.timeout??C,...r.logger&&{logger:r.logger}},f=new S,o=k(a,r.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const l={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await w(async()=>g(`${s.baseUrl}/email/3/reports/${e}`,{headers:l,method:"GET",timeout:s.timeout}),s.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new c(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(l){return{error:v(a,"retrieve email",l,o),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Infobip API not available or invalid API key");o.debug("Provider initialized successfully")},a)},async isAvailable(){try{o.debug("Checking Infobip API availability");const e={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"};return(await g(`${s.baseUrl}/account/1/me`,{headers:e,method:"GET",timeout:s.timeout})).success}catch(e){return o.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const l=q(e);if(l.length>0)return{error:new c(a,`Invalid email options: ${l.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={from:typeof e.from=="string"?e.from:e.from.email,subject:e.subject,to:y(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=y(e.cc)),e.bcc&&(t.bcc=y(e.bcc)),e.replyTo&&(t.replyTo=typeof e.replyTo=="string"?e.replyTo:e.replyTo.email),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateData=e.templateVariables)),e.trackingUrl&&(t.trackingUrl=e.trackingUrl),e.notifyUrl&&(t.notifyUrl=e.notifyUrl),e.intermediateReport!==void 0&&(t.intermediateReport=e.intermediateReport),e.sendAt&&(t.sendAt=e.sendAt),e.headers){const i=U(e.headers);t.headers=i}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async i=>{let u;if(i.content)if(typeof i.content=="string")u=i.content;else if(i.content instanceof Promise){const A=await i.content;u=_.from(A).toString("base64")}else u=i.content.toString("base64");else if(i.raw)u=typeof i.raw=="string"?i.raw:i.raw.toString("base64");else throw new c(a,`Attachment ${i.filename} has no content`);return{content:u,contentType:i.contentType??"application/octet-stream",name:i.filename}}))),o.debug("Sending email via Infobip API",{subject:t.subject,to:t.to});const I={Authorization:`App ${s.apiKey}`,"Content-Type":"application/json"},m=await w(async()=>g(s.endpoint,{headers:I,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!m.success)return o.debug("API request failed when sending email",m.error),{error:m.error??new c(a,"Failed to send email"),success:!1};const h=m.data?.body?.messages?.[0]?.messageId??E();return o.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(l){return{error:v(a,"send email",l,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import c from"./EmailError-zm2ffVav.js";import P from"./RequiredOptionError-CevW3u2K.js";import{s as I}from"./generate-message-id-D4uA8gkj.js";import{i as T}from"./headers-to-record-Qo124ImV.js";import{m as d}from"./make-request-CaT4d5oC.js";import{c as A,P as k,u as g,h as f}from"./provider-base-Cmzx6BTO.js";import{a as $,s as z}from"./sanitize-header-wWav-Scu.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as j}from"./defineProvider-CtLH0VBE.js";import{n as u,c as h}from"./address-formatter-Cm_E_ZMa.js";const r="mailpace",C="https://app.mailpace.com/api/v1",M=3e4,S=3,G=j((n={})=>{if(!n.apiToken)throw new P(r,"apiToken");const s={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??C,retries:n.retries??S,timeout:n.timeout??M,...n.logger&&{logger:n.logger}},l=new k,i=A(r,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[$(v)]=z(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},o=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const m=o.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
|
package/dist/packem_shared/{mailerSendProvider-FiR_X5Be.js → mailerSendProvider-Dx_iHInH.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var h=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request
|
|
1
|
+
var T=Object.defineProperty;var h=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request-CaT4d5oC.js";import{c as S,P as $,u as b,h as y}from"./provider-base-Cmzx6BTO.js";import{d as C}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as E}from"./defineProvider-CtLH0VBE.js";import{f,a as q}from"./address-formatter-Cm_E_ZMa.js";const I=A(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=h(o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,c]=m.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return m.getBuiltinModule(o)}return I(o)},"__cjs_getBuiltinModule"),{Buffer:_}=P("node:buffer"),s="mailersend",M="https://api.mailersend.com",B=3e4,R=3,K=E((o={})=>{if(!o.apiToken)throw new k(s,"apiToken");const a={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??R,timeout:o.timeout??B,...o.logger&&{logger:o.logger}},c=new $,n=S(s,o.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(s,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const r={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>p(`${a.endpoint}/v1/activity/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new l(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:y(s,"retrieve email",r,n),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"MailerSend API not available or invalid API token");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"};n.debug("Checking MailerSend API availability");const r=await p(`${a.endpoint}/v1/tokens/verify`,{headers:e,method:"GET",timeout:a.timeout});return n.debug("MailerSend API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const r=C(e);if(r.length>0)return{error:new l(s,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),s);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.reply_to=q(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.variables=e.templateVariables)),e.personalization&&e.personalization.length>0&&(t.personalization=e.personalization),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.scheduledAt&&(t.send_at=e.scheduledAt),e.domainId&&(t.domain_id=e.domainId),e.headers){const i=j(e.headers);t.headers=i}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async i=>{let u;if(i.content)if(typeof i.content=="string")u=i.content;else if(i.content instanceof Promise){const w=await i.content;u=_.from(w).toString("base64")}else u=i.content.toString("base64");else if(i.raw)u=typeof i.raw=="string"?i.raw:i.raw.toString("base64");else throw new l(s,`Attachment ${i.filename} has no content`);return{content:u,filename:i.filename,...i.contentType&&{type:i.contentType},...i.cid&&{id:i.cid}}}))),n.debug("Sending email via MailerSend API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiToken}`,"Content-Type":"application/json"},d=await b(async()=>p(`${a.endpoint}/v1/email`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new l(s,"Failed to send email"),success:!1};const g=d.data?.body?.message_id??z();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:y(s,"send email",r,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{K as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var A=Object.defineProperty;var y=(i,r)=>A(i,"name",{value:r,configurable:!0});import{createRequire as P}from"node:module";import m from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as R}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request
|
|
1
|
+
var A=Object.defineProperty;var y=(i,r)=>A(i,"name",{value:r,configurable:!0});import{createRequire as P}from"node:module";import m from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as R}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request-CaT4d5oC.js";import{c as _,P as z,u as j,h as I}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{b as v,c as k}from"./address-formatter-Cm_E_ZMa.js";import{a as U}from"./attachment-processor-DsmIomKc.js";const C=P(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(i=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[r,n]=u.versions.node.split(".").map(Number);if(r>22||r===22&&n>=3||r===20&&n>=16)return u.getBuiltinModule(i)}return C(i)},"__cjs_getBuiltinModule"),{Buffer:b}=$("node:buffer");var M=Object.defineProperty,K=y((i,r)=>M(i,"name",{value:r,configurable:!0}),"T");const s="mailgun",B="https://api.mailgun.net",O=3e4,x=3,D=K(i=>{const r=[];for(const[n,o]of Object.entries(i))if(o!=null)if(Array.isArray(o))for(const e of o)r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(e))}`);else typeof o=="object"?r.push(`${encodeURIComponent(n)}=${encodeURIComponent(JSON.stringify(o))}`):r.push(`${encodeURIComponent(n)}=${encodeURIComponent(String(o))}`);return r.join("&")},"objectToFormData"),ee=q((i={})=>{if(!i.apiKey)throw new T(s,"apiKey");if(!i.domain)throw new T(s,"domain");const r={apiKey:i.apiKey,debug:i.debug??!1,domain:i.domain,endpoint:i.endpoint??B,retries:i.retries??x,timeout:i.timeout??O,...i.logger&&{logger:i.logger}},n=new z,o=_(s,i.logger);return{endpoint:r.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new m(s,"Email ID is required to retrieve email details"),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const a={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/events?message-id=${encodeURIComponent(e)}&limit=1`,{headers:a,method:"GET",timeout:r.timeout}),r.retries);if(!t.success)return o.debug("API request failed when retrieving email",t.error),{error:new m(s,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1};o.debug("Email details retrieved successfully");const p=t.data?.items??[],g=p.length>0?p[0]:void 0;return{data:g?.message?.headers??g?.storage??void 0,success:!0}}catch(a){return{error:I(s,"retrieve email",a,o),success:!1}}},async initialize(){await n.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(s,"Mailgun API not available or invalid API key/domain");o.debug("Provider initialized successfully")},s)},async isAvailable(){try{const e={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailgun API availability");const a=await h(`${r.endpoint}/v3/domains/${r.domain}`,{headers:e,method:"GET",timeout:r.timeout});if(o.debug("Mailgun API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!a.success||!a.data||typeof a.data!="object")return!1;const{statusCode:t}=a.data;return typeof t=="number"&&t>=200&&t<300}catch(e){return o.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new m(s,`Invalid email options: ${a.join(", ")}`),success:!1};await n.ensureInitialized(()=>this.initialize(),s);const t={from:k(e.from),to:v(e.to).join(",")};if(e.subject&&(t.subject=e.subject),e.cc&&(t.cc=v(e.cc).join(",")),e.bcc&&(t.bcc=v(e.bcc).join(",")),e.replyTo&&(t["h:Reply-To"]=k(e.replyTo)),e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.template&&(t.template=e.template,e.templateVariables))for(const[d,c]of Object.entries(e.templateVariables))t[`v:${d}`]=c;if(e.tags&&e.tags.length>0&&(t["o:tag"]=e.tags),e.campaignId&&(t["o:campaign"]=e.campaignId),e.deliveryTime&&(t["o:deliverytime"]=typeof e.deliveryTime=="number"?new Date(e.deliveryTime*1e3).toUTCString():e.deliveryTime),e.clickTracking!==void 0&&(t["o:clicktracking"]=e.clickTracking?"yes":"no"),e.openTracking!==void 0&&(t["o:tracking"]=e.openTracking?"yes":"no"),e.unsubscribeTracking!==void 0&&(t["o:tracking-clicks"]=e.unsubscribeTracking?"yes":"no"),e.testMode&&(t["o:testmode"]="yes"),e.requireTls&&(t["o:require-tls"]="yes"),e.skipVerification&&(t["o:skip-verification"]="yes"),e.headers){const d=S(e.headers);for(const[c,f]of Object.entries(d))t[`h:${c}`]=f}if(e.attachments&&e.attachments.length>0){const d=await Promise.all(e.attachments.map((c,f)=>U(c,s,f)));for(const c of d)t[c.key]=c.content}o.debug("Sending email via Mailgun API",{subject:t.subject,to:t.to});const p={Authorization:`Basic ${b.from(`api:${r.apiKey}`).toString("base64")}`,"Content-Type":"application/x-www-form-urlencoded"},g=D(t),l=await j(async()=>h(`${r.endpoint}/v3/${r.domain}/messages`,{headers:p,method:"POST",timeout:r.timeout},g),r.retries);if(!l.success)return o.debug("API request failed when sending email",l.error),{error:l.error??new m(s,"Failed to send email"),success:!1};const w=l.data?.body?.id??R();return o.debug("Email sent successfully",{messageId:w}),{data:{messageId:w,provider:s,response:l.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:I(s,"send email",a,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{ee as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var P=Object.defineProperty;var b=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as $}from"node:module";import d from"./EmailError-zm2ffVav.js";import v from"./RequiredOptionError-CevW3u2K.js";import{s as M}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-CaT4d5oC.js";import{c as z,P as D,u as w,h as T}from"./provider-base-Cmzx6BTO.js";import{d as B}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as R}from"./defineProvider-CtLH0VBE.js";import{d as y,e as S}from"./address-formatter-Cm_E_ZMa.js";const A=$(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,E=b(s=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,l]=m.versions.node.split(".").map(Number);if(a>22||a===22&&l>=3||a===20&&l>=16)return m.getBuiltinModule(s)}return A(s)},"__cjs_getBuiltinModule"),{Buffer:p}=E("node:buffer"),n="mailjet",k="https://api.mailjet.com",q=3e4,K=3,W=R((s={})=>{if(!s.apiKey)throw new v(n,"apiKey");if(!s.apiSecret)throw new v(n,"apiSecret");const a={apiKey:s.apiKey,apiSecret:s.apiSecret,debug:s.debug??!1,endpoint:s.endpoint??k,retries:s.retries??K,timeout:s.timeout??q,...s.logger&&{logger:s.logger}},l=new D,o=z(n,s.logger);return{endpoint:a.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(n,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const i={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await w(async()=>f(`${a.endpoint}/v3.1/REST/message/${e}`,{headers:i,method:"GET",timeout:a.timeout}),a.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new d(n,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(i){return{error:T(n,"retrieve email",i,o),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(n,"Mailjet API not available or invalid API credentials");o.debug("Provider initialized successfully")},n)},async isAvailable(){try{const e={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailjet API availability");const i=await f(`${a.endpoint}/v3.1/REST/user`,{headers:e,method:"GET",timeout:a.timeout});return o.debug("Mailjet API availability check response:",{error:i.error instanceof Error?i.error.message:void 0,statusCode:i.data?.statusCode,success:i.success}),!!(i.success&&i.data&&typeof i.data=="object"&&"statusCode"in i.data&&typeof i.data.statusCode=="number"&&i.data.statusCode>=200&&i.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:n,options:a,async sendEmail(e){try{const i=B(e);if(i.length>0)return{error:new d(n,`Invalid email options: ${i.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const t={From:S(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=S(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 r=_(e.headers),c=[];for(const[g,I]of Object.entries(r))c.push({Name:g,Value:String(I)});c.length>0&&(t.Headers=c)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async r=>{let c;if(r.content)if(typeof r.content=="string")c=r.content;else if(r.content instanceof Promise){const g=await r.content;c=p.from(g).toString("base64")}else c=r.content.toString("base64");else if(r.raw)c=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new d(n,`Attachment ${r.filename} has no content`);return{Base64Content:c,ContentType:r.contentType??"application/octet-stream",Filename:r.filename,...r.cid&&{ContentID:r.cid}}})));const j={Messages:[t]};o.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const C={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},u=await w(async()=>f(`${a.endpoint}/v3.1/send`,{headers:C,method:"POST",timeout:a.timeout},JSON.stringify(j)),a.retries);if(!u.success)return o.debug("API request failed when sending email",u.error),{error:u.error??new d(n,"Failed to send email"),success:!1};const h=u.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??M();return o.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:n,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(i){return{error:T(n,"send email",i,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var h=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as K}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request
|
|
1
|
+
var P=Object.defineProperty;var h=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import S from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as K}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request-CaT4d5oC.js";import{c as k,P as q,u as b,h as w}from"./provider-base-Cmzx6BTO.js";import{d as z}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as C}from"./defineProvider-CtLH0VBE.js";import{f,a as M}from"./address-formatter-Cm_E_ZMa.js";const j=A(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=h(s=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[a,l]=u.versions.node.split(".").map(Number);if(a>22||a===22&&l>=3||a===20&&l>=16)return u.getBuiltinModule(s)}return j(s)},"__cjs_getBuiltinModule"),{Buffer:_}=T("node:buffer"),i="mailomat",x="https://api.mailomat.com",R=3e4,B=3,$=C((s={})=>{if(!s.apiKey)throw new S(i,"apiKey");const a={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??x,retries:s.retries??B,timeout:s.timeout??R,...s.logger&&{logger:s.logger}},l=new q,n=k(i,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(i,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),i);const o={"Content-Type":"application/json","X-API-Key":a.apiKey};n.debug("Retrieving email details",{id:e});const t=await b(async()=>y(`${a.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(i,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(i,"retrieve email",o,n),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(i,"Mailomat API not available or invalid API key");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{return n.debug("Checking Mailomat API availability"),!0}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:a,async sendEmail(e){try{const o=z(e);if(o.length>0)return{error:new c(i,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),i);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.replyTo=M(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const r=K(e.headers);t.headers=r}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async r=>{let d;if(r.content)if(typeof r.content=="string")d=r.content;else if(r.content instanceof Promise){const I=await r.content;d=_.from(I).toString("base64")}else d=r.content.toString("base64");else if(r.raw)d=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new c(i,`Attachment ${r.filename} has no content`);return{content:d,contentType:r.contentType??"application/octet-stream",filename:r.filename,...r.cid&&{cid:r.cid}}}))),n.debug("Sending email via Mailomat API",{subject:t.subject,to:t.to});const v={"Content-Type":"application/json","X-API-Key":a.apiKey},m=await b(async()=>y(`${a.endpoint}/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!m.success)return n.debug("API request failed when sending email",m.error),{error:m.error??new c(i,"Failed to send email"),success:!1};const p=m.data?.body,g=p?.messageId??p?.id??E();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:i,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(i,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{$ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var T=Object.defineProperty;var b=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as _}from"node:module";import l from"./EmailError-zm2ffVav.js";import I from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as C}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request
|
|
1
|
+
var T=Object.defineProperty;var b=(o,a)=>T(o,"name",{value:a,configurable:!0});import{createRequire as _}from"node:module";import l from"./EmailError-zm2ffVav.js";import I from"./RequiredOptionError-CevW3u2K.js";import{s as j}from"./generate-message-id-D4uA8gkj.js";import{i as C}from"./headers-to-record-Qo124ImV.js";import{m as p}from"./make-request-CaT4d5oC.js";import{c as E,P as S,u as h,h as y}from"./provider-base-Cmzx6BTO.js";import{d as $}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{f,a as z}from"./address-formatter-Cm_E_ZMa.js";const k=_(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,P=b(o=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,c]=m.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return m.getBuiltinModule(o)}return k(o)},"__cjs_getBuiltinModule"),{Buffer:A}=P("node:buffer"),i="mailtrap",M="https://send.api.mailtrap.io",x=3e4,G=3,K=q((o={})=>{if(!o.apiToken)throw new I(i,"apiToken");const a={apiToken:o.apiToken,debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??G,timeout:o.timeout??x,...o.logger&&{logger:o.logger}},c=new S,n=E(i,o.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(i,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),i);const r={"Api-Token":a.apiToken,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await h(async()=>p(`${a.endpoint}/api/send/${e}`,{headers:r,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new l(i,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(r){return{error:y(i,"retrieve email",r,n),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(i,"Mailtrap API not available or invalid API token");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{const e={"Api-Token":a.apiToken,"Content-Type":"application/json"};n.debug("Checking Mailtrap API availability");const r=await p(`${a.endpoint}/api/account`,{headers:e,method:"GET",timeout:a.timeout});return n.debug("Mailtrap API availability check response:",{error:r.error instanceof Error?r.error.message:void 0,statusCode:r.data?.statusCode,success:r.success}),!!(r.success&&r.data&&typeof r.data=="object"&&"statusCode"in r.data&&typeof r.data.statusCode=="number"&&r.data.statusCode>=200&&r.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:a,async sendEmail(e){try{const r=$(e);if(r.length>0)return{error:new l(i,`Invalid email options: ${r.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),i);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.reply_to=z(e.replyTo)),e.templateUuid&&(t.template_uuid=e.templateUuid,e.templateVariables&&(t.template_variables=e.templateVariables)),e.category&&(t.category=e.category),e.customVariables&&(t.custom_variables=e.customVariables),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const s=C(e.headers);t.headers=s}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async s=>{let u;if(s.content)if(typeof s.content=="string")u=s.content;else if(s.content instanceof Promise){const w=await s.content;u=A.from(w).toString("base64")}else u=s.content.toString("base64");else if(s.raw)u=typeof s.raw=="string"?s.raw:s.raw.toString("base64");else throw new l(i,`Attachment ${s.filename} has no content`);return{content:u,filename:s.filename,type:s.contentType??"application/octet-stream",...s.cid&&{cid:s.cid}}}))),n.debug("Sending email via Mailtrap API",{subject:t.subject,to:t.to});const v={"Api-Token":a.apiToken,"Content-Type":"application/json"},d=await h(async()=>p(`${a.endpoint}/api/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new l(i,"Failed to send email"),success:!1};const g=d.data?.body?.message_ids?.[0]??j();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:i,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:y(i,"send email",r,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{K as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var b=Object.defineProperty;var h=(s,t)=>b(s,"name",{value:t,configurable:!0});import d from"./EmailError-zm2ffVav.js";var g=Object.defineProperty,p=h((s,t)=>g(s,"name",{value:t,configurable:!0}),"
|
|
1
|
+
var b=Object.defineProperty;var h=(s,t)=>b(s,"name",{value:t,configurable:!0});import d from"./EmailError-zm2ffVav.js";var g=Object.defineProperty,p=h((s,t)=>g(s,"name",{value:t,configurable:!0}),"y");const E=globalThis.Buffer!==void 0,q=p(async(s,t={},a)=>{const m=typeof s=="string"?new URL(s):s;try{const r=new Headers;t.headers&&Object.entries(t.headers).forEach(([e,u])=>{r.set(e,u)});const o={headers:r,method:t.method??(a?"POST":"GET")};a&&(typeof a=="string"||a instanceof Uint8Array?o.body=a:E&&a instanceof globalThis.Buffer?o.body=new Uint8Array(a):o.body=new Uint8Array(a));let c,n;t.timeout&&(c=new AbortController,n=setTimeout(()=>{c?.abort()},t.timeout),o.signal=c.signal);try{const e=await fetch(m.toString(),o);n&&clearTimeout(n);const u=(e.headers.get("content-type")??"").includes("application/json");let i;if(u)try{i=await e.json()}catch{i=await e.text()}else i=await e.text();const f=e.status>=200&&e.status<300,l={};return e.headers.forEach((w,y)=>{l[y]=w}),{data:{body:i,headers:l,statusCode:e.status},error:f?void 0:new d("http",`Request failed with status ${e.status}`,{code:e.status.toString()}),success:f}}catch(e){if(n&&clearTimeout(n),e instanceof Error&&e.name==="AbortError")return{error:new d("http",`Request timed out after ${t.timeout}ms`),success:!1};throw e}}catch(r){return{error:new d("http",`Request failed: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))}),success:!1}}},"makeRequest");export{q as m};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var A=Object.defineProperty;var h=(i,s)=>A(i,"name",{value:s,configurable:!0});import{createRequire as T}from"node:module";import d from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request
|
|
1
|
+
var A=Object.defineProperty;var h=(i,s)=>A(i,"name",{value:s,configurable:!0});import{createRequire as T}from"node:module";import d from"./EmailError-zm2ffVav.js";import k from"./RequiredOptionError-CevW3u2K.js";import{s as z}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-CaT4d5oC.js";import{c as M,P as q,u as v,h as w}from"./provider-base-Cmzx6BTO.js";import{s as _,a as K}from"./sanitize-header-wWav-Scu.js";import{d as N}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as O}from"./defineProvider-CtLH0VBE.js";import{g as y}from"./address-formatter-Cm_E_ZMa.js";const C=T(import.meta.url),g=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,I=h(i=>{if(typeof g<"u"&&g.versions&&g.versions.node){const[s,m]=g.versions.node.split(".").map(Number);if(s>22||s===22&&m>=3||s===20&&m>=16)return g.getBuiltinModule(i)}return C(i)},"__cjs_getBuiltinModule"),{Buffer:S}=I("node:buffer"),r="mandrill",V="https://mandrillapp.com/api/1.0",D=3e4,R=3,Y=O((i={})=>{if(!i.apiKey)throw new k(r,"apiKey");const s={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??V,retries:i.retries??R,timeout:i.timeout??D,...i.logger&&{logger:i.logger}},m=new q,n=M(r,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 d(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r),n.debug("Retrieving email details",{id:e});const l={id:e,key:s.apiKey},t={"Content-Type":"application/json"},o=await v(async()=>f(`${s.endpoint}/messages/info.json`,{headers:t,method:"POST",timeout:s.timeout},JSON.stringify(l)),s.retries);return o.success?(n.debug("Email details retrieved successfully"),{data:o.data?.body,success:!0}):(n.debug("API request failed when retrieving email",o.error),{error:new d(r,`Failed to retrieve email: ${o.error instanceof Error?o.error.message:"Unknown error"}`,{cause:o.error}),success:!1})}catch(l){return{error:w(r,"retrieve email",l,n),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(r,"Mandrill API not available or invalid API key");n.debug("Provider initialized successfully")},r)},async isAvailable(){try{n.debug("Checking Mandrill API availability");const e={key:s.apiKey},l={"Content-Type":"application/json"},t=await f(`${s.endpoint}/users/info.json`,{headers:l,method:"POST",timeout:s.timeout},JSON.stringify(e));return n.debug("Mandrill API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return n.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const l=N(e);if(l.length>0)return{error:new d(r,`Invalid email options: ${l.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={from_email:e.from.email,html:e.html??"",subject:e.subject,text:e.text??"",...e.from.name&&{from_name:e.from.name},to:y(e.to,"to")};if(e.cc){const a=y(e.cc,"cc");for(const c of a)c.type="cc";t.to=[...t.to,...a]}if(e.bcc){const a=y(e.bcc,"bcc");for(const c of a)c.type="bcc";t.to=[...t.to,...a]}if(e.replyTo){const a=e.replyTo.name?`${_(e.replyTo.name)} <${e.replyTo.email}>`:e.replyTo.email;t.headers={"Reply-To":a}}if(e.headers){const a=E(e.headers),c={};Object.entries(a).forEach(([p,P])=>{c[K(p)]=_(P)}),t.headers={...t.headers,...c}}e.tags&&e.tags.length>0&&(t.tags=e.tags),e.metadata&&(t.metadata=e.metadata),(e.googleAnalyticsDomains||e.googleAnalyticsCampaign)&&(t.google_analytics_domains=e.googleAnalyticsDomains,t.google_analytics_campaign=e.googleAnalyticsCampaign),e.subaccount&&(t.subaccount=e.subaccount),e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async a=>{let c;if(a.content)if(typeof a.content=="string")c=a.content;else if(a.content instanceof Promise){const p=await a.content;c=S.from(p).toString("base64")}else c=a.content.toString("base64");else if(a.raw)c=typeof a.raw=="string"?a.raw:a.raw.toString("base64");else throw new d(r,`Attachment ${a.filename} has no content`);return{content:c,name:a.filename,type:a.contentType??"application/octet-stream"}})));const o={key:s.apiKey,message:t};e.templateName&&(o.template_name=e.templateName,e.templateContent&&(o.template_content=e.templateContent),e.templateVariables&&(o.template_vars=e.templateVariables)),e.globalMergeVars&&(t.global_merge_vars=e.globalMergeVars),e.mergeVars&&(t.merge_vars=e.mergeVars),e.sendAt&&(o.send_at=e.sendAt),n.debug("Sending email via Mandrill API",{subject:t.subject,to:t.to});const j={"Content-Type":"application/json"},u=await v(async()=>f(`${s.endpoint}/messages/send.json`,{headers:j,method:"POST",timeout:s.timeout},JSON.stringify(o)),s.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new d(r,"Failed to send email"),success:!1};const b=u.data?.body?.[0]?.id??z();return n.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:r,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(l){return{error:w(r,"send email",l,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Y as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var j=Object.defineProperty;var b=(i,t)=>j(i,"name",{value:t,configurable:!0});import{createRequire as A}from"node:module";import m from"./EmailError-zm2ffVav.js";import z from"./RequiredOptionError-CevW3u2K.js";import{s as h}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as v}from"./make-request
|
|
1
|
+
var j=Object.defineProperty;var b=(i,t)=>j(i,"name",{value:t,configurable:!0});import{createRequire as A}from"node:module";import m from"./EmailError-zm2ffVav.js";import z from"./RequiredOptionError-CevW3u2K.js";import{s as h}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as v}from"./make-request-CaT4d5oC.js";import{c as K,P as x,u as w,h as P}from"./provider-base-Cmzx6BTO.js";import{a as S,s as q}from"./sanitize-header-wWav-Scu.js";import{d as B}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as R}from"./defineProvider-CtLH0VBE.js";const $=A(import.meta.url),f=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=b(i=>{if(typeof f<"u"&&f.versions&&f.versions.node){const[t,u]=f.versions.node.split(".").map(Number);if(t>22||t===22&&u>=3||t===20&&u>=16)return f.getBuiltinModule(i)}return $(i)},"__cjs_getBuiltinModule"),{Buffer:k}=T("node:buffer");var O=Object.defineProperty,C=b((i,t)=>O(i,"name",{value:t,configurable:!0}),"b");const s="plunk",D="https://api.useplunk.com/v1",H=3e4,N=3,Z=R((i={})=>{if(!i.apiKey)throw new z(s,"apiKey");const t={apiKey:i.apiKey,debug:i.debug??!1,endpoint:i.endpoint??D,logger:i.logger,retries:i.retries??N,timeout:i.timeout??H},u=new x,n=K(s,i.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new m(s,"Email ID is required to retrieve email details"),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const c={Authorization:`Bearer ${t.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const l=await w(async()=>v(`${t.endpoint}/emails/${e}`,{headers:c,method:"GET",timeout:t.timeout}),t.retries);return l.success?(n.debug("Email details retrieved successfully"),{data:l.data?.body,success:!0}):(n.debug("API request failed when retrieving email",l.error),{error:new m(s,`Failed to retrieve email: ${l.error instanceof Error?l.error.message:"Unknown error"}`,{cause:l.error}),success:!1})}catch(c){return{error:P(s,"retrieve email",c,n),success:!1}}},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new m(s,"Plunk API not available or invalid API key");n.debug("Provider initialized successfully")},s)},async isAvailable(){try{return t.apiKey&&t.apiKey.length>0?(n.debug("API key exists, assuming Plunk is available"),!0):!1}catch(e){return n.debug("Error checking availability:",e),!1}},name:s,options:t,async sendEmail(e){try{const c=B(e);if(c.length>0)return{error:new m(s,`Invalid email options: ${c.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const l=C(r=>Array.isArray(r)?r.map(o=>o.email):[r.email],"formatRecipients"),a={to:e.subscriber??(Array.isArray(e.to)?e.to[0]?.email:e.to.email)};if(e.from&&(a.from=e.from.email,e.from.name&&(a.from_name=e.from.name)),e.subject&&(a.subject=e.subject),e.html?a.body=e.html:e.text&&(a.body=e.text),e.html&&e.text&&(a.text=e.text),e.cc&&(a.cc=l(e.cc)),e.bcc&&(a.bcc=l(e.bcc)),e.replyTo&&(a.reply_to=e.replyTo.email,e.replyTo.name&&(a.reply_to_name=e.replyTo.name)),e.templateId&&(a.template=e.templateId),e.data&&(a.data=e.data),e.subscriberId&&(a.subscriber_id=e.subscriberId),e.headers){const r=E(e.headers),o={};Object.entries(r).forEach(([y,_])=>{o[S(y)]=q(_)}),a.headers=o}e.attachments&&e.attachments.length>0&&(a.attachments=await Promise.all(e.attachments.map(async r=>{let o;if(r.content)if(typeof r.content=="string")o=r.content;else if(r.content instanceof Promise){const y=await r.content;o=k.from(y).toString("base64")}else o=r.content.toString("base64");else if(r.raw)o=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new m(s,`Attachment ${r.filename} has no content`);return{content:o,filename:r.filename,type:r.contentType??"application/octet-stream"}}))),n.debug("Sending email via Plunk API",{subject:a.subject,to:a.to});const I={Authorization:`Bearer ${t.apiKey}`,"Content-Type":"application/json"},d=await w(async()=>v(`${t.endpoint}/send`,{headers:I,method:"POST",timeout:t.timeout},JSON.stringify(a)),t.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new m(s,"Failed to send email"),success:!1};const p=d.data,g=p?.body&&typeof p.body=="object"?p.body.id??p.body.messageId??h():h();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:s,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(c){return{error:P(s,"send email",c,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var I=Object.defineProperty;var y=(r,l)=>I(r,"name",{value:l,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import b from"./RequiredOptionError-CevW3u2K.js";import{s as T}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as g}from"./make-request
|
|
1
|
+
var I=Object.defineProperty;var y=(r,l)=>I(r,"name",{value:l,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import b from"./RequiredOptionError-CevW3u2K.js";import{s as T}from"./generate-message-id-D4uA8gkj.js";import{i as E}from"./headers-to-record-Qo124ImV.js";import{m as g}from"./make-request-CaT4d5oC.js";import{c as C,P as K,u as v}from"./provider-base-Cmzx6BTO.js";import{d as k}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as q}from"./defineProvider-CtLH0VBE.js";import{h as f,i as w}from"./address-formatter-Cm_E_ZMa.js";const j=A(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,$=y(r=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[l,n]=m.versions.node.split(".").map(Number);if(l>22||l===22&&n>=3||l===20&&n>=16)return m.getBuiltinModule(r)}return j(r)},"__cjs_getBuiltinModule"),{Buffer:S}=$("node:buffer"),i="postal",z=3e4,x=3,J=q((r={})=>{if(!r.host)throw new b(i,"host");if(!r.apiKey)throw new b(i,"apiKey");const l=r.endpoint??`https://${r.host}/api/v1`,n={apiKey:r.apiKey,debug:r.debug??!1,endpoint:l,host:r.host,retries:r.retries??x,timeout:r.timeout??z,...r.logger&&{logger:r.logger}},p=new K,o=C(i,r.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(i,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),i);const t={"Content-Type":"application/json","X-Server-API-Key":n.apiKey};o.debug("Retrieving email details",{id:e});const a=await v(async()=>g(`${n.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:n.timeout}),n.retries);return a.success?(o.debug("Email details retrieved successfully"),{data:a.data?.body,success:!0}):(o.debug("API request failed when retrieving email",a.error),{error:new c(i,`Failed to retrieve email: ${a.error instanceof Error?a.error.message:"Unknown error"}`,{cause:a.error}),success:!1})}catch(t){return o.debug("Exception retrieving email",t),{error:new c(i,`Failed to retrieve email: ${t.message}`,{cause:t}),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(i,"Postal API not available or invalid API key");o.debug("Provider initialized successfully")},i)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Server-API-Key":n.apiKey};o.debug("Checking Postal API availability");const t=await g(`${n.endpoint}/server`,{headers:e,method:"GET",timeout:n.timeout});return o.debug("Postal API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:i,options:n,async sendEmail(e){try{const t=k(e);if(t.length>0)return{error:new c(i,`Invalid email options: ${t.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),i);const a={from:w(e.from).address,subject:e.subject,to:f(e.to).map(s=>s.address)};if(e.html&&(a.html_body=e.html),e.text&&(a.plain_body=e.text),e.cc&&(a.cc=f(e.cc).map(s=>s.address)),e.bcc&&(a.bcc=f(e.bcc).map(s=>s.address)),e.replyTo&&(a.reply_to=w(e.replyTo).address),e.templateId&&(a.template_id=e.templateId,e.templateVariables&&(a.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(a.tag=e.tags.join(",")),e.headers){const s=E(e.headers);a.headers=s}e.attachments&&e.attachments.length>0&&(a.attachments=await Promise.all(e.attachments.map(async s=>{let u;if(s.content)if(typeof s.content=="string")u=s.content;else if(s.content instanceof Promise){const _=await s.content;u=S.from(_).toString("base64")}else u=s.content.toString("base64");else if(s.raw)u=typeof s.raw=="string"?s.raw:s.raw.toString("base64");else throw new c(i,`Attachment ${s.filename} has no content`);return{content_type:s.contentType??"application/octet-stream",data:u,name:s.filename}}))),o.debug("Sending email via Postal API",{subject:a.subject,to:a.to});const P={"Content-Type":"application/json","X-Server-API-Key":n.apiKey},d=await v(async()=>g(`${n.endpoint}/send/message`,{headers:P,method:"POST",timeout:n.timeout},JSON.stringify(a)),n.retries);if(!d.success)return o.debug("API request failed when sending email",d.error),{error:d.error??new c(i,"Failed to send email"),success:!1};const h=d.data?.body?.message_id?.toString()??T();return o.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:i,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return o.debug("Exception sending email",t),{error:new c(i,`Failed to send email: ${t.message}`,{cause:t}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{J as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as P}from"./generate-message-id-D4uA8gkj.js";import{i as w}from"./headers-to-record-Qo124ImV.js";import{m as u}from"./make-request
|
|
1
|
+
import d from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as P}from"./generate-message-id-D4uA8gkj.js";import{i as w}from"./headers-to-record-Qo124ImV.js";import{m as u}from"./make-request-CaT4d5oC.js";import{c as I,P as A,u as f,h}from"./provider-base-Cmzx6BTO.js";import{s as C,a as S}from"./sanitize-header-wWav-Scu.js";import{d as j}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as E}from"./defineProvider-CtLH0VBE.js";import{b as p,c as v}from"./address-formatter-Cm_E_ZMa.js";import{b as z}from"./attachment-processor-DsmIomKc.js";const r="postmark",M="https://api.postmarkapp.com",$=3e4,O=3,V=E((o={})=>{if(!o.serverToken)throw new T(r,"serverToken");const s={debug:o.debug??!1,endpoint:o.endpoint??M,retries:o.retries??O,serverToken:o.serverToken,timeout:o.timeout??$,...o.logger&&{logger:o.logger}},m=new A,i=I(r,o.logger);return{endpoint:s.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(r,"Email ID is required to retrieve email details"),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const a={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Retrieving email details",{id:e});const t=await f(async()=>u(`${s.endpoint}/messages/outbound/${e}/details`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new d(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:h(r,"retrieve email",a,i),success:!1}}},async initialize(){await m.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(r,"Postmark API not available or invalid server token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken};i.debug("Checking Postmark API availability");const a=await u(`${s.endpoint}/server`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("Postmark API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=j(e);if(a.length>0)return{error:new d(r,`Invalid email options: ${a.join(", ")}`),success:!1};await m.ensureInitialized(()=>this.initialize(),r);const t={From:v(e.from),Subject:e.subject,To:p(e.to).join(",")};if(e.html&&(t.HtmlBody=e.html),e.text&&(t.TextBody=e.text),e.cc&&(t.Cc=p(e.cc).join(",")),e.bcc&&(t.Bcc=p(e.bcc).join(",")),e.replyTo&&(t.ReplyTo=v(e.replyTo)),e.templateId?(t.TemplateId=e.templateId,e.templateModel&&(t.TemplateModel=e.templateModel)):e.templateAlias&&(t.TemplateAlias=e.templateAlias,e.templateModel&&(t.TemplateModel=e.templateModel)),e.trackOpens!==void 0&&(t.TrackOpens=e.trackOpens),e.trackLinks!==void 0&&(t.TrackLinks=e.trackLinks),e.inlineCss!==void 0&&(t.InlineCss=e.inlineCss),e.messageStream&&(t.MessageStream=e.messageStream),e.metadata&&(t.Metadata=e.metadata),e.tags&&e.tags.length>0){const[l]=e.tags;t.Tag=l}if(e.headers){const l=w(e.headers),c=[];for(const[b,y]of Object.entries(l))c.push({Name:S(b),Value:C(String(y))});c.length>0&&(t.Headers=c)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async l=>z(l,r)))),i.debug("Sending email via Postmark API",{subject:t.Subject,to:t.To});const k={"Content-Type":"application/json","X-Postmark-Server-Token":s.serverToken},n=await f(async()=>u(`${s.endpoint}/email`,{headers:k,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new d(r,"Failed to send email"),success:!1};const g=n.data?.body?.MessageID??P();return i.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:r,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:h(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var I=Object.defineProperty;var h=(r,a)=>I(r,"name",{value:a,configurable:!0});import c from"./EmailError-zm2ffVav.js";import P from"./RequiredOptionError-CevW3u2K.js";import{s as $}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request-CaT4d5oC.js";import{c as T,P as C,u as y,h as b}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as S}from"./defineProvider-CtLH0VBE.js";import{b as z,c as v,l as w}from"./address-formatter-Cm_E_ZMa.js";var k=Object.defineProperty,K=h((r,a)=>k(r,"name",{value:a,configurable:!0}),"p");const n="resend",R="https://api.resend.com",_=3e4,x=3,D=K(r=>{const a=[],l=/^[\w-]+$/;return l.test(r.name)||a.push(`Tag name '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r.name.length>256&&a.push(`Tag name '${r.name}' exceeds maximum length of 256 characters`),l.test(r.value)||a.push(`Tag value '${r.value}' for tag '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),a},"validateTag"),W=S((r={})=>{if(!r.apiKey)throw new P(n,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??R,logger:r.logger,retries:r.retries??x,timeout:r.timeout??_},l=new C,o=T(n,r.logger);return{endpoint:a.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(n,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const i=await y(async()=>f(`${a.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.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(n,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1})}catch(t){return{error:b(n,"retrieve email",t,o),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(n,"Resend API not available or invalid API key");o.debug("Provider initialized successfully")},n)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("re_"))return o.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};o.debug("Checking Resend API availability");const t=await f(`${a.endpoint}/domains`,{headers:e,method:"GET",timeout:a.timeout});return t.data&&typeof t.data=="object"&&"body"in t.data&&t.data.body&&typeof t.data.body=="object"&&"name"in t.data.body&&t.data.body.name==="restricted_api_key"?(o.debug("API key is valid but restricted to only sending emails"),!0):(o.debug("Resend API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300))}catch(e){return o.debug("Error checking availability:",e),!1}},name:n,options:a,async sendEmail(e){try{const t=E(e);if(t.length>0)return{error:new c(n,`Invalid email options: ${t.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const i={from:v(e.from),headers:e.headers?j(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:z(e.to)};if(e.cc&&(i.cc=w(e.cc)),e.bcc&&(i.bcc=w(e.bcc)),e.replyTo&&(i.reply_to=v(e.replyTo)),e.templateId&&(i.template=e.templateId,e.templateData&&(i.data=e.templateData)),e.scheduledAt&&(i.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const s=[];if(e.tags.forEach(d=>{const p=D(d);p.length>0&&s.push(...p)}),s.length>0)return{error:new c(n,`Invalid email tags: ${s.join(", ")}`),success:!1};i.tags=e.tags.map(d=>({name:d.name,value:d.value}))}e.attachments&&e.attachments.length>0&&(i.attachments=await Promise.all(e.attachments.map(async s=>{let d;if(s.content)if(typeof s.content=="string")d=s.content;else if(s.content instanceof Promise){const p=await s.content;d=Buffer.from(p).toString("base64")}else d=s.content.toString("base64");else if(s.raw)d=typeof s.raw=="string"?s.raw:s.raw.toString("base64");else throw new c(n,`Attachment ${s.filename} has no content`);return{content:d,content_type:s.contentType,filename:s.filename,...s.path&&{path:s.path}}}))),o.debug("Sending email via Resend API",{subject:i.subject,to:i.to});const A={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},u=await y(async()=>f(`${a.endpoint}/emails`,{headers:A,method:"POST",timeout:a.timeout},JSON.stringify(i)),a.retries);if(!u.success)return o.debug("API request failed when sending email",u.error),{error:u.error??new c(n,"Failed to send email"),success:!1};const m=u.data,g=m?.body&&typeof m.body=="object"&&m.body.id?m.body.id:$();return o.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:n,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:b(n,"send email",t,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{W as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var h=(r,l)=>P(r,"name",{value:l,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import y from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as k}from"./headers-to-record-Qo124ImV.js";import{m as b}from"./make-request
|
|
1
|
+
var P=Object.defineProperty;var h=(r,l)=>P(r,"name",{value:l,configurable:!0});import{createRequire as A}from"node:module";import c from"./EmailError-zm2ffVav.js";import y from"./RequiredOptionError-CevW3u2K.js";import{s as E}from"./generate-message-id-D4uA8gkj.js";import{i as k}from"./headers-to-record-Qo124ImV.js";import{m as b}from"./make-request-CaT4d5oC.js";import{c as z,P as q,u as w,h as v}from"./provider-base-Cmzx6BTO.js";import{d as K}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as C}from"./defineProvider-CtLH0VBE.js";import{f as p,a as x}from"./address-formatter-Cm_E_ZMa.js";const T=A(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,S=h(r=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[l,s]=u.versions.node.split(".").map(Number);if(l>22||l===22&&s>=3||l===20&&s>=16)return u.getBuiltinModule(r)}return T(r)},"__cjs_getBuiltinModule"),{Buffer:_}=S("node:buffer"),a="scaleway",R="https://api.scaleway.com/transactional-email/v1alpha1",B=3e4,G=3,U=C((r={})=>{if(!r.apiKey)throw new y(a,"apiKey");if(!r.region)throw new y(a,"region");const l=r.endpoint??R,s={apiKey:r.apiKey,debug:r.debug??!1,endpoint:l,region:r.region,retries:r.retries??G,timeout:r.timeout??B,...r.logger&&{logger:r.logger}},f=new q,n=z(a,r.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(a,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const o={"Content-Type":"application/json","X-Auth-Token":s.apiKey};n.debug("Retrieving email details",{id:e});const t=await w(async()=>b(`${s.endpoint}/regions/${s.region}/emails/${e}`,{headers:o,method:"GET",timeout:s.timeout}),s.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new c(a,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:v(a,"retrieve email",o,n),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(a,"Scaleway API not available or invalid API key");n.debug("Provider initialized successfully")},a)},async isAvailable(){try{return n.debug("Checking Scaleway API availability"),!0}catch(e){return n.debug("Error checking availability:",e),!1}},name:a,options:s,async sendEmail(e){try{const o=K(e);if(o.length>0)return{error:new c(a,`Invalid email options: ${o.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),a);const t={from:{email:e.from.email,...e.from.name&&{name:e.from.name}},subject:e.subject,to:p(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=p(e.cc)),e.bcc&&(t.bcc=p(e.bcc)),e.replyTo&&(t.replyTo=x(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.projectId&&(t.projectId=e.projectId),e.headers){const i=k(e.headers);t.headers=i}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async i=>{let d;if(i.content)if(typeof i.content=="string")d=i.content;else if(i.content instanceof Promise){const j=await i.content;d=_.from(j).toString("base64")}else d=i.content.toString("base64");else if(i.raw)d=typeof i.raw=="string"?i.raw:i.raw.toString("base64");else throw new c(a,`Attachment ${i.filename} has no content`);return{content:d,name:i.filename,type:i.contentType??"application/octet-stream"}}))),n.debug("Sending email via Scaleway API",{subject:t.subject,to:t.to});const I={"Content-Type":"application/json","X-Auth-Token":s.apiKey},m=await w(async()=>b(`${s.endpoint}/regions/${s.region}/emails`,{headers:I,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!m.success)return n.debug("API request failed when sending email",m.error),{error:m.error??new c(a,"Failed to send email"),success:!1};const g=m.data?.body?.id??E();return n.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:a,response:m.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:v(a,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{U as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import l from"./EmailError-zm2ffVav.js";import A from"./RequiredOptionError-CevW3u2K.js";import{s as P}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request
|
|
1
|
+
import l from"./EmailError-zm2ffVav.js";import A from"./RequiredOptionError-CevW3u2K.js";import{s as P}from"./generate-message-id-D4uA8gkj.js";import{i as S}from"./headers-to-record-Qo124ImV.js";import{m as h}from"./make-request-CaT4d5oC.js";import{c as $,P as j,u as b,h as v}from"./provider-base-Cmzx6BTO.js";import{d as G}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as k}from"./defineProvider-CtLH0VBE.js";import{f,a as I}from"./address-formatter-Cm_E_ZMa.js";import{c as z}from"./attachment-processor-DsmIomKc.js";const s="sendgrid",C="https://api.sendgrid.com/v3",E=3e4,_=3,R=k((o={})=>{if(!o.apiKey)throw new A(s,"apiKey");const a={apiKey:o.apiKey,debug:o.debug??!1,endpoint:o.endpoint??C,...o.logger&&{logger:o.logger},retries:o.retries??_,timeout:o.timeout??E},p=new j,i=$(s,o.logger);return{endpoint:a.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(s,"Email ID is required to retrieve email details"),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const r=await b(async()=>h(`${a.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new l(s,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(t){return{error:v(s,"retrieve email",t,i),success:!1}}},async initialize(){await p.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"SendGrid API not available or invalid API key");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("SG."))return i.debug("API key format is valid, assuming SendGrid is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};i.debug("Checking SendGrid API availability");const t=await h(`${a.endpoint}/user/profile`,{headers:e,method:"GET",timeout:a.timeout});return i.debug("SendGrid API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:a,async sendEmail(e){try{const t=G(e);if(t.length>0)return{error:new l(s,`Invalid email options: ${t.join(", ")}`),success:!1};await p.ensureInitialized(()=>this.initialize(),s);const r={to:f(e.to)};if(e.cc&&(r.cc=f(e.cc)),e.bcc&&(r.bcc=f(e.bcc)),e.subject&&(r.subject=e.subject),e.tags&&e.tags.length>0){const d={};for(let m=0;m<e.tags.length;m+=1)d[`tag_${m}`]=e.tags[m];r.customArgs=d}const n={from:I(e.from),personalizations:[r]},u=[];if(e.html&&u.push({type:"text/html",value:e.html}),e.text&&u.push({type:"text/plain",value:e.text}),u.length>0&&(n.content=u),e.replyTo&&(n.reply_to=I(e.replyTo)),e.subject&&(n.subject=e.subject),e.templateId&&(n.template_id=e.templateId,e.templateData&&(r.dynamicTemplateData=e.templateData)),e.sendAt&&(r.send_at=e.sendAt),e.batchId&&(n.batch_id=e.batchId),e.asmGroupId&&(n.asm={group_id:e.asmGroupId}),e.ipPoolName&&(n.ip_pool_name=e.ipPoolName),e.mailSettings&&(n.mail_settings=e.mailSettings),e.trackingSettings&&(n.tracking_settings=e.trackingSettings),e.headers){const d=S(e.headers);n.headers=d}e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async d=>z(d,s)))),i.debug("Sending email via SendGrid API",{subject:n.subject,to:r.to});const w={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},c=await b(async()=>h(`${a.endpoint}/mail/send`,{headers:w,method:"POST",timeout:a.timeout},JSON.stringify(n)),a.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new l(s,"Failed to send email"),success:!1};const g=c.data?.headers,y=(g&&g instanceof Headers?g.get("X-Message-Id"):void 0)??P();return i.debug("Email sent successfully",{messageId:y}),{data:{messageId:y,provider:s,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(s,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var P=Object.defineProperty;var h=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as z}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request
|
|
1
|
+
var P=Object.defineProperty;var h=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as A}from"node:module";import l from"./EmailError-zm2ffVav.js";import T from"./RequiredOptionError-CevW3u2K.js";import{s as _}from"./generate-message-id-D4uA8gkj.js";import{i as z}from"./headers-to-record-Qo124ImV.js";import{m as y}from"./make-request-CaT4d5oC.js";import{c as E,P as k,u as b,h as w}from"./provider-base-Cmzx6BTO.js";import{d as q}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as K}from"./defineProvider-CtLH0VBE.js";import{f,a as B}from"./address-formatter-Cm_E_ZMa.js";const $=A(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,j=h(s=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[a,c]=u.versions.node.split(".").map(Number);if(a>22||a===22&&c>=3||a===20&&c>=16)return u.getBuiltinModule(s)}return $(s)},"__cjs_getBuiltinModule"),{Buffer:S}=j("node:buffer"),i="sweego",x="https://api.sweego.com",C=3e4,R=3,Q=K((s={})=>{if(!s.apiKey)throw new T(i,"apiKey");const a={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??x,retries:s.retries??R,timeout:s.timeout??C,...s.logger&&{logger:s.logger}},c=new k,n=E(i,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new l(i,"Email ID is required to retrieve email details"),success:!1};await c.ensureInitialized(()=>this.initialize(),i);const o={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const t=await b(async()=>y(`${a.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:a.timeout}),a.retries);return t.success?(n.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(n.debug("API request failed when retrieving email",t.error),{error:new l(i,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(o){return{error:w(i,"retrieve email",o,n),success:!1}}},async initialize(){await c.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(i,"Sweego API not available or invalid API key");n.debug("Provider initialized successfully")},i)},async isAvailable(){try{return n.debug("Checking Sweego API availability"),!0}catch(e){return n.debug("Error checking availability:",e),!1}},name:i,options:a,async sendEmail(e){try{const o=q(e);if(o.length>0)return{error:new l(i,`Invalid email options: ${o.join(", ")}`),success:!1};await c.ensureInitialized(()=>this.initialize(),i);const t={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:f(e.to)};if(e.html&&(t.html=e.html),e.text&&(t.text=e.text),e.cc&&(t.cc=f(e.cc)),e.bcc&&(t.bcc=f(e.bcc)),e.replyTo&&(t.replyTo=B(e.replyTo)),e.templateId&&(t.templateId=e.templateId,e.templateVariables&&(t.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.headers){const r=z(e.headers);t.headers=r}e.attachments&&e.attachments.length>0&&(t.attachments=await Promise.all(e.attachments.map(async r=>{let m;if(r.content)if(typeof r.content=="string")m=r.content;else if(r.content instanceof Promise){const I=await r.content;m=S.from(I).toString("base64")}else m=r.content.toString("base64");else if(r.raw)m=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new l(i,`Attachment ${r.filename} has no content`);return{content:m,contentType:r.contentType??"application/octet-stream",filename:r.filename,...r.cid&&{cid:r.cid}}}))),n.debug("Sending email via Sweego API",{subject:t.subject,to:t.to});const v={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},d=await b(async()=>y(`${a.endpoint}/send`,{headers:v,method:"POST",timeout:a.timeout},JSON.stringify(t)),a.retries);if(!d.success)return n.debug("API request failed when sending email",d.error),{error:d.error??new l(i,"Failed to send email"),success:!1};const g=d.data?.body,p=g?.messageId??g?.id??_();return n.debug("Email sent successfully",{messageId:p}),{data:{messageId:p,provider:i,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:w(i,"send email",o,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{Q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import l from"./EmailError-zm2ffVav.js";import y from"./RequiredOptionError-CevW3u2K.js";import{s as b}from"./generate-message-id-D4uA8gkj.js";import{i as k}from"./headers-to-record-Qo124ImV.js";import{m as v}from"./make-request
|
|
1
|
+
import l from"./EmailError-zm2ffVav.js";import y from"./RequiredOptionError-CevW3u2K.js";import{s as b}from"./generate-message-id-D4uA8gkj.js";import{i as k}from"./headers-to-record-Qo124ImV.js";import{m as v}from"./make-request-CaT4d5oC.js";import{c as w,P as A,u as z,h as _}from"./provider-base-Cmzx6BTO.js";import{a as j,s as P}from"./sanitize-header-wWav-Scu.js";import{d as I}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as T}from"./defineProvider-CtLH0VBE.js";import{m as h}from"./address-formatter-Cm_E_ZMa.js";const i="zeptomail",O="https://api.zeptomail.com/v1.1",$=3e4,Z=3,F=T((s={})=>{if(!s.token)throw new y(i,"token");if(!s.token.startsWith("Zoho-enczapikey "))throw new l(i,'Token should be in the format "Zoho-enczapikey <your_api_key>"');const n={debug:s.debug??!1,endpoint:s.endpoint??O,logger:s.logger,retries:s.retries??Z,timeout:s.timeout??$,token:s.token},u=new A,o=w(i,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(i,"Zeptomail API not available or invalid token");o.debug("Provider initialized successfully")},i)},async isAvailable(){try{return n.token&&n.token.startsWith("Zoho-enczapikey ")?(o.debug("Token format is valid, assuming Zeptomail is available"),!0):!1}catch(e){return o.debug("Error checking availability:",e),!1}},name:i,options:n,async sendEmail(e){try{const m=I(e);if(m.length>0)return{error:new l(i,`Invalid email options: ${m.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),i);const a={from:h(e.from).address,subject:e.subject};if(Array.isArray(e.to)?a.to=e.to.length===1?e.to[0].email:e.to.map(t=>t.email):a.to=e.to.email,e.text&&(a.textbody=e.text),e.html&&(a.htmlbody=e.html),e.cc&&(Array.isArray(e.cc)?a.cc=e.cc.length===1?e.cc[0].email:e.cc.map(t=>t.email):a.cc=e.cc.email),e.bcc&&(Array.isArray(e.bcc)?a.bcc=e.bcc.length===1?e.bcc[0].email:e.bcc.map(t=>t.email):a.bcc=e.bcc.email),e.replyTo&&(a.reply_to=[h(e.replyTo).address]),e.trackClicks!==void 0&&(a.track_clicks=e.trackClicks),e.trackOpens!==void 0&&(a.track_opens=e.trackOpens),e.clientReference&&(a.client_reference=e.clientReference),e.mimeHeaders&&Object.keys(e.mimeHeaders).length>0){const t={};for(const[r,d]of Object.entries(e.mimeHeaders))t[r]=d;a.mime_headers=t}if(e.headers){const t=k(e.headers);Object.keys(t).length>0&&(a.mime_headers??={},Object.entries(t).forEach(([r,d])=>{a.mime_headers&&(a.mime_headers[j(r)]=P(d))}))}e.attachments&&e.attachments.length>0&&(a.attachments=e.attachments.map(t=>{const r={name:t.filename};return t.content?(r.content=typeof t.content=="string"?t.content:t.content.toString("base64"),t.contentType&&(r.mime_type=t.contentType)):t.path&&(r.file_cache_key=t.path),r})),o.debug("Sending email via Zeptomail API",{subject:a.subject,to:a.to});const g={Accept:"application/json",Authorization:n.token,"Content-Type":"application/json"},c=await z(async()=>v(`${n.endpoint}/email`,{headers:g,method:"POST",timeout:n.timeout},JSON.stringify(a)),n.retries);if(!c.success){o.debug("API request failed",c.error);let t=c.error instanceof Error?c.error.message:"Unknown error";const r=c.data;return r?.body?.message?t+=` Details: ${r.body.message}`:r?.body?.error?.message&&(t+=` Details: ${r.body.error.message}`),{error:new l(i,`Failed to send email: ${t}`,{cause:c.error}),success:!1}}const p=c.data?.body,f=p?.request_id??b();return o.debug("Email sent successfully",{messageId:f}),{data:{messageId:f,provider:i,response:p,sent:!0,timestamp:new Date},success:!0}}catch(m){return{error:_(i,"send email",m,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/ahaSendProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/ahaSendProvider-DOAAW65O.js";export{r as ahaSendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/awsSesProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/awsSesProvider-DX1630Ms.js";export{a as awsSesProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/azureProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/azureProvider-EkNYKAiF.js";export{a as azureProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/brevoProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/brevoProvider-CkR4U4RD.js";export{o as brevoProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/httpProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/httpProvider-DUg1AQfO.js";export{e as httpProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/infobipProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/infobipProvider-BhTsWi7e.js";export{e as infobipProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/mailerSendProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/mailerSendProvider-Dx_iHInH.js";export{a as mailerSendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mailgunProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mailgunProvider-ChkLGZZW.js";export{e as mailgunProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/mailjetProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/mailjetProvider-BMRhNe6H.js";export{a as mailjetProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/mailomatProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/mailomatProvider-CydV-JB6.js";export{r as mailomatProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/mailPaceProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/mailPaceProvider-DRt6Z9Hr.js";export{r as mailPaceProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mailtrapProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mailtrapProvider-CuAfJWDr.js";export{e as mailtrapProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as d}from"../../packem_shared/mandrillProvider-
|
|
1
|
+
import{default as d}from"../../packem_shared/mandrillProvider-BBeLbaw0.js";export{d as mandrillProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/plunkProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/plunkProvider-BQyjG6YT.js";export{o as plunkProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/postalProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/postalProvider-DPHQ620q.js";export{a as postalProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/postmarkProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/postmarkProvider-bMTC2gdJ.js";export{a as postmarkProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as d}from"../../packem_shared/resendProvider-
|
|
1
|
+
import{default as d}from"../../packem_shared/resendProvider-Cns1tvF5.js";export{d as resendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/scalewayProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/scalewayProvider-O1dHz7iJ.js";export{r as scalewayProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/sendGridProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/sendGridProvider-DmywC-eT.js";export{e as sendGridProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/sweegoProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/sweegoProvider-D086G6xG.js";export{r as sweegoProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/zeptomailProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/zeptomailProvider-DKKEpEsW.js";export{r as zeptomailProvider};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/email",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
4
4
|
"description": "A comprehensive email library with multi-provider support, crypto utilities, and template engines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ahasend",
|
|
@@ -52,6 +52,11 @@
|
|
|
52
52
|
"bugs": {
|
|
53
53
|
"url": "https://github.com/visulima/visulima/issues"
|
|
54
54
|
},
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"author": {
|
|
57
|
+
"name": "Daniel Bannert",
|
|
58
|
+
"email": "d.bannert@anolilab.de"
|
|
59
|
+
},
|
|
55
60
|
"repository": {
|
|
56
61
|
"type": "git",
|
|
57
62
|
"url": "git+https://github.com/visulima/visulima.git",
|
|
@@ -67,13 +72,13 @@
|
|
|
67
72
|
"url": "https://anolilab.com/support"
|
|
68
73
|
}
|
|
69
74
|
],
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
"sideEffects": false,
|
|
75
|
+
"files": [
|
|
76
|
+
"dist",
|
|
77
|
+
"README.md",
|
|
78
|
+
"CHANGELOG.md"
|
|
79
|
+
],
|
|
76
80
|
"type": "module",
|
|
81
|
+
"sideEffects": false,
|
|
77
82
|
"exports": {
|
|
78
83
|
".": {
|
|
79
84
|
"types": "./dist/index.d.ts",
|
|
@@ -257,11 +262,10 @@
|
|
|
257
262
|
},
|
|
258
263
|
"./package.json": "./package.json"
|
|
259
264
|
},
|
|
260
|
-
"
|
|
261
|
-
"
|
|
262
|
-
"
|
|
263
|
-
|
|
264
|
-
],
|
|
265
|
+
"publishConfig": {
|
|
266
|
+
"access": "public",
|
|
267
|
+
"provenance": true
|
|
268
|
+
},
|
|
265
269
|
"dependencies": {
|
|
266
270
|
"@visulima/disposable-email-domains": "1.0.0-alpha.13",
|
|
267
271
|
"html-to-text": "^10.0.0",
|
|
@@ -307,9 +311,5 @@
|
|
|
307
311
|
},
|
|
308
312
|
"engines": {
|
|
309
313
|
"node": "^22.14.0 || >=24.10.0"
|
|
310
|
-
},
|
|
311
|
-
"publishConfig": {
|
|
312
|
-
"access": "public",
|
|
313
|
-
"provenance": true
|
|
314
314
|
}
|
|
315
315
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import c from"./EmailError-zm2ffVav.js";import P from"./RequiredOptionError-CevW3u2K.js";import{s as I}from"./generate-message-id-D4uA8gkj.js";import{i as T}from"./headers-to-record-Qo124ImV.js";import{m as d}from"./make-request--BdZNxIl.js";import{c as A,P as k,u as g,h as f}from"./provider-base-Cmzx6BTO.js";import{a as $,s as z}from"./sanitize-header-wWav-Scu.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as j}from"./defineProvider-CtLH0VBE.js";import{n as u,c as h}from"./address-formatter-Cm_E_ZMa.js";const r="mailpace",C="https://app.mailpace.com/api/v1",M=3e4,S=3,G=j(((n={})=>{if(!n.apiToken)throw new P(r,"apiToken");const s={apiToken:n.apiToken,debug:n.debug??!1,endpoint:n.endpoint??C,retries:n.retries??S,timeout:n.timeout??M,...n.logger&&{logger:n.logger}},l=new k,i=A(r,n.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new c(r,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const a={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const t=await g(async()=>d(`${s.endpoint}/emails/${e}`,{headers:a,method:"GET",timeout:s.timeout}),s.retries);return t.success?(i.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(i.debug("API request failed when retrieving email",t.error),{error:new c(r,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(a){return{error:f(r,"retrieve email",a,i),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(r,"MailPace API not available or invalid API token");i.debug("Provider initialized successfully")},r)},async isAvailable(){try{const e={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"};i.debug("Checking MailPace API availability");const a=await d(`${s.endpoint}/account`,{headers:e,method:"GET",timeout:s.timeout});return i.debug("MailPace API availability check response:",{error:a.error instanceof Error?a.error.message:void 0,statusCode:a.data?.statusCode,success:a.success}),!!(a.success&&a.data&&typeof a.data=="object"&&"statusCode"in a.data&&typeof a.data.statusCode=="number"&&a.data.statusCode>=200&&a.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:r,options:s,async sendEmail(e){try{const a=E(e);if(a.length>0)return{error:new c(r,`Invalid email options: ${a.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),r);const t={from:h(e.from),subject:e.subject,to:u(e.to)};if(e.html&&(t.htmlbody=e.html),e.text&&(t.textbody=e.text),e.cc&&(t.cc=u(e.cc)),e.bcc&&(t.bcc=u(e.bcc)),e.replyTo&&(t.replyto=h(e.replyTo)),e.templateId&&(t.template_id=e.templateId,e.templateVariables&&(t.template_variables=e.templateVariables)),e.tags&&e.tags.length>0&&(t.tags=e.tags),e.listUnsubscribe&&(t.list_unsubscribe=e.listUnsubscribe),e.headers){const y=T(e.headers),p={};Object.entries(y).forEach(([v,w])=>{p[$(v)]=z(w)}),t.headers=p}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments),i.debug("Sending email via MailPace API",{subject:t.subject,to:t.to});const b={Authorization:`Bearer ${s.apiToken}`,"Content-Type":"application/json"},o=await g(async()=>d(`${s.endpoint}/send`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(t)),s.retries);if(!o.success)return i.debug("API request failed when sending email",o.error),{error:o.error??new c(r,"Failed to send email"),success:!1};const m=o.data?.body?.id??I();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:r,response:o.data,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:f(r,"send email",a,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}}));export{G as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var P=Object.defineProperty;var b=(s,a)=>P(s,"name",{value:a,configurable:!0});import{createRequire as $}from"node:module";import d from"./EmailError-zm2ffVav.js";import v from"./RequiredOptionError-CevW3u2K.js";import{s as M}from"./generate-message-id-D4uA8gkj.js";import{i as _}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request--BdZNxIl.js";import{c as z,P as D,u as w,h as T}from"./provider-base-Cmzx6BTO.js";import{d as B}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as R}from"./defineProvider-CtLH0VBE.js";import{d as y,e as S}from"./address-formatter-Cm_E_ZMa.js";const A=$(import.meta.url),m=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,E=b(s=>{if(typeof m<"u"&&m.versions&&m.versions.node){const[a,l]=m.versions.node.split(".").map(Number);if(a>22||a===22&&l>=3||a===20&&l>=16)return m.getBuiltinModule(s)}return A(s)},"__cjs_getBuiltinModule"),{Buffer:p}=E("node:buffer"),n="mailjet",k="https://api.mailjet.com",q=3e4,K=3,W=R(((s={})=>{if(!s.apiKey)throw new v(n,"apiKey");if(!s.apiSecret)throw new v(n,"apiSecret");const a={apiKey:s.apiKey,apiSecret:s.apiSecret,debug:s.debug??!1,endpoint:s.endpoint??k,retries:s.retries??K,timeout:s.timeout??q,...s.logger&&{logger:s.logger}},l=new D,o=z(n,s.logger);return{endpoint:a.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(n,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const i={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const t=await w(async()=>f(`${a.endpoint}/v3.1/REST/message/${e}`,{headers:i,method:"GET",timeout:a.timeout}),a.retries);return t.success?(o.debug("Email details retrieved successfully"),{data:t.data?.body,success:!0}):(o.debug("API request failed when retrieving email",t.error),{error:new d(n,`Failed to retrieve email: ${t.error instanceof Error?t.error.message:"Unknown error"}`,{cause:t.error}),success:!1})}catch(i){return{error:T(n,"retrieve email",i,o),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(n,"Mailjet API not available or invalid API credentials");o.debug("Provider initialized successfully")},n)},async isAvailable(){try{const e={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"};o.debug("Checking Mailjet API availability");const i=await f(`${a.endpoint}/v3.1/REST/user`,{headers:e,method:"GET",timeout:a.timeout});return o.debug("Mailjet API availability check response:",{error:i.error instanceof Error?i.error.message:void 0,statusCode:i.data?.statusCode,success:i.success}),!!(i.success&&i.data&&typeof i.data=="object"&&"statusCode"in i.data&&typeof i.data.statusCode=="number"&&i.data.statusCode>=200&&i.data.statusCode<300)}catch(e){return o.debug("Error checking availability:",e),!1}},name:n,options:a,async sendEmail(e){try{const i=B(e);if(i.length>0)return{error:new d(n,`Invalid email options: ${i.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const t={From:S(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=S(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 r=_(e.headers),c=[];for(const[g,I]of Object.entries(r))c.push({Name:g,Value:String(I)});c.length>0&&(t.Headers=c)}e.attachments&&e.attachments.length>0&&(t.Attachments=await Promise.all(e.attachments.map(async r=>{let c;if(r.content)if(typeof r.content=="string")c=r.content;else if(r.content instanceof Promise){const g=await r.content;c=p.from(g).toString("base64")}else c=r.content.toString("base64");else if(r.raw)c=typeof r.raw=="string"?r.raw:r.raw.toString("base64");else throw new d(n,`Attachment ${r.filename} has no content`);return{Base64Content:c,ContentType:r.contentType??"application/octet-stream",Filename:r.filename,...r.cid&&{ContentID:r.cid}}})));const j={Messages:[t]};o.debug("Sending email via Mailjet API",{subject:t.Subject,to:t.To});const C={Authorization:`Basic ${p.from(`${a.apiKey}:${a.apiSecret}`).toString("base64")}`,"Content-Type":"application/json"},u=await w(async()=>f(`${a.endpoint}/v3.1/send`,{headers:C,method:"POST",timeout:a.timeout},JSON.stringify(j)),a.retries);if(!u.success)return o.debug("API request failed when sending email",u.error),{error:u.error??new d(n,"Failed to send email"),success:!1};const h=u.data?.body?.Messages?.[0]?.To?.[0]?.MessageID?.toString()??M();return o.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:n,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(i){return{error:T(n,"send email",i,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}}));export{W as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var I=Object.defineProperty;var h=(r,a)=>I(r,"name",{value:a,configurable:!0});import c from"./EmailError-zm2ffVav.js";import P from"./RequiredOptionError-CevW3u2K.js";import{s as $}from"./generate-message-id-D4uA8gkj.js";import{i as j}from"./headers-to-record-Qo124ImV.js";import{m as f}from"./make-request--BdZNxIl.js";import{c as T,P as C,u as y,h as b}from"./provider-base-Cmzx6BTO.js";import{d as E}from"./validate-email-options-DPo3SgC0.js";import{defineProvider as S}from"./defineProvider-CtLH0VBE.js";import{b as z,c as v,l as w}from"./address-formatter-Cm_E_ZMa.js";var k=Object.defineProperty,K=h((r,a)=>k(r,"name",{value:a,configurable:!0}),"p");const n="resend",R="https://api.resend.com",_=3e4,x=3,D=K(r=>{const a=[],l=/^[\w-]+$/;return l.test(r.name)||a.push(`Tag name '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r.name.length>256&&a.push(`Tag name '${r.name}' exceeds maximum length of 256 characters`),l.test(r.value)||a.push(`Tag value '${r.value}' for tag '${r.name}' must only contain ASCII letters, numbers, underscores, or dashes`),a},"validateTag"),W=S(((r={})=>{if(!r.apiKey)throw new P(n,"apiKey");const a={apiKey:r.apiKey,debug:r.debug??!1,endpoint:r.endpoint??R,logger:r.logger,retries:r.retries??x,timeout:r.timeout??_},l=new C,o=T(n,r.logger);return{endpoint:a.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(n,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const t={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};o.debug("Retrieving email details",{id:e});const i=await y(async()=>f(`${a.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:a.timeout}),a.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(n,`Failed to retrieve email: ${i.error instanceof Error?i.error.message:"Unknown error"}`,{cause:i.error}),success:!1})}catch(t){return{error:b(n,"retrieve email",t,o),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(n,"Resend API not available or invalid API key");o.debug("Provider initialized successfully")},n)},async isAvailable(){try{if(a.apiKey&&a.apiKey.startsWith("re_"))return o.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"};o.debug("Checking Resend API availability");const t=await f(`${a.endpoint}/domains`,{headers:e,method:"GET",timeout:a.timeout});return t.data&&typeof t.data=="object"&&"body"in t.data&&t.data.body&&typeof t.data.body=="object"&&"name"in t.data.body&&t.data.body.name==="restricted_api_key"?(o.debug("API key is valid but restricted to only sending emails"),!0):(o.debug("Resend API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300))}catch(e){return o.debug("Error checking availability:",e),!1}},name:n,options:a,async sendEmail(e){try{const t=E(e);if(t.length>0)return{error:new c(n,`Invalid email options: ${t.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),n);const i={from:v(e.from),headers:e.headers?j(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:z(e.to)};if(e.cc&&(i.cc=w(e.cc)),e.bcc&&(i.bcc=w(e.bcc)),e.replyTo&&(i.reply_to=v(e.replyTo)),e.templateId&&(i.template=e.templateId,e.templateData&&(i.data=e.templateData)),e.scheduledAt&&(i.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const s=[];if(e.tags.forEach(d=>{const p=D(d);p.length>0&&s.push(...p)}),s.length>0)return{error:new c(n,`Invalid email tags: ${s.join(", ")}`),success:!1};i.tags=e.tags.map(d=>({name:d.name,value:d.value}))}e.attachments&&e.attachments.length>0&&(i.attachments=await Promise.all(e.attachments.map(async s=>{let d;if(s.content)if(typeof s.content=="string")d=s.content;else if(s.content instanceof Promise){const p=await s.content;d=Buffer.from(p).toString("base64")}else d=s.content.toString("base64");else if(s.raw)d=typeof s.raw=="string"?s.raw:s.raw.toString("base64");else throw new c(n,`Attachment ${s.filename} has no content`);return{content:d,content_type:s.contentType,filename:s.filename,...s.path&&{path:s.path}}}))),o.debug("Sending email via Resend API",{subject:i.subject,to:i.to});const A={Authorization:`Bearer ${a.apiKey}`,"Content-Type":"application/json"},u=await y(async()=>f(`${a.endpoint}/emails`,{headers:A,method:"POST",timeout:a.timeout},JSON.stringify(i)),a.retries);if(!u.success)return o.debug("API request failed when sending email",u.error),{error:u.error??new c(n,"Failed to send email"),success:!1};const m=u.data,g=m?.body&&typeof m.body=="object"&&m.body.id?m.body.id:$();return o.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:n,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:b(n,"send email",t,o),success:!1}}},async validateCredentials(){return this.isAvailable()}}}));export{W as default};
|