@drfed/drfed 0.0.0-stage → 0.1.0-dev.561
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 +661 -0
- package/README.md +1198 -2
- package/bin/drfed-account.mjs +20 -0
- package/bin/drfed-migrate.mjs +20 -0
- package/bin/drfed-server.mjs +20 -0
- package/bin/drfed-web.mjs +20 -0
- package/completions/bash/drfed-account +219 -0
- package/completions/bash/drfed-migrate +219 -0
- package/completions/bash/drfed-server +219 -0
- package/completions/bash/drfed-web +219 -0
- package/completions/fish/drfed-account.fish +264 -0
- package/completions/fish/drfed-migrate.fish +264 -0
- package/completions/fish/drfed-server.fish +264 -0
- package/completions/fish/drfed-web.fish +264 -0
- package/completions/nu/drfed-account.nu +293 -0
- package/completions/nu/drfed-migrate.nu +293 -0
- package/completions/nu/drfed-server.nu +293 -0
- package/completions/nu/drfed-web.nu +293 -0
- package/completions/pwsh/drfed-account.ps1 +183 -0
- package/completions/pwsh/drfed-migrate.ps1 +183 -0
- package/completions/pwsh/drfed-server.ps1 +183 -0
- package/completions/pwsh/drfed-web.ps1 +183 -0
- package/completions/zsh/_drfed-account +145 -0
- package/completions/zsh/_drfed-migrate +145 -0
- package/completions/zsh/_drfed-server +145 -0
- package/completions/zsh/_drfed-web +145 -0
- package/dist/api-mail-parser.d.mts +106 -0
- package/dist/api-mail-parser.d.mts.map +1 -0
- package/dist/api-mail-parser.mjs +145 -0
- package/dist/api-mail-parser.mjs.map +1 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts +142 -0
- package/dist/api-mail-settings-BcGaqQ9f.d.mts.map +1 -0
- package/dist/api-mail-settings.d.mts +2 -0
- package/dist/api-mail-settings.mjs +272 -0
- package/dist/api-mail-settings.mjs.map +1 -0
- package/dist/bounded-mail-runtime.d.mts +9 -0
- package/dist/bounded-mail-runtime.d.mts.map +1 -0
- package/dist/bounded-mail-runtime.mjs +66 -0
- package/dist/bounded-mail-runtime.mjs.map +1 -0
- package/dist/commands/account-create.d.mts +37 -0
- package/dist/commands/account-create.d.mts.map +1 -0
- package/dist/commands/account-create.mjs +87 -0
- package/dist/commands/account-create.mjs.map +1 -0
- package/dist/commands/account-program.d.mts +223 -0
- package/dist/commands/account-program.d.mts.map +1 -0
- package/dist/commands/account-program.mjs +116 -0
- package/dist/commands/account-program.mjs.map +1 -0
- package/dist/commands/account.d.mts +6 -0
- package/dist/commands/account.d.mts.map +1 -0
- package/dist/commands/account.mjs +91 -0
- package/dist/commands/account.mjs.map +1 -0
- package/dist/commands/migrate-program.d.mts +219 -0
- package/dist/commands/migrate-program.d.mts.map +1 -0
- package/dist/commands/migrate-program.mjs +116 -0
- package/dist/commands/migrate-program.mjs.map +1 -0
- package/dist/commands/migrate.d.mts +6 -0
- package/dist/commands/migrate.d.mts.map +1 -0
- package/dist/commands/migrate.mjs +85 -0
- package/dist/commands/migrate.mjs.map +1 -0
- package/dist/commands/web-program.d.mts +213 -0
- package/dist/commands/web-program.d.mts.map +1 -0
- package/dist/commands/web-program.mjs +112 -0
- package/dist/commands/web-program.mjs.map +1 -0
- package/dist/commands/web.d.mts +6 -0
- package/dist/commands/web.d.mts.map +1 -0
- package/dist/commands/web.mjs +184 -0
- package/dist/commands/web.mjs.map +1 -0
- package/dist/configuration-DVVF7xNv.d.mts +432 -0
- package/dist/configuration-DVVF7xNv.d.mts.map +1 -0
- package/dist/configuration.d.mts +2 -0
- package/dist/configuration.mjs +469 -0
- package/dist/configuration.mjs.map +1 -0
- package/dist/data-path.d.mts +9 -0
- package/dist/data-path.d.mts.map +1 -0
- package/dist/data-path.mjs +21 -0
- package/dist/data-path.mjs.map +1 -0
- package/dist/database-runtime.d.mts +26 -0
- package/dist/database-runtime.d.mts.map +1 -0
- package/dist/database-runtime.mjs +92 -0
- package/dist/database-runtime.mjs.map +1 -0
- package/dist/database-settings.d.mts +36 -0
- package/dist/database-settings.d.mts.map +1 -0
- package/dist/database-settings.mjs +67 -0
- package/dist/database-settings.mjs.map +1 -0
- package/dist/diagnostics.d.mts +29 -0
- package/dist/diagnostics.d.mts.map +1 -0
- package/dist/diagnostics.mjs +61 -0
- package/dist/diagnostics.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +344 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jmap-parser.d.mts +35 -0
- package/dist/jmap-parser.d.mts.map +1 -0
- package/dist/jmap-parser.mjs +42 -0
- package/dist/jmap-parser.mjs.map +1 -0
- package/dist/jmap-runtime.d.mts +10 -0
- package/dist/jmap-runtime.d.mts.map +1 -0
- package/dist/jmap-runtime.mjs +17 -0
- package/dist/jmap-runtime.mjs.map +1 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts +41 -0
- package/dist/jmap-settings-BXNAF1ep.d.mts.map +1 -0
- package/dist/jmap-settings.d.mts +2 -0
- package/dist/jmap-settings.mjs +104 -0
- package/dist/jmap-settings.mjs.map +1 -0
- package/dist/logging.d.mts +33 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +56 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/mail-parser-DyI4wuQp.d.mts +246 -0
- package/dist/mail-parser-DyI4wuQp.d.mts.map +1 -0
- package/dist/mail-parser.d.mts +2 -0
- package/dist/mail-parser.mjs +100 -0
- package/dist/mail-parser.mjs.map +1 -0
- package/dist/mail-runtime-YROIQ8up.mjs +314 -0
- package/dist/mail-runtime-YROIQ8up.mjs.map +1 -0
- package/dist/mail-runtime.d.mts +68 -0
- package/dist/mail-runtime.d.mts.map +1 -0
- package/dist/mail-runtime.mjs +2 -0
- package/dist/mail-settings-BD1TQ0rt.mjs +427 -0
- package/dist/mail-settings-BD1TQ0rt.mjs.map +1 -0
- package/dist/mail-settings-DjWMAUaE.d.mts +80 -0
- package/dist/mail-settings-DjWMAUaE.d.mts.map +1 -0
- package/dist/mail-settings.d.mts +2 -0
- package/dist/mail-settings.mjs +2 -0
- package/dist/operations.d.mts +32 -0
- package/dist/operations.d.mts.map +1 -0
- package/dist/operations.mjs +55 -0
- package/dist/operations.mjs.map +1 -0
- package/dist/package-D1pbtLwn.mjs +6 -0
- package/dist/package-D1pbtLwn.mjs.map +1 -0
- package/dist/parser-DGIQTgS7.mjs +178 -0
- package/dist/parser-DGIQTgS7.mjs.map +1 -0
- package/dist/parser-TANGHRjL.d.mts +305 -0
- package/dist/parser-TANGHRjL.d.mts.map +1 -0
- package/dist/postgres-settings.d.mts +20 -0
- package/dist/postgres-settings.d.mts.map +1 -0
- package/dist/postgres-settings.mjs +60 -0
- package/dist/postgres-settings.mjs.map +1 -0
- package/dist/query-logger.d.mts +9 -0
- package/dist/query-logger.d.mts.map +1 -0
- package/dist/query-logger.mjs +17 -0
- package/dist/query-logger.mjs.map +1 -0
- package/dist/resources.d.mts +20 -0
- package/dist/resources.d.mts.map +1 -0
- package/dist/resources.mjs +34 -0
- package/dist/resources.mjs.map +1 -0
- package/dist/secret-source-BeZx72Ue.d.mts +21 -0
- package/dist/secret-source-BeZx72Ue.d.mts.map +1 -0
- package/dist/secret-source.d.mts +2 -0
- package/dist/secret-source.mjs +58 -0
- package/dist/secret-source.mjs.map +1 -0
- package/dist/serving.d.mts +82 -0
- package/dist/serving.d.mts.map +1 -0
- package/dist/serving.mjs +138 -0
- package/dist/serving.mjs.map +1 -0
- package/dist/smtp-settings.d.mts +11 -0
- package/dist/smtp-settings.d.mts.map +1 -0
- package/dist/smtp-settings.mjs +38 -0
- package/dist/smtp-settings.mjs.map +1 -0
- package/dist/valueparser.d.mts +46 -0
- package/dist/valueparser.d.mts.map +1 -0
- package/dist/valueparser.mjs +121 -0
- package/dist/valueparser.mjs.map +1 -0
- package/package.json +287 -3
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { configurationBoolean, configurationProvenance, configurationSettings } from "./configuration.mjs";
|
|
2
|
+
import { resolveSecretSource } from "./secret-source.mjs";
|
|
3
|
+
import { resolveApiMailSettings } from "./api-mail-settings.mjs";
|
|
4
|
+
import { resolveJmapSettings } from "./jmap-settings.mjs";
|
|
5
|
+
import { resolveSmtpConnection } from "./smtp-settings.mjs";
|
|
6
|
+
import { url } from "@optique/core/valueparser";
|
|
7
|
+
//#region src/ses-settings.ts
|
|
8
|
+
const priority$1 = {
|
|
9
|
+
default: 0,
|
|
10
|
+
config: 1,
|
|
11
|
+
env: 2,
|
|
12
|
+
cli: 3
|
|
13
|
+
};
|
|
14
|
+
const rank$1 = (input) => input?.value === void 0 ? -1 : priority$1[input.source];
|
|
15
|
+
/** Validate credential bytes without including them in diagnostic errors. */
|
|
16
|
+
function validateSesCredential(value, kind) {
|
|
17
|
+
if (value === "" || /[^\x21-\x7e]/u.test(value) || kind === "access key ID" && !/^[A-Za-z0-9]{1,128}$/u.test(value)) throw new Error(`Invalid SES ${kind}.`);
|
|
18
|
+
}
|
|
19
|
+
function secret(literal, file, kind, cwd) {
|
|
20
|
+
const resolved = resolveSecretSource(literal, file, `SES ${kind}`, cwd);
|
|
21
|
+
if (resolved === void 0) throw new Error(`SES requires a ${kind}.`);
|
|
22
|
+
if (resolved.type === "literal") validateSesCredential(resolved.value, kind);
|
|
23
|
+
return resolved;
|
|
24
|
+
}
|
|
25
|
+
function authenticationMode(raw) {
|
|
26
|
+
const token = rank$1(raw.sesSessionToken) >= rank$1(raw.sesSessionTokenFile) ? raw.sesSessionToken : raw.sesSessionTokenFile;
|
|
27
|
+
if (rank$1(token) > rank$1(raw.sesAuth)) return {
|
|
28
|
+
type: "session",
|
|
29
|
+
source: token
|
|
30
|
+
};
|
|
31
|
+
const type = raw.sesAuth?.value ?? "credentials";
|
|
32
|
+
if (type !== "credentials" && type !== "session") throw new Error("Invalid SES authentication mode.");
|
|
33
|
+
return {
|
|
34
|
+
type,
|
|
35
|
+
source: raw.sesAuth
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/** Resolve the selected SES branch without resource acquisition.
|
|
39
|
+
* @returns Prepared meaning, effective source tags and redacted diagnostics.
|
|
40
|
+
*/
|
|
41
|
+
function resolveSesSettings(raw, cwd) {
|
|
42
|
+
const mode = authenticationMode(raw);
|
|
43
|
+
const accessKeyId = secret(raw.sesAccessKeyId, raw.sesAccessKeyIdFile, "access key ID", cwd);
|
|
44
|
+
const secretAccessKey = secret(raw.sesSecretAccessKey, raw.sesSecretAccessKeyFile, "secret access key", cwd);
|
|
45
|
+
const sessionToken = mode.type === "session" ? secret(raw.sesSessionToken, raw.sesSessionTokenFile, "session token", cwd) : void 0;
|
|
46
|
+
const region = raw.sesRegion?.value ?? "us-east-1";
|
|
47
|
+
if (region.length > 63 || !/^[a-z]{2}(?:-[a-z]+)+-[1-9]\d*$/u.test(region) || /^(?:cn-|us-iso|eu-isoe-)/u.test(region)) throw new Error("Invalid or unsupported SES region.");
|
|
48
|
+
const timeout = Number(raw.sesTimeout?.value ?? "30000");
|
|
49
|
+
if (!/^\d+$/u.test(raw.sesTimeout?.value ?? "30000") || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 2147483647) throw new Error("Invalid SES delivery timeout.");
|
|
50
|
+
const mail = {
|
|
51
|
+
transport: "ses",
|
|
52
|
+
connection: {
|
|
53
|
+
region,
|
|
54
|
+
timeout,
|
|
55
|
+
retries: 0,
|
|
56
|
+
validateSsl: true
|
|
57
|
+
},
|
|
58
|
+
authentication: mode.type === "session" ? {
|
|
59
|
+
type: mode.type,
|
|
60
|
+
accessKeyId,
|
|
61
|
+
secretAccessKey,
|
|
62
|
+
sessionToken
|
|
63
|
+
} : {
|
|
64
|
+
type: mode.type,
|
|
65
|
+
accessKeyId,
|
|
66
|
+
secretAccessKey
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const selected = (literal, file) => rank$1(literal) >= rank$1(file) ? [literal, void 0] : [void 0, file];
|
|
70
|
+
const access = selected(raw.sesAccessKeyId, raw.sesAccessKeyIdFile);
|
|
71
|
+
const secretKey = selected(raw.sesSecretAccessKey, raw.sesSecretAccessKeyFile);
|
|
72
|
+
const token = mode.type === "session" ? selected(raw.sesSessionToken, raw.sesSessionTokenFile) : [void 0, void 0];
|
|
73
|
+
return {
|
|
74
|
+
mail,
|
|
75
|
+
sources: {
|
|
76
|
+
sesAuth: mode.source,
|
|
77
|
+
sesAccessKeyId: access[0],
|
|
78
|
+
sesAccessKeyIdFile: access[1],
|
|
79
|
+
sesSecretAccessKey: secretKey[0],
|
|
80
|
+
sesSecretAccessKeyFile: secretKey[1],
|
|
81
|
+
sesSessionToken: token[0],
|
|
82
|
+
sesSessionTokenFile: token[1]
|
|
83
|
+
},
|
|
84
|
+
values: {
|
|
85
|
+
sesAuth: mode.type,
|
|
86
|
+
sesRegion: region,
|
|
87
|
+
sesTimeout: timeout
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/mail-settings.ts
|
|
93
|
+
const priority = {
|
|
94
|
+
default: 0,
|
|
95
|
+
config: 1,
|
|
96
|
+
env: 2,
|
|
97
|
+
cli: 3
|
|
98
|
+
};
|
|
99
|
+
const rank = (value) => value?.value === void 0 ? -1 : priority[value.source];
|
|
100
|
+
function isMailTransport(value) {
|
|
101
|
+
return [
|
|
102
|
+
"logtape",
|
|
103
|
+
"smtp",
|
|
104
|
+
"jmap",
|
|
105
|
+
"lettermint",
|
|
106
|
+
"maileroo",
|
|
107
|
+
"mailtrap",
|
|
108
|
+
"mailgun",
|
|
109
|
+
"sendgrid",
|
|
110
|
+
"ses",
|
|
111
|
+
"resend",
|
|
112
|
+
"plunk"
|
|
113
|
+
].includes(value);
|
|
114
|
+
}
|
|
115
|
+
function selectTransport(raw) {
|
|
116
|
+
const highest = Math.max(rank(raw.mailTransport), rank(raw.smtpUrl), rank(raw.smtpHost), rank(raw.jmapSessionUrl));
|
|
117
|
+
const explicit = rank(raw.mailTransport) === highest ? raw.mailTransport?.value : void 0;
|
|
118
|
+
const smtp = rank(raw.smtpUrl) === highest || rank(raw.smtpHost) === highest;
|
|
119
|
+
const jmap = rank(raw.jmapSessionUrl) === highest && highest >= 0;
|
|
120
|
+
const transport = explicit ?? (jmap ? "jmap" : smtp && highest >= 0 ? "smtp" : "logtape");
|
|
121
|
+
if (!isMailTransport(transport)) throw new Error("Unsupported mail transport; expected logtape, smtp, jmap, lettermint, maileroo, mailtrap, mailgun, plunk, resend, sendgrid or ses.");
|
|
122
|
+
if (smtp && highest >= 0 && transport !== "smtp" || jmap && transport !== "jmap") throw new Error("Mail selectors at the same source disagree.");
|
|
123
|
+
return {
|
|
124
|
+
transport,
|
|
125
|
+
selector: [
|
|
126
|
+
raw.mailTransport,
|
|
127
|
+
raw.smtpUrl,
|
|
128
|
+
raw.smtpHost,
|
|
129
|
+
raw.jmapSessionUrl
|
|
130
|
+
].find((value) => rank(value) === highest && value?.value !== void 0)
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function component(explicit, inherited, field) {
|
|
134
|
+
if (rank(explicit) === rank(inherited) && rank(explicit) >= 0) throw new Error(`Duplicate SMTP setting for ${field} at the same source.`);
|
|
135
|
+
return rank(explicit) > rank(inherited) ? explicit : inherited;
|
|
136
|
+
}
|
|
137
|
+
function boundedNumber(value, fallback, maximum, field) {
|
|
138
|
+
if (value?.value === void 0) return fallback;
|
|
139
|
+
const number = Number(value.value);
|
|
140
|
+
if (!/^\d+$/u.test(value.value) || !Number.isSafeInteger(number) || number < 1 || number > maximum) throw new Error(`Invalid SMTP setting for ${field}.`);
|
|
141
|
+
return number;
|
|
142
|
+
}
|
|
143
|
+
function extractUriPort(value) {
|
|
144
|
+
const scheme = /^smtps?:\/\//iu.exec(value)?.[0];
|
|
145
|
+
if (scheme === void 0 || /[\r\n\u2028\u2029]/u.test(value)) throw new Error("Invalid SMTP connection URL.");
|
|
146
|
+
const remainder = value.slice(scheme.length);
|
|
147
|
+
const delimiter = remainder.search(/[/?#]/u);
|
|
148
|
+
const authority = delimiter < 0 ? remainder : remainder.slice(0, delimiter);
|
|
149
|
+
const tail = delimiter < 0 ? "" : remainder.slice(delimiter);
|
|
150
|
+
const portComponent = /:(?<port>\d*)$/u.exec(authority);
|
|
151
|
+
const port = portComponent?.groups?.port;
|
|
152
|
+
return {
|
|
153
|
+
url: `${scheme}${portComponent === null ? authority : authority.slice(0, -portComponent[0].length)}${tail}`,
|
|
154
|
+
port
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function urlComponents(raw) {
|
|
158
|
+
const source = raw.smtpUrl;
|
|
159
|
+
if (source?.value === void 0) return {};
|
|
160
|
+
const extracted = extractUriPort(source.value);
|
|
161
|
+
const rawPort = extracted.port;
|
|
162
|
+
const parsed = url({ allowedProtocols: ["smtp:", "smtps:"] }).parse(extracted.url);
|
|
163
|
+
if (!parsed.success) throw new Error("Invalid SMTP connection URL.");
|
|
164
|
+
const original = parsed.value;
|
|
165
|
+
if (!/^smtps?:\/\//u.test(original.href) || original.port !== "" || original.pathname !== "" && original.pathname !== "/" || original.search !== "" || original.hash !== "") throw new Error("Invalid SMTP connection URL.");
|
|
166
|
+
const secure = original.protocol === "smtps:";
|
|
167
|
+
const inherit = (value) => ({
|
|
168
|
+
...source,
|
|
169
|
+
value
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
host: inherit(original.hostname),
|
|
173
|
+
port: inherit(rawPort === void 0 || rawPort === "" ? secure ? "465" : "587" : rawPort),
|
|
174
|
+
tls: inherit(secure ? "direct" : "opportunistic"),
|
|
175
|
+
...original.username === "" ? {} : { user: inherit(original.username) },
|
|
176
|
+
...original.password === "" ? {} : { password: inherit(original.password) }
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function decodedComponent(explicit, inherited, field) {
|
|
180
|
+
const selected = component(explicit, inherited, field);
|
|
181
|
+
if (selected === void 0 || selected !== inherited || selected.value === void 0) return selected;
|
|
182
|
+
try {
|
|
183
|
+
return {
|
|
184
|
+
...selected,
|
|
185
|
+
value: decodeURIComponent(selected.value)
|
|
186
|
+
};
|
|
187
|
+
} catch {
|
|
188
|
+
throw new Error(`Invalid SMTP setting for ${field}.`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** Validate the password API's currently supported encoding without secret errors. */
|
|
192
|
+
function validateSmtpPassword(user, password) {
|
|
193
|
+
if (user === "" || /[^\x20-\x7e]/u.test(user) || /[^\x20-\x7e]/u.test(password)) throw new Error("Invalid SMTP password authentication settings.");
|
|
194
|
+
}
|
|
195
|
+
/** Validate static OAuth authentication without exposing tokens in errors. */
|
|
196
|
+
function validateSmtpOAuth(user, token) {
|
|
197
|
+
if (user === "" || token === "" || /[^\x21-\x7e]/u.test(token) || /\p{Cc}/u.test(user)) throw new Error("Invalid SMTP OAuth authentication settings.");
|
|
198
|
+
}
|
|
199
|
+
function authenticationMethod(input, passwordSelected, selectedRank) {
|
|
200
|
+
let method = input?.value;
|
|
201
|
+
const methods = passwordSelected ? ["plain", "login"] : ["xoauth2", "oauthbearer"];
|
|
202
|
+
if (method !== void 0 && !methods.includes(method) && [
|
|
203
|
+
"plain",
|
|
204
|
+
"login",
|
|
205
|
+
"xoauth2",
|
|
206
|
+
"oauthbearer"
|
|
207
|
+
].includes(method) && rank(input) < selectedRank) method = void 0;
|
|
208
|
+
if (method !== void 0 && !methods.includes(method)) throw new Error("Invalid SMTP authentication method.");
|
|
209
|
+
return {
|
|
210
|
+
value: method ?? (passwordSelected ? "plain" : "xoauth2"),
|
|
211
|
+
source: method === void 0 ? "default" : input?.source ?? "default",
|
|
212
|
+
...method === void 0 || input?.configPath === void 0 ? {} : { configPath: input.configPath }
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function authenticationSources(raw, user, password, passwordSelected) {
|
|
216
|
+
const literalPassword = passwordSelected && rank(password) > rank(raw.smtpPasswordFile);
|
|
217
|
+
const literalToken = !passwordSelected && rank(raw.smtpAccessToken) > rank(raw.smtpAccessTokenFile);
|
|
218
|
+
return {
|
|
219
|
+
smtpUser: user,
|
|
220
|
+
smtpPassword: literalPassword ? password : void 0,
|
|
221
|
+
smtpPasswordFile: passwordSelected && !literalPassword ? raw.smtpPasswordFile : void 0,
|
|
222
|
+
smtpAccessToken: literalToken ? raw.smtpAccessToken : void 0,
|
|
223
|
+
smtpAccessTokenFile: !passwordSelected && !literalToken ? raw.smtpAccessTokenFile : void 0
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function validateLiteralCredential(passwordSelected, user, secret) {
|
|
227
|
+
if (secret.type !== "literal") return;
|
|
228
|
+
if (passwordSelected) validateSmtpPassword(user, secret.value);
|
|
229
|
+
else validateSmtpOAuth(user, secret.value);
|
|
230
|
+
}
|
|
231
|
+
function authentication(raw, inherited, cwd) {
|
|
232
|
+
const user = decodedComponent(raw.smtpUser, inherited.user, "user");
|
|
233
|
+
let password;
|
|
234
|
+
const passwordRank = Math.max(rank(raw.smtpPassword), rank(inherited.password), rank(raw.smtpPasswordFile));
|
|
235
|
+
const tokenRank = Math.max(rank(raw.smtpAccessToken), rank(raw.smtpAccessTokenFile));
|
|
236
|
+
if (passwordRank < 0 && tokenRank < 0) {
|
|
237
|
+
if (user?.value !== void 0 || raw.smtpAuthMethod?.value !== void 0) throw new Error("SMTP authentication requires a password or access token.");
|
|
238
|
+
return {
|
|
239
|
+
auth: void 0,
|
|
240
|
+
sources: { smtpUser: user }
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (passwordRank === tokenRank) throw new Error("SMTP authentication variants at the same source disagree.");
|
|
244
|
+
if (user?.value === void 0 || user.value === "") throw new Error("SMTP authentication requires a username.");
|
|
245
|
+
const passwordSelected = passwordRank > tokenRank;
|
|
246
|
+
if (passwordSelected && rank(raw.smtpPasswordFile) <= Math.max(rank(raw.smtpPassword), rank(inherited.password))) password = component(raw.smtpPassword, inherited.password, "password");
|
|
247
|
+
if (passwordSelected && rank(password) >= rank(raw.smtpPasswordFile)) password = decodedComponent(raw.smtpPassword, inherited.password, "password");
|
|
248
|
+
const secret = passwordSelected ? resolveSecretSource(password, raw.smtpPasswordFile, "SMTP password", cwd) : resolveSecretSource(raw.smtpAccessToken, raw.smtpAccessTokenFile, "SMTP access token", cwd);
|
|
249
|
+
if (secret === void 0) throw new Error("Missing SMTP credential.");
|
|
250
|
+
const method = authenticationMethod(raw.smtpAuthMethod, passwordSelected, Math.max(passwordRank, tokenRank));
|
|
251
|
+
validateLiteralCredential(passwordSelected, user.value, secret);
|
|
252
|
+
return {
|
|
253
|
+
auth: passwordSelected ? {
|
|
254
|
+
type: "password",
|
|
255
|
+
user: user.value,
|
|
256
|
+
secret,
|
|
257
|
+
method: method.value
|
|
258
|
+
} : {
|
|
259
|
+
type: "oauth2",
|
|
260
|
+
user: user.value,
|
|
261
|
+
secret,
|
|
262
|
+
method: method.value
|
|
263
|
+
},
|
|
264
|
+
sources: {
|
|
265
|
+
...authenticationSources(raw, user, password, passwordSelected),
|
|
266
|
+
smtpAuthMethod: method
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
function tlsMode(tls, explicit, auth) {
|
|
271
|
+
let mode = tls?.value ?? "starttls-required";
|
|
272
|
+
if (![
|
|
273
|
+
"direct",
|
|
274
|
+
"starttls-required",
|
|
275
|
+
"opportunistic"
|
|
276
|
+
].includes(mode)) throw new Error("Invalid SMTP TLS mode.");
|
|
277
|
+
if (auth !== void 0 && mode === "opportunistic") {
|
|
278
|
+
if (tls === explicit && explicit?.value !== void 0) throw new Error("SMTP authentication requires direct TLS or mandatory STARTTLS.");
|
|
279
|
+
mode = "starttls-required";
|
|
280
|
+
}
|
|
281
|
+
return mode;
|
|
282
|
+
}
|
|
283
|
+
function smtpSettings(raw, cwd) {
|
|
284
|
+
const inherited = urlComponents(raw);
|
|
285
|
+
const host = component(raw.smtpHost, inherited.host, "host");
|
|
286
|
+
const port = component(raw.smtpPort, inherited.port, "port");
|
|
287
|
+
const tls = component(raw.smtpTls, inherited.tls, "tls");
|
|
288
|
+
if (host?.value === void 0 || host.value === "") throw new Error("SMTP transport requires a host or SMTP URL.");
|
|
289
|
+
const selected = authentication(raw, inherited, cwd);
|
|
290
|
+
const mode = tlsMode(tls, raw.smtpTls, selected.auth);
|
|
291
|
+
let normalized;
|
|
292
|
+
try {
|
|
293
|
+
const authority = host.value.includes(":") && !host.value.startsWith("[") ? `[${host.value}]` : host.value;
|
|
294
|
+
normalized = resolveSmtpConnection(new URL(`${mode === "direct" ? "smtps" : "smtp"}://${authority}:${boundedNumber(port, mode === "direct" ? 465 : 587, 65535, "port")}`));
|
|
295
|
+
} catch {
|
|
296
|
+
throw new Error("Invalid SMTP host or port.");
|
|
297
|
+
}
|
|
298
|
+
if (raw.smtpLocalName?.value !== void 0 && !/^(?:[A-Za-z0-9.-]+|\[[0-9A-Fa-f:.]+\])$/u.test(raw.smtpLocalName.value)) throw new Error("Invalid SMTP local name.");
|
|
299
|
+
const cert = resolveSecretSource(void 0, raw.smtpCertFile, "SMTP client certificate", cwd);
|
|
300
|
+
const key = resolveSecretSource(void 0, raw.smtpKeyFile, "SMTP client key", cwd);
|
|
301
|
+
if (cert === void 0 !== (key === void 0)) throw new Error("SMTP client certificate and key must be configured together.");
|
|
302
|
+
return {
|
|
303
|
+
mail: {
|
|
304
|
+
transport: "smtp",
|
|
305
|
+
connection: {
|
|
306
|
+
host: normalized.host,
|
|
307
|
+
port: normalized.port ?? (mode === "direct" ? 465 : 587),
|
|
308
|
+
secure: mode === "direct",
|
|
309
|
+
requireTls: mode === "starttls-required",
|
|
310
|
+
connectionTimeout: boundedNumber(raw.smtpConnectionTimeout, 3e4, 2147483647, "connection timeout"),
|
|
311
|
+
socketTimeout: boundedNumber(raw.smtpSocketTimeout, 3e4, 2147483647, "socket timeout"),
|
|
312
|
+
poolSize: boundedNumber(raw.smtpPoolSize, 5, 2147483647, "pool size"),
|
|
313
|
+
...raw.smtpLocalName?.value === void 0 ? {} : { localName: raw.smtpLocalName.value }
|
|
314
|
+
},
|
|
315
|
+
authentication: selected.auth,
|
|
316
|
+
files: {
|
|
317
|
+
ca: resolveSecretSource(void 0, raw.smtpCaFile, "SMTP certificate authorities", cwd),
|
|
318
|
+
cert,
|
|
319
|
+
key
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
mode,
|
|
323
|
+
sources: {
|
|
324
|
+
...raw,
|
|
325
|
+
smtpHost: host,
|
|
326
|
+
smtpPort: port,
|
|
327
|
+
smtpTls: tls,
|
|
328
|
+
...selected.sources
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
function logContent(raw) {
|
|
333
|
+
const parsed = configurationBoolean().parse(raw.mailLogContent?.value ?? "false");
|
|
334
|
+
if (!parsed.success) throw new Error("Invalid mail.log_content setting.");
|
|
335
|
+
return parsed.value;
|
|
336
|
+
}
|
|
337
|
+
function selectedMailSettings(transport, raw, cwd) {
|
|
338
|
+
if (transport === "ses") return resolveSesSettings(raw, cwd);
|
|
339
|
+
if (transport === "lettermint" || transport === "maileroo" || transport === "mailtrap" || transport === "mailgun" || transport === "plunk" || transport === "resend" || transport === "sendgrid") return resolveApiMailSettings(raw, cwd, transport);
|
|
340
|
+
if (transport === "jmap") return resolveJmapSettings(raw, cwd);
|
|
341
|
+
if (transport === "logtape") {
|
|
342
|
+
const logContentValue = logContent(raw);
|
|
343
|
+
return {
|
|
344
|
+
mail: {
|
|
345
|
+
transport,
|
|
346
|
+
logContent: logContentValue
|
|
347
|
+
},
|
|
348
|
+
sources: {},
|
|
349
|
+
values: { mailLogContent: logContentValue }
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
const smtp = smtpSettings(raw, cwd);
|
|
353
|
+
const { mail } = smtp;
|
|
354
|
+
return {
|
|
355
|
+
mail,
|
|
356
|
+
sources: smtp.sources,
|
|
357
|
+
values: {
|
|
358
|
+
smtpHost: mail.connection.host,
|
|
359
|
+
smtpPort: mail.connection.port,
|
|
360
|
+
smtpTls: smtp.mode,
|
|
361
|
+
smtpConnectionTimeout: mail.connection.connectionTimeout,
|
|
362
|
+
smtpSocketTimeout: mail.connection.socketTimeout,
|
|
363
|
+
smtpPoolSize: mail.connection.poolSize,
|
|
364
|
+
smtpLocalName: mail.connection.localName,
|
|
365
|
+
smtpAuthMethod: mail.authentication?.method
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function secretFieldForTransport(key, transport) {
|
|
370
|
+
if (key.startsWith(transport)) return true;
|
|
371
|
+
return (transport === "lettermint" || transport === "maileroo" || transport === "mailtrap" || transport === "mailgun" || transport === "plunk" || transport === "resend" || transport === "sendgrid") && (key === "mailApiKey" || key === "mailApiKeyFile");
|
|
372
|
+
}
|
|
373
|
+
function ignoredMailField(key, provider, sources) {
|
|
374
|
+
if (key === "mailLogContent") return provider !== "logtape";
|
|
375
|
+
if (key === "mailApiKey" || key === "mailApiKeyFile") return provider !== "lettermint" && provider !== "maileroo" && provider !== "mailtrap" && provider !== "mailgun" && provider !== "plunk" && provider !== "resend" && provider !== "sendgrid" || sources[key]?.value === void 0;
|
|
376
|
+
const branch = [
|
|
377
|
+
"smtp",
|
|
378
|
+
"jmap",
|
|
379
|
+
"lettermint",
|
|
380
|
+
"maileroo",
|
|
381
|
+
"mailtrap",
|
|
382
|
+
"mailgun",
|
|
383
|
+
"sendgrid",
|
|
384
|
+
"ses",
|
|
385
|
+
"resend",
|
|
386
|
+
"plunk"
|
|
387
|
+
].find((name) => key.startsWith(name));
|
|
388
|
+
if (branch === void 0) return false;
|
|
389
|
+
if (branch !== provider) return true;
|
|
390
|
+
if (key === "smtpAuthMethod" && sources[key]?.source === "default") return true;
|
|
391
|
+
return key in sources && sources[key]?.value === void 0;
|
|
392
|
+
}
|
|
393
|
+
/** Resolve provider selection and safe diagnostics without reading credentials.
|
|
394
|
+
* @returns Runtime settings, redacted diagnostics and ignored branch metadata.
|
|
395
|
+
*/
|
|
396
|
+
function resolveMailSettings(raw, cwd = process.cwd()) {
|
|
397
|
+
const selection = selectTransport(raw);
|
|
398
|
+
const resolved = selectedMailSettings(selection.transport, raw, cwd);
|
|
399
|
+
const { mail, sources: activeSources } = resolved;
|
|
400
|
+
const provenance = configurationProvenance({
|
|
401
|
+
...raw,
|
|
402
|
+
...activeSources,
|
|
403
|
+
mailTransport: selection.selector
|
|
404
|
+
});
|
|
405
|
+
const values = {
|
|
406
|
+
mailTransport: mail.transport,
|
|
407
|
+
...resolved.values
|
|
408
|
+
};
|
|
409
|
+
for (const [key, value] of Object.entries(activeSources)) if (secretFieldForTransport(key, mail.transport) && value?.value !== void 0 && configurationSettings[key].secret) values[key] = "<redacted>";
|
|
410
|
+
const ignored = Object.entries(raw).filter(([key, value]) => value?.value !== void 0 && value.source !== "default" && ignoredMailField(key, mail.transport, activeSources)).map(([key, value]) => ({
|
|
411
|
+
field: configurationSettings[key].toml,
|
|
412
|
+
source: value?.source ?? "default"
|
|
413
|
+
}));
|
|
414
|
+
return {
|
|
415
|
+
mail,
|
|
416
|
+
diagnostic: Object.fromEntries(Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => [configurationSettings[key].toml, {
|
|
417
|
+
value,
|
|
418
|
+
...provenance[key] ?? { source: "default" }
|
|
419
|
+
}])),
|
|
420
|
+
ignored,
|
|
421
|
+
provenance
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
//#endregion
|
|
425
|
+
export { validateSesCredential as i, validateSmtpOAuth as n, validateSmtpPassword as r, resolveMailSettings as t };
|
|
426
|
+
|
|
427
|
+
//# sourceMappingURL=mail-settings-BD1TQ0rt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mail-settings-BD1TQ0rt.mjs","names":["priority","rank"],"sources":["../src/ses-settings.ts","../src/mail-settings.ts"],"sourcesContent":["// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport type { SesConfig } from \"@upyo/ses\";\n\nimport type { Sourced } from \"./configuration.ts\";\nimport type { RawMailOptions } from \"./mail-parser.ts\";\nimport { type SecretSource, resolveSecretSource } from \"./secret-source.ts\";\n\ntype Input = Sourced<string | undefined> | undefined;\nconst priority = { default: 0, config: 1, env: 2, cli: 3 } as const;\nconst rank = (input: Input) =>\n input?.value === undefined ? -1 : priority[input.source];\n\n/** SES connection settings before selected credential files are opened. */\nexport interface SesMailSettings {\n readonly transport: \"ses\";\n readonly connection: Omit<\n SesConfig,\n \"authentication\" | \"headers\" | \"defaultTags\" | \"batchSize\"\n >;\n readonly authentication: {\n readonly accessKeyId: SecretSource;\n readonly secretAccessKey: SecretSource;\n } & (\n | { readonly type: \"credentials\" }\n | { readonly type: \"session\"; readonly sessionToken: SecretSource }\n );\n}\n\n/** Validate credential bytes without including them in diagnostic errors. */\nexport function validateSesCredential(\n value: string,\n kind: \"access key ID\" | \"secret access key\" | \"session token\",\n) {\n if (\n value === \"\" ||\n /[^\\x21-\\x7e]/u.test(value) ||\n (kind === \"access key ID\" && !/^[A-Za-z0-9]{1,128}$/u.test(value))\n ) {\n throw new Error(`Invalid SES ${kind}.`);\n }\n}\n\nfunction secret(\n literal: Input,\n file: Input,\n kind: Parameters<typeof validateSesCredential>[1],\n cwd: string,\n) {\n const resolved = resolveSecretSource(literal, file, `SES ${kind}`, cwd);\n if (resolved === undefined) throw new Error(`SES requires a ${kind}.`);\n if (resolved.type === \"literal\") validateSesCredential(resolved.value, kind);\n return resolved;\n}\n\nfunction authenticationMode(raw: RawMailOptions): {\n type: \"credentials\" | \"session\";\n source: Input;\n} {\n const token =\n rank(raw.sesSessionToken) >= rank(raw.sesSessionTokenFile)\n ? raw.sesSessionToken\n : raw.sesSessionTokenFile;\n if (rank(token) > rank(raw.sesAuth)) {\n return { type: \"session\" as const, source: token };\n }\n const type = raw.sesAuth?.value ?? \"credentials\";\n if (type !== \"credentials\" && type !== \"session\") {\n throw new Error(\"Invalid SES authentication mode.\");\n }\n return { type, source: raw.sesAuth };\n}\n\n/** Resolve the selected SES branch without resource acquisition.\n * @returns Prepared meaning, effective source tags and redacted diagnostics.\n */\nexport function resolveSesSettings(raw: RawMailOptions, cwd: string) {\n const mode = authenticationMode(raw);\n const accessKeyId = secret(\n raw.sesAccessKeyId,\n raw.sesAccessKeyIdFile,\n \"access key ID\",\n cwd,\n );\n const secretAccessKey = secret(\n raw.sesSecretAccessKey,\n raw.sesSecretAccessKeyFile,\n \"secret access key\",\n cwd,\n );\n const sessionToken =\n mode.type === \"session\"\n ? secret(\n raw.sesSessionToken,\n raw.sesSessionTokenFile,\n \"session token\",\n cwd,\n )\n : undefined;\n const region = raw.sesRegion?.value ?? \"us-east-1\";\n if (\n region.length > 63 ||\n !/^[a-z]{2}(?:-[a-z]+)+-[1-9]\\d*$/u.test(region) ||\n /^(?:cn-|us-iso|eu-isoe-)/u.test(region)\n ) {\n throw new Error(\"Invalid or unsupported SES region.\");\n }\n const timeout = Number(raw.sesTimeout?.value ?? \"30000\");\n if (\n !/^\\d+$/u.test(raw.sesTimeout?.value ?? \"30000\") ||\n !Number.isSafeInteger(timeout) ||\n timeout < 1 ||\n timeout > 2147483647\n ) {\n throw new Error(\"Invalid SES delivery timeout.\");\n }\n const mail: SesMailSettings = {\n transport: \"ses\",\n connection: { region, timeout, retries: 0, validateSsl: true },\n authentication:\n mode.type === \"session\"\n ? {\n type: mode.type,\n accessKeyId,\n secretAccessKey,\n sessionToken: sessionToken!,\n }\n : { type: mode.type, accessKeyId, secretAccessKey },\n };\n const selected = (literal: Input, file: Input) =>\n rank(literal) >= rank(file) ? [literal, undefined] : [undefined, file];\n const access = selected(raw.sesAccessKeyId, raw.sesAccessKeyIdFile);\n const secretKey = selected(\n raw.sesSecretAccessKey,\n raw.sesSecretAccessKeyFile,\n );\n const token =\n mode.type === \"session\"\n ? selected(raw.sesSessionToken, raw.sesSessionTokenFile)\n : [undefined, undefined];\n return {\n mail,\n sources: {\n sesAuth: mode.source,\n sesAccessKeyId: access[0],\n sesAccessKeyIdFile: access[1],\n sesSecretAccessKey: secretKey[0],\n sesSecretAccessKeyFile: secretKey[1],\n sesSessionToken: token[0],\n sesSessionTokenFile: token[1],\n },\n values: { sesAuth: mode.type, sesRegion: region, sesTimeout: timeout },\n };\n}\n","// DrFed: A web-based platform for developing and debugging ActivityPub apps\n// Copyright (C) 2026 DrFed team\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program. If not, see <https://www.gnu.org/licenses/>.\n\nimport { url } from \"@optique/core/valueparser\";\nimport type { SmtpConfig } from \"@upyo/smtp\";\n\nimport {\n type ApiMailSettings,\n resolveApiMailSettings,\n} from \"./api-mail-settings.ts\";\nimport {\n type Sourced,\n configurationBoolean,\n configurationProvenance,\n configurationSettings,\n} from \"./configuration.ts\";\nimport { type JmapSettings, resolveJmapSettings } from \"./jmap-settings.ts\";\nimport type { RawMailOptions } from \"./mail-parser.ts\";\nimport { type SecretSource, resolveSecretSource } from \"./secret-source.ts\";\nimport { type SesMailSettings, resolveSesSettings } from \"./ses-settings.ts\";\nimport { resolveSmtpConnection } from \"./smtp-settings.ts\";\n\n/** SMTP authentication selected before credential files are read. */\nexport type MailAuthentication =\n | {\n readonly type: \"password\";\n readonly user: string;\n readonly secret: SecretSource;\n readonly method: \"plain\" | \"login\";\n }\n | {\n readonly type: \"oauth2\";\n readonly user: string;\n readonly secret: SecretSource;\n readonly method: \"xoauth2\" | \"oauthbearer\";\n };\n\n/** Listener-independent mail configuration; secret files remain unopened. */\nexport type MailSettings =\n | ApiMailSettings\n | JmapSettings\n | SesMailSettings\n | { readonly transport: \"logtape\"; readonly logContent: boolean }\n | {\n readonly transport: \"smtp\";\n readonly connection: Omit<SmtpConfig, \"auth\" | \"tls\">;\n readonly authentication: MailAuthentication | undefined;\n readonly files: {\n readonly ca: SecretSource | undefined;\n readonly cert: SecretSource | undefined;\n readonly key: SecretSource | undefined;\n };\n };\n\ntype Input = Sourced<string | undefined> | undefined;\nconst priority = { default: 0, config: 1, env: 2, cli: 3 } as const;\nconst rank = (value: Sourced<unknown> | undefined) =>\n value?.value === undefined ? -1 : priority[value.source];\n\nfunction isMailTransport(value: string): value is MailSettings[\"transport\"] {\n return [\n \"logtape\",\n \"smtp\",\n \"jmap\",\n \"lettermint\",\n \"maileroo\",\n \"mailtrap\",\n \"mailgun\",\n \"sendgrid\",\n \"ses\",\n \"resend\",\n \"plunk\",\n ].includes(value);\n}\n\nfunction selectTransport(raw: RawMailOptions): {\n transport: MailSettings[\"transport\"];\n selector: Input;\n} {\n const highest = Math.max(\n rank(raw.mailTransport),\n rank(raw.smtpUrl),\n rank(raw.smtpHost),\n rank(raw.jmapSessionUrl),\n );\n const explicit =\n rank(raw.mailTransport) === highest ? raw.mailTransport?.value : undefined;\n const smtp = rank(raw.smtpUrl) === highest || rank(raw.smtpHost) === highest;\n const jmap = rank(raw.jmapSessionUrl) === highest && highest >= 0;\n const transport =\n explicit ?? (jmap ? \"jmap\" : smtp && highest >= 0 ? \"smtp\" : \"logtape\");\n if (!isMailTransport(transport)) {\n throw new Error(\n \"Unsupported mail transport; expected logtape, smtp, jmap, lettermint, maileroo, mailtrap, mailgun, plunk, resend, sendgrid or ses.\",\n );\n }\n if (\n (smtp && highest >= 0 && transport !== \"smtp\") ||\n (jmap && transport !== \"jmap\")\n ) {\n throw new Error(\"Mail selectors at the same source disagree.\");\n }\n const selector = [\n raw.mailTransport,\n raw.smtpUrl,\n raw.smtpHost,\n raw.jmapSessionUrl,\n ].find((value) => rank(value) === highest && value?.value !== undefined);\n return { transport, selector };\n}\n\nfunction component(explicit: Input, inherited: Input, field: string): Input {\n if (rank(explicit) === rank(inherited) && rank(explicit) >= 0) {\n throw new Error(`Duplicate SMTP setting for ${field} at the same source.`);\n }\n return rank(explicit) > rank(inherited) ? explicit : inherited;\n}\n\nfunction boundedNumber(\n value: Input,\n fallback: number,\n maximum: number,\n field: string,\n) {\n if (value?.value === undefined) return fallback;\n const number = Number(value.value);\n if (\n !/^\\d+$/u.test(value.value) ||\n !Number.isSafeInteger(number) ||\n number < 1 ||\n number > maximum\n ) {\n throw new Error(`Invalid SMTP setting for ${field}.`);\n }\n return number;\n}\n\nfunction extractUriPort(value: string) {\n // WHATWG URL parsing enforces the TCP port range too early for overrides.\n // Preserve an RFC URI decimal port and parse the remaining URL normally.\n const scheme = /^smtps?:\\/\\//iu.exec(value)?.[0];\n if (scheme === undefined || /[\\r\\n\\u2028\\u2029]/u.test(value)) {\n throw new Error(\"Invalid SMTP connection URL.\");\n }\n const remainder = value.slice(scheme.length);\n const delimiter = remainder.search(/[/?#]/u);\n const authority = delimiter < 0 ? remainder : remainder.slice(0, delimiter);\n const tail = delimiter < 0 ? \"\" : remainder.slice(delimiter);\n const portComponent = /:(?<port>\\d*)$/u.exec(authority);\n const port = portComponent?.groups?.port;\n const withoutPort =\n portComponent === null\n ? authority\n : authority.slice(0, -portComponent[0].length);\n return { url: `${scheme}${withoutPort}${tail}`, port };\n}\n\nfunction urlComponents(raw: RawMailOptions): {\n host?: Input;\n port?: Input;\n tls?: Input;\n user?: Input;\n password?: Input;\n} {\n const source = raw.smtpUrl;\n if (source?.value === undefined) return {};\n const extracted = extractUriPort(source.value);\n const rawPort = extracted.port;\n const parsed = url({ allowedProtocols: [\"smtp:\", \"smtps:\"] }).parse(\n extracted.url,\n );\n if (!parsed.success) throw new Error(\"Invalid SMTP connection URL.\");\n const original = parsed.value;\n if (\n !/^smtps?:\\/\\//u.test(original.href) ||\n original.port !== \"\" ||\n (original.pathname !== \"\" && original.pathname !== \"/\") ||\n original.search !== \"\" ||\n original.hash !== \"\"\n ) {\n throw new Error(\"Invalid SMTP connection URL.\");\n }\n const secure = original.protocol === \"smtps:\";\n const inherit = (value: string): Sourced<string> => ({ ...source, value });\n return {\n host: inherit(original.hostname),\n port: inherit(\n rawPort === undefined || rawPort === \"\"\n ? secure\n ? \"465\"\n : \"587\"\n : rawPort,\n ),\n tls: inherit(secure ? \"direct\" : \"opportunistic\"),\n ...(original.username === \"\" ? {} : { user: inherit(original.username) }),\n ...(original.password === \"\"\n ? {}\n : { password: inherit(original.password) }),\n };\n}\n\nfunction decodedComponent(\n explicit: Input,\n inherited: Input,\n field: string,\n): Input {\n const selected = component(explicit, inherited, field);\n if (\n selected === undefined ||\n selected !== inherited ||\n selected.value === undefined\n ) {\n return selected;\n }\n try {\n return { ...selected, value: decodeURIComponent(selected.value) };\n } catch {\n throw new Error(`Invalid SMTP setting for ${field}.`);\n }\n}\n\n/** Validate the password API's currently supported encoding without secret errors. */\nexport function validateSmtpPassword(user: string, password: string) {\n if (\n user === \"\" ||\n /[^\\x20-\\x7e]/u.test(user) ||\n /[^\\x20-\\x7e]/u.test(password)\n ) {\n throw new Error(\"Invalid SMTP password authentication settings.\");\n }\n}\n\n/** Validate static OAuth authentication without exposing tokens in errors. */\nexport function validateSmtpOAuth(user: string, token: string) {\n if (\n user === \"\" ||\n token === \"\" ||\n /[^\\x21-\\x7e]/u.test(token) ||\n /\\p{Cc}/u.test(user)\n ) {\n throw new Error(\"Invalid SMTP OAuth authentication settings.\");\n }\n}\n\nfunction authenticationMethod(\n input: Input,\n passwordSelected: boolean,\n selectedRank: number,\n) {\n let method = input?.value;\n const methods = passwordSelected\n ? [\"plain\", \"login\"]\n : [\"xoauth2\", \"oauthbearer\"];\n if (\n method !== undefined &&\n !methods.includes(method) &&\n [\"plain\", \"login\", \"xoauth2\", \"oauthbearer\"].includes(method) &&\n rank(input) < selectedRank\n ) {\n method = undefined;\n }\n if (method !== undefined && !methods.includes(method)) {\n throw new Error(\"Invalid SMTP authentication method.\");\n }\n return {\n value: method ?? (passwordSelected ? \"plain\" : \"xoauth2\"),\n source:\n method === undefined\n ? (\"default\" as const)\n : (input?.source ?? (\"default\" as const)),\n ...(method === undefined || input?.configPath === undefined\n ? {}\n : { configPath: input.configPath }),\n };\n}\n\nfunction authenticationSources(\n raw: RawMailOptions,\n user: Input,\n password: Input,\n passwordSelected: boolean,\n) {\n const literalPassword =\n passwordSelected && rank(password) > rank(raw.smtpPasswordFile);\n const literalToken =\n !passwordSelected &&\n rank(raw.smtpAccessToken) > rank(raw.smtpAccessTokenFile);\n return {\n smtpUser: user,\n smtpPassword: literalPassword ? password : undefined,\n smtpPasswordFile:\n passwordSelected && !literalPassword ? raw.smtpPasswordFile : undefined,\n smtpAccessToken: literalToken ? raw.smtpAccessToken : undefined,\n smtpAccessTokenFile:\n !passwordSelected && !literalToken ? raw.smtpAccessTokenFile : undefined,\n };\n}\n\nfunction validateLiteralCredential(\n passwordSelected: boolean,\n user: string,\n secret: SecretSource,\n) {\n if (secret.type !== \"literal\") return;\n if (passwordSelected) validateSmtpPassword(user, secret.value);\n else validateSmtpOAuth(user, secret.value);\n}\n\nfunction authentication(\n raw: RawMailOptions,\n inherited: ReturnType<typeof urlComponents>,\n cwd: string,\n) {\n const user = decodedComponent(raw.smtpUser, inherited.user, \"user\");\n let password: Input;\n const passwordRank = Math.max(\n rank(raw.smtpPassword),\n rank(inherited.password),\n rank(raw.smtpPasswordFile),\n );\n const tokenRank = Math.max(\n rank(raw.smtpAccessToken),\n rank(raw.smtpAccessTokenFile),\n );\n if (passwordRank < 0 && tokenRank < 0) {\n if (user?.value !== undefined || raw.smtpAuthMethod?.value !== undefined) {\n throw new Error(\n \"SMTP authentication requires a password or access token.\",\n );\n }\n return { auth: undefined, sources: { smtpUser: user } };\n }\n if (passwordRank === tokenRank) {\n throw new Error(\n \"SMTP authentication variants at the same source disagree.\",\n );\n }\n if (user?.value === undefined || user.value === \"\") {\n throw new Error(\"SMTP authentication requires a username.\");\n }\n const passwordSelected = passwordRank > tokenRank;\n if (\n passwordSelected &&\n rank(raw.smtpPasswordFile) <=\n Math.max(rank(raw.smtpPassword), rank(inherited.password))\n ) {\n password = component(raw.smtpPassword, inherited.password, \"password\");\n }\n if (passwordSelected && rank(password) >= rank(raw.smtpPasswordFile)) {\n password = decodedComponent(\n raw.smtpPassword,\n inherited.password,\n \"password\",\n );\n }\n const secret = passwordSelected\n ? resolveSecretSource(password, raw.smtpPasswordFile, \"SMTP password\", cwd)\n : resolveSecretSource(\n raw.smtpAccessToken,\n raw.smtpAccessTokenFile,\n \"SMTP access token\",\n cwd,\n );\n if (secret === undefined) throw new Error(\"Missing SMTP credential.\");\n const method = authenticationMethod(\n raw.smtpAuthMethod,\n passwordSelected,\n Math.max(passwordRank, tokenRank),\n );\n validateLiteralCredential(passwordSelected, user.value, secret);\n const auth: MailAuthentication = passwordSelected\n ? {\n type: \"password\",\n user: user.value,\n secret,\n method: method.value as \"plain\" | \"login\",\n }\n : {\n type: \"oauth2\",\n user: user.value,\n secret,\n method: method.value as \"xoauth2\" | \"oauthbearer\",\n };\n return {\n auth,\n sources: {\n ...authenticationSources(raw, user, password, passwordSelected),\n smtpAuthMethod: method,\n },\n };\n}\n\nfunction tlsMode(\n tls: Input,\n explicit: Input,\n auth: MailAuthentication | undefined,\n) {\n let mode = tls?.value ?? \"starttls-required\";\n if (![\"direct\", \"starttls-required\", \"opportunistic\"].includes(mode)) {\n throw new Error(\"Invalid SMTP TLS mode.\");\n }\n if (auth !== undefined && mode === \"opportunistic\") {\n if (tls === explicit && explicit?.value !== undefined) {\n throw new Error(\n \"SMTP authentication requires direct TLS or mandatory STARTTLS.\",\n );\n }\n mode = \"starttls-required\";\n }\n return mode;\n}\n\nfunction smtpSettings(raw: RawMailOptions, cwd: string) {\n const inherited = urlComponents(raw);\n const host = component(raw.smtpHost, inherited.host, \"host\");\n const port = component(raw.smtpPort, inherited.port, \"port\");\n const tls = component(raw.smtpTls, inherited.tls, \"tls\");\n if (host?.value === undefined || host.value === \"\") {\n throw new Error(\"SMTP transport requires a host or SMTP URL.\");\n }\n const selected = authentication(raw, inherited, cwd);\n const mode = tlsMode(tls, raw.smtpTls, selected.auth);\n let normalized: SmtpConfig;\n try {\n const authority =\n host.value.includes(\":\") && !host.value.startsWith(\"[\")\n ? `[${host.value}]`\n : host.value;\n normalized = resolveSmtpConnection(\n new URL(\n `${mode === \"direct\" ? \"smtps\" : \"smtp\"}://${authority}:${boundedNumber(port, mode === \"direct\" ? 465 : 587, 65535, \"port\")}`,\n ),\n );\n } catch {\n throw new Error(\"Invalid SMTP host or port.\");\n }\n if (\n raw.smtpLocalName?.value !== undefined &&\n !/^(?:[A-Za-z0-9.-]+|\\[[0-9A-Fa-f:.]+\\])$/u.test(raw.smtpLocalName.value)\n ) {\n throw new Error(\"Invalid SMTP local name.\");\n }\n const cert = resolveSecretSource(\n undefined,\n raw.smtpCertFile,\n \"SMTP client certificate\",\n cwd,\n );\n const key = resolveSecretSource(\n undefined,\n raw.smtpKeyFile,\n \"SMTP client key\",\n cwd,\n );\n if ((cert === undefined) !== (key === undefined)) {\n throw new Error(\n \"SMTP client certificate and key must be configured together.\",\n );\n }\n const mail: MailSettings = {\n transport: \"smtp\",\n connection: {\n host: normalized.host,\n port: normalized.port ?? (mode === \"direct\" ? 465 : 587),\n secure: mode === \"direct\",\n requireTls: mode === \"starttls-required\",\n connectionTimeout: boundedNumber(\n raw.smtpConnectionTimeout,\n 30_000,\n 2_147_483_647,\n \"connection timeout\",\n ),\n socketTimeout: boundedNumber(\n raw.smtpSocketTimeout,\n 30_000,\n 2_147_483_647,\n \"socket timeout\",\n ),\n poolSize: boundedNumber(raw.smtpPoolSize, 5, 2_147_483_647, \"pool size\"),\n ...(raw.smtpLocalName?.value === undefined\n ? {}\n : { localName: raw.smtpLocalName.value }),\n },\n authentication: selected.auth,\n files: {\n ca: resolveSecretSource(\n undefined,\n raw.smtpCaFile,\n \"SMTP certificate authorities\",\n cwd,\n ),\n cert,\n key,\n },\n };\n return {\n mail,\n mode,\n sources: {\n ...raw,\n smtpHost: host,\n smtpPort: port,\n smtpTls: tls,\n ...selected.sources,\n },\n };\n}\n\nfunction logContent(raw: RawMailOptions) {\n const parsed = configurationBoolean().parse(\n raw.mailLogContent?.value ?? \"false\",\n );\n if (!parsed.success) throw new Error(\"Invalid mail.log_content setting.\");\n return parsed.value;\n}\n\nfunction selectedMailSettings(\n transport: MailSettings[\"transport\"],\n raw: RawMailOptions,\n cwd: string,\n): {\n mail: MailSettings;\n sources: Record<string, Input>;\n values: Record<string, unknown>;\n} {\n if (transport === \"ses\") return resolveSesSettings(raw, cwd);\n if (\n transport === \"lettermint\" ||\n transport === \"maileroo\" ||\n transport === \"mailtrap\" ||\n transport === \"mailgun\" ||\n transport === \"plunk\" ||\n transport === \"resend\" ||\n transport === \"sendgrid\"\n ) {\n return resolveApiMailSettings(raw, cwd, transport);\n }\n if (transport === \"jmap\") return resolveJmapSettings(raw, cwd);\n if (transport === \"logtape\") {\n const logContentValue = logContent(raw);\n return {\n mail: { transport, logContent: logContentValue },\n sources: {},\n values: { mailLogContent: logContentValue },\n };\n }\n const smtp = smtpSettings(raw, cwd);\n const { mail } = smtp;\n return {\n mail,\n sources: smtp.sources,\n values: {\n smtpHost: mail.connection.host,\n smtpPort: mail.connection.port,\n smtpTls: smtp.mode,\n smtpConnectionTimeout: mail.connection.connectionTimeout,\n smtpSocketTimeout: mail.connection.socketTimeout,\n smtpPoolSize: mail.connection.poolSize,\n smtpLocalName: mail.connection.localName,\n smtpAuthMethod: mail.authentication?.method,\n },\n };\n}\n\nfunction secretFieldForTransport(\n key: string,\n transport: MailSettings[\"transport\"],\n) {\n if (key.startsWith(transport)) return true;\n return (\n (transport === \"lettermint\" ||\n transport === \"maileroo\" ||\n transport === \"mailtrap\" ||\n transport === \"mailgun\" ||\n transport === \"plunk\" ||\n transport === \"resend\" ||\n transport === \"sendgrid\") &&\n (key === \"mailApiKey\" || key === \"mailApiKeyFile\")\n );\n}\n\nfunction ignoredMailField(\n key: string,\n provider: MailSettings[\"transport\"],\n sources: Record<string, Input>,\n) {\n if (key === \"mailLogContent\") return provider !== \"logtape\";\n if (key === \"mailApiKey\" || key === \"mailApiKeyFile\") {\n return (\n (provider !== \"lettermint\" &&\n provider !== \"maileroo\" &&\n provider !== \"mailtrap\" &&\n provider !== \"mailgun\" &&\n provider !== \"plunk\" &&\n provider !== \"resend\" &&\n provider !== \"sendgrid\") ||\n sources[key]?.value === undefined\n );\n }\n const branch = [\n \"smtp\",\n \"jmap\",\n \"lettermint\",\n \"maileroo\",\n \"mailtrap\",\n \"mailgun\",\n \"sendgrid\",\n \"ses\",\n \"resend\",\n \"plunk\",\n ].find((name) => key.startsWith(name));\n if (branch === undefined) return false;\n if (branch !== provider) return true;\n if (key === \"smtpAuthMethod\" && sources[key]?.source === \"default\") {\n return true;\n }\n return key in sources && sources[key]?.value === undefined;\n}\n\n/** Resolve provider selection and safe diagnostics without reading credentials.\n * @returns Runtime settings, redacted diagnostics and ignored branch metadata.\n */\nexport function resolveMailSettings(raw: RawMailOptions, cwd = process.cwd()) {\n const selection = selectTransport(raw);\n const resolved = selectedMailSettings(selection.transport, raw, cwd);\n const { mail, sources: activeSources } = resolved;\n const provenance = configurationProvenance({\n ...raw,\n ...activeSources,\n mailTransport: selection.selector,\n });\n const values: Record<string, unknown> = {\n mailTransport: mail.transport,\n ...resolved.values,\n };\n for (const [key, value] of Object.entries(activeSources)) {\n if (\n secretFieldForTransport(key, mail.transport) &&\n value?.value !== undefined &&\n configurationSettings[key as keyof typeof configurationSettings].secret\n ) {\n values[key] = \"<redacted>\";\n }\n }\n const ignored = Object.entries(raw)\n .filter(\n ([key, value]) =>\n value?.value !== undefined &&\n value.source !== \"default\" &&\n ignoredMailField(key, mail.transport, activeSources),\n )\n .map(([key, value]) => ({\n field:\n configurationSettings[key as keyof typeof configurationSettings].toml,\n source: value?.source ?? \"default\",\n }));\n const diagnostic = Object.fromEntries(\n Object.entries(values)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => [\n configurationSettings[key as keyof typeof configurationSettings].toml,\n { value, ...(provenance[key] ?? { source: \"default\" as const }) },\n ]),\n );\n return { mail, diagnostic, ignored, provenance };\n}\n"],"mappings":";;;;;;;AAuBA,MAAMA,aAAW;CAAE,SAAS;CAAG,QAAQ;CAAG,KAAK;CAAG,KAAK;AAAE;AACzD,MAAMC,UAAQ,UACZ,OAAO,UAAU,KAAA,IAAY,KAAKD,WAAS,MAAM;;AAmBnD,SAAgB,sBACd,OACA,MACA;CACA,IACE,UAAU,MACV,gBAAgB,KAAK,KAAK,KACzB,SAAS,mBAAmB,CAAC,wBAAwB,KAAK,KAAK,GAEhE,MAAM,IAAI,MAAM,eAAe,KAAK,EAAE;AAE1C;AAEA,SAAS,OACP,SACA,MACA,MACA,KACA;CACA,MAAM,WAAW,oBAAoB,SAAS,MAAM,OAAO,QAAQ,GAAG;CACtE,IAAI,aAAa,KAAA,GAAW,MAAM,IAAI,MAAM,kBAAkB,KAAK,EAAE;CACrE,IAAI,SAAS,SAAS,WAAW,sBAAsB,SAAS,OAAO,IAAI;CAC3E,OAAO;AACT;AAEA,SAAS,mBAAmB,KAG1B;CACA,MAAM,QACJC,OAAK,IAAI,eAAe,KAAKA,OAAK,IAAI,mBAAmB,IACrD,IAAI,kBACJ,IAAI;CACV,IAAIA,OAAK,KAAK,IAAIA,OAAK,IAAI,OAAO,GAChC,OAAO;EAAE,MAAM;EAAoB,QAAQ;CAAM;CAEnD,MAAM,OAAO,IAAI,SAAS,SAAS;CACnC,IAAI,SAAS,iBAAiB,SAAS,WACrC,MAAM,IAAI,MAAM,kCAAkC;CAEpD,OAAO;EAAE;EAAM,QAAQ,IAAI;CAAQ;AACrC;;;;AAKA,SAAgB,mBAAmB,KAAqB,KAA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;CAC5E,MAAM,YAAY,gBAAgB,GAAG;CACrC,MAAM,WAAW,qBAAqB,UAAU,WAAW,KAAK,GAAG;CACnE,MAAM,EAAE,MAAM,SAAS,kBAAkB;CACzC,MAAM,aAAa,wBAAwB;EACzC,GAAG;EACH,GAAG;EACH,eAAe,UAAU;CAC3B,CAAC;CACD,MAAM,SAAkC;EACtC,eAAe,KAAK;EACpB,GAAG,SAAS;CACd;CACA,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,aAAa,GACrD,IACE,wBAAwB,KAAK,KAAK,SAAS,KAC3C,OAAO,UAAU,KAAA,KACjB,sBAAsB,IAA0C,CAAC,QAEjE,OAAO,OAAO;CAGlB,MAAM,UAAU,OAAO,QAAQ,GAAG,CAAC,CAChC,QACE,CAAC,KAAK,WACL,OAAO,UAAU,KAAA,KACjB,MAAM,WAAW,aACjB,iBAAiB,KAAK,KAAK,WAAW,aAAa,CACvD,CAAC,CACA,KAAK,CAAC,KAAK,YAAY;EACtB,OACE,sBAAsB,IAA0C,CAAC;EACnE,QAAQ,OAAO,UAAU;CAC3B,EAAE;CASJ,OAAO;EAAE;EAAM,YARI,OAAO,YACxB,OAAO,QAAQ,MAAM,CAAC,CACnB,QAAQ,GAAG,WAAW,UAAU,KAAA,CAAS,CAAC,CAC1C,KAAK,CAAC,KAAK,WAAW,CACrB,sBAAsB,IAA0C,CAAC,MACjE;GAAE;GAAO,GAAI,WAAW,QAAQ,EAAE,QAAQ,UAAmB;EAAG,CAClE,CAAC,CAEmB;EAAG;EAAS;CAAW;AACjD"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { o as ConfigurationSource } from "./configuration-DVVF7xNv.mjs";
|
|
2
|
+
import { t as RawMailOptions } from "./mail-parser-DyI4wuQp.mjs";
|
|
3
|
+
import { t as SecretSource } from "./secret-source-BeZx72Ue.mjs";
|
|
4
|
+
import { t as ApiMailSettings } from "./api-mail-settings-BcGaqQ9f.mjs";
|
|
5
|
+
import { t as JmapSettings } from "./jmap-settings-BXNAF1ep.mjs";
|
|
6
|
+
import { SmtpConfig } from "@upyo/smtp";
|
|
7
|
+
import { SesConfig } from "@upyo/ses";
|
|
8
|
+
//#region src/ses-settings.d.ts
|
|
9
|
+
/** SES connection settings before selected credential files are opened. */
|
|
10
|
+
interface SesMailSettings {
|
|
11
|
+
readonly transport: "ses";
|
|
12
|
+
readonly connection: Omit<SesConfig, "authentication" | "headers" | "defaultTags" | "batchSize">;
|
|
13
|
+
readonly authentication: {
|
|
14
|
+
readonly accessKeyId: SecretSource;
|
|
15
|
+
readonly secretAccessKey: SecretSource;
|
|
16
|
+
} & ({
|
|
17
|
+
readonly type: "credentials";
|
|
18
|
+
} | {
|
|
19
|
+
readonly type: "session";
|
|
20
|
+
readonly sessionToken: SecretSource;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/mail-settings.d.ts
|
|
25
|
+
/** SMTP authentication selected before credential files are read. */
|
|
26
|
+
type MailAuthentication = {
|
|
27
|
+
readonly type: "password";
|
|
28
|
+
readonly user: string;
|
|
29
|
+
readonly secret: SecretSource;
|
|
30
|
+
readonly method: "plain" | "login";
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "oauth2";
|
|
33
|
+
readonly user: string;
|
|
34
|
+
readonly secret: SecretSource;
|
|
35
|
+
readonly method: "xoauth2" | "oauthbearer";
|
|
36
|
+
};
|
|
37
|
+
/** Listener-independent mail configuration; secret files remain unopened. */
|
|
38
|
+
type MailSettings = ApiMailSettings | JmapSettings | SesMailSettings | {
|
|
39
|
+
readonly transport: "logtape";
|
|
40
|
+
readonly logContent: boolean;
|
|
41
|
+
} | {
|
|
42
|
+
readonly transport: "smtp";
|
|
43
|
+
readonly connection: Omit<SmtpConfig, "auth" | "tls">;
|
|
44
|
+
readonly authentication: MailAuthentication | undefined;
|
|
45
|
+
readonly files: {
|
|
46
|
+
readonly ca: SecretSource | undefined;
|
|
47
|
+
readonly cert: SecretSource | undefined;
|
|
48
|
+
readonly key: SecretSource | undefined;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/** Validate the password API's currently supported encoding without secret errors. */
|
|
52
|
+
declare function validateSmtpPassword(user: string, password: string): void;
|
|
53
|
+
/** Validate static OAuth authentication without exposing tokens in errors. */
|
|
54
|
+
declare function validateSmtpOAuth(user: string, token: string): void;
|
|
55
|
+
/** Resolve provider selection and safe diagnostics without reading credentials.
|
|
56
|
+
* @returns Runtime settings, redacted diagnostics and ignored branch metadata.
|
|
57
|
+
*/
|
|
58
|
+
declare function resolveMailSettings(raw: RawMailOptions, cwd?: string): {
|
|
59
|
+
mail: MailSettings;
|
|
60
|
+
diagnostic: {
|
|
61
|
+
[k: string]: {
|
|
62
|
+
source: ConfigurationSource;
|
|
63
|
+
configPath?: string;
|
|
64
|
+
value: unknown;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
ignored: {
|
|
68
|
+
field: string;
|
|
69
|
+
source: ConfigurationSource;
|
|
70
|
+
}[];
|
|
71
|
+
provenance: {
|
|
72
|
+
[k: string]: {
|
|
73
|
+
source: ConfigurationSource;
|
|
74
|
+
configPath?: string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
export { validateSmtpPassword as a, validateSmtpOAuth as i, MailSettings as n, resolveMailSettings as r, MailAuthentication as t };
|
|
80
|
+
//# sourceMappingURL=mail-settings-DjWMAUaE.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mail-settings-DjWMAUaE.d.mts","names":[],"sources":["../src/ses-settings.ts","../src/mail-settings.ts"],"mappings":";;;;;;;;;UA4BiB;WACN;WACA,YAAY,KACnB;WAGO;aACE,aAAa;aACb,iBAAiB;;aAEb;;aACA;aAA0B,cAAc;;;;;;KCH7C;WAEG;WACA;WACA,QAAQ;WACR;;WAGA;WACA;WACA,QAAQ;WACR;;;KAIH,eACR,kBACA,eACA;WACW;WAA+B;;WAE/B;WACA,YAAY,KAAK;WACjB,gBAAgB;WAChB;aACE,IAAI;aACJ,MAAM;aACN,KAAK;;;;iBA4KN,qBAAqB,cAAc;;iBAWnC,kBAAkB,cAAc;;;;iBAqYhC,oBAAoB,KAAK,gBAAgB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/operations.d.ts
|
|
2
|
+
/** Track asynchronous work so shutdown can refuse new work and await existing work. */
|
|
3
|
+
declare class OperationRegistry {
|
|
4
|
+
#private;
|
|
5
|
+
/**
|
|
6
|
+
* A shared cancellation signal for operations owned by this registry.
|
|
7
|
+
* @returns The cancellation signal shared by registered operations.
|
|
8
|
+
*/
|
|
9
|
+
get signal(): AbortSignal;
|
|
10
|
+
/**
|
|
11
|
+
* Register before invoking an operation, including operations that reject.
|
|
12
|
+
* @returns The operation's result; the caller remains responsible for errors.
|
|
13
|
+
*/
|
|
14
|
+
run<T>(operation: (signal: AbortSignal) => T | Promise<T>): Promise<T>;
|
|
15
|
+
/**
|
|
16
|
+
* Track a continuation of work already admitted by the runtime.
|
|
17
|
+
* The caller must prevent new requests and stop background producers before
|
|
18
|
+
* draining. Continuations remain allowed so accepted requests can finish.
|
|
19
|
+
* @returns The continuation's result; the caller remains responsible for errors.
|
|
20
|
+
*/
|
|
21
|
+
track<T>(operation: (signal: AbortSignal) => T | Promise<T>): Promise<T>;
|
|
22
|
+
/** Refuse new work and signal existing operations to stop. */
|
|
23
|
+
abort(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Abort and await all registered work, even if an operation rejected.
|
|
26
|
+
* @returns Completion after every active operation has settled.
|
|
27
|
+
*/
|
|
28
|
+
drain(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { OperationRegistry };
|
|
32
|
+
//# sourceMappingURL=operations.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.mts","names":[],"sources":["../src/operations.ts"],"mappings":";;cAiBa;;;;;;MAQP,UAAU;;;;;EAQd,IAAI,GAAG,YAAY,QAAQ,gBAAgB,IAAI,QAAQ,KAAK,QAAQ;;;;;;;EAcpE,MAAM,GAAG,YAAY,QAAQ,gBAAgB,IAAI,QAAQ,KAAK,QAAQ;;EAetE;;;;;EAQM,SAAS"}
|