lastfm-nodejs-client 1.0.1 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ - Adds types file to distribution
6
+ - Updates readme with types imports
7
+
8
+ ## 1.0.2
9
+
10
+ - Refactors types.d.ts to types.ts so can ship them with package and consumers can import them in their projects.
11
+
3
12
  ## 1.0.1
4
13
 
5
14
  - Refactors config and methods to own modules
package/README.md CHANGED
@@ -14,16 +14,23 @@ Consider [PNPM](https://pnpm.io/) ▶️
14
14
 
15
15
  ### Import it
16
16
 
17
+ Import module
18
+
17
19
  ```js
18
20
  import { lastFm } from 'lastfm-nodejs-client';
19
21
  ```
20
22
 
23
+ Import types
24
+
25
+ ```js
26
+ import { Artist, Track, User, WeeklyAlbum, ...} from 'lastfm-nodejs-client/types';
27
+ ```
28
+
21
29
  ### Use it
22
30
 
23
31
  ```js
24
32
  const lastFm = LastFmApi();
25
- const { config } = lastFm;
26
- const { method } = lastFm;
33
+ const { config, method } = lastFm;
27
34
 
28
35
  const getUser = async () => {
29
36
  const data = await lastFm.getInfo(
@@ -43,7 +50,7 @@ console.log(user.name);
43
50
 
44
51
  ## Developing client
45
52
 
46
- Written in TypeScript and compiles down to ES2015.
53
+ Written in TypeScript, compiles down to ES2015, provides the types for the lastFm entities.
47
54
 
48
55
  ### Postman collections
49
56
 
@@ -51,44 +58,41 @@ A list of endpoints currently mapped to this client. Still under development, no
51
58
 
52
59
  [View collections](https://documenter.getpostman.com/view/4217/2s8YKJELqJ) ▶️
53
60
 
54
- Clone repo
61
+ ## Clone repo
55
62
 
56
63
  ```bash
57
64
  git clone git@github.com:mannuelf/lastfm-nodejs-client.git
58
65
  ```
59
66
 
60
- create `.env` file in project root.
61
- Requirements for environment are:
67
+ Create `.env` file in project root.
68
+ Requirements for environment are at minimum a username. You do not need an API key to query the public USER entity.
69
+
70
+ ```bash
71
+ LASTFM_USER=""
72
+ ```
73
+
74
+ For everything else you will need:
62
75
 
63
76
  ```bash
64
77
  LASTFM_API_BASE_URL=""
65
78
  LASTFM_API_KEY=""
66
79
  LASTFM_APPNAME=""
67
- LASTFM_USER=""
68
80
  ```
69
81
 
70
- Get it [here](https://www.last.fm/api/account/create)
82
+ Create them [here](https://www.last.fm/api/account/create).
71
83
 
72
- Develop
84
+ ### Develop
73
85
 
74
86
  ```bash
75
87
  pnpm dev
76
88
  ```
77
89
 
78
- Build
90
+ ### Build
79
91
 
80
92
  ```bash
81
93
  pnpm build
82
94
  ```
83
95
 
84
- ## Testing code
85
-
86
- ```bash
87
- pnpm test
88
- ```
89
-
90
- ## TODO
96
+ ### Why I built this?
91
97
 
92
- - [ ] Add types to DefinitelyTyped project
93
- - [ ] Write tests
94
- - [ ] Write more endpoints
98
+ I was building a scrobbles page [https://mannuelferreira.com/scrobbles](https://mannuelferreira.com/scrobbles) and I thought others might want it to.
@@ -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 = {}));
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lastfm-nodejs-client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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": {
@@ -16,6 +16,9 @@
16
16
  "node"
17
17
  ],
18
18
  "author": "Mannuel Ferreira",
19
+ "maintainers": [
20
+ "Mannuel Ferreira"
21
+ ],
19
22
  "license": "MIT",
20
23
  "dependencies": {
21
24
  "node-fetch": "^3.2.10",
package/src/types.ts ADDED
@@ -0,0 +1,295 @@
1
+ export interface AuthResponse {
2
+ token: string;
3
+ }
4
+
5
+ export interface LovedTracksResponse {
6
+ lovedtracks: LovedTracks;
7
+ }
8
+
9
+ export interface LovedTracks {
10
+ track: Track[];
11
+ '@attr': Attr;
12
+ }
13
+ export interface TopAlbumsResponse {
14
+ topalbums: TopAlbums;
15
+ }
16
+
17
+ export interface TopTrackResponse {
18
+ toptracks: TopTracks;
19
+ }
20
+
21
+ export interface TopTracks {
22
+ track: Track[];
23
+ '@attr': Attr2;
24
+ }
25
+
26
+ export interface UserResponse {
27
+ user: User;
28
+ }
29
+
30
+ export interface RecentTracksResponse {
31
+ recenttracks: RecentTracks;
32
+ }
33
+
34
+ export interface RecentTracks {
35
+ track: Track[];
36
+ '@attr': Attr2;
37
+ }
38
+
39
+ export interface LoveTracksResponse {
40
+ lovedtracks: LovedTracks;
41
+ }
42
+
43
+ export interface LovedTracks {
44
+ track: Track[];
45
+ '@attr': Attr;
46
+ }
47
+ export interface FriendsResponse {
48
+ friends: Friends;
49
+ }
50
+
51
+ export interface Friends {
52
+ '@attr': Attr;
53
+ user: User[];
54
+ }
55
+
56
+ export interface TopArtistsResponse {
57
+ topartists: TopArtists;
58
+ }
59
+
60
+ export interface TopArtists {
61
+ artist: Artist[];
62
+ '@attr': Attr2;
63
+ }
64
+
65
+ export interface WeeklyArtistChartResponse {
66
+ weeklyartistchart: WeeklyArtistChart;
67
+ }
68
+
69
+ export interface WeeklyArtistChart {
70
+ artist: Artist[];
71
+ '@attr': Attr2;
72
+ }
73
+
74
+ export interface WeeklyAlbumChartResponse {
75
+ weeklyalbumchart: WeeklyAlbumChart;
76
+ }
77
+
78
+ export interface WeeklyAlbumChart {
79
+ album: WeeklyAlbum[];
80
+ '@attr': WeeklyalbumChartAttr;
81
+ }
82
+
83
+ export type WeeklyAlbum = {
84
+ artist: {
85
+ mbid: string;
86
+ '#text': string;
87
+ };
88
+ mbid: string;
89
+ url: string;
90
+ name: string;
91
+ '@attr': { rank: string };
92
+ playcount: string;
93
+ image?: string;
94
+ };
95
+
96
+ export interface WeeklyalbumChartAttr {
97
+ from: string;
98
+ to: string;
99
+ user: string;
100
+ }
101
+
102
+ export interface AlbumAttr {
103
+ rank: string;
104
+ }
105
+
106
+ export type Artist = {
107
+ '@attr': {
108
+ rank: number;
109
+ };
110
+ cover: ArtistImage;
111
+ image?: string;
112
+ mbid: string;
113
+ name: string;
114
+ playcount: number;
115
+ streamable: number;
116
+ url: string;
117
+ '#text': string;
118
+ };
119
+
120
+ export interface Attribs {
121
+ page: number;
122
+ perPage: number;
123
+ user: string;
124
+ total: number;
125
+ totalPages: number;
126
+ }
127
+
128
+ export interface ArtistImage {
129
+ name: string;
130
+ photo: string;
131
+ attribution: string;
132
+ playcount: number;
133
+ }
134
+
135
+ export interface Album {
136
+ mbid: string;
137
+ '#text': string;
138
+ }
139
+
140
+ export interface Attr {
141
+ nowplaying: string;
142
+ }
143
+
144
+ export interface Date {
145
+ uts: string;
146
+ '#text': string;
147
+ }
148
+
149
+ export interface Track {
150
+ artist: Artist;
151
+ streamable: string;
152
+ image: '';
153
+ mbid: string;
154
+ album: Album;
155
+ name: string;
156
+ '@attr': Attr;
157
+ url: string;
158
+ date: Date;
159
+ }
160
+
161
+ export interface Attr2 {
162
+ user: string;
163
+ totalPages: string;
164
+ page: string;
165
+ perPage: string;
166
+ total: string;
167
+ }
168
+
169
+ export interface RecentTracks {
170
+ track: Track[];
171
+ '@attr': Attr2;
172
+ }
173
+
174
+ export interface Image {
175
+ size: string;
176
+ '#text': string;
177
+ }
178
+
179
+ export interface Registered {
180
+ unixtime: string;
181
+ '#text': number;
182
+ }
183
+
184
+ export interface User {
185
+ name: string;
186
+ age: string;
187
+ subscriber: string;
188
+ realname: string;
189
+ bootstrap: string;
190
+ playcount: string;
191
+ artist_count: string;
192
+ playlists: string;
193
+ track_count: string;
194
+ album_count: string;
195
+ image: Image[];
196
+ registered: Registered;
197
+ country: string;
198
+ gender: string;
199
+ url: string;
200
+ type: string;
201
+ }
202
+
203
+ export interface TopAlbums {
204
+ album: Album[];
205
+ '@attr': Attr2;
206
+ }
207
+
208
+ export interface WeeklyArtistChartResponse {
209
+ weeklyartistchart: WeeklyArtistChart;
210
+ }
211
+
212
+ export interface WeeklyArtistChart {
213
+ artist: Artist[];
214
+ '@attr': Attr2;
215
+ }
216
+
217
+ export interface Attr1 {
218
+ rank: string;
219
+ }
220
+
221
+ export interface Attr2 {
222
+ from: string;
223
+ user: string;
224
+ to: string;
225
+ }
226
+
227
+ export interface WeeklyChartListResponse {
228
+ weeklychartlist: WeeklyChartList;
229
+ }
230
+
231
+ export interface WeeklyChartList {
232
+ chart: WeeklyChartListChart[];
233
+ '@attr': WeeklyChartListAttr;
234
+ }
235
+
236
+ export interface WeeklyChartListChart {
237
+ '#text': string;
238
+ from: string;
239
+ to: string;
240
+ }
241
+
242
+ export interface WeeklyChartListAttr {
243
+ user: string;
244
+ }
245
+
246
+ export interface WeeklyTrackChartResponse {
247
+ weeklytrackchart: WeeklyTrackChart;
248
+ }
249
+
250
+ export interface WeeklyTrackChart {
251
+ track: Track[];
252
+ '@attr': WeeklyTrackChartAttr2;
253
+ }
254
+
255
+ export interface WeeklyTrackChartTrack {
256
+ artist: WeeklyTrackChartArtist;
257
+ image: Image[];
258
+ mbid: string;
259
+ url: string;
260
+ name: string;
261
+ '@attr': Attr;
262
+ playcount: string;
263
+ }
264
+
265
+ export interface WeeklyTrackChartArtist {
266
+ mbid: string;
267
+ '#text': string;
268
+ }
269
+
270
+ export interface WeeklyTrackChartAttr {
271
+ rank: string;
272
+ }
273
+
274
+ export interface WeeklyTrackChartAttr2 {
275
+ from: string;
276
+ user: string;
277
+ to: string;
278
+ }
279
+
280
+ export enum Errors {
281
+ 'InvalidService' = 2,
282
+ 'InvalidMethod' = 3,
283
+ 'AuthenticationFailed' = 4,
284
+ 'Invalid format' = 5,
285
+ 'Invalid parameters' = 6,
286
+ 'InvalidResourceSpecified' = 7,
287
+ 'OperationFailed' = 8,
288
+ 'Invalid session key' = 9,
289
+ 'InvalidApiKey' = 10,
290
+ 'ServiceOffline' = 11,
291
+ 'InvalidMethodSignatureSupplied' = 13,
292
+ 'TemporaryErrorRequest' = 16,
293
+ 'SuspendedApiKey' = 26,
294
+ 'RateLimitExceeded' = 29,
295
+ }