From f4c93438f8a4d0e8f57024898f450c63b14554fb Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Wed, 3 May 2023 10:55:09 -0600 Subject: [PATCH] filter union for smtp --- lib/config/builder/config.ts | 2 +- lib/config/constants.ts | 9 ++++++--- lib/types.ts | 2 ++ lib/util/GetSystemSmtp.ts | 4 +--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/config/builder/config.ts b/lib/config/builder/config.ts index 5b2d3ec..4fe6052 100644 --- a/lib/config/builder/config.ts +++ b/lib/config/builder/config.ts @@ -18,7 +18,7 @@ export type ExtractConfigType | Config | Config ? B : A -export type TypeAsConfigOf, WD = never> = { +export type ConfigSpecOf, WD = never> = { [K in keyof A]: Value } diff --git a/lib/config/constants.ts b/lib/config/constants.ts index b2e5601..b2e4002 100644 --- a/lib/config/constants.ts +++ b/lib/config/constants.ts @@ -1,9 +1,12 @@ import { SmtpValue } from "../types" -import { Config, TypeAsConfigOf } from "./builder/config" +import { Config, ConfigSpecOf } from "./builder/config" import { Value } from "./builder/value" import { Variants } from "./builder/variants" -export const smtpConfig = Value.union( +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 email", @@ -14,7 +17,7 @@ export const smtpConfig = Value.union( system: { name: "System Credentials", spec: Config.of({}) }, custom: { name: "Custom Credentials", - spec: Config.of>({ + spec: Config.of>({ server: Value.text({ name: "SMTP Server", required: { diff --git a/lib/types.ts b/lib/types.ts index 413789a..26b700e 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -335,6 +335,8 @@ export type Effects = { interfaceId: string, packageId?: string, ): Promise + /** Get the IP address of the container */ + getContainerIp(): Promise /** * Get the port address for another service */ diff --git a/lib/util/GetSystemSmtp.ts b/lib/util/GetSystemSmtp.ts index cf5b57b..33c58c1 100644 --- a/lib/util/GetSystemSmtp.ts +++ b/lib/util/GetSystemSmtp.ts @@ -1,6 +1,4 @@ -import { Parser } from "ts-matches" -import { Effects, EnsureWrapperDataPath, ExtractWrapperData } from "../types" -import { NoAny } from "." +import { Effects } from "../types" export class GetSystemSmtp { constructor(readonly effects: Effects) {}