2024-11-29 15:33:47 +01:00
|
|
|
import {
|
|
|
|
Config,
|
|
|
|
ConfigType,
|
|
|
|
GetPublicOIDCConfigResponse,
|
|
|
|
GetPublicSettingsResponse,
|
|
|
|
OIDCLogosConfig,
|
|
|
|
} from "@budibase/types"
|
|
|
|
import { BaseAPIClient } from "./types"
|
|
|
|
|
|
|
|
export interface ConfigEndpoints {
|
|
|
|
saveConfig: <T>(
|
|
|
|
config: Config<T>
|
|
|
|
) => Promise<{ type: ConfigType; _id: string; _rev: string }>
|
|
|
|
getConfig: <T>(type: ConfigType) => Promise<Config<T>>
|
|
|
|
deleteConfig: (id: string, rev: string) => Promise<{ message: string }>
|
|
|
|
getTenantConfig: (tentantId: string) => Promise<GetPublicSettingsResponse>
|
|
|
|
getOIDCConfig: (tenantId: string) => Promise<GetPublicOIDCConfigResponse>
|
|
|
|
getOIDCLogos: () => Promise<Config<OIDCLogosConfig>>
|
|
|
|
|
|
|
|
// Missing request or response types
|
|
|
|
getChecklist: (tenantId: string) => Promise<any>
|
|
|
|
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 => ({
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
|
|
|
* Saves a global config.
|
|
|
|
* @param config the config to save
|
|
|
|
*/
|
|
|
|
saveConfig: async config => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/configs",
|
|
|
|
body: config,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a global config of a certain type.
|
|
|
|
* @param type the type to fetch
|
|
|
|
*/
|
|
|
|
getConfig: async type => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/configs/${type}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-05-12 17:57:05 +02:00
|
|
|
/**
|
2022-05-12 17:57:54 +02:00
|
|
|
* Deletes a global config
|
2022-05-12 17:57:05 +02:00
|
|
|
* @param id the id of the config to delete
|
|
|
|
* @param rev the revision of the config to delete
|
|
|
|
*/
|
2024-11-29 15:33:47 +01:00
|
|
|
deleteConfig: async (id, rev) => {
|
2022-05-12 17:57:05 +02:00
|
|
|
return await API.delete({
|
2022-05-12 17:57:54 +02:00
|
|
|
url: `/api/global/configs/${id}/${rev}`,
|
2022-05-12 17:57:05 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
|
|
|
* Gets the config for a certain tenant.
|
|
|
|
* @param tenantId the tenant ID to get the config for
|
|
|
|
*/
|
|
|
|
getTenantConfig: async tenantId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/configs/public?tenantId=${tenantId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the OIDC config for a certain tenant.
|
|
|
|
* @param tenantId the tenant ID to get the config for
|
|
|
|
*/
|
|
|
|
getOIDCConfig: async tenantId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/configs/public/oidc?tenantId=${tenantId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the checklist for a specific tenant.
|
|
|
|
* @param tenantId the tenant ID to get the checklist for
|
|
|
|
*/
|
|
|
|
getChecklist: async tenantId => {
|
|
|
|
return await API.get({
|
|
|
|
url: `/api/global/configs/checklist?tenantId=${tenantId}`,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the company logo for the environment.
|
|
|
|
* @param data the logo form data
|
|
|
|
*/
|
|
|
|
uploadLogo: async data => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/configs/upload/settings/logoUrl",
|
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2023-03-13 13:33:16 +01:00
|
|
|
/**
|
|
|
|
* Updates the company favicon for the environment.
|
|
|
|
* @param data the favicon form data
|
|
|
|
*/
|
|
|
|
uploadFavicon: async data => {
|
|
|
|
return await API.post({
|
|
|
|
url: "/api/global/configs/upload/settings/faviconUrl",
|
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-01-24 15:32:27 +01:00
|
|
|
/**
|
|
|
|
* Uploads a logo for an OIDC provider.
|
|
|
|
* @param name the name of the OIDC provider
|
|
|
|
* @param data the logo form data to upload
|
|
|
|
*/
|
2024-11-29 15:33:47 +01:00
|
|
|
uploadOIDCLogo: async (name, data) => {
|
2022-01-24 15:32:27 +01:00
|
|
|
return await API.post({
|
|
|
|
url: `/api/global/configs/upload/logos_oidc/${name}`,
|
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the list of OIDC logos.
|
|
|
|
*/
|
|
|
|
getOIDCLogos: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/global/configs/logos_oidc",
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|