export type RESTWebhook = {name: string, url: string, enable: boolean, type: string, cfg_type: string}; export type RESTSystemWebhookConfigData = {config: RESTWebhook}; export type PatchApiSystemConfigWebhookNameArgs = {'X-Auth-Token': string, name: string, scope?: ('fed' | 'local') | undefined, body: RESTSystemWebhookConfigData}; export type PatchApiSystemConfigWebhookNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Configure system webhook * * PATCH /system/config/webhook/{name} */ export const patchApiSystemConfigWebhookName = async (args: PatchApiSystemConfigWebhookNameArgs, options: PatchApiSystemConfigWebhookNameOptions) => { 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'])) if (args.scope != null) query.append("scope", String(args.scope)) const url = `${baseUrl.replace(/\/+$/, '')}/system/config/webhook/${encodeURIComponent(String(args.name))}${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 };