@statsig/statsig-node-core 0.12.2-rc.2511250017 → 0.13.1-beta.2512040240
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/error_boundary.js +2 -1
- package/index.d.ts +8 -2
- package/index.js +24 -19
- package/package.json +9 -9
- package/statsig-generated.d.ts +16 -64
- package/statsig-generated.js +1 -3
- package/statsig_types.d.ts +45 -0
- package/statsig_types.js +146 -0
package/error_boundary.js
CHANGED
|
@@ -35,7 +35,8 @@ class ErrorBoundary {
|
|
|
35
35
|
}
|
|
36
36
|
static _onError(tag, error) {
|
|
37
37
|
_tryConvertInvalidArgError(error);
|
|
38
|
-
|
|
38
|
+
const printableTag = tag.replace('__INTERNAL_', '');
|
|
39
|
+
console.error('Statsig::' + printableTag, error);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
exports.ErrorBoundary = ErrorBoundary;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DynamicConfigEvaluationOptions, ExperimentEvaluationOptions, FeatureGateEvaluationOptions, LayerEvaluationOptions, SdkEvent, StatsigNapiInternal, StatsigOptions, StatsigResult, StatsigUser } from './statsig-generated';
|
|
2
|
+
import { DynamicConfig, Experiment, FeatureGate, Layer } from './statsig_types';
|
|
2
3
|
export * from './statsig-generated';
|
|
3
|
-
export
|
|
4
|
+
export * from './statsig_types';
|
|
4
5
|
export declare class Statsig extends StatsigNapiInternal {
|
|
5
6
|
private static _sharedInstance;
|
|
6
7
|
static shared(): Statsig;
|
|
@@ -11,4 +12,9 @@ export declare class Statsig extends StatsigNapiInternal {
|
|
|
11
12
|
stopConsoleCapture(): void;
|
|
12
13
|
shutdown(timeout_ms?: number): Promise<StatsigResult>;
|
|
13
14
|
subscribe(eventName: SdkEvent, callback: (event: any) => void): string;
|
|
15
|
+
getFeatureGate(user: StatsigUser, gateName: string, options?: FeatureGateEvaluationOptions): FeatureGate;
|
|
16
|
+
getDynamicConfig(user: StatsigUser, configName: string, options?: DynamicConfigEvaluationOptions): DynamicConfig;
|
|
17
|
+
getExperiment(user: StatsigUser, experimentName: string, options?: ExperimentEvaluationOptions): Experiment;
|
|
18
|
+
getExperimentByGroupName(experimentName: string, groupName: string): Experiment;
|
|
19
|
+
getLayer(user: StatsigUser, layerName: string, options?: LayerEvaluationOptions): Layer;
|
|
14
20
|
}
|
package/index.js
CHANGED
|
@@ -26,36 +26,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Statsig =
|
|
29
|
+
exports.Statsig = void 0;
|
|
30
30
|
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
31
31
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
32
32
|
const console_capture_1 = require("./console_capture");
|
|
33
33
|
const error_boundary_1 = require("./error_boundary");
|
|
34
34
|
const statsig_generated_1 = require("./statsig-generated");
|
|
35
|
-
|
|
36
|
-
Object.defineProperty(exports, "Experiment", { enumerable: true, get: function () { return statsig_generated_1.Experiment; } });
|
|
37
|
-
Object.defineProperty(exports, "Layer", { enumerable: true, get: function () { return statsig_generated_1.Layer; } });
|
|
38
|
-
Object.defineProperty(exports, "ParameterStore", { enumerable: true, get: function () { return statsig_generated_1.ParameterStore; } });
|
|
39
|
-
Object.defineProperty(exports, "StatsigUser", { enumerable: true, get: function () { return statsig_generated_1.StatsigUser; } });
|
|
35
|
+
const statsig_types_1 = require("./statsig_types");
|
|
40
36
|
__exportStar(require("./statsig-generated"), exports);
|
|
37
|
+
__exportStar(require("./statsig_types"), exports);
|
|
41
38
|
const inspectSym = Symbol.for('nodejs.util.inspect.custom');
|
|
42
39
|
// @ts-expect-error - prototype assignment
|
|
43
40
|
statsig_generated_1.StatsigUser.prototype[inspectSym] = function () {
|
|
44
41
|
return this.toJSON();
|
|
45
42
|
};
|
|
46
43
|
// @ts-expect-error - prototype assignment
|
|
47
|
-
statsig_generated_1.Experiment.prototype[inspectSym] = function () {
|
|
48
|
-
return this.toJSON();
|
|
49
|
-
};
|
|
50
|
-
// @ts-expect-error - prototype assignment
|
|
51
|
-
statsig_generated_1.DynamicConfig.prototype[inspectSym] = function () {
|
|
52
|
-
return this.toJSON();
|
|
53
|
-
};
|
|
54
|
-
// @ts-expect-error - prototype assignment
|
|
55
|
-
statsig_generated_1.Layer.prototype[inspectSym] = function () {
|
|
56
|
-
return this.toJSON();
|
|
57
|
-
};
|
|
58
|
-
// @ts-expect-error - prototype assignment
|
|
59
44
|
statsig_generated_1.ParameterStore.prototype[inspectSym] = function () {
|
|
60
45
|
return this.toJSON();
|
|
61
46
|
};
|
|
@@ -149,10 +134,30 @@ class Statsig extends statsig_generated_1.StatsigNapiInternal {
|
|
|
149
134
|
callback(JSON.parse(raw));
|
|
150
135
|
}
|
|
151
136
|
catch (error) {
|
|
152
|
-
console.error(`Error parsing
|
|
137
|
+
console.error(`[Statsig] Error parsing SDK Event: ${error}`);
|
|
153
138
|
}
|
|
154
139
|
});
|
|
155
140
|
}
|
|
141
|
+
getFeatureGate(user, gateName, options) {
|
|
142
|
+
const raw = this.__INTERNAL_getFeatureGate(user, gateName, options);
|
|
143
|
+
return new statsig_types_1.FeatureGate(gateName, raw);
|
|
144
|
+
}
|
|
145
|
+
getDynamicConfig(user, configName, options) {
|
|
146
|
+
const raw = this.__INTERNAL_getDynamicConfig(user, configName, options);
|
|
147
|
+
return new statsig_types_1.DynamicConfig(configName, raw);
|
|
148
|
+
}
|
|
149
|
+
getExperiment(user, experimentName, options) {
|
|
150
|
+
const raw = this.__INTERNAL_getExperiment(user, experimentName, options);
|
|
151
|
+
return new statsig_types_1.Experiment(experimentName, raw);
|
|
152
|
+
}
|
|
153
|
+
getExperimentByGroupName(experimentName, groupName) {
|
|
154
|
+
const raw = this.__INTERNAL_getExperimentByGroupName(experimentName, groupName);
|
|
155
|
+
return new statsig_types_1.Experiment(experimentName, raw);
|
|
156
|
+
}
|
|
157
|
+
getLayer(user, layerName, options) {
|
|
158
|
+
const raw = this.__INTERNAL_getLayer(user, layerName, options);
|
|
159
|
+
return new statsig_types_1.Layer((param) => this.__INTERNAL_logLayerParamExposure(raw, param), layerName, raw);
|
|
160
|
+
}
|
|
156
161
|
}
|
|
157
162
|
exports.Statsig = Statsig;
|
|
158
163
|
Statsig._sharedInstance = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/statsig-node-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1-beta.2512040240",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest --colors"
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
]
|
|
56
56
|
},
|
|
57
57
|
"optionalDependencies": {
|
|
58
|
-
"@statsig/statsig-node-core-linux-x64-musl": "0.
|
|
59
|
-
"@statsig/statsig-node-core-linux-x64-gnu": "0.
|
|
60
|
-
"@statsig/statsig-node-core-win32-x64-msvc": "0.
|
|
61
|
-
"@statsig/statsig-node-core-darwin-x64": "0.
|
|
62
|
-
"@statsig/statsig-node-core-win32-ia32-msvc": "0.
|
|
63
|
-
"@statsig/statsig-node-core-linux-arm64-musl": "0.
|
|
64
|
-
"@statsig/statsig-node-core-linux-arm64-gnu": "0.
|
|
65
|
-
"@statsig/statsig-node-core-darwin-arm64": "0.
|
|
58
|
+
"@statsig/statsig-node-core-linux-x64-musl": "0.13.1-beta.2512040240",
|
|
59
|
+
"@statsig/statsig-node-core-linux-x64-gnu": "0.13.1-beta.2512040240",
|
|
60
|
+
"@statsig/statsig-node-core-win32-x64-msvc": "0.13.1-beta.2512040240",
|
|
61
|
+
"@statsig/statsig-node-core-darwin-x64": "0.13.1-beta.2512040240",
|
|
62
|
+
"@statsig/statsig-node-core-win32-ia32-msvc": "0.13.1-beta.2512040240",
|
|
63
|
+
"@statsig/statsig-node-core-linux-arm64-musl": "0.13.1-beta.2512040240",
|
|
64
|
+
"@statsig/statsig-node-core-linux-arm64-gnu": "0.13.1-beta.2512040240",
|
|
65
|
+
"@statsig/statsig-node-core-darwin-arm64": "0.13.1-beta.2512040240"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/statsig-generated.d.ts
CHANGED
|
@@ -1,53 +1,5 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
export declare class DynamicConfig {
|
|
4
|
-
name: string
|
|
5
|
-
value: Record<string, any>
|
|
6
|
-
ruleID: string
|
|
7
|
-
idType: string
|
|
8
|
-
details: EvaluationDetails
|
|
9
|
-
getValue(paramName: string, fallback?: boolean | number | string | object | Array<any> | null): any | null
|
|
10
|
-
get<T>(paramName: string, fallback: T): T
|
|
11
|
-
getRuleId(): string
|
|
12
|
-
getIdType(): string
|
|
13
|
-
getEvaluationDetails(): EvaluationDetails
|
|
14
|
-
getSecondaryExposures(): Array<SecondaryExposure> | null
|
|
15
|
-
toJSON(): Record<string, any>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export declare class Experiment {
|
|
19
|
-
name: string
|
|
20
|
-
value: Record<string, any>
|
|
21
|
-
ruleID: string
|
|
22
|
-
idType: string
|
|
23
|
-
groupName?: string
|
|
24
|
-
details: EvaluationDetails
|
|
25
|
-
getValue(paramName: string, fallback?: boolean | number | string | object | Array<any> | null): any | null
|
|
26
|
-
get<T>(paramName: string, fallback: T): T
|
|
27
|
-
getRuleId(): string
|
|
28
|
-
getIdType(): string
|
|
29
|
-
getGroupName(): string | null
|
|
30
|
-
getEvaluationDetails(): EvaluationDetails
|
|
31
|
-
getSecondaryExposures(): Array<SecondaryExposure> | null
|
|
32
|
-
toJSON(): Record<string, any>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export declare class Layer {
|
|
36
|
-
name: string
|
|
37
|
-
ruleID: string
|
|
38
|
-
groupName?: string
|
|
39
|
-
allocatedExperimentName?: string
|
|
40
|
-
value: Record<string, any>
|
|
41
|
-
details: EvaluationDetails
|
|
42
|
-
getValue(paramName: string, fallback?: boolean | number | string | object | Array<any> | null): any | null
|
|
43
|
-
get<T>(paramName: string, fallback: T): T
|
|
44
|
-
getRuleId(): string
|
|
45
|
-
getGroupName(): string | null
|
|
46
|
-
getEvaluationDetails(): EvaluationDetails
|
|
47
|
-
getSecondaryExposures(): Array<SecondaryExposure> | null
|
|
48
|
-
toJSON(): Record<string, any>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
3
|
export declare class ParameterStore {
|
|
52
4
|
name: string
|
|
53
5
|
getValue<T>(paramName: string, fallback?: T): T
|
|
@@ -67,14 +19,15 @@ export declare class StatsigNapiInternal {
|
|
|
67
19
|
logEvent(user: StatsigUser, eventName: string, value?: string | number | null, metadata?: Record<string, string> | undefined | null): void
|
|
68
20
|
forwardLogLineEvent(user: StatsigUser, logLevel: 'trace' | 'debug' |'log' | 'info' | 'warn' | 'error', value?: string | undefined | null, metadata?: Record<string, string> | undefined | null): void
|
|
69
21
|
checkGate(user: StatsigUser, gateName: string, options?: FeatureGateEvaluationOptions | undefined | null): boolean
|
|
70
|
-
|
|
22
|
+
__INTERNAL_getFeatureGate(user: StatsigUser, featureName: string, options?: FeatureGateEvaluationOptions | undefined | null): string
|
|
71
23
|
getFieldsNeededForGate(gateName: string): Array<string>
|
|
72
|
-
|
|
24
|
+
__INTERNAL_getDynamicConfig(user: StatsigUser, configName: string, options?: DynamicConfigEvaluationOptions | undefined | null): string
|
|
73
25
|
getFieldsNeededForDynamicConfig(configName: string): Array<string>
|
|
74
|
-
|
|
75
|
-
|
|
26
|
+
__INTERNAL_getExperiment(user: StatsigUser, experimentName: string, options?: ExperimentEvaluationOptions | undefined | null): string
|
|
27
|
+
__INTERNAL_getExperimentByGroupName(experimentName: string, groupName: string): string
|
|
76
28
|
getFieldsNeededForExperiment(experimentName: string): Array<string>
|
|
77
|
-
|
|
29
|
+
__INTERNAL_getLayer(user: StatsigUser, layerName: string, options?: LayerEvaluationOptions | undefined | null): string
|
|
30
|
+
__INTERNAL_logLayerParamExposure(raw: string, paramName: string): void
|
|
78
31
|
getFieldsNeededForLayer(layerName: string): Array<string>
|
|
79
32
|
identify(user: StatsigUser): void
|
|
80
33
|
getParameterStore(user: StatsigUser, parameterStoreName: string, options?: ParameterStoreEvaluationOptions | undefined | null): ParameterStore
|
|
@@ -106,9 +59,9 @@ export declare class StatsigUser {
|
|
|
106
59
|
static withCustomIDs(customIds: Record<string, string>): StatsigUser
|
|
107
60
|
get customIDs(): Record<string, string> | null
|
|
108
61
|
set customIDs(value: Record<string, string> | null)
|
|
109
|
-
get custom(): Record<string, string
|
|
62
|
+
get custom(): Record<string, string | number | boolean | Array<string | number | boolean>> | null
|
|
110
63
|
set custom(value: Record<string, string | number | boolean | Array<string | number | boolean>> | null)
|
|
111
|
-
get privateAttributes(): Record<string, string
|
|
64
|
+
get privateAttributes(): Record<string, string | number | boolean | Array<string | number | boolean>> | null
|
|
112
65
|
set privateAttributes(value: Record<string, string | number | boolean | Array<string | number | boolean>> | null)
|
|
113
66
|
get statsigEnvironment(): Record<string, string> | null
|
|
114
67
|
set statsigEnvironment(value: { tier?: string, [key: string]: string | undefined } | null | undefined)
|
|
@@ -126,7 +79,7 @@ export declare class StatsigUser {
|
|
|
126
79
|
set locale(value: any)
|
|
127
80
|
get appVersion(): string | null
|
|
128
81
|
set appVersion(value: any)
|
|
129
|
-
toJSON():
|
|
82
|
+
toJSON(): any
|
|
130
83
|
}
|
|
131
84
|
|
|
132
85
|
export declare function __internal__testDataStore(store: DataStore, path: string, value: string): Promise<[DataStoreResponse | undefined | null, boolean]>
|
|
@@ -148,6 +101,7 @@ export interface ClientInitResponseOptions {
|
|
|
148
101
|
paramStoreFilter?: Set<string>
|
|
149
102
|
removeIdType?: boolean
|
|
150
103
|
removeDefaultValueGates?: boolean
|
|
104
|
+
responseFormat?: GCIRResponseFormat
|
|
151
105
|
}
|
|
152
106
|
|
|
153
107
|
export interface ConsoleCaptureOptions {
|
|
@@ -188,18 +142,16 @@ export interface ExperimentEvaluationOptions {
|
|
|
188
142
|
userPersistedValues?: Record<string, any>
|
|
189
143
|
}
|
|
190
144
|
|
|
191
|
-
export interface FeatureGate {
|
|
192
|
-
name: string
|
|
193
|
-
value: boolean
|
|
194
|
-
ruleID: string
|
|
195
|
-
idType: string
|
|
196
|
-
details: EvaluationDetails
|
|
197
|
-
}
|
|
198
|
-
|
|
199
145
|
export interface FeatureGateEvaluationOptions {
|
|
200
146
|
disableExposureLogging?: boolean
|
|
201
147
|
}
|
|
202
148
|
|
|
149
|
+
export declare const enum GCIRResponseFormat {
|
|
150
|
+
Initialize = 0,
|
|
151
|
+
InitializeWithSecondaryExposureMapping = 1,
|
|
152
|
+
InitializeV2 = 2
|
|
153
|
+
}
|
|
154
|
+
|
|
203
155
|
export interface LayerEvaluationOptions {
|
|
204
156
|
disableExposureLogging?: boolean
|
|
205
157
|
userPersistedValues?: Record<string, any>
|
package/statsig-generated.js
CHANGED
|
@@ -364,9 +364,6 @@ if (!nativeBinding) {
|
|
|
364
364
|
throw new Error(`Failed to load native binding`)
|
|
365
365
|
}
|
|
366
366
|
|
|
367
|
-
module.exports.DynamicConfig = nativeBinding.DynamicConfig
|
|
368
|
-
module.exports.Experiment = nativeBinding.Experiment
|
|
369
|
-
module.exports.Layer = nativeBinding.Layer
|
|
370
367
|
module.exports.ParameterStore = nativeBinding.ParameterStore
|
|
371
368
|
module.exports.StatsigNapiInternal = nativeBinding.StatsigNapiInternal
|
|
372
369
|
module.exports.StatsigUser = nativeBinding.StatsigUser
|
|
@@ -374,5 +371,6 @@ module.exports.__internal__testDataStore = nativeBinding.__internal__testDataSto
|
|
|
374
371
|
module.exports.__internal__testObservabilityClient = nativeBinding.__internal__testObservabilityClient
|
|
375
372
|
module.exports.__internal__testOutputLogger = nativeBinding.__internal__testOutputLogger
|
|
376
373
|
module.exports.__internal__testPersistentStorage = nativeBinding.__internal__testPersistentStorage
|
|
374
|
+
module.exports.GCIRResponseFormat = nativeBinding.GCIRResponseFormat
|
|
377
375
|
module.exports.OverrideAdapterType = nativeBinding.OverrideAdapterType
|
|
378
376
|
module.exports.statsigCaptureLogLine = nativeBinding.statsigCaptureLogLine
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { EvaluationDetails, SecondaryExposure } from './statsig-generated';
|
|
2
|
+
export type TypedGet = <T = unknown>(key: string, fallback?: T) => TypedReturn<T>;
|
|
3
|
+
export type UnknownGet = (key: string, fallback?: boolean | number | string | object | Array<unknown> | null) => unknown | null;
|
|
4
|
+
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;
|
|
5
|
+
declare class BaseEvaluation {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly ruleID: string;
|
|
8
|
+
readonly idType: string;
|
|
9
|
+
readonly details: EvaluationDetails;
|
|
10
|
+
readonly secondaryExposures: SecondaryExposure[];
|
|
11
|
+
constructor(name: string, data: Record<string, unknown>);
|
|
12
|
+
getEvaluationDetails(): EvaluationDetails;
|
|
13
|
+
getRuleId(): string;
|
|
14
|
+
getIdType(): string;
|
|
15
|
+
getSecondaryExposures(): SecondaryExposure[];
|
|
16
|
+
}
|
|
17
|
+
export declare class FeatureGate extends BaseEvaluation {
|
|
18
|
+
readonly value: boolean;
|
|
19
|
+
constructor(name: string, raw: string | null);
|
|
20
|
+
}
|
|
21
|
+
export declare class DynamicConfig extends BaseEvaluation {
|
|
22
|
+
readonly value: Record<string, unknown>;
|
|
23
|
+
readonly get: TypedGet;
|
|
24
|
+
readonly getValue: UnknownGet;
|
|
25
|
+
constructor(name: string, raw: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class Experiment extends BaseEvaluation {
|
|
28
|
+
readonly groupName: string | null;
|
|
29
|
+
readonly value: Record<string, unknown>;
|
|
30
|
+
readonly get: TypedGet;
|
|
31
|
+
readonly getValue: UnknownGet;
|
|
32
|
+
constructor(name: string, raw: string);
|
|
33
|
+
getGroupName(): string | null;
|
|
34
|
+
}
|
|
35
|
+
export declare class Layer extends BaseEvaluation {
|
|
36
|
+
readonly groupName: string | null;
|
|
37
|
+
readonly allocatedExperimentName: string | null;
|
|
38
|
+
readonly __value: Record<string, unknown>;
|
|
39
|
+
readonly get: TypedGet;
|
|
40
|
+
readonly getValue: UnknownGet;
|
|
41
|
+
constructor(exposeFn: (param: string) => void, name: string, raw: string);
|
|
42
|
+
getGroupName(): string | null;
|
|
43
|
+
getAllocatedExperimentName(): string | null;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
package/statsig_types.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Layer = exports.Experiment = exports.DynamicConfig = exports.FeatureGate = void 0;
|
|
4
|
+
class BaseEvaluation {
|
|
5
|
+
constructor(name, data) {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
this.secondaryExposures = [];
|
|
8
|
+
this.name = name;
|
|
9
|
+
this.ruleID = (_a = data.ruleID) !== null && _a !== void 0 ? _a : '';
|
|
10
|
+
this.idType = (_b = data.idType) !== null && _b !== void 0 ? _b : '';
|
|
11
|
+
this.details = _extractEvaluationDetails(data.details);
|
|
12
|
+
this.secondaryExposures =
|
|
13
|
+
(_c = data.secondaryExposures) !== null && _c !== void 0 ? _c : [];
|
|
14
|
+
}
|
|
15
|
+
getEvaluationDetails() {
|
|
16
|
+
return this.details;
|
|
17
|
+
}
|
|
18
|
+
getRuleId() {
|
|
19
|
+
return this.ruleID;
|
|
20
|
+
}
|
|
21
|
+
getIdType() {
|
|
22
|
+
return this.idType;
|
|
23
|
+
}
|
|
24
|
+
getSecondaryExposures() {
|
|
25
|
+
return this.secondaryExposures;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class FeatureGate extends BaseEvaluation {
|
|
29
|
+
constructor(name, raw) {
|
|
30
|
+
const data = _parseRawEvaluation(raw);
|
|
31
|
+
super(name, data);
|
|
32
|
+
this.value = data.value === true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.FeatureGate = FeatureGate;
|
|
36
|
+
class DynamicConfig extends BaseEvaluation {
|
|
37
|
+
constructor(name, raw) {
|
|
38
|
+
var _a;
|
|
39
|
+
const data = _parseRawEvaluation(raw);
|
|
40
|
+
super(name, data);
|
|
41
|
+
this.value = {};
|
|
42
|
+
this.value = (_a = data.value) !== null && _a !== void 0 ? _a : {};
|
|
43
|
+
this.get = _makeTypedGet(name, this.value);
|
|
44
|
+
this.getValue = _makeUnknownGet(this.value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.DynamicConfig = DynamicConfig;
|
|
48
|
+
class Experiment extends BaseEvaluation {
|
|
49
|
+
constructor(name, raw) {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
const data = _parseRawEvaluation(raw);
|
|
52
|
+
super(name, data);
|
|
53
|
+
this.groupName = null;
|
|
54
|
+
this.value = {};
|
|
55
|
+
this.groupName = (_a = data.groupName) !== null && _a !== void 0 ? _a : null;
|
|
56
|
+
this.value = (_b = data.value) !== null && _b !== void 0 ? _b : {};
|
|
57
|
+
this.get = _makeTypedGet(name, this.value);
|
|
58
|
+
this.getValue = _makeUnknownGet(this.value);
|
|
59
|
+
}
|
|
60
|
+
getGroupName() {
|
|
61
|
+
return this.groupName;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Experiment = Experiment;
|
|
65
|
+
class Layer extends BaseEvaluation {
|
|
66
|
+
constructor(exposeFn, name, raw) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
const data = _parseRawEvaluation(raw);
|
|
69
|
+
super(name, data);
|
|
70
|
+
this.groupName = null;
|
|
71
|
+
this.allocatedExperimentName = null;
|
|
72
|
+
this.__value = {};
|
|
73
|
+
this.__value = (_a = data.value) !== null && _a !== void 0 ? _a : {};
|
|
74
|
+
this.groupName = (_b = data.groupName) !== null && _b !== void 0 ? _b : null;
|
|
75
|
+
this.allocatedExperimentName =
|
|
76
|
+
(_c = data.allocatedExperimentName) !== null && _c !== void 0 ? _c : null;
|
|
77
|
+
this.get = _makeTypedGet(name, this.__value, exposeFn);
|
|
78
|
+
this.getValue = _makeUnknownGet(this.__value, exposeFn);
|
|
79
|
+
}
|
|
80
|
+
getGroupName() {
|
|
81
|
+
return this.groupName;
|
|
82
|
+
}
|
|
83
|
+
getAllocatedExperimentName() {
|
|
84
|
+
return this.allocatedExperimentName;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Layer = Layer;
|
|
88
|
+
function _parseRawEvaluation(raw) {
|
|
89
|
+
try {
|
|
90
|
+
return JSON.parse(raw !== null && raw !== void 0 ? raw : '{}');
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
console.error(`[Statsig] Error parsing BaseEvaluation: ${error}`);
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function _isTypeMatch(a, b) {
|
|
98
|
+
const typeOf = (x) => Array.isArray(x) ? 'array' : x === null ? 'null' : typeof x;
|
|
99
|
+
return typeOf(a) === typeOf(b);
|
|
100
|
+
}
|
|
101
|
+
function _makeTypedGet(name, value, exposeFunc) {
|
|
102
|
+
return (param, fallback) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const found = (_a = value[param]) !== null && _a !== void 0 ? _a : null;
|
|
105
|
+
if (found == null) {
|
|
106
|
+
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
107
|
+
}
|
|
108
|
+
if (fallback != null && !_isTypeMatch(found, fallback)) {
|
|
109
|
+
console.warn(`[Statsig] Parameter type mismatch. '${name}.${param}' was found to be type '${typeof found}' but fallback/return type is '${typeof fallback}'`);
|
|
110
|
+
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
111
|
+
}
|
|
112
|
+
exposeFunc === null || exposeFunc === void 0 ? void 0 : exposeFunc(param);
|
|
113
|
+
return found;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function _makeUnknownGet(value, exposeFunc) {
|
|
117
|
+
return (param, fallback) => {
|
|
118
|
+
var _a;
|
|
119
|
+
if (fallback === undefined) {
|
|
120
|
+
fallback = null;
|
|
121
|
+
}
|
|
122
|
+
if (param == null) {
|
|
123
|
+
return fallback;
|
|
124
|
+
}
|
|
125
|
+
if (value[param] != null) {
|
|
126
|
+
exposeFunc === null || exposeFunc === void 0 ? void 0 : exposeFunc(param);
|
|
127
|
+
}
|
|
128
|
+
return (_a = value[param]) !== null && _a !== void 0 ? _a : fallback;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function _extractEvaluationDetails(data) {
|
|
132
|
+
if (data == null) {
|
|
133
|
+
return {
|
|
134
|
+
reason: '',
|
|
135
|
+
lcut: 0,
|
|
136
|
+
receivedAt: 0,
|
|
137
|
+
version: 0,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
reason: data.reason,
|
|
142
|
+
lcut: data.lcut,
|
|
143
|
+
receivedAt: data.received_at,
|
|
144
|
+
version: data.version,
|
|
145
|
+
};
|
|
146
|
+
}
|