import {z} from 'zod' export type FilterItem = {column?: string | undefined, type?: string | undefined, value?: string | undefined}; export type Filters = Array; export type CreateApiSmartfolderIdEditArgs = {id: number, body: {name?: string | undefined, description?: string | undefined, notifications?: (Array<{type: 'email' | 'slack' | 'servicenow', email?: string | undefined, webhookUrl?: string | undefined, enabled: boolean}>) | undefined, filters?: Filters | undefined, extra?: ({columns?: Array | undefined, view?: string | undefined, details?: string | undefined, exploit_cost?: number | undefined, fix_cost?: number | undefined, exploit_likelihood?: number | undefined, exploitation_duration?: number | undefined, severity?: ('CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW' | 'INFO') | undefined, groupByType?: ('id' | 'bd.original_hostname' | 'bd.ip_address') | undefined}) | undefined}}; export type CreateApiSmartfolderIdEditOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiSmartfolderIdEditResponse = z.object({affectedRows: 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 }; /** * Edit subscription by id * * POST /smartfolder/{id}/edit */ export const createApiSmartfolderIdEdit = async (args: CreateApiSmartfolderIdEditArgs, options?: CreateApiSmartfolderIdEditOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/smartfolder/${encodeURIComponent(String(args.id))}/edit${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(createApiSmartfolderIdEditResponse, await res.json()) };