@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
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { createCaptureTransport } from './createCaptureTransport-Crz_8822.mjs';
|
|
3
|
-
import createMailer from './createMailer-B4Z_Cgiu.mjs';
|
|
4
|
-
import { a as applyJurisdiction } from './shard-CJ-TvmfT.mjs';
|
|
5
|
-
|
|
6
|
-
const RECORD_MAIL_OP = "__lunora_admin__:recordMail";
|
|
7
|
-
const DEFAULT_ROOT_SHARD = "__root__";
|
|
8
|
-
const DEV_ENVIRONMENT_PATTERN = /^(?:dev(?:elopment)?|local(?:host)?|test)$/iu;
|
|
9
|
-
const ENVIRONMENT_VARS = ["CF_ENV", "ENVIRONMENT", "NODE_ENV", "WORKER_ENV"];
|
|
10
|
-
const requireStringEnv = (env, name) => {
|
|
11
|
-
const value = env[name];
|
|
12
|
-
if (typeof value !== "string" || value === "") {
|
|
13
|
-
throw new LunoraError("INTERNAL", `@lunora/mail: missing env var \`${name}\` — set it in .dev.vars (and \`wrangler secret put ${name}\` for secrets).`);
|
|
14
|
-
}
|
|
15
|
-
return value;
|
|
16
|
-
};
|
|
17
|
-
const shouldCaptureMail = (env) => {
|
|
18
|
-
const flag = env["LUNORA_MAIL_CAPTURE"];
|
|
19
|
-
if (typeof flag === "string") {
|
|
20
|
-
return flag === "1" || flag.toLowerCase() === "true";
|
|
21
|
-
}
|
|
22
|
-
return ENVIRONMENT_VARS.some((key) => {
|
|
23
|
-
const value = env[key];
|
|
24
|
-
return typeof value === "string" && DEV_ENVIRONMENT_PATTERN.test(value);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const createCaptureSink = (env, rootShard = DEFAULT_ROOT_SHARD, jurisdiction) => {
|
|
28
|
-
return {
|
|
29
|
-
record: async (mail) => {
|
|
30
|
-
const binding = env["SHARD"];
|
|
31
|
-
const adminToken = typeof env["LUNORA_ADMIN_TOKEN"] === "string" ? env["LUNORA_ADMIN_TOKEN"] : void 0;
|
|
32
|
-
if (binding === void 0 || adminToken === void 0) {
|
|
33
|
-
return { id: "uncaptured" };
|
|
34
|
-
}
|
|
35
|
-
const namespace = applyJurisdiction(binding, jurisdiction);
|
|
36
|
-
const stub = namespace.get(namespace.idFromName(rootShard));
|
|
37
|
-
const response = await stub.fetch("https://shard.internal/rpc", {
|
|
38
|
-
body: JSON.stringify({ args: mail, functionPath: RECORD_MAIL_OP }),
|
|
39
|
-
headers: { authorization: `Bearer ${adminToken}`, "content-type": "application/json" },
|
|
40
|
-
method: "POST"
|
|
41
|
-
});
|
|
42
|
-
const body = await response.json();
|
|
43
|
-
return { id: body.result?.id ?? "captured" };
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const createMailerFromEnv = (env, options = {}) => {
|
|
48
|
-
const from = requireStringEnv(env, "MAIL_FROM");
|
|
49
|
-
if (shouldCaptureMail(env)) {
|
|
50
|
-
return createMailer({ from, transport: createCaptureTransport(createCaptureSink(env, options.rootShard, options.jurisdiction)) });
|
|
51
|
-
}
|
|
52
|
-
if (options.cloudflareSend) {
|
|
53
|
-
return createMailer({ cloudflareSend: options.cloudflareSend, from });
|
|
54
|
-
}
|
|
55
|
-
const apiKey = typeof env["RESEND_API_KEY"] === "string" ? env["RESEND_API_KEY"] : void 0;
|
|
56
|
-
if (apiKey !== void 0 && apiKey !== "") {
|
|
57
|
-
return createMailer({ apiKey, from });
|
|
58
|
-
}
|
|
59
|
-
throw new LunoraError(
|
|
60
|
-
"INTERNAL",
|
|
61
|
-
"@lunora/mail: no transport configured — provide `cloudflareSend` (a SEND_EMAIL binding) or RESEND_API_KEY, or run in a dev environment to capture."
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export { createCaptureSink, createMailerFromEnv, shouldCaptureMail };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const CAPTURE_TRANSPORT_BRAND = /* @__PURE__ */ Symbol.for("@lunora/mail.captureTransport");
|
|
2
|
-
const isCaptureTransport = (transport) => transport[CAPTURE_TRANSPORT_BRAND] === true;
|
|
3
|
-
const createCaptureTransport = (sink) => {
|
|
4
|
-
const transport = {
|
|
5
|
-
[CAPTURE_TRANSPORT_BRAND]: true,
|
|
6
|
-
send: async (payload) => sink.record(payload)
|
|
7
|
-
};
|
|
8
|
-
return transport;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export { CAPTURE_TRANSPORT_BRAND, createCaptureTransport, isCaptureTransport };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { cloudflareEmailProvider } from '@visulima/email/providers/cloudflare-email';
|
|
3
|
-
import { r as requireRecipients, t as toProviderEmail, i as interpretSendResult } from './provider-transport-C0xHi3oy.mjs';
|
|
4
|
-
|
|
5
|
-
const createCloudflareTransport = (options) => {
|
|
6
|
-
const provider = cloudflareEmailProvider({ send: options.send });
|
|
7
|
-
return {
|
|
8
|
-
send: async (payload) => {
|
|
9
|
-
await provider.initialize();
|
|
10
|
-
const hasCc = payload.cc !== void 0 && payload.cc.length > 0;
|
|
11
|
-
const hasBcc = payload.bcc !== void 0 && payload.bcc.length > 0;
|
|
12
|
-
if (hasCc || hasBcc) {
|
|
13
|
-
throw new LunoraError("INTERNAL", "@lunora/mail: Cloudflare Email Workers does not support cc/bcc — fan out one send per recipient instead");
|
|
14
|
-
}
|
|
15
|
-
const { first, list } = requireRecipients(payload.to);
|
|
16
|
-
if (list.length > 1) {
|
|
17
|
-
throw new LunoraError(
|
|
18
|
-
"INTERNAL",
|
|
19
|
-
`@lunora/mail: Cloudflare Email Workers is single-recipient but received ${String(list.length)} \`to\` addresses — fan out one send per recipient instead`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
const result = await provider.sendEmail(toProviderEmail(payload, options.from, first));
|
|
23
|
-
return interpretSendResult(result);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { createCloudflareTransport };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { a as applyJurisdiction } from './shard-CJ-TvmfT.mjs';
|
|
3
|
-
|
|
4
|
-
const GENERIC_REJECT_REASON = "message could not be processed";
|
|
5
|
-
const rejectOnError = (error, context) => {
|
|
6
|
-
console.error("@lunora/mail/inbound: dropping message —", error);
|
|
7
|
-
context.message.setReject(GENERIC_REJECT_REASON);
|
|
8
|
-
};
|
|
9
|
-
const createInboundEmailHandler = (options) => {
|
|
10
|
-
const onError = options.onError ?? rejectOnError;
|
|
11
|
-
return async (message, env, context_) => {
|
|
12
|
-
const context = { ctx: context_, env, message };
|
|
13
|
-
try {
|
|
14
|
-
const parsed = await options.parse(message.raw);
|
|
15
|
-
if (options.verify) {
|
|
16
|
-
const verified = await options.verify(parsed, context);
|
|
17
|
-
if (verified === false) {
|
|
18
|
-
throw new LunoraError("INTERNAL", "@lunora/mail/inbound: sender verification rejected the message");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
await options.dispatch(parsed, context);
|
|
22
|
-
} catch (error) {
|
|
23
|
-
await onError(error, context);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const DEFAULT_ROOT_SHARD = "__root__";
|
|
28
|
-
const toBase64 = (bytes) => {
|
|
29
|
-
let binary = "";
|
|
30
|
-
for (const byte of bytes) {
|
|
31
|
-
binary += String.fromCodePoint(byte);
|
|
32
|
-
}
|
|
33
|
-
return btoa(binary);
|
|
34
|
-
};
|
|
35
|
-
const toJsonSafeEmail = (email) => {
|
|
36
|
-
if (email.attachments.length === 0) {
|
|
37
|
-
return email;
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
...email,
|
|
41
|
-
attachments: email.attachments.map((attachment) => {
|
|
42
|
-
const { content } = attachment;
|
|
43
|
-
if (typeof content === "string") {
|
|
44
|
-
return attachment;
|
|
45
|
-
}
|
|
46
|
-
const bytes = content instanceof Uint8Array ? content : new Uint8Array(content);
|
|
47
|
-
return { ...attachment, content: toBase64(bytes), encoding: "base64" };
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
const dispatchToLunoraFunction = (options) => {
|
|
52
|
-
const shardKey = options.shardKey ?? DEFAULT_ROOT_SHARD;
|
|
53
|
-
const resolveArgs = options.resolveArgs ?? ((email) => toJsonSafeEmail(email));
|
|
54
|
-
return async (email, context) => {
|
|
55
|
-
const adminToken = options.adminToken ?? (typeof context.env["LUNORA_ADMIN_TOKEN"] === "string" ? context.env["LUNORA_ADMIN_TOKEN"] : void 0);
|
|
56
|
-
if (adminToken === void 0 || adminToken === "") {
|
|
57
|
-
throw new LunoraError("INTERNAL", "@lunora/mail/inbound: missing LUNORA_ADMIN_TOKEN — cannot authorize inbound dispatch to the shard RPC.");
|
|
58
|
-
}
|
|
59
|
-
const envelope = {
|
|
60
|
-
args: resolveArgs(email, context),
|
|
61
|
-
functionPath: options.functionPath,
|
|
62
|
-
shardKey
|
|
63
|
-
};
|
|
64
|
-
const namespace = applyJurisdiction(options.shard, options.jurisdiction);
|
|
65
|
-
const stub = namespace.get(namespace.idFromName(shardKey));
|
|
66
|
-
const response = await stub.fetch("https://shard.internal/rpc", {
|
|
67
|
-
body: JSON.stringify(envelope),
|
|
68
|
-
headers: { authorization: `Bearer ${adminToken}`, "content-type": "application/json" },
|
|
69
|
-
method: "POST"
|
|
70
|
-
});
|
|
71
|
-
if (response.ok === false) {
|
|
72
|
-
throw new LunoraError("INTERNAL", `@lunora/mail/inbound: dispatch to \`${options.functionPath}\` failed (HTTP ${String(response.status ?? "?")}).`);
|
|
73
|
-
}
|
|
74
|
-
const body = await response.json();
|
|
75
|
-
if (typeof body === "object" && body !== null && "error" in body) {
|
|
76
|
-
const { error } = body;
|
|
77
|
-
if (error !== void 0 && error !== null) {
|
|
78
|
-
throw new LunoraError("INTERNAL", `@lunora/mail/inbound: dispatch to \`${options.functionPath}\` returned an error: ${JSON.stringify(error)}`);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export { createInboundEmailHandler, dispatchToLunoraFunction };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { a as assertSafeHeaderValue, b as assertSafeAddresses } from './address-vSUAVU2T.mjs';
|
|
3
|
-
import { isCaptureTransport } from './createCaptureTransport-Crz_8822.mjs';
|
|
4
|
-
import { createCloudflareTransport } from './createCloudflareTransport-DXh1nUNi.mjs';
|
|
5
|
-
import { toQueuedPayload } from './consumeQueuedSend-B9hTDOZ6.mjs';
|
|
6
|
-
import renderEmail from './renderEmail-hyS1bpVP.mjs';
|
|
7
|
-
import createResendTransport from './createResendTransport-CMQWjZoi.mjs';
|
|
8
|
-
|
|
9
|
-
const buildDefaultTransport = (options) => {
|
|
10
|
-
if (options.cloudflareSend) {
|
|
11
|
-
return createCloudflareTransport({ from: options.from, send: options.cloudflareSend });
|
|
12
|
-
}
|
|
13
|
-
if (options.apiKey) {
|
|
14
|
-
return createResendTransport(options.apiKey, options.from);
|
|
15
|
-
}
|
|
16
|
-
throw new LunoraError(
|
|
17
|
-
"INTERNAL",
|
|
18
|
-
"@lunora/mail: a transport is required — pass `transport`, `cloudflareSend` (Cloudflare Email Workers, the default), or `apiKey` (Resend)"
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
const createMailer = (options) => {
|
|
22
|
-
if (!options.from) {
|
|
23
|
-
throw new LunoraError("INTERNAL", "@lunora/mail: `from` is required");
|
|
24
|
-
}
|
|
25
|
-
const transport = options.transport ?? buildDefaultTransport(options);
|
|
26
|
-
const buildPayload = async (options_) => {
|
|
27
|
-
let { html } = options_;
|
|
28
|
-
let { text } = options_;
|
|
29
|
-
if (options_.react) {
|
|
30
|
-
const rendered = await renderEmail(options_.react);
|
|
31
|
-
html = html ?? rendered.html;
|
|
32
|
-
text = text ?? rendered.text;
|
|
33
|
-
}
|
|
34
|
-
assertSafeHeaderValue("subject", options_.subject);
|
|
35
|
-
if (options_.headers) {
|
|
36
|
-
for (const [name, value] of Object.entries(options_.headers)) {
|
|
37
|
-
assertSafeHeaderValue(`header name "${name}"`, name);
|
|
38
|
-
assertSafeHeaderValue(`header "${name}" value`, value);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const from = options_.from ?? options.from;
|
|
42
|
-
assertSafeAddresses({
|
|
43
|
-
bcc: options_.bcc,
|
|
44
|
-
cc: options_.cc,
|
|
45
|
-
from,
|
|
46
|
-
replyTo: options_.replyTo,
|
|
47
|
-
to: options_.to
|
|
48
|
-
});
|
|
49
|
-
return {
|
|
50
|
-
bcc: options_.bcc,
|
|
51
|
-
cc: options_.cc,
|
|
52
|
-
from,
|
|
53
|
-
headers: options_.headers,
|
|
54
|
-
html,
|
|
55
|
-
replyTo: options_.replyTo,
|
|
56
|
-
subject: options_.subject,
|
|
57
|
-
text,
|
|
58
|
-
to: options_.to
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
const send = async (options_) => {
|
|
62
|
-
const payload = await buildPayload(options_);
|
|
63
|
-
return transport.send(payload);
|
|
64
|
-
};
|
|
65
|
-
const queue = async (options_) => {
|
|
66
|
-
if (!options.queue) {
|
|
67
|
-
if (isCaptureTransport(transport)) {
|
|
68
|
-
const captured = await buildPayload(options_);
|
|
69
|
-
await transport.send(captured);
|
|
70
|
-
return { queued: true };
|
|
71
|
-
}
|
|
72
|
-
throw new LunoraError("INTERNAL", "@lunora/mail: `queue` binding is required for mailer.queue()");
|
|
73
|
-
}
|
|
74
|
-
const payload = await buildPayload(options_);
|
|
75
|
-
await options.queue.send(toQueuedPayload(payload));
|
|
76
|
-
return { queued: true };
|
|
77
|
-
};
|
|
78
|
-
return { queue, send };
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
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-C0xHi3oy.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-vSUAVU2T.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,48 +0,0 @@
|
|
|
1
|
-
import { LunoraError } from '@lunora/errors';
|
|
2
|
-
import { t as toAddressList, c as toAddress } from './address-vSUAVU2T.mjs';
|
|
3
|
-
|
|
4
|
-
const reasonOf = (rawError) => {
|
|
5
|
-
if (rawError instanceof Error) {
|
|
6
|
-
return rawError.message;
|
|
7
|
-
}
|
|
8
|
-
if (rawError === null || rawError === void 0) {
|
|
9
|
-
return "send failed";
|
|
10
|
-
}
|
|
11
|
-
if (typeof rawError === "string") {
|
|
12
|
-
return rawError;
|
|
13
|
-
}
|
|
14
|
-
if (typeof rawError === "number" || typeof rawError === "boolean" || typeof rawError === "bigint") {
|
|
15
|
-
return rawError.toString();
|
|
16
|
-
}
|
|
17
|
-
return JSON.stringify(rawError) ?? "send failed";
|
|
18
|
-
};
|
|
19
|
-
const requireRecipients = (to) => {
|
|
20
|
-
const list = toAddressList(to);
|
|
21
|
-
const [first] = list ?? [];
|
|
22
|
-
if (!list || first === void 0) {
|
|
23
|
-
throw new LunoraError("INTERNAL", "@lunora/mail: at least one recipient is required");
|
|
24
|
-
}
|
|
25
|
-
return { first, list };
|
|
26
|
-
};
|
|
27
|
-
const toProviderEmail = (payload, defaultFrom, to) => {
|
|
28
|
-
return {
|
|
29
|
-
bcc: toAddressList(payload.bcc),
|
|
30
|
-
cc: toAddressList(payload.cc),
|
|
31
|
-
from: toAddress(payload.from ?? defaultFrom),
|
|
32
|
-
headers: payload.headers,
|
|
33
|
-
html: payload.html,
|
|
34
|
-
replyTo: payload.replyTo ? toAddress(payload.replyTo) : void 0,
|
|
35
|
-
subject: payload.subject,
|
|
36
|
-
text: payload.text,
|
|
37
|
-
to
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const interpretSendResult = (result) => {
|
|
41
|
-
if (!result.success || !result.data) {
|
|
42
|
-
console.error(`@lunora/mail: send failed: ${reasonOf(result.error)}`);
|
|
43
|
-
throw new LunoraError("INTERNAL", "@lunora/mail: send failed");
|
|
44
|
-
}
|
|
45
|
-
return { id: result.data.messageId };
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
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 };
|