import {z} from 'zod' export type UpdateAssetTrackRequest = {language_code?: string | undefined, name?: string | undefined, closed_captions?: boolean | undefined, passthrough?: string | undefined}; export type PatchApiVideoV1AssetsASSETIDTracksTRACKIDArgs = {ASSET_ID: string, TRACK_ID: string, body: UpdateAssetTrackRequest}; export type PatchApiVideoV1AssetsASSETIDTracksTRACKIDOptions = {baseUrl?: string | undefined, accessToken?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const track = z.object({id: z.string().optional(), type: z.enum(["video", "audio", "text"]).optional(), duration: z.number().optional(), max_width: z.number().int().optional(), max_height: z.number().int().optional(), max_frame_rate: z.number().optional(), max_channels: z.number().int().optional(), text_type: z.enum(["subtitles", "chapters"]).optional(), text_source: z.enum(["uploaded", "embedded", "generated_live", "generated_live_final", "generated_vod"]).optional(), language_code: z.string().optional(), name: z.string().optional(), closed_captions: z.boolean().optional(), passthrough: z.string().optional(), status: z.enum(["preparing", "ready", "errored", "deleted", "skipped"]).optional(), primary: z.boolean().optional(), auto_language_confidence: z.number().optional()}); export const updateAssetTrackResponse = z.object({data: track}); 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 }; /** * Update an asset track * * PATCH /video/v1/assets/{ASSET_ID}/tracks/{TRACK_ID} * * Also accepts auth: authorizationToken */ export const patchApiVideoV1AssetsASSETIDTracksTRACKID = async (args: PatchApiVideoV1AssetsASSETIDTracksTRACKIDArgs, options?: PatchApiVideoV1AssetsASSETIDTracksTRACKIDOptions) => { const {baseUrl = "https://api.mux.com", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") 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))}/tracks/${encodeURIComponent(String(args.TRACK_ID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(updateAssetTrackResponse, await res.json()) };