From 4ee030de1c6b50bda4d9270abec34d62d5eb247e Mon Sep 17 00:00:00 2001 From: BluJ Date: Fri, 19 May 2023 11:27:37 -0600 Subject: [PATCH] fix: Create or update Vault: Updating the thing to always return a string. Make sure the key is in the vault --- lib/util/utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/util/utils.ts b/lib/util/utils.ts index 3f2bc74..cabaa5c 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -63,10 +63,10 @@ export type Utils = { search: Record }) => NetworkInterfaceBuilder createOrUpdateVault: (opts: { - key: string + key: keyof Vault & string value: string | null | undefined generator: DefaultString - }) => Promise + }) => Promise getSystemSmtp: () => GetSystemSmtp & WrapperOverWrite host: { static: (id: string) => StaticHost @@ -129,7 +129,7 @@ export const utils = < value, generator, }: { - key: string + key: keyof Vault & string value: string | null | undefined generator: DefaultString }) => { @@ -137,8 +137,9 @@ export const utils = < await effects.vault.set({ key, value }) return value } - if (await effects.vault.get({ key, callback: noop })) { - return null + const oldValue = await effects.vault.get({ key, callback: noop }) + if (oldValue) { + return oldValue } const newValue = getDefaultString(generator) await effects.vault.set({ key, value: newValue })