import {z} from 'zod' export type FilterItem = {column?: string | undefined, type?: string | undefined, value?: string | undefined}; export type Filters = Array; export type CreateApiUserActionLogsArgs = {actor_id?: number | undefined, offset?: number | undefined, limit?: number | undefined, body: Filters}; export type CreateApiUserActionLogsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiUserActionLogsResponse = z.object({list: z.array(z.object({id: z.string().optional(), action: z.string().optional(), target: z.string().optional(), actor: z.string().optional(), actor_id: z.number().int().optional(), inventory_id: z.number().int().optional(), description_values: z.string().optional(), created_at: z.string().optional()})).optional(), total: z.number().int().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 user action logs from store. * * POST /user-action-logs */ export const createApiUserActionLogs = async (args: CreateApiUserActionLogsArgs, options?: CreateApiUserActionLogsOptions) => { const {baseUrl = "https://asm.cloud.tenable.com/api/1.0", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.actor_id != null) query.append("actor_id", String(args.actor_id)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/user-action-logs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiUserActionLogsResponse, await res.json()) };