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 CreateApiV1PlaylistsPlaylistIdItemsArgs = {'App-ID': string, 'Auth-Token': string, playlist_id: string, index_immediately?: boolean | undefined, low_priority_indexing?: boolean | undefined, body: PlaylistItemSchema}; export type CreateApiV1PlaylistsPlaylistIdItemsOptions = {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 }; /** * Add an item to a playlist * * POST /v1/playlists/{playlist_id}/items/ */ export const createApiV1PlaylistsPlaylistIdItems = async (args: CreateApiV1PlaylistsPlaylistIdItemsArgs, options: CreateApiV1PlaylistsPlaylistIdItemsOptions) => { 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)) if (args.low_priority_indexing != null) query.append("low_priority_indexing", String(args.low_priority_indexing)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/playlists/${encodeURIComponent(String(args.playlist_id))}/items/${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(playlistItemSchema, await res.json()) };