import {z} from 'zod' export type CreateApiCustomerTrustQuestionnairesFileArgs = {body: BodyInit}; export type CreateApiCustomerTrustQuestionnairesFileOptions = {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 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 file questionnaire * * POST /customer-trust/questionnaires/file */ export const createApiCustomerTrustQuestionnairesFile = async (args: CreateApiCustomerTrustQuestionnairesFileArgs, options?: CreateApiCustomerTrustQuestionnairesFileOptions) => { 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(/\/+$/, '')}/customer-trust/questionnaires/file${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(customerTrustQuestionnaire, await res.json()) };