@lunora/mail 1.0.0-alpha.2 → 1.0.0-alpha.21
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/LICENSE.md +6 -0
- package/dist/inbound/index.d.mts +80 -69
- package/dist/inbound/index.d.ts +80 -69
- package/dist/inbound/index.mjs +1 -2
- package/dist/index.d.mts +95 -78
- package/dist/index.d.ts +95 -78
- package/dist/index.mjs +1 -7
- package/dist/packem_shared/address-Y4Z--6ZO.mjs +3 -0
- package/dist/packem_shared/capture-transport.d-BJ__iWzS.d.mts +117 -0
- package/dist/packem_shared/capture-transport.d-BJ__iWzS.d.ts +117 -0
- package/dist/packem_shared/consumeQueuedSend-BXrPhND5.mjs +1 -0
- package/dist/packem_shared/createCaptureSink-fVjCTUBC.mjs +1 -0
- package/dist/packem_shared/createCaptureTransport-BPdMkU0O.mjs +1 -0
- package/dist/packem_shared/createCloudflareTransport-V23CVw7F.mjs +1 -0
- package/dist/packem_shared/createInboundEmailHandler-B7H4h_sK.mjs +1 -0
- package/dist/packem_shared/createMailer-CsVLrc75.mjs +1 -0
- package/dist/packem_shared/createResendTransport-CpSJ4j7C.mjs +1 -0
- package/dist/packem_shared/parseInboundEmail-tJMs3YON.mjs +1 -0
- package/dist/packem_shared/provider-transport-BZngzyeS.mjs +1 -0
- package/dist/packem_shared/renderEmail-DM8_pWKa.mjs +1 -0
- package/dist/packem_shared/shard-CcKsuWAm.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 -57
- package/package.json +6 -5
- package/dist/packem_shared/address-fkXxLKza.mjs +0 -62
- 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-BEKOdaxU.mjs +0 -75
- package/dist/packem_shared/createCaptureSink-DeihS4LH.mjs +0 -63
- package/dist/packem_shared/createCaptureTransport-Crz_8822.mjs +0 -11
- package/dist/packem_shared/createCloudflareTransport-yHOVEsZv.mjs +0 -26
- package/dist/packem_shared/createInboundEmailHandler-D0uCOrU-.mjs +0 -83
- package/dist/packem_shared/createMailer-oEKPAd4J.mjs +0 -77
- package/dist/packem_shared/createResendTransport-oNIorpzv.mjs +0 -16
- package/dist/packem_shared/parseInboundEmail-Bw9u_1oc.mjs +0 -72
- package/dist/packem_shared/provider-transport-C5CVbjRF.mjs +0 -47
- 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.mts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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 Q as QueueLike, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-
|
|
3
|
-
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-
|
|
1
|
+
import { M as MailTransport, L as LunoraMailOptions, a as Mailer, b as MailboxSink, S as SendOptions } from "./packem_shared/capture-transport.d-BJ__iWzS.mjs";
|
|
2
|
+
export { type C as CapturedMail, type Q as QueueLike, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-BJ__iWzS.mjs";
|
|
3
|
+
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.mjs";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
5
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
18
18
|
type CloudflareSend = (from: string, to: string, raw: string) => Promise<void>;
|
|
19
19
|
interface CloudflareTransportOptions {
|
|
20
20
|
/** Default sender used when a `SendOptions.from` isn't supplied. */
|
|
@@ -23,17 +23,34 @@ interface CloudflareTransportOptions {
|
|
|
23
23
|
send: CloudflareSend;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
36
36
|
declare const createCloudflareTransport: (options: CloudflareTransportOptions) => MailTransport;
|
|
37
|
+
/**
|
|
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
|
+
*/
|
|
37
54
|
declare const createMailer: (options: LunoraMailOptions) => Mailer;
|
|
38
55
|
/** A Worker `env` projected as a plain record (vars, secrets, and bindings are `unknown`-valued). */
|
|
39
56
|
type MailEnv = Record<string, unknown>;
|
|
@@ -42,39 +59,39 @@ interface FromEnvOptions {
|
|
|
42
59
|
/** RFC 822 send callback bound to the Worker's `send_email` binding (Cloudflare default transport). */
|
|
43
60
|
cloudflareSend?: CloudflareSend;
|
|
44
61
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
* Pin the captured-mail inbox shard to a Cloudflare data-residency
|
|
63
|
+
* jurisdiction. Pass the same value as the worker's `jurisdiction` so the
|
|
64
|
+
* dev inbox co-resides with app data. Omit for the un-pinned global namespace.
|
|
65
|
+
*/
|
|
49
66
|
jurisdiction?: DurableObjectJurisdiction;
|
|
50
67
|
/** Shard the captured-mail inbox lives on; override if your worker sets a custom `defaultShardKey`. */
|
|
51
68
|
rootShard?: string;
|
|
52
69
|
}
|
|
53
70
|
/**
|
|
54
|
-
* Whether outbound mail should be captured (into the studio inbox) rather than
|
|
55
|
-
* delivered. Explicit `LUNORA_MAIL_CAPTURE` (`"1"`/`"true"` vs `"0"`/`"false"`)
|
|
56
|
-
* always wins; unset, capture is on only in a development environment. It does
|
|
57
|
-
* NOT fall back to "no SEND_EMAIL binding ⇒ capture" — a production deploy that
|
|
58
|
-
* forgot the binding must fail loudly on send, not silently swallow mail.
|
|
59
|
-
*/
|
|
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 in a development environment. It does
|
|
74
|
+
* NOT fall back to "no SEND_EMAIL binding ⇒ capture" — a production deploy that
|
|
75
|
+
* forgot the binding must fail loudly on send, not silently swallow mail.
|
|
76
|
+
*/
|
|
60
77
|
declare const shouldCaptureMail: (env: MailEnv) => boolean;
|
|
61
78
|
/**
|
|
62
|
-
* Build the {@link MailboxSink} that records a captured message into the studio's
|
|
63
|
-
* root-shard inbox via the reserved `recordMail` admin RPC — the same
|
|
64
|
-
* worker→root-shard path the runtime uses for auth events. Best-effort: without
|
|
65
|
-
* the `SHARD` binding or `LUNORA_ADMIN_TOKEN` it returns a sentinel id so a send
|
|
66
|
-
* never fails for lack of somewhere to record.
|
|
67
|
-
*/
|
|
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
|
+
*/
|
|
68
85
|
declare const createCaptureSink: (env: MailEnv, rootShard?: string, jurisdiction?: DurableObjectJurisdiction) => MailboxSink;
|
|
69
86
|
/**
|
|
70
|
-
* Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
|
|
71
|
-
* captured into the studio's Mail inbox; otherwise it delivers via the supplied
|
|
72
|
-
* `cloudflareSend` (the `SEND_EMAIL` binding) or, failing that, `RESEND_API_KEY`.
|
|
73
|
-
* Throws when neither a capture context nor a real transport is available, so a
|
|
74
|
-
* misconfigured production deploy fails loudly instead of silently dropping mail.
|
|
75
|
-
*
|
|
76
|
-
* `MAIL_FROM` is required (the default sender).
|
|
77
|
-
*/
|
|
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` (the `SEND_EMAIL` binding) or, failing that, `RESEND_API_KEY`.
|
|
90
|
+
* Throws when neither a capture context nor a real transport is available, so a
|
|
91
|
+
* misconfigured production deploy fails loudly instead of silently dropping mail.
|
|
92
|
+
*
|
|
93
|
+
* `MAIL_FROM` is required (the default sender).
|
|
94
|
+
*/
|
|
78
95
|
declare const createMailerFromEnv: (env: MailEnv, options?: FromEnvOptions) => Mailer;
|
|
79
96
|
/** Serializable representation of a `SendOptions` payload — drops the `react` field. */
|
|
80
97
|
interface QueuedSend {
|
|
@@ -89,45 +106,45 @@ interface QueuedSend {
|
|
|
89
106
|
to: string | string[];
|
|
90
107
|
}
|
|
91
108
|
/**
|
|
92
|
-
* Narrow a `SendOptions` to its serializable `QueuedSend` shape by dropping the
|
|
93
|
-
* non-cloneable `react` field. React elements are not structured-cloneable, so
|
|
94
|
-
* the queue body must carry only the pre-rendered html/text and scalar fields.
|
|
95
|
-
*/
|
|
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
|
+
*/
|
|
96
113
|
declare const toQueuedPayload: (options: SendOptions) => QueuedSend;
|
|
97
114
|
/**
|
|
98
|
-
* Helper used by Queue consumers: rehydrate a `QueuedSend` payload and forward
|
|
99
|
-
* to a configured `Mailer.send()`. Use this inside your Worker's `queue()`
|
|
100
|
-
* handler.
|
|
101
|
-
*
|
|
102
|
-
* ```ts
|
|
103
|
-
* export default {
|
|
104
|
-
* queue: async (batch, env) => {
|
|
105
|
-
* const mailer = createMailer({ apiKey: env.RESEND_API_KEY, from: "..." });
|
|
106
|
-
* for (const message of batch.messages) {
|
|
107
|
-
* await consumeQueuedSend(mailer, message.body);
|
|
108
|
-
* }
|
|
109
|
-
* },
|
|
110
|
-
* };
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
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
|
+
* ```ts
|
|
120
|
+
* export default {
|
|
121
|
+
* queue: async (batch, env) => {
|
|
122
|
+
* const mailer = createMailer({ apiKey: env.RESEND_API_KEY, from: "..." });
|
|
123
|
+
* for (const message of batch.messages) {
|
|
124
|
+
* await consumeQueuedSend(mailer, message.body);
|
|
125
|
+
* }
|
|
126
|
+
* },
|
|
127
|
+
* };
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
113
130
|
declare const consumeQueuedSend: (mailer: Mailer, payload: unknown) => Promise<{
|
|
114
131
|
id: string;
|
|
115
132
|
}>;
|
|
116
133
|
/**
|
|
117
|
-
* Render a React element to an HTML/text pair suitable for inlining into a
|
|
118
|
-
* provider payload. Wraps `@react-email/render` so we can swap to
|
|
119
|
-
* `@visulima/email`'s react-email template engine without touching callers.
|
|
120
|
-
*/
|
|
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
|
+
*/
|
|
121
138
|
declare const renderEmail: (element: ReactElement) => Promise<{
|
|
122
139
|
html: string;
|
|
123
140
|
text: string;
|
|
124
141
|
}>;
|
|
125
142
|
/**
|
|
126
|
-
* Build a Resend-backed transport via `@visulima/email`. Wraps the provider's
|
|
127
|
-
* `sendEmail()` into the minimal `{ send(payload) -> { id } }` shape the rest of
|
|
128
|
-
* `@lunora/mail` consumes. Kept reachable as a named export so a project that
|
|
129
|
-
* prefers Resend over the Cloudflare default can pass
|
|
130
|
-
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
131
|
-
*/
|
|
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
|
+
*/
|
|
132
149
|
declare const createResendTransport: (apiKey: string, defaultFrom: string) => MailTransport;
|
|
133
150
|
export { type CloudflareSend, type CloudflareTransportOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, type MailTransport, type MailboxSink, type Mailer, type QueuedSend, type SendOptions, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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 Q as QueueLike, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-
|
|
3
|
-
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-
|
|
1
|
+
import { M as MailTransport, L as LunoraMailOptions, a as Mailer, b as MailboxSink, S as SendOptions } from "./packem_shared/capture-transport.d-BJ__iWzS.js";
|
|
2
|
+
export { type C as CapturedMail, type Q as QueueLike, type c as SendPayload, d as createCaptureTransport } from "./packem_shared/capture-transport.d-BJ__iWzS.js";
|
|
3
|
+
import { D as DurableObjectJurisdiction } from "./packem_shared/shard.d-DVADjmEJ.js";
|
|
4
4
|
import { ReactElement } from 'react';
|
|
5
5
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
18
18
|
type CloudflareSend = (from: string, to: string, raw: string) => Promise<void>;
|
|
19
19
|
interface CloudflareTransportOptions {
|
|
20
20
|
/** Default sender used when a `SendOptions.from` isn't supplied. */
|
|
@@ -23,17 +23,34 @@ interface CloudflareTransportOptions {
|
|
|
23
23
|
send: CloudflareSend;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
36
36
|
declare const createCloudflareTransport: (options: CloudflareTransportOptions) => MailTransport;
|
|
37
|
+
/**
|
|
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
|
+
*/
|
|
37
54
|
declare const createMailer: (options: LunoraMailOptions) => Mailer;
|
|
38
55
|
/** A Worker `env` projected as a plain record (vars, secrets, and bindings are `unknown`-valued). */
|
|
39
56
|
type MailEnv = Record<string, unknown>;
|
|
@@ -42,39 +59,39 @@ interface FromEnvOptions {
|
|
|
42
59
|
/** RFC 822 send callback bound to the Worker's `send_email` binding (Cloudflare default transport). */
|
|
43
60
|
cloudflareSend?: CloudflareSend;
|
|
44
61
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
* Pin the captured-mail inbox shard to a Cloudflare data-residency
|
|
63
|
+
* jurisdiction. Pass the same value as the worker's `jurisdiction` so the
|
|
64
|
+
* dev inbox co-resides with app data. Omit for the un-pinned global namespace.
|
|
65
|
+
*/
|
|
49
66
|
jurisdiction?: DurableObjectJurisdiction;
|
|
50
67
|
/** Shard the captured-mail inbox lives on; override if your worker sets a custom `defaultShardKey`. */
|
|
51
68
|
rootShard?: string;
|
|
52
69
|
}
|
|
53
70
|
/**
|
|
54
|
-
* Whether outbound mail should be captured (into the studio inbox) rather than
|
|
55
|
-
* delivered. Explicit `LUNORA_MAIL_CAPTURE` (`"1"`/`"true"` vs `"0"`/`"false"`)
|
|
56
|
-
* always wins; unset, capture is on only in a development environment. It does
|
|
57
|
-
* NOT fall back to "no SEND_EMAIL binding ⇒ capture" — a production deploy that
|
|
58
|
-
* forgot the binding must fail loudly on send, not silently swallow mail.
|
|
59
|
-
*/
|
|
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 in a development environment. It does
|
|
74
|
+
* NOT fall back to "no SEND_EMAIL binding ⇒ capture" — a production deploy that
|
|
75
|
+
* forgot the binding must fail loudly on send, not silently swallow mail.
|
|
76
|
+
*/
|
|
60
77
|
declare const shouldCaptureMail: (env: MailEnv) => boolean;
|
|
61
78
|
/**
|
|
62
|
-
* Build the {@link MailboxSink} that records a captured message into the studio's
|
|
63
|
-
* root-shard inbox via the reserved `recordMail` admin RPC — the same
|
|
64
|
-
* worker→root-shard path the runtime uses for auth events. Best-effort: without
|
|
65
|
-
* the `SHARD` binding or `LUNORA_ADMIN_TOKEN` it returns a sentinel id so a send
|
|
66
|
-
* never fails for lack of somewhere to record.
|
|
67
|
-
*/
|
|
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
|
+
*/
|
|
68
85
|
declare const createCaptureSink: (env: MailEnv, rootShard?: string, jurisdiction?: DurableObjectJurisdiction) => MailboxSink;
|
|
69
86
|
/**
|
|
70
|
-
* Build a {@link Mailer} from a Worker `env`. In a dev environment every send is
|
|
71
|
-
* captured into the studio's Mail inbox; otherwise it delivers via the supplied
|
|
72
|
-
* `cloudflareSend` (the `SEND_EMAIL` binding) or, failing that, `RESEND_API_KEY`.
|
|
73
|
-
* Throws when neither a capture context nor a real transport is available, so a
|
|
74
|
-
* misconfigured production deploy fails loudly instead of silently dropping mail.
|
|
75
|
-
*
|
|
76
|
-
* `MAIL_FROM` is required (the default sender).
|
|
77
|
-
*/
|
|
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` (the `SEND_EMAIL` binding) or, failing that, `RESEND_API_KEY`.
|
|
90
|
+
* Throws when neither a capture context nor a real transport is available, so a
|
|
91
|
+
* misconfigured production deploy fails loudly instead of silently dropping mail.
|
|
92
|
+
*
|
|
93
|
+
* `MAIL_FROM` is required (the default sender).
|
|
94
|
+
*/
|
|
78
95
|
declare const createMailerFromEnv: (env: MailEnv, options?: FromEnvOptions) => Mailer;
|
|
79
96
|
/** Serializable representation of a `SendOptions` payload — drops the `react` field. */
|
|
80
97
|
interface QueuedSend {
|
|
@@ -89,45 +106,45 @@ interface QueuedSend {
|
|
|
89
106
|
to: string | string[];
|
|
90
107
|
}
|
|
91
108
|
/**
|
|
92
|
-
* Narrow a `SendOptions` to its serializable `QueuedSend` shape by dropping the
|
|
93
|
-
* non-cloneable `react` field. React elements are not structured-cloneable, so
|
|
94
|
-
* the queue body must carry only the pre-rendered html/text and scalar fields.
|
|
95
|
-
*/
|
|
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
|
+
*/
|
|
96
113
|
declare const toQueuedPayload: (options: SendOptions) => QueuedSend;
|
|
97
114
|
/**
|
|
98
|
-
* Helper used by Queue consumers: rehydrate a `QueuedSend` payload and forward
|
|
99
|
-
* to a configured `Mailer.send()`. Use this inside your Worker's `queue()`
|
|
100
|
-
* handler.
|
|
101
|
-
*
|
|
102
|
-
* ```ts
|
|
103
|
-
* export default {
|
|
104
|
-
* queue: async (batch, env) => {
|
|
105
|
-
* const mailer = createMailer({ apiKey: env.RESEND_API_KEY, from: "..." });
|
|
106
|
-
* for (const message of batch.messages) {
|
|
107
|
-
* await consumeQueuedSend(mailer, message.body);
|
|
108
|
-
* }
|
|
109
|
-
* },
|
|
110
|
-
* };
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
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
|
+
* ```ts
|
|
120
|
+
* export default {
|
|
121
|
+
* queue: async (batch, env) => {
|
|
122
|
+
* const mailer = createMailer({ apiKey: env.RESEND_API_KEY, from: "..." });
|
|
123
|
+
* for (const message of batch.messages) {
|
|
124
|
+
* await consumeQueuedSend(mailer, message.body);
|
|
125
|
+
* }
|
|
126
|
+
* },
|
|
127
|
+
* };
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
113
130
|
declare const consumeQueuedSend: (mailer: Mailer, payload: unknown) => Promise<{
|
|
114
131
|
id: string;
|
|
115
132
|
}>;
|
|
116
133
|
/**
|
|
117
|
-
* Render a React element to an HTML/text pair suitable for inlining into a
|
|
118
|
-
* provider payload. Wraps `@react-email/render` so we can swap to
|
|
119
|
-
* `@visulima/email`'s react-email template engine without touching callers.
|
|
120
|
-
*/
|
|
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
|
+
*/
|
|
121
138
|
declare const renderEmail: (element: ReactElement) => Promise<{
|
|
122
139
|
html: string;
|
|
123
140
|
text: string;
|
|
124
141
|
}>;
|
|
125
142
|
/**
|
|
126
|
-
* Build a Resend-backed transport via `@visulima/email`. Wraps the provider's
|
|
127
|
-
* `sendEmail()` into the minimal `{ send(payload) -> { id } }` shape the rest of
|
|
128
|
-
* `@lunora/mail` consumes. Kept reachable as a named export so a project that
|
|
129
|
-
* prefers Resend over the Cloudflare default can pass
|
|
130
|
-
* `transport: createResendTransport(apiKey, from)` to `createMailer`.
|
|
131
|
-
*/
|
|
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
|
+
*/
|
|
132
149
|
declare const createResendTransport: (apiKey: string, defaultFrom: string) => MailTransport;
|
|
133
150
|
export { type CloudflareSend, type CloudflareTransportOptions, type FromEnvOptions, type LunoraMailOptions, type MailEnv, type MailTransport, type MailboxSink, type Mailer, type QueuedSend, type SendOptions, consumeQueuedSend, createCaptureSink, createCloudflareTransport, createMailer, createMailerFromEnv, createResendTransport, renderEmail, shouldCaptureMail, toQueuedPayload };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createCloudflareTransport } from './packem_shared/createCloudflareTransport-yHOVEsZv.mjs';
|
|
3
|
-
export { default as createMailer } from './packem_shared/createMailer-oEKPAd4J.mjs';
|
|
4
|
-
export { createCaptureSink, createMailerFromEnv, shouldCaptureMail } from './packem_shared/createCaptureSink-DeihS4LH.mjs';
|
|
5
|
-
export { consumeQueuedSend, toQueuedPayload } from './packem_shared/consumeQueuedSend-BEKOdaxU.mjs';
|
|
6
|
-
export { default as renderEmail } from './packem_shared/renderEmail-hyS1bpVP.mjs';
|
|
7
|
-
export { default as createResendTransport } from './packem_shared/createResendTransport-oNIorpzv.mjs';
|
|
1
|
+
import{createCaptureTransport as a}from"./packem_shared/createCaptureTransport-BPdMkU0O.mjs";import{createCloudflareTransport as t}from"./packem_shared/createCloudflareTransport-V23CVw7F.mjs";import{default as u}from"./packem_shared/createMailer-CsVLrc75.mjs";import{createCaptureSink as f,createMailerFromEnv as l,shouldCaptureMail as m}from"./packem_shared/createCaptureSink-fVjCTUBC.mjs";import{consumeQueuedSend as s,toQueuedPayload as c}from"./packem_shared/consumeQueuedSend-BXrPhND5.mjs";import{default as i}from"./packem_shared/renderEmail-DM8_pWKa.mjs";import{default as M}from"./packem_shared/createResendTransport-CpSJ4j7C.mjs";export{s as consumeQueuedSend,f as createCaptureSink,a as createCaptureTransport,t as createCloudflareTransport,u as createMailer,l as createMailerFromEnv,M as createResendTransport,i as renderEmail,m as shouldCaptureMail,c as toQueuedPayload};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{LunoraError as i}from"@lunora/errors";const r=320,l=256,s=/^([^<]*)<([^>]*)>\s*$/,o=(e,a)=>{if(a.includes("\r")||a.includes(`
|
|
2
|
+
`)||a.includes(","))throw new i("INTERNAL",`@lunora/mail: address ${e} must not contain CR, LF, or comma`)},h=(e,a)=>{if(a.includes("\r")||a.includes(`
|
|
3
|
+
`))throw new i("INTERNAL",`@lunora/mail: ${e} must not contain CR or LF`)},c=(e,a)=>{if(e.length>l)throw new i("INTERNAL",`@lunora/mail: address name must be <= ${String(l)} characters`);if(a.length>r)throw new i("INTERNAL",`@lunora/mail: address email must be <= ${String(r)} characters`);return e&&o("name",e),o("email",a),e?{email:a,name:e}:{email:a}},u=e=>{const a=e.trim();if(a.length>r)throw new i("INTERNAL",`@lunora/mail: address email must be <= ${String(r)} characters`);return o("email",a),{email:a}},n=e=>{const a=s.exec(e),m=(a?.[2]??"").trim();return a&&m?c((a[1]??"").trim(),m):u(e)},t=e=>e===void 0?void 0:(Array.isArray(e)?e:[e]).map(a=>n(a)),w=e=>{t(e.to),t(e.cc),t(e.bcc),e.from!==void 0&&n(e.from),e.replyTo!==void 0&&n(e.replyTo)};export{w as f,t as i,h as m,n as o};
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
+
react?: ReactElement;
|
|
38
|
+
replyTo?: string;
|
|
39
|
+
subject: string;
|
|
40
|
+
text?: string;
|
|
41
|
+
to: string | string[];
|
|
42
|
+
}
|
|
43
|
+
interface LunoraMailOptions {
|
|
44
|
+
/** API key for the Resend transport (bring-your-own-provider). Ignored when `transport` or `cloudflareSend` is set. */
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/**
|
|
47
|
+
* RFC 822 send callback bound to the Worker's `send_email` binding. When set
|
|
48
|
+
* (and no explicit `transport` is supplied) the default transport is
|
|
49
|
+
* Cloudflare Email Workers — Lunora's default provider. Ignored when
|
|
50
|
+
* `transport` is set.
|
|
51
|
+
*/
|
|
52
|
+
cloudflareSend?: (from: string, to: string, raw: string) => Promise<void>;
|
|
53
|
+
/** Default sender (`Name <addr@host>` or bare email). */
|
|
54
|
+
from: string;
|
|
55
|
+
/** Default queue binding for `mailer.queue()`. */
|
|
56
|
+
queue?: QueueLike;
|
|
57
|
+
/** Override the underlying transport. Useful for tests, the dev capture transport, + multi-provider setups. */
|
|
58
|
+
transport?: MailTransport;
|
|
59
|
+
}
|
|
60
|
+
interface Mailer {
|
|
61
|
+
queue: (options: SendOptions) => Promise<{
|
|
62
|
+
queued: true;
|
|
63
|
+
}>;
|
|
64
|
+
send: (options: SendOptions) => Promise<{
|
|
65
|
+
id: string;
|
|
66
|
+
}>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One captured outbound message as persisted by the dev mail catcher. Extends
|
|
70
|
+
* the rendered, validated {@link SendPayload} with an `id` and a capture
|
|
71
|
+
* timestamp assigned by the sink (the root-shard mailbox), so the studio inbox
|
|
72
|
+
* can list and open it.
|
|
73
|
+
*
|
|
74
|
+
* **Canonical captured-mail wire type — single source of truth.** Every other
|
|
75
|
+
* representation of a captured message mirrors this shape; consumers import it
|
|
76
|
+
* directly wherever the package dependency direction allows.
|
|
77
|
+
*
|
|
78
|
+
* `@lunora/studio`'s `CapturedMail` re-exports this (type-only dep on
|
|
79
|
+
* `@lunora/mail`). `@lunora/do`'s `CapturedMailRow` / `RecordMailInput` are
|
|
80
|
+
* documented mirrors — the DO runtime stays free of any `@lunora/mail` *runtime*
|
|
81
|
+
* dep — guarded by a compile-time structural assertion against this type, so a
|
|
82
|
+
* field added here that isn't mirrored fails the `@lunora/do` build.
|
|
83
|
+
*
|
|
84
|
+
* Add or change a captured-mail field here first; the guards will point at the
|
|
85
|
+
* mirrors that need the matching change.
|
|
86
|
+
*/
|
|
87
|
+
interface CapturedMail extends SendPayload {
|
|
88
|
+
/** Epoch-ms the message was captured. */
|
|
89
|
+
capturedAt: number;
|
|
90
|
+
/** Stable id assigned to the captured message. */
|
|
91
|
+
id: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Minimal projection of the persistence target the capture transport writes to
|
|
95
|
+
* (the studio's root-shard mailbox). Declared structurally — like
|
|
96
|
+
* {@link import("./types").QueueLike} — so `@lunora/mail` stays free of any
|
|
97
|
+
* Durable Object / runtime dependency. The registry scaffold supplies the
|
|
98
|
+
* concrete sink that POSTs to the root shard's `__lunora_admin__:recordMail` RPC.
|
|
99
|
+
*/
|
|
100
|
+
interface MailboxSink {
|
|
101
|
+
record: (mail: SendPayload) => Promise<{
|
|
102
|
+
id: string;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Build a capture {@link MailTransport}: instead of delivering, it persists the
|
|
107
|
+
* fully rendered + validated payload to `sink` and returns the assigned id.
|
|
108
|
+
*
|
|
109
|
+
* Wired in dev by the mail registry scaffold so `lunora dev` shows every send in
|
|
110
|
+
* the studio's Mail inbox — including `@lunora/auth`'s verification and
|
|
111
|
+
* forgot-password mail — with no provider credentials and nothing leaving the
|
|
112
|
+
* machine. Address/header validation already ran in `createMailer.buildPayload`
|
|
113
|
+
* before the payload reaches here, so the captured message is the same one a
|
|
114
|
+
* real transport would have sent.
|
|
115
|
+
*/
|
|
116
|
+
declare const createCaptureTransport: (sink: MailboxSink) => MailTransport;
|
|
117
|
+
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 };
|