import {z} from 'zod' export type EditProxySchema = {allow_mxf?: (boolean | null) | undefined, directory_path: string | null, file_suffix?: (string | null) | undefined, force_storage_id?: boolean | undefined, height: number, ignore_transcoder_settings?: boolean | undefined, keep_extension?: (boolean | null) | undefined, name: string, storage_id: string, version_id: string, width: number}; export type CreateApiV1AssetsAssetIdFilesFileIdEditProxiesArgs = {'App-ID': string, 'Auth-Token': string, asset_id: string, file_id: string, body: EditProxySchema}; export type CreateApiV1AssetsAssetIdFilesFileIdEditProxiesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const editProxyResponseSchema = z.object({audio_bitrate: z.number().int().gte(-2147483648).lte(2147483647).optional(), audio_codec: z.string().optional(), bitrate: z.number().int().gte(-2147483648).lte(2147483647).optional(), codec: z.string().optional(), directory_path: z.string().optional(), file_set_id: z.string().optional(), format_id: z.string().optional(), gop_length_seconds: z.number().optional(), height: z.number().int().gte(-2147483648).lte(2147483647).optional(), id: z.string().optional(), name: z.string().optional(), transcoder_id: z.string().optional(), type: z.string().optional(), width: z.number().int().gte(-2147483648).lte(2147483647).optional()}); 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 }; /** * Create format, file_set, and file for edit proxy if storage has edit proxy transcoder configured * * POST /v1/assets/{asset_id}/files/{file_id}/edit_proxies/ */ export const createApiV1AssetsAssetIdFilesFileIdEditProxies = async (args: CreateApiV1AssetsAssetIdFilesFileIdEditProxiesArgs, options: CreateApiV1AssetsAssetIdFilesFileIdEditProxiesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/files/${encodeURIComponent(String(args.file_id))}/edit_proxies/${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(editProxyResponseSchema, await res.json()) };