@weaverse/hydrogen 5.16.0 → 5.16.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/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -394,6 +394,7 @@ declare class WeaverseClient {
|
|
|
394
394
|
* Returns same format as withCache.fetch for consistency.
|
|
395
395
|
* Includes 10-second timeout to prevent hanging requests.
|
|
396
396
|
*/
|
|
397
|
+
private readonly fetchOnce;
|
|
397
398
|
private readonly directFetch;
|
|
398
399
|
private getApiUrl;
|
|
399
400
|
private isExternalPublicApiUrl;
|
package/dist/index.d.ts
CHANGED
|
@@ -394,6 +394,7 @@ declare class WeaverseClient {
|
|
|
394
394
|
* Returns same format as withCache.fetch for consistency.
|
|
395
395
|
* Includes 10-second timeout to prevent hanging requests.
|
|
396
396
|
*/
|
|
397
|
+
private readonly fetchOnce;
|
|
397
398
|
private readonly directFetch;
|
|
398
399
|
private getApiUrl;
|
|
399
400
|
private isExternalPublicApiUrl;
|
package/dist/index.js
CHANGED
|
@@ -1089,7 +1089,11 @@ function normalizePageUrl(url) {
|
|
|
1089
1089
|
);
|
|
1090
1090
|
kept.sort(([a], [b]) => a.localeCompare(b));
|
|
1091
1091
|
const search = new URLSearchParams(kept).toString();
|
|
1092
|
-
|
|
1092
|
+
let { pathname } = parsed;
|
|
1093
|
+
if (pathname.endsWith(".data")) {
|
|
1094
|
+
pathname = pathname.slice(0, -".data".length);
|
|
1095
|
+
}
|
|
1096
|
+
return `${parsed.origin}${pathname}${search ? `?${search}` : ""}`;
|
|
1093
1097
|
}
|
|
1094
1098
|
|
|
1095
1099
|
// src/weaverse-client.ts
|
|
@@ -1104,6 +1108,17 @@ var CACHE_DURATIONS = {
|
|
|
1104
1108
|
STATIC: 3600
|
|
1105
1109
|
};
|
|
1106
1110
|
var DEFAULT_FETCH_TIMEOUT_MS = 1e4;
|
|
1111
|
+
var MAX_FETCH_ATTEMPTS = 2;
|
|
1112
|
+
var FETCH_RETRY_BACKOFF_MS = 300;
|
|
1113
|
+
function isRetryableFetchError(error) {
|
|
1114
|
+
if (!(error instanceof WeaverseError)) {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
if (error.code === "TIMEOUT_ERROR" || error.code === "NETWORK_ERROR") {
|
|
1118
|
+
return true;
|
|
1119
|
+
}
|
|
1120
|
+
return error.code === "FETCH_ERROR" && (error.statusCode ?? 0) >= 500;
|
|
1121
|
+
}
|
|
1107
1122
|
var API_PATH = "v1";
|
|
1108
1123
|
var DEFAULT_CACHE_STRATEGY = {
|
|
1109
1124
|
maxAge: CACHE_DURATIONS.SHORT,
|
|
@@ -1394,7 +1409,7 @@ var WeaverseClient = class {
|
|
|
1394
1409
|
* Returns same format as withCache.fetch for consistency.
|
|
1395
1410
|
* Includes 10-second timeout to prevent hanging requests.
|
|
1396
1411
|
*/
|
|
1397
|
-
|
|
1412
|
+
fetchOnce = async (url, options, timeoutMs) => {
|
|
1398
1413
|
const controller = new AbortController();
|
|
1399
1414
|
const timeoutId = setTimeout(
|
|
1400
1415
|
() => controller.abort(),
|
|
@@ -1440,6 +1455,23 @@ var WeaverseClient = class {
|
|
|
1440
1455
|
}
|
|
1441
1456
|
}
|
|
1442
1457
|
};
|
|
1458
|
+
directFetch = async (url, options = {}, timeoutMs = this.fetchTimeoutMs) => {
|
|
1459
|
+
let lastError;
|
|
1460
|
+
for (let attempt = 1; attempt <= MAX_FETCH_ATTEMPTS; attempt++) {
|
|
1461
|
+
try {
|
|
1462
|
+
return await this.fetchOnce(url, options, timeoutMs);
|
|
1463
|
+
} catch (err) {
|
|
1464
|
+
lastError = err;
|
|
1465
|
+
if (attempt >= MAX_FETCH_ATTEMPTS || !isRetryableFetchError(err)) {
|
|
1466
|
+
throw err;
|
|
1467
|
+
}
|
|
1468
|
+
await new Promise(
|
|
1469
|
+
(resolve) => setTimeout(resolve, FETCH_RETRY_BACKOFF_MS * attempt)
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
throw lastError;
|
|
1474
|
+
};
|
|
1443
1475
|
// Helper method for building API URLs consistently
|
|
1444
1476
|
getApiUrl(endpoint) {
|
|
1445
1477
|
const { weaverseApiBase } = this.configs;
|