@statsig/client-core 0.0.1-beta.3 → 0.0.1-beta.31

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 (74) hide show
  1. package/README.md +1 -1
  2. package/package.json +1 -1
  3. package/src/$_StatsigGlobal.d.ts +8 -1
  4. package/src/$_StatsigGlobal.js +22 -12
  5. package/src/ClientInterfaces.d.ts +47 -14
  6. package/src/DataAdapterCore.d.ts +32 -0
  7. package/src/DataAdapterCore.js +167 -0
  8. package/src/Diagnostics.js +24 -26
  9. package/src/DownloadConfigSpecsResponse.d.ts +41 -0
  10. package/src/ErrorBoundary.d.ts +1 -0
  11. package/src/ErrorBoundary.js +41 -86
  12. package/src/EvaluationOptions.d.ts +20 -0
  13. package/src/EvaluationOptions.js +2 -0
  14. package/src/EvaluationTypes.d.ts +39 -0
  15. package/src/EvaluationTypes.js +2 -0
  16. package/src/EventLogger.d.ts +21 -8
  17. package/src/EventLogger.js +206 -228
  18. package/src/Hashing.d.ts +2 -1
  19. package/src/Hashing.js +25 -6
  20. package/src/InitializeResponse.d.ts +18 -0
  21. package/src/InitializeResponse.js +2 -0
  22. package/src/Log.js +15 -34
  23. package/src/Monitoring.d.ts +1 -2
  24. package/src/Monitoring.js +68 -27
  25. package/src/NetworkCore.d.ts +17 -6
  26. package/src/NetworkCore.js +128 -166
  27. package/src/NetworkDefaults.d.ts +5 -0
  28. package/src/NetworkDefaults.js +8 -0
  29. package/src/NetworkParams.d.ts +9 -0
  30. package/src/NetworkParams.js +13 -0
  31. package/src/OverrideAdapter.d.ts +9 -0
  32. package/src/OverrideAdapter.js +2 -0
  33. package/src/SDKType.d.ts +8 -0
  34. package/src/SDKType.js +19 -0
  35. package/src/SafeJs.d.ts +4 -0
  36. package/src/SafeJs.js +27 -0
  37. package/src/SessionID.d.ts +10 -1
  38. package/src/SessionID.js +86 -6
  39. package/src/StableID.js +24 -53
  40. package/src/StatsigClientBase.d.ts +57 -28
  41. package/src/StatsigClientBase.js +114 -238
  42. package/src/StatsigClientEventEmitter.d.ts +65 -28
  43. package/src/StatsigDataAdapter.d.ts +89 -0
  44. package/src/StatsigDataAdapter.js +4 -0
  45. package/src/StatsigEvent.d.ts +10 -19
  46. package/src/StatsigEvent.js +50 -41
  47. package/src/StatsigMetadata.d.ts +1 -1
  48. package/src/StatsigMetadata.js +7 -18
  49. package/src/StatsigOptionsCommon.d.ts +68 -17
  50. package/src/StatsigTypeFactories.d.ts +6 -0
  51. package/src/StatsigTypeFactories.js +50 -0
  52. package/src/StatsigTypes.d.ts +29 -18
  53. package/src/StatsigTypes.js +0 -29
  54. package/src/StatsigUser.d.ts +2 -5
  55. package/src/StatsigUser.js +10 -18
  56. package/src/StorageProvider.d.ts +12 -7
  57. package/src/StorageProvider.js +58 -67
  58. package/src/TypedJsonParse.d.ts +8 -0
  59. package/src/TypedJsonParse.js +27 -0
  60. package/src/UUID.js +9 -5
  61. package/src/UrlOverrides.d.ts +1 -0
  62. package/src/UrlOverrides.js +15 -0
  63. package/src/UtitlityTypes.d.ts +3 -0
  64. package/src/UtitlityTypes.js +2 -0
  65. package/src/VisibilityObserving.d.ts +8 -0
  66. package/src/VisibilityObserving.js +30 -0
  67. package/src/index.d.ts +21 -4
  68. package/src/index.js +31 -17
  69. package/src/StatsigDataProvider.d.ts +0 -9
  70. package/src/VisibilityChangeObserver.d.ts +0 -13
  71. package/src/VisibilityChangeObserver.js +0 -48
  72. package/src/__tests__/MockLocalStorage.d.ts +0 -9
  73. package/src/__tests__/MockLocalStorage.js +0 -37
  74. /package/src/{StatsigDataProvider.js → DownloadConfigSpecsResponse.js} +0 -0
@@ -1,57 +1,66 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLayerParameterExposure = exports.createConfigExposure = exports.createGateExposure = exports.isExposureEvent = void 0;
4
- var CONFIG_EXPOSURE_NAME = 'statsig::config_exposure';
5
- var GATE_EXPOSURE_NAME = 'statsig::gate_exposure';
6
- var LAYER_EXPOSURE_NAME = 'statsig::layer_exposure';
7
- function createExposure(eventName, user, metadata, secondaryExposures) {
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: eventName,
10
- user: user,
9
+ eventName,
10
+ user,
11
11
  value: null,
12
- metadata: metadata,
13
- secondaryExposures: secondaryExposures,
12
+ metadata: _addEvaluationDetailsToMetadata(details, metadata),
13
+ secondaryExposures,
14
14
  time: Date.now(),
15
15
  };
16
- }
17
- function isExposureEvent(_a) {
18
- var eventName = _a.eventName;
16
+ };
17
+ const _isExposureEvent = ({ eventName, }) => {
19
18
  return eventName === GATE_EXPOSURE_NAME || eventName === CONFIG_EXPOSURE_NAME;
20
- }
21
- exports.isExposureEvent = isExposureEvent;
22
- function createGateExposure(user, gate, secondaryExposures) {
23
- return createExposure(GATE_EXPOSURE_NAME, user, {
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
- reason: gate.source,
28
- }, secondaryExposures !== null && secondaryExposures !== void 0 ? secondaryExposures : []);
29
- }
30
- exports.createGateExposure = createGateExposure;
31
- function createConfigExposure(user, config, secondaryExposures) {
32
- return createExposure(CONFIG_EXPOSURE_NAME, user, {
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
- reason: config.source,
36
- }, secondaryExposures !== null && secondaryExposures !== void 0 ? secondaryExposures : []);
37
- }
38
- exports.createConfigExposure = createConfigExposure;
39
- function createLayerParameterExposure(user, layerName, parameterName, spec) {
40
- var _a;
41
- var isExplicit = spec.explicit_parameters.includes(parameterName);
42
- var allocatedExperiment = '';
43
- var secondaryExposures = (_a = spec.undelegated_secondary_exposures) !== null && _a !== void 0 ? _a : [];
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 = spec.allocated_experiment_name;
46
- secondaryExposures = spec.secondary_exposures;
45
+ allocatedExperiment = (_c = evaluation.allocated_experiment_name) !== null && _c !== void 0 ? _c : '';
46
+ secondaryExposures = evaluation.secondary_exposures;
47
47
  }
48
- return createExposure(LAYER_EXPOSURE_NAME, user, {
49
- config: layerName,
50
- parameterName: parameterName,
51
- ruleID: spec.rule_id,
52
- allocatedExperiment: 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.createLayerParameterExposure = createLayerParameterExposure;
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
+ };
@@ -1,10 +1,10 @@
1
+ export declare const SDK_VERSION = "0.0.1-beta.31";
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;
@@ -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
- var SDK_VERSION = '0.0.1-beta.3';
16
- var metadata = {
17
- sdkVersion: SDK_VERSION,
3
+ exports.StatsigMetadataProvider = exports.SDK_VERSION = void 0;
4
+ exports.SDK_VERSION = '0.0.1-beta.31';
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: function () { return metadata; },
22
- add: function (additions) {
23
- metadata = __assign(__assign({}, metadata), additions);
10
+ get: () => metadata,
11
+ add: (additions) => {
12
+ metadata = Object.assign(Object.assign({}, metadata), additions);
24
13
  },
25
14
  };
@@ -1,12 +1,52 @@
1
1
  import { LogLevel } from './Log';
2
- import { StatsigDataProvider } from './StatsigDataProvider';
3
- /** Common options for configuring the Statsig SDK. */
4
- export type StatsigOptionsCommon = {
2
+ import { OverrideAdapter } from './OverrideAdapter';
3
+ /** Options that can be set at init and updated during runtime. */
4
+ export type StatsigRuntimeMutableOptions = {
5
+ /**
6
+ * Prevents sending any events over the network.
7
+ */
8
+ disableLogging?: boolean;
9
+ /**
10
+ * Prevents writing anything to storage.
11
+ *
12
+ * Note: caching will not work if storage is disabled
13
+ */
14
+ disableStorage?: boolean;
15
+ };
16
+ export type NetworkConfigCommon = {
5
17
  /**
6
18
  * The API to use for all SDK network requests. You should not need to override this
7
- * unless you have another API that implements the Statsig API endpoints.
19
+ * unless you have a custom API that implements the Statsig endpoints.
8
20
  */
9
21
  api?: string;
22
+ /**
23
+ * The URL used to flush queued events via a POST request. Takes precedence over {@link StatsigOptionsCommon.api}.
24
+ *
25
+ * default: `https://featuregates.org/v1/initialize`
26
+ */
27
+ logEventUrl?: string;
28
+ /**
29
+ * The URL used to flush queued events via {@link window.navigator.sendBeacon} (web only). Takes precedence over {@link StatsigOptionsCommon.api}.
30
+ *
31
+ * default: `https://featuregates.org/v1/initialize`
32
+ */
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;
10
50
  /**
11
51
  * An object you can use to set environment variables that apply to all of your users
12
52
  * in the same session.
@@ -18,30 +58,41 @@ export type StatsigOptionsCommon = {
18
58
  overrideStableID?: string;
19
59
  /**
20
60
  * How much information is allowed to be printed to the console.
21
- * Default: LogLevel.Warn
61
+ *
62
+ * default: {@link LogLevel.Warn}
22
63
  */
23
64
  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
65
  /**
35
66
  * The maximum number of events to batch before flushing logs to Statsig.
36
- * Default: 50
67
+ *
68
+ * default: `50`
37
69
  */
38
70
  loggingBufferMaxSize?: number;
39
71
  /**
40
72
  * How often (in milliseconds) to flush logs to Statsig.
41
- * Default: 10,000 (10 seconds)
73
+ *
74
+ * default: `10,000 ms` (10 seconds)
42
75
  */
43
76
  loggingIntervalMs?: number;
77
+ /**
78
+ * An implementor of {@link OverrideAdapter}, used to alter evaluations before its
79
+ * returned to the caller of a check api (checkGate/getExperiment etc).
80
+ */
81
+ overrideAdapter?: OverrideAdapter;
82
+ /**
83
+ * (Web only) Should the 'current page' url be included with logged events.
84
+ *
85
+ * default: true
86
+ */
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;
44
94
  };
95
+ export type AnyStatsigOptions = StatsigOptionsCommon<NetworkConfigCommon>;
45
96
  export type StatsigEnvironment = {
46
97
  tier?: string;
47
98
  [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
+ }
@@ -1,22 +1,33 @@
1
- export type Flatten<T> = {
2
- [K in keyof T]: T[K];
3
- } & {};
4
- 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<{
5
7
  readonly name: string;
6
8
  readonly ruleID: string;
7
- readonly source: string;
8
- };
9
- export type FeatureGate = EvaluatedSpec & {
9
+ readonly details: EvaluationDetails;
10
10
  readonly value: boolean;
11
- };
12
- export type DynamicConfig = EvaluatedSpec & {
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
- export type Experiment = DynamicConfig;
16
- export type Layer = EvaluatedSpec & {
17
- readonly getValue: (parameterName: string) => unknown;
18
- };
19
- export declare function makeFeatureGate(name: string, source: string, ruleID?: string, value?: boolean): FeatureGate;
20
- export declare function makeDynamicConfig(name: string, source: string, ruleID?: string, value?: Record<string, unknown>): DynamicConfig;
21
- export declare function makeLayer(name: string, source: string, ruleID?: string, getValue?: (param: string) => unknown): Layer;
22
- export {};
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;
@@ -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, source, ruleID, value) {
6
- return {
7
- name: name,
8
- source: source,
9
- ruleID: ruleID !== null && ruleID !== void 0 ? ruleID : DEFAULT_RULE,
10
- value: value === true,
11
- };
12
- }
13
- exports.makeFeatureGate = makeFeatureGate;
14
- function makeDynamicConfig(name, source, ruleID, value) {
15
- return {
16
- name: name,
17
- source: source,
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, source, ruleID, getValue) {
24
- return {
25
- name: name,
26
- source: source,
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;
@@ -1,10 +1,6 @@
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
5
  customIDs?: Record<string, string>;
10
6
  email?: string;
@@ -21,4 +17,5 @@ export type StatsigUserInternal = StatsigUser & {
21
17
  };
22
18
  export declare function normalizeUser(original: StatsigUser, environment?: StatsigEnvironment): StatsigUser;
23
19
  export declare function getUserStorageKey(sdkKey: string, user?: StatsigUser): string;
20
+ export declare function getUnitIDFromUser(user: StatsigUser, idType: string): string | undefined;
24
21
  export {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUserStorageKey = exports.normalizeUser = void 0;
4
- var Hashing_1 = require("./Hashing");
3
+ exports.getUnitIDFromUser = exports.getUserStorageKey = exports.normalizeUser = void 0;
4
+ const Hashing_1 = require("./Hashing");
5
5
  function normalizeUser(original, environment) {
6
6
  try {
7
- var copy = JSON.parse(JSON.stringify(original));
7
+ const copy = JSON.parse(JSON.stringify(original));
8
8
  if (environment != null) {
9
9
  copy.statsigEnvironment = environment;
10
10
  }
@@ -16,22 +16,14 @@ function normalizeUser(original, environment) {
16
16
  }
17
17
  exports.normalizeUser = normalizeUser;
18
18
  function getUserStorageKey(sdkKey, user) {
19
- var key = (0, Hashing_1.DJB2)(JSON.stringify(_getSortedObject({ sdkKey: sdkKey, user: user })));
20
- return "statsig.user_cache.".concat(key);
19
+ return (0, Hashing_1.DJB2Object)({ sdkKey, user });
21
20
  }
22
21
  exports.getUserStorageKey = getUserStorageKey;
23
- function _getSortedObject(object) {
24
- if (object == null) {
25
- return null;
22
+ function getUnitIDFromUser(user, idType) {
23
+ var _a, _b, _c;
24
+ if (typeof idType === 'string' && idType.toLowerCase() !== 'userid') {
25
+ return (_b = (_a = user.customIDs) === null || _a === void 0 ? void 0 : _a[idType]) !== null && _b !== void 0 ? _b : (_c = user === null || user === void 0 ? void 0 : user.customIDs) === null || _c === void 0 ? void 0 : _c[idType.toLowerCase()];
26
26
  }
27
- var keys = Object.keys(object).sort();
28
- var sortedObject = {};
29
- keys.forEach(function (key) {
30
- var value = object[key];
31
- if (value instanceof Object) {
32
- value = _getSortedObject(value);
33
- }
34
- sortedObject[key] = value;
35
- });
36
- return sortedObject;
27
+ return user.userID;
37
28
  }
29
+ exports.getUnitIDFromUser = getUnitIDFromUser;
@@ -1,11 +1,16 @@
1
1
  type StorageProvider = {
2
- getItem: (key: string) => Promise<string | null>;
3
- setItem: (key: string, value: string) => Promise<void>;
4
- removeItem: (key: string) => Promise<void>;
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;
5
8
  };
6
- export declare const Storage: StorageProvider & {
7
- setProvider: (n: StorageProvider) => void;
9
+ type StorageProviderManagment = {
10
+ _setProvider: (newProvider: StorageProvider) => void;
11
+ _setDisabled: (isDisabled: boolean) => void;
8
12
  };
9
- export declare function getObjectFromStorage<T>(key: string): Promise<T | null>;
10
- export declare function setObjectInStorage(key: string, obj: unknown): Promise<void>;
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>;
11
16
  export {};