import {z} from 'zod' export type GetApiVideoV1AssetsASSETIDInputInfoArgs = {ASSET_ID: string}; export type GetApiVideoV1AssetsASSETIDInputInfoOptions = {baseUrl?: string | undefined, accessToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const assetGeneratedSubtitleSettings = z.object({name: z.string().optional(), passthrough: z.string().optional(), language_code: z.enum(["en", "es", "it", "pt", "de", "fr", "pl", "ru", "nl", "ca", "tr", "sv", "uk", "no", "fi", "sk", "el", "cs", "hr", "da", "ro", "bg", "auto"]).optional()}); export const inputSettings = z.object({url: z.string().optional(), overlay_settings: z.object({vertical_align: z.enum(["top", "middle", "bottom"]).optional(), vertical_margin: z.string().optional(), horizontal_align: z.enum(["left", "center", "right"]).optional(), horizontal_margin: z.string().optional(), width: z.string().optional(), height: z.string().optional(), opacity: z.string().optional()}).optional(), generated_subtitles: z.array(assetGeneratedSubtitleSettings).optional(), start_time: z.number().optional(), end_time: z.number().optional(), type: z.enum(["video", "audio", "text"]).optional(), text_type: z.enum(["subtitles", "chapters"]).optional(), language_code: z.string().optional(), name: z.string().optional(), closed_captions: z.boolean().optional(), passthrough: z.string().optional()}); export const inputTrack = z.object({type: z.string(), duration: z.number().optional(), encoding: z.string().optional(), width: z.number().int().optional(), height: z.number().int().optional(), frame_rate: z.number().optional(), sample_rate: z.number().int().optional(), sample_size: z.number().int().optional(), channels: z.number().int().optional()}); export const inputFile = z.object({container_format: z.string().optional(), tracks: z.array(inputTrack).optional()}); export const inputInfo = z.object({settings: inputSettings.optional(), file: inputFile.optional()}); export const getAssetInputInfoResponse = z.object({data: z.array(inputInfo)}); 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 }; /** * Retrieve asset input info * * GET /video/v1/assets/{ASSET_ID}/input-info * * Also accepts auth: authorizationToken */ export const getApiVideoV1AssetsASSETIDInputInfo = async (args: GetApiVideoV1AssetsASSETIDInputInfoArgs, options?: GetApiVideoV1AssetsASSETIDInputInfoOptions) => { const {baseUrl = "https://api.mux.com", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (accessToken !== undefined) headers.set('authorization', `Basic ${btoa(`${accessToken.username}:${accessToken.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/video/v1/assets/${encodeURIComponent(String(args.ASSET_ID))}/input-info${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(getAssetInputInfoResponse, await res.json()) };