import {z} from 'zod' export type GetApiCabinetAdminRbacAuditLogExportArgs = {user_id?: (number | null) | undefined, action?: (string | null) | undefined, resource_type?: (string | null) | undefined, status?: (string | null) | undefined, date_from?: (string | null) | undefined, date_to?: (string | null) | undefined, limit?: number | undefined}; export type GetApiCabinetAdminRbacAuditLogExportOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCabinetAdminRbacAuditLogExportResponse = z.unknown(); 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 /cabinet/admin/rbac/audit-log/export */ export const getApiCabinetAdminRbacAuditLogExport = async (args: GetApiCabinetAdminRbacAuditLogExportArgs, options: GetApiCabinetAdminRbacAuditLogExportOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.user_id != null) query.append("user_id", String(args.user_id)) if (args.action != null) query.append("action", String(args.action)) if (args.resource_type != null) query.append("resource_type", String(args.resource_type)) if (args.status != null) query.append("status", String(args.status)) if (args.date_from != null) query.append("date_from", String(args.date_from)) if (args.date_to != null) query.append("date_to", String(args.date_to)) if (args.limit != null) query.append("limit", String(args.limit)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cabinet/admin/rbac/audit-log/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(getApiCabinetAdminRbacAuditLogExportResponse, await res.json()) };