@statsig/client-core 1.3.0 → 1.4.0
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 +2 -2
- package/src/ClientInterfaces.d.ts +1 -1
- package/src/EvaluationTypes.d.ts +1 -1
- package/src/EventLogger.js +1 -1
- package/src/Hashing.d.ts +2 -1
- package/src/Hashing.js +11 -8
- package/src/NetworkCore.d.ts +1 -1
- package/src/SafeJs.d.ts +1 -1
- package/src/SafeJs.js +11 -4
- package/src/StatsigClientBase.js +1 -1
- package/src/StatsigClientEventEmitter.d.ts +1 -1
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +1 -1
- package/src/StatsigTypeFactories.d.ts +0 -4
- package/src/StatsigTypeFactories.js +3 -11
- package/src/StatsigTypes.d.ts +1 -1
- package/src/TypingUtils.d.ts +7 -0
- package/src/TypingUtils.js +12 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/UtitlityTypes.d.ts +0 -3
- package/src/UtitlityTypes.js +0 -2
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ import { StatsigEvent } from './StatsigEvent';
|
|
|
9
9
|
import { AnyStatsigOptions, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
|
|
10
10
|
import { DynamicConfig, Experiment, FeatureGate, Layer, ParameterStore } from './StatsigTypes';
|
|
11
11
|
import { StatsigUser } from './StatsigUser';
|
|
12
|
-
import { Flatten } from './
|
|
12
|
+
import { Flatten } from './TypingUtils';
|
|
13
13
|
export interface StatsigClientCommonInterface extends StatsigClientEventEmitterInterface {
|
|
14
14
|
initializeSync(): void;
|
|
15
15
|
initializeAsync(): Promise<void>;
|
package/src/EvaluationTypes.d.ts
CHANGED
package/src/EventLogger.js
CHANGED
|
@@ -256,7 +256,7 @@ class EventLogger {
|
|
|
256
256
|
}
|
|
257
257
|
_startBackgroundFlushInterval() {
|
|
258
258
|
var _a, _b;
|
|
259
|
-
if (
|
|
259
|
+
if ((0, SafeJs_1._isServerEnv)()) {
|
|
260
260
|
return; // do not run in server environments
|
|
261
261
|
}
|
|
262
262
|
const flushInterval = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.loggingIntervalMs) !== null && _b !== void 0 ? _b : DEFAULT_FLUSH_INTERVAL_MS;
|
package/src/Hashing.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const _DJB2: (value: string) => string;
|
|
2
|
-
export declare const _DJB2Object: (value: Record<string, unknown> | null) => string;
|
|
2
|
+
export declare const _DJB2Object: (value: Record<string, unknown> | null, maxLevels?: number) => string;
|
|
3
|
+
export declare const _getSortedObject: (object: Record<string, unknown> | null, maxDepth: number | undefined) => Record<string, unknown> | null;
|
package/src/Hashing.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._DJB2Object = exports._DJB2 = void 0;
|
|
3
|
+
exports._getSortedObject = exports._DJB2Object = exports._DJB2 = void 0;
|
|
4
|
+
const TypingUtils_1 = require("./TypingUtils");
|
|
4
5
|
const _DJB2 = (value) => {
|
|
5
6
|
let hash = 0;
|
|
6
7
|
for (let i = 0; i < value.length; i++) {
|
|
@@ -11,22 +12,24 @@ const _DJB2 = (value) => {
|
|
|
11
12
|
return String(hash >>> 0);
|
|
12
13
|
};
|
|
13
14
|
exports._DJB2 = _DJB2;
|
|
14
|
-
const _DJB2Object = (value) => {
|
|
15
|
-
return (0, exports._DJB2)(JSON.stringify(_getSortedObject(value)));
|
|
15
|
+
const _DJB2Object = (value, maxLevels) => {
|
|
16
|
+
return (0, exports._DJB2)(JSON.stringify((0, exports._getSortedObject)(value, maxLevels)));
|
|
16
17
|
};
|
|
17
18
|
exports._DJB2Object = _DJB2Object;
|
|
18
|
-
const _getSortedObject = (object) => {
|
|
19
|
+
const _getSortedObject = (object, maxDepth) => {
|
|
19
20
|
if (object == null) {
|
|
20
21
|
return null;
|
|
21
22
|
}
|
|
22
23
|
const keys = Object.keys(object).sort();
|
|
23
24
|
const sortedObject = {};
|
|
24
25
|
keys.forEach((key) => {
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
const value = object[key];
|
|
27
|
+
if (maxDepth === 0 || (0, TypingUtils_1._typeOf)(value) !== 'object') {
|
|
28
|
+
sortedObject[key] = value;
|
|
29
|
+
return;
|
|
28
30
|
}
|
|
29
|
-
sortedObject[key] = value;
|
|
31
|
+
sortedObject[key] = (0, exports._getSortedObject)(value, maxDepth != null ? maxDepth - 1 : maxDepth);
|
|
30
32
|
});
|
|
31
33
|
return sortedObject;
|
|
32
34
|
};
|
|
35
|
+
exports._getSortedObject = _getSortedObject;
|
package/src/NetworkCore.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import './$_StatsigGlobal';
|
|
|
2
2
|
import { NetworkPriority } from './NetworkConfig';
|
|
3
3
|
import { StatsigClientEmitEventFunc } from './StatsigClientBase';
|
|
4
4
|
import { AnyStatsigOptions } from './StatsigOptionsCommon';
|
|
5
|
-
import { Flatten } from './
|
|
5
|
+
import { Flatten } from './TypingUtils';
|
|
6
6
|
type RequestArgs = {
|
|
7
7
|
sdkKey: string;
|
|
8
8
|
url: string;
|
package/src/SafeJs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const _getWindowSafe: () => Window | null;
|
|
2
2
|
export declare const _getDocumentSafe: () => Document | null;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const _isServerEnv: () => boolean;
|
|
4
4
|
export declare const _addWindowEventListenerSafe: (key: string, listener: () => void) => void;
|
|
5
5
|
export declare const _addDocumentEventListenerSafe: (key: string, listener: () => void) => void;
|
|
6
6
|
export declare const _getCurrentPageUrlSafe: () => string | undefined;
|
package/src/SafeJs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._getCurrentPageUrlSafe = exports._addDocumentEventListenerSafe = exports._addWindowEventListenerSafe = exports.
|
|
3
|
+
exports._getCurrentPageUrlSafe = exports._addDocumentEventListenerSafe = exports._addWindowEventListenerSafe = exports._isServerEnv = exports._getDocumentSafe = exports._getWindowSafe = void 0;
|
|
4
4
|
const _getWindowSafe = () => {
|
|
5
5
|
return typeof window !== 'undefined' ? window : null;
|
|
6
6
|
};
|
|
@@ -11,10 +11,17 @@ const _getDocumentSafe = () => {
|
|
|
11
11
|
return (_a = win === null || win === void 0 ? void 0 : win.document) !== null && _a !== void 0 ? _a : null;
|
|
12
12
|
};
|
|
13
13
|
exports._getDocumentSafe = _getDocumentSafe;
|
|
14
|
-
const
|
|
15
|
-
|
|
14
|
+
const _isServerEnv = () => {
|
|
15
|
+
if ((0, exports._getDocumentSafe)() !== null) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
const isNode = typeof process !== 'undefined' &&
|
|
19
|
+
process.versions != null &&
|
|
20
|
+
process.versions.node != null;
|
|
21
|
+
const isVercel = typeof EdgeRuntime === 'string';
|
|
22
|
+
return isVercel || isNode;
|
|
16
23
|
};
|
|
17
|
-
exports.
|
|
24
|
+
exports._isServerEnv = _isServerEnv;
|
|
18
25
|
const _addWindowEventListenerSafe = (key, listener) => {
|
|
19
26
|
const win = (0, exports._getWindowSafe)();
|
|
20
27
|
if (typeof (win === null || win === void 0 ? void 0 : win.addEventListener) === 'function') {
|
package/src/StatsigClientBase.js
CHANGED
|
@@ -37,7 +37,7 @@ class StatsigClientBase {
|
|
|
37
37
|
this._errorBoundary.wrap(network);
|
|
38
38
|
this._errorBoundary.wrap(adapter);
|
|
39
39
|
this._errorBoundary.wrap(this._logger);
|
|
40
|
-
if ((0, SafeJs_1.
|
|
40
|
+
if (!(0, SafeJs_1._isServerEnv)()) {
|
|
41
41
|
const statsigGlobal = (0, __StatsigGlobal_1._getStatsigGlobal)();
|
|
42
42
|
const instances = (_b = statsigGlobal.instances) !== null && _b !== void 0 ? _b : {};
|
|
43
43
|
const inst = this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DataAdapterResult } from './StatsigDataAdapter';
|
|
2
2
|
import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
|
|
3
|
-
import { Flatten } from './
|
|
3
|
+
import { Flatten } from './TypingUtils';
|
|
4
4
|
export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
5
5
|
type EventNameToEventDataMap = {
|
|
6
6
|
values_updated: {
|
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 = '1.
|
|
4
|
+
exports.SDK_VERSION = '1.4.0';
|
|
5
5
|
let metadata = {
|
|
6
6
|
sdkVersion: exports.SDK_VERSION,
|
|
7
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { DynamicConfigEvaluation, EvaluationDetails, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
|
|
2
2
|
import { AnyConfigBasedStatsigType, DynamicConfig, Experiment, FeatureGate, Layer, TypedGet } from './StatsigTypes';
|
|
3
|
-
type Primitive = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
|
|
4
3
|
export declare function _makeFeatureGate(name: string, details: EvaluationDetails, evaluation: GateEvaluation | null): FeatureGate;
|
|
5
4
|
export declare function _makeDynamicConfig(name: string, details: EvaluationDetails, evaluation: DynamicConfigEvaluation | null): DynamicConfig;
|
|
6
5
|
export declare function _makeExperiment(name: string, details: EvaluationDetails, evaluation: DynamicConfigEvaluation | null): Experiment;
|
|
7
6
|
export declare function _makeLayer(name: string, details: EvaluationDetails, evaluation: LayerEvaluation | null, exposeFunc?: (param: string) => void): Layer;
|
|
8
7
|
export declare function _mergeOverride<T extends AnyConfigBasedStatsigType>(original: T, overridden: T | null | undefined, value: Record<string, unknown>, exposeFunc?: (param: string) => void): T;
|
|
9
|
-
export declare function _typeOf(input: unknown): Primitive | 'array';
|
|
10
|
-
export declare function _isTypeMatch<T>(a: unknown, b: unknown): a is T;
|
|
11
8
|
export declare function _makeTypedGet(value: Record<string, unknown> | undefined, exposeFunc?: (param: string) => void): TypedGet;
|
|
12
|
-
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._makeTypedGet = exports.
|
|
3
|
+
exports._makeTypedGet = exports._mergeOverride = exports._makeLayer = exports._makeExperiment = exports._makeDynamicConfig = exports._makeFeatureGate = void 0;
|
|
4
|
+
const TypingUtils_1 = require("./TypingUtils");
|
|
4
5
|
const DEFAULT_RULE = 'default';
|
|
5
6
|
function _makeEvaluation(name, details, evaluation, value) {
|
|
6
7
|
var _a;
|
|
@@ -37,15 +38,6 @@ function _mergeOverride(original, overridden, value, exposeFunc) {
|
|
|
37
38
|
return Object.assign(Object.assign(Object.assign({}, original), overridden), { get: _makeTypedGet(value, exposeFunc) });
|
|
38
39
|
}
|
|
39
40
|
exports._mergeOverride = _mergeOverride;
|
|
40
|
-
function _typeOf(input) {
|
|
41
|
-
return Array.isArray(input) ? 'array' : typeof input;
|
|
42
|
-
}
|
|
43
|
-
exports._typeOf = _typeOf;
|
|
44
|
-
function _isTypeMatch(a, b) {
|
|
45
|
-
const typeOf = (x) => (Array.isArray(x) ? 'array' : typeof x);
|
|
46
|
-
return typeOf(a) === typeOf(b);
|
|
47
|
-
}
|
|
48
|
-
exports._isTypeMatch = _isTypeMatch;
|
|
49
41
|
function _makeTypedGet(value, exposeFunc) {
|
|
50
42
|
return (param, fallback) => {
|
|
51
43
|
var _a;
|
|
@@ -53,7 +45,7 @@ function _makeTypedGet(value, exposeFunc) {
|
|
|
53
45
|
if (found == null) {
|
|
54
46
|
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
55
47
|
}
|
|
56
|
-
if (fallback != null && !_isTypeMatch(found, fallback)) {
|
|
48
|
+
if (fallback != null && !(0, TypingUtils_1._isTypeMatch)(found, fallback)) {
|
|
57
49
|
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
58
50
|
}
|
|
59
51
|
exposeFunc === null || exposeFunc === void 0 ? void 0 : exposeFunc(param);
|
package/src/StatsigTypes.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EvaluationDetails, ExperimentEvaluation, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
|
|
2
2
|
import { ParamStoreConfig } from './ParamStoreTypes';
|
|
3
|
-
import { Flatten } from './
|
|
3
|
+
import { Flatten } from './TypingUtils';
|
|
4
4
|
export type TypedGet = <T = unknown>(key: string, fallback?: T) => TypedReturn<T>;
|
|
5
5
|
export type ParamStoreTypedGet = <T = unknown>(key: string, fallback: T) => T;
|
|
6
6
|
export type TypedReturn<T = unknown> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T extends Array<unknown> ? Array<unknown> : T extends object ? object : unknown;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Primitive = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
|
|
2
|
+
export type Flatten<T> = {
|
|
3
|
+
[K in keyof T]: T[K];
|
|
4
|
+
} & {};
|
|
5
|
+
export declare function _typeOf(input: unknown): Primitive | 'array';
|
|
6
|
+
export declare function _isTypeMatch<T>(a: unknown, b: unknown): a is T;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._isTypeMatch = exports._typeOf = void 0;
|
|
4
|
+
function _typeOf(input) {
|
|
5
|
+
return Array.isArray(input) ? 'array' : typeof input;
|
|
6
|
+
}
|
|
7
|
+
exports._typeOf = _typeOf;
|
|
8
|
+
function _isTypeMatch(a, b) {
|
|
9
|
+
const typeOf = (x) => (Array.isArray(x) ? 'array' : typeof x);
|
|
10
|
+
return typeOf(a) === typeOf(b);
|
|
11
|
+
}
|
|
12
|
+
exports._isTypeMatch = _isTypeMatch;
|
package/src/index.d.ts
CHANGED
|
@@ -33,8 +33,8 @@ export * from './StatsigTypes';
|
|
|
33
33
|
export * from './StatsigUser';
|
|
34
34
|
export * from './StorageProvider';
|
|
35
35
|
export * from './TypedJsonParse';
|
|
36
|
+
export * from './TypingUtils';
|
|
36
37
|
export * from './UrlOverrides';
|
|
37
|
-
export * from './UtitlityTypes';
|
|
38
38
|
export * from './UUID';
|
|
39
39
|
export * from './VisibilityObserving';
|
|
40
40
|
export { EventLogger, Storage, Log };
|
package/src/index.js
CHANGED
|
@@ -54,8 +54,8 @@ __exportStar(require("./StatsigTypes"), exports);
|
|
|
54
54
|
__exportStar(require("./StatsigUser"), exports);
|
|
55
55
|
__exportStar(require("./StorageProvider"), exports);
|
|
56
56
|
__exportStar(require("./TypedJsonParse"), exports);
|
|
57
|
+
__exportStar(require("./TypingUtils"), exports);
|
|
57
58
|
__exportStar(require("./UrlOverrides"), exports);
|
|
58
|
-
__exportStar(require("./UtitlityTypes"), exports);
|
|
59
59
|
__exportStar(require("./UUID"), exports);
|
|
60
60
|
__exportStar(require("./VisibilityObserving"), exports);
|
|
61
61
|
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { Log: Log_1.Log,
|
package/src/UtitlityTypes.d.ts
DELETED
package/src/UtitlityTypes.js
DELETED