import {z} from 'zod' export type AddClipRequest = {name?: string | undefined, sourceId: string}; export type CreateApiV1VideosIdClipsArgs = {id: string, body: AddClipRequest}; export type CreateApiV1VideosIdClipsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const clipBackgroundOutput = z.object({color: z.string().nullable().optional(), gradientAngle: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), gradientColor1: z.string().nullable().optional(), gradientColor2: z.string().nullable().optional(), imageUrl: z.string().nullable().optional(), shaderGradientPreset: z.string().nullable().optional(), sourceId: z.string().nullable().optional(), type: z.enum(["solid", "gradient", "image", "video", "shaderGradient", "ambient"]), videoDurationSeconds: z.number().gte(0).nullable().optional(), videoUrl: z.string().nullable().optional()}); export const clipCameraCropOutput = z.object({bottom: z.number().gte(0), left: z.number().gte(0), right: z.number().gte(0), top: z.number().gte(0)}); export const clipCameraFocusPointOutput = z.object({xPct: z.number().gte(0).lte(100), yPct: z.number().gte(0).lte(100)}); export const cutOutput = z.object({durationMs: z.number().int().gt(0).lte(9007199254740991), startTimeMs: z.number().int().gte(0).lte(9007199254740991)}); export const layoutSceneType = z.enum(["basicSubject", "cameraSubject", "combi"]); export const clipTransition = z.enum(["default", "smooth", "hard_cut"]); export const clip = z.object({animatedCursor: z.boolean().optional(), background: clipBackgroundOutput, borderStyle: z.enum(["none", "subtle-shadow", "deep-shadow", "transparent", "solid-shadow-left", "solid-shadow-right", "snake", "glass", "custom"]), cameraCrop: clipCameraCropOutput.nullable().optional(), cameraFocusPoint: clipCameraFocusPointOutput.optional(), corners: z.enum(["none", "regular", "squircle"]), createdAt: z.string(), cuts: z.array(cutOutput), durationSeconds: z.number().gte(0), id: z.string(), keepCameraFaceCentered: z.boolean().optional(), layoutSceneType: layoutSceneType, maxDurationSeconds: z.number().gte(0), microphoneVolume: z.number().gte(0).lte(2).nullable().optional(), mirrorCamera: z.boolean().optional(), name: z.string(), order: z.number().int().gte(0).lte(9007199254740991), studioSound: z.boolean(), systemAudioVolume: z.number().gte(0).lte(2).nullable().optional(), transition: clipTransition, updatedAt: z.string(), videoId: z.string()}); export const getClipResponse = z.object({clip: clip}); 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 }; /** * Add a clip from an uploaded source * * POST /v1/videos/{id}/clips */ export const createApiV1VideosIdClips = async (args: CreateApiV1VideosIdClipsArgs, options?: CreateApiV1VideosIdClipsOptions) => { 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${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(getClipResponse, await res.json()) };