@lunora/mail 1.0.0-alpha.2 → 1.0.0-alpha.20

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/LICENSE.md +6 -0
  2. package/dist/inbound/index.d.mts +80 -69
  3. package/dist/inbound/index.d.ts +80 -69
  4. package/dist/inbound/index.mjs +1 -2
  5. package/dist/index.d.mts +95 -78
  6. package/dist/index.d.ts +95 -78
  7. package/dist/index.mjs +1 -7
  8. package/dist/packem_shared/address-Y4Z--6ZO.mjs +3 -0
  9. package/dist/packem_shared/capture-transport.d-BJ__iWzS.d.mts +117 -0
  10. package/dist/packem_shared/capture-transport.d-BJ__iWzS.d.ts +117 -0
  11. package/dist/packem_shared/consumeQueuedSend-BXrPhND5.mjs +1 -0
  12. package/dist/packem_shared/createCaptureSink-fVjCTUBC.mjs +1 -0
  13. package/dist/packem_shared/createCaptureTransport-BPdMkU0O.mjs +1 -0
  14. package/dist/packem_shared/createCloudflareTransport-V23CVw7F.mjs +1 -0
  15. package/dist/packem_shared/createInboundEmailHandler-B7H4h_sK.mjs +1 -0
  16. package/dist/packem_shared/createMailer-CsVLrc75.mjs +1 -0
  17. package/dist/packem_shared/createResendTransport-CpSJ4j7C.mjs +1 -0
  18. package/dist/packem_shared/parseInboundEmail-tJMs3YON.mjs +1 -0
  19. package/dist/packem_shared/provider-transport-BZngzyeS.mjs +1 -0
  20. package/dist/packem_shared/renderEmail-DM8_pWKa.mjs +1 -0
  21. package/dist/packem_shared/shard-CcKsuWAm.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 -57
  27. package/package.json +6 -5
  28. package/dist/packem_shared/address-fkXxLKza.mjs +0 -62
  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-BEKOdaxU.mjs +0 -75
  32. package/dist/packem_shared/createCaptureSink-DeihS4LH.mjs +0 -63
  33. package/dist/packem_shared/createCaptureTransport-Crz_8822.mjs +0 -11
  34. package/dist/packem_shared/createCloudflareTransport-yHOVEsZv.mjs +0 -26
  35. package/dist/packem_shared/createInboundEmailHandler-D0uCOrU-.mjs +0 -83
  36. package/dist/packem_shared/createMailer-oEKPAd4J.mjs +0 -77
  37. package/dist/packem_shared/createResendTransport-oNIorpzv.mjs +0 -16
  38. package/dist/packem_shared/parseInboundEmail-Bw9u_1oc.mjs +0 -72
  39. package/dist/packem_shared/provider-transport-C5CVbjRF.mjs +0 -47
  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
package/LICENSE.md CHANGED
@@ -103,3 +103,9 @@ Unless required by applicable law or agreed to in writing, software distributed
103
103
  under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
104
  CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
105
  specific language governing permissions and limitations under the License.
106
+
107
+ <!-- DEPENDENCIES -->
108
+ <!-- /DEPENDENCIES -->
109
+
110
+ <!-- TYPE_DEPENDENCIES -->
111
+ <!-- /TYPE_DEPENDENCIES -->
@@ -1,5 +1,5 @@
1
- import { D as DurableObjectJurisdiction, S as ShardNamespaceLike } from "../packem_shared/shard.d-CL2Lmliv.mjs";
2
- export type { a as ShardStubLike } from "../packem_shared/shard.d-CL2Lmliv.mjs";
1
+ import { D as DurableObjectJurisdiction, S as ShardNamespaceLike } from "../packem_shared/shard.d-DVADjmEJ.mjs";
2
+ export type { a as ShardStubLike } from "../packem_shared/shard.d-DVADjmEJ.mjs";
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. */
@@ -16,16 +16,24 @@ interface InboundAttachment {
16
16
  mimeType: string;
17
17
  }
18
18
  /**
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
- */
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
+ *
29
+ * SECURITY: verdicts are read from the **first/topmost** `Authentication-Results`
30
+ * header in document order. The receiving MX prepends its own genuine header per
31
+ * RFC 8601, so the topmost occurrence is the trustworthy one; any lower
32
+ * occurrences (which an untrusted sender can inject into the raw message) are
33
+ * ignored. As defense-in-depth a consumer may additionally verify the topmost
34
+ * header's `authserv-id` matches its receiving MX (e.g. Cloudflare) — that needs
35
+ * config this runtime-agnostic parser does not carry, so it is left to the host.
36
+ */
29
37
  interface InboundAuthentication {
30
38
  /** DKIM verdict (`"pass"`/`"fail"`/…), or `null` when not reported. */
31
39
  dkim: string | null;
@@ -39,10 +47,13 @@ interface InboundEmail {
39
47
  /** Decoded attachments (empty array when none). */
40
48
  attachments: InboundAttachment[];
41
49
  /**
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
- */
50
+ * Sender-authentication verdicts (DKIM/SPF/DMARC) parsed from the receiving
51
+ * MX's **first/topmost** `Authentication-Results` header. SECURITY: see
52
+ * {@link InboundAuthentication} — `from` is spoofable; gate trust on these
53
+ * verdicts, not on `from`. Reading the raw `headers["authentication-results"]`
54
+ * map instead exposes last-wins (a lower, potentially attacker-injected)
55
+ * value — trust `authentication`, not the raw map.
56
+ */
46
57
  authentication: InboundAuthentication;
47
58
  /** Sender mailbox (`from`), CR/LF-checked. Empty string when the message omitted it. SECURITY: spoofable — do not trust for authorization. */
48
59
  from: string;
@@ -64,17 +75,17 @@ interface InboundEmail {
64
75
  to: string[];
65
76
  }
66
77
  /**
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
- */
78
+ * Parse a raw RFC 822 message into a normalised {@link InboundEmail}. Accepts the
79
+ * shapes a Cloudflare Email Worker can hand off — `ReadableStream`, `ArrayBuffer`,
80
+ * `Uint8Array`, or a decoded string.
81
+ */
71
82
  declare const parseInboundEmail: (raw: RawInboundEmail) => Promise<InboundEmail>;
72
83
  /**
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
- */
84
+ * Structural projection of Cloudflare's `ForwardableEmailMessage` (verified
85
+ * against `@cloudflare/workers-types`' `ForwardableEmailMessage`). Only the
86
+ * members the handler touches are modelled, so the host can pass the real
87
+ * runtime object without `@lunora/mail` importing `cloudflare:email`.
88
+ */
78
89
  interface ForwardableEmailMessageLike {
79
90
  /** Forward this message to a verified destination address. */
80
91
  forward: (rcptTo: string, headers?: Headers) => Promise<unknown>;
@@ -107,43 +118,43 @@ interface InboundDispatchContext<TEnv = Record<string, unknown>> {
107
118
  /** Routes a parsed message into a Lunora function (or anywhere). */
108
119
  type InboundDispatch<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<void>;
109
120
  /**
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
- */
121
+ * Opt-in sender-verification gate. Runs after `parse` and before `dispatch` with
122
+ * the parsed message. Return `false` (or throw) to reject the message before it
123
+ * reaches the privileged dispatch — use it to enforce DKIM/SPF/DMARC via
124
+ * `email.authentication`, an allow-list, etc. Returning `true`/`undefined`
125
+ * proceeds.
126
+ */
116
127
  type InboundVerify<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<boolean | void> | boolean | void;
117
128
  /** Options for {@link createInboundEmailHandler}. */
118
129
  interface InboundEmailHandlerOptions<TEnv = Record<string, unknown>> {
119
130
  /** Routes the parsed message onward (e.g. {@link dispatchToLunoraFunction}). */
120
131
  dispatch: InboundDispatch<TEnv>;
121
132
  /**
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
- */
133
+ * Called when `parse`/`verify`/`dispatch` throws. The default rejects the
134
+ * message via `message.setReject` so Cloudflare bounces/retries rather than
135
+ * silently dropping it. SECURITY: the reject reason is delivered to the
136
+ * (attacker-controlled) sender as a bounce, so the default reason is a fixed,
137
+ * generic string and the real error is logged server-side. Override to log,
138
+ * forward, or swallow — but never pass internal error text to `setReject`.
139
+ */
129
140
  onError?: (error: unknown, context: InboundDispatchContext<TEnv>) => Promise<void> | void;
130
141
  /** Parses raw bytes into an {@link InboundEmail} (e.g. `parseInboundEmail`). */
131
142
  parse: (raw: RawInboundEmail) => Promise<InboundEmail>;
132
143
  /**
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
- */
144
+ * Opt-in sender-authentication gate run before `dispatch`. SECURITY: inbound
145
+ * `from` is spoofable and dispatch is privileged — supply this (gating on
146
+ * `email.authentication`) when an inbound function makes any trust decision.
147
+ */
137
148
  verify?: InboundVerify<TEnv>;
138
149
  }
139
150
  /** The `email(message, env, ctx)` callback the factory returns. */
140
151
  type InboundEmailHandler<TEnv = Record<string, unknown>> = (message: ForwardableEmailMessageLike, env: TEnv, context: unknown) => Promise<void>;
141
152
  /**
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
- */
153
+ * Build the `email(message, env, ctx)` handler. It (a) reads `message.raw`,
154
+ * (b) parses it via `parse`, (c) runs the optional `verify` gate, then
155
+ * (d) calls `dispatch(parsed, { message, env, ctx })`. Any throw (or a falsy
156
+ * `verify`) routes through `onError` (default: a generic `message.setReject`).
157
+ */
147
158
  declare const createInboundEmailHandler: <TEnv = Record<string, unknown>>(options: InboundEmailHandlerOptions<TEnv>) => InboundEmailHandler<TEnv>;
148
159
  /** The `RpcEnvelope` shape the runtime's `/_lunora/rpc` path consumes. */
149
160
  interface RpcEnvelope {
@@ -154,23 +165,23 @@ interface RpcEnvelope {
154
165
  /** Options for {@link dispatchToLunoraFunction}. */
155
166
  interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
156
167
  /**
157
- * Admin bearer authorizing the shard RPC. Defaults to reading
158
- * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
159
- */
168
+ * Admin bearer authorizing the shard RPC. Defaults to reading
169
+ * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
170
+ */
160
171
  adminToken?: string;
161
172
  /** `functionPath` of the target mutation/action (e.g. `"inbound:onEmail"`). */
162
173
  functionPath: string;
163
174
  /**
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
- */
175
+ * Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Pass the
176
+ * same value as the worker's `jurisdiction` so inbound mail routes to the
177
+ * jurisdiction-pinned shard. Omit for the un-pinned global namespace.
178
+ */
168
179
  jurisdiction?: DurableObjectJurisdiction;
169
180
  /**
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
- */
181
+ * Map the parsed message into the function's args. Defaults to passing the
182
+ * whole {@link InboundEmail} with binary attachment `content` base64-encoded
183
+ * (see {@link toJsonSafeEmail}) so it survives the JSON-serialised RPC body.
184
+ */
174
185
  resolveArgs?: (email: InboundEmail, context: InboundDispatchContext<TEnv>) => unknown;
175
186
  /** The `SHARD` Durable Object namespace. */
176
187
  shard: ShardNamespaceLike;
@@ -178,16 +189,16 @@ interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
178
189
  shardKey?: string;
179
190
  }
180
191
  /**
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
- */
192
+ * Build a {@link InboundDispatch} that posts an {@link RpcEnvelope} to the root
193
+ * shard stub — the same admin-RPC-over-shard path the dev capture sink uses
194
+ * (`from-env.ts`) — routing the parsed message into a named Lunora
195
+ * mutation/action. Throws on a non-2xx RPC or a missing admin token so the
196
+ * handler's `onError` (default `setReject`) bounces the message.
197
+ *
198
+ * SECURITY: the RPC carries the admin bearer, so the target function runs with
199
+ * RLS bypassed over fully attacker-controlled, spoofable input — see the module
200
+ * docstring. Verify the sender (`verify` hook / `email.authentication`) before
201
+ * making any trust decision in the target function.
202
+ */
192
203
  declare const dispatchToLunoraFunction: <TEnv extends Record<string, unknown> = Record<string, unknown>>(options: DispatchToLunoraFunctionOptions<TEnv>) => InboundDispatch<TEnv>;
193
204
  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 };
@@ -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. */
@@ -16,16 +16,24 @@ interface InboundAttachment {
16
16
  mimeType: string;
17
17
  }
18
18
  /**
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
- */
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
+ *
29
+ * SECURITY: verdicts are read from the **first/topmost** `Authentication-Results`
30
+ * header in document order. The receiving MX prepends its own genuine header per
31
+ * RFC 8601, so the topmost occurrence is the trustworthy one; any lower
32
+ * occurrences (which an untrusted sender can inject into the raw message) are
33
+ * ignored. As defense-in-depth a consumer may additionally verify the topmost
34
+ * header's `authserv-id` matches its receiving MX (e.g. Cloudflare) — that needs
35
+ * config this runtime-agnostic parser does not carry, so it is left to the host.
36
+ */
29
37
  interface InboundAuthentication {
30
38
  /** DKIM verdict (`"pass"`/`"fail"`/…), or `null` when not reported. */
31
39
  dkim: string | null;
@@ -39,10 +47,13 @@ interface InboundEmail {
39
47
  /** Decoded attachments (empty array when none). */
40
48
  attachments: InboundAttachment[];
41
49
  /**
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
- */
50
+ * Sender-authentication verdicts (DKIM/SPF/DMARC) parsed from the receiving
51
+ * MX's **first/topmost** `Authentication-Results` header. SECURITY: see
52
+ * {@link InboundAuthentication} — `from` is spoofable; gate trust on these
53
+ * verdicts, not on `from`. Reading the raw `headers["authentication-results"]`
54
+ * map instead exposes last-wins (a lower, potentially attacker-injected)
55
+ * value — trust `authentication`, not the raw map.
56
+ */
46
57
  authentication: InboundAuthentication;
47
58
  /** Sender mailbox (`from`), CR/LF-checked. Empty string when the message omitted it. SECURITY: spoofable — do not trust for authorization. */
48
59
  from: string;
@@ -64,17 +75,17 @@ interface InboundEmail {
64
75
  to: string[];
65
76
  }
66
77
  /**
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
- */
78
+ * Parse a raw RFC 822 message into a normalised {@link InboundEmail}. Accepts the
79
+ * shapes a Cloudflare Email Worker can hand off — `ReadableStream`, `ArrayBuffer`,
80
+ * `Uint8Array`, or a decoded string.
81
+ */
71
82
  declare const parseInboundEmail: (raw: RawInboundEmail) => Promise<InboundEmail>;
72
83
  /**
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
- */
84
+ * Structural projection of Cloudflare's `ForwardableEmailMessage` (verified
85
+ * against `@cloudflare/workers-types`' `ForwardableEmailMessage`). Only the
86
+ * members the handler touches are modelled, so the host can pass the real
87
+ * runtime object without `@lunora/mail` importing `cloudflare:email`.
88
+ */
78
89
  interface ForwardableEmailMessageLike {
79
90
  /** Forward this message to a verified destination address. */
80
91
  forward: (rcptTo: string, headers?: Headers) => Promise<unknown>;
@@ -107,43 +118,43 @@ interface InboundDispatchContext<TEnv = Record<string, unknown>> {
107
118
  /** Routes a parsed message into a Lunora function (or anywhere). */
108
119
  type InboundDispatch<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<void>;
109
120
  /**
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
- */
121
+ * Opt-in sender-verification gate. Runs after `parse` and before `dispatch` with
122
+ * the parsed message. Return `false` (or throw) to reject the message before it
123
+ * reaches the privileged dispatch — use it to enforce DKIM/SPF/DMARC via
124
+ * `email.authentication`, an allow-list, etc. Returning `true`/`undefined`
125
+ * proceeds.
126
+ */
116
127
  type InboundVerify<TEnv = Record<string, unknown>> = (email: InboundEmail, context: InboundDispatchContext<TEnv>) => Promise<boolean | void> | boolean | void;
117
128
  /** Options for {@link createInboundEmailHandler}. */
118
129
  interface InboundEmailHandlerOptions<TEnv = Record<string, unknown>> {
119
130
  /** Routes the parsed message onward (e.g. {@link dispatchToLunoraFunction}). */
120
131
  dispatch: InboundDispatch<TEnv>;
121
132
  /**
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
- */
133
+ * Called when `parse`/`verify`/`dispatch` throws. The default rejects the
134
+ * message via `message.setReject` so Cloudflare bounces/retries rather than
135
+ * silently dropping it. SECURITY: the reject reason is delivered to the
136
+ * (attacker-controlled) sender as a bounce, so the default reason is a fixed,
137
+ * generic string and the real error is logged server-side. Override to log,
138
+ * forward, or swallow — but never pass internal error text to `setReject`.
139
+ */
129
140
  onError?: (error: unknown, context: InboundDispatchContext<TEnv>) => Promise<void> | void;
130
141
  /** Parses raw bytes into an {@link InboundEmail} (e.g. `parseInboundEmail`). */
131
142
  parse: (raw: RawInboundEmail) => Promise<InboundEmail>;
132
143
  /**
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
- */
144
+ * Opt-in sender-authentication gate run before `dispatch`. SECURITY: inbound
145
+ * `from` is spoofable and dispatch is privileged — supply this (gating on
146
+ * `email.authentication`) when an inbound function makes any trust decision.
147
+ */
137
148
  verify?: InboundVerify<TEnv>;
138
149
  }
139
150
  /** The `email(message, env, ctx)` callback the factory returns. */
140
151
  type InboundEmailHandler<TEnv = Record<string, unknown>> = (message: ForwardableEmailMessageLike, env: TEnv, context: unknown) => Promise<void>;
141
152
  /**
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
- */
153
+ * Build the `email(message, env, ctx)` handler. It (a) reads `message.raw`,
154
+ * (b) parses it via `parse`, (c) runs the optional `verify` gate, then
155
+ * (d) calls `dispatch(parsed, { message, env, ctx })`. Any throw (or a falsy
156
+ * `verify`) routes through `onError` (default: a generic `message.setReject`).
157
+ */
147
158
  declare const createInboundEmailHandler: <TEnv = Record<string, unknown>>(options: InboundEmailHandlerOptions<TEnv>) => InboundEmailHandler<TEnv>;
148
159
  /** The `RpcEnvelope` shape the runtime's `/_lunora/rpc` path consumes. */
149
160
  interface RpcEnvelope {
@@ -154,23 +165,23 @@ interface RpcEnvelope {
154
165
  /** Options for {@link dispatchToLunoraFunction}. */
155
166
  interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
156
167
  /**
157
- * Admin bearer authorizing the shard RPC. Defaults to reading
158
- * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
159
- */
168
+ * Admin bearer authorizing the shard RPC. Defaults to reading
169
+ * `env.LUNORA_ADMIN_TOKEN` at dispatch time.
170
+ */
160
171
  adminToken?: string;
161
172
  /** `functionPath` of the target mutation/action (e.g. `"inbound:onEmail"`). */
162
173
  functionPath: string;
163
174
  /**
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
- */
175
+ * Pin inbound dispatch to a Cloudflare data-residency jurisdiction. Pass the
176
+ * same value as the worker's `jurisdiction` so inbound mail routes to the
177
+ * jurisdiction-pinned shard. Omit for the un-pinned global namespace.
178
+ */
168
179
  jurisdiction?: DurableObjectJurisdiction;
169
180
  /**
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
- */
181
+ * Map the parsed message into the function's args. Defaults to passing the
182
+ * whole {@link InboundEmail} with binary attachment `content` base64-encoded
183
+ * (see {@link toJsonSafeEmail}) so it survives the JSON-serialised RPC body.
184
+ */
174
185
  resolveArgs?: (email: InboundEmail, context: InboundDispatchContext<TEnv>) => unknown;
175
186
  /** The `SHARD` Durable Object namespace. */
176
187
  shard: ShardNamespaceLike;
@@ -178,16 +189,16 @@ interface DispatchToLunoraFunctionOptions<TEnv = Record<string, unknown>> {
178
189
  shardKey?: string;
179
190
  }
180
191
  /**
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
- */
192
+ * Build a {@link InboundDispatch} that posts an {@link RpcEnvelope} to the root
193
+ * shard stub — the same admin-RPC-over-shard path the dev capture sink uses
194
+ * (`from-env.ts`) — routing the parsed message into a named Lunora
195
+ * mutation/action. Throws on a non-2xx RPC or a missing admin token so the
196
+ * handler's `onError` (default `setReject`) bounces the message.
197
+ *
198
+ * SECURITY: the RPC carries the admin bearer, so the target function runs with
199
+ * RLS bypassed over fully attacker-controlled, spoofable input — see the module
200
+ * docstring. Verify the sender (`verify` hook / `email.authentication`) before
201
+ * making any trust decision in the target function.
202
+ */
192
203
  declare const dispatchToLunoraFunction: <TEnv extends Record<string, unknown> = Record<string, unknown>>(options: DispatchToLunoraFunctionOptions<TEnv>) => InboundDispatch<TEnv>;
193
204
  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 };
@@ -1,2 +1 @@
1
- export { createInboundEmailHandler, dispatchToLunoraFunction } from '../packem_shared/createInboundEmailHandler-D0uCOrU-.mjs';
2
- export { parseInboundEmail } from '../packem_shared/parseInboundEmail-Bw9u_1oc.mjs';
1
+ import{createInboundEmailHandler as r,dispatchToLunoraFunction as a}from"../packem_shared/createInboundEmailHandler-B7H4h_sK.mjs";import{parseInboundEmail as t}from"../packem_shared/parseInboundEmail-tJMs3YON.mjs";export{r as createInboundEmailHandler,a as dispatchToLunoraFunction,t as parseInboundEmail};