From 60e4d3f0e6dedb16cc5e9f9dd53ec8bf62231c92 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 5 Dec 2024 14:50:50 +0000 Subject: [PATCH] Config API typing. --- packages/types/src/api/web/global/configs.ts | 39 ++++++++++++++++++- .../src/api/controllers/global/configs.ts | 20 +++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/types/src/api/web/global/configs.ts b/packages/types/src/api/web/global/configs.ts index b36d974904..e16ed3c27f 100644 --- a/packages/types/src/api/web/global/configs.ts +++ b/packages/types/src/api/web/global/configs.ts @@ -1,4 +1,10 @@ -import { SettingsConfig, SettingsInnerConfig } from "../../../documents" +import { + Config, + ConfigType, + SettingsBrandingConfig, + SettingsConfig, + SettingsInnerConfig, +} from "../../../documents" /** * Settings that aren't stored in the database - enriched at runtime. @@ -22,3 +28,34 @@ export interface PublicOIDCConfig { } export type GetPublicOIDCConfigResponse = PublicOIDCConfig[] + +export interface SaveConfigRequest extends Config {} +export interface SaveConfigResponse { + type: ConfigType + _id: string + _rev: string +} + +export interface DeleteConfigResponse { + message: string +} + +interface ChecklistItem { + checked: boolean + label: string + link: string +} +export interface ConfigChecklistResponse { + apps: ChecklistItem + smtp: ChecklistItem + adminUser: ChecklistItem + sso: ChecklistItem + branding: SettingsBrandingConfig +} + +export type FindConfigResponse = Config | {} + +export interface UploadConfigFileResponse { + message: string + url: string +} diff --git a/packages/worker/src/api/controllers/global/configs.ts b/packages/worker/src/api/controllers/global/configs.ts index b3f02a44c6..a10fce35f6 100644 --- a/packages/worker/src/api/controllers/global/configs.ts +++ b/packages/worker/src/api/controllers/global/configs.ts @@ -15,8 +15,11 @@ import { AIConfig, AIInnerConfig, Config, + ConfigChecklistResponse, ConfigType, Ctx, + DeleteConfigResponse, + FindConfigResponse, GetPublicOIDCConfigResponse, GetPublicSettingsResponse, GoogleInnerConfig, @@ -29,11 +32,14 @@ import { OIDCLogosConfig, PASSWORD_REPLACEMENT, QuotaUsageType, + SaveConfigRequest, + SaveConfigResponse, SettingsBrandingConfig, SettingsInnerConfig, SSOConfig, SSOConfigType, StaticQuotaName, + UploadConfigFileResponse, UserCtx, } from "@budibase/types" import * as pro from "@budibase/pro" @@ -225,7 +231,9 @@ export async function verifyAIConfig( } } -export async function save(ctx: UserCtx) { +export async function save( + ctx: UserCtx +) { const body = ctx.request.body const type = body.type const config = body.config @@ -337,7 +345,7 @@ function enrichOIDCLogos(oidcLogos: OIDCLogosConfig) { ) } -export async function find(ctx: UserCtx) { +export async function find(ctx: UserCtx) { try { // Find the config with the most granular scope based on context const type = ctx.params.type @@ -473,7 +481,7 @@ export async function publicSettings( } } -export async function upload(ctx: UserCtx) { +export async function upload(ctx: UserCtx) { if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) { ctx.throw(400, "One file must be uploaded.") } @@ -518,7 +526,7 @@ export async function upload(ctx: UserCtx) { } } -export async function destroy(ctx: UserCtx) { +export async function destroy(ctx: UserCtx) { const db = tenancy.getGlobalDB() const { id, rev } = ctx.params try { @@ -537,14 +545,14 @@ export async function destroy(ctx: UserCtx) { } } -export async function configChecklist(ctx: Ctx) { +export async function configChecklist(ctx: Ctx) { const tenantId = tenancy.getTenantId() try { ctx.body = await cache.withCache( cache.CacheKey.CHECKLIST, env.CHECKLIST_CACHE_TTL, - async () => { + async (): Promise => { let apps = [] if (!env.MULTI_TENANCY || tenantId) { // Apps exist