@kameleoon/react-sdk 6.1.1 → 6.1.3

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.
Files changed (72) hide show
  1. package/dist/KameleoonContext.js +7 -3
  2. package/dist/KameleoonContext.js.map +1 -1
  3. package/dist/KameleoonError.js +16 -27
  4. package/dist/KameleoonError.js.map +1 -1
  5. package/dist/KameleoonProvider.js +18 -19
  6. package/dist/KameleoonProvider.js.map +1 -1
  7. package/dist/ProviderError.js +10 -25
  8. package/dist/ProviderError.js.map +1 -1
  9. package/dist/constants.js +6 -2
  10. package/dist/constants.js.map +1 -1
  11. package/dist/eventSource/browserEventSource.js +40 -30
  12. package/dist/eventSource/browserEventSource.js.map +1 -1
  13. package/dist/eventSource/index.js +18 -6
  14. package/dist/eventSource/index.js.map +1 -1
  15. package/dist/eventSource/nativeEventSource.js +42 -35
  16. package/dist/eventSource/nativeEventSource.js.map +1 -1
  17. package/dist/index.js +288 -51
  18. package/dist/index.js.map +1 -1
  19. package/dist/kameleoonClient.js +27 -22
  20. package/dist/kameleoonClient.js.map +1 -1
  21. package/dist/kameleoonUtils/browserUtils.js +45 -58
  22. package/dist/kameleoonUtils/browserUtils.js.map +1 -1
  23. package/dist/kameleoonUtils/nativeUtils.js +38 -54
  24. package/dist/kameleoonUtils/nativeUtils.js.map +1 -1
  25. package/dist/requester.d.ts +5 -0
  26. package/dist/requester.js +29 -0
  27. package/dist/requester.js.map +1 -0
  28. package/dist/storage/index.js +18 -6
  29. package/dist/storage/index.js.map +1 -1
  30. package/dist/storage/localStorage.js +37 -39
  31. package/dist/storage/localStorage.js.map +1 -1
  32. package/dist/storage/nativeStorage.js +36 -36
  33. package/dist/storage/nativeStorage.js.map +1 -1
  34. package/dist/useAddData.js +26 -49
  35. package/dist/useAddData.js.map +1 -1
  36. package/dist/useBrowserVisitorCode.js +13 -11
  37. package/dist/useBrowserVisitorCode.js.map +1 -1
  38. package/dist/useConfigurationUpdate.js +26 -20
  39. package/dist/useConfigurationUpdate.js.map +1 -1
  40. package/dist/useError.js +14 -12
  41. package/dist/useError.js.map +1 -1
  42. package/dist/useErrors.js +15 -38
  43. package/dist/useErrors.js.map +1 -1
  44. package/dist/useExperiments.js +27 -21
  45. package/dist/useExperiments.js.map +1 -1
  46. package/dist/useFeatureFlagActive.js +27 -21
  47. package/dist/useFeatureFlagActive.js.map +1 -1
  48. package/dist/useFeatureFlagVariationKey.js +27 -21
  49. package/dist/useFeatureFlagVariationKey.js.map +1 -1
  50. package/dist/useFeatureFlags.js +27 -21
  51. package/dist/useFeatureFlags.js.map +1 -1
  52. package/dist/useFeatureVariable.js +27 -21
  53. package/dist/useFeatureVariable.js.map +1 -1
  54. package/dist/useFlushData.js +16 -12
  55. package/dist/useFlushData.js.map +1 -1
  56. package/dist/useInitialize.js +27 -65
  57. package/dist/useInitialize.js.map +1 -1
  58. package/dist/useKameleoon.js +15 -13
  59. package/dist/useKameleoon.js.map +1 -1
  60. package/dist/useNativeVisitorCode.js +13 -11
  61. package/dist/useNativeVisitorCode.js.map +1 -1
  62. package/dist/useRemoteData.js +28 -67
  63. package/dist/useRemoteData.js.map +1 -1
  64. package/dist/useTrackConversion.js +26 -20
  65. package/dist/useTrackConversion.js.map +1 -1
  66. package/dist/useTriggerExperiment.js +28 -22
  67. package/dist/useTriggerExperiment.js.map +1 -1
  68. package/dist/useVisitorExperiments.js +27 -21
  69. package/dist/useVisitorExperiments.js.map +1 -1
  70. package/dist/useVisitorFeatureFlags.js +27 -21
  71. package/dist/useVisitorFeatureFlags.js.map +1 -1
  72. package/package.json +8 -5
