@kameleoon/react-sdk 5.0.0 → 6.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/LICENSE.md +3 -162
- package/README.md +62 -1456
- package/dist/KameleoonContext.d.ts +2 -2
- package/dist/KameleoonContext.js.map +1 -1
- package/dist/KameleoonError.d.ts +1 -1
- package/dist/KameleoonProvider.d.ts +5 -5
- package/dist/KameleoonProvider.js +1 -1
- package/dist/KameleoonProvider.js.map +1 -1
- package/dist/constants.d.ts +1 -24
- package/dist/constants.js +2 -28
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/browserEventSource.d.ts +4 -0
- package/dist/eventSource/browserEventSource.js +38 -0
- package/dist/eventSource/browserEventSource.js.map +1 -0
- package/dist/eventSource/index.d.ts +2 -0
- package/dist/eventSource/index.js +8 -0
- package/dist/eventSource/index.js.map +1 -0
- package/dist/eventSource/nativeEventSource.d.ts +4 -0
- package/dist/eventSource/nativeEventSource.js +39 -0
- package/dist/eventSource/nativeEventSource.js.map +1 -0
- package/dist/index.d.ts +16 -42
- package/dist/index.js +36 -94
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +4 -13
- package/dist/kameleoonClient.js +18 -72
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonUtils/browserUtils.d.ts +13 -0
- package/dist/kameleoonUtils/browserUtils.js +72 -0
- package/dist/kameleoonUtils/browserUtils.js.map +1 -0
- package/dist/kameleoonUtils/nativeUtils.d.ts +12 -0
- package/dist/kameleoonUtils/nativeUtils.js +68 -0
- package/dist/kameleoonUtils/nativeUtils.js.map +1 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +8 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/localStorage.d.ts +4 -0
- package/dist/storage/localStorage.js +44 -0
- package/dist/storage/localStorage.js.map +1 -0
- package/dist/storage/nativeStorage.d.ts +4 -0
- package/dist/storage/nativeStorage.js +41 -0
- package/dist/storage/nativeStorage.js.map +1 -0
- package/dist/useAddData.d.ts +14 -9
- package/dist/useAddData.js +14 -5
- package/dist/useAddData.js.map +1 -1
- package/dist/useBrowserVisitorCode.d.ts +17 -0
- package/dist/useBrowserVisitorCode.js +20 -0
- package/dist/useBrowserVisitorCode.js.map +1 -0
- package/dist/useConfigurationUpdate.d.ts +17 -0
- package/dist/useConfigurationUpdate.js +29 -0
- package/dist/useConfigurationUpdate.js.map +1 -0
- package/dist/useError.d.ts +1 -1
- package/dist/useError.js +1 -3
- package/dist/useError.js.map +1 -1
- package/dist/useErrors.d.ts +2 -2
- package/dist/useExperiments.d.ts +18 -0
- package/dist/useExperiments.js +30 -0
- package/dist/useExperiments.js.map +1 -0
- package/dist/useFeatureFlagActive.d.ts +19 -0
- package/dist/useFeatureFlagActive.js +30 -0
- package/dist/useFeatureFlagActive.js.map +1 -0
- package/dist/useFeatureFlagVariationKey.d.ts +19 -0
- package/dist/useFeatureFlagVariationKey.js +30 -0
- package/dist/useFeatureFlagVariationKey.js.map +1 -0
- package/dist/useFeatureFlags.d.ts +18 -0
- package/dist/useFeatureFlags.js +30 -0
- package/dist/useFeatureFlags.js.map +1 -0
- package/dist/useFeatureVariable.d.ts +12 -8
- package/dist/useFeatureVariable.js +7 -18
- package/dist/useFeatureVariable.js.map +1 -1
- package/dist/useFlushData.d.ts +14 -0
- package/dist/useFlushData.js +21 -0
- package/dist/useFlushData.js.map +1 -0
- package/dist/useInitialize.d.ts +15 -0
- package/dist/{useAsyncVisitorCode.js → useInitialize.js} +28 -10
- package/dist/useInitialize.js.map +1 -0
- package/dist/useKameleoon.d.ts +8 -7
- package/dist/useKameleoon.js +3 -1
- package/dist/useKameleoon.js.map +1 -1
- package/dist/useNativeVisitorCode.d.ts +16 -0
- package/dist/useNativeVisitorCode.js +20 -0
- package/dist/useNativeVisitorCode.js.map +1 -0
- package/dist/useRemoteData.d.ts +19 -0
- package/dist/{useRetrieveDataFromRemoteSource.js → useRemoteData.js} +25 -28
- package/dist/useRemoteData.js.map +1 -0
- package/dist/useTrackConversion.d.ts +18 -0
- package/dist/useTrackConversion.js +29 -0
- package/dist/useTrackConversion.js.map +1 -0
- package/dist/useTriggerExperiment.d.ts +12 -10
- package/dist/useTriggerExperiment.js +8 -9
- package/dist/useTriggerExperiment.js.map +1 -1
- package/dist/useVisitorExperiments.d.ts +20 -0
- package/dist/useVisitorExperiments.js +30 -0
- package/dist/useVisitorExperiments.js.map +1 -0
- package/dist/useVisitorFeatureFlags.d.ts +19 -0
- package/dist/useVisitorFeatureFlags.js +30 -0
- package/dist/useVisitorFeatureFlags.js.map +1 -0
- package/package.json +8 -3
- package/dist/Feature.d.ts +0 -11
- package/dist/Feature.js +0 -26
- package/dist/Feature.js.map +0 -1
- package/dist/compose.d.ts +0 -8
- package/dist/compose.js +0 -58
- package/dist/compose.js.map +0 -1
- package/dist/getKameleoonException.d.ts +0 -2
- package/dist/getKameleoonException.js +0 -34
- package/dist/getKameleoonException.js.map +0 -1
- package/dist/types.d.ts +0 -37
- package/dist/types.js +0 -4
- package/dist/types.js.map +0 -1
- package/dist/useActivateFeature.d.ts +0 -14
- package/dist/useActivateFeature.js +0 -32
- package/dist/useActivateFeature.js.map +0 -1
- package/dist/useAsyncVisitorCode.d.ts +0 -12
- package/dist/useAsyncVisitorCode.js.map +0 -1
- package/dist/useBrowser.d.ts +0 -13
- package/dist/useBrowser.js +0 -22
- package/dist/useBrowser.js.map +0 -1
- package/dist/useConversion.d.ts +0 -14
- package/dist/useConversion.js +0 -18
- package/dist/useConversion.js.map +0 -1
- package/dist/useCustomData.d.ts +0 -13
- package/dist/useCustomData.js +0 -18
- package/dist/useCustomData.js.map +0 -1
- package/dist/useDevice.d.ts +0 -12
- package/dist/useDevice.js +0 -16
- package/dist/useDevice.js.map +0 -1
- package/dist/useFeature.d.ts +0 -5
- package/dist/useFeature.js +0 -101
- package/dist/useFeature.js.map +0 -1
- package/dist/useFlush.d.ts +0 -11
- package/dist/useFlush.js +0 -19
- package/dist/useFlush.js.map +0 -1
- package/dist/usePageView.d.ts +0 -14
- package/dist/usePageView.js +0 -18
- package/dist/usePageView.js.map +0 -1
- package/dist/useRetrieveDataFromRemoteSource.d.ts +0 -12
- package/dist/useRetrieveDataFromRemoteSource.js.map +0 -1
- package/dist/useRunWhenReady.d.ts +0 -14
- package/dist/useRunWhenReady.js +0 -23
- package/dist/useRunWhenReady.js.map +0 -1
- package/dist/useTrackingConversion.d.ts +0 -13
- package/dist/useTrackingConversion.js +0 -19
- package/dist/useTrackingConversion.js.map +0 -1
- package/dist/useVariationAssociatedData.d.ts +0 -16
- package/dist/useVariationAssociatedData.js +0 -30
- package/dist/useVariationAssociatedData.js.map +0 -1
- package/dist/useVisitorCode.d.ts +0 -12
- package/dist/useVisitorCode.js +0 -19
- package/dist/useVisitorCode.js.map +0 -1
- package/dist/withActivateFeature.d.ts +0 -17
- package/dist/withActivateFeature.js +0 -28
- package/dist/withActivateFeature.js.map +0 -1
- package/dist/withAddData.d.ts +0 -16
- package/dist/withAddData.js +0 -28
- package/dist/withAddData.js.map +0 -1
- package/dist/withAsyncVisitorCode.d.ts +0 -15
- package/dist/withAsyncVisitorCode.js +0 -75
- package/dist/withAsyncVisitorCode.js.map +0 -1
- package/dist/withBrowser.d.ts +0 -16
- package/dist/withBrowser.js +0 -35
- package/dist/withBrowser.js.map +0 -1
- package/dist/withConversion.d.ts +0 -17
- package/dist/withConversion.js +0 -31
- package/dist/withConversion.js.map +0 -1
- package/dist/withCustomData.d.ts +0 -16
- package/dist/withCustomData.js +0 -31
- package/dist/withCustomData.js.map +0 -1
- package/dist/withDevice.d.ts +0 -15
- package/dist/withDevice.js +0 -29
- package/dist/withDevice.js.map +0 -1
- package/dist/withFeature.d.ts +0 -6
- package/dist/withFeature.js +0 -31
- package/dist/withFeature.js.map +0 -1
- package/dist/withFeatureVariable.d.ts +0 -17
- package/dist/withFeatureVariable.js +0 -28
- package/dist/withFeatureVariable.js.map +0 -1
- package/dist/withFlush.d.ts +0 -14
- package/dist/withFlush.js +0 -36
- package/dist/withFlush.js.map +0 -1
- package/dist/withKameleoon.d.ts +0 -13
- package/dist/withKameleoon.js +0 -33
- package/dist/withKameleoon.js.map +0 -1
- package/dist/withPageView.d.ts +0 -17
- package/dist/withPageView.js +0 -31
- package/dist/withPageView.js.map +0 -1
- package/dist/withRetrieveDataFromRemoteSource.d.ts +0 -14
- package/dist/withRetrieveDataFromRemoteSource.js +0 -28
- package/dist/withRetrieveDataFromRemoteSource.js.map +0 -1
- package/dist/withRunWhenReady.d.ts +0 -16
- package/dist/withRunWhenReady.js +0 -28
- package/dist/withRunWhenReady.js.map +0 -1
- package/dist/withTrackingConversion.d.ts +0 -16
- package/dist/withTrackingConversion.js +0 -36
- package/dist/withTrackingConversion.js.map +0 -1
- package/dist/withTriggerExperiment.d.ts +0 -19
- package/dist/withTriggerExperiment.js +0 -30
- package/dist/withTriggerExperiment.js.map +0 -1
- package/dist/withVariationAssociatedData.d.ts +0 -18
- package/dist/withVariationAssociatedData.js +0 -30
- package/dist/withVariationAssociatedData.js.map +0 -1
- package/dist/withVisitorCode.d.ts +0 -15
- package/dist/withVisitorCode.js +0 -36
- package/dist/withVisitorCode.js.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
* BrowserUtils - a class with containing a number of static helper methods
|
|
4
|
+
* */
|
|
5
|
+
export declare class BrowserUtils {
|
|
6
|
+
/**
|
|
7
|
+
* @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
|
|
8
|
+
* @param {string} domain domain which cookie belongs to
|
|
9
|
+
* @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
|
|
10
|
+
* @returns {string} result visitor code
|
|
11
|
+
* */
|
|
12
|
+
static getVisitorCode(domain: string, defaultVisitorCode?: string): string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.BrowserUtils = void 0;
|
|
19
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
20
|
+
// --- Note ---
|
|
21
|
+
// Extra class is created:
|
|
22
|
+
// - To be able to enforce abstract `getVisitorCode` method
|
|
23
|
+
// - To be able to use extended methods while `KameleoonUtils` iself only operates on static methods
|
|
24
|
+
// - To keep similar parameters object on inner implementation and dispers it for proprietary implementations
|
|
25
|
+
var KameleoonUtilsConstructor = /** @class */ (function (_super) {
|
|
26
|
+
__extends(KameleoonUtilsConstructor, _super);
|
|
27
|
+
function KameleoonUtilsConstructor() {
|
|
28
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
29
|
+
}
|
|
30
|
+
KameleoonUtilsConstructor.prototype.getVisitorCode = function (_a) {
|
|
31
|
+
var domain = _a.domain, defaultVisitorCode = _a.defaultVisitorCode;
|
|
32
|
+
var cookie = document.cookie;
|
|
33
|
+
var visitorCodeResult = this.getCookieVisitorCode(cookie);
|
|
34
|
+
if (visitorCodeResult.ok && visitorCodeResult.data) {
|
|
35
|
+
return visitorCodeResult.data;
|
|
36
|
+
}
|
|
37
|
+
var visitorCode = defaultVisitorCode || this.generateRandomString(javascript_sdk_core_1.VISITOR_CODE_LENGTH);
|
|
38
|
+
var resultCookie = this.getResultCookie({ domain: domain, visitorCode: visitorCode });
|
|
39
|
+
// --- Note ---
|
|
40
|
+
// - Browser automatically adds new cookie in the end (without overwrite)
|
|
41
|
+
// - Only one key-value pair can be added at a time
|
|
42
|
+
resultCookie.split(javascript_sdk_core_1.Cookie.PairsDelimiter).forEach(function (item) {
|
|
43
|
+
document.cookie = item;
|
|
44
|
+
});
|
|
45
|
+
return visitorCode;
|
|
46
|
+
};
|
|
47
|
+
return KameleoonUtilsConstructor;
|
|
48
|
+
}(javascript_sdk_core_1.KameleoonCoreUtils));
|
|
49
|
+
/**
|
|
50
|
+
* @class
|
|
51
|
+
* BrowserUtils - a class with containing a number of static helper methods
|
|
52
|
+
* */
|
|
53
|
+
var BrowserUtils = /** @class */ (function () {
|
|
54
|
+
function BrowserUtils() {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
|
|
58
|
+
* @param {string} domain domain which cookie belongs to
|
|
59
|
+
* @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
|
|
60
|
+
* @returns {string} result visitor code
|
|
61
|
+
* */
|
|
62
|
+
BrowserUtils.getVisitorCode = function (domain, defaultVisitorCode) {
|
|
63
|
+
var kameleoonUtilsConstructor = new KameleoonUtilsConstructor();
|
|
64
|
+
return kameleoonUtilsConstructor.getVisitorCode({
|
|
65
|
+
domain: domain,
|
|
66
|
+
defaultVisitorCode: defaultVisitorCode,
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
return BrowserUtils;
|
|
70
|
+
}());
|
|
71
|
+
exports.BrowserUtils = BrowserUtils;
|
|
72
|
+
//# sourceMappingURL=browserUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserUtils.js","sourceRoot":"","sources":["../../src/kameleoonUtils/browserUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sEAKwC;AAExC,eAAe;AACf,0BAA0B;AAC1B,2DAA2D;AAC3D,oGAAoG;AACpG,6GAA6G;AAC7G;IAAwC,6CAAkB;IAA1D;;IA2BA,CAAC;IA1BQ,kDAAc,GAArB,UAAsB,EAGe;YAFnC,MAAM,YAAA,EACN,kBAAkB,wBAAA;QAElB,IAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAE/B,IAAM,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;QAE5D,IAAI,iBAAiB,CAAC,EAAE,IAAI,iBAAiB,CAAC,IAAI,EAAE;YAClD,OAAO,iBAAiB,CAAC,IAAI,CAAC;SAC/B;QAED,IAAM,WAAW,GACf,kBAAkB,IAAI,IAAI,CAAC,oBAAoB,CAAC,yCAAmB,CAAC,CAAC;QAEvE,IAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,EAAE,MAAM,QAAA,EAAE,WAAW,aAAA,EAAE,CAAC,CAAC;QAEnE,eAAe;QACf,yEAAyE;QACzE,mDAAmD;QACnD,YAAY,CAAC,KAAK,CAAC,4BAAM,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,UAAC,IAAI;YACrD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;QACzB,CAAC,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC;IACH,gCAAC;AAAD,CAAC,AA3BD,CAAwC,wCAAkB,GA2BzD;AAED;;;KAGK;AACL;IAAA;IAeA,CAAC;IAdC;;;;;SAKK;IACE,2BAAc,GAArB,UAAsB,MAAc,EAAE,kBAA2B;QAC/D,IAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;QAElE,OAAO,yBAAyB,CAAC,cAAc,CAAC;YAC9C,MAAM,QAAA;YACN,kBAAkB,oBAAA;SACnB,CAAC,CAAC;IACL,CAAC;IACH,mBAAC;AAAD,CAAC,AAfD,IAeC;AAfY,oCAAY"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
* BrowserUtils - a class with containing a number of static helper methods
|
|
4
|
+
* */
|
|
5
|
+
export declare class NativeUtils {
|
|
6
|
+
/**
|
|
7
|
+
* @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
|
|
8
|
+
* @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
|
|
9
|
+
* @returns {string} result visitor code
|
|
10
|
+
* */
|
|
11
|
+
static getVisitorCode(defaultVisitorCode?: string): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NativeUtils = void 0;
|
|
19
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
20
|
+
var storage_1 = require("../storage");
|
|
21
|
+
var storage = new storage_1.NativeStorageConstructor().initialize(javascript_sdk_core_1.KameleoonStorageKey.VisitorCode);
|
|
22
|
+
// --- Note ---
|
|
23
|
+
// Extra class is created:
|
|
24
|
+
// - To be able to enforce abstract `getVisitorCode` method
|
|
25
|
+
// - To be able to use extended methods while `KameleoonUtils` iself only operates on static methods
|
|
26
|
+
// - To keep similar parameters object on inner implementation and dispers it for proprietary implementations
|
|
27
|
+
var KameleoonUtilsConstructor = /** @class */ (function (_super) {
|
|
28
|
+
__extends(KameleoonUtilsConstructor, _super);
|
|
29
|
+
function KameleoonUtilsConstructor() {
|
|
30
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
31
|
+
}
|
|
32
|
+
KameleoonUtilsConstructor.prototype.getVisitorCode = function (_a) {
|
|
33
|
+
var defaultVisitorCode = _a.defaultVisitorCode;
|
|
34
|
+
var readResult = storage.read();
|
|
35
|
+
if (readResult.ok) {
|
|
36
|
+
return readResult.data;
|
|
37
|
+
}
|
|
38
|
+
var visitorCode = defaultVisitorCode || this.generateRandomString(javascript_sdk_core_1.VISITOR_CODE_LENGTH);
|
|
39
|
+
// --- Note ---
|
|
40
|
+
// `write` result is ignored because there is no exceptions for `mmkv` write operation
|
|
41
|
+
storage.write(visitorCode);
|
|
42
|
+
return visitorCode;
|
|
43
|
+
};
|
|
44
|
+
return KameleoonUtilsConstructor;
|
|
45
|
+
}(javascript_sdk_core_1.KameleoonCoreUtils));
|
|
46
|
+
/**
|
|
47
|
+
* @class
|
|
48
|
+
* BrowserUtils - a class with containing a number of static helper methods
|
|
49
|
+
* */
|
|
50
|
+
var NativeUtils = /** @class */ (function () {
|
|
51
|
+
function NativeUtils() {
|
|
52
|
+
}
|
|
53
|
+
// TODO: docs
|
|
54
|
+
/**
|
|
55
|
+
* @method getVisitorCode obtains visitor code from the browser cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to cookie
|
|
56
|
+
* @param {string | undefined} defaultVisitorCode visitor code to be used in case there is no visitor code in cookies Note: if not passed visitor code will be randomly generated
|
|
57
|
+
* @returns {string} result visitor code
|
|
58
|
+
* */
|
|
59
|
+
NativeUtils.getVisitorCode = function (defaultVisitorCode) {
|
|
60
|
+
var kameleoonUtilsConstructor = new KameleoonUtilsConstructor();
|
|
61
|
+
return kameleoonUtilsConstructor.getVisitorCode({
|
|
62
|
+
defaultVisitorCode: defaultVisitorCode,
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return NativeUtils;
|
|
66
|
+
}());
|
|
67
|
+
exports.NativeUtils = NativeUtils;
|
|
68
|
+
//# sourceMappingURL=nativeUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeUtils.js","sourceRoot":"","sources":["../../src/kameleoonUtils/nativeUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,sEAKwC;AACxC,sCAAsD;AAEtD,IAAM,OAAO,GAAG,IAAI,kCAAwB,EAAE,CAAC,UAAU,CACvD,yCAAmB,CAAC,WAAW,CAChC,CAAC;AAEF,eAAe;AACf,0BAA0B;AAC1B,2DAA2D;AAC3D,oGAAoG;AACpG,6GAA6G;AAC7G;IAAwC,6CAAkB;IAA1D;;IAmBA,CAAC;IAlBQ,kDAAc,GAArB,UAAsB,EAEe;YADnC,kBAAkB,wBAAA;QAElB,IAAM,UAAU,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAElC,IAAI,UAAU,CAAC,EAAE,EAAE;YACjB,OAAO,UAAU,CAAC,IAAI,CAAC;SACxB;QAED,IAAM,WAAW,GACf,kBAAkB,IAAI,IAAI,CAAC,oBAAoB,CAAC,yCAAmB,CAAC,CAAC;QAEvE,eAAe;QACf,sFAAsF;QACtF,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAE3B,OAAO,WAAW,CAAC;IACrB,CAAC;IACH,gCAAC;AAAD,CAAC,AAnBD,CAAwC,wCAAkB,GAmBzD;AAED;;;KAGK;AACL;IAAA;IAcA,CAAC;IAbC,aAAa;IACb;;;;SAIK;IACE,0BAAc,GAArB,UAAsB,kBAA2B;QAC/C,IAAM,yBAAyB,GAAG,IAAI,yBAAyB,EAAE,CAAC;QAElE,OAAO,yBAAyB,CAAC,cAAc,CAAC;YAC9C,kBAAkB,oBAAA;SACnB,CAAC,CAAC;IACL,CAAC;IACH,kBAAC;AAAD,CAAC,AAdD,IAcC;AAdY,kCAAW"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeStorageConstructor = exports.LocalStorageConstructor = void 0;
|
|
4
|
+
var localStorage_1 = require("./localStorage");
|
|
5
|
+
Object.defineProperty(exports, "LocalStorageConstructor", { enumerable: true, get: function () { return localStorage_1.LocalStorageConstructor; } });
|
|
6
|
+
var nativeStorage_1 = require("./nativeStorage");
|
|
7
|
+
Object.defineProperty(exports, "NativeStorageConstructor", { enumerable: true, get: function () { return nativeStorage_1.NativeStorageConstructor; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/storage/index.ts"],"names":[],"mappings":";;;AAAA,+CAAyD;AAAhD,uHAAA,uBAAuB,OAAA;AAChC,iDAA2D;AAAlD,yHAAA,wBAAwB,OAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalStorageConstructor = void 0;
|
|
4
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
5
|
+
var LocalStorageConstructor = /** @class */ (function () {
|
|
6
|
+
function LocalStorageConstructor() {
|
|
7
|
+
}
|
|
8
|
+
LocalStorageConstructor.prototype.initialize = function (key) {
|
|
9
|
+
var storage = new LocalStorage(key);
|
|
10
|
+
return storage;
|
|
11
|
+
};
|
|
12
|
+
return LocalStorageConstructor;
|
|
13
|
+
}());
|
|
14
|
+
exports.LocalStorageConstructor = LocalStorageConstructor;
|
|
15
|
+
var LocalStorage = /** @class */ (function () {
|
|
16
|
+
function LocalStorage(key) {
|
|
17
|
+
this.storageKey = key;
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(LocalStorage.prototype, "key", {
|
|
20
|
+
get: function () {
|
|
21
|
+
return this.storageKey;
|
|
22
|
+
},
|
|
23
|
+
enumerable: false,
|
|
24
|
+
configurable: true
|
|
25
|
+
});
|
|
26
|
+
LocalStorage.prototype.read = function () {
|
|
27
|
+
var data = localStorage.getItem(this.storageKey);
|
|
28
|
+
if (!data) {
|
|
29
|
+
return (0, javascript_sdk_core_1.Err)(new javascript_sdk_core_1.KameleoonError(javascript_sdk_core_1.KameleoonException.StorageRead, this.storageKey));
|
|
30
|
+
}
|
|
31
|
+
return (0, javascript_sdk_core_1.Ok)(data);
|
|
32
|
+
};
|
|
33
|
+
LocalStorage.prototype.write = function (data) {
|
|
34
|
+
try {
|
|
35
|
+
localStorage.setItem(this.storageKey, data);
|
|
36
|
+
return (0, javascript_sdk_core_1.Ok)();
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
return (0, javascript_sdk_core_1.Err)(new javascript_sdk_core_1.KameleoonError(javascript_sdk_core_1.KameleoonException.StorageWrite, err));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return LocalStorage;
|
|
43
|
+
}());
|
|
44
|
+
//# sourceMappingURL=localStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localStorage.js","sourceRoot":"","sources":["../../src/storage/localStorage.ts"],"names":[],"mappings":";;;AAAA,sEASwC;AAExC;IAAA;IAMA,CAAC;IALQ,4CAAU,GAAjB,UAAkB,GAAwB;QACxC,IAAM,OAAO,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;QAEtC,OAAO,OAAO,CAAC;IACjB,CAAC;IACH,8BAAC;AAAD,CAAC,AAND,IAMC;AANY,0DAAuB;AAQpC;IAGE,sBAAY,GAAwB;QAClC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,sBAAI,6BAAG;aAAP;YACE,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;;;OAAA;IAEM,2BAAI,GAAX;QACE,IAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnD,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,IAAA,yBAAG,EACR,IAAI,oCAAc,CAAC,wCAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CACpE,CAAC;SACH;QAED,OAAO,IAAA,wBAAE,EAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAEM,4BAAK,GAAZ,UAAa,IAAY;QACvB,IAAI;YACF,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YAE5C,OAAO,IAAA,wBAAE,GAAE,CAAC;SACb;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,IAAA,yBAAG,EAAC,IAAI,oCAAc,CAAC,wCAAkB,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;SACtE;IACH,CAAC;IACH,mBAAC;AAAD,CAAC,AAhCD,IAgCC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NativeStorageConstructor = void 0;
|
|
4
|
+
var javascript_sdk_core_1 = require("@kameleoon/javascript-sdk-core");
|
|
5
|
+
var react_native_mmkv_1 = require("react-native-mmkv");
|
|
6
|
+
var NativeStorageConstructor = /** @class */ (function () {
|
|
7
|
+
function NativeStorageConstructor() {
|
|
8
|
+
}
|
|
9
|
+
NativeStorageConstructor.prototype.initialize = function (key) {
|
|
10
|
+
var storage = new NativeStorage(key);
|
|
11
|
+
return storage;
|
|
12
|
+
};
|
|
13
|
+
return NativeStorageConstructor;
|
|
14
|
+
}());
|
|
15
|
+
exports.NativeStorageConstructor = NativeStorageConstructor;
|
|
16
|
+
var NativeStorage = /** @class */ (function () {
|
|
17
|
+
function NativeStorage(key) {
|
|
18
|
+
this.storage = new react_native_mmkv_1.MMKV();
|
|
19
|
+
this.storageKey = key;
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(NativeStorage.prototype, "key", {
|
|
22
|
+
get: function () {
|
|
23
|
+
return this.storageKey;
|
|
24
|
+
},
|
|
25
|
+
enumerable: false,
|
|
26
|
+
configurable: true
|
|
27
|
+
});
|
|
28
|
+
NativeStorage.prototype.read = function () {
|
|
29
|
+
var data = this.storage.getString(this.storageKey);
|
|
30
|
+
if (!data) {
|
|
31
|
+
return (0, javascript_sdk_core_1.Err)(new javascript_sdk_core_1.KameleoonError(javascript_sdk_core_1.KameleoonException.StorageRead, this.storageKey));
|
|
32
|
+
}
|
|
33
|
+
return (0, javascript_sdk_core_1.Ok)(data);
|
|
34
|
+
};
|
|
35
|
+
NativeStorage.prototype.write = function (data) {
|
|
36
|
+
this.storage.set(this.storageKey, data);
|
|
37
|
+
return (0, javascript_sdk_core_1.Ok)();
|
|
38
|
+
};
|
|
39
|
+
return NativeStorage;
|
|
40
|
+
}());
|
|
41
|
+
//# sourceMappingURL=nativeStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeStorage.js","sourceRoot":"","sources":["../../src/storage/nativeStorage.ts"],"names":[],"mappings":";;;AAAA,sEASwC;AACxC,uDAAyC;AAEzC;IAAA;IAMA,CAAC;IALQ,6CAAU,GAAjB,UAAkB,GAAwB;QACxC,IAAM,OAAO,GAAG,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC;QAEvC,OAAO,OAAO,CAAC;IACjB,CAAC;IACH,+BAAC;AAAD,CAAC,AAND,IAMC;AANY,4DAAwB;AAQrC;IAIE,uBAAY,GAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,IAAI,wBAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,sBAAI,8BAAG;aAAP;YACE,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;;;OAAA;IAEM,4BAAI,GAAX;QACE,IAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAErD,IAAI,CAAC,IAAI,EAAE;YACT,OAAO,IAAA,yBAAG,EACR,IAAI,oCAAc,CAAC,wCAAkB,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CACpE,CAAC;SACH;QAED,OAAO,IAAA,wBAAE,EAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IAEM,6BAAK,GAAZ,UAAa,IAAY;QACvB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAExC,OAAO,IAAA,wBAAE,GAAE,CAAC;IACd,CAAC;IACH,oBAAC;AAAD,CAAC,AA9BD,IA8BC"}
|
package/dist/useAddData.d.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { KameleoonDataType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
+
import { KameleoonError } from './KameleoonError';
|
|
3
|
+
export interface IAddDataHookResult {
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* Adds targeting data to the storage so that other methods could decide whether the current visitor is targeted or not. Note: userAgent data will not be stored in storage like other data, and it will be sent with every tracking request for bot filtration.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.
|
|
8
|
+
* @param {...KameleoonDataType} data - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments.
|
|
6
9
|
*/
|
|
7
|
-
addData: (visitorCode: string, ...
|
|
10
|
+
addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;
|
|
11
|
+
/** An optional error object that may be returned if an error occurs while calling the `addData` function. */
|
|
12
|
+
error: KameleoonError | null;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
|
-
* A React Hook that returns
|
|
11
|
-
*
|
|
15
|
+
* A React Hook that returns `addData` function for adding targeting data to the Kameleoon storage.
|
|
16
|
+
*
|
|
17
|
+
* @returns {IAddDataHookResult} an object containing the `addData` function and an optional error object.
|
|
12
18
|
*/
|
|
13
|
-
export declare function useAddData():
|
|
14
|
-
export {};
|
|
19
|
+
export declare function useAddData(): IAddDataHookResult;
|
package/dist/useAddData.js
CHANGED
|
@@ -28,21 +28,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
exports.useAddData = void 0;
|
|
29
29
|
var react_1 = require("react");
|
|
30
30
|
var useKameleoon_1 = require("./useKameleoon");
|
|
31
|
+
var useError_1 = require("./useError");
|
|
31
32
|
/**
|
|
32
|
-
* A React Hook that returns
|
|
33
|
-
*
|
|
33
|
+
* A React Hook that returns `addData` function for adding targeting data to the Kameleoon storage.
|
|
34
|
+
*
|
|
35
|
+
* @returns {IAddDataHookResult} an object containing the `addData` function and an optional error object.
|
|
34
36
|
*/
|
|
35
37
|
function useAddData() {
|
|
36
38
|
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
39
|
+
var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
|
|
37
40
|
var addData = (0, react_1.useCallback)(function (visitorCode) {
|
|
38
|
-
var
|
|
41
|
+
var data = [];
|
|
39
42
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
40
|
-
|
|
43
|
+
data[_i - 1] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
client.addData.apply(client, __spreadArray([visitorCode], __read(data), false));
|
|
47
|
+
}
|
|
48
|
+
catch (unknownError) {
|
|
49
|
+
setError(unknownError);
|
|
41
50
|
}
|
|
42
|
-
client.addData.apply(client, __spreadArray([visitorCode], __read(dataTypes), false));
|
|
43
51
|
}, [client]);
|
|
44
52
|
return {
|
|
45
53
|
addData: addData,
|
|
54
|
+
error: error,
|
|
46
55
|
};
|
|
47
56
|
}
|
|
48
57
|
exports.useAddData = useAddData;
|
package/dist/useAddData.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAddData.js","sourceRoot":"","sources":["../src/useAddData.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAEpC,+CAA8C;
|
|
1
|
+
{"version":3,"file":"useAddData.js","sourceRoot":"","sources":["../src/useAddData.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAoC;AAEpC,+CAA8C;AAC9C,uCAAsC;AAetC;;;;GAIG;AACH,SAAgB,UAAU;IAChB,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAC5B,IAAA,KAAsB,IAAA,mBAAQ,GAAE,EAA9B,KAAK,WAAA,EAAE,QAAQ,cAAe,CAAC;IAEvC,IAAM,OAAO,GAAG,IAAA,mBAAW,EACzB,UAAC,WAAmB;QAAE,cAA4B;aAA5B,UAA4B,EAA5B,qBAA4B,EAA5B,IAA4B;YAA5B,6BAA4B;;QAChD,IAAI;YACF,MAAM,CAAC,OAAO,OAAd,MAAM,iBAAS,WAAW,UAAK,IAAI,WAAE;SACtC;QAAC,OAAO,YAAY,EAAE;YACrB,QAAQ,CAAC,YAAY,CAAC,CAAC;SACxB;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,OAAO,SAAA;QACP,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AAnBD,gCAmBC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface IBrowserVisitorCodeHookResult {
|
|
2
|
+
/**
|
|
3
|
+
* Obtains visitor code from browser cookie, if no cookie exists returns new random visitor code (or the specified default value).
|
|
4
|
+
*
|
|
5
|
+
* @param domain - domain to be set to browser cookie along with visitor code.
|
|
6
|
+
* @param defaultVisitorCode - visitor code to be used instead of randomly generated visitor code in case there is no visitor code saved in browser cookie.
|
|
7
|
+
* @returns {string} result visitor code.
|
|
8
|
+
*/
|
|
9
|
+
getBrowserVisitorCode: (domain: string, defaultVisitorCode?: string) => string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A React Hook that returns `getBrowserVisitorCode` function which obtains the Kameleoon visitorCode.
|
|
13
|
+
*
|
|
14
|
+
* @returns {IBrowserVisitorCodeHookResult} an object containing the `getBrowserVisitorCode` function and an optional error object.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useBrowserVisitorCode(): IBrowserVisitorCodeHookResult;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBrowserVisitorCode = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var browserUtils_1 = require("./kameleoonUtils/browserUtils");
|
|
6
|
+
/**
|
|
7
|
+
* A React Hook that returns `getBrowserVisitorCode` function which obtains the Kameleoon visitorCode.
|
|
8
|
+
*
|
|
9
|
+
* @returns {IBrowserVisitorCodeHookResult} an object containing the `getBrowserVisitorCode` function and an optional error object.
|
|
10
|
+
*/
|
|
11
|
+
function useBrowserVisitorCode() {
|
|
12
|
+
var getBrowserVisitorCode = (0, react_1.useCallback)(function (domain, defaultVisitorCode) {
|
|
13
|
+
return browserUtils_1.BrowserUtils.getVisitorCode(domain, defaultVisitorCode);
|
|
14
|
+
}, []);
|
|
15
|
+
return {
|
|
16
|
+
getBrowserVisitorCode: getBrowserVisitorCode,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.useBrowserVisitorCode = useBrowserVisitorCode;
|
|
20
|
+
//# sourceMappingURL=useBrowserVisitorCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBrowserVisitorCode.js","sourceRoot":"","sources":["../src/useBrowserVisitorCode.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,8DAA6D;AAgB7D;;;;GAIG;AACH,SAAgB,qBAAqB;IACnC,IAAM,qBAAqB,GAAG,IAAA,mBAAW,EACvC,UAAC,MAAc,EAAE,kBAA2B;QAC1C,OAAO,2BAAY,CAAC,cAAc,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IACjE,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO;QACL,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC;AAXD,sDAWC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { KameleoonError } from './KameleoonError';
|
|
2
|
+
export interface IConfigurationUpdateHookResult {
|
|
3
|
+
/**
|
|
4
|
+
* Fires a callback on client configuration update. Note: this method only works for server sent events of real time update.
|
|
5
|
+
*
|
|
6
|
+
* @param {() => void} callback - callback function with no parameters that will be called upon configuration update.
|
|
7
|
+
*/
|
|
8
|
+
onConfigurationUpdate: (callback: () => void) => void;
|
|
9
|
+
/** An optional error object that may be returned if an error occurs while calling the `onConfigurationUpdate` function. */
|
|
10
|
+
error: KameleoonError | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A React Hook that returns `onConfigurationUpdate` function which fires a callback on client configuration update.
|
|
14
|
+
*
|
|
15
|
+
* @returns {IConfigurationUpdateHookResult} an object containing the `onConfigurationUpdate` function and an optional error object.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useConfigurationUpdate(): IConfigurationUpdateHookResult;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useConfigurationUpdate = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var useKameleoon_1 = require("./useKameleoon");
|
|
6
|
+
var useError_1 = require("./useError");
|
|
7
|
+
/**
|
|
8
|
+
* A React Hook that returns `onConfigurationUpdate` function which fires a callback on client configuration update.
|
|
9
|
+
*
|
|
10
|
+
* @returns {IConfigurationUpdateHookResult} an object containing the `onConfigurationUpdate` function and an optional error object.
|
|
11
|
+
*/
|
|
12
|
+
function useConfigurationUpdate() {
|
|
13
|
+
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
14
|
+
var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
|
|
15
|
+
var onConfigurationUpdate = (0, react_1.useCallback)(function (callback) {
|
|
16
|
+
try {
|
|
17
|
+
client.onConfigurationUpdate(callback);
|
|
18
|
+
}
|
|
19
|
+
catch (unknownError) {
|
|
20
|
+
setError(unknownError);
|
|
21
|
+
}
|
|
22
|
+
}, [client]);
|
|
23
|
+
return {
|
|
24
|
+
onConfigurationUpdate: onConfigurationUpdate,
|
|
25
|
+
error: error,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.useConfigurationUpdate = useConfigurationUpdate;
|
|
29
|
+
//# sourceMappingURL=useConfigurationUpdate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useConfigurationUpdate.js","sourceRoot":"","sources":["../src/useConfigurationUpdate.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,+CAA8C;AAC9C,uCAAsC;AActC;;;;GAIG;AACH,SAAgB,sBAAsB;IAC5B,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAC5B,IAAA,KAAsB,IAAA,mBAAQ,GAAE,EAA9B,KAAK,WAAA,EAAE,QAAQ,cAAe,CAAC;IAEvC,IAAM,qBAAqB,GAAG,IAAA,mBAAW,EACvC,UAAC,QAAoB;QACnB,IAAI;YACF,MAAM,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;SACxC;QAAC,OAAO,YAAY,EAAE;YACrB,QAAQ,CAAC,YAAY,CAAC,CAAC;SACxB;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,qBAAqB,uBAAA;QACrB,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AAnBD,wDAmBC"}
|
package/dist/useError.d.ts
CHANGED
package/dist/useError.js
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useError = void 0;
|
|
4
4
|
var react_1 = require("react");
|
|
5
|
-
var getKameleoonException_1 = require("./getKameleoonException");
|
|
6
5
|
function useError() {
|
|
7
6
|
var errorRef = (0, react_1.useRef)(null);
|
|
8
7
|
var setError = (0, react_1.useCallback)(function (unknownError) {
|
|
9
|
-
|
|
10
|
-
errorRef.current = exception;
|
|
8
|
+
errorRef.current = unknownError;
|
|
11
9
|
}, [errorRef]);
|
|
12
10
|
return {
|
|
13
11
|
error: errorRef.current,
|
package/dist/useError.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useError.js","sourceRoot":"","sources":["../src/useError.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;
|
|
1
|
+
{"version":3,"file":"useError.js","sourceRoot":"","sources":["../src/useError.ts"],"names":[],"mappings":";;;AAAA,+BAA4C;AAQ5C,SAAgB,QAAQ;IACtB,IAAM,QAAQ,GAAG,IAAA,cAAM,EAAwB,IAAI,CAAC,CAAC;IAErD,IAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,UAAC,YAAqB;QACpB,QAAQ,CAAC,OAAO,GAAG,YAA8B,CAAC;IACpD,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,OAAO;QACvB,QAAQ,UAAA;KACT,CAAC;AACJ,CAAC;AAdD,4BAcC"}
|
package/dist/useErrors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { KameleoonException } from '
|
|
2
|
-
|
|
1
|
+
import { KameleoonException } from '@kameleoon/javascript-sdk-core';
|
|
2
|
+
type UseErrorsHookResultType = {
|
|
3
3
|
errors: KameleoonException[];
|
|
4
4
|
setErrors: (newErrors: Array<KameleoonException | undefined>) => void;
|
|
5
5
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExperimentType } from '@kameleoon/javascript-sdk-core';
|
|
2
|
+
import { KameleoonError } from './KameleoonError';
|
|
3
|
+
export interface IExperimentsHookResult {
|
|
4
|
+
/**
|
|
5
|
+
* Returns a list of experiments stored in the client configuration.
|
|
6
|
+
*
|
|
7
|
+
* @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields.
|
|
8
|
+
*/
|
|
9
|
+
getExperiments: () => ExperimentType[];
|
|
10
|
+
/** An optional error object that may be returned if an error occurs while calling the `getExperiments` function. */
|
|
11
|
+
error: KameleoonError | null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A React Hook that returns `getExperiments` function which returns a list of experiments.
|
|
15
|
+
*
|
|
16
|
+
* @returns {IExperimentsHookResult} an object containing the `getExperiments` function and an optional error object.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useExperiments(): IExperimentsHookResult;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useExperiments = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var useKameleoon_1 = require("./useKameleoon");
|
|
6
|
+
var useError_1 = require("./useError");
|
|
7
|
+
/**
|
|
8
|
+
* A React Hook that returns `getExperiments` function which returns a list of experiments.
|
|
9
|
+
*
|
|
10
|
+
* @returns {IExperimentsHookResult} an object containing the `getExperiments` function and an optional error object.
|
|
11
|
+
*/
|
|
12
|
+
function useExperiments() {
|
|
13
|
+
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
14
|
+
var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
|
|
15
|
+
var getExperiments = (0, react_1.useCallback)(function () {
|
|
16
|
+
try {
|
|
17
|
+
return client.getExperiments();
|
|
18
|
+
}
|
|
19
|
+
catch (unknownError) {
|
|
20
|
+
setError(unknownError);
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}, [client]);
|
|
24
|
+
return {
|
|
25
|
+
getExperiments: getExperiments,
|
|
26
|
+
error: error,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.useExperiments = useExperiments;
|
|
30
|
+
//# sourceMappingURL=useExperiments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useExperiments.js","sourceRoot":"","sources":["../src/useExperiments.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAEpC,+CAA8C;AAC9C,uCAAsC;AActC;;;;GAIG;AACH,SAAgB,cAAc;IACpB,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAC5B,IAAA,KAAsB,IAAA,mBAAQ,GAAE,EAA9B,KAAK,WAAA,EAAE,QAAQ,cAAe,CAAC;IAEvC,IAAM,cAAc,GAAG,IAAA,mBAAW,EAAC;QACjC,IAAI;YACF,OAAO,MAAM,CAAC,cAAc,EAAE,CAAC;SAChC;QAAC,OAAO,YAAY,EAAE;YACrB,QAAQ,CAAC,YAAY,CAAC,CAAC;YAEvB,OAAO,EAAE,CAAC;SACX;IACH,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAEb,OAAO;QACL,cAAc,gBAAA;QACd,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AAlBD,wCAkBC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KameleoonError } from './KameleoonError';
|
|
2
|
+
export interface IFeatureFlagActiveHookResult {
|
|
3
|
+
/**
|
|
4
|
+
* Indicates whether the visitor with `visitorCode` has `featureKey` active for him, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request if the feature rollout rule was of type of `Experimentation`.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.
|
|
7
|
+
* @param {string} featureKey - a unique key for feature flag.
|
|
8
|
+
* @returns {boolean} a boolean indicator of whether the feature flag with `featureKey` is active for visitor with `visitorCode`.
|
|
9
|
+
*/
|
|
10
|
+
isFeatureFlagActive: (visitorCode: string, featureKey: string) => boolean;
|
|
11
|
+
/** An optional error object that may be returned if an error occurs while calling the `isFeatureFlagActive` function. */
|
|
12
|
+
error: KameleoonError | null;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A React Hook that returns `isFeatureFlagActive` function which indicates whether the visitor with `visitorCode` has `featureKey` active for him.
|
|
16
|
+
*
|
|
17
|
+
* @returns {IFeatureFlagActiveHookResult} an object containing the `isFeatureFlagActive` function.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useFeatureFlagActive(): IFeatureFlagActiveHookResult;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFeatureFlagActive = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var useKameleoon_1 = require("./useKameleoon");
|
|
6
|
+
var useError_1 = require("./useError");
|
|
7
|
+
/**
|
|
8
|
+
* A React Hook that returns `isFeatureFlagActive` function which indicates whether the visitor with `visitorCode` has `featureKey` active for him.
|
|
9
|
+
*
|
|
10
|
+
* @returns {IFeatureFlagActiveHookResult} an object containing the `isFeatureFlagActive` function.
|
|
11
|
+
*/
|
|
12
|
+
function useFeatureFlagActive() {
|
|
13
|
+
var client = (0, useKameleoon_1.useKameleoon)().client;
|
|
14
|
+
var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
|
|
15
|
+
var isFeatureFlagActive = (0, react_1.useCallback)(function (visitorCode, featureKey) {
|
|
16
|
+
try {
|
|
17
|
+
return client.isFeatureFlagActive(visitorCode, featureKey);
|
|
18
|
+
}
|
|
19
|
+
catch (unknownError) {
|
|
20
|
+
setError(unknownError);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}, [client, setError]);
|
|
24
|
+
return {
|
|
25
|
+
isFeatureFlagActive: isFeatureFlagActive,
|
|
26
|
+
error: error,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
exports.useFeatureFlagActive = useFeatureFlagActive;
|
|
30
|
+
//# sourceMappingURL=useFeatureFlagActive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeatureFlagActive.js","sourceRoot":"","sources":["../src/useFeatureFlagActive.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AACpC,+CAA8C;AAE9C,uCAAsC;AAetC;;;;GAIG;AACH,SAAgB,oBAAoB;IAC1B,IAAA,MAAM,GAAK,IAAA,2BAAY,GAAE,OAAnB,CAAoB;IAC5B,IAAA,KAAsB,IAAA,mBAAQ,GAAE,EAA9B,KAAK,WAAA,EAAE,QAAQ,cAAe,CAAC;IAEvC,IAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,UAAC,WAAmB,EAAE,UAAkB;QACtC,IAAI;YACF,OAAO,MAAM,CAAC,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;SAC5D;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,OAAO;QACL,mBAAmB,qBAAA;QACnB,KAAK,OAAA;KACN,CAAC;AACJ,CAAC;AArBD,oDAqBC"}
|