export type SystemPolicyRequest = {policy?: string | undefined, rules?: string | undefined}; export type CreateApiSysPolicyNameArgs = {body: SystemPolicyRequest}; export type CreateApiSysPolicyNameOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Add a new or update an existing policy. * * POST /sys/policy/{name} */ export const createApiSysPolicyName = async (args: CreateApiSysPolicyNameArgs, options: CreateApiSysPolicyNameOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/sys/policy/${encodeURIComponent(String(args.name))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 };