@ekwoka/spotify-api
Advanced tools
Comparing version 0.1.1 to 0.2.0
export { resetCache } from './resetCache'; | ||
export { setToken } from './setToken'; | ||
export { spotifyApiClient } from './spotifyApiClient'; | ||
export type { PersistentApiProperties, SpotifyApiClient, QueryFunction, } from './types'; | ||
export type { PersistentApiProperties, SpotifyApiClient, QueryFunction, PaginatedList, } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,5 +10,10 @@ /** | ||
if (!cacheType) | ||
Client.cache = {}; | ||
Client.cache = { | ||
albums: {}, | ||
saved: { | ||
albums: {}, | ||
}, | ||
}; | ||
else | ||
delete Client.cache[cacheType]; | ||
}; |
@@ -6,3 +6,8 @@ export function spotifyApiClient(token) { | ||
token, | ||
cache: {}, | ||
cache: { | ||
albums: {}, | ||
saved: { | ||
albums: {}, | ||
}, | ||
}, | ||
}; | ||
@@ -9,0 +14,0 @@ return (fn) => { |
@@ -0,4 +1,9 @@ | ||
import { Album } from '../endpoints/albums'; | ||
export declare type PersistentApiProperties = { | ||
token: string; | ||
cache: { | ||
albums: Record<string, Album>; | ||
saved: { | ||
albums: Record<string, boolean>; | ||
}; | ||
[key: string]: unknown; | ||
@@ -9,2 +14,15 @@ }; | ||
export declare type QueryFunction<T = void> = (props: PersistentApiProperties) => T; | ||
export declare type PaginatedList<T> = { | ||
href: string; | ||
items: T[]; | ||
limit: number; | ||
next: string | null; | ||
offset: number; | ||
previous: string | null; | ||
total: number; | ||
}; | ||
export declare type Copyrights = { | ||
text: string; | ||
type: string; | ||
}[]; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -0,1 +1,2 @@ | ||
export { albumIsSaved } from './albumIsSaved'; | ||
export { batchAlbums } from './batchAlbums'; | ||
@@ -5,4 +6,8 @@ export { getAlbum } from './getAlbum'; | ||
export { getAlbumTracks } from './getAlbumTracks'; | ||
export { getSavedAlbums } from './getSavedAlbums'; | ||
export { removeAlbums } from './removeAlbums'; | ||
export { saveAlbums } from './saveAlbums'; | ||
export type { Albums } from './getAlbums'; | ||
export type { SavedAlbum } from './getSavedAlbums'; | ||
export type { AlbumStub, Album, TrackList } from './types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,1 +1,2 @@ | ||
export { albumIsSaved } from './albumIsSaved'; | ||
export { batchAlbums } from './batchAlbums'; | ||
@@ -5,1 +6,4 @@ export { getAlbum } from './getAlbum'; | ||
export { getAlbumTracks } from './getAlbumTracks'; | ||
export { getSavedAlbums } from './getSavedAlbums'; | ||
export { removeAlbums } from './removeAlbums'; | ||
export { saveAlbums } from './saveAlbums'; |
@@ -0,4 +1,5 @@ | ||
import { Copyrights } from '../../core/types'; | ||
import { SpotifyAPIURL, SpotifyPageURL, Image } from '../../utils'; | ||
import { ArtistStub } from '../artists/'; | ||
import { Track } from '../tracks/'; | ||
import { TrackStub } from '../tracks/types'; | ||
export declare type AlbumStub = { | ||
@@ -26,6 +27,11 @@ album_type: 'single' | 'album' | 'compilation'; | ||
tracks: TrackList; | ||
copyrights?: Copyrights; | ||
external_ids: Record<string, string>; | ||
genres: string[]; | ||
label: string; | ||
popularity: number; | ||
}; | ||
export declare type TrackList = { | ||
href: SpotifyAPIURL; | ||
items: Track[]; | ||
items: TrackStub[]; | ||
limit: number; | ||
@@ -32,0 +38,0 @@ next: SpotifyAPIURL | null; |
@@ -0,4 +1,9 @@ | ||
export { albumIsSaved } from './albums/albumIsSaved'; | ||
export { batchAlbums } from './albums/batchAlbums'; | ||
export { getAlbum } from './albums/getAlbum'; | ||
export { getAlbums } from './albums/getAlbums'; | ||
export { getAlbumTracks } from './albums/getAlbumTracks'; | ||
export { getSavedAlbums } from './albums/getSavedAlbums'; | ||
export { removeAlbums } from './albums/removeAlbums'; | ||
export { saveAlbums } from './albums/saveAlbums'; | ||
export { getCurrentUser } from './users/getCurrentUser'; | ||
@@ -8,5 +13,6 @@ export { getTopItems } from './users/getTopItems'; | ||
export type { Albums } from './albums/getAlbums'; | ||
export type { SavedAlbum } from './albums/getSavedAlbums'; | ||
export type { AlbumStub, Album, TrackList } from './albums/types'; | ||
export type { Artist, ArtistStub } from './artists/types'; | ||
export type { Track } from './tracks/types'; | ||
export type { Track, TrackStub } from './tracks/types'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,6 +1,11 @@ | ||
export { albumIsSaved } from './albums/albumIsSaved'; | ||
export { batchAlbums } from './albums/batchAlbums'; | ||
export { getAlbum } from './albums/getAlbum'; | ||
export { getAlbums } from './albums/getAlbums'; | ||
export { getAlbumTracks } from './albums/getAlbumTracks'; | ||
export { getSavedAlbums } from './albums/getSavedAlbums'; | ||
export { removeAlbums } from './albums/removeAlbums'; | ||
export { saveAlbums } from './albums/saveAlbums'; | ||
export { getCurrentUser } from './users/getCurrentUser'; | ||
export { getTopItems } from './users/getTopItems'; | ||
export { getUserProfile } from './users/getUserProfile'; |
import { SpotifyAPIURL, SpotifyPageURL } from '../../utils/SpotifyUtilityTypes'; | ||
import { AlbumStub } from '../albums'; | ||
import { ArtistStub } from '../artists/types'; | ||
export declare type Track = { | ||
export declare type Track = TrackStub & { | ||
album: AlbumStub; | ||
external_ids: { | ||
isrc?: string; | ||
ean?: string; | ||
upc?: string; | ||
}; | ||
popularity: number; | ||
}; | ||
export declare type TrackStub = { | ||
artists: ArtistStub[]; | ||
@@ -11,7 +19,2 @@ available_markets: string[]; | ||
explicit: boolean; | ||
external_ids: { | ||
isrc?: string; | ||
ean?: string; | ||
upc?: string; | ||
}; | ||
external_urls: { | ||
@@ -24,3 +27,2 @@ spotify: SpotifyPageURL; | ||
name: string; | ||
popularity: number; | ||
preview_url: string; | ||
@@ -27,0 +29,0 @@ track_number: number; |
@@ -1,15 +0,6 @@ | ||
import { QueryFunction } from '../../core'; | ||
import { QueryFunction, PaginatedList } from '../../core'; | ||
import { Artist } from '../artists/types'; | ||
import { Track } from '../tracks/types'; | ||
export declare const getTopItems: GetTopItems; | ||
declare type GetTopItems = <T extends keyof TopItem>(type: T, options?: TopItemOptions) => QueryFunction<Promise<TopItems<TopItem[T]>>>; | ||
declare type TopItems<T> = { | ||
href: 'string'; | ||
items: T[]; | ||
limit: number; | ||
next: string; | ||
offset: number; | ||
previous: string; | ||
total: number; | ||
}; | ||
declare type GetTopItems = <T extends keyof TopItem>(type: T, options?: TopItemOptions) => QueryFunction<Promise<PaginatedList<TopItem[T]>>>; | ||
declare type TopItem = { | ||
@@ -16,0 +7,0 @@ tracks: Track; |
@@ -5,3 +5,3 @@ export { fetchOptions, makeAuthURL, refreshToken, tokensFromCode, } from './auth'; | ||
export { spotifyApiClient } from './core/spotifyApiClient'; | ||
export { getCurrentUser, getTopItems, getUserProfile, getAlbum, getAlbums, getAlbumTracks, } from './endpoints'; | ||
export { getCurrentUser, getTopItems, getUserProfile, getAlbum, getAlbums, getAlbumTracks, getSavedAlbums, albumIsSaved, saveAlbums, removeAlbums, } from './endpoints'; | ||
export { spotifyFetch } from './utils/spotifyFetch'; | ||
@@ -8,0 +8,0 @@ export type { RefreshedToken } from './auth'; |
@@ -5,3 +5,3 @@ export { fetchOptions, makeAuthURL, refreshToken, tokensFromCode, } from './auth'; | ||
export { spotifyApiClient } from './core/spotifyApiClient'; | ||
export { getCurrentUser, getTopItems, getUserProfile, getAlbum, getAlbums, getAlbumTracks, } from './endpoints'; | ||
export { getCurrentUser, getTopItems, getUserProfile, getAlbum, getAlbums, getAlbumTracks, getSavedAlbums, albumIsSaved, saveAlbums, removeAlbums, } from './endpoints'; | ||
export { spotifyFetch } from './utils/spotifyFetch'; |
@@ -1,2 +0,2 @@ | ||
export declare const deepFreeze: (obj: unknown) => Readonly<unknown>; | ||
export declare const deepFreeze: <T>(obj: T) => Readonly<T>; | ||
//# sourceMappingURL=deepFreeze.d.ts.map |
@@ -27,3 +27,3 @@ import { SPOTIFY_URL } from '../constants'; | ||
* Spotify API Error Handling | ||
* 401: Bad of Expired Token. Should reauthenticate. | ||
* 401: Bad or Expired Token. Should reauthenticate. | ||
* 403: Forbidden. Fatal Error. | ||
@@ -30,0 +30,0 @@ * 404: Not Found. Internal Error. |
@@ -12,3 +12,3 @@ { | ||
"license": "MIT", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Composable Wrapper for the Spotify Web Api and Spotify Web Playback SDK", | ||
@@ -25,8 +25,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/node": "^18.7.2", | ||
"@typescript-eslint/eslint-plugin": "^5.33.0", | ||
"@typescript-eslint/parser": "^5.33.0", | ||
"@types/node": "^18.7.5", | ||
"@typescript-eslint/eslint-plugin": "^5.33.1", | ||
"@typescript-eslint/parser": "^5.33.1", | ||
"c8": "^7.12.0", | ||
"esbuild": "^0.15.2", | ||
"eslint": "^8.21.0", | ||
"esbuild": "^0.15.3", | ||
"eslint": "^8.22.0", | ||
"gzip-size": "^7.0.0", | ||
@@ -39,4 +39,4 @@ "husky": "^8.0.1", | ||
"undici": "^5.8.2", | ||
"vite": "^3.0.7", | ||
"vitest": "^0.21.1" | ||
"vite": "^3.0.8", | ||
"vitest": "^0.22.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "prettier": { |
@@ -123,10 +123,21 @@ # ⚡️A tree-shakable, composable, lightweight wrapper for the multiple Spotify APIs🔥 | ||
- `getAlbumTracks` - Retrieves info about an albums tracks | ||
- `getSavedAlbums` - Retrieves a paginated list of albums in the user's library | ||
> While these correspond to 3 different endpoints to Spotify's API, internally these 3 use only the `getAlbums` endpoints for improved code-reuse. | ||
Cachekey: 'albums.[id]' | ||
Cachekey: `albums.[id]` | ||
Batching Limit: 20 | ||
### getAlbum | ||
- `albumIsSaved` - Retrieves whether a provided album id is in the user's library | ||
- `saveAlbums` - Adds albums to the user's library | ||
- `removeAlbums` - Removes albums from the user's library | ||
> These last 3 all use batching to improve performance, and these 3 all also use a shared cache of in-Library states. | ||
Cachekey: `saved.albums[id]` | ||
Batching Limit: 20 | ||
#### getAlbum | ||
Gets details of an Album by ID. | ||
@@ -161,2 +172,43 @@ | ||
#### getSavedAlbums | ||
Gets a list of the users saved albums (those in the users library) | ||
```js | ||
const savedAlbums = client(getSavedAlbums()) | ||
const savedAlbumsLong = client(getSavedAlbums({ limit: 50 })) | ||
``` | ||
Options: | ||
- `limit`: The number of items to return. Default: `20`. Maximum: `50`. | ||
- `offset`: The index of the first item to return. Default: `0`. | ||
- `time_range`: Over what time frame the data is retrieved. Options: `short_term`, `medium_term`, `long_term`. Default: `medium_term`. | ||
#### albumIsSaved | ||
Gets whether the provided album IDs are present in the user's library. Works with single IDs or arrays of IDs. | ||
```js | ||
const isSaved = client(albumIsSaved('6tLZvqqoWszgPagzzNNQQF')) // true | false | ||
const areSaved = client(albumIsSaved(['6tLZvqqoWszgPagzzNNQQF', '6XBIkDFhDgc3PQOUEcO2fd'])) // [true, false] | ||
``` | ||
#### saveAlbums | ||
Puts album ID into the user's library. Returns `true` if successful. Works with single IDs or arrays of IDs. | ||
```js | ||
const isSaved = client(saveAlbums('6tLZvqqoWszgPagzzNNQQF')) // true | ||
const wasSaved = client(saveAlbums(['6tLZvqqoWszgPagzzNNQQF', '6XBIkDFhDgc3PQOUEcO2fd'])) // [true, true] | ||
``` | ||
#### removeAlbums | ||
Deletes album ID from the user's library. Returns `true` if successful. Works with single IDs or arrays of IDs. | ||
```js | ||
const isRemoved = client(removeAlbums('6tLZvqqoWszgPagzzNNQQF')) // true | ||
const wasRemoved = client(removeAlbums(['6tLZvqqoWszgPagzzNNQQF', '6XBIkDFhDgc3PQOUEcO2fd'])) // [true, true] | ||
``` | ||
### Users | ||
@@ -180,3 +232,3 @@ | ||
cache key: 'user' | ||
CacheKey: `user` | ||
@@ -183,0 +235,0 @@ #### getTopItems |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
67881
131
949
314