export type SystemConfigCorsRequest = {allowed_headers?: Array | undefined, allowed_origins?: Array | undefined, enable?: boolean | undefined}; export type CreateApiSysConfigCorsArgs = {body: SystemConfigCorsRequest}; export type CreateApiSysConfigCorsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Configure the CORS settings. * * POST /sys/config/cors */ export const createApiSysConfigCors = async (args: CreateApiSysConfigCorsArgs, options: CreateApiSysConfigCorsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/sys/config/cors${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };