import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type QuestionnaireStatus = 'APPROVED' | 'IN_PROGRESS' | 'IN_REVIEW' | 'READY_FOR_REVIEW' | 'WAITING_ON_ANSWERS' | 'ON_HOLD' | 'NO_LONGER_NEEDED' | 'COMPLETE' | 'ERROR' | 'EXTRACTING_QUESTIONS' | 'QUEUED_FOR_EXTRACTION' | 'PROCESSING' | 'QUEUED_FOR_PROCESSING' | 'WAITING_ON_COLUMN_SELECTION' | 'WAITING_ON_COLUMN_APPROVAL' | 'QUEUED_FOR_COLUMN_DETECTION' | 'DETECTING_COLUMNS'; export type CustomerTrustQuestionnaireType = 'SPREADSHEET' | 'WEBSITE' | 'DOCUMENT'; export type GetApiCustomerTrustQuestionnairesArgs = {pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, q?: string | undefined, statusMatchesAny?: Array | undefined, typeMatchesAny?: Array | undefined, createdAfter?: string | undefined, createdBefore?: string | undefined, ownerIdMatchesAny?: Array | undefined, approverIdMatchesAny?: Array | undefined}; export type GetApiCustomerTrustQuestionnairesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerTrustQuestionnaireType = z.enum(["SPREADSHEET", "WEBSITE", "DOCUMENT"]); export const questionnaireStatus = z.enum(["APPROVED", "IN_PROGRESS", "IN_REVIEW", "READY_FOR_REVIEW", "WAITING_ON_ANSWERS", "ON_HOLD", "NO_LONGER_NEEDED", "COMPLETE", "ERROR", "EXTRACTING_QUESTIONS", "QUEUED_FOR_EXTRACTION", "PROCESSING", "QUEUED_FOR_PROCESSING", "WAITING_ON_COLUMN_SELECTION", "WAITING_ON_COLUMN_APPROVAL", "QUEUED_FOR_COLUMN_DETECTION", "DETECTING_COLUMNS"]); export const questionnaireUser = z.object({id: z.string(), displayName: z.string().nullable(), email: z.string().nullable()}); export const questionnaireStatusChangeEntry = z.object({updatedBy: questionnaireUser, updatedAt: z.string(), status: questionnaireStatus, message: z.string().nullable()}); export const actorAssignment = z.object({type: z.enum(["User", "Team"]), id: z.string(), displayName: z.string().nullable()}); export const tagInput = z.object({categoryId: z.string(), tagId: z.string()}); export const customerTrustQuestionnaire = z.object({id: z.string(), displayName: z.string(), url: z.string().optional(), type: customerTrustQuestionnaireType, status: questionnaireStatus, statusLog: z.array(questionnaireStatusChangeEntry), ownerAssignment: actorAssignment.optional(), approverAssignment: actorAssignment.optional(), customerTrustAccountId: z.string().optional(), dueDate: z.string().optional(), metadata: z.array(z.object({value: z.string(), key: z.string()})).optional(), tagAndCategoryIds: z.array(tagInput), createdDate: z.string(), updatedDate: z.string(), completedDate: z.string().optional()}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedResponseCustomerTrustQuestionnaire = z.object({results: z.object({data: z.array(customerTrustQuestionnaire), 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 questionnaires * * GET /customer-trust/questionnaires */ export const getApiCustomerTrustQuestionnaires = async (args: GetApiCustomerTrustQuestionnairesArgs, options?: GetApiCustomerTrustQuestionnairesOptions) => { 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.q != null) query.append("q", String(args.q)) for (const item of args.statusMatchesAny ?? []) query.append("statusMatchesAny", String(item)) for (const item of args.typeMatchesAny ?? []) query.append("typeMatchesAny", String(item)) if (args.createdAfter != null) query.append("createdAfter", String(args.createdAfter)) if (args.createdBefore != null) query.append("createdBefore", String(args.createdBefore)) for (const item of args.ownerIdMatchesAny ?? []) query.append("ownerIdMatchesAny", String(item)) for (const item of args.approverIdMatchesAny ?? []) query.append("approverIdMatchesAny", String(item)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer-trust/questionnaires${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(paginatedResponseCustomerTrustQuestionnaire, await res.json()) };