import {z} from 'zod' export type GLBCompressionType = 1 | 2 | 3 | 4 | 5; export type GetLesson3DAssetCurrentVersionExternalRequest = {lessonId: number, fileFormatId: number, gLBCompressionType?: GLBCompressionType | undefined}; export type CreateApiExternalGetLesson3DAssetCurrentVersionArgs = {'X-Version'?: string | undefined, body: GetLesson3DAssetCurrentVersionExternalRequest}; export type CreateApiExternalGetLesson3DAssetCurrentVersionOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const lessonAssetVersionV1 = z.object({id: z.number().int().nullable().optional(), lessonId: z.number().int().nullable().optional(), contentId: z.number().int().nullable().optional(), name: z.string().nullable().optional(), version: z.number().int().nullable().optional(), versionId: z.number().int().nullable().optional(), comments: z.string().nullable().optional(), dateCreated: z.string().nullable().optional(), createdBy: z.number().int().nullable().optional(), type: z.string().nullable().optional(), isSelected: z.boolean().nullable().optional(), instituteId: z.number().int().nullable().optional(), url: z.string().nullable().optional(), orientationFix: z.string().nullable().optional(), lastModifiedDate: z.string().nullable().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 }; /** * Get the latest asset used for a lesson. * * POST /External/GetLesson3DAssetCurrentVersion */ export const createApiExternalGetLesson3DAssetCurrentVersion = async (args: CreateApiExternalGetLesson3DAssetCurrentVersionArgs, options: CreateApiExternalGetLesson3DAssetCurrentVersionOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Version'] != null) headers.set("X-Version", String(args['X-Version'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/External/GetLesson3DAssetCurrentVersion${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(lessonAssetVersionV1, await res.json()) };