import {z} from 'zod' export type GetApiApiAuditLogsExportArgs = {format?: ('json' | 'jsonl' | 'syslog') | undefined, search?: string | undefined, actions?: string | undefined, outcomes?: string | undefined, event_types?: string | undefined, start_date?: string | undefined, end_date?: string | undefined, period?: string | undefined}; export type GetApiApiAuditLogsExportOptions = {baseUrl?: string | undefined, ManagementBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiAuditLogsExportResponse = z.string(); 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 * * GET /api/audit-logs/export */ export const getApiApiAuditLogsExport = async (args: GetApiApiAuditLogsExportArgs, options?: GetApiApiAuditLogsExportOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, ManagementBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.format != null) query.append("format", String(args.format)) if (args.search != null) query.append("search", String(args.search)) if (args.actions != null) query.append("actions", String(args.actions)) if (args.outcomes != null) query.append("outcomes", String(args.outcomes)) if (args.event_types != null) query.append("event_types", String(args.event_types)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.period != null) query.append("period", String(args.period)) if (ManagementBearerAuth !== undefined) headers.set('authorization', `Bearer ${ManagementBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/audit-logs/export${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(getApiApiAuditLogsExportResponse, await res.json()) };