import {z} from 'zod' export type ControlDomain = 'ARTIFICIAL_&_AUTONOMOUS_TECHNOLOGY' | 'ASSET_MANAGEMENT' | 'BUSINESS_CONTINUITY_&_DISASTER_RECOVERY' | 'CAPACITY_&_PERFORMANCE_PLANNING' | 'CHANGE_MANAGEMENT' | 'CLOUD_SECURITY' | 'COMPLIANCE' | 'CONFIGURATION_MANAGEMENT' | 'CONTINUOUS_MONITORING' | 'CRYPTOGRAPHIC_PROTECTIONS' | 'DATA_CLASSIFICATION_&_HANDLING' | 'EMBEDDED_TECHNOLOGY' | 'ENDPOINT_SECURITY' | 'HUMAN_RESOURCES_SECURITY' | 'IDENTIFICATION_&_AUTHENTICATION' | 'INCIDENT_RESPONSE' | 'INFORMATION_ASSURANCE' | 'MAINTENANCE' | 'MOBILE_DEVICE_MANAGEMENT' | 'NETWORK SECURITY' | 'PHYSICAL_&_ENVIRONMENTAL_SECURITY' | 'PRIVACY' | 'PROJECT_&_RESOURCE MANAGEMENT' | 'RISK_MANAGEMENT' | 'SECURE_ENGINEERING_&_ARCHITECTURE' | 'SECURITY_AWARENESS_&_TRAINING' | 'SECURITY_OPERATIONS' | 'SECURITY_&_PRIVACY_GOVERNANCE' | 'TECHNOLOGY_DEVELOPMENT_&_ACQUISITION' | 'THIRD-PARTY_MANAGEMENT' | 'THREAT_MANAGEMENT' | 'VULNERABILITY_&_PATCH_MANAGEMENT' | 'WEB_SECURITY' | 'ADMINISTRATIVE' | 'PHYSICAL' | 'TECHNICAL' | 'BASIC' | 'DERIVED'; export type FrameworkId = 'AU_E_8' | 'AWS_FTR' | 'CCPA' | 'CIS_V8' | 'CPS_234' | 'DORA' | 'FEDRAMP' | 'GDPR' | 'HIPAA' | 'HITRUST_E1' | 'ISO_27001' | 'ISO_27001_2022' | 'ISO_27017' | 'ISO_27018' | 'ISO_27701' | 'ISO_42001' | 'ISO_9001' | 'MSFT_SSPA' | 'MVSP' | 'NIS_2D' | 'NIST_171' | 'NIST_171_R3' | 'NIST_53' | 'NIST_AI_RMF' | 'NIST_CSF' | 'NIST_CSF_2' | 'OFDSS' | 'PCI_SAQ_A' | 'PCI_SAQ_A_EP' | 'PCI_SAQ_D_MERCHANT' | 'PCI_SAQ_D_SP' | 'PCI_DDS_4' | 'SOC_2' | 'SOX_ITGC' | 'UK_CYBER_ESSENTIALS' | 'US_DATA_PRIVACY'; export type FrameworkSection = {frameworkId: FrameworkId | string, sectionId: string}; export type GdprRole = 'BOTH' | 'CONTROLLER' | 'PROCESSOR'; export type CreateCustomControlInput = {externalId: string, name: string | null, description: string, effectiveDate: string, category: ControlDomain, sections?: (Array | null) | undefined, role?: (GdprRole | null) | undefined}; export type CreateApiAuditsAuditIdControlsCustomControlsArgs = {auditId: string, body: CreateCustomControlInput}; export type CreateApiAuditsAuditIdControlsCustomControlsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const controlSource = z.enum(["Vanta", "Custom"]); export const owner = z.object({id: z.string(), displayName: z.string(), emailAddress: z.string()}); export const customField = z.object({label: z.string(), value: z.union([z.string(), z.array(z.string())])}); export const control = z.object({id: z.string(), externalId: z.string().nullable(), name: z.string(), description: z.string(), source: controlSource, domains: z.array(z.string()), owner: owner.nullable(), role: z.string().nullable().optional(), customFields: z.array(customField), creationDate: z.string().nullable(), modificationDate: 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 }; /** * Create a custom control for an audit * * POST /audits/{auditId}/controls/custom-controls */ export const createApiAuditsAuditIdControlsCustomControls = async (args: CreateApiAuditsAuditIdControlsCustomControlsArgs, options?: CreateApiAuditsAuditIdControlsCustomControlsOptions) => { 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(/\/+$/, '')}/audits/${encodeURIComponent(String(args.auditId))}/controls/custom-controls${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(control, await res.json()) };