import {z} from 'zod' export type GetApiV1VideosIdClipsClipIdSourcesArgs = {id: string, clipId: string}; export type GetApiV1VideosIdClipsClipIdSourcesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const clipSource = z.object({dimensions: z.object({height: z.number().int().gt(0).lte(9007199254740991), width: z.number().int().gt(0).lte(9007199254740991)}).nullable().optional(), durationMs: z.number().nullable().optional(), effectiveVolume: z.number().gte(0).lte(2), id: z.string(), medium: z.string(), url: z.string().nullable().optional(), volume: z.number().gte(0).lte(2).nullable()}); export const listClipSourcesResponse = z.object({sources: z.array(clipSource)}); 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 sources for a clip * * GET /v1/videos/{id}/clips/{clipId}/sources */ export const getApiV1VideosIdClipsClipIdSources = async (args: GetApiV1VideosIdClipsClipIdSourcesArgs, options?: GetApiV1VideosIdClipsClipIdSourcesOptions) => { 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))}/sources${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(listClipSourcesResponse, await res.json()) };