import {z} from 'zod' export type PlaylistItemSchema = {id?: string | undefined, object_id: string, object_type: 'assets' | 'sequences', time_end_milliseconds?: (number | null) | undefined, time_start_milliseconds?: (number | null) | undefined, version_id?: (string | null) | undefined}; export type UpdateApiV1PlaylistsPlaylistIdItemsItemIdArgs = {'App-ID': string, 'Auth-Token': string, playlist_id: string, item_id: string, index_immediately?: boolean | undefined, body: PlaylistItemSchema}; export type UpdateApiV1PlaylistsPlaylistIdItemsItemIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const playlistItemSchema = z.object({id: z.string().optional(), object_id: z.string(), object_type: z.enum(["assets", "sequences"]), time_end_milliseconds: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).nullable().optional(), time_start_milliseconds: z.number().int().gte(-9223372036854776000).lte(9223372036854776000).nullable().optional(), version_id: z.string().nullable().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 }; /** * Update a playlist item * * PUT /v1/playlists/{playlist_id}/items/{item_id}/ */ export const updateApiV1PlaylistsPlaylistIdItemsItemId = async (args: UpdateApiV1PlaylistsPlaylistIdItemsItemIdArgs, options: UpdateApiV1PlaylistsPlaylistIdItemsItemIdOptions) => { 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'])) if (args.index_immediately != null) query.append("index_immediately", String(args.index_immediately)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/playlists/${encodeURIComponent(String(args.playlist_id))}/items/${encodeURIComponent(String(args.item_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(playlistItemSchema, await res.json()) };