import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type GetApiVendorsVendorIdFindingsArgs = {vendorId: string, pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, securityReviewId?: string | undefined, documentId?: string | undefined}; export type GetApiVendorsVendorIdFindingsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const findingRiskStatus = z.enum(["ACCEPT", "REMEDIATE", "NONE"]); export const findingRemediationState = z.enum(["OPEN", "CLOSED"]); export const vendorFinding = z.object({id: z.string(), vendorId: z.string(), securityReviewId: z.string().nullable(), documentId: z.string().nullable(), content: z.string(), riskStatus: findingRiskStatus, remediation: z.object({state: findingRemediationState, requirementNotes: z.string().nullable()}).nullable()}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedResponseVendorFinding = z.object({results: z.object({data: z.array(vendorFinding), pageInfo: pageInfo})}); 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 }; /** * List vendor findings * * GET /vendors/{vendorId}/findings */ export const getApiVendorsVendorIdFindings = async (args: GetApiVendorsVendorIdFindingsArgs, options?: GetApiVendorsVendorIdFindingsOptions) => { 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 (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.securityReviewId != null) query.append("securityReviewId", String(args.securityReviewId)) if (args.documentId != null) query.append("documentId", String(args.documentId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/vendors/${encodeURIComponent(String(args.vendorId))}/findings${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(paginatedResponseVendorFinding, await res.json()) };