@statsig/client-core 0.0.1-beta.9 → 1.0.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/README.md +0 -3
- package/package.json +1 -1
- package/src/$_StatsigGlobal.d.ts +9 -1
- package/src/$_StatsigGlobal.js +29 -12
- package/src/CacheKey.d.ts +4 -0
- package/src/CacheKey.js +27 -0
- package/src/ClientInterfaces.d.ts +46 -12
- package/src/DataAdapterCore.d.ts +31 -0
- package/src/DataAdapterCore.js +192 -0
- package/src/Diagnostics.d.ts +1 -3
- package/src/Diagnostics.js +4 -49
- package/src/DownloadConfigSpecsResponse.d.ts +41 -0
- package/src/DownloadConfigSpecsResponse.js +2 -0
- package/src/ErrorBoundary.d.ts +7 -2
- package/src/ErrorBoundary.js +81 -88
- 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 +15 -10
- package/src/EventLogger.js +216 -256
- package/src/Hashing.d.ts +2 -1
- package/src/Hashing.js +26 -7
- package/src/InitializeResponse.d.ts +20 -0
- package/src/InitializeResponse.js +2 -0
- package/src/Log.js +15 -34
- package/src/NetworkConfig.d.ts +19 -0
- package/src/NetworkConfig.js +19 -0
- package/src/NetworkCore.d.ts +17 -7
- package/src/NetworkCore.js +173 -196
- 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 +56 -19
- package/src/StatsigClientBase.js +126 -48
- package/src/StatsigClientEventEmitter.d.ts +54 -33
- package/src/StatsigDataAdapter.d.ts +103 -17
- package/src/StatsigDataAdapter.js +2 -0
- package/src/StatsigEvent.d.ts +10 -18
- package/src/StatsigEvent.js +41 -39
- package/src/StatsigMetadata.d.ts +1 -1
- package/src/StatsigMetadata.js +7 -18
- package/src/StatsigOptionsCommon.d.ts +84 -20
- package/src/StatsigTypeFactories.d.ts +6 -0
- package/src/StatsigTypeFactories.js +50 -0
- package/src/StatsigTypes.d.ts +28 -22
- package/src/StatsigTypes.js +0 -29
- package/src/StatsigUser.d.ts +7 -8
- package/src/StatsigUser.js +11 -24
- package/src/StorageProvider.d.ts +13 -8
- package/src/StorageProvider.js +66 -85
- 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 +9 -0
- package/src/VisibilityObserving.js +39 -0
- package/src/index.d.ts +20 -4
- package/src/index.js +26 -18
- package/src/Monitoring.d.ts +0 -3
- package/src/Monitoring.js +0 -33
- 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
|
@@ -1,40 +1,126 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NetworkPriority } from './NetworkConfig';
|
|
2
|
+
import type { AnyStatsigOptions, NetworkConfigCommon } from './StatsigOptionsCommon';
|
|
2
3
|
import { StatsigUser } from './StatsigUser';
|
|
3
|
-
export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap';
|
|
4
|
-
export type
|
|
4
|
+
export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap' | 'Prefetch';
|
|
5
|
+
export type DataAdapterResult = {
|
|
5
6
|
readonly source: DataSource;
|
|
6
7
|
readonly data: string;
|
|
8
|
+
readonly receivedAt: number;
|
|
9
|
+
readonly stableID: string | null;
|
|
10
|
+
readonly fullUserHash: string | null;
|
|
7
11
|
};
|
|
12
|
+
export type DataAdapterAsyncOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* The maximum amount of time (in milliseconds) this operation is permitted to run.
|
|
15
|
+
* If the timeout is hit, null is returned but any in-flight requests are kept alive with results going to cache for future updates.
|
|
16
|
+
*
|
|
17
|
+
* Note: If no timeout is given, the {@link NetworkConfigCommon.networkTimeoutMs|StatsigOptions.networkConfig.networkTimeoutMs} is used.
|
|
18
|
+
*/
|
|
19
|
+
readonly timeoutMs?: NetworkConfigCommon['networkTimeoutMs'];
|
|
20
|
+
/**
|
|
21
|
+
* The priority that should be applied to the Http request that is fired.
|
|
22
|
+
*
|
|
23
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch#priority
|
|
24
|
+
*
|
|
25
|
+
* default: 'auto'
|
|
26
|
+
*/
|
|
27
|
+
readonly priority?: NetworkPriority;
|
|
28
|
+
};
|
|
29
|
+
export declare const DataAdapterCachePrefix = "statsig.cached";
|
|
8
30
|
/**
|
|
9
31
|
* Describes a type that is used during intialize/update operations of a Statsig client.
|
|
10
32
|
*
|
|
11
33
|
* See below to find the default adapters, but know that it is possible to create your
|
|
12
|
-
* own StatsigDataAdapter and provide it via
|
|
34
|
+
* own StatsigDataAdapter and provide it via `StatsigOptions.dataAdapter`.
|
|
13
35
|
*
|
|
14
|
-
*
|
|
36
|
+
* defaults:
|
|
15
37
|
*
|
|
16
|
-
* - {@link
|
|
38
|
+
* - {@link StatsigClient} uses {@link EvaluationsDataAdapter}
|
|
17
39
|
*
|
|
18
|
-
* - {@link
|
|
40
|
+
* - {@link StatsigOnDeviceEvalClient} uses {@link SpecsDataAdapter}
|
|
19
41
|
*/
|
|
20
|
-
|
|
42
|
+
type DataAdapterCommon = {
|
|
21
43
|
/**
|
|
22
44
|
* Called when the StatsigDataAdapter is attached to the Statsig client instance during construction.
|
|
23
45
|
* @param {string} sdkKey The SDK key being used by the Statsig client.
|
|
24
46
|
* @param {StatsigOptionsCommon | null} options The StatsigOptions being used by the Statsig client.
|
|
25
47
|
*/
|
|
26
|
-
readonly attach: (sdkKey: string, options:
|
|
48
|
+
readonly attach: (sdkKey: string, options: AnyStatsigOptions | null) => void;
|
|
49
|
+
/**
|
|
50
|
+
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
51
|
+
*
|
|
52
|
+
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
53
|
+
*/
|
|
54
|
+
readonly __primeInMemoryCache: (cache: Record<string, DataAdapterResult>) => void;
|
|
55
|
+
};
|
|
56
|
+
export type EvaluationsDataAdapter = DataAdapterCommon & {
|
|
57
|
+
/**
|
|
58
|
+
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
|
|
59
|
+
*
|
|
60
|
+
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
61
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
62
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
63
|
+
*/
|
|
64
|
+
readonly getDataSync: (user: StatsigUser) => DataAdapterResult | null;
|
|
65
|
+
/**
|
|
66
|
+
* Asynchronously get evaluation data for the given user. Called during initializeAsync and/or updateUserAsync.
|
|
67
|
+
*
|
|
68
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
69
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
70
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
71
|
+
*/
|
|
72
|
+
readonly getDataAsync: (current: DataAdapterResult | null, user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
|
|
73
|
+
/**
|
|
74
|
+
* Manually trigger a fetch for new evaluations data for the given user.
|
|
75
|
+
*
|
|
76
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
77
|
+
*/
|
|
78
|
+
readonly prefetchData: (user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Manually set the evaluations data from a JSON string.
|
|
81
|
+
*
|
|
82
|
+
* Statsig Server SDKs supported:
|
|
83
|
+
* - node-js-server-sdk\@5.20.0
|
|
84
|
+
* - java-server-sdk\@1.18.0
|
|
85
|
+
* - python-sdk\@0.32.0
|
|
86
|
+
* - ruby-sdk\@1.34.0
|
|
87
|
+
* - dotnet-sdk\@1.25.0
|
|
88
|
+
* - php-sdk\@3.2.0
|
|
89
|
+
*
|
|
90
|
+
* Note: You can use {@link EvaluationsDataAdapter.setDataLegacy} if your server is running an older Statsig Server SDK.
|
|
91
|
+
*/
|
|
92
|
+
readonly setData: (data: string) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Manually set evaluations data for the given user.
|
|
95
|
+
*
|
|
96
|
+
* @param {StatsigUser} user The StatsigUser this data is for.
|
|
97
|
+
*
|
|
98
|
+
* @deprecated This method is provided only to support older versions of Statsig server SDKs.
|
|
99
|
+
* Newer SDKs include the StatsigUser as part of the data string, and can be used with the {@link EvaluationsDataAdapter.setData} method instead.
|
|
100
|
+
*/
|
|
101
|
+
readonly setDataLegacy: (data: string, user: StatsigUser) => void;
|
|
102
|
+
};
|
|
103
|
+
export type SpecsDataAdapter = DataAdapterCommon & {
|
|
27
104
|
/**
|
|
28
|
-
* Synchronously get data
|
|
105
|
+
* Synchronously get specs data. Called during initializeSync and/or updateUserSync.
|
|
29
106
|
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
30
|
-
* @
|
|
31
|
-
|
|
107
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
108
|
+
*/
|
|
109
|
+
readonly getDataSync: () => DataAdapterResult | null;
|
|
110
|
+
/**
|
|
111
|
+
* Asynchronously get specs data. Called during initializeAsync and/or updateUserAsync.
|
|
112
|
+
*
|
|
113
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
114
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
115
|
+
*/
|
|
116
|
+
readonly getDataAsync: (current: DataAdapterResult | null, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
|
|
117
|
+
/**
|
|
118
|
+
* Manually trigger a fetch for new specs data.
|
|
32
119
|
*/
|
|
33
|
-
readonly
|
|
120
|
+
readonly prefetchData: (options?: DataAdapterAsyncOptions) => Promise<void>;
|
|
34
121
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {StatsigUser | undefined} user The StatsigUser to get data for.
|
|
37
|
-
* @returns {StatsigDataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
122
|
+
* Manually set specs data (Bootstrap).
|
|
38
123
|
*/
|
|
39
|
-
readonly
|
|
124
|
+
readonly setData: (data: string) => void;
|
|
40
125
|
};
|
|
126
|
+
export {};
|
package/src/StatsigEvent.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SecondaryExposure } from './EvaluationTypes';
|
|
2
|
+
import { DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
|
|
2
3
|
import { StatsigUser } from './StatsigUser';
|
|
3
|
-
export type SecondaryExposure = {
|
|
4
|
-
gate: string;
|
|
5
|
-
gateValue: string;
|
|
6
|
-
ruleID: string;
|
|
7
|
-
};
|
|
8
4
|
export type StatsigEvent = {
|
|
9
5
|
eventName: string;
|
|
10
6
|
value?: string | number | null;
|
|
@@ -12,19 +8,15 @@ export type StatsigEvent = {
|
|
|
12
8
|
[key: string]: string;
|
|
13
9
|
} | null;
|
|
14
10
|
};
|
|
15
|
-
export type StatsigEventInternal = StatsigEvent & {
|
|
11
|
+
export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
|
|
16
12
|
user: StatsigUser | null;
|
|
17
13
|
time: number;
|
|
14
|
+
metadata?: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
} | null;
|
|
18
17
|
secondaryExposures?: SecondaryExposure[];
|
|
19
18
|
};
|
|
20
|
-
export declare
|
|
21
|
-
export declare
|
|
22
|
-
export declare
|
|
23
|
-
export declare
|
|
24
|
-
rule_id: string;
|
|
25
|
-
explicit_parameters: string[];
|
|
26
|
-
undelegated_secondary_exposures?: SecondaryExposure[];
|
|
27
|
-
secondary_exposures: SecondaryExposure[];
|
|
28
|
-
allocated_experiment_name: string;
|
|
29
|
-
details: EvaluationDetails;
|
|
30
|
-
}): 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;
|
package/src/StatsigEvent.js
CHANGED
|
@@ -1,58 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
exports._createLayerParameterExposure = exports._createConfigExposure = exports._createGateExposure = exports._isExposureEvent = void 0;
|
|
4
|
+
const CONFIG_EXPOSURE_NAME = 'statsig::config_exposure';
|
|
5
|
+
const GATE_EXPOSURE_NAME = 'statsig::gate_exposure';
|
|
6
|
+
const LAYER_EXPOSURE_NAME = 'statsig::layer_exposure';
|
|
7
|
+
const _createExposure = (eventName, user, details, metadata, secondaryExposures) => {
|
|
8
8
|
return {
|
|
9
|
-
eventName
|
|
10
|
-
user
|
|
9
|
+
eventName,
|
|
10
|
+
user,
|
|
11
11
|
value: null,
|
|
12
12
|
metadata: _addEvaluationDetailsToMetadata(details, metadata),
|
|
13
|
-
secondaryExposures
|
|
13
|
+
secondaryExposures,
|
|
14
14
|
time: Date.now(),
|
|
15
15
|
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var eventName = _a.eventName;
|
|
16
|
+
};
|
|
17
|
+
const _isExposureEvent = ({ eventName, }) => {
|
|
19
18
|
return eventName === GATE_EXPOSURE_NAME || eventName === CONFIG_EXPOSURE_NAME;
|
|
20
|
-
}
|
|
21
|
-
exports.
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
};
|
|
20
|
+
exports._isExposureEvent = _isExposureEvent;
|
|
21
|
+
const _createGateExposure = (user, gate) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return _createExposure(GATE_EXPOSURE_NAME, user, gate.details, {
|
|
24
24
|
gate: gate.name,
|
|
25
25
|
gateValue: String(gate.value),
|
|
26
26
|
ruleID: gate.ruleID,
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
exports.
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
}, (_b = (_a = gate.__evaluation) === null || _a === void 0 ? void 0 : _a.secondary_exposures) !== null && _b !== void 0 ? _b : []);
|
|
28
|
+
};
|
|
29
|
+
exports._createGateExposure = _createGateExposure;
|
|
30
|
+
const _createConfigExposure = (user, config) => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
return _createExposure(CONFIG_EXPOSURE_NAME, user, config.details, {
|
|
32
33
|
config: config.name,
|
|
33
34
|
ruleID: config.ruleID,
|
|
34
|
-
},
|
|
35
|
-
}
|
|
36
|
-
exports.
|
|
37
|
-
|
|
38
|
-
var _a;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
}, (_b = (_a = config.__evaluation) === null || _a === void 0 ? void 0 : _a.secondary_exposures) !== null && _b !== void 0 ? _b : []);
|
|
36
|
+
};
|
|
37
|
+
exports._createConfigExposure = _createConfigExposure;
|
|
38
|
+
const _createLayerParameterExposure = (user, layer, parameterName) => {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
const evaluation = layer.__evaluation;
|
|
41
|
+
const isExplicit = ((_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.explicit_parameters) === null || _a === void 0 ? void 0 : _a.includes(parameterName)) === true;
|
|
42
|
+
let allocatedExperiment = '';
|
|
43
|
+
let secondaryExposures = (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.undelegated_secondary_exposures) !== null && _b !== void 0 ? _b : [];
|
|
42
44
|
if (isExplicit) {
|
|
43
|
-
allocatedExperiment =
|
|
44
|
-
secondaryExposures =
|
|
45
|
+
allocatedExperiment = (_c = evaluation.allocated_experiment_name) !== null && _c !== void 0 ? _c : '';
|
|
46
|
+
secondaryExposures = evaluation.secondary_exposures;
|
|
45
47
|
}
|
|
46
|
-
return
|
|
47
|
-
config:
|
|
48
|
-
parameterName
|
|
49
|
-
ruleID:
|
|
50
|
-
allocatedExperiment
|
|
48
|
+
return _createExposure(LAYER_EXPOSURE_NAME, user, layer.details, {
|
|
49
|
+
config: layer.name,
|
|
50
|
+
parameterName,
|
|
51
|
+
ruleID: layer.ruleID,
|
|
52
|
+
allocatedExperiment,
|
|
51
53
|
isExplicitParameter: String(isExplicit),
|
|
52
54
|
}, secondaryExposures);
|
|
53
|
-
}
|
|
54
|
-
exports.
|
|
55
|
-
|
|
55
|
+
};
|
|
56
|
+
exports._createLayerParameterExposure = _createLayerParameterExposure;
|
|
57
|
+
const _addEvaluationDetailsToMetadata = (details, metadata) => {
|
|
56
58
|
metadata['reason'] = details.reason;
|
|
57
59
|
if (details.lcut) {
|
|
58
60
|
metadata['lcut'] = String(details.lcut);
|
|
@@ -61,4 +63,4 @@ function _addEvaluationDetailsToMetadata(details, metadata) {
|
|
|
61
63
|
metadata['receivedAt'] = String(details.receivedAt);
|
|
62
64
|
}
|
|
63
65
|
return metadata;
|
|
64
|
-
}
|
|
66
|
+
};
|
package/src/StatsigMetadata.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "1.0.0";
|
|
1
2
|
export type StatsigMetadata = {
|
|
2
3
|
readonly [key: string]: string | undefined;
|
|
3
4
|
readonly appVersion?: string;
|
|
4
5
|
readonly deviceModel?: string;
|
|
5
6
|
readonly deviceModelName?: string;
|
|
6
7
|
readonly locale?: string;
|
|
7
|
-
readonly sdkType: string;
|
|
8
8
|
readonly sdkVersion: string;
|
|
9
9
|
readonly stableID?: string;
|
|
10
10
|
readonly systemName?: string;
|
package/src/StatsigMetadata.js
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.StatsigMetadataProvider = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sdkVersion: SDK_VERSION,
|
|
3
|
+
exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
|
|
4
|
+
exports.SDK_VERSION = '1.0.0';
|
|
5
|
+
let metadata = {
|
|
6
|
+
sdkVersion: exports.SDK_VERSION,
|
|
18
7
|
sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
|
|
19
8
|
};
|
|
20
9
|
exports.StatsigMetadataProvider = {
|
|
21
|
-
get:
|
|
22
|
-
add:
|
|
23
|
-
metadata =
|
|
10
|
+
get: () => metadata,
|
|
11
|
+
add: (additions) => {
|
|
12
|
+
metadata = Object.assign(Object.assign({}, metadata), additions);
|
|
24
13
|
},
|
|
25
14
|
};
|
|
@@ -1,47 +1,111 @@
|
|
|
1
1
|
import { LogLevel } from './Log';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { NetworkArgs } from './NetworkConfig';
|
|
3
|
+
import { OverrideAdapter } from './OverrideAdapter';
|
|
4
|
+
/** Options that can be set at init and updated during runtime. */
|
|
5
|
+
export type StatsigRuntimeMutableOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Prevents sending any events over the network.
|
|
8
|
+
*/
|
|
9
|
+
disableLogging?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Prevents writing anything to storage.
|
|
12
|
+
*
|
|
13
|
+
* Note: caching will not work if storage is disabled
|
|
14
|
+
*/
|
|
15
|
+
disableStorage?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type NetworkConfigCommon = {
|
|
5
18
|
/**
|
|
6
19
|
* The API to use for all SDK network requests. You should not need to override this
|
|
7
|
-
* unless you have
|
|
20
|
+
* unless you have a custom API that implements the Statsig endpoints.
|
|
8
21
|
*/
|
|
9
22
|
api?: string;
|
|
10
23
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
24
|
+
* The URL used to flush queued events via a POST request. Takes precedence over {@link StatsigOptionsCommon.api}.
|
|
25
|
+
*
|
|
26
|
+
* default: `https://featuregates.org/v1/initialize`
|
|
13
27
|
*/
|
|
14
|
-
|
|
28
|
+
logEventUrl?: string;
|
|
15
29
|
/**
|
|
16
|
-
*
|
|
30
|
+
* The maximum amount of time (in milliseconds) that any network request can take
|
|
31
|
+
* before timing out.
|
|
32
|
+
*
|
|
33
|
+
* default: `10,000 ms` (10 seconds)
|
|
17
34
|
*/
|
|
18
|
-
|
|
35
|
+
networkTimeoutMs?: number;
|
|
19
36
|
/**
|
|
20
|
-
*
|
|
21
|
-
* Default: LogLevel.Warn
|
|
37
|
+
* Intended for testing purposes. Prevents any network requests being made.
|
|
22
38
|
*/
|
|
23
|
-
|
|
39
|
+
preventAllNetworkTraffic?: boolean;
|
|
24
40
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
41
|
+
* Overrides the default networking layer used by the Statsig client.
|
|
42
|
+
* By default, the client use `fetch`, but overriding this
|
|
43
|
+
* you could use `axios` or raw `XMLHttpRequest`
|
|
44
|
+
*
|
|
45
|
+
* default: `Fetch API`
|
|
46
|
+
*
|
|
47
|
+
* @param {string} url Where the request is going.
|
|
48
|
+
* @param {NetworkArgs} args Configuration for the network request.
|
|
49
|
+
* @returns {Response}
|
|
27
50
|
*/
|
|
28
|
-
|
|
51
|
+
networkOverrideFunc?: (url: string, args: NetworkArgs) => Promise<Response>;
|
|
52
|
+
};
|
|
53
|
+
/** Options for configuring a Statsig client. */
|
|
54
|
+
export type StatsigOptionsCommon<NetworkConfig extends NetworkConfigCommon> = StatsigRuntimeMutableOptions & {
|
|
29
55
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
56
|
+
* Allows for fine grained control over which api or urls are hit for specific Statsig network requests.
|
|
57
|
+
*
|
|
58
|
+
* For defaults see {@link StatsigClientUrlOverrideOptions}
|
|
32
59
|
*/
|
|
33
|
-
|
|
60
|
+
networkConfig?: NetworkConfig;
|
|
61
|
+
/**
|
|
62
|
+
* An object you can use to set environment variables that apply to all of your users
|
|
63
|
+
* in the same session.
|
|
64
|
+
*/
|
|
65
|
+
environment?: StatsigEnvironment;
|
|
66
|
+
/**
|
|
67
|
+
* How much information is allowed to be printed to the console.
|
|
68
|
+
*
|
|
69
|
+
* default: {@link LogLevel.Warn}
|
|
70
|
+
*/
|
|
71
|
+
logLevel?: LogLevel;
|
|
34
72
|
/**
|
|
35
73
|
* The maximum number of events to batch before flushing logs to Statsig.
|
|
36
|
-
*
|
|
74
|
+
*
|
|
75
|
+
* default: `50`
|
|
37
76
|
*/
|
|
38
77
|
loggingBufferMaxSize?: number;
|
|
39
78
|
/**
|
|
40
79
|
* How often (in milliseconds) to flush logs to Statsig.
|
|
41
|
-
*
|
|
80
|
+
*
|
|
81
|
+
* default: `10,000 ms` (10 seconds)
|
|
42
82
|
*/
|
|
43
83
|
loggingIntervalMs?: number;
|
|
84
|
+
/**
|
|
85
|
+
* An implementor of {@link OverrideAdapter}, used to alter evaluations before its
|
|
86
|
+
* returned to the caller of a check api (checkGate/getExperiment etc).
|
|
87
|
+
*/
|
|
88
|
+
overrideAdapter?: OverrideAdapter;
|
|
89
|
+
/**
|
|
90
|
+
* (Web only) Should the 'current page' url be included with logged events.
|
|
91
|
+
*
|
|
92
|
+
* default: true
|
|
93
|
+
*/
|
|
94
|
+
includeCurrentPageUrlWithEvents?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Whether or not Statsig should use raw JSON for network requests where possible.
|
|
97
|
+
*
|
|
98
|
+
* default: `false`
|
|
99
|
+
*/
|
|
100
|
+
disableStatsigEncoding?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether or not Statsig should compress JSON bodies for network requests where possible.
|
|
103
|
+
*
|
|
104
|
+
* default: `false`
|
|
105
|
+
*/
|
|
106
|
+
disableCompression?: boolean;
|
|
44
107
|
};
|
|
108
|
+
export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;
|
|
45
109
|
export type StatsigEnvironment = {
|
|
46
110
|
tier?: string;
|
|
47
111
|
[key: string]: string | undefined;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicConfigEvaluation, EvaluationDetails, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
|
|
2
|
+
import { AnyConfigBasedStatsigType, DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
|
|
3
|
+
export declare function _makeFeatureGate(name: string, details: EvaluationDetails, evaluation: GateEvaluation | null): FeatureGate;
|
|
4
|
+
export declare function _makeDynamicConfig(name: string, details: EvaluationDetails, evaluation: DynamicConfigEvaluation | null): DynamicConfig;
|
|
5
|
+
export declare function _makeLayer(name: string, details: EvaluationDetails, evaluation: LayerEvaluation | null, exposeFunc?: (param: string) => void): Layer;
|
|
6
|
+
export declare function _mergeOverride<T extends AnyConfigBasedStatsigType>(original: T, overridden: T | null | undefined, value: Record<string, unknown>, exposeFunc?: (param: string) => void): T;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._mergeOverride = exports._makeLayer = exports._makeDynamicConfig = exports._makeFeatureGate = void 0;
|
|
4
|
+
const DEFAULT_RULE = 'default';
|
|
5
|
+
function _makeEvaluation(name, details, evaluation, value) {
|
|
6
|
+
var _a;
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
details,
|
|
10
|
+
ruleID: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.rule_id) !== null && _a !== void 0 ? _a : DEFAULT_RULE,
|
|
11
|
+
__evaluation: evaluation,
|
|
12
|
+
value,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function _makeFeatureGate(name, details, evaluation) {
|
|
16
|
+
return _makeEvaluation(name, details, evaluation, (evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) === true);
|
|
17
|
+
}
|
|
18
|
+
exports._makeFeatureGate = _makeFeatureGate;
|
|
19
|
+
function _makeDynamicConfig(name, details, evaluation) {
|
|
20
|
+
var _a;
|
|
21
|
+
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _a !== void 0 ? _a : {})), { groupName: null, get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) });
|
|
22
|
+
}
|
|
23
|
+
exports._makeDynamicConfig = _makeDynamicConfig;
|
|
24
|
+
function _makeLayer(name, details, evaluation, exposeFunc) {
|
|
25
|
+
var _a, _b;
|
|
26
|
+
return Object.assign(Object.assign({}, _makeEvaluation(name, details, evaluation, undefined)), { get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value, exposeFunc), groupName: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _a !== void 0 ? _a : null, __value: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _b !== void 0 ? _b : {} });
|
|
27
|
+
}
|
|
28
|
+
exports._makeLayer = _makeLayer;
|
|
29
|
+
function _mergeOverride(original, overridden, value, exposeFunc) {
|
|
30
|
+
return Object.assign(Object.assign(Object.assign({}, original), overridden), { get: _makeTypedGet(value, exposeFunc) });
|
|
31
|
+
}
|
|
32
|
+
exports._mergeOverride = _mergeOverride;
|
|
33
|
+
function _isTypeMatch(a, b) {
|
|
34
|
+
const typeOf = (x) => (Array.isArray(x) ? 'array' : typeof x);
|
|
35
|
+
return typeOf(a) === typeOf(b);
|
|
36
|
+
}
|
|
37
|
+
function _makeTypedGet(value, exposeFunc) {
|
|
38
|
+
return (param, fallback) => {
|
|
39
|
+
var _a;
|
|
40
|
+
const found = (_a = value === null || value === void 0 ? void 0 : value[param]) !== null && _a !== void 0 ? _a : null;
|
|
41
|
+
if (found == null) {
|
|
42
|
+
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
43
|
+
}
|
|
44
|
+
if (fallback != null && !_isTypeMatch(found, fallback)) {
|
|
45
|
+
return (fallback !== null && fallback !== void 0 ? fallback : null);
|
|
46
|
+
}
|
|
47
|
+
exposeFunc === null || exposeFunc === void 0 ? void 0 : exposeFunc(param);
|
|
48
|
+
return found;
|
|
49
|
+
};
|
|
50
|
+
}
|
package/src/StatsigTypes.d.ts
CHANGED
|
@@ -1,27 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
receivedAt?: number;
|
|
8
|
-
};
|
|
9
|
-
type EvaluatedSpec = {
|
|
1
|
+
import { EvaluationDetails, ExperimentEvaluation, GateEvaluation, LayerEvaluation } from './EvaluationTypes';
|
|
2
|
+
import { Flatten } from './UtitlityTypes';
|
|
3
|
+
export type TypedGet = <T = unknown>(key: string, fallback?: T) => TypedReturn<T>;
|
|
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
|
+
export type SpecType = 'gate' | 'dynamic_config' | 'experiment' | 'layer';
|
|
6
|
+
export type FeatureGate = Flatten<{
|
|
10
7
|
readonly name: string;
|
|
11
8
|
readonly ruleID: string;
|
|
12
9
|
readonly details: EvaluationDetails;
|
|
13
|
-
};
|
|
14
|
-
export type FeatureGate = EvaluatedSpec & {
|
|
15
10
|
readonly value: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
readonly __evaluation: GateEvaluation | null;
|
|
12
|
+
}>;
|
|
13
|
+
export type Experiment = Flatten<{
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly ruleID: string;
|
|
16
|
+
readonly details: EvaluationDetails;
|
|
18
17
|
readonly value: Record<string, unknown>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
readonly groupName: string | null;
|
|
19
|
+
readonly __evaluation: ExperimentEvaluation | null;
|
|
20
|
+
readonly get: TypedGet;
|
|
21
|
+
}>;
|
|
22
|
+
export type DynamicConfig = Flatten<Experiment>;
|
|
23
|
+
export type Layer = Flatten<{
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly ruleID: string;
|
|
26
|
+
readonly details: EvaluationDetails;
|
|
27
|
+
readonly groupName: string | null;
|
|
28
|
+
readonly __value: Record<string, unknown>;
|
|
29
|
+
readonly __evaluation: LayerEvaluation | null;
|
|
30
|
+
readonly get: TypedGet;
|
|
31
|
+
}>;
|
|
32
|
+
export type AnyConfigBasedStatsigType = DynamicConfig | Experiment | Layer;
|
|
33
|
+
export type AnyStatsigType = FeatureGate | AnyConfigBasedStatsigType;
|
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, details, ruleID, value) {
|
|
6
|
-
return {
|
|
7
|
-
name: name,
|
|
8
|
-
details: details,
|
|
9
|
-
ruleID: ruleID !== null && ruleID !== void 0 ? ruleID : DEFAULT_RULE,
|
|
10
|
-
value: value === true,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
exports.makeFeatureGate = makeFeatureGate;
|
|
14
|
-
function makeDynamicConfig(name, details, ruleID, value) {
|
|
15
|
-
return {
|
|
16
|
-
name: name,
|
|
17
|
-
details: details,
|
|
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, details, ruleID, getValue) {
|
|
24
|
-
return {
|
|
25
|
-
name: name,
|
|
26
|
-
details: details,
|
|
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,12 +1,11 @@
|
|
|
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
|
-
customIDs?:
|
|
5
|
+
customIDs?: {
|
|
6
|
+
[key: string]: string | undefined;
|
|
7
|
+
stableID?: string;
|
|
8
|
+
};
|
|
10
9
|
email?: string;
|
|
11
10
|
ip?: string;
|
|
12
11
|
userAgent?: string;
|
|
@@ -19,6 +18,6 @@ export type StatsigUser = ({
|
|
|
19
18
|
export type StatsigUserInternal = StatsigUser & {
|
|
20
19
|
statsigEnvironment?: StatsigEnvironment;
|
|
21
20
|
};
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
21
|
+
export declare function _normalizeUser(original: StatsigUser, environment?: StatsigEnvironment): StatsigUser;
|
|
22
|
+
export declare function _getFullUserHash(user: StatsigUser | undefined): string | null;
|
|
24
23
|
export {};
|