Skip to content

Commit

Permalink
chore: add jsdoc annotations for premium only endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MellKam committed Feb 26, 2024
1 parent f62097b commit c75bf4d
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[typescript]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,13 @@ import { PageIterator } from "@soundify/web-api/pagination";
const client = new SpotifyClient("YOUR_ACCESS_TOKEN");

const playlistIter = new PageIterator(
(offset) => getPlaylistTracks(client, "37i9dQZEVXbMDoHDwVN2tF", {
// you can find the max limit for specific endpoint
// in spotify docs or in the jsdoc comments of this property
limit: 50,
offset,
}),
(offset) =>
getPlaylistTracks(client, "37i9dQZEVXbMDoHDwVN2tF", {
// you can find the max limit for specific endpoint
// in spotify docs or in the jsdoc comments of this property
limit: 50,
offset,
}),
);

// iterate over all tracks in the playlist
Expand All @@ -233,12 +234,13 @@ console.log(allTracks.length);

// Want to get the last 100 items? No problem
const lastHundredTracks = new PageIterator(
(offset) => getPlaylistTracks(
client,
"37i9dQZEVXbMDoHDwVN2tF",
{ limit: 50, offset }
),
{ initialOffset: -100 }, // this will work just as `Array.slice(-100)`
(offset) =>
getPlaylistTracks(
client,
"37i9dQZEVXbMDoHDwVN2tF",
{ limit: 50, offset },
),
{ initialOffset: -100 }, // this will work just as `Array.slice(-100)`
).collect();
```

Expand All @@ -249,21 +251,23 @@ import { CursorPageIterator } from "@soundify/web-api/pagination";
const client = new SpotifyClient("YOUR_ACCESS_TOKEN");

// loop over all followed artists
for await (const artist of new CursorPageIterator(
opts => getFollowedArtists(client, { limit: 50, after: opts.after })
)) {
for await (
const artist of new CursorPageIterator(
(opts) => getFollowedArtists(client, { limit: 50, after: opts.after }),
)
) {
console.log(artist.name);
}

// or collect all followed artists into an array
const artists = await new CursorPageIterator(
opts => getFollowedArtists(client, { limit: 50, after: opts.after })
(opts) => getFollowedArtists(client, { limit: 50, after: opts.after }),
).collect();

// get all followed artists starting from Radiohead
const artists = await new CursorPageIterator(
opts => getFollowedArtists(client, { limit: 50, after: opts.after }),
{ initialAfter: "4Z8W4fKeB5YxbusRsdQVPb" } // let's start from Radiohead
(opts) => getFollowedArtists(client, { limit: 50, after: opts.after }),
{ initialAfter: "4Z8W4fKeB5YxbusRsdQVPb" }, // let's start from Radiohead
).collect();
```

