import superjson from "superjson"; export type SpotifyLibrarySection = "tracks" | "albums" | "artists" | "shows"; export type SpotifyLibraryItem = { id: string; type: "track" | "album" | "artist" | "show"; name: string; subtitle?: string; detail?: string; imageUrl?: string; externalUrl?: string; uri?: string; durationMs?: number; addedAt?: string; total?: number; }; export type OutputType = { section: SpotifyLibrarySection; items: SpotifyLibraryItem[]; total?: number; nextCursor?: string; }; export async function getSpotifyLibrary( section: SpotifyLibrarySection, cursor?: string, ): Promise { const params = new URLSearchParams({ section }); if (cursor) params.set("cursor", cursor); const response = await fetch("/_api/spotify-library?" + params.toString(), { cache: "no-store", }); if (!response.ok) { const parsed = superjson.parse<{ error: string }>(await response.text()); throw new Error(parsed.error); } return superjson.parse(await response.text()); }