@kameleoon/react-sdk 6.1.3 → 7.1.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/README.md +8 -1
- package/dist/eventSource/nativeEventSource.js +2 -2
- package/dist/eventSource/nativeEventSource.js.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.js +68 -3
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.js +2 -2
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonUtils/nativeUtils.js +0 -1
- package/dist/kameleoonUtils/nativeUtils.js.map +1 -1
- package/dist/useAddData.d.ts +7 -5
- package/dist/useAddData.js +3 -13
- package/dist/useAddData.js.map +1 -1
- package/dist/useBrowserVisitorCode.d.ts +4 -5
- package/dist/useBrowserVisitorCode.js +1 -1
- package/dist/useBrowserVisitorCode.js.map +1 -1
- package/dist/useConfigurationUpdate.d.ts +4 -4
- package/dist/useConfigurationUpdate.js +3 -13
- package/dist/useConfigurationUpdate.js.map +1 -1
- package/dist/useEngineTrackingCode.d.ts +5 -0
- package/dist/useEngineTrackingCode.js +20 -0
- package/dist/useEngineTrackingCode.js.map +1 -0
- package/dist/useExperimentVariationData.d.ts +21 -0
- package/dist/useExperimentVariationData.js +25 -0
- package/dist/useExperimentVariationData.js.map +1 -0
- package/dist/useExperiments.d.ts +4 -4
- package/dist/useExperiments.js +3 -14
- package/dist/useExperiments.js.map +1 -1
- package/dist/useFeatureFlagActive.d.ts +8 -4
- package/dist/useFeatureFlagActive.js +3 -14
- package/dist/useFeatureFlagActive.js.map +1 -1
- package/dist/useFeatureFlagVariationKey.d.ts +10 -7
- package/dist/useFeatureFlagVariationKey.js +3 -14
- package/dist/useFeatureFlagVariationKey.js.map +1 -1
- package/dist/useFeatureFlags.d.ts +4 -4
- package/dist/useFeatureFlags.js +3 -14
- package/dist/useFeatureFlags.js.map +1 -1
- package/dist/useFeatureVariable.d.ts +11 -6
- package/dist/useFeatureVariable.js +3 -14
- package/dist/useFeatureVariable.js.map +1 -1
- package/dist/useFlushData.d.ts +3 -0
- package/dist/useFlushData.js.map +1 -1
- package/dist/useInitialize.d.ts +5 -4
- package/dist/useInitialize.js +3 -14
- package/dist/useInitialize.js.map +1 -1
- package/dist/useKameleoon.d.ts +2 -1
- package/dist/useKameleoon.js +3 -3
- package/dist/useKameleoon.js.map +1 -1
- package/dist/useNativeVisitorCode.d.ts +3 -4
- package/dist/useNativeVisitorCode.js +1 -1
- package/dist/useNativeVisitorCode.js.map +1 -1
- package/dist/useRemoteData.d.ts +5 -5
- package/dist/useRemoteData.js +2 -14
- package/dist/useRemoteData.js.map +1 -1
- package/dist/useTrackConversion.d.ts +4 -3
- package/dist/useTrackConversion.js +2 -12
- package/dist/useTrackConversion.js.map +1 -1
- package/dist/useTriggerExperiment.d.ts +7 -3
- package/dist/useTriggerExperiment.js +3 -15
- package/dist/useTriggerExperiment.js.map +1 -1
- package/dist/useVisitorExperiments.d.ts +7 -6
- package/dist/useVisitorExperiments.js +3 -14
- package/dist/useVisitorExperiments.js.map +1 -1
- package/dist/useVisitorFeatureFlags.d.ts +6 -4
- package/dist/useVisitorFeatureFlags.js +3 -14
- package/dist/useVisitorFeatureFlags.js.map +1 -1
- package/package.json +3 -2
- package/dist/KameleoonError.d.ts +0 -5
- package/dist/KameleoonError.js +0 -20
- package/dist/KameleoonError.js.map +0 -1
- package/dist/ProviderError.d.ts +0 -3
- package/dist/ProviderError.js +0 -14
- package/dist/ProviderError.js.map +0 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +0 -9
- package/dist/constants.js.map +0 -1
- package/dist/useError.d.ts +0 -7
- package/dist/useError.js +0 -18
- package/dist/useError.js.map +0 -1
- package/dist/useErrors.d.ts +0 -7
- package/dist/useErrors.js +0 -19
- package/dist/useErrors.js.map +0 -1
package/dist/useRemoteData.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useRemoteData = useRemoteData;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useKameleoon = require("./useKameleoon");
|
|
9
|
-
var _useError = require("./useError");
|
|
10
9
|
/**
|
|
11
10
|
* A React Hook that returns asynchronous getRemoteData function which retrieves data from Kameleoon server.
|
|
12
11
|
*
|
|
@@ -16,22 +15,11 @@ function useRemoteData() {
|
|
|
16
15
|
const {
|
|
17
16
|
client
|
|
18
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
19
|
-
const {
|
|
20
|
-
error,
|
|
21
|
-
setError
|
|
22
|
-
} = (0, _useError.useError)();
|
|
23
18
|
const getRemoteData = (0, _react.useCallback)(async key => {
|
|
24
|
-
|
|
25
|
-
const remoteData = await client.getRemoteData(key);
|
|
26
|
-
return remoteData;
|
|
27
|
-
} catch (unknownError) {
|
|
28
|
-
setError(unknownError);
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
19
|
+
return await client.getRemoteData(key);
|
|
31
20
|
}, [client]);
|
|
32
21
|
return {
|
|
33
|
-
getRemoteData
|
|
34
|
-
error
|
|
22
|
+
getRemoteData
|
|
35
23
|
};
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=useRemoteData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteData.js","names":["_react","require","_useKameleoon","
|
|
1
|
+
{"version":3,"file":"useRemoteData.js","names":["_react","require","_useKameleoon","useRemoteData","client","useKameleoon","getRemoteData","useCallback","key"],"sources":["../src/useRemoteData.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { JSONType } from '@kameleoon/javascript-sdk-core';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface IRemoteDataHookResult {\n /**\n * Returns a data which is stored for specified siteCode on a remote Kameleoon server.\n *\n * @param {string} key - unique key that the data you try to get is associated with.\n * @returns {Promise<JSONType>} promise with retrieving data for specific key.\n * @throws `KameleoonError` with one of the following `type` s:\n * \n * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server.\n */\n getRemoteData: (key: string) => Promise<JSONType>;\n}\n\n/**\n * A React Hook that returns asynchronous getRemoteData function which retrieves data from Kameleoon server.\n *\n * @returns {IRemoteDataHookResult} an object containing the `getRemoteData` function.\n */\nexport function useRemoteData(): IRemoteDataHookResult {\n const { client } = useKameleoon();\n\n const getRemoteData = useCallback(\n async (key: string): Promise<JSONType> => {\n return await client.getRemoteData(key);\n },\n [client],\n );\n\n return {\n getRemoteData,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAeA;AACA;AACA;AACA;AACA;AACO,SAASE,aAAaA,CAAA,EAA0B;EACrD,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,aAAa,GAAG,IAAAC,kBAAW,EAC/B,MAAOC,GAAW,IAAwB;IACxC,OAAO,MAAMJ,MAAM,CAACE,aAAa,CAACE,GAAG,CAAC;EACxC,CAAC,EACD,CAACJ,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { TrackConversionParamsType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
-
import { KameleoonError } from './KameleoonError';
|
|
3
2
|
export interface ITrackConversionHookResult {
|
|
4
3
|
/**
|
|
5
4
|
* Creates and adds `Conversion` data to the visitor with specified parameters and executes `flushData`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter.
|
|
6
5
|
*
|
|
7
6
|
* @param {TrackConversionParamsType} params - `visitorCode`, `goalId` and `revenue` parameters for data tracking.
|
|
7
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
8
|
+
*
|
|
9
|
+
* - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded.
|
|
10
|
+
* - `KameleoonException.StorageWrite` Couldn't update storage data.
|
|
8
11
|
*/
|
|
9
12
|
trackConversion: (params: TrackConversionParamsType) => void;
|
|
10
|
-
/** An optional error object that may be returned if an error occurs while calling the `trackConversion` function. */
|
|
11
|
-
error: KameleoonError | null;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* A React Hook that returns trackConversion function which tracks conversion.
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useTrackConversion = useTrackConversion;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useKameleoon = require("./useKameleoon");
|
|
9
|
-
var _useError = require("./useError");
|
|
10
9
|
/**
|
|
11
10
|
* A React Hook that returns trackConversion function which tracks conversion.
|
|
12
11
|
*
|
|
@@ -16,20 +15,11 @@ function useTrackConversion() {
|
|
|
16
15
|
const {
|
|
17
16
|
client
|
|
18
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
19
|
-
const {
|
|
20
|
-
error,
|
|
21
|
-
setError
|
|
22
|
-
} = (0, _useError.useError)();
|
|
23
18
|
const trackConversion = (0, _react.useCallback)(params => {
|
|
24
|
-
|
|
25
|
-
client.trackConversion(params);
|
|
26
|
-
} catch (unknownError) {
|
|
27
|
-
setError(unknownError);
|
|
28
|
-
}
|
|
19
|
+
client.trackConversion(params);
|
|
29
20
|
}, [client]);
|
|
30
21
|
return {
|
|
31
|
-
trackConversion
|
|
32
|
-
error
|
|
22
|
+
trackConversion
|
|
33
23
|
};
|
|
34
24
|
}
|
|
35
25
|
//# sourceMappingURL=useTrackConversion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTrackConversion.js","names":["_react","require","_useKameleoon","
|
|
1
|
+
{"version":3,"file":"useTrackConversion.js","names":["_react","require","_useKameleoon","useTrackConversion","client","useKameleoon","trackConversion","useCallback","params"],"sources":["../src/useTrackConversion.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { TrackConversionParamsType } from '@kameleoon/javascript-sdk-core';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface ITrackConversionHookResult {\n /**\n * Creates and adds `Conversion` data to the visitor with specified parameters and executes `flushData`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter.\n *\n * @param {TrackConversionParamsType} params - `visitorCode`, `goalId` and `revenue` parameters for data tracking.\n * @throws `KameleoonError` with one of the following `type` s:\n * \n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded.\n * - `KameleoonException.StorageWrite` Couldn't update storage data.\n */\n trackConversion: (params: TrackConversionParamsType) => void;\n}\n\n/**\n * A React Hook that returns trackConversion function which tracks conversion.\n *\n * @returns {ITrackConversionHookResult} an object containing the `trackConversion` function.\n */\nexport function useTrackConversion(): ITrackConversionHookResult {\n const { client } = useKameleoon();\n\n const trackConversion = useCallback(\n (params: TrackConversionParamsType): void => {\n client.trackConversion(params);\n },\n [client],\n );\n\n return {\n trackConversion,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAeA;AACA;AACA;AACA;AACA;AACO,SAASE,kBAAkBA,CAAA,EAA+B;EAC/D,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,eAAe,GAAG,IAAAC,kBAAW,EAChCC,MAAiC,IAAW;IAC3CJ,MAAM,CAACE,eAAe,CAACE,MAAM,CAAC;EAChC,CAAC,EACD,CAACJ,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { KameleoonError } from './KameleoonError';
|
|
2
1
|
export interface ITriggerExperimentHookResult {
|
|
3
2
|
/**
|
|
4
3
|
* Triggers experiment by assigning the variation to the user with `visitorCode`, if the variation is already assigned just returns it's id. Note: returned id `0` indicates default variation. At the same time executes `flushData` without sending extra request.
|
|
@@ -6,10 +5,15 @@ export interface ITriggerExperimentHookResult {
|
|
|
6
5
|
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.
|
|
7
6
|
* @param {number} experimentId - id of experiment running for the current visitor.
|
|
8
7
|
* @returns {number} associated variationId which is successfully searched/assigned.
|
|
8
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
9
|
+
*
|
|
10
|
+
* - `KameleoonException.ExperimentConfigurationNotFound` No configuration found for provided `experimentId`.
|
|
11
|
+
* - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded.
|
|
12
|
+
* - `KameleoonException.StorageRead` Couldn't find associated experiment by provided `experimentId` and `visitorCode` inside the storage.
|
|
13
|
+
* - `KameleoonException.NotTargeted` Current visitor is not targeted.
|
|
14
|
+
* - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.
|
|
9
15
|
*/
|
|
10
16
|
triggerExperiment: (visitorCode: string, experimentId: number) => number;
|
|
11
|
-
/** An optional error object that may be returned if an error occurs while calling the `triggerExperiment` function. */
|
|
12
|
-
error: KameleoonError | null;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* A React Hook that returns `triggerExperiment` function which triggers experiment.
|
|
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useTriggerExperiment = useTriggerExperiment;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useKameleoon = require("./useKameleoon");
|
|
9
|
-
var _useError = require("./useError");
|
|
10
|
-
var _constants = require("./constants");
|
|
11
9
|
/**
|
|
12
10
|
* A React Hook that returns `triggerExperiment` function which triggers experiment.
|
|
13
11
|
*
|
|
@@ -17,21 +15,11 @@ function useTriggerExperiment() {
|
|
|
17
15
|
const {
|
|
18
16
|
client
|
|
19
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
20
|
-
const {
|
|
21
|
-
error,
|
|
22
|
-
setError
|
|
23
|
-
} = (0, _useError.useError)();
|
|
24
18
|
const triggerExperiment = (0, _react.useCallback)((visitorCode, experimentId) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} catch (unknownError) {
|
|
28
|
-
setError(unknownError);
|
|
29
|
-
return _constants.DEFAULT_VARIATION_ID;
|
|
30
|
-
}
|
|
31
|
-
}, [client, setError]);
|
|
19
|
+
return client.triggerExperiment(visitorCode, experimentId);
|
|
20
|
+
}, [client]);
|
|
32
21
|
return {
|
|
33
|
-
triggerExperiment
|
|
34
|
-
error
|
|
22
|
+
triggerExperiment
|
|
35
23
|
};
|
|
36
24
|
}
|
|
37
25
|
//# sourceMappingURL=useTriggerExperiment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTriggerExperiment.js","names":["_react","require","_useKameleoon","
|
|
1
|
+
{"version":3,"file":"useTriggerExperiment.js","names":["_react","require","_useKameleoon","useTriggerExperiment","client","useKameleoon","triggerExperiment","useCallback","visitorCode","experimentId"],"sources":["../src/useTriggerExperiment.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface ITriggerExperimentHookResult {\n /**\n * Triggers experiment by assigning the variation to the user with `visitorCode`, if the variation is already assigned just returns it's id. Note: returned id `0` indicates default variation. At the same time executes `flushData` without sending extra request.\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.\n * @param {number} experimentId - id of experiment running for the current visitor.\n * @returns {number} associated variationId which is successfully searched/assigned.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.ExperimentConfigurationNotFound` No configuration found for provided `experimentId`.\n * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded.\n * - `KameleoonException.StorageRead` Couldn't find associated experiment by provided `experimentId` and `visitorCode` inside the storage.\n * - `KameleoonException.NotTargeted` Current visitor is not targeted.\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.\n */\n triggerExperiment: (visitorCode: string, experimentId: number) => number;\n}\n\n/**\n * A React Hook that returns `triggerExperiment` function which triggers experiment.\n *\n * @returns {ITriggerExperimentHookResult} an object containing the `triggerExperiment` function.\n */\nexport function useTriggerExperiment(): ITriggerExperimentHookResult {\n const { client } = useKameleoon();\n\n const triggerExperiment = useCallback(\n (visitorCode: string, experimentId: number): number => {\n return client.triggerExperiment(visitorCode, experimentId);\n },\n [client],\n );\n\n return {\n triggerExperiment,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAoBA;AACA;AACA;AACA;AACA;AACO,SAASE,oBAAoBA,CAAA,EAAiC;EACnE,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,iBAAiB,GAAG,IAAAC,kBAAW,EACnC,CAACC,WAAmB,EAAEC,YAAoB,KAAa;IACrD,OAAOL,MAAM,CAACE,iBAAiB,CAACE,WAAW,EAAEC,YAAY,CAAC;EAC5D,CAAC,EACD,CAACL,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { ExperimentType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
-
import { KameleoonError } from './KameleoonError';
|
|
3
2
|
export interface IVisitorExperimentsHookResult {
|
|
4
3
|
/**
|
|
5
4
|
* Returns a list of experiments that the visitor with `visitorCode` is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated if the experiment will be triggered).
|
|
6
5
|
*
|
|
7
6
|
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.
|
|
8
|
-
* @param {boolean} isAllocated - boolean value indicating that only experiments *allocated* for visitor will be returned. Default value is `true`.
|
|
7
|
+
* @param {boolean | undefined} isAllocated - boolean value indicating that only experiments *allocated* for visitor will be returned. Default value is `true`.
|
|
9
8
|
* @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields.
|
|
9
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
10
|
+
*
|
|
11
|
+
* - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded.
|
|
12
|
+
* - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.
|
|
10
13
|
*/
|
|
11
|
-
getVisitorExperiments: (visitorCode: string, isAllocated
|
|
12
|
-
/** An optional error object that may be returned if an error occurs while calling the `getVisitorExperiments` function. */
|
|
13
|
-
error: KameleoonError | null;
|
|
14
|
+
getVisitorExperiments: (visitorCode: string, isAllocated?: boolean) => ExperimentType[];
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* A React Hook that returns `getVisitorExperiments` function which returns a list of experiments that the visitor with `visitorCode` is targeted by.
|
|
17
18
|
*
|
|
18
|
-
* @returns {IVisitorExperimentsHookResult} an object containing the `getVisitorExperiments` function
|
|
19
|
+
* @returns {IVisitorExperimentsHookResult} an object containing the `getVisitorExperiments` function.
|
|
19
20
|
*/
|
|
20
21
|
export declare function useVisitorExperiments(): IVisitorExperimentsHookResult;
|
|
@@ -6,31 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useVisitorExperiments = useVisitorExperiments;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useKameleoon = require("./useKameleoon");
|
|
9
|
-
var _useError = require("./useError");
|
|
10
9
|
/**
|
|
11
10
|
* A React Hook that returns `getVisitorExperiments` function which returns a list of experiments that the visitor with `visitorCode` is targeted by.
|
|
12
11
|
*
|
|
13
|
-
* @returns {IVisitorExperimentsHookResult} an object containing the `getVisitorExperiments` function
|
|
12
|
+
* @returns {IVisitorExperimentsHookResult} an object containing the `getVisitorExperiments` function.
|
|
14
13
|
*/
|
|
15
14
|
function useVisitorExperiments() {
|
|
16
15
|
const {
|
|
17
16
|
client
|
|
18
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
19
|
-
const {
|
|
20
|
-
error,
|
|
21
|
-
setError
|
|
22
|
-
} = (0, _useError.useError)();
|
|
23
18
|
const getVisitorExperiments = (0, _react.useCallback)((visitorCode, isAllocated) => {
|
|
24
|
-
|
|
25
|
-
return client.getVisitorExperiments(visitorCode, isAllocated);
|
|
26
|
-
} catch (unknownError) {
|
|
27
|
-
setError(unknownError);
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
19
|
+
return client.getVisitorExperiments(visitorCode, isAllocated);
|
|
30
20
|
}, [client]);
|
|
31
21
|
return {
|
|
32
|
-
getVisitorExperiments
|
|
33
|
-
error
|
|
22
|
+
getVisitorExperiments
|
|
34
23
|
};
|
|
35
24
|
}
|
|
36
25
|
//# sourceMappingURL=useVisitorExperiments.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVisitorExperiments.js","names":["_react","require","_useKameleoon","
|
|
1
|
+
{"version":3,"file":"useVisitorExperiments.js","names":["_react","require","_useKameleoon","useVisitorExperiments","client","useKameleoon","getVisitorExperiments","useCallback","visitorCode","isAllocated"],"sources":["../src/useVisitorExperiments.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { ExperimentType } from '@kameleoon/javascript-sdk-core';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface IVisitorExperimentsHookResult {\n /**\n * Returns a list of experiments that the visitor with `visitorCode` is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated if the experiment will be triggered).\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.\n * @param {boolean | undefined} isAllocated - boolean value indicating that only experiments *allocated* for visitor will be returned. Default value is `true`.\n * @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded.\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.\n */\n getVisitorExperiments: (\n visitorCode: string,\n isAllocated?: boolean,\n ) => ExperimentType[];\n}\n\n/**\n * A React Hook that returns `getVisitorExperiments` function which returns a list of experiments that the visitor with `visitorCode` is targeted by.\n *\n * @returns {IVisitorExperimentsHookResult} an object containing the `getVisitorExperiments` function.\n */\nexport function useVisitorExperiments(): IVisitorExperimentsHookResult {\n const { client } = useKameleoon();\n\n const getVisitorExperiments = useCallback(\n (visitorCode: string, isAllocated?: boolean): ExperimentType[] => {\n return client.getVisitorExperiments(visitorCode, isAllocated);\n },\n [client],\n );\n\n return {\n getVisitorExperiments,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAoBA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CAAA,EAAkC;EACrE,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,qBAAqB,GAAG,IAAAC,kBAAW,EACvC,CAACC,WAAmB,EAAEC,WAAqB,KAAuB;IAChE,OAAOL,MAAM,CAACE,qBAAqB,CAACE,WAAW,EAAEC,WAAW,CAAC;EAC/D,CAAC,EACD,CAACL,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { FeatureFlagType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
-
import { KameleoonError } from './KameleoonError';
|
|
3
2
|
export interface IVisitorFeatureFlagsHookResult {
|
|
4
3
|
/**
|
|
5
4
|
* Returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).
|
|
6
5
|
*
|
|
7
6
|
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.
|
|
8
7
|
* @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields.
|
|
8
|
+
* @throws `KameleoonError` with one of the following `type` s:
|
|
9
|
+
*
|
|
10
|
+
* - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded.
|
|
11
|
+
* - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.
|
|
12
|
+
* - `KameleoonException.NotTargeted` - Current visitor is not targeted.
|
|
9
13
|
*/
|
|
10
14
|
getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];
|
|
11
|
-
/** An optional error object that may be returned if an error occurs while calling the `getVisitorFeatureFlags` function. */
|
|
12
|
-
error: KameleoonError | null;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* A React Hook that returns `getVisitorFeatureFlags` function which returns a list of feature flags that the visitor with `visitorCode` that is targeted by.
|
|
16
18
|
*
|
|
17
|
-
* @returns {IVisitorFeatureFlagsHookResult} an object containing the `getVisitorFeatureFlags` function
|
|
19
|
+
* @returns {IVisitorFeatureFlagsHookResult} an object containing the `getVisitorFeatureFlags` function.
|
|
18
20
|
*/
|
|
19
21
|
export declare function useVisitorFeatureFlags(): IVisitorFeatureFlagsHookResult;
|
|
@@ -6,31 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useVisitorFeatureFlags = useVisitorFeatureFlags;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _useKameleoon = require("./useKameleoon");
|
|
9
|
-
var _useError = require("./useError");
|
|
10
9
|
/**
|
|
11
10
|
* A React Hook that returns `getVisitorFeatureFlags` function which returns a list of feature flags that the visitor with `visitorCode` that is targeted by.
|
|
12
11
|
*
|
|
13
|
-
* @returns {IVisitorFeatureFlagsHookResult} an object containing the `getVisitorFeatureFlags` function
|
|
12
|
+
* @returns {IVisitorFeatureFlagsHookResult} an object containing the `getVisitorFeatureFlags` function.
|
|
14
13
|
*/
|
|
15
14
|
function useVisitorFeatureFlags() {
|
|
16
15
|
const {
|
|
17
16
|
client
|
|
18
17
|
} = (0, _useKameleoon.useKameleoon)();
|
|
19
|
-
const {
|
|
20
|
-
error,
|
|
21
|
-
setError
|
|
22
|
-
} = (0, _useError.useError)();
|
|
23
18
|
const getVisitorFeatureFlags = (0, _react.useCallback)(visitorCode => {
|
|
24
|
-
|
|
25
|
-
return client.getVisitorFeatureFlags(visitorCode);
|
|
26
|
-
} catch (unknownError) {
|
|
27
|
-
setError(unknownError);
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
19
|
+
return client.getVisitorFeatureFlags(visitorCode);
|
|
30
20
|
}, [client]);
|
|
31
21
|
return {
|
|
32
|
-
getVisitorFeatureFlags
|
|
33
|
-
error
|
|
22
|
+
getVisitorFeatureFlags
|
|
34
23
|
};
|
|
35
24
|
}
|
|
36
25
|
//# sourceMappingURL=useVisitorFeatureFlags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVisitorFeatureFlags.js","names":["_react","require","_useKameleoon","
|
|
1
|
+
{"version":3,"file":"useVisitorFeatureFlags.js","names":["_react","require","_useKameleoon","useVisitorFeatureFlags","client","useKameleoon","getVisitorFeatureFlags","useCallback","visitorCode"],"sources":["../src/useVisitorFeatureFlags.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { FeatureFlagType } from '@kameleoon/javascript-sdk-core';\nimport { useKameleoon } from './useKameleoon';\n\nexport interface IVisitorFeatureFlagsHookResult {\n /**\n * Returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.\n * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields.\n * @throws `KameleoonError` with one of the following `type` s:\n *\n * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded.\n * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`.\n * - `KameleoonException.NotTargeted` - Current visitor is not targeted.\n */\n getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];\n}\n\n/**\n * A React Hook that returns `getVisitorFeatureFlags` function which returns a list of feature flags that the visitor with `visitorCode` that is targeted by.\n *\n * @returns {IVisitorFeatureFlagsHookResult} an object containing the `getVisitorFeatureFlags` function.\n */\nexport function useVisitorFeatureFlags(): IVisitorFeatureFlagsHookResult {\n const { client } = useKameleoon();\n\n const getVisitorFeatureFlags = useCallback(\n (visitorCode: string): FeatureFlagType[] => {\n return client.getVisitorFeatureFlags(visitorCode);\n },\n [client],\n );\n\n return {\n getVisitorFeatureFlags,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAiBA;AACA;AACA;AACA;AACA;AACO,SAASE,sBAAsBA,CAAA,EAAmC;EACvE,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EAEjC,MAAMC,sBAAsB,GAAG,IAAAC,kBAAW,EACvCC,WAAmB,IAAwB;IAC1C,OAAOJ,MAAM,CAACE,sBAAsB,CAACE,WAAW,CAAC;EACnD,CAAC,EACD,CAACJ,MAAM,CAAC,CACT;EAED,OAAO;IACLE;EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kameleoon/react-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Kameleoon React SDK",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
|
|
12
|
+
"start": "npm run clean && tsc -w",
|
|
12
13
|
"build": "npm run clean && npm run build:types && npm run build:js",
|
|
13
14
|
"build:types": "tsc --emitDeclarationOnly",
|
|
14
15
|
"build:js": "babel src --out-dir dist --extensions \".ts,.tsx\" --source-maps true",
|
|
@@ -39,7 +40,7 @@
|
|
|
39
40
|
"dependencies": {
|
|
40
41
|
"@kameleoon/javascript-sdk-core": "*",
|
|
41
42
|
"react-native": "^0.71.4",
|
|
42
|
-
"react-native-event-source": "
|
|
43
|
+
"react-native-event-source-ts": "^1.0.1",
|
|
43
44
|
"react-native-mmkv": "2.4.4",
|
|
44
45
|
"validator": "^13.6.0"
|
|
45
46
|
},
|
package/dist/KameleoonError.d.ts
DELETED
package/dist/KameleoonError.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.KameleoonError = void 0;
|
|
7
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
9
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
10
|
-
class KameleoonError extends Error {
|
|
11
|
-
constructor(type) {
|
|
12
|
-
super(`Error: ${type}`);
|
|
13
|
-
_defineProperty(this, "type", void 0);
|
|
14
|
-
this.name = 'KameleoonError';
|
|
15
|
-
this.message = `${this.name}.${type}`;
|
|
16
|
-
this.type = type;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.KameleoonError = KameleoonError;
|
|
20
|
-
//# sourceMappingURL=KameleoonError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"KameleoonError.js","names":["KameleoonError","Error","constructor","type","_defineProperty","name","message","exports"],"sources":["../src/KameleoonError.ts"],"sourcesContent":["import { KameleoonException } from '@kameleoon/javascript-sdk-core';\n\nexport class KameleoonError extends Error {\n type: KameleoonException;\n\n constructor(type: KameleoonException) {\n super(`Error: ${type}`);\n this.name = 'KameleoonError';\n this.message = `${this.name}.${type}`;\n this.type = type;\n }\n}\n"],"mappings":";;;;;;;;;AAEO,MAAMA,cAAc,SAASC,KAAK,CAAC;EAGxCC,WAAWA,CAACC,IAAwB,EAAE;IACpC,KAAK,CAAE,UAASA,IAAK,EAAC,CAAC;IAACC,eAAA;IACxB,IAAI,CAACC,IAAI,GAAG,gBAAgB;IAC5B,IAAI,CAACC,OAAO,GAAI,GAAE,IAAI,CAACD,IAAK,IAAGF,IAAK,EAAC;IACrC,IAAI,CAACA,IAAI,GAAGA,IAAI;EAClB;AACF;AAACI,OAAA,CAAAP,cAAA,GAAAA,cAAA"}
|
package/dist/ProviderError.d.ts
DELETED
package/dist/ProviderError.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ProviderError = void 0;
|
|
7
|
-
class ProviderError extends Error {
|
|
8
|
-
constructor(method) {
|
|
9
|
-
super(`${method} must be used within a KameleoonProvider`);
|
|
10
|
-
this.name = 'ProviderError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
exports.ProviderError = ProviderError;
|
|
14
|
-
//# sourceMappingURL=ProviderError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProviderError.js","names":["ProviderError","Error","constructor","method","name","exports"],"sources":["../src/ProviderError.ts"],"sourcesContent":["export class ProviderError extends Error {\n constructor(method: string) {\n super(`${method} must be used within a KameleoonProvider`);\n this.name = 'ProviderError';\n }\n}\n"],"mappings":";;;;;;AAAO,MAAMA,aAAa,SAASC,KAAK,CAAC;EACvCC,WAAWA,CAACC,MAAc,EAAE;IAC1B,KAAK,CAAE,GAAEA,MAAO,0CAAyC,CAAC;IAC1D,IAAI,CAACC,IAAI,GAAG,eAAe;EAC7B;AACF;AAACC,OAAA,CAAAL,aAAA,GAAAA,aAAA"}
|
package/dist/constants.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_VARIATION_ID = 0;
|
package/dist/constants.js
DELETED
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["DEFAULT_VARIATION_ID","exports"],"sources":["../src/constants.ts"],"sourcesContent":["export const DEFAULT_VARIATION_ID = 0;\n"],"mappings":";;;;;;AAAO,MAAMA,oBAAoB,GAAG,CAAC;AAACC,OAAA,CAAAD,oBAAA,GAAAA,oBAAA"}
|
package/dist/useError.d.ts
DELETED
package/dist/useError.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useError = useError;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
function useError() {
|
|
9
|
-
const errorRef = (0, _react.useRef)(null);
|
|
10
|
-
const setError = (0, _react.useCallback)(unknownError => {
|
|
11
|
-
errorRef.current = unknownError;
|
|
12
|
-
}, [errorRef]);
|
|
13
|
-
return {
|
|
14
|
-
error: errorRef.current,
|
|
15
|
-
setError
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=useError.js.map
|
package/dist/useError.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useError.js","names":["_react","require","useError","errorRef","useRef","setError","useCallback","unknownError","current","error"],"sources":["../src/useError.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { KameleoonError } from './KameleoonError';\n\ntype UseErrorHookResultType = {\n error: KameleoonError | null;\n setError: (unknownError: unknown) => void;\n};\n\nexport function useError(): UseErrorHookResultType {\n const errorRef = useRef<KameleoonError | null>(null);\n\n const setError = useCallback(\n (unknownError: unknown) => {\n errorRef.current = unknownError as KameleoonError;\n },\n [errorRef],\n );\n\n return {\n error: errorRef.current,\n setError,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAQO,SAASC,QAAQA,CAAA,EAA2B;EACjD,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAwB,IAAI,CAAC;EAEpD,MAAMC,QAAQ,GAAG,IAAAC,kBAAW,EACzBC,YAAqB,IAAK;IACzBJ,QAAQ,CAACK,OAAO,GAAGD,YAA8B;EACnD,CAAC,EACD,CAACJ,QAAQ,CAAC,CACX;EAED,OAAO;IACLM,KAAK,EAAEN,QAAQ,CAACK,OAAO;IACvBH;EACF,CAAC;AACH"}
|
package/dist/useErrors.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { KameleoonException } from '@kameleoon/javascript-sdk-core';
|
|
2
|
-
type UseErrorsHookResultType = {
|
|
3
|
-
errors: KameleoonException[];
|
|
4
|
-
setErrors: (newErrors: Array<KameleoonException | undefined>) => void;
|
|
5
|
-
};
|
|
6
|
-
export declare function useErrors(): UseErrorsHookResultType;
|
|
7
|
-
export {};
|
package/dist/useErrors.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useErrors = useErrors;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
function useErrors() {
|
|
9
|
-
const errorsRef = (0, _react.useRef)([]);
|
|
10
|
-
const setErrors = (0, _react.useCallback)(newErrors => {
|
|
11
|
-
const uniqueErrors = [...new Set(newErrors)].filter(value => Boolean(value));
|
|
12
|
-
errorsRef.current = uniqueErrors;
|
|
13
|
-
}, [errorsRef]);
|
|
14
|
-
return {
|
|
15
|
-
errors: errorsRef.current,
|
|
16
|
-
setErrors
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=useErrors.js.map
|
package/dist/useErrors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useErrors.js","names":["_react","require","useErrors","errorsRef","useRef","setErrors","useCallback","newErrors","uniqueErrors","Set","filter","value","Boolean","current","errors"],"sources":["../src/useErrors.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { KameleoonException } from '@kameleoon/javascript-sdk-core';\n\ntype UseErrorsHookResultType = {\n errors: KameleoonException[];\n setErrors: (newErrors: Array<KameleoonException | undefined>) => void;\n};\n\nexport function useErrors(): UseErrorsHookResultType {\n const errorsRef = useRef<KameleoonException[]>([]);\n\n const setErrors = useCallback(\n (newErrors: Array<KameleoonException | undefined>) => {\n const uniqueErrors = [...new Set(newErrors)].filter(\n (value): value is KameleoonException => Boolean(value),\n );\n\n errorsRef.current = uniqueErrors;\n },\n [errorsRef],\n );\n\n return {\n errors: errorsRef.current,\n setErrors,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAQO,SAASC,SAASA,CAAA,EAA4B;EACnD,MAAMC,SAAS,GAAG,IAAAC,aAAM,EAAuB,EAAE,CAAC;EAElD,MAAMC,SAAS,GAAG,IAAAC,kBAAW,EAC1BC,SAAgD,IAAK;IACpD,MAAMC,YAAY,GAAG,CAAC,GAAG,IAAIC,GAAG,CAACF,SAAS,CAAC,CAAC,CAACG,MAAM,CAChDC,KAAK,IAAkCC,OAAO,CAACD,KAAK,CAAC,CACvD;IAEDR,SAAS,CAACU,OAAO,GAAGL,YAAY;EAClC,CAAC,EACD,CAACL,SAAS,CAAC,CACZ;EAED,OAAO;IACLW,MAAM,EAAEX,SAAS,CAACU,OAAO;IACzBR;EACF,CAAC;AACH"}
|