import {z} from 'zod' export type ExportVideoRequest = {fps?: ('30' | '60') | undefined, granularity?: ('video' | 'clips' | 'tracks' | 'raw') | undefined, resolution?: ('1080p' | '4k') | undefined, speed?: ('1' | '2' | '0.5' | '0.75' | '0.8' | '0.9' | '1.1' | '1.2' | '1.25' | '1.3' | '1.35' | '1.5' | '1.7' | '1.75' | '2.5') | undefined, subtitles?: boolean | undefined}; export type CreateApiV1VideosIdExportsArgs = {id: string, body: ExportVideoRequest}; export type CreateApiV1VideosIdExportsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const exportStatus = z.object({downloadUrl: z.string().nullable(), exportId: z.string(), progress: z.number().gte(0).lte(100).nullable(), status: z.enum(["queued", "running", "completed", "failed"]), updatedAt: z.string()}); export const exportVideoResponse = z.object({export: exportStatus}); 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 }; /** * Start a video export * * POST /v1/videos/{id}/exports */ export const createApiV1VideosIdExports = async (args: CreateApiV1VideosIdExportsArgs, options?: CreateApiV1VideosIdExportsOptions) => { const {baseUrl = "https://api.tella.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(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.id))}/exports${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(exportVideoResponse, await res.json()) };