import {z} from 'zod' export type GetApiApiV1OverridesArgs = {'X-Tenant-ID': string, policy_id?: string | undefined, include_revoked?: boolean | undefined}; export type GetApiApiV1OverridesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const overrideSummary = z.object({id: z.string(), policy_id: z.string(), policy_type: z.string(), tenant_id: z.string().optional(), org_id: z.string(), organization_id: z.string(), action_override: z.string().optional(), enabled_override: z.boolean().optional(), override_reason: z.string(), expires_at: z.string().optional(), tool_signature: z.string().optional(), created_by: z.string(), created_at: z.string(), revoked_at: z.string().optional(), revoked_by: z.string().optional()}); export const getApiApiV1OverridesResponse = z.object({overrides: z.array(overrideSummary).optional(), count: z.number().int().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List policy overrides * * GET /api/v1/overrides */ export const getApiApiV1Overrides = async (args: GetApiApiV1OverridesArgs, options?: GetApiApiV1OverridesOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args.policy_id != null) query.append("policy_id", String(args.policy_id)) if (args.include_revoked != null) query.append("include_revoked", String(args.include_revoked)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/overrides${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiApiV1OverridesResponse, await res.json()) };