import {z} from 'zod' export type GetApiManagementAuditLogsArgs = {startTime?: number | undefined, endTime?: number | undefined, timePeriod?: ('DAY' | 'WEEK') | undefined, category?: Array | undefined, subject?: Array | undefined, event?: Array | undefined, user?: Array | undefined, userId?: Array | undefined, order?: ('ASC' | 'DESC') | undefined, pageSize?: number | undefined, pageCursor?: string | undefined, cursor?: string | undefined}; export type GetApiManagementAuditLogsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const auditLogData = z.object({id: z.string().optional(), timestamp: z.number().optional(), createdAt: z.number().optional(), user: z.string().optional(), subject: z.string().optional(), event: z.string().optional(), category: z.string().optional(), tenantId: z.string().optional(), userId: z.string().optional()}); export const auditLogsData = z.array(auditLogData); export const getAuditLogsResponse = z.object({data: auditLogsData.optional(), next: z.string().nullable().optional(), cursor: z.string().nullable().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 }; /** * Get audit logs * * GET /management/audit_logs */ export const getApiManagementAuditLogs = async (args: GetApiManagementAuditLogsArgs, options?: GetApiManagementAuditLogsOptions) => { const {baseUrl = "https://api.fireblocks.io/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) if (args.timePeriod != null) query.append("timePeriod", String(args.timePeriod)) for (const item of args.category ?? []) query.append("category", String(item)) for (const item of args.subject ?? []) query.append("subject", String(item)) for (const item of args.event ?? []) query.append("event", String(item)) for (const item of args.user ?? []) query.append("user", String(item)) for (const item of args.userId ?? []) query.append("userId", String(item)) if (args.order != null) query.append("order", String(args.order)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.cursor != null) query.append("cursor", String(args.cursor)) const url = `${baseUrl.replace(/\/+$/, '')}/management/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(getAuditLogsResponse, await res.json()) };