import {z} from 'zod' export type GetApiApiV1PoliciesArgs = {'X-Tenant-ID': string, type?: ('static' | 'dynamic') | undefined, enabled?: boolean | undefined, search?: string | undefined, page?: number | undefined, page_size?: number | undefined, sort_by?: ('name' | 'created_at' | 'updated_at' | 'priority') | undefined, sort_dir?: ('asc' | 'desc') | undefined}; export type GetApiApiV1PoliciesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const policy = z.object({id: z.string().optional(), policy_id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), type: z.enum(["static", "dynamic"]).optional(), category: z.string().optional(), tier: z.enum(["system", "organization", "tenant"]).optional(), pattern: z.string().optional(), action: z.enum(["block", "require_approval", "redact", "warn", "log"]).optional(), severity: z.enum(["critical", "high", "medium", "low"]).optional(), priority: z.number().int().optional(), enabled: z.boolean().optional(), conditions: z.array(z.object({})).optional(), actions: z.array(z.object({})).optional(), version: z.number().int().optional(), tenant_id: z.string().optional(), organization_id: z.string().optional(), created_by: z.string().optional(), created_at: z.string().optional(), updated_by: z.string().optional(), updated_at: z.string().optional()}); export const policiesListResponse = z.object({policies: z.array(policy).optional(), pagination: z.object({page: z.number().int().optional(), page_size: z.number().int().optional(), total_items: z.number().int().optional(), total_pages: z.number().int().optional()}).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 policies * * GET /api/v1/policies */ export const getApiApiV1Policies = async (args: GetApiApiV1PoliciesArgs, options?: GetApiApiV1PoliciesOptions) => { 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.type != null) query.append("type", String(args.type)) if (args.enabled != null) query.append("enabled", String(args.enabled)) if (args.search != null) query.append("search", String(args.search)) if (args.page != null) query.append("page", String(args.page)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_dir != null) query.append("sort_dir", String(args.sort_dir)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/policies${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(policiesListResponse, await res.json()) };