export type RESTCLUSEventCondition = {type?: string | undefined, value?: string | undefined}; export type RESTResponseRule = {id: number, event: string, comment: string, group: string, conditions: Array, actions: Array, webhooks: Array, disable: boolean, cfg_type: string}; export type RESTResponseRuleInsert = {after?: number | undefined, rules: Array}; export type RESTResponseRuleActionData = {insert?: RESTResponseRuleInsert | undefined}; export type PatchApiResponseRuleArgs = {'X-Auth-Token': string, body: RESTResponseRuleActionData}; export type PatchApiResponseRuleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update response rule action * * PATCH /response/rule */ export const patchApiResponseRule = async (args: PatchApiResponseRuleArgs, options: PatchApiResponseRuleOptions) => { 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(/\/+$/, '')}/response/rule${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 };