lastfm-nodejs-client 1.2.4 → 1.4.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/.env.example +6 -5
- package/@types/index.d.ts +19 -19
- package/CHANGELOG.md +34 -24
- package/README.md +4 -0
- package/dist/auth.js +23 -0
- package/dist/config.js +12 -1
- package/dist/createOptions.js +12 -0
- package/dist/getInfo.js +19 -0
- package/dist/getLovedTracks.js +19 -0
- package/dist/getRecentTracks.js +19 -0
- package/dist/getTopAlbums.js +19 -0
- package/dist/getTopArtists.js +19 -0
- package/dist/getTopTracks.js +19 -0
- package/dist/getWeeklyAlbumChart.js +19 -0
- package/dist/getWeeklyArtistChart.js +19 -0
- package/dist/getWeeklyChartList.js +19 -0
- package/dist/getWeeklyTrackChart.js +19 -0
- package/dist/index.js +26 -188
- package/dist/method.js +13 -10
- package/dist/request.js +92 -8
- package/package.json +6 -5
- package/src/auth.ts +23 -0
- package/src/config.ts +22 -2
- package/src/createOptions.ts +12 -0
- package/src/getInfo.ts +17 -0
- package/src/getLovedTracks.ts +19 -0
- package/src/getRecentTracks.ts +19 -0
- package/src/getTopAlbums.ts +19 -0
- package/src/getTopArtists.ts +19 -0
- package/src/getTopTracks.ts +19 -0
- package/src/getWeeklyAlbumChart.ts +19 -0
- package/src/getWeeklyArtistChart.ts +19 -0
- package/src/getWeeklyChartList.ts +19 -0
- package/src/getWeeklyTrackChart.ts +20 -0
- package/src/index.ts +15 -255
- package/src/method.ts +29 -11
- package/src/request.ts +96 -5
- package/tsconfig.json +7 -7
- package/dist/config.d.ts +0 -12
- package/dist/index.d.ts +0 -41
- package/dist/method.d.ts +0 -16
- package/dist/request.d.ts +0 -8
- package/src/types.d.ts +0 -392
package/dist/index.js
CHANGED
|
@@ -1,195 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
3
|
+
const auth_1 = require("./auth");
|
|
4
|
+
const config_1 = require("./config");
|
|
5
|
+
const getInfo_1 = require("./getInfo");
|
|
6
|
+
const getLovedTracks_1 = require("./getLovedTracks");
|
|
7
|
+
const getRecentTracks_1 = require("./getRecentTracks");
|
|
8
|
+
const getTopAlbums_1 = require("./getTopAlbums");
|
|
9
|
+
const getTopArtists_1 = require("./getTopArtists");
|
|
10
|
+
const getTopTracks_1 = require("./getTopTracks");
|
|
11
|
+
const getWeeklyAlbumChart_1 = require("./getWeeklyAlbumChart");
|
|
12
|
+
const getWeeklyArtistChart_1 = require("./getWeeklyArtistChart");
|
|
13
|
+
const getWeeklyChartList_1 = require("./getWeeklyChartList");
|
|
14
|
+
const getWeeklyTrackChart_1 = require("./getWeeklyTrackChart");
|
|
15
|
+
const method_1 = require("./method");
|
|
9
16
|
function LastFmApi() {
|
|
10
|
-
/**
|
|
11
|
-
* POST: Auth - LastFM
|
|
12
|
-
*
|
|
13
|
-
* https://www.last.fm/api/show/auth.getToken
|
|
14
|
-
*
|
|
15
|
-
* Authentication tokens are API account specific.
|
|
16
|
-
* They are valid for 60 minutes from the moment they are granted.
|
|
17
|
-
* Can only used once (they are consumed when a session is created).
|
|
18
|
-
* @returns Auth token
|
|
19
|
-
*/
|
|
20
|
-
function auth(method, user, period, limit) {
|
|
21
|
-
const options = {
|
|
22
|
-
method,
|
|
23
|
-
user,
|
|
24
|
-
period,
|
|
25
|
-
limit,
|
|
26
|
-
};
|
|
27
|
-
return (0, request_1.default)(options);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* GET: User profile information - LastFM
|
|
31
|
-
*
|
|
32
|
-
* https://www.last.fm/api/show/user.getInfo
|
|
33
|
-
* @returns User profile data
|
|
34
|
-
*/
|
|
35
|
-
function getInfo(method, user, period, limit) {
|
|
36
|
-
const options = {
|
|
37
|
-
method,
|
|
38
|
-
user,
|
|
39
|
-
period,
|
|
40
|
-
limit,
|
|
41
|
-
};
|
|
42
|
-
return (0, request_1.default)(options);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* GET: Love Tracks - LastFM
|
|
46
|
-
*
|
|
47
|
-
* https://www.last.fm/api/show/user.getLovedTracks
|
|
48
|
-
* @returns Loved Tracks;
|
|
49
|
-
*/
|
|
50
|
-
function getLovedTracks(method, user, period, limit) {
|
|
51
|
-
const options = {
|
|
52
|
-
method,
|
|
53
|
-
user,
|
|
54
|
-
period,
|
|
55
|
-
limit,
|
|
56
|
-
};
|
|
57
|
-
return (0, request_1.default)(options);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* GET: Recent Tracks - LastFM
|
|
61
|
-
*
|
|
62
|
-
* https://www.last.fm/api/show/user.getRecentTracks
|
|
63
|
-
* @returns Recent Tracks
|
|
64
|
-
*/
|
|
65
|
-
function getRecentTracks(method, user, period, limit) {
|
|
66
|
-
const options = {
|
|
67
|
-
method,
|
|
68
|
-
user,
|
|
69
|
-
period,
|
|
70
|
-
limit,
|
|
71
|
-
};
|
|
72
|
-
return (0, request_1.default)(options);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* GET: Top Albums - LastFM
|
|
76
|
-
*
|
|
77
|
-
* https://www.last.fm/api/show/user.getTopAlbums
|
|
78
|
-
* @returns Top Albums
|
|
79
|
-
*/
|
|
80
|
-
function getTopAlbums(method, user, period, limit) {
|
|
81
|
-
const options = {
|
|
82
|
-
method,
|
|
83
|
-
user,
|
|
84
|
-
period,
|
|
85
|
-
limit,
|
|
86
|
-
};
|
|
87
|
-
return (0, request_1.default)(options);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* GET: Top Artist - LastFM
|
|
91
|
-
*
|
|
92
|
-
* https://www.last.fm/api/show/user.getTopArtists
|
|
93
|
-
* @returns Top Artists
|
|
94
|
-
*/
|
|
95
|
-
function getTopArtists(method, user, period, limit) {
|
|
96
|
-
const options = {
|
|
97
|
-
method,
|
|
98
|
-
user,
|
|
99
|
-
period,
|
|
100
|
-
limit,
|
|
101
|
-
};
|
|
102
|
-
return (0, request_1.default)(options);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* GET: Top Tracks - LastFM
|
|
106
|
-
*
|
|
107
|
-
* https://www.last.fm/api/show/user.getTopTracks
|
|
108
|
-
* @returns Top Tracks
|
|
109
|
-
*/
|
|
110
|
-
function getTopTracks(method, user, period, limit) {
|
|
111
|
-
const options = {
|
|
112
|
-
method,
|
|
113
|
-
user,
|
|
114
|
-
period,
|
|
115
|
-
limit,
|
|
116
|
-
};
|
|
117
|
-
return (0, request_1.default)(options);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* GET: Weekly album chart - LastFM
|
|
121
|
-
*
|
|
122
|
-
* https://www.last.fm/api/show/user.getWeeklyAlbumChart
|
|
123
|
-
* @returns Weekly album chart
|
|
124
|
-
*/
|
|
125
|
-
function getWeeklyAlbumChart(method, user, period, limit) {
|
|
126
|
-
const options = {
|
|
127
|
-
method,
|
|
128
|
-
user,
|
|
129
|
-
period,
|
|
130
|
-
limit,
|
|
131
|
-
};
|
|
132
|
-
return (0, request_1.default)(options);
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* GET: Weekly artist chart - LastFM
|
|
136
|
-
*
|
|
137
|
-
* https://www.last.fm/api/show/user.getWeeklyArtistChart
|
|
138
|
-
* @returns Weekly artist chart
|
|
139
|
-
*/
|
|
140
|
-
function getWeeklyArtistChart(method, user, period, limit) {
|
|
141
|
-
const options = {
|
|
142
|
-
method,
|
|
143
|
-
user,
|
|
144
|
-
period,
|
|
145
|
-
limit,
|
|
146
|
-
};
|
|
147
|
-
return (0, request_1.default)(options);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* GET: Weekly chart list - LastFM
|
|
151
|
-
*
|
|
152
|
-
* https://www.last.fm/api/show/user.getWeeklyChartList
|
|
153
|
-
* @returns Weekly chart list
|
|
154
|
-
*/
|
|
155
|
-
function getWeeklyChartList(method, user, period, limit) {
|
|
156
|
-
const options = {
|
|
157
|
-
method,
|
|
158
|
-
user,
|
|
159
|
-
period,
|
|
160
|
-
limit,
|
|
161
|
-
};
|
|
162
|
-
return (0, request_1.default)(options);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* GET: Weekly track chart - LastFM
|
|
166
|
-
*
|
|
167
|
-
* https://www.last.fm/api/show/user.getWeeklyTrackChart
|
|
168
|
-
* @returns Weekly track chart
|
|
169
|
-
*/
|
|
170
|
-
function getWeeklyTrackChart(method, user, period, limit) {
|
|
171
|
-
const options = {
|
|
172
|
-
method,
|
|
173
|
-
user,
|
|
174
|
-
period,
|
|
175
|
-
limit,
|
|
176
|
-
};
|
|
177
|
-
return (0, request_1.default)(options);
|
|
178
|
-
}
|
|
179
17
|
return {
|
|
180
|
-
auth,
|
|
181
|
-
config: config_1.
|
|
182
|
-
getInfo,
|
|
183
|
-
getLovedTracks,
|
|
184
|
-
getRecentTracks,
|
|
185
|
-
getTopAlbums,
|
|
186
|
-
getTopArtists,
|
|
187
|
-
getTopTracks,
|
|
188
|
-
getWeeklyAlbumChart,
|
|
189
|
-
getWeeklyArtistChart,
|
|
190
|
-
getWeeklyChartList,
|
|
191
|
-
getWeeklyTrackChart,
|
|
192
|
-
method: method_1.
|
|
18
|
+
auth: auth_1.auth,
|
|
19
|
+
config: config_1.config,
|
|
20
|
+
getInfo: getInfo_1.getInfo,
|
|
21
|
+
getLovedTracks: getLovedTracks_1.getLovedTracks,
|
|
22
|
+
getRecentTracks: getRecentTracks_1.getRecentTracks,
|
|
23
|
+
getTopAlbums: getTopAlbums_1.getTopAlbums,
|
|
24
|
+
getTopArtists: getTopArtists_1.getTopArtists,
|
|
25
|
+
getTopTracks: getTopTracks_1.getTopTracks,
|
|
26
|
+
getWeeklyAlbumChart: getWeeklyAlbumChart_1.getWeeklyAlbumChart,
|
|
27
|
+
getWeeklyArtistChart: getWeeklyArtistChart_1.getWeeklyArtistChart,
|
|
28
|
+
getWeeklyChartList: getWeeklyChartList_1.getWeeklyChartList,
|
|
29
|
+
getWeeklyTrackChart: getWeeklyTrackChart_1.getWeeklyTrackChart,
|
|
30
|
+
method: method_1.method,
|
|
193
31
|
};
|
|
194
32
|
}
|
|
195
33
|
exports.default = LastFmApi;
|
package/dist/method.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.method = void 0;
|
|
4
|
+
;
|
|
5
|
+
;
|
|
6
|
+
exports.method = {
|
|
4
7
|
auth: 'auth.getToken',
|
|
5
8
|
user: {
|
|
6
9
|
getInfo: 'user.getInfo',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
getLovedTracks: 'user.getLovedTracks',
|
|
11
|
+
getRecentTracks: 'user.getRecentTracks',
|
|
12
|
+
getTopAlbums: 'user.getTopAlbums',
|
|
13
|
+
getTopArtists: 'user.getTopArtists',
|
|
14
|
+
getTopTracks: 'user.getTopTracks',
|
|
15
|
+
getWeeklyAlbumChart: 'user.getWeeklyAlbumChart',
|
|
16
|
+
getWeeklyArtistChart: 'user.getWeeklyArtistChart',
|
|
17
|
+
getWeeklyChartList: 'user.getWeeklyChartList',
|
|
18
|
+
getWeeklyTrackChart: 'user.getWeeklyTrackChart',
|
|
16
19
|
},
|
|
17
20
|
};
|
package/dist/request.js
CHANGED
|
@@ -13,7 +13,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
16
|
-
const config_1 =
|
|
16
|
+
const config_1 = require("./config");
|
|
17
|
+
var ErrorResponse;
|
|
18
|
+
(function (ErrorResponse) {
|
|
19
|
+
ErrorResponse[ErrorResponse["InvalidService"] = 2] = "InvalidService";
|
|
20
|
+
ErrorResponse[ErrorResponse["InvalidMethod"] = 3] = "InvalidMethod";
|
|
21
|
+
ErrorResponse[ErrorResponse["AuthenticationFailed"] = 4] = "AuthenticationFailed";
|
|
22
|
+
ErrorResponse[ErrorResponse["InvalidFormat"] = 5] = "InvalidFormat";
|
|
23
|
+
ErrorResponse[ErrorResponse["InvalidParameters"] = 6] = "InvalidParameters";
|
|
24
|
+
ErrorResponse[ErrorResponse["InvalidResource"] = 7] = "InvalidResource";
|
|
25
|
+
ErrorResponse[ErrorResponse["OperationFailed"] = 8] = "OperationFailed";
|
|
26
|
+
ErrorResponse[ErrorResponse["InvalidSessionKey"] = 9] = "InvalidSessionKey";
|
|
27
|
+
ErrorResponse[ErrorResponse["InvalidAPIKey"] = 10] = "InvalidAPIKey";
|
|
28
|
+
ErrorResponse[ErrorResponse["ServiceOffline"] = 11] = "ServiceOffline";
|
|
29
|
+
ErrorResponse[ErrorResponse["InvalidMethodSignature"] = 13] = "InvalidMethodSignature";
|
|
30
|
+
ErrorResponse[ErrorResponse["TemporaryError"] = 16] = "TemporaryError";
|
|
31
|
+
ErrorResponse[ErrorResponse["SuspendedAPIKey"] = 26] = "SuspendedAPIKey";
|
|
32
|
+
ErrorResponse[ErrorResponse["RateLimitExceeded"] = 29] = "RateLimitExceeded";
|
|
33
|
+
})(ErrorResponse || (ErrorResponse = {}));
|
|
17
34
|
const buildUrl = (options) => {
|
|
18
35
|
const params = new URLSearchParams();
|
|
19
36
|
params.append('method', options.method);
|
|
@@ -23,9 +40,9 @@ const buildUrl = (options) => {
|
|
|
23
40
|
params.append('period', options.period);
|
|
24
41
|
if (options.limit)
|
|
25
42
|
params.append('limit', options.limit);
|
|
26
|
-
params.append('api_key', config_1.
|
|
27
|
-
params.append('format', config_1.
|
|
28
|
-
return `${config_1.
|
|
43
|
+
params.append('api_key', config_1.config.api_key);
|
|
44
|
+
params.append('format', config_1.config.format.json);
|
|
45
|
+
return `${config_1.config.base_url}?${params.toString()}`;
|
|
29
46
|
};
|
|
30
47
|
const request = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
48
|
const url = buildUrl(options);
|
|
@@ -35,14 +52,81 @@ const request = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
35
52
|
},
|
|
36
53
|
})
|
|
37
54
|
.then((res) => {
|
|
38
|
-
if (res.
|
|
39
|
-
throw new Error(
|
|
55
|
+
if (!res.ok) {
|
|
56
|
+
throw new Error(res.statusText);
|
|
57
|
+
}
|
|
58
|
+
switch (res.status) {
|
|
59
|
+
case 200: {
|
|
60
|
+
return res.json();
|
|
61
|
+
}
|
|
62
|
+
case 400: {
|
|
63
|
+
throw new Error('Bad request');
|
|
64
|
+
}
|
|
65
|
+
case 401: {
|
|
66
|
+
throw new Error('Unauthorized');
|
|
67
|
+
}
|
|
68
|
+
case 403: {
|
|
69
|
+
throw new Error('Forbidden');
|
|
70
|
+
}
|
|
71
|
+
case 404: {
|
|
72
|
+
throw new Error('Not found');
|
|
73
|
+
}
|
|
74
|
+
case 500: {
|
|
75
|
+
throw new Error('Internal server error');
|
|
76
|
+
}
|
|
77
|
+
case 503: {
|
|
78
|
+
throw new Error('Service unavailable');
|
|
79
|
+
}
|
|
80
|
+
case ErrorResponse.InvalidAPIKey: {
|
|
81
|
+
throw new Error('Invalid API key');
|
|
82
|
+
}
|
|
83
|
+
case ErrorResponse.InvalidMethod: {
|
|
84
|
+
throw new Error('Invalid method');
|
|
85
|
+
}
|
|
86
|
+
case ErrorResponse.InvalidParameters: {
|
|
87
|
+
throw new Error('Invalid parameters');
|
|
88
|
+
}
|
|
89
|
+
case ErrorResponse.InvalidResource: {
|
|
90
|
+
throw new Error('Invalid resource');
|
|
91
|
+
}
|
|
92
|
+
case ErrorResponse.InvalidSessionKey: {
|
|
93
|
+
throw new Error('Invalid session key');
|
|
94
|
+
}
|
|
95
|
+
case ErrorResponse.InvalidService: {
|
|
96
|
+
throw new Error('Invalid service');
|
|
97
|
+
}
|
|
98
|
+
case ErrorResponse.OperationFailed: {
|
|
99
|
+
throw new Error('Operation failed');
|
|
100
|
+
}
|
|
101
|
+
case ErrorResponse.RateLimitExceeded: {
|
|
102
|
+
throw new Error('Rate limit exceeded');
|
|
103
|
+
}
|
|
104
|
+
case ErrorResponse.ServiceOffline: {
|
|
105
|
+
throw new Error('Service offline');
|
|
106
|
+
}
|
|
107
|
+
case ErrorResponse.SuspendedAPIKey: {
|
|
108
|
+
throw new Error('Suspended API key');
|
|
109
|
+
}
|
|
110
|
+
case ErrorResponse.TemporaryError: {
|
|
111
|
+
throw new Error('Temporary error');
|
|
112
|
+
}
|
|
113
|
+
case ErrorResponse.AuthenticationFailed: {
|
|
114
|
+
throw new Error('Authentication failed');
|
|
115
|
+
}
|
|
116
|
+
case ErrorResponse.InvalidFormat: {
|
|
117
|
+
throw new Error('Invalid format');
|
|
118
|
+
}
|
|
119
|
+
case ErrorResponse.InvalidMethodSignature: {
|
|
120
|
+
throw new Error('Invalid method signature');
|
|
121
|
+
}
|
|
122
|
+
default: {
|
|
123
|
+
throw new Error('Unknown error');
|
|
124
|
+
}
|
|
40
125
|
}
|
|
41
|
-
return res.json();
|
|
42
126
|
})
|
|
43
127
|
.then((json) => json)
|
|
44
128
|
.catch((error) => {
|
|
45
|
-
console.log(error);
|
|
129
|
+
console.log('🚨 error:', error);
|
|
46
130
|
}));
|
|
47
131
|
});
|
|
48
132
|
exports.default = request;
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lastfm-nodejs-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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
|
"scripts": {
|
|
7
7
|
"build": "rimraf dist && tsc",
|
|
8
8
|
"clean": "rimraf dist",
|
|
9
9
|
"dev": "npm run clean && tsc --watch --project tsconfig.dev.json",
|
|
10
|
+
"publish": "npm run build && npm publish --access public",
|
|
10
11
|
"test": "npx playwright test --reporter=list"
|
|
11
12
|
},
|
|
12
13
|
"keywords": [
|
|
@@ -27,9 +28,9 @@
|
|
|
27
28
|
"rimraf": "^5.0.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"@playwright/test": "^1.
|
|
31
|
-
"@types/node": "^20.
|
|
32
|
-
"typescript": "^5.
|
|
31
|
+
"@playwright/test": "^1.38.0",
|
|
32
|
+
"@types/node": "^20.6.2",
|
|
33
|
+
"typescript": "^5.2.2"
|
|
33
34
|
},
|
|
34
35
|
"repository": {
|
|
35
36
|
"type": "git",
|
|
@@ -39,4 +40,4 @@
|
|
|
39
40
|
"url": "https://github.com/mannuelf/lastfm-nodejs-client/issues"
|
|
40
41
|
},
|
|
41
42
|
"homepage": "https://github.com/mannuelf/lastfm-nodejs-client#readme"
|
|
42
|
-
}
|
|
43
|
+
}
|
package/src/auth.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AuthResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* POST: Auth - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/auth.getToken
|
|
9
|
+
*
|
|
10
|
+
* Authentication tokens are API account specific.
|
|
11
|
+
* They are valid for 60 minutes from the moment they are granted.
|
|
12
|
+
* Can only used once (they are consumed when a session is created).
|
|
13
|
+
* @returns Auth token
|
|
14
|
+
*/
|
|
15
|
+
export function auth(
|
|
16
|
+
method: string,
|
|
17
|
+
user: string,
|
|
18
|
+
period: string,
|
|
19
|
+
limit: string,
|
|
20
|
+
): Promise<AuthResponse> {
|
|
21
|
+
const options = createOptions(method, user, period, limit);
|
|
22
|
+
return request<AuthResponse>(options);
|
|
23
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import * as dotenv from 'dotenv';
|
|
2
2
|
dotenv.config();
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
interface Config {
|
|
5
|
+
api_key: string;
|
|
6
|
+
app_name: string;
|
|
7
|
+
base_url: string;
|
|
8
|
+
format: {
|
|
9
|
+
json: string;
|
|
10
|
+
xml: string;
|
|
11
|
+
};
|
|
12
|
+
share_secret: string;
|
|
13
|
+
username: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @description Stores the Last.fm API key, app name, base url, format, shared secret, and username.
|
|
17
|
+
* Simply add a .env file to the root of the project and add the following:
|
|
18
|
+
* LASTFM_API_KEY=your_api_key
|
|
19
|
+
* LASTFM_APPNAME=your_app_name
|
|
20
|
+
* LASTFM_API_BASE_URL=your_base_url
|
|
21
|
+
* LASTFM_SHARED_SECRET=your_shared_secret
|
|
22
|
+
* LASTFM_USER=your_username
|
|
23
|
+
*/
|
|
24
|
+
export const config = {
|
|
5
25
|
api_key: `${process.env.LASTFM_API_KEY}`,
|
|
6
26
|
app_name: `${process.env.LASTFM_APPNAME}`,
|
|
7
27
|
base_url: `${process.env.LASTFM_API_BASE_URL}`,
|
|
@@ -11,4 +31,4 @@ export default {
|
|
|
11
31
|
},
|
|
12
32
|
share_secret: `${process.env.LASTFM_SHARED_SECRET}`,
|
|
13
33
|
username: `${process.env.LASTFM_USER}`,
|
|
14
|
-
};
|
|
34
|
+
} satisfies Config;
|
package/src/getInfo.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UserResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: User profile information - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getInfo
|
|
9
|
+
* @returns User profile information
|
|
10
|
+
*/
|
|
11
|
+
export function getInfo(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
): Promise<UserResponse> {
|
|
15
|
+
const options = createOptions(method, user);
|
|
16
|
+
return request<UserResponse>(options);
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LovedTracksResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Love Tracks - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getLovedTracks
|
|
9
|
+
* @returns Loved Tracks;
|
|
10
|
+
*/
|
|
11
|
+
export function getLovedTracks(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<LovedTracksResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<LovedTracksResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RecentTracksResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Recent Tracks - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getRecentTracks
|
|
9
|
+
* @returns Recent Tracks
|
|
10
|
+
*/
|
|
11
|
+
export function getRecentTracks(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<RecentTracksResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<RecentTracksResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TopAlbumsResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Top Albums - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getTopAlbums
|
|
9
|
+
* @returns Top Albums
|
|
10
|
+
*/
|
|
11
|
+
export function getTopAlbums(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<TopAlbumsResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<TopAlbumsResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TopArtistsResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Top Artist - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getTopArtists
|
|
9
|
+
* @returns Top Artists
|
|
10
|
+
*/
|
|
11
|
+
export function getTopArtists(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<TopArtistsResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<TopArtistsResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TopTrackResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Top Tracks - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getTopTracks
|
|
9
|
+
* @returns Top Tracks
|
|
10
|
+
*/
|
|
11
|
+
export function getTopTracks(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<TopTrackResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<TopTrackResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WeeklyAlbumChartResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Weekly album chart - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getWeeklyAlbumChart
|
|
9
|
+
* @returns Weekly album chart
|
|
10
|
+
*/
|
|
11
|
+
export function getWeeklyAlbumChart(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<WeeklyAlbumChartResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<WeeklyAlbumChartResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WeeklyArtistChartResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Weekly artist chart - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getWeeklyArtistChart
|
|
9
|
+
* @returns Weekly artist chart
|
|
10
|
+
*/
|
|
11
|
+
export function getWeeklyArtistChart(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<WeeklyArtistChartResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<WeeklyArtistChartResponse>(options);
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WeeklyChartListResponse } from '../@types';
|
|
2
|
+
import { createOptions } from './createOptions';
|
|
3
|
+
import request from './request';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* GET: Weekly chart list - LastFM
|
|
7
|
+
*
|
|
8
|
+
* https://www.last.fm/api/show/user.getWeeklyChartList
|
|
9
|
+
* @returns Weekly chart list
|
|
10
|
+
*/
|
|
11
|
+
export function getWeeklyChartList(
|
|
12
|
+
method: string,
|
|
13
|
+
user: string,
|
|
14
|
+
period: string,
|
|
15
|
+
limit: string,
|
|
16
|
+
): Promise<WeeklyChartListResponse> {
|
|
17
|
+
const options = createOptions(method, user, period, limit);
|
|
18
|
+
return request<WeeklyChartListResponse>(options);
|
|
19
|
+
}
|