export type RESTPolicyRuleConfig = {id: number, comment?: string | undefined, from?: string | undefined, to?: string | undefined, ports?: string | undefined, action?: string | undefined, applications?: Array | undefined, disable?: boolean | undefined, cfg_type: string, priority?: number | undefined}; export type RESTPolicyRuleConfigData = {config: RESTPolicyRuleConfig, replicate?: boolean | undefined}; export type PatchApiPolicyRuleIdArgs = {'X-Auth-Token': string, id: number, body: RESTPolicyRuleConfigData}; export type PatchApiPolicyRuleIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Update policy rule * * PATCH /policy/rule/{id} */ export const patchApiPolicyRuleId = async (args: PatchApiPolicyRuleIdArgs, options: PatchApiPolicyRuleIdOptions) => { 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(/\/+$/, '')}/policy/rule/${encodeURIComponent(String(args.id))}${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 };