import {z} from 'zod' export type GetApiV1MotionDocumentsIdThumbnailArgs = {id: string, format?: ('jpg' | 'png' | 'webp' | 'gif' | 'mp4') | undefined, startTimeMs?: number | undefined, durationMs?: number | undefined, fps?: number | undefined, width?: number | undefined, height?: number | undefined, download?: ('true' | 'false') | undefined, response?: 'json' | undefined}; export type GetApiV1MotionDocumentsIdThumbnailOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const thumbnailResponse = z.object({url: z.string()}); 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 a frame or preview of a Tella Motion document * * GET /v1/motion/documents/{id}/thumbnail */ export const getApiV1MotionDocumentsIdThumbnail = async (args: GetApiV1MotionDocumentsIdThumbnailArgs, options?: GetApiV1MotionDocumentsIdThumbnailOptions) => { const {baseUrl = "https://api.tella.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.format != null) query.append("format", String(args.format)) if (args.startTimeMs != null) query.append("startTimeMs", String(args.startTimeMs)) if (args.durationMs != null) query.append("durationMs", String(args.durationMs)) if (args.fps != null) query.append("fps", String(args.fps)) if (args.width != null) query.append("width", String(args.width)) if (args.height != null) query.append("height", String(args.height)) if (args.download != null) query.append("download", String(args.download)) if (args.response != null) query.append("response", String(args.response)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/motion/documents/${encodeURIComponent(String(args.id))}/thumbnail${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(thumbnailResponse, await res.json()) };