@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
|
@@ -1,33 +1,74 @@
|
|
|
1
|
+
import { DataAdapterResult } from './StatsigDataAdapter';
|
|
1
2
|
import { DynamicConfig, Experiment, FeatureGate, Layer } from './StatsigTypes';
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
3
|
+
import { Flatten } from './UtitlityTypes';
|
|
4
|
+
export type StatsigLoadingStatus = 'Uninitialized' | 'Loading' | 'Ready';
|
|
5
|
+
type EventNameToEventDataMap = {
|
|
6
|
+
values_updated: {
|
|
7
|
+
status: StatsigLoadingStatus;
|
|
8
|
+
values: DataAdapterResult | null;
|
|
9
|
+
};
|
|
10
|
+
session_expired: object;
|
|
11
|
+
error: {
|
|
12
|
+
error: unknown;
|
|
13
|
+
};
|
|
14
|
+
logs_flushed: {
|
|
15
|
+
events: Record<string, unknown>[];
|
|
16
|
+
};
|
|
17
|
+
pre_shutdown: object;
|
|
18
|
+
gate_evaluation: {
|
|
19
|
+
gate: FeatureGate;
|
|
20
|
+
};
|
|
21
|
+
dynamic_config_evaluation: {
|
|
22
|
+
dynamicConfig: DynamicConfig;
|
|
23
|
+
};
|
|
24
|
+
experiment_evaluation: {
|
|
25
|
+
experiment: Experiment;
|
|
26
|
+
};
|
|
27
|
+
layer_evaluation: {
|
|
28
|
+
layer: Layer;
|
|
29
|
+
};
|
|
27
30
|
};
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Type representing various events emitted by a Statsig client.
|
|
33
|
+
*
|
|
34
|
+
* `values_updated` - When the Statsig clients internal values change as the result of an initialize/update operation.
|
|
35
|
+
*
|
|
36
|
+
* `error` - When an unexpected error occurs within the Statsig client.
|
|
37
|
+
*
|
|
38
|
+
* `logs_flushed` - When queued StatsigEvents are flushed to Statsig servers.
|
|
39
|
+
*
|
|
40
|
+
* `pre_shutdown` - Fired just before the SDK is shutdown
|
|
41
|
+
*
|
|
42
|
+
* `gate_evaluation` - Fired when any gate is checked from the Statsig client.
|
|
43
|
+
*
|
|
44
|
+
* `dynamic_config_evaluation` - Fired when any dyanamic config is checked from the Statsig client.
|
|
45
|
+
*
|
|
46
|
+
* `experiment_evaluation` - Fired when any experiment is checked from the Statsig client.
|
|
47
|
+
*
|
|
48
|
+
* `layer_evaluation` - Fired when any layer is checked from the Statsig client.
|
|
49
|
+
*/
|
|
50
|
+
export type AnyStatsigClientEvent = Flatten<{
|
|
51
|
+
[K in keyof EventNameToEventDataMap]: {
|
|
52
|
+
name: K;
|
|
53
|
+
} & EventNameToEventDataMap[K];
|
|
54
|
+
}[keyof EventNameToEventDataMap]>;
|
|
55
|
+
export type StatsigClientEvent<T> = Extract<AnyStatsigClientEvent, {
|
|
56
|
+
name: T;
|
|
57
|
+
}>;
|
|
58
|
+
export type AnyStatsigClientEventListener = StatsigClientEventCallback<StatsigClientEventName>;
|
|
59
|
+
export type StatsigClientEventName = AnyStatsigClientEvent['name'] | '*';
|
|
60
|
+
export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? AnyStatsigClientEvent : StatsigClientEvent<T>) => void;
|
|
29
61
|
export interface StatsigClientEventEmitterInterface {
|
|
30
62
|
readonly loadingStatus: StatsigLoadingStatus;
|
|
31
|
-
on(event:
|
|
32
|
-
off(event:
|
|
63
|
+
on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
64
|
+
off<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
65
|
+
/**
|
|
66
|
+
* (Statsig Use Only) - Same as .on() but logs errors to sdk_exception
|
|
67
|
+
*/
|
|
68
|
+
$on<T extends StatsigClientEventName>(event: T, listener: StatsigClientEventCallback<T>): void;
|
|
69
|
+
/**
|
|
70
|
+
* (Statsig Use Only) - Emit StatsigClientEvents
|
|
71
|
+
*/
|
|
72
|
+
$emt(event: AnyStatsigClientEvent): void;
|
|
33
73
|
}
|
|
74
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { NetworkPriority } from './NetworkConfig';
|
|
2
|
+
import type { AnyStatsigOptions, NetworkConfigCommon } from './StatsigOptionsCommon';
|
|
3
|
+
import { StatsigUser } from './StatsigUser';
|
|
4
|
+
export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap' | 'Prefetch';
|
|
5
|
+
export type DataAdapterResult = {
|
|
6
|
+
readonly source: DataSource;
|
|
7
|
+
readonly data: string;
|
|
8
|
+
readonly receivedAt: number;
|
|
9
|
+
};
|
|
10
|
+
export type DataAdapterAsyncOptions = {
|
|
11
|
+
/**
|
|
12
|
+
* The maximum amount of time (in milliseconds) this operation is permitted to run.
|
|
13
|
+
* If the timeout is hit, null is returned but any in-flight requests are kept alive with results going to cache for future updates.
|
|
14
|
+
*
|
|
15
|
+
* Note: If no timeout is given, the {@link NetworkConfigCommon.networkTimeoutMs|StatsigOptions.networkConfig.networkTimeoutMs} is used.
|
|
16
|
+
*/
|
|
17
|
+
readonly timeoutMs?: NetworkConfigCommon['networkTimeoutMs'];
|
|
18
|
+
/**
|
|
19
|
+
* The priority that should be applied to the Http request that is fired.
|
|
20
|
+
*
|
|
21
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/fetch#priority
|
|
22
|
+
*
|
|
23
|
+
* default: 'auto'
|
|
24
|
+
*/
|
|
25
|
+
readonly priority?: NetworkPriority;
|
|
26
|
+
};
|
|
27
|
+
export declare const DataAdapterCachePrefix = "statsig.cached";
|
|
28
|
+
/**
|
|
29
|
+
* Describes a type that is used during intialize/update operations of a Statsig client.
|
|
30
|
+
*
|
|
31
|
+
* See below to find the default adapters, but know that it is possible to create your
|
|
32
|
+
* own StatsigDataAdapter and provide it via `StatsigOptions.dataAdapter`.
|
|
33
|
+
*
|
|
34
|
+
* defaults:
|
|
35
|
+
*
|
|
36
|
+
* - {@link StatsigClient} uses {@link EvaluationsDataAdapter}
|
|
37
|
+
*
|
|
38
|
+
* - {@link StatsigOnDeviceEvalClient} uses {@link SpecsDataAdapter}
|
|
39
|
+
*/
|
|
40
|
+
type DataAdapterCommon = {
|
|
41
|
+
/**
|
|
42
|
+
* Called when the StatsigDataAdapter is attached to the Statsig client instance during construction.
|
|
43
|
+
* @param {string} sdkKey The SDK key being used by the Statsig client.
|
|
44
|
+
* @param {StatsigOptionsCommon | null} options The StatsigOptions being used by the Statsig client.
|
|
45
|
+
*/
|
|
46
|
+
readonly attach: (sdkKey: string, options: AnyStatsigOptions | null) => void;
|
|
47
|
+
/**
|
|
48
|
+
* (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
|
|
49
|
+
*
|
|
50
|
+
* @param {Record<string, DataAdapterResult>} cache The values to merge into _inMemoryCache
|
|
51
|
+
*/
|
|
52
|
+
readonly __primeInMemoryCache: (cache: Record<string, DataAdapterResult>) => void;
|
|
53
|
+
};
|
|
54
|
+
export type EvaluationsDataAdapter = DataAdapterCommon & {
|
|
55
|
+
/**
|
|
56
|
+
* Synchronously get evaluation data for the given user. Called during initializeSync and/or updateUserSync.
|
|
57
|
+
*
|
|
58
|
+
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
59
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
60
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
61
|
+
*/
|
|
62
|
+
readonly getDataSync: (user: StatsigUser) => DataAdapterResult | null;
|
|
63
|
+
/**
|
|
64
|
+
* Asynchronously get evaluation data for the given user. Called during initializeAsync and/or updateUserAsync.
|
|
65
|
+
*
|
|
66
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
67
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
68
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
69
|
+
*/
|
|
70
|
+
readonly getDataAsync: (current: DataAdapterResult | null, user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Manually trigger a fetch for new evaluations data for the given user.
|
|
73
|
+
*
|
|
74
|
+
* @param {StatsigUser} user The StatsigUser to get data for.
|
|
75
|
+
*/
|
|
76
|
+
readonly prefetchData: (user: StatsigUser, options?: DataAdapterAsyncOptions) => Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Manually set evaluations data for the given user.
|
|
79
|
+
*
|
|
80
|
+
* @param {StatsigUser} user The StatsigUser this data is for.
|
|
81
|
+
*/
|
|
82
|
+
readonly setData: (data: string, user: StatsigUser) => void;
|
|
83
|
+
};
|
|
84
|
+
export type SpecsDataAdapter = DataAdapterCommon & {
|
|
85
|
+
/**
|
|
86
|
+
* Synchronously get specs data. Called during initializeSync and/or updateUserSync.
|
|
87
|
+
* It is also called during async update operations before StatsigDataAdapter.getDataAsync is called.
|
|
88
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
89
|
+
*/
|
|
90
|
+
readonly getDataSync: () => DataAdapterResult | null;
|
|
91
|
+
/**
|
|
92
|
+
* Asynchronously get specs data. Called during initializeAsync and/or updateUserAsync.
|
|
93
|
+
*
|
|
94
|
+
* @param {DataAdapterResult | null} current The data that was found synchronously (Cache). Will be used as fallback if getDataAsync fails
|
|
95
|
+
* @returns {DataAdapterResult | null} The data that was found for the given StatsigUser.
|
|
96
|
+
*/
|
|
97
|
+
readonly getDataAsync: (current: DataAdapterResult | null, options?: DataAdapterAsyncOptions) => Promise<DataAdapterResult | null>;
|
|
98
|
+
/**
|
|
99
|
+
* Manually trigger a fetch for new specs data.
|
|
100
|
+
*/
|
|
101
|
+
readonly prefetchData: (options?: DataAdapterAsyncOptions) => Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Manually set specs data (Bootstrap).
|
|
104
|
+
*/
|
|
105
|
+
readonly setData: (data: string) => void;
|
|
106
|
+
};
|
|
107
|
+
export {};
|
package/src/StatsigEvent.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DynamicConfig, FeatureGate } from './StatsigTypes';
|
|
1
|
+
import { SecondaryExposure } from './EvaluationTypes';
|
|
2
|
+
import { DynamicConfig, FeatureGate, Layer } from './StatsigTypes';
|
|
3
3
|
import { StatsigUser } from './StatsigUser';
|
|
4
|
-
export type SecondaryExposure = {
|
|
5
|
-
gate: string;
|
|
6
|
-
gateValue: string;
|
|
7
|
-
ruleID: string;
|
|
8
|
-
};
|
|
9
4
|
export type StatsigEvent = {
|
|
10
5
|
eventName: string;
|
|
11
6
|
value?: string | number | null;
|
|
@@ -13,19 +8,15 @@ export type StatsigEvent = {
|
|
|
13
8
|
[key: string]: string;
|
|
14
9
|
} | null;
|
|
15
10
|
};
|
|
16
|
-
export type StatsigEventInternal = StatsigEvent & {
|
|
11
|
+
export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
|
|
17
12
|
user: StatsigUser | null;
|
|
18
13
|
time: number;
|
|
14
|
+
metadata?: {
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
} | null;
|
|
19
17
|
secondaryExposures?: SecondaryExposure[];
|
|
20
18
|
};
|
|
21
|
-
export declare
|
|
22
|
-
export declare
|
|
23
|
-
export declare
|
|
24
|
-
export declare
|
|
25
|
-
rule_id: string;
|
|
26
|
-
explicit_parameters: string[];
|
|
27
|
-
undelegated_secondary_exposures?: SecondaryExposure[];
|
|
28
|
-
secondary_exposures: SecondaryExposure[];
|
|
29
|
-
allocated_experiment_name: string;
|
|
30
|
-
source: DataSource;
|
|
31
|
-
}): 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,57 +1,66 @@
|
|
|
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
|
-
metadata: metadata,
|
|
13
|
-
secondaryExposures
|
|
12
|
+
metadata: _addEvaluationDetailsToMetadata(details, metadata),
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return
|
|
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, {
|
|
33
33
|
config: config.name,
|
|
34
34
|
ruleID: config.ruleID,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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 : [];
|
|
44
44
|
if (isExplicit) {
|
|
45
|
-
allocatedExperiment =
|
|
46
|
-
secondaryExposures =
|
|
45
|
+
allocatedExperiment = (_c = evaluation.allocated_experiment_name) !== null && _c !== void 0 ? _c : '';
|
|
46
|
+
secondaryExposures = evaluation.secondary_exposures;
|
|
47
47
|
}
|
|
48
|
-
return
|
|
49
|
-
config:
|
|
50
|
-
parameterName
|
|
51
|
-
ruleID:
|
|
52
|
-
allocatedExperiment
|
|
48
|
+
return _createExposure(LAYER_EXPOSURE_NAME, user, layer.details, {
|
|
49
|
+
config: layer.name,
|
|
50
|
+
parameterName,
|
|
51
|
+
ruleID: layer.ruleID,
|
|
52
|
+
allocatedExperiment,
|
|
53
53
|
isExplicitParameter: String(isExplicit),
|
|
54
|
-
reason: spec.source,
|
|
55
54
|
}, secondaryExposures);
|
|
56
|
-
}
|
|
57
|
-
exports.
|
|
55
|
+
};
|
|
56
|
+
exports._createLayerParameterExposure = _createLayerParameterExposure;
|
|
57
|
+
const _addEvaluationDetailsToMetadata = (details, metadata) => {
|
|
58
|
+
metadata['reason'] = details.reason;
|
|
59
|
+
if (details.lcut) {
|
|
60
|
+
metadata['lcut'] = String(details.lcut);
|
|
61
|
+
}
|
|
62
|
+
if (details.receivedAt) {
|
|
63
|
+
metadata['receivedAt'] = String(details.receivedAt);
|
|
64
|
+
}
|
|
65
|
+
return metadata;
|
|
66
|
+
};
|
package/src/StatsigMetadata.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.0.1-beta.40";
|
|
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 = '0.0.1-beta.40';
|
|
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,12 +1,69 @@
|
|
|
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;
|
|
23
|
+
/**
|
|
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`
|
|
27
|
+
*/
|
|
28
|
+
logEventUrl?: string;
|
|
29
|
+
/**
|
|
30
|
+
* The URL used to flush queued events via {@link window.navigator.sendBeacon} (web only). Takes precedence over {@link StatsigOptionsCommon.api}.
|
|
31
|
+
*
|
|
32
|
+
* default: `https://featuregates.org/v1/initialize`
|
|
33
|
+
*/
|
|
34
|
+
logEventBeaconUrl?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The maximum amount of time (in milliseconds) that any network request can take
|
|
37
|
+
* before timing out.
|
|
38
|
+
*
|
|
39
|
+
* default: `10,000 ms` (10 seconds)
|
|
40
|
+
*/
|
|
41
|
+
networkTimeoutMs?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Intended for testing purposes. Prevents any network requests being made.
|
|
44
|
+
*/
|
|
45
|
+
preventAllNetworkTraffic?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Overrides the default networking layer used by the Statsig client.
|
|
48
|
+
* By default, the client use `fetch`, but overriding this
|
|
49
|
+
* you could use `axios` or raw `XMLHttpRequest`
|
|
50
|
+
*
|
|
51
|
+
* default: `Fetch API`
|
|
52
|
+
*
|
|
53
|
+
* @param {string} url Where the request is going.
|
|
54
|
+
* @param {NetworkArgs} args Configuration for the network request.
|
|
55
|
+
* @returns {Response}
|
|
56
|
+
*/
|
|
57
|
+
networkOverrideFunc?: (url: string, args: NetworkArgs) => Promise<Response>;
|
|
58
|
+
};
|
|
59
|
+
/** Options for configuring a Statsig client. */
|
|
60
|
+
export type StatsigOptionsCommon<NetworkConfig extends NetworkConfigCommon> = StatsigRuntimeMutableOptions & {
|
|
61
|
+
/**
|
|
62
|
+
* Allows for fine grained control over which api or urls are hit for specific Statsig network requests.
|
|
63
|
+
*
|
|
64
|
+
* For defaults see {@link StatsigClientUrlOverrideOptions}
|
|
65
|
+
*/
|
|
66
|
+
networkConfig?: NetworkConfig;
|
|
10
67
|
/**
|
|
11
68
|
* An object you can use to set environment variables that apply to all of your users
|
|
12
69
|
* in the same session.
|
|
@@ -18,30 +75,41 @@ export type StatsigOptionsCommon = {
|
|
|
18
75
|
overrideStableID?: string;
|
|
19
76
|
/**
|
|
20
77
|
* How much information is allowed to be printed to the console.
|
|
21
|
-
*
|
|
78
|
+
*
|
|
79
|
+
* default: {@link LogLevel.Warn}
|
|
22
80
|
*/
|
|
23
81
|
logLevel?: LogLevel;
|
|
24
|
-
/**
|
|
25
|
-
* StatsigDataProvider implementors used to customize the initialization flow.
|
|
26
|
-
* Default: LocalStorageCache then Network
|
|
27
|
-
*/
|
|
28
|
-
dataProviders?: StatsigDataProvider[];
|
|
29
|
-
/**
|
|
30
|
-
* The maximum amount of time (in milliseconds) that any network request can take
|
|
31
|
-
* before timing out. Default: 10,000 (10 seconds)
|
|
32
|
-
*/
|
|
33
|
-
networkTimeoutMs?: number;
|
|
34
82
|
/**
|
|
35
83
|
* The maximum number of events to batch before flushing logs to Statsig.
|
|
36
|
-
*
|
|
84
|
+
*
|
|
85
|
+
* default: `50`
|
|
37
86
|
*/
|
|
38
87
|
loggingBufferMaxSize?: number;
|
|
39
88
|
/**
|
|
40
89
|
* How often (in milliseconds) to flush logs to Statsig.
|
|
41
|
-
*
|
|
90
|
+
*
|
|
91
|
+
* default: `10,000 ms` (10 seconds)
|
|
42
92
|
*/
|
|
43
93
|
loggingIntervalMs?: number;
|
|
94
|
+
/**
|
|
95
|
+
* An implementor of {@link OverrideAdapter}, used to alter evaluations before its
|
|
96
|
+
* returned to the caller of a check api (checkGate/getExperiment etc).
|
|
97
|
+
*/
|
|
98
|
+
overrideAdapter?: OverrideAdapter;
|
|
99
|
+
/**
|
|
100
|
+
* (Web only) Should the 'current page' url be included with logged events.
|
|
101
|
+
*
|
|
102
|
+
* default: true
|
|
103
|
+
*/
|
|
104
|
+
includeCurrentPageUrlWithEvents?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Whether or not Statsig should use raw JSON for network requests where possible.
|
|
107
|
+
*
|
|
108
|
+
* default: `false`
|
|
109
|
+
*/
|
|
110
|
+
disableStatsigEncoding?: boolean;
|
|
44
111
|
};
|
|
112
|
+
export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;
|
|
45
113
|
export type StatsigEnvironment = {
|
|
46
114
|
tier?: string;
|
|
47
115
|
[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,22 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type
|
|
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<{
|
|
5
7
|
readonly name: string;
|
|
6
8
|
readonly ruleID: string;
|
|
7
|
-
readonly
|
|
8
|
-
};
|
|
9
|
-
export type FeatureGate = EvaluatedSpec & {
|
|
9
|
+
readonly details: EvaluationDetails;
|
|
10
10
|
readonly value: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
readonly __evaluation: GateEvaluation | null;
|
|
12
|
+
}>;
|
|
13
|
+
export type Experiment = Flatten<{
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly ruleID: string;
|
|
16
|
+
readonly details: EvaluationDetails;
|
|
13
17
|
readonly value: Record<string, unknown>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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;
|