@visulima/email 4.1.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +17 -0
  3. package/dist/crypto/index.d.ts +2 -2
  4. package/dist/deliverability/index.d.ts +1 -1
  5. package/dist/inbound/index.d.ts +1 -1
  6. package/dist/index.d.ts +5 -5
  7. package/dist/index.js +1 -1
  8. package/dist/middleware/index.d.ts +4 -4
  9. package/dist/packem_chunks/index.js +1 -1
  10. package/dist/packem_shared/{DraftMailMessage-B0gwf8n_.js → DraftMailMessage-zkKTOxQ8.js} +1 -1
  11. package/dist/packem_shared/Mail-DtpXUSIl.js +1 -0
  12. package/dist/packem_shared/MailMessage-Aw0vVAh-.js +1 -0
  13. package/dist/packem_shared/{createTestEmail-DWimjf0F.js → createTestEmail-B2Fz-Ifb.js} +1 -1
  14. package/dist/packem_shared/{mail.d-BdyyyQO5.d.ts → mail.d-2u-30lWz.d.ts} +12 -4
  15. package/dist/packem_shared/{provider.d-Cx5YQJdP.d.ts → provider.d-BLLbEuQ8.d.ts} +1 -1
  16. package/dist/packem_shared/resendProvider-BaIZCvph.js +1 -0
  17. package/dist/packem_shared/{tracer.d-sb5yrt_n.d.ts → tracer.d-B103E-TW.d.ts} +84 -32
  18. package/dist/packem_shared/{types.d-Cb5fls_X.d.ts → types.d-A1Eea-p_.d.ts} +1 -1
  19. package/dist/packem_shared/{types.d-kHO4kX9q.d.ts → types.d-B5iH_mgb.d.ts} +1 -1
  20. package/dist/packem_shared/{types.d-GKqPNk0I.d.ts → types.d-Chhzb-48.d.ts} +1 -1
  21. package/dist/packem_shared/{types.d-B9295M4_.d.ts → types.d-CyiC9uRC.d.ts} +10 -0
  22. package/dist/packem_shared/{types.d-C5geVKes.d.ts → types.d-V_yuAOrx.d.ts} +1 -1
  23. package/dist/providers/ahasend/index.d.ts +3 -3
  24. package/dist/providers/autosend/index.d.ts +3 -3
  25. package/dist/providers/aws-ses/index.d.ts +3 -3
  26. package/dist/providers/azure/index.d.ts +3 -3
  27. package/dist/providers/brevo/index.d.ts +3 -3
  28. package/dist/providers/cloudflare-email/index.d.ts +4 -4
  29. package/dist/providers/failover/index.d.ts +3 -3
  30. package/dist/providers/file/index.d.ts +3 -3
  31. package/dist/providers/http/index.d.ts +3 -3
  32. package/dist/providers/infobip/index.d.ts +3 -3
  33. package/dist/providers/loops/index.d.ts +3 -3
  34. package/dist/providers/mailchannels/index.d.ts +3 -3
  35. package/dist/providers/mailcrab/index.d.ts +3 -3
  36. package/dist/providers/mailersend/index.d.ts +3 -3
  37. package/dist/providers/mailgun/index.d.ts +3 -3
  38. package/dist/providers/mailjet/index.d.ts +3 -3
  39. package/dist/providers/mailomat/index.d.ts +3 -3
  40. package/dist/providers/mailpace/index.d.ts +3 -3
  41. package/dist/providers/mailtrap/index.d.ts +3 -3
  42. package/dist/providers/mandrill/index.d.ts +3 -3
  43. package/dist/providers/mock/index.d.ts +5 -5
  44. package/dist/providers/netcore/index.d.ts +3 -3
  45. package/dist/providers/nodemailer/index.d.ts +3 -3
  46. package/dist/providers/opentelemetry/index.d.ts +3 -3
  47. package/dist/providers/outlook365/index.d.ts +3 -3
  48. package/dist/providers/plunk/index.d.ts +3 -3
  49. package/dist/providers/postal/index.d.ts +3 -3
  50. package/dist/providers/postmark/index.d.ts +3 -3
  51. package/dist/providers/resend/index.d.ts +3 -3
  52. package/dist/providers/resend/index.js +1 -1
  53. package/dist/providers/roundrobin/index.d.ts +3 -3
  54. package/dist/providers/scaleway/index.d.ts +3 -3
  55. package/dist/providers/sendgrid/index.d.ts +3 -3
  56. package/dist/providers/smtp/index.d.ts +4 -4
  57. package/dist/providers/sparkpost/index.d.ts +3 -3
  58. package/dist/providers/sweego/index.d.ts +3 -3
  59. package/dist/providers/zeptomail/index.d.ts +3 -3
  60. package/dist/queue/bullmq-queue.d.ts +2 -2
  61. package/dist/queue/index.d.ts +2 -2
  62. package/dist/queue/pg-boss-queue.d.ts +2 -2
  63. package/dist/queue/sqs-queue.d.ts +2 -2
  64. package/dist/queue/unstorage-queue.d.ts +2 -2
  65. package/dist/test/index.d.ts +6 -6
  66. package/dist/test/index.js +1 -1
  67. package/dist/utils/format-email-address.d.ts +1 -1
  68. package/dist/utils/parse-address.d.ts +1 -1
  69. package/dist/utils/parse-eml.d.ts +1 -1
  70. package/dist/utils/result.d.ts +1 -1
  71. package/dist/utils/validation/check-feature-support.d.ts +1 -1
  72. package/dist/utils/validation/check-feature-support.js +1 -1
  73. package/package.json +5 -5
  74. package/dist/packem_shared/Mail-0cxS6jre.js +0 -1
  75. package/dist/packem_shared/MailMessage-DmmaNHHc.js +0 -1
  76. package/dist/packem_shared/resendProvider-DC7Op5Gr.js +0 -1
