@statsig/react-bindings 1.7.0 → 2.0.0
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 +6 -2
- package/src/NoopEvaluationsClient.js +5 -15
- package/src/index.d.ts +5 -1
- package/src/index.js +17 -4
- package/src/requireOptionalDependency.d.ts +3 -0
- package/src/requireOptionalDependency.js +35 -0
- package/src/useClientAsyncInit.d.ts +5 -0
- package/src/useClientAsyncInit.js +19 -0
- package/src/useClientBootstrapInit.d.ts +4 -0
- package/src/useClientBootstrapInit.js +15 -0
- package/src/useOnDeviceClientAsyncInit.d.ts +5 -0
- package/src/useOnDeviceClientAsyncInit.js +19 -0
- package/src/useOnDeviceClientBootstrapInit.d.ts +4 -0
- package/src/useOnDeviceClientBootstrapInit.js +15 -0
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-bindings",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "
|
|
5
|
+
"@statsig/client-core": "2.0.0"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0"
|
|
9
9
|
},
|
|
10
|
+
"optionalDependencies": {
|
|
11
|
+
"@statsig/js-client": "2.0.0",
|
|
12
|
+
"@statsig/js-on-device-eval-client": "2.0.0"
|
|
13
|
+
},
|
|
10
14
|
"type": "commonjs",
|
|
11
15
|
"main": "./src/index.js",
|
|
12
16
|
"typings": "./src/index.d.ts"
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.NoopEvaluationsClient = void 0;
|
|
13
4
|
const client_core_1 = require("@statsig/client-core");
|
|
@@ -46,6 +37,11 @@ const context = {
|
|
|
46
37
|
values: null,
|
|
47
38
|
user: { userID: '' },
|
|
48
39
|
errorBoundary: {},
|
|
40
|
+
session: {
|
|
41
|
+
data: { sessionID: '', startTime: 0, lastUpdate: 0 },
|
|
42
|
+
sdkKey: '',
|
|
43
|
+
},
|
|
44
|
+
stableID: '',
|
|
49
45
|
};
|
|
50
46
|
const _client = {
|
|
51
47
|
isNoop: true,
|
|
@@ -58,12 +54,6 @@ const _client = {
|
|
|
58
54
|
updateUserSync: _noop,
|
|
59
55
|
updateUserAsync: _noopAsync,
|
|
60
56
|
getContext: () => (Object.assign({}, context)),
|
|
61
|
-
getAsyncContext: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
return (Object.assign(Object.assign({}, context), { session: {
|
|
63
|
-
data: { sessionID: '', startTime: 0, lastUpdate: 0 },
|
|
64
|
-
sdkKey: '',
|
|
65
|
-
}, stableID: '' }));
|
|
66
|
-
}),
|
|
67
57
|
checkGate: () => false,
|
|
68
58
|
getFeatureGate: _defaultEvaluation('gate'),
|
|
69
59
|
getDynamicConfig: _defaultEvaluation('config'),
|
package/src/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import StatsigContext from './StatsigContext';
|
|
2
2
|
import { StatsigProvider, StatsigProviderProps } from './StatsigProvider';
|
|
3
|
+
import { useClientAsyncInit } from './useClientAsyncInit';
|
|
4
|
+
import { useClientBootstrapInit } from './useClientBootstrapInit';
|
|
3
5
|
import useDynamicConfig from './useDynamicConfig';
|
|
4
6
|
import useExperiment from './useExperiment';
|
|
5
7
|
import useFeatureGate from './useFeatureGate';
|
|
6
8
|
import useGateValue from './useGateValue';
|
|
7
9
|
import useLayer from './useLayer';
|
|
10
|
+
import { useOnDeviceClientAsyncInit } from './useOnDeviceClientAsyncInit';
|
|
11
|
+
import { useOnDeviceClientBootstrapInit } from './useOnDeviceClientBootstrapInit';
|
|
8
12
|
import useParameterStore from './useParameterStore';
|
|
9
13
|
import { useStatsigClient } from './useStatsigClient';
|
|
10
14
|
import { useStatsigOnDeviceEvalClient } from './useStatsigOnDeviceEvalClient';
|
|
11
15
|
import { useStatsigUser } from './useStatsigUser';
|
|
12
16
|
export type { StatsigProviderProps };
|
|
13
|
-
export { StatsigContext, StatsigProvider, useDynamicConfig, useExperiment, useFeatureGate, useGateValue, useLayer, useParameterStore, useStatsigClient, useStatsigOnDeviceEvalClient, useStatsigUser, };
|
|
17
|
+
export { StatsigContext, StatsigProvider, useClientAsyncInit, useClientBootstrapInit, useDynamicConfig, useExperiment, useFeatureGate, useGateValue, useLayer, useOnDeviceClientAsyncInit, useOnDeviceClientBootstrapInit, useParameterStore, useStatsigClient, useStatsigOnDeviceEvalClient, useStatsigUser, };
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useStatsigUser = exports.useStatsigOnDeviceEvalClient = exports.useStatsigClient = exports.useParameterStore = exports.useLayer = exports.useGateValue = exports.useFeatureGate = exports.useExperiment = exports.useDynamicConfig = exports.StatsigProvider = exports.StatsigContext = void 0;
|
|
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;
|
|
4
4
|
const StatsigContext_1 = require("./StatsigContext");
|
|
5
5
|
exports.StatsigContext = StatsigContext_1.default;
|
|
6
6
|
const StatsigProvider_1 = require("./StatsigProvider");
|
|
7
7
|
Object.defineProperty(exports, "StatsigProvider", { enumerable: true, get: function () { return StatsigProvider_1.StatsigProvider; } });
|
|
8
|
+
const useClientAsyncInit_1 = require("./useClientAsyncInit");
|
|
9
|
+
Object.defineProperty(exports, "useClientAsyncInit", { enumerable: true, get: function () { return useClientAsyncInit_1.useClientAsyncInit; } });
|
|
10
|
+
const useClientBootstrapInit_1 = require("./useClientBootstrapInit");
|
|
11
|
+
Object.defineProperty(exports, "useClientBootstrapInit", { enumerable: true, get: function () { return useClientBootstrapInit_1.useClientBootstrapInit; } });
|
|
8
12
|
const useDynamicConfig_1 = require("./useDynamicConfig");
|
|
9
13
|
exports.useDynamicConfig = useDynamicConfig_1.default;
|
|
10
14
|
const useExperiment_1 = require("./useExperiment");
|
|
@@ -15,6 +19,10 @@ const useGateValue_1 = require("./useGateValue");
|
|
|
15
19
|
exports.useGateValue = useGateValue_1.default;
|
|
16
20
|
const useLayer_1 = require("./useLayer");
|
|
17
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; } });
|
|
18
26
|
const useParameterStore_1 = require("./useParameterStore");
|
|
19
27
|
exports.useParameterStore = useParameterStore_1.default;
|
|
20
28
|
const useStatsigClient_1 = require("./useStatsigClient");
|
|
@@ -25,11 +33,16 @@ const useStatsigUser_1 = require("./useStatsigUser");
|
|
|
25
33
|
Object.defineProperty(exports, "useStatsigUser", { enumerable: true, get: function () { return useStatsigUser_1.useStatsigUser; } });
|
|
26
34
|
__STATSIG__ = Object.assign(Object.assign({}, (__STATSIG__ !== null && __STATSIG__ !== void 0 ? __STATSIG__ : {})), { StatsigContext: StatsigContext_1.default,
|
|
27
35
|
StatsigProvider: StatsigProvider_1.StatsigProvider,
|
|
36
|
+
useClientAsyncInit: useClientAsyncInit_1.useClientAsyncInit,
|
|
37
|
+
useClientBootstrapInit: useClientBootstrapInit_1.useClientBootstrapInit,
|
|
28
38
|
useDynamicConfig: useDynamicConfig_1.default,
|
|
29
39
|
useExperiment: useExperiment_1.default,
|
|
30
|
-
useGateValue: useGateValue_1.default,
|
|
31
40
|
useFeatureGate: useFeatureGate_1.default,
|
|
41
|
+
useGateValue: useGateValue_1.default,
|
|
32
42
|
useLayer: useLayer_1.default,
|
|
33
|
-
|
|
43
|
+
useOnDeviceClientAsyncInit: useOnDeviceClientAsyncInit_1.useOnDeviceClientAsyncInit,
|
|
44
|
+
useOnDeviceClientBootstrapInit: useOnDeviceClientBootstrapInit_1.useOnDeviceClientBootstrapInit,
|
|
45
|
+
useParameterStore: useParameterStore_1.default,
|
|
34
46
|
useStatsigClient: useStatsigClient_1.useStatsigClient,
|
|
35
|
-
|
|
47
|
+
useStatsigOnDeviceEvalClient: useStatsigOnDeviceEvalClient_1.useStatsigOnDeviceEvalClient,
|
|
48
|
+
useStatsigUser: useStatsigUser_1.useStatsigUser });
|
|
@@ -0,0 +1,3 @@
|
|
|
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;
|
|
@@ -0,0 +1,35 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AnyStatsigOptions, PrecomputedEvaluationsInterface, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export declare function useClientAsyncInit(sdkKey: string, initialUser: StatsigUser, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
client: PrecomputedEvaluationsInterface;
|
|
5
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useClientAsyncInit = 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 useClientAsyncInit(sdkKey, initialUser, statsigOptions = null) {
|
|
8
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
9
|
+
const [args] = (0, react_1.useState)(() => {
|
|
10
|
+
const client = (0, requireOptionalDependency_1.requireOptionalClientDependency)(sdkKey, initialUser, statsigOptions);
|
|
11
|
+
client
|
|
12
|
+
.initializeAsync()
|
|
13
|
+
.catch(client_core_1.Log.error)
|
|
14
|
+
.finally(() => setIsLoading(false));
|
|
15
|
+
return { client, initialUser, sdkKey };
|
|
16
|
+
});
|
|
17
|
+
return { client: args.client, isLoading };
|
|
18
|
+
}
|
|
19
|
+
exports.useClientAsyncInit = useClientAsyncInit;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AnyStatsigOptions, PrecomputedEvaluationsInterface, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
export declare function useClientBootstrapInit(sdkKey: string, initialUser: StatsigUser, initialValues: string, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
|
+
client: PrecomputedEvaluationsInterface;
|
|
4
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useClientBootstrapInit = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const requireOptionalDependency_1 = require("./requireOptionalDependency");
|
|
6
|
+
function useClientBootstrapInit(sdkKey, initialUser, initialValues, statsigOptions = null) {
|
|
7
|
+
const [args] = (0, react_1.useState)(() => {
|
|
8
|
+
const client = (0, requireOptionalDependency_1.requireOptionalClientDependency)(sdkKey, initialUser, statsigOptions);
|
|
9
|
+
client.dataAdapter.setData(initialValues);
|
|
10
|
+
client.initializeSync();
|
|
11
|
+
return { client, initialValues, initialUser, sdkKey };
|
|
12
|
+
});
|
|
13
|
+
return { client: args.client };
|
|
14
|
+
}
|
|
15
|
+
exports.useClientBootstrapInit = useClientBootstrapInit;
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AnyStatsigOptions, OnDeviceEvaluationsInterface } from '@statsig/client-core';
|
|
2
|
+
export declare function useOnDeviceClientBootstrapInit(sdkKey: string, initialValues: string, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
|
+
client: OnDeviceEvaluationsInterface;
|
|
4
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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;
|