lastfm-nodejs-client 1.2.1 → 1.2.3

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 CHANGED
@@ -1,5 +1,5 @@
1
- LASTFM_API_BASE_URL=""
2
- LASTFM_API_KEY=""
3
- LASTFM_APPNAME=""
4
- LASTFM_SHARED_SECRET=""
5
- LASTFM_USER=""
1
+ LASTFM_API_BASE_URL="https://ws.audioscrobbler.com/2.0/"
2
+ LASTFM_API_KEY="abcdefghijkhlmnopqrstuvwxyz"
3
+ LASTFM_APPNAME="your app name"
4
+ LASTFM_SHARED_SECRET="xxxxxxxxxxxxxxxxxxxxx"
5
+ LASTFM_USER="your username"
@@ -0,0 +1,34 @@
1
+ name: Playwright Tests
2
+ on:
3
+ push:
4
+ branches: [main, master]
5
+ pull_request:
6
+ branches: [main, master]
7
+ jobs:
8
+ test:
9
+ timeout-minutes: 60
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: actions/setup-node@v3
14
+ with:
15
+ node-version: 16
16
+ - uses: pnpm/action-setup@v2
17
+ with:
18
+ version: 7.14.1
19
+ - name: Install dependencies
20
+ run: pnpm install
21
+ - name: Install Playwright Browsers
22
+ run: npx playwright install --with-deps
23
+ - name: Creates environment variables
24
+ run: |
25
+ echo "LASTFM_API_BASE_URL: https://ws.audioscrobbler.com/2.0/"
26
+ echo "LASTFM_API_KEY: abcdefghijklmnopqrstuvxyz"
27
+ - name: Run Playwright tests
28
+ run: pnpm dlx playwright test
29
+ - uses: actions/upload-artifact@v3
30
+ if: always()
31
+ with:
32
+ name: playwright-report
33
+ path: playwright-report/
34
+ retention-days: 30
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3
4
+
5
+ - Adds tests, using Playwright
6
+ - Adds dotenv npm module as a new dependency
7
+
8
+ ## 1.2.2
9
+
10
+ - Put log back, some APIs do get Bad Request for MBIDs that don't exist, don't have solve for this yet, so not throwing any more as it grinds future request to a halt. This is a working version.
11
+
3
12
  ## 1.2.1
4
13
 
5
14
  - Tidy up, removes console logs
package/SECURITY.md CHANGED
@@ -1,4 +1,4 @@
1
- # Security Policy
1
+ # 🔐 Security Policy
2
2
 
3
3
  ## Supported Versions
4
4
 
