From f294726c0d36b92f3ffa23b2936364de45b16832 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Thu, 11 May 2023 07:40:27 -0600 Subject: [PATCH] better smtp const --- lib/config/configConstants.ts | 92 ++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/lib/config/configConstants.ts b/lib/config/configConstants.ts index 54e0e62..4e0c7ef 100644 --- a/lib/config/configConstants.ts +++ b/lib/config/configConstants.ts @@ -3,6 +3,46 @@ import { Config, ConfigSpecOf } from "./builder/config" import { Value } from "./builder/value" import { Variants } from "./builder/variants" +export const customSmtp = Config.of, 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: "test@example.com", + inputmode: "email", + }), + login: Value.text({ + name: "Login", + required: { + default: null, + }, + }), + password: Value.text({ + name: "Password", + required: false, + }), + 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 if the SMTP server supports it. If enabled, email will refuse to connect unless the server supports STARTTLS.", + }), +}) + export const smtpConfig = Value.filteredUnion( async ({ effects, utils }) => { const smtp = await utils.getSystemSmtp().once() @@ -10,53 +50,27 @@ export const smtpConfig = Value.filteredUnion( }, { name: "SMTP", - description: "Optionally provide an SMTP server for sending email", + 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({}) }, - custom: { - name: "Custom Credentials", - spec: Config.of, 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, - }, + 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: "test@example.com", inputmode: "email", }), - login: Value.text({ - name: "Login", - required: { - default: null, - }, - }), - password: Value.text({ - name: "Password", - required: false, - }), - 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 if the SMTP server supports it. If enabled, email will refuse to connect unless the server supports STARTTLS.", - }), }), }, + custom: { + name: "Custom Credentials", + spec: customSmtp, + }, }), )