lastfm-nodejs-client 1.0.0 → 1.0.2

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 CHANGED
@@ -1,3 +1,15 @@
1
- # 1.0.0
1
+ # Changelog
2
+
3
+ ## 1.0.2
4
+
5
+ - Refactors types.d.ts to types.ts so can ship them with package and consumers can import them in their projects.
6
+
7
+ ## 1.0.1
8
+
9
+ - Refactors config and methods to own modules
10
+ - tsconfig, generate types to allow shipping types in one package, no need to DefinitleyTyped right now.
11
+ - update docs with new way of interacting with API.
12
+
13
+ ## 1.0.0
2
14
 
3
15
  - Initial project setup
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A Node JS wrapper client for fetching public data from [LastFm API](https://www.last.fm/api).
4
4
 
5
+ ## But Why?
6
+
7
+ I was building scrobbles page [https://mannuelferreira.com/scrobbles](https://mannuelferreira.com/scrobbles) and I thought other might want it to.
8
+
5
9
  ## How to use the client
6
10
 
7
11
  Install the npm package in your project.
@@ -21,9 +25,13 @@ import { lastFm } from 'lastfm-nodejs-client';
21
25
  ### Use it
22
26
 
23
27
  ```js
28
+ const lastFm = LastFmApi();
29
+ const { config } = lastFm;
30
+ const { method } = lastFm;
31
+
24
32
  const getUser = async () => {
25
33
  const data = await lastFm.getInfo(
26
- config.method.user.getInfo,
34
+ method.user.getInfo,
27
35
  config.username,
28
36
  'overall',
29
37
  12
@@ -76,9 +84,3 @@ Build
76
84
  ```bash
77
85
  pnpm build
78
86
  ```
79
-
80
- ## Testing code
81
-
82
- ```bash
83
- pnpm test
84
- ```
@@ -0,0 +1,12 @@
1
+ declare const _default: {
2
+ api_key: string;
3
+ app_name: string;
4
+ base_url: string;
5
+ format: {
6
+ json: string;
7
+ xml: string;
8
+ };
9
+ share_secret: string;
10
+ username: string;
11
+ };
12
+ export default _default;
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const config = {
3
+ exports.default = {
4
4
  api_key: `${process.env.LASTFM_API_KEY}`,
5
5
  app_name: `${process.env.LASTFM_APPNAME}`,
6
6
  base_url: `${process.env.LASTFM_API_BASE_URL}`,
@@ -8,22 +8,6 @@ const config = {
8
8
  json: 'json',
9
9
  xml: 'xml',
10
10
  },
11
- method: {
12
- auth: 'auth.getToken',
13
- user: {
14
- getInfo: 'user.getInfo',
15
- loved_tracks: 'user.getLovedTracks',
16
- recent_tracks: 'user.getRecentTracks',
17
- top_albums: 'user.getTopAlbums',
18
- top_artists: 'user.getTopArtists',
19
- top_tracks: 'user.getTopTracks',
20
- weekly_album_chart: 'user.getWeeklyAlbumChart',
21
- weekly_artist_chart: 'user.getWeeklyArtistChart',
22
- weekly_chart_list: 'user.getWeeklyChartList',
23
- weekly_track_chart: 'user.getWeeklyTrackChart',
24
- },
25
- },
26
11
  share_secret: `${process.env.LASTFM_SHARED_SECRET}`,
27
12
  username: `${process.env.LASTFM_USER}`,
28
13
  };
29
- exports.default = config;
@@ -0,0 +1,41 @@
1
+ import { AuthResponse, LovedTracksResponse, RecentTracksResponse, TopAlbumsResponse, TopArtistsResponse, TopTrackResponse, UserResponse, WeeklyAlbumChartResponse, WeeklyArtistChartResponse, WeeklyChartListResponse, WeeklyTrackChartResponse } from './types';
2
+ declare const LastFmApi: () => {
3
+ auth: (method: string, user: string, period: string, limit: number) => Promise<AuthResponse>;
4
+ 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
+ getInfo: (method: string, user: string, period: string, limit: number) => Promise<UserResponse>;
16
+ getLovedTracks: (method: string, user: string, period: string, limit: number) => Promise<LovedTracksResponse>;
17
+ getRecentTracks: (method: string, user: string, period: string, limit: number) => Promise<RecentTracksResponse>;
18
+ getTopAlbums: (method: string, user: string, period: string, limit: number) => Promise<TopAlbumsResponse>;
19
+ getTopArtists: (method: string, user: string, period: string, limit: number) => Promise<TopArtistsResponse>;
20
+ getTopTracks: (method: string, user: string, period: string, limit: number) => Promise<TopTrackResponse>;
21
+ getWeeklyAlbumChart: (method: string, user: string, period: string, limit: number) => Promise<WeeklyAlbumChartResponse>;
22
+ getWeeklyArtistChart: (method: string, user: string, period: string, limit: number) => Promise<WeeklyArtistChartResponse>;
23
+ getWeeklyChartList: (method: string, user: string, period: string, limit: number) => Promise<WeeklyChartListResponse>;
24
+ getWeeklyTrackChart: (method: string, user: string, period: string, limit: number) => Promise<WeeklyTrackChartResponse>;
25
+ method: {
26
+ auth: string;
27
+ user: {
28
+ getInfo: string;
29
+ loved_tracks: string;
30
+ recent_tracks: string;
31
+ top_albums: string;
32
+ top_artists: string;
33
+ top_tracks: string;
34
+ weekly_album_chart: string;
35
+ weekly_artist_chart: string;
36
+ weekly_chart_list: string;
37
+ weekly_track_chart: string;
38
+ };
39
+ };
40
+ };
41
+ export default LastFmApi;
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_1 = __importDefault(require("./config"));
7
+ const method_1 = __importDefault(require("./method"));
6
8
  const request_1 = __importDefault(require("./request"));
7
9
  const LastFmApi = function LastFmApi() {
8
10
  /**
@@ -110,6 +112,7 @@ const LastFmApi = function LastFmApi() {
110
112
  };
111
113
  return {
112
114
  auth,
115
+ config: config_1.default,
113
116
  getInfo,
114
117
  getLovedTracks,
115
118
  getRecentTracks,
@@ -120,6 +123,7 @@ const LastFmApi = function LastFmApi() {
120
123
  getWeeklyArtistChart,
121
124
  getWeeklyChartList,
122
125
  getWeeklyTrackChart,
126
+ method: method_1.default,
123
127
  };
124
128
  };
125
129
  exports.default = LastFmApi;
@@ -0,0 +1,16 @@
1
+ declare const _default: {
2
+ auth: string;
3
+ user: {
4
+ getInfo: string;
5
+ loved_tracks: string;
6
+ recent_tracks: string;
7
+ top_albums: string;
8
+ top_artists: string;
9
+ top_tracks: string;
10
+ weekly_album_chart: string;
11
+ weekly_artist_chart: string;
12
+ weekly_chart_list: string;
13
+ weekly_track_chart: string;
14
+ };
15
+ };
16
+ export default _default;
package/dist/method.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ auth: 'auth.getToken',
5
+ user: {
6
+ getInfo: 'user.getInfo',
7
+ loved_tracks: 'user.getLovedTracks',
8
+ recent_tracks: 'user.getRecentTracks',
9
+ top_albums: 'user.getTopAlbums',
10
+ top_artists: 'user.getTopArtists',
11
+ top_tracks: 'user.getTopTracks',
12
+ weekly_album_chart: 'user.getWeeklyAlbumChart',
13
+ weekly_artist_chart: 'user.getWeeklyArtistChart',
14
+ weekly_chart_list: 'user.getWeeklyChartList',
15
+ weekly_track_chart: 'user.getWeeklyTrackChart',
16
+ },
17
+ };
@@ -0,0 +1,2 @@
1
+ declare const request: <Parameters_1, Response_1>(method: string, user: string, period?: string, limit?: number) => Promise<Response_1>;
2
+ export default request;
@@ -0,0 +1,250 @@
1
+ export interface AuthResponse {
2
+ token: string;
3
+ }
4
+ export interface LovedTracksResponse {
5
+ lovedtracks: LovedTracks;
6
+ }
7
+ export interface LovedTracks {
8
+ track: Track[];
9
+ '@attr': Attr;
10
+ }
11
+ export interface TopAlbumsResponse {
12
+ topalbums: TopAlbums;
13
+ }
14
+ export interface TopTrackResponse {
15
+ toptracks: TopTracks;
16
+ }
17
+ export interface TopTracks {
18
+ track: Track[];
19
+ '@attr': Attr2;
20
+ }
21
+ export interface UserResponse {
22
+ user: User;
23
+ }
24
+ export interface RecentTracksResponse {
25
+ recenttracks: RecentTracks;
26
+ }
27
+ export interface RecentTracks {
28
+ track: Track[];
29
+ '@attr': Attr2;
30
+ }
31
+ export interface LoveTracksResponse {
32
+ lovedtracks: LovedTracks;
33
+ }
34
+ export interface LovedTracks {
35
+ track: Track[];
36
+ '@attr': Attr;
37
+ }
38
+ export interface FriendsResponse {
39
+ friends: Friends;
40
+ }
41
+ export interface Friends {
42
+ '@attr': Attr;
43
+ user: User[];
44
+ }
45
+ export interface TopArtistsResponse {
46
+ topartists: TopArtists;
47
+ }
48
+ export interface TopArtists {
49
+ artist: Artist[];
50
+ '@attr': Attr2;
51
+ }
52
+ export interface WeeklyArtistChartResponse {
53
+ weeklyartistchart: WeeklyArtistChart;
54
+ }
55
+ export interface WeeklyArtistChart {
56
+ artist: Artist[];
57
+ '@attr': Attr2;
58
+ }
59
+ export interface WeeklyAlbumChartResponse {
60
+ weeklyalbumchart: WeeklyAlbumChart;
61
+ }
62
+ export interface WeeklyAlbumChart {
63
+ album: WeeklyAlbum[];
64
+ '@attr': WeeklyalbumChartAttr;
65
+ }
66
+ export declare type WeeklyAlbum = {
67
+ artist: {
68
+ mbid: string;
69
+ '#text': string;
70
+ };
71
+ mbid: string;
72
+ url: string;
73
+ name: string;
74
+ '@attr': {
75
+ rank: string;
76
+ };
77
+ playcount: string;
78
+ image?: string;
79
+ };
80
+ export interface WeeklyalbumChartAttr {
81
+ from: string;
82
+ to: string;
83
+ user: string;
84
+ }
85
+ export interface AlbumAttr {
86
+ rank: string;
87
+ }
88
+ export declare type Artist = {
89
+ '@attr': {
90
+ rank: number;
91
+ };
92
+ cover: ArtistImage;
93
+ image?: string;
94
+ mbid: string;
95
+ name: string;
96
+ playcount: number;
97
+ streamable: number;
98
+ url: string;
99
+ '#text': string;
100
+ };
101
+ export interface Attribs {
102
+ page: number;
103
+ perPage: number;
104
+ user: string;
105
+ total: number;
106
+ totalPages: number;
107
+ }
108
+ export interface ArtistImage {
109
+ name: string;
110
+ photo: string;
111
+ attribution: string;
112
+ playcount: number;
113
+ }
114
+ export interface Album {
115
+ mbid: string;
116
+ '#text': string;
117
+ }
118
+ export interface Attr {
119
+ nowplaying: string;
120
+ }
121
+ export interface Date {
122
+ uts: string;
123
+ '#text': string;
124
+ }
125
+ export interface Track {
126
+ artist: Artist;
127
+ streamable: string;
128
+ image: '';
129
+ mbid: string;
130
+ album: Album;
131
+ name: string;
132
+ '@attr': Attr;
133
+ url: string;
134
+ date: Date;
135
+ }
136
+ export interface Attr2 {
137
+ user: string;
138
+ totalPages: string;
139
+ page: string;
140
+ perPage: string;
141
+ total: string;
142
+ }
143
+ export interface RecentTracks {
144
+ track: Track[];
145
+ '@attr': Attr2;
146
+ }
147
+ export interface Image {
148
+ size: string;
149
+ '#text': string;
150
+ }
151
+ export interface Registered {
152
+ unixtime: string;
153
+ '#text': number;
154
+ }
155
+ export interface User {
156
+ name: string;
157
+ age: string;
158
+ subscriber: string;
159
+ realname: string;
160
+ bootstrap: string;
161
+ playcount: string;
162
+ artist_count: string;
163
+ playlists: string;
164
+ track_count: string;
165
+ album_count: string;
166
+ image: Image[];
167
+ registered: Registered;
168
+ country: string;
169
+ gender: string;
170
+ url: string;
171
+ type: string;
172
+ }
173
+ export interface TopAlbums {
174
+ album: Album[];
175
+ '@attr': Attr2;
176
+ }
177
+ export interface WeeklyArtistChartResponse {
178
+ weeklyartistchart: WeeklyArtistChart;
179
+ }
180
+ export interface WeeklyArtistChart {
181
+ artist: Artist[];
182
+ '@attr': Attr2;
183
+ }
184
+ export interface Attr1 {
185
+ rank: string;
186
+ }
187
+ export interface Attr2 {
188
+ from: string;
189
+ user: string;
190
+ to: string;
191
+ }
192
+ export interface WeeklyChartListResponse {
193
+ weeklychartlist: WeeklyChartList;
194
+ }
195
+ export interface WeeklyChartList {
196
+ chart: WeeklyChartListChart[];
197
+ '@attr': WeeklyChartListAttr;
198
+ }
199
+ export interface WeeklyChartListChart {
200
+ '#text': string;
201
+ from: string;
202
+ to: string;
203
+ }
204
+ export interface WeeklyChartListAttr {
205
+ user: string;
206
+ }
207
+ export interface WeeklyTrackChartResponse {
208
+ weeklytrackchart: WeeklyTrackChart;
209
+ }
210
+ export interface WeeklyTrackChart {
211
+ track: Track[];
212
+ '@attr': WeeklyTrackChartAttr2;
213
+ }
214
+ export interface WeeklyTrackChartTrack {
215
+ artist: WeeklyTrackChartArtist;
216
+ image: Image[];
217
+ mbid: string;
218
+ url: string;
219
+ name: string;
220
+ '@attr': Attr;
221
+ playcount: string;
222
+ }
223
+ export interface WeeklyTrackChartArtist {
224
+ mbid: string;
225
+ '#text': string;
226
+ }
227
+ export interface WeeklyTrackChartAttr {
228
+ rank: string;
229
+ }
230
+ export interface WeeklyTrackChartAttr2 {
231
+ from: string;
232
+ user: string;
233
+ to: string;
234
+ }
235
+ export declare enum Errors {
236
+ 'InvalidService' = 2,
237
+ 'InvalidMethod' = 3,
238
+ 'AuthenticationFailed' = 4,
239
+ 'Invalid format' = 5,
240
+ 'Invalid parameters' = 6,
241
+ 'InvalidResourceSpecified' = 7,
242
+ 'OperationFailed' = 8,
243
+ 'Invalid session key' = 9,
244
+ 'InvalidApiKey' = 10,
245
+ 'ServiceOffline' = 11,
246
+ 'InvalidMethodSignatureSupplied' = 13,
247
+ 'TemporaryErrorRequest' = 16,
248
+ 'SuspendedApiKey' = 26,
249
+ 'RateLimitExceeded' = 29
250
+ }
package/dist/types.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Errors = void 0;
4
+ var Errors;
5
+ (function (Errors) {
6
+ Errors[Errors["InvalidService"] = 2] = "InvalidService";
7
+ Errors[Errors["InvalidMethod"] = 3] = "InvalidMethod";
8
+ Errors[Errors["AuthenticationFailed"] = 4] = "AuthenticationFailed";
9
+ Errors[Errors["Invalid format"] = 5] = "Invalid format";
10
+ Errors[Errors["Invalid parameters"] = 6] = "Invalid parameters";
11
+ Errors[Errors["InvalidResourceSpecified"] = 7] = "InvalidResourceSpecified";
12
+ Errors[Errors["OperationFailed"] = 8] = "OperationFailed";
13
+ Errors[Errors["Invalid session key"] = 9] = "Invalid session key";
14
+ Errors[Errors["InvalidApiKey"] = 10] = "InvalidApiKey";
15
+ Errors[Errors["ServiceOffline"] = 11] = "ServiceOffline";
16
+ Errors[Errors["InvalidMethodSignatureSupplied"] = 13] = "InvalidMethodSignatureSupplied";
17
+ Errors[Errors["TemporaryErrorRequest"] = 16] = "TemporaryErrorRequest";
18
+ Errors[Errors["SuspendedApiKey"] = 26] = "SuspendedApiKey";
19
+ Errors[Errors["RateLimitExceeded"] = 29] = "RateLimitExceeded";
20
+ })(Errors = exports.Errors || (exports.Errors = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lastfm-nodejs-client",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A client for fetching public data with username using the LastFm public API",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -10,11 +10,15 @@
10
10
  },
11
11
  "keywords": [
12
12
  "client",
13
- "lastfm",
13
+ "lastFm",
14
14
  "nodejs",
15
- "typescript"
15
+ "typescript",
16
+ "node"
16
17
  ],
17
18
  "author": "Mannuel Ferreira",
19
+ "maintainers": [
20
+ "Mannuel Ferreira"
21
+ ],
18
22
  "license": "MIT",
19
23
  "dependencies": {
20
24
  "node-fetch": "^3.2.10",
package/src/config.ts CHANGED
@@ -1,4 +1,4 @@
1
- const config = {
1
+ export default {
2
2
  api_key: `${process.env.LASTFM_API_KEY}`,
3
3
  app_name: `${process.env.LASTFM_APPNAME}`,
4
4
  base_url: `${process.env.LASTFM_API_BASE_URL}`,
@@ -6,23 +6,6 @@ const config = {
6
6
  json: 'json',
7
7
  xml: 'xml',
8
8
  },
9
- method: {
10
- auth: 'auth.getToken',
11
- user: {
12
- getInfo: 'user.getInfo',
13
- loved_tracks: 'user.getLovedTracks',
14
- recent_tracks: 'user.getRecentTracks',
15
- top_albums: 'user.getTopAlbums',
16
- top_artists: 'user.getTopArtists',
17
- top_tracks: 'user.getTopTracks',
18
- weekly_album_chart: 'user.getWeeklyAlbumChart',
19
- weekly_artist_chart: 'user.getWeeklyArtistChart',
20
- weekly_chart_list: 'user.getWeeklyChartList',
21
- weekly_track_chart: 'user.getWeeklyTrackChart',
22
- },
23
- },
24
9
  share_secret: `${process.env.LASTFM_SHARED_SECRET}`,
25
10
  username: `${process.env.LASTFM_USER}`,
26
11
  };
27
-
28
- export default config;
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import config from './config';
2
+ import method from './method';
3
+ import request from './request';
1
4
  import {
2
5
  AuthResponse,
3
6
  LovedTracksResponse,
@@ -11,7 +14,6 @@ import {
11
14
  WeeklyChartListResponse,
12
15
  WeeklyTrackChartResponse,
13
16
  } from './types';
14
- import request from './request';
15
17
 
16
18
  const LastFmApi = function LastFmApi() {
17
19
  /**
@@ -185,6 +187,7 @@ const LastFmApi = function LastFmApi() {
185
187
 
186
188
  return {
187
189
  auth,
190
+ config,
188
191
  getInfo,
189
192
  getLovedTracks,
190
193
  getRecentTracks,
@@ -195,6 +198,7 @@ const LastFmApi = function LastFmApi() {
195
198
  getWeeklyArtistChart,
196
199
  getWeeklyChartList,
197
200
  getWeeklyTrackChart,
201
+ method,
198
202
  };
199
203
  };
200
204
 
package/src/method.ts ADDED
@@ -0,0 +1,15 @@
1
+ export default {
2
+ auth: 'auth.getToken',
3
+ user: {
4
+ getInfo: 'user.getInfo',
5
+ loved_tracks: 'user.getLovedTracks',
6
+ recent_tracks: 'user.getRecentTracks',
7
+ top_albums: 'user.getTopAlbums',
8
+ top_artists: 'user.getTopArtists',
9
+ top_tracks: 'user.getTopTracks',
10
+ weekly_album_chart: 'user.getWeeklyAlbumChart',
11
+ weekly_artist_chart: 'user.getWeeklyArtistChart',
12
+ weekly_chart_list: 'user.getWeeklyChartList',
13
+ weekly_track_chart: 'user.getWeeklyTrackChart',
14
+ },
15
+ };
File without changes
package/tsconfig.json CHANGED
@@ -44,7 +44,7 @@
44
44
  // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
45
 
46
46
  /* Emit */
47
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
47
+ "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
48
48
  // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
49
  // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
50
  // "sourceMap": true, /* Create source map files for emitted JavaScript files. */