@@ -1,6 +1,6 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
4
4
  import 'node:buffer';
5
5
  /**
6
6
  * Scaleway configuration
@@ -1,6 +1,6 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
4
4
  import 'node:buffer';
5
5
  /**
6
6
  * SendGrid configuration
@@ -1,7 +1,7 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { D as DkimOptions } from "../../packem_shared/types.d-Cb5fls_X.js";
4
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { D as DkimOptions } from "../../packem_shared/types.d-A1Eea-p_.js";
4
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
5
5
  import 'node:buffer';
6
6
  /**
7
7
  * SMTP configuration
@@ -1,6 +1,6 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
4
4
  import 'node:buffer';
5
5
  /**
6
6
  * SparkPost configuration.
@@ -1,6 +1,6 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
4
4
  import 'node:buffer';
5
5
  /**
6
6
  * Sweego configuration
@@ -1,6 +1,6 @@
1
- import { P as ProviderFactory } from "../../packem_shared/provider.d-Cx5YQJdP.js";
2
- export type { a as Provider } from "../../packem_shared/provider.d-Cx5YQJdP.js";
3
- import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { P as ProviderFactory } from "../../packem_shared/provider.d-BLLbEuQ8.js";
2
+ export type { a as Provider } from "../../packem_shared/provider.d-BLLbEuQ8.js";
3
+ import { B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
4
4
  import 'node:buffer';
5
5
  /**
6
6
  * Zeptomail configuration
@@ -1,5 +1,5 @@
1
- import { E as EmailOptions, a as EmailResult, R as Result } from "../packem_shared/types.d-B9295M4_.js";
2
- import { E as EnqueueOptions } from "../packem_shared/types.d-kHO4kX9q.js";
1
+ import { E as EmailOptions, a as EmailResult, R as Result } from "../packem_shared/types.d-CyiC9uRC.js";
2
+ import { E as EnqueueOptions } from "../packem_shared/types.d-B5iH_mgb.js";
3
3
  import 'node:buffer';
4
4
  /**
5
5
  * The subset of a [BullMQ](https://docs.bullmq.io/) `Queue` this adapter uses.
@@ -1,5 +1,5 @@
1
- import { E as EmailOptions, a as EmailResult, R as Result } from "../packem_shared/types.d-B9295M4_.js";
2
- import { E as EnqueueOptions, Q as QueueJob, a as EmailQueue } from "../packem_shared/types.d-kHO4kX9q.js";
1
+ import { E as EmailOptions, a as EmailResult, R as Result } from "../packem_shared/types.d-CyiC9uRC.js";
2
+ import { E as EnqueueOptions, Q as QueueJob, a as EmailQueue } from "../packem_shared/types.d-B5iH_mgb.js";
3
3
  export { UnstorageQueue, type UnstorageQueueOptions, createUnstorageQueue } from "./unstorage-queue.js";
4
4
  import 'node:buffer';
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { a as EmailQueue } from "../packem_shared/types.d-kHO4kX9q.js";
2
- import "../packem_shared/types.d-B9295M4_.js";
1
+ import { a as EmailQueue } from "../packem_shared/types.d-B5iH_mgb.js";
2
+ import "../packem_shared/types.d-CyiC9uRC.js";
3
3
  import 'node:buffer';
4
4
  interface PgBossJob {
5
5
  data: unknown;
@@ -1,5 +1,5 @@
1
- import { a as EmailQueue } from "../packem_shared/types.d-kHO4kX9q.js";
2
- import "../packem_shared/types.d-B9295M4_.js";
1
+ import { a as EmailQueue } from "../packem_shared/types.d-B5iH_mgb.js";
2
+ import "../packem_shared/types.d-CyiC9uRC.js";
3
3
  import 'node:buffer';
4
4
  /**
5
5
  * The subset of the `@aws-sdk/client-sqs` `SQS` client this adapter uses. The `SQS` class (not the
@@ -1,5 +1,5 @@
1
- import { E as EmailOptions } from "../packem_shared/types.d-B9295M4_.js";
2
- import { E as EnqueueOptions, Q as QueueJob, a as EmailQueue } from "../packem_shared/types.d-kHO4kX9q.js";
1
+ import { E as EmailOptions } from "../packem_shared/types.d-CyiC9uRC.js";
2
+ import { E as EnqueueOptions, Q as QueueJob, a as EmailQueue } from "../packem_shared/types.d-B5iH_mgb.js";
3
3
  import 'node:buffer';
4
4
  type StorageValue = null | string | number | boolean | object;
5
5
  type WatchEvent = "update" | "remove";
@@ -1,12 +1,12 @@
1
- import { E as EmailOptions } from "../packem_shared/types.d-B9295M4_.js";
2
- import { a as MockEmailEntry } from "../packem_shared/types.d-C5geVKes.js";
3
- import { M as Mail } from "../packem_shared/mail.d-BdyyyQO5.js";
1
+ import { E as EmailOptions } from "../packem_shared/types.d-CyiC9uRC.js";
2
+ import { a as MockEmailEntry } from "../packem_shared/types.d-V_yuAOrx.js";
3
+ import { M as Mail } from "../packem_shared/mail.d-2u-30lWz.js";
4
4
  import 'node:buffer';
5
5
  import 'ical-generator';
6
6
  import "../packem_shared/types.d-I-KeZ5w2.js";
7
- import "../packem_shared/types.d-Cb5fls_X.js";
8
- import "../packem_shared/types.d-GKqPNk0I.js";
9
- import "../packem_shared/provider.d-Cx5YQJdP.js";
7
+ import "../packem_shared/types.d-A1Eea-p_.js";
8
+ import "../packem_shared/types.d-Chhzb-48.js";
9
+ import "../packem_shared/provider.d-BLLbEuQ8.js";
10
10
  /**
11
11
  * Returns the http(s) URLs in a message without duplicates, in this order: `href` targets of
12
12
  * anchor and area elements in the HTML, bare URLs in the visible HTML text, then bare URLs in the
@@ -1 +1 @@
1
- import{default as a}from"../packem_shared/extractLinks-BwE1SjNF.js";import{emailMatchers as r,registerEmailMatchers as i,toHaveSentMatching as m,toHaveSentTo as n,toHaveSentWithAttachment as c,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DpwItmkN.js";import{toEmailSnapshot as S}from"../packem_shared/toEmailSnapshot-BOhTn44E.js";import{createTestEmail as l}from"../packem_shared/createTestEmail-DWimjf0F.js";export{l as createTestEmail,r as emailMatchers,a as extractLinks,i as registerEmailMatchers,S as toEmailSnapshot,m as toHaveSentMatching,n as toHaveSentTo,c as toHaveSentWithAttachment,h as toHaveSentWithSubject};
1
+ import{default as a}from"../packem_shared/extractLinks-BwE1SjNF.js";import{emailMatchers as r,registerEmailMatchers as i,toHaveSentMatching as m,toHaveSentTo as n,toHaveSentWithAttachment as c,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DpwItmkN.js";import{toEmailSnapshot as S}from"../packem_shared/toEmailSnapshot-BOhTn44E.js";import{createTestEmail as l}from"../packem_shared/createTestEmail-B2Fz-Ifb.js";export{l as createTestEmail,r as emailMatchers,a as extractLinks,i as registerEmailMatchers,S as toEmailSnapshot,m as toHaveSentMatching,n as toHaveSentTo,c as toHaveSentWithAttachment,h as toHaveSentWithSubject};
@@ -1,4 +1,4 @@
1
- import { c as EmailAddress } from "../packem_shared/types.d-B9295M4_.js";
1
+ import { c as EmailAddress } from "../packem_shared/types.d-CyiC9uRC.js";
2
2
  import 'node:buffer';
3
3
  /**
4
4
  * Formats an email address as "Name <email@example.com>" or just "email@example.com" if no name is provided.
@@ -1,4 +1,4 @@
1
- import { c as EmailAddress } from "../packem_shared/types.d-B9295M4_.js";
1
+ import { c as EmailAddress } from "../packem_shared/types.d-CyiC9uRC.js";
2
2
  import 'node:buffer';
3
3
  /**
4
4
  * Parses a string representation of an email address into an EmailAddress object.
@@ -1,4 +1,4 @@
1
- import { E as EmailOptions } from "../packem_shared/types.d-B9295M4_.js";
1
+ import { E as EmailOptions } from "../packem_shared/types.d-CyiC9uRC.js";
2
2
  import 'node:buffer';
3
3
  /**
4
4
  * Parses a raw EML / RFC 5322 MIME message back into {@link EmailOptions}.
@@ -1,4 +1,4 @@
1
- import { R as Result } from "../packem_shared/types.d-B9295M4_.js";
1
+ import { R as Result } from "../packem_shared/types.d-CyiC9uRC.js";
2
2
  import 'node:buffer';
3
3
  /**
4
4
  * A successful {@link Result} with its data narrowed to be present.
@@ -1,4 +1,4 @@
1
- import { F as FeatureFlags, E as EmailOptions } from "../../packem_shared/types.d-B9295M4_.js";
1
+ import { F as FeatureFlags, E as EmailOptions } from "../../packem_shared/types.d-CyiC9uRC.js";
2
2
  import 'node:buffer';
3
3
  /**
4
4
  * A single capability that a message uses but the target provider cannot represent.
@@ -1 +1 @@
1
- import{h as o}from"../../packem_shared/headers-to-record-ZOZ7Dubo.js";const d=e=>Array.isArray(e)&&e.length>0,l=(e,r)=>r.find(t=>e[t]!==void 0),c=[{detect:e=>d(e.attachments)?"attachments":void 0,feature:"attachments",label:"attachments"},{detect:e=>typeof e.html=="string"&&e.html.length>0?"html":void 0,feature:"html",label:"HTML content"},{detect:e=>e.replyTo?"replyTo":void 0,feature:"replyTo",label:"a reply-to address"},{detect:e=>e.headers!==void 0&&Object.keys(o(e.headers)).length>0?"headers":void 0,feature:"customHeaders",label:"custom headers"},{detect:e=>d(e.tags)?"tags":void 0,feature:"tagging",label:"tags"},{detect:e=>l(e,["scheduledAt","sendAt"]),feature:"scheduling",label:"scheduled delivery"},{detect:e=>l(e,["templateId","template"]),feature:"templates",label:"provider templates"}];function n(e,r){if(!r)return{supported:!0,violations:[]};const t=[];for(const a of c){if(r[a.feature]!==!1)continue;const s=a.detect(e);s!==void 0&&t.push({feature:a.feature,field:s,message:`Message uses ${a.label} (field "${s}") but the provider does not support the "${a.feature}" capability`})}return{supported:t.length===0,violations:t}}export{n as default};
1
+ import{h as l}from"../../packem_shared/headers-to-record-ZOZ7Dubo.js";const s=e=>Array.isArray(e)&&e.length>0,o=(e,d)=>d.find(t=>e[t]!==void 0),c=[{detect:e=>s(e.attachments)?"attachments":void 0,feature:"attachments",label:"attachments"},{detect:e=>typeof e.html=="string"&&e.html.length>0?"html":void 0,feature:"html",label:"HTML content"},{detect:e=>e.replyTo?"replyTo":void 0,feature:"replyTo",label:"a reply-to address"},{detect:e=>e.headers!==void 0&&Object.keys(l(e.headers)).length>0?"headers":void 0,feature:"customHeaders",label:"custom headers"},{detect:e=>s(e.tags)?"tags":void 0,feature:"tagging",label:"tags"},{detect:e=>e.idempotencyKey===void 0?void 0:"idempotencyKey",feature:"idempotency",label:"an idempotency key"},{detect:e=>o(e,["scheduledAt","sendAt"]),feature:"scheduling",label:"scheduled delivery"},{detect:e=>o(e,["templateId","template"]),feature:"templates",label:"provider templates"}];function n(e,d){if(!d)return{supported:!0,violations:[]};const t=[];for(const a of c){if(d[a.feature]!==!1)continue;const r=a.detect(e);r!==void 0&&t.push({feature:a.feature,field:r,message:`Message uses ${a.label} (field "${r}") but the provider does not support the "${a.feature}" capability`})}return{supported:t.length===0,violations:t}}export{n as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/email",
3
- "version": "4.1.0",
3
+ "version": "4.2.1",
4
4
  "description": "A comprehensive email library with multi-provider support, crypto utilities, and template engines",
5
5
  "keywords": [
6
6
  "ahasend",
@@ -378,14 +378,14 @@
378
378
  "CHANGELOG.md"
379
379
  ],
380
380
  "dependencies": {
381
- "html-to-text": "^10.0.0",
382
- "ical-generator": "11.1.0",
381
+ "html-to-text": "^10.0.1",
382
+ "ical-generator": "11.1.3",
383
383
  "lru-cache": "11.5.3",
384
- "mime": "^4.1.0"
384
+ "mime": "^4.1.2"
385
385
  },
386
386
  "peerDependencies": {
387
387
  "@opentelemetry/api": "^1.0.0 || ^2.0.0",
388
- "@react-email/render": "^2.1.0",
388
+ "@react-email/render": "^2.2.0",
389
389
  "@vue-email/render": "0.0.9",
390
390
  "asn1js": ">=3.0.10",
391
391
  "fast-xml-parser": "^4.5.0 || ^5.0.0",
@@ -1 +0,0 @@
1
- import f from"./DraftMailMessage-B0gwf8n_.js";import v from"./EmailError-SXEFQEyA.js";import u from"./MailMessage-DmmaNHHc.js";import{composeMiddleware as w}from"./composeMiddleware-B3RCDFsy.js";import{b as C}from"./build-mime-message-D45WdgfP.js";import{c as M}from"./create-logger-CazqtXcL.js";import{h as d}from"./headers-to-record-ZOZ7Dubo.js";import T from"../utils/validation/check-feature-support.js";const S=(a,e,r)=>{e.success&&e.data?a&&a.info("Email sent successfully",{messageId:e.data.messageId,provider:e.data.provider}):a&&a.error("Email send failed",{error:e.error,provider:r})},E=async(a,e,r)=>{const t={...a,to:e.to};return e.cc&&(t.cc=e.cc),e.bcc&&(t.bcc=e.bcc),e.replyTo&&(t.replyTo=e.replyTo),e.headers&&(t.headers={...d(a.headers??{}),...d(e.headers)}),t.subject=e.subject??a.subject,r&&e.data&&(t.subject=await r(t.subject,e.data),a.html!==void 0&&(t.html=await r(a.html,e.data)),a.text!==void 0&&(t.text=await r(a.text,e.data))),t};class h{static extractErrorMessages(e){return e instanceof Error?[e.message]:[String(e??"Unknown error")]}provider;logger;loggerInstance;globalConfig;featureCheck;middlewares=[];composedSend;mountedProviders=new Map;constructor(e,r){this.provider=e,this.featureCheck=r?.featureCheck??"error"}setLogger(e){return this.loggerInstance=e,this.logger=M("Mail",e),this}use(e){return this.middlewares.push(e),this.composedSend=void 0,this}mount(e,r){return this.mountedProviders.set(e,r),this}setFrom(e){return this.globalConfig??={},this.globalConfig.from=e,this.logger&&this.logger.debug("Default from address updated",{from:e.email}),this}setReplyTo(e){return this.globalConfig??={},this.globalConfig.replyTo=e,this.logger&&this.logger.debug("Default reply-to address updated",{replyTo:e.email}),this}setHeaders(e){if(this.globalConfig??={},this.globalConfig.headers=e,this.logger){const r=d(e);this.logger.debug("Default headers updated",{count:Object.keys(r).length,headers:Object.keys(r)})}return this}async draft(e){let r=e instanceof u||e instanceof f?await this.buildDraftFromMessage(e):await this.buildDraftFromOptions(e);r=this.applyGlobalConfig(r);const t=r.headers?d(r.headers):{};r.headers={...t,"X-Unsent":"1"};const s=await C(r,{includeBcc:!0});return this.logger&&this.logger.debug("Draft created successfully in EML format",{from:r.from.email,size:s.length,subject:r.subject,to:Array.isArray(r.to)?r.to.length:1}),s}async send(e){if(e instanceof f)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");let r;if(e instanceof u)this.logger&&this.logger.debug("Sending MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),r=await e.build();else{const o=e;this.logger&&this.logger.debug("Sending email with options",{subject:o.subject,to:Array.isArray(o.to)?o.to.length:1}),r=o}r=this.applyGlobalConfig(r);const t=this.assertFeatureSupport(r,this.resolveProvider(r));if(t)return{error:t,success:!1};const s=await this.dispatch(r);return S(this.logger,s,this.provider.name??"unknown"),s}sendMany(e,r){const t=Math.max(1,Math.floor(r?.concurrency??1));return t===1?this.sendManySerial(e,r?.signal):this.sendManyConcurrent(e,t,r?.signal)}sendBatch(e,r,t){const s=async function*(){const o=e instanceof u?await e.build():e;for(const i of r)yield await E(o,i,t?.render)};return this.sendMany(s(),{concurrency:t?.concurrency,signal:t?.signal})}async sendOneToReceipt(e){const r=this.provider.name;try{const t=await this.send(e);return t.success&&t.data?{messageId:t.data.messageId,provider:t.data.provider??r,response:t.data.response,successful:!0,timestamp:t.data.timestamp}:{errorMessages:h.extractErrorMessages(t.error),provider:r,successful:!1}}catch(t){return{errorMessages:h.extractErrorMessages(t),provider:r,successful:!1}}}async*sendManySerial(e,r){const t=this.provider.name;let s=0,o=0,i=0;this.logger&&this.logger.debug("Starting batch email send",{provider:t});for await(const l of e){if(l instanceof f)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");if(r?.aborted){this.logger&&this.logger.warn("Batch send operation was aborted",{failed:i,processed:s,successful:o}),yield{errorMessages:["Send operation was aborted"],provider:t,successful:!1};return}s+=1;const n=await this.sendOneToReceipt(l);n.successful?o+=1:i+=1,yield n}this.logger&&this.logger.debug("Batch email send completed",{failureCount:i,processedCount:s,provider:t,successCount:o})}async*sendManyConcurrent(e,r,t){const s=this.provider.name;this.logger&&this.logger.debug("Starting concurrent batch email send",{concurrency:r,provider:s});const o=Symbol.asyncIterator in e?e[Symbol.asyncIterator]():e[Symbol.iterator](),i=new Map;let l=0,n=!1,p=!1;const m=async()=>{for(;!n&&!p&&i.size<r;){const g=await o.next();if(g.done){n=!0;break}const c=g.value;if(c instanceof f)throw new TypeError("Cannot send draft messages. Convert to MailMessage first or remove X-Unsent header.");const b=l;l+=1,i.set(b,this.sendOneToReceipt(c).then(y=>({id:b,receipt:y})))}};for(await m();i.size>0;){if(t?.aborted){p=!0,yield{errorMessages:["Send operation was aborted"],provider:s,successful:!1};return}const{id:g,receipt:c}=await Promise.race(i.values());i.delete(g),yield c,await m()}this.logger&&this.logger.debug("Concurrent batch email send completed",{processedCount:l,provider:s})}async dispatch(e){return this.middlewares.length===0?await this.resolveProvider(e).sendEmail(e):(this.composedSend??=w(this.middlewares,r=>Promise.resolve(this.resolveProvider(r).sendEmail(r))),await this.composedSend(e))}resolveProvider(e){return e.stream!==void 0?this.mountedProviders.get(e.stream)??this.provider:this.provider}assertFeatureSupport(e,r){if(this.featureCheck==="off")return;const{supported:t,violations:s}=T(e,r.features);if(t)return;const o=r.name??"unknown",i=s.map(n=>n.field),l=s.map(n=>n.message);if(this.featureCheck==="warn"){this.logger&&this.logger.warn("Message uses capabilities the provider does not support",{fields:i,provider:o});return}return this.logger&&this.logger.error("Message rejected by capability guard",{fields:i,provider:o}),new v(o,`Provider does not support the following message fields: ${i.join(", ")}`,{code:"UNSUPPORTED_FEATURES",hint:l})}async buildDraftFromMessage(e){return this.logger&&this.logger.debug("Creating draft from MailMessage instance"),this.loggerInstance&&e.setLogger(this.loggerInstance),this.applyGlobalConfigToMessage(e),await e.build()}async buildDraftFromOptions(e){return this.logger&&this.logger.debug("Creating draft from email options",{subject:e.subject,to:Array.isArray(e.to)?e.to.length:1}),e}applyGlobalConfigToMessage(e){const r=this.globalConfig?.from;r&&!e.getFrom()&&e.from(r);const t=this.globalConfig?.replyTo;if(t&&!e.getReplyTo()&&e.replyTo(t),this.globalConfig?.headers){const s=d(this.globalConfig.headers);Object.entries(s).forEach(([o,i])=>{e.header(o,i)})}}applyGlobalConfig(e){if(!this.globalConfig)return e;const r={...e};if(!r.from&&this.globalConfig.from&&(r.from=this.globalConfig.from,this.logger&&this.logger.debug("Applied global from address",{from:this.globalConfig.from.email})),!r.replyTo&&this.globalConfig.replyTo&&(r.replyTo=this.globalConfig.replyTo,this.logger&&this.logger.debug("Applied global reply-to address",{replyTo:this.globalConfig.replyTo.email})),this.globalConfig.headers){const t=d(this.globalConfig.headers),s=r.headers?d(r.headers):{};r.headers={...t,...s},this.logger&&this.logger.debug("Merged global headers",{globalCount:Object.keys(t).length,messageCount:Object.keys(s).length})}return r}}const O=(a,e)=>new h(a,e);export{h as Mail,O as createMail};
@@ -1 +0,0 @@
1
- import{createRequire as p}from"node:module";import{readFileAsBuffer as c,detectMimeType as d,generateContentId as u}from"./detectMimeType-BRz3Qjyz.js";import{c as T}from"./create-logger-CazqtXcL.js";import{h as l}from"./headers-to-record-ZOZ7Dubo.js";let y;const A=n=>(y??=p(import.meta.url))(n),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,f=n=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[t,e]=o.versions.node.split(".").map(Number);if(t>22||t===22&&e>=3||t===20&&e>=16)return o.getBuiltinModule(n)}return A(n)},{basename:g}=f("node:path"),{fileURLToPath:b}=f("node:url"),m=async()=>(await import("../template-engines/html-to-text.js")).default,x=async()=>(await import("ical-generator")).default,a=n=>Array.isArray(n)?n.map(t=>typeof t=="string"?{email:t}:t):typeof n=="string"?[{email:n}]:[n];class D{fromAddress;toAddresses=[];ccAddresses=[];bccAddresses=[];subjectText="";textContent;textCharset="utf8";autoTextEnabled=!0;htmlContent;htmlCharset="utf8";dateValue;returnPathAddress;senderAddress;headers={};attachments=[];replyToAddress;priorityValue;tagsValue=[];signer;encrypter;logger;icalEventData;icalEventBuilder;from(t){return this.fromAddress=typeof t=="string"?{email:t}:t,this}to(t){return this.toAddresses.length=0,this.toAddresses.push(...a(t)),this}cc(t){return this.ccAddresses.length=0,this.ccAddresses.push(...a(t)),this}bcc(t){return this.bccAddresses.length=0,this.bccAddresses.push(...a(t)),this}subject(t){return this.subjectText=t,this}text(t,e="utf8"){return this.textContent=t,this.textCharset=e,this}html(t,e="utf8"){return this.htmlContent=t,this.htmlCharset=e,this}header(t,e){return this.headers[t]=e,this}setHeaders(t){const e=l(t);return Object.assign(this.headers,e),this}async attachFromPath(t,e){try{const r=await c(t),i=e?.filename??(g(t)||"attachment"),s=e?.contentType??d(i);this.attachments.push({cid:e?.cid,content:r,contentDisposition:e?.contentDisposition??"attachment",contentType:s,encoding:e?.encoding,filename:i,headers:e?.headers}),this.logger&&this.logger.debug(`Attachment added from path: ${t}`,{contentType:s,filename:i})}catch(r){throw this.logger&&this.logger.error(`Failed to attach file from path: ${t}`,r),r}return this}attachData(t,e){const r=e.contentType??d(e.filename);return this.attachments.push({cid:e.cid,content:t,contentDisposition:e.contentDisposition??"attachment",contentType:r,encoding:e.encoding,filename:e.filename,headers:e.headers}),this.logger&&this.logger.debug("Attachment added from data",{contentType:r,filename:e.filename}),this}async embedFromPath(t,e){try{const r=await c(t),i=e?.filename??(g(t)||"inline"),s=e?.contentType??d(i),h=u(i);return this.attachments.push({cid:h,content:r,contentDisposition:"inline",contentType:s,filename:i}),this.logger&&this.logger.debug(`Inline attachment embedded from path: ${t}`,{cid:h,contentType:s,filename:i}),h}catch(r){throw this.logger&&this.logger.error(`Failed to embed file from path: ${t}`,r),r}}embedData(t,e,r){const i=r?.contentType??d(e),s=u(e);return this.attachments.push({cid:s,content:t,contentDisposition:"inline",contentType:i,filename:e}),this.logger&&this.logger.debug("Inline attachment embedded from data",{cid:s,contentType:i,filename:e}),s}replyTo(t){return this.replyToAddress=typeof t=="string"?{email:t}:t,this}date(t){return this.dateValue=typeof t=="string"?new Date(t):t,this.logger&&this.logger.debug("Date header set",{date:this.dateValue.toISOString()}),this}returnPath(t){return this.returnPathAddress=typeof t=="string"?{email:t}:t,this.logger&&this.logger.debug("Return-path address set",{returnPath:this.returnPathAddress.email}),this}sender(t){return this.senderAddress=typeof t=="string"?{email:t}:t,this.logger&&this.logger.debug("Sender address set",{sender:this.senderAddress.email}),this}addTo(t){return this.toAddresses.push(...a(t)),this}addCc(t){return this.ccAddresses.push(...a(t)),this}addBcc(t){return this.bccAddresses.push(...a(t)),this}addReplyTo(t){const e=Array.isArray(t)?t:[t];if(e.length>0){const r=e[0];this.replyToAddress=typeof r=="string"?{email:r}:r}return this}addFrom(t){const e=Array.isArray(t)?t:[t];if(e.length>0){const r=e[0];this.fromAddress=typeof r=="string"?{email:r}:r}return this}priority(t){return this.priorityValue=t,this}tags(t){return this.tagsValue=Array.isArray(t)?t:[t],this}sign(t){return this.signer=t,this.logger&&this.logger.debug("Email signer configured"),this}encrypt(t){return this.encrypter=t,this.logger&&this.logger.debug("Email encrypter configured"),this}setLogger(t){return this.logger=T("MailMessage",t),this}icalEvent(t,e){return typeof t=="function"?(this.icalEventBuilder={build:t,options:e},this.icalEventData=void 0):(this.icalEventBuilder=void 0,this.icalEventData={content:t,...e}),this.logger&&this.logger.debug("Calendar event attached",{method:e?.method}),this}icalEventFromFile(t,e){const r=typeof t=="string"?t:b(t);return this.icalEventData={path:r,...e},this.logger&&this.logger.debug(`Calendar event attached from file: ${r}`,{method:e?.method}),this}icalEventFromUrl(t,e){return this.icalEventData={href:t,...e},this.logger&&this.logger.debug(`Calendar event attached from URL: ${t}`,{method:e?.method}),this}async view(t,e,r,i){try{const s=i?.autoText!==!1;this.autoTextEnabled=s,this.logger&&this.logger.debug("Rendering template",{autoText:s});const h=await t(e,r,i);this.html(h),s&&h&&await this.tryAutoGenerateText(h),this.logger&&this.logger.debug("Template rendered successfully")}catch(s){throw this.logger&&this.logger.error("Failed to render template",s),new Error(`Failed to render template: ${s.message}`)}return this}async viewText(t,e,r,i){try{this.logger&&this.logger.debug("Rendering text template");const s=await t(e,r,i);if(typeof s=="string")this.text(s),this.logger&&this.logger.debug("Text template rendered successfully");else throw new TypeError("Text renderer must return a string")}catch(s){throw this.logger&&this.logger.error("Failed to render text template",s),new Error(`Failed to render text template: ${s.message}`)}return this}async build(){if(this.logger&&this.logger.debug("Building email message"),this.fromAddress||this.throwAndLogError("From address is required","Build failed: from address is required"),this.toAddresses.length===0&&this.throwAndLogError("At least one recipient is required","Build failed: at least one recipient is required"),this.subjectText||this.throwAndLogError("Subject is required","Build failed: subject is required"),this.htmlContent&&!this.textContent&&this.autoTextEnabled)try{const e=await m();this.textContent=e(this.htmlContent),this.logger&&this.logger.debug("Auto-generated text content from HTML")}catch{this.logger&&this.logger.debug("Failed to convert HTML to text; proceeding without text content.")}!this.textContent&&!this.htmlContent&&this.throwAndLogError("Either text or html content is required","Build failed: either text or html content is required");let t={from:this.fromAddress,html:this.htmlContent,subject:this.subjectText,text:this.textContent,to:this.toAddresses.length===1?this.toAddresses[0]:this.toAddresses};if(this.ccAddresses.length>0&&(t.cc=this.ccAddresses.length===1?this.ccAddresses[0]:this.ccAddresses),this.bccAddresses.length>0&&(t.bcc=this.bccAddresses.length===1?this.bccAddresses[0]:this.bccAddresses),Object.keys(this.headers).length>0&&(t.headers=this.headers),this.attachments.length>0&&(t.attachments=this.attachments,this.logger&&this.logger.debug(`Email includes ${this.attachments.length} attachment(s)`)),this.replyToAddress&&(t.replyTo=this.replyToAddress),this.priorityValue&&(t.priority=this.priorityValue),this.tagsValue.length>0&&(t.tags=this.tagsValue),this.icalEventBuilder){const r=(await x())();this.icalEventBuilder.build(r),this.icalEventData={content:r.toString(),...this.icalEventBuilder.options}}return this.icalEventData&&(t.icalEvent=this.icalEventData,this.logger&&this.logger.debug("Email includes calendar event")),this.dateValue&&(t.headers={...l(t.headers??{}),Date:this.dateValue.toUTCString()}),this.returnPathAddress&&(t.headers={...l(t.headers??{}),"Return-Path":this.returnPathAddress.email}),this.senderAddress&&(t.headers={...l(t.headers??{}),Sender:this.senderAddress.email}),this.signer&&(this.logger&&this.logger.debug("Signing email message"),t=await this.signer.sign(t),this.logger&&this.logger.debug("Email message signed successfully")),this.encrypter&&(this.logger&&this.logger.debug("Encrypting email message"),t=await this.encrypter.encrypt(t),this.logger&&this.logger.debug("Email message encrypted successfully")),this.logger&&this.logger.debug("Email message built successfully",{bcc:this.bccAddresses.length,cc:this.ccAddresses.length,hasHtml:!!this.htmlContent,hasText:!!this.textContent,to:this.toAddresses.length}),t}getSubject(){return this.subjectText}getFrom(){return this.fromAddress}getTo(){return[...this.toAddresses]}getCc(){return[...this.ccAddresses]}getBcc(){return[...this.bccAddresses]}getReplyTo(){return this.replyToAddress}getSender(){return this.senderAddress}getReturnPath(){return this.returnPathAddress}getDate(){return this.dateValue}getPriority(){return this.priorityValue}getTextBody(){return this.textContent}getTextCharset(){return this.textCharset}getHtmlBody(){return this.htmlContent}getHtmlCharset(){return this.htmlCharset}getAttachments(){return[...this.attachments]}async tryAutoGenerateText(t){try{const r=(await m())(t);r&&!this.textContent&&this.text(r),this.logger&&this.logger.debug("Auto-generated text content from HTML template")}catch(e){this.logger&&this.logger.warn("Failed to auto-generate text from HTML template",e)}}throwAndLogError(t,e){const r=new Error(t);throw this.logger&&this.logger.error(e??t),r}}export{D as default};
@@ -1 +0,0 @@
1
- import c from"./EmailError-SXEFQEyA.js";import E from"./RequiredOptionError-C2wWqmiE.js";import{g as I}from"./generate-message-id-C5AM6DFE.js";import{h as w}from"./headers-to-record-ZOZ7Dubo.js";import{m as f}from"./make-request-mszP240P.js";import{r as g}from"./retry-ByPJFAtq.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as P}from"./defineProvider-C9q-7iwt.js";import{c as $,P as C,h as p}from"./provider-base-G22b4a87.js";import{e as j,g as b,d as v}from"./address-formatter-w36S9ZYj.js";import{p as R}from"./attachment-processor-AB1m-n9T.js";const o="resend",S="https://api.resend.com",k=3e4,z=3,D=s=>{const r=[],d=/^[\w-]+$/;return d.test(s.name)||r.push(`Tag name '${s.name}' must only contain ASCII letters, numbers, underscores, or dashes`),s.name.length>256&&r.push(`Tag name '${s.name}' exceeds maximum length of 256 characters`),d.test(s.value)||r.push(`Tag value '${s.value}' for tag '${s.name}' must only contain ASCII letters, numbers, underscores, or dashes`),r},V=P((s={})=>{if(!s.apiKey)throw new E(o,"apiKey");const r={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??S,logger:s.logger,retries:s.retries??z,timeout:s.timeout??k},d=new C,n=$(o,s.logger);return{endpoint:r.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new c(o,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),o);const t={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Retrieving email details",{id:e});const a=await g(async()=>f(`${r.endpoint}/emails/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return a.success?(n.debug("Email details retrieved successfully"),{data:a.data?.body,success:!0}):(n.debug("API request failed when retrieving email",a.error),{error:new c(o,`Failed to retrieve email: ${a.error instanceof Error?a.error.message:"Unknown error"}`,{cause:a.error}),success:!1})}catch(t){return{error:p(o,"retrieve email",t,n),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new c(o,"Resend API not available or invalid API key");n.debug("Provider initialized successfully")},o)},async isAvailable(){try{if(r.apiKey&&r.apiKey.startsWith("re_"))return n.debug("API key format is valid, assuming Resend is available"),!0;const e={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};n.debug("Checking Resend API availability");const t=await f(`${r.endpoint}/domains`,{headers:e,method:"GET",timeout:r.timeout});return t.data&&typeof t.data=="object"&&"body"in t.data&&t.data.body&&typeof t.data.body=="object"&&"name"in t.data.body&&t.data.body.name==="restricted_api_key"?(n.debug("API key is valid but restricted to only sending emails"),!0):(n.debug("Resend API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300))}catch(e){return n.debug("Error checking availability:",e),!1}},name:o,options:r,async sendEmail(e){try{const t=T(e);if(t.length>0)return{error:new c(o,`Invalid email options: ${t.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),o);const a={from:b(e.from),headers:e.headers?w(e.headers):{},html:e.html,subject:e.subject,text:e.text,to:j(e.to)};if(e.cc&&(a.cc=v(e.cc)),e.bcc&&(a.bcc=v(e.bcc)),e.replyTo&&(a.reply_to=b(e.replyTo)),e.templateId&&(a.template=e.templateId,e.templateData&&(a.data=e.templateData)),e.scheduledAt&&(a.scheduled_at=typeof e.scheduledAt=="string"?e.scheduledAt:e.scheduledAt.toISOString()),e.tags&&e.tags.length>0){const i=[];if(e.tags.forEach(l=>{const y=D(l);y.length>0&&i.push(...y)}),i.length>0)return{error:new c(o,`Invalid email tags: ${i.join(", ")}`),success:!1};a.tags=e.tags.map(l=>({name:l.name,value:l.value}))}e.attachments&&e.attachments.length>0&&(a.attachments=await Promise.all(e.attachments.map(async i=>({content:await R(i,o),content_type:i.contentType,filename:i.filename,...i.path&&{path:i.path}})))),n.debug("Sending email via Resend API",{subject:a.subject,to:a.to});const A={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},u=await g(async()=>f(`${r.endpoint}/emails`,{headers:A,method:"POST",timeout:r.timeout},JSON.stringify(a)),r.retries);if(!u.success)return n.debug("API request failed when sending email",u.error),{error:u.error??new c(o,"Failed to send email"),success:!1};const m=u.data,h=m?.body&&typeof m.body=="object"&&m.body.id?m.body.id:I();return n.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:o,response:u.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:p(o,"send email",t,n),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{V as default};