@statsig/client-core 3.3.0-beta.1 → 3.3.0-beta.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/package.json +1 -1
- package/src/ErrorBoundary.js +10 -2
- package/src/NetworkCore.js +2 -1
- package/src/NetworkFallbackResolver.d.ts +2 -0
- package/src/NetworkFallbackResolver.js +33 -22
- package/src/StatsigClientEventEmitter.d.ts +5 -0
- package/src/StatsigClientEventEmitter.js +4 -0
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
package/package.json
CHANGED
package/src/ErrorBoundary.js
CHANGED
|
@@ -69,7 +69,11 @@ class ErrorBoundary {
|
|
|
69
69
|
}
|
|
70
70
|
this._seen.add(name);
|
|
71
71
|
if ((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.preventAllNetworkTraffic) {
|
|
72
|
-
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, {
|
|
72
|
+
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, {
|
|
73
|
+
name: 'error',
|
|
74
|
+
error,
|
|
75
|
+
tag,
|
|
76
|
+
});
|
|
73
77
|
return;
|
|
74
78
|
}
|
|
75
79
|
const sdkType = SDKType_1.SDKType._get(this._sdkKey);
|
|
@@ -87,7 +91,11 @@ class ErrorBoundary {
|
|
|
87
91
|
},
|
|
88
92
|
body,
|
|
89
93
|
});
|
|
90
|
-
(_g = this._emitter) === null || _g === void 0 ? void 0 : _g.call(this, {
|
|
94
|
+
(_g = this._emitter) === null || _g === void 0 ? void 0 : _g.call(this, {
|
|
95
|
+
name: 'error',
|
|
96
|
+
error,
|
|
97
|
+
tag,
|
|
98
|
+
});
|
|
91
99
|
});
|
|
92
100
|
impl()
|
|
93
101
|
.then(() => {
|
package/src/NetworkCore.js
CHANGED
|
@@ -20,6 +20,7 @@ const SDKType_1 = require("./SDKType");
|
|
|
20
20
|
const SafeJs_1 = require("./SafeJs");
|
|
21
21
|
const SessionID_1 = require("./SessionID");
|
|
22
22
|
const StableID_1 = require("./StableID");
|
|
23
|
+
const StatsigClientEventEmitter_1 = require("./StatsigClientEventEmitter");
|
|
23
24
|
const StatsigMetadata_1 = require("./StatsigMetadata");
|
|
24
25
|
const VisibilityObserving_1 = require("./VisibilityObserving");
|
|
25
26
|
const DEFAULT_TIMEOUT_MS = 10000;
|
|
@@ -134,7 +135,7 @@ class NetworkCore {
|
|
|
134
135
|
if (!retries ||
|
|
135
136
|
currentAttempt > retries ||
|
|
136
137
|
!RETRYABLE_CODES.has((_b = response === null || response === void 0 ? void 0 : response.status) !== null && _b !== void 0 ? _b : 500)) {
|
|
137
|
-
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
|
|
138
|
+
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error, tag: StatsigClientEventEmitter_1.ErrorTag.NetworkError });
|
|
138
139
|
Log_1.Log.error(`A networking error occured during ${method} request to ${populatedUrl}.`, errorMessage, error);
|
|
139
140
|
return null;
|
|
140
141
|
}
|
|
@@ -7,11 +7,13 @@ export declare class NetworkFallbackResolver {
|
|
|
7
7
|
private _fallbackInfo;
|
|
8
8
|
private _errorBoundary;
|
|
9
9
|
private _networkOverrideFunc?;
|
|
10
|
+
private _cooldowns;
|
|
10
11
|
constructor(options: AnyStatsigOptions);
|
|
11
12
|
setErrorBoundary(errorBoundary: ErrorBoundary): void;
|
|
12
13
|
tryBumpExpiryTime(sdkKey: string, url: string): void;
|
|
13
14
|
getFallbackUrl(sdkKey: string, url: string): string | null;
|
|
14
15
|
tryFetchUpdatedFallbackInfo(sdkKey: string, url: string, errorMessage: string | null, timedOut: boolean): Promise<boolean>;
|
|
16
|
+
private _updateFallbackInfoWithNewUrl;
|
|
15
17
|
private _fetchFallbackUrl;
|
|
16
18
|
}
|
|
17
19
|
export declare function _isDefaultUrl(url: string): boolean;
|
|
@@ -15,12 +15,14 @@ const Hashing_1 = require("./Hashing");
|
|
|
15
15
|
const Log_1 = require("./Log");
|
|
16
16
|
const NetworkConfig_1 = require("./NetworkConfig");
|
|
17
17
|
const StorageProvider_1 = require("./StorageProvider");
|
|
18
|
-
const
|
|
18
|
+
const DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
|
|
19
|
+
const COOLDOWN_TIME_MS = 4 * 60 * 60 * 1000; // 4 hours
|
|
19
20
|
class NetworkFallbackResolver {
|
|
20
21
|
constructor(options) {
|
|
21
22
|
var _a;
|
|
22
23
|
this._fallbackInfo = null;
|
|
23
24
|
this._errorBoundary = null;
|
|
25
|
+
this._cooldowns = {};
|
|
24
26
|
this._networkOverrideFunc = (_a = options.networkConfig) === null || _a === void 0 ? void 0 : _a.networkOverrideFunc;
|
|
25
27
|
}
|
|
26
28
|
setErrorBoundary(errorBoundary) {
|
|
@@ -36,7 +38,7 @@ class NetworkFallbackResolver {
|
|
|
36
38
|
if (!info) {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
|
-
info.expiryTime = Date.now() +
|
|
41
|
+
info.expiryTime = Date.now() + DEFAULT_TTL_MS;
|
|
40
42
|
_tryWriteFallbackInfoToCache(sdkKey, Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: info }));
|
|
41
43
|
}
|
|
42
44
|
getFallbackUrl(sdkKey, url) {
|
|
@@ -64,43 +66,52 @@ class NetworkFallbackResolver {
|
|
|
64
66
|
return null;
|
|
65
67
|
}
|
|
66
68
|
tryFetchUpdatedFallbackInfo(sdkKey, url, errorMessage, timedOut) {
|
|
67
|
-
var _a
|
|
69
|
+
var _a;
|
|
68
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
71
|
try {
|
|
70
72
|
const domainKey = _getDomainKeyFromEndpoint(url);
|
|
71
73
|
if (!_isDomainFailure(errorMessage, timedOut) || !domainKey) {
|
|
72
74
|
return false;
|
|
73
75
|
}
|
|
76
|
+
if (this._cooldowns[domainKey] &&
|
|
77
|
+
Date.now() < this._cooldowns[domainKey]) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
this._cooldowns[domainKey] = Date.now() + COOLDOWN_TIME_MS;
|
|
74
81
|
const newUrl = yield this._fetchFallbackUrl(domainKey);
|
|
75
82
|
if (!newUrl) {
|
|
76
83
|
return false;
|
|
77
84
|
}
|
|
78
|
-
|
|
79
|
-
url: newUrl,
|
|
80
|
-
expiryTime: Date.now() + DEFAULT_TTL,
|
|
81
|
-
previous: [],
|
|
82
|
-
};
|
|
83
|
-
const previousInfo = (_a = this._fallbackInfo) === null || _a === void 0 ? void 0 : _a[domainKey];
|
|
84
|
-
if (previousInfo) {
|
|
85
|
-
newFallbackInfo.previous.push(...previousInfo.previous);
|
|
86
|
-
}
|
|
87
|
-
if (newFallbackInfo.previous.length > 10) {
|
|
88
|
-
newFallbackInfo.previous = [];
|
|
89
|
-
}
|
|
90
|
-
const previousUrl = (_c = (_b = this._fallbackInfo) === null || _b === void 0 ? void 0 : _b[domainKey]) === null || _c === void 0 ? void 0 : _c.url;
|
|
91
|
-
if (previousUrl != null) {
|
|
92
|
-
newFallbackInfo.previous.push(previousUrl);
|
|
93
|
-
}
|
|
94
|
-
this._fallbackInfo = Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: newFallbackInfo });
|
|
95
|
-
_tryWriteFallbackInfoToCache(sdkKey, this._fallbackInfo);
|
|
85
|
+
this._updateFallbackInfoWithNewUrl(sdkKey, domainKey, newUrl);
|
|
96
86
|
return true;
|
|
97
87
|
}
|
|
98
88
|
catch (error) {
|
|
99
|
-
(
|
|
89
|
+
(_a = this._errorBoundary) === null || _a === void 0 ? void 0 : _a.logError('tryFetchUpdatedFallbackInfo', error);
|
|
100
90
|
return false;
|
|
101
91
|
}
|
|
102
92
|
});
|
|
103
93
|
}
|
|
94
|
+
_updateFallbackInfoWithNewUrl(sdkKey, domainKey, newUrl) {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
const newFallbackInfo = {
|
|
97
|
+
url: newUrl,
|
|
98
|
+
expiryTime: Date.now() + DEFAULT_TTL_MS,
|
|
99
|
+
previous: [],
|
|
100
|
+
};
|
|
101
|
+
const previousInfo = (_a = this._fallbackInfo) === null || _a === void 0 ? void 0 : _a[domainKey];
|
|
102
|
+
if (previousInfo) {
|
|
103
|
+
newFallbackInfo.previous.push(...previousInfo.previous);
|
|
104
|
+
}
|
|
105
|
+
if (newFallbackInfo.previous.length > 10) {
|
|
106
|
+
newFallbackInfo.previous = [];
|
|
107
|
+
}
|
|
108
|
+
const previousUrl = (_c = (_b = this._fallbackInfo) === null || _b === void 0 ? void 0 : _b[domainKey]) === null || _c === void 0 ? void 0 : _c.url;
|
|
109
|
+
if (previousUrl != null) {
|
|
110
|
+
newFallbackInfo.previous.push(previousUrl);
|
|
111
|
+
}
|
|
112
|
+
this._fallbackInfo = Object.assign(Object.assign({}, this._fallbackInfo), { [domainKey]: newFallbackInfo });
|
|
113
|
+
_tryWriteFallbackInfoToCache(sdkKey, this._fallbackInfo);
|
|
114
|
+
}
|
|
104
115
|
_fetchFallbackUrl(domainKey) {
|
|
105
116
|
var _a, _b, _c, _d, _e, _f;
|
|
106
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -2,6 +2,10 @@ import { DataAdapterResult } from './StatsigDataAdapter';
|
|
|
2
2
|
import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
|
|
3
3
|
import { Flatten } from './TypingUtils';
|
|
4
4
|
export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
5
|
+
export declare const ErrorTag: {
|
|
6
|
+
readonly NetworkError: "NetworkError";
|
|
7
|
+
};
|
|
8
|
+
export type ErrorTag = (typeof ErrorTag)[keyof typeof ErrorTag];
|
|
5
9
|
type EventNameToEventDataMap = {
|
|
6
10
|
values_updated: {
|
|
7
11
|
status: StatsigLoadingStatus;
|
|
@@ -10,6 +14,7 @@ type EventNameToEventDataMap = {
|
|
|
10
14
|
session_expired: object;
|
|
11
15
|
error: {
|
|
12
16
|
error: unknown;
|
|
17
|
+
tag: ErrorTag | string;
|
|
13
18
|
};
|
|
14
19
|
logs_flushed: {
|
|
15
20
|
events: Record<string, unknown>[];
|
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.3.0-beta.
|
|
4
|
+
exports.SDK_VERSION = '3.3.0-beta.2';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|