@statsig/client-core 0.0.1-beta.4 → 0.0.1-beta.40
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 -4
- package/package.json +1 -1
- package/src/$_StatsigGlobal.d.ts +8 -1
- package/src/$_StatsigGlobal.js +22 -12
- package/src/ClientInterfaces.d.ts +50 -14
- package/src/DataAdapterCore.d.ts +30 -0
- package/src/DataAdapterCore.js +169 -0
- package/src/Diagnostics.d.ts +1 -3
- package/src/Diagnostics.js +4 -49
- package/src/DownloadConfigSpecsResponse.d.ts +41 -0
- package/src/ErrorBoundary.d.ts +7 -2
- package/src/ErrorBoundary.js +79 -87
- 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 +20 -9
- package/src/EventLogger.js +216 -232
- 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/NetworkConfig.d.ts +18 -0
- package/src/NetworkConfig.js +18 -0
- package/src/NetworkCore.d.ts +19 -6
- package/src/NetworkCore.js +137 -167
- 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 +6 -0
- package/src/SafeJs.js +41 -0
- package/src/SessionID.d.ts +17 -1
- package/src/SessionID.js +89 -8
- package/src/StableID.js +24 -53
- package/src/StatsigClientBase.d.ts +57 -28
- package/src/StatsigClientBase.js +115 -238
- package/src/StatsigClientEventEmitter.d.ts +69 -28
- package/src/StatsigDataAdapter.d.ts +107 -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 +85 -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 +13 -8
- package/src/StorageProvider.js +77 -73
- 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 +20 -5
- package/src/index.js +30 -18
- package/src/Monitoring.d.ts +0 -3
- package/src/Monitoring.js +0 -33
- 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/ErrorBoundary.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,107 +8,99 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.ErrorBoundary = exports.EXCEPTION_ENDPOINT = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
13
|
+
const Log_1 = require("./Log");
|
|
14
|
+
const SDKType_1 = require("./SDKType");
|
|
15
|
+
const StatsigMetadata_1 = require("./StatsigMetadata");
|
|
53
16
|
exports.EXCEPTION_ENDPOINT = 'https://statsigapi.net/v1/sdk_exception';
|
|
54
|
-
|
|
55
|
-
|
|
17
|
+
class ErrorBoundary {
|
|
18
|
+
constructor(_sdkKey, _options, _emitter) {
|
|
56
19
|
this._sdkKey = _sdkKey;
|
|
20
|
+
this._options = _options;
|
|
21
|
+
this._emitter = _emitter;
|
|
57
22
|
this._seen = new Set();
|
|
58
23
|
}
|
|
59
|
-
|
|
60
|
-
var _this = this;
|
|
24
|
+
wrap(instance) {
|
|
61
25
|
try {
|
|
62
|
-
|
|
26
|
+
const obj = instance;
|
|
27
|
+
_getAllInstanceMethodNames(obj).forEach((name) => {
|
|
28
|
+
const original = obj[name];
|
|
29
|
+
if ('$EB' in original) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
obj[name] = (...args) => {
|
|
33
|
+
return this.capture(name, () => original.apply(instance, args));
|
|
34
|
+
};
|
|
35
|
+
obj[name].$EB = true;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
this._onError('eb:wrap', err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
capture(tag, task) {
|
|
43
|
+
try {
|
|
44
|
+
const res = task();
|
|
63
45
|
if (res && res instanceof Promise) {
|
|
64
|
-
return res.catch(
|
|
46
|
+
return res.catch((err) => this._onError(tag, err));
|
|
65
47
|
}
|
|
66
48
|
return res;
|
|
67
49
|
}
|
|
68
50
|
catch (error) {
|
|
69
|
-
this._onError(tag, error
|
|
51
|
+
this._onError(tag, error);
|
|
70
52
|
return null;
|
|
71
53
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
}
|
|
55
|
+
logError(tag, error) {
|
|
56
|
+
this._onError(tag, error);
|
|
57
|
+
}
|
|
58
|
+
_onError(tag, error) {
|
|
75
59
|
try {
|
|
76
|
-
Log_1.Log.warn(
|
|
77
|
-
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
emitter === null || emitter === void 0 ? void 0 : emitter({ event: 'error', error: error });
|
|
105
|
-
return [2 /*return*/];
|
|
106
|
-
}
|
|
60
|
+
Log_1.Log.warn(`Caught error in ${tag}`, { error });
|
|
61
|
+
const impl = () => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
63
|
+
const unwrapped = (error !== null && error !== void 0 ? error : Error('[Statsig] Error was empty'));
|
|
64
|
+
const isError = unwrapped instanceof Error;
|
|
65
|
+
const name = isError ? unwrapped.name : 'No Name';
|
|
66
|
+
if (this._seen.has(name)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this._seen.add(name);
|
|
70
|
+
if ((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.networkConfig) === null || _b === void 0 ? void 0 : _b.preventAllNetworkTraffic) {
|
|
71
|
+
(_c = this._emitter) === null || _c === void 0 ? void 0 : _c.call(this, { name: 'error', error });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const sdkType = SDKType_1.SDKType._get(this._sdkKey);
|
|
75
|
+
const statsigMetadata = StatsigMetadata_1.StatsigMetadataProvider.get();
|
|
76
|
+
const info = isError ? unwrapped.stack : _getDescription(unwrapped);
|
|
77
|
+
const body = JSON.stringify(Object.assign({ tag, exception: name, info }, Object.assign(Object.assign({}, statsigMetadata), { sdkType })));
|
|
78
|
+
const func = (_f = (_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.networkConfig) === null || _e === void 0 ? void 0 : _e.networkOverrideFunc) !== null && _f !== void 0 ? _f : fetch;
|
|
79
|
+
yield func(exports.EXCEPTION_ENDPOINT, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: {
|
|
82
|
+
'STATSIG-API-KEY': this._sdkKey,
|
|
83
|
+
'STATSIG-SDK-TYPE': String(sdkType),
|
|
84
|
+
'STATSIG-SDK-VERSION': String(statsigMetadata.sdkVersion),
|
|
85
|
+
'Content-Type': 'application/json',
|
|
86
|
+
},
|
|
87
|
+
body,
|
|
107
88
|
});
|
|
108
|
-
|
|
89
|
+
(_g = this._emitter) === null || _g === void 0 ? void 0 : _g.call(this, { name: 'error', error });
|
|
90
|
+
});
|
|
109
91
|
impl()
|
|
110
|
-
.then(
|
|
92
|
+
.then(() => {
|
|
111
93
|
/* noop */
|
|
112
94
|
})
|
|
113
|
-
.catch(
|
|
95
|
+
.catch(() => {
|
|
114
96
|
/* noop */
|
|
115
97
|
});
|
|
116
98
|
}
|
|
117
99
|
catch (_error) {
|
|
118
100
|
/* noop */
|
|
119
101
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
}());
|
|
102
|
+
}
|
|
103
|
+
}
|
|
123
104
|
exports.ErrorBoundary = ErrorBoundary;
|
|
124
105
|
function _getDescription(obj) {
|
|
125
106
|
try {
|
|
@@ -129,3 +110,14 @@ function _getDescription(obj) {
|
|
|
129
110
|
return '[Statsig] Failed to get string for error.';
|
|
130
111
|
}
|
|
131
112
|
}
|
|
113
|
+
function _getAllInstanceMethodNames(instance) {
|
|
114
|
+
const names = new Set();
|
|
115
|
+
let proto = Object.getPrototypeOf(instance);
|
|
116
|
+
while (proto && proto !== Object.prototype) {
|
|
117
|
+
Object.getOwnPropertyNames(proto)
|
|
118
|
+
.filter((prop) => typeof (proto === null || proto === void 0 ? void 0 : proto[prop]) === 'function')
|
|
119
|
+
.forEach((name) => names.add(name));
|
|
120
|
+
proto = Object.getPrototypeOf(proto);
|
|
121
|
+
}
|
|
122
|
+
return Array.from(names);
|
|
123
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type EvaluationOptionsCommon = {
|
|
2
|
+
/**
|
|
3
|
+
* Prevents an exposure log being created for this check.
|
|
4
|
+
*
|
|
5
|
+
* default: `false`
|
|
6
|
+
*/
|
|
7
|
+
disableExposureLog?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type FeatureGateEvaluationOptions = EvaluationOptionsCommon & {};
|
|
10
|
+
export type DynamicConfigEvaluationOptions = EvaluationOptionsCommon & {};
|
|
11
|
+
export type ExperimentEvaluationOptions = EvaluationOptionsCommon & {
|
|
12
|
+
/**
|
|
13
|
+
* Provide a map of values to be used across checks
|
|
14
|
+
*
|
|
15
|
+
* @requires {@link @statsig/js-user-persisted-storage}
|
|
16
|
+
* @see {@link https://docs.statsig.com/client/concepts/persistent_assignment#example-usage}
|
|
17
|
+
*/
|
|
18
|
+
userPersistedValues?: unknown;
|
|
19
|
+
};
|
|
20
|
+
export type LayerEvaluationOptions = EvaluationOptionsCommon & {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Flatten } from './UtitlityTypes';
|
|
2
|
+
type EvaluationBase<T> = {
|
|
3
|
+
id_type: string;
|
|
4
|
+
name: string;
|
|
5
|
+
rule_id: string;
|
|
6
|
+
secondary_exposures: SecondaryExposure[];
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
export type SecondaryExposure = {
|
|
10
|
+
gate: string;
|
|
11
|
+
gateValue: string;
|
|
12
|
+
ruleID: string;
|
|
13
|
+
};
|
|
14
|
+
export type GateEvaluation = EvaluationBase<boolean>;
|
|
15
|
+
export type ExperimentEvaluation = Flatten<EvaluationBase<Record<string, unknown>> & {
|
|
16
|
+
group_name?: string;
|
|
17
|
+
group: string;
|
|
18
|
+
id_type: string;
|
|
19
|
+
is_device_based: boolean;
|
|
20
|
+
is_experiment_active?: boolean;
|
|
21
|
+
is_user_in_experiment?: boolean;
|
|
22
|
+
}>;
|
|
23
|
+
export type DynamicConfigEvaluation = ExperimentEvaluation;
|
|
24
|
+
export type LayerEvaluation = Flatten<Omit<ExperimentEvaluation, 'id_type'> & {
|
|
25
|
+
allocated_experiment_name: string;
|
|
26
|
+
explicit_parameters: string[];
|
|
27
|
+
undelegated_secondary_exposures?: SecondaryExposure[];
|
|
28
|
+
}>;
|
|
29
|
+
export type AnyEvaluation = GateEvaluation | ExperimentEvaluation | DynamicConfigEvaluation | LayerEvaluation;
|
|
30
|
+
export type EvaluationDetails = {
|
|
31
|
+
reason: string;
|
|
32
|
+
lcut?: number;
|
|
33
|
+
receivedAt?: number;
|
|
34
|
+
};
|
|
35
|
+
export type DetailedEvaluation<T extends AnyEvaluation> = {
|
|
36
|
+
evaluation: T | null;
|
|
37
|
+
details: EvaluationDetails;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
package/src/EventLogger.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { NetworkCore } from './NetworkCore';
|
|
2
2
|
import { StatsigClientEmitEventFunc } from './StatsigClientBase';
|
|
3
3
|
import { StatsigEventInternal } from './StatsigEvent';
|
|
4
|
-
import { StatsigOptionsCommon } from './StatsigOptionsCommon';
|
|
5
|
-
import { Visibility } from './VisibilityChangeObserver';
|
|
4
|
+
import { NetworkConfigCommon, StatsigOptionsCommon } from './StatsigOptionsCommon';
|
|
6
5
|
export declare class EventLogger {
|
|
7
6
|
private _sdkKey;
|
|
8
7
|
private _emitter;
|
|
@@ -10,22 +9,34 @@ export declare class EventLogger {
|
|
|
10
9
|
private _options;
|
|
11
10
|
private _queue;
|
|
12
11
|
private _flushTimer;
|
|
13
|
-
private
|
|
12
|
+
private _lastExposureTimeMap;
|
|
13
|
+
private _nonExposedChecks;
|
|
14
14
|
private _maxQueueSize;
|
|
15
|
-
private
|
|
16
|
-
|
|
15
|
+
private _hasRunQuickFlush;
|
|
16
|
+
private _creationTime;
|
|
17
|
+
private _isLoggingDisabled;
|
|
18
|
+
private _logEventUrl;
|
|
19
|
+
private _logEventBeaconUrl;
|
|
20
|
+
constructor(_sdkKey: string, _emitter: StatsigClientEmitEventFunc, _network: NetworkCore, _options: StatsigOptionsCommon<NetworkConfigCommon> | null);
|
|
21
|
+
setLoggingDisabled(isDisabled: boolean): void;
|
|
17
22
|
enqueue(event: StatsigEventInternal): void;
|
|
23
|
+
incrementNonExposureCount(name: string): void;
|
|
18
24
|
reset(): void;
|
|
19
|
-
onVisibilityChanged(visibility: Visibility): void;
|
|
20
25
|
shutdown(): Promise<void>;
|
|
26
|
+
flush(): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* We 'Quick Flush' following the very first event enqueued
|
|
29
|
+
* within the quick flush window
|
|
30
|
+
*/
|
|
31
|
+
private _quickFlushIfNeeded;
|
|
21
32
|
private _shouldLogEvent;
|
|
22
|
-
private _flushAndForget;
|
|
23
|
-
private _flush;
|
|
24
33
|
private _sendEvents;
|
|
25
34
|
private _sendEventsViaPost;
|
|
26
35
|
private _sendEventsViaBeacon;
|
|
27
|
-
private _isBeaconSupported;
|
|
28
36
|
private _saveFailedLogsToStorage;
|
|
29
37
|
private _retryFailedLogs;
|
|
30
38
|
private _getStorageKey;
|
|
39
|
+
private _normalizeAndAppendEvent;
|
|
40
|
+
private _appendAndResetNonExposedChecks;
|
|
41
|
+
private _getCurrentPageUrl;
|
|
31
42
|
}
|