This repository was archived by the owner on May 25, 2026. It is now read-only.
feat: add tracks-read helper for shuffle - #47
Merged
Conversation
ivorycrayon
approved these changes
May 22, 2026
ivorycrayon
left a comment
Contributor
There was a problem hiding this comment.
Solid. It mirrors the playlists.ts boundary pattern exactly — non-Spotify-origin refusal on the next URL, 10s per-page timeout, the shared error-class mapping, .loose() schemas with the projection as the gatekeeper — and the test coverage is thorough: both dispatch branches, the pagination loop, URI filtering, and every error class.
Two non-blocking notes:
/v1/playlists/{id}/itemsis the one thing the mocked tests can't confirm — worth a real-API smoke test before the shuffle route wires this in. Thetracks→itemsfield rename already documented inplaylists.tslines up with it, so it's likely right.- Agreed on back-porting the throw-on-exceed (
SpotifyPageBudgetExceededError) toplaylists.ts— its silent exit atMAX_PAGEScarries the same truncation risk.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
src/lib/spotify/tracks.tswith one exported function:fetchTracksForShuffle(accessToken, playlistId): Promise<string[]>.Dispatches to
GET /v1/me/tracksfor theLIKED_SONGS_IDsentinelor
GET /v1/playlists/{id}/itemsfor any other playlist, returninga flat list of
spotify:track:*URIs. Vitest coverage intracks.test.tsfor both dispatch branches, the pagination loop,URI filtering, and each boundary error class.
Why
Read prerequisite for the shuffle write path (#18, POST batching
into 100-URI chunks). A flat
string[]gives the future add-tracksstep a clean array to chunk without the read layer coupling to the
write cap.
Uses the non-deprecated
/v1/playlists/{id}/items; rationale livesin the code comment on
buildInitialUrl.Filters to
spotify:track:*only:spotify:local:*cannot bere-added via POST,
spotify:episode:*is out of v0 scope, and nulltrackitems (catalog-removed) are dropped.MAX_PAGES = 1000raisesSpotifyPageBudgetExceededErroron exceedrather than truncating silently, which would corrupt a shuffle. The
same throw-on-exceed pattern is worth back-porting to
playlists.ts.