@anywayseo/gatsby-plugin 2.6.0 → 2.6.1
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/gatsby-node.js
CHANGED
|
@@ -43,12 +43,12 @@ function createSchemaCustomization(args) {
|
|
|
43
43
|
function sourceNodes(args, options) {
|
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
45
|
const { reporter } = args;
|
|
46
|
-
const { strapiApiUrl, strapiAccessToken, pageSize, skipFileDownloads = false } = options;
|
|
46
|
+
const { strapiApiUrl, strapiAccessToken, pageSize, skipFileDownloads = false, retryNumber, retryDelay } = options;
|
|
47
47
|
if (source === 'local') {
|
|
48
48
|
reporter.warn('Local source mode enabled. Skipping Strapi source nodes.');
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
51
|
-
const strapiClient = new strapi_source_1.StrapiClient(strapiApiUrl, strapiAccessToken);
|
|
51
|
+
const strapiClient = new strapi_source_1.StrapiClient(reporter, strapiApiUrl, strapiAccessToken, retryNumber, retryDelay);
|
|
52
52
|
yield (0, strapi_source_1.sourceStrapiContentNode)(args, strapiClient, { pageSize, skipFileDownloads });
|
|
53
53
|
yield (0, strapi_source_1.sourceStrapiNavigationNode)(args, strapiClient);
|
|
54
54
|
yield (0, strapi_source_1.sourceStrapiLocalizationNode)(args, strapiClient);
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import type { Reporter } from 'gatsby';
|
|
1
2
|
export declare class StrapiClient {
|
|
3
|
+
private reporter;
|
|
2
4
|
private apiUrl;
|
|
3
5
|
private accessToken;
|
|
4
|
-
|
|
6
|
+
private retries;
|
|
7
|
+
private delay;
|
|
8
|
+
constructor(reporter: Reporter, apiUrl?: string, accessToken?: string, retries?: number, delay?: number);
|
|
9
|
+
private fetchWithRetry;
|
|
5
10
|
fetch<T = any>(path: string): Promise<T>;
|
|
6
11
|
getApiUrl(): string;
|
|
7
12
|
}
|
|
@@ -11,15 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.StrapiClient = void 0;
|
|
13
13
|
class StrapiClient {
|
|
14
|
-
constructor(apiUrl, accessToken) {
|
|
14
|
+
constructor(reporter, apiUrl, accessToken, retries = 3, delay = 1000) {
|
|
15
15
|
if (!apiUrl || !accessToken) {
|
|
16
16
|
throw new Error('Missing STRAPI_API_URL or STRAPI_TOKEN in environment variables.');
|
|
17
17
|
}
|
|
18
|
+
this.reporter = reporter;
|
|
18
19
|
this.apiUrl = apiUrl;
|
|
19
20
|
this.accessToken = accessToken;
|
|
21
|
+
this.retries = retries;
|
|
22
|
+
this.delay = delay;
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
return __awaiter(this,
|
|
24
|
+
fetchWithRetry(path_1) {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function* (path, retries = this.retries, delay = this.delay) {
|
|
23
26
|
try {
|
|
24
27
|
const result = yield fetch(`${this.apiUrl}/api/${path}`, {
|
|
25
28
|
headers: {
|
|
@@ -33,10 +36,20 @@ class StrapiClient {
|
|
|
33
36
|
return data;
|
|
34
37
|
}
|
|
35
38
|
catch (error) {
|
|
36
|
-
|
|
39
|
+
if (retries > 0) {
|
|
40
|
+
this.reporter.warn(`Fetch failed for ${path}. Retrying in ${delay}ms... (${retries} retries left)`);
|
|
41
|
+
yield new Promise((res) => setTimeout(res, delay));
|
|
42
|
+
return this.fetchWithRetry(path, retries - 1, delay * 2); // exponential backoff
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`Error fetching ${path}: ${error}`);
|
|
37
45
|
}
|
|
38
46
|
});
|
|
39
47
|
}
|
|
48
|
+
fetch(path) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return this.fetchWithRetry(path, this.retries, this.delay);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
40
53
|
getApiUrl() {
|
|
41
54
|
return this.apiUrl;
|
|
42
55
|
}
|