package/dist/config.js CHANGED
@@ -1,5 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ const dotenv = __importStar(require("dotenv"));
27
+ dotenv.config();
3
28
  exports.default = {
4
29
  api_key: `${process.env.LASTFM_API_KEY}`,
5
30
  app_name: `${process.env.LASTFM_APPNAME}`,
package/dist/index.js CHANGED
@@ -17,99 +17,99 @@ function LastFmApi() {
17
17
  * Can only used once (they are consumed when a session is created).
18
18
  * @returns Auth token
19
19
  */
20
- const auth = (method, user, period, limit) => {
20
+ function auth(method, user, period, limit) {
21
21
  return (0, request_1.default)(method, user, period, limit);
22
- };
22
+ }
23
23
  /**
24
24
  * GET: User profile information - LastFM
25
25
  *
26
26
  * https://www.last.fm/api/show/user.getInfo
27
27
  * @returns User profile data
28
28
  */
29
- const getInfo = (method, user, period, limit) => {
29
+ function getInfo(method, user, period, limit) {
30
30
  return (0, request_1.default)(method, user, period, limit);
31
- };
31
+ }
32
32
  /**
33
33
  * GET: Love Tracks - LastFM
34
34
  *
35
35
  * https://www.last.fm/api/show/user.getLovedTracks
36
36
  * @returns Loved Tracks;
37
37
  */
38
- const getLovedTracks = (method, user, period, limit) => {
38
+ function getLovedTracks(method, user, period, limit) {
39
39
  return (0, request_1.default)(method, user, period, limit);
40
- };
40
+ }
41
41
  /**
42
42
  * GET: Recent Tracks - LastFM
43
43
  *
44
44
  * https://www.last.fm/api/show/user.getRecentTracks
45
45
  * @returns Recent Tracks
46
46
  */
47
- const getRecentTracks = (method, user, period, limit) => {
47
+ function getRecentTracks(method, user, period, limit) {
48
48
  return (0, request_1.default)(method, user, period, limit);
49
- };
49
+ }
50
50
  /**
51
51
  * GET: Top Albums - LastFM
52
52
  *
53
53
  * https://www.last.fm/api/show/user.getTopAlbums
54
54
  * @returns Top Albums
55
55
  */
56
- const getTopAlbums = (method, user, period, limit) => {
56
+ function getTopAlbums(method, user, period, limit) {
57
57
  return (0, request_1.default)(method, user, period, limit);
58
- };
58
+ }
59
59
  /**
60
60
  * GET: Top Artist - LastFM
61
61
  *
62
62
  * https://www.last.fm/api/show/user.getTopArtists
63
63
  * @returns Top Artists
64
64
  */
65
- const getTopArtists = (method, user, period, limit) => {
65
+ function getTopArtists(method, user, period, limit) {
66
66
  return (0, request_1.default)(method, user, period, limit);
67
- };
67
+ }
68
68
  /**
69
69
  * GET: Top Tracks - LastFM
70
70
  *
71
71
  * https://www.last.fm/api/show/user.getTopTracks
72
72
  * @returns Top Tracks
73
73
  */
74
- const getTopTracks = (method, user, period, limit) => {
74
+ function getTopTracks(method, user, period, limit) {
75
75
  return (0, request_1.default)(method, user, period, limit);
76
- };
76
+ }
77
77
  /**
78
78
  * GET: Weekly album chart - LastFM
79
79
  *
80
80
  * https://www.last.fm/api/show/user.getWeeklyAlbumChart
81
81
  * @returns Weekly album chart
82
82
  */
83
- const getWeeklyAlbumChart = (method, user, period, limit) => {
83
+ function getWeeklyAlbumChart(method, user, period, limit) {
84
84
  return (0, request_1.default)(method, user, period, limit);
85
- };
85
+ }
86
86
  /**
87
87
  * GET: Weekly artist chart - LastFM
88
88
  *
89
89
  * https://www.last.fm/api/show/user.getWeeklyArtistChart
90
90
  * @returns Weekly artist chart
91
91
  */
92
- const getWeeklyArtistChart = (method, user, period, limit) => {
92
+ function getWeeklyArtistChart(method, user, period, limit) {
93
93
  return (0, request_1.default)(method, user, period, limit);
94
- };
94
+ }
95
95
  /**
96
96
  * GET: Weekly chart list - LastFM
97
97
  *
98
98
  * https://www.last.fm/api/show/user.getWeeklyChartList
99
99
  * @returns Weekly chart list
100
100
  */
101
- const getWeeklyChartList = (method, user, period, limit) => {
101
+ function getWeeklyChartList(method, user, period, limit) {
102
102
  return (0, request_1.default)(method, user, period, limit);
103
- };
103
+ }
104
104
  /**
105
105
  * GET: Weekly track chart - LastFM
106
106
  *
107
107
  * https://www.last.fm/api/show/user.getWeeklyTrackChart
108
108
  * @returns Weekly track chart
109
109
  */
110
- const getWeeklyTrackChart = (method, user, period, limit) => {
110
+ function getWeeklyTrackChart(method, user, period, limit) {
111
111
  return (0, request_1.default)(method, user, period, limit);
112
- };
112
+ }
113
113
  return {
114
114
  auth,
115
115
  config: config_1.default,
package/dist/request.js CHANGED
@@ -30,7 +30,7 @@ const request = (method, user, period, limit) => __awaiter(void 0, void 0, void
30
30
  })
31
31
  .then((json) => json)
32
32
  .catch((error) => {
33
- throw new Error(error);
33
+ console.log(error);
34
34
  }));
35
35
  });
