import {z} from 'zod' export type GetApiV1LibraryImportsIdArgs = {id: string, videoId?: string | undefined}; export type GetApiV1LibraryImportsIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const libraryItemScope = z.enum(["private", "workspace", "default", "video", "pinterest", "arena", "mymind", "vintage"]); export const libraryItemType = z.enum(["image", "video", "sound-effect", "music", "lut", "screenshot", "font"]); export const libraryItem = z.object({category: z.string().optional(), createdAt: z.string().optional(), dimensions: z.object({height: z.number().int().gte(-9007199254740991).lte(9007199254740991), width: z.number().int().gte(-9007199254740991).lte(9007199254740991)}).optional(), durationMs: z.number().optional(), id: z.string(), link: z.string().optional(), name: z.string(), presetId: z.string().optional(), scope: libraryItemScope, sourceId: z.string().optional(), summary: z.string().optional(), tags: z.array(z.string()).optional(), type: libraryItemType, updatedAt: z.string().optional(), url: z.string().optional()}); export const import = z.object({error: z.string().optional(), id: z.string(), item: libraryItem.optional(), status: z.enum(["running", "completed", "failed"])}); export const importResponse = z.object({import: import}); 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 }; /** * Get an import's status * * GET /v1/library/imports/{id} */ export const getApiV1LibraryImportsId = async (args: GetApiV1LibraryImportsIdArgs, options?: GetApiV1LibraryImportsIdOptions) => { 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 (args.videoId != null) query.append("videoId", String(args.videoId)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/library/imports/${encodeURIComponent(String(args.id))}${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(importResponse, await res.json()) };