import {z} from 'zod' export type GetApiV1AdminMonitorAuditLogsArgs = {actorId?: string | undefined, module?: string | undefined, action?: string | undefined, targetType?: string | undefined, targetId?: string | undefined, from?: string | undefined, to?: string | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiV1AdminMonitorAuditLogsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const adminV1AuditLogEntry = z.object({action: z.string().optional(), actorAccountType: z.number().int().optional(), actorEmail: z.string().optional(), actorId: z.string().optional(), actorName: z.string().optional(), actorRole: z.string().optional(), after: z.string().optional(), before: z.string().optional(), createdAt: z.string().optional(), errMsg: z.string().optional(), id: z.string().optional(), ip: z.string().optional(), module: z.string().optional(), page: z.string().optional(), result: z.string().optional(), source: z.string().optional(), targetId: z.string().optional(), targetName: z.string().optional(), targetType: z.string().optional()}); export const adminV1ListAuditLogsReply = z.object({items: z.array(adminV1AuditLogEntry).optional(), page: z.number().int().optional(), size: z.number().int().optional(), total: z.string().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 /v1/admin/monitor/audit-logs */ export const getApiV1AdminMonitorAuditLogs = async (args: GetApiV1AdminMonitorAuditLogsArgs, options: GetApiV1AdminMonitorAuditLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.actorId != null) query.append("actorId", String(args.actorId)) if (args.module != null) query.append("module", String(args.module)) if (args.action != null) query.append("action", String(args.action)) if (args.targetType != null) query.append("targetType", String(args.targetType)) if (args.targetId != null) query.append("targetId", String(args.targetId)) if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/monitor/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(adminV1ListAuditLogsReply, await res.json()) };