36
36
  exports.default = request;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lastfm-nodejs-client",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
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": [
@@ -17,9 +17,11 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "cross-fetch": "^3.1.5",
20
+ "dotenv": "^16.0.3",
20
21
  "rimraf": "^3.0.2"
21
22
  },
22
23
  "devDependencies": {
24
+ "@playwright/test": "^1.28.1",
23
25
  "@types/node": "^18.11.7",
24
26
  "typescript": "^4.8.4"
25
27
  },
@@ -33,7 +35,8 @@
33
35
  "homepage": "https://github.com/mannuelf/lastfm-nodejs-client#readme",
34
36
  "scripts": {
35
37
  "build": "rimraf dist && tsc",
36
- "dev": "tsc --watch",
37
- "test": "echo \"Error: no test specified\" && exit 1"
38
+ "clean": "rimraf dist",
39
+ "dev": "npm run clean && tsc --watch --project tsconfig.dev.json",
40
+ "test": "npx playwright test --reporter=list"
38
41
  }
39
42
  }
@@ -0,0 +1,37 @@
1
+ import { devices, PlaywrightTestConfig } from '@playwright/test';
2
+ import * as dotenv from 'dotenv'; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
3
+ dotenv.config();
4
+
5
+ /**
6
+ * See https://playwright.dev/docs/test-configuration.
7
+ */
8
+ const config: PlaywrightTestConfig = {
9
+ testDir: './tests',
10
+ timeout: 30 * 1000,
11
+ expect: {
12
+ timeout: 5000,
13
+ },
14
+ fullyParallel: true,
15
+ forbidOnly: !!process.env.CI,
16
+ retries: process.env.CI ? 2 : 0,
17
+ workers: process.env.CI ? 1 : undefined,
18
+ reporter: 'html',
19
+ use: {
20
+ actionTimeout: 0,
21
+ trace: 'on-first-retry',
22
+ headless: true,
23
+ },
24
+ projects: [
25
+ {
26
+ name: 'chromium',
27
+ use: { ...devices['Desktop Chrome'] },
28
+ },
29
+ ],
30
+ // outputDir: 'test-results/',
31
+ // webServer: {
32
+ // command: 'npm run dev',
33
+ // port: 3000,
34
+ // },
35
+ };
36
+
37
+ export default config;
package/src/config.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import * as dotenv from 'dotenv';
2
+ dotenv.config();
3
+
1
4
  export default {
2
5
  api_key: `${process.env.LASTFM_API_KEY}`,
3
6
  app_name: `${process.env.LASTFM_APPNAME}`,
package/src/index.ts CHANGED
@@ -26,14 +26,14 @@ function LastFmApi() {
26
26
  * Can only used once (they are consumed when a session is created).
27
27
  * @returns Auth token
28
28
  */
29
- const auth = (
29
+ function auth(
30
30
  method: string,
31
31
  user: string,
32
32
  period: string,
33
33
  limit: string,
34
- ): Promise<AuthResponse> => {
34
+ ): Promise<AuthResponse> {
35
35
  return request(method, user, period, limit);
36
- };
36
+ }
37
37
 
38
38
  /**
39
39
  * GET: User profile information - LastFM
@@ -41,14 +41,14 @@ function LastFmApi() {
41
41
  * https://www.last.fm/api/show/user.getInfo
42
42
  * @returns User profile data
43
43
  */
44
- const getInfo = (
44
+ function getInfo(
45
45
  method: string,
46
46
  user: string,
47
47
  period: string,
48
48
  limit: string,
49
- ): Promise<UserResponse> => {
49
+ ): Promise<UserResponse> {
50
50
  return request(method, user, period, limit);
51
- };
51
+ }
52
52
 
53
53
  /**
54
54
  * GET: Love Tracks - LastFM
@@ -56,14 +56,14 @@ function LastFmApi() {
56
56
  * https://www.last.fm/api/show/user.getLovedTracks
57
57
  * @returns Loved Tracks;
58
58
  */
59
- const getLovedTracks = (
59
+ function getLovedTracks(
60
60
  method: string,
61
61
  user: string,
62
62
  period: string,
63
63
  limit: string,
64
- ): Promise<LovedTracksResponse> => {
64
+ ): Promise<LovedTracksResponse> {
65
65
  return request(method, user, period, limit);
66
- };
66
+ }
67
67
 
68
68
  /**
69
69
  * GET: Recent Tracks - LastFM
@@ -71,14 +71,14 @@ function LastFmApi() {
71
71
  * https://www.last.fm/api/show/user.getRecentTracks
72
72
  * @returns Recent Tracks
73
73
  */
74
- const getRecentTracks = (
74
+ function getRecentTracks(
75
75
  method: string,
76
76
  user: string,
77
77
  period: string,
78
78
  limit: string,
79
- ): Promise<RecentTracksResponse> => {
79
+ ): Promise<RecentTracksResponse> {
80
80
  return request(method, user, period, limit);
81
- };
81
+ }
82
82
 
83
83
  /**
84
84
  * GET: Top Albums - LastFM
@@ -86,14 +86,14 @@ function LastFmApi() {
86
86
  * https://www.last.fm/api/show/user.getTopAlbums
87
87
  * @returns Top Albums
88
88
  */
89
- const getTopAlbums = (
89
+ function getTopAlbums(
90
90
  method: string,
91
91
  user: string,
92
92
  period: string,
93
93
  limit: string,
94
- ): Promise<TopAlbumsResponse> => {
94
+ ): Promise<TopAlbumsResponse> {
95
95
  return request(method, user, period, limit);
96
- };
96
+ }
97
97
 
98
98
  /**
99
99
  * GET: Top Artist - LastFM
@@ -101,14 +101,14 @@ function LastFmApi() {
101
101
  * https://www.last.fm/api/show/user.getTopArtists
102
102
  * @returns Top Artists
103
103
  */
104
- const getTopArtists = (
104
+ function getTopArtists(
105
105
  method: string,
106
106
  user: string,
107
107
  period: string,
108
108
  limit: string,
109
- ): Promise<TopArtistsResponse> => {
109
+ ): Promise<TopArtistsResponse> {
110
110
  return request(method, user, period, limit);
111
- };
111
+ }
112
112
 
113
113
  /**
114
114
  * GET: Top Tracks - LastFM
@@ -116,14 +116,14 @@ function LastFmApi() {
116
116
  * https://www.last.fm/api/show/user.getTopTracks
117
117
  * @returns Top Tracks
118
118
  */
119
- const getTopTracks = (
119
+ function getTopTracks(
120
120
  method: string,
121
121
  user: string,
122
122
  period: string,
123
123
  limit: string,
124
- ): Promise<TopTrackResponse> => {
124
+ ): Promise<TopTrackResponse> {
125
125
  return request(method, user, period, limit);
126
- };
126
+ }
127
127
 
128
128
  /**
129
129
  * GET: Weekly album chart - LastFM
@@ -131,14 +131,14 @@ function LastFmApi() {
131
131
  * https://www.last.fm/api/show/user.getWeeklyAlbumChart
132
132
  * @returns Weekly album chart
133
133
  */
134
- const getWeeklyAlbumChart = (
134
+ function getWeeklyAlbumChart(
135
135
  method: string,
136
136
  user: string,
137
137
  period: string,
138
138
  limit: string,
139
- ): Promise<WeeklyAlbumChartResponse> => {
139
+ ): Promise<WeeklyAlbumChartResponse> {
140
140
  return request(method, user, period, limit);
141
- };
141
+ }
142
142
 
143
143
  /**
144
144
  * GET: Weekly artist chart - LastFM
@@ -146,14 +146,14 @@ function LastFmApi() {
146
146
  * https://www.last.fm/api/show/user.getWeeklyArtistChart
147
147
  * @returns Weekly artist chart
148
148
  */
149
- const getWeeklyArtistChart = (
149
+ function getWeeklyArtistChart(
150
150
  method: string,
151
151
  user: string,
152
152
  period: string,
153
153
  limit: string,
154
- ): Promise<WeeklyArtistChartResponse> => {
154
+ ): Promise<WeeklyArtistChartResponse> {
155
155
  return request(method, user, period, limit);
156
- };
156
+ }
157
157
 
158
158
  /**
159
159
  * GET: Weekly chart list - LastFM
@@ -161,14 +161,14 @@ function LastFmApi() {
161
161
  * https://www.last.fm/api/show/user.getWeeklyChartList
162
162
  * @returns Weekly chart list
163
163
  */
164
- const getWeeklyChartList = (
164
+ function getWeeklyChartList(
165
165
  method: string,
166
166
  user: string,
167
167
  period: string,
168
168
  limit: string,
169
- ): Promise<WeeklyChartListResponse> => {
169
+ ): Promise<WeeklyChartListResponse> {
170
170
  return request(method, user, period, limit);
171
- };
171
+ }
172
172
 
173
173
  /**
174
174
  * GET: Weekly track chart - LastFM
@@ -176,14 +176,14 @@ function LastFmApi() {
176
176
  * https://www.last.fm/api/show/user.getWeeklyTrackChart
177
177
  * @returns Weekly track chart
178
178
  */
179
- const getWeeklyTrackChart = (
179
+ function getWeeklyTrackChart(
180
180
  method: string,
181
181
  user: string,
182
182
  period: string,
183
183
  limit: string,
184
- ): Promise<WeeklyTrackChartResponse> => {
184
+ ): Promise<WeeklyTrackChartResponse> {
185
185
  return request(method, user, period, limit);
186
- };
186
+ }
187
187
 
188
188
  return {
189
189
  auth,
package/src/request.ts CHANGED
@@ -27,7 +27,7 @@ const request = async <Response>(
27
27
  })
28
28
  .then((json) => json)
29
29
  .catch((error) => {
30
- throw new Error(error);
30
+ console.log(error);
31
31
  })) as Response;
32
32
  };
