@statsig/react-bindings 2.1.1 → 2.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -6
- package/src/NoopEvaluationsClient.d.ts +3 -2
- package/src/NoopEvaluationsClient.js +5 -1
- package/src/StatsigContext.d.ts +2 -2
- package/src/StatsigProvider.d.ts +4 -3
- package/src/index.d.ts +1 -4
- package/src/index.js +1 -10
- package/src/useClientAsyncInit.d.ts +3 -2
- package/src/useClientAsyncInit.js +2 -2
- package/src/useClientBootstrapInit.d.ts +3 -2
- package/src/useClientBootstrapInit.js +2 -2
- package/src/useDynamicConfig.d.ts +2 -4
- package/src/useDynamicConfig.js +4 -8
- package/src/useExperiment.d.ts +2 -4
- package/src/useExperiment.js +4 -8
- package/src/useFeatureGate.d.ts +2 -4
- package/src/useFeatureGate.js +4 -8
- package/src/useGateValue.d.ts +2 -4
- package/src/useGateValue.js +4 -8
- package/src/useLayer.d.ts +2 -4
- package/src/useLayer.js +4 -8
- package/src/useParameterStore.d.ts +2 -4
- package/src/useParameterStore.js +4 -10
- package/src/useStatsigClient.js +4 -5
- package/src/OnDeviceVsPrecomputedUtils.d.ts +0 -4
- package/src/OnDeviceVsPrecomputedUtils.js +0 -19
- package/src/requireOptionalDependency.d.ts +0 -3
- package/src/requireOptionalDependency.js +0 -35
- package/src/useOnDeviceClientAsyncInit.d.ts +0 -5
- package/src/useOnDeviceClientAsyncInit.js +0 -19
- package/src/useOnDeviceClientBootstrapInit.d.ts +0 -4
- package/src/useOnDeviceClientBootstrapInit.js +0 -15
- package/src/useStatsigOnDeviceEvalClient.d.ts +0 -6
- 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.
|
|
3
|
+
"version": "2.2.0-beta.2",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "2.
|
|
5
|
+
"@statsig/client-core": "2.2.0-beta.2",
|
|
6
|
+
"@statsig/js-client": "2.2.0-beta.2"
|
|
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",
|
|
12
|
-
"@statsig/js-on-device-eval-client": "2.1.1"
|
|
13
|
-
},
|
|
14
11
|
"type": "commonjs",
|
|
15
12
|
"main": "./src/index.js",
|
|
16
13
|
"typings": "./src/index.d.ts"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const NoopEvaluationsClient:
|
|
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;
|
package/src/StatsigContext.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
2
2
|
export interface StatsigContext {
|
|
3
3
|
readonly renderVersion: number;
|
|
4
|
-
readonly client:
|
|
4
|
+
readonly client: PrecomputedEvaluationsInterface;
|
|
5
5
|
}
|
|
6
6
|
declare const _default: import("react").Context<StatsigContext>;
|
|
7
7
|
export default _default;
|
package/src/StatsigProvider.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { StatsigUser } from '@statsig/client-core';
|
|
3
|
+
import { StatsigClient, StatsigOptions } from '@statsig/js-client';
|
|
3
4
|
type WithClient = {
|
|
4
|
-
client:
|
|
5
|
+
client: StatsigClient;
|
|
5
6
|
};
|
|
6
7
|
type WithConfiguration = {
|
|
7
8
|
sdkKey: string;
|
|
8
9
|
user: StatsigUser;
|
|
9
|
-
options?:
|
|
10
|
+
options?: StatsigOptions;
|
|
10
11
|
};
|
|
11
12
|
export type StatsigProviderProps = {
|
|
12
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,
|
|
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.
|
|
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,6 @@
|
|
|
1
|
-
import { AnyStatsigOptions,
|
|
1
|
+
import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
import { StatsigClient } from '@statsig/js-client';
|
|
2
3
|
export declare function useClientAsyncInit(sdkKey: string, initialUser: StatsigUser, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
4
|
isLoading: boolean;
|
|
4
|
-
client:
|
|
5
|
+
client: StatsigClient;
|
|
5
6
|
};
|
|
@@ -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
|
|
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 =
|
|
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,4 +1,5 @@
|
|
|
1
|
-
import { AnyStatsigOptions,
|
|
1
|
+
import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
import { StatsigClient } from '@statsig/js-client';
|
|
2
3
|
export declare function useClientBootstrapInit(sdkKey: string, initialUser: StatsigUser, initialValues: string, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
|
-
client:
|
|
4
|
+
client: StatsigClient;
|
|
4
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
|
|
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 =
|
|
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
|
|
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;
|
package/src/useDynamicConfig.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(configName, options) {
|
|
9
8
|
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
9
|
return (0, react_1.useMemo)(() => {
|
|
11
|
-
if ((0,
|
|
12
|
-
|
|
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
|
-
|
|
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;
|
package/src/useExperiment.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { Experiment, ExperimentEvaluationOptions
|
|
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;
|
package/src/useExperiment.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(experimentName, options) {
|
|
9
8
|
const { client, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
9
|
return (0, react_1.useMemo)(() => {
|
|
11
|
-
if ((0,
|
|
12
|
-
|
|
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
|
-
|
|
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;
|
package/src/useFeatureGate.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FeatureGate, FeatureGateEvaluationOptions
|
|
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;
|
package/src/useFeatureGate.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(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,
|
|
12
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/useGateValue.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FeatureGateEvaluationOptions
|
|
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;
|
package/src/useGateValue.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(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,
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
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,
|
|
12
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
package/src/useParameterStore.js
CHANGED
|
@@ -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,
|
|
12
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/useStatsigClient.js
CHANGED
|
@@ -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,
|
|
13
|
-
|
|
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
|
-
|
|
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, OnDeviceEvaluationsInterface, PrecomputedEvaluationsInterface, StatsigUser } from '@statsig/client-core';
|
|
2
|
-
export declare function requireOptionalClientDependency(sdkKey: string, initialUser: StatsigUser, statsigOptions: AnyStatsigOptions | null): PrecomputedEvaluationsInterface;
|
|
3
|
-
export declare function requireOptionalOnDeviceClientDependency(sdkKey: string, statsigOptions: AnyStatsigOptions | null): OnDeviceEvaluationsInterface;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireOptionalOnDeviceClientDependency = exports.requireOptionalClientDependency = void 0;
|
|
4
|
-
const client_core_1 = require("@statsig/client-core");
|
|
5
|
-
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
-
function requireOptionalClientDependency(sdkKey, initialUser, statsigOptions) {
|
|
7
|
-
let client;
|
|
8
|
-
try {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
|
10
|
-
const mod = require('@statsig/js-client');
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
12
|
-
client = new mod.StatsigClient(sdkKey, initialUser, statsigOptions);
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
client = NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
16
|
-
client_core_1.Log.error('Failed to load StatsigClient. Do you have @statsig/js-client installed?');
|
|
17
|
-
}
|
|
18
|
-
return client;
|
|
19
|
-
}
|
|
20
|
-
exports.requireOptionalClientDependency = requireOptionalClientDependency;
|
|
21
|
-
function requireOptionalOnDeviceClientDependency(sdkKey, statsigOptions) {
|
|
22
|
-
let client;
|
|
23
|
-
try {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
|
|
25
|
-
const mod = require('@statsig/js-on-device-eval-client');
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
27
|
-
client = new mod.StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
client = NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
31
|
-
client_core_1.Log.error('Failed to load StatsigClient. Do you have @statsig/js-on-device-eval-client installed?');
|
|
32
|
-
}
|
|
33
|
-
return client;
|
|
34
|
-
}
|
|
35
|
-
exports.requireOptionalOnDeviceClientDependency = requireOptionalOnDeviceClientDependency;
|
|
@@ -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 requireOptionalDependency_1 = require("./requireOptionalDependency");
|
|
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, requireOptionalDependency_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 requireOptionalDependency_1 = require("./requireOptionalDependency");
|
|
6
|
-
function useOnDeviceClientBootstrapInit(sdkKey, initialValues, statsigOptions = null) {
|
|
7
|
-
const [args] = (0, react_1.useState)(() => {
|
|
8
|
-
const client = (0, requireOptionalDependency_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;
|