Expand Down
2 changes: 1 addition & 1 deletion endpoints/audiobook/audiobook.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ export type SavedAudiobook = {
* Information about the audiobook.
*/
audiobook: SimplifiedAudiobook;
};
};
5 changes: 4 additions & 1 deletion endpoints/episode/episode.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ export const saveEpisodes = (
* @param client Spotify HTTPClient
* @param episodeId The Spotify ID of the episode
*/
export const saveEpisode = (client: HTTPClient, episodeId: string): Promise<Response> => {
export const saveEpisode = (
client: HTTPClient,
episodeId: string,
): Promise<Response> => {
return saveEpisodes(client, [episodeId]);
};

Expand Down
2 changes: 1 addition & 1 deletion endpoints/episode/episode.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ export type SavedEpisode = {
* Information about the episode.
*/
episode: Episode;
}
};
4 changes: 3 additions & 1 deletion endpoints/genre/genre.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type { HTTPClient } from "../../client.ts";
*
* @param client Spotify HTTPClient
*/
export const getAvailableGenreSeeds = async (client: HTTPClient): Promise<string[]> => {
export const getAvailableGenreSeeds = async (
client: HTTPClient,
): Promise<string[]> => {
const res = await client.fetch("/v1/recommendations/available-genre-seeds");
return ((await res.json()) as { genres: string[] }).genres;
};
4 changes: 3 additions & 1 deletion endpoints/market/market.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type { HTTPClient } from "../../client.ts";
*
* @param client Spotify HTTPClient
*/
export const getAvailableMarkets = async (client: HTTPClient): Promise<string[]> => {
export const getAvailableMarkets = async (
client: HTTPClient,
): Promise<string[]> => {
const res = await client.fetch("/v1/markets");
return (await res.json() as { markets: string[] }).markets;
};
48 changes: 31 additions & 17 deletions endpoints/player/player.endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export type GetPlaybackStateOpts = {
/**
* Get information about the user’s current playback state, including track or episode, progress, and active device.
*
* @requires `user-read-playback-state`
* @requires `user-read-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param options Additional options for request
Expand Down Expand Up @@ -58,7 +59,8 @@ export type TransferPlaybackBody = {
/**
* Transfer playback to a new device and optionally begin playback. The order of execution is not guaranteed when you use this API with other Player API endpoints.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*/
export const transferPlayback = (
client: HTTPClient,
Expand All @@ -70,13 +72,14 @@ export const transferPlayback = (
/**
* Get information about a user’s available Spotify Connect devices. Some device models are not supported and will not be listed in the API response.
*
* @requires `user-read-playback-state`
* @requires `user-read-playback-state` \
* **The user must have a Spotify Premium subscription.**
*/
export const getAvailableDevices = async (
client: HTTPClient,
): Promise<Device[]> => {
const res = await client.fetch("/v1/me/player/devices");
return (await res.json() as { devices: Device[] }).devices;
return ((await res.json()) as { devices: Device[] }).devices;
};

export type GetCurrentPlayingTrackOpts = {
Expand All @@ -93,7 +96,8 @@ export type GetCurrentPlayingTrackOpts = {
/**
* Get the object currently being played on the user's Spotify account.
*
* @requires `user-read-currently-playing`
* @requires `user-read-currently-playing` \
* **The user must have a Spotify Premium subscription.**
*/
export const getCurrentPlayingTrack = async (
client: HTTPClient,
Expand Down Expand Up @@ -149,7 +153,8 @@ export type StartResumePlaybackBody = {
/**
* Start a new context or resume current playback on the user’s active device.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*/
export const startPlayback = (
client: HTTPClient,
Expand All @@ -166,14 +171,16 @@ export const startPlayback = (
/**
* Start a new context or resume current playback on the user’s active device.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*/
export const resumePlayback = startPlayback;

/**
* Pause playback on the user’s account.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param deviceId The id of the device this command is targeting. If not supplied, the user's currently active device is the target.
Expand All @@ -191,7 +198,8 @@ export const pausePlayback = (
/**
* Skips to next track in the user’s queue.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param deviceId The id of the device this command is targeting. If not supplied, the user's currently active device is the target.
Expand All @@ -209,7 +217,8 @@ export const skipToNext = (
/**
* Skips to previous track in the user’s queue.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param deviceId The id of the device this command is targeting. If not supplied, the user's currently active device is the target.
Expand All @@ -227,7 +236,8 @@ export const skipToPrevious = (
/**
* Seeks to the given position in the user’s currently playing track.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param positionMs The position in milliseconds to seek to. Must be a positive number. Passing in a position that is greater than the length of the track will cause the player to start playing the next song.
Expand All @@ -247,7 +257,8 @@ export const seekToPosition = (
/**
* Set the repeat mode for the user's playback.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param state
Expand All @@ -270,7 +281,8 @@ export const setRepeatMode = (
/**
* Toggle shuffle on or off for user’s playback.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param state `true` to turn shuffle on, `false` to turn it off.
Expand Down Expand Up @@ -308,7 +320,8 @@ export type GetRecentlyPlayedTracksOpts = {
/**
* Get tracks from the current user's recently played tracks.
*
* @requires `user-read-recently-played`
* @requires `user-read-recently-played` \
* **The user must have a Spotify Premium subscription.**
*/
export const getRecentPlayedTracks = async (
client: HTTPClient,
Expand All @@ -323,8 +336,8 @@ export const getRecentPlayedTracks = async (
/**
* Get the list of objects that make up the user's queue.
*
* @requires `user-read-currently-playing`,
`user-read-playback-state`
* @requires `user-read-currently-playing`, `user-read-playback-state` \
* **The user must have a Spotify Premium subscription.**
*/
export const getUserQueue = async (client: HTTPClient): Promise<Queue> => {
const res = await client.fetch("/v1/me/player/queue");
Expand All @@ -334,7 +347,8 @@ export const getUserQueue = async (client: HTTPClient): Promise<Queue> => {
/**
* Add an item to the end of the user's current playback queue.
*
* @requires `user-modify-playback-state`
* @requires `user-modify-playback-state` \
* **The user must have a Spotify Premium subscription.**
*
* @param client Spotify HTTPClient
* @param uri The uri of the item to add to the queue. Must be a track or an episode uri.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"allowUnusedLabels": false,
"skipLibCheck": true
}
}
}

0 comments on commit c75bf4d

Please sign in to comment.