export type RESTCustomCheck = {name: string, script: string}; export type RESTCustomChecks = {group: string, scripts: Array}; export type RESTCustomCheckConfig = {add: RESTCustomChecks, delete: RESTCustomChecks, update: RESTCustomChecks}; export type RESTCustomCheckConfigData = {config: RESTCustomCheckConfig}; export type PatchApiCustomCheckGroupArgs = {'X-Auth-Token': string, group: string, body: RESTCustomCheckConfigData}; export type PatchApiCustomCheckGroupOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update custom check scripts of the specified group * * PATCH /custom_check/{group} */ export const patchApiCustomCheckGroup = async (args: PatchApiCustomCheckGroupArgs, options: PatchApiCustomCheckGroupOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Auth-Token'] != null) headers.set("X-Auth-Token", String(args['X-Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/custom_check/${encodeURIComponent(String(args.group))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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 };