Config API typing.

This commit is contained in:
mike12345567 2024-12-05 14:50:50 +00:00
parent 73c5b2f729
commit 60e4d3f0e6
2 changed files with 52 additions and 7 deletions

View File

@ -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. * Settings that aren't stored in the database - enriched at runtime.
@ -22,3 +28,34 @@ export interface PublicOIDCConfig {
} }
export type GetPublicOIDCConfigResponse = 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
}

View File

@ -15,8 +15,11 @@ import {
AIConfig, AIConfig,
AIInnerConfig, AIInnerConfig,
Config, Config,
ConfigChecklistResponse,
ConfigType, ConfigType,
Ctx, Ctx,
DeleteConfigResponse,
FindConfigResponse,
GetPublicOIDCConfigResponse, GetPublicOIDCConfigResponse,
GetPublicSettingsResponse, GetPublicSettingsResponse,
GoogleInnerConfig, GoogleInnerConfig,
@ -29,11 +32,14 @@ import {
OIDCLogosConfig, OIDCLogosConfig,
PASSWORD_REPLACEMENT, PASSWORD_REPLACEMENT,
QuotaUsageType, QuotaUsageType,
SaveConfigRequest,
SaveConfigResponse,
SettingsBrandingConfig, SettingsBrandingConfig,
SettingsInnerConfig, SettingsInnerConfig,
SSOConfig, SSOConfig,
SSOConfigType, SSOConfigType,
StaticQuotaName, StaticQuotaName,
UploadConfigFileResponse,
UserCtx, UserCtx,
} from "@budibase/types" } from "@budibase/types"
import * as pro from "@budibase/pro" import * as pro from "@budibase/pro"
@ -225,7 +231,9 @@ export async function verifyAIConfig(
} }
} }
export async function save(ctx: UserCtx<Config>) { export async function save(
ctx: UserCtx<SaveConfigRequest, SaveConfigResponse>
) {
const body = ctx.request.body const body = ctx.request.body
const type = body.type const type = body.type
const config = body.config const config = body.config
@ -337,7 +345,7 @@ function enrichOIDCLogos(oidcLogos: OIDCLogosConfig) {
) )
} }
export async function find(ctx: UserCtx) { export async function find(ctx: UserCtx<void, FindConfigResponse>) {
try { try {
// Find the config with the most granular scope based on context // Find the config with the most granular scope based on context
const type = ctx.params.type 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<void, UploadConfigFileResponse>) {
if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) { if (ctx.request.files == null || Array.isArray(ctx.request.files.file)) {
ctx.throw(400, "One file must be uploaded.") 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<void, DeleteConfigResponse>) {
const db = tenancy.getGlobalDB() const db = tenancy.getGlobalDB()
const { id, rev } = ctx.params const { id, rev } = ctx.params
try { try {
@ -537,14 +545,14 @@ export async function destroy(ctx: UserCtx) {
} }
} }
export async function configChecklist(ctx: Ctx) { export async function configChecklist(ctx: Ctx<void, ConfigChecklistResponse>) {
const tenantId = tenancy.getTenantId() const tenantId = tenancy.getTenantId()
try { try {
ctx.body = await cache.withCache( ctx.body = await cache.withCache(
cache.CacheKey.CHECKLIST, cache.CacheKey.CHECKLIST,
env.CHECKLIST_CACHE_TTL, env.CHECKLIST_CACHE_TTL,
async () => { async (): Promise<ConfigChecklistResponse> => {
let apps = [] let apps = []
if (!env.MULTI_TENANCY || tenantId) { if (!env.MULTI_TENANCY || tenantId) {
// Apps exist // Apps exist