33
33
 
@@ -0,0 +1,21 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import dotenv from 'dotenv';
3
+ import path from 'path';
4
+
5
+ dotenv.config();
6
+ dotenv.config({ path: path.resolve(__dirname, '..', process.env.CI ? '.env.example' : '.env') });
7
+
8
+ const { LASTFM_API_BASE_URL, LASTFM_API_KEY } = process.env;
9
+
10
+ let environmentVarWarning =
11
+ '❗ No environment variable found, use the .env.example file to create your own .env file with required properties and values.';
12
+
13
+ test.describe('Environment variables present and configured', async () => {
14
+ test('LASTFM_API_BASE_URL is present', async () => {
15
+ expect(LASTFM_API_BASE_URL, environmentVarWarning).toBeDefined();
16
+ });
17
+
18
+ test('LASTFM_API_KEY is present', async () => {
19
+ expect(LASTFM_API_KEY, environmentVarWarning).toBeDefined();
20
+ });
21
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": false
5
+ },
6
+ "exclude": ["tests/**/*.spec.ts", "tests/**/*.test.ts", "./playwright.config.ts"]
7
+ }
package/tsconfig.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
+ "exclude": ["tests/**/*.spec.ts", "tests/**/*.test.ts", "./playwright.config.ts"],
2
3
  "compilerOptions": {
3
4
  /* Visit https://aka.ms/tsconfig to read more about this file */
4
5