import {z} from 'zod' export type UpdateApiV1StoragesStorageIdTranscodersTranscoderIdArgs = {'App-ID': string, 'Auth-Token': string, storage_id: string, transcoder_id: string}; export type UpdateApiV1StoragesStorageIdTranscodersTranscoderIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const transcoderByStorageReadSchema = z.object({id: z.string().optional(), name: z.string().optional(), settings: z.record(z.string(), z.unknown()).optional(), storage_id: z.string().optional(), type: z.enum(["VANTAGE", "FFMPEG", "EDIT_PROXY", "IMAGEMAGICK", "ENCODING_COM", "ZENCODER", "TELESTREAM_CLOUD", "ELEMENTAL_MEDIACONVERT", "ELEMENTAL_SERVER", "REDLINE", "ICONIK_EDGE_TRANSCODER", "WATCH_FOLDER_VIDEO", "EDITREADY", "FLICS", "WILDMOKA", "LIBREOFFICE"]).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 }; /** * Add a transcoder to storage * * PUT /v1/storages/{storage_id}/transcoders/{transcoder_id}/ */ export const updateApiV1StoragesStorageIdTranscodersTranscoderId = async (args: UpdateApiV1StoragesStorageIdTranscodersTranscoderIdArgs, options: UpdateApiV1StoragesStorageIdTranscodersTranscoderIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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/storages/${encodeURIComponent(String(args.storage_id))}/transcoders/${encodeURIComponent(String(args.transcoder_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(transcoderByStorageReadSchema, await res.json()) };