import {z} from 'zod' export type GetApiHubsHubHashIdProjectsProjectIdDocumentsDocumentIdHistoryArgs = {DocumentId: string, HubHashId: string, ProjectId: number}; export type GetApiHubsHubHashIdProjectsProjectIdDocumentsDocumentIdHistoryOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const featuresDocumentsRevisionNumberResponse = z.object({prefix: z.string().nullable().optional(), number: z.string().nullable().optional(), suffix: z.string().nullable().optional()}); export const featuresSharedModelsUserSummary = z.object({id: z.number().int().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), avatarUrl: z.string().nullable().optional(), isDisabled: z.boolean().optional()}); export const bIMOneBIMTrackDocumentControlDataEntitiesAuditAction = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(27)]); export const bIMOneBIMTrackDocumentControlDataEntitiesAuditDocumentSource = z.literal(1); export const bIMOneBIMTrackDocumentControlAuditDetailsAuditDetailsProperty = z.object({property: z.string().nullable(), type: z.string().nullable(), value: z.string().nullable()}); export const bIMOneBIMTrackDocumentControlAuditDetailsAuditDetailsChange = z.object({property: z.string().nullable(), type: z.string().nullable(), previousValue: z.string().nullable(), newValue: z.string().nullable()}); export const featuresDocumentsGetDocumentHistoryHistoryLog = z.object({id: z.string().nullable().optional(), name: z.string().nullable().optional(), documentRevisionNumber: featuresDocumentsRevisionNumberResponse.optional(), performedOn: z.string().optional(), performedBy: featuresSharedModelsUserSummary.optional(), performedAction: bIMOneBIMTrackDocumentControlDataEntitiesAuditAction.optional(), documentSource: bIMOneBIMTrackDocumentControlDataEntitiesAuditDocumentSource.optional(), properties: z.array(bIMOneBIMTrackDocumentControlAuditDetailsAuditDetailsProperty).nullable().optional(), changes: z.array(bIMOneBIMTrackDocumentControlAuditDetailsAuditDetailsChange).nullable().optional()}); export const featuresDocumentsGetDocumentHistoryHistoryLogsResponse = z.object({historyLogs: z.array(featuresDocumentsGetDocumentHistoryHistoryLog).nullable().optional(), skipToken: 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 }; /** * Get document history * * GET /hubs/{HubHashId}/projects/{ProjectId}/documents/{DocumentId}/history */ export const getApiHubsHubHashIdProjectsProjectIdDocumentsDocumentIdHistory = async (args: GetApiHubsHubHashIdProjectsProjectIdDocumentsDocumentIdHistoryArgs, options?: GetApiHubsHubHashIdProjectsProjectIdDocumentsDocumentIdHistoryOptions) => { const {baseUrl = "https://docs.bimtrackapp.co", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/hubs/${encodeURIComponent(String(args.HubHashId))}/projects/${encodeURIComponent(String(args.ProjectId))}/documents/${encodeURIComponent(String(args.DocumentId))}/history${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(featuresDocumentsGetDocumentHistoryHistoryLogsResponse, await res.json()) };