import {z} from 'zod' export type SongInfo = {Name?: (string | null) | undefined, Path?: (string | null) | undefined, MetadataLanguage?: (string | null) | undefined, MetadataCountryCode?: (string | null) | undefined, ProviderIds?: ({[key: string]: string} | null) | undefined, Year?: (number | null) | undefined, IndexNumber?: (number | null) | undefined, ParentIndexNumber?: (number | null) | undefined, PremiereDate?: (string | null) | undefined, IsAutomated?: boolean | undefined, AlbumArtists?: (Array | null) | undefined, Album?: (string | null) | undefined, Artists?: (Array | null) | undefined}; export type AlbumInfo = {Name?: (string | null) | undefined, Path?: (string | null) | undefined, MetadataLanguage?: (string | null) | undefined, MetadataCountryCode?: (string | null) | undefined, ProviderIds?: ({[key: string]: string} | null) | undefined, Year?: (number | null) | undefined, IndexNumber?: (number | null) | undefined, ParentIndexNumber?: (number | null) | undefined, PremiereDate?: (string | null) | undefined, IsAutomated?: boolean | undefined, AlbumArtists?: (Array | null) | undefined, ArtistProviderIds?: ({[key: string]: string} | null) | undefined, SongInfos?: (Array | null) | undefined}; export type AlbumInfoRemoteSearchQuery = {SearchInfo?: AlbumInfo | undefined, ItemId?: string | undefined, SearchProviderName?: (string | null) | undefined, IncludeDisabledProviders?: boolean | undefined}; export type CreateApiItemsRemoteSearchMusicAlbumArgs = {body: AlbumInfoRemoteSearchQuery}; export type CreateApiItemsRemoteSearchMusicAlbumOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; export const remoteSearchResult: z.ZodType = z.object({Name: z.string().nullable().optional(), ProviderIds: z.record(z.string(), z.string()).nullable().optional(), ProductionYear: z.number().int().nullable().optional(), IndexNumber: z.number().int().nullable().optional(), IndexNumberEnd: z.number().int().nullable().optional(), ParentIndexNumber: z.number().int().nullable().optional(), PremiereDate: z.string().nullable().optional(), ImageUrl: z.string().nullable().optional(), SearchProviderName: z.string().nullable().optional(), Overview: z.string().nullable().optional(), AlbumArtist: z.lazy(() => remoteSearchResult.optional()), Artists: z.array(z.lazy(() => remoteSearchResult)).nullable().optional()}); export const createApiItemsRemoteSearchMusicAlbumResponse = z.array(remoteSearchResult); 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 music album remote search. * * POST /Items/RemoteSearch/MusicAlbum */ export const createApiItemsRemoteSearchMusicAlbum = async (args: CreateApiItemsRemoteSearchMusicAlbumArgs, options?: CreateApiItemsRemoteSearchMusicAlbumOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/Items/RemoteSearch/MusicAlbum${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(createApiItemsRemoteSearchMusicAlbumResponse, await res.json()) };