import {z} from 'zod' export type CreateApiApiV2RiskintelligenceVulnerabilitiesSearchArgs = {body: {GenericSearchText?: string | undefined, Cves?: (Array | null) | undefined, EcosystemIds?: (Array | null) | undefined, TagIds?: (Array | null) | undefined, CvssGreaterThan?: number | undefined, CvssLessThan?: number | undefined, EpssGreaterThan?: number | undefined, EpssLessThan?: number | undefined, CurrentExposureGreaterThan?: number | undefined, CurrentExposureLessThan?: number | undefined, ExploitabilityScoreGreaterThan?: number | undefined, ExploitabilityScoreLessThan?: number | undefined, AddedToKevDateFrom?: unknown | undefined, AddedToKevDateTo?: unknown | undefined, TagApplyDateFrom?: unknown | undefined, TagApplyDateTo?: unknown | undefined, TagExpiryDateFrom?: unknown | undefined, TagExpiryDateTo?: unknown | undefined, InKev?: boolean | undefined, ExploitPoC?: boolean | undefined, MentionedCyberSecCom?: boolean | undefined, ExploitedByThreatActors?: boolean | undefined, TagProcess?: string | undefined, ConfidenceLevel?: ('Low' | 'Medium' | 'High' | 'Very High') | undefined, Lev1LessThan?: number | undefined, Lev1GreaterThan?: number | undefined, Lev2LessThan?: number | undefined, Lev2GreaterThan?: number | undefined, TagConfidences?: (Array<'Low' | 'Medium' | 'High' | 'VeryHigh'> | null) | undefined}}; export type CreateApiApiV2RiskintelligenceVulnerabilitiesSearchOptions = {baseUrl?: string | undefined, OAuthv2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV2RiskintelligenceVulnerabilitiesSearchResponse = z.object({Key: z.string()}); 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 }; /** * Searches through the vulnerabilities. * * POST /api/v2/riskintelligence/vulnerabilities/search */ export const createApiApiV2RiskintelligenceVulnerabilitiesSearch = async (args: CreateApiApiV2RiskintelligenceVulnerabilitiesSearchArgs, options?: CreateApiApiV2RiskintelligenceVulnerabilitiesSearchOptions) => { const {baseUrl = "https://app.blackkitetech.com", fetch: fetchFn = fetch, OAuthv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuthv2 !== undefined) headers.set('authorization', `Bearer ${OAuthv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/riskintelligence/vulnerabilities/search${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(createApiApiV2RiskintelligenceVulnerabilitiesSearchResponse, await res.json()) };