@@ -1,68 +1,52 @@
1
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 });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
18
6
  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);
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ var _storage = require("../storage");
9
+ const storage = new _storage.NativeStorageConstructor().initialize(_javascriptSdkCore.KameleoonStorageKey.VisitorCode);
10
+
22
11
  // --- Note ---
23
12
  // Extra class is created:
24
13
  // - To be able to enforce abstract `getVisitorCode` method
25
14
  // - To be able to use extended methods while `KameleoonUtils` iself only operates on static methods
26
15
  // - 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;
16
+ class KameleoonUtilsConstructor extends _javascriptSdkCore.KameleoonCoreUtils {
17
+ getVisitorCode({
18
+ defaultVisitorCode
19
+ }) {
20
+ const readResult = storage.read();
21
+ if (readResult.ok) {
22
+ return readResult.data;
31
23
  }
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));
24
+ const visitorCode = defaultVisitorCode || this.generateRandomString(_javascriptSdkCore.VISITOR_CODE_LENGTH);
25
+
26
+ // --- Note ---
27
+ // `write` result is ignored because there is no exceptions for `mmkv` write operation
28
+ storage.write(visitorCode);
29
+ return visitorCode;
30
+ }
31
+ }
32
+
46
33
  /**
47
34
  * @class
48
35
  * BrowserUtils - a class with containing a number of static helper methods
49
36
  * */
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
- }());
37
+ class NativeUtils {
38
+ // TODO: docs
39
+ /**
40
+ * @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
41
+ * @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
42
+ * @returns {string} result visitor code
43
+ * */
44
+ static getVisitorCode(defaultVisitorCode) {
45
+ const kameleoonUtilsConstructor = new KameleoonUtilsConstructor();
46
+ return kameleoonUtilsConstructor.getVisitorCode({
47
+ defaultVisitorCode
48
+ });
49
+ }
50
+ }
67
51
  exports.NativeUtils = NativeUtils;
68
52
  //# sourceMappingURL=nativeUtils.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"nativeUtils.js","names":["_javascriptSdkCore","require","_storage","storage","NativeStorageConstructor","initialize","KameleoonStorageKey","VisitorCode","KameleoonUtilsConstructor","KameleoonCoreUtils","getVisitorCode","defaultVisitorCode","readResult","read","ok","data","visitorCode","generateRandomString","VISITOR_CODE_LENGTH","write","NativeUtils","kameleoonUtilsConstructor","exports"],"sources":["../../src/kameleoonUtils/nativeUtils.ts"],"sourcesContent":["import {\n KameleoonCoreUtils,\n KameleoonStorageKey,\n VISITOR_CODE_LENGTH,\n MobileGetVisitorCodeParametersType,\n} from '@kameleoon/javascript-sdk-core';\nimport { NativeStorageConstructor } from '../storage';\n\nconst storage = new NativeStorageConstructor().initialize(\n KameleoonStorageKey.VisitorCode,\n);\n\n// --- Note ---\n// Extra class is created:\n// - To be able to enforce abstract `getVisitorCode` method\n// - To be able to use extended methods while `KameleoonUtils` iself only operates on static methods\n// - To keep similar parameters object on inner implementation and dispers it for proprietary implementations\nclass KameleoonUtilsConstructor extends KameleoonCoreUtils {\n public getVisitorCode({\n defaultVisitorCode,\n }: MobileGetVisitorCodeParametersType): string {\n const readResult = storage.read();\n\n if (readResult.ok) {\n return readResult.data;\n }\n\n const visitorCode =\n defaultVisitorCode || this.generateRandomString(VISITOR_CODE_LENGTH);\n\n // --- Note ---\n // `write` result is ignored because there is no exceptions for `mmkv` write operation\n storage.write(visitorCode);\n\n return visitorCode;\n }\n}\n\n/**\n * @class\n * BrowserUtils - a class with containing a number of static helper methods\n * */\nexport class NativeUtils {\n // TODO: docs\n /**\n * @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\n * @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\n * @returns {string} result visitor code\n * */\n static getVisitorCode(defaultVisitorCode?: string): string {\n const kameleoonUtilsConstructor = new KameleoonUtilsConstructor();\n\n return kameleoonUtilsConstructor.getVisitorCode({\n defaultVisitorCode,\n });\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAMA,IAAAC,QAAA,GAAAD,OAAA;AAEA,MAAME,OAAO,GAAG,IAAIC,iCAAwB,EAAE,CAACC,UAAU,CACvDC,sCAAmB,CAACC,WAAW,CAChC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,SAASC,qCAAkB,CAAC;EAClDC,cAAcA,CAAC;IACpBC;EACkC,CAAC,EAAU;IAC7C,MAAMC,UAAU,GAAGT,OAAO,CAACU,IAAI,EAAE;IAEjC,IAAID,UAAU,CAACE,EAAE,EAAE;MACjB,OAAOF,UAAU,CAACG,IAAI;IACxB;IAEA,MAAMC,WAAW,GACfL,kBAAkB,IAAI,IAAI,CAACM,oBAAoB,CAACC,sCAAmB,CAAC;;IAEtE;IACA;IACAf,OAAO,CAACgB,KAAK,CAACH,WAAW,CAAC;IAE1B,OAAOA,WAAW;EACpB;AACF;;AAEA;AACA;AACA;AACA;AACO,MAAMI,WAAW,CAAC;EACvB;EACA;AACF;AACA;AACA;AACA;EACE,OAAOV,cAAcA,CAACC,kBAA2B,EAAU;IACzD,MAAMU,yBAAyB,GAAG,IAAIb,yBAAyB,EAAE;IAEjE,OAAOa,yBAAyB,CAACX,cAAc,CAAC;MAC9CC;IACF,CAAC,CAAC;EACJ;AACF;AAACW,OAAA,CAAAF,WAAA,GAAAA,WAAA"}
