@statsig/client-core 0.0.1-beta.29 → 0.0.1-beta.30

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.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/src/$_StatsigGlobal.d.ts +2 -0
  3. package/src/$_StatsigGlobal.js +10 -4
  4. package/src/ClientInterfaces.d.ts +20 -9
  5. package/src/DataAdapterCore.d.ts +2 -2
  6. package/src/DataAdapterCore.js +6 -6
  7. package/src/Diagnostics.js +4 -1
  8. package/src/DownloadConfigSpecsResponse.d.ts +41 -0
  9. package/src/DownloadConfigSpecsResponse.js +2 -0
  10. package/src/ErrorBoundary.js +4 -2
  11. package/src/EventLogger.d.ts +3 -4
  12. package/src/EventLogger.js +18 -19
  13. package/src/Hashing.d.ts +2 -2
  14. package/src/Hashing.js +7 -7
  15. package/src/NetworkCore.d.ts +5 -2
  16. package/src/NetworkCore.js +27 -12
  17. package/src/NetworkDefaults.d.ts +5 -0
  18. package/src/NetworkDefaults.js +8 -0
  19. package/src/NetworkParams.d.ts +9 -0
  20. package/src/NetworkParams.js +13 -0
  21. package/src/OverrideAdapter.d.ts +0 -7
  22. package/src/OverrideAdapter.js +0 -22
  23. package/src/SDKType.d.ts +8 -0
  24. package/src/SDKType.js +19 -0
  25. package/src/SafeJs.d.ts +4 -0
  26. package/src/SafeJs.js +27 -0
  27. package/src/SessionID.js +4 -4
  28. package/src/StableID.js +2 -2
  29. package/src/StatsigClientBase.d.ts +4 -4
  30. package/src/StatsigClientBase.js +7 -6
  31. package/src/StatsigClientEventEmitter.d.ts +1 -0
  32. package/src/StatsigDataAdapter.d.ts +2 -2
  33. package/src/StatsigEvent.d.ts +4 -4
  34. package/src/StatsigEvent.js +20 -20
  35. package/src/StatsigMetadata.d.ts +1 -2
  36. package/src/StatsigMetadata.js +1 -1
  37. package/src/StatsigOptionsCommon.d.ts +27 -12
  38. package/src/StatsigTypeFactories.js +9 -22
  39. package/src/StorageProvider.d.ts +10 -10
  40. package/src/StorageProvider.js +27 -27
  41. package/src/VisibilityObserving.d.ts +8 -0
  42. package/src/VisibilityObserving.js +30 -0
  43. package/src/index.d.ts +6 -1
  44. package/src/index.js +6 -1
  45. package/src/VisibilityChangeObserver.d.ts +0 -13
  46. package/src/VisibilityChangeObserver.js +0 -39
package/src/SDKType.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SDKType = void 0;
4
+ const SDK_CLIENT = {};
5
+ let suffix;
6
+ exports.SDKType = {
7
+ _get: (sdkKey) => {
8
+ var _a;
9
+ return ((_a = SDK_CLIENT[sdkKey]) !== null && _a !== void 0 ? _a : 'js-mono') + (suffix !== null && suffix !== void 0 ? suffix : '');
10
+ },
11
+ _setClientType(sdkKey, client) {
12
+ SDK_CLIENT[sdkKey] = client;
13
+ },
14
+ _setBindingType(binding) {
15
+ if (!suffix || suffix === '-react') {
16
+ suffix = '-' + binding;
17
+ }
18
+ },
19
+ };
@@ -0,0 +1,4 @@
1
+ export declare const _getWindowSafe: () => Window | null;
2
+ export declare const _getDocumentSafe: () => Document | null;
3
+ export declare const _addWindowEventListenerSafe: (key: string, listener: () => void) => void;
4
+ export declare const _addDocumentEventListenerSafe: (key: string, listener: () => void) => void;
package/src/SafeJs.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._addDocumentEventListenerSafe = exports._addWindowEventListenerSafe = exports._getDocumentSafe = exports._getWindowSafe = void 0;
4
+ const _getWindowSafe = () => {
5
+ return typeof window !== 'undefined' ? window : null;
6
+ };
7
+ exports._getWindowSafe = _getWindowSafe;
8
+ const _getDocumentSafe = () => {
9
+ var _a;
10
+ const win = (0, exports._getWindowSafe)();
11
+ return (_a = win === null || win === void 0 ? void 0 : win.document) !== null && _a !== void 0 ? _a : null;
12
+ };
13
+ exports._getDocumentSafe = _getDocumentSafe;
14
+ const _addWindowEventListenerSafe = (key, listener) => {
15
+ const win = (0, exports._getWindowSafe)();
16
+ if (typeof (win === null || win === void 0 ? void 0 : win.addEventListener) === 'function') {
17
+ win.addEventListener(key, listener);
18
+ }
19
+ };
20
+ exports._addWindowEventListenerSafe = _addWindowEventListenerSafe;
21
+ const _addDocumentEventListenerSafe = (key, listener) => {
22
+ const doc = (0, exports._getDocumentSafe)();
23
+ if (typeof (doc === null || doc === void 0 ? void 0 : doc.addEventListener) === 'function') {
24
+ doc.addEventListener(key, listener);
25
+ }
26
+ };
27
+ exports._addDocumentEventListenerSafe = _addDocumentEventListenerSafe;
package/src/SessionID.js CHANGED
@@ -20,12 +20,12 @@ const PROMISE_MAP = {};
20
20
  const MAX_SESSION_IDLE_TIME = 30 * 60 * 1000; // 30 minutes
21
21
  const MAX_SESSION_AGE = 4 * 60 * 60 * 1000; // 4 hours
22
22
  exports.SessionID = {
23
- get: (sdkKey) => __awaiter(void 0, void 0, void 0, function* () {
23
+ get: (sdkKey) => {
24
24
  if (PROMISE_MAP[sdkKey] != null) {
25
25
  return PROMISE_MAP[sdkKey];
26
26
  }
27
27
  return (PROMISE_MAP[sdkKey] = exports.SessionID._getPromise(sdkKey));
28
- }),
28
+ },
29
29
  _getPromise: (sdkKey) => __awaiter(void 0, void 0, void 0, function* () {
30
30
  var _a;
31
31
  let session = SESSION_ID_MAP[sdkKey];
@@ -83,11 +83,11 @@ function _getSessionIDStorageKey(sdkKey) {
83
83
  }
84
84
  function _persistToStorage(session, sdkKey) {
85
85
  const storageKey = _getSessionIDStorageKey(sdkKey);
86
- (0, StorageProvider_1.setObjectInStorage)(storageKey, session).catch(() => {
86
+ (0, StorageProvider_1._setObjectInStorage)(storageKey, session).catch(() => {
87
87
  Log_1.Log.warn('Failed to save SessionID');
88
88
  });
89
89
  }
90
90
  function _loadFromStorage(sdkKey) {
91
91
  const storageKey = _getSessionIDStorageKey(sdkKey);
92
- return (0, StorageProvider_1.getObjectFromStorage)(storageKey);
92
+ return (0, StorageProvider_1._getObjectFromStorage)(storageKey);
93
93
  }
package/src/StableID.js CHANGED
@@ -39,11 +39,11 @@ function _getStableIDStorageKey(sdkKey) {
39
39
  }
40
40
  function _persistToStorage(stableID, sdkKey) {
41
41
  const storageKey = _getStableIDStorageKey(sdkKey);
42
- (0, StorageProvider_1.setObjectInStorage)(storageKey, stableID).catch(() => {
42
+ (0, StorageProvider_1._setObjectInStorage)(storageKey, stableID).catch(() => {
43
43
  Log_1.Log.warn('Failed to save StableID');
44
44
  });
45
45
  }
46
46
  function _loadFromStorage(sdkKey) {
47
47
  const storageKey = _getStableIDStorageKey(sdkKey);
48
- return (0, StorageProvider_1.getObjectFromStorage)(storageKey);
48
+ return (0, StorageProvider_1._getObjectFromStorage)(storageKey);
49
49
  }
@@ -7,11 +7,11 @@ import { OverrideAdapter } from './OverrideAdapter';
7
7
  import { StatsigClientEvent, StatsigClientEventCallback, StatsigClientEventEmitterInterface, StatsigClientEventName, StatsigLoadingStatus } from './StatsigClientEventEmitter';
8
8
  import { DataAdapterResult, EvaluationsDataAdapter, SpecsDataAdapter } from './StatsigDataAdapter';
9
9
  import { StatsigEventInternal } from './StatsigEvent';
10
- import { StatsigOptionsCommon, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
10
+ import { AnyStatsigOptions, StatsigRuntimeMutableOptions } from './StatsigOptionsCommon';
11
11
  export type StatsigClientEmitEventFunc = (event: StatsigClientEvent) => void;
12
12
  export type StatsigContext = {
13
13
  sdkKey: string;
14
- options: StatsigOptionsCommon;
14
+ options: AnyStatsigOptions;
15
15
  sessionID: string;
16
16
  values: unknown;
17
17
  };
@@ -19,12 +19,12 @@ export declare abstract class StatsigClientBase<TAdapter extends EvaluationsData
19
19
  loadingStatus: StatsigLoadingStatus;
20
20
  readonly dataAdapter: TAdapter;
21
21
  protected readonly _sdkKey: string;
22
- protected readonly _options: StatsigOptionsCommon;
22
+ protected readonly _options: AnyStatsigOptions;
23
23
  protected readonly _errorBoundary: ErrorBoundary;
24
24
  protected readonly _logger: EventLogger;
25
25
  protected readonly _overrideAdapter: OverrideAdapter | null;
26
26
  private _listeners;
27
- constructor(sdkKey: string, adapter: TAdapter, network: NetworkCore, options: StatsigOptionsCommon | null);
27
+ constructor(sdkKey: string, adapter: TAdapter, network: NetworkCore, options: AnyStatsigOptions | null);
28
28
  /**
29
29
  * Updates runtime configuration options for the SDK, allowing toggling of certain behaviors such as logging and storage to comply with user preferences or regulations such as GDPR.
30
30
  *
@@ -24,7 +24,7 @@ class StatsigClientBase {
24
24
  this._listeners = {};
25
25
  this._sdkKey = sdkKey;
26
26
  this._options = options !== null && options !== void 0 ? options : {};
27
- (options === null || options === void 0 ? void 0 : options.disableStorage) && StorageProvider_1.Storage.setDisabled(true);
27
+ (options === null || options === void 0 ? void 0 : options.disableStorage) && StorageProvider_1.Storage._setDisabled(true);
28
28
  (options === null || options === void 0 ? void 0 : options.overrideStableID) &&
29
29
  StableID_1.StableID.setOverride(options.overrideStableID, sdkKey);
30
30
  Log_1.Log.level = (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : Log_1.LogLevel.Warn;
@@ -34,12 +34,13 @@ class StatsigClientBase {
34
34
  this._emit({ name: 'session_expired' });
35
35
  }, sdkKey);
36
36
  this._errorBoundary = new ErrorBoundary_1.ErrorBoundary(sdkKey);
37
- __STATSIG__ = __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {};
38
- const instances = (_c = __STATSIG__.instances) !== null && _c !== void 0 ? _c : {};
37
+ const statsigGlobal = __STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {};
38
+ const instances = (_c = statsigGlobal.instances) !== null && _c !== void 0 ? _c : {};
39
39
  const inst = this;
40
40
  instances[sdkKey] = inst;
41
- __STATSIG__.instances = instances;
42
- __STATSIG__.lastInstance = inst;
41
+ statsigGlobal.lastInstance = inst;
42
+ statsigGlobal.instances = instances;
43
+ __STATSIG__ = statsigGlobal;
43
44
  this.dataAdapter = adapter;
44
45
  this.dataAdapter.attach(sdkKey, options);
45
46
  }
@@ -55,7 +56,7 @@ class StatsigClientBase {
55
56
  }
56
57
  if (options.disableStorage != null) {
57
58
  this._options.disableStorage = options.disableStorage;
58
- StorageProvider_1.Storage.setDisabled(options.disableStorage);
59
+ StorageProvider_1.Storage._setDisabled(options.disableStorage);
59
60
  }
60
61
  }
61
62
  /**
@@ -52,6 +52,7 @@ export type StatsigClientEvent = Flatten<{
52
52
  name: K;
53
53
  } & EventNameToEventDataMap[K];
54
54
  }[keyof EventNameToEventDataMap]>;
55
+ export type AnyStatsigClientEventListener = StatsigClientEventCallback<StatsigClientEventName>;
55
56
  export type StatsigClientEventName = StatsigClientEvent['name'] | '*';
56
57
  export type StatsigClientEventCallback<T extends StatsigClientEventName> = (event: T extends '*' ? StatsigClientEvent : Extract<StatsigClientEvent, {
57
58
  name: T;
@@ -1,4 +1,4 @@
1
- import { StatsigOptionsCommon } from './StatsigOptionsCommon';
1
+ import { AnyStatsigOptions } from './StatsigOptionsCommon';
2
2
  import { StatsigUser } from './StatsigUser';
3
3
  export type DataSource = 'Uninitialized' | 'Loading' | 'NoValues' | 'Cache' | 'Network' | 'NetworkNotModified' | 'Bootstrap' | 'Prefetch';
4
4
  export type DataAdapterResult = {
@@ -25,7 +25,7 @@ type DataAdapterCommon = {
25
25
  * @param {string} sdkKey The SDK key being used by the Statsig client.
26
26
  * @param {StatsigOptionsCommon | null} options The StatsigOptions being used by the Statsig client.
27
27
  */
28
- readonly attach: (sdkKey: string, options: StatsigOptionsCommon | null) => void;
28
+ readonly attach: (sdkKey: string, options: AnyStatsigOptions | null) => void;
29
29
  /**
30
30
  * (Internal Use Only) - Used by \@statsig/react-native-bindings to prime the cache from AsyncStorage
31
31
  *
@@ -16,7 +16,7 @@ export type StatsigEventInternal = Omit<StatsigEvent, 'metadata'> & {
16
16
  } | null;
17
17
  secondaryExposures?: SecondaryExposure[];
18
18
  };
19
- export declare function isExposureEvent({ eventName }: StatsigEventInternal): boolean;
20
- export declare function createGateExposure(user: StatsigUser, gate: FeatureGate): StatsigEventInternal;
21
- export declare function createConfigExposure(user: StatsigUser, config: DynamicConfig): StatsigEventInternal;
22
- export declare function createLayerParameterExposure(user: StatsigUser, layer: Layer, parameterName: string): 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;
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLayerParameterExposure = exports.createConfigExposure = exports.createGateExposure = exports.isExposureEvent = void 0;
3
+ exports._createLayerParameterExposure = exports._createConfigExposure = exports._createGateExposure = exports._isExposureEvent = void 0;
4
4
  const CONFIG_EXPOSURE_NAME = 'statsig::config_exposure';
5
5
  const GATE_EXPOSURE_NAME = 'statsig::gate_exposure';
6
6
  const LAYER_EXPOSURE_NAME = 'statsig::layer_exposure';
7
- function createExposure(eventName, user, details, metadata, secondaryExposures) {
7
+ const _createExposure = (eventName, user, details, metadata, secondaryExposures) => {
8
8
  return {
9
9
  eventName,
10
10
  user,
@@ -13,29 +13,29 @@ function createExposure(eventName, user, details, metadata, secondaryExposures)
13
13
  secondaryExposures,
14
14
  time: Date.now(),
15
15
  };
16
- }
17
- function isExposureEvent({ eventName }) {
16
+ };
17
+ const _isExposureEvent = ({ eventName, }) => {
18
18
  return eventName === GATE_EXPOSURE_NAME || eventName === CONFIG_EXPOSURE_NAME;
19
- }
20
- exports.isExposureEvent = isExposureEvent;
21
- function createGateExposure(user, gate) {
19
+ };
20
+ exports._isExposureEvent = _isExposureEvent;
21
+ const _createGateExposure = (user, gate) => {
22
22
  var _a, _b;
23
- return createExposure(GATE_EXPOSURE_NAME, user, gate.details, {
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
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
- function createConfigExposure(user, config) {
28
+ };
29
+ exports._createGateExposure = _createGateExposure;
30
+ const _createConfigExposure = (user, config) => {
31
31
  var _a, _b;
32
- return createExposure(CONFIG_EXPOSURE_NAME, user, config.details, {
32
+ return _createExposure(CONFIG_EXPOSURE_NAME, user, config.details, {
33
33
  config: config.name,
34
34
  ruleID: config.ruleID,
35
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
- function createLayerParameterExposure(user, layer, parameterName) {
36
+ };
37
+ exports._createConfigExposure = _createConfigExposure;
38
+ const _createLayerParameterExposure = (user, layer, parameterName) => {
39
39
  var _a, _b, _c;
40
40
  const evaluation = layer.__evaluation;
41
41
  const isExplicit = ((_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.explicit_parameters) === null || _a === void 0 ? void 0 : _a.includes(parameterName)) === true;
@@ -45,16 +45,16 @@ function createLayerParameterExposure(user, layer, parameterName) {
45
45
  allocatedExperiment = (_c = evaluation.allocated_experiment_name) !== null && _c !== void 0 ? _c : '';
46
46
  secondaryExposures = evaluation.secondary_exposures;
47
47
  }
48
- return createExposure(LAYER_EXPOSURE_NAME, user, layer.details, {
48
+ return _createExposure(LAYER_EXPOSURE_NAME, user, layer.details, {
49
49
  config: layer.name,
50
50
  parameterName,
51
51
  ruleID: layer.ruleID,
52
52
  allocatedExperiment,
53
53
  isExplicitParameter: String(isExplicit),
54
54
  }, secondaryExposures);
55
- }
56
- exports.createLayerParameterExposure = createLayerParameterExposure;
57
- function _addEvaluationDetailsToMetadata(details, metadata) {
55
+ };
56
+ exports._createLayerParameterExposure = _createLayerParameterExposure;
57
+ const _addEvaluationDetailsToMetadata = (details, metadata) => {
58
58
  metadata['reason'] = details.reason;
59
59
  if (details.lcut) {
60
60
  metadata['lcut'] = String(details.lcut);
@@ -63,4 +63,4 @@ function _addEvaluationDetailsToMetadata(details, metadata) {
63
63
  metadata['receivedAt'] = String(details.receivedAt);
64
64
  }
65
65
  return metadata;
66
- }
66
+ };
@@ -1,11 +1,10 @@
1
- export declare const SDK_VERSION = "0.0.1-beta.29";
1
+ export declare const SDK_VERSION = "0.0.1-beta.30";
2
2
  export type StatsigMetadata = {
3
3
  readonly [key: string]: string | undefined;
4
4
  readonly appVersion?: string;
5
5
  readonly deviceModel?: string;
6
6
  readonly deviceModelName?: string;
7
7
  readonly locale?: string;
8
- readonly sdkType: string;
9
8
  readonly sdkVersion: string;
10
9
  readonly stableID?: string;
11
10
  readonly systemName?: string;
@@ -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 = '0.0.1-beta.29';
4
+ exports.SDK_VERSION = '0.0.1-beta.30';
5
5
  let metadata = {
6
6
  sdkVersion: exports.SDK_VERSION,
7
7
  sdkType: 'js-mono', // js-mono is overwritten by Precomp and OnDevice clients
@@ -13,25 +13,40 @@ export type StatsigRuntimeMutableOptions = {
13
13
  */
14
14
  disableStorage?: boolean;
15
15
  };
16
- /** Options for configuring a Statsig client. */
17
- export type StatsigOptionsCommon = StatsigRuntimeMutableOptions & {
16
+ export type NetworkConfigCommon = {
18
17
  /**
19
18
  * The API to use for all SDK network requests. You should not need to override this
20
- * unless you have another API that implements the Statsig API endpoints.
19
+ * unless you have a custom API that implements the Statsig endpoints.
21
20
  */
22
21
  api?: string;
23
22
  /**
24
23
  * The URL used to flush queued events via a POST request. Takes precedence over {@link StatsigOptionsCommon.api}.
25
24
  *
26
- * default: `https://api.statsig.com/v1/initialize`
25
+ * default: `https://featuregates.org/v1/initialize`
27
26
  */
28
27
  logEventUrl?: string;
29
28
  /**
30
29
  * The URL used to flush queued events via {@link window.navigator.sendBeacon} (web only). Takes precedence over {@link StatsigOptionsCommon.api}.
31
30
  *
32
- * default: `https://api.statsig.com/v1/initialize`
31
+ * default: `https://featuregates.org/v1/initialize`
33
32
  */
34
33
  logEventBeaconUrl?: string;
34
+ /**
35
+ * The maximum amount of time (in milliseconds) that any network request can take
36
+ * before timing out.
37
+ *
38
+ * default: `10,000 ms` (10 seconds)
39
+ */
40
+ networkTimeoutMs?: number;
41
+ };
42
+ /** Options for configuring a Statsig client. */
43
+ export type StatsigOptionsCommon<NetworkConfig extends NetworkConfigCommon> = StatsigRuntimeMutableOptions & {
44
+ /**
45
+ * Allows for fine grained control over which api or urls are hit for specific Statsig network requests.
46
+ *
47
+ * For defaults see {@link StatsigClientUrlOverrideOptions}
48
+ */
49
+ networkConfig?: NetworkConfig;
35
50
  /**
36
51
  * An object you can use to set environment variables that apply to all of your users
37
52
  * in the same session.
@@ -47,13 +62,6 @@ export type StatsigOptionsCommon = StatsigRuntimeMutableOptions & {
47
62
  * default: {@link LogLevel.Warn}
48
63
  */
49
64
  logLevel?: LogLevel;
50
- /**
51
- * The maximum amount of time (in milliseconds) that any network request can take
52
- * before timing out.
53
- *
54
- * default: `10,000 ms` (10 seconds)
55
- */
56
- networkTimeoutMs?: number;
57
65
  /**
58
66
  * The maximum number of events to batch before flushing logs to Statsig.
59
67
  *
@@ -77,7 +85,14 @@ export type StatsigOptionsCommon = StatsigRuntimeMutableOptions & {
77
85
  * default: true
78
86
  */
79
87
  includeCurrentPageUrlWithEvents?: boolean;
88
+ /**
89
+ * Whether or not Statsig should use raw JSON for network requests where possible.
90
+ *
91
+ * default: `false`
92
+ */
93
+ disableStatsigEncoding?: boolean;
80
94
  };
95
+ export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;
81
96
  export type StatsigEnvironment = {
82
97
  tier?: string;
83
98
  [key: string]: string | undefined;
@@ -2,41 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._mergeOverride = exports._makeLayer = exports._makeDynamicConfig = exports._makeFeatureGate = void 0;
4
4
  const DEFAULT_RULE = 'default';
5
- function _makeFeatureGate(name, details, evaluation) {
5
+ function _makeEvaluation(name, details, evaluation, value) {
6
6
  var _a;
7
7
  return {
8
8
  name,
9
9
  details,
10
10
  ruleID: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.rule_id) !== null && _a !== void 0 ? _a : DEFAULT_RULE,
11
- value: (evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) === true,
12
11
  __evaluation: evaluation,
12
+ value,
13
13
  };
14
14
  }
15
+ function _makeFeatureGate(name, details, evaluation) {
16
+ return _makeEvaluation(name, details, evaluation, (evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) === true);
17
+ }
15
18
  exports._makeFeatureGate = _makeFeatureGate;
16
19
  function _makeDynamicConfig(name, details, evaluation) {
17
- var _a, _b;
18
- return {
19
- name,
20
- details,
21
- value: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _a !== void 0 ? _a : {},
22
- ruleID: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.rule_id) !== null && _b !== void 0 ? _b : DEFAULT_RULE,
23
- groupName: null,
24
- get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value),
25
- __evaluation: evaluation,
26
- };
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) });
27
22
  }
28
23
  exports._makeDynamicConfig = _makeDynamicConfig;
29
24
  function _makeLayer(name, details, evaluation, exposeFunc) {
30
- var _a, _b, _c;
31
- return {
32
- name,
33
- details,
34
- get: _makeTypedGet(evaluation === null || evaluation === void 0 ? void 0 : evaluation.value, exposeFunc),
35
- ruleID: (_a = evaluation === null || evaluation === void 0 ? void 0 : evaluation.rule_id) !== null && _a !== void 0 ? _a : DEFAULT_RULE,
36
- groupName: (_b = evaluation === null || evaluation === void 0 ? void 0 : evaluation.group_name) !== null && _b !== void 0 ? _b : null,
37
- __value: (_c = evaluation === null || evaluation === void 0 ? void 0 : evaluation.value) !== null && _c !== void 0 ? _c : {},
38
- __evaluation: evaluation,
39
- };
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 : {} });
40
27
  }
41
28
  exports._makeLayer = _makeLayer;
42
29
  function _mergeOverride(original, overridden, value, exposeFunc) {
@@ -1,16 +1,16 @@
1
1
  type StorageProvider = {
2
- getProviderName: () => string;
3
- getItem: (key: string) => Promise<string | null>;
4
- setItem: (key: string, value: string) => Promise<void>;
5
- removeItem: (key: string) => Promise<void>;
6
- getAllKeys: () => Promise<readonly string[]>;
7
- getItemSync?: (key: string) => string | null;
2
+ _getProviderName: () => string;
3
+ _getItem: (key: string) => Promise<string | null>;
4
+ _setItem: (key: string, value: string) => Promise<void>;
5
+ _removeItem: (key: string) => Promise<void>;
6
+ _getAllKeys: () => Promise<readonly string[]>;
7
+ _getItemSync?: (key: string) => string | null;
8
8
  };
9
9
  type StorageProviderManagment = {
10
- setProvider: (newProvider: StorageProvider) => void;
11
- setDisabled: (isDisabled: boolean) => void;
10
+ _setProvider: (newProvider: StorageProvider) => void;
11
+ _setDisabled: (isDisabled: boolean) => void;
12
12
  };
13
13
  export declare const Storage: StorageProvider & StorageProviderManagment;
14
- export declare function getObjectFromStorage<T>(key: string): Promise<T | null>;
15
- export declare function setObjectInStorage(key: string, obj: unknown): Promise<void>;
14
+ export declare function _getObjectFromStorage<T>(key: string): Promise<T | null>;
15
+ export declare function _setObjectInStorage(key: string, obj: unknown): Promise<void>;
16
16
  export {};
@@ -9,28 +9,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setObjectInStorage = exports.getObjectFromStorage = exports.Storage = void 0;
12
+ exports._setObjectInStorage = exports._getObjectFromStorage = exports.Storage = void 0;
13
13
  const Log_1 = require("./Log");
14
14
  const inMemoryStore = {};
15
15
  const _inMemoryProvider = {
16
- getProviderName: () => 'InMemory',
17
- getItemSync(key) {
16
+ _getProviderName: () => 'InMemory',
17
+ _getItemSync(key) {
18
18
  var _a;
19
19
  return (_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null;
20
20
  },
21
- getItem(key) {
21
+ _getItem(key) {
22
22
  var _a;
23
23
  return Promise.resolve((_a = inMemoryStore[key]) !== null && _a !== void 0 ? _a : null);
24
24
  },
25
- setItem(key, value) {
25
+ _setItem(key, value) {
26
26
  inMemoryStore[key] = value;
27
27
  return Promise.resolve();
28
28
  },
29
- removeItem(key) {
29
+ _removeItem(key) {
30
30
  delete inMemoryStore[key];
31
31
  return Promise.resolve();
32
32
  },
33
- getAllKeys() {
33
+ _getAllKeys() {
34
34
  return Promise.resolve(Object.keys(inMemoryStore));
35
35
  },
36
36
  };
@@ -38,22 +38,22 @@ let _localStorageProvider = null;
38
38
  try {
39
39
  if (typeof window !== 'undefined' && 'localStorage' in window) {
40
40
  _localStorageProvider = {
41
- getProviderName: () => 'LocalStorage',
42
- getItemSync(key) {
41
+ _getProviderName: () => 'LocalStorage',
42
+ _getItemSync(key) {
43
43
  return localStorage.getItem(key);
44
44
  },
45
- getItem(key) {
45
+ _getItem(key) {
46
46
  return Promise.resolve(localStorage.getItem(key));
47
47
  },
48
- setItem(key, value) {
48
+ _setItem(key, value) {
49
49
  localStorage.setItem(key, value);
50
50
  return Promise.resolve();
51
51
  },
52
- removeItem(key) {
52
+ _removeItem(key) {
53
53
  localStorage.removeItem(key);
54
54
  return Promise.resolve();
55
55
  },
56
- getAllKeys() {
56
+ _getAllKeys() {
57
57
  const keys = Object.keys(localStorage);
58
58
  return Promise.resolve(keys);
59
59
  },
@@ -66,18 +66,18 @@ catch (error) {
66
66
  let _main = _localStorageProvider !== null && _localStorageProvider !== void 0 ? _localStorageProvider : _inMemoryProvider;
67
67
  let _current = _main;
68
68
  exports.Storage = {
69
- getProviderName: () => _current.getProviderName(),
70
- getItem: (key) => _current.getItem(key),
71
- setItem: (key, value) => _current.setItem(key, value),
72
- removeItem: (key) => _current.removeItem(key),
73
- getAllKeys: () => _current.getAllKeys(),
74
- getItemSync: (key) => { var _a, _b; return (_b = (_a = _current.getItemSync) === null || _a === void 0 ? void 0 : _a.call(_current, key)) !== null && _b !== void 0 ? _b : null; },
69
+ _getProviderName: () => _current._getProviderName(),
70
+ _getItem: (key) => _current._getItem(key),
71
+ _setItem: (key, value) => _current._setItem(key, value),
72
+ _removeItem: (key) => _current._removeItem(key),
73
+ _getAllKeys: () => _current._getAllKeys(),
74
+ _getItemSync: (key) => { var _a, _b; return (_b = (_a = _current._getItemSync) === null || _a === void 0 ? void 0 : _a.call(_current, key)) !== null && _b !== void 0 ? _b : null; },
75
75
  // StorageProviderManagment
76
- setProvider: (newProvider) => {
76
+ _setProvider: (newProvider) => {
77
77
  _main = newProvider;
78
78
  _current = newProvider;
79
79
  },
80
- setDisabled: (isDisabled) => {
80
+ _setDisabled: (isDisabled) => {
81
81
  if (isDisabled) {
82
82
  _current = _inMemoryProvider;
83
83
  }
@@ -86,16 +86,16 @@ exports.Storage = {
86
86
  }
87
87
  },
88
88
  };
89
- function getObjectFromStorage(key) {
89
+ function _getObjectFromStorage(key) {
90
90
  return __awaiter(this, void 0, void 0, function* () {
91
- const value = yield _current.getItem(key);
91
+ const value = yield _current._getItem(key);
92
92
  return JSON.parse(value !== null && value !== void 0 ? value : 'null');
93
93
  });
94
94
  }
95
- exports.getObjectFromStorage = getObjectFromStorage;
96
- function setObjectInStorage(key, obj) {
95
+ exports._getObjectFromStorage = _getObjectFromStorage;
96
+ function _setObjectInStorage(key, obj) {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
- yield _current.setItem(key, JSON.stringify(obj));
98
+ yield _current._setItem(key, JSON.stringify(obj));
99
99
  });
100
100
  }
101
- exports.setObjectInStorage = setObjectInStorage;
101
+ exports._setObjectInStorage = _setObjectInStorage;
@@ -0,0 +1,8 @@
1
+ declare const FOREGROUND = "foreground";
2
+ declare const BACKGROUND = "background";
3
+ export type Visibility = typeof FOREGROUND | typeof BACKGROUND;
4
+ type VisibilityChangedCallback = (visibility: Visibility) => void;
5
+ export declare const _isCurrentlyVisible: () => boolean;
6
+ export declare const _subscribeToVisiblityChanged: (listener: VisibilityChangedCallback) => void;
7
+ export declare const _notifyVisibilityChanged: (visibility: Visibility) => void;
8
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._notifyVisibilityChanged = exports._subscribeToVisiblityChanged = exports._isCurrentlyVisible = void 0;
4
+ const SafeJs_1 = require("./SafeJs");
5
+ const FOREGROUND = 'foreground';
6
+ const BACKGROUND = 'background';
7
+ const LISTENERS = [];
8
+ let current = FOREGROUND;
9
+ const _isCurrentlyVisible = () => {
10
+ return current === FOREGROUND;
11
+ };
12
+ exports._isCurrentlyVisible = _isCurrentlyVisible;
13
+ const _subscribeToVisiblityChanged = (listener) => {
14
+ LISTENERS.unshift(listener);
15
+ };
16
+ exports._subscribeToVisiblityChanged = _subscribeToVisiblityChanged;
17
+ const _notifyVisibilityChanged = (visibility) => {
18
+ if (visibility === current) {
19
+ return;
20
+ }
21
+ current = visibility;
22
+ LISTENERS.forEach((l) => l(visibility));
23
+ };
24
+ exports._notifyVisibilityChanged = _notifyVisibilityChanged;
25
+ (0, SafeJs_1._addWindowEventListenerSafe)('focus', () => (0, exports._notifyVisibilityChanged)(FOREGROUND));
26
+ (0, SafeJs_1._addWindowEventListenerSafe)('blur', () => (0, exports._notifyVisibilityChanged)(BACKGROUND));
27
+ (0, SafeJs_1._addWindowEventListenerSafe)('beforeunload', () => (0, exports._notifyVisibilityChanged)(BACKGROUND));
28
+ (0, SafeJs_1._addDocumentEventListenerSafe)('visibilitychange', () => {
29
+ (0, exports._notifyVisibilityChanged)(document.visibilityState === 'visible' ? FOREGROUND : BACKGROUND);
30
+ });
package/src/index.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Storage } from './StorageProvider';
6
6
  export * from './$_StatsigGlobal';
7
7
  export * from './ClientInterfaces';
8
8
  export * from './DataAdapterCore';
9
+ export * from './DownloadConfigSpecsResponse';
9
10
  export * from './ErrorBoundary';
10
11
  export * from './EvaluationOptions';
11
12
  export * from './EvaluationTypes';
@@ -13,8 +14,12 @@ export * from './Hashing';
13
14
  export * from './InitializeResponse';
14
15
  export * from './Log';
15
16
  export * from './Monitoring';
17
+ export * from './NetworkParams';
16
18
  export * from './NetworkCore';
19
+ export * from './NetworkDefaults';
17
20
  export * from './OverrideAdapter';
21
+ export * from './SafeJs';
22
+ export * from './SDKType';
18
23
  export * from './SessionID';
19
24
  export * from './StableID';
20
25
  export * from './StatsigClientBase';
@@ -31,5 +36,5 @@ export * from './TypedJsonParse';
31
36
  export * from './UrlOverrides';
32
37
  export * from './UtitlityTypes';
33
38
  export * from './UUID';
34
- export * from './VisibilityChangeObserver';
39
+ export * from './VisibilityObserving';
35
40
  export { EventLogger, Storage, Log };