import {z} from 'zod' export type GetApiAccountAuditeventsArgs = {userId?: string | undefined, eventType?: string | undefined, httpMethod?: string | undefined, controllerName?: string | undefined, actionName?: string | undefined, startDate?: string | undefined, endDate?: string | undefined, ipAddress?: string | undefined, responseCode?: string | undefined, limit?: number | undefined, page?: number | undefined}; export type GetApiAccountAuditeventsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const auditEvent = z.object({event_id: z.number().int().optional(), timestamp: z.string().optional(), event_type: z.string().nullable().optional(), user_id: z.string().nullable().optional(), user_name: z.string().nullable().optional(), account_id: z.string().nullable().optional(), ip_address: z.string().nullable().optional(), remote_ip_address: z.string().nullable().optional(), user_agent: z.string().nullable().optional(), response_code: z.string().nullable().optional(), duration: z.string().nullable().optional(), http_method: z.string().nullable().optional(), controller_name: z.string().nullable().optional(), action_name: z.string().nullable().optional(), app_id: z.string().nullable().optional(), geo_location: z.string().nullable().optional()}); export const getApiAccountAuditeventsResponse = z.array(auditEvent); 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 }; /** * Gets audit events for the account. * * GET /account/auditevents * * Also accepts auth: ApiKeyInHeader, ApiKeyInQuery */ export const getApiAccountAuditevents = async (args: GetApiAccountAuditeventsArgs, options?: GetApiAccountAuditeventsOptions) => { const {baseUrl = "https://api.reveldigital.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userId != null) query.append("userId", String(args.userId)) if (args.eventType != null) query.append("eventType", String(args.eventType)) if (args.httpMethod != null) query.append("httpMethod", String(args.httpMethod)) if (args.controllerName != null) query.append("controllerName", String(args.controllerName)) if (args.actionName != null) query.append("actionName", String(args.actionName)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.ipAddress != null) query.append("ipAddress", String(args.ipAddress)) if (args.responseCode != null) query.append("responseCode", String(args.responseCode)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/account/auditevents${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(getApiAccountAuditeventsResponse, await res.json()) };