Files
start-sdk/lib/config/configConstants.ts
2023-05-16 07:50:51 -06:00

87 lines
2.3 KiB
TypeScript

import { SmtpValue } from "../types"
import { email } from "../util/patterns"
import { Config, ConfigSpecOf } from "./builder/config"
import { Value } from "./builder/value"
import { Variants } from "./builder/variants"
/**
* Base SMTP settings, to be used by StartOS for system wide SMTP
*/
export const customSmtp = Config.of<ConfigSpecOf<SmtpValue>, never, never>({
server: Value.text({
name: "SMTP Server",
required: {
default: null,
},
}),
port: Value.number({
name: "Port",
required: { default: 587 },
min: 1,
max: 65535,
integer: true,
}),
from: Value.text({
name: "From Address",
required: {
default: null,
},
placeholder: "<name>test@example.com",
inputmode: "email",
patterns: [email],
}),
login: Value.text({
name: "Login",
required: {
default: null,
},
}),
password: Value.text({
name: "Password",
required: false,
masked: true,
}),
tls: Value.toggle({
name: "Require Transport Security",
default: true,
description:
"Require TLS transport security. If disabled, email will use plaintext by default and TLS via STARTTLS <strong>if the SMTP server supports it</strong>. If enabled, email will refuse to connect unless the server supports STARTTLS.",
}),
})
/**
* For service config. Gives users 3 options for SMTP: (1) disabled, (2) use system SMTP settings, (3) use custom SMTP settings
*/
export const smtpConfig = Value.filteredUnion(
async ({ effects, utils }) => {
const smtp = await utils.getSystemSmtp().once()
return smtp ? [] : ["system"]
},
{
name: "SMTP",
description: "Optionally provide an SMTP server for sending emails",
required: { default: "disabled" },
},
Variants.of({
disabled: { name: "Disabled", spec: Config.of({}) },
system: {
name: "System Credentials",
spec: Config.of({
customFrom: Value.text({
name: "Custom From Address",
description:
"A custom from address for this service. If not provided, the system from address will be used.",
required: false,
placeholder: "<name>test@example.com",
inputmode: "email",
patterns: [email],
}),
}),
},
custom: {
name: "Custom Credentials",
spec: customSmtp,
},
}),
)