@lunora/mail 1.0.0-alpha.129 → 1.0.0-alpha.130
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/dist/index.d.mts +46 -3
- package/dist/index.d.ts +46 -3
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/MailSendError-HH5Yimut.mjs +1 -0
- package/dist/packem_shared/createCaptureSink-BSAR1HTL.mjs +1 -0
- package/dist/packem_shared/createCloudflareTransport-fOhfy2fP.mjs +1 -0
- package/dist/packem_shared/createMailer-C5NIzkNb.mjs +1 -0
- package/dist/packem_shared/{createResendTransport-BMjRlHmy.mjs → createResendTransport-q3surKen.mjs} +1 -1
- package/dist/packem_shared/provider-transport-DklK6xUa.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/createCaptureSink-BuIyx2-4.mjs +0 -1
- package/dist/packem_shared/createCloudflareTransport-bWoNSnK_.mjs +0 -1
- package/dist/packem_shared/createMailer-lFM_i5VM.mjs +0 -1
- package/dist/packem_shared/provider-transport-BnA39QbI.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { M as MailTransport, L as LunoraMailOptions, a as Mailer, Q as QueueLike
|
|
|
2
2
|
export { type C as CapturedMail, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-BD67fxbB.mjs";
|
|
3
3
|
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.mjs";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
|
+
import { LunoraError } from '@lunora/errors';
|
|
5
6
|
/**
|
|
6
7
|
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
7
8
|
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
@@ -160,9 +161,24 @@ declare const toQueuedPayload: (options: SendOptions) => QueuedSend;
|
|
|
160
161
|
* // createMailerFromEnv, so dev captures the message here instead of sending it.
|
|
161
162
|
* const mailer = createMailerFromEnv(env);
|
|
162
163
|
* for (const message of batch.messages) {
|
|
163
|
-
* const
|
|
164
|
+
* const idempotencyKey = message.body?.idempotencyKey;
|
|
165
|
+
* // Malformed, and no retry fixes it; unguarded, this would throw and retry the whole batch. Logged without the
|
|
166
|
+
* // body, which can still carry recipients and content.
|
|
167
|
+
* if (typeof idempotencyKey !== "string") { console.error("malformed mail message: no idempotencyKey"); message.ack(); continue; }
|
|
164
168
|
* if (await env.SENT.get(idempotencyKey)) { message.ack(); continue; }
|
|
165
|
-
*
|
|
169
|
+
* try {
|
|
170
|
+
* await consumeQueuedSend(mailer, message.body);
|
|
171
|
+
* } catch (error) {
|
|
172
|
+
* // A refusal the provider will never accept: a retry only dead-letters it.
|
|
173
|
+
* if (!isRetryableMailError(error)) {
|
|
174
|
+
* console.error("mail refused", error);
|
|
175
|
+
* message.ack();
|
|
176
|
+
* continue;
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* message.retry();
|
|
180
|
+
* continue;
|
|
181
|
+
* }
|
|
166
182
|
* await env.SENT.put(idempotencyKey, "1", { expirationTtl: 86_400 });
|
|
167
183
|
* message.ack();
|
|
168
184
|
* }
|
|
@@ -194,4 +210,31 @@ declare const renderEmail: (element: ReactElement) => Promise<{
|
|
|
194
210
|
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
195
211
|
*/
|
|
196
212
|
declare const createResendTransport: (apiKey: string, defaultFrom: string) => MailTransport;
|
|
197
|
-
|
|
213
|
+
/** What a {@link MailSendError} carries on `data`, so a caller can tell a retry from a refusal. */
|
|
214
|
+
interface MailSendErrorData {
|
|
215
|
+
/** Whether repeating the same message may succeed. A refused address or malformed message never will. */
|
|
216
|
+
retryable: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A send that did not deliver. `retryable` is the decision a queue consumer
|
|
220
|
+
* needs: a send is a refusal only when the provider answered with an explicit
|
|
221
|
+
* permanent HTTP status (anything but 408, 429 and 5xx); every other failure may
|
|
222
|
+
* clear on a redelivery. Retrying a refusal only drains the queue into its
|
|
223
|
+
* dead-letter queue.
|
|
224
|
+
*/
|
|
225
|
+
declare class MailSendError extends LunoraError {
|
|
226
|
+
readonly retryable: boolean;
|
|
227
|
+
constructor(options: {
|
|
228
|
+
cause?: unknown;
|
|
229
|
+
message?: string;
|
|
230
|
+
retryable: boolean;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Whether a failed send is worth a queue redelivery. Only an error the mail
|
|
235
|
+
* path classified as retryable qualifies. Everything else, including the
|
|
236
|
+
* shape-check refusals `consumeQueuedSend` throws before any provider call, is
|
|
237
|
+
* a message that will never send.
|
|
238
|
+
*/
|
|
239
|
+
declare const isRetryableMailError: (error: unknown) => boolean;
|
|
240
|
+
export { type CloudflareSend, type CloudflareTransportOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { M as MailTransport, L as LunoraMailOptions, a as Mailer, Q as QueueLike
|
|
|
2
2
|
export { type C as CapturedMail, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-BD67fxbB.js";
|
|
3
3
|
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.js";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
|
+
import { LunoraError } from '@lunora/errors';
|
|
5
6
|
/**
|
|
6
7
|
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
7
8
|
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
@@ -160,9 +161,24 @@ declare const toQueuedPayload: (options: SendOptions) => QueuedSend;
|
|
|
160
161
|
* // createMailerFromEnv, so dev captures the message here instead of sending it.
|
|
161
162
|
* const mailer = createMailerFromEnv(env);
|
|
162
163
|
* for (const message of batch.messages) {
|
|
163
|
-
* const
|
|
164
|
+
* const idempotencyKey = message.body?.idempotencyKey;
|
|
165
|
+
* // Malformed, and no retry fixes it; unguarded, this would throw and retry the whole batch. Logged without the
|
|
166
|
+
* // body, which can still carry recipients and content.
|
|
167
|
+
* if (typeof idempotencyKey !== "string") { console.error("malformed mail message: no idempotencyKey"); message.ack(); continue; }
|
|
164
168
|
* if (await env.SENT.get(idempotencyKey)) { message.ack(); continue; }
|
|
165
|
-
*
|
|
169
|
+
* try {
|
|
170
|
+
* await consumeQueuedSend(mailer, message.body);
|
|
171
|
+
* } catch (error) {
|
|
172
|
+
* // A refusal the provider will never accept: a retry only dead-letters it.
|
|
173
|
+
* if (!isRetryableMailError(error)) {
|
|
174
|
+
* console.error("mail refused", error);
|
|
175
|
+
* message.ack();
|
|
176
|
+
* continue;
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* message.retry();
|
|
180
|
+
* continue;
|
|
181
|
+
* }
|
|
166
182
|
* await env.SENT.put(idempotencyKey, "1", { expirationTtl: 86_400 });
|
|
167
183
|
* message.ack();
|
|
168
184
|
* }
|
|
@@ -194,4 +210,31 @@ declare const renderEmail: (element: ReactElement) => Promise<{
|
|
|
194
210
|
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
195
211
|
*/
|
|
196
212
|
declare const createResendTransport: (apiKey: string, defaultFrom: string) => MailTransport;
|
|
197
|
-
|
|
213
|
+
/** What a {@link MailSendError} carries on `data`, so a caller can tell a retry from a refusal. */
|
|
214
|
+
interface MailSendErrorData {
|
|
215
|
+
/** Whether repeating the same message may succeed. A refused address or malformed message never will. */
|
|
216
|
+
retryable: boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A send that did not deliver. `retryable` is the decision a queue consumer
|
|
220
|
+
* needs: a send is a refusal only when the provider answered with an explicit
|
|
221
|
+
* permanent HTTP status (anything but 408, 429 and 5xx); every other failure may
|
|
222
|
+
* clear on a redelivery. Retrying a refusal only drains the queue into its
|
|
223
|
+
* dead-letter queue.
|
|
224
|
+
*/
|
|
225
|
+
declare class MailSendError extends LunoraError {
|
|
226
|
+
readonly retryable: boolean;
|
|
227
|
+
constructor(options: {
|
|
228
|
+
cause?: unknown;
|
|
229
|
+
message?: string;
|
|
230
|
+
retryable: boolean;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Whether a failed send is worth a queue redelivery. Only an error the mail
|
|
235
|
+
* path classified as retryable qualifies. Everything else, including the
|
|
236
|
+
* shape-check refusals `consumeQueuedSend` throws before any provider call, is
|
|
237
|
+
* a message that will never send.
|
|
238
|
+
*/
|
|
239
|
+
declare const isRetryableMailError: (error: unknown) => boolean;
|
|
240
|
+
export { type CloudflareSend, type CloudflareTransportOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, MailSendError, type MailSendErrorData, type MailTransport, type MailboxSink, type Mailer, type QueueLike, type QueuedSend, type SendOptions, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, isRetryableMailError, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-
|
|
1
|
+
import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-fOhfy2fP.mjs";import{default as p}from"./packem_shared/createMailer-C5NIzkNb.mjs";import{createCaptureSink as d,createMailerFromEnv as f,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-BSAR1HTL.mjs";import{consumeQueuedSend as s,toQueuedPayload as i}from"./packem_shared/consumeQueuedSend-CRfALnCU.mjs";import{default as c}from"./packem_shared/renderEmail-xypKDdux.mjs";import{default as C}from"./packem_shared/createResendTransport-q3surKen.mjs";import{MailSendError as S,isRetryableMailError as T}from"./packem_shared/MailSendError-HH5Yimut.mjs";export{S as MailSendError,s as consumeQueuedSend,d as createCaptureSink,a as createCaptureTransport,t as createCloudflareTransport,p as createMailer,f as createMailerFromEnv,C as createResendTransport,T as isRetryableMailError,c as renderEmail,m as shouldCaptureMail,i as toQueuedPayload};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";class t extends l{retryable;constructor(r){const a={retryable:r.retryable};super("INTERNAL",r.message??"@lunora/mail: send failed",{cause:r.cause,data:a,name:"MailSendError"}),this.retryable=r.retryable}}const n=e=>e instanceof t&&e.retryable;export{t as MailSendError,n as isRetryableMailError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createCaptureTransport as d}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-fOhfy2fP.mjs";import s from"./createMailer-C5NIzkNb.mjs";import{LunoraError as l}from"@lunora/errors";import{D as p,a as E,p as _}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-CRfALnCU.mjs";import"./renderEmail-xypKDdux.mjs";import"./createResendTransport-q3surKen.mjs";import"./MailSendError-HH5Yimut.mjs";const N="__lunora_admin__:recordMail",m=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,f=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],R=(r,e)=>{const o=r[e];if(typeof o!="string"||o==="")throw new l("INTERNAL",`@lunora/mail: missing env var \`${e}\` — set it in .dev.vars (and \`wrangler secret put ${e}\` for secrets).`);return o},A=r=>{const e=r.LUNORA_MAIL_CAPTURE;if(typeof e=="string"){const t=e.toLowerCase();if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${e}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}const o=f.map(t=>r[t]).filter(t=>typeof t=="string"&&t!=="");return o.length>0&&o.every(t=>m.test(t))};let u=!1;const g=(r,e=p,o)=>({record:async t=>{const i=r.SHARD,a=typeof r.LUNORA_ADMIN_TOKEN=="string"?r.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return u||(u=!0,console.warn("@lunora/mail: capturing mail but there is nowhere to record it — the `SHARD` binding and/or `LUNORA_ADMIN_TOKEN` is missing, so every captured message is discarded. Set both to see mail in the studio inbox, or set LUNORA_MAIL_CAPTURE=0 to deliver for real.")),{id:"uncaptured"};const c=E(i,o);try{return{id:(await _(c,{adminToken:a,envelope:{args:t,functionPath:N},label:"@lunora/mail: recording captured mail",shardKey:e})).result?.id??"captured"}}catch(n){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",n),{id:"uncaptured"}}}}),b=(r,e={})=>{const o=R(r,"MAIL_FROM");if(A(r))return s({from:o,queue:e.queue,transport:d(g(r,e.rootShard,e.jurisdiction))});const{cloudflareSend:t}=e,i=typeof r.RESEND_API_KEY=="string"&&r.RESEND_API_KEY!==""?r.RESEND_API_KEY:void 0;return s({apiKey:i,cloudflareSend:t,from:o,queue:e.queue})};export{g as createCaptureSink,b as createMailerFromEnv,A as shouldCaptureMail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cloudflareEmailProvider as l}from"@visulima/email/providers/cloudflare-email";import{r as d,t as m,i as f}from"./provider-transport-DklK6xUa.mjs";import{MailSendError as n}from"./MailSendError-HH5Yimut.mjs";const h=r=>{const t=l({send:r.send});return{send:async e=>{await t.initialize();const s=e.cc!==void 0&&e.cc.length>0,o=e.bcc!==void 0&&e.bcc.length>0;if(s||o)throw new n({message:"@lunora/mail: Cloudflare Email Workers does not support cc/bcc — fan out one send per recipient instead",retryable:!1});const{first:c,list:i}=d(e.to);if(i.length>1)throw new n({message:`@lunora/mail: Cloudflare Email Workers is single-recipient but received ${String(i.length)} \`to\` addresses — fan out one send per recipient instead`,retryable:!1});const a=await t.sendEmail(m(e,r.from,c));return f(a)}}};export{h as createCloudflareTransport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as l}from"@lunora/errors";import{a as o,c as m}from"./address-oKy_d0aG.mjs";import{isCaptureTransport as i}from"./createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as y}from"./createCloudflareTransport-fOhfy2fP.mjs";import{toQueuedPayload as b}from"./consumeQueuedSend-CRfALnCU.mjs";import w from"./renderEmail-xypKDdux.mjs";import h from"./createResendTransport-q3surKen.mjs";import{MailSendError as s}from"./MailSendError-HH5Yimut.mjs";const p=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const r=crypto.getRandomValues(new Uint8Array(16));return Array.from(r,u=>u.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},q=r=>{if(r.cloudflareSend)return y({from:r.from,send:r.cloudflareSend});if(r.apiKey)return h(r.apiKey,r.from);if(r.queue)return{send:()=>Promise.reject(new s({message:"@lunora/mail: no transport configured — this mailer can only queue(); pass `transport`, `cloudflareSend` (a SEND_EMAIL binding) or `apiKey` (Resend) to send()",retryable:!0}))};throw new l("INTERNAL","@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend), or a `queue` for a producer-only mailer")},K=r=>{if(!r.from)throw new l("INTERNAL","@lunora/mail: `from` is required");const u=r.transport??q(r),d=async e=>{let{html:t}=e,{text:a}=e;if(e.react){const n=await w(e.react);t=t??n.html,a=a??n.text}if(o("subject",e.subject),e.headers)for(const[n,f]of Object.entries(e.headers))o(`header name "${n}"`,n),o(`header "${n}" value`,f);const c=e.from??r.from;return m({bcc:e.bcc,cc:e.cc,from:c,replyTo:e.replyTo,to:e.to}),{bcc:e.bcc?.length?e.bcc:void 0,cc:e.cc?.length?e.cc:void 0,from:c,headers:e.headers,html:t,replyTo:e.replyTo,subject:e.subject,text:a,to:e.to}};return{queue:async e=>{if(!r.queue){if(i(u)){const c=await d(e);return await u.send(c),{queued:!0}}throw new l("INTERNAL","@lunora/mail: `queue` binding is required for mailer.queue()")}const t=await d(e),a=e.idempotencyKey??p();return await r.queue.send(b({...t,idempotencyKey:a})),{queued:!0}},send:async e=>{const t=await d(e);try{return await u.send(t)}catch(a){throw a instanceof s?a:new s({cause:a,retryable:!0})}}}};export{K as default};
|
package/dist/packem_shared/{createResendTransport-BMjRlHmy.mjs → createResendTransport-q3surKen.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resendProvider as a}from"@visulima/email/providers/resend";import{r as d,t as c,i as l}from"./provider-transport-
|
|
1
|
+
import{resendProvider as a}from"@visulima/email/providers/resend";import{r as d,t as c,i as l}from"./provider-transport-DklK6xUa.mjs";const u=(i,s)=>{const e=a({apiKey:i});return{send:async r=>{await e.initialize();const{first:n,list:t}=d(r.to),o=await e.sendEmail(c(r,s,t.length===1?n:t));return l(o)}}};export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as n,b as o}from"./address-oKy_d0aG.mjs";import{MailSendError as s}from"./MailSendError-HH5Yimut.mjs";const f=e=>e instanceof Error?e.message:e==null?"send failed":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?e.toString():JSON.stringify(e)??"send failed",c=/^\d{3}$/,u=e=>typeof e=="number"?e:typeof e=="string"&&c.test(e)?Number(e):void 0,d=e=>{if(!(e instanceof Error))return!0;let t;for(let r=e,i=0;r instanceof Error&&i<5&&(t=u("code"in r?r.code:void 0),t===void 0);r=r.cause,i+=1);return t!==void 0&&t>=100&&t<=599?t===408||t===429||t>=500:!0},b=e=>{const t=n(e),[r]=t??[];if(!t||r===void 0)throw new s({message:"@lunora/mail: at least one recipient is required",retryable:!1});return{first:r,list:t}},l=(e,t,r)=>({bcc:n(e.bcc),cc:n(e.cc),from:o(e.from??t),headers:e.headers,html:e.html,replyTo:e.replyTo?o(e.replyTo):void 0,subject:e.subject,text:e.text,to:r}),p=e=>{if(e.success&&!e.data)throw new s({message:"@lunora/mail: provider accepted the send but returned no message id",retryable:!1});if(!e.success||!e.data)throw console.error(`@lunora/mail: send failed: ${f(e.error)}`),new s({cause:e.error,retryable:d(e.error)});return{id:e.data.messageId}};export{p as i,b as r,l as t};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCaptureTransport as d}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-bWoNSnK_.mjs";import s from"./createMailer-lFM_i5VM.mjs";import{LunoraError as l}from"@lunora/errors";import{D as p,a as E,p as _}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-CRfALnCU.mjs";import"./renderEmail-xypKDdux.mjs";import"./createResendTransport-BMjRlHmy.mjs";const N="__lunora_admin__:recordMail",m=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,f=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],R=(r,e)=>{const o=r[e];if(typeof o!="string"||o==="")throw new l("INTERNAL",`@lunora/mail: missing env var \`${e}\` — set it in .dev.vars (and \`wrangler secret put ${e}\` for secrets).`);return o},A=r=>{const e=r.LUNORA_MAIL_CAPTURE;if(typeof e=="string"){const t=e.toLowerCase();if(t==="1"||t==="true")return!0;if(t==="0"||t==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${e}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}const o=f.map(t=>r[t]).filter(t=>typeof t=="string"&&t!=="");return o.length>0&&o.every(t=>m.test(t))};let u=!1;const g=(r,e=p,o)=>({record:async t=>{const i=r.SHARD,a=typeof r.LUNORA_ADMIN_TOKEN=="string"?r.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return u||(u=!0,console.warn("@lunora/mail: capturing mail but there is nowhere to record it — the `SHARD` binding and/or `LUNORA_ADMIN_TOKEN` is missing, so every captured message is discarded. Set both to see mail in the studio inbox, or set LUNORA_MAIL_CAPTURE=0 to deliver for real.")),{id:"uncaptured"};const c=E(i,o);try{return{id:(await _(c,{adminToken:a,envelope:{args:t,functionPath:N},label:"@lunora/mail: recording captured mail",shardKey:e})).result?.id??"captured"}}catch(n){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",n),{id:"uncaptured"}}}}),S=(r,e={})=>{const o=R(r,"MAIL_FROM");if(A(r))return s({from:o,queue:e.queue,transport:d(g(r,e.rootShard,e.jurisdiction))});const{cloudflareSend:t}=e,i=typeof r.RESEND_API_KEY=="string"&&r.RESEND_API_KEY!==""?r.RESEND_API_KEY:void 0;return s({apiKey:i,cloudflareSend:t,from:o,queue:e.queue})};export{g as createCaptureSink,S as createMailerFromEnv,A as shouldCaptureMail};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as n}from"@lunora/errors";import{cloudflareEmailProvider as l}from"@visulima/email/providers/cloudflare-email";import{r as d,t as u,i as m}from"./provider-transport-BnA39QbI.mjs";const E=r=>{const t=l({send:r.send});return{send:async e=>{await t.initialize();const o=e.cc!==void 0&&e.cc.length>0,s=e.bcc!==void 0&&e.bcc.length>0;if(o||s)throw new n("INTERNAL","@lunora/mail: Cloudflare Email Workers does not support cc/bcc — fan out one send per recipient instead");const{first:c,list:i}=d(e.to);if(i.length>1)throw new n("INTERNAL",`@lunora/mail: Cloudflare Email Workers is single-recipient but received ${String(i.length)} \`to\` addresses — fan out one send per recipient instead`);const a=await t.sendEmail(u(e,r.from,c));return m(a)}}};export{E as createCloudflareTransport};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as c}from"@lunora/errors";import{a as l,c as s}from"./address-oKy_d0aG.mjs";import{isCaptureTransport as m}from"./createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as i}from"./createCloudflareTransport-bWoNSnK_.mjs";import{toQueuedPayload as y}from"./consumeQueuedSend-CRfALnCU.mjs";import b from"./renderEmail-xypKDdux.mjs";import h from"./createResendTransport-BMjRlHmy.mjs";const w=()=>{if(typeof crypto<"u"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"){const r=crypto.getRandomValues(new Uint8Array(16));return Array.from(r,n=>n.toString(16).padStart(2,"0")).join("")}}throw new Error("randomSessionId: no Web Crypto available — a session id needs crypto.randomUUID or crypto.getRandomValues")},p=r=>{if(r.cloudflareSend)return i({from:r.from,send:r.cloudflareSend});if(r.apiKey)return h(r.apiKey,r.from);if(r.queue)return{send:()=>Promise.reject(new c("INTERNAL","@lunora/mail: no transport configured — this mailer can only queue(); pass `transport`, `cloudflareSend` (a SEND_EMAIL binding) or `apiKey` (Resend) to send()"))};throw new c("INTERNAL","@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend), or a `queue` for a producer-only mailer")},j=r=>{if(!r.from)throw new c("INTERNAL","@lunora/mail: `from` is required");const n=r.transport??p(r),o=async e=>{let{html:a}=e,{text:u}=e;if(e.react){const t=await b(e.react);a=a??t.html,u=u??t.text}if(l("subject",e.subject),e.headers)for(const[t,f]of Object.entries(e.headers))l(`header name "${t}"`,t),l(`header "${t}" value`,f);const d=e.from??r.from;return s({bcc:e.bcc,cc:e.cc,from:d,replyTo:e.replyTo,to:e.to}),{bcc:e.bcc?.length?e.bcc:void 0,cc:e.cc?.length?e.cc:void 0,from:d,headers:e.headers,html:a,replyTo:e.replyTo,subject:e.subject,text:u,to:e.to}};return{queue:async e=>{if(!r.queue){if(m(n)){const d=await o(e);return await n.send(d),{queued:!0}}throw new c("INTERNAL","@lunora/mail: `queue` binding is required for mailer.queue()")}const a=await o(e),u=e.idempotencyKey??w();return await r.queue.send(y({...a,idempotencyKey:u})),{queued:!0}},send:async e=>{const a=await o(e);return n.send(a)}}};export{j as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as o}from"@lunora/errors";import{t as n,b as s}from"./address-oKy_d0aG.mjs";const c=e=>e instanceof Error?e.message:e==null?"send failed":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?e.toString():JSON.stringify(e)??"send failed",u=e=>{const t=n(e),[i]=t??[];if(!t||i===void 0)throw new o("INTERNAL","@lunora/mail: at least one recipient is required");return{first:i,list:t}},d=(e,t,i)=>({bcc:n(e.bcc),cc:n(e.cc),from:s(e.from??t),headers:e.headers,html:e.html,replyTo:e.replyTo?s(e.replyTo):void 0,subject:e.subject,text:e.text,to:i}),m=e=>{if(!e.success||!e.data)throw console.error(`@lunora/mail: send failed: ${c(e.error)}`),new o("INTERNAL","@lunora/mail: send failed");return{id:e.data.messageId}};export{m as i,u as r,d as t};
|