@statsig/client-core 3.25.4 → 3.25.6
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/package.json +1 -1
- package/src/NetworkCore.js +24 -15
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
package/package.json
CHANGED
package/src/NetworkCore.js
CHANGED
|
@@ -109,8 +109,10 @@ class NetworkCore {
|
|
|
109
109
|
}
|
|
110
110
|
const currentAttempt = attempt !== null && attempt !== void 0 ? attempt : 1;
|
|
111
111
|
const abortController = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
112
|
+
let reqTimedOut = false;
|
|
112
113
|
const timeoutHandle = setTimeout(() => {
|
|
113
|
-
|
|
114
|
+
reqTimedOut = true;
|
|
115
|
+
abortController === null || abortController === void 0 ? void 0 : abortController.abort();
|
|
114
116
|
}, this._timeout);
|
|
115
117
|
const populatedUrl = this._getPopulatedURL(args);
|
|
116
118
|
let response = null;
|
|
@@ -131,8 +133,21 @@ class NetworkCore {
|
|
|
131
133
|
this._leakyBucket[endpoint] = bucket;
|
|
132
134
|
}
|
|
133
135
|
const func = (_a = this._netConfig.networkOverrideFunc) !== null && _a !== void 0 ? _a : fetch;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
if (abortController) {
|
|
137
|
+
// Modern path: true cancellation with AbortController
|
|
138
|
+
response = yield func(populatedUrl, config);
|
|
139
|
+
clearTimeout(timeoutHandle);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
// Fallback path: Promise.race timeout
|
|
143
|
+
response = yield Promise.race([
|
|
144
|
+
func(populatedUrl, config),
|
|
145
|
+
new Promise((_, reject) => setTimeout(() => {
|
|
146
|
+
reqTimedOut = true;
|
|
147
|
+
reject(new Error(`Timeout of ${this._timeout}ms expired.`));
|
|
148
|
+
}, this._timeout)),
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
136
151
|
if (!response.ok) {
|
|
137
152
|
const text = yield response.text().catch(() => 'No Text');
|
|
138
153
|
const err = new Error(`NetworkError: ${populatedUrl} ${text}`);
|
|
@@ -148,8 +163,8 @@ class NetworkCore {
|
|
|
148
163
|
};
|
|
149
164
|
}
|
|
150
165
|
catch (error) {
|
|
151
|
-
const errorMessage = _getErrorMessage(
|
|
152
|
-
const timedOut = _didTimeout(
|
|
166
|
+
const errorMessage = _getErrorMessage(error);
|
|
167
|
+
const timedOut = _didTimeout(errorMessage !== null && errorMessage !== void 0 ? errorMessage : '', reqTimedOut);
|
|
153
168
|
_tryMarkInitEnd(args, response, currentAttempt, '', error);
|
|
154
169
|
const fallbackUpdated = yield this._fallbackResolver.tryFetchUpdatedFallbackInfo(args.sdkKey, args.urlConfig, errorMessage, timedOut);
|
|
155
170
|
if (fallbackUpdated) {
|
|
@@ -328,11 +343,7 @@ function _allowCompression(args, options) {
|
|
|
328
343
|
return false;
|
|
329
344
|
}
|
|
330
345
|
}
|
|
331
|
-
function _getErrorMessage(
|
|
332
|
-
if ((controller === null || controller === void 0 ? void 0 : controller.signal.aborted) &&
|
|
333
|
-
typeof controller.signal.reason === 'string') {
|
|
334
|
-
return controller.signal.reason;
|
|
335
|
-
}
|
|
346
|
+
function _getErrorMessage(error) {
|
|
336
347
|
if (typeof error === 'string') {
|
|
337
348
|
return error;
|
|
338
349
|
}
|
|
@@ -341,11 +352,9 @@ function _getErrorMessage(controller, error) {
|
|
|
341
352
|
}
|
|
342
353
|
return 'Unknown Error';
|
|
343
354
|
}
|
|
344
|
-
function _didTimeout(
|
|
345
|
-
const timeout = (
|
|
346
|
-
|
|
347
|
-
controller.signal.reason.includes('Timeout');
|
|
348
|
-
return timeout || false;
|
|
355
|
+
function _didTimeout(errorMsg, abortedByTimeout) {
|
|
356
|
+
const timeout = errorMsg.includes('Timeout'); // probably not needed but just in case
|
|
357
|
+
return timeout || abortedByTimeout;
|
|
349
358
|
}
|
|
350
359
|
function _tryMarkInitStart(args, attempt) {
|
|
351
360
|
if (args.urlConfig.endpoint !== NetworkConfig_1.Endpoint._initialize) {
|
package/src/StatsigMetadata.d.ts
CHANGED
package/src/StatsigMetadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
|
|
4
|
-
exports.SDK_VERSION = '3.25.
|
|
4
|
+
exports.SDK_VERSION = '3.25.6';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|