@lunora/mail 1.0.0-alpha.89 → 1.0.0-alpha.90
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/inbound/index.d.mts +5 -3
- package/dist/inbound/index.d.ts +5 -3
- package/dist/inbound/index.mjs +1 -1
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/createCaptureSink-D5FHD5HJ.mjs +1 -0
- package/dist/packem_shared/createInboundEmailHandler-QnZHQZpF.mjs +1 -0
- package/dist/packem_shared/shard-C5t-b7FX.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/createCaptureSink-DI9tmsLn.mjs +0 -1
- package/dist/packem_shared/createInboundEmailHandler-Bh10YPyJ.mjs +0 -1
- package/dist/packem_shared/shard-CRhAKK93.mjs +0 -1
package/dist/inbound/index.d.mts
CHANGED
|
@@ -274,9 +274,11 @@ interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
|
|
|
274
274
|
/** `functionPath` of the target mutation/action (e.g. `"inbound:onEmail"`). */
|
|
275
275
|
functionPath: string;
|
|
276
276
|
/**
|
|
277
|
-
* Pin inbound dispatch to a Cloudflare data-residency jurisdiction.
|
|
278
|
-
*
|
|
279
|
-
*
|
|
277
|
+
* Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Defaults
|
|
278
|
+
* to the jurisdiction the schema declares (`.jurisdiction("eu")`), so a
|
|
279
|
+
* generated app needs nothing here; set it only for a hand-written worker, to
|
|
280
|
+
* the same value as its `jurisdiction`. A value that contradicts the schema's
|
|
281
|
+
* throws.
|
|
280
282
|
*/
|
|
281
283
|
jurisdiction?: DurableObjectJurisdiction;
|
|
282
284
|
/**
|
package/dist/inbound/index.d.ts
CHANGED
|
@@ -274,9 +274,11 @@ interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
|
|
|
274
274
|
/** `functionPath` of the target mutation/action (e.g. `"inbound:onEmail"`). */
|
|
275
275
|
functionPath: string;
|
|
276
276
|
/**
|
|
277
|
-
* Pin inbound dispatch to a Cloudflare data-residency jurisdiction.
|
|
278
|
-
*
|
|
279
|
-
*
|
|
277
|
+
* Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Defaults
|
|
278
|
+
* to the jurisdiction the schema declares (`.jurisdiction("eu")`), so a
|
|
279
|
+
* generated app needs nothing here; set it only for a hand-written worker, to
|
|
280
|
+
* the same value as its `jurisdiction`. A value that contradicts the schema's
|
|
281
|
+
* throws.
|
|
280
282
|
*/
|
|
281
283
|
jurisdiction?: DurableObjectJurisdiction;
|
|
282
284
|
/**
|
package/dist/inbound/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createInboundEmailHandler as n,dispatchToLunoraFunction as r}from"../packem_shared/createInboundEmailHandler-
|
|
1
|
+
import{createInboundEmailHandler as n,dispatchToLunoraFunction as r}from"../packem_shared/createInboundEmailHandler-QnZHQZpF.mjs";import{authenticatesFrom as t,parseInboundEmail as i}from"../packem_shared/authenticatesFrom-BOX-Paur.mjs";export{t as authenticatesFrom,n as createInboundEmailHandler,r as dispatchToLunoraFunction,i as parseInboundEmail};
|
package/dist/index.d.mts
CHANGED
|
@@ -60,8 +60,10 @@ interface FromEnvOptions {
|
|
|
60
60
|
cloudflareSend?: CloudflareSend;
|
|
61
61
|
/**
|
|
62
62
|
* Pin the captured-mail inbox shard to a Cloudflare data-residency
|
|
63
|
-
* jurisdiction.
|
|
64
|
-
*
|
|
63
|
+
* jurisdiction. Defaults to the jurisdiction the schema declares
|
|
64
|
+
* (`.jurisdiction("eu")`), so a generated app needs nothing here; set it only
|
|
65
|
+
* for a hand-written worker, to the same value as its `jurisdiction`. A value
|
|
66
|
+
* that contradicts the schema's throws.
|
|
65
67
|
*/
|
|
66
68
|
jurisdiction?: DurableObjectJurisdiction;
|
|
67
69
|
/** Shard the captured-mail inbox lives on; override if your worker sets a custom `defaultShardKey`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -60,8 +60,10 @@ interface FromEnvOptions {
|
|
|
60
60
|
cloudflareSend?: CloudflareSend;
|
|
61
61
|
/**
|
|
62
62
|
* Pin the captured-mail inbox shard to a Cloudflare data-residency
|
|
63
|
-
* jurisdiction.
|
|
64
|
-
*
|
|
63
|
+
* jurisdiction. Defaults to the jurisdiction the schema declares
|
|
64
|
+
* (`.jurisdiction("eu")`), so a generated app needs nothing here; set it only
|
|
65
|
+
* for a hand-written worker, to the same value as its `jurisdiction`. A value
|
|
66
|
+
* that contradicts the schema's throws.
|
|
65
67
|
*/
|
|
66
68
|
jurisdiction?: DurableObjectJurisdiction;
|
|
67
69
|
/** Shard the captured-mail inbox lives on; override if your worker sets a custom `defaultShardKey`. */
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-CKc6NpZR.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-bWoNSnK_.mjs";import{default as u}from"./packem_shared/createMailer-aRrzRLwc.mjs";import{createCaptureSink as f,createMailerFromEnv as l,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-
|
|
1
|
+
import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-CKc6NpZR.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-bWoNSnK_.mjs";import{default as u}from"./packem_shared/createMailer-aRrzRLwc.mjs";import{createCaptureSink as f,createMailerFromEnv as l,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-D5FHD5HJ.mjs";import{consumeQueuedSend as s,toQueuedPayload as c}from"./packem_shared/consumeQueuedSend-CRfALnCU.mjs";import{default as i}from"./packem_shared/renderEmail-BOUnr6i3.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 l}from"./createCaptureTransport-CKc6NpZR.mjs";import"./createCloudflareTransport-bWoNSnK_.mjs";import n from"./createMailer-aRrzRLwc.mjs";import{LunoraError as u}from"@lunora/errors";import{D as p,a as E,p as N}from"./shard-C5t-b7FX.mjs";import"./consumeQueuedSend-CRfALnCU.mjs";import"./renderEmail-BOUnr6i3.mjs";import"./createResendTransport-BMjRlHmy.mjs";const _="__lunora_admin__:recordMail",f=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,m=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],A=(e,t)=>{const r=e[t];if(typeof r!="string"||r==="")throw new u("INTERNAL",`@lunora/mail: missing env var \`${t}\` — set it in .dev.vars (and \`wrangler secret put ${t}\` for secrets).`);return r},R=e=>{const t=e.LUNORA_MAIL_CAPTURE;if(typeof t=="string"){const r=t.toLowerCase();if(r==="1"||r==="true")return!0;if(r==="0"||r==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${t}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}return m.some(r=>{const o=e[r];return typeof o=="string"&&f.test(o)})};let d=!1;const g=(e,t=p,r)=>({record:async o=>{const i=e.SHARD,a=typeof e.LUNORA_ADMIN_TOKEN=="string"?e.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return d||(d=!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,r);try{return{id:(await N(c,{adminToken:a,envelope:{args:o,functionPath:_},label:"@lunora/mail: recording captured mail",shardKey:t})).result?.id??"captured"}}catch(s){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",s),{id:"uncaptured"}}}}),D=(e,t={})=>{const r=A(e,"MAIL_FROM");if(R(e))return n({from:r,transport:l(g(e,t.rootShard,t.jurisdiction))});if(t.cloudflareSend)return n({cloudflareSend:t.cloudflareSend,from:r});const o=typeof e.RESEND_API_KEY=="string"?e.RESEND_API_KEY:void 0;if(o!==void 0&&o!=="")return n({apiKey:o,from:r});throw new u("INTERNAL","@lunora/mail: no transport configured — provide `cloudflareSend` (a SEND_EMAIL binding) or RESEND_API_KEY, or run in a dev environment to capture.")};export{g as createCaptureSink,D as createMailerFromEnv,R as shouldCaptureMail};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as d}from"@lunora/errors";import{D as h,p as l,a as f}from"./shard-C5t-b7FX.mjs";const E=r=>{let n="";for(let e=0;e<r.length;e+=32768)n+=String.fromCharCode(...r.subarray(e,e+32768));return btoa(n)},m="message could not be processed",u=(r,n)=>{console.error("@lunora/mail/inbound: dropping message —",r),n.message.setReject(m)},y=r=>r===!0||r===void 0,N=r=>{const n=r.onError??u;return async(t,e,c)=>{const a={ctx:c,env:e,message:t};let i;try{if(i=await r.parse(t.raw),r.verify){const o=await r.verify(i,a);if(!y(o))throw new d("INTERNAL","@lunora/mail/inbound: sender verification rejected the message")}}catch(o){await n(o,a);return}try{await r.dispatch(i,a)}catch(o){if(r.onError)try{await r.onError(o,a)}catch(s){console.error("@lunora/mail/inbound: onError threw while reporting a dispatch failure —",s)}if(r.retain)try{await r.retain(i,a,o);return}catch(s){console.error("@lunora/mail/inbound: retain failed to take ownership of the message —",s)}u(o,a)}}},g=r=>r.attachments.length===0?r:{...r,attachments:r.attachments.map(n=>{const{content:t}=n;if(typeof t=="string")return n;const e=t instanceof Uint8Array?t:new Uint8Array(t);return{...n,content:E(e),encoding:"base64"}})},b=r=>{const n=r.shardKey??h,t=r.resolveArgs??(e=>g(e));return async(e,c)=>{const a=r.adminToken??(typeof c.env.LUNORA_ADMIN_TOKEN=="string"?c.env.LUNORA_ADMIN_TOKEN:void 0);if(a===void 0||a==="")throw new d("INTERNAL","@lunora/mail/inbound: missing LUNORA_ADMIN_TOKEN — cannot authorize inbound dispatch to the shard RPC.");const i={args:t(e,c),functionPath:r.functionPath,shardKey:n};await l(f(r.shard,r.jurisdiction),{adminToken:a,envelope:i,label:`@lunora/mail/inbound: dispatch to \`${r.functionPath}\``,shardKey:n})}};export{N as createInboundEmailHandler,b as dispatchToLunoraFunction};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as s}from"@lunora/errors";const a=Symbol.for("lunora:app-jurisdiction"),c=globalThis,l=()=>c[a],u="__root__",p=(t,o)=>{const e=l();if(o!==void 0&&e!==void 0&&o!==e)throw new TypeError(`@lunora/mail: jurisdiction "${o}" contradicts the app's declared jurisdiction "${e}" — drop the option; mail follows the schema's \`.jurisdiction()\``);const r=o??e;if(r===void 0)return t;if(typeof t.jurisdiction!="function")throw new TypeError(`@lunora/mail: Durable Object namespace does not support jurisdiction("${r}") — update @cloudflare/workers-types or remove the jurisdiction`);return t.jurisdiction(r)},f=async(t,o)=>{const r=await t.get(t.idFromName(o.shardKey)).fetch("https://shard.internal/rpc",{body:JSON.stringify(o.envelope),headers:{authorization:`Bearer ${o.adminToken}`,"content-type":"application/json","x-lunora-system":"1"},method:"POST"});if(r.ok===!1)throw new s("INTERNAL",`${o.label} failed (HTTP ${String(r.status??"?")}).`);const i=await r.json();if(typeof i=="object"&&i!==null&&"error"in i){const{error:n}=i;if(n!=null)throw new s("INTERNAL",`${o.label} returned an error: ${JSON.stringify(n)}`)}return i};export{u as D,p as a,f as p};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createCaptureTransport as l}from"./createCaptureTransport-CKc6NpZR.mjs";import"./createCloudflareTransport-bWoNSnK_.mjs";import n from"./createMailer-aRrzRLwc.mjs";import{LunoraError as u}from"@lunora/errors";import{D as c,p as E}from"./shard-CRhAKK93.mjs";import"./consumeQueuedSend-CRfALnCU.mjs";import"./renderEmail-BOUnr6i3.mjs";import"./createResendTransport-BMjRlHmy.mjs";const p="__lunora_admin__:recordMail",N=/^(?:dev(?:elopment)?|local(?:host)?|test)$/iu,_=["CF_ENV","ENVIRONMENT","NODE_ENV","WORKER_ENV"],f=(e,t)=>{const r=e[t];if(typeof r!="string"||r==="")throw new u("INTERNAL",`@lunora/mail: missing env var \`${t}\` — set it in .dev.vars (and \`wrangler secret put ${t}\` for secrets).`);return r},m=e=>{const t=e.LUNORA_MAIL_CAPTURE;if(typeof t=="string"){const r=t.toLowerCase();if(r==="1"||r==="true")return!0;if(r==="0"||r==="false")return!1;console.warn(`@lunora/mail: unrecognized LUNORA_MAIL_CAPTURE value "${t}" — expected "1"/"true" or "0"/"false"; falling back to environment detection.`)}return _.some(r=>{const o=e[r];return typeof o=="string"&&N.test(o)})};let d=!1;const A=(e,t=c,r)=>({record:async o=>{const i=e.SHARD,a=typeof e.LUNORA_ADMIN_TOKEN=="string"?e.LUNORA_ADMIN_TOKEN:void 0;if(i===void 0||a===void 0)return d||(d=!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"};try{return{id:(await E(i,{adminToken:a,envelope:{args:o,functionPath:p},jurisdiction:r,label:"@lunora/mail: recording captured mail",shardKey:t})).result?.id??"captured"}}catch(s){return console.error("@lunora/mail: failed to record captured mail into the studio inbox —",s),{id:"uncaptured"}}}}),h=(e,t={})=>{const r=f(e,"MAIL_FROM");if(m(e))return n({from:r,transport:l(A(e,t.rootShard,t.jurisdiction))});if(t.cloudflareSend)return n({cloudflareSend:t.cloudflareSend,from:r});const o=typeof e.RESEND_API_KEY=="string"?e.RESEND_API_KEY:void 0;if(o!==void 0&&o!=="")return n({apiKey:o,from:r});throw new u("INTERNAL","@lunora/mail: no transport configured — provide `cloudflareSend` (a SEND_EMAIL binding) or RESEND_API_KEY, or run in a dev environment to capture.")};export{A as createCaptureSink,h as createMailerFromEnv,m as shouldCaptureMail};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as d}from"@lunora/errors";import{D as h,p as l}from"./shard-CRhAKK93.mjs";const f=r=>{let n="";for(let e=0;e<r.length;e+=32768)n+=String.fromCharCode(...r.subarray(e,e+32768));return btoa(n)},E="message could not be processed",u=(r,n)=>{console.error("@lunora/mail/inbound: dropping message —",r),n.message.setReject(E)},m=r=>r===!0||r===void 0,A=r=>{const n=r.onError??u;return async(t,e,c)=>{const a={ctx:c,env:e,message:t};let i;try{if(i=await r.parse(t.raw),r.verify){const o=await r.verify(i,a);if(!m(o))throw new d("INTERNAL","@lunora/mail/inbound: sender verification rejected the message")}}catch(o){await n(o,a);return}try{await r.dispatch(i,a)}catch(o){if(r.onError)try{await r.onError(o,a)}catch(s){console.error("@lunora/mail/inbound: onError threw while reporting a dispatch failure —",s)}if(r.retain)try{await r.retain(i,a,o);return}catch(s){console.error("@lunora/mail/inbound: retain failed to take ownership of the message —",s)}u(o,a)}}},y=r=>r.attachments.length===0?r:{...r,attachments:r.attachments.map(n=>{const{content:t}=n;if(typeof t=="string")return n;const e=t instanceof Uint8Array?t:new Uint8Array(t);return{...n,content:f(e),encoding:"base64"}})},N=r=>{const n=r.shardKey??h,t=r.resolveArgs??(e=>y(e));return async(e,c)=>{const a=r.adminToken??(typeof c.env.LUNORA_ADMIN_TOKEN=="string"?c.env.LUNORA_ADMIN_TOKEN:void 0);if(a===void 0||a==="")throw new d("INTERNAL","@lunora/mail/inbound: missing LUNORA_ADMIN_TOKEN — cannot authorize inbound dispatch to the shard RPC.");const i={args:t(e,c),functionPath:r.functionPath,shardKey:n};await l(r.shard,{adminToken:a,envelope:i,jurisdiction:r.jurisdiction,label:`@lunora/mail/inbound: dispatch to \`${r.functionPath}\``,shardKey:n})}};export{A as createInboundEmailHandler,N as dispatchToLunoraFunction};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as s}from"@lunora/errors";const d="__root__",a=(t,r)=>{if(r===void 0)return t;if(typeof t.jurisdiction!="function")throw new TypeError(`@lunora/mail: Durable Object namespace does not support jurisdiction("${r}") — update @cloudflare/workers-types or remove the jurisdiction option`);return t.jurisdiction(r)},l=async(t,r)=>{const i=a(t,r.jurisdiction),e=await i.get(i.idFromName(r.shardKey)).fetch("https://shard.internal/rpc",{body:JSON.stringify(r.envelope),headers:{authorization:`Bearer ${r.adminToken}`,"content-type":"application/json","x-lunora-system":"1"},method:"POST"});if(e.ok===!1)throw new s("INTERNAL",`${r.label} failed (HTTP ${String(e.status??"?")}).`);const o=await e.json();if(typeof o=="object"&&o!==null&&"error"in o){const{error:n}=o;if(n!=null)throw new s("INTERNAL",`${r.label} returned an error: ${JSON.stringify(n)}`)}return o};export{d as D,l as p};
|