@statsig/client-core 0.0.1-beta.3 → 0.0.1-beta.31
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 +1 -1
- package/package.json +1 -1
- package/src/$_StatsigGlobal.d.ts +8 -1
- package/src/$_StatsigGlobal.js +22 -12
- package/src/ClientInterfaces.d.ts +47 -14
- package/src/DataAdapterCore.d.ts +32 -0
- package/src/DataAdapterCore.js +167 -0
- package/src/Diagnostics.js +24 -26
- package/src/DownloadConfigSpecsResponse.d.ts +41 -0
- package/src/ErrorBoundary.d.ts +1 -0
- package/src/ErrorBoundary.js +41 -86
- package/src/EvaluationOptions.d.ts +20 -0
- package/src/EvaluationOptions.js +2 -0
- package/src/EvaluationTypes.d.ts +39 -0
- package/src/EvaluationTypes.js +2 -0
- package/src/EventLogger.d.ts +21 -8
- package/src/EventLogger.js +206 -228
- package/src/Hashing.d.ts +2 -1
- package/src/Hashing.js +25 -6
- package/src/InitializeResponse.d.ts +18 -0
- package/src/InitializeResponse.js +2 -0
- package/src/Log.js +15 -34
- package/src/Monitoring.d.ts +1 -2
- package/src/Monitoring.js +68 -27
- package/src/NetworkCore.d.ts +17 -6
- package/src/NetworkCore.js +128 -166
- package/src/NetworkDefaults.d.ts +5 -0
- package/src/NetworkDefaults.js +8 -0
- package/src/NetworkParams.d.ts +9 -0
- package/src/NetworkParams.js +13 -0
- package/src/OverrideAdapter.d.ts +9 -0
- package/src/OverrideAdapter.js +2 -0
- package/src/SDKType.d.ts +8 -0
- package/src/SDKType.js +19 -0
- package/src/SafeJs.d.ts +4 -0
- package/src/SafeJs.js +27 -0
- package/src/SessionID.d.ts +10 -1
- package/src/SessionID.js +86 -6
- package/src/StableID.js +24 -53
- package/src/StatsigClientBase.d.ts +57 -28
- package/src/StatsigClientBase.js +114 -238
- package/src/StatsigClientEventEmitter.d.ts +65 -28
- package/src/StatsigDataAdapter.d.ts +89 -0
- package/src/StatsigDataAdapter.js +4 -0
- package/src/StatsigEvent.d.ts +10 -19
- package/src/StatsigEvent.js +50 -41
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +7 -18
- package/src/StatsigOptionsCommon.d.ts +68 -17
- package/src/StatsigTypeFactories.d.ts +6 -0
- package/src/StatsigTypeFactories.js +50 -0
- package/src/StatsigTypes.d.ts +29 -18
- package/src/StatsigTypes.js +0 -29
- package/src/StatsigUser.d.ts +2 -5
- package/src/StatsigUser.js +10 -18
- package/src/StorageProvider.d.ts +12 -7
- package/src/StorageProvider.js +58 -67
- package/src/TypedJsonParse.d.ts +8 -0
- package/src/TypedJsonParse.js +27 -0
- package/src/UUID.js +9 -5
- package/src/UrlOverrides.d.ts +1 -0
- package/src/UrlOverrides.js +15 -0
- package/src/UtitlityTypes.d.ts +3 -0
- package/src/UtitlityTypes.js +2 -0
- package/src/VisibilityObserving.d.ts +8 -0
- package/src/VisibilityObserving.js +30 -0
- package/src/index.d.ts +21 -4
- package/src/index.js +31 -17
- package/src/StatsigDataProvider.d.ts +0 -9
- package/src/VisibilityChangeObserver.d.ts +0 -13
- package/src/VisibilityChangeObserver.js +0 -48
- package/src/__tests__/MockLocalStorage.d.ts +0 -9
- package/src/__tests__/MockLocalStorage.js +0 -37
- /package/src/{StatsigDataProvider.js → DownloadConfigSpecsResponse.js} +0 -0
package/src/StatsigClientBase.js
CHANGED
|
@@ -8,265 +8,141 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
39
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
40
|
-
var m = o[Symbol.asyncIterator], i;
|
|
41
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
42
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
43
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
44
|
-
};
|
|
45
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.StatsigClientBase =
|
|
12
|
+
exports.StatsigClientBase = void 0;
|
|
47
13
|
require("./$_StatsigGlobal");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var _a, _b;
|
|
14
|
+
const __StatsigGlobal_1 = require("./$_StatsigGlobal");
|
|
15
|
+
const ErrorBoundary_1 = require("./ErrorBoundary");
|
|
16
|
+
const EventLogger_1 = require("./EventLogger");
|
|
17
|
+
const Log_1 = require("./Log");
|
|
18
|
+
const SessionID_1 = require("./SessionID");
|
|
19
|
+
const StableID_1 = require("./StableID");
|
|
20
|
+
const StorageProvider_1 = require("./StorageProvider");
|
|
21
|
+
class StatsigClientBase {
|
|
22
|
+
constructor(sdkKey, adapter, network, options) {
|
|
23
|
+
var _a, _b, _c;
|
|
58
24
|
this.loadingStatus = 'Uninitialized';
|
|
59
25
|
this._listeners = {};
|
|
60
|
-
this._logger = new EventLogger_1.EventLogger(sdkKey, this.emit.bind(this), network, options);
|
|
61
26
|
this._sdkKey = sdkKey;
|
|
62
|
-
this.
|
|
63
|
-
|
|
27
|
+
this._options = options !== null && options !== void 0 ? options : {};
|
|
28
|
+
(options === null || options === void 0 ? void 0 : options.disableStorage) && StorageProvider_1.Storage._setDisabled(true);
|
|
29
|
+
(options === null || options === void 0 ? void 0 : options.overrideStableID) &&
|
|
64
30
|
StableID_1.StableID.setOverride(options.overrideStableID, sdkKey);
|
|
31
|
+
Log_1.Log.level = (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : Log_1.LogLevel.Warn;
|
|
32
|
+
this._overrideAdapter = (_b = options === null || options === void 0 ? void 0 : options.overrideAdapter) !== null && _b !== void 0 ? _b : null;
|
|
33
|
+
this._logger = new EventLogger_1.EventLogger(sdkKey, this._emit.bind(this), network, options);
|
|
34
|
+
SessionID_1.SessionID._setEmitFunction(() => {
|
|
35
|
+
this._emit({ name: 'session_expired' });
|
|
36
|
+
}, sdkKey);
|
|
37
|
+
this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey);
|
|
38
|
+
const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
|
|
39
|
+
const instances = (_c = statsigGlobal.instances) !== null && _c !== void 0 ? _c : {};
|
|
40
|
+
if (instances[sdkKey] != null) {
|
|
41
|
+
Log_1.Log.warn('Creating multiple Statsig clients with the same SDK key can lead to unexpected behavior. Multi-instance support requires different SDK keys.');
|
|
42
|
+
}
|
|
43
|
+
const inst = this;
|
|
44
|
+
instances[sdkKey] = inst;
|
|
45
|
+
statsigGlobal.lastInstance = inst;
|
|
46
|
+
statsigGlobal.instances = instances;
|
|
47
|
+
__STATSIG__ = statsigGlobal;
|
|
48
|
+
this.dataAdapter = adapter;
|
|
49
|
+
this.dataAdapter.attach(sdkKey, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Updates runtime configuration options for the SDK, allowing toggling of certain behaviors such as logging and storage to comply with user preferences or regulations such as GDPR.
|
|
53
|
+
*
|
|
54
|
+
* @param {StatsigRuntimeMutableOptions} options - The configuration options that dictate the runtime behavior of the SDK.
|
|
55
|
+
*/
|
|
56
|
+
updateRuntimeOptions(options) {
|
|
57
|
+
if (options.disableLogging != null) {
|
|
58
|
+
this._options.disableLogging = options.disableLogging;
|
|
59
|
+
this._logger.setLoggingDisabled(options.disableLogging);
|
|
60
|
+
}
|
|
61
|
+
if (options.disableStorage != null) {
|
|
62
|
+
this._options.disableStorage = options.disableStorage;
|
|
63
|
+
StorageProvider_1.Storage._setDisabled(options.disableStorage);
|
|
65
64
|
}
|
|
66
|
-
__STATSIG__ = __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {};
|
|
67
|
-
var instances = (_a = __STATSIG__.instances) !== null && _a !== void 0 ? _a : new Set();
|
|
68
|
-
instances.add(this);
|
|
69
|
-
__STATSIG__.instances = instances;
|
|
70
|
-
Log_1.Log.level = (_b = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _b !== void 0 ? _b : Log_1.LogLevel.Warn;
|
|
71
|
-
this._dataProviders = dataProviders;
|
|
72
65
|
}
|
|
73
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Flushes any currently queued events.
|
|
68
|
+
*/
|
|
69
|
+
flush() {
|
|
70
|
+
return this._logger.flush();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gracefully shuts down the SDK, ensuring that all pending events are send before the SDK stops.
|
|
74
|
+
* This function emits a 'pre_shutdown' event and then waits for the logger to complete its shutdown process.
|
|
75
|
+
*
|
|
76
|
+
* @returns {Promise<void>} A promise that resolves when all shutdown procedures, including logging shutdown, have been completed.
|
|
77
|
+
*/
|
|
78
|
+
shutdown() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
this._emit({ name: 'pre_shutdown' });
|
|
81
|
+
yield this._logger.shutdown();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Subscribes a callback function to a specific {@link StatsigClientEvent} or all StatsigClientEvents if the wildcard '*' is used.
|
|
86
|
+
* Once subscribed, the listener callback will be invoked whenever the specified event is emitted.
|
|
87
|
+
*
|
|
88
|
+
* @param {StatsigClientEventName} event - The name of the event to subscribe to, or '*' to subscribe to all events.
|
|
89
|
+
* @param {StatsigClientEventCallback<T>} listener - The callback function to execute when the event occurs. The function receives event-specific data as its parameter.
|
|
90
|
+
* @see {@link off} for unsubscribing from events.
|
|
91
|
+
*/
|
|
92
|
+
on(event, listener) {
|
|
74
93
|
if (!this._listeners[event]) {
|
|
75
94
|
this._listeners[event] = [];
|
|
76
95
|
}
|
|
77
96
|
this._listeners[event].push(listener);
|
|
78
|
-
}
|
|
79
|
-
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Unsubscribes a previously registered callback function from a specific {@link StatsigClientEvent} or all StatsigClientEvents if the wildcard '*' is used.
|
|
100
|
+
*
|
|
101
|
+
* @param {StatsigClientEventName} event - The name of the event from which to unsubscribe, or '*' to unsubscribe from all events.
|
|
102
|
+
* @param {StatsigClientEventCallback<T>} listener - The callback function to remove from the event's notification list.
|
|
103
|
+
* @see {@link on} for subscribing to events.
|
|
104
|
+
*/
|
|
105
|
+
off(event, listener) {
|
|
80
106
|
if (this._listeners[event]) {
|
|
81
|
-
|
|
107
|
+
const index = this._listeners[event].indexOf(listener);
|
|
82
108
|
if (index !== -1) {
|
|
83
109
|
this._listeners[event].splice(index, 1);
|
|
84
110
|
}
|
|
85
111
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
(_a = this._listeners['*']) === null || _a === void 0 ? void 0 : _a.forEach(function (listener) { return listener(data); });
|
|
93
|
-
};
|
|
94
|
-
StatsigClientBase.prototype._setStatus = function (newStatus) {
|
|
95
|
-
this.loadingStatus = newStatus;
|
|
96
|
-
this.emit({ event: 'status_change', loadingStatus: newStatus });
|
|
97
|
-
};
|
|
98
|
-
StatsigClientBase.prototype._getDataFromProviders = function (user) {
|
|
112
|
+
}
|
|
113
|
+
__on(event, listener) {
|
|
114
|
+
listener.__isInternal = true;
|
|
115
|
+
this.on(event, listener);
|
|
116
|
+
}
|
|
117
|
+
_emit(event) {
|
|
99
118
|
var _a;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (data) {
|
|
104
|
-
return { data: data, source: provider.source };
|
|
119
|
+
const barrier = (listener) => {
|
|
120
|
+
try {
|
|
121
|
+
listener(event);
|
|
105
122
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var _a, e_1, _b, _c;
|
|
111
|
-
var _d;
|
|
112
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
113
|
-
var _e, _f, _g, provider, data, e_1_1;
|
|
114
|
-
return __generator(this, function (_h) {
|
|
115
|
-
switch (_h.label) {
|
|
116
|
-
case 0:
|
|
117
|
-
_h.trys.push([0, 6, 7, 12]);
|
|
118
|
-
_e = true, _f = __asyncValues(this._dataProviders);
|
|
119
|
-
_h.label = 1;
|
|
120
|
-
case 1: return [4 /*yield*/, _f.next()];
|
|
121
|
-
case 2:
|
|
122
|
-
if (!(_g = _h.sent(), _a = _g.done, !_a)) return [3 /*break*/, 5];
|
|
123
|
-
_c = _g.value;
|
|
124
|
-
_e = false;
|
|
125
|
-
provider = _c;
|
|
126
|
-
return [4 /*yield*/, ((_d = provider.getDataAsync) === null || _d === void 0 ? void 0 : _d.call(provider, this._sdkKey, user))];
|
|
127
|
-
case 3:
|
|
128
|
-
data = _h.sent();
|
|
129
|
-
if (data) {
|
|
130
|
-
return [2 /*return*/, { data: data, source: provider.source }];
|
|
131
|
-
}
|
|
132
|
-
_h.label = 4;
|
|
133
|
-
case 4:
|
|
134
|
-
_e = true;
|
|
135
|
-
return [3 /*break*/, 1];
|
|
136
|
-
case 5: return [3 /*break*/, 12];
|
|
137
|
-
case 6:
|
|
138
|
-
e_1_1 = _h.sent();
|
|
139
|
-
e_1 = { error: e_1_1 };
|
|
140
|
-
return [3 /*break*/, 12];
|
|
141
|
-
case 7:
|
|
142
|
-
_h.trys.push([7, , 10, 11]);
|
|
143
|
-
if (!(!_e && !_a && (_b = _f.return))) return [3 /*break*/, 9];
|
|
144
|
-
return [4 /*yield*/, _b.call(_f)];
|
|
145
|
-
case 8:
|
|
146
|
-
_h.sent();
|
|
147
|
-
_h.label = 9;
|
|
148
|
-
case 9: return [3 /*break*/, 11];
|
|
149
|
-
case 10:
|
|
150
|
-
if (e_1) throw e_1.error;
|
|
151
|
-
return [7 /*endfinally*/];
|
|
152
|
-
case 11: return [7 /*endfinally*/];
|
|
153
|
-
case 12: return [2 /*return*/, { data: null, source: 'NoValues' }];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
StatsigClientBase.prototype._getDataPostInitFromProviders = function (currentData, user) {
|
|
159
|
-
var _a, e_2, _b, _c;
|
|
160
|
-
var _d;
|
|
161
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
162
|
-
var _e, _f, _g, provider, data, e_2_1;
|
|
163
|
-
return __generator(this, function (_h) {
|
|
164
|
-
switch (_h.label) {
|
|
165
|
-
case 0:
|
|
166
|
-
_h.trys.push([0, 6, 7, 12]);
|
|
167
|
-
_e = true, _f = __asyncValues(this._dataProviders);
|
|
168
|
-
_h.label = 1;
|
|
169
|
-
case 1: return [4 /*yield*/, _f.next()];
|
|
170
|
-
case 2:
|
|
171
|
-
if (!(_g = _h.sent(), _a = _g.done, !_a)) return [3 /*break*/, 5];
|
|
172
|
-
_c = _g.value;
|
|
173
|
-
_e = false;
|
|
174
|
-
provider = _c;
|
|
175
|
-
return [4 /*yield*/, ((_d = provider.getDataPostInit) === null || _d === void 0 ? void 0 : _d.call(provider, this._sdkKey, currentData, user))];
|
|
176
|
-
case 3:
|
|
177
|
-
data = _h.sent();
|
|
178
|
-
if (data) {
|
|
179
|
-
return [2 /*return*/, { data: data, source: provider.source }];
|
|
180
|
-
}
|
|
181
|
-
_h.label = 4;
|
|
182
|
-
case 4:
|
|
183
|
-
_e = true;
|
|
184
|
-
return [3 /*break*/, 1];
|
|
185
|
-
case 5: return [3 /*break*/, 12];
|
|
186
|
-
case 6:
|
|
187
|
-
e_2_1 = _h.sent();
|
|
188
|
-
e_2 = { error: e_2_1 };
|
|
189
|
-
return [3 /*break*/, 12];
|
|
190
|
-
case 7:
|
|
191
|
-
_h.trys.push([7, , 10, 11]);
|
|
192
|
-
if (!(!_e && !_a && (_b = _f.return))) return [3 /*break*/, 9];
|
|
193
|
-
return [4 /*yield*/, _b.call(_f)];
|
|
194
|
-
case 8:
|
|
195
|
-
_h.sent();
|
|
196
|
-
_h.label = 9;
|
|
197
|
-
case 9: return [3 /*break*/, 11];
|
|
198
|
-
case 10:
|
|
199
|
-
if (e_2) throw e_2.error;
|
|
200
|
-
return [7 /*endfinally*/];
|
|
201
|
-
case 11: return [7 /*endfinally*/];
|
|
202
|
-
case 12: return [2 /*return*/, { data: null, source: 'NoValues' }];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
};
|
|
207
|
-
StatsigClientBase.prototype._saveToDataProviders = function (currentData, user) {
|
|
208
|
-
var _this = this;
|
|
209
|
-
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
210
|
-
var latest, data, _a, _b, _c, provider, e_3_1;
|
|
211
|
-
var _d, e_3, _e, _f;
|
|
212
|
-
var _g, _h;
|
|
213
|
-
return __generator(this, function (_j) {
|
|
214
|
-
switch (_j.label) {
|
|
215
|
-
case 0: return [4 /*yield*/, this._getDataPostInitFromProviders(currentData, user)];
|
|
216
|
-
case 1:
|
|
217
|
-
latest = _j.sent();
|
|
218
|
-
data = (_g = latest.data) !== null && _g !== void 0 ? _g : currentData;
|
|
219
|
-
if (!data) {
|
|
220
|
-
return [2 /*return*/];
|
|
221
|
-
}
|
|
222
|
-
_j.label = 2;
|
|
223
|
-
case 2:
|
|
224
|
-
_j.trys.push([2, 8, 9, 14]);
|
|
225
|
-
_a = true, _b = __asyncValues(this._dataProviders);
|
|
226
|
-
_j.label = 3;
|
|
227
|
-
case 3: return [4 /*yield*/, _b.next()];
|
|
228
|
-
case 4:
|
|
229
|
-
if (!(_c = _j.sent(), _d = _c.done, !_d)) return [3 /*break*/, 7];
|
|
230
|
-
_f = _c.value;
|
|
231
|
-
_a = false;
|
|
232
|
-
provider = _f;
|
|
233
|
-
return [4 /*yield*/, ((_h = provider.setDataPostInit) === null || _h === void 0 ? void 0 : _h.call(provider, this._sdkKey, data, user))];
|
|
234
|
-
case 5:
|
|
235
|
-
_j.sent();
|
|
236
|
-
_j.label = 6;
|
|
237
|
-
case 6:
|
|
238
|
-
_a = true;
|
|
239
|
-
return [3 /*break*/, 3];
|
|
240
|
-
case 7: return [3 /*break*/, 14];
|
|
241
|
-
case 8:
|
|
242
|
-
e_3_1 = _j.sent();
|
|
243
|
-
e_3 = { error: e_3_1 };
|
|
244
|
-
return [3 /*break*/, 14];
|
|
245
|
-
case 9:
|
|
246
|
-
_j.trys.push([9, , 12, 13]);
|
|
247
|
-
if (!(!_a && !_d && (_e = _b.return))) return [3 /*break*/, 11];
|
|
248
|
-
return [4 /*yield*/, _e.call(_b)];
|
|
249
|
-
case 10:
|
|
250
|
-
_j.sent();
|
|
251
|
-
_j.label = 11;
|
|
252
|
-
case 11: return [3 /*break*/, 13];
|
|
253
|
-
case 12:
|
|
254
|
-
if (e_3) throw e_3.error;
|
|
255
|
-
return [7 /*endfinally*/];
|
|
256
|
-
case 13: return [7 /*endfinally*/];
|
|
257
|
-
case 14: return [2 /*return*/];
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (listener.__isInternal === true) {
|
|
125
|
+
this._errorBoundary.logError(`_emit:${event.name}`, error);
|
|
126
|
+
return;
|
|
258
127
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
128
|
+
Log_1.Log.error(`An error occurred in a StatsigClientEvent listener. This is not an issue with Statsig.`, event);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
if (this._listeners[event.name]) {
|
|
132
|
+
this._listeners[event.name].forEach((l) => barrier(l));
|
|
133
|
+
}
|
|
134
|
+
(_a = this._listeners['*']) === null || _a === void 0 ? void 0 : _a.forEach(barrier);
|
|
135
|
+
}
|
|
136
|
+
_setStatus(newStatus, values) {
|
|
137
|
+
this.loadingStatus = newStatus;
|
|
138
|
+
this._emit({ name: 'values_updated', status: newStatus, values });
|
|
139
|
+
}
|
|
140
|
+
_enqueueExposure(name, exposure, options) {
|
|
141
|
+
if ((options === null || options === void 0 ? void 0 : options.disableExposureLog) === true) {
|
|
142
|
+
this._logger.incrementNonExposureCount(name);
|
|
266
143
|
return;
|
|
267
144
|
}
|
|
268
145
|
this._logger.enqueue(exposure);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
}());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
272
148
|
exports.StatsigClientBase = StatsigClientBase;
|
|
@@ -1,33 +1,70 @@
|
|
|
1
|
+
import { DataAdapterResult } from './StatsigDataAdapter';
|
|
1
2
|
import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
import { Flatten } from './UtitlityTypes';
|
|
4
|
+
export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
5
|
+
type EventNameToEventDataMap = {
|
|
6
|
+
values_updated: {
|
|
7
|
+
status: StatsigLoadingStatus;
|
|
8
|
+
values: DataAdapterResult | null;
|
|
9
|
+
};
|
|
10
|
+
session_expired: object;
|
|
11
|
+
error: {
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
logs_flushed: {
|
|
15
|
+
events: Record<string, unknown>[];
|
|
16
|
+
};
|
|
17
|
+
pre_shutdown: object;
|
|
18
|
+
gate_evaluation: {
|
|
19
|
+
gate: FeatureGate;
|
|
20
|
+
};
|
|
21
|
+
dynamic_config_evaluation: {
|
|
22
|
+
dynamicConfig: DynamicConfig;
|
|
23
|
+
};
|
|
24
|
+
experiment_evaluation: {
|
|
25
|
+
experiment: Experiment;
|
|
26
|
+
};
|
|
27
|
+
layer_evaluation: {
|
|
28
|
+
layer: Layer;
|
|
29
|
+
};
|
|
27
30
|
};
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Type representing various events emitted by a Statsig client.
|
|
33
|
+
*
|
|
34
|
+
* `values_updated` - When the Statsig clients internal values change as the result of an initialize/update operation.
|
|
35
|
+
*
|
|
36
|
+
* `error` - When an unexpected error occurs within the Statsig client.
|
|
37
|
+
*
|
|
38
|
+
* `logs_flushed` - When queued StatsigEvents are flushed to Statsig servers.
|
|
39
|
+
*
|
|
40
|
+
* `pre_shutdown` - Fired just before the SDK is shutdown
|
|
41
|
+
*
|
|
42
|
+
* `gate_evaluation` - Fired when any gate is checked from the Statsig client.
|
|
43
|
+
*
|
|
44
|
+
* `dynamic_config_evaluation` - Fired when any dyanamic config is checked from the Statsig client.
|
|
45
|
+
*
|
|
46
|
+
* `experiment_evaluation` - Fired when any experiment is checked from the Statsig client.
|
|
47
|
+
*
|
|
48
|
+
* `layer_evaluation` - Fired when any layer is checked from the Statsig client.
|
|
49
|
+
*/
|
|
50
|
+
export type AnyStatsigClientEvent = Flatten<{
|
|
51
|
+
[K in keyof EventNameToEventDataMap]: {
|
|
52
|
+
name: K;
|
|
53
|
+
} & EventNameToEventDataMap[K];
|
|
54
|
+
}[keyof EventNameToEventDataMap]>;
|
|
55
|
+
export type StatsigClientEvent<T> = Extract<AnyStatsigClientEvent, {
|
|
56
|
+
name: T;
|
|
57
|
+
}>;
|
|
58
|
+
export type AnyStatsigClientEventListener = StatsigClientEventCallback<StatsigClientEventName>;
|
|
59
|
+
export type StatsigClientEventName = AnyStatsigClientEvent['name'] | '*';
|
|
60
|
+
export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? AnyStatsigClientEvent : StatsigClientEvent<T>) => void;
|
|
29
61
|
export interface StatsigClientEventEmitterInterface {
|
|
30
62
|
readonly loadingStatus: StatsigLoadingStatus;
|
|
31
|
-
on(event:
|
|
32
|
-
off(event:
|
|
63
|
+
on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
64
|
+
off<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
65
|
+
/**
|
|
66
|
+
* (Statsig Use Only) - Same as .on() but logs errors to sdk_exception
|
|
67
|
+
*/
|
|
68
|
+
__on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
33
69
|
}
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AnyStatsigOptions } from './StatsigOptionsCommon';
|
|
2
|
+
import { StatsigUser } from './StatsigUser';
|
|
3
|
+
export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap' | 'Prefetch';
|
|
4
|
+
export type DataAdapterResult = {
|
|
5
|
+
readonly source: DataSource;
|
|
6
|
+
readonly data: string;
|
|
7
|
+
readonly receivedAt: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const DataAdapterCachePrefix = "statsig.cached";
|
|
10
|
+
/**
|
|
11
|
+
* Describes a type that is used during intialize/update operations of a Statsig client.
|
|
12
|
+
*
|
|
13
|
+
* See below to find the default adapters, but know that it is possible to create your
|
|
14
|
+
* own StatsigDataAdapter and provide it via {@link StatsigOptionsCommon.dataAdapter}.
|
|
15
|
+
*
|
|
16
|
+
* Defaults:
|
|
17
|
+
*
|
|
18
|
+
* - {@link StatsigClient} uses {@link EvaluationsDataAdapter}
|
|
19
|
+
*
|
|
20
|
+
* - {@link StatsigOnDeviceEvalClient} uses {@link SpecsDataAdapter}
|
|
21
|
+
*/
|
|
22
|
+
type DataAdapterCommon = {
|
|
23
|
+
/**
|
|
24
|
+
* Called when the StatsigDataAdapter is attached to the Statsig client instance during construction.
|
|
25
|
+
* @param {string} sdkKey The SDK key being used by the Statsig client.
|
|
26
|
+
* @param {StatsigOptionsCommon | null} options The StatsigOptions being used by the Statsig client.
|
|
27
|
+
*/
|
|
28
|
+
readonly attach: (sdkKey: string, options: AnyStatsigOptions | null) => void;
|
|
29
|
+
/**
|
|
30
|
+
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
31
|
+
*
|
|
32
|
+
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
33
|
+
*/
|
|
34
|
+
readonly __primeInMemoryCache: (cache: Record<string, DataAdapterResult>) => void;
|
|
35
|
+
};
|
|
36
|
+
export type EvaluationsDataAdapter = DataAdapterCommon & {
|
|
37
|
+
/**
|
|
38
|
+
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
|
|
39
|
+
*
|
|
40
|
+
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
41
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
42
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
43
|
+
*/
|
|
44
|
+
readonly getDataSync: (user: StatsigUser) => DataAdapterResult | null;
|
|
45
|
+
/**
|
|
46
|
+
* Asynchronously get evaluation data for the given user. Called during initializeAsync and/or updateUserAsync.
|
|
47
|
+
*
|
|
48
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
49
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
50
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
51
|
+
*/
|
|
52
|
+
readonly getDataAsync: (current: DataAdapterResult | null, user: StatsigUser) => Promise<DataAdapterResult | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Manually trigger a fetch for new evaluations data for the given user.
|
|
55
|
+
*
|
|
56
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
57
|
+
*/
|
|
58
|
+
readonly prefetchData: (user: StatsigUser) => Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Manually set evaluations data for the given user.
|
|
61
|
+
*
|
|
62
|
+
* @param {StatsigUser} user The StatsigUser this data is for.
|
|
63
|
+
*/
|
|
64
|
+
readonly setData: (data: string, user: StatsigUser) => void;
|
|
65
|
+
};
|
|
66
|
+
export type SpecsDataAdapter = DataAdapterCommon & {
|
|
67
|
+
/**
|
|
68
|
+
* Synchronously get specs data. Called during initializeSync and/or updateUserSync.
|
|
69
|
+
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
70
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
71
|
+
*/
|
|
72
|
+
readonly getDataSync: () => DataAdapterResult | null;
|
|
73
|
+
/**
|
|
74
|
+
* Asynchronously get specs data. Called during initializeAsync and/or updateUserAsync.
|
|
75
|
+
*
|
|
76
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
77
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
78
|
+
*/
|
|
79
|
+
readonly getDataAsync: (current: DataAdapterResult | null) => Promise<DataAdapterResult | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Manually trigger a fetch for new specs data.
|
|
82
|
+
*/
|
|
83
|
+
readonly prefetchData: () => Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Manually set specs data (Bootstrap).
|
|
86
|
+
*/
|
|
87
|
+
readonly setData: (data: string) => void;
|
|
88
|
+
};
|
|
89
|
+
export {};
|
package/src/StatsigEvent.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DynamicConfig, FeatureGate } from './StatsigTypes';
|
|
1
|
+
import { SecondaryExposure } from './EvaluationTypes';
|
|
2
|
+
import { DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
|
|
3
3
|
import { StatsigUser } from './StatsigUser';
|
|
4
|
-
export type SecondaryExposure = {
|
|
5
|
-
gate: string;
|
|
6
|
-
gateValue: string;
|
|
7
|
-
ruleID: string;
|
|
8
|
-
};
|
|
9
4
|
export type StatsigEvent = {
|
|
10
5
|
eventName: string;
|
|
11
6
|
value?: string | number | null;
|
|
@@ -13,19 +8,15 @@ export type StatsigEvent = {
|
|
|
13
8
|
[key: string]: string;
|
|
14
9
|
} | null;
|
|
15
10
|
};
|
|
16
|
-
export type StatsigEventInternal = StatsigEvent & {
|
|
11
|
+
export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
|
|
17
12
|
user: StatsigUser | null;
|
|
18
13
|
time: number;
|
|
14
|
+
metadata?: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
} | null;
|
|
19
17
|
secondaryExposures?: SecondaryExposure[];
|
|
20
18
|
};
|
|
21
|
-
export declare
|
|
22
|
-
export declare
|
|
23
|
-
export declare
|
|
24
|
-
export declare
|
|
25
|
-
rule_id: string;
|
|
26
|
-
explicit_parameters: string[];
|
|
27
|
-
undelegated_secondary_exposures?: SecondaryExposure[];
|
|
28
|
-
secondary_exposures: SecondaryExposure[];
|
|
29
|
-
allocated_experiment_name: string;
|
|
30
|
-
source: DataSource;
|
|
31
|
-
}): StatsigEventInternal;
|
|
19
|
+
export declare const _isExposureEvent: ({ eventName, }: StatsigEventInternal) => boolean;
|
|
20
|
+
export declare const _createGateExposure: (user: StatsigUser, gate: FeatureGate) => StatsigEventInternal;
|
|
21
|
+
export declare const _createConfigExposure: (user: StatsigUser, config: DynamicConfig) => StatsigEventInternal;
|
|
22
|
+
export declare const _createLayerParameterExposure: (user: StatsigUser, layer: Layer, parameterName: string) => StatsigEventInternal;
|