lastfm-nodejs-client 1.4.2 → 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 (133) 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 -392
  91. package/CHANGELOG.md +0 -104
  92. package/CODE_OF_CONDUCT.md +0 -128
  93. package/CONTRIBUTING.md +0 -9
  94. package/SECURITY.md +0 -13
  95. package/dist/@types/index.d.ts +0 -392
  96. package/dist/auth.d.ts +0 -13
  97. package/dist/auth.d.ts.map +0 -1
  98. package/dist/config.d.ts.map +0 -1
  99. package/dist/createOptions.d.ts +0 -7
  100. package/dist/createOptions.d.ts.map +0 -1
  101. package/dist/getInfo.d.ts.map +0 -1
  102. package/dist/getLovedTracks.d.ts.map +0 -1
  103. package/dist/getRecentTracks.d.ts.map +0 -1
  104. package/dist/getTopAlbums.d.ts.map +0 -1
  105. package/dist/getTopArtists.d.ts.map +0 -1
  106. package/dist/getTopTracks.d.ts.map +0 -1
  107. package/dist/getWeeklyAlbumChart.d.ts.map +0 -1
  108. package/dist/getWeeklyArtistChart.d.ts.map +0 -1
  109. package/dist/getWeeklyChartList.d.ts.map +0 -1
  110. package/dist/getWeeklyTrackChart.d.ts.map +0 -1
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/index.js +0 -31
  113. package/dist/method.d.ts.map +0 -1
  114. package/dist/request.d.ts.map +0 -1
  115. package/playwright.config.ts +0 -37
  116. package/src/auth.ts +0 -23
  117. package/src/config.ts +0 -34
  118. package/src/createOptions.ts +0 -12
  119. package/src/getInfo.ts +0 -17
  120. package/src/getLovedTracks.ts +0 -19
  121. package/src/getRecentTracks.ts +0 -19
  122. package/src/getTopAlbums.ts +0 -19
  123. package/src/getTopArtists.ts +0 -19
  124. package/src/getTopTracks.ts +0 -19
  125. package/src/getWeeklyAlbumChart.ts +0 -19
  126. package/src/getWeeklyArtistChart.ts +0 -19
  127. package/src/getWeeklyChartList.ts +0 -19
  128. package/src/getWeeklyTrackChart.ts +0 -20
  129. package/src/method.ts +0 -33
  130. package/src/request.ts +0 -133
  131. package/tests/env.spec.ts +0 -21
  132. package/tsconfig.dev.json +0 -7
  133. package/tsconfig.json +0 -104
