@visulima/email 2.0.0 → 2.1.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.
- package/CHANGELOG.md +54 -0
- package/README.md +48 -5
- package/dist/index.js +1 -1
- package/dist/middleware/index.d.ts +9 -2
- package/dist/middleware/index.js +1 -1
- package/dist/packem_shared/{Mail-C1zp-fqt.js → Mail-CYAwMRnX.js} +1 -1
- package/dist/packem_shared/{ahaSendProvider-D81_wUA1.js → ahaSendProvider-DSuZIzaQ.js} +1 -1
- package/dist/packem_shared/autoSendProvider-DqAoelWR.js +1 -0
- package/dist/packem_shared/{awsSesProvider-BGZJUIep.js → awsSesProvider-ClK1FUln.js} +1 -1
- package/dist/packem_shared/{azureProvider-CmcK4bsf.js → azureProvider-Cw_Tmde6.js} +1 -1
- package/dist/packem_shared/{brevoProvider-C1BDXr41.js → brevoProvider-CIzuIDlt.js} +1 -1
- package/dist/packem_shared/{build-mime-message-B6927SQy.js → build-mime-message-BW5FQ2Bt.js} +1 -1
- package/dist/packem_shared/{cloudflareEmailProvider-Bv-ty-74.js → cloudflareEmailProvider-B8mOEl3N.js} +1 -1
- package/dist/packem_shared/create-token-cache-D56KQGVQ.js +1 -0
- package/dist/packem_shared/{createTestEmail-D3XPGiHY.js → createTestEmail-f12yLlWn.js} +1 -1
- package/dist/packem_shared/{httpProvider-DJAsYSun.js → httpProvider-aBfTXyCT.js} +1 -1
- package/dist/packem_shared/{infobipProvider-lHyGrXgZ.js → infobipProvider-DxzsONUX.js} +1 -1
- package/dist/packem_shared/{loopsProvider-DyloxzNC.js → loopsProvider-QBsAH6Ee.js} +1 -1
- package/dist/packem_shared/{mailCrabProvider-CPtBT6Th.js → mailCrabProvider-DRE5snM9.js} +1 -1
- package/dist/packem_shared/{mailPaceProvider-CJEvOFBh.js → mailPaceProvider-DCa-4ghl.js} +1 -1
- package/dist/packem_shared/{mailchannelsProvider-osRkW_tz.js → mailchannelsProvider-GiwkYBdD.js} +1 -1
- package/dist/packem_shared/{mailerSendProvider-C_6LzARK.js → mailerSendProvider-RK6IbUrL.js} +1 -1
- package/dist/packem_shared/{mailgunProvider-DkISvMPe.js → mailgunProvider-D9HUWGKN.js} +1 -1
- package/dist/packem_shared/{mailjetProvider-CV0i4Xzh.js → mailjetProvider-DelLs2Vt.js} +1 -1
- package/dist/packem_shared/{mailomatProvider-B5YFonEO.js → mailomatProvider-DPDpVS8r.js} +1 -1
- package/dist/packem_shared/{mailtrapProvider-C4ZquIPz.js → mailtrapProvider-DtrS4Q34.js} +1 -1
- package/dist/packem_shared/make-request-B9XjBynA.js +1 -0
- package/dist/packem_shared/{mandrillProvider-DWPFh_Sj.js → mandrillProvider-B84zH-eV.js} +1 -1
- package/dist/packem_shared/{netcoreProvider-C5TEciaN.js → netcoreProvider-D-wtCyJj.js} +1 -1
- package/dist/packem_shared/oauth2Middleware-DQh-hIkv.js +1 -0
- package/dist/packem_shared/outlook365Provider-Btk4Emig.js +1 -0
- package/dist/packem_shared/{plunkProvider-yTlrJVEp.js → plunkProvider-Bw8e6460.js} +1 -1
- package/dist/packem_shared/{postalProvider-CRX_bMYD.js → postalProvider-CT8zr89z.js} +1 -1
- package/dist/packem_shared/{postmarkProvider-CDx85Yge.js → postmarkProvider-CQSqZWDs.js} +1 -1
- package/dist/packem_shared/{resendProvider-CiclWxzr.js → resendProvider-drJYlvLP.js} +1 -1
- package/dist/packem_shared/retry-ipI5DRJ8.js +1 -0
- package/dist/packem_shared/{sanitize-header-DJhgZl3y.js → sanitize-header-DtQwAnzg.js} +1 -1
- package/dist/packem_shared/{scalewayProvider-BcND48qO.js → scalewayProvider-DU5gXQrl.js} +1 -1
- package/dist/packem_shared/{sendGridProvider-D8ZLgY62.js → sendGridProvider-BuTbEXW8.js} +1 -1
- package/dist/packem_shared/{smtpProvider-Bm0yP97W.js → smtpProvider-5MI3-EPh.js} +1 -1
- package/dist/packem_shared/{sparkpostProvider-CTYfSRaV.js → sparkpostProvider-UAsFYIjP.js} +1 -1
- package/dist/packem_shared/{sweegoProvider-DOoin_vi.js → sweegoProvider-SUz0LIcA.js} +1 -1
- package/dist/packem_shared/{zeptomailProvider-DKBPSHPj.js → zeptomailProvider-DXNX9mG_.js} +1 -1
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/autosend/index.d.ts +56 -0
- package/dist/providers/autosend/index.js +1 -0
- package/dist/providers/aws-ses/index.js +1 -1
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/cloudflare-email/index.js +1 -1
- package/dist/providers/http/index.js +1 -1
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/loops/index.js +1 -1
- package/dist/providers/mailchannels/index.js +1 -1
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/netcore/index.js +1 -1
- package/dist/providers/outlook365/index.d.ts +83 -5
- package/dist/providers/outlook365/index.js +1 -1
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sparkpost/index.js +1 -1
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/test/index.js +1 -1
- package/package.json +5 -1
- package/dist/packem_shared/make-request-BlK_B72c.js +0 -1
- package/dist/packem_shared/oauth2Middleware-CodqXkyj.js +0 -1
- package/dist/packem_shared/outlook365Provider-63ggDpqV.js +0 -1
- package/dist/packem_shared/retry-3pnxTuNs.js +0 -1
|
@@ -3,11 +3,25 @@ export type { a as Provider } from "../../packem_shared/provider.d-J-y6iogK.js";
|
|
|
3
3
|
import { M as MaybePromise, B as BaseConfig, E as EmailOptions } from "../../packem_shared/types.d-ejzh-xBP.js";
|
|
4
4
|
import 'node:buffer';
|
|
5
5
|
/**
|
|
6
|
+
* Which OAuth2 flow a config resolves to.
|
|
7
|
+
*/
|
|
8
|
+
type Outlook365AuthMode = "accessToken" | "clientCredentials" | "getAccessToken" | "refreshToken";
|
|
9
|
+
/**
|
|
6
10
|
* Outlook365 / Microsoft Graph configuration.
|
|
7
11
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
12
|
+
* Four authentication modes are supported, in precedence order:
|
|
13
|
+
*
|
|
14
|
+
* 1. `getAccessToken` — bring your own async token source (e.g. `@azure/msal-node`).
|
|
15
|
+
* 2. `accessToken` — a static token, for scripts and tests.
|
|
16
|
+
* 3. `refreshToken` — delegated flow; the provider exchanges the refresh token for access tokens and caches them. Requires `tenantId` + `clientId`.
|
|
17
|
+
* 4. `clientCredentials` (selected by supplying `clientSecret`) — app-only flow. Requires `tenantId` + `clientId`, and `userId` must name a real mailbox, since app-only tokens have no `me`.
|
|
18
|
+
*
|
|
19
|
+
* A confidential-client delegated config and an app-only config with a leftover `refreshToken`
|
|
20
|
+
* are indistinguishable — both carry `tenantId`, `clientId`, `clientSecret` and `refreshToken`.
|
|
21
|
+
* Set {@link Outlook365Config.authMode} to pin the flow when both are present.
|
|
22
|
+
*
|
|
23
|
+
* The built-in flows talk to the Azure AD token endpoint over `fetch` — no auth SDK is
|
|
24
|
+
* bundled, so the provider stays dependency-light and runtime-agnostic.
|
|
11
25
|
*/
|
|
12
26
|
interface Outlook365Config extends BaseConfig {
|
|
13
27
|
/**
|
|
@@ -16,6 +30,28 @@ interface Outlook365Config extends BaseConfig {
|
|
|
16
30
|
*/
|
|
17
31
|
accessToken?: string;
|
|
18
32
|
/**
|
|
33
|
+
* Pins the authentication flow instead of inferring it from which credentials are present.
|
|
34
|
+
* Use it when a config could match more than one flow — most notably `clientCredentials`
|
|
35
|
+
* vs `refreshToken` when both a client secret and a refresh token are supplied.
|
|
36
|
+
*/
|
|
37
|
+
authMode?: Outlook365AuthMode;
|
|
38
|
+
/**
|
|
39
|
+
* Azure AD login authority (default `https://login.microsoftonline.com`). Override for
|
|
40
|
+
* sovereign clouds, e.g. `https://login.microsoftonline.us`.
|
|
41
|
+
*/
|
|
42
|
+
authority?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Application (client) id of the Azure AD app registration. Required by the
|
|
45
|
+
* `refreshToken` and `clientSecret` flows.
|
|
46
|
+
*/
|
|
47
|
+
clientId?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Client secret of the Azure AD app registration. Supplying this without a
|
|
50
|
+
* {@link Outlook365Config.refreshToken} selects the app-only (client credentials) flow.
|
|
51
|
+
* It is also sent with the delegated flow when the app is a confidential client.
|
|
52
|
+
*/
|
|
53
|
+
clientSecret?: string;
|
|
54
|
+
/**
|
|
19
55
|
* API endpoint override (default `https://graph.microsoft.com/v1.0`).
|
|
20
56
|
*/
|
|
21
57
|
endpoint?: string;
|
|
@@ -24,11 +60,50 @@ interface Outlook365Config extends BaseConfig {
|
|
|
24
60
|
*/
|
|
25
61
|
getAccessToken?: () => MaybePromise<string>;
|
|
26
62
|
/**
|
|
63
|
+
* Time source in milliseconds — injectable for tests. Defaults to `Date.now`.
|
|
64
|
+
*/
|
|
65
|
+
now?: () => number;
|
|
66
|
+
/**
|
|
67
|
+
* Called whenever Azure AD rotates the refresh token, so it can be persisted. Awaited
|
|
68
|
+
* before the access token is handed out, so a rejected promise is reported rather than
|
|
69
|
+
* surfacing as an unhandled rejection.
|
|
70
|
+
*
|
|
71
|
+
* The rotated token is adopted in-process regardless of whether persisting succeeds — the
|
|
72
|
+
* previous token is already dead at Azure AD, so the new one is the only usable value. A
|
|
73
|
+
* persist failure is logged rather than failing the send, but the stored token is then
|
|
74
|
+
* stale and sending will break on restart.
|
|
75
|
+
* @param refreshToken The new refresh token.
|
|
76
|
+
*/
|
|
77
|
+
onRefreshToken?: (refreshToken: string) => MaybePromise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* A long-lived OAuth2 refresh token, selecting the delegated flow. Obtain it via the
|
|
80
|
+
* authorization-code flow with the `offline_access` scope.
|
|
81
|
+
*/
|
|
82
|
+
refreshToken?: string;
|
|
83
|
+
/**
|
|
27
84
|
* Whether to keep a copy in the Sent Items folder (default true).
|
|
28
85
|
*/
|
|
29
86
|
saveToSentItems?: boolean;
|
|
30
87
|
/**
|
|
88
|
+
* Scope override for the built-in flows. Defaults to
|
|
89
|
+
* `["https://graph.microsoft.com/.default"]` for the app-only flow and
|
|
90
|
+
* `["https://graph.microsoft.com/Mail.Send", "offline_access"]` for the delegated flow.
|
|
91
|
+
*/
|
|
92
|
+
scopes?: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Azure AD tenant id (or `common` / `organizations` for the delegated flow). Required by
|
|
95
|
+
* the `refreshToken` and `clientSecret` flows.
|
|
96
|
+
*/
|
|
97
|
+
tenantId?: string;
|
|
98
|
+
/**
|
|
99
|
+
* Renew the access token this many milliseconds before it expires (default 60000).
|
|
100
|
+
* Negative values are clamped to 0. A value larger than the token lifetime disables
|
|
101
|
+
* caching, costing one token request per send.
|
|
102
|
+
*/
|
|
103
|
+
tokenRefreshSkewMs?: number;
|
|
104
|
+
/**
|
|
31
105
|
* The mailbox to send as: a user id/UPN. Defaults to `me` (the token's own mailbox).
|
|
106
|
+
* The app-only flow has no `me`, so it requires an explicit value.
|
|
32
107
|
*/
|
|
33
108
|
userId?: string;
|
|
34
109
|
}
|
|
@@ -43,6 +118,9 @@ interface Outlook365EmailOptions extends EmailOptions {
|
|
|
43
118
|
}
|
|
44
119
|
/**
|
|
45
120
|
* Outlook365 provider — sends email through the Microsoft Graph `sendMail` endpoint.
|
|
121
|
+
*
|
|
122
|
+
* Authenticates with a caller-supplied token (`accessToken` / `getAccessToken`), the delegated
|
|
123
|
+
* refresh-token flow, or the app-only client-credentials flow. See {@link Outlook365Config}.
|
|
46
124
|
*/
|
|
47
|
-
declare const outlook365Provider: ProviderFactory<Outlook365Config>;
|
|
48
|
-
export { type Outlook365Config, type Outlook365EmailOptions, type ProviderFactory, outlook365Provider };
|
|
125
|
+
declare const outlook365Provider: ProviderFactory<Outlook365Config, unknown, Outlook365EmailOptions>;
|
|
126
|
+
export { type Outlook365AuthMode, type Outlook365Config, type Outlook365EmailOptions, type ProviderFactory, outlook365Provider };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/outlook365Provider-
|
|
1
|
+
import{default as e}from"../../packem_shared/outlook365Provider-Btk4Emig.js";export{e as outlook365Provider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/plunkProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/plunkProvider-Bw8e6460.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-CT8zr89z.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-CQSqZWDs.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-drJYlvLP.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-DU5gXQrl.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-BuTbEXW8.js";export{e as sendGridProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/smtpProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/smtpProvider-5MI3-EPh.js";export{o as smtpProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/sparkpostProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/sparkpostProvider-UAsFYIjP.js";export{a as sparkpostProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/sweegoProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/sweegoProvider-SUz0LIcA.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-DXNX9mG_.js";export{r as zeptomailProvider};
|
package/dist/test/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DZDkrZ_3.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-DeRqM5SJ.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-
|
|
1
|
+
import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DZDkrZ_3.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-DeRqM5SJ.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-f12yLlWn.js";export{s as createTestEmail,a as emailMatchers,o as registerEmailMatchers,c as toEmailSnapshot,r as toHaveSentMatching,i as toHaveSentTo,m as toHaveSentWithAttachment,h as toHaveSentWithSubject};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/email",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "A comprehensive email library with multi-provider support, crypto utilities, and template engines",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ahasend",
|
|
@@ -122,6 +122,10 @@
|
|
|
122
122
|
"types": "./dist/template-engines/i18n.d.ts",
|
|
123
123
|
"default": "./dist/template-engines/i18n.js"
|
|
124
124
|
},
|
|
125
|
+
"./providers/autosend": {
|
|
126
|
+
"types": "./dist/providers/autosend/index.d.ts",
|
|
127
|
+
"default": "./dist/providers/autosend/index.js"
|
|
128
|
+
},
|
|
125
129
|
"./providers/aws-ses": {
|
|
126
130
|
"types": "./dist/providers/aws-ses/index.d.ts",
|
|
127
131
|
"default": "./dist/providers/aws-ses/index.js"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import d from"./EmailError-B-sEf3bp.js";const y=globalThis.Buffer!==void 0,p=async(i,s={},r)=>{const l=typeof i=="string"?new URL(i):i;try{const e=new Headers;s.headers&&Object.entries(s.headers).forEach(([t,u])=>{e.set(t,u)});const o={headers:e,method:s.method??(r?"POST":"GET")};r&&(typeof r=="string"||r instanceof Uint8Array?o.body=r:y&&r instanceof globalThis.Buffer?o.body=new Uint8Array(r):o.body=new Uint8Array(r));let c,a;s.timeout&&(c=new AbortController,a=setTimeout(()=>{c?.abort()},s.timeout),o.signal=c.signal);try{const t=await fetch(l.toString(),o);a&&clearTimeout(a);const u=(t.headers.get("content-type")??"").includes("application/json");let n;if(u)try{n=await t.json()}catch{n=await t.text()}else n=await t.text();const f=t.status>=200&&t.status<300,h={};return t.headers.forEach((m,w)=>{h[w]=m}),{data:{body:n,headers:h,statusCode:t.status},error:f?void 0:new d("http",`Request failed with status ${t.status}`,{code:t.status.toString()}),success:f}}catch(t){if(a&&clearTimeout(a),t instanceof Error&&t.name==="AbortError")return{error:new d("http",`Request timed out after ${s.timeout}ms`),success:!1};throw t}}catch(e){return{error:new d("http",`Request failed: ${e instanceof Error?e.message:String(e)}`,{cause:e instanceof Error?e:new Error(String(e))}),success:!1}}};export{p as m};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as u}from"./headers-to-record-De1Eg951.js";const p=o=>{const{fetchToken:r,headerName:s="Authorization",now:t=Date.now,onToken:n,scheme:c="Bearer",skewMs:i=6e4}=o;let e;const h=async()=>(e&&(e.expiresAt===void 0||e.expiresAt-i>t())&&e||(e=await r(),n?.(e)),e);return async(a,d)=>{const w=await h(),k=a.headers?u(a.headers):{};return d({...a,headers:{...k,[s]:`${c} ${w.accessToken}`}})}};export{p as oauth2Middleware};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import u from"./EmailError-B-sEf3bp.js";import h from"./RequiredOptionError-DuNNY_a5.js";import{e as y}from"./generate-message-id-gXAuMz4g.js";import{m as k}from"./make-request-BlK_B72c.js";import{u as v}from"./retry-3pnxTuNs.js";import{f as A}from"./validate-email-options-mCM9dVug.js";import{defineProvider as b}from"./defineProvider-C9q-7iwt.js";import{c as w}from"./attachment-processor-CMp7qqMI.js";import{h as I,P as S,c as P}from"./provider-base-C7PuopYK.js";const a="outlook365",j="https://graph.microsoft.com/v1.0",R=3e4,x=3,o=t=>[t].flat(),c=t=>t.map(s=>({emailAddress:{address:s.email,...s.name?{name:s.name}:{}}})),q=b((t={})=>{if(!t.accessToken&&!t.getAccessToken)throw new h(a,["accessToken","getAccessToken"]);const s={accessToken:t.accessToken,debug:t.debug??!1,endpoint:t.endpoint??j,getAccessToken:t.getAccessToken,logger:t.logger,retries:t.retries??x,saveToSentItems:t.saveToSentItems??!0,timeout:t.timeout??R,userId:t.userId??"me"},p=new S,f=P(a,t.logger),g=async()=>s.getAccessToken?s.getAccessToken():s.accessToken;return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){p.setInitialized()},async isAvailable(){return!!(s.accessToken??s.getAccessToken)},name:a,options:s,async sendEmail(e){try{const n=A(e);if(n.length>0)return{error:new u(a,`Invalid email options: ${n.join(", ")}`),success:!1};let d;try{d=await g()}catch(m){return{error:new u(a,"Failed to obtain access token",{cause:m}),success:!1}}const r={body:{content:e.html??e.text??"",contentType:e.html?"HTML":"Text"},subject:e.subject,toRecipients:c(o(e.to))};e.cc&&(r.ccRecipients=c(o(e.cc))),e.bcc&&(r.bccRecipients=c(o(e.bcc))),e.replyTo&&(r.replyTo=c(o(e.replyTo))),e.importance&&(r.importance=e.importance),e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async m=>{const l=await w(m,a);return{"@odata.type":"#microsoft.graph.fileAttachment",contentBytes:l.content,contentType:l.contentType,name:l.filename}})));const T=s.userId==="me"?"me":`users/${s.userId}`,i=await v(async()=>k(`${s.endpoint}/${T}/sendMail`,{headers:{Authorization:`Bearer ${d}`,"Content-Type":"application/json"},method:"POST",timeout:s.timeout},JSON.stringify({message:r,saveToSentItems:s.saveToSentItems})),s.retries);return i.success?{data:{messageId:y(),provider:a,response:i.data,sent:!0,timestamp:new Date},success:!0}:{error:i.error??new u(a,"Failed to send email"),success:!1}}catch(n){return{error:I(a,"send email",n,f),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{q as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o=async(t,e=3,s=300)=>{try{const r=await t();return r.success||e<=0?r:(await new Promise(n=>{setTimeout(()=>{n()},s)}),o(t,e-1,s*2))}catch(r){return e<=0?{error:r instanceof Error?r:new Error(String(r)),success:!1}:(await new Promise(n=>{setTimeout(()=>{n()},s)}),o(t,e-1,s*2))}};export{o as u};
|