import {z} from 'zod' export type KnowledgeBaseResourceActorAssignmentInput = {type: 'User', id: string}; export type KnowledgeBaseCustomerVisibility = 'PRIVATE' | 'SHAREABLE' | 'REQUEST_ACCESS' | 'PUBLIC'; export type KnowledgeBaseResourceDownloadPermission = 'VIEW_ONLY' | 'VIEW_AND_DOWNLOAD'; export type TagInput = {categoryId: string, tagId: string}; export type UpdateDocumentResourceInput = {title?: string | undefined, description?: (string | null) | undefined, ownerAssignment?: (KnowledgeBaseResourceActorAssignmentInput | null) | undefined, customerVisibility?: KnowledgeBaseCustomerVisibility | undefined, downloadPermission?: KnowledgeBaseResourceDownloadPermission | undefined, isUsedInQuestionnaires?: boolean | undefined, expirationDate?: (string | null) | undefined, tags?: Array | undefined, categoryId?: (string | null) | undefined}; export type PatchApiKnowledgeBaseResourcesDocumentsIdArgs = {id: string, body: UpdateDocumentResourceInput}; export type PatchApiKnowledgeBaseResourcesDocumentsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const knowledgeBaseResourceActorAssignment = z.object({type: z.enum(["User", "Team"]), id: z.string(), displayName: z.string().nullable()}); export const knowledgeBaseExpirationStatus = z.enum(["CURRENT", "EXPIRED"]); export const tagInput = z.object({categoryId: z.string(), tagId: z.string()}); export const knowledgeBaseDocumentResourceOutput = z.object({id: z.string(), type: z.literal("FILE"), title: z.string(), description: z.string().nullable(), fileUrl: z.string(), customerVisibility: z.enum(["PRIVATE", "SHAREABLE", "REQUEST_ACCESS", "PUBLIC", "null"]).nullable(), downloadPermission: z.enum(["VIEW_ONLY", "VIEW_AND_DOWNLOAD", "null"]).nullable(), isUsedInQuestionnaires: z.boolean().nullable(), ownerAssignment: knowledgeBaseResourceActorAssignment.nullable(), expirationStatus: knowledgeBaseExpirationStatus, expirationDate: z.string().nullable(), lastUpdated: z.string(), lastVerified: z.string().nullable(), tags: z.array(tagInput), categoryId: 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 }; /** * Update document resource * * PATCH /knowledge-base/resources/documents/{id} */ export const patchApiKnowledgeBaseResourcesDocumentsId = async (args: PatchApiKnowledgeBaseResourcesDocumentsIdArgs, options?: PatchApiKnowledgeBaseResourcesDocumentsIdOptions) => { 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(/\/+$/, '')}/knowledge-base/resources/documents/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(knowledgeBaseDocumentResourceOutput, await res.json()) };