@irfanshadikrishad/anilist 1.0.8 → 1.1.0-forbidden.0

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.
@@ -8,5 +8,5 @@
8
8
  * @param {object} variables - An object containing the variables for the query.
9
9
  * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
10
10
  */
11
- declare function fetcher(query: string, variables: object): Promise<object | null>;
11
+ declare function fetcher(query: string, variables?: object): Promise<any | null>;
12
12
  export { fetcher };
@@ -8,8 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import fetch from "node-fetch";
11
- import { isLoggedIn, retriveAccessToken } from "./auth.js";
12
- import { aniListEndpoint } from "./workers.js";
11
+ import { Auth } from "./auth.js";
13
12
  /**
14
13
  * Sends a GraphQL request to the AniList API.
15
14
  *
@@ -22,32 +21,34 @@ import { aniListEndpoint } from "./workers.js";
22
21
  */
23
22
  function fetcher(query, variables) {
24
23
  return __awaiter(this, void 0, void 0, function* () {
25
- var _a;
26
- try {
27
- const headers = {
28
- "content-type": "application/json",
29
- };
30
- if (yield isLoggedIn()) {
31
- headers["Authorization"] = `Bearer ${yield retriveAccessToken()}`;
32
- }
33
- const request = yield fetch(aniListEndpoint, {
34
- method: "POST",
35
- headers: headers,
36
- body: JSON.stringify({ query, variables }),
37
- });
38
- const response = yield request.json();
39
- if (request.status === 200) {
40
- return response;
24
+ const headers = {
25
+ "content-type": "application/json",
26
+ };
27
+ if (yield Auth.isLoggedIn()) {
28
+ headers["Authorization"] = `Bearer ${yield Auth.RetriveAccessToken()}`;
29
+ }
30
+ const response = yield fetch("https://graphql.anilist.co", {
31
+ method: "POST",
32
+ headers: headers,
33
+ body: JSON.stringify({
34
+ query,
35
+ variables,
36
+ }),
37
+ });
38
+ // Check if the response is successful
39
+ if (response.status !== 200) {
40
+ // If the status is 429, handle the rate limit
41
+ if (response.status === 429) {
42
+ console.warn("Rate limit hit. Waiting for 1 minute before retrying...");
43
+ yield new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
44
+ return fetcher(query, variables); // Retry the request
41
45
  }
42
46
  else {
43
- console.error(`\n${request.status} ${(_a = response === null || response === void 0 ? void 0 : response.errors[0]) === null || _a === void 0 ? void 0 : _a.message}.`);
44
- return null;
47
+ throw new Error(`\nError fetching data: ${response.statusText}`);
45
48
  }
46
49
  }
47
- catch (error) {
48
- console.error(`\nSomething went wrong. ${error.message}.`);
49
- return null;
50
- }
50
+ const data = yield response.json();
51
+ return data;
51
52
  });
52
53
  }
53
54
  export { fetcher };
@@ -1,8 +1,22 @@
1
- declare function getTrending(count: number): Promise<void>;
2
- declare function getPopular(count: number): Promise<void>;
3
- declare function loggedInUsersAnimeLists(): Promise<void>;
4
- declare function loggedInUsersMangaLists(): Promise<void>;
5
- declare function deleteAnimeCollection(): Promise<void>;
6
- declare function deleteMangaCollection(): Promise<void>;
7
- declare function getUpcomingAnimes(count: number): Promise<void>;
8
- export { deleteAnimeCollection, deleteMangaCollection, getPopular, getTrending, getUpcomingAnimes, loggedInUsersAnimeLists, loggedInUsersMangaLists, };
1
+ declare class AniList {
2
+ static importAnime(): Promise<void>;
3
+ static importManga(): Promise<void>;
4
+ static exportAnime(): Promise<void>;
5
+ static exportManga(): Promise<void>;
6
+ static MyAnime(): Promise<void>;
7
+ static MyManga(): Promise<void>;
8
+ static getTrendingAnime(count: number): Promise<void>;
9
+ static getPopularAnime(count: number): Promise<void>;
10
+ static getUpcomingAnime(count: number): Promise<void>;
11
+ static getUserByUsername(username: string): Promise<void>;
12
+ static getAnimeDetailsByID(anilistID: number): Promise<void>;
13
+ static searchAnime(search: string, count: number): Promise<void>;
14
+ static searchManga(search: string, count: number): Promise<void>;
15
+ }
16
+ declare class MyAnimeList {
17
+ static importAnime(): Promise<void>;
18
+ static importManga(): Promise<void>;
19
+ static exportAnime(): Promise<void>;
20
+ static exportManga(): Promise<void>;
21
+ }
22
+ export { AniList, MyAnimeList };