import {z} from 'zod' export type ZoomFocusPoint = {xPct: number, yPct: number}; export type TransitionStyle = 'smooth' | 'hard_cut'; export type UpdateClipZoomRequest = {durationMs?: number | undefined, focusPoint?: ZoomFocusPoint | undefined, introTransition?: TransitionStyle | undefined, outroTransition?: TransitionStyle | undefined, scale?: number | undefined, startTimeMs?: number | undefined, type?: ('manualZoom' | 'trackingZoom') | undefined}; export type PatchApiV1VideosIdClipsClipIdZoomsZoomIdArgs = {id: string, clipId: string, zoomId: string, body: UpdateClipZoomRequest}; export type PatchApiV1VideosIdClipsClipIdZoomsZoomIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const zoomFocusPointOutput = z.object({xPct: z.number().gte(0).lte(100), yPct: z.number().gte(0).lte(100)}); export const transitionStyle = z.enum(["smooth", "hard_cut"]); export const clipZoom = z.object({durationMs: z.number().gte(0), focusPoint: zoomFocusPointOutput.nullable().optional(), id: z.string(), introTransition: transitionStyle, outroTransition: transitionStyle, scale: z.number().gte(1).lte(3.5).nullable().optional(), startTimeMs: z.number().gte(0), type: z.enum(["manualZoom", "trackingZoom"])}); export const clipZoomResponse = z.object({zoom: clipZoom}); 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 a zoom * * PATCH /v1/videos/{id}/clips/{clipId}/zooms/{zoomId} */ export const patchApiV1VideosIdClipsClipIdZoomsZoomId = async (args: PatchApiV1VideosIdClipsClipIdZoomsZoomIdArgs, options?: PatchApiV1VideosIdClipsClipIdZoomsZoomIdOptions) => { 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))}/clips/${encodeURIComponent(String(args.clipId))}/zooms/${encodeURIComponent(String(args.zoomId))}${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(clipZoomResponse, await res.json()) };