@kameleoon/react-sdk 4.0.3 → 4.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 +56 -0
- package/dist/Feature.js +1 -1
- package/dist/Feature.js.map +1 -1
- package/dist/KameleoonContext.d.ts +1 -1
- package/dist/KameleoonProvider.d.ts +1 -1
- package/dist/KameleoonProvider.js +1 -1
- package/dist/KameleoonProvider.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +2 -2
- package/dist/kameleoonClient.js +73 -5
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/useActivateFeature.js +2 -4
- package/dist/useActivateFeature.js.map +1 -1
- package/dist/useAddData.d.ts +1 -1
- package/dist/useAsyncVisitorCode.d.ts +12 -0
- package/dist/useAsyncVisitorCode.js +56 -0
- package/dist/useAsyncVisitorCode.js.map +1 -0
- package/dist/useBrowser.d.ts +1 -1
- package/dist/useBrowser.js +3 -3
- package/dist/useBrowser.js.map +1 -1
- package/dist/useConversion.d.ts +1 -1
- package/dist/useConversion.js +2 -2
- package/dist/useConversion.js.map +1 -1
- package/dist/useCustomData.d.ts +1 -1
- package/dist/useCustomData.js +2 -2
- package/dist/useCustomData.js.map +1 -1
- package/dist/useDevice.d.ts +1 -1
- package/dist/useDevice.js +2 -2
- package/dist/useDevice.js.map +1 -1
- package/dist/useFeature.js +8 -11
- package/dist/useFeature.js.map +1 -1
- package/dist/useKameleoon.d.ts +1 -1
- package/dist/usePageView.d.ts +1 -1
- package/dist/usePageView.js +2 -2
- package/dist/usePageView.js.map +1 -1
- package/dist/withActivateFeature.js +1 -1
- package/dist/withActivateFeature.js.map +1 -1
- package/dist/withAddData.d.ts +1 -1
- package/dist/withAddData.js +3 -40
- package/dist/withAddData.js.map +1 -1
- package/dist/withAsyncVisitorCode.d.ts +15 -0
- package/dist/withAsyncVisitorCode.js +75 -0
- package/dist/withAsyncVisitorCode.js.map +1 -0
- package/dist/withBrowser.d.ts +1 -1
- package/dist/withBrowser.js +4 -4
- package/dist/withBrowser.js.map +1 -1
- package/dist/withConversion.d.ts +1 -1
- package/dist/withConversion.js +3 -3
- package/dist/withConversion.js.map +1 -1
- package/dist/withCustomData.d.ts +1 -1
- package/dist/withCustomData.js +3 -3
- package/dist/withCustomData.js.map +1 -1
- package/dist/withDevice.d.ts +1 -1
- package/dist/withDevice.js +3 -3
- package/dist/withDevice.js.map +1 -1
- package/dist/withFeature.js +1 -1
- package/dist/withFeature.js.map +1 -1
- package/dist/withFeatureVariable.js +1 -1
- package/dist/withFeatureVariable.js.map +1 -1
- package/dist/withFlush.js +1 -1
- package/dist/withFlush.js.map +1 -1
- package/dist/withKameleoon.d.ts +1 -1
- package/dist/withKameleoon.js +1 -1
- package/dist/withKameleoon.js.map +1 -1
- package/dist/withPageView.d.ts +1 -1
- package/dist/withPageView.js +3 -3
- package/dist/withPageView.js.map +1 -1
- package/dist/withRetrieveDataFromRemoteSource.js +1 -1
- package/dist/withRetrieveDataFromRemoteSource.js.map +1 -1
- package/dist/withRunWhenReady.js +1 -1
- package/dist/withRunWhenReady.js.map +1 -1
- package/dist/withTrackingConversion.js +1 -1
- package/dist/withTrackingConversion.js.map +1 -1
- package/dist/withTriggerExperiment.js +1 -1
- package/dist/withTriggerExperiment.js.map +1 -1
- package/dist/withVariationAssociatedData.js +1 -1
- package/dist/withVariationAssociatedData.js.map +1 -1
- package/dist/withVisitorCode.js +1 -1
- package/dist/withVisitorCode.js.map +1 -1
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -296,6 +296,8 @@ A callback function `getVisitorCode()` retrieves the Kameleoon `visitorCode` for
|
|
|
296
296
|
|
|
297
297
|
For more information, refer to [this article](https://developers.kameleoon.com/back-front-bridge.html).
|
|
298
298
|
|
|
299
|
+
There is also an alternative `getAsyncVisitorCode()` callback, which is asynchronous and is meant for *ReactNative* applications.
|
|
300
|
+
|
|
299
301
|
##### Please Note:
|
|
300
302
|
_If you provide your own `visitorCode`, its uniqueness must be guaranteed on your end - the SDK cannot check it. Also note that the length of `visitorCode` is **limited to 255 characters**. Any excess characters will throw an exception._
|
|
301
303
|
|
|
@@ -361,6 +363,60 @@ class MyComponent extends React.Component {
|
|
|
361
363
|
export default withVisitorCode(MyComponent);
|
|
362
364
|
```
|
|
363
365
|
|
|
366
|
+
### `useAsyncVisitorCode`
|
|
367
|
+
#### Returns
|
|
368
|
+
- A callback function `getAsyncVisitorCode()`.
|
|
369
|
+
|
|
370
|
+
#### Example
|
|
371
|
+
```jsx
|
|
372
|
+
import { useState } from 'react';
|
|
373
|
+
import { uuidv4 } from 'uuid';
|
|
374
|
+
import { useAsyncVisitorCode } from '@kameleoon/react-sdk';
|
|
375
|
+
|
|
376
|
+
function MyComponent(): JSX.Element {
|
|
377
|
+
const { getAsyncVisitorCode } = useAsyncVisitorCode();
|
|
378
|
+
const [visitorCode, setVisitorCode] = useState<string>('');
|
|
379
|
+
|
|
380
|
+
async function retrieveVisitorCode(): Promise<void> {
|
|
381
|
+
// Without defaultVisitorCode argument
|
|
382
|
+
const result = await getAsyncVisitorCode('example.com');
|
|
383
|
+
// With defaultVisitorCode argument
|
|
384
|
+
const result = await getAsyncVisitorCode('example.com', uuidv4());
|
|
385
|
+
|
|
386
|
+
setVisitorCode(result);
|
|
387
|
+
}
|
|
388
|
+
...
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
### `withAsyncVisitorCode`
|
|
392
|
+
#### Arguments
|
|
393
|
+
- `Component: React.Component` - component which will be enhanced with the prop `getAsyncVisitorCode()`.
|
|
394
|
+
|
|
395
|
+
#### Returns
|
|
396
|
+
- A wrapped component with additional props as described above.
|
|
397
|
+
|
|
398
|
+
#### Example
|
|
399
|
+
```jsx
|
|
400
|
+
import { uuidv4 } from 'uuid';
|
|
401
|
+
import { withAsyncVisitorCode } from '@kameleoon/react-sdk';
|
|
402
|
+
|
|
403
|
+
class MyComponent extends React.Component {
|
|
404
|
+
async componentDidMount(): Promise<void> {
|
|
405
|
+
const { getAsyncVisitorCode } = this.props;
|
|
406
|
+
|
|
407
|
+
// Without defaultVisitorCode argument
|
|
408
|
+
const visitorCode = await getAsyncVisitorCode('example.com');
|
|
409
|
+
|
|
410
|
+
// With defaultVisitorCode argument
|
|
411
|
+
const visitorCode = await getAsyncVisitorCode('example.com', uuidv4());
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
...
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export default withVisitorCode(MyComponent);
|
|
418
|
+
```
|
|
419
|
+
|
|
364
420
|
## Triggering an experiment
|
|
365
421
|
A callback function `getVariationId()` takes `visitorCode` and `experimentId` as mandatory arguments to register a variation for a given user.
|
|
366
422
|
|
package/dist/Feature.js
CHANGED
|
@@ -20,7 +20,7 @@ var useFeature_1 = require("./useFeature");
|
|
|
20
20
|
*/
|
|
21
21
|
function Feature(props) {
|
|
22
22
|
var result = (0, useFeature_1.useFeature)(__assign({}, props));
|
|
23
|
-
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children(result) }
|
|
23
|
+
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children(result) });
|
|
24
24
|
}
|
|
25
25
|
exports.Feature = Feature;
|
|
26
26
|
//# sourceMappingURL=Feature.js.map
|
package/dist/Feature.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Feature.js","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA0C;AAM1C;;;GAGG;AACH,SAAgB,OAAO,CAAC,KAAoB;IAC1C,IAAM,MAAM,GAAG,IAAA,uBAAU,eAAM,KAAK,EAAG,CAAC;IAExC,OAAO,2DAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"Feature.js","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA0C;AAM1C;;;GAGG;AACH,SAAgB,OAAO,CAAC,KAAoB;IAC1C,IAAM,MAAM,GAAG,IAAA,uBAAU,eAAM,KAAK,EAAG,CAAC;IAExC,OAAO,2DAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAI,CAAC;AACvC,CAAC;AAJD,0BAIC"}
|
|
@@ -19,7 +19,7 @@ var KameleoonContext_1 = require("./KameleoonContext");
|
|
|
19
19
|
*/
|
|
20
20
|
function KameleoonProvider(_a) {
|
|
21
21
|
var client = _a.client, children = _a.children;
|
|
22
|
-
return ((0, jsx_runtime_1.jsx)(KameleoonContext_1.KameleoonContext.Provider, __assign({ value: client }, { children: children })
|
|
22
|
+
return ((0, jsx_runtime_1.jsx)(KameleoonContext_1.KameleoonContext.Provider, __assign({ value: client }, { children: children })));
|
|
23
23
|
}
|
|
24
24
|
exports.default = (0, react_1.memo)(KameleoonProvider);
|
|
25
25
|
//# sourceMappingURL=KameleoonProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KameleoonProvider.js","sourceRoot":"","sources":["../src/KameleoonProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAAwC;AAExC,uDAAsD;AAStD;;GAEG;AACH,SAAS,iBAAiB,CAAC,EAGD;QAFxB,MAAM,YAAA,EACN,QAAQ,cAAA;IAER,OAAO,CACL,uBAAC,mCAAgB,CAAC,QAAQ,aAAC,KAAK,EAAE,MAAM,gBACrC,QAAQ,
|
|
1
|
+
{"version":3,"file":"KameleoonProvider.js","sourceRoot":"","sources":["../src/KameleoonProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+BAAwC;AAExC,uDAAsD;AAStD;;GAEG;AACH,SAAS,iBAAiB,CAAC,EAGD;QAFxB,MAAM,YAAA,EACN,QAAQ,cAAA;IAER,OAAO,CACL,uBAAC,mCAAgB,CAAC,QAAQ,aAAC,KAAK,EAAE,MAAM,gBACrC,QAAQ,IACiB,CAC7B,CAAC;AACJ,CAAC;AAED,kBAAe,IAAA,YAAI,EAAC,iBAAiB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { KameleoonContext } from './KameleoonContext';
|
|
2
2
|
export { KAMELEOON_SDK_LOCAL_STORAGE_KEY, Browser, KameleoonException, } from './constants';
|
|
3
|
-
export { Browser as IBrowser, Conversion as IConversion, Device as IDevice, PageView as IPageView, DeviceType, } from 'kameleoon-
|
|
3
|
+
export { Browser as IBrowser, Conversion as IConversion, Device as IDevice, PageView as IPageView, DeviceType, } from '@kameleoon/javascript-sdk-core/dist/data';
|
|
4
4
|
export { default as compose } from './compose';
|
|
5
5
|
export { default as KameleoonProvider } from './KameleoonProvider';
|
|
6
6
|
export * from './types';
|
|
@@ -9,6 +9,7 @@ export { Feature } from './Feature';
|
|
|
9
9
|
export { useKameleoon } from './useKameleoon';
|
|
10
10
|
export { useFeature } from './useFeature';
|
|
11
11
|
export { useVisitorCode } from './useVisitorCode';
|
|
12
|
+
export { useAsyncVisitorCode } from './useAsyncVisitorCode';
|
|
12
13
|
export { useTriggerExperiment } from './useTriggerExperiment';
|
|
13
14
|
export { useActivateFeature } from './useActivateFeature';
|
|
14
15
|
export { useVariationAssociatedData } from './useVariationAssociatedData';
|
|
@@ -26,6 +27,7 @@ export { useRunWhenReady } from './useRunWhenReady';
|
|
|
26
27
|
export { withKameleoon } from './withKameleoon';
|
|
27
28
|
export { withFeature } from './withFeature';
|
|
28
29
|
export { withVisitorCode } from './withVisitorCode';
|
|
30
|
+
export { withAsyncVisitorCode } from './withAsyncVisitorCode';
|
|
29
31
|
export { withTriggerExperiment } from './withTriggerExperiment';
|
|
30
32
|
export { withActivateFeature } from './withActivateFeature';
|
|
31
33
|
export { withVariationAssociatedData } from './withVariationAssociatedData';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -13,14 +17,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
18
|
};
|
|
15
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.withRunWhenReady = exports.withCustomData = exports.withConversion = exports.withPageView = exports.withDevice = exports.withBrowser = exports.withFlush = exports.withAddData = exports.withTrackingConversion = exports.withFeatureVariable = exports.withRetrieveDataFromRemoteSource = exports.withVariationAssociatedData = exports.withActivateFeature = exports.withTriggerExperiment = exports.withVisitorCode = exports.withFeature = exports.withKameleoon = exports.useRunWhenReady = exports.useDevice = exports.useCustomData = exports.useConversion = exports.usePageView = exports.useBrowser = exports.useFlush = exports.useAddData = exports.useRetrieveDataFromRemoteSource = exports.useTrackingConversion = exports.useFeatureVariable = exports.useVariationAssociatedData = exports.useActivateFeature = exports.useTriggerExperiment = exports.useVisitorCode = exports.useFeature = exports.useKameleoon = exports.Feature = exports.createClient = exports.KameleoonProvider = exports.compose = exports.DeviceType = exports.IPageView = exports.IDevice = exports.IConversion = exports.IBrowser = exports.KameleoonException = exports.Browser = exports.KAMELEOON_SDK_LOCAL_STORAGE_KEY = exports.KameleoonContext = void 0;
|
|
20
|
+
exports.withRunWhenReady = exports.withCustomData = exports.withConversion = exports.withPageView = exports.withDevice = exports.withBrowser = exports.withFlush = exports.withAddData = exports.withTrackingConversion = exports.withFeatureVariable = exports.withRetrieveDataFromRemoteSource = exports.withVariationAssociatedData = exports.withActivateFeature = exports.withTriggerExperiment = exports.withAsyncVisitorCode = exports.withVisitorCode = exports.withFeature = exports.withKameleoon = exports.useRunWhenReady = exports.useDevice = exports.useCustomData = exports.useConversion = exports.usePageView = exports.useBrowser = exports.useFlush = exports.useAddData = exports.useRetrieveDataFromRemoteSource = exports.useTrackingConversion = exports.useFeatureVariable = exports.useVariationAssociatedData = exports.useActivateFeature = exports.useTriggerExperiment = exports.useAsyncVisitorCode = exports.useVisitorCode = exports.useFeature = exports.useKameleoon = exports.Feature = exports.createClient = exports.KameleoonProvider = exports.compose = exports.DeviceType = exports.IPageView = exports.IDevice = exports.IConversion = exports.IBrowser = exports.KameleoonException = exports.Browser = exports.KAMELEOON_SDK_LOCAL_STORAGE_KEY = exports.KameleoonContext = void 0;
|
|
17
21
|
var KameleoonContext_1 = require("./KameleoonContext");
|
|
18
22
|
Object.defineProperty(exports, "KameleoonContext", { enumerable: true, get: function () { return KameleoonContext_1.KameleoonContext; } });
|
|
19
23
|
var constants_1 = require("./constants");
|
|
20
24
|
Object.defineProperty(exports, "KAMELEOON_SDK_LOCAL_STORAGE_KEY", { enumerable: true, get: function () { return constants_1.KAMELEOON_SDK_LOCAL_STORAGE_KEY; } });
|
|
21
25
|
Object.defineProperty(exports, "Browser", { enumerable: true, get: function () { return constants_1.Browser; } });
|
|
22
26
|
Object.defineProperty(exports, "KameleoonException", { enumerable: true, get: function () { return constants_1.KameleoonException; } });
|
|
23
|
-
var data_1 = require("kameleoon-
|
|
27
|
+
var data_1 = require("@kameleoon/javascript-sdk-core/dist/data");
|
|
24
28
|
Object.defineProperty(exports, "IBrowser", { enumerable: true, get: function () { return data_1.Browser; } });
|
|
25
29
|
Object.defineProperty(exports, "IConversion", { enumerable: true, get: function () { return data_1.Conversion; } });
|
|
26
30
|
Object.defineProperty(exports, "IDevice", { enumerable: true, get: function () { return data_1.Device; } });
|
|
@@ -41,6 +45,8 @@ var useFeature_1 = require("./useFeature");
|
|
|
41
45
|
Object.defineProperty(exports, "useFeature", { enumerable: true, get: function () { return useFeature_1.useFeature; } });
|
|
42
46
|
var useVisitorCode_1 = require("./useVisitorCode");
|
|
43
47
|
Object.defineProperty(exports, "useVisitorCode", { enumerable: true, get: function () { return useVisitorCode_1.useVisitorCode; } });
|
|
48
|
+
var useAsyncVisitorCode_1 = require("./useAsyncVisitorCode");
|
|
49
|
+
Object.defineProperty(exports, "useAsyncVisitorCode", { enumerable: true, get: function () { return useAsyncVisitorCode_1.useAsyncVisitorCode; } });
|
|
44
50
|
var useTriggerExperiment_1 = require("./useTriggerExperiment");
|
|
45
51
|
Object.defineProperty(exports, "useTriggerExperiment", { enumerable: true, get: function () { return useTriggerExperiment_1.useTriggerExperiment; } });
|
|
46
52
|
var useActivateFeature_1 = require("./useActivateFeature");
|
|
@@ -75,6 +81,8 @@ var withFeature_1 = require("./withFeature");
|
|
|
75
81
|
Object.defineProperty(exports, "withFeature", { enumerable: true, get: function () { return withFeature_1.withFeature; } });
|
|
76
82
|
var withVisitorCode_1 = require("./withVisitorCode");
|
|
77
83
|
Object.defineProperty(exports, "withVisitorCode", { enumerable: true, get: function () { return withVisitorCode_1.withVisitorCode; } });
|
|
84
|
+
var withAsyncVisitorCode_1 = require("./withAsyncVisitorCode");
|
|
85
|
+
Object.defineProperty(exports, "withAsyncVisitorCode", { enumerable: true, get: function () { return withAsyncVisitorCode_1.withAsyncVisitorCode; } });
|
|
78
86
|
var withTriggerExperiment_1 = require("./withTriggerExperiment");
|
|
79
87
|
Object.defineProperty(exports, "withTriggerExperiment", { enumerable: true, get: function () { return withTriggerExperiment_1.withTriggerExperiment; } });
|
|
80
88
|
var withActivateFeature_1 = require("./withActivateFeature");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AACzB,yCAIqB;AAHnB,4HAAA,+BAA+B,OAAA;AAC/B,oGAAA,OAAO,OAAA;AACP,+GAAA,kBAAkB,OAAA;AAEpB,iEAMkD;AALhD,gGAAA,OAAO,OAAY;AACnB,mGAAA,UAAU,OAAe;AACzB,+FAAA,MAAM,OAAW;AACjB,iGAAA,QAAQ,OAAa;AACrB,kGAAA,UAAU,OAAA;AAEZ,qCAA+C;AAAtC,mHAAA,OAAO,OAAW;AAC3B,yDAAmE;AAA1D,uIAAA,OAAO,OAAqB;AACrC,0CAAwB;AACxB,qDAAiD;AAAxC,+GAAA,YAAY,OAAA;AACrB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,2EAA0E;AAAjE,wIAAA,0BAA0B,OAAA;AACnC,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,qFAAoF;AAA3E,kJAAA,+BAA+B,OAAA;AACxC,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,qDAAoD;AAA3C,kHAAA,eAAe,OAAA;AACxB,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,6EAA4E;AAAnE,0IAAA,2BAA2B,OAAA;AACpC,uFAAsF;AAA7E,oJAAA,gCAAgC,OAAA;AACzC,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SDKConfiguration } from 'kameleoon-
|
|
2
|
-
import { KameleoonClient } from 'kameleoon-
|
|
1
|
+
import { SDKConfiguration } from '@kameleoon/javascript-sdk-core/dist/interfaces/interfaces';
|
|
2
|
+
import { KameleoonClient } from '@kameleoon/javascript-sdk-core';
|
|
3
3
|
export interface ICreateClientParams {
|
|
4
4
|
/** Code of the website you want to run experiments on */
|
|
5
5
|
siteCode: string;
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -1,16 +1,84 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.createClient = void 0;
|
|
4
|
-
var
|
|
40
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
5
41
|
/**
|
|
6
42
|
* Creates an instance of KameleoonClient
|
|
7
43
|
*/
|
|
8
44
|
function createClient(_a) {
|
|
9
45
|
var siteCode = _a.siteCode, visitorCode = _a.visitorCode, options = _a.options;
|
|
10
|
-
var client = new
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
46
|
+
var client = new javascript_sdk_core_1.KameleoonClient(siteCode, options);
|
|
47
|
+
var isBrowser = window && window.document;
|
|
48
|
+
function addTargeting(kameleoonClient, code) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
kameleoonClient.runWhenReady(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
return __generator(this, function (_a) {
|
|
52
|
+
switch (_a.label) {
|
|
53
|
+
case 0: return [4 /*yield*/, client.addData(code, new javascript_sdk_core_1.KameleoonData.CustomData(1, visitorCode))];
|
|
54
|
+
case 1:
|
|
55
|
+
_a.sent();
|
|
56
|
+
return [2 /*return*/];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}); }, function () { }, 1000);
|
|
60
|
+
client.flush(visitorCode);
|
|
61
|
+
}
|
|
62
|
+
if (visitorCode) {
|
|
63
|
+
addTargeting(client, visitorCode);
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
if (isBrowser) {
|
|
67
|
+
addTargeting(client, client.obtainVisitorCode(''));
|
|
68
|
+
return client;
|
|
69
|
+
}
|
|
70
|
+
var generatedVisitorCode = '';
|
|
71
|
+
client
|
|
72
|
+
.obtainAsyncVisitorCode('')
|
|
73
|
+
.then(function (code) {
|
|
74
|
+
generatedVisitorCode = code;
|
|
75
|
+
})
|
|
76
|
+
.catch(function () {
|
|
77
|
+
generatedVisitorCode = '';
|
|
78
|
+
})
|
|
79
|
+
.finally(function () {
|
|
80
|
+
addTargeting(client, generatedVisitorCode);
|
|
81
|
+
});
|
|
14
82
|
return client;
|
|
15
83
|
}
|
|
16
84
|
exports.createClient = createClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kameleoonClient.js","sourceRoot":"","sources":["../src/kameleoonClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kameleoonClient.js","sourceRoot":"","sources":["../src/kameleoonClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sEAAgF;AAahF;;GAEG;AACH,SAAgB,YAAY,CAAC,EAIP;QAHpB,QAAQ,cAAA,EACR,WAAW,iBAAA,EACX,OAAO,aAAA;IAEP,IAAM,MAAM,GAAG,IAAI,qCAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,IAAM,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC;IAE5C,SAAS,YAAY,CAAC,eAAgC,EAAE,IAAY;QAApE,iBAaC;QAZC,eAAe,CAAC,YAAY,CAC1B;;;4BACE,qBAAM,MAAM,CAAC,OAAO,CAClB,IAAI,EACJ,IAAI,mCAAa,CAAC,UAAU,CAAC,CAAC,EAAE,WAAW,CAAC,CAC7C,EAAA;;wBAHD,SAGC,CAAC;;;;aACH,EACD,cAAO,CAAC,EACR,IAAI,CACL,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,WAAW,EAAE;QACf,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QAElC,OAAO,MAAM,CAAC;KACf;IAED,IAAI,SAAS,EAAE;QACb,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC,CAAC;QAEnD,OAAO,MAAM,CAAC;KACf;IAED,IAAI,oBAAoB,GAAG,EAAE,CAAC;IAE9B,MAAM;SACH,sBAAsB,CAAC,EAAE,CAAC;SAC1B,IAAI,CAAC,UAAC,IAAY;QACjB,oBAAoB,GAAG,IAAI,CAAC;IAC9B,CAAC,CAAC;SACD,KAAK,CAAC;QACL,oBAAoB,GAAG,EAAE,CAAC;IAC5B,CAAC,CAAC;SACD,OAAO,CAAC;QACP,YAAY,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEL,OAAO,MAAM,CAAC;AAChB,CAAC;AAjDD,oCAiDC"}
|
|
@@ -5,24 +5,22 @@ var react_1 = require("react");
|
|
|
5
5
|
var useKameleoon_1 = require("./useKameleoon");
|
|
6
6
|
var ProviderError_1 = require("./ProviderError");
|
|
7
7
|
var useError_1 = require("./useError");
|
|
8
|
-
var useVisitorCode_1 = require("./useVisitorCode");
|
|
9
8
|
/**
|
|
10
9
|
* A React Hook that returns callback function which activates a feature toggle
|
|
11
10
|
*/
|
|
12
11
|
function useActivateFeature() {
|
|
13
12
|
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
14
13
|
var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
|
|
15
|
-
var getVisitorCode = (0, useVisitorCode_1.useVisitorCode)().getVisitorCode;
|
|
16
14
|
var hasFeature = (0, react_1.useCallback)(function (featureKey, visitorCode) {
|
|
17
15
|
try {
|
|
18
|
-
var userCode = visitorCode !== null && visitorCode !== void 0 ? visitorCode :
|
|
16
|
+
var userCode = visitorCode !== null && visitorCode !== void 0 ? visitorCode : client.generateRandomString();
|
|
19
17
|
return client.activateFeature(userCode, featureKey);
|
|
20
18
|
}
|
|
21
19
|
catch (unknownError) {
|
|
22
20
|
setError(unknownError);
|
|
23
21
|
return false;
|
|
24
22
|
}
|
|
25
|
-
}, [client,
|
|
23
|
+
}, [client, setError]);
|
|
26
24
|
if (!client) {
|
|
27
25
|
throw new ProviderError_1.ProviderError('useActivateFeature');
|
|
28
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActivateFeature.js","sourceRoot":"","sources":["../src/useActivateFeature.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,+CAA8C;AAC9C,iDAAgD;AAEhD,uCAAsC;
|
|
1
|
+
{"version":3,"file":"useActivateFeature.js","sourceRoot":"","sources":["../src/useActivateFeature.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,+CAA8C;AAC9C,iDAAgD;AAEhD,uCAAsC;AAWtC;;GAEG;AACH,SAAgB,kBAAkB;IACxB,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAC5B,IAAA,KAAsB,IAAA,mBAAQ,GAAE,EAA9B,KAAK,WAAA,EAAE,QAAQ,cAAe,CAAC;IAEvC,IAAM,UAAU,GAAG,IAAA,mBAAW,EAC5B,UAAC,UAA2B,EAAE,WAAoB;QAChD,IAAI;YACF,IAAM,QAAQ,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,MAAM,CAAC,oBAAoB,EAAE,CAAC;YAE9D,OAAO,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;SACrD;QAAC,OAAO,YAAY,EAAE;YACrB,QAAQ,CAAC,YAAY,CAAC,CAAC;YAEvB,OAAO,KAAK,CAAC;SACd;IACH,CAAC,EACD,CAAC,MAAM,EAAE,QAAQ,CAAC,CACnB,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,6BAAa,CAAC,oBAAoB,CAAC,CAAC;KAC/C;IAED,OAAO;QACL,UAAU,YAAA;QACV,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AA3BD,gDA2BC"}
|
package/dist/useAddData.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataInterface as IData } from 'kameleoon-
|
|
1
|
+
import { DataInterface as IData } from '@kameleoon/javascript-sdk-core/dist/interfaces/interfaces';
|
|
2
2
|
interface AddDataHookResult {
|
|
3
3
|
/**
|
|
4
4
|
* @param visitorCode - unique identifier of the user
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface AsyncVisitorCodeHookResult {
|
|
2
|
+
/**
|
|
3
|
+
* @param topLevelDomain - current top level domain for the concerned site
|
|
4
|
+
* @param defaultVisitorCode - this parameter will be used as the visitorCode
|
|
5
|
+
*/
|
|
6
|
+
getAsyncVisitorCode: (topLevelDomain: string, defaultVisitorCode?: string) => Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A React Hook that returns callback function which obtains the Kameleoon visitorCode asynchronously for the current visitor
|
|
10
|
+
*/
|
|
11
|
+
export declare function useAsyncVisitorCode(): AsyncVisitorCodeHookResult;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.useAsyncVisitorCode = void 0;
|
|
40
|
+
var react_1 = require("react");
|
|
41
|
+
var useKameleoon_1 = require("./useKameleoon");
|
|
42
|
+
/**
|
|
43
|
+
* A React Hook that returns callback function which obtains the Kameleoon visitorCode asynchronously for the current visitor
|
|
44
|
+
*/
|
|
45
|
+
function useAsyncVisitorCode() {
|
|
46
|
+
var _this = this;
|
|
47
|
+
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
48
|
+
var getAsyncVisitorCode = (0, react_1.useCallback)(function (topLevelDomain, defaultVisitorCode) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
49
|
+
return [2 /*return*/, client.obtainAsyncVisitorCode(topLevelDomain, defaultVisitorCode)];
|
|
50
|
+
}); }); }, [client]);
|
|
51
|
+
return {
|
|
52
|
+
getAsyncVisitorCode: getAsyncVisitorCode,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.useAsyncVisitorCode = useAsyncVisitorCode;
|
|
56
|
+
//# sourceMappingURL=useAsyncVisitorCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAsyncVisitorCode.js","sourceRoot":"","sources":["../src/useAsyncVisitorCode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AACpC,+CAA8C;AAa9C;;GAEG;AACH,SAAgB,mBAAmB;IAAnC,iBAeC;IAdS,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAElC,IAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,UACE,cAAsB,EACtB,kBAA2B;QAE3B,sBAAA,MAAM,CAAC,sBAAsB,CAAC,cAAc,EAAE,kBAAkB,CAAC,EAAA;aAAA,EACnE,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,mBAAmB,qBAAA;KACpB,CAAC;AACJ,CAAC;AAfD,kDAeC"}
|
package/dist/useBrowser.d.ts
CHANGED
package/dist/useBrowser.js
CHANGED
|
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.useBrowser = void 0;
|
|
7
7
|
var react_1 = require("react");
|
|
8
|
-
var
|
|
9
|
-
var data_1 = __importDefault(require("kameleoon-
|
|
8
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
9
|
+
var data_1 = __importDefault(require("@kameleoon/javascript-sdk-core/dist/data"));
|
|
10
10
|
/**
|
|
11
11
|
* A React Hook that returns callback function which adds browser type
|
|
12
12
|
*/
|
|
13
13
|
function useBrowser() {
|
|
14
14
|
var addBrowser = (0, react_1.useCallback)(function (browser) {
|
|
15
|
-
return new
|
|
15
|
+
return new javascript_sdk_core_1.KameleoonData.Browser(data_1.default.browsers[browser]);
|
|
16
16
|
}, []);
|
|
17
17
|
return {
|
|
18
18
|
addBrowser: addBrowser,
|
package/dist/useBrowser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowser.js","sourceRoot":"","sources":["../src/useBrowser.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"useBrowser.js","sourceRoot":"","sources":["../src/useBrowser.ts"],"names":[],"mappings":";;;;;;AAAA,+BAAoC;AACpC,sEAA+D;AAC/D,kFAAqF;AAUrF;;GAEG;AACH,SAAgB,UAAU;IACxB,IAAM,UAAU,GAAG,IAAA,mBAAW,EAC5B,UAAC,OAAgB;QACf,OAAA,IAAI,mCAAa,CAAC,OAAO,CAAC,cAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAAjD,CAAiD,EACnD,EAAE,CACH,CAAC;IAEF,OAAO;QACL,UAAU,YAAA;KACX,CAAC;AACJ,CAAC;AAVD,gCAUC"}
|
package/dist/useConversion.d.ts
CHANGED
package/dist/useConversion.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useConversion = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var
|
|
5
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
6
6
|
/**
|
|
7
7
|
* A React Hook that returns callback function which adds conversion
|
|
8
8
|
*/
|
|
9
9
|
function useConversion() {
|
|
10
10
|
var addConversion = (0, react_1.useCallback)(function (goalId, revenue, negative) {
|
|
11
|
-
return new
|
|
11
|
+
return new javascript_sdk_core_1.KameleoonData.Conversion(goalId, revenue, negative);
|
|
12
12
|
}, []);
|
|
13
13
|
return {
|
|
14
14
|
addConversion: addConversion,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConversion.js","sourceRoot":"","sources":["../src/useConversion.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"useConversion.js","sourceRoot":"","sources":["../src/useConversion.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,sEAA+D;AAgB/D;;GAEG;AACH,SAAgB,aAAa;IAC3B,IAAM,aAAa,GAAG,IAAA,mBAAW,EAC/B,UAAC,MAAc,EAAE,OAAgB,EAAE,QAAkB;QACnD,OAAA,IAAI,mCAAa,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC;IAAvD,CAAuD,EACzD,EAAE,CACH,CAAC;IAEF,OAAO;QACL,aAAa,eAAA;KACd,CAAC;AACJ,CAAC;AAVD,sCAUC"}
|
package/dist/useCustomData.d.ts
CHANGED
package/dist/useCustomData.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useCustomData = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var
|
|
5
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
6
6
|
/**
|
|
7
7
|
* A React Hook that returns callback function which adds custom data
|
|
8
8
|
*/
|
|
9
9
|
function useCustomData() {
|
|
10
10
|
var addCustomData = (0, react_1.useCallback)(function (index, value) {
|
|
11
|
-
return new
|
|
11
|
+
return new javascript_sdk_core_1.KameleoonData.CustomData(index, value);
|
|
12
12
|
}, []);
|
|
13
13
|
return {
|
|
14
14
|
addCustomData: addCustomData,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCustomData.js","sourceRoot":"","sources":["../src/useCustomData.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"useCustomData.js","sourceRoot":"","sources":["../src/useCustomData.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,sEAA+D;AAW/D;;GAEG;AACH,SAAgB,aAAa;IAC3B,IAAM,aAAa,GAAG,IAAA,mBAAW,EAC/B,UAAC,KAAa,EAAE,KAAa;QAC3B,OAAA,IAAI,mCAAa,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC;IAA1C,CAA0C,EAC5C,EAAE,CACH,CAAC;IAEF,OAAO;QACL,aAAa,eAAA;KACd,CAAC;AACJ,CAAC;AAVD,sCAUC"}
|
package/dist/useDevice.d.ts
CHANGED
package/dist/useDevice.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useDevice = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var
|
|
5
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
6
6
|
/**
|
|
7
7
|
* A React Hook that returns a callback function which adds interest
|
|
8
8
|
*/
|
|
9
9
|
function useDevice() {
|
|
10
|
-
var addDevice = (0, react_1.useCallback)(function (device) { return new
|
|
10
|
+
var addDevice = (0, react_1.useCallback)(function (device) { return new javascript_sdk_core_1.KameleoonData.Device(device); }, []);
|
|
11
11
|
return {
|
|
12
12
|
addDevice: addDevice,
|
|
13
13
|
};
|
package/dist/useDevice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDevice.js","sourceRoot":"","sources":["../src/useDevice.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"useDevice.js","sourceRoot":"","sources":["../src/useDevice.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,sEAA+D;AAa/D;;GAEG;AACH,SAAgB,SAAS;IACvB,IAAM,SAAS,GAAG,IAAA,mBAAW,EAC3B,UAAC,MAAkB,IAAc,OAAA,IAAI,mCAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAhC,CAAgC,EACjE,EAAE,CACH,CAAC;IAEF,OAAO;QACL,SAAS,WAAA;KACV,CAAC;AACJ,CAAC;AATD,8BASC"}
|
package/dist/useFeature.js
CHANGED
|
@@ -32,7 +32,6 @@ var react_1 = require("react");
|
|
|
32
32
|
var useActivateFeature_1 = require("./useActivateFeature");
|
|
33
33
|
var useFeatureVariable_1 = require("./useFeatureVariable");
|
|
34
34
|
var constants_1 = require("./constants");
|
|
35
|
-
var useVisitorCode_1 = require("./useVisitorCode");
|
|
36
35
|
var useKameleoon_1 = require("./useKameleoon");
|
|
37
36
|
var useErrors_1 = require("./useErrors");
|
|
38
37
|
/**
|
|
@@ -43,14 +42,12 @@ function useFeature(_a) {
|
|
|
43
42
|
var featureKey = _a.featureKey, variableKeys = _a.variableKeys, visitorCode = _a.visitorCode;
|
|
44
43
|
var _c = (0, useActivateFeature_1.useActivateFeature)(), hasFeature = _c.hasFeature, activateFeatureError = _c.error;
|
|
45
44
|
var _d = (0, useFeatureVariable_1.useFeatureVariable)(), getFeatureVariable = _d.getFeatureVariable, featureVariableError = _d.error;
|
|
46
|
-
var getVisitorCode = (0, useVisitorCode_1.useVisitorCode)().getVisitorCode;
|
|
47
45
|
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
48
46
|
var _e = __read((0, react_1.useState)((_b = {},
|
|
49
47
|
_b[constants_1.FeatureResultField.IsActive] = false,
|
|
50
48
|
_b[constants_1.FeatureResultField.Variables] = [],
|
|
51
49
|
_b)), 2), feature = _e[0], setFeature = _e[1];
|
|
52
50
|
var _f = (0, useErrors_1.useErrors)(), errors = _f.errors, setErrors = _f.setErrors;
|
|
53
|
-
var userCode = visitorCode !== null && visitorCode !== void 0 ? visitorCode : getVisitorCode('');
|
|
54
51
|
function getVariableObject(key, value) {
|
|
55
52
|
var _a;
|
|
56
53
|
if (value) {
|
|
@@ -75,18 +72,18 @@ function useFeature(_a) {
|
|
|
75
72
|
}, [variableKeys, getFeatureVariable, featureKey]);
|
|
76
73
|
(0, react_1.useEffect)(function () {
|
|
77
74
|
var _a;
|
|
78
|
-
var _b, _c, _d;
|
|
79
|
-
var
|
|
75
|
+
var _b, _c, _d, _e;
|
|
76
|
+
var featureFlagArray = (_b = client.configurations) === null || _b === void 0 ? void 0 : _b.configuration.featureFlags.filter(function (item) {
|
|
80
77
|
return item.identificationKey === featureKey;
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
});
|
|
79
|
+
if (Array.isArray(featureFlagArray) && featureFlagArray.length) {
|
|
80
|
+
var currentEnvironment = (_e = (_d = (_c = featureFlagArray[0]) === null || _c === void 0 ? void 0 : _c.environment) === null || _d === void 0 ? void 0 : _d.key) !== null && _e !== void 0 ? _e : constants_1.PRODUCTION;
|
|
84
81
|
setFeature((_a = {},
|
|
85
|
-
_a[constants_1.FeatureResultField.IsActive] = hasFeature(featureKey,
|
|
82
|
+
_a[constants_1.FeatureResultField.IsActive] = hasFeature(featureKey, visitorCode),
|
|
86
83
|
_a[constants_1.FeatureResultField.Variables] = getVariablesArray(currentEnvironment),
|
|
87
84
|
_a));
|
|
88
85
|
}
|
|
89
|
-
|
|
86
|
+
else {
|
|
90
87
|
setFeature(function (prevFeature) {
|
|
91
88
|
var _a;
|
|
92
89
|
return (__assign(__assign({}, prevFeature), (_a = {}, _a[constants_1.FeatureResultField.IsActive] = false, _a)));
|
|
@@ -94,7 +91,7 @@ function useFeature(_a) {
|
|
|
94
91
|
}
|
|
95
92
|
// getVariablesArray put in dependencies creates an infinite loop
|
|
96
93
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
-
}, [
|
|
94
|
+
}, [visitorCode, featureKey, hasFeature]);
|
|
98
95
|
(0, react_1.useEffect)(function () {
|
|
99
96
|
setErrors([activateFeatureError === null || activateFeatureError === void 0 ? void 0 : activateFeatureError.type, featureVariableError === null || featureVariableError === void 0 ? void 0 : featureVariableError.type]);
|
|
100
97
|
}, [activateFeatureError, featureVariableError, setErrors]);
|