import {z} from 'zod' export type GetApiV1GovernanceAuditLogsArgs = {'X-Request-Id'?: string | undefined, actor?: string | undefined, date_from?: string | undefined, date_to?: string | undefined, action?: string | undefined, entity_type?: string | undefined, limit?: number | undefined, cursor?: string | undefined}; export type GetApiV1GovernanceAuditLogsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const auditLogResponse = z.object({action: z.string().optional(), actorId: z.string().optional(), changes: z.array(z.number().int()).optional(), createdAt: z.string().optional(), entityId: z.string().optional(), entityType: z.string().optional(), id: z.string().optional(), tenantId: z.string().optional(), truncated: z.boolean().optional(), originalSize: z.number().int().optional()}); export const listAuditLogsResponse = z.object({hasMore: z.boolean().optional(), items: z.array(auditLogResponse).optional(), limit: z.number().int().gte(1).lte(200).optional(), nextCursor: z.string().optional(), prevCursor: 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 }; /** * List audit logs * * GET /v1/governance/audit-logs */ export const getApiV1GovernanceAuditLogs = async (args: GetApiV1GovernanceAuditLogsArgs, options?: GetApiV1GovernanceAuditLogsOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args.actor != null) query.append("actor", String(args.actor)) 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.action != null) query.append("action", String(args.action)) if (args.entity_type != null) query.append("entity_type", String(args.entity_type)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/governance/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(listAuditLogsResponse, await res.json()) };