@@ -1 +0,0 @@
1
- {"version":3,"file":"getWeeklyArtistChart.d.ts","sourceRoot":"","sources":["../src/getWeeklyArtistChart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAItD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,yBAAyB,CAAC,CAGpC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getWeeklyChartList.d.ts","sourceRoot":"","sources":["../src/getWeeklyChartList.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAIpD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,uBAAuB,CAAC,CAGlC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"getWeeklyTrackChart.d.ts","sourceRoot":"","sources":["../src/getWeeklyTrackChart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAKrD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,wBAAwB,CAAC,CAGnC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAcb,CAAA;AAEF,eAAe,SAAS,CAAC"}
package/dist/index.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const auth_1 = require("./auth");
4
- const config_1 = require("./config");
5
- const getInfo_1 = require("./getInfo");
6
- const getLovedTracks_1 = require("./getLovedTracks");
7
- const getRecentTracks_1 = require("./getRecentTracks");
8
- const getTopAlbums_1 = require("./getTopAlbums");
9
- const getTopArtists_1 = require("./getTopArtists");
10
- const getTopTracks_1 = require("./getTopTracks");
11
- const getWeeklyAlbumChart_1 = require("./getWeeklyAlbumChart");
12
- const getWeeklyArtistChart_1 = require("./getWeeklyArtistChart");
13
- const getWeeklyChartList_1 = require("./getWeeklyChartList");
14
- const getWeeklyTrackChart_1 = require("./getWeeklyTrackChart");
15
- const method_1 = require("./method");
16
- const LastFmApi = () => ({
17
- auth: auth_1.auth,
18
- config: config_1.config,
19
- getInfo: getInfo_1.getInfo,
20
- getLovedTracks: getLovedTracks_1.getLovedTracks,
21
- getRecentTracks: getRecentTracks_1.getRecentTracks,
22
- getTopAlbums: getTopAlbums_1.getTopAlbums,
23
- getTopArtists: getTopArtists_1.getTopArtists,
24
- getTopTracks: getTopTracks_1.getTopTracks,
25
- getWeeklyAlbumChart: getWeeklyAlbumChart_1.getWeeklyAlbumChart,
26
- getWeeklyArtistChart: getWeeklyArtistChart_1.getWeeklyArtistChart,
27
- getWeeklyChartList: getWeeklyChartList_1.getWeeklyChartList,
28
- getWeeklyTrackChart: getWeeklyTrackChart_1.getWeeklyTrackChart,
29
- method: method_1.method,
30
- });
31
- exports.default = LastFmApi;
@@ -1 +0,0 @@
1
- {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../src/method.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;CAcD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAGA,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAkCD,QAAA,MAAM,OAAO,wBAA6B,cAAc,wBAwFvD,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -1,37 +0,0 @@
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/auth.ts DELETED
@@ -1,23 +0,0 @@
1
- import { AuthResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * POST: Auth - LastFM
7
- *
8
- * https://www.last.fm/api/show/auth.getToken
9
- *
10
- * Authentication tokens are API account specific.
11
- * They are valid for 60 minutes from the moment they are granted.
12
- * Can only used once (they are consumed when a session is created).
13
- * @returns Auth token
14
- */
15
- export function auth(
16
- method: string,
17
- user: string,
18
- period: string,
19
- limit: string,
20
- ): Promise<AuthResponse> {
21
- const options = createOptions(method, user, period, limit);
22
- return request<AuthResponse>(options);
23
- }
package/src/config.ts DELETED
@@ -1,34 +0,0 @@
1
- import * as dotenv from 'dotenv';
2
- dotenv.config();
3
-
4
- interface 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
- /**
16
- * @description Stores the Last.fm API key, app name, base url, format, shared secret, and username.
17
- * Simply add a .env file to the root of the project and add the following:
18
- * LASTFM_API_KEY=your_api_key
19
- * LASTFM_APPNAME=your_app_name
20
- * LASTFM_API_BASE_URL=your_base_url
21
- * LASTFM_SHARED_SECRET=your_shared_secret
22
- * LASTFM_USER=your_username
23
- */
24
- export const config = {
25
- api_key: `${process.env.LASTFM_API_KEY}`,
26
- app_name: `${process.env.LASTFM_APPNAME}`,
27
- base_url: `${process.env.LASTFM_API_BASE_URL}`,
28
- format: {
29
- json: 'json',
30
- xml: 'xml',
31
- },
32
- share_secret: `${process.env.LASTFM_SHARED_SECRET}`,
33
- username: `${process.env.LASTFM_USER}`,
34
- } satisfies Config;
@@ -1,12 +0,0 @@
1
- export function createOptions(
2
- method: string,
3
- user: string,
4
- period?: string,
5
- limit?: string) {
6
- return {
7
- method,
8
- user,
9
- period,
10
- limit,
11
- }
12
- }
package/src/getInfo.ts DELETED
@@ -1,17 +0,0 @@
1
- import { UserResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: User profile information - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getInfo
9
- * @returns User profile information
10
- */
11
- export function getInfo(
12
- method: string,
13
- user: string,
14
- ): Promise<UserResponse> {
15
- const options = createOptions(method, user);
16
- return request<UserResponse>(options);
17
- }
@@ -1,19 +0,0 @@
1
- import { LovedTracksResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Love Tracks - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getLovedTracks
9
- * @returns Loved Tracks;
10
- */
11
- export function getLovedTracks(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<LovedTracksResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<LovedTracksResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { RecentTracksResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Recent Tracks - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getRecentTracks
9
- * @returns Recent Tracks
10
- */
11
- export function getRecentTracks(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<RecentTracksResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<RecentTracksResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { TopAlbumsResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Top Albums - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getTopAlbums
9
- * @returns Top Albums
10
- */
11
- export function getTopAlbums(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<TopAlbumsResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<TopAlbumsResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { TopArtistsResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Top Artist - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getTopArtists
9
- * @returns Top Artists
10
- */
11
- export function getTopArtists(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<TopArtistsResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<TopArtistsResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { TopTrackResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Top Tracks - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getTopTracks
9
- * @returns Top Tracks
10
- */
11
- export function getTopTracks(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<TopTrackResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<TopTrackResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { WeeklyAlbumChartResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Weekly album chart - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getWeeklyAlbumChart
9
- * @returns Weekly album chart
10
- */
11
- export function getWeeklyAlbumChart(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<WeeklyAlbumChartResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<WeeklyAlbumChartResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { WeeklyArtistChartResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Weekly artist chart - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getWeeklyArtistChart
9
- * @returns Weekly artist chart
10
- */
11
- export function getWeeklyArtistChart(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<WeeklyArtistChartResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<WeeklyArtistChartResponse>(options);
19
- }
@@ -1,19 +0,0 @@
1
- import { WeeklyChartListResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
- /**
6
- * GET: Weekly chart list - LastFM
7
- *
8
- * https://www.last.fm/api/show/user.getWeeklyChartList
9
- * @returns Weekly chart list
10
- */
11
- export function getWeeklyChartList(
12
- method: string,
13
- user: string,
14
- period: string,
15
- limit: string,
16
- ): Promise<WeeklyChartListResponse> {
17
- const options = createOptions(method, user, period, limit);
18
- return request<WeeklyChartListResponse>(options);
19
- }
@@ -1,20 +0,0 @@
1
- import { WeeklyTrackChartResponse } from '../@types';
2
- import { createOptions } from './createOptions';
3
- import request from './request';
4
-
5
-
6
- /**
7
- * GET: Weekly track chart - LastFM
8
- *
9
- * https://www.last.fm/api/show/user.getWeeklyTrackChart
10
- * @returns Weekly track chart
11
- */
12
- export function getWeeklyTrackChart(
13
- method: string,
14
- user: string,
15
- period: string,
16
- limit: string,
17
- ): Promise<WeeklyTrackChartResponse> {
18
- const options = createOptions(method, user, period, limit);
19
- return request<WeeklyTrackChartResponse>(options);
20
- }
package/src/method.ts DELETED
@@ -1,33 +0,0 @@
1
- interface UserMethod {
2
- getInfo: string;
3
- getLovedTracks: string;
4
- getRecentTracks: string;
5
- getTopAlbums: string;
6
- getTopArtists: string;
7
- getTopTracks: string;
8
- getWeeklyAlbumChart: string;
9
- getWeeklyArtistChart: string;
10
- getWeeklyChartList: string;
11
- getWeeklyTrackChart: string;
12
- };
13
-
14
- export interface Method {
15
- auth: string;
16
- user: UserMethod;
17
- };
18
-
19
- export const method = {
20
- auth: 'auth.getToken',
21
- user: {
22
- getInfo: 'user.getInfo',
23
- getLovedTracks: 'user.getLovedTracks',
24
- getRecentTracks: 'user.getRecentTracks',
25
- getTopAlbums: 'user.getTopAlbums',
26
- getTopArtists: 'user.getTopArtists',
27
- getTopTracks: 'user.getTopTracks',
28
- getWeeklyAlbumChart: 'user.getWeeklyAlbumChart',
29
- getWeeklyArtistChart: 'user.getWeeklyArtistChart',
30
- getWeeklyChartList: 'user.getWeeklyChartList',
31
- getWeeklyTrackChart: 'user.getWeeklyTrackChart',
32
- },
33
- } satisfies Method;
package/src/request.ts DELETED
@@ -1,133 +0,0 @@
1
- import fetch from 'cross-fetch';
2
- import { config } from './config';
3
-
4
- interface RequestOptions {
5
- method: string;
6
- user?: string;
7
- period?: string;
8
- limit?: string;
9
- }
10
-
11
- enum ErrorResponse {
12
- InvalidService = 2,
13
- InvalidMethod = 3,
14
- AuthenticationFailed = 4,
15
- InvalidFormat = 5,
16
- InvalidParameters = 6,
17
- InvalidResource = 7,
18
- OperationFailed = 8,
19
- InvalidSessionKey = 9,
20
- InvalidAPIKey = 10,
21
- ServiceOffline = 11,
22
- InvalidMethodSignature = 13,
23
- TemporaryError = 16,
24
- SuspendedAPIKey = 26,
25
- RateLimitExceeded = 29
26
- }
27
-
28
- const buildUrl = (options: RequestOptions): string => {
29
- const params = new URLSearchParams();
30
-
31
- params.append('method', options.method);
32
-
33
- if (options.user) params.append('user', options.user);
34
- if (options.period) params.append('period', options.period);
35
- if (options.limit) params.append('limit', options.limit);
36
-
37
- params.append('api_key', config.api_key);
38
- params.append('format', config.format.json);
39
-
40
- return `${config.base_url}?${params.toString()}`;
41
- }
42
-
43
- const request = async <Response>(options: RequestOptions): Promise<Response> => {
44
- const url = buildUrl(options);
45
-
46
- return (await fetch(url, {
47
- headers: {
48
- 'Content-Type': 'application/json',
49
- },
50
- })
51
- .then((res) => {
52
- if(!res.ok) {
53
- throw new Error(res.statusText);
54
- }
55
-
56
- switch (res.status) {
57
- case 200: {
58
- return res.json();
59
- }
60
- case 400: {
61
- throw new Error('Bad request');
62
- }
63
- case 401: {
64
- throw new Error('Unauthorized');
65
- }
66
- case 403: {
67
- throw new Error('Forbidden');
68
- }
69
- case 404: {
70
- throw new Error('Not found');
71
- }
72
- case 500: {
73
- throw new Error('Internal server error');
74
- }
75
- case 503: {
76
- throw new Error('Service unavailable');
77
- }
78
- case ErrorResponse.InvalidAPIKey: {
79
- throw new Error('Invalid API key');
80
- }
81
- case ErrorResponse.InvalidMethod: {
82
- throw new Error('Invalid method');
83
- }
84
- case ErrorResponse.InvalidParameters: {
85
- throw new Error('Invalid parameters');
86
- }
87
- case ErrorResponse.InvalidResource: {
88
- throw new Error('Invalid resource');
89
- }
90
- case ErrorResponse.InvalidSessionKey: {
91
- throw new Error('Invalid session key');
92
- }
93
- case ErrorResponse.InvalidService: {
94
- throw new Error('Invalid service');
95
- }
96
- case ErrorResponse.OperationFailed: {
97
- throw new Error('Operation failed');
98
- }
99
- case ErrorResponse.RateLimitExceeded: {
100
- throw new Error('Rate limit exceeded');
101
- }
102
- case ErrorResponse.ServiceOffline: {
103
- throw new Error('Service offline');
104
- }
105
- case ErrorResponse.SuspendedAPIKey: {
106
- throw new Error('Suspended API key');
107
- }
108
- case ErrorResponse.TemporaryError: {
109
- throw new Error('Temporary error');
110
- }
111
- case ErrorResponse.AuthenticationFailed: {
112
- throw new Error('Authentication failed');
113
- }
114
- case ErrorResponse.InvalidFormat: {
115
- throw new Error('Invalid format');
116
- }
117
- case ErrorResponse.InvalidMethodSignature: {
118
- throw new Error('Invalid method signature');
119
- }
120
-
121
- default: {
122
- throw new Error('Unknown error');
123
- }
124
- }
125
-
126
- })
127
- .then((json) => json)
128
- .catch((error) => {
129
- console.log('🚨 error:', error);
130
- })) as Response;
131
- };
132
-
133
- export default request;
package/tests/env.spec.ts DELETED
@@ -1,21 +0,0 @@
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
- });
package/tsconfig.dev.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "declaration": false
5
- },
6
- "exclude": ["tests/**/*.spec.ts", "tests/**/*.test.ts", "./playwright.config.ts"]
7
- }