export type RESTPolicyRuleMove = {after?: number | undefined, id: number}; export type RESTPolicyRule = {id: number, comment: string, from: string, to: string, ports: string, action: string, applications: Array, learned: boolean, disable: boolean, created_timestamp: number, last_modified_timestamp: number, cfg_type: string, priority: number}; export type RESTPolicyRuleInsert = {after?: number | undefined, rules: Array}; export type RESTPolicyRuleActionData = {move?: RESTPolicyRuleMove | undefined, insert?: RESTPolicyRuleInsert | undefined, rules?: Array | undefined, delete?: Array | undefined}; export type PatchApiPolicyRuleArgs = {'X-Auth-Token': string, scope?: ('fed' | 'local') | undefined, body: RESTPolicyRuleActionData}; export type PatchApiPolicyRuleOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Policy rule action * * PATCH /policy/rule */ export const patchApiPolicyRule = async (args: PatchApiPolicyRuleArgs, options: PatchApiPolicyRuleOptions) => { 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(/\/+$/, '')}/policy/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 };