@benliam12/spotify-api-helper 1.0.0-DEV.5 → 1.0.0-DEV.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -75,6 +75,7 @@ export declare class SpotifyHelper {
|
|
|
75
75
|
* Returns null if the request fails.
|
|
76
76
|
*/
|
|
77
77
|
getAlbum(albumId: string): Promise<Album | null>;
|
|
78
|
+
getAlbums(albumIds: string[]): Promise<(Album | null)[]>;
|
|
78
79
|
/**
|
|
79
80
|
* Get a track by ID.
|
|
80
81
|
* Returns null if the request fails.
|
|
@@ -105,6 +106,10 @@ export declare class SpotifyHelper {
|
|
|
105
106
|
* Manually clear the token (useful for testing or forcing a refresh).
|
|
106
107
|
*/
|
|
107
108
|
clearToken(): void;
|
|
109
|
+
/**
|
|
110
|
+
* Get the current configuration.
|
|
111
|
+
*/
|
|
112
|
+
getConfig(): SpotifyConfiguration;
|
|
108
113
|
/**
|
|
109
114
|
* Get token info for debugging (without exposing the actual token).
|
|
110
115
|
*/
|
|
@@ -178,13 +178,38 @@ export class SpotifyHelper {
|
|
|
178
178
|
const album = {
|
|
179
179
|
id: data.id,
|
|
180
180
|
name: data.name,
|
|
181
|
-
market: data.market,
|
|
182
181
|
album_type: data.album_type,
|
|
183
182
|
total_tracks: data.total_tracks,
|
|
184
|
-
data: data
|
|
183
|
+
data: data.data
|
|
185
184
|
};
|
|
186
185
|
return album;
|
|
187
186
|
}
|
|
187
|
+
async getAlbums(albumIds) {
|
|
188
|
+
const idsParam = albumIds.join(",");
|
|
189
|
+
if (albumIds.length === 0) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
if (albumIds.length > 20) {
|
|
193
|
+
throw new Error("Spotify API allows a maximum of 20 album IDs per request.");
|
|
194
|
+
}
|
|
195
|
+
const result = await this.makeAuthenticatedRequest(`https://api.spotify.com/v1/albums?ids=${idsParam}`, "getAlbums", { method: "GET" });
|
|
196
|
+
if (result.success) {
|
|
197
|
+
return result.data.map((data) => {
|
|
198
|
+
if (!data) {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
const album = {
|
|
202
|
+
id: data.id,
|
|
203
|
+
name: data.name,
|
|
204
|
+
album_type: data.album_type,
|
|
205
|
+
total_tracks: data.total_tracks,
|
|
206
|
+
data: data.data
|
|
207
|
+
};
|
|
208
|
+
return album;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return [];
|
|
212
|
+
}
|
|
188
213
|
/**
|
|
189
214
|
* Get a track by ID.
|
|
190
215
|
* Returns null if the request fails.
|
|
@@ -194,9 +219,33 @@ export class SpotifyHelper {
|
|
|
194
219
|
if (!result.success) {
|
|
195
220
|
return null;
|
|
196
221
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
222
|
+
else {
|
|
223
|
+
const { id, name, album_type, total_tracks, ...data } = result.data.album;
|
|
224
|
+
const trackAlbumData = {
|
|
225
|
+
id: id,
|
|
226
|
+
name: name,
|
|
227
|
+
album_type: album_type,
|
|
228
|
+
total_tracks: total_tracks,
|
|
229
|
+
data: data
|
|
230
|
+
};
|
|
231
|
+
const trackArtistData = result.data.artists.map((artistData) => {
|
|
232
|
+
const { id, name, ...data } = artistData;
|
|
233
|
+
const artist = {
|
|
234
|
+
id: id,
|
|
235
|
+
name: name,
|
|
236
|
+
data: data
|
|
237
|
+
};
|
|
238
|
+
return artist;
|
|
239
|
+
});
|
|
240
|
+
const trackData = {
|
|
241
|
+
id: result.data.id,
|
|
242
|
+
name: result.data.name,
|
|
243
|
+
artists: trackArtistData,
|
|
244
|
+
album: trackAlbumData,
|
|
245
|
+
data: result.data
|
|
246
|
+
};
|
|
247
|
+
return trackData;
|
|
248
|
+
}
|
|
200
249
|
}
|
|
201
250
|
/**
|
|
202
251
|
* Get an artist by ID.
|
|
@@ -254,6 +303,12 @@ export class SpotifyHelper {
|
|
|
254
303
|
clearToken() {
|
|
255
304
|
this.clientToken = null;
|
|
256
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* Get the current configuration.
|
|
308
|
+
*/
|
|
309
|
+
getConfig() {
|
|
310
|
+
return this.config;
|
|
311
|
+
}
|
|
257
312
|
/**
|
|
258
313
|
* Get token info for debugging (without exposing the actual token).
|
|
259
314
|
*/
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
export interface Album {
|
|
2
2
|
id: string;
|
|
3
3
|
name: string;
|
|
4
|
-
market: string;
|
|
5
4
|
album_type: string;
|
|
6
5
|
total_tracks: number;
|
|
7
|
-
data
|
|
6
|
+
data: any;
|
|
8
7
|
}
|
|
9
8
|
export interface Track {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
artists: Artist[];
|
|
12
|
+
album: Album;
|
|
13
|
+
data: any;
|
|
10
14
|
}
|
|
11
15
|
export interface Artist {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
data: any;
|
|
12
19
|
}
|
|
13
20
|
export interface ClientToken {
|
|
14
21
|
access_token: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@benliam12/spotify-api-helper",
|
|
3
|
-
"version": "1.0.0-DEV.
|
|
3
|
+
"version": "1.0.0-DEV.6",
|
|
4
4
|
"description": "A utility package for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"clean": "rimraf dist",
|
|
17
17
|
"lint": "eslint src --ext .ts",
|
|
18
18
|
"prepare": "npm run build",
|
|
19
|
-
"release": "semantic-release --no-ci",
|
|
20
|
-
"release:dry": "semantic-release --dry-run --no-ci"
|
|
19
|
+
"release": "dotenv -e .env -- semantic-release --no-ci --dry-run=false",
|
|
20
|
+
"release:dry": "dotenv -e .env semantic-release --dry-run --no-ci"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"utility",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"@types/node": "^22.19.3",
|
|
39
39
|
"@typescript-eslint/eslint-plugin": "^8.50.1",
|
|
40
40
|
"@typescript-eslint/parser": "^8.50.1",
|
|
41
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
42
|
+
"dotenv-cli": "^11.0.0",
|
|
41
43
|
"eslint": "^9.39.2",
|
|
42
44
|
"jest": "^29.7.0",
|
|
43
45
|
"rimraf": "^6.1.2",
|