import {z} from 'zod' export type GetApiVulnerabilitiesVulnerabilityIdArgs = {vulnerabilityId: string}; export type GetApiVulnerabilitiesVulnerabilityIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const vulnerabilityType = z.enum(["CONFIGURATION", "COMMON", "GROUPED"]); export const externalFindingSeverityType = z.enum(["CRITICAL", "HIGH", "LOW", "MEDIUM"]); export const vulnerability = z.object({id: z.string(), name: z.string(), description: z.string(), integrationId: z.string(), packageIdentifier: z.string().nullable(), vulnerabilityType: vulnerabilityType, targetId: z.string(), firstDetectedDate: z.string(), sourceDetectedDate: z.string().nullable(), lastDetectedDate: z.string().nullable(), severity: externalFindingSeverityType, cvssSeverityScore: z.number().nullable(), scannerScore: z.number().nullable(), isFixable: z.boolean(), remediateByDate: z.string().nullable(), relatedVulns: z.array(z.string()), relatedUrls: z.array(z.string()), externalURL: z.string(), scanSource: z.string().optional(), deactivateMetadata: z.object({isVulnDeactivatedIndefinitely: z.boolean(), deactivatedUntilDate: z.string().nullable(), deactivationReason: z.string(), deactivatedOnDate: z.string(), deactivatedBy: z.string()}).nullable(), fixedVersion: z.string().nullable(), externalId: z.string().nullable()}); 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 vulnerability by ID * * GET /vulnerabilities/{vulnerabilityId} */ export const getApiVulnerabilitiesVulnerabilityId = async (args: GetApiVulnerabilitiesVulnerabilityIdArgs, options?: GetApiVulnerabilitiesVulnerabilityIdOptions) => { const {baseUrl = "https://api.vanta.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/vulnerabilities/${encodeURIComponent(String(args.vulnerabilityId))}${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(vulnerability, await res.json()) };