@@ -0,0 +1,5 @@
1
+ import { JSONType, TrackParametersType, IExternalRequestDispatcher } from '@kameleoon/javascript-sdk-core';
2
+ export declare class RequestDispatcher implements IExternalRequestDispatcher {
3
+ track({ url, headers, body, }: TrackParametersType): Promise<boolean>;
4
+ get(url: string): Promise<JSONType>;
5
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.RequestDispatcher = void 0;
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ class RequestDispatcher {
9
+ async track({
10
+ url,
11
+ headers,
12
+ body
13
+ }) {
14
+ const response = await fetch(url, {
15
+ method: _javascriptSdkCore.HttpMethod.Post,
16
+ headers,
17
+ body
18
+ });
19
+ return response.ok;
20
+ }
21
+ async get(url) {
22
+ const response = await fetch(url, {
23
+ method: _javascriptSdkCore.HttpMethod.Get
24
+ });
25
+ return response.json();
26
+ }
27
+ }
28
+ exports.RequestDispatcher = RequestDispatcher;
29
+ //# sourceMappingURL=requester.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requester.js","names":["_javascriptSdkCore","require","RequestDispatcher","track","url","headers","body","response","fetch","method","HttpMethod","Post","ok","get","Get","json","exports"],"sources":["../src/requester.ts"],"sourcesContent":["import {\n JSONType,\n HttpMethod,\n TrackParametersType,\n IExternalRequestDispatcher,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class RequestDispatcher implements IExternalRequestDispatcher {\n public async track({\n url,\n headers,\n body,\n }: TrackParametersType): Promise<boolean> {\n const response = await fetch(url, {\n method: HttpMethod.Post,\n headers,\n body,\n });\n\n return response.ok;\n }\n\n public async get(url: string): Promise<JSONType> {\n const response = await fetch(url, {\n method: HttpMethod.Get,\n });\n\n return response.json();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAOO,MAAMC,iBAAiB,CAAuC;EACnE,MAAaC,KAAKA,CAAC;IACjBC,GAAG;IACHC,OAAO;IACPC;EACmB,CAAC,EAAoB;IACxC,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;MAChCK,MAAM,EAAEC,6BAAU,CAACC,IAAI;MACvBN,OAAO;MACPC;IACF,CAAC,CAAC;IAEF,OAAOC,QAAQ,CAACK,EAAE;EACpB;EAEA,MAAaC,GAAGA,CAACT,GAAW,EAAqB;IAC/C,MAAMG,QAAQ,GAAG,MAAMC,KAAK,CAACJ,GAAG,EAAE;MAChCK,MAAM,EAAEC,6BAAU,CAACI;IACrB,CAAC,CAAC;IAEF,OAAOP,QAAQ,CAACQ,IAAI,EAAE;EACxB;AACF;AAACC,OAAA,CAAAd,iBAAA,GAAAA,iBAAA"}
@@ -1,8 +1,20 @@
1
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; } });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "LocalStorageConstructor", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _localStorage.LocalStorageConstructor;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "NativeStorageConstructor", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _nativeStorage.NativeStorageConstructor;
16
+ }
17
+ });
18
+ var _localStorage = require("./localStorage");
19
+ var _nativeStorage = require("./nativeStorage");
8
20
  //# sourceMappingURL=index.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","names":["_localStorage","require","_nativeStorage"],"sources":["../../src/storage/index.ts"],"sourcesContent":["export { LocalStorageConstructor } from './localStorage';\nexport { NativeStorageConstructor } from './nativeStorage';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA"}
