@irfanshadikrishad/anilist 1.0.0-forbidden.0 → 1.0.0-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 +243 -232
- package/bin/helpers/auth.d.ts +39 -7
- package/bin/helpers/auth.js +281 -106
- package/bin/helpers/fetcher.d.ts +3 -2
- package/bin/helpers/fetcher.js +29 -24
- package/bin/helpers/lists.d.ts +4 -1
- package/bin/helpers/lists.js +357 -268
- package/bin/helpers/mutations.js +35 -35
- package/bin/helpers/queries.d.ts +10 -6
- package/bin/helpers/queries.js +171 -144
- package/bin/helpers/types.d.ts +304 -8
- package/bin/helpers/workers.d.ts +9 -5
- package/bin/helpers/workers.js +155 -69
- package/bin/index.js +13 -5
- package/package.json +81 -73
- /package/{LICENSE → LICENSE.md} +0 -0
package/bin/helpers/fetcher.js
CHANGED
|
@@ -9,11 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import fetch from "node-fetch";
|
|
11
11
|
import { Auth } from "./auth.js";
|
|
12
|
+
import { aniListEndpoint } from "./workers.js";
|
|
12
13
|
/**
|
|
13
14
|
* Sends a GraphQL request to the AniList API.
|
|
14
15
|
*
|
|
15
16
|
* This function constructs a request with the provided query and variables,
|
|
16
|
-
* handles authorization, and processes the API response.
|
|
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.
|
|
17
19
|
*
|
|
18
20
|
* @param {string} query - The AniList GraphQL query to be executed.
|
|
19
21
|
* @param {object} variables - An object containing the variables for the query.
|
|
@@ -21,34 +23,37 @@ import { Auth } from "./auth.js";
|
|
|
21
23
|
*/
|
|
22
24
|
function fetcher(query, variables) {
|
|
23
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
variables,
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
console.warn("Rate limit
|
|
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...");
|
|
43
45
|
yield new Promise((resolve) => setTimeout(resolve, 60000)); // Wait for 1 minute
|
|
44
|
-
return fetcher(query, variables); // Retry the request
|
|
46
|
+
return yield fetcher(query, variables); // Retry the request
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
|
-
|
|
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;
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(`\nSomething went wrong. ${error.message}.`);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
52
57
|
});
|
|
53
58
|
}
|
|
54
59
|
export { fetcher };
|
package/bin/helpers/lists.d.ts
CHANGED