From 6d67a10b34a671ffc7224a71cbdafd0da81282bb Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 29 Nov 2024 14:33:47 +0000 Subject: [PATCH] Convert config endpoints to TS --- .../src/api/{configs.js => configs.ts} | 35 +++++++++++++++++-- packages/frontend-core/src/api/types.ts | 4 ++- 2 files changed, 35 insertions(+), 4 deletions(-) rename packages/frontend-core/src/api/{configs.js => configs.ts} (67%) diff --git a/packages/frontend-core/src/api/configs.js b/packages/frontend-core/src/api/configs.ts similarity index 67% rename from packages/frontend-core/src/api/configs.js rename to packages/frontend-core/src/api/configs.ts index 8d0d176a55..75f4cc66ec 100644 --- a/packages/frontend-core/src/api/configs.js +++ b/packages/frontend-core/src/api/configs.ts @@ -1,4 +1,33 @@ -export const buildConfigEndpoints = API => ({ +import { + Config, + ConfigType, + GetPublicOIDCConfigResponse, + GetPublicSettingsResponse, + OIDCLogosConfig, +} from "@budibase/types" +import { BaseAPIClient } from "./types" + +export interface ConfigEndpoints { + saveConfig: ( + config: Config + ) => Promise<{ type: ConfigType; _id: string; _rev: string }> + getConfig: (type: ConfigType) => Promise> + deleteConfig: (id: string, rev: string) => Promise<{ message: string }> + getTenantConfig: (tentantId: string) => Promise + getOIDCConfig: (tenantId: string) => Promise + getOIDCLogos: () => Promise> + + // Missing request or response types + getChecklist: (tenantId: string) => Promise + uploadLogo: (data: any) => Promise<{ message: string; url: string }> + uploadFavicon: (data: any) => Promise<{ message: string; url: string }> + uploadOIDCLogo: ( + name: string, + data: any + ) => Promise<{ message: string; url: string }> +} + +export const buildConfigEndpoints = (API: BaseAPIClient): ConfigEndpoints => ({ /** * Saves a global config. * @param config the config to save @@ -25,7 +54,7 @@ export const buildConfigEndpoints = API => ({ * @param id the id of the config to delete * @param rev the revision of the config to delete */ - deleteConfig: async ({ id, rev }) => { + deleteConfig: async (id, rev) => { return await API.delete({ url: `/api/global/configs/${id}/${rev}`, }) @@ -90,7 +119,7 @@ export const buildConfigEndpoints = API => ({ * @param name the name of the OIDC provider * @param data the logo form data to upload */ - uploadOIDCLogo: async ({ name, data }) => { + uploadOIDCLogo: async (name, data) => { return await API.post({ url: `/api/global/configs/upload/logos_oidc/${name}`, body: data, diff --git a/packages/frontend-core/src/api/types.ts b/packages/frontend-core/src/api/types.ts index 9277d9097a..acc3586f88 100644 --- a/packages/frontend-core/src/api/types.ts +++ b/packages/frontend-core/src/api/types.ts @@ -6,6 +6,7 @@ import { AuditLogEndpoints } from "./auditLogs" import { AuthEndpoints } from "./auth" import { AutomationEndpoints } from "./automations" import { BackupEndpoints } from "./backups" +import { ConfigEndpoints } from "./configs" export enum HTTPMethod { POST = "POST", @@ -56,4 +57,5 @@ export type APIClient = BaseAPIClient & AuditLogEndpoints & AuthEndpoints & AutomationEndpoints & - BackupEndpoints & { [key: string]: any } + BackupEndpoints & + ConfigEndpoints & { [key: string]: any }