@statsig/react-bindings 2.1.1-beta.7 → 2.2.0-beta.1

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 (36) hide show
  1. package/package.json +3 -6
  2. package/src/NoopEvaluationsClient.d.ts +3 -2
  3. package/src/NoopEvaluationsClient.js +5 -1
  4. package/src/StatsigContext.d.ts +2 -2
  5. package/src/StatsigProvider.d.ts +3 -4
  6. package/src/index.d.ts +1 -4
  7. package/src/index.js +1 -10
  8. package/src/useClientAsyncInit.d.ts +1 -1
  9. package/src/useClientAsyncInit.js +2 -2
  10. package/src/useClientBootstrapInit.d.ts +1 -1
  11. package/src/useClientBootstrapInit.js +2 -2
  12. package/src/useDynamicConfig.d.ts +2 -4
  13. package/src/useDynamicConfig.js +4 -8
  14. package/src/useExperiment.d.ts +2 -4
  15. package/src/useExperiment.js +4 -8
  16. package/src/useFeatureGate.d.ts +2 -4
  17. package/src/useFeatureGate.js +4 -8
  18. package/src/useGateValue.d.ts +2 -4
  19. package/src/useGateValue.js +4 -8
  20. package/src/useLayer.d.ts +2 -4
  21. package/src/useLayer.js +4 -8
  22. package/src/useParameterStore.d.ts +2 -4
  23. package/src/useParameterStore.js +4 -10
  24. package/src/useStatsigClient.js +4 -5
  25. package/src/OnDeviceVsPrecomputedUtils.d.ts +0 -4
  26. package/src/OnDeviceVsPrecomputedUtils.js +0 -19
  27. package/src/requireOptionalOnDeviceClient.d.ts +0 -3
  28. package/src/requireOptionalOnDeviceClient.js +0 -26
  29. package/src/requireOptionalStatsigClient.d.ts +0 -3
  30. package/src/requireOptionalStatsigClient.js +0 -25
  31. package/src/useOnDeviceClientAsyncInit.d.ts +0 -6
  32. package/src/useOnDeviceClientAsyncInit.js +0 -19
  33. package/src/useOnDeviceClientBootstrapInit.d.ts +0 -4
  34. package/src/useOnDeviceClientBootstrapInit.js +0 -15
  35. package/src/useStatsigOnDeviceEvalClient.d.ts +0 -6
  36. package/src/useStatsigOnDeviceEvalClient.js +0 -44