@@ -1,44 +1,42 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  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
- }());
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ 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; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ 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); }
11
+ class LocalStorageConstructor {
12
+ initialize(key) {
13
+ const storage = new LocalStorage(key);
14
+ return storage;
15
+ }
16
+ }
14
17
  exports.LocalStorageConstructor = LocalStorageConstructor;
15
- var LocalStorage = /** @class */ (function () {
16
- function LocalStorage(key) {
17
- this.storageKey = key;
18
+ class LocalStorage {
19
+ constructor(key) {
20
+ _defineProperty(this, "storageKey", void 0);
21
+ this.storageKey = key;
22
+ }
23
+ get key() {
24
+ return this.storageKey;
25
+ }
26
+ read() {
27
+ const data = localStorage.getItem(this.storageKey);
28
+ if (!data) {
29
+ return (0, _javascriptSdkCore.Err)(new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.StorageRead, this.storageKey));
30
+ }
31
+ return (0, _javascriptSdkCore.Ok)(data);
32
+ }
33
+ write(data) {
34
+ try {
35
+ localStorage.setItem(this.storageKey, data);
36
+ return (0, _javascriptSdkCore.Ok)();
37
+ } catch (err) {
38
+ return (0, _javascriptSdkCore.Err)(new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.StorageWrite, err));
18
39
  }
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
- }());
40
+ }
41
+ }
44
42
  //# sourceMappingURL=localStorage.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"localStorage.js","names":["_javascriptSdkCore","require","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","LocalStorageConstructor","initialize","storage","LocalStorage","exports","constructor","storageKey","read","data","localStorage","getItem","Err","KameleoonError","KameleoonException","StorageRead","Ok","write","setItem","err","StorageWrite"],"sources":["../../src/storage/localStorage.ts"],"sourcesContent":["import {\n Ok,\n Err,\n Result,\n KameleoonError,\n IExternalStorage,\n KameleoonException,\n KameleoonStorageKey,\n IExternalStorageConstructor,\n} from '@kameleoon/javascript-sdk-core';\n\nexport class LocalStorageConstructor implements IExternalStorageConstructor {\n public initialize(key: KameleoonStorageKey): IExternalStorage {\n const storage = new LocalStorage(key);\n\n return storage;\n }\n}\n\nclass LocalStorage implements IExternalStorage {\n private storageKey: KameleoonStorageKey;\n\n constructor(key: KameleoonStorageKey) {\n this.storageKey = key;\n }\n\n get key(): KameleoonStorageKey {\n return this.storageKey;\n }\n\n public read(): Result<string, KameleoonError> {\n const data = localStorage.getItem(this.storageKey);\n\n if (!data) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, this.storageKey),\n );\n }\n\n return Ok(data);\n }\n\n public write(data: string): Result<void, KameleoonError> {\n try {\n localStorage.setItem(this.storageKey, data);\n\n return Ok();\n } catch (err) {\n return Err(new KameleoonError(KameleoonException.StorageWrite, err));\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AASwC,SAAAC,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAEjC,MAAMU,uBAAuB,CAAwC;EACnEC,UAAUA,CAACtB,GAAwB,EAAoB;IAC5D,MAAMuB,OAAO,GAAG,IAAIC,YAAY,CAACxB,GAAG,CAAC;IAErC,OAAOuB,OAAO;EAChB;AACF;AAACE,OAAA,CAAAJ,uBAAA,GAAAA,uBAAA;AAED,MAAMG,YAAY,CAA6B;EAG7CE,WAAWA,CAAC1B,GAAwB,EAAE;IAAAF,eAAA;IACpC,IAAI,CAAC6B,UAAU,GAAG3B,GAAG;EACvB;EAEA,IAAIA,GAAGA,CAAA,EAAwB;IAC7B,OAAO,IAAI,CAAC2B,UAAU;EACxB;EAEOC,IAAIA,CAAA,EAAmC;IAC5C,MAAMC,IAAI,GAAGC,YAAY,CAACC,OAAO,CAAC,IAAI,CAACJ,UAAU,CAAC;IAElD,IAAI,CAACE,IAAI,EAAE;MACT,OAAO,IAAAG,sBAAG,EACR,IAAIC,iCAAc,CAACC,qCAAkB,CAACC,WAAW,EAAE,IAAI,CAACR,UAAU,CAAC,CACpE;IACH;IAEA,OAAO,IAAAS,qBAAE,EAACP,IAAI,CAAC;EACjB;EAEOQ,KAAKA,CAACR,IAAY,EAAgC;IACvD,IAAI;MACFC,YAAY,CAACQ,OAAO,CAAC,IAAI,CAACX,UAAU,EAAEE,IAAI,CAAC;MAE3C,OAAO,IAAAO,qBAAE,GAAE;IACb,CAAC,CAAC,OAAOG,GAAG,EAAE;MACZ,OAAO,IAAAP,sBAAG,EAAC,IAAIC,iCAAc,CAACC,qCAAkB,CAACM,YAAY,EAAED,GAAG,CAAC,CAAC;IACtE;EACF;AACF"}
