lastfm-nodejs-client 1.1.4 → 1.2.0
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.
- package/CHANGELOG.md +12 -0
- package/README.md +7 -0
- package/dist/index.d.ts +11 -11
- package/dist/request.d.ts +1 -1
- package/dist/request.js +11 -3
- package/package.json +2 -2
- package/src/request.ts +11 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.1
|
|
4
|
+
|
|
5
|
+
- Tidy up, removes console logs
|
|
6
|
+
|
|
7
|
+
## 1.2.0
|
|
8
|
+
|
|
9
|
+
- Swops `node-fetch` for `cross-fetch` for server and browser fetching support in one.
|
|
10
|
+
|
|
11
|
+
## 1.1.5
|
|
12
|
+
|
|
13
|
+
- Fix incorrect type on request method
|
|
14
|
+
|
|
3
15
|
## 1.1.4
|
|
4
16
|
|
|
5
17
|
- Fix incorrect type on request method
|
package/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# LastFm NodeJs client
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/lastfm-nodejs-client)
|
|
4
|
+
[](https://www.npmjs.com/package/lastfm-nodejs-client)
|
|
5
|
+
[](https://www.codacy.com/gh/mannuelf/lastfm-nodejs-client/dashboard?utm_source=github.com&utm_medium=referral&utm_content=mannuelf/lastfm-nodejs-client&utm_campaign=Badge_Grade)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
3
8
|
A Node JS wrapper client for fetching public data from [LastFm API](https://www.last.fm/api).
|
|
4
9
|
|
|
10
|
+
Fetch server side or client side, thanks to [cross-fetch](https://github.com/lquixada/cross-fetch)
|
|
11
|
+
|
|
5
12
|
## How to use the client
|
|
6
13
|
|
|
7
14
|
Install the npm package in your project.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AuthResponse, LovedTracksResponse, RecentTracksResponse, TopAlbumsResponse, TopArtistsResponse, TopTrackResponse, UserResponse, WeeklyAlbumChartResponse, WeeklyArtistChartResponse, WeeklyChartListResponse, WeeklyTrackChartResponse } from '../@types';
|
|
2
2
|
declare function LastFmApi(): {
|
|
3
|
-
auth: (method: string, user: string, period: string, limit:
|
|
3
|
+
auth: (method: string, user: string, period: string, limit: string) => Promise<AuthResponse>;
|
|
4
4
|
config: {
|
|
5
5
|
api_key: string;
|
|
6
6
|
app_name: string;
|
|
@@ -12,16 +12,16 @@ declare function LastFmApi(): {
|
|
|
12
12
|
share_secret: string;
|
|
13
13
|
username: string;
|
|
14
14
|
};
|
|
15
|
-
getInfo: (method: string, user: string, period: string, limit:
|
|
16
|
-
getLovedTracks: (method: string, user: string, period: string, limit:
|
|
17
|
-
getRecentTracks: (method: string, user: string, period: string, limit:
|
|
18
|
-
getTopAlbums: (method: string, user: string, period: string, limit:
|
|
19
|
-
getTopArtists: (method: string, user: string, period: string, limit:
|
|
20
|
-
getTopTracks: (method: string, user: string, period: string, limit:
|
|
21
|
-
getWeeklyAlbumChart: (method: string, user: string, period: string, limit:
|
|
22
|
-
getWeeklyArtistChart: (method: string, user: string, period: string, limit:
|
|
23
|
-
getWeeklyChartList: (method: string, user: string, period: string, limit:
|
|
24
|
-
getWeeklyTrackChart: (method: string, user: string, period: string, limit:
|
|
15
|
+
getInfo: (method: string, user: string, period: string, limit: string) => Promise<UserResponse>;
|
|
16
|
+
getLovedTracks: (method: string, user: string, period: string, limit: string) => Promise<LovedTracksResponse>;
|
|
17
|
+
getRecentTracks: (method: string, user: string, period: string, limit: string) => Promise<RecentTracksResponse>;
|
|
18
|
+
getTopAlbums: (method: string, user: string, period: string, limit: string) => Promise<TopAlbumsResponse>;
|
|
19
|
+
getTopArtists: (method: string, user: string, period: string, limit: string) => Promise<TopArtistsResponse>;
|
|
20
|
+
getTopTracks: (method: string, user: string, period: string, limit: string) => Promise<TopTrackResponse>;
|
|
21
|
+
getWeeklyAlbumChart: (method: string, user: string, period: string, limit: string) => Promise<WeeklyAlbumChartResponse>;
|
|
22
|
+
getWeeklyArtistChart: (method: string, user: string, period: string, limit: string) => Promise<WeeklyArtistChartResponse>;
|
|
23
|
+
getWeeklyChartList: (method: string, user: string, period: string, limit: string) => Promise<WeeklyChartListResponse>;
|
|
24
|
+
getWeeklyTrackChart: (method: string, user: string, period: string, limit: string) => Promise<WeeklyTrackChartResponse>;
|
|
25
25
|
method: {
|
|
26
26
|
auth: string;
|
|
27
27
|
user: {
|
package/dist/request.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const request: <
|
|
1
|
+
declare const request: <Response_1>(method: string, user: string, period?: string, limit?: string) => Promise<Response_1>;
|
|
2
2
|
export default request;
|
package/dist/request.js
CHANGED
|
@@ -12,17 +12,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
15
16
|
const config_1 = __importDefault(require("./config"));
|
|
16
17
|
const request = (method, user, period, limit) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
18
|
const url = `
|
|
18
19
|
${config_1.default.base_url}?method=${method}${user ? '&user=' : ''}${user}${user ? '&user=' : ''}${user}${period ? '&period=' : ''}${period}&${limit ? '&limit=' : ''}${limit}&api_key=${config_1.default.api_key}&format=${config_1.default.format.json}`;
|
|
19
|
-
return (yield
|
|
20
|
+
return (yield (0, cross_fetch_1.default)(url, {
|
|
20
21
|
headers: {
|
|
21
22
|
'Content-Type': 'application/json',
|
|
22
23
|
},
|
|
23
24
|
})
|
|
24
|
-
.then((res) =>
|
|
25
|
+
.then((res) => {
|
|
26
|
+
if (res.status >= 400) {
|
|
27
|
+
throw new Error('Bad response from server');
|
|
28
|
+
}
|
|
29
|
+
return res.json();
|
|
30
|
+
})
|
|
25
31
|
.then((json) => json)
|
|
26
|
-
.catch((error) =>
|
|
32
|
+
.catch((error) => {
|
|
33
|
+
throw new Error(error);
|
|
34
|
+
}));
|
|
27
35
|
});
|
|
28
36
|
exports.default = request;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lastfm-nodejs-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A NodeJS wrapper client for LastFm API. Fetching public data by username using the LastFm public API",
|
|
5
5
|
"main": "./dist",
|
|
6
6
|
"keywords": [
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"
|
|
19
|
+
"cross-fetch": "^3.1.5",
|
|
20
20
|
"rimraf": "^3.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/src/request.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import fetch from 'cross-fetch';
|
|
1
2
|
import config from './config';
|
|
2
3
|
|
|
3
|
-
const request = async <
|
|
4
|
+
const request = async <Response>(
|
|
4
5
|
method: string,
|
|
5
6
|
user: string,
|
|
6
7
|
period?: string,
|
|
@@ -18,9 +19,16 @@ const request = async <Parameters, Response>(
|
|
|
18
19
|
'Content-Type': 'application/json',
|
|
19
20
|
},
|
|
20
21
|
})
|
|
21
|
-
.then((res) =>
|
|
22
|
+
.then((res) => {
|
|
23
|
+
if (res.status >= 400) {
|
|
24
|
+
throw new Error('Bad response from server');
|
|
25
|
+
}
|
|
26
|
+
return res.json();
|
|
27
|
+
})
|
|
22
28
|
.then((json) => json)
|
|
23
|
-
.catch((error) =>
|
|
29
|
+
.catch((error) => {
|
|
30
|
+
throw new Error(error);
|
|
31
|
+
})) as Response;
|
|
24
32
|
};
|
|
25
33
|
|
|
26
34
|
export default request;
|