import {z} from 'zod' export type ProcessActionParams = {cond_name?: number | undefined, is_blocked?: string | undefined, process_id?: number | undefined, rank?: number | undefined}; export type CreateApiV1ThreatLibraryActionsArgs = {body: {action_result?: string | undefined, affected_os?: Array | undefined, affected_platform_ids?: Array | undefined, attack_module?: string | undefined, category?: string | undefined, description?: string | undefined, is_privileged?: boolean | undefined, is_sensitive_content?: boolean | undefined, keyword?: string | undefined, name?: string | undefined, play_processes?: Array | undefined, process_result?: string | undefined, remote_file_ids?: Array | undefined, rewind_processes?: Array | undefined, sources?: Array | undefined, tactic_id?: number | undefined, tags?: Array | undefined, technique_id?: number | undefined, title?: string | undefined, ukc_phase_id?: number | undefined, url?: string | undefined, url_category?: string | undefined, use_case?: string | undefined}}; export type CreateApiV1ThreatLibraryActionsOptions = {baseUrl?: string | undefined, AccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const capiActionDTO = z.object({created_at: z.string().optional(), description: z.string().optional(), display_id: z.number().int().optional(), id: z.number().int().optional(), name: z.string().optional(), tags: z.array(z.string()).optional()}); export const createApiV1ThreatLibraryActionsResponse = z.object({action: capiActionDTO.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 }; /** * You can refer to following link for string parameters * https://support.picussecurity.com/hc/en-us/articles/36765648951837 * * POST /v1/threat-library/actions */ export const createApiV1ThreatLibraryActions = async (args: CreateApiV1ThreatLibraryActionsArgs, options?: CreateApiV1ThreatLibraryActionsOptions) => { const {baseUrl = "https://api.picussecurity.com", fetch: fetchFn = fetch, AccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (AccessToken !== undefined) headers.set("Authorization", AccessToken) const url = `${baseUrl.replace(/\/+$/, '')}/v1/threat-library/actions${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(createApiV1ThreatLibraryActionsResponse, await res.json()) };