@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/StatsigTypes.js
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeLayer = exports.makeDynamicConfig = exports.makeFeatureGate = void 0;
|
|
4
|
-
var DEFAULT_RULE = 'default';
|
|
5
|
-
function makeFeatureGate(name, source, ruleID, value) {
|
|
6
|
-
return {
|
|
7
|
-
name: name,
|
|
8
|
-
source: source,
|
|
9
|
-
ruleID: ruleID !== null && ruleID !== void 0 ? ruleID : DEFAULT_RULE,
|
|
10
|
-
value: value === true,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.makeFeatureGate = makeFeatureGate;
|
|
14
|
-
function makeDynamicConfig(name, source, ruleID, value) {
|
|
15
|
-
return {
|
|
16
|
-
name: name,
|
|
17
|
-
source: source,
|
|
18
|
-
ruleID: ruleID !== null && ruleID !== void 0 ? ruleID : DEFAULT_RULE,
|
|
19
|
-
value: value !== null && value !== void 0 ? value : {},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
exports.makeDynamicConfig = makeDynamicConfig;
|
|
23
|
-
function makeLayer(name, source, ruleID, getValue) {
|
|
24
|
-
return {
|
|
25
|
-
name: name,
|
|
26
|
-
source: source,
|
|
27
|
-
getValue: getValue !== null && getValue !== void 0 ? getValue : (function () { return undefined; }),
|
|
28
|
-
ruleID: ruleID !== null && ruleID !== void 0 ? ruleID : DEFAULT_RULE,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
exports.makeLayer = makeLayer;
|
package/src/StatsigUser.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { StatsigEnvironment } from './StatsigOptionsCommon';
|
|
2
2
|
type StatsigUserPrimitives = string | number | boolean | Array<string> | undefined;
|
|
3
|
-
export type StatsigUser =
|
|
4
|
-
userID: string;
|
|
5
|
-
} | {
|
|
6
|
-
customIDs: Record<string, string>;
|
|
7
|
-
}) & {
|
|
3
|
+
export type StatsigUser = {
|
|
8
4
|
userID?: string;
|
|
9
5
|
customIDs?: Record<string, string>;
|
|
10
6
|
email?: string;
|
|
@@ -21,4 +17,5 @@ export type StatsigUserInternal = StatsigUser & {
|
|
|
21
17
|
};
|
|
22
18
|
export declare function normalizeUser(original: StatsigUser, environment?: StatsigEnvironment): StatsigUser;
|
|
23
19
|
export declare function getUserStorageKey(sdkKey: string, user?: StatsigUser): string;
|
|
20
|
+
export declare function getUnitIDFromUser(user: StatsigUser, idType: string): string | undefined;
|
|
24
21
|
export {};
|
package/src/StatsigUser.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getUserStorageKey = exports.normalizeUser = void 0;
|
|
4
|
-
|
|
3
|
+
exports.getUnitIDFromUser = exports.getUserStorageKey = exports.normalizeUser = void 0;
|
|
4
|
+
const Hashing_1 = require("./Hashing");
|
|
5
5
|
function normalizeUser(original, environment) {
|
|
6
6
|
try {
|
|
7
|
-
|
|
7
|
+
const copy = JSON.parse(JSON.stringify(original));
|
|
8
8
|
if (environment != null) {
|
|
9
9
|
copy.statsigEnvironment = environment;
|
|
10
10
|
}
|
|
@@ -16,22 +16,14 @@ function normalizeUser(original, environment) {
|
|
|
16
16
|
}
|
|
17
17
|
exports.normalizeUser = normalizeUser;
|
|
18
18
|
function getUserStorageKey(sdkKey, user) {
|
|
19
|
-
|
|
20
|
-
return "statsig.user_cache.".concat(key);
|
|
19
|
+
return (0, Hashing_1.DJB2Object)({ sdkKey, user });
|
|
21
20
|
}
|
|
22
21
|
exports.getUserStorageKey = getUserStorageKey;
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
function getUnitIDFromUser(user, idType) {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
if (typeof idType === 'string' && idType.toLowerCase() !== 'userid') {
|
|
25
|
+
return (_b = (_a = user.customIDs) === null || _a === void 0 ? void 0 : _a[idType]) !== null && _b !== void 0 ? _b : (_c = user === null || user === void 0 ? void 0 : user.customIDs) === null || _c === void 0 ? void 0 : _c[idType.toLowerCase()];
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
var sortedObject = {};
|
|
29
|
-
keys.forEach(function (key) {
|
|
30
|
-
var value = object[key];
|
|
31
|
-
if (value instanceof Object) {
|
|
32
|
-
value = _getSortedObject(value);
|
|
33
|
-
}
|
|
34
|
-
sortedObject[key] = value;
|
|
35
|
-
});
|
|
36
|
-
return sortedObject;
|
|
27
|
+
return user.userID;
|
|
37
28
|
}
|
|
29
|
+
exports.getUnitIDFromUser = getUnitIDFromUser;
|
package/src/StorageProvider.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
type StorageProvider = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export type StorageProvider = {
|
|
2
|
+
_getProviderName: () => string;
|
|
3
|
+
_getItem: (key: string) => Promise<string | null>;
|
|
4
|
+
_setItem: (key: string, value: string) => Promise<void>;
|
|
5
|
+
_removeItem: (key: string) => Promise<void>;
|
|
6
|
+
_getAllKeys: () => Promise<readonly string[]>;
|
|
7
|
+
_getItemSync?: (key: string) => string | null;
|
|
5
8
|
};
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
type StorageProviderManagment = {
|
|
10
|
+
_setProvider: (newProvider: StorageProvider) => void;
|
|
11
|
+
_setDisabled: (isDisabled: boolean) => void;
|
|
8
12
|
};
|
|
9
|
-
export declare
|
|
10
|
-
export declare function
|
|
13
|
+
export declare const Storage: StorageProvider & StorageProviderManagment;
|
|
14
|
+
export declare function _getObjectFromStorage<T>(key: string): Promise<T | null>;
|
|
15
|
+
export declare function _setObjectInStorage(key: string, obj: unknown): Promise<void>;
|
|
11
16
|
export {};
|
package/src/StorageProvider.js
CHANGED
|
@@ -8,103 +8,107 @@ 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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
12
|
+
exports._setObjectInStorage = exports._getObjectFromStorage = exports.Storage = void 0;
|
|
13
|
+
const Log_1 = require("./Log");
|
|
14
|
+
const inMemoryStore = {};
|
|
15
|
+
const _resolve = (input) => Promise.resolve(input);
|
|
16
|
+
const _inMemoryProvider = {
|
|
17
|
+
_getProviderName: () => 'InMemory',
|
|
18
|
+
_getItemSync(key) {
|
|
19
|
+
var _a;
|
|
20
|
+
return (_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null;
|
|
21
|
+
},
|
|
22
|
+
_getItem(key) {
|
|
44
23
|
var _a;
|
|
45
|
-
return
|
|
24
|
+
return _resolve((_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null);
|
|
46
25
|
},
|
|
47
|
-
|
|
26
|
+
_setItem(key, value) {
|
|
48
27
|
inMemoryStore[key] = value;
|
|
49
|
-
return
|
|
28
|
+
return _resolve();
|
|
50
29
|
},
|
|
51
|
-
|
|
30
|
+
_removeItem(key) {
|
|
52
31
|
delete inMemoryStore[key];
|
|
53
|
-
return
|
|
32
|
+
return _resolve();
|
|
33
|
+
},
|
|
34
|
+
_getAllKeys() {
|
|
35
|
+
return _resolve(Object.keys(inMemoryStore));
|
|
54
36
|
},
|
|
55
37
|
};
|
|
38
|
+
let _localStorageProvider = null;
|
|
56
39
|
try {
|
|
57
40
|
if (typeof window !== 'undefined' && 'localStorage' in window) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
_localStorageProvider = {
|
|
42
|
+
_getProviderName: () => 'LocalStorage',
|
|
43
|
+
_getItemSync(key) {
|
|
44
|
+
return localStorage.getItem(key);
|
|
45
|
+
},
|
|
46
|
+
_getItem(key) {
|
|
47
|
+
return _resolve(localStorage.getItem(key));
|
|
61
48
|
},
|
|
62
|
-
|
|
49
|
+
_setItem(key, value) {
|
|
63
50
|
localStorage.setItem(key, value);
|
|
64
|
-
return
|
|
51
|
+
return _resolve();
|
|
65
52
|
},
|
|
66
|
-
|
|
53
|
+
_removeItem(key) {
|
|
67
54
|
localStorage.removeItem(key);
|
|
68
|
-
return
|
|
55
|
+
return _resolve();
|
|
56
|
+
},
|
|
57
|
+
_getAllKeys() {
|
|
58
|
+
const keys = Object.keys(localStorage);
|
|
59
|
+
return _resolve(keys);
|
|
69
60
|
},
|
|
70
61
|
};
|
|
71
62
|
}
|
|
72
63
|
}
|
|
73
64
|
catch (error) {
|
|
74
|
-
Log_1.Log.warn('Failed to
|
|
65
|
+
Log_1.Log.warn('Failed to setup localStorageProvider.');
|
|
66
|
+
}
|
|
67
|
+
let _main = _localStorageProvider !== null && _localStorageProvider !== void 0 ? _localStorageProvider : _inMemoryProvider;
|
|
68
|
+
let _current = _main;
|
|
69
|
+
function _inMemoryBreaker(get) {
|
|
70
|
+
try {
|
|
71
|
+
return get();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error instanceof Error && error.name === 'SecurityError') {
|
|
75
|
+
exports.Storage._setProvider(_inMemoryProvider);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
75
80
|
}
|
|
76
81
|
exports.Storage = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
_getProviderName: () => _current._getProviderName(),
|
|
83
|
+
_getItem: (key) => __awaiter(void 0, void 0, void 0, function* () { return _inMemoryBreaker(() => _current._getItem(key)); }),
|
|
84
|
+
_getItemSync: (key) => _inMemoryBreaker(() => { var _a, _b; return (_b = (_a = _current._getItemSync) === null || _a === void 0 ? void 0 : _a.call(_current, key)) !== null && _b !== void 0 ? _b : null; }),
|
|
85
|
+
_setItem: (key, value) => _current._setItem(key, value),
|
|
86
|
+
_removeItem: (key) => _current._removeItem(key),
|
|
87
|
+
_getAllKeys: () => _current._getAllKeys(),
|
|
88
|
+
// StorageProviderManagment
|
|
89
|
+
_setProvider: (newProvider) => {
|
|
90
|
+
_main = newProvider;
|
|
91
|
+
_current = newProvider;
|
|
92
|
+
},
|
|
93
|
+
_setDisabled: (isDisabled) => {
|
|
94
|
+
if (isDisabled) {
|
|
95
|
+
_current = _inMemoryProvider;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
_current = _main;
|
|
99
|
+
}
|
|
82
100
|
},
|
|
83
101
|
};
|
|
84
|
-
function
|
|
85
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
switch (_a.label) {
|
|
89
|
-
case 0: return [4 /*yield*/, provider.getItem(key)];
|
|
90
|
-
case 1:
|
|
91
|
-
value = _a.sent();
|
|
92
|
-
return [2 /*return*/, JSON.parse(value !== null && value !== void 0 ? value : 'null')];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
102
|
+
function _getObjectFromStorage(key) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const value = yield exports.Storage._getItem(key);
|
|
105
|
+
return JSON.parse(value !== null && value !== void 0 ? value : 'null');
|
|
95
106
|
});
|
|
96
107
|
}
|
|
97
|
-
exports.
|
|
98
|
-
function
|
|
99
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
-
|
|
101
|
-
switch (_a.label) {
|
|
102
|
-
case 0: return [4 /*yield*/, provider.setItem(key, JSON.stringify(obj))];
|
|
103
|
-
case 1:
|
|
104
|
-
_a.sent();
|
|
105
|
-
return [2 /*return*/];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
+
exports._getObjectFromStorage = _getObjectFromStorage;
|
|
109
|
+
function _setObjectInStorage(key, obj) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
yield exports.Storage._setItem(key, JSON.stringify(obj));
|
|
108
112
|
});
|
|
109
113
|
}
|
|
110
|
-
exports.
|
|
114
|
+
exports._setObjectInStorage = _setObjectInStorage;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {string} data The values to parse into T
|
|
4
|
+
* @param {string} guard A field that must exists on the parsed object for the parse to be valid
|
|
5
|
+
* @param {string} error An error to print via Log.error() when parsing fails
|
|
6
|
+
* @returns {T | null} The parse object T or null if it failed
|
|
7
|
+
*/
|
|
8
|
+
export declare function typedJsonParse<T>(data: string, guard: string, error: string): T | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typedJsonParse = void 0;
|
|
4
|
+
const Log_1 = require("./Log");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {string} data The values to parse into T
|
|
8
|
+
* @param {string} guard A field that must exists on the parsed object for the parse to be valid
|
|
9
|
+
* @param {string} error An error to print via Log.error() when parsing fails
|
|
10
|
+
* @returns {T | null} The parse object T or null if it failed
|
|
11
|
+
*/
|
|
12
|
+
function typedJsonParse(data, guard, error) {
|
|
13
|
+
try {
|
|
14
|
+
const result = JSON.parse(data);
|
|
15
|
+
if (typeof result === 'object' &&
|
|
16
|
+
guard in result) {
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
catch (_a) {
|
|
22
|
+
// noop
|
|
23
|
+
}
|
|
24
|
+
Log_1.Log.error(error);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
exports.typedJsonParse = typedJsonParse;
|
package/src/UUID.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUUID = void 0;
|
|
4
4
|
function getUUID() {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (typeof crypto !== 'undefined' &&
|
|
6
|
+
typeof crypto.randomUUID === 'function') {
|
|
7
|
+
return crypto.randomUUID();
|
|
8
|
+
}
|
|
9
|
+
let d = new Date().getTime();
|
|
10
|
+
let d2 = (typeof performance !== 'undefined' &&
|
|
7
11
|
performance.now &&
|
|
8
12
|
performance.now() * 1000) ||
|
|
9
13
|
0;
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
|
|
14
|
+
const y = '89ab'[Math.floor(Math.random() * 4)];
|
|
15
|
+
return `xxxxxxxx-xxxx-4xxx-${y}xxx-xxxxxxxxxxxx`.replace(/[xy]/g, (c) => {
|
|
16
|
+
let r = Math.random() * 16;
|
|
13
17
|
if (d > 0) {
|
|
14
18
|
r = (d + r) % 16 | 0;
|
|
15
19
|
d = Math.floor(d / 16);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function _getOverridableUrl(overrideUrl: string | undefined, overrideApi: string | undefined, defaultEndpoint: string, defaultApi: string): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._getOverridableUrl = void 0;
|
|
4
|
+
function _getOverridableUrl(overrideUrl, overrideApi, defaultEndpoint, defaultApi) {
|
|
5
|
+
if (overrideUrl) {
|
|
6
|
+
return overrideUrl;
|
|
7
|
+
}
|
|
8
|
+
else if (overrideApi) {
|
|
9
|
+
return `${overrideApi}${defaultEndpoint}`;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
return `${defaultApi}${defaultEndpoint}`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports._getOverridableUrl = _getOverridableUrl;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const FOREGROUND = "foreground";
|
|
2
|
+
declare const BACKGROUND = "background";
|
|
3
|
+
export type Visibility = typeof FOREGROUND | typeof BACKGROUND;
|
|
4
|
+
type VisibilityChangedCallback = (visibility: Visibility) => void;
|
|
5
|
+
export declare const _isCurrentlyVisible: () => boolean;
|
|
6
|
+
export declare const _subscribeToVisiblityChanged: (listener: VisibilityChangedCallback) => void;
|
|
7
|
+
export declare const _notifyVisibilityChanged: (visibility: Visibility) => void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._notifyVisibilityChanged = exports._subscribeToVisiblityChanged = exports._isCurrentlyVisible = void 0;
|
|
4
|
+
const SafeJs_1 = require("./SafeJs");
|
|
5
|
+
const FOREGROUND = 'foreground';
|
|
6
|
+
const BACKGROUND = 'background';
|
|
7
|
+
const LISTENERS = [];
|
|
8
|
+
let current = FOREGROUND;
|
|
9
|
+
const _isCurrentlyVisible = () => {
|
|
10
|
+
return current === FOREGROUND;
|
|
11
|
+
};
|
|
12
|
+
exports._isCurrentlyVisible = _isCurrentlyVisible;
|
|
13
|
+
const _subscribeToVisiblityChanged = (listener) => {
|
|
14
|
+
LISTENERS.unshift(listener);
|
|
15
|
+
};
|
|
16
|
+
exports._subscribeToVisiblityChanged = _subscribeToVisiblityChanged;
|
|
17
|
+
const _notifyVisibilityChanged = (visibility) => {
|
|
18
|
+
if (visibility === current) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
current = visibility;
|
|
22
|
+
LISTENERS.forEach((l) => l(visibility));
|
|
23
|
+
};
|
|
24
|
+
exports._notifyVisibilityChanged = _notifyVisibilityChanged;
|
|
25
|
+
(0, SafeJs_1._addWindowEventListenerSafe)('focus', () => (0, exports._notifyVisibilityChanged)(FOREGROUND));
|
|
26
|
+
(0, SafeJs_1._addWindowEventListenerSafe)('blur', () => (0, exports._notifyVisibilityChanged)(BACKGROUND));
|
|
27
|
+
(0, SafeJs_1._addWindowEventListenerSafe)('beforeunload', () => (0, exports._notifyVisibilityChanged)(BACKGROUND));
|
|
28
|
+
(0, SafeJs_1._addDocumentEventListenerSafe)('visibilitychange', () => {
|
|
29
|
+
(0, exports._notifyVisibilityChanged)(document.visibilityState === 'visible' ? FOREGROUND : BACKGROUND);
|
|
30
|
+
});
|
package/src/index.d.ts
CHANGED
|
@@ -1,23 +1,38 @@
|
|
|
1
1
|
/** Statsig Global should go first */
|
|
2
2
|
import './$_StatsigGlobal';
|
|
3
3
|
import { EventLogger } from './EventLogger';
|
|
4
|
+
import { Log } from './Log';
|
|
5
|
+
import { Storage } from './StorageProvider';
|
|
4
6
|
export * from './$_StatsigGlobal';
|
|
5
7
|
export * from './ClientInterfaces';
|
|
8
|
+
export * from './DataAdapterCore';
|
|
9
|
+
export * from './DownloadConfigSpecsResponse';
|
|
6
10
|
export * from './ErrorBoundary';
|
|
11
|
+
export * from './EvaluationOptions';
|
|
12
|
+
export * from './EvaluationTypes';
|
|
7
13
|
export * from './Hashing';
|
|
8
|
-
export * from './
|
|
14
|
+
export * from './InitializeResponse';
|
|
9
15
|
export * from './Log';
|
|
10
|
-
export * from './Monitoring';
|
|
11
16
|
export * from './NetworkCore';
|
|
17
|
+
export * from './NetworkConfig';
|
|
18
|
+
export * from './OverrideAdapter';
|
|
19
|
+
export * from './SafeJs';
|
|
20
|
+
export * from './SDKType';
|
|
21
|
+
export * from './SessionID';
|
|
12
22
|
export * from './StableID';
|
|
13
23
|
export * from './StatsigClientBase';
|
|
14
24
|
export * from './StatsigClientEventEmitter';
|
|
15
|
-
export * from './
|
|
25
|
+
export * from './StatsigDataAdapter';
|
|
16
26
|
export * from './StatsigEvent';
|
|
17
27
|
export * from './StatsigMetadata';
|
|
18
28
|
export * from './StatsigOptionsCommon';
|
|
29
|
+
export * from './StatsigTypeFactories';
|
|
19
30
|
export * from './StatsigTypes';
|
|
20
31
|
export * from './StatsigUser';
|
|
32
|
+
export * from './StorageProvider';
|
|
33
|
+
export * from './TypedJsonParse';
|
|
34
|
+
export * from './UrlOverrides';
|
|
35
|
+
export * from './UtitlityTypes';
|
|
21
36
|
export * from './UUID';
|
|
22
|
-
export * from './
|
|
23
|
-
export { EventLogger };
|
|
37
|
+
export * from './VisibilityObserving';
|
|
38
|
+
export { EventLogger, Storage, Log };
|
package/src/index.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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -25,28 +14,51 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
25
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
15
|
};
|
|
27
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.EventLogger = void 0;
|
|
17
|
+
exports.Log = exports.Storage = exports.EventLogger = void 0;
|
|
29
18
|
/** Statsig Global should go first */
|
|
30
19
|
require("./$_StatsigGlobal");
|
|
31
|
-
|
|
20
|
+
const EventLogger_1 = require("./EventLogger");
|
|
32
21
|
Object.defineProperty(exports, "EventLogger", { enumerable: true, get: function () { return EventLogger_1.EventLogger; } });
|
|
22
|
+
const Log_1 = require("./Log");
|
|
23
|
+
Object.defineProperty(exports, "Log", { enumerable: true, get: function () { return Log_1.Log; } });
|
|
24
|
+
const StatsigMetadata_1 = require("./StatsigMetadata");
|
|
25
|
+
const StorageProvider_1 = require("./StorageProvider");
|
|
26
|
+
Object.defineProperty(exports, "Storage", { enumerable: true, get: function () { return StorageProvider_1.Storage; } });
|
|
27
|
+
const UUID_1 = require("./UUID");
|
|
33
28
|
__exportStar(require("./$_StatsigGlobal"), exports);
|
|
34
29
|
__exportStar(require("./ClientInterfaces"), exports);
|
|
30
|
+
__exportStar(require("./DataAdapterCore"), exports);
|
|
31
|
+
__exportStar(require("./DownloadConfigSpecsResponse"), exports);
|
|
35
32
|
__exportStar(require("./ErrorBoundary"), exports);
|
|
33
|
+
__exportStar(require("./EvaluationOptions"), exports);
|
|
34
|
+
__exportStar(require("./EvaluationTypes"), exports);
|
|
36
35
|
__exportStar(require("./Hashing"), exports);
|
|
37
|
-
__exportStar(require("./
|
|
36
|
+
__exportStar(require("./InitializeResponse"), exports);
|
|
38
37
|
__exportStar(require("./Log"), exports);
|
|
39
|
-
__exportStar(require("./Monitoring"), exports);
|
|
40
38
|
__exportStar(require("./NetworkCore"), exports);
|
|
39
|
+
__exportStar(require("./NetworkConfig"), exports);
|
|
40
|
+
__exportStar(require("./OverrideAdapter"), exports);
|
|
41
|
+
__exportStar(require("./SafeJs"), exports);
|
|
42
|
+
__exportStar(require("./SDKType"), exports);
|
|
43
|
+
__exportStar(require("./SessionID"), exports);
|
|
41
44
|
__exportStar(require("./StableID"), exports);
|
|
42
45
|
__exportStar(require("./StatsigClientBase"), exports);
|
|
43
46
|
__exportStar(require("./StatsigClientEventEmitter"), exports);
|
|
44
|
-
__exportStar(require("./
|
|
47
|
+
__exportStar(require("./StatsigDataAdapter"), exports);
|
|
45
48
|
__exportStar(require("./StatsigEvent"), exports);
|
|
46
49
|
__exportStar(require("./StatsigMetadata"), exports);
|
|
47
50
|
__exportStar(require("./StatsigOptionsCommon"), exports);
|
|
51
|
+
__exportStar(require("./StatsigTypeFactories"), exports);
|
|
48
52
|
__exportStar(require("./StatsigTypes"), exports);
|
|
49
53
|
__exportStar(require("./StatsigUser"), exports);
|
|
54
|
+
__exportStar(require("./StorageProvider"), exports);
|
|
55
|
+
__exportStar(require("./TypedJsonParse"), exports);
|
|
56
|
+
__exportStar(require("./UrlOverrides"), exports);
|
|
57
|
+
__exportStar(require("./UtitlityTypes"), exports);
|
|
50
58
|
__exportStar(require("./UUID"), exports);
|
|
51
|
-
__exportStar(require("./
|
|
52
|
-
__STATSIG__ =
|
|
59
|
+
__exportStar(require("./VisibilityObserving"), exports);
|
|
60
|
+
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { EventLogger: EventLogger_1.EventLogger,
|
|
61
|
+
Log: Log_1.Log,
|
|
62
|
+
getUUID: UUID_1.getUUID,
|
|
63
|
+
Storage: StorageProvider_1.Storage,
|
|
64
|
+
SDK_VERSION: StatsigMetadata_1.SDK_VERSION });
|
package/src/Monitoring.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { ErrorBoundary } from './ErrorBoundary';
|
|
2
|
-
export declare function monitorClass<T extends new (...args: any[]) => any>(errorBoundary: ErrorBoundary, target: T, instance: unknown): void;
|
|
3
|
-
export declare function monitorFunction<T>(errorBoundary: ErrorBoundary, tag: string, func: () => T, instance: unknown): T;
|
package/src/Monitoring.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.monitorFunction = exports.monitorClass = void 0;
|
|
4
|
-
var Diagnostics_1 = require("./Diagnostics");
|
|
5
|
-
var StatsigClientBase_1 = require("./StatsigClientBase");
|
|
6
|
-
function monitorClass(errorBoundary, target, instance) {
|
|
7
|
-
var methods = Object.getOwnPropertyNames(target.prototype);
|
|
8
|
-
var obj = instance;
|
|
9
|
-
var _loop_1 = function (method) {
|
|
10
|
-
if (method === 'constructor' || typeof obj[method] !== 'function') {
|
|
11
|
-
return "continue";
|
|
12
|
-
}
|
|
13
|
-
var original = obj[method];
|
|
14
|
-
obj[method] = function () {
|
|
15
|
-
var _this = this;
|
|
16
|
-
var args = [];
|
|
17
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18
|
-
args[_i] = arguments[_i];
|
|
19
|
-
}
|
|
20
|
-
return monitorFunction(errorBoundary, method, function () { return original.apply(_this, args); }, instance);
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
for (var _i = 0, methods_1 = methods; _i < methods_1.length; _i++) {
|
|
24
|
-
var method = methods_1[_i];
|
|
25
|
-
_loop_1(method);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.monitorClass = monitorClass;
|
|
29
|
-
function monitorFunction(errorBoundary, tag, func, instance) {
|
|
30
|
-
var client = instance instanceof StatsigClientBase_1.StatsigClientBase ? instance['emit'] : undefined;
|
|
31
|
-
return errorBoundary.capture(tag, function () { return (0, Diagnostics_1.captureDiagnostics)(tag, function () { return func.apply(instance); }); }, client);
|
|
32
|
-
}
|
|
33
|
-
exports.monitorFunction = monitorFunction;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { StatsigUser } from './StatsigUser';
|
|
2
|
-
export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'Bootstrap' | 'Prefetch';
|
|
3
|
-
export type StatsigDataProvider = {
|
|
4
|
-
readonly getData?: (sdkKey: string, user?: StatsigUser) => string | null;
|
|
5
|
-
readonly getDataAsync?: (sdkKey: string, user?: StatsigUser) => Promise<string | null>;
|
|
6
|
-
readonly getDataPostInit?: (sdkKey: string, currentData: string | null, user?: StatsigUser) => Promise<string | null>;
|
|
7
|
-
readonly setDataPostInit?: (sdkKey: string, data: string, user?: StatsigUser) => Promise<void>;
|
|
8
|
-
readonly source: DataSource;
|
|
9
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type Visibility = 'foreground' | 'background';
|
|
2
|
-
type VisibilityChangeListener = {
|
|
3
|
-
onVisibilityChanged: (visibility: Visibility) => void;
|
|
4
|
-
};
|
|
5
|
-
export declare class VisibilityChangeObserver {
|
|
6
|
-
private static _listeners;
|
|
7
|
-
private static _current;
|
|
8
|
-
static isCurrentlyVisible(): boolean;
|
|
9
|
-
static add(listener: VisibilityChangeListener): void;
|
|
10
|
-
static remove(listener: VisibilityChangeListener): void;
|
|
11
|
-
static notify(visibility: Visibility): void;
|
|
12
|
-
}
|
|
13
|
-
export {};
|