@scaleway/use-growthbook 2.1.14 → 2.1.15

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 CHANGED
@@ -23,7 +23,7 @@ ReactDOM.render(
23
23
  <React.StrictMode>
24
24
  <AbTestProvider
25
25
  config={{ apiHost: 'string', clientKey: 'string', enableDevMode: true }}
26
- anonymousId="123456789"
26
+ anonymousId='123456789'
27
27
  trackingCallback={(experiment, result) => console.log(experiment, result)}
28
28
  errorCallback={console.error}
29
29
  >
@@ -1,6 +1,7 @@
1
1
  let _growthbook_growthbook_react = require("@growthbook/growthbook-react");
2
2
  let react = require("react");
3
3
  let react_jsx_runtime = require("react/jsx-runtime");
4
+ //#region src/AbTestProvider.tsx
4
5
  var defaultLoadConfig = {
5
6
  skipCache: false,
6
7
  timeout: 500
@@ -11,7 +12,7 @@ var getGrowthBookInstance = ({ config: { apiHost, clientKey, enableDevMode }, tr
11
12
  enableDevMode,
12
13
  trackingCallback
13
14
  });
14
- const AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
15
+ var AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
15
16
  const growthbook = (0, react.useMemo)(() => getGrowthBookInstance({
16
17
  config,
17
18
  trackingCallback
@@ -30,14 +31,20 @@ const AbTestProvider = ({ children, config, trackingCallback, errorCallback, att
30
31
  loadConfig
31
32
  ]);
32
33
  (0, react.useEffect)(() => {
33
- loadFeature().catch(errorCallback);
34
+ loadFeature().catch((error) => {
35
+ if (errorCallback && error instanceof Error) errorCallback(error);
36
+ return null;
37
+ });
34
38
  }, [loadFeature, errorCallback]);
35
39
  (0, react.useEffect)(() => {
36
40
  const currentAttributes = growthbook.getAttributes();
37
41
  if (currentAttributes !== attributes) growthbook.setAttributes({
38
42
  ...currentAttributes,
39
43
  ...attributes
40
- }).catch(errorCallback);
44
+ }).catch((error) => {
45
+ if (errorCallback && error instanceof Error) errorCallback(error);
46
+ return null;
47
+ });
41
48
  }, [
42
49
  attributes,
43
50
  growthbook,
@@ -48,4 +55,5 @@ const AbTestProvider = ({ children, config, trackingCallback, errorCallback, att
48
55
  children
49
56
  });
50
57
  };
58
+ //#endregion
51
59
  exports.AbTestProvider = AbTestProvider;
@@ -1,6 +1,7 @@
1
1
  import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
2
2
  import { useCallback, useEffect, useMemo } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
+ //#region src/AbTestProvider.tsx
4
5
  var defaultLoadConfig = {
5
6
  skipCache: false,
6
7
  timeout: 500
@@ -11,7 +12,7 @@ var getGrowthBookInstance = ({ config: { apiHost, clientKey, enableDevMode }, tr
11
12
  enableDevMode,
12
13
  trackingCallback
13
14
  });
14
- const AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
15
+ var AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
15
16
  const growthbook = useMemo(() => getGrowthBookInstance({
16
17
  config,
17
18
  trackingCallback
@@ -30,14 +31,20 @@ const AbTestProvider = ({ children, config, trackingCallback, errorCallback, att
30
31
  loadConfig
31
32
  ]);
32
33
  useEffect(() => {
33
- loadFeature().catch(errorCallback);
34
+ loadFeature().catch((error) => {
35
+ if (errorCallback && error instanceof Error) errorCallback(error);
36
+ return null;
37
+ });
34
38
  }, [loadFeature, errorCallback]);
35
39
  useEffect(() => {
36
40
  const currentAttributes = growthbook.getAttributes();
37
41
  if (currentAttributes !== attributes) growthbook.setAttributes({
38
42
  ...currentAttributes,
39
43
  ...attributes
40
- }).catch(errorCallback);
44
+ }).catch((error) => {
45
+ if (errorCallback && error instanceof Error) errorCallback(error);
46
+ return null;
47
+ });
41
48
  }, [
42
49
  attributes,
43
50
  growthbook,
@@ -48,4 +55,5 @@ const AbTestProvider = ({ children, config, trackingCallback, errorCallback, att
48
55
  children
49
56
  });
50
57
  };
58
+ //#endregion
51
59
  export { AbTestProvider };
package/dist/types.d.ts CHANGED
@@ -8,4 +8,4 @@ export type Attributes = Record<string, string | number | undefined>;
8
8
  export type LoadConfig = NonNullable<Parameters<GrowthBook['init']>[0]>;
9
9
  export type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'debug' | 'stickyBucketService'>;
10
10
  export type TrackingCallback = NonNullable<Context['trackingCallback']>;
11
- export type ErrorCallback = (error: Error | string) => void | null;
11
+ export type ErrorCallback = ((error: Error | string) => void) | null;
@@ -1,5 +1,6 @@
1
1
  let _growthbook_growthbook_react = require("@growthbook/growthbook-react");
2
- const useAbTestAttributes = () => {
2
+ //#region src/useAbTestAttributes.ts
3
+ var useAbTestAttributes = () => {
3
4
  const growthBook = (0, _growthbook_growthbook_react.useGrowthBook)();
4
5
  const attributes = growthBook.getAttributes();
5
6
  const setAttributes = async (newAttributes) => growthBook.setAttributes({
@@ -8,4 +9,5 @@ const useAbTestAttributes = () => {
8
9
  });
9
10
  return [attributes, setAttributes];
10
11
  };
12
+ //#endregion
11
13
  exports.useAbTestAttributes = useAbTestAttributes;
@@ -1,5 +1,6 @@
1
1
  import { useGrowthBook } from "@growthbook/growthbook-react";
2
- const useAbTestAttributes = () => {
2
+ //#region src/useAbTestAttributes.ts
3
+ var useAbTestAttributes = () => {
3
4
  const growthBook = useGrowthBook();
4
5
  const attributes = growthBook.getAttributes();
5
6
  const setAttributes = async (newAttributes) => growthBook.setAttributes({
@@ -8,4 +9,5 @@ const useAbTestAttributes = () => {
8
9
  });
9
10
  return [attributes, setAttributes];
10
11
  };
12
+ //#endregion
11
13
  export { useAbTestAttributes };
package/package.json CHANGED
@@ -1,13 +1,23 @@
1
1
  {
2
2
  "name": "@scaleway/use-growthbook",
3
- "version": "2.1.14",
3
+ "version": "2.1.15",
4
4
  "description": "Utility package to expose AB test tool",
5
- "engines": {
6
- "node": ">=20.x"
5
+ "keywords": [
6
+ "ab",
7
+ "feature flags"
8
+ ],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/scaleway/scaleway-lib",
13
+ "directory": "packages/growthbook"
7
14
  },
8
- "main": "./dist/index.cjs",
9
- "sideEffects": false,
15
+ "files": [
16
+ "dist/*"
17
+ ],
10
18
  "type": "module",
19
+ "sideEffects": false,
20
+ "main": "./dist/index.cjs",
11
21
  "module": "./dist/index.js",
12
22
  "types": "./dist/index.d.ts",
13
23
  "exports": {
@@ -20,34 +30,22 @@
20
30
  "publishConfig": {
21
31
  "access": "public"
22
32
  },
23
- "files": [
24
- "dist/*"
25
- ],
26
- "repository": {
27
- "type": "git",
28
- "url": "https://github.com/scaleway/scaleway-lib",
29
- "directory": "packages/growthbook"
30
- },
31
- "license": "MIT",
32
- "keywords": [
33
- "ab",
34
- "feature flags"
35
- ],
36
33
  "dependencies": {
37
- "@growthbook/growthbook-react": "1.6.4"
34
+ "@growthbook/growthbook-react": "1.6.5"
38
35
  },
39
36
  "devDependencies": {
40
- "react": "19.2.4"
37
+ "react": "19.2.5"
41
38
  },
42
39
  "peerDependencies": {
43
40
  "react": "18.x || 19.x"
44
41
  },
42
+ "engines": {
43
+ "node": ">=20.x"
44
+ },
45
45
  "scripts": {
46
46
  "prebuild": "shx rm -rf dist",
47
- "typecheck": "tsc --noEmit",
48
- "typecheck:go": "tsgo --noEmit",
49
- "type:generate": "tsc --declaration -p tsconfig.build.json",
50
- "type:generate:go": "tsgo --declaration -p tsconfig.build.json",
47
+ "typecheck": "tsgo --noEmit",
48
+ "type:generate": "tsgo --declaration -p tsconfig.build.json",
51
49
  "build": "vite build --config vite.config.ts && pnpm run type:generate",
52
50
  "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
53
51
  "test:unit": "vitest --run --config vite.config.ts",