@irfanshadikrishad/anilist 1.0.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Sends a GraphQL request to the AniList API.
3
+ *
4
+ * This function constructs a request with the provided query and variables,
5
+ * handles authorization, and processes the API response.
6
+ *
7
+ * @param {string} query - The AniList GraphQL query to be executed.
8
+ * @param {object} variables - An object containing the variables for the query.
9
+ * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
10
+ */
11
+ declare function fetcher(query: string, variables?: object): Promise<any | null>;
12
+ export { fetcher };
@@ -0,0 +1,54 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fetch from "node-fetch";
11
+ import { Auth } from "./auth.js";
12
+ /**
13
+ * Sends a GraphQL request to the AniList API.
14
+ *
15
+ * This function constructs a request with the provided query and variables,
16
+ * handles authorization, and processes the API response.
17
+ *
18
+ * @param {string} query - The AniList GraphQL query to be executed.
19
+ * @param {object} variables - An object containing the variables for the query.
20
+ * @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
21
+ */
22
+ function fetcher(query, variables) {
23
+ return __awaiter(this, void 0, void 0, function* () {
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
45
+ }
46
+ else {
47
+ throw new Error(`\nError fetching data: ${response.statusText}`);
48
+ }
49
+ }
50
+ const data = yield response.json();
51
+ return data;
52
+ });
53
+ }
54
+ export { fetcher };
@@ -0,0 +1,22 @@
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 };