import {z} from 'zod' export type GetApiDisplayPreferencesDisplayPreferencesIdArgs = {displayPreferencesId: string, userId: string, client: string}; export type GetApiDisplayPreferencesDisplayPreferencesIdOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const scrollDirection = z.enum(["Horizontal", "Vertical"]); export const sortOrder = z.enum(["Ascending", "Descending"]); export const displayPreferencesDto = z.object({Id: z.string().nullable().optional(), ViewType: z.string().nullable().optional(), SortBy: z.string().nullable().optional(), IndexBy: z.string().nullable().optional(), RememberIndexing: z.boolean().optional(), PrimaryImageHeight: z.number().int().optional(), PrimaryImageWidth: z.number().int().optional(), CustomPrefs: z.record(z.string(), z.string()).nullable().optional(), ScrollDirection: scrollDirection.optional(), ShowBackdrop: z.boolean().optional(), RememberSorting: z.boolean().optional(), SortOrder: sortOrder.optional(), ShowSidebar: z.boolean().optional(), Client: 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 }; /** * Get Display Preferences. * * GET /DisplayPreferences/{displayPreferencesId} */ export const getApiDisplayPreferencesDisplayPreferencesId = async (args: GetApiDisplayPreferencesDisplayPreferencesIdArgs, options?: GetApiDisplayPreferencesDisplayPreferencesIdOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.userId != null) query.append("userId", String(args.userId)) if (args.client != null) query.append("client", String(args.client)) if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/DisplayPreferences/${encodeURIComponent(String(args.displayPreferencesId))}${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(displayPreferencesDto, await res.json()) };