@lunora/mail 1.0.0-alpha.13 → 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.
Files changed (43) hide show
  1. package/dist/inbound/index.d.mts +326 -78
  2. package/dist/inbound/index.d.ts +326 -78
  3. package/dist/inbound/index.mjs +1 -2
  4. package/dist/index.d.mts +186 -96
  5. package/dist/index.d.ts +186 -96
  6. package/dist/index.mjs +1 -7
  7. package/dist/packem_shared/MailSendError-HH5Yimut.mjs +1 -0
  8. package/dist/packem_shared/address-oKy_d0aG.mjs +3 -0
  9. package/dist/packem_shared/authenticatesFrom-BDGSL3q4.mjs +1 -0
  10. package/dist/packem_shared/capture-transport.d-BD67fxbB.d.mts +130 -0
  11. package/dist/packem_shared/capture-transport.d-BD67fxbB.d.ts +130 -0
  12. package/dist/packem_shared/consumeQueuedSend-CRfALnCU.mjs +1 -0
  13. package/dist/packem_shared/createCaptureSink-BSAR1HTL.mjs +1 -0
  14. package/dist/packem_shared/createCaptureTransport-DZhMUmaI.mjs +1 -0
  15. package/dist/packem_shared/createCloudflareTransport-fOhfy2fP.mjs +1 -0
  16. package/dist/packem_shared/createInboundEmailHandler-CixBJpmc.mjs +1 -0
  17. package/dist/packem_shared/createMailer-C5NIzkNb.mjs +1 -0
  18. package/dist/packem_shared/createResendTransport-q3surKen.mjs +1 -0
  19. package/dist/packem_shared/provider-transport-DklK6xUa.mjs +1 -0
  20. package/dist/packem_shared/renderEmail-xypKDdux.mjs +1 -0
  21. package/dist/packem_shared/shard-C5t-b7FX.mjs +1 -0
  22. package/dist/packem_shared/shard.d-DVADjmEJ.d.mts +29 -0
  23. package/dist/packem_shared/shard.d-DVADjmEJ.d.ts +29 -0
  24. package/dist/testing.d.mts +9 -9
  25. package/dist/testing.d.ts +9 -9
  26. package/dist/testing.mjs +1 -63
  27. package/package.json +5 -5
  28. package/dist/packem_shared/address-vSUAVU2T.mjs +0 -64
  29. package/dist/packem_shared/capture-transport.d-ChnhdPO2.d.mts +0 -117
  30. package/dist/packem_shared/capture-transport.d-ChnhdPO2.d.ts +0 -117
  31. package/dist/packem_shared/consumeQueuedSend-B9hTDOZ6.mjs +0 -77
  32. package/dist/packem_shared/createCaptureSink-Di-5AJUs.mjs +0 -65
  33. package/dist/packem_shared/createCaptureTransport-Crz_8822.mjs +0 -11
  34. package/dist/packem_shared/createCloudflareTransport-DXh1nUNi.mjs +0 -28
  35. package/dist/packem_shared/createInboundEmailHandler-BW_s0-Vc.mjs +0 -84
  36. package/dist/packem_shared/createMailer-B4Z_Cgiu.mjs +0 -81
  37. package/dist/packem_shared/createResendTransport-CMQWjZoi.mjs +0 -16
  38. package/dist/packem_shared/parseInboundEmail-6lafQBT1.mjs +0 -72
  39. package/dist/packem_shared/provider-transport-C0xHi3oy.mjs +0 -48
  40. package/dist/packem_shared/renderEmail-hyS1bpVP.mjs +0 -8
  41. package/dist/packem_shared/shard-CJ-TvmfT.mjs +0 -13
  42. package/dist/packem_shared/shard.d-CL2Lmliv.d.mts +0 -39
  43. package/dist/packem_shared/shard.d-CL2Lmliv.d.ts +0 -39
