@scaleway/use-growthbook 2.1.16 → 3.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Scaleway
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,12 +1,15 @@
1
- import type { ComponentType, ReactNode } from 'react';
2
- import type { Attributes, ErrorCallback, LoadConfig, ToolConfig, TrackingCallback } from './types';
1
+ import { Attributes, ErrorCallback, LoadConfig, ToolConfig, TrackingCallback } from "./types.js";
2
+ import { ComponentType, ReactNode } from "react";
3
+
4
+ //#region src/AbTestProvider.d.ts
3
5
  type AbTestProviderProps = {
4
- children: ReactNode;
5
- config: ToolConfig;
6
- trackingCallback: TrackingCallback;
7
- errorCallback: ErrorCallback;
8
- attributes: Attributes;
9
- loadConfig?: LoadConfig;
6
+ children: ReactNode;
7
+ config: ToolConfig;
8
+ trackingCallback: TrackingCallback;
9
+ errorCallback: ErrorCallback;
10
+ attributes: Attributes;
11
+ loadConfig?: LoadConfig;
10
12
  };
11
- export declare const AbTestProvider: ComponentType<AbTestProviderProps>;
12
- export {};
13
+ declare const AbTestProvider: ComponentType<AbTestProviderProps>;
14
+ //#endregion
15
+ export { AbTestProvider };
@@ -2,17 +2,17 @@ import { GrowthBook, GrowthBookProvider } from "@growthbook/growthbook-react";
2
2
  import { useCallback, useEffect, useMemo } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  //#region src/AbTestProvider.tsx
5
- var defaultLoadConfig = {
5
+ const defaultLoadConfig = {
6
6
  skipCache: false,
7
7
  timeout: 500
8
8
  };
9
- var getGrowthBookInstance = ({ config: { apiHost, clientKey, enableDevMode }, trackingCallback }) => new GrowthBook({
9
+ const getGrowthBookInstance = ({ config: { apiHost, clientKey, enableDevMode }, trackingCallback }) => new GrowthBook({
10
10
  apiHost,
11
11
  clientKey,
12
12
  enableDevMode,
13
13
  trackingCallback
14
14
  });
15
- var AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
15
+ const AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
16
16
  const growthbook = useMemo(() => getGrowthBookInstance({
17
17
  config,
18
18
  trackingCallback
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, withRunExperiment, } from '@growthbook/growthbook-react';
2
- export { AbTestProvider } from './AbTestProvider';
3
- export type { ErrorCallback, ToolConfig, TrackingCallback } from './types';
4
- export { useAbTestAttributes } from './useAbTestAttributes';
1
+ import { ErrorCallback, ToolConfig, TrackingCallback } from "./types.js";
2
+ import { AbTestProvider } from "./AbTestProvider.js";
3
+ import { useAbTestAttributes } from "./useAbTestAttributes.js";
4
+ import { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, withRunExperiment } from "@growthbook/growthbook-react";
5
+ export { AbTestProvider, type ErrorCallback, FeatureString, FeaturesReady, IfFeatureEnabled, type ToolConfig, type TrackingCallback, useAbTestAttributes, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, withRunExperiment };
package/dist/types.d.ts CHANGED
@@ -1,11 +1,15 @@
1
- import type { Context, GrowthBook } from '@growthbook/growthbook-react';
2
- export type Attributes = Record<string, string | number | undefined>;
1
+ import { Context, GrowthBook } from "@growthbook/growthbook-react";
2
+
3
+ //#region src/types.d.ts
4
+ type Attributes = Record<string, string | number | undefined>;
3
5
  /**
4
6
  * @param {boolean} [autoRefresh] - false.
5
7
  * @param {number} [timeout] - 500.
6
8
  * @param {boolean} [skipCache] - false.
7
9
  */
8
- export type LoadConfig = NonNullable<Parameters<GrowthBook['init']>[0]>;
9
- export type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'debug' | 'stickyBucketService'>;
10
- export type TrackingCallback = NonNullable<Context['trackingCallback']>;
11
- export type ErrorCallback = ((error: Error | string) => void) | null;
10
+ type LoadConfig = NonNullable<Parameters<GrowthBook['init']>[0]>;
11
+ type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'debug' | 'stickyBucketService'>;
12
+ type TrackingCallback = NonNullable<Context['trackingCallback']>;
13
+ type ErrorCallback = ((error: Error | string) => void) | null;
14
+ //#endregion
15
+ export { Attributes, ErrorCallback, LoadConfig, ToolConfig, TrackingCallback };
@@ -1,2 +1,6 @@
1
- import type { Attributes } from './types';
2
- export declare const useAbTestAttributes: () => [Attributes, (attributes: Attributes) => void];
1
+ import { Attributes } from "./types.js";
2
+
3
+ //#region src/useAbTestAttributes.d.ts
4
+ declare const useAbTestAttributes: () => [Attributes, (attributes: Attributes) => void];
5
+ //#endregion
6
+ export { useAbTestAttributes };
@@ -1,6 +1,6 @@
1
1
  import { useGrowthBook } from "@growthbook/growthbook-react";
2
2
  //#region src/useAbTestAttributes.ts
3
- var useAbTestAttributes = () => {
3
+ const useAbTestAttributes = () => {
4
4
  const growthBook = useGrowthBook();
5
5
  const attributes = growthBook.getAttributes();
6
6
  const setAttributes = async (newAttributes) => growthBook.setAttributes({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleway/use-growthbook",
3
- "version": "2.1.16",
3
+ "version": "3.0.0",
4
4
  "description": "Utility package to expose AB test tool",
5
5
  "keywords": [
6
6
  "ab",
@@ -9,7 +9,7 @@
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "https://github.com/scaleway/scaleway-lib",
12
+ "url": "git+https://github.com/scaleway/scaleway-lib.git",
13
13
  "directory": "packages/growthbook"
14
14
  },
15
15
  "files": [
@@ -17,15 +17,10 @@
17
17
  ],
18
18
  "type": "module",
19
19
  "sideEffects": false,
20
- "main": "./dist/index.cjs",
21
- "module": "./dist/index.js",
22
20
  "types": "./dist/index.d.ts",
23
21
  "exports": {
24
- ".": {
25
- "types": "./dist/index.d.ts",
26
- "require": "./dist/index.cjs",
27
- "default": "./dist/index.js"
28
- }
22
+ ".": "./dist/index.js",
23
+ "./package.json": "./package.json"
29
24
  },
30
25
  "publishConfig": {
31
26
  "access": "public"
@@ -43,12 +38,9 @@
43
38
  "node": ">=20.x"
44
39
  },
45
40
  "scripts": {
46
- "prebuild": "shx rm -rf dist",
47
41
  "typecheck": "tsgo --noEmit",
48
- "type:generate": "tsgo --declaration -p tsconfig.build.json",
49
- "build": "vite build --config vite.config.ts && pnpm run type:generate",
50
- "build:profile": "npx vite-bundle-visualizer -c vite.config.ts",
51
- "test:unit": "vitest --run --config vite.config.ts",
42
+ "build": "tsdown",
43
+ "test:unit": "vitest --run",
52
44
  "test:unit:coverage": "pnpm test:unit --coverage"
53
45
  }
54
46
  }
@@ -1,3 +0,0 @@
1
- # Licenses
2
-
3
- The app does not bundle any dependencies with licenses.
@@ -1,59 +0,0 @@
1
- let _growthbook_growthbook_react = require("@growthbook/growthbook-react");
2
- let react = require("react");
3
- let react_jsx_runtime = require("react/jsx-runtime");
4
- //#region src/AbTestProvider.tsx
5
- var defaultLoadConfig = {
6
- skipCache: false,
7
- timeout: 500
8
- };
9
- var getGrowthBookInstance = ({ config: { apiHost, clientKey, enableDevMode }, trackingCallback }) => new _growthbook_growthbook_react.GrowthBook({
10
- apiHost,
11
- clientKey,
12
- enableDevMode,
13
- trackingCallback
14
- });
15
- var AbTestProvider = ({ children, config, trackingCallback, errorCallback, attributes, loadConfig }) => {
16
- const growthbook = (0, react.useMemo)(() => getGrowthBookInstance({
17
- config,
18
- trackingCallback
19
- }), [trackingCallback, config]);
20
- const loadFeature = (0, react.useCallback)(async () => {
21
- if (config.clientKey) {
22
- const initConfig = {
23
- ...defaultLoadConfig,
24
- ...loadConfig
25
- };
26
- await growthbook.init(initConfig);
27
- }
28
- }, [
29
- growthbook,
30
- config,
31
- loadConfig
32
- ]);
33
- (0, react.useEffect)(() => {
34
- loadFeature().catch((error) => {
35
- if (errorCallback && error instanceof Error) errorCallback(error);
36
- return null;
37
- });
38
- }, [loadFeature, errorCallback]);
39
- (0, react.useEffect)(() => {
40
- const currentAttributes = growthbook.getAttributes();
41
- if (currentAttributes !== attributes) growthbook.setAttributes({
42
- ...currentAttributes,
43
- ...attributes
44
- }).catch((error) => {
45
- if (errorCallback && error instanceof Error) errorCallback(error);
46
- return null;
47
- });
48
- }, [
49
- attributes,
50
- growthbook,
51
- errorCallback
52
- ]);
53
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_growthbook_growthbook_react.GrowthBookProvider, {
54
- growthbook,
55
- children
56
- });
57
- };
58
- //#endregion
59
- exports.AbTestProvider = AbTestProvider;
package/dist/index.cjs DELETED
@@ -1,60 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_AbTestProvider = require("./AbTestProvider.cjs");
3
- const require_useAbTestAttributes = require("./useAbTestAttributes.cjs");
4
- let _growthbook_growthbook_react = require("@growthbook/growthbook-react");
5
- exports.AbTestProvider = require_AbTestProvider.AbTestProvider;
6
- Object.defineProperty(exports, "FeatureString", {
7
- enumerable: true,
8
- get: function() {
9
- return _growthbook_growthbook_react.FeatureString;
10
- }
11
- });
12
- Object.defineProperty(exports, "FeaturesReady", {
13
- enumerable: true,
14
- get: function() {
15
- return _growthbook_growthbook_react.FeaturesReady;
16
- }
17
- });
18
- Object.defineProperty(exports, "IfFeatureEnabled", {
19
- enumerable: true,
20
- get: function() {
21
- return _growthbook_growthbook_react.IfFeatureEnabled;
22
- }
23
- });
24
- exports.useAbTestAttributes = require_useAbTestAttributes.useAbTestAttributes;
25
- Object.defineProperty(exports, "useExperiment", {
26
- enumerable: true,
27
- get: function() {
28
- return _growthbook_growthbook_react.useExperiment;
29
- }
30
- });
31
- Object.defineProperty(exports, "useFeature", {
32
- enumerable: true,
33
- get: function() {
34
- return _growthbook_growthbook_react.useFeature;
35
- }
36
- });
37
- Object.defineProperty(exports, "useFeatureIsOn", {
38
- enumerable: true,
39
- get: function() {
40
- return _growthbook_growthbook_react.useFeatureIsOn;
41
- }
42
- });
43
- Object.defineProperty(exports, "useFeatureValue", {
44
- enumerable: true,
45
- get: function() {
46
- return _growthbook_growthbook_react.useFeatureValue;
47
- }
48
- });
49
- Object.defineProperty(exports, "useGrowthBook", {
50
- enumerable: true,
51
- get: function() {
52
- return _growthbook_growthbook_react.useGrowthBook;
53
- }
54
- });
55
- Object.defineProperty(exports, "withRunExperiment", {
56
- enumerable: true,
57
- get: function() {
58
- return _growthbook_growthbook_react.withRunExperiment;
59
- }
60
- });
@@ -1,13 +0,0 @@
1
- let _growthbook_growthbook_react = require("@growthbook/growthbook-react");
2
- //#region src/useAbTestAttributes.ts
3
- var useAbTestAttributes = () => {
4
- const growthBook = (0, _growthbook_growthbook_react.useGrowthBook)();
5
- const attributes = growthBook.getAttributes();
6
- const setAttributes = async (newAttributes) => growthBook.setAttributes({
7
- ...attributes,
8
- ...newAttributes
9
- });
10
- return [attributes, setAttributes];
11
- };
12
- //#endregion
13
- exports.useAbTestAttributes = useAbTestAttributes;