lastfm-nodejs-client 1.4.3 → 1.4.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.
Files changed (132) hide show
  1. package/README.md +14 -2
  2. package/dist/cjs/auth.d.ts +12 -0
  3. package/dist/{auth.js → cjs/auth.js} +11 -11
  4. package/dist/cjs/chart/topArtists.d.ts +2 -0
  5. package/dist/cjs/chart/topArtists.js +13 -0
  6. package/dist/cjs/chart/topTags.d.ts +2 -0
  7. package/dist/cjs/chart/topTags.js +13 -0
  8. package/dist/cjs/chart/topTracks.d.ts +2 -0
  9. package/dist/cjs/chart/topTracks.js +13 -0
  10. package/dist/{config.d.ts → cjs/config.d.ts} +0 -1
  11. package/dist/{config.js → cjs/config.js} +0 -1
  12. package/dist/cjs/createOptions.d.ts +7 -0
  13. package/dist/{createOptions.js → cjs/createOptions.js} +2 -1
  14. package/dist/{getInfo.d.ts → cjs/getInfo.d.ts} +1 -2
  15. package/dist/{getInfo.js → cjs/getInfo.js} +2 -2
  16. package/dist/{getLovedTracks.d.ts → cjs/getLovedTracks.d.ts} +1 -2
  17. package/dist/{getLovedTracks.js → cjs/getLovedTracks.js} +2 -2
  18. package/dist/{getRecentTracks.d.ts → cjs/getRecentTracks.d.ts} +1 -2
  19. package/dist/{getRecentTracks.js → cjs/getRecentTracks.js} +2 -2
  20. package/dist/{getTopAlbums.d.ts → cjs/getTopAlbums.d.ts} +1 -2
  21. package/dist/{getTopAlbums.js → cjs/getTopAlbums.js} +2 -2
  22. package/dist/{getTopArtists.d.ts → cjs/getTopArtists.d.ts} +1 -2
  23. package/dist/{getTopArtists.js → cjs/getTopArtists.js} +2 -2
  24. package/dist/{getTopTracks.d.ts → cjs/getTopTracks.d.ts} +1 -2
  25. package/dist/{getTopTracks.js → cjs/getTopTracks.js} +2 -2
  26. package/dist/{getWeeklyAlbumChart.d.ts → cjs/getWeeklyAlbumChart.d.ts} +1 -2
  27. package/dist/{getWeeklyAlbumChart.js → cjs/getWeeklyAlbumChart.js} +2 -2
  28. package/dist/{getWeeklyArtistChart.d.ts → cjs/getWeeklyArtistChart.d.ts} +1 -2
  29. package/dist/{getWeeklyArtistChart.js → cjs/getWeeklyArtistChart.js} +2 -2
  30. package/dist/{getWeeklyChartList.d.ts → cjs/getWeeklyChartList.d.ts} +1 -2
  31. package/dist/{getWeeklyChartList.js → cjs/getWeeklyChartList.js} +2 -2
  32. package/dist/{getWeeklyTrackChart.d.ts → cjs/getWeeklyTrackChart.d.ts} +1 -2
  33. package/dist/{getWeeklyTrackChart.js → cjs/getWeeklyTrackChart.js} +2 -2
  34. package/dist/{index.d.ts → cjs/index.d.ts} +14 -3
  35. package/dist/cjs/index.js +41 -0
  36. package/dist/{method.d.ts → cjs/method.d.ts} +11 -1
  37. package/dist/{method.js → cjs/method.js} +5 -2
  38. package/dist/cjs/package.json +3 -0
  39. package/dist/{request.d.ts → cjs/request.d.ts} +0 -1
  40. package/dist/{request.js → cjs/request.js} +7 -15
  41. package/dist/mjs/auth.d.ts +12 -0
  42. package/dist/mjs/auth.js +16 -0
  43. package/dist/mjs/chart/topArtists.d.ts +2 -0
  44. package/dist/mjs/chart/topArtists.js +6 -0
  45. package/dist/mjs/chart/topTags.d.ts +2 -0
  46. package/dist/mjs/chart/topTags.js +6 -0
  47. package/dist/mjs/chart/topTracks.d.ts +2 -0
  48. package/dist/mjs/chart/topTracks.js +6 -0
  49. package/dist/mjs/config.d.ts +20 -0
  50. package/dist/mjs/config.js +22 -0
  51. package/dist/mjs/createOptions.d.ts +7 -0
  52. package/dist/mjs/createOptions.js +9 -0
  53. package/dist/mjs/getInfo.d.ts +8 -0
  54. package/dist/mjs/getInfo.js +12 -0
  55. package/dist/mjs/getLovedTracks.d.ts +8 -0
  56. package/dist/mjs/getLovedTracks.js +12 -0
  57. package/dist/mjs/getRecentTracks.d.ts +8 -0
  58. package/dist/mjs/getRecentTracks.js +12 -0
  59. package/dist/mjs/getTopAlbums.d.ts +8 -0
  60. package/dist/mjs/getTopAlbums.js +12 -0
  61. package/dist/mjs/getTopArtists.d.ts +8 -0
  62. package/dist/mjs/getTopArtists.js +12 -0
  63. package/dist/mjs/getTopTracks.d.ts +8 -0
  64. package/dist/mjs/getTopTracks.js +12 -0
  65. package/dist/mjs/getWeeklyAlbumChart.d.ts +8 -0
  66. package/dist/mjs/getWeeklyAlbumChart.js +12 -0
  67. package/dist/mjs/getWeeklyArtistChart.d.ts +8 -0
  68. package/dist/mjs/getWeeklyArtistChart.js +12 -0
  69. package/dist/mjs/getWeeklyChartList.d.ts +8 -0
  70. package/dist/mjs/getWeeklyChartList.js +12 -0
  71. package/dist/mjs/getWeeklyTrackChart.d.ts +8 -0
  72. package/dist/mjs/getWeeklyTrackChart.js +12 -0
  73. package/dist/mjs/index.d.ts +63 -0
  74. package/{src/index.ts → dist/mjs/index.js} +25 -18
  75. package/dist/mjs/method.d.ts +43 -0
  76. package/dist/mjs/method.js +20 -0
  77. package/dist/mjs/package.json +3 -0
  78. package/dist/mjs/request.d.ts +8 -0
  79. package/dist/mjs/request.js +119 -0
  80. package/lastfm-nodejs-client/package.json +7 -0
  81. package/package.json +41 -13
  82. package/.env.example +0 -6
  83. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  84. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  85. package/.github/dependabot.yml +0 -11
  86. package/.github/workflows/codeql.yml +0 -74
  87. package/.github/workflows/playwright.yml +0 -36
  88. package/.nvmrc +0 -1
  89. package/.prettierrc.yaml +0 -6
  90. package/@types/index.d.ts +0 -289
  91. package/CHANGELOG.md +0 -108
  92. package/CODE_OF_CONDUCT.md +0 -128
  93. package/CONTRIBUTING.md +0 -9
  94. package/SECURITY.md +0 -13
  95. package/dist/auth.d.ts +0 -13
  96. package/dist/auth.d.ts.map +0 -1
  97. package/dist/config.d.ts.map +0 -1
  98. package/dist/createOptions.d.ts +0 -7
  99. package/dist/createOptions.d.ts.map +0 -1
  100. package/dist/getInfo.d.ts.map +0 -1
  101. package/dist/getLovedTracks.d.ts.map +0 -1
  102. package/dist/getRecentTracks.d.ts.map +0 -1
  103. package/dist/getTopAlbums.d.ts.map +0 -1
  104. package/dist/getTopArtists.d.ts.map +0 -1
  105. package/dist/getTopTracks.d.ts.map +0 -1
  106. package/dist/getWeeklyAlbumChart.d.ts.map +0 -1
  107. package/dist/getWeeklyArtistChart.d.ts.map +0 -1
  108. package/dist/getWeeklyChartList.d.ts.map +0 -1
  109. package/dist/getWeeklyTrackChart.d.ts.map +0 -1
  110. package/dist/index.d.ts.map +0 -1
  111. package/dist/index.js +0 -31
  112. package/dist/method.d.ts.map +0 -1
  113. package/dist/request.d.ts.map +0 -1
  114. package/playwright.config.ts +0 -37
  115. package/src/auth.ts +0 -23
  116. package/src/config.ts +0 -34
  117. package/src/createOptions.ts +0 -12
  118. package/src/getInfo.ts +0 -17
  119. package/src/getLovedTracks.ts +0 -19
  120. package/src/getRecentTracks.ts +0 -19
  121. package/src/getTopAlbums.ts +0 -19
  122. package/src/getTopArtists.ts +0 -19
  123. package/src/getTopTracks.ts +0 -19
  124. package/src/getWeeklyAlbumChart.ts +0 -19
  125. package/src/getWeeklyArtistChart.ts +0 -19
  126. package/src/getWeeklyChartList.ts +0 -19
  127. package/src/getWeeklyTrackChart.ts +0 -20
  128. package/src/method.ts +0 -33
  129. package/src/request.ts +0 -133
  130. package/tests/env.spec.ts +0 -21
  131. package/tsconfig.dev.json +0 -7
  132. package/tsconfig.json +0 -104
