@irfanshadikrishad/anilist 1.0.0 → 1.0.1-forbidden.2
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/README.md +165 -26
- package/bin/helpers/auth.d.ts +67 -9
- package/bin/helpers/auth.js +943 -141
- package/bin/helpers/fetcher.d.ts +13 -0
- package/bin/helpers/fetcher.js +59 -0
- package/bin/helpers/lists.d.ts +25 -7
- package/bin/helpers/lists.js +1023 -293
- package/bin/helpers/mutations.d.ts +8 -0
- package/bin/helpers/mutations.js +43 -0
- package/bin/helpers/queries.d.ts +28 -9
- package/bin/helpers/queries.js +150 -154
- package/bin/helpers/types.d.ts +452 -0
- package/bin/helpers/types.js +26 -0
- package/bin/helpers/workers.d.ts +35 -1
- package/bin/helpers/workers.js +360 -6
- package/bin/index.js +169 -24
- package/package.json +51 -9
- package/bin/helpers/more.d.ts +0 -2
- package/bin/helpers/more.js +0 -60
- /package/{LICENSE → LICENSE.md} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
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. If a rate-limit error (429) is returned,
|
|
6
|
+
* it waits for 1 minute and retries the request.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} query - The AniList GraphQL query to be executed.
|
|
9
|
+
* @param {object} variables - An object containing the variables for the query.
|
|
10
|
+
* @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
|
|
11
|
+
*/
|
|
12
|
+
declare function fetcher(query: string, variables: object): Promise<object | null>;
|
|
13
|
+
export { fetcher };
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
import { aniListEndpoint } from "./workers.js";
|
|
13
|
+
/**
|
|
14
|
+
* Sends a GraphQL request to the AniList API.
|
|
15
|
+
*
|
|
16
|
+
* This function constructs a request with the provided query and variables,
|
|
17
|
+
* handles authorization, and processes the API response. If a rate-limit error (429) is returned,
|
|
18
|
+
* it waits for 1 minute and retries the request.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} query - The AniList GraphQL query to be executed.
|
|
21
|
+
* @param {object} variables - An object containing the variables for the query.
|
|
22
|
+
* @returns {Promise<object|null>} The response from the API as a JSON object if successful; otherwise, null.
|
|
23
|
+
*/
|
|
24
|
+
function fetcher(query, variables) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
try {
|
|
28
|
+
const headers = {
|
|
29
|
+
"content-type": "application/json",
|
|
30
|
+
};
|
|
31
|
+
if (yield Auth.isLoggedIn()) {
|
|
32
|
+
headers["Authorization"] = `Bearer ${yield Auth.RetriveAccessToken()}`;
|
|
33
|
+
}
|
|
34
|
+
const request = yield fetch(aniListEndpoint, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: headers,
|
|
37
|
+
body: JSON.stringify({ query, variables }),
|
|
38
|
+
});
|
|
39
|
+
const response = yield request.json();
|
|
40
|
+
if (request.status === 200) {
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
else if (request.status === 429) {
|
|
44
|
+
console.warn("Rate limit reached. Retrying in 1 minute...");
|
|
45
|
+
yield new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
|
|
46
|
+
return yield fetcher(query, variables); // Retry the request
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.error(`\n${request.status} ${((_b = (_a = response === null || response === void 0 ? void 0 : response.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) || "Unknown error"}.`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(`\nSomething went wrong. ${error.message}.`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export { fetcher };
|
package/bin/helpers/lists.d.ts
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
declare class AniDB {
|
|
23
|
+
static importAnime(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export { AniDB, AniList, MyAnimeList };
|