@@ -1,5 +1,5 @@
1
- import { D as DurableObjectJurisdiction, S as ShardNamespaceLike } from "../packem_shared/shard.d-CL2Lmliv.js";
2
- export type { a as ShardStubLike } from "../packem_shared/shard.d-CL2Lmliv.js";
1
+ import { D as DurableObjectJurisdiction, S as ShardNamespaceLike } from "../packem_shared/shard.d-DVADjmEJ.js";
2
+ export type { a as ShardStubLike } from "../packem_shared/shard.d-DVADjmEJ.js";
3
3
  /** A raw RFC 822 message as accepted by the parser. */
4
4
  type RawInboundEmail = ArrayBuffer | ReadableStream<Uint8Array> | string | Uint8Array;
5
5
  /** One parsed attachment. `content` is preserved as the parser decoded it. */
@@ -14,35 +14,82 @@ interface InboundAttachment {
14
14
  filename: string | null;
15
15
  /** Declared MIME type (e.g. `image/png`). */
16
16
  mimeType: string;
17
+ /** Binary content dropped because the forwarded envelope exceeded the attachment byte budget. */
18
+ truncated?: boolean;
19
+ }
20
+ /** One reported `method=result [ptype.property=value]` clause of an `Authentication-Results` header. */
21
+ interface InboundAuthResult {
22
+ /**
23
+ * The identifier the result is about, lowercased — DKIM's signing domain
24
+ * (`header.d=`), SPF's envelope `MAIL FROM` domain (`smtp.mailfrom=`, local
25
+ * part dropped) or DMARC's `header.from=`. `null` when the clause reported
26
+ * none, in which case it cannot be aligned and vouches for nothing.
27
+ */
28
+ domain: string | null;
29
+ /** The result token, lowercased (`"pass"`, `"fail"`, `"none"`, …). */
30
+ result: string;
17
31
  }
18
32
  /**
19
- * Sender-authentication verdicts pulled from the `Authentication-Results` header
20
- * the receiving MX (e.g. Cloudflare Email Routing) stamped on the message.
21
- *
22
- * SECURITY: Cloudflare Email Routing authenticates only the *recipient* domain,
23
- * **not** the sender. The envelope `from` and message content are trivially
24
- * spoofable, so a downstream handler MUST NOT make trust/authorization decisions
25
- * on `email.from` alone — gate on these verdicts (or your own policy) instead.
26
- * Verdicts are best-effort: when the receiving MX did not stamp an
27
- * `Authentication-Results` header, every field is `null` ("unknown").
28
- */
33
+ * Sender-authentication verdicts pulled from the `Authentication-Results` header
34
+ * the receiving MX (e.g. Cloudflare Email Routing) stamped on the message.
35
+ *
36
+ * SECURITY: Cloudflare Email Routing authenticates only the *recipient* domain,
37
+ * **not** the sender. The envelope `from` and message content are trivially
38
+ * spoofable, so a downstream handler MUST NOT make trust/authorization decisions
39
+ * on `email.from` alone — gate on these verdicts (or your own policy) instead.
40
+ * Verdicts are best-effort: when the receiving MX did not stamp an
41
+ * `Authentication-Results` header, every list is empty ("unknown").
42
+ *
43
+ * Each method holds a LIST, because RFC 8601 lets one header report the same
44
+ * method more than once and real mail does. An ESP-relayed message carries two
45
+ * DKIM signatures — the relay's and the author domain's — and the MX stamps a
46
+ * clause per signature in whatever order it verified them. Keeping only the
47
+ * first threw the aligned one away whenever it was not the one that happened to
48
+ * come first, and the message was rejected as unauthenticated. A consumer
49
+ * therefore asks "does ANY reported clause pass and align?", not "did the first
50
+ * one?".
51
+ *
52
+ * SECURITY: a bare `"pass"` is NOT proof the `From` header is genuine. SPF
53
+ * authenticates the envelope `MAIL FROM` domain and DKIM the signing domain
54
+ * (`d=`), and an attacker controls both — `spf=pass smtp.mailfrom=evil.example;
55
+ * dkim=pass header.d=evil.example` is routine for a message whose `From` says
56
+ * `ceo@victim.example`. Each verdict therefore carries the identifier it is
57
+ * about ({@link InboundAuthResult.domain}): an SPF or DKIM pass only vouches for
58
+ * `from` when that domain equals the `From` address's domain (RFC 7489 strict
59
+ * alignment). Only a DMARC pass already checked alignment for you. A pass with
60
+ * no identifier reported cannot be aligned and must be treated as
61
+ * unauthenticated.
62
+ *
63
+ * SECURITY: verdicts are read from the **first/topmost** `Authentication-Results`
64
+ * header in document order. The receiving MX prepends its own genuine header per
65
+ * RFC 8601, so the topmost occurrence is the trustworthy one; any lower
66
+ * occurrences (which an untrusted sender can inject into the raw message) are
67
+ * ignored. As defense-in-depth a consumer may additionally verify the topmost
68
+ * header's `authserv-id` matches its receiving MX (e.g. Cloudflare) — that needs
69
+ * config this runtime-agnostic parser does not carry, so it is left to the host.
70
+ */
29
71
  interface InboundAuthentication {
30
- /** DKIM verdict (`"pass"`/`"fail"`/…), or `null` when not reported. */
31
- dkim: string | null;
32
- /** DMARC verdict (`"pass"`/`"fail"`/…), or `null` when not reported. */
33
- dmarc: string | null;
34
- /** SPF verdict (`"pass"`/`"fail"`/…), or `null` when not reported. */
35
- spf: string | null;
72
+ /** Every DKIM clause the header reported, in header order; empty when the method was not reported. */
73
+ dkim: InboundAuthResult[];
74
+ /** Every DMARC clause the header reported, in header order; empty when the method was not reported. */
75
+ dmarc: InboundAuthResult[];
76
+ /** Every SPF clause the header reported, in header order; empty when the method was not reported. */
77
+ spf: InboundAuthResult[];
36
78
  }
37
79
  /** Normalised, transport-agnostic view of a received message. */
38
80
  interface InboundEmail {
39
81
  /** Decoded attachments (empty array when none). */
40
82
  attachments: InboundAttachment[];
41
83
  /**
42
- * Sender-authentication verdicts (DKIM/SPF/DMARC) parsed from the receiving
43
- * MX's `Authentication-Results` header. SECURITY: see {@link InboundAuthentication}
44
- * — `from` is spoofable; gate trust on these verdicts, not on `from`.
45
- */
84
+ * Sender-authentication verdicts (DKIM/SPF/DMARC) and the domain each is
85
+ * about, parsed from the receiving MX's **first/topmost**
86
+ * `Authentication-Results` header. SECURITY: see
87
+ * {@link InboundAuthentication} — `from` is spoofable, and an SPF/DKIM pass
88
+ * vouches for it only when that clause's `domain` equals the `From` domain (a
89
+ * DMARC pass checked that already). Reading the raw `headers["authentication-results"]`
90
+ * map instead exposes last-wins (a lower, potentially attacker-injected)
91
+ * value — trust `authentication`, not the raw map.
92
+ */
46
93
  authentication: InboundAuthentication;
47
94
  /** Sender mailbox (`from`), CR/LF-checked. Empty string when the message omitted it. SECURITY: spoofable — do not trust for authorization. */
48
95
  from: string;
@@ -64,17 +111,48 @@ interface InboundEmail {
64
111
  to: string[];
65
112
  }
66
113
  /**
67
- * Parse a raw RFC 822 message into a normalised {@link InboundEmail}. Accepts the
68
- * shapes a Cloudflare Email Worker can hand off — `ReadableStream`, `ArrayBuffer`,
69
- * `Uint8Array`, or a decoded string.
70
- */
114
+ * Parse a raw RFC 822 message into a normalised {@link InboundEmail}. Accepts the
115
+ * shapes a Cloudflare Email Worker can hand off — `ReadableStream`, `ArrayBuffer`,
116
+ * `Uint8Array`, or a decoded string.
117
+ */
71
118
  declare const parseInboundEmail: (raw: RawInboundEmail) => Promise<InboundEmail>;
72
119
  /**
73
- * Structural projection of Cloudflare's `ForwardableEmailMessage` (verified
74
- * against `@cloudflare/workers-types`' `ForwardableEmailMessage`). Only the
75
- * members the handler touches are modelled, so the host can pass the real
76
- * runtime object without `@lunora/mail` importing `cloudflare:email`.
77
- */
120
+ * THE inbound sender-authentication gate: does the receiving MX vouch for this
121
+ * message's `From` domain? Pass it as the `verify` hook of
122
+ * `createInboundEmailHandler` (or call it from your own) — it is one exported
123
+ * helper precisely so the insecure variants cannot be hand-rolled again.
124
+ *
125
+ * True when ANY reported DMARC, SPF or DKIM clause both **passes** and names a
126
+ * `domain` equal to the `From` address's domain. False otherwise — including for
127
+ * an empty verdict list (the MX stamped no `Authentication-Results` header at
128
+ * all, which is "unknown", not "fine") and for a `From` with no single mailbox
129
+ * to align against.
130
+ *
131
+ * SECURITY — the two halves are each load-bearing.
132
+ *
133
+ * **Alignment.** A bare `pass` proves nothing about `From`. SPF authenticates the
134
+ * envelope `MAIL FROM` domain and DKIM the signing `d=`, both attacker-chosen, so
135
+ * `spf=pass`+`dkim=pass` for `evil.example` is routine on a message whose `From`
136
+ * says `ceo@victim.example`. Only a clause whose own `domain` equals the `From`
137
+ * domain vouches for it. Alignment is STRICT (RFC 7489): there is no
138
+ * public-suffix list here, so `mail.example.com` does not vouch for
139
+ * `example.com`. A pass reporting no domain (`null`) cannot be aligned and is
140
+ * rejected. A DMARC pass already checked alignment at the MX.
141
+ *
142
+ * **Every clause, not the first.** One header legitimately reports a method more
143
+ * than once (an ESP-relayed message is DKIM-signed by both the relay and the
144
+ * author domain), and the aligned clause is not reliably the first, so reading
145
+ * only the first bounced fully authenticated mail. "Any clause passes AND aligns"
146
+ * stays strictly narrower than a bare pass: a clause vouching for some other
147
+ * domain contributes nothing.
148
+ */
149
+ declare const authenticatesFrom: (email: InboundEmail) => boolean;
150
+ /**
151
+ * Structural projection of Cloudflare's `ForwardableEmailMessage` (verified
152
+ * against `@cloudflare/workers-types`' `ForwardableEmailMessage`). Only the
153
+ * members the handler touches are modelled, so the host can pass the real
154
+ * runtime object without `@lunora/mail` importing `cloudflare:email`.
155
+ */
78
156
  interface ForwardableEmailMessageLike {
79
157
  /** Forward this message to a verified destination address. */
80
158
  forward: (rcptTo: string, headers?: Headers) => Promise<unknown>;
@@ -90,7 +168,14 @@ interface ForwardableEmailMessageLike {
90
168
  raw: string;
91
169
  to: string;
92
170
  }) => Promise<unknown>;
93
- /** Reject the message with a permanent SMTP error (Cloudflare bounces/retries). */
171
+ /**
172
+ * Reject the message with a PERMANENT SMTP error — Cloudflare returns it to
173
+ * the connecting client with this reason, and it is never redelivered.
174
+ * Documented at https://developers.cloudflare.com/email-routing/email-workers/runtime-api/
175
+ * ("Reject this email message by returning a permanent SMTP error back to
176
+ * the connecting client, including the given reason") and mirrored in
177
+ * workerd's own `types/defines/email.d.ts`.
178
+ */
94
179
  setReject: (reason: string) => void;
95
180
  /** Envelope `To`. */
96
181
  readonly to: string;
@@ -107,43 +192,73 @@ interface InboundDispatchContext<TEnv = Record<string, unknown>> {
107
192
  /** Routes a parsed message into a Lunora function (or anywhere). */
108
193
  type InboundDispatch<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<void>;
109
194
  /**
110
- * Opt-in sender-verification gate. Runs after `parse` and before `dispatch` with
111
- * the parsed message. Return `false` (or throw) to reject the message before it
112
- * reaches the privileged dispatch — use it to enforce DKIM/SPF/DMARC via
113
- * `email.authentication`, an allow-list, etc. Returning `true`/`undefined`
114
- * proceeds.
115
- */
195
+ * Opt-in sender-verification gate. Runs after `parse` and before `dispatch` with
196
+ * the parsed message. Return `false` (or throw) to reject the message before it
197
+ * reaches the privileged dispatch — use it to enforce DKIM/SPF/DMARC via
198
+ * `email.authentication`, an allow-list, etc.
199
+ *
200
+ * `true` and `undefined` are the ONLY answers that proceed — `undefined` so a
201
+ * `(): void` hook that rejects by throwing type-checks. Anything else is read as a
202
+ * rejection: this is the gate whose failure mode would otherwise grant.
203
+ */
116
204
  type InboundVerify<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<boolean | void> | boolean | void;
205
+ /**
206
+ * Opt-in durable sink for a failed `dispatch`. Hand the parsed message to
207
+ * something that owns the retry — a queue producer, a Durable Object, an alarm
208
+ * — and the handler ACCEPTS the SMTP session instead of bouncing, because the
209
+ * message is now owned rather than lost. Returning normally means "I have it";
210
+ * throwing means the hand-off itself failed and the message bounces with the
211
+ * generic reason (see {@link createInboundEmailHandler}).
212
+ *
213
+ * `error` is the dispatch failure, for classification/logging by the sink.
214
+ *
215
+ * NOTE: binary attachment `content` is an `ArrayBuffer`/`Uint8Array`, which
216
+ * survives structured clone (Cloudflare Queues, DO storage) but is corrupted by
217
+ * `JSON.stringify` — encode it yourself if the sink is JSON-bodied.
218
+ */
219
+ type InboundRetain<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>, error: unknown) => Promise<void> | void;
117
220
  /** Options for {@link createInboundEmailHandler}. */
118
221
  interface InboundEmailHandlerOptions<TEnv = Record<string, unknown>> {
119
222
  /** Routes the parsed message onward (e.g. {@link dispatchToLunoraFunction}). */
120
223
  dispatch: InboundDispatch<TEnv>;
121
224
  /**
122
- * Called when `parse`/`verify`/`dispatch` throws. The default rejects the
123
- * message via `message.setReject` so Cloudflare bounces/retries rather than
124
- * silently dropping it. SECURITY: the reject reason is delivered to the
125
- * (attacker-controlled) sender as a bounce, so the default reason is a fixed,
126
- * generic string and the real error is logged server-side. Override to log,
127
- * forward, or swallow — but never pass internal error text to `setReject`.
128
- */
225
+ * Called when `parse`, `verify`, or `dispatch` fails — but with two DIFFERENT
226
+ * contracts, because only the first two decide the message's fate here:
227
+ *
228
+ * - `parse` / `verify` — this hook DECIDES the outcome. The default
229
+ * ({@link rejectOnError}) rejects via `message.setReject`; supplying your own
230
+ * replaces that, so the message is accepted unless you reject it yourself.
231
+ * - `dispatch` — this hook is OBSERVABILITY ONLY. It is called for the side
232
+ * effect (log, alert, forward) and the outcome is then decided by `retain`
233
+ * (accept) or a generic reject, regardless of what it does; the built-in
234
+ * default is deliberately NOT applied there. A `setReject` from inside it
235
+ * still takes effect, which would bounce a message `retain` went on to
236
+ * accept — almost certainly not what you want. A throw from the hook itself
237
+ * is logged and swallowed so it cannot mask the original dispatch error.
238
+ *
239
+ * SECURITY: a reject reason is delivered to the (attacker-controlled) sender
240
+ * as a bounce, so the default reason is a fixed, generic string and the real
241
+ * error is logged server-side. Never pass internal error text to `setReject`.
242
+ */
129
243
  onError?: (error: unknown, context: InboundDispatchContext<TEnv>) => Promise<void> | void;
130
244
  /** Parses raw bytes into an {@link InboundEmail} (e.g. `parseInboundEmail`). */
131
245
  parse: (raw: RawInboundEmail) => Promise<InboundEmail>;
132
246
  /**
133
- * Opt-in sender-authentication gate run before `dispatch`. SECURITY: inbound
134
- * `from` is spoofable and dispatch is privileged — supply this (gating on
135
- * `email.authentication`) when an inbound function makes any trust decision.
136
- */
247
+ * Opt-in: take durable ownership of a message whose `dispatch` failed, so a
248
+ * transient fault (a shard 502, a briefly-absent admin token) is retried
249
+ * instead of bounced. Omit it and a dispatch failure bounces, as it always
250
+ * has. See {@link InboundRetain}.
251
+ */
252
+ retain?: InboundRetain<TEnv>;
253
+ /**
254
+ * Opt-in sender-authentication gate run before `dispatch`. SECURITY: inbound
255
+ * `from` is spoofable and dispatch is privileged — supply this (gating on
256
+ * `email.authentication`) when an inbound function makes any trust decision.
257
+ */
137
258
  verify?: InboundVerify<TEnv>;
138
259
  }
139
260
  /** The `email(message, env, ctx)` callback the factory returns. */
140
261
  type InboundEmailHandler<TEnv = Record<string, unknown>> = (message: ForwardableEmailMessageLike, env: TEnv, context: unknown) => Promise<void>;
141
- /**
142
- * Build the `email(message, env, ctx)` handler. It (a) reads `message.raw`,
143
- * (b) parses it via `parse`, (c) runs the optional `verify` gate, then
144
- * (d) calls `dispatch(parsed, { message, env, ctx })`. Any throw (or a falsy
145
- * `verify`) routes through `onError` (default: a generic `message.setReject`).
146
- */
147
262
  declare const createInboundEmailHandler: <TEnv = Record<string, unknown>>(options: InboundEmailHandlerOptions<TEnv>) => InboundEmailHandler<TEnv>;
148
263
  /** The `RpcEnvelope` shape the runtime's `/_lunora/rpc` path consumes. */
149
264
  interface RpcEnvelope {
@@ -154,23 +269,25 @@ interface RpcEnvelope {
154
269
  /** Options for {@link dispatchToLunoraFunction}. */
155
270
  interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
156
271
  /**
157
- * Admin bearer authorizing the shard RPC. Defaults to reading
158
- * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
159
- */
272
+ * Admin bearer authorizing the shard RPC. Defaults to reading
273
+ * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
274
+ */
160
275
  adminToken?: string;
161
276
  /** `functionPath` of the target mutation/action (e.g. `"inbound:onEmail"`). */
162
277
  functionPath: string;
163
278
  /**
164
- * Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Pass the
165
- * same value as the worker's `jurisdiction` so inbound mail routes to the
166
- * jurisdiction-pinned shard. Omit for the un-pinned global namespace.
167
- */
279
+ * Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Defaults
280
+ * to the jurisdiction the schema declares (`.jurisdiction("eu")`), so a
281
+ * generated app needs nothing here; set it only for a hand-written worker, to
282
+ * the same value as its `jurisdiction`. A value that contradicts the schema's
283
+ * throws.
284
+ */
168
285
  jurisdiction?: DurableObjectJurisdiction;
169
286
  /**
170
- * Map the parsed message into the function's args. Defaults to passing the
171
- * whole {@link InboundEmail} with binary attachment `content` base64-encoded
172
- * (see {@link toJsonSafeEmail}) so it survives the JSON-serialised RPC body.
173
- */
287
+ * Map the parsed message into the function's args. Defaults to passing the
288
+ * whole {@link InboundEmail} with binary attachment `content` base64-encoded
289
+ * (see {@link toJsonSafeEmail}) so it survives the JSON-serialised RPC body.
290
+ */
174
291
  resolveArgs?: (email: InboundEmail, context: InboundDispatchContext<TEnv>) => unknown;
175
292
  /** The `SHARD` Durable Object namespace. */
176
293
  shard: ShardNamespaceLike;
@@ -178,16 +295,147 @@ interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
178
295
  shardKey?: string;
179
296
  }
180
297
  /**
181
- * Build a {@link InboundDispatch} that posts an {@link RpcEnvelope} to the root
182
- * shard stub — the same admin-RPC-over-shard path the dev capture sink uses
183
- * (`from-env.ts`) — routing the parsed message into a named Lunora
184
- * mutation/action. Throws on a non-2xx RPC or a missing admin token so the
185
- * handler's `onError` (default `setReject`) bounces the message.
186
- *
187
- * SECURITY: the RPC carries the admin bearer, so the target function runs with
188
- * RLS bypassed over fully attacker-controlled, spoofable input — see the module
189
- * docstring. Verify the sender (`verify` hook / `email.authentication`) before
190
- * making any trust decision in the target function.
191
- */
298
+ * Build a {@link InboundDispatch} that posts an {@link RpcEnvelope} to the root
299
+ * shard stub — the same admin-RPC-over-shard path the dev capture sink uses
300
+ * (`from-env.ts`) — routing the parsed message into a named Lunora
301
+ * mutation/action. Throws on a non-2xx RPC or a missing admin token — both
302
+ * transient in principle, so the handler reports it through a custom `onError`
303
+ * and then hands the message to `retain` if one is configured, bouncing only
304
+ * when there is nowhere durable to put it (see {@link createInboundEmailHandler}).
305
+ *
306
+ * SECURITY: the RPC is marked a trusted system dispatch, so `functionPath` may
307
+ * (and should) name an `internalMutation`/`internalAction` — a public `mutation`
308
+ * target is callable by any browser client with a forged message. The input is
309
+ * fully attacker-controlled and spoofable; verify the sender (`verify` hook /
310
+ * `email.authentication`) before making any trust decision in the target.
311
+ */
192
312
  declare const dispatchToLunoraFunction: <TEnv extends Record<string, unknown> = Record<string, unknown>>(options: DispatchToLunoraFunctionOptions<TEnv>) => InboundDispatch<TEnv>;
193
- export { type DispatchToLunoraFunctionOptions, type ForwardableEmailMessageLike, type InboundAttachment, type InboundAuthentication, type InboundDispatch, type InboundDispatchContext, type InboundEmail, type InboundEmailHandler, type InboundEmailHandlerOptions, type InboundVerify, type RawInboundEmail, type RpcEnvelope, type ShardNamespaceLike, createInboundEmailHandler, dispatchToLunoraFunction, parseInboundEmail };
313
+ export {
314
+ /**
315
+ * `@lunora/mail/inbound` — inbound Email Routing support.
316
+ *
317
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
318
+ * mutation/action:
319
+ *
320
+ * ```ts
321
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
322
+ *
323
+ * export const email = createInboundEmailHandler({
324
+ * parse: parseInboundEmail,
325
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
326
+ * });
327
+ * ```
328
+ */
329
+ type DispatchToLunoraFunctionOptions,
330
+ /**
331
+ * `@lunora/mail/inbound` — inbound Email Routing support.
332
+ *
333
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
334
+ * mutation/action:
335
+ *
336
+ * ```ts
337
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
338
+ *
339
+ * export const email = createInboundEmailHandler({
340
+ * parse: parseInboundEmail,
341
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
342
+ * });
343
+ * ```
344
+ */
345
+ type ForwardableEmailMessageLike, type InboundAttachment, type InboundAuthResult, type InboundAuthentication,
346
+ /**
347
+ * `@lunora/mail/inbound` — inbound Email Routing support.
348
+ *
349
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
350
+ * mutation/action:
351
+ *
352
+ * ```ts
353
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
354
+ *
355
+ * export const email = createInboundEmailHandler({
356
+ * parse: parseInboundEmail,
357
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
358
+ * });
359
+ * ```
360
+ */
361
+ type InboundDispatch,
362
+ /**
363
+ * `@lunora/mail/inbound` — inbound Email Routing support.
364
+ *
365
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
366
+ * mutation/action:
367
+ *
368
+ * ```ts
369
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
370
+ *
371
+ * export const email = createInboundEmailHandler({
372
+ * parse: parseInboundEmail,
373
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
374
+ * });
375
+ * ```
376
+ */
377
+ type InboundDispatchContext, type InboundEmail,
378
+ /**
379
+ * `@lunora/mail/inbound` — inbound Email Routing support.
380
+ *
381
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
382
+ * mutation/action:
383
+ *
384
+ * ```ts
385
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
386
+ *
387
+ * export const email = createInboundEmailHandler({
388
+ * parse: parseInboundEmail,
389
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
390
+ * });
391
+ * ```
392
+ */
393
+ type InboundEmailHandler,
394
+ /**
395
+ * `@lunora/mail/inbound` — inbound Email Routing support.
396
+ *
397
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
398
+ * mutation/action:
399
+ *
400
+ * ```ts
401
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
402
+ *
403
+ * export const email = createInboundEmailHandler({
404
+ * parse: parseInboundEmail,
405
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
406
+ * });
407
+ * ```
408
+ */
409
+ type InboundEmailHandlerOptions,
410
+ /**
411
+ * `@lunora/mail/inbound` — inbound Email Routing support.
412
+ *
413
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
414
+ * mutation/action:
415
+ *
416
+ * ```ts
417
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
418
+ *
419
+ * export const email = createInboundEmailHandler({
420
+ * parse: parseInboundEmail,
421
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
422
+ * });
423
+ * ```
424
+ */
425
+ type InboundVerify, type RawInboundEmail,
426
+ /**
427
+ * `@lunora/mail/inbound` — inbound Email Routing support.
428
+ *
429
+ * Wire a Cloudflare Email Worker entry to route received mail into a Lunora
430
+ * mutation/action:
431
+ *
432
+ * ```ts
433
+ * import { createInboundEmailHandler, parseInboundEmail, dispatchToLunoraFunction } from "@lunora/mail/inbound";
434
+ *
435
+ * export const email = createInboundEmailHandler({
436
+ * parse: parseInboundEmail,
437
+ * dispatch: dispatchToLunoraFunction({ shard: env.SHARD, functionPath: "inbound:onEmail" }),
438
+ * });
439
+ * ```
440
+ */
441
+ type RpcEnvelope, type ShardNamespaceLike, authenticatesFrom, createInboundEmailHandler, dispatchToLunoraFunction, parseInboundEmail };
@@ -1,2 +1 @@
1
- export { createInboundEmailHandler, dispatchToLunoraFunction } from '../packem_shared/createInboundEmailHandler-BW_s0-Vc.mjs';
2
- export { parseInboundEmail } from '../packem_shared/parseInboundEmail-6lafQBT1.mjs';
1
+ import{createInboundEmailHandler as n,dispatchToLunoraFunction as r}from"../packem_shared/createInboundEmailHandler-CixBJpmc.mjs";import{authenticatesFrom as t,parseInboundEmail as i}from"../packem_shared/authenticatesFrom-BDGSL3q4.mjs";export{t as authenticatesFrom,n as createInboundEmailHandler,r as dispatchToLunoraFunction,i as parseInboundEmail};