@@ -0,0 +1,6 @@
1
+ import { createOptions } from '../createOptions';
2
+ import request from '../request';
3
+ export async function chartTopTags(method, page) {
4
+ const options = createOptions(method, page);
5
+ return await request(options);
6
+ }
@@ -0,0 +1,2 @@
1
+ import { TopTrackResponse } from '../../@types';
2
+ export declare function chartTopTracks(method: string, page: string): Promise<TopTrackResponse>;
@@ -0,0 +1,6 @@
1
+ import { createOptions } from '../createOptions';
2
+ import request from '../request';
3
+ export async function chartTopTracks(method, page) {
4
+ const options = createOptions(method, page);
5
+ return await request(options);
6
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @description Stores the Last.fm API key, app name, base url, format, shared secret, and username.
3
+ * Simply add a .env file to the root of the project and add the following:
4
+ * LASTFM_API_KEY=your_api_key
5
+ * LASTFM_APPNAME=your_app_name
6
+ * LASTFM_API_BASE_URL=your_base_url
7
+ * LASTFM_SHARED_SECRET=your_shared_secret
8
+ * LASTFM_USER=your_username
9
+ */
10
+ export declare const config: {
11
+ api_key: string;
12
+ app_name: string;
13
+ base_url: string;
14
+ format: {
15
+ json: string;
16
+ xml: string;
17
+ };
18
+ share_secret: string;
19
+ username: string;
20
+ };
@@ -0,0 +1,22 @@
1
+ import * as dotenv from 'dotenv';
2
+ dotenv.config();
3
+ /**
4
+ * @description Stores the Last.fm API key, app name, base url, format, shared secret, and username.
5
+ * Simply add a .env file to the root of the project and add the following:
6
+ * LASTFM_API_KEY=your_api_key
7
+ * LASTFM_APPNAME=your_app_name
8
+ * LASTFM_API_BASE_URL=your_base_url
9
+ * LASTFM_SHARED_SECRET=your_shared_secret
10
+ * LASTFM_USER=your_username
11
+ */
12
+ export const config = {
13
+ api_key: `${process.env.LASTFM_API_KEY}`,
14
+ app_name: `${process.env.LASTFM_APPNAME}`,
15
+ base_url: `${process.env.LASTFM_API_BASE_URL}`,
16
+ format: {
17
+ json: 'json',
18
+ xml: 'xml',
19
+ },
20
+ share_secret: `${process.env.LASTFM_SHARED_SECRET}`,
21
+ username: `${process.env.LASTFM_USER}`,
22
+ };
@@ -0,0 +1,7 @@
1
+ export declare function createOptions(method: string, user: string, period?: string, limit?: string, page?: string): {
2
+ method: string;
3
+ page: string;
4
+ user: string;
5
+ period: string;
6
+ limit: string;
7
+ };
@@ -0,0 +1,9 @@
1
+ export function createOptions(method, user, period, limit, page) {
2
+ return {
3
+ method,
4
+ page,
5
+ user,
6
+ period,
7
+ limit,
8
+ };
9
+ }
@@ -0,0 +1,8 @@
1
+ import { type UserResponse } from "../@types";
2
+ /**
3
+ * GET: User profile information - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getInfo
6
+ * @returns User profile information
7
+ */
8
+ export declare function getInfo(method: string, user: string): Promise<UserResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from "./createOptions";
2
+ import request from "./request";
3
+ /**
4
+ * GET: User profile information - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getInfo
7
+ * @returns User profile information
8
+ */
9
+ export async function getInfo(method, user) {
10
+ const options = createOptions(method, user);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type LovedTracksResponse } from '../@types';
2
+ /**
3
+ * GET: Love Tracks - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getLovedTracks
6
+ * @returns Loved Tracks;
7
+ */
8
+ export declare function getLovedTracks(method: string, user: string, period: string, limit: string): Promise<LovedTracksResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Love Tracks - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getLovedTracks
7
+ * @returns Loved Tracks;
8
+ */
9
+ export async function getLovedTracks(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type RecentTracksResponse } from '../@types';
2
+ /**
3
+ * GET: Recent Tracks - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getRecentTracks
6
+ * @returns Recent Tracks
7
+ */
8
+ export declare function getRecentTracks(method: string, user: string, period: string, limit: string): Promise<RecentTracksResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Recent Tracks - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getRecentTracks
7
+ * @returns Recent Tracks
8
+ */
9
+ export async function getRecentTracks(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type TopAlbumsResponse } from '../@types';
2
+ /**
3
+ * GET: Top Albums - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getTopAlbums
6
+ * @returns Top Albums
7
+ */
8
+ export declare function getTopAlbums(method: string, user: string, period: string, limit: string): Promise<TopAlbumsResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Top Albums - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getTopAlbums
7
+ * @returns Top Albums
8
+ */
9
+ export async function getTopAlbums(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type TopArtistsResponse } from '../@types';
2
+ /**
3
+ * GET: Top Artist - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getTopArtists
6
+ * @returns Top Artists
7
+ */
8
+ export declare function getTopArtists(method: string, user: string, period: string, limit: string): Promise<TopArtistsResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Top Artist - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getTopArtists
7
+ * @returns Top Artists
8
+ */
9
+ export async function getTopArtists(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type TopTrackResponse } from '../@types';
2
+ /**
3
+ * GET: Top Tracks - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getTopTracks
6
+ * @returns Top Tracks
7
+ */
8
+ export declare function getTopTracks(method: string, user: string, period: string, limit: string): Promise<TopTrackResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Top Tracks - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getTopTracks
7
+ * @returns Top Tracks
8
+ */
9
+ export async function getTopTracks(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type WeeklyAlbumChartResponse } from '../@types';
2
+ /**
3
+ * GET: Weekly album chart - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getWeeklyAlbumChart
6
+ * @returns Weekly album chart
7
+ */
8
+ export declare function getWeeklyAlbumChart(method: string, user: string, period: string, limit: string): Promise<WeeklyAlbumChartResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Weekly album chart - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getWeeklyAlbumChart
7
+ * @returns Weekly album chart
8
+ */
9
+ export async function getWeeklyAlbumChart(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type WeeklyArtistChartResponse } from '../@types';
2
+ /**
3
+ * GET: Weekly artist chart - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getWeeklyArtistChart
6
+ * @returns Weekly artist chart
7
+ */
8
+ export declare function getWeeklyArtistChart(method: string, user: string, period: string, limit: string): Promise<WeeklyArtistChartResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Weekly artist chart - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getWeeklyArtistChart
7
+ * @returns Weekly artist chart
8
+ */
9
+ export async function getWeeklyArtistChart(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type WeeklyChartListResponse } from '../@types';
2
+ /**
3
+ * GET: Weekly chart list - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getWeeklyChartList
6
+ * @returns Weekly chart list
7
+ */
8
+ export declare function getWeeklyChartList(method: string, user: string, period: string, limit: string): Promise<WeeklyChartListResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Weekly chart list - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getWeeklyChartList
7
+ * @returns Weekly chart list
8
+ */
9
+ export async function getWeeklyChartList(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,8 @@
1
+ import { type WeeklyTrackChartResponse } from '../@types';
2
+ /**
3
+ * GET: Weekly track chart - LastFM
4
+ *
5
+ * https://www.last.fm/api/show/user.getWeeklyTrackChart
6
+ * @returns Weekly track chart
7
+ */
8
+ export declare function getWeeklyTrackChart(method: string, user: string, period: string, limit: string): Promise<WeeklyTrackChartResponse>;
@@ -0,0 +1,12 @@
1
+ import { createOptions } from './createOptions';
2
+ import request from './request';
3
+ /**
4
+ * GET: Weekly track chart - LastFM
5
+ *
6
+ * https://www.last.fm/api/show/user.getWeeklyTrackChart
7
+ * @returns Weekly track chart
8
+ */
9
+ export async function getWeeklyTrackChart(method, user, period, limit) {
10
+ const options = createOptions(method, user, period, limit);
11
+ return await request(options);
12
+ }
@@ -0,0 +1,63 @@
1
+ import { auth } from './auth';
2
+ import { getInfo } from './getInfo';
3
+ import { getLovedTracks } from './getLovedTracks';
4
+ import { getRecentTracks } from './getRecentTracks';
5
+ import { getTopAlbums } from './getTopAlbums';
6
+ import { getTopArtists } from './getTopArtists';
7
+ import { getTopTracks } from './getTopTracks';
8
+ import { getWeeklyAlbumChart } from './getWeeklyAlbumChart';
9
+ import { getWeeklyArtistChart } from './getWeeklyArtistChart';
10
+ import { getWeeklyChartList } from './getWeeklyChartList';
11
+ import { getWeeklyTrackChart } from './getWeeklyTrackChart';
12
+ import { chartTopTags } from './chart/topTags';
13
+ import { chartTopTracks } from './chart/topTracks';
14
+ import { chartTopArtists } from './chart/topArtists';
15
+ export default function LastFmApi(): {
16
+ auth: typeof auth;
17
+ chart: {
18
+ chartTopArtists: typeof chartTopArtists;
19
+ chartTopTracks: typeof chartTopTracks;
20
+ chartTopTags: typeof chartTopTags;
21
+ };
22
+ config: {
23
+ api_key: string;
24
+ app_name: string;
25
+ base_url: string;
26
+ format: {
27
+ json: string;
28
+ xml: string;
29
+ };
30
+ share_secret: string;
31
+ username: string;
32
+ };
33
+ getInfo: typeof getInfo;
34
+ getLovedTracks: typeof getLovedTracks;
35
+ getRecentTracks: typeof getRecentTracks;
36
+ getTopAlbums: typeof getTopAlbums;
37
+ getTopArtists: typeof getTopArtists;
38
+ getTopTracks: typeof getTopTracks;
39
+ getWeeklyAlbumChart: typeof getWeeklyAlbumChart;
40
+ getWeeklyArtistChart: typeof getWeeklyArtistChart;
41
+ getWeeklyChartList: typeof getWeeklyChartList;
42
+ getWeeklyTrackChart: typeof getWeeklyTrackChart;
43
+ method: {
44
+ auth: string;
45
+ chart: {
46
+ getTopTracks: string;
47
+ getTopTags: string;
48
+ getTopArtists: string;
49
+ };
50
+ user: {
51
+ getInfo: string;
52
+ getLovedTracks: string;
53
+ getRecentTracks: string;
54
+ getTopAlbums: string;
55
+ getTopArtists: string;
56
+ getTopTracks: string;
57
+ getWeeklyAlbumChart: string;
58
+ getWeeklyArtistChart: string;
59
+ getWeeklyChartList: string;
60
+ getWeeklyTrackChart: string;
61
+ };
62
+ };
63
+ };
@@ -11,21 +11,28 @@ import { getWeeklyArtistChart } from './getWeeklyArtistChart';
11
11
  import { getWeeklyChartList } from './getWeeklyChartList';
12
12
  import { getWeeklyTrackChart } from './getWeeklyTrackChart';
13
13
  import { method } from './method';
14
-
15
- const LastFmApi = () => ({
16
- auth,
17
- config,
18
- getInfo,
19
- getLovedTracks,
20
- getRecentTracks,
21
- getTopAlbums,
22
- getTopArtists,
23
- getTopTracks,
24
- getWeeklyAlbumChart,
25
- getWeeklyArtistChart,
26
- getWeeklyChartList,
27
- getWeeklyTrackChart,
28
- method,
29
- })
30
-
31
- export default LastFmApi;
14
+ import { chartTopTags } from './chart/topTags';
15
+ import { chartTopTracks } from './chart/topTracks';
16
+ import { chartTopArtists } from './chart/topArtists';
17
+ export default function LastFmApi() {
18
+ return {
19
+ auth,
20
+ chart: {
21
+ chartTopArtists,
22
+ chartTopTracks,
23
+ chartTopTags,
24
+ },
25
+ config,
26
+ getInfo,
27
+ getLovedTracks,
28
+ getRecentTracks,
29
+ getTopAlbums,
30
+ getTopArtists,
31
+ getTopTracks,
32
+ getWeeklyAlbumChart,
33
+ getWeeklyArtistChart,
34
+ getWeeklyChartList,
35
+ getWeeklyTrackChart,
36
+ method,
37
+ };
38
+ }
@@ -0,0 +1,43 @@
1
+ interface ChartMethod {
2
+ getTopArtists: string;
3
+ getTopTags: string;
4
+ getTopTracks: string;
5
+ }
6
+ interface UserMethod {
7
+ getInfo: string;
8
+ getLovedTracks: string;
9
+ getRecentTracks: string;
10
+ getTopAlbums: string;
11
+ getTopArtists: string;
12
+ getTopTracks: string;
13
+ getWeeklyAlbumChart: string;
14
+ getWeeklyArtistChart: string;
15
+ getWeeklyChartList: string;
16
+ getWeeklyTrackChart: string;
17
+ }
18
+ export interface Method {
19
+ auth: string;
20
+ chart: ChartMethod;
21
+ user: UserMethod;
22
+ }
23
+ export declare const method: {
24
+ auth: string;
25
+ chart: {
26
+ getTopTracks: string;
27
+ getTopTags: string;
28
+ getTopArtists: string;
29
+ };
30
+ user: {
31
+ getInfo: string;
32
+ getLovedTracks: string;
33
+ getRecentTracks: string;
34
+ getTopAlbums: string;
35
+ getTopArtists: string;
36
+ getTopTracks: string;
37
+ getWeeklyAlbumChart: string;
38
+ getWeeklyArtistChart: string;
39
+ getWeeklyChartList: string;
40
+ getWeeklyTrackChart: string;
41
+ };
42
+ };
43
+ export {};
@@ -0,0 +1,20 @@
1
+ export const method = {
2
+ auth: 'auth.getToken',
3
+ chart: {
4
+ getTopTracks: 'chart.getTopTracks',
5
+ getTopTags: 'chart.getTopTags',
6
+ getTopArtists: 'chart.getTopArtists',
7
+ },
8
+ user: {
9
+ getInfo: 'user.getInfo',
10
+ getLovedTracks: 'user.getLovedTracks',
11
+ getRecentTracks: 'user.getRecentTracks',
12
+ getTopAlbums: 'user.getTopAlbums',
13
+ getTopArtists: 'user.getTopArtists',
14
+ getTopTracks: 'user.getTopTracks',
15
+ getWeeklyAlbumChart: 'user.getWeeklyAlbumChart',
16
+ getWeeklyArtistChart: 'user.getWeeklyArtistChart',
17
+ getWeeklyChartList: 'user.getWeeklyChartList',
18
+ getWeeklyTrackChart: 'user.getWeeklyTrackChart',
19
+ },
20
+ };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,8 @@
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>;
8
+ export default request;
@@ -0,0 +1,119 @@
1
+ import fetch from 'cross-fetch';
2
+ import { config } from './config';
3
+ var ErrorResponse;
4
+ (function (ErrorResponse) {
5
+ ErrorResponse[ErrorResponse["InvalidService"] = 2] = "InvalidService";
6
+ ErrorResponse[ErrorResponse["InvalidMethod"] = 3] = "InvalidMethod";
7
+ ErrorResponse[ErrorResponse["AuthenticationFailed"] = 4] = "AuthenticationFailed";
8
+ ErrorResponse[ErrorResponse["InvalidFormat"] = 5] = "InvalidFormat";
9
+ ErrorResponse[ErrorResponse["InvalidParameters"] = 6] = "InvalidParameters";
10
+ ErrorResponse[ErrorResponse["InvalidResource"] = 7] = "InvalidResource";
11
+ ErrorResponse[ErrorResponse["OperationFailed"] = 8] = "OperationFailed";
12
+ ErrorResponse[ErrorResponse["InvalidSessionKey"] = 9] = "InvalidSessionKey";
13
+ ErrorResponse[ErrorResponse["InvalidAPIKey"] = 10] = "InvalidAPIKey";
14
+ ErrorResponse[ErrorResponse["ServiceOffline"] = 11] = "ServiceOffline";
15
+ ErrorResponse[ErrorResponse["InvalidMethodSignature"] = 13] = "InvalidMethodSignature";
16
+ ErrorResponse[ErrorResponse["TemporaryError"] = 16] = "TemporaryError";
17
+ ErrorResponse[ErrorResponse["SuspendedAPIKey"] = 26] = "SuspendedAPIKey";
18
+ ErrorResponse[ErrorResponse["RateLimitExceeded"] = 29] = "RateLimitExceeded";
19
+ })(ErrorResponse || (ErrorResponse = {}));
20
+ const buildUrl = (options) => {
21
+ const params = new URLSearchParams();
22
+ params.append('method', options.method);
23
+ if (options.user)
24
+ params.append('user', options.user);
25
+ if (options.period)
26
+ params.append('period', options.period);
27
+ if (options.limit)
28
+ params.append('limit', options.limit);
29
+ params.append('api_key', config.api_key);
30
+ params.append('format', config.format.json);
31
+ return `${config.base_url}?${params.toString()}`;
32
+ };
33
+ const request = async (options) => {
34
+ const url = buildUrl(options);
35
+ return (await fetch(url, {
36
+ headers: {
37
+ 'Content-Type': 'application/json',
38
+ },
39
+ })
40
+ .then(async (res) => {
41
+ if (!res.ok) {
42
+ throw new Error(res.statusText);
43
+ }
44
+ switch (res.status) {
45
+ case 200: {
46
+ return await res.json();
47
+ }
48
+ case 400: {
49
+ throw new Error('Bad request');
50
+ }
51
+ case 401: {
52
+ throw new Error('Unauthorized');
53
+ }
54
+ case 403: {
55
+ throw new Error('Forbidden');
56
+ }
57
+ case 404: {
58
+ throw new Error('Not found');
59
+ }
60
+ case 500: {
61
+ throw new Error('Internal server error');
62
+ }
63
+ case 503: {
64
+ throw new Error('Service unavailable');
65
+ }
66
+ case ErrorResponse.InvalidAPIKey: {
67
+ throw new Error('Invalid API key');
68
+ }
69
+ case ErrorResponse.InvalidMethod: {
70
+ throw new Error('Invalid method');
71
+ }
72
+ case ErrorResponse.InvalidParameters: {
73
+ throw new Error('Invalid parameters');
74
+ }
75
+ case ErrorResponse.InvalidResource: {
76
+ throw new Error('Invalid resource');
77
+ }
78
+ case ErrorResponse.InvalidSessionKey: {
79
+ throw new Error('Invalid session key');
80
+ }
81
+ case ErrorResponse.InvalidService: {
82
+ throw new Error('Invalid service');
83
+ }
84
+ case ErrorResponse.OperationFailed: {
85
+ throw new Error('Operation failed');
86
+ }
87
+ case ErrorResponse.RateLimitExceeded: {
88
+ throw new Error('Rate limit exceeded');
89
+ }
90
+ case ErrorResponse.ServiceOffline: {
91
+ throw new Error('Service offline');
92
+ }
93
+ case ErrorResponse.SuspendedAPIKey: {
94
+ throw new Error('Suspended API key');
95
+ }
96
+ case ErrorResponse.TemporaryError: {
97
+ throw new Error('Temporary error');
98
+ }
99
+ case ErrorResponse.AuthenticationFailed: {
100
+ throw new Error('Authentication failed');
101
+ }
102
+ case ErrorResponse.InvalidFormat: {
103
+ throw new Error('Invalid format');
104
+ }
105
+ case ErrorResponse.InvalidMethodSignature: {
106
+ throw new Error('Invalid method signature');
107
+ }
108
+ default: {
109
+ throw new Error('Unknown error');
110
+ }
111
+ }
112
+ })
113
+ .then((json) => json)
114
+ .catch((error) => {
115
+ // eslint-disable-next-line no-console
116
+ console.error('🚨 error:', error);
117
+ }));
118
+ };
119
+ export default request;
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "lastfm-nodejs-client",
3
+ "description": "A client for interacting with the lastFm API",
4
+ "main": "../dist/cjs/index.js",
5
+ "module": "../dist/mjs/indext.js",
6
+ "types": "../dist/mjs/index.d.ts"
7
+ }