@lunora/mail 1.0.0-alpha.5 → 1.0.0-alpha.50

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 +209 -70
  3. package/dist/inbound/index.d.ts +209 -70
  4. package/dist/inbound/index.mjs +1 -2
  5. package/dist/index.d.mts +94 -94
  6. package/dist/index.d.ts +94 -94
  7. package/dist/index.mjs +1 -7
  8. package/dist/packem_shared/address-BQ5RUGdT.mjs +3 -0
  9. package/dist/packem_shared/capture-transport.d-_rIl9W6N.d.mts +117 -0
  10. package/dist/packem_shared/capture-transport.d-_rIl9W6N.d.ts +117 -0
  11. package/dist/packem_shared/consumeQueuedSend-8TXPj5o-.mjs +1 -0
  12. package/dist/packem_shared/createCaptureSink-CE24od5h.mjs +1 -0
  13. package/dist/packem_shared/createCaptureTransport-CKc6NpZR.mjs +1 -0
  14. package/dist/packem_shared/createCloudflareTransport-E-UdW8Dc.mjs +1 -0
  15. package/dist/packem_shared/createInboundEmailHandler-D2i0mEBB.mjs +1 -0
  16. package/dist/packem_shared/createMailer-LHgKs5yh.mjs +1 -0
  17. package/dist/packem_shared/createResendTransport-CG9s8iI9.mjs +1 -0
  18. package/dist/packem_shared/parseInboundEmail-Cxe54g-h.mjs +1 -0
  19. package/dist/packem_shared/provider-transport-DXmTG_xv.mjs +1 -0
  20. package/dist/packem_shared/renderEmail-BOUnr6i3.mjs +1 -0
  21. package/dist/packem_shared/shard-C0aRRoVy.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 +5 -4
  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
@@ -1,77 +0,0 @@
1
- import { a as assertSafeHeaderValue, b as assertSafeAddresses } from './address-fkXxLKza.mjs';
2
- import { isCaptureTransport } from './createCaptureTransport-Crz_8822.mjs';
3
- import { createCloudflareTransport } from './createCloudflareTransport-yHOVEsZv.mjs';
4
- import { toQueuedPayload } from './consumeQueuedSend-BEKOdaxU.mjs';
5
- import renderEmail from './renderEmail-hyS1bpVP.mjs';
6
- import createResendTransport from './createResendTransport-oNIorpzv.mjs';
7
-
8
- const buildDefaultTransport = (options) => {
9
- if (options.cloudflareSend) {
10
- return createCloudflareTransport({ from: options.from, send: options.cloudflareSend });
11
- }
12
- if (options.apiKey) {
13
- return createResendTransport(options.apiKey, options.from);
14
- }
15
- throw new Error("@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend)");
16
- };
17
- const createMailer = (options) => {
18
- if (!options.from) {
19
- throw new Error("@lunora/mail: `from` is required");
20
- }
21
- const transport = options.transport ?? buildDefaultTransport(options);
22
- const buildPayload = async (options_) => {
23
- let { html } = options_;
24
- let { text } = options_;
25
- if (options_.react) {
26
- const rendered = await renderEmail(options_.react);
27
- html = html ?? rendered.html;
28
- text = text ?? rendered.text;
29
- }
30
- assertSafeHeaderValue("subject", options_.subject);
31
- if (options_.headers) {
32
- for (const [name, value] of Object.entries(options_.headers)) {
33
- assertSafeHeaderValue(`header name "${name}"`, name);
34
- assertSafeHeaderValue(`header "${name}" value`, value);
35
- }
36
- }
37
- const from = options_.from ?? options.from;
38
- assertSafeAddresses({
39
- bcc: options_.bcc,
40
- cc: options_.cc,
41
- from,
42
- replyTo: options_.replyTo,
43
- to: options_.to
44
- });
45
- return {
46
- bcc: options_.bcc,
47
- cc: options_.cc,
48
- from,
49
- headers: options_.headers,
50
- html,
51
- replyTo: options_.replyTo,
52
- subject: options_.subject,
53
- text,
54
- to: options_.to
55
- };
56
- };
57
- const send = async (options_) => {
58
- const payload = await buildPayload(options_);
59
- return transport.send(payload);
60
- };
61
- const queue = async (options_) => {
62
- if (!options.queue) {
63
- if (isCaptureTransport(transport)) {
64
- const captured = await buildPayload(options_);
65
- await transport.send(captured);
66
- return { queued: true };
67
- }
68
- throw new Error("@lunora/mail: `queue` binding is required for mailer.queue()");
69
- }
70
- const payload = await buildPayload(options_);
71
- await options.queue.send(toQueuedPayload(payload));
72
- return { queued: true };
73
- };
74
- return { queue, send };
75
- };
76
-
77
- export { createMailer as default };
@@ -1,16 +0,0 @@
1
- import { resendProvider } from '@visulima/email/providers/resend';
2
- import { r as requireRecipients, t as toProviderEmail, i as interpretSendResult } from './provider-transport-C5CVbjRF.mjs';
3
-
4
- const createResendTransport = (apiKey, defaultFrom) => {
5
- const provider = resendProvider({ apiKey });
6
- return {
7
- send: async (payload) => {
8
- await provider.initialize();
9
- const { first, list } = requireRecipients(payload.to);
10
- const result = await provider.sendEmail(toProviderEmail(payload, defaultFrom, list.length === 1 ? first : list));
11
- return interpretSendResult(result);
12
- }
13
- };
14
- };
15
-
16
- export { createResendTransport as default };
@@ -1,72 +0,0 @@
1
- import PostalMime from 'postal-mime';
2
- import { a as assertSafeHeaderValue } from './address-fkXxLKza.mjs';
3
-
4
- const safe = (label, value) => {
5
- if (value === void 0) {
6
- return void 0;
7
- }
8
- assertSafeHeaderValue(`inbound ${label}`, value);
9
- return value;
10
- };
11
- const formatAddress = (entry) => {
12
- if (entry.address !== void 0 && entry.address !== "") {
13
- return entry.name ? `${entry.name} <${entry.address}>` : entry.address;
14
- }
15
- if (entry.group) {
16
- return entry.group.map((member) => member.address ?? "").filter((address) => address !== "").join(", ");
17
- }
18
- return entry.name ?? "";
19
- };
20
- const authVerdict = (authResults, method) => {
21
- const match = new RegExp(String.raw`\b${method}=([a-zA-Z]+)`, "i").exec(authResults);
22
- return match?.[1]?.toLowerCase() ?? null;
23
- };
24
- const parseAuthentication = (authResults) => {
25
- if (authResults === void 0 || authResults === "") {
26
- return { dkim: null, dmarc: null, spf: null };
27
- }
28
- return {
29
- dkim: authVerdict(authResults, "dkim"),
30
- dmarc: authVerdict(authResults, "dmarc"),
31
- spf: authVerdict(authResults, "spf")
32
- };
33
- };
34
- const parseInboundEmail = async (raw) => {
35
- const parsed = await PostalMime.parse(raw);
36
- const headers = {};
37
- for (const header of parsed.headers) {
38
- assertSafeHeaderValue(`inbound header \`${header.key}\``, header.value);
39
- headers[header.key] = header.value;
40
- }
41
- const to = (parsed.to ?? []).map((entry) => {
42
- const formatted = formatAddress(entry);
43
- assertSafeHeaderValue("inbound to", formatted);
44
- return formatted;
45
- });
46
- const from = parsed.from ? formatAddress(parsed.from) : "";
47
- assertSafeHeaderValue("inbound from", from);
48
- const attachments = parsed.attachments.map((attachment) => {
49
- return {
50
- content: attachment.content,
51
- disposition: attachment.disposition,
52
- ...attachment.encoding === void 0 ? {} : { encoding: attachment.encoding },
53
- filename: attachment.filename,
54
- mimeType: attachment.mimeType
55
- };
56
- });
57
- return {
58
- attachments,
59
- authentication: parseAuthentication(headers["authentication-results"]),
60
- from,
61
- headers,
62
- ...parsed.html === void 0 ? {} : { html: parsed.html },
63
- ...safe("inReplyTo", parsed.inReplyTo) === void 0 ? {} : { inReplyTo: parsed.inReplyTo },
64
- ...safe("messageId", parsed.messageId) === void 0 ? {} : { messageId: parsed.messageId },
65
- ...safe("references", parsed.references) === void 0 ? {} : { references: parsed.references },
66
- ...safe("subject", parsed.subject) === void 0 ? {} : { subject: parsed.subject },
67
- ...parsed.text === void 0 ? {} : { text: parsed.text },
68
- to
69
- };
70
- };
71
-
72
- export { parseInboundEmail };
@@ -1,47 +0,0 @@
1
- import { t as toAddressList, c as toAddress } from './address-fkXxLKza.mjs';
2
-
3
- const reasonOf = (rawError) => {
4
- if (rawError instanceof Error) {
5
- return rawError.message;
6
- }
7
- if (rawError === null || rawError === void 0) {
8
- return "send failed";
9
- }
10
- if (typeof rawError === "string") {
11
- return rawError;
12
- }
13
- if (typeof rawError === "number" || typeof rawError === "boolean" || typeof rawError === "bigint") {
14
- return rawError.toString();
15
- }
16
- return JSON.stringify(rawError) ?? "send failed";
17
- };
18
- const requireRecipients = (to) => {
19
- const list = toAddressList(to);
20
- const [first] = list ?? [];
21
- if (!list || first === void 0) {
22
- throw new Error("@lunora/mail: at least one recipient is required");
23
- }
24
- return { first, list };
25
- };
26
- const toProviderEmail = (payload, defaultFrom, to) => {
27
- return {
28
- bcc: toAddressList(payload.bcc),
29
- cc: toAddressList(payload.cc),
30
- from: toAddress(payload.from ?? defaultFrom),
31
- headers: payload.headers,
32
- html: payload.html,
33
- replyTo: payload.replyTo ? toAddress(payload.replyTo) : void 0,
34
- subject: payload.subject,
35
- text: payload.text,
36
- to
37
- };
38
- };
39
- const interpretSendResult = (result) => {
40
- if (!result.success || !result.data) {
41
- console.error(`@lunora/mail: send failed: ${reasonOf(result.error)}`);
42
- throw new Error("@lunora/mail: send failed");
43
- }
44
- return { id: result.data.messageId };
45
- };
46
-
47
- export { interpretSendResult as i, requireRecipients as r, toProviderEmail as t };
@@ -1,8 +0,0 @@
1
- import { render } from '@react-email/render';
2
-
3
- const renderEmail = async (element) => {
4
- const [html, text] = await Promise.all([render(element, { pretty: false }), render(element, { plainText: true })]);
5
- return { html, text };
6
- };
7
-
8
- export { renderEmail as default };
@@ -1,13 +0,0 @@
1
- const applyJurisdiction = (namespace, jurisdiction) => {
2
- if (jurisdiction === void 0) {
3
- return namespace;
4
- }
5
- if (typeof namespace.jurisdiction !== "function") {
6
- throw new TypeError(
7
- `@lunora/mail: Durable Object namespace does not support jurisdiction("${jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`
8
- );
9
- }
10
- return namespace.jurisdiction(jurisdiction);
11
- };
12
-
13
- export { applyJurisdiction as a };
@@ -1,39 +0,0 @@
1
- /**
2
- * Structural projections of the `SHARD` Durable Object namespace + one shard
3
- * stub, shared by the inbound dispatcher. Mirrors the shapes the outbound dev
4
- * capture sink uses (`packages/mail/src/from-env.ts`) so inbound dispatch routes
5
- * a parsed message into a Lunora function over the exact same admin-RPC-over-shard
6
- * path — without importing any Cloudflare types into `@lunora/mail`.
7
- */
8
- /** Structural projection of one shard stub — only `fetch` returning something with `.json()`. */
9
- interface ShardStubLike {
10
- fetch: (input: string, init?: {
11
- body?: string;
12
- headers?: Record<string, string>;
13
- method?: string;
14
- }) => Promise<{
15
- json: () => Promise<unknown>;
16
- }>;
17
- }
18
- /**
19
- * Cloudflare Durable Object data-residency jurisdiction. Widening union —
20
- * Cloudflare adds values over time.
21
- * @see https://developers.cloudflare.com/durable-objects/reference/data-location/
22
- */
23
- type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
24
- /** Structural projection of the `SHARD` Durable Object namespace. */
25
- interface ShardNamespaceLike {
26
- get: (id: unknown) => ShardStubLike;
27
- idFromName: (name: string) => unknown;
28
- /**
29
- * Derive a jurisdiction-restricted subnamespace. Optional because older
30
- * workers-types releases (and test doubles) may not expose it.
31
- */
32
- jurisdiction?: (jurisdiction: DurableObjectJurisdiction) => ShardNamespaceLike;
33
- }
34
- /**
35
- * Return a jurisdiction-restricted view of `namespace`, or `namespace`
36
- * unchanged when no jurisdiction is configured. Fail-closed when the binding
37
- * lacks `.jurisdiction()` so a residency constraint is never silently dropped.
38
- */
39
- export { DurableObjectJurisdiction as D, ShardNamespaceLike as S, ShardStubLike as a };
@@ -1,39 +0,0 @@
1
- /**
2
- * Structural projections of the `SHARD` Durable Object namespace + one shard
3
- * stub, shared by the inbound dispatcher. Mirrors the shapes the outbound dev
4
- * capture sink uses (`packages/mail/src/from-env.ts`) so inbound dispatch routes
5
- * a parsed message into a Lunora function over the exact same admin-RPC-over-shard
6
- * path — without importing any Cloudflare types into `@lunora/mail`.
7
- */
8
- /** Structural projection of one shard stub — only `fetch` returning something with `.json()`. */
9
- interface ShardStubLike {
10
- fetch: (input: string, init?: {
11
- body?: string;
12
- headers?: Record<string, string>;
13
- method?: string;
14
- }) => Promise<{
15
- json: () => Promise<unknown>;
16
- }>;
17
- }
18
- /**
19
- * Cloudflare Durable Object data-residency jurisdiction. Widening union —
20
- * Cloudflare adds values over time.
21
- * @see https://developers.cloudflare.com/durable-objects/reference/data-location/
22
- */
23
- type DurableObjectJurisdiction = "eu" | "fedramp" | "us";
24
- /** Structural projection of the `SHARD` Durable Object namespace. */
25
- interface ShardNamespaceLike {
26
- get: (id: unknown) => ShardStubLike;
27
- idFromName: (name: string) => unknown;
28
- /**
29
- * Derive a jurisdiction-restricted subnamespace. Optional because older
30
- * workers-types releases (and test doubles) may not expose it.
31
- */
32
- jurisdiction?: (jurisdiction: DurableObjectJurisdiction) => ShardNamespaceLike;
33
- }
34
- /**
35
- * Return a jurisdiction-restricted view of `namespace`, or `namespace`
36
- * unchanged when no jurisdiction is configured. Fail-closed when the binding
37
- * lacks `.jurisdiction()` so a residency constraint is never silently dropped.
38
- */
39
- export { DurableObjectJurisdiction as D, ShardNamespaceLike as S, ShardStubLike as a };