import {z} from 'zod' export type CreateApiApiV1AuditExportArgs = {'X-Tenant-ID': string, format?: ('csv' | 'json') | undefined, body: {user_email?: string | undefined, client_id?: string | undefined, action?: string | undefined, session_id?: string | undefined, decision_id?: string | undefined, policy_name?: string | undefined, override_id?: string | undefined, start_time?: string | undefined, end_time?: string | undefined}}; export type CreateApiApiV1AuditExportOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const auditLogEntry = z.object({id: z.string().optional(), request_id: z.string().optional(), timestamp: z.string().optional(), user_id: z.number().int().optional(), user_email: z.string().optional(), user_role: z.string().optional(), client_id: z.string().optional(), tenant_id: z.string().optional(), org_id: z.string().optional(), request_type: z.string().optional(), query: z.string().optional(), query_hash: z.string().optional(), policy_decision: z.string().optional(), policy_details: z.record(z.string(), z.unknown()).optional(), provider: z.string().optional(), model: z.string().optional(), response_time_ms: z.number().int().optional(), tokens_used: z.number().int().optional(), cost: z.number().optional(), redacted_fields: z.array(z.string()).optional(), error_message: z.string().optional(), response_sample: z.string().optional(), compliance_flags: z.array(z.string()).optional(), security_metrics: z.record(z.string(), z.unknown()).optional(), decision_id: z.string().optional(), plane: z.string().optional(), correlation_id: z.string().optional(), transfer_basis: z.string().optional(), data_residency: z.string().optional(), session_id: z.string().optional()}); export const createApiApiV1AuditExportResponse = z.object({entries: z.array(auditLogEntry).optional(), count: z.number().int().optional(), truncated: z.boolean().optional(), row_cap: 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 }; /** * Export audit logs (CSV or JSON) * * POST /api/v1/audit/export */ export const createApiApiV1AuditExport = async (args: CreateApiApiV1AuditExportArgs, options?: CreateApiApiV1AuditExportOptions) => { const {baseUrl = "https://orchestrator.getaxonflow.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Tenant-ID'] != null) headers.set("X-Tenant-ID", String(args['X-Tenant-ID'])) if (args.format != null) query.append("format", String(args.format)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/audit/export${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 validateResponse(createApiApiV1AuditExportResponse, await res.json()) };