import {z} from 'zod' export type GetApiApiAlbumIdPlatformStatusPlaylistsArgs = {id: number, platform: 'cm' | 'spotify' | 'itunes' | 'applemusic' | 'deezer' | 'shazam' | 'beatport' | 'amazon' | 'youtube' | 'tunefind' | 'soundcloud', status: 'current' | 'past', since?: string | undefined, until?: string | undefined, offset?: number | undefined, limit?: number | undefined, indie?: boolean | undefined, majorCurator?: boolean | undefined, editorial?: boolean | undefined, newMusicFriday?: boolean | undefined, editorialBrand?: boolean | undefined, personalized?: boolean | undefined, deezerPartner?: boolean | undefined, chart?: boolean | undefined, thisIs?: boolean | undefined, hundredPercent?: boolean | undefined, radio?: boolean | undefined, fullyPersonalized?: boolean | undefined, brand?: boolean | undefined, musicBrand?: boolean | undefined, nonMusicBrand?: boolean | undefined, popularIndie?: boolean | undefined, audiobook?: boolean | undefined, personalityArtist?: boolean | undefined, minFollowers?: number | undefined, showPositionStats?: boolean | undefined}; export type GetApiApiAlbumIdPlatformStatusPlaylistsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiAlbumIdPlatformStatusPlaylistsResponse = z.object({obj: z.array(z.object({playlist: z.object({playlist_id: z.string().nullable().optional(), track_id: z.number().int().gte(0).lte(2147483647).nullable().optional(), position: z.number().int().gte(0).nullable().optional(), added_at: z.union([z.string(), z.string()]).nullable().optional(), period: z.number().int().gte(0).nullable().optional(), id: z.number().int().gte(0).lte(2147483647).nullable().optional(), name: z.string().nullable().optional(), description: z.string().nullable().optional(), image_url: z.string().nullable().optional(), sys_last_updated: z.string().nullable().optional(), last_updated: z.string().nullable().optional(), personalized: z.boolean().nullable().optional(), code2: z.string().min(2).max(2).nullable().optional(), owner_name: z.string().nullable().optional(), owner_id: z.union([z.string(), z.number()]).nullable().optional(), editorial: z.boolean().nullable().optional(), tags: z.array(z.object({id: z.number().int().gte(0).lte(2147483647), name: z.string().nullable().optional()})).nullable().optional(), followers: z.number().int().gte(0).nullable().optional(), num_track: z.union([z.string(), z.number()]).nullable().optional(), fdiff_week: z.number().int().nullable().optional(), fdiff_month: z.number().int().nullable().optional(), catalog: z.string().nullable().optional(), active_ratio: z.number().nullable().optional()}).optional(), track: z.object({id: z.number().int().gte(0).lte(2147483647).nullable().optional(), name: z.string().nullable().optional(), isrc: z.string().nullable().optional(), spotify_album_id: z.string().nullable().optional(), image_url: z.string().nullable().optional(), spotify_popularity: z.number().int().gte(0).nullable().optional(), cm_track: z.number().int().gte(0).lte(2147483647).nullable().optional(), spotify_artist_names: z.array(z.string().nullable()).nullable().optional(), track_genre: z.string().nullable().optional(), cm_artist: z.array(z.number().int().gte(0).lte(2147483647)).nullable().optional(), artist_names: z.array(z.string().nullable()).nullable().optional(), code2s: z.array(z.string().min(2).max(2).nullable()).nullable().optional(), artist_images: z.array(z.string().nullable()).nullable().optional(), artist_covers: z.array(z.string().nullable()).nullable().optional(), spotify_artist_ids: z.array(z.string()).nullable().optional(), spotify_track_ids: z.array(z.string()).nullable().optional(), spotify_album_ids: z.array(z.string()).nullable().optional(), spotify_duration_ms: z.union([z.number(), z.array(z.unknown())]).nullable().optional(), album_ids: z.array(z.number().int().gte(0).lte(2147483647)).nullable().optional(), album_names: z.array(z.string().nullable()).nullable().optional(), album_upc: z.array(z.string().nullable()).nullable().optional(), album_label: z.array(z.string().nullable()).nullable().optional(), release_dates: z.array(z.string().nullable()).nullable().optional()}).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 }; /** * Album Playlists * * GET /api/album/{id}/{platform}/{status}/playlists */ export const getApiApiAlbumIdPlatformStatusPlaylists = async (args: GetApiApiAlbumIdPlatformStatusPlaylistsArgs, options?: GetApiApiAlbumIdPlatformStatusPlaylistsOptions) => { const {baseUrl = "https://api.chartmetric.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.since != null) query.append("since", String(args.since)) if (args.until != null) query.append("until", String(args.until)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.indie != null) query.append("indie", String(args.indie)) if (args.majorCurator != null) query.append("majorCurator", String(args.majorCurator)) if (args.editorial != null) query.append("editorial", String(args.editorial)) if (args.newMusicFriday != null) query.append("newMusicFriday", String(args.newMusicFriday)) if (args.editorialBrand != null) query.append("editorialBrand", String(args.editorialBrand)) if (args.personalized != null) query.append("personalized", String(args.personalized)) if (args.deezerPartner != null) query.append("deezerPartner", String(args.deezerPartner)) if (args.chart != null) query.append("chart", String(args.chart)) if (args.thisIs != null) query.append("thisIs", String(args.thisIs)) if (args.hundredPercent != null) query.append("hundredPercent", String(args.hundredPercent)) if (args.radio != null) query.append("radio", String(args.radio)) if (args.fullyPersonalized != null) query.append("fullyPersonalized", String(args.fullyPersonalized)) if (args.brand != null) query.append("brand", String(args.brand)) if (args.musicBrand != null) query.append("musicBrand", String(args.musicBrand)) if (args.nonMusicBrand != null) query.append("nonMusicBrand", String(args.nonMusicBrand)) if (args.popularIndie != null) query.append("popularIndie", String(args.popularIndie)) if (args.audiobook != null) query.append("audiobook", String(args.audiobook)) if (args.personalityArtist != null) query.append("personalityArtist", String(args.personalityArtist)) if (args.minFollowers != null) query.append("minFollowers", String(args.minFollowers)) if (args.showPositionStats != null) query.append("showPositionStats", String(args.showPositionStats)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/album/${encodeURIComponent(String(args.id))}/${encodeURIComponent(String(args.platform))}/${encodeURIComponent(String(args.status))}/playlists${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(getApiApiAlbumIdPlatformStatusPlaylistsResponse, await res.json()) };