import {z} from 'zod' export type GetApiChannelsChannelIdFeaturesArgs = {channelId: string}; export type GetApiChannelsChannelIdFeaturesOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const channelMediaType = z.enum(["Audio", "Video", "Photo"]); export const channelMediaContentType = z.enum(["Clip", "Podcast", "Trailer", "Movie", "Episode", "Song", "MovieExtra", "TvExtra"]); export const channelItemSortField = z.enum(["Name", "CommunityRating", "PremiereDate", "DateCreated", "Runtime", "PlayCount", "CommunityPlayCount"]); export const channelFeatures = z.object({Name: z.string().nullable().optional(), Id: z.string().nullable().optional(), CanSearch: z.boolean().optional(), MediaTypes: z.array(channelMediaType).nullable().optional(), ContentTypes: z.array(channelMediaContentType).nullable().optional(), MaxPageSize: z.number().int().nullable().optional(), AutoRefreshLevels: z.number().int().nullable().optional(), DefaultSortFields: z.array(channelItemSortField).nullable().optional(), SupportsSortOrderToggle: z.boolean().optional(), SupportsLatestMedia: z.boolean().optional(), CanFilter: z.boolean().optional(), SupportsContentDownloading: z.boolean().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 }; /** * Get channel features. * * GET /Channels/{channelId}/Features */ export const getApiChannelsChannelIdFeatures = async (args: GetApiChannelsChannelIdFeaturesArgs, options?: GetApiChannelsChannelIdFeaturesOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/Channels/${encodeURIComponent(String(args.channelId))}/Features${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(channelFeatures, await res.json()) };