lastfm-nodejs-client 1.2.3 → 1.2.4

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.
@@ -20,13 +20,15 @@ jobs:
20
20
  run: pnpm install
21
21
  - name: Install Playwright Browsers
22
22
  run: npx playwright install --with-deps
23
+ - name: Install @playwright/test package
24
+ run: pnpm add -D @playwright/test
23
25
  - name: Creates environment variables
24
26
  run: |
25
27
  echo "LASTFM_API_BASE_URL: https://ws.audioscrobbler.com/2.0/"
26
28
  echo "LASTFM_API_KEY: abcdefghijklmnopqrstuvxyz"
27
29
  - name: Run Playwright tests
28
30
  run: pnpm dlx playwright test
29
- - uses: actions/upload-artifact@v3
31
+ - uses: actions/upload-artifact@v2
30
32
  if: always()
31
33
  with:
32
34
  name: playwright-report
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ v20
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.4
4
+
5
+ - Updates npm dependencies
6
+ - Refactors request methods options and updates all callsites.
7
+ - Add nvmrc file for easy switching node version.
8
+
3
9
  ## 1.2.3
4
10
 
5
11
  - Adds tests, using Playwright
package/SECURITY.md CHANGED
@@ -2,13 +2,12 @@
2
2
 
3
3
  ## Supported Versions
4
4
 
5
- Dependebot alerts have been enabled and security patches to any dependecies will be brought to light and merged manually by maintainer.
5
+ Dependabot alerts have been enabled and security patches to any dependencies will be brought to light and merged manually by maintainer.
6
6
 
7
7
  | Version | Supported |
8
8
  | ------- | ------------------ |
9
9
  | 1.0.x | :white_check_mark: |
10
10
 
11
-
12
11
  ## Reporting a Vulnerability
13
12
 
14
13
  If you find anything at all kindly report it as bug report here on github ✌️
package/dist/index.js CHANGED
@@ -18,7 +18,13 @@ function LastFmApi() {
18
18
  * @returns Auth token
19
19
  */
20
20
  function auth(method, user, period, limit) {
21
- return (0, request_1.default)(method, user, period, limit);
21
+ const options = {
22
+ method,
23
+ user,
24
+ period,
25
+ limit,
26
+ };
27
+ return (0, request_1.default)(options);
22
28
  }
23
29
  /**
24
30
  * GET: User profile information - LastFM
@@ -27,7 +33,13 @@ function LastFmApi() {
27
33
  * @returns User profile data
28
34
  */
29
35
  function getInfo(method, user, period, limit) {
30
- return (0, request_1.default)(method, user, period, limit);
36
+ const options = {
37
+ method,
38
+ user,
39
+ period,
40
+ limit,
41
+ };
42
+ return (0, request_1.default)(options);
31
43
  }
32
44
  /**
33
45
  * GET: Love Tracks - LastFM
@@ -36,7 +48,13 @@ function LastFmApi() {
36
48
  * @returns Loved Tracks;
37
49
  */
38
50
  function getLovedTracks(method, user, period, limit) {
39
- return (0, request_1.default)(method, user, period, limit);
51
+ const options = {
52
+ method,
53
+ user,
54
+ period,
55
+ limit,
56
+ };
57
+ return (0, request_1.default)(options);
40
58
  }
41
59
  /**
42
60
  * GET: Recent Tracks - LastFM
@@ -45,7 +63,13 @@ function LastFmApi() {
45
63
  * @returns Recent Tracks
46
64
  */
47
65
  function getRecentTracks(method, user, period, limit) {
48
- return (0, request_1.default)(method, user, period, limit);
66
+ const options = {
67
+ method,
68
+ user,
69
+ period,
70
+ limit,
71
+ };
72
+ return (0, request_1.default)(options);
49
73
  }
50
74
  /**
51
75
  * GET: Top Albums - LastFM
@@ -54,7 +78,13 @@ function LastFmApi() {
54
78
  * @returns Top Albums
55
79
  */
56
80
  function getTopAlbums(method, user, period, limit) {
57
- return (0, request_1.default)(method, user, period, limit);
81
+ const options = {
82
+ method,
83
+ user,
84
+ period,
85
+ limit,
86
+ };
87
+ return (0, request_1.default)(options);
58
88
  }
59
89
  /**
60
90
  * GET: Top Artist - LastFM
@@ -63,7 +93,13 @@ function LastFmApi() {
63
93
  * @returns Top Artists
64
94
  */
65
95
  function getTopArtists(method, user, period, limit) {
66
- return (0, request_1.default)(method, user, period, limit);
96
+ const options = {
97
+ method,
98
+ user,
99
+ period,
100
+ limit,
101
+ };
102
+ return (0, request_1.default)(options);
67
103
  }
68
104
  /**
69
105
  * GET: Top Tracks - LastFM
@@ -72,7 +108,13 @@ function LastFmApi() {
72
108
  * @returns Top Tracks
73
109
  */
74
110
  function getTopTracks(method, user, period, limit) {
75
- return (0, request_1.default)(method, user, period, limit);
111
+ const options = {
112
+ method,
113
+ user,
114
+ period,
115
+ limit,
116
+ };
117
+ return (0, request_1.default)(options);
76
118
  }
77
119
  /**
78
120
  * GET: Weekly album chart - LastFM
@@ -81,7 +123,13 @@ function LastFmApi() {
81
123
  * @returns Weekly album chart
82
124
  */
83
125
  function getWeeklyAlbumChart(method, user, period, limit) {
84
- return (0, request_1.default)(method, user, period, limit);
126
+ const options = {
127
+ method,
128
+ user,
129
+ period,
130
+ limit,
131
+ };
132
+ return (0, request_1.default)(options);
85
133
  }
86
134
  /**
87
135
  * GET: Weekly artist chart - LastFM
@@ -90,7 +138,13 @@ function LastFmApi() {
90
138
  * @returns Weekly artist chart
91
139
  */
92
140
  function getWeeklyArtistChart(method, user, period, limit) {
93
- return (0, request_1.default)(method, user, period, limit);
141
+ const options = {
142
+ method,
143
+ user,
144
+ period,
145
+ limit,
146
+ };
147
+ return (0, request_1.default)(options);
94
148
  }
95
149
  /**
96
150
  * GET: Weekly chart list - LastFM
@@ -99,7 +153,13 @@ function LastFmApi() {
99
153
  * @returns Weekly chart list
100
154
  */
101
155
  function getWeeklyChartList(method, user, period, limit) {
102
- return (0, request_1.default)(method, user, period, limit);
156
+ const options = {
157
+ method,
158
+ user,
159
+ period,
160
+ limit,
161
+ };
162
+ return (0, request_1.default)(options);
103
163
  }
104
164
  /**
105
165
  * GET: Weekly track chart - LastFM
@@ -108,7 +168,13 @@ function LastFmApi() {
108
168
  * @returns Weekly track chart
109
169
  */
110
170
  function getWeeklyTrackChart(method, user, period, limit) {
111
- return (0, request_1.default)(method, user, period, limit);
171
+ const options = {
172
+ method,
173
+ user,
174
+ period,
175
+ limit,
176
+ };
177
+ return (0, request_1.default)(options);
112
178
  }
113
179
  return {
114
180
  auth,
package/dist/request.d.ts CHANGED
@@ -1,2 +1,8 @@
1
- declare const request: <Response_1>(method: string, user: string, period?: string, limit?: string) => Promise<Response_1>;
1
+ interface RequestOptions {
2
+ method: string;
3
+ user?: string;
4
+ period?: string;
5
+ limit?: string;
6
+ }
7
+ declare const request: <Response_1>(options: RequestOptions) => Promise<Response_1>;
2
8
  export default request;
package/dist/request.js CHANGED
@@ -14,9 +14,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
16
16
  const config_1 = __importDefault(require("./config"));
17
- const request = (method, user, period, limit) => __awaiter(void 0, void 0, void 0, function* () {
18
- const url = `
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}`;
17
+ const buildUrl = (options) => {
18
+ const params = new URLSearchParams();
19
+ params.append('method', options.method);
20
+ if (options.user)
21
+ params.append('user', options.user);
22
+ if (options.period)
23
+ params.append('period', options.period);
24
+ if (options.limit)
25
+ params.append('limit', options.limit);
26
+ params.append('api_key', config_1.default.api_key);
27
+ params.append('format', config_1.default.format.json);
28
+ return `${config_1.default.base_url}?${params.toString()}`;
29
+ };
30
+ const request = (options) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const url = buildUrl(options);
20
32
  return (yield (0, cross_fetch_1.default)(url, {
21
33
  headers: {
22
34
  'Content-Type': 'application/json',
package/package.json CHANGED
@@ -1,8 +1,14 @@
1
1
  {
2
2
  "name": "lastfm-nodejs-client",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
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
+ "scripts": {
7
+ "build": "rimraf dist && tsc",
8
+ "clean": "rimraf dist",
9
+ "dev": "npm run clean && tsc --watch --project tsconfig.dev.json",
10
+ "test": "npx playwright test --reporter=list"
11
+ },
6
12
  "keywords": [
7
13
  "client",
8
14
  "lastFm",
@@ -16,14 +22,14 @@
16
22
  ],
17
23
  "license": "MIT",
18
24
  "dependencies": {
19
- "cross-fetch": "^3.1.5",
20
- "dotenv": "^16.0.3",
21
- "rimraf": "^3.0.2"
25
+ "cross-fetch": "^4.0.0",
26
+ "dotenv": "^16.3.1",
27
+ "rimraf": "^5.0.1"
22
28
  },
23
29
  "devDependencies": {
24
- "@playwright/test": "^1.28.1",
25
- "@types/node": "^18.11.7",
26
- "typescript": "^4.8.4"
30
+ "@playwright/test": "^1.37.1",
31
+ "@types/node": "^20.5.1",
32
+ "typescript": "^5.1.6"
27
33
  },
28
34
  "repository": {
29
35
  "type": "git",
@@ -32,11 +38,5 @@
32
38
  "bugs": {
33
39
  "url": "https://github.com/mannuelf/lastfm-nodejs-client/issues"
34
40
  },
35
- "homepage": "https://github.com/mannuelf/lastfm-nodejs-client#readme",
36
- "scripts": {
37
- "build": "rimraf dist && tsc",
38
- "clean": "rimraf dist",
39
- "dev": "npm run clean && tsc --watch --project tsconfig.dev.json",
40
- "test": "npx playwright test --reporter=list"
41
- }
42
- }
41
+ "homepage": "https://github.com/mannuelf/lastfm-nodejs-client#readme"
42
+ }
package/src/index.ts CHANGED
@@ -32,7 +32,13 @@ function LastFmApi() {
32
32
  period: string,
33
33
  limit: string,
34
34
  ): Promise<AuthResponse> {
35
- return request(method, user, period, limit);
35
+ const options = {
36
+ method,
37
+ user,
38
+ period,
39
+ limit,
40
+ }
41
+ return request<AuthResponse>(options);
36
42
  }
37
43
 
38
44
  /**
@@ -47,7 +53,13 @@ function LastFmApi() {
47
53
  period: string,
48
54
  limit: string,
49
55
  ): Promise<UserResponse> {
50
- return request(method, user, period, limit);
56
+ const options = {
57
+ method,
58
+ user,
59
+ period,
60
+ limit,
61
+ }
62
+ return request<UserResponse>(options);
51
63
  }
52
64
 
53
65
  /**
@@ -62,7 +74,13 @@ function LastFmApi() {
62
74
  period: string,
63
75
  limit: string,
64
76
  ): Promise<LovedTracksResponse> {
65
- return request(method, user, period, limit);
77
+ const options = {
78
+ method,
79
+ user,
80
+ period,
81
+ limit,
82
+ }
83
+ return request<LovedTracksResponse>(options);
66
84
  }
67
85
 
68
86
  /**
@@ -77,7 +95,13 @@ function LastFmApi() {
77
95
  period: string,
78
96
  limit: string,
79
97
  ): Promise<RecentTracksResponse> {
80
- return request(method, user, period, limit);
98
+ const options = {
99
+ method,
100
+ user,
101
+ period,
102
+ limit,
103
+ }
104
+ return request<RecentTracksResponse>(options);
81
105
  }
82
106
 
83
107
  /**
@@ -92,7 +116,13 @@ function LastFmApi() {
92
116
  period: string,
93
117
  limit: string,
94
118
  ): Promise<TopAlbumsResponse> {
95
- return request(method, user, period, limit);
119
+ const options = {
120
+ method,
121
+ user,
122
+ period,
123
+ limit,
124
+ }
125
+ return request<TopAlbumsResponse>(options);
96
126
  }
97
127
 
98
128
  /**
@@ -107,7 +137,13 @@ function LastFmApi() {
107
137
  period: string,
108
138
  limit: string,
109
139
  ): Promise<TopArtistsResponse> {
110
- return request(method, user, period, limit);
140
+ const options = {
141
+ method,
142
+ user,
143
+ period,
144
+ limit,
145
+ }
146
+ return request<TopArtistsResponse>(options);
111
147
  }
112
148
 
113
149
  /**
@@ -122,7 +158,13 @@ function LastFmApi() {
122
158
  period: string,
123
159
  limit: string,
124
160
  ): Promise<TopTrackResponse> {
125
- return request(method, user, period, limit);
161
+ const options = {
162
+ method,
163
+ user,
164
+ period,
165
+ limit,
166
+ }
167
+ return request<TopTrackResponse>(options);
126
168
  }
127
169
 
128
170
  /**
@@ -137,7 +179,13 @@ function LastFmApi() {
137
179
  period: string,
138
180
  limit: string,
139
181
  ): Promise<WeeklyAlbumChartResponse> {
140
- return request(method, user, period, limit);
182
+ const options = {
183
+ method,
184
+ user,
185
+ period,
186
+ limit,
187
+ }
188
+ return request<WeeklyAlbumChartResponse>(options);
141
189
  }
142
190
 
143
191
  /**
@@ -152,7 +200,13 @@ function LastFmApi() {
152
200
  period: string,
153
201
  limit: string,
154
202
  ): Promise<WeeklyArtistChartResponse> {
155
- return request(method, user, period, limit);
203
+ const options = {
204
+ method,
205
+ user,
206
+ period,
207
+ limit,
208
+ }
209
+ return request<WeeklyArtistChartResponse>(options);
156
210
  }
157
211
 
158
212
  /**
@@ -167,7 +221,13 @@ function LastFmApi() {
167
221
  period: string,
168
222
  limit: string,
169
223
  ): Promise<WeeklyChartListResponse> {
170
- return request(method, user, period, limit);
224
+ const options = {
225
+ method,
226
+ user,
227
+ period,
228
+ limit,
229
+ }
230
+ return request<WeeklyChartListResponse>(options);
171
231
  }
172
232
 
173
233
  /**
@@ -182,7 +242,13 @@ function LastFmApi() {
182
242
  period: string,
183
243
  limit: string,
184
244
  ): Promise<WeeklyTrackChartResponse> {
185
- return request(method, user, period, limit);
245
+ const options = {
246
+ method,
247
+ user,
248
+ period,
249
+ limit,
250
+ }
251
+ return request<WeeklyTrackChartResponse>(options);
186
252
  }
187
253
 
188
254
  return {
package/src/request.ts CHANGED
@@ -1,18 +1,26 @@
1
1
  import fetch from 'cross-fetch';
2
2
  import config from './config';
3
3
 
4
- const request = async <Response>(
5
- method: string,
6
- user: string,
7
- period?: string,
8
- limit?: string,
9
- ): Promise<Response> => {
10
- const url = `
11
- ${config.base_url}?method=${method}${user ? '&user=' : ''}${user}${
12
- user ? '&user=' : ''
13
- }${user}${period ? '&period=' : ''}${period}&${limit ? '&limit=' : ''}${limit}&api_key=${
14
- config.api_key
15
- }&format=${config.format.json}`;
4
+ interface RequestOptions {
5
+ method: string;
6
+ user?: string;
7
+ period?: string;
8
+ limit?: string;
9
+ }
10
+
11
+ const buildUrl = (options: RequestOptions): string => {
12
+ const params = new URLSearchParams();
13
+ params.append('method', options.method);
14
+ if (options.user) params.append('user', options.user);
15
+ if (options.period) params.append('period', options.period);
16
+ if (options.limit) params.append('limit', options.limit);
17
+ params.append('api_key', config.api_key);
18
+ params.append('format', config.format.json);
19
+ return `${config.base_url}?${params.toString()}`;
20
+ }
21
+
22
+ const request = async <Response>(options: RequestOptions): Promise<Response> => {
23
+ const url = buildUrl(options);
16
24
 
17
25
  return (await fetch(url, {
18
26
  headers: {