import {z} from 'zod' export type TranscodeRequestSchema = {job_id?: (string | null) | undefined, priority?: (number | null) | undefined, set_as_custom_keyframe?: (boolean | null) | undefined, update_proxy_mediainfo?: boolean | undefined, use_storage_transcode_ignore_pattern?: (boolean | null) | undefined}; export type CreateApiV1AssetsAssetIdProxiesProxyIdKeyframesArgs = {'Auth-Token': string, 'App-ID': string, asset_id: string, proxy_id: string, body: TranscodeRequestSchema}; export type CreateApiV1AssetsAssetIdProxiesProxyIdKeyframesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const transcodeResponseSchema = z.object({job_id: z.string().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 a transcode job for keyframes from a proxy * * POST /v1/assets/{asset_id}/proxies/{proxy_id}/keyframes/ */ export const createApiV1AssetsAssetIdProxiesProxyIdKeyframes = async (args: CreateApiV1AssetsAssetIdProxiesProxyIdKeyframesArgs, options: CreateApiV1AssetsAssetIdProxiesProxyIdKeyframesOptions) => { 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['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assets/${encodeURIComponent(String(args.asset_id))}/proxies/${encodeURIComponent(String(args.proxy_id))}/keyframes/${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(transcodeResponseSchema, await res.json()) };