import {z} from 'zod' export type GetApiApiV1AuditLogsArgs = {page_size?: number | undefined, cursor?: string | undefined, object_type: 'document' | 'annotation' | 'user', action?: string | undefined, object_id?: number | undefined, timestamp_before?: string | undefined, timestamp_after?: string | undefined, username?: string | undefined}; export type GetApiApiV1AuditLogsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const auditLogContent = z.object({path: z.string().optional(), method: z.string().optional(), request_id: z.string().optional(), status_code: z.number().int().optional(), details: z.object({payload: z.object({groups: z.array(z.string()).optional()}).optional()}).optional()}); export const auditLog = z.object({organization_id: z.number().int(), timestamp: z.string(), username: z.string(), object_id: z.number().int(), object_type: z.enum(["document", "annotation", "user"]), action: z.string(), content: auditLogContent}); export const getApiApiV1AuditLogsResponse = z.object({pagination: pagination, results: z.array(auditLog)}); 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 audit logs * * GET /api/v1/audit_logs */ export const getApiApiV1AuditLogs = async (args: GetApiApiV1AuditLogsArgs, options?: GetApiApiV1AuditLogsOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.object_type != null) query.append("object_type", String(args.object_type)) if (args.action != null) query.append("action", String(args.action)) if (args.object_id != null) query.append("object_id", String(args.object_id)) if (args.timestamp_before != null) query.append("timestamp_before", String(args.timestamp_before)) if (args.timestamp_after != null) query.append("timestamp_after", String(args.timestamp_after)) if (args.username != null) query.append("username", String(args.username)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/audit_logs${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(getApiApiV1AuditLogsResponse, await res.json()) };