import {z} from 'zod' export type InformationRequestType = 'POINT_IN_TIME' | 'POPULATION' | 'SAMPLE'; export type InformationRequestCadence = 'ANNUALLY' | 'BIANNUALLY' | 'MONTHLY' | 'QUARTERLY'; export type CreateInformationRequestInput = {uniqueId: string, title: string, requestType: InformationRequestType, description?: (string | null) | undefined, frameworkCodes: Array, cadence?: (InformationRequestCadence | null) | undefined, dueDate?: (string | null) | undefined, evidenceCaptureDate?: (string | null) | undefined, additionalControlIds?: Array | undefined}; export type CreateApiAuditsAuditIdInformationRequestsArgs = {auditId: string, body: CreateInformationRequestInput}; export type CreateApiAuditsAuditIdInformationRequestsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const informationRequestApprovalStatus = z.enum(["NEEDS_EVIDENCE", "READY_FOR_AUDIT", "AUDITOR_APPROVED", "AUDITOR_FLAGGED"]); export const informationRequestCadence = z.enum(["ANNUALLY", "BIANNUALLY", "MONTHLY", "QUARTERLY"]); export const informationRequestType = z.enum(["POINT_IN_TIME", "POPULATION", "SAMPLE"]); export const resourceOwner = z.union([z.object({displayName: z.string(), id: z.string(), type: z.literal("user")}), z.object({displayName: z.string(), id: z.string(), type: z.literal("team")})]); export const informationRequest = z.object({id: z.string(), uniqueId: z.string(), additionalControlIds: z.array(z.string()), approvalStatus: informationRequestApprovalStatus, cadence: informationRequestCadence.nullable(), frameworkCodes: z.array(z.string()), description: z.string().nullable(), dueDate: z.string().nullable(), evidenceCaptureDate: z.string().nullable(), requestId: z.string().nullable(), requestType: informationRequestType, title: z.string(), creationDate: z.string(), modificationDate: z.string(), deletionDate: z.string().nullable(), ownerAssignment: resourceOwner.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 new information request * * POST /audits/{auditId}/information-requests */ export const createApiAuditsAuditIdInformationRequests = async (args: CreateApiAuditsAuditIdInformationRequestsArgs, options?: CreateApiAuditsAuditIdInformationRequestsOptions) => { 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))}/information-requests${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(informationRequest, await res.json()) };