import {z} from 'zod' export type VendorAuthenticationMethod = 'AUTH_0' | 'AZURE_AD' | 'GOOGLE_WORKSPACE' | 'O_AUTH' | 'O365' | 'OKTA' | 'ONE_LOGIN' | 'OWA' | 'SSO' | 'USERNAME_PASSWORD' | 'OTHER'; export type VendorStatus = 'MANAGED' | 'ARCHIVED' | 'IN_PROCUREMENT'; export type VendorRiskLevel = 'CRITICAL' | 'HIGH' | 'LOW' | 'MEDIUM' | 'UNSCORED'; export type CountryCode = '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 type CurrencyCode = '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 type VendorContractAmount = {amount: number, currency: CurrencyCode}; export type CustomField = {label: string, value: string | Array}; export type VendorFrameworkScope = {scopeType: 'ALL' | 'PARTIAL' | 'NONE', frameworkIds?: Array | undefined}; export type UpdateVendorInput = {name?: string | undefined, websiteUrl?: (string | null) | undefined, accountManagerName?: (string | null) | undefined, accountManagerEmail?: string | undefined, securityOwnerUserId?: (string | null) | undefined, servicesProvided?: (string | null) | undefined, additionalNotes?: (string | null) | undefined, businessOwnerUserId?: (string | null) | undefined, contractStartDate?: (string | null) | undefined, contractRenewalDate?: (string | null) | undefined, contractTerminationDate?: (string | null) | undefined, isVisibleToAuditors?: boolean | undefined, authDetails?: ({passwordMinimumLength?: number | undefined, passwordRequiresSymbol?: boolean | undefined, passwordRequiresNumber?: boolean | undefined, passwordMFA?: boolean | undefined, method?: (VendorAuthenticationMethod | null) | undefined}) | undefined, status?: VendorStatus | undefined, category?: string | undefined, inherentRiskLevel?: (VendorRiskLevel | null) | undefined, residualRiskLevel?: VendorRiskLevel | undefined, riskAttributeIds?: Array | undefined, vendorHeadquarters?: (CountryCode | null) | undefined, contractAmount?: (VendorContractAmount | null) | undefined, customFields?: Array | undefined, frameworkScope?: VendorFrameworkScope | undefined}; export type PatchApiVendorsVendorIdArgs = {vendorId: string, body: UpdateVendorInput}; export type PatchApiVendorsVendorIdOptions = {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 }; /** * Update vendor by ID * * PATCH /vendors/{vendorId} */ export const patchApiVendorsVendorId = async (args: PatchApiVendorsVendorIdArgs, options?: PatchApiVendorsVendorIdOptions) => { const {baseUrl = "https://api.vanta.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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: "PATCH", 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(vendor, await res.json()) };