@@ -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
5788export 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}
0 commit comments