@lunora/mail 1.0.0-alpha.103 → 1.0.0-alpha.105

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 CHANGED
@@ -57,9 +57,10 @@ type MailEnv = Record<string, unknown>;
57
57
  /** Options for {@link createMailerFromEnv}. */
58
58
  interface FromEnvOptions {
59
59
  /**
60
- * RFC 822 send callback bound to the Worker's `send_email` binding (Cloudflare
61
- * default transport). Used only when `env.SEND_EMAIL` is set, so it can be
62
- * passed unconditionally.
60
+ * RFC 822 send callback bound to the Worker's Cloudflare Email binding (the
61
+ * default transport). Honoured whenever it is passed, whatever the binding is
62
+ * named: passing it is the caller's choice of transport, so pass it only when
63
+ * the binding exists.
63
64
  */
64
65
  cloudflareSend?: CloudflareSend;
65
66
  /**
@@ -95,7 +96,7 @@ declare const createCaptureSink: (env: MailEnv, rootShard?: string, jurisdiction
95
96
  /**
96
97
  * Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
97
98
  * captured into the studio's Mail inbox; otherwise it delivers via the supplied
98
- * `cloudflareSend` (used only when the `SEND_EMAIL` binding is present) or,
99
+ * `cloudflareSend` (when passed) or,
99
100
  * failing that, `RESEND_API_KEY`. With no real transport `send()` rejects, so a
100
101
  * misconfigured production deploy fails loudly instead of silently dropping mail
101
102
  * — while `queue()` still works for a producer-only worker.
package/dist/index.d.ts CHANGED
@@ -57,9 +57,10 @@ type MailEnv = Record<string, unknown>;
57
57
  /** Options for {@link createMailerFromEnv}. */
58
58
  interface FromEnvOptions {
59
59
  /**
60
- * RFC 822 send callback bound to the Worker's `send_email` binding (Cloudflare
61
- * default transport). Used only when `env.SEND_EMAIL` is set, so it can be
62
- * passed unconditionally.
60
+ * RFC 822 send callback bound to the Worker's Cloudflare Email binding (the
61
+ * default transport). Honoured whenever it is passed, whatever the binding is
62
+ * named: passing it is the caller's choice of transport, so pass it only when
63
+ * the binding exists.
63
64
  */
64
65
  cloudflareSend?: CloudflareSend;
65
66
  /**
@@ -95,7 +96,7 @@ declare const createCaptureSink: (env: MailEnv, rootShard?: string, jurisdiction
95
96
  /**
96
97
  * Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
97
98
  * captured into the studio's Mail inbox; otherwise it delivers via the supplied
98
- * `cloudflareSend` (used only when the `SEND_EMAIL` binding is present) or,
99
+ * `cloudflareSend` (when passed) or,
99
100
  * failing that, `RESEND_API_KEY`. With no real transport `send()` rejects, so a
100
101
  * misconfigured production deploy fails loudly instead of silently dropping mail
101
102
  * — while `queue()` still works for a producer-only worker.
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-bWoNSnK_.mjs";import{default as u}from"./packem_shared/createMailer-ImyDcZuj.mjs";import{createCaptureSink as f,createMailerFromEnv as l,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-Bw5lqHql.mjs";import{consumeQueuedSend as s,toQueuedPayload as c}from"./packem_shared/consumeQueuedSend-CRfALnCU.mjs";import{default as i}from"./packem_shared/renderEmail-CkxYrU2s.mjs";import{default as M}from"./packem_shared/createResendTransport-BMjRlHmy.mjs";export{s as consumeQueuedSend,f as createCaptureSink,a as createCaptureTransport,t as createCloudflareTransport,u as createMailer,l as createMailerFromEnv,M as createResendTransport,i as renderEmail,m as shouldCaptureMail,c as toQueuedPayload};
1
+ import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-DZhMUmaI.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-bWoNSnK_.mjs";import{default as u}from"./packem_shared/createMailer-ImyDcZuj.mjs";import{createCaptureSink as f,createMailerFromEnv as l,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-BIu-c0Kd.mjs";import{consumeQueuedSend as s,toQueuedPayload as c}from"./packem_shared/consumeQueuedSend-CRfALnCU.mjs";import{default as i}from"./packem_shared/renderEmail-CkxYrU2s.mjs";import{default as M}from"./packem_shared/createResendTransport-BMjRlHmy.mjs";export{s as consumeQueuedSend,f as createCaptureSink,a as createCaptureTransport,t as createCloudflareTransport,u as createMailer,l as createMailerFromEnv,M as createResendTransport,i as renderEmail,m as shouldCaptureMail,c as toQueuedPayload};
@@ -0,0 +1 @@
1
+ import{createCaptureTransport as d}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-bWoNSnK_.mjs";import s from"./createMailer-ImyDcZuj.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-CkxYrU2s.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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/mail",
3
- "version": "1.0.0-alpha.103",
3
+ "version": "1.0.0-alpha.105",
4
4
  "description": "Email for Lunora: Resend adapter, TSX templates, and queue-backed sends",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -1 +0,0 @@
1
- import{createCaptureTransport as d}from"./createCaptureTransport-DZhMUmaI.mjs";import"./createCloudflareTransport-bWoNSnK_.mjs";import s from"./createMailer-ImyDcZuj.mjs";import{LunoraError as l}from"@lunora/errors";import{D as E,a as _,p}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-CRfALnCU.mjs";import"./renderEmail-CkxYrU2s.mjs";import"./createResendTransport-BMjRlHmy.mjs";const N="__lunora_admin__:recordMail",f=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,m=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],A=(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},R=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=m.map(t=>r[t]).filter(t=>typeof t=="string"&&t!=="");return o.length>0&&o.every(t=>f.test(t))};let u=!1;const g=(r,e=E,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=_(i,o);try{return{id:(await p(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"}}}}),y=(r,e={})=>{const o=A(r,"MAIL_FROM");if(R(r))return s({from:o,queue:e.queue,transport:d(g(r,e.rootShard,e.jurisdiction))});const t=r.SEND_EMAIL===void 0?void 0:e.cloudflareSend,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,y as createMailerFromEnv,R as shouldCaptureMail};