Skip to content

Commit 5542a99

Browse files
committed
chore(vault): add smtp config to flags for coherence
1 parent f1e68c8 commit 5542a99

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

vault/AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ For more information, read the Bun API docs in `node_modules/bun-types/docs/**.m
116116
- Make sure to remove rambling "stream of consciousness" (a.k.a. thinking out loud) comments in the final code.
117117
- Prefer broader integration-style tests. Avoid excessive mocking.
118118
- Consult files in `docs/` to see if there's anything relevant for your current job.
119+
- Flags are the primary way to configure this application, and they are the source of truth, with the benefit of being self-documenting. Environment variables are layered on top of flags. See @src/config.ts for how configuration is managed.

vault/src/config.ts

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,71 @@ export type Config = {
1919
smtp: email.SmtpConfig | null
2020
}
2121

22-
export const flags = {
22+
/** Creates flag definitions with default values parsed from the current env. */
23+
export const flags = (env: NodeJS.ProcessEnv = process.env) => ({
2324
"server-hostname": {
2425
type: String,
25-
default: process.env.SEED_VAULT_HTTP_HOSTNAME || "0.0.0.0",
26+
default: env.SEED_VAULT_HTTP_HOSTNAME || "0.0.0.0",
2627
description: "The hostname to bind the HTTP server to",
2728
},
2829
"server-port": {
2930
type: Number,
30-
default: Number(process.env.SEED_VAULT_HTTP_PORT) || 3000,
31+
default: Number(env.SEED_VAULT_HTTP_PORT) || 3000,
3132
description: "The port to bind the HTTP server to",
3233
},
34+
3335
"rp-id": {
3436
type: String,
35-
default: process.env.SEED_VAULT_RP_ID || "",
37+
default: env.SEED_VAULT_RP_ID || "",
3638
description: "The relying party ID",
3739
},
3840
"rp-name": {
3941
type: String,
40-
default: process.env.SEED_VAULT_RP_NAME || "Seed Hypermedia Identity Vault",
42+
default: env.SEED_VAULT_RP_NAME || "Seed Hypermedia Identity Vault",
4143
description: "The relying party name",
4244
},
4345
"rp-origin": {
4446
type: String,
45-
default: process.env.SEED_VAULT_RP_ORIGIN || "",
47+
default: env.SEED_VAULT_RP_ORIGIN || "",
4648
description: "The relying party origin",
4749
},
50+
4851
"db-path": {
4952
type: String,
50-
default: process.env.SEED_VAULT_DB_PATH || "vault.sqlite",
53+
default: env.SEED_VAULT_DB_PATH || "vault.sqlite",
5154
description: "Path to the database file",
5255
},
53-
}
5456

55-
type ParsedFlags = cleye.TypeFlag<typeof flags>["flags"]
57+
"smtp-host": {
58+
type: String,
59+
default: env.SEED_VAULT_SMTP_HOST || "",
60+
description: "The SMTP host to use for sending emails",
61+
},
62+
"smtp-port": {
63+
type: Number,
64+
default: Number(env.SEED_VAULT_SMTP_PORT) || 587,
65+
description: "The SMTP port to use for sending emails",
66+
},
67+
"smtp-user": {
68+
type: String,
69+
default: env.SEED_VAULT_SMTP_USER || "",
70+
description: "The SMTP username to use for sending emails",
71+
},
72+
"smtp-password": {
73+
type: String,
74+
default: env.SEED_VAULT_SMTP_PASSWORD || "",
75+
description: "The SMTP password to use for sending emails",
76+
},
77+
"smtp-sender": {
78+
type: String,
79+
default: env.SEED_VAULT_SMTP_SENDER || "",
80+
description: "The email address to use as the sender",
81+
},
82+
})
83+
84+
type FlagsDef = ReturnType<typeof flags>
85+
86+
type ParsedFlags = cleye.TypeFlag<FlagsDef>["flags"]
5687

5788
export function create(pflags: ParsedFlags): Config {
5889
const http: Server = {
@@ -74,21 +105,22 @@ export function create(pflags: ParsedFlags): Config {
74105
throw new Error("Relying party origin configuration is required")
75106
}
76107

77-
const smtpHost = process.env.SEED_VAULT_SMTP_HOST
78-
const smtp: email.SmtpConfig | null = smtpHost
108+
const dbPath = pflags["db-path"]
109+
110+
const smtp = pflags["smtp-host"]
79111
? {
80-
host: smtpHost,
81-
port: Number(process.env.SEED_VAULT_SMTP_PORT) || 587,
82-
user: process.env.SEED_VAULT_SMTP_USER || "",
83-
password: process.env.SEED_VAULT_SMTP_PASSWORD || "",
84-
sender: process.env.SEED_VAULT_SMTP_SENDER || "",
112+
host: pflags["smtp-host"],
113+
port: pflags["smtp-port"],
114+
user: pflags["smtp-user"],
115+
password: pflags["smtp-password"],
116+
sender: pflags["smtp-sender"],
85117
}
86118
: null
87119

88120
return {
89121
http,
90122
relyingParty,
91-
dbPath: pflags["db-path"],
123+
dbPath,
92124
smtp,
93125
}
94126
}

vault/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function collectStaticAssets(dir: string, urlPrefix: string): Map<string, Return
3030
async function main() {
3131
const argv = cli({
3232
name: "seed-vault",
33-
flags: config.flags,
33+
flags: config.flags(),
3434
strictFlags: true,
3535
})
3636

0 commit comments

Comments
 (0)