@benliam12/spotify-api-helper 1.0.0-DEV.4 → 1.0.0-DEV.5
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SpotifyConfiguration } from "./SpotifyConfiguration.js";
|
|
2
|
-
import { Album, Track, Artist } from "./SpotifyTypes.js";
|
|
2
|
+
import { Album, Track, Artist, SearchType } from "./SpotifyTypes.js";
|
|
3
3
|
/**
|
|
4
4
|
* Result wrapper for operations that can fail
|
|
5
5
|
*/
|
|
@@ -70,7 +70,6 @@ export declare class SpotifyHelper {
|
|
|
70
70
|
* Handle errors consistently - log and/or call callback
|
|
71
71
|
*/
|
|
72
72
|
private handleError;
|
|
73
|
-
test(): string;
|
|
74
73
|
/**
|
|
75
74
|
* Get an album by ID.
|
|
76
75
|
* Returns null if the request fails.
|
|
@@ -96,6 +95,7 @@ export declare class SpotifyHelper {
|
|
|
96
95
|
* Returns empty array if the request fails.
|
|
97
96
|
*/
|
|
98
97
|
getAvailableMarkets(): Promise<string[]>;
|
|
98
|
+
search(query: string, type: SearchType, limit?: number, offset?: number): Promise<any | null>;
|
|
99
99
|
/**
|
|
100
100
|
* Check if the helper is properly authenticated.
|
|
101
101
|
* Useful for health checks.
|
|
@@ -165,9 +165,6 @@ export class SpotifyHelper {
|
|
|
165
165
|
}
|
|
166
166
|
this.options.onError(error);
|
|
167
167
|
}
|
|
168
|
-
test() {
|
|
169
|
-
return "SpotifyHelper is working!";
|
|
170
|
-
}
|
|
171
168
|
/**
|
|
172
169
|
* Get an album by ID.
|
|
173
170
|
* Returns null if the request fails.
|
|
@@ -184,7 +181,7 @@ export class SpotifyHelper {
|
|
|
184
181
|
market: data.market,
|
|
185
182
|
album_type: data.album_type,
|
|
186
183
|
total_tracks: data.total_tracks,
|
|
187
|
-
|
|
184
|
+
data: data
|
|
188
185
|
};
|
|
189
186
|
return album;
|
|
190
187
|
}
|
|
@@ -236,6 +233,13 @@ export class SpotifyHelper {
|
|
|
236
233
|
}
|
|
237
234
|
return result.data.markets || [];
|
|
238
235
|
}
|
|
236
|
+
async search(query, type, limit = 20, offset = 0) {
|
|
237
|
+
const result = await this.makeAuthenticatedRequest(`https://api.spotify.com/v1/search?q=${encodeURIComponent(query)}&type=${type}&limit=${limit}&offset=${offset}`, "search", { method: "GET" });
|
|
238
|
+
if (!result.success) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return result.data;
|
|
242
|
+
}
|
|
239
243
|
/**
|
|
240
244
|
* Check if the helper is properly authenticated.
|
|
241
245
|
* Useful for health checks.
|
|
@@ -4,7 +4,7 @@ export interface Album {
|
|
|
4
4
|
market: string;
|
|
5
5
|
album_type: string;
|
|
6
6
|
total_tracks: number;
|
|
7
|
-
|
|
7
|
+
data?: any;
|
|
8
8
|
}
|
|
9
9
|
export interface Track {
|
|
10
10
|
}
|
|
@@ -15,3 +15,9 @@ export interface ClientToken {
|
|
|
15
15
|
token_type: string;
|
|
16
16
|
expires_at: Date;
|
|
17
17
|
}
|
|
18
|
+
export declare enum SearchType {
|
|
19
|
+
ALBUM = "album",
|
|
20
|
+
ARTIST = "artist",
|
|
21
|
+
TRACK = "track",
|
|
22
|
+
PLAYLIST = "playlist"
|
|
23
|
+
}
|
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.5",
|
|
4
4
|
"description": "A utility package for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
],
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "npm run clean && tsc",
|
|
13
|
-
"test": "jest",
|
|
13
|
+
"test": "node --experimental-vm-modules --no-warnings --env-file=.env.test.local node_modules/jest/bin/jest.js",
|
|
14
|
+
"test:watch": "node --experimental-vm-modules --no-warnings --env-file=.env.test.local node_modules/jest/bin/jest.js --watch",
|
|
15
|
+
"test:coverage": "node --experimental-vm-modules --no-warnings --env-file=.env.test.local node_modules/jest/bin/jest.js --coverage",
|
|
14
16
|
"clean": "rimraf dist",
|
|
15
17
|
"lint": "eslint src --ext .ts",
|
|
16
18
|
"prepare": "npm run build",
|