@fabrika/installation-init 0.4.8 → 0.5.0
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/package.json +4 -3
- package/src/email.ts +49 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/installation-init",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"zod": "^3.25.76",
|
|
30
|
-
"@fabrika/app": "0.
|
|
31
|
-
"@fabrika/
|
|
30
|
+
"@fabrika/app": "0.5.0",
|
|
31
|
+
"@fabrika/email": "0.5.0",
|
|
32
|
+
"@fabrika/iam-contract": "0.5.0"
|
|
32
33
|
}
|
|
33
34
|
}
|
package/src/email.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The installation's mail transport as both installers take it: the provider, the sender and the display name from a
|
|
2
|
+
// flag or the variable beside it, and each provider variable from the environment only, under its own name, because an
|
|
3
|
+
// open provider registry cannot have one flag per variable and most of them are credentials.
|
|
4
|
+
|
|
5
|
+
import { type EmailEnvironment, type EmailProviderRegistry, readEmailTransportConfig } from '@fabrika/email'
|
|
6
|
+
import { type CommandEnv, readEnv, readFlag, requiredSetting, setting } from './options'
|
|
7
|
+
|
|
8
|
+
export type InstallationEmail =
|
|
9
|
+
| { readonly kind: 'none' }
|
|
10
|
+
| { readonly kind: 'provider'; readonly variables: ReadonlyMap<string, string>; readonly secretNames: ReadonlySet<string> }
|
|
11
|
+
|
|
12
|
+
export const EMAIL_FLAGS = ['--email-provider', '--email-from', '--email-from-name'] as const
|
|
13
|
+
|
|
14
|
+
const PROVIDER_VARIABLE = 'FABRIKA_EMAIL_PROVIDER'
|
|
15
|
+
const FROM_VARIABLE = 'FABRIKA_EMAIL_FROM'
|
|
16
|
+
const FROM_NAME_VARIABLE = 'FABRIKA_EMAIL_FROM_NAME'
|
|
17
|
+
|
|
18
|
+
/** Throws naming flags and variables, never a value. */
|
|
19
|
+
export function readInstallationEmail(
|
|
20
|
+
argv: readonly string[],
|
|
21
|
+
env: CommandEnv,
|
|
22
|
+
options: { readonly registry: EmailProviderRegistry; readonly required: boolean },
|
|
23
|
+
): InstallationEmail {
|
|
24
|
+
const given = setting(argv, env, '--email-provider', PROVIDER_VARIABLE)
|
|
25
|
+
const provider = options.required ? requiredSetting(given, '--email-provider', PROVIDER_VARIABLE) : given
|
|
26
|
+
if (provider === undefined || provider === 'none') {
|
|
27
|
+
const refused = ['--email-from', '--email-from-name'].find((flag) => readFlag(argv, flag) !== undefined)
|
|
28
|
+
if (refused !== undefined) throw new Error(`${refused} was given, but the email provider is none`)
|
|
29
|
+
return { kind: 'none' }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const variables = new Map<string, string>([[PROVIDER_VARIABLE, provider]])
|
|
33
|
+
const secretNames = new Set<string>()
|
|
34
|
+
const collect = (name: string, value: string | undefined): void => {
|
|
35
|
+
if (value !== undefined) variables.set(name, value)
|
|
36
|
+
}
|
|
37
|
+
collect(FROM_VARIABLE, setting(argv, env, '--email-from', FROM_VARIABLE))
|
|
38
|
+
collect(FROM_NAME_VARIABLE, setting(argv, env, '--email-from-name', FROM_NAME_VARIABLE))
|
|
39
|
+
const declared = Object.hasOwn(options.registry, provider) ? options.registry[provider]?.variables ?? [] : []
|
|
40
|
+
for (const variable of declared) {
|
|
41
|
+
const value = readEnv(env, variable.name)
|
|
42
|
+
collect(variable.name, value)
|
|
43
|
+
if (value !== undefined && variable.secret) secretNames.add(variable.name)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const collected: EmailEnvironment = Object.fromEntries(variables)
|
|
47
|
+
readEmailTransportConfig(collected, options.registry)
|
|
48
|
+
return { kind: 'provider', variables, secretNames }
|
|
49
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export {
|
|
|
11
11
|
} from './admin'
|
|
12
12
|
export { CHECKOUT_FLAG, sidecarCheckoutDir } from './checkout'
|
|
13
13
|
export { type Confirmations, confirmations, UNATTENDED_FLAG } from './confirmations'
|
|
14
|
+
export { EMAIL_FLAGS, type InstallationEmail, readInstallationEmail } from './email'
|
|
14
15
|
export {
|
|
15
16
|
configureEnvironment,
|
|
16
17
|
type EnvironmentConfig,
|