From c6907eb09e325b167dd83db93cf7fdb12ea1602d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 10 Sep 2024 16:41:44 +0100 Subject: [PATCH] fix types --- packages/builder/src/stores/portal/menu.js | 4 ++- packages/types/src/documents/global/config.ts | 2 +- .../src/api/controllers/global/configs.ts | 9 +++--- .../controllers/global/tests/configs.spec.ts | 31 +++++++++---------- packages/worker/src/tests/api/configs.ts | 1 - .../worker/src/tests/structures/configs.ts | 5 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/builder/src/stores/portal/menu.js b/packages/builder/src/stores/portal/menu.js index 19b190fd24..a1b5450ea4 100644 --- a/packages/builder/src/stores/portal/menu.js +++ b/packages/builder/src/stores/portal/menu.js @@ -84,7 +84,9 @@ export const menu = derived([admin, auth], ([$admin, $auth]) => { menu.push({ title: "Settings", href: "/builder/portal/settings", - subPages: [...settingsSubPages].sort((a, b) => a.title.localeCompare(b.title)), + subPages: [...settingsSubPages].sort((a, b) => + a.title.localeCompare(b.title) + ), }) } diff --git a/packages/types/src/documents/global/config.ts b/packages/types/src/documents/global/config.ts index 6e9c29af97..8d64b49ee9 100644 --- a/packages/types/src/documents/global/config.ts +++ b/packages/types/src/documents/global/config.ts @@ -121,7 +121,7 @@ export interface AIInnerConfig { active: boolean baseUrl?: string apiKey?: string - defaultModel: string + defaultModel?: string } } diff --git a/packages/worker/src/api/controllers/global/configs.ts b/packages/worker/src/api/controllers/global/configs.ts index d51ae65c51..0760a6c692 100644 --- a/packages/worker/src/api/controllers/global/configs.ts +++ b/packages/worker/src/api/controllers/global/configs.ts @@ -32,6 +32,7 @@ import { AIConfig, PASSWORD_REPLACEMENT, isAIConfig, + AIInnerConfig, } from "@budibase/types" import * as pro from "@budibase/pro" @@ -210,13 +211,13 @@ async function verifyOIDCConfig(config: OIDCConfigs) { } export async function verifyAIConfig( - config: AIConfig, + configToSave: AIInnerConfig, existingConfig: AIConfig ) { // ensure that the redacted API keys are not overwritten in the DB for (let uuid in existingConfig.config) { - if (config[uuid]?.apiKey === PASSWORD_REPLACEMENT) { - config[uuid].apiKey = existingConfig.config[uuid].apiKey + if (configToSave[uuid]?.apiKey === PASSWORD_REPLACEMENT) { + configToSave[uuid].apiKey = existingConfig.config[uuid].apiKey } } } @@ -351,7 +352,7 @@ async function enrichAIConfig(aiConfig: AIConfig) { provider: "OpenAI", active: true, isDefault: !defaultConfigExists, - defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL, + defaultModel: env.BUDIBASE_AI_DEFAULT_MODEL || "", name: "Budibase AI", } } diff --git a/packages/worker/src/api/controllers/global/tests/configs.spec.ts b/packages/worker/src/api/controllers/global/tests/configs.spec.ts index 1a6e6b7075..06d1ad0b2f 100644 --- a/packages/worker/src/api/controllers/global/tests/configs.spec.ts +++ b/packages/worker/src/api/controllers/global/tests/configs.spec.ts @@ -1,6 +1,7 @@ import * as pro from "@budibase/pro" import { verifyAIConfig } from "../configs" import { TestConfiguration, structures } from "../../../../tests" +import { AIInnerConfig } from "@budibase/types" describe("Global configs controller", () => { const config = new TestConfiguration() @@ -29,8 +30,8 @@ describe("Global configs controller", () => { defaultModel: "gpt4", isDefault: false, name: "Test", - provider: "OpenAI" - } + provider: "OpenAI", + }, }) }) @@ -56,7 +57,7 @@ describe("Global configs controller", () => { defaultModel: "gpt4", isDefault: false, name: "Test", - provider: "OpenAI" + provider: "OpenAI", }, }) }) @@ -77,7 +78,7 @@ describe("Global configs controller", () => { defaultModel: "gpt4", isDefault: false, name: "Test", - provider: "OpenAI" + provider: "OpenAI", }, }) }) @@ -87,22 +88,18 @@ describe("Global configs controller", () => { await config.api.configs.saveConfig(data) const existingConfig = await config.api.configs.getAIConfig() - const newConfig = { - type: "ai", - config: { - aiconfig: { - provider: "OpenAI", - isDefault: true, - name: "MyConfig", - active: true, - defaultModel: "gpt4", - apiKey: "myapikey", - }, + const newConfig: AIInnerConfig = { + aiconfig: { + provider: "OpenAI", + isDefault: true, + name: "MyConfig", + active: true, + defaultModel: "gpt4", }, } - await verifyAIConfig(newConfig, existingConfig) + await verifyAIConfig(newConfig, existingConfig.body) // should be unchanged - expect(newConfig.config.aiconfig.apiKey).toEqual("myapikey") + expect(newConfig.aiconfig.apiKey).toEqual("myapikey") }) }) diff --git a/packages/worker/src/tests/api/configs.ts b/packages/worker/src/tests/api/configs.ts index c64419b490..e0c1c806af 100644 --- a/packages/worker/src/tests/api/configs.ts +++ b/packages/worker/src/tests/api/configs.ts @@ -30,7 +30,6 @@ export class ConfigAPI extends TestAPI { .expect("Content-Type", /json/) } - saveConfig = (data: any) => { return this.request .post(`/api/global/configs`) diff --git a/packages/worker/src/tests/structures/configs.ts b/packages/worker/src/tests/structures/configs.ts index e1fd835d41..9257e813cb 100644 --- a/packages/worker/src/tests/structures/configs.ts +++ b/packages/worker/src/tests/structures/configs.ts @@ -4,7 +4,8 @@ import { ConfigType, SMTPConfig, GoogleConfig, - OIDCConfig, AIConfig, + OIDCConfig, + AIConfig, } from "@budibase/types" export function oidc(conf?: any): OIDCConfig { @@ -95,6 +96,6 @@ export function ai(): AIConfig { apiKey: "abc123APIKey", baseUrl: "https://api.example.com", }, - } + }, } }