@statsig/react-bindings 2.0.0 → 2.1.1-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.
- package/README.md +2 -2
- package/package.json +4 -4
- package/src/StatsigProvider.d.ts +14 -4
- package/src/StatsigProvider.js +8 -4
- package/src/requireOptionalDependency.d.ts +5 -3
- package/src/requireOptionalDependency.js +10 -9
- package/src/useClientAsyncInit.d.ts +3 -2
- package/src/useClientBootstrapInit.d.ts +3 -2
- package/src/useOnDeviceClientAsyncInit.d.ts +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
Statsig helps you move faster with feature gates (feature flags), and/or dynamic configs. It also allows you to run A/B/n tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, check out our product and create an account at [statsig.com](https://www.statsig.com/?ref=gh_jsm).
|
|
2
|
+
|
|
1
3
|
<h1 align="center">
|
|
2
4
|
<a href="https://statsig.com/?ref=gh_jsm">
|
|
3
5
|
<img src="https://github.com/statsig-io/js-client-monorepo/assets/95646168/ae5499ed-20ff-4584-bf21-8857f800d485" />
|
|
@@ -18,8 +20,6 @@
|
|
|
18
20
|
</a>
|
|
19
21
|
</p>
|
|
20
22
|
|
|
21
|
-
Statsig helps you move faster with feature gates (feature flags), and/or dynamic configs. It also allows you to run A/B/n tests to validate your new features and understand their impact on your KPIs. If you're new to Statsig, check out our product and create an account at [statsig.com](https://www.statsig.com/?ref=gh_jsm).
|
|
22
|
-
|
|
23
23
|
## Getting Started
|
|
24
24
|
|
|
25
25
|
Read through the [Documentation](https://docs.statsig.com/client/javascript-sdk?ref=gh_jsm) or check out the [Samples](samples/).
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-bindings",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1-beta.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "2.
|
|
5
|
+
"@statsig/client-core": "2.1.1-beta.1"
|
|
6
6
|
},
|
|
7
7
|
"peerDependencies": {
|
|
8
8
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0"
|
|
9
9
|
},
|
|
10
10
|
"optionalDependencies": {
|
|
11
|
-
"@statsig/js-client": "2.
|
|
12
|
-
"@statsig/js-on-device-eval-client": "2.
|
|
11
|
+
"@statsig/js-client": "2.1.1-beta.1",
|
|
12
|
+
"@statsig/js-on-device-eval-client": "2.1.1-beta.1"
|
|
13
13
|
},
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"main": "./src/index.js",
|
package/src/StatsigProvider.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
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';
|
|
5
|
+
type WithClient = {
|
|
6
|
+
client: StatsigClient | StatsigOnDeviceEvalClient;
|
|
7
|
+
};
|
|
8
|
+
type WithConfiguration = {
|
|
9
|
+
sdkKey: string;
|
|
10
|
+
user: StatsigUser;
|
|
11
|
+
options?: StatsigOptionsOnDeviceEval | StatsigOptions;
|
|
12
|
+
};
|
|
3
13
|
export type StatsigProviderProps = {
|
|
4
14
|
children: ReactNode | ReactNode[];
|
|
5
|
-
client: StatsigClientInterface;
|
|
6
15
|
loadingComponent?: ReactNode | ReactNode[];
|
|
7
|
-
};
|
|
8
|
-
export declare function StatsigProvider(
|
|
16
|
+
} & (WithClient | WithConfiguration);
|
|
17
|
+
export declare function StatsigProvider(props: StatsigProviderProps): JSX.Element;
|
|
18
|
+
export {};
|
package/src/StatsigProvider.js
CHANGED
|
@@ -5,8 +5,12 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const client_core_1 = require("@statsig/client-core");
|
|
7
7
|
const StatsigContext_1 = require("./StatsigContext");
|
|
8
|
-
|
|
8
|
+
const useClientAsyncInit_1 = require("./useClientAsyncInit");
|
|
9
|
+
function StatsigProvider(props) {
|
|
9
10
|
const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
|
|
11
|
+
const client = 'client' in props
|
|
12
|
+
? props.client
|
|
13
|
+
: (0, useClientAsyncInit_1.useClientAsyncInit)(props.sdkKey, props.user).client;
|
|
10
14
|
(0, react_1.useEffect)(() => {
|
|
11
15
|
const onValuesUpdated = () => {
|
|
12
16
|
setRenderVersion((v) => v + 1);
|
|
@@ -21,9 +25,9 @@ function StatsigProvider({ client, children, loadingComponent, }) {
|
|
|
21
25
|
};
|
|
22
26
|
}, [client]);
|
|
23
27
|
const contextValue = (0, react_1.useMemo)(() => ({ renderVersion, client }), [renderVersion, client]);
|
|
24
|
-
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: loadingComponent == null || _isReady(client)
|
|
25
|
-
? children
|
|
26
|
-
: loadingComponent }));
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: props.loadingComponent == null || _isReady(client)
|
|
29
|
+
? props.children
|
|
30
|
+
: props.loadingComponent }));
|
|
27
31
|
}
|
|
28
32
|
exports.StatsigProvider = StatsigProvider;
|
|
29
33
|
function _isReady(client) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { AnyStatsigOptions,
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
import type { StatsigClient as TStatsigClient } from '@statsig/js-client';
|
|
3
|
+
import type { StatsigOnDeviceEvalClient as TStatsigOnDeviceEvalClient } from '@statsig/js-on-device-eval-client';
|
|
4
|
+
export declare function requireOptionalClientDependency(sdkKey: string, initialUser: StatsigUser, statsigOptions: AnyStatsigOptions | null): TStatsigClient;
|
|
5
|
+
export declare function requireOptionalOnDeviceClientDependency(sdkKey: string, statsigOptions: AnyStatsigOptions | null): TStatsigOnDeviceEvalClient;
|
|
@@ -3,13 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.requireOptionalOnDeviceClientDependency = exports.requireOptionalClientDependency = void 0;
|
|
4
4
|
const client_core_1 = require("@statsig/client-core");
|
|
5
5
|
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
function _unsafeRequire(modName) {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
9
|
+
return require(modName);
|
|
10
|
+
}
|
|
6
11
|
function requireOptionalClientDependency(sdkKey, initialUser, statsigOptions) {
|
|
7
12
|
let client;
|
|
8
13
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
12
|
-
client = new mod.StatsigClient(sdkKey, initialUser, statsigOptions);
|
|
14
|
+
const { StatsigClient } = _unsafeRequire('@statsig/js-client');
|
|
15
|
+
client = new StatsigClient(sdkKey, initialUser, statsigOptions);
|
|
13
16
|
}
|
|
14
17
|
catch (error) {
|
|
15
18
|
client = NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
@@ -21,14 +24,12 @@ exports.requireOptionalClientDependency = requireOptionalClientDependency;
|
|
|
21
24
|
function requireOptionalOnDeviceClientDependency(sdkKey, statsigOptions) {
|
|
22
25
|
let client;
|
|
23
26
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
27
|
-
client = new mod.StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
|
|
27
|
+
const { StatsigOnDeviceEvalClient } = _unsafeRequire('@statsig/js-on-device-eval-client');
|
|
28
|
+
client = new StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
|
|
28
29
|
}
|
|
29
30
|
catch (error) {
|
|
30
31
|
client = NoopEvaluationsClient_1.NoopEvaluationsClient;
|
|
31
|
-
client_core_1.Log.error('Failed to load
|
|
32
|
+
client_core_1.Log.error('Failed to load StatsigOnDeviceEvalClient. Do you have @statsig/js-on-device-eval-client installed?');
|
|
32
33
|
}
|
|
33
34
|
return client;
|
|
34
35
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AnyStatsigOptions,
|
|
1
|
+
import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
import type { 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
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AnyStatsigOptions,
|
|
1
|
+
import { AnyStatsigOptions, StatsigUser } from '@statsig/client-core';
|
|
2
|
+
import type { 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
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AnyStatsigOptions
|
|
1
|
+
import { AnyStatsigOptions } from '@statsig/client-core';
|
|
2
|
+
import type { StatsigOnDeviceEvalClient } from '@statsig/js-on-device-eval-client';
|
|
2
3
|
export declare function useOnDeviceClientAsyncInit(sdkKey: string, statsigOptions?: AnyStatsigOptions | null): {
|
|
3
4
|
isLoading: boolean;
|
|
4
|
-
client:
|
|
5
|
+
client: StatsigOnDeviceEvalClient;
|
|
5
6
|
};
|