import {z} from 'zod' export type GetApiV1VideosIdClipsClipIdBlursArgs = {id: string, clipId: string}; export type GetApiV1VideosIdClipsClipIdBlursOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const maskDimensionsOutput = z.object({heightPct: z.number().gte(0).lte(100), widthPct: z.number().gte(0).lte(100)}); export const maskPointOutput = 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 clipMask = z.object({dimensions: maskDimensionsOutput, durationMs: z.number().gte(0), id: z.string(), intensity: z.number().gte(0).lte(1), point: maskPointOutput, startTimeMs: z.number().gte(0), transition: transitionStyle, type: z.enum(["blur", "highlight"])}); export const listClipMasksResponse = z.object({masks: z.array(clipMask)}); 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 }; /** * List blurs on a clip * * GET /v1/videos/{id}/clips/{clipId}/blurs */ export const getApiV1VideosIdClipsClipIdBlurs = async (args: GetApiV1VideosIdClipsClipIdBlursArgs, options?: GetApiV1VideosIdClipsClipIdBlursOptions) => { 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 (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/videos/${encodeURIComponent(String(args.id))}/clips/${encodeURIComponent(String(args.clipId))}/blurs${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(listClipMasksResponse, await res.json()) };