package/package.json CHANGED
@@ -1,16 +1,13 @@
1
1
  {
2
2
  "name": "@statsig/react-bindings",
3
- "version": "2.1.1-beta.7",
3
+ "version": "2.2.0-beta.1",
4
4
  "dependencies": {
5
- "@statsig/client-core": "2.1.1-beta.7"
5
+ "@statsig/client-core": "2.2.0-beta.1",
6
+ "@statsig/js-client": "2.2.0-beta.1"
6
7
  },
7
8
  "peerDependencies": {
8
9
  "react": "^16.6.3 || ^17.0.0 || ^18.0.0"
9
10
  },
10
- "optionalDependencies": {
11
- "@statsig/js-client": "2.1.1-beta.7",
12
- "@statsig/js-on-device-eval-client": "2.1.1-beta.7"
13
- },
14
11
  "type": "commonjs",
15
12
  "main": "./src/index.js",
16
13
  "typings": "./src/index.d.ts"
@@ -1,4 +1,5 @@
1
- import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
- export declare const NoopEvaluationsClient: OnDeviceEvaluationsInterface & PrecomputedEvaluationsInterface & {
1
+ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
+ export declare const NoopEvaluationsClient: PrecomputedEvaluationsInterface & {
3
3
  isNoop: true;
4
4
  };
5
+ export declare function isNoopClient(client: PrecomputedEvaluationsInterface): boolean;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NoopEvaluationsClient = void 0;
3
+ exports.isNoopClient = exports.NoopEvaluationsClient = void 0;
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const _noop = () => {
6
6
  // noop
@@ -68,3 +68,7 @@ const _client = {
68
68
  dataAdapter: _noopDataAdapter,
69
69
  };
70
70
  exports.NoopEvaluationsClient = _client;
71
+ function isNoopClient(client) {
72
+ return 'isNoop' in client;
73
+ }
74
+ exports.isNoopClient = isNoopClient;
@@ -1,7 +1,7 @@
1
- import { StatsigClientInterface } from '@statsig/client-core';
1
+ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
2
  export interface StatsigContext {
3
3
  readonly renderVersion: number;
4
- readonly client: StatsigClientInterface;
4
+ readonly client: PrecomputedEvaluationsInterface;
5
5
  }
6
6
  declare const _default: import("react").Context<StatsigContext>;
7
7
  export default _default;
@@ -1,14 +1,13 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { StatsigUser } from '@statsig/client-core';
3
- import type { StatsigClient, StatsigOptions } from '@statsig/js-client';
4
- import type { StatsigOnDeviceEvalClient, StatsigOptions as StatsigOptionsOnDeviceEval } from '@statsig/js-on-device-eval-client';
3
+ import { StatsigClient, StatsigOptions } from '@statsig/js-client';
5
4
  type WithClient = {
6
- client: StatsigClient | StatsigOnDeviceEvalClient;
5
+ client: StatsigClient;
7
6
  };
8
7
  type WithConfiguration = {
9
8
  sdkKey: string;
10
9
  user: StatsigUser;
11
- options?: StatsigOptionsOnDeviceEval | StatsigOptions;
10
+ options?: StatsigOptions;
12
11
  };
13
12
  export type StatsigProviderProps = {
14
13
  children: ReactNode | ReactNode[];
package/src/index.d.ts CHANGED
@@ -7,11 +7,8 @@ import useExperiment from './useExperiment';
7
7
  import useFeatureGate from './useFeatureGate';
8
8
  import useGateValue from './useGateValue';
9
9
  import useLayer from './useLayer';
10
- import { useOnDeviceClientAsyncInit } from './useOnDeviceClientAsyncInit';
11
- import { useOnDeviceClientBootstrapInit } from './useOnDeviceClientBootstrapInit';
12
10
  import useParameterStore from './useParameterStore';
13
11
  import { useStatsigClient } from './useStatsigClient';
14
- import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
15
12
  import { useStatsigUser } from './useStatsigUser';
16
13
  export type { StatsigProviderProps };
17
- export { StatsigContext, StatsigProvider, useClientAsyncInit, useClientBootstrapInit, useDynamicConfig, useExperiment, useFeatureGate, useGateValue, useLayer, useOnDeviceClientAsyncInit, useOnDeviceClientBootstrapInit, useParameterStore, useStatsigClient, useStatsigOnDeviceEvalClient, useStatsigUser, };
14
+ export { StatsigContext, StatsigProvider, useClientAsyncInit, useClientBootstrapInit, useDynamicConfig, useExperiment, useFeatureGate, useGateValue, useLayer, useParameterStore, useStatsigClient, useStatsigUser, };
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useStatsigUser = exports.useStatsigOnDeviceEvalClient = exports.useStatsigClient = exports.useParameterStore = exports.useOnDeviceClientBootstrapInit = exports.useOnDeviceClientAsyncInit = exports.useLayer = exports.useGateValue = exports.useFeatureGate = exports.useExperiment = exports.useDynamicConfig = exports.useClientBootstrapInit = exports.useClientAsyncInit = exports.StatsigProvider = exports.StatsigContext = void 0;
3
+ exports.useStatsigUser = exports.useStatsigClient = exports.useParameterStore = exports.useLayer = exports.useGateValue = exports.useFeatureGate = exports.useExperiment = exports.useDynamicConfig = exports.useClientBootstrapInit = exports.useClientAsyncInit = exports.StatsigProvider = exports.StatsigContext = void 0;
4
4
  const StatsigContext_1 = require("./StatsigContext");
5
5
  exports.StatsigContext = StatsigContext_1.default;
6
6
  const StatsigProvider_1 = require("./StatsigProvider");
@@ -19,16 +19,10 @@ const useGateValue_1 = require("./useGateValue");
19
19
  exports.useGateValue = useGateValue_1.default;
20
20
  const useLayer_1 = require("./useLayer");
21
21
  exports.useLayer = useLayer_1.default;
22
- const useOnDeviceClientAsyncInit_1 = require("./useOnDeviceClientAsyncInit");
23
- Object.defineProperty(exports, "useOnDeviceClientAsyncInit", { enumerable: true, get: function () { return useOnDeviceClientAsyncInit_1.useOnDeviceClientAsyncInit; } });
24
- const useOnDeviceClientBootstrapInit_1 = require("./useOnDeviceClientBootstrapInit");
25
- Object.defineProperty(exports, "useOnDeviceClientBootstrapInit", { enumerable: true, get: function () { return useOnDeviceClientBootstrapInit_1.useOnDeviceClientBootstrapInit; } });
26
22
  const useParameterStore_1 = require("./useParameterStore");
27
23
  exports.useParameterStore = useParameterStore_1.default;
28
24
  const useStatsigClient_1 = require("./useStatsigClient");
29
25
  Object.defineProperty(exports, "useStatsigClient", { enumerable: true, get: function () { return useStatsigClient_1.useStatsigClient; } });
30
- const useStatsigOnDeviceEvalClient_1 = require("./useStatsigOnDeviceEvalClient");
31
- Object.defineProperty(exports, "useStatsigOnDeviceEvalClient", { enumerable: true, get: function () { return useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient; } });
32
26
  const useStatsigUser_1 = require("./useStatsigUser");
33
27
  Object.defineProperty(exports, "useStatsigUser", { enumerable: true, get: function () { return useStatsigUser_1.useStatsigUser; } });
34
28
  __STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { StatsigContext: StatsigContext_1.default,
@@ -40,9 +34,6 @@ __STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG
40
34
  useFeatureGate: useFeatureGate_1.default,
41
35
  useGateValue: useGateValue_1.default,
42
36
  useLayer: useLayer_1.default,
43
- useOnDeviceClientAsyncInit: useOnDeviceClientAsyncInit_1.useOnDeviceClientAsyncInit,
44
- useOnDeviceClientBootstrapInit: useOnDeviceClientBootstrapInit_1.useOnDeviceClientBootstrapInit,
45
37
  useParameterStore: useParameterStore_1.default,
46
38
  useStatsigClient: useStatsigClient_1.useStatsigClient,
47
- useStatsigOnDeviceEvalClient: useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient,
48
39
  useStatsigUser: useStatsigUser_1.useStatsigUser });
@@ -1,5 +1,5 @@
1
1
  import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
2
- import type { StatsigClient } from '@statsig/js-client';
2
+ import { StatsigClient } from '@statsig/js-client';
3
3
  export declare function useClientAsyncInit(sdkKey: string, initialUser: StatsigUser, statsigOptions?: AnyStatsigOptions | null): {
4
4
  isLoading: boolean;
5
5
  client: StatsigClient;
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useClientAsyncInit = void 0;
4
4
  const react_1 = require("react");
5
5
  const client_core_1 = require("@statsig/client-core");
6
- const requireOptionalStatsigClient_1 = require("./requireOptionalStatsigClient");
6
+ const js_client_1 = require("@statsig/js-client");
7
7
  function useClientAsyncInit(sdkKey, initialUser, statsigOptions = null) {
8
8
  const [isLoading, setIsLoading] = (0, react_1.useState)(true);
9
9
  const [args] = (0, react_1.useState)(() => {
10
- const client = (0, requireOptionalStatsigClient_1.requireOptionalClientDependency)(sdkKey, initialUser, statsigOptions);
10
+ const client = new js_client_1.StatsigClient(sdkKey, initialUser, statsigOptions);
11
11
  client
12
12
  .initializeAsync()
13
13
  .catch(client_core_1.Log.error)
@@ -1,5 +1,5 @@
1
1
  import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
2
- import type { StatsigClient } from '@statsig/js-client';
2
+ import { StatsigClient } from '@statsig/js-client';
3
3
  export declare function useClientBootstrapInit(sdkKey: string, initialUser: StatsigUser, initialValues: string, statsigOptions?: AnyStatsigOptions | null): {
4
4
  client: StatsigClient;
5
5
  };
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useClientBootstrapInit = void 0;
4
4
  const react_1 = require("react");
5
- const requireOptionalStatsigClient_1 = require("./requireOptionalStatsigClient");
5
+ const js_client_1 = require("@statsig/js-client");
6
6
  function useClientBootstrapInit(sdkKey, initialUser, initialValues, statsigOptions = null) {
7
7
  const [args] = (0, react_1.useState)(() => {
8
- const client = (0, requireOptionalStatsigClient_1.requireOptionalClientDependency)(sdkKey, initialUser, statsigOptions);
8
+ const client = new js_client_1.StatsigClient(sdkKey, initialUser, statsigOptions);
9
9
  client.dataAdapter.setData(initialValues);
10
10
  client.initializeSync();
11
11
  return { client, initialValues, initialUser, sdkKey };
@@ -1,5 +1,3 @@
1
- import { DynamicConfig, DynamicConfigEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type UseDynamicConfigOptions = DynamicConfigEvaluationOptions & {
3
- user: StatsigUser | null;
4
- };
1
+ import { DynamicConfig, DynamicConfigEvaluationOptions } from '@statsig/client-core';
2
+ export type UseDynamicConfigOptions = DynamicConfigEvaluationOptions;
5
3
  export default function (configName: string, options?: UseDynamicConfigOptions): DynamicConfig;
@@ -3,19 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(configName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  return (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.getDynamicConfig(configName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useDynamicConfig hook failed to find a valid StatsigClient for dynamic config '${configName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.getDynamicConfig(configName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- return client.getDynamicConfig(configName, options.user, options);
16
- }
17
- client_core_1.Log.warn(`useDynamicConfig hook failed to find a valid Statsig client for dynamic config '${configName}'.`);
18
- return NoopEvaluationsClient_1.NoopEvaluationsClient.getDynamicConfig(configName, options);
14
+ return client.getDynamicConfig(configName, options);
19
15
  }, [configName, client, renderVersion, options]);
20
16
  }
21
17
  exports.default = default_1;
@@ -1,5 +1,3 @@
1
- import { Experiment, ExperimentEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type UseExperimentOptions = ExperimentEvaluationOptions & {
3
- user: StatsigUser | null;
4
- };
1
+ import { Experiment, ExperimentEvaluationOptions } from '@statsig/client-core';
2
+ export type UseExperimentOptions = ExperimentEvaluationOptions;
5
3
  export default function (experimentName: string, options?: UseExperimentOptions): Experiment;
@@ -3,19 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(experimentName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  return (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.getExperiment(experimentName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useExperiment hook failed to find a valid Statsig client for experiment '${experimentName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(experimentName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- return client.getExperiment(experimentName, options.user, options);
16
- }
17
- client_core_1.Log.warn(`useExperiment hook failed to find a valid Statsig client for experiment '${experimentName}'.`);
18
- return NoopEvaluationsClient_1.NoopEvaluationsClient.getExperiment(experimentName, options);
14
+ return client.getExperiment(experimentName, options);
19
15
  }, [experimentName, client, renderVersion, options]);
20
16
  }
21
17
  exports.default = default_1;
@@ -1,5 +1,3 @@
1
- import { FeatureGate, FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type useFeatureGateOptions = FeatureGateEvaluationOptions & {
3
- user: StatsigUser | null;
4
- };
1
+ import { FeatureGate, FeatureGateEvaluationOptions } from '@statsig/client-core';
2
+ export type useFeatureGateOptions = FeatureGateEvaluationOptions;
5
3
  export default function (gateName: string, options?: useFeatureGateOptions): FeatureGate;
@@ -3,19 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(gateName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  const gate = (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.getFeatureGate(gateName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useFeatureGate hook failed to find a valid StatsigClient for gate '${gateName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- return client.getFeatureGate(gateName, options.user, options);
16
- }
17
- client_core_1.Log.warn(`useFeatureGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
18
- return NoopEvaluationsClient_1.NoopEvaluationsClient.getFeatureGate(gateName, options);
14
+ return client.getFeatureGate(gateName, options);
19
15
  }, [gateName, client, renderVersion, options]);
20
16
  return gate;
21
17
  }
@@ -1,5 +1,3 @@
1
- import { FeatureGateEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type useFeatureGateOptions = FeatureGateEvaluationOptions & {
3
- user: StatsigUser | null;
4
- };
1
+ import { FeatureGateEvaluationOptions } from '@statsig/client-core';
2
+ export type useFeatureGateOptions = FeatureGateEvaluationOptions;
5
3
  export default function (gateName: string, options?: useFeatureGateOptions): boolean;
@@ -3,19 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(gateName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  const gate = (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.checkGate(gateName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useGateValue hook failed to find a valid StatsigClient for gate '${gateName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.checkGate(gateName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- return client.checkGate(gateName, options.user, options);
16
- }
17
- client_core_1.Log.warn(`useFeatureGate hook failed to find a valid Statsig client for gate '${gateName}'.`);
18
- return NoopEvaluationsClient_1.NoopEvaluationsClient.checkGate(gateName, options);
14
+ return client.checkGate(gateName, options);
19
15
  }, [gateName, client, renderVersion, options]);
20
16
  return gate;
21
17
  }
package/src/useLayer.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { Layer, LayerEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type UseLayerOptions = LayerEvaluationOptions & {
3
- user: StatsigUser | null;
4
- };
1
+ import { Layer, LayerEvaluationOptions } from '@statsig/client-core';
2
+ export type UseLayerOptions = LayerEvaluationOptions;
5
3
  export default function (layerName: string, options?: UseLayerOptions): Layer;
package/src/useLayer.js CHANGED
@@ -3,19 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(layerName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  const layer = (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.getLayer(layerName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useLayer hook failed to find a valid Statsig client for layer '${layerName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.getLayer(layerName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- return client.getLayer(layerName, options.user, options);
16
- }
17
- client_core_1.Log.warn(`useLayer hook failed to find a valid Statsig client for layer '${layerName}'.`);
18
- return NoopEvaluationsClient_1.NoopEvaluationsClient.getLayer(layerName, options);
14
+ return client.getLayer(layerName, options);
19
15
  }, [layerName, client, renderVersion, options]);
20
16
  return layer;
21
17
  }
@@ -1,5 +1,3 @@
1
- import { ParameterStore, ParameterStoreEvaluationOptions, StatsigUser } from '@statsig/client-core';
2
- export type useParameterStoreOptions = ParameterStoreEvaluationOptions & {
3
- user?: StatsigUser;
4
- };
1
+ import { ParameterStore, ParameterStoreEvaluationOptions } from '@statsig/client-core';
2
+ export type useParameterStoreOptions = ParameterStoreEvaluationOptions;
5
3
  export default function (storeName: string, options?: useParameterStoreOptions): ParameterStore;
@@ -3,21 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const client_core_1 = require("@statsig/client-core");
5
5
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
7
6
  const StatsigContext_1 = require("./StatsigContext");
8
7
  function default_1(storeName, options) {
9
8
  const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
10
9
  const store = (0, react_1.useMemo)(() => {
11
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(client)) {
12
- return client.getParameterStore(storeName, options);
10
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(client)) {
11
+ client_core_1.Log.warn(`useParameterStore hook failed to find a valid StatsigClient for parameter store '${storeName}'.`);
12
+ return NoopEvaluationsClient_1.NoopEvaluationsClient.getParameterStore(storeName, options);
13
13
  }
14
- if ((options === null || options === void 0 ? void 0 : options.user) != null) {
15
- client_core_1.Log.warn(`useParameterStore hook is not yet supported by StatsigOnDeviceEvalClient.`);
16
- }
17
- else {
18
- client_core_1.Log.warn(`useParameterStore hook failed to find a valid Statsig client for parameter store '${storeName}'.`);
19
- }
20
- return NoopEvaluationsClient_1.NoopEvaluationsClient.getParameterStore(storeName, options);
14
+ return client.getParameterStore(storeName, options);
21
15
  }, [storeName, client, renderVersion, options]);
22
16
  return store;
23
17
  }
@@ -4,16 +4,15 @@ exports.useStatsigClient = void 0;
4
4
  const react_1 = require("react");
5
5
  const client_core_1 = require("@statsig/client-core");
6
6
  const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
7
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
8
7
  const StatsigContext_1 = require("./StatsigContext");
9
8
  function useStatsigClient() {
10
9
  const { client: anyClient, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
11
10
  const client = (0, react_1.useMemo)(() => {
12
- if ((0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(anyClient)) {
13
- return anyClient;
11
+ if ((0, NoopEvaluationsClient_1.isNoopClient)(anyClient)) {
12
+ client_core_1.Log.warn('Attempting to retrieve a StatsigClient but none was set.');
13
+ return NoopEvaluationsClient_1.NoopEvaluationsClient;
14
14
  }
15
- client_core_1.Log.warn('Attempting to retrieve a StatsigClient but none was set.');
16
- return NoopEvaluationsClient_1.NoopEvaluationsClient;
15
+ return anyClient;
17
16
  }, [anyClient, renderVersion]);
18
17
  const deps = [client, renderVersion];
19
18
  const checkGate = (0, react_1.useCallback)((name, options) => {
@@ -1,4 +0,0 @@
1
- import { OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
- export declare function isPrecomputedEvalClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): client is PrecomputedEvaluationsInterface;
3
- export declare function isNoopClient(client: OnDeviceEvaluationsInterface | PrecomputedEvaluationsInterface): boolean;
4
- export declare function logMissingStatsigUserWarning(): void;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logMissingStatsigUserWarning = exports.isNoopClient = exports.isPrecomputedEvalClient = void 0;
4
- const client_core_1 = require("@statsig/client-core");
5
- function isPrecomputedEvalClient(client) {
6
- if (isNoopClient(client)) {
7
- return false;
8
- }
9
- return 'updateUserSync' in client;
10
- }
11
- exports.isPrecomputedEvalClient = isPrecomputedEvalClient;
12
- function isNoopClient(client) {
13
- return 'isNoop' in client;
14
- }
15
- exports.isNoopClient = isNoopClient;
16
- function logMissingStatsigUserWarning() {
17
- client_core_1.Log.warn('StatsigUser not provided for On Device Evaluation. Returning default value.');
18
- }
19
- exports.logMissingStatsigUserWarning = logMissingStatsigUserWarning;
@@ -1,3 +0,0 @@
1
- import { AnyStatsigOptions } from '@statsig/client-core';
2
- import type { StatsigOnDeviceEvalClient as TStatsigOnDeviceEvalClient } from '@statsig/js-on-device-eval-client';
3
- export declare function requireOptionalOnDeviceClientDependency(sdkKey: string, statsigOptions: AnyStatsigOptions | null): TStatsigOnDeviceEvalClient;
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireOptionalOnDeviceClientDependency = void 0;
4
- const client_core_1 = require("@statsig/client-core");
5
- const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- let jsOnDeviceEvalClientMod = null;
7
- try {
8
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
9
- jsOnDeviceEvalClientMod = require('@statsig/js-on-device-eval-client');
10
- }
11
- catch (error) {
12
- // noop
13
- }
14
- function requireOptionalOnDeviceClientDependency(sdkKey, statsigOptions) {
15
- let client;
16
- if (jsOnDeviceEvalClientMod) {
17
- const { StatsigOnDeviceEvalClient } = jsOnDeviceEvalClientMod;
18
- client = new StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
19
- }
20
- else {
21
- client = NoopEvaluationsClient_1.NoopEvaluationsClient;
22
- client_core_1.Log.error('Failed to load StatsigOnDeviceEvalClient. Do you have @statsig/js-on-device-eval-client installed?');
23
- }
24
- return client;
25
- }
26
- exports.requireOptionalOnDeviceClientDependency = requireOptionalOnDeviceClientDependency;
@@ -1,3 +0,0 @@
1
- import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
2
- import type { StatsigClient as TStatsigClient } from '@statsig/js-client';
3
- export declare function requireOptionalClientDependency(sdkKey: string, initialUser: StatsigUser, statsigOptions: AnyStatsigOptions | null): TStatsigClient;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireOptionalClientDependency = void 0;
4
- const client_core_1 = require("@statsig/client-core");
5
- const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
6
- let jsClientMod = null;
7
- try {
8
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
9
- jsClientMod = require('@statsig' + '/js-client');
10
- }
11
- catch (error) {
12
- // noop
13
- }
14
- function requireOptionalClientDependency(sdkKey, initialUser, statsigOptions) {
15
- let client;
16
- if (jsClientMod) {
17
- client = new jsClientMod.StatsigClient(sdkKey, initialUser, statsigOptions);
18
- }
19
- else {
20
- client = NoopEvaluationsClient_1.NoopEvaluationsClient;
21
- client_core_1.Log.error('Failed to load StatsigClient. Do you have @statsig/js-client installed?');
22
- }
23
- return client;
24
- }
25
- exports.requireOptionalClientDependency = requireOptionalClientDependency;
@@ -1,6 +0,0 @@
1
- import { AnyStatsigOptions } from '@statsig/client-core';
2
- import type { StatsigOnDeviceEvalClient } from '@statsig/js-on-device-eval-client';
3
- export declare function useOnDeviceClientAsyncInit(sdkKey: string, statsigOptions?: AnyStatsigOptions | null): {
4
- isLoading: boolean;
5
- client: StatsigOnDeviceEvalClient;
6
- };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useOnDeviceClientAsyncInit = void 0;
4
- const react_1 = require("react");
5
- const client_core_1 = require("@statsig/client-core");
6
- const requireOptionalOnDeviceClient_1 = require("./requireOptionalOnDeviceClient");
7
- function useOnDeviceClientAsyncInit(sdkKey, statsigOptions = null) {
8
- const [isLoading, setIsLoading] = (0, react_1.useState)(true);
9
- const [args] = (0, react_1.useState)(() => {
10
- const client = (0, requireOptionalOnDeviceClient_1.requireOptionalOnDeviceClientDependency)(sdkKey, statsigOptions);
11
- client
12
- .initializeAsync()
13
- .catch(client_core_1.Log.error)
14
- .finally(() => setIsLoading(false));
15
- return { client, sdkKey };
16
- });
17
- return { client: args.client, isLoading };
18
- }
19
- exports.useOnDeviceClientAsyncInit = useOnDeviceClientAsyncInit;
@@ -1,4 +0,0 @@
1
- import { AnyStatsigOptions, OnDeviceEvaluationsInterface } from '@statsig/client-core';
2
- export declare function useOnDeviceClientBootstrapInit(sdkKey: string, initialValues: string, statsigOptions?: AnyStatsigOptions | null): {
3
- client: OnDeviceEvaluationsInterface;
4
- };
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useOnDeviceClientBootstrapInit = void 0;
4
- const react_1 = require("react");
5
- const requireOptionalOnDeviceClient_1 = require("./requireOptionalOnDeviceClient");
6
- function useOnDeviceClientBootstrapInit(sdkKey, initialValues, statsigOptions = null) {
7
- const [args] = (0, react_1.useState)(() => {
8
- const client = (0, requireOptionalOnDeviceClient_1.requireOptionalOnDeviceClientDependency)(sdkKey, statsigOptions);
9
- client.dataAdapter.setData(initialValues);
10
- client.initializeSync();
11
- return { client, initialValues, sdkKey };
12
- });
13
- return { client: args.client };
14
- }
15
- exports.useOnDeviceClientBootstrapInit = useOnDeviceClientBootstrapInit;
@@ -1,6 +0,0 @@
1
- import { OnDeviceEvaluationsInterface } from '@statsig/client-core';
2
- type HositedFuncs = Pick<OnDeviceEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'logEvent'>;
3
- export declare function useStatsigOnDeviceEvalClient(): HositedFuncs & {
4
- client: OnDeviceEvaluationsInterface;
5
- };
6
- export {};
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useStatsigOnDeviceEvalClient = void 0;
4
- const react_1 = require("react");
5
- const client_core_1 = require("@statsig/client-core");
6
- const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
7
- const OnDeviceVsPrecomputedUtils_1 = require("./OnDeviceVsPrecomputedUtils");
8
- const StatsigContext_1 = require("./StatsigContext");
9
- function useStatsigOnDeviceEvalClient() {
10
- const { client: anyClient, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
11
- const client = (0, react_1.useMemo)(() => {
12
- if (!(0, OnDeviceVsPrecomputedUtils_1.isPrecomputedEvalClient)(anyClient)) {
13
- return anyClient;
14
- }
15
- client_core_1.Log.warn('Attempting to retrieve a StatsigOnDeviceEvalClient but none was set.');
16
- return NoopEvaluationsClient_1.NoopEvaluationsClient;
17
- }, [anyClient, renderVersion]);
18
- const deps = [client, renderVersion];
19
- return {
20
- client,
21
- checkGate: (0, react_1.useCallback)((name, options) => {
22
- return client.checkGate(name, options);
23
- }, deps),
24
- getFeatureGate: (0, react_1.useCallback)((name, options) => {
25
- return client.getFeatureGate(name, options);
26
- }, deps),
27
- getDynamicConfig: (0, react_1.useCallback)((name, options) => {
28
- return client.getDynamicConfig(name, options);
29
- }, deps),
30
- getExperiment: (0, react_1.useCallback)((name, options) => {
31
- return client.getExperiment(name, options);
32
- }, deps),
33
- getLayer: (0, react_1.useCallback)((name, options) => {
34
- return client.getLayer(name, options);
35
- }, deps),
36
- logEvent: (0, react_1.useCallback)((eventName, user, value, metadata) => {
37
- if (typeof eventName === 'string') {
38
- return client.logEvent(eventName, user, value, metadata);
39
- }
40
- return client.logEvent(eventName, user);
41
- }, deps),
42
- };
43
- }
44
- exports.useStatsigOnDeviceEvalClient = useStatsigOnDeviceEvalClient;