@@ -1,41 +1,41 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  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
- }());
7
+ var _javascriptSdkCore = require("@kameleoon/javascript-sdk-core");
8
+ var _reactNativeMmkv = require("react-native-mmkv");
9
+ 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; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
+ 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); }
12
+ class NativeStorageConstructor {
13
+ initialize(key) {
14
+ const storage = new NativeStorage(key);
15
+ return storage;
16
+ }
17
+ }
15
18
  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;
19
+ class NativeStorage {
20
+ constructor(key) {
21
+ _defineProperty(this, "storageKey", void 0);
22
+ _defineProperty(this, "storage", void 0);
23
+ this.storage = new _reactNativeMmkv.MMKV();
24
+ this.storageKey = key;
25
+ }
26
+ get key() {
27
+ return this.storageKey;
28
+ }
29
+ read() {
30
+ const data = this.storage.getString(this.storageKey);
31
+ if (!data) {
32
+ return (0, _javascriptSdkCore.Err)(new _javascriptSdkCore.KameleoonError(_javascriptSdkCore.KameleoonException.StorageRead, this.storageKey));
20
33
  }
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
- }());
34
+ return (0, _javascriptSdkCore.Ok)(data);
35
+ }
36
+ write(data) {
37
+ this.storage.set(this.storageKey, data);
38
+ return (0, _javascriptSdkCore.Ok)();
39
+ }
40
+ }
41
41
  //# sourceMappingURL=nativeStorage.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"nativeStorage.js","names":["_javascriptSdkCore","require","_reactNativeMmkv","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","NativeStorageConstructor","initialize","storage","NativeStorage","exports","constructor","MMKV","storageKey","read","data","getString","Err","KameleoonError","KameleoonException","StorageRead","Ok","write","set"],"sources":["../../src/storage/nativeStorage.ts"],"sourcesContent":["import {\n Ok,\n Err,\n Result,\n KameleoonError,\n IExternalStorage,\n KameleoonException,\n KameleoonStorageKey,\n IExternalStorageConstructor,\n} from '@kameleoon/javascript-sdk-core';\nimport { MMKV } from 'react-native-mmkv';\n\nexport class NativeStorageConstructor implements IExternalStorageConstructor {\n public initialize(key: KameleoonStorageKey): IExternalStorage {\n const storage = new NativeStorage(key);\n\n return storage;\n }\n}\n\nclass NativeStorage implements IExternalStorage {\n private storageKey: KameleoonStorageKey;\n private storage: MMKV;\n\n constructor(key: KameleoonStorageKey) {\n this.storage = new MMKV();\n this.storageKey = key;\n }\n\n get key(): KameleoonStorageKey {\n return this.storageKey;\n }\n\n public read(): Result<string, KameleoonError> {\n const data = this.storage.getString(this.storageKey);\n\n if (!data) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, this.storageKey),\n );\n }\n\n return Ok(data);\n }\n\n public write(data: string): Result<void, KameleoonError> {\n this.storage.set(this.storageKey, data);\n\n return Ok();\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAUA,IAAAC,gBAAA,GAAAD,OAAA;AAAyC,SAAAE,gBAAAC,GAAA,EAAAC,GAAA,EAAAC,KAAA,IAAAD,GAAA,GAAAE,cAAA,CAAAF,GAAA,OAAAA,GAAA,IAAAD,GAAA,IAAAI,MAAA,CAAAC,cAAA,CAAAL,GAAA,EAAAC,GAAA,IAAAC,KAAA,EAAAA,KAAA,EAAAI,UAAA,QAAAC,YAAA,QAAAC,QAAA,oBAAAR,GAAA,CAAAC,GAAA,IAAAC,KAAA,WAAAF,GAAA;AAAA,SAAAG,eAAAM,GAAA,QAAAR,GAAA,GAAAS,YAAA,CAAAD,GAAA,2BAAAR,GAAA,gBAAAA,GAAA,GAAAU,MAAA,CAAAV,GAAA;AAAA,SAAAS,aAAAE,KAAA,EAAAC,IAAA,eAAAD,KAAA,iBAAAA,KAAA,kBAAAA,KAAA,MAAAE,IAAA,GAAAF,KAAA,CAAAG,MAAA,CAAAC,WAAA,OAAAF,IAAA,KAAAG,SAAA,QAAAC,GAAA,GAAAJ,IAAA,CAAAK,IAAA,CAAAP,KAAA,EAAAC,IAAA,2BAAAK,GAAA,sBAAAA,GAAA,YAAAE,SAAA,4DAAAP,IAAA,gBAAAF,MAAA,GAAAU,MAAA,EAAAT,KAAA;AAElC,MAAMU,wBAAwB,CAAwC;EACpEC,UAAUA,CAACtB,GAAwB,EAAoB;IAC5D,MAAMuB,OAAO,GAAG,IAAIC,aAAa,CAACxB,GAAG,CAAC;IAEtC,OAAOuB,OAAO;EAChB;AACF;AAACE,OAAA,CAAAJ,wBAAA,GAAAA,wBAAA;AAED,MAAMG,aAAa,CAA6B;EAI9CE,WAAWA,CAAC1B,GAAwB,EAAE;IAAAF,eAAA;IAAAA,eAAA;IACpC,IAAI,CAACyB,OAAO,GAAG,IAAII,qBAAI,EAAE;IACzB,IAAI,CAACC,UAAU,GAAG5B,GAAG;EACvB;EAEA,IAAIA,GAAGA,CAAA,EAAwB;IAC7B,OAAO,IAAI,CAAC4B,UAAU;EACxB;EAEOC,IAAIA,CAAA,EAAmC;IAC5C,MAAMC,IAAI,GAAG,IAAI,CAACP,OAAO,CAACQ,SAAS,CAAC,IAAI,CAACH,UAAU,CAAC;IAEpD,IAAI,CAACE,IAAI,EAAE;MACT,OAAO,IAAAE,sBAAG,EACR,IAAIC,iCAAc,CAACC,qCAAkB,CAACC,WAAW,EAAE,IAAI,CAACP,UAAU,CAAC,CACpE;IACH;IAEA,OAAO,IAAAQ,qBAAE,EAACN,IAAI,CAAC;EACjB;EAEOO,KAAKA,CAACP,IAAY,EAAgC;IACvD,IAAI,CAACP,OAAO,CAACe,GAAG,CAAC,IAAI,CAACV,UAAU,EAAEE,IAAI,CAAC;IAEvC,OAAO,IAAAM,qBAAE,GAAE;EACb;AACF"}
@@ -1,58 +1,35 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.useAddData = void 0;
29
- var react_1 = require("react");
30
- var useKameleoon_1 = require("./useKameleoon");
31
- var useError_1 = require("./useError");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAddData = useAddData;
7
+ var _react = require("react");
8
+ var _useKameleoon = require("./useKameleoon");
9
+ var _useError = require("./useError");
32
10
  /**
33
11
  * A React Hook that returns `addData` function for adding targeting data to the Kameleoon storage.
34
12
  *
35
13
  * @returns {IAddDataHookResult} an object containing the `addData` function and an optional error object.
36
14
  */
37
15
  function useAddData() {
38
- var client = (0, useKameleoon_1.useKameleoon)().client;
39
- var _a = (0, useError_1.useError)(), error = _a.error, setError = _a.setError;
40
- var addData = (0, react_1.useCallback)(function (visitorCode) {
41
- var data = [];
42
- for (var _i = 1; _i < arguments.length; _i++) {
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);
50
- }
51
- }, [client]);
52
- return {
53
- addData: addData,
54
- error: error,
55
- };
16
+ const {
17
+ client
18
+ } = (0, _useKameleoon.useKameleoon)();
19
+ const {
20
+ error,
21
+ setError
22
+ } = (0, _useError.useError)();
23
+ const addData = (0, _react.useCallback)((visitorCode, ...data) => {
24
+ try {
25
+ client.addData(visitorCode, ...data);
26
+ } catch (unknownError) {
27
+ setError(unknownError);
28
+ }
29
+ }, [client]);
30
+ return {
31
+ addData,
32
+ error
33
+ };
56
34
  }
57
- exports.useAddData = useAddData;
58
35
  //# sourceMappingURL=useAddData.js.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"useAddData.js","names":["_react","require","_useKameleoon","_useError","useAddData","client","useKameleoon","error","setError","useError","addData","useCallback","visitorCode","data","unknownError"],"sources":["../src/useAddData.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { KameleoonDataType } from '@kameleoon/javascript-sdk-core';\nimport { useKameleoon } from './useKameleoon';\nimport { useError } from './useError';\nimport { KameleoonError } from './KameleoonError';\n\nexport interface IAddDataHookResult {\n /**\n * 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.\n *\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length.\n * @param {...KameleoonDataType} data - number of instances of any type of `KameleoonData`, can be added solely in array or as a sequential arguments.\n */\n addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;\n /** An optional error object that may be returned if an error occurs while calling the `addData` function. */\n error: KameleoonError | null;\n}\n\n/**\n * A React Hook that returns `addData` function for adding targeting data to the Kameleoon storage.\n *\n * @returns {IAddDataHookResult} an object containing the `addData` function and an optional error object.\n */\nexport function useAddData(): IAddDataHookResult {\n const { client } = useKameleoon();\n const { error, setError } = useError();\n\n const addData = useCallback(\n (visitorCode: string, ...data: KameleoonDataType[]): void => {\n try {\n client.addData(visitorCode, ...data);\n } catch (unknownError) {\n setError(unknownError);\n }\n },\n [client],\n );\n\n return {\n addData,\n error,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAeA;AACA;AACA;AACA;AACA;AACO,SAASG,UAAUA,CAAA,EAAuB;EAC/C,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EACjC,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAG,IAAAC,kBAAQ,GAAE;EAEtC,MAAMC,OAAO,GAAG,IAAAC,kBAAW,EACzB,CAACC,WAAmB,EAAE,GAAGC,IAAyB,KAAW;IAC3D,IAAI;MACFR,MAAM,CAACK,OAAO,CAACE,WAAW,EAAE,GAAGC,IAAI,CAAC;IACtC,CAAC,CAAC,OAAOC,YAAY,EAAE;MACrBN,QAAQ,CAACM,YAAY,CAAC;IACxB;EACF,CAAC,EACD,CAACT,MAAM,CAAC,CACT;EAED,OAAO;IACLK,OAAO;IACPH;EACF,CAAC;AACH"}
@@ -1,20 +1,22 @@
1
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");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useBrowserVisitorCode = useBrowserVisitorCode;
7
+ var _react = require("react");
8
+ var _browserUtils = require("./kameleoonUtils/browserUtils");
6
9
  /**
7
10
  * A React Hook that returns `getBrowserVisitorCode` function which obtains the Kameleoon visitorCode.
8
11
  *
9
12
  * @returns {IBrowserVisitorCodeHookResult} an object containing the `getBrowserVisitorCode` function and an optional error object.
10
13
  */
11
14
  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
- };
15
+ const getBrowserVisitorCode = (0, _react.useCallback)((domain, defaultVisitorCode) => {
16
+ return _browserUtils.BrowserUtils.getVisitorCode(domain, defaultVisitorCode);
17
+ }, []);
18
+ return {
19
+ getBrowserVisitorCode
20
+ };
18
21
  }
19
- exports.useBrowserVisitorCode = useBrowserVisitorCode;
20
22
  //# sourceMappingURL=useBrowserVisitorCode.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"useBrowserVisitorCode.js","names":["_react","require","_browserUtils","useBrowserVisitorCode","getBrowserVisitorCode","useCallback","domain","defaultVisitorCode","BrowserUtils","getVisitorCode"],"sources":["../src/useBrowserVisitorCode.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { BrowserUtils } from './kameleoonUtils/browserUtils';\n\ninterface IBrowserVisitorCodeHookResult {\n /**\n * Obtains visitor code from browser cookie, if no cookie exists returns new random visitor code (or the specified default value).\n *\n * @param domain - domain to be set to browser cookie along with visitor code.\n * @param defaultVisitorCode - visitor code to be used instead of randomly generated visitor code in case there is no visitor code saved in browser cookie.\n * @returns {string} result visitor code.\n */\n getBrowserVisitorCode: (\n domain: string,\n defaultVisitorCode?: string,\n ) => string;\n}\n\n/**\n * A React Hook that returns `getBrowserVisitorCode` function which obtains the Kameleoon visitorCode.\n *\n * @returns {IBrowserVisitorCodeHookResult} an object containing the `getBrowserVisitorCode` function and an optional error object.\n */\nexport function useBrowserVisitorCode(): IBrowserVisitorCodeHookResult {\n const getBrowserVisitorCode = useCallback(\n (domain: string, defaultVisitorCode?: string): string => {\n return BrowserUtils.getVisitorCode(domain, defaultVisitorCode);\n },\n [],\n );\n\n return {\n getBrowserVisitorCode,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAgBA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CAAA,EAAkC;EACrE,MAAMC,qBAAqB,GAAG,IAAAC,kBAAW,EACvC,CAACC,MAAc,EAAEC,kBAA2B,KAAa;IACvD,OAAOC,0BAAY,CAACC,cAAc,CAACH,MAAM,EAAEC,kBAAkB,CAAC;EAChE,CAAC,EACD,EAAE,CACH;EAED,OAAO;IACLH;EACF,CAAC;AACH"}
@@ -1,29 +1,35 @@
1
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");
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useConfigurationUpdate = useConfigurationUpdate;
7
+ var _react = require("react");
8
+ var _useKameleoon = require("./useKameleoon");
9
+ var _useError = require("./useError");
7
10
  /**
8
11
  * A React Hook that returns `onConfigurationUpdate` function which fires a callback on client configuration update.
9
12
  *
10
13
  * @returns {IConfigurationUpdateHookResult} an object containing the `onConfigurationUpdate` function and an optional error object.
11
14
  */
12
15
  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
- };
16
+ const {
17
+ client
18
+ } = (0, _useKameleoon.useKameleoon)();
19
+ const {
20
+ error,
21
+ setError
22
+ } = (0, _useError.useError)();
23
+ const onConfigurationUpdate = (0, _react.useCallback)(callback => {
24
+ try {
25
+ client.onConfigurationUpdate(callback);
26
+ } catch (unknownError) {
27
+ setError(unknownError);
28
+ }
29
+ }, [client]);
30
+ return {
31
+ onConfigurationUpdate,
32
+ error
33
+ };
27
34
  }
28
- exports.useConfigurationUpdate = useConfigurationUpdate;
29
35
  //# sourceMappingURL=useConfigurationUpdate.js.map
@@ -1 +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"}
1
+ {"version":3,"file":"useConfigurationUpdate.js","names":["_react","require","_useKameleoon","_useError","useConfigurationUpdate","client","useKameleoon","error","setError","useError","onConfigurationUpdate","useCallback","callback","unknownError"],"sources":["../src/useConfigurationUpdate.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useKameleoon } from './useKameleoon';\nimport { useError } from './useError';\nimport { KameleoonError } from './KameleoonError';\n\nexport interface IConfigurationUpdateHookResult {\n /**\n * Fires a callback on client configuration update. Note: this method only works for server sent events of real time update.\n *\n * @param {() => void} callback - callback function with no parameters that will be called upon configuration update.\n */\n onConfigurationUpdate: (callback: () => void) => void;\n /** An optional error object that may be returned if an error occurs while calling the `onConfigurationUpdate` function. */\n error: KameleoonError | null;\n}\n\n/**\n * A React Hook that returns `onConfigurationUpdate` function which fires a callback on client configuration update.\n *\n * @returns {IConfigurationUpdateHookResult} an object containing the `onConfigurationUpdate` function and an optional error object.\n */\nexport function useConfigurationUpdate(): IConfigurationUpdateHookResult {\n const { client } = useKameleoon();\n const { error, setError } = useError();\n\n const onConfigurationUpdate = useCallback(\n (callback: () => void): void => {\n try {\n client.onConfigurationUpdate(callback);\n } catch (unknownError) {\n setError(unknownError);\n }\n },\n [client],\n );\n\n return {\n onConfigurationUpdate,\n error,\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAcA;AACA;AACA;AACA;AACA;AACO,SAASG,sBAAsBA,CAAA,EAAmC;EACvE,MAAM;IAAEC;EAAO,CAAC,GAAG,IAAAC,0BAAY,GAAE;EACjC,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAC,GAAG,IAAAC,kBAAQ,GAAE;EAEtC,MAAMC,qBAAqB,GAAG,IAAAC,kBAAW,EACtCC,QAAoB,IAAW;IAC9B,IAAI;MACFP,MAAM,CAACK,qBAAqB,CAACE,QAAQ,CAAC;IACxC,CAAC,CAAC,OAAOC,YAAY,EAAE;MACrBL,QAAQ,CAACK,YAAY,CAAC;IACxB;EACF,CAAC,EACD,CAACR,MAAM,CAAC,CACT;EAED,OAAO;IACLK,qBAAqB;IACrBH;EACF,CAAC;AACH"}