lastfm-nodejs-client 1.0.2 → 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,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ - Adds types file to distribution
6
+ - Updates readme with types imports
7
+
3
8
  ## 1.0.2
4
9
 
5
10
  - Refactors types.d.ts to types.ts so can ship them with package and consumers can import them in their projects.
package/README.md CHANGED
@@ -2,10 +2,6 @@
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
-
9
5
  ## How to use the client
10
6
 
11
7
  Install the npm package in your project.
@@ -18,16 +14,23 @@ Consider [PNPM](https://pnpm.io/) ▶️
18
14
 
19
15
  ### Import it
20
16
 
17
+ Import module
18
+
21
19
  ```js
22
20
  import { lastFm } from 'lastfm-nodejs-client';
23
21
  ```
24
22
 
23
+ Import types
24
+
25
+ ```js
26
+ import { Artist, Track, User, WeeklyAlbum, ...} from 'lastfm-nodejs-client/types';
27
+ ```
28
+
25
29
  ### Use it
26
30
 
27
31
  ```js
28
32
  const lastFm = LastFmApi();
29
- const { config } = lastFm;
30
- const { method } = lastFm;
33
+ const { config, method } = lastFm;
31
34
 
32
35
  const getUser = async () => {
33
36
  const data = await lastFm.getInfo(
@@ -47,7 +50,7 @@ console.log(user.name);
47
50
 
48
51
  ## Developing client
49
52
 
50
- Written in TypeScript and compiles down to ES2015.
53
+ Written in TypeScript, compiles down to ES2015, provides the types for the lastFm entities.
51
54
 
52
55
  ### Postman collections
53
56
 
@@ -55,32 +58,41 @@ A list of endpoints currently mapped to this client. Still under development, no
55
58
 
56
59
  [View collections](https://documenter.getpostman.com/view/4217/2s8YKJELqJ) ▶️
57
60
 
58
- Clone repo
61
+ ## Clone repo
59
62
 
60
63
  ```bash
61
64
  git clone git@github.com:mannuelf/lastfm-nodejs-client.git
62
65
  ```
63
66
 
64
- create `.env` file in project root.
65
- 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:
66
75
 
67
76
  ```bash
68
77
  LASTFM_API_BASE_URL=""
69
78
  LASTFM_API_KEY=""
70
79
  LASTFM_APPNAME=""
71
- LASTFM_USER=""
72
80
  ```
73
81
 
74
- Get it [here](https://www.last.fm/api/account/create)
82
+ Create them [here](https://www.last.fm/api/account/create).
75
83
 
76
- Develop
84
+ ### Develop
77
85
 
78
86
  ```bash
79
87
  pnpm dev
80
88
  ```
81
89
 
82
- Build
90
+ ### Build
83
91
 
84
92
  ```bash
85
93
  pnpm build
86
94
  ```
95
+
96
+ ### Why I built this?
97
+
98
+ I was building a scrobbles page [https://mannuelferreira.com/scrobbles](https://mannuelferreira.com/scrobbles) and I thought others might want it to.
package/dist/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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lastfm-nodejs-client",
3
- "version": "1.0.2",
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": {