import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type AuditIntegrationTag = 'ACCESS' | 'COMPUTERS' | 'CUSTOM_RESOURCE' | 'DATA_LOSS_PREVENTION' | 'DOCUMENTS' | 'DOCUMENT_UPLOAD' | 'FRAMEWORK' | 'GROUPS' | 'INVENTORY' | 'NOTIFICATIONS' | 'PEOPLE' | 'POLICIES' | 'SECURITY_AWARENESS_TRAINING' | 'SECURITY_SCANNER_ALERTS' | 'SSO' | 'TASK_CREATION' | 'TASK_TRACKING' | 'TRUST_CENTER' | 'VENDOR_DISCOVERY' | 'VENDOR_PROCUREMENT' | 'VULNERABILITIES'; export type AuditIntegrationCategory = 'ATS_MERGE_ACCOUNT' | 'BACKGROUND_CHECK_SERVICE' | 'CLOUD_PROVIDER' | 'COMMUNICATION_PLATFORM' | 'CRM_MERGE_ACCOUNT' | 'CRM_PLATFORM' | 'DATASTORE_PROVIDER' | 'DATA_LOSS_PREVENTION' | 'DATA_WAREHOUSE_PROVIDER' | 'DOCUMENT_MANAGEMENT_TOOL' | 'ENDPOINT_SECURITY_TOOL' | 'HR_PROVIDER' | 'IDENTITY_PROVIDER' | 'INCIDENT_MANAGEMENT_TOOL' | 'MOBILE_DEVICE_MANAGEMENT_TOOL' | 'MONITORING_SERVICE' | 'OTHER_INTEGRATION' | 'SECURITY_AWARENESS_TRAINING_PROVIDER' | 'SECURITY_SCANNER_ALERTS' | 'TASK_TRACKER' | 'VERSION_CONTROL_SYSTEM' | 'VULNERABILITY_SCANNER'; export type GetApiAuditsAuditIdIntegrationsArgs = {auditId: string, pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, search?: string | undefined, tagsMatchesAny?: Array | undefined, categoriesMatchesAny?: Array | undefined}; export type GetApiAuditsAuditIdIntegrationsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const auditIntegration = z.object({id: z.string(), name: z.string(), tags: z.array(z.string()).optional(), categories: z.array(z.string()).optional()}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedResponseAuditIntegration = z.object({results: z.object({data: z.array(auditIntegration), 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 integrations for an audit * * GET /audits/{auditId}/integrations */ export const getApiAuditsAuditIdIntegrations = async (args: GetApiAuditsAuditIdIntegrationsArgs, options?: GetApiAuditsAuditIdIntegrationsOptions) => { 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.search != null) query.append("search", String(args.search)) for (const item of args.tagsMatchesAny ?? []) query.append("tagsMatchesAny", String(item)) for (const item of args.categoriesMatchesAny ?? []) query.append("categoriesMatchesAny", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/audits/${encodeURIComponent(String(args.auditId))}/integrations${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(paginatedResponseAuditIntegration, await res.json()) };