import {z} from 'zod' export type GetApiVendorsVendorIdArgs = {vendorId: string}; export type GetApiVendorsVendorIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const vendorAuthenticationMethod = z.enum(["AUTH_0", "AZURE_AD", "GOOGLE_WORKSPACE", "O_AUTH", "O365", "OKTA", "ONE_LOGIN", "OWA", "SSO", "USERNAME_PASSWORD", "OTHER"]); export const vendorStatus = z.enum(["MANAGED", "ARCHIVED", "IN_PROCUREMENT"]); export const vendorRiskLevel = z.enum(["CRITICAL", "HIGH", "LOW", "MEDIUM", "UNSCORED"]); export const countryCode = z.enum(["EUE", "AND", "ARE", "AFG", "ATG", "AIA", "ALB", "ARM", "AGO", "ATA", "ARG", "ASM", "AUT", "AUS", "ABW", "ALA", "AZE", "BIH", "BRB", "BGD", "BEL", "BFA", "BGR", "BHR", "BDI", "BEN", "BLM", "BMU", "BRN", "BOL", "BES", "BRA", "BHS", "BTN", "BVT", "BWA", "BLR", "BLZ", "CAN", "CCK", "COD", "CAF", "COG", "CHE", "CIV", "COK", "CHL", "CMR", "CHN", "COL", "CRI", "CUB", "CPV", "CUW", "CXR", "CYP", "CZE", "DEU", "DJI", "DNK", "DMA", "DOM", "DZA", "ECU", "EST", "EGY", "ESH", "ERI", "ESP", "ETH", "FIN", "FJI", "FLK", "FSM", "FRO", "FRA", "GAB", "ENG", "SCT", "GBR", "WAL", "NIR", "GRD", "GEO", "GUF", "GGY", "GHA", "GIB", "GRL", "GMB", "GIN", "GLP", "GNQ", "GRC", "SGS", "GTM", "GUM", "GNB", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IRL", "ISR", "IMN", "IND", "IOT", "IRQ", "IRN", "ISL", "ITA", "JEY", "JAM", "JOR", "JPN", "KEN", "KGZ", "KHM", "KIR", "COM", "KNA", "PRK", "KOR", "KWT", "CYM", "KAZ", "LAO", "LBN", "LCA", "LIE", "LKA", "LBR", "LSO", "LTU", "LUX", "LVA", "LBY", "MAR", "MCO", "MDA", "MNE", "MAF", "MDG", "MHL", "MKD", "MLI", "MMR", "MNG", "MAC", "MNP", "MTQ", "MRT", "MSR", "MLT", "MUS", "MDV", "MWI", "MEX", "MYS", "MOZ", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NLD", "NOR", "NPL", "NRU", "NIU", "NZL", "OMN", "PAN", "PER", "PYF", "PNG", "PHL", "PAK", "POL", "SPM", "PCN", "PRI", "PSE", "PRT", "PLW", "PRY", "QAT", "REU", "ROU", "SRB", "RUS", "RWA", "SAU", "SLB", "SYC", "SDN", "SWE", "SGP", "SHN", "SVN", "SJM", "SVK", "SLE", "SMR", "SEN", "SOM", "SUR", "SSD", "STP", "SLV", "SXM", "SYR", "SWZ", "TCA", "TCD", "ATF", "TGO", "THA", "TJK", "TKL", "TLS", "TKM", "TUN", "TON", "TUR", "TTO", "TUV", "TWN", "TZA", "UKR", "UGA", "UMI", "USA", "URY", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "YEM", "MYT", "ZAF", "ZMB", "ZWE"]); export const currencyCode = z.enum(["ARS", "AUD", "BRL", "CAD", "COP", "CZK", "DKK", "EUR", "GBP", "ILS", "INR", "JPY", "MXN", "NOK", "NZD", "PHP", "PKR", "PLN", "RSD", "SEK", "SGD", "UAH", "USD", "ZAR"]); export const vendorContractAmount = z.object({amount: z.number(), currency: currencyCode}); export const customField = z.object({label: z.string(), value: z.union([z.string(), z.array(z.string())])}); export const vendorDecisionStatus = z.enum(["APPROVED", "CONDITIONALLY_APPROVED", "NOT_APPROVED"]); export const vendorDecision = z.object({status: vendorDecisionStatus, lastUpdatedAt: z.string()}); export const vendor = z.object({id: z.string(), name: z.string(), websiteUrl: z.string().nullable(), accountManagerName: z.string().nullable(), accountManagerEmail: z.string().nullable(), servicesProvided: z.string().nullable(), additionalNotes: z.string().nullable(), securityOwnerUserId: z.string().nullable(), businessOwnerUserId: z.string().nullable(), contractStartDate: z.string().nullable(), contractRenewalDate: z.string().nullable(), contractTerminationDate: z.string().nullable(), nextSecurityReviewDueDate: z.string().nullable(), lastSecurityReviewCompletionDate: z.string().nullable(), isVisibleToAuditors: z.boolean().nullable(), isRiskAutoScored: z.boolean().nullable(), riskAttributeIds: z.array(z.string()), category: z.object({displayName: z.string()}).nullable(), authDetails: z.object({passwordMinimumLength: z.number().nullable(), passwordRequiresSymbol: z.boolean().nullable(), passwordRequiresNumber: z.boolean().nullable(), passwordMFA: z.boolean().nullable(), method: vendorAuthenticationMethod.nullable()}), status: vendorStatus, inherentRiskLevel: vendorRiskLevel, residualRiskLevel: vendorRiskLevel, vendorHeadquarters: countryCode.nullable(), contractAmount: vendorContractAmount.nullable(), customFields: z.array(customField).nullable(), latestDecision: vendorDecision.nullable(), linkedTaskTrackerTaskProcurementRequest: z.object({url: z.string(), service: 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 vendor by ID * * GET /vendors/{vendorId} */ export const getApiVendorsVendorId = async (args: GetApiVendorsVendorIdArgs, options?: GetApiVendorsVendorIdOptions) => { 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(/\/+$/, '')}/vendors/${encodeURIComponent(String(args.vendorId))}${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(vendor, await res.json()) };