@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.
- package/dist/inbound/index.d.mts +326 -78
- package/dist/inbound/index.d.ts +326 -78
- package/dist/inbound/index.mjs +1 -2
- package/dist/index.d.mts +186 -96
- package/dist/index.d.ts +186 -96
- package/dist/index.mjs +1 -7
- package/dist/packem_shared/MailSendError-HH5Yimut.mjs +1 -0
- package/dist/packem_shared/address-oKy_d0aG.mjs +3 -0
- package/dist/packem_shared/authenticatesFrom-BDGSL3q4.mjs +1 -0
- package/dist/packem_shared/capture-transport.d-BD67fxbB.d.mts +130 -0
- package/dist/packem_shared/capture-transport.d-BD67fxbB.d.ts +130 -0
- package/dist/packem_shared/consumeQueuedSend-CRfALnCU.mjs +1 -0
- package/dist/packem_shared/createCaptureSink-BSAR1HTL.mjs +1 -0
- package/dist/packem_shared/createCaptureTransport-DZhMUmaI.mjs +1 -0
- package/dist/packem_shared/createCloudflareTransport-fOhfy2fP.mjs +1 -0
- package/dist/packem_shared/createInboundEmailHandler-CixBJpmc.mjs +1 -0
- package/dist/packem_shared/createMailer-C5NIzkNb.mjs +1 -0
- package/dist/packem_shared/createResendTransport-q3surKen.mjs +1 -0
- package/dist/packem_shared/provider-transport-DklK6xUa.mjs +1 -0
- package/dist/packem_shared/renderEmail-xypKDdux.mjs +1 -0
- package/dist/packem_shared/shard-C5t-b7FX.mjs +1 -0
- package/dist/packem_shared/shard.d-DVADjmEJ.d.mts +29 -0
- package/dist/packem_shared/shard.d-DVADjmEJ.d.ts +29 -0
- package/dist/testing.d.mts +9 -9
- package/dist/testing.d.ts +9 -9
- package/dist/testing.mjs +1 -63
- package/package.json +5 -5
- package/dist/packem_shared/address-vSUAVU2T.mjs +0 -64
- package/dist/packem_shared/capture-transport.d-ChnhdPO2.d.mts +0 -117
- package/dist/packem_shared/capture-transport.d-ChnhdPO2.d.ts +0 -117
- package/dist/packem_shared/consumeQueuedSend-B9hTDOZ6.mjs +0 -77
- package/dist/packem_shared/createCaptureSink-Di-5AJUs.mjs +0 -65
- package/dist/packem_shared/createCaptureTransport-Crz_8822.mjs +0 -11
- package/dist/packem_shared/createCloudflareTransport-DXh1nUNi.mjs +0 -28
- package/dist/packem_shared/createInboundEmailHandler-BW_s0-Vc.mjs +0 -84
- package/dist/packem_shared/createMailer-B4Z_Cgiu.mjs +0 -81
- package/dist/packem_shared/createResendTransport-CMQWjZoi.mjs +0 -16
- package/dist/packem_shared/parseInboundEmail-6lafQBT1.mjs +0 -72
- package/dist/packem_shared/provider-transport-C0xHi3oy.mjs +0 -48
- package/dist/packem_shared/renderEmail-hyS1bpVP.mjs +0 -8
- package/dist/packem_shared/shard-CJ-TvmfT.mjs +0 -13
- package/dist/packem_shared/shard.d-CL2Lmliv.d.mts +0 -39
- package/dist/packem_shared/shard.d-CL2Lmliv.d.ts +0 -39
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { M as MailTransport, L as LunoraMailOptions, a as Mailer, b as MailboxSink, S as SendOptions } from "./packem_shared/capture-transport.d-
|
|
2
|
-
export { type C as CapturedMail, type
|
|
3
|
-
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-
|
|
1
|
+
import { M as MailTransport, L as LunoraMailOptions, a as Mailer, Q as QueueLike, b as MailboxSink, S as SendOptions } from "./packem_shared/capture-transport.d-BD67fxbB.js";
|
|
2
|
+
export { type C as CapturedMail, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-BD67fxbB.js";
|
|
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
|
-
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
7
|
-
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
8
|
-
* `@lunora/mail` free of a `cloudflare:email` import and unit-testable. Wire it
|
|
9
|
-
* in your project as:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* send: async (from, to, raw) => {
|
|
13
|
-
* const { EmailMessage } = await import("cloudflare:email");
|
|
14
|
-
* await env.SEND_EMAIL.send(new EmailMessage(from, to, raw));
|
|
15
|
-
* }
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
7
|
+
* Sends a raw RFC 822 message through a Worker's Email send binding. The Workers
|
|
8
|
+
* runtime owns the binding, so the caller supplies this thin callback — keeping
|
|
9
|
+
* `@lunora/mail` free of a `cloudflare:email` import and unit-testable. Wire it
|
|
10
|
+
* in your project as:
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* send: async (from, to, raw) => {
|
|
14
|
+
* const { EmailMessage } = await import("cloudflare:email");
|
|
15
|
+
* await env.SEND_EMAIL.send(new EmailMessage(from, to, raw));
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
18
19
|
type CloudflareSend = (from: string, to: string, raw: string) => Promise<void>;
|
|
19
20
|
interface CloudflareTransportOptions {
|
|
20
21
|
/** Default sender used when a `SendOptions.from` isn't supplied. */
|
|
@@ -23,75 +24,89 @@ interface CloudflareTransportOptions {
|
|
|
23
24
|
send: CloudflareSend;
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* Build the default Cloudflare Email Workers transport via `@visulima/email`.
|
|
27
|
-
* Cloudflare's `send_email` binding is **single-recipient** and only delivers to
|
|
28
|
-
* **verified Email Routing destination addresses**, and the underlying provider
|
|
29
|
-
* rejects any `cc`/`bcc` or a non-single `to` outright. So this enforces a single
|
|
30
|
-
* `to` recipient (throwing a clear error instead of silently dropping the rest)
|
|
31
|
-
* and rejects `cc`/`bcc` rather than forwarding them into a generic "send failed".
|
|
32
|
-
* Multi-recipient transactional mail must fan out one send per recipient at the
|
|
33
|
-
* call site. In dev the capture transport intercepts before this runs, so the
|
|
34
|
-
* verified-address constraint never bites the dev loop.
|
|
35
|
-
*/
|
|
27
|
+
* Build the default Cloudflare Email Workers transport via `@visulima/email`.
|
|
28
|
+
* Cloudflare's `send_email` binding is **single-recipient** and only delivers to
|
|
29
|
+
* **verified Email Routing destination addresses**, and the underlying provider
|
|
30
|
+
* rejects any `cc`/`bcc` or a non-single `to` outright. So this enforces a single
|
|
31
|
+
* `to` recipient (throwing a clear error instead of silently dropping the rest)
|
|
32
|
+
* and rejects `cc`/`bcc` rather than forwarding them into a generic "send failed".
|
|
33
|
+
* Multi-recipient transactional mail must fan out one send per recipient at the
|
|
34
|
+
* call site. In dev the capture transport intercepts before this runs, so the
|
|
35
|
+
* verified-address constraint never bites the dev loop.
|
|
36
|
+
*/
|
|
36
37
|
declare const createCloudflareTransport: (options: CloudflareTransportOptions) => MailTransport;
|
|
37
38
|
/**
|
|
38
|
-
* Create a mailer bound to a transport.
|
|
39
|
-
*
|
|
40
|
-
* SECURITY — recipient policy and HTML content are the caller's responsibility.
|
|
41
|
-
* The mailer fully blocks header/CRLF/comma injection in addresses
|
|
42
|
-
* (`assertSafeAddresses` / `assertSafeHeaderValue`), but it does NOT decide WHO
|
|
43
|
-
* you may send to or WHAT HTML you render.
|
|
44
|
-
*
|
|
45
|
-
* Open relay: derive `to`/`cc`/`bcc` from server-trusted state, never from raw
|
|
46
|
-
* request input, and prefer a fixed/allowlisted `from` — sending to an arbitrary
|
|
47
|
-
* user-supplied address turns your deployment into a spam relay.
|
|
48
|
-
*
|
|
49
|
-
* Template XSS / content injection: treat template HTML like any other HTML sink
|
|
50
|
-
* — never interpolate untrusted data into raw markup (or a
|
|
51
|
-
* `dangerouslySetInnerHTML`-style template) without escaping. The mailer sends
|
|
52
|
-
* whatever HTML you hand it verbatim.
|
|
53
|
-
*/
|
|
39
|
+
* Create a mailer bound to a transport.
|
|
40
|
+
*
|
|
41
|
+
* SECURITY — recipient policy and HTML content are the caller's responsibility.
|
|
42
|
+
* The mailer fully blocks header/CRLF/comma injection in addresses
|
|
43
|
+
* (`assertSafeAddresses` / `assertSafeHeaderValue`), but it does NOT decide WHO
|
|
44
|
+
* you may send to or WHAT HTML you render.
|
|
45
|
+
*
|
|
46
|
+
* Open relay: derive `to`/`cc`/`bcc` from server-trusted state, never from raw
|
|
47
|
+
* request input, and prefer a fixed/allowlisted `from` — sending to an arbitrary
|
|
48
|
+
* user-supplied address turns your deployment into a spam relay.
|
|
49
|
+
*
|
|
50
|
+
* Template XSS / content injection: treat template HTML like any other HTML sink
|
|
51
|
+
* — never interpolate untrusted data into raw markup (or a
|
|
52
|
+
* `dangerouslySetInnerHTML`-style template) without escaping. The mailer sends
|
|
53
|
+
* whatever HTML you hand it verbatim.
|
|
54
|
+
*/
|
|
54
55
|
declare const createMailer: (options: LunoraMailOptions) => Mailer;
|
|
55
56
|
/** A Worker `env` projected as a plain record (vars, secrets, and bindings are `unknown`-valued). */
|
|
56
57
|
type MailEnv = Record<string, unknown>;
|
|
57
58
|
/** Options for {@link createMailerFromEnv}. */
|
|
58
59
|
interface FromEnvOptions {
|
|
59
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* RFC 822 send callback bound to the Worker's Cloudflare Email binding (the
|
|
62
|
+
* default transport). Honoured whenever it is passed, whatever the binding is
|
|
63
|
+
* named: passing it is the caller's choice of transport, so pass it only when
|
|
64
|
+
* the binding exists.
|
|
65
|
+
*/
|
|
60
66
|
cloudflareSend?: CloudflareSend;
|
|
61
67
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
* Pin the captured-mail inbox shard to a Cloudflare data-residency
|
|
69
|
+
* jurisdiction. Defaults to the jurisdiction the schema declares
|
|
70
|
+
* (`.jurisdiction("eu")`), so a generated app needs nothing here; set it only
|
|
71
|
+
* for a hand-written worker, to the same value as its `jurisdiction`. A value
|
|
72
|
+
* that contradicts the schema's throws.
|
|
73
|
+
*/
|
|
66
74
|
jurisdiction?: DurableObjectJurisdiction;
|
|
75
|
+
/** Cloudflare Queue binding backing `mailer.queue()`; without it `queue()` throws outside capture mode. */
|
|
76
|
+
queue?: QueueLike;
|
|
67
77
|
/** Shard the captured-mail inbox lives on; override if your worker sets a custom `defaultShardKey`. */
|
|
68
78
|
rootShard?: string;
|
|
69
79
|
}
|
|
70
80
|
/**
|
|
71
|
-
* Whether outbound mail should be captured (into the studio inbox) rather than
|
|
72
|
-
* delivered. Explicit `LUNORA_MAIL_CAPTURE` (`"1"`/`"true"` vs `"0"`/`"false"`)
|
|
73
|
-
* always wins; unset, capture is on only
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
81
|
+
* Whether outbound mail should be captured (into the studio inbox) rather than
|
|
82
|
+
* delivered. Explicit `LUNORA_MAIL_CAPTURE` (`"1"`/`"true"` vs `"0"`/`"false"`)
|
|
83
|
+
* always wins; unset, capture is on only when every set environment var (`CF_ENV`,
|
|
84
|
+
* `ENVIRONMENT`, `NODE_ENV`, `WORKER_ENV`) names a development one. It does
|
|
85
|
+
* NOT fall back to "no SEND_EMAIL binding ⇒ capture" — a production deploy that
|
|
86
|
+
* forgot the binding must fail loudly on send, not silently swallow mail.
|
|
87
|
+
*/
|
|
77
88
|
declare const shouldCaptureMail: (env: MailEnv) => boolean;
|
|
78
89
|
/**
|
|
79
|
-
* Build the {@link MailboxSink} that records a captured message into the studio's
|
|
80
|
-
* root-shard inbox via the reserved `recordMail` admin RPC — the same
|
|
81
|
-
* worker→root-shard path the runtime uses for auth events. Best-effort: without
|
|
82
|
-
* the `SHARD` binding or `LUNORA_ADMIN_TOKEN` it returns a sentinel id so a send
|
|
83
|
-
* never fails for lack of somewhere to record.
|
|
84
|
-
*/
|
|
90
|
+
* Build the {@link MailboxSink} that records a captured message into the studio's
|
|
91
|
+
* root-shard inbox via the reserved `recordMail` admin RPC — the same
|
|
92
|
+
* worker→root-shard path the runtime uses for auth events. Best-effort: without
|
|
93
|
+
* the `SHARD` binding or `LUNORA_ADMIN_TOKEN` it returns a sentinel id so a send
|
|
94
|
+
* never fails for lack of somewhere to record — but it says so first (see below).
|
|
95
|
+
*/
|
|
85
96
|
declare const createCaptureSink: (env: MailEnv, rootShard?: string, jurisdiction?: DurableObjectJurisdiction) => MailboxSink;
|
|
86
97
|
/**
|
|
87
|
-
* Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
|
|
88
|
-
* captured into the studio's Mail inbox; otherwise it delivers via the supplied
|
|
89
|
-
* `cloudflareSend` (
|
|
90
|
-
*
|
|
91
|
-
* misconfigured production deploy fails loudly instead of silently dropping mail
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
|
|
98
|
+
* Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
|
|
99
|
+
* captured into the studio's Mail inbox; otherwise it delivers via the supplied
|
|
100
|
+
* `cloudflareSend` (when passed) or,
|
|
101
|
+
* failing that, `RESEND_API_KEY`. With no real transport `send()` rejects, so a
|
|
102
|
+
* misconfigured production deploy fails loudly instead of silently dropping mail
|
|
103
|
+
* — while `queue()` still works for a producer-only worker.
|
|
104
|
+
*
|
|
105
|
+
* A queue consumer should build its mailer here too: `consumeQueuedSend` goes
|
|
106
|
+
* through `send()`, so in dev queued mail is captured at consume time.
|
|
107
|
+
*
|
|
108
|
+
* `MAIL_FROM` is required (the default sender).
|
|
109
|
+
*/
|
|
95
110
|
declare const createMailerFromEnv: (env: MailEnv, options?: FromEnvOptions) => Mailer;
|
|
96
111
|
/** Serializable representation of a `SendOptions` payload — drops the `react` field. */
|
|
97
112
|
interface QueuedSend {
|
|
@@ -100,51 +115,126 @@ interface QueuedSend {
|
|
|
100
115
|
from?: string;
|
|
101
116
|
headers?: Record<string, string>;
|
|
102
117
|
html?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Stable dedup key, minted at enqueue time by `createMailer(...).queue()` — see
|
|
120
|
+
* `SendOptions.idempotencyKey`. Carried through untouched by `consumeQueuedSend`;
|
|
121
|
+
* a consumer wanting exactly-once delivery dedupes against its own store using it.
|
|
122
|
+
*/
|
|
123
|
+
idempotencyKey?: string;
|
|
103
124
|
replyTo?: string;
|
|
104
125
|
subject: string;
|
|
105
126
|
text?: string;
|
|
106
127
|
to: string | string[];
|
|
107
128
|
}
|
|
108
129
|
/**
|
|
109
|
-
* Narrow a `SendOptions` to its serializable `QueuedSend` shape by dropping the
|
|
110
|
-
* non-cloneable `react` field. React elements are not structured-cloneable, so
|
|
111
|
-
* the queue body must carry only the pre-rendered html/text and scalar fields.
|
|
112
|
-
*/
|
|
130
|
+
* Narrow a `SendOptions` to its serializable `QueuedSend` shape by dropping the
|
|
131
|
+
* non-cloneable `react` field. React elements are not structured-cloneable, so
|
|
132
|
+
* the queue body must carry only the pre-rendered html/text and scalar fields.
|
|
133
|
+
*/
|
|
113
134
|
declare const toQueuedPayload: (options: SendOptions) => QueuedSend;
|
|
114
135
|
/**
|
|
115
|
-
* Helper used by Queue consumers: rehydrate a `QueuedSend` payload and forward
|
|
116
|
-
* to a configured `Mailer.send()`. Use this inside your Worker's `queue()`
|
|
117
|
-
* handler.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
|
|
136
|
+
* Helper used by Queue consumers: rehydrate a `QueuedSend` payload and forward
|
|
137
|
+
* to a configured `Mailer.send()`. Use this inside your Worker's `queue()`
|
|
138
|
+
* handler.
|
|
139
|
+
*
|
|
140
|
+
* DEDUPE IS THE CONSUMER'S JOB, and this helper does not do it. The payload's
|
|
141
|
+
* `idempotencyKey` was minted once at enqueue time so it survives redelivery, but
|
|
142
|
+
* nothing downstream reads it: no transport forwards it to the provider (Resend
|
|
143
|
+
* dedupes on an `Idempotency-Key` REQUEST header, which the provider client offers
|
|
144
|
+
* no hook for — its `headers` field becomes message headers in the body). A
|
|
145
|
+
* consumer that only acks is correct for the failure the ack covers and sends a
|
|
146
|
+
* duplicate for the one it does not: the provider accepted the message and the
|
|
147
|
+
* worker died before acking.
|
|
148
|
+
*
|
|
149
|
+
* The recipe below NARROWS that window; it does not close it, and nothing on
|
|
150
|
+
* this path can. The mark is written after the provider accepted the message, so
|
|
151
|
+
* a crash in between still redelivers and resends, and a KV read is eventually
|
|
152
|
+
* consistent — a redelivery seconds later can miss a mark that was written.
|
|
153
|
+
* Delivery is at-least-once end to end. An app that must not double-send needs a
|
|
154
|
+
* strongly-consistent mark taken BEFORE the send (a Durable Object or D1 row
|
|
155
|
+
* claimed by this key, released on failure), and even then the send-then-crash
|
|
156
|
+
* window is only ever traded for a send-that-may-not-have-happened one.
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* export default {
|
|
160
|
+
* queue: async (batch, env) => {
|
|
161
|
+
* // createMailerFromEnv, so dev captures the message here instead of sending it.
|
|
162
|
+
* const mailer = createMailerFromEnv(env);
|
|
163
|
+
* for (const message of batch.messages) {
|
|
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; }
|
|
168
|
+
* if (await env.SENT.get(idempotencyKey)) { message.ack(); continue; }
|
|
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
|
+
* }
|
|
182
|
+
* await env.SENT.put(idempotencyKey, "1", { expirationTtl: 86_400 });
|
|
183
|
+
* message.ack();
|
|
184
|
+
* }
|
|
185
|
+
* },
|
|
186
|
+
* };
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
130
189
|
declare const consumeQueuedSend: (mailer: Mailer, payload: unknown) => Promise<{
|
|
131
190
|
id: string;
|
|
132
191
|
}>;
|
|
133
192
|
/**
|
|
134
|
-
* Render a React element to an HTML/text pair suitable for inlining into a
|
|
135
|
-
* provider payload. Wraps `@react-email/render` so we can swap to
|
|
136
|
-
* `@visulima/email`'s react-email template engine without touching callers.
|
|
137
|
-
|
|
193
|
+
* Render a React element to an HTML/text pair suitable for inlining into a
|
|
194
|
+
* provider payload. Wraps `@react-email/render` so we can swap to
|
|
195
|
+
* `@visulima/email`'s react-email template engine without touching callers.
|
|
196
|
+
*
|
|
197
|
+
* The renderer is imported lazily so its top-level evaluation (prettier and
|
|
198
|
+
* html-to-text, in its workerd build) is deferred until the first React render
|
|
199
|
+
* instead of running on cold start. Bundlers may still include the code.
|
|
200
|
+
*/
|
|
138
201
|
declare const renderEmail: (element: ReactElement) => Promise<{
|
|
139
202
|
html: string;
|
|
140
203
|
text: string;
|
|
141
204
|
}>;
|
|
142
205
|
/**
|
|
143
|
-
* Build a Resend-backed transport via `@visulima/email`. Wraps the provider's
|
|
144
|
-
* `sendEmail()` into the minimal `{ send(payload) -> { id } }` shape the rest of
|
|
145
|
-
* `@lunora/mail` consumes. Kept reachable as a named export so a project that
|
|
146
|
-
* prefers Resend over the Cloudflare default can pass
|
|
147
|
-
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
148
|
-
*/
|
|
206
|
+
* Build a Resend-backed transport via `@visulima/email`. Wraps the provider's
|
|
207
|
+
* `sendEmail()` into the minimal `{ send(payload) -> { id } }` shape the rest of
|
|
208
|
+
* `@lunora/mail` consumes. Kept reachable as a named export so a project that
|
|
209
|
+
* prefers Resend over the Cloudflare default can pass
|
|
210
|
+
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
211
|
+
*/
|
|
149
212
|
declare const createResendTransport: (apiKey: string, defaultFrom: string) => MailTransport;
|
|
150
|
-
|
|
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,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createCloudflareTransport } from './packem_shared/createCloudflareTransport-DXh1nUNi.mjs';
|
|
3
|
-
export { default as createMailer } from './packem_shared/createMailer-B4Z_Cgiu.mjs';
|
|
4
|
-
export { createCaptureSink, createMailerFromEnv, shouldCaptureMail } from './packem_shared/createCaptureSink-Di-5AJUs.mjs';
|
|
5
|
-
export { consumeQueuedSend, toQueuedPayload } from './packem_shared/consumeQueuedSend-B9hTDOZ6.mjs';
|
|
6
|
-
export { default as renderEmail } from './packem_shared/renderEmail-hyS1bpVP.mjs';
|
|
7
|
-
export { default as createResendTransport } from './packem_shared/createResendTransport-CMQWjZoi.mjs';
|
|
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,3 @@
|
|
|
1
|
+
import{LunoraError as t}from"@lunora/errors";const n=320,a=256,d=/^([^<]*)<([^>]*)>\s*$/,i=(r,s)=>{if(s.includes("\r")||s.includes(`
|
|
2
|
+
`)||s.includes(","))throw new t("INTERNAL",`@lunora/mail: address ${r} must not contain CR, LF, or comma`)},u=(r,s)=>{if(s.includes("\r")||s.includes(`
|
|
3
|
+
`))throw new t("INTERNAL",`@lunora/mail: ${r} must not contain CR or LF`)},m=(r,s)=>{if(r.length>a)throw new t("INTERNAL",`@lunora/mail: address name must be <= ${String(a)} characters`);if(s.length>n)throw new t("INTERNAL",`@lunora/mail: address email must be <= ${String(n)} characters`);return r&&i("name",r),i("email",s),r?{email:s,name:r}:{email:s}},l=r=>{const s=r.trim();if(s.length>n)throw new t("INTERNAL",`@lunora/mail: address email must be <= ${String(n)} characters`);return i("email",s),{email:s}},c=r=>{const s=d.exec(r),e=(s?.[2]??"").trim();return s&&e?m((s[1]??"").trim(),e):l(r)},o=r=>{if(r===void 0)return;const s=Array.isArray(r)?r:[r];if(s.length!==0)return s.map(e=>c(e))},f=r=>{if(o(r.to)===void 0)throw new t("INTERNAL","@lunora/mail: at least one recipient is required");o(r.cc),o(r.bcc),r.from!==void 0&&c(r.from),r.replyTo!==void 0&&c(r.replyTo)};export{u as a,c as b,f as c,o as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import l from"postal-mime";import{a as c}from"./address-oKy_d0aG.mjs";const d=(s,e)=>{if(e!==void 0)return c(`inbound ${s}`,e),e},p=s=>s===null?s:s==="inline"?"inline":"attachment",f=s=>s.address!==void 0&&s.address!==""?s.name?`${s.name} <${s.address}>`:s.address:s.group?s.group.map(e=>e.address??"").filter(e=>e!=="").join(", "):s.name??"",g=/"(?:[^"\\]|\\.)*(?:"|$)|\((?:[^()\\]|\\.)*(?:\)|$)/g,v=s=>s.replaceAll(g,e=>e.startsWith('"')?e.replaceAll(/[;=]/gu," "):" "),m=(s,e,n)=>{const i=v(s).matchAll(new RegExp(String.raw`(?:^|;)\s*${e}\s*(?:/\s*\d+\s*)?=\s*([a-z]+)([^;]*)`,"gi")),a=new RegExp(String.raw`\b${n.split(".").join(String.raw`\s*\.\s*`)}\s*=\s*"?([^\s;"]+)`,"i");return[...i].map(o=>{const t=a.exec(o[2]??"")?.[1];return{domain:t===void 0?null:t.slice(t.lastIndexOf("@")+1).toLowerCase(),result:(o[1]??"").toLowerCase()}})},h=s=>s===void 0||s===""?{dkim:[],dmarc:[],spf:[]}:{dkim:m(s,"dkim","header.d"),dmarc:m(s,"dmarc","header.from"),spf:m(s,"spf","smtp.mailfrom")},$=async s=>{const e=await l.parse(s),n={};for(const r of e.headers)c(`inbound header \`${r.key}\``,r.value),n[r.key]=r.value;const i=e.headers.find(r=>r.key==="authentication-results")?.value,a=(e.to??[]).map(r=>{const u=f(r);return c("inbound to",u),u}),o=e.from?f(e.from):"";return c("inbound from",o),{attachments:e.attachments.map(r=>({content:r.content,disposition:p(r.disposition),...r.encoding===void 0?{}:{encoding:r.encoding},filename:r.filename,mimeType:r.mimeType})),authentication:h(i),from:o,headers:n,...e.html===void 0?{}:{html:e.html},...d("inReplyTo",e.inReplyTo)===void 0?{}:{inReplyTo:e.inReplyTo},...d("messageId",e.messageId)===void 0?{}:{messageId:e.messageId},...d("references",e.references)===void 0?{}:{references:e.references},...d("subject",e.subject)===void 0?{}:{subject:e.subject},...e.text===void 0?{}:{text:e.text},to:a}},x=/<([^<>]*)>$/,b=s=>{const e=x.exec(s)?.[1]??s,n=e.indexOf("@");if(!(n===-1||n!==e.lastIndexOf("@")))return e.slice(n+1).trim().toLowerCase()},T=s=>{const e=b(s.from);if(e===void 0)return!1;const n=t=>t.some(r=>r.result==="pass"&&r.domain===e),{dkim:i,dmarc:a,spf:o}=s.authentication;return n(a)||n(o)||n(i)};export{T as authenticatesFrom,$ as parseInboundEmail};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal projection of a Cloudflare Queue binding — accepts a JSON payload
|
|
4
|
+
* via `.send()`. Declared structurally so callers can pass either the real
|
|
5
|
+
* `Queue` binding or a unit-test double.
|
|
6
|
+
*/
|
|
7
|
+
interface QueueLike {
|
|
8
|
+
send: (payload: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minimal projection of a transport adapter. Returning `{ id }` follows
|
|
12
|
+
* Resend's response shape; the real `@visulima/email` `MailManager` flattens
|
|
13
|
+
* provider responses to the same field for us.
|
|
14
|
+
*/
|
|
15
|
+
interface MailTransport {
|
|
16
|
+
send: (payload: SendPayload) => Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
interface SendPayload {
|
|
21
|
+
bcc?: string[];
|
|
22
|
+
cc?: string[];
|
|
23
|
+
from?: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
html?: string;
|
|
26
|
+
replyTo?: string;
|
|
27
|
+
subject: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
to: string | string[];
|
|
30
|
+
}
|
|
31
|
+
interface SendOptions {
|
|
32
|
+
bcc?: string[];
|
|
33
|
+
cc?: string[];
|
|
34
|
+
from?: string;
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
html?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Stable key for deduping a queued send across Cloudflare Queues' at-least-once
|
|
39
|
+
* redelivery. Only meaningful for `mailer.queue()` — `mailer.send()` ignores it.
|
|
40
|
+
* When omitted, `queue()` generates one at enqueue time so it survives redelivery
|
|
41
|
+
* (a key minted in the consumer would change on every retry, defeating the point).
|
|
42
|
+
* Not forwarded to the mail provider, and no transport can: Resend dedupes on an
|
|
43
|
+
* `Idempotency-Key` REQUEST header, and the provider client exposes no hook for
|
|
44
|
+
* one (its own `headers` field becomes message headers in the JSON body). So a
|
|
45
|
+
* consumer that wants to collapse redeliveries MUST dedupe against its own store
|
|
46
|
+
* using this key — see `consumeQueuedSend` for the shape, and for why that is a
|
|
47
|
+
* narrowed at-least-once rather than exactly-once.
|
|
48
|
+
*/
|
|
49
|
+
idempotencyKey?: string;
|
|
50
|
+
react?: ReactElement;
|
|
51
|
+
replyTo?: string;
|
|
52
|
+
subject: string;
|
|
53
|
+
text?: string;
|
|
54
|
+
to: string | string[];
|
|
55
|
+
}
|
|
56
|
+
interface LunoraMailOptions {
|
|
57
|
+
/** API key for the Resend transport (bring-your-own-provider). Ignored when `transport` or `cloudflareSend` is set. */
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/**
|
|
60
|
+
* RFC 822 send callback bound to the Worker's `send_email` binding. When set
|
|
61
|
+
* (and no explicit `transport` is supplied) the default transport is
|
|
62
|
+
* Cloudflare Email Workers — Lunora's default provider. Ignored when
|
|
63
|
+
* `transport` is set.
|
|
64
|
+
*/
|
|
65
|
+
cloudflareSend?: (from: string, to: string, raw: string) => Promise<void>;
|
|
66
|
+
/** Default sender (`Name <addr@host>` or bare email). */
|
|
67
|
+
from: string;
|
|
68
|
+
/** Default queue binding for `mailer.queue()`. */
|
|
69
|
+
queue?: QueueLike;
|
|
70
|
+
/** Override the underlying transport. Useful for tests, the dev capture transport, + multi-provider setups. */
|
|
71
|
+
transport?: MailTransport;
|
|
72
|
+
}
|
|
73
|
+
interface Mailer {
|
|
74
|
+
queue: (options: SendOptions) => Promise<{
|
|
75
|
+
queued: true;
|
|
76
|
+
}>;
|
|
77
|
+
send: (options: SendOptions) => Promise<{
|
|
78
|
+
id: string;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One captured outbound message as persisted by the dev mail catcher. Extends
|
|
83
|
+
* the rendered, validated {@link SendPayload} with an `id` and a capture
|
|
84
|
+
* timestamp assigned by the sink (the root-shard mailbox), so the studio inbox
|
|
85
|
+
* can list and open it.
|
|
86
|
+
*
|
|
87
|
+
* **Canonical captured-mail wire type — single source of truth.** Every other
|
|
88
|
+
* representation of a captured message mirrors this shape; consumers import it
|
|
89
|
+
* directly wherever the package dependency direction allows.
|
|
90
|
+
*
|
|
91
|
+
* `@lunora/studio`'s `CapturedMail` re-exports this (type-only dep on
|
|
92
|
+
* `@lunora/mail`). `@lunora/do`'s `CapturedMailRow` / `RecordMailInput` are
|
|
93
|
+
* documented mirrors — the DO runtime stays free of any `@lunora/mail` *runtime*
|
|
94
|
+
* dep — guarded by a compile-time structural assertion against this type, so a
|
|
95
|
+
* field added here that isn't mirrored fails the `@lunora/do` build.
|
|
96
|
+
*
|
|
97
|
+
* Add or change a captured-mail field here first; the guards will point at the
|
|
98
|
+
* mirrors that need the matching change.
|
|
99
|
+
*/
|
|
100
|
+
interface CapturedMail extends SendPayload {
|
|
101
|
+
/** Epoch-ms the message was captured. */
|
|
102
|
+
capturedAt: number;
|
|
103
|
+
/** Stable id assigned to the captured message. */
|
|
104
|
+
id: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Minimal projection of the persistence target the capture transport writes to
|
|
108
|
+
* (the studio's root-shard mailbox). Declared structurally — like
|
|
109
|
+
* {@link import("./types").QueueLike} — so `@lunora/mail` stays free of any
|
|
110
|
+
* Durable Object / runtime dependency. The registry scaffold supplies the
|
|
111
|
+
* concrete sink that POSTs to the root shard's `__lunora_admin__:recordMail` RPC.
|
|
112
|
+
*/
|
|
113
|
+
interface MailboxSink {
|
|
114
|
+
record: (mail: SendPayload) => Promise<{
|
|
115
|
+
id: string;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build a capture {@link MailTransport}: instead of delivering, it persists the
|
|
120
|
+
* fully rendered + validated payload to `sink` and returns the assigned id.
|
|
121
|
+
*
|
|
122
|
+
* Wired in dev by the mail registry scaffold so `lunora dev` shows every send in
|
|
123
|
+
* the studio's Mail inbox — including `@lunora/auth`'s verification and
|
|
124
|
+
* forgot-password mail — with no provider credentials and nothing leaving the
|
|
125
|
+
* machine. Address/header validation already ran in `createMailer.buildPayload`
|
|
126
|
+
* before the payload reaches here, so the captured message is the same one a
|
|
127
|
+
* real transport would have sent.
|
|
128
|
+
*/
|
|
129
|
+
declare const createCaptureTransport: (sink: MailboxSink) => MailTransport;
|
|
130
|
+
export { CapturedMail as C, LunoraMailOptions as L, MailTransport as M, QueueLike as Q, SendOptions as S, Mailer as a, MailboxSink as b, SendPayload as c, createCaptureTransport as d };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal projection of a Cloudflare Queue binding — accepts a JSON payload
|
|
4
|
+
* via `.send()`. Declared structurally so callers can pass either the real
|
|
5
|
+
* `Queue` binding or a unit-test double.
|
|
6
|
+
*/
|
|
7
|
+
interface QueueLike {
|
|
8
|
+
send: (payload: unknown, options?: Record<string, unknown>) => Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minimal projection of a transport adapter. Returning `{ id }` follows
|
|
12
|
+
* Resend's response shape; the real `@visulima/email` `MailManager` flattens
|
|
13
|
+
* provider responses to the same field for us.
|
|
14
|
+
*/
|
|
15
|
+
interface MailTransport {
|
|
16
|
+
send: (payload: SendPayload) => Promise<{
|
|
17
|
+
id: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
interface SendPayload {
|
|
21
|
+
bcc?: string[];
|
|
22
|
+
cc?: string[];
|
|
23
|
+
from?: string;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
html?: string;
|
|
26
|
+
replyTo?: string;
|
|
27
|
+
subject: string;
|
|
28
|
+
text?: string;
|
|
29
|
+
to: string | string[];
|
|
30
|
+
}
|
|
31
|
+
interface SendOptions {
|
|
32
|
+
bcc?: string[];
|
|
33
|
+
cc?: string[];
|
|
34
|
+
from?: string;
|
|
35
|
+
headers?: Record<string, string>;
|
|
36
|
+
html?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Stable key for deduping a queued send across Cloudflare Queues' at-least-once
|
|
39
|
+
* redelivery. Only meaningful for `mailer.queue()` — `mailer.send()` ignores it.
|
|
40
|
+
* When omitted, `queue()` generates one at enqueue time so it survives redelivery
|
|
41
|
+
* (a key minted in the consumer would change on every retry, defeating the point).
|
|
42
|
+
* Not forwarded to the mail provider, and no transport can: Resend dedupes on an
|
|
43
|
+
* `Idempotency-Key` REQUEST header, and the provider client exposes no hook for
|
|
44
|
+
* one (its own `headers` field becomes message headers in the JSON body). So a
|
|
45
|
+
* consumer that wants to collapse redeliveries MUST dedupe against its own store
|
|
46
|
+
* using this key — see `consumeQueuedSend` for the shape, and for why that is a
|
|
47
|
+
* narrowed at-least-once rather than exactly-once.
|
|
48
|
+
*/
|
|
49
|
+
idempotencyKey?: string;
|
|
50
|
+
react?: ReactElement;
|
|
51
|
+
replyTo?: string;
|
|
52
|
+
subject: string;
|
|
53
|
+
text?: string;
|
|
54
|
+
to: string | string[];
|
|
55
|
+
}
|
|
56
|
+
interface LunoraMailOptions {
|
|
57
|
+
/** API key for the Resend transport (bring-your-own-provider). Ignored when `transport` or `cloudflareSend` is set. */
|
|
58
|
+
apiKey?: string;
|
|
59
|
+
/**
|
|
60
|
+
* RFC 822 send callback bound to the Worker's `send_email` binding. When set
|
|
61
|
+
* (and no explicit `transport` is supplied) the default transport is
|
|
62
|
+
* Cloudflare Email Workers — Lunora's default provider. Ignored when
|
|
63
|
+
* `transport` is set.
|
|
64
|
+
*/
|
|
65
|
+
cloudflareSend?: (from: string, to: string, raw: string) => Promise<void>;
|
|
66
|
+
/** Default sender (`Name <addr@host>` or bare email). */
|
|
67
|
+
from: string;
|
|
68
|
+
/** Default queue binding for `mailer.queue()`. */
|
|
69
|
+
queue?: QueueLike;
|
|
70
|
+
/** Override the underlying transport. Useful for tests, the dev capture transport, + multi-provider setups. */
|
|
71
|
+
transport?: MailTransport;
|
|
72
|
+
}
|
|
73
|
+
interface Mailer {
|
|
74
|
+
queue: (options: SendOptions) => Promise<{
|
|
75
|
+
queued: true;
|
|
76
|
+
}>;
|
|
77
|
+
send: (options: SendOptions) => Promise<{
|
|
78
|
+
id: string;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* One captured outbound message as persisted by the dev mail catcher. Extends
|
|
83
|
+
* the rendered, validated {@link SendPayload} with an `id` and a capture
|
|
84
|
+
* timestamp assigned by the sink (the root-shard mailbox), so the studio inbox
|
|
85
|
+
* can list and open it.
|
|
86
|
+
*
|
|
87
|
+
* **Canonical captured-mail wire type — single source of truth.** Every other
|
|
88
|
+
* representation of a captured message mirrors this shape; consumers import it
|
|
89
|
+
* directly wherever the package dependency direction allows.
|
|
90
|
+
*
|
|
91
|
+
* `@lunora/studio`'s `CapturedMail` re-exports this (type-only dep on
|
|
92
|
+
* `@lunora/mail`). `@lunora/do`'s `CapturedMailRow` / `RecordMailInput` are
|
|
93
|
+
* documented mirrors — the DO runtime stays free of any `@lunora/mail` *runtime*
|
|
94
|
+
* dep — guarded by a compile-time structural assertion against this type, so a
|
|
95
|
+
* field added here that isn't mirrored fails the `@lunora/do` build.
|
|
96
|
+
*
|
|
97
|
+
* Add or change a captured-mail field here first; the guards will point at the
|
|
98
|
+
* mirrors that need the matching change.
|
|
99
|
+
*/
|
|
100
|
+
interface CapturedMail extends SendPayload {
|
|
101
|
+
/** Epoch-ms the message was captured. */
|
|
102
|
+
capturedAt: number;
|
|
103
|
+
/** Stable id assigned to the captured message. */
|
|
104
|
+
id: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Minimal projection of the persistence target the capture transport writes to
|
|
108
|
+
* (the studio's root-shard mailbox). Declared structurally — like
|
|
109
|
+
* {@link import("./types").QueueLike} — so `@lunora/mail` stays free of any
|
|
110
|
+
* Durable Object / runtime dependency. The registry scaffold supplies the
|
|
111
|
+
* concrete sink that POSTs to the root shard's `__lunora_admin__:recordMail` RPC.
|
|
112
|
+
*/
|
|
113
|
+
interface MailboxSink {
|
|
114
|
+
record: (mail: SendPayload) => Promise<{
|
|
115
|
+
id: string;
|
|
116
|
+
}>;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Build a capture {@link MailTransport}: instead of delivering, it persists the
|
|
120
|
+
* fully rendered + validated payload to `sink` and returns the assigned id.
|
|
121
|
+
*
|
|
122
|
+
* Wired in dev by the mail registry scaffold so `lunora dev` shows every send in
|
|
123
|
+
* the studio's Mail inbox — including `@lunora/auth`'s verification and
|
|
124
|
+
* forgot-password mail — with no provider credentials and nothing leaving the
|
|
125
|
+
* machine. Address/header validation already ran in `createMailer.buildPayload`
|
|
126
|
+
* before the payload reaches here, so the captured message is the same one a
|
|
127
|
+
* real transport would have sent.
|
|
128
|
+
*/
|
|
129
|
+
declare const createCaptureTransport: (sink: MailboxSink) => MailTransport;
|
|
130
|
+
export { CapturedMail as C, LunoraMailOptions as L, MailTransport as M, QueueLike as Q, SendOptions as S, Mailer as a, MailboxSink as b, SendPayload as c, createCaptureTransport as d };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as c}from"@lunora/errors";const d=n=>{const t={...n};return delete t.react,t},p=async(n,t)=>{if(!t||typeof t!="object"||Array.isArray(t))throw new c("INTERNAL","@lunora/mail: queue message body must be an object");const e=t;if(typeof e.subject!="string")throw new TypeError("@lunora/mail: queue message must have a string `subject`");const y=typeof e.to=="string",m=Array.isArray(e.to)&&e.to.every(o=>typeof o=="string");if(!y&&!m)throw new c("INTERNAL","@lunora/mail: queue message `to` must be a string or string[]");const s=(o,r)=>{if(r!==void 0){if(typeof r!="string")throw new TypeError(`@lunora/mail: queue message \`${o}\` must be a string`);return r}},a=(o,r)=>{if(r!==void 0){if(typeof r=="string")return[r];if(Array.isArray(r)&&r.every(i=>typeof i=="string"))return r;throw new TypeError(`@lunora/mail: queue message \`${o}\` must be a string or string[]`)}};let u;if(e.headers!==void 0){if(!e.headers||typeof e.headers!="object"||Array.isArray(e.headers))throw new TypeError("@lunora/mail: queue message `headers` must be an object of string values");const o=Object.entries(e.headers);for(const[r,i]of o)if(typeof i!="string")throw new TypeError(`@lunora/mail: queue message header "${r}" must be a string`);u=e.headers}const f={bcc:a("bcc",e.bcc),cc:a("cc",e.cc),from:s("from",e.from),headers:u,html:s("html",e.html),idempotencyKey:s("idempotencyKey",e.idempotencyKey),replyTo:s("replyTo",e.replyTo),subject:e.subject,text:s("text",e.text),to:e.to};return n.send(f)};export{p as consumeQueuedSend,d as toQueuedPayload};
|
|
@@ -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
|
+
const t=Symbol.for("@lunora/mail.captureTransport"),a=r=>r[t]===!0,s=r=>({[t]:!0,send:async o=>r.record(o)});export{s as createCaptureTransport,a as isCaptureTransport};
|