@kameleoon/javascript-sdk-core 2.4.6 → 2.5.1

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 (190) hide show
  1. package/dist/cacheManager/cacheManager.js +3 -65
  2. package/dist/cacheManager/cacheManager.js.map +1 -1
  3. package/dist/cacheManager/index.js +1 -19
  4. package/dist/cacheManager/index.js.map +1 -1
  5. package/dist/cacheManager/types.js +1 -5
  6. package/dist/campaignConfiguration/campaignConfiguration.d.ts +10 -7
  7. package/dist/campaignConfiguration/campaignConfiguration.js +9 -283
  8. package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -1
  9. package/dist/campaignConfiguration/constants.d.ts +2 -10
  10. package/dist/campaignConfiguration/constants.js +2 -21
  11. package/dist/campaignConfiguration/constants.js.map +1 -1
  12. package/dist/campaignConfiguration/index.js +1 -86
  13. package/dist/campaignConfiguration/index.js.map +1 -1
  14. package/dist/campaignConfiguration/types.d.ts +8 -7
  15. package/dist/campaignConfiguration/types.js +1 -54
  16. package/dist/campaignConfiguration/types.js.map +1 -1
  17. package/dist/clientSettings/clientSettings.d.ts +1 -1
  18. package/dist/clientSettings/clientSettings.js +1 -35
  19. package/dist/clientSettings/clientSettings.js.map +1 -1
  20. package/dist/clientSettings/index.js +1 -19
  21. package/dist/clientSettings/index.js.map +1 -1
  22. package/dist/clientSettings/types.d.ts +1 -1
  23. package/dist/clientSettings/types.js +1 -5
  24. package/dist/clientSettings/types.js.map +1 -1
  25. package/dist/constants.d.ts +13 -4
  26. package/dist/constants.js +2 -36
  27. package/dist/constants.js.map +1 -1
  28. package/dist/eventSource/constants.js +1 -8
  29. package/dist/eventSource/constants.js.map +1 -1
  30. package/dist/eventSource/externalEventSource.js +1 -33
  31. package/dist/eventSource/externalEventSource.js.map +1 -1
  32. package/dist/eventSource/index.js +1 -50
  33. package/dist/eventSource/index.js.map +1 -1
  34. package/dist/eventSource/types.js +1 -5
  35. package/dist/hasher/hasher.js +6 -44
  36. package/dist/hasher/hasher.js.map +1 -1
  37. package/dist/hasher/index.js +1 -12
  38. package/dist/hasher/index.js.map +1 -1
  39. package/dist/hasher/types.d.ts +1 -1
  40. package/dist/hasher/types.js +1 -5
  41. package/dist/hasher/types.js.map +1 -1
  42. package/dist/index.d.ts +3 -3
  43. package/dist/index.js +1 -310
  44. package/dist/index.js.map +1 -1
  45. package/dist/kameleoonClient.d.ts +16 -4
  46. package/dist/kameleoonClient.js +10 -384
  47. package/dist/kameleoonClient.js.map +1 -1
  48. package/dist/kameleoonData/browser.d.ts +8 -3
  49. package/dist/kameleoonData/browser.js +9 -40
  50. package/dist/kameleoonData/browser.js.map +1 -1
  51. package/dist/kameleoonData/conversion.d.ts +2 -2
  52. package/dist/kameleoonData/conversion.js +5 -50
  53. package/dist/kameleoonData/conversion.js.map +1 -1
  54. package/dist/kameleoonData/customData.d.ts +2 -2
  55. package/dist/kameleoonData/customData.js +5 -55
  56. package/dist/kameleoonData/customData.js.map +1 -1
  57. package/dist/kameleoonData/device.d.ts +2 -2
  58. package/dist/kameleoonData/device.js +5 -40
  59. package/dist/kameleoonData/device.js.map +1 -1
  60. package/dist/kameleoonData/index.d.ts +1 -1
  61. package/dist/kameleoonData/index.js +1 -102
  62. package/dist/kameleoonData/index.js.map +1 -1
  63. package/dist/kameleoonData/pageView.d.ts +2 -2
  64. package/dist/kameleoonData/pageView.js +5 -56
  65. package/dist/kameleoonData/pageView.js.map +1 -1
  66. package/dist/kameleoonData/types.d.ts +44 -27
  67. package/dist/kameleoonData/types.js +6 -42
  68. package/dist/kameleoonData/types.js.map +1 -1
  69. package/dist/kameleoonData/userAgent.d.ts +2 -2
  70. package/dist/kameleoonData/userAgent.js +4 -37
  71. package/dist/kameleoonData/userAgent.js.map +1 -1
  72. package/dist/kameleoonError/constants.d.ts +4 -2
  73. package/dist/kameleoonError/constants.js +1 -31
  74. package/dist/kameleoonError/constants.js.map +1 -1
  75. package/dist/kameleoonError/helpers.js +1 -9
  76. package/dist/kameleoonError/helpers.js.map +1 -1
  77. package/dist/kameleoonError/index.js +1 -26
  78. package/dist/kameleoonError/index.js.map +1 -1
  79. package/dist/kameleoonError/kameleoonError.d.ts +3 -3
  80. package/dist/kameleoonError/kameleoonError.js +2 -75
  81. package/dist/kameleoonError/kameleoonError.js.map +1 -1
  82. package/dist/kameleoonError/types.d.ts +2 -0
  83. package/dist/kameleoonError/types.js +1 -31
  84. package/dist/kameleoonError/types.js.map +1 -1
  85. package/dist/kameleoonUtils.js +2 -44
  86. package/dist/kameleoonUtils.js.map +1 -1
  87. package/dist/requester/constants.js +1 -73
  88. package/dist/requester/constants.js.map +1 -1
  89. package/dist/requester/index.js +1 -80
  90. package/dist/requester/index.js.map +1 -1
  91. package/dist/requester/requester.d.ts +4 -5
  92. package/dist/requester/requester.js +1 -106
  93. package/dist/requester/requester.js.map +1 -1
  94. package/dist/requester/types.d.ts +8 -7
  95. package/dist/requester/types.js +1 -16
  96. package/dist/requester/types.js.map +1 -1
  97. package/dist/storage/constants.js +2 -15
  98. package/dist/storage/constants.js.map +1 -1
  99. package/dist/storage/externalStorage.d.ts +1 -1
  100. package/dist/storage/externalStorage.js +1 -40
  101. package/dist/storage/externalStorage.js.map +1 -1
  102. package/dist/storage/index.js +1 -56
  103. package/dist/storage/index.js.map +1 -1
  104. package/dist/storage/types.d.ts +4 -4
  105. package/dist/storage/types.js +1 -5
  106. package/dist/storage/types.js.map +1 -1
  107. package/dist/targeting/conditions/browserCondition.d.ts +13 -0
  108. package/dist/targeting/conditions/browserCondition.js +2 -0
  109. package/dist/targeting/conditions/browserCondition.js.map +1 -0
  110. package/dist/targeting/conditions/conditionFactory.d.ts +1 -1
  111. package/dist/targeting/conditions/conditionFactory.js +1 -30
  112. package/dist/targeting/conditions/conditionFactory.js.map +1 -1
  113. package/dist/targeting/conditions/conversionCondition.d.ts +10 -0
  114. package/dist/targeting/conditions/conversionCondition.js +4 -0
  115. package/dist/targeting/conditions/conversionCondition.js.map +1 -0
  116. package/dist/targeting/conditions/customDataCondition.d.ts +5 -7
  117. package/dist/targeting/conditions/customDataCondition.js +7 -114
  118. package/dist/targeting/conditions/customDataCondition.js.map +1 -1
  119. package/dist/targeting/conditions/deviceCondition.d.ts +9 -0
  120. package/dist/targeting/conditions/deviceCondition.js +2 -0
  121. package/dist/targeting/conditions/deviceCondition.js.map +1 -0
  122. package/dist/targeting/conditions/exclusiveExperimentCondition.d.ts +3 -5
  123. package/dist/targeting/conditions/exclusiveExperimentCondition.js +1 -32
  124. package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -1
  125. package/dist/targeting/conditions/index.d.ts +7 -0
  126. package/dist/targeting/conditions/index.js +1 -46
  127. package/dist/targeting/conditions/index.js.map +1 -1
  128. package/dist/targeting/conditions/pageTitleCondition.d.ts +11 -0
  129. package/dist/targeting/conditions/pageTitleCondition.js +2 -0
  130. package/dist/targeting/conditions/pageTitleCondition.js.map +1 -0
  131. package/dist/targeting/conditions/pageUrlCondition.d.ts +11 -0
  132. package/dist/targeting/conditions/pageUrlCondition.js +2 -0
  133. package/dist/targeting/conditions/pageUrlCondition.js.map +1 -0
  134. package/dist/targeting/conditions/sdkLanguageCondition.d.ts +15 -0
  135. package/dist/targeting/conditions/sdkLanguageCondition.js +2 -0
  136. package/dist/targeting/conditions/sdkLanguageCondition.js.map +1 -0
  137. package/dist/targeting/conditions/targetExperimentCondition.d.ts +3 -4
  138. package/dist/targeting/conditions/targetExperimentCondition.js +1 -63
  139. package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -1
  140. package/dist/targeting/conditions/types.d.ts +25 -6
  141. package/dist/targeting/conditions/types.js +1 -5
  142. package/dist/targeting/conditions/types.js.map +1 -1
  143. package/dist/targeting/conditions/visitorCodeCondition.d.ts +11 -0
  144. package/dist/targeting/conditions/visitorCodeCondition.js +2 -0
  145. package/dist/targeting/conditions/visitorCodeCondition.js.map +1 -0
  146. package/dist/targeting/index.d.ts +2 -2
  147. package/dist/targeting/index.js +1 -80
  148. package/dist/targeting/index.js.map +1 -1
  149. package/dist/targeting/targetingNode.d.ts +3 -1
  150. package/dist/targeting/targetingNode.js +1 -47
  151. package/dist/targeting/targetingNode.js.map +1 -1
  152. package/dist/targeting/targetingTree.d.ts +3 -1
  153. package/dist/targeting/targetingTree.js +34 -135
  154. package/dist/targeting/targetingTree.js.map +1 -1
  155. package/dist/targeting/types.d.ts +24 -9
  156. package/dist/targeting/types.js +1 -100
  157. package/dist/targeting/types.js.map +1 -1
  158. package/dist/types.d.ts +9 -4
  159. package/dist/types.js +12 -41
  160. package/dist/types.js.map +1 -1
  161. package/dist/utilities/constants.d.ts +1 -0
  162. package/dist/utilities/constants.js +1 -8
  163. package/dist/utilities/constants.js.map +1 -1
  164. package/dist/utilities/index.d.ts +1 -0
  165. package/dist/utilities/index.js +1 -12
  166. package/dist/utilities/index.js.map +1 -1
  167. package/dist/utilities/types.d.ts +14 -7
  168. package/dist/utilities/types.js +1 -5
  169. package/dist/utilities/types.js.map +1 -1
  170. package/dist/utilities/utilities.d.ts +12 -8
  171. package/dist/utilities/utilities.js +1 -216
  172. package/dist/utilities/utilities.js.map +1 -1
  173. package/dist/variationConfiguration/index.js +1 -25
  174. package/dist/variationConfiguration/index.js.map +1 -1
  175. package/dist/variationConfiguration/types.d.ts +5 -3
  176. package/dist/variationConfiguration/types.js +1 -5
  177. package/dist/variationConfiguration/types.js.map +1 -1
  178. package/dist/variationConfiguration/variation.d.ts +1 -1
  179. package/dist/variationConfiguration/variation.js +6 -44
  180. package/dist/variationConfiguration/variation.js.map +1 -1
  181. package/dist/variationConfiguration/variationConfiguration.d.ts +4 -4
  182. package/dist/variationConfiguration/variationConfiguration.js +65 -290
  183. package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
  184. package/package.json +1 -1
  185. package/dist/kameleoonData/constants.d.ts +0 -1
  186. package/dist/kameleoonData/constants.js +0 -9
  187. package/dist/kameleoonData/constants.js.map +0 -1
  188. package/dist/kameleoonData/nonce.d.ts +0 -5
  189. package/dist/kameleoonData/nonce.js +0 -32
  190. package/dist/kameleoonData/nonce.js.map +0 -1
@@ -1,41 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ExternalStorage = void 0;
7
- var _tsRes = require("ts-res");
8
- var _kameleoonError = require("../kameleoonError");
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 ExternalStorage {
13
- constructor(externalStorage) {
14
- _defineProperty(this, "key", void 0);
15
- _defineProperty(this, "storage", void 0);
16
- this.key = externalStorage.key;
17
- this.storage = externalStorage;
18
- }
19
- read() {
20
- const result = this.storage.read();
21
- if (!result.ok) {
22
- return result;
23
- }
24
- return this.parse(result.data);
25
- }
26
- write(data) {
27
- this.storage.write(JSON.stringify(data));
28
- return (0, _tsRes.Ok)();
29
- }
30
- parse(data) {
31
- let result;
32
- try {
33
- result = JSON.parse(data);
34
- } catch (err) {
35
- throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageParse, err, this.key);
36
- }
37
- return (0, _tsRes.Ok)(result);
38
- }
39
- }
40
- exports.ExternalStorage = ExternalStorage;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExternalStorage=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var ExternalStorage=/*#__PURE__*/function(){function a(b){_classCallCheck(this,a),_defineProperty(this,"key",void 0),_defineProperty(this,"storage",void 0),this.key=b.key,this.storage=b}return _createClass(a,[{key:"read",value:function read(){var a=this.storage.read();return a.ok?this.parse(a.data):a}},{key:"write",value:function write(a){return this.storage.write(JSON.stringify(a)),(0,_tsRes.Ok)()}},{key:"parse",value:function parse(a){var b;try{b=JSON.parse(a)}catch(a){throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageParse,a,this.key)}return(0,_tsRes.Ok)(b)}}]),a}();exports.ExternalStorage=ExternalStorage;
41
2
  //# sourceMappingURL=externalStorage.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"externalStorage.js","names":["_tsRes","require","_kameleoonError","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","ExternalStorage","constructor","externalStorage","storage","read","result","ok","parse","data","write","JSON","stringify","Ok","err","KameleoonError","KameleoonException","StorageParse","exports"],"sources":["../../src/storage/externalStorage.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { IExternalStorage, IStorage, StorageDataType } from './types';\nimport { KameleoonError, KameleoonException } from '../kameleoonError';\nimport { KameleoonStorageKey } from './constants';\n\nexport class ExternalStorage<T extends StorageDataType> implements IStorage<T> {\n private key: KameleoonStorageKey;\n private storage: IExternalStorage;\n\n constructor(externalStorage: IExternalStorage) {\n this.key = externalStorage.key;\n this.storage = externalStorage;\n }\n\n public read(): Result<T, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n return this.parse(result.data);\n }\n\n public write(data: T): Result<void, KameleoonError> {\n this.storage.write(JSON.stringify(data));\n\n return Ok();\n }\n\n private parse(data: string): Result<T, KameleoonError> {\n let result: T;\n\n try {\n result = JSON.parse(data);\n } catch (err) {\n throw new KameleoonError(KameleoonException.StorageParse, err, this.key);\n }\n\n return Ok(result);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AAAuE,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;AAGhE,MAAMU,eAAe,CAAmD;EAI7EC,WAAWA,CAACC,eAAiC,EAAE;IAAAzB,eAAA;IAAAA,eAAA;IAC7C,IAAI,CAACE,GAAG,GAAGuB,eAAe,CAACvB,GAAG;IAC9B,IAAI,CAACwB,OAAO,GAAGD,eAAe;EAChC;EAEOE,IAAIA,CAAA,EAA8B;IACvC,MAAMC,MAAM,GAAG,IAAI,CAACF,OAAO,CAACC,IAAI,EAAE;IAElC,IAAI,CAACC,MAAM,CAACC,EAAE,EAAE;MACd,OAAOD,MAAM;IACf;IAEA,OAAO,IAAI,CAACE,KAAK,CAACF,MAAM,CAACG,IAAI,CAAC;EAChC;EAEOC,KAAKA,CAACD,IAAO,EAAgC;IAClD,IAAI,CAACL,OAAO,CAACM,KAAK,CAACC,IAAI,CAACC,SAAS,CAACH,IAAI,CAAC,CAAC;IAExC,OAAO,IAAAI,SAAE,GAAE;EACb;EAEQL,KAAKA,CAACC,IAAY,EAA6B;IACrD,IAAIH,MAAS;IAEb,IAAI;MACFA,MAAM,GAAGK,IAAI,CAACH,KAAK,CAACC,IAAI,CAAC;IAC3B,CAAC,CAAC,OAAOK,GAAG,EAAE;MACZ,MAAM,IAAIC,8BAAc,CAACC,kCAAkB,CAACC,YAAY,EAAEH,GAAG,EAAE,IAAI,CAAClC,GAAG,CAAC;IAC1E;IAEA,OAAO,IAAAiC,SAAE,EAACP,MAAM,CAAC;EACnB;AACF;AAACY,OAAA,CAAAjB,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"file":"externalStorage.js","names":["ExternalStorage","a","externalStorage","_classCallCheck","_defineProperty","key","storage","_createClass","value","read","result","ok","parse","data","write","JSON","stringify","Ok","err","KameleoonError","KameleoonException","StorageParse","exports"],"sources":["../../src/storage/externalStorage.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { IExternalStorage, IStorage, StorageDataType } from './types';\nimport { KameleoonStorageKey } from './constants';\n\nexport class ExternalStorage<T extends StorageDataType> implements IStorage<T> {\n private key: KameleoonStorageKey;\n private storage: IExternalStorage;\n\n constructor(externalStorage: IExternalStorage) {\n this.key = externalStorage.key;\n this.storage = externalStorage;\n }\n\n public read(): Result<T, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n return this.parse(result.data);\n }\n\n public write(data: T): Result<void, KameleoonError> {\n this.storage.write(JSON.stringify(data));\n\n return Ok();\n }\n\n private parse(data: string): Result<T, KameleoonError> {\n let result: T;\n\n try {\n result = JSON.parse(data);\n } catch (err) {\n throw new KameleoonError(KameleoonException.StorageParse, err, this.key);\n }\n\n return Ok(result);\n }\n}\n"],"mappings":"y5CAKa,CAAAA,eAAe,yBAI1B,SAAAC,EAAYC,CAAiC,CAAE,CAAAC,eAAA,MAAAF,CAAA,EAAAG,eAAA,oBAAAA,eAAA,wBAC7C,IAAI,CAACC,GAAG,CAAGH,CAAe,CAACG,GAAG,CAC9B,IAAI,CAACC,OAAO,CAAGJ,CACjB,CAAC,OAAAK,YAAA,CAAAN,CAAA,GAAAI,GAAA,QAAAG,KAAA,CAED,SAAAC,KAAA,CAAyC,CACvC,GAAM,CAAAC,CAAM,CAAG,IAAI,CAACJ,OAAO,CAACG,IAAI,EAAE,CAAC,MAE9B,CAAAC,CAAM,CAACC,EAAE,CAIP,IAAI,CAACC,KAAK,CAACF,CAAM,CAACG,IAAI,CAAC,CAHrBH,CAIX,CAAC,GAAAL,GAAA,SAAAG,KAAA,CAED,SAAAM,MAAaD,CAAO,CAAgC,CAGlD,MAFA,KAAI,CAACP,OAAO,CAACQ,KAAK,CAACC,IAAI,CAACC,SAAS,CAACH,CAAI,CAAC,CAAC,CAEjC,GAAAI,SAAE,GACX,CAAC,GAAAZ,GAAA,SAAAG,KAAA,CAED,SAAAI,MAAcC,CAAY,CAA6B,CACrD,GAAI,CAAAH,CAAS,CAEb,GAAI,CACFA,CAAM,CAAGK,IAAI,CAACH,KAAK,CAACC,CAAI,CAC1B,CAAE,MAAOK,CAAG,CAAE,CACZ,KAAM,IAAI,CAAAC,8BAAc,CAACC,kCAAkB,CAACC,YAAY,CAAEH,CAAG,CAAE,IAAI,CAACb,GAAG,CACzE,CAEA,MAAO,GAAAY,SAAE,EAACP,CAAM,CAClB,CAAC,IAAAT,CAAA,IAAAqB,OAAA,CAAAtB,eAAA,CAAAA,eAAA"}
@@ -1,57 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "ClientDataType", {
7
- enumerable: true,
8
- get: function () {
9
- return _types.ClientDataType;
10
- }
11
- });
12
- Object.defineProperty(exports, "ExperimentVariationsType", {
13
- enumerable: true,
14
- get: function () {
15
- return _types.ExperimentVariationsType;
16
- }
17
- });
18
- Object.defineProperty(exports, "ExternalStorage", {
19
- enumerable: true,
20
- get: function () {
21
- return _externalStorage.ExternalStorage;
22
- }
23
- });
24
- Object.defineProperty(exports, "IExternalStorage", {
25
- enumerable: true,
26
- get: function () {
27
- return _types.IExternalStorage;
28
- }
29
- });
30
- Object.defineProperty(exports, "IExternalStorageConstructor", {
31
- enumerable: true,
32
- get: function () {
33
- return _types.IExternalStorageConstructor;
34
- }
35
- });
36
- Object.defineProperty(exports, "IStorage", {
37
- enumerable: true,
38
- get: function () {
39
- return _types.IStorage;
40
- }
41
- });
42
- Object.defineProperty(exports, "KameleoonStorageKey", {
43
- enumerable: true,
44
- get: function () {
45
- return _constants.KameleoonStorageKey;
46
- }
47
- });
48
- Object.defineProperty(exports, "VariationDataType", {
49
- enumerable: true,
50
- get: function () {
51
- return _types.VariationDataType;
52
- }
53
- });
54
- var _constants = require("./constants");
55
- var _externalStorage = require("./externalStorage");
56
- var _types = require("./types");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ClientDataType",{enumerable:!0,get:function get(){return _types.ClientDataType}}),Object.defineProperty(exports,"ExperimentVariationsType",{enumerable:!0,get:function get(){return _types.ExperimentVariationsType}}),Object.defineProperty(exports,"ExternalStorage",{enumerable:!0,get:function get(){return _externalStorage.ExternalStorage}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function get(){return _types.IExternalStorage}}),Object.defineProperty(exports,"IExternalStorageConstructor",{enumerable:!0,get:function get(){return _types.IExternalStorageConstructor}}),Object.defineProperty(exports,"IStorage",{enumerable:!0,get:function get(){return _types.IStorage}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function get(){return _constants.KameleoonStorageKey}}),Object.defineProperty(exports,"VariationDataType",{enumerable:!0,get:function get(){return _types.VariationDataType}});var _constants=require("./constants"),_externalStorage=require("./externalStorage"),_types=require("./types");
57
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_constants","require","_externalStorage","_types"],"sources":["../../src/storage/index.ts"],"sourcesContent":["export { KameleoonStorageKey } from './constants';\nexport { ExternalStorage } from './externalStorage';\nexport {\n IStorage,\n ClientDataType,\n IExternalStorage,\n VariationDataType,\n ExperimentVariationsType,\n IExternalStorageConstructor,\n} from './types';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/storage/index.ts"],"sourcesContent":["export { KameleoonStorageKey } from './constants';\nexport { ExternalStorage } from './externalStorage';\nexport {\n IStorage,\n ClientDataType,\n IExternalStorage,\n VariationDataType,\n ExperimentVariationsType,\n IExternalStorageConstructor,\n} from './types';\n"],"mappings":""}
@@ -1,9 +1,9 @@
1
1
  import { Result } from 'ts-res';
2
- import { ConfigurationDataType } from '../campaignConfiguration';
3
- import { KameleoonError } from '../kameleoonError';
4
- import { TargetingDataType } from '../targeting';
5
- import { VariationType } from '../variationConfiguration';
2
+ import { ConfigurationDataType } from 'src/campaignConfiguration';
3
+ import { KameleoonError } from 'src/kameleoonError';
4
+ import { VariationType } from 'src/variationConfiguration';
6
5
  import { KameleoonStorageKey } from './constants';
6
+ import { TargetingDataType } from 'src/targeting';
7
7
  export type ClientDataType = {
8
8
  kameleoonTargetingData: TargetingDataType;
9
9
  kameleoonConfiguration: ConfigurationDataType;
@@ -1,6 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});
6
2
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/storage/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { ConfigurationDataType } from '../campaignConfiguration';\nimport { KameleoonError } from '../kameleoonError';\nimport { TargetingDataType } from '../targeting';\nimport { VariationType } from '../variationConfiguration';\nimport { KameleoonStorageKey } from './constants';\n\nexport type ClientDataType = {\n kameleoonTargetingData: TargetingDataType;\n kameleoonConfiguration: ConfigurationDataType;\n lastUpdate: string;\n};\n\nexport type ExperimentVariationsType = {\n [experimentId: string]: VariationType;\n};\n\nexport type VariationDataType = {\n [visitorCode: string]: ExperimentVariationsType;\n};\n\nexport type StorageDataType = ClientDataType | VariationDataType;\n\nexport interface IStorage<T> {\n read: () => Result<T, KameleoonError>;\n write: (data: T) => Result<void, KameleoonError>;\n}\n\n/**\n * @interface an interface of External Constructor for Storage which must be implemented by the wrapper constructor to initialize new `IExternalStorage` in order to be able to pass necessary initialization parameters\n * */\nexport interface IExternalStorageConstructor {\n /**\n * @method initialize - creates and instance of `IExternalStorage` and returns it\n * @param {KameleoonStorageKey} key - an enum variant containing keys for Kameleoon SDK related data stored on storage\n * @returns {IExternalEventSource} an initialized instance of `IExternalEventSource`\n * */\n initialize: (key: KameleoonStorageKey) => IExternalStorage;\n}\n\n/**\n * @interface an interface of External Storage which must be implemented to be used as external storage for initialized JS SDK Core.\n * Note: Only React Native SDK supports external storage for the moment\n * */\nexport interface IExternalStorage {\n /**\n * @property key - an Enum `KameleoonStorageKey` variant containing a key for Kameleoon SDK related data stored on storage\n * */\n readonly key: KameleoonStorageKey;\n /**\n * @method read - reads data from the storage\n * @returns {Result<string, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains `data` field with a type `string`, if not contains `error` field with a type of `KameleoonError`\n * */\n read: () => Result<string, KameleoonError>;\n /**\n * @method write - writes data to storage\n * @param {string} data - string representation of data\n * @returns {Result<void, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains an empty `data`, if not contains `error` field with a type of `KameleoonError`\n * */\n write: (data: string) => Result<void, KameleoonError>;\n}\n"],"mappings":""}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/storage/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { ConfigurationDataType } from 'src/campaignConfiguration';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { VariationType } from 'src/variationConfiguration';\nimport { KameleoonStorageKey } from './constants';\nimport { TargetingDataType } from 'src/targeting';\n\nexport type ClientDataType = {\n kameleoonTargetingData: TargetingDataType;\n kameleoonConfiguration: ConfigurationDataType;\n lastUpdate: string;\n};\n\nexport type ExperimentVariationsType = {\n [experimentId: string]: VariationType;\n};\n\nexport type VariationDataType = {\n [visitorCode: string]: ExperimentVariationsType;\n};\n\nexport type StorageDataType = ClientDataType | VariationDataType;\n\nexport interface IStorage<T> {\n read: () => Result<T, KameleoonError>;\n write: (data: T) => Result<void, KameleoonError>;\n}\n\n/**\n * @interface an interface of External Constructor for Storage which must be implemented by the wrapper constructor to initialize new `IExternalStorage` in order to be able to pass necessary initialization parameters\n * */\nexport interface IExternalStorageConstructor {\n /**\n * @method initialize - creates and instance of `IExternalStorage` and returns it\n * @param {KameleoonStorageKey} key - an enum variant containing keys for Kameleoon SDK related data stored on storage\n * @returns {IExternalEventSource} an initialized instance of `IExternalEventSource`\n * */\n initialize: (key: KameleoonStorageKey) => IExternalStorage;\n}\n\n/**\n * @interface an interface of External Storage which must be implemented to be used as external storage for initialized JS SDK Core.\n * Note: Only React Native SDK supports external storage for the moment\n * */\nexport interface IExternalStorage {\n /**\n * @property key - an Enum `KameleoonStorageKey` variant containing a key for Kameleoon SDK related data stored on storage\n * */\n readonly key: KameleoonStorageKey;\n /**\n * @method read - reads data from the storage\n * @returns {Result<string, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains `data` field with a type `string`, if not contains `error` field with a type of `KameleoonError`\n * */\n read: () => Result<string, KameleoonError>;\n /**\n * @method write - writes data to storage\n * @param {string} data - string representation of data\n * @returns {Result<void, KameleoonError>} result with an `ok` boolean field indicated success or error. If result is ok contains an empty `data`, if not contains `error` field with a type of `KameleoonError`\n * */\n write: (data: string) => Result<void, KameleoonError>;\n}\n"],"mappings":""}
@@ -0,0 +1,13 @@
1
+ import { Result } from 'ts-res';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
+ import { EvaluationDataType } from 'src/targeting/types';
4
+ import { ConditionDataType, ICondition } from './types';
5
+ export declare class BrowserCondition implements ICondition {
6
+ private browser?;
7
+ private version?;
8
+ private versionMatchType?;
9
+ private error?;
10
+ constructor({ browser, version, versionMatchType }: ConditionDataType);
11
+ evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
12
+ private checkCondition;
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BrowserCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var BrowserCondition=/*#__PURE__*/function(){function a(b){var c=b.browser,d=b.version,e=b.versionMatchType;_classCallCheck(this,a),_defineProperty(this,"browser",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"versionMatchType",void 0),_defineProperty(this,"error",void 0),this.browser=c,this.version=d,this.versionMatchType=e}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.targetingData,c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Browser];if(c){var d=this.checkCondition(c);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(d)}return(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){var b=a.browser,c=a.version;if("string"!=typeof this.browser)return!1;if("string"!=typeof this.version)return b===this.browser;if(!this.versionMatchType||"number"!=typeof c)return!1;var d=parseFloat(this.version);switch(isNaN(d)&&(this.error=new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VersionParse,this.version)),this.versionMatchType){case _types.VersionMatchType.EQUAL:return b===this.browser&&c===d;case _types.VersionMatchType.GREATER:return b===this.browser&&c>d;case _types.VersionMatchType.LOWER:return b===this.browser&&c<d;default:(0,_kameleoonError.exhaustCheck)(this.versionMatchType);}}}]),a}();exports.BrowserCondition=BrowserCondition;
2
+ //# sourceMappingURL=browserCondition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browserCondition.js","names":["BrowserCondition","a","b","browser","version","versionMatchType","_classCallCheck","_defineProperty","_createClass","key","value","evaluate","targetingData","browserData","KameleoonData","Browser","result","checkCondition","error","Err","Ok","parsedVersion","parseFloat","isNaN","KameleoonError","KameleoonException","VersionParse","VersionMatchType","EQUAL","GREATER","LOWER","exhaustCheck","exports"],"sources":["../../../src/targeting/conditions/browserCondition.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonData, BrowserType, BrowserDataType } from 'src/kameleoonData';\nimport {\n exhaustCheck,\n KameleoonError,\n KameleoonException,\n} from 'src/kameleoonError';\nimport { EvaluationDataType, VersionMatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class BrowserCondition implements ICondition {\n private browser?: BrowserType | null;\n private version?: string | null;\n private versionMatchType?: VersionMatchType | null;\n private error?: KameleoonError;\n\n constructor({ browser, version, versionMatchType }: ConditionDataType) {\n this.browser = browser;\n this.version = version;\n this.versionMatchType = versionMatchType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const browserData = targetingData?.[KameleoonData.Browser];\n\n if (browserData) {\n const result = this.checkCondition(browserData);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n return Ok(false);\n }\n\n private checkCondition(browserData: BrowserDataType): boolean {\n const { browser, version } = browserData;\n\n if (typeof this.browser !== 'string') {\n return false;\n }\n\n if (typeof this.version !== 'string') {\n return browser === this.browser;\n }\n\n if (!this.versionMatchType || typeof version !== 'number') {\n return false;\n }\n\n const parsedVersion = parseFloat(this.version);\n\n if (isNaN(parsedVersion)) {\n this.error = new KameleoonError(\n KameleoonException.VersionParse,\n this.version,\n );\n }\n\n switch (this.versionMatchType) {\n case VersionMatchType.EQUAL:\n return browser === this.browser && version === parsedVersion;\n case VersionMatchType.GREATER:\n return browser === this.browser && version > parsedVersion;\n case VersionMatchType.LOWER:\n return browser === this.browser && version < parsedVersion;\n default:\n exhaustCheck(this.versionMatchType);\n }\n }\n}\n"],"mappings":"s+CAUa,CAAAA,gBAAgB,yBAM3B,SAAAC,EAAAC,CAAA,CAAuE,IAAzD,CAAAC,CAAO,CAAAD,CAAA,CAAPC,OAAO,CAAEC,CAAO,CAAAF,CAAA,CAAPE,OAAO,CAAEC,CAAgB,CAAAH,CAAA,CAAhBG,gBAAgB,CAAAC,eAAA,MAAAL,CAAA,EAAAM,eAAA,wBAAAA,eAAA,wBAAAA,eAAA,iCAAAA,eAAA,sBAC9C,IAAI,CAACJ,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,gBAAgB,CAAGA,CAC1B,CAAC,OAAAG,YAAA,CAAAP,CAAA,GAAAQ,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAV,CAAA,CAEwD,IADtD,CAAAW,CAAa,CAAAX,CAAA,CAAbW,aAAa,CAEPC,CAAW,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,OAAO,CAAC,CAE1D,GAAIF,CAAW,CAAE,CACf,GAAM,CAAAG,CAAM,CAAG,IAAI,CAACC,cAAc,CAACJ,CAAW,CAAC,CAAC,MAE5C,KAAI,CAACK,KAAK,CACL,GAAAC,UAAG,EAAC,IAAI,CAACD,KAAK,CAAC,CAGjB,GAAAE,SAAE,EAACJ,CAAM,CAClB,CAEA,MAAO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leoonError } from '../../kameleoonError';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
3
  import { ConditionDataType, ConditionType } from './types';
4
4
  export declare class ConditionFactory {
5
5
  static createCondition(data: ConditionDataType): Result<ConditionType, KameleoonError>;
@@ -1,31 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ConditionFactory = void 0;
7
- var _tsRes = require("ts-res");
8
- var _kameleoonError = require("../../kameleoonError");
9
- var _types = require("../types");
10
- var _customDataCondition = require("./customDataCondition");
11
- var _exclusiveExperimentCondition = require("./exclusiveExperimentCondition");
12
- var _targetExperimentCondition = require("./targetExperimentCondition");
13
- class ConditionFactory {
14
- static createCondition(data) {
15
- const {
16
- targetingType
17
- } = data;
18
- switch (targetingType) {
19
- case _types.TargetingType.CUSTOM_DATUM:
20
- return (0, _tsRes.Ok)(new _customDataCondition.CustomDataCondition(data));
21
- case _types.TargetingType.EXCLUSIVE_EXPERIMENT:
22
- return (0, _tsRes.Ok)(new _exclusiveExperimentCondition.ExclusiveExperimentCondition(data));
23
- case _types.TargetingType.TARGET_EXPERIMENT:
24
- return (0, _tsRes.Ok)(new _targetExperimentCondition.TargetExperimentCondition(data));
25
- default:
26
- return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.TargetingCondition, targetingType));
27
- }
28
- }
29
- }
30
- exports.ConditionFactory = ConditionFactory;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionFactory=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_browserCondition=require("./browserCondition"),_conversionCondition=require("./conversionCondition"),_customDataCondition=require("./customDataCondition"),_deviceCondition=require("./deviceCondition"),_exclusiveExperimentCondition=require("./exclusiveExperimentCondition"),_pageTitleCondition=require("./pageTitleCondition"),_pageUrlCondition=require("./pageUrlCondition"),_sdkLanguageCondition=require("./sdkLanguageCondition"),_targetExperimentCondition=require("./targetExperimentCondition"),_visitorCodeCondition=require("./visitorCodeCondition");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var ConditionFactory=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}return _createClass(a,null,[{key:"createCondition",value:function createCondition(a){var b=a.targetingType;return b===_types.TargetingType.CUSTOM_DATUM?(0,_tsRes.Ok)(new _customDataCondition.CustomDataCondition(a)):b===_types.TargetingType.EXCLUSIVE_EXPERIMENT?(0,_tsRes.Ok)(new _exclusiveExperimentCondition.ExclusiveExperimentCondition):b===_types.TargetingType.TARGET_EXPERIMENT?(0,_tsRes.Ok)(new _targetExperimentCondition.TargetExperimentCondition(a)):b===_types.TargetingType.DEVICE_TYPE?(0,_tsRes.Ok)(new _deviceCondition.DeviceCondition(a)):b===_types.TargetingType.BROWSER?(0,_tsRes.Ok)(new _browserCondition.BrowserCondition(a)):b===_types.TargetingType.PAGE_URL?(0,_tsRes.Ok)(new _pageUrlCondition.PageUrlCondition(a)):b===_types.TargetingType.PAGE_TITLE?(0,_tsRes.Ok)(new _pageTitleCondition.PageTitleCondition(a)):b===_types.TargetingType.CONVERSIONS?(0,_tsRes.Ok)(new _conversionCondition.ConversionCondition(a)):b===_types.TargetingType.VISITOR_CODE?(0,_tsRes.Ok)(new _visitorCodeCondition.VisitorCodeCondition(a)):b===_types.TargetingType.SDK_LANGUAGE?(0,_tsRes.Ok)(new _sdkLanguageCondition.SdkLanguageCondition(a)):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.TargetingCondition,b))}}]),a}();exports.ConditionFactory=ConditionFactory;
31
2
  //# sourceMappingURL=conditionFactory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conditionFactory.js","names":["_tsRes","require","_kameleoonError","_types","_customDataCondition","_exclusiveExperimentCondition","_targetExperimentCondition","ConditionFactory","createCondition","data","targetingType","TargetingType","CUSTOM_DATUM","Ok","CustomDataCondition","EXCLUSIVE_EXPERIMENT","ExclusiveExperimentCondition","TARGET_EXPERIMENT","TargetExperimentCondition","Err","KameleoonError","KameleoonException","TargetingCondition","exports"],"sources":["../../../src/targeting/conditions/conditionFactory.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonError, KameleoonException } from '../../kameleoonError';\nimport { TargetingType } from '../types';\nimport { CustomDataCondition } from './customDataCondition';\nimport { ExclusiveExperimentCondition } from './exclusiveExperimentCondition';\nimport { TargetExperimentCondition } from './targetExperimentCondition';\nimport { ConditionDataType, ConditionType } from './types';\n\nexport class ConditionFactory {\n static createCondition(\n data: ConditionDataType,\n ): Result<ConditionType, KameleoonError> {\n const { targetingType } = data;\n\n switch (targetingType) {\n case TargetingType.CUSTOM_DATUM:\n return Ok(new CustomDataCondition(data));\n case TargetingType.EXCLUSIVE_EXPERIMENT:\n return Ok(new ExclusiveExperimentCondition(data));\n case TargetingType.TARGET_EXPERIMENT:\n return Ok(new TargetExperimentCondition(data));\n default:\n return Err(\n new KameleoonError(\n KameleoonException.TargetingCondition,\n targetingType,\n ),\n );\n }\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,oBAAA,GAAAH,OAAA;AACA,IAAAI,6BAAA,GAAAJ,OAAA;AACA,IAAAK,0BAAA,GAAAL,OAAA;AAGO,MAAMM,gBAAgB,CAAC;EAC5B,OAAOC,eAAeA,CACpBC,IAAuB,EACgB;IACvC,MAAM;MAAEC;IAAc,CAAC,GAAGD,IAAI;IAE9B,QAAQC,aAAa;MACnB,KAAKC,oBAAa,CAACC,YAAY;QAC7B,OAAO,IAAAC,SAAE,EAAC,IAAIC,wCAAmB,CAACL,IAAI,CAAC,CAAC;MAC1C,KAAKE,oBAAa,CAACI,oBAAoB;QACrC,OAAO,IAAAF,SAAE,EAAC,IAAIG,0DAA4B,CAACP,IAAI,CAAC,CAAC;MACnD,KAAKE,oBAAa,CAACM,iBAAiB;QAClC,OAAO,IAAAJ,SAAE,EAAC,IAAIK,oDAAyB,CAACT,IAAI,CAAC,CAAC;MAChD;QACE,OAAO,IAAAU,UAAG,EACR,IAAIC,8BAAc,CAChBC,kCAAkB,CAACC,kBAAkB,EACrCZ,aAAa,CACd,CACF;IAAC;EAER;AACF;AAACa,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
1
+ {"version":3,"file":"conditionFactory.js","names":["ConditionFactory","a","_classCallCheck","_createClass","key","value","createCondition","data","targetingType","TargetingType","CUSTOM_DATUM","Ok","CustomDataCondition","EXCLUSIVE_EXPERIMENT","ExclusiveExperimentCondition","TARGET_EXPERIMENT","TargetExperimentCondition","DEVICE_TYPE","DeviceCondition","BROWSER","BrowserCondition","PAGE_URL","PageUrlCondition","PAGE_TITLE","PageTitleCondition","CONVERSIONS","ConversionCondition","VISITOR_CODE","VisitorCodeCondition","SDK_LANGUAGE","SdkLanguageCondition","Err","KameleoonError","KameleoonException","TargetingCondition","exports"],"sources":["../../../src/targeting/conditions/conditionFactory.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { TargetingType } from 'src/targeting/types';\nimport { BrowserCondition } from './browserCondition';\nimport { ConversionCondition } from './conversionCondition';\nimport { CustomDataCondition } from './customDataCondition';\nimport { DeviceCondition } from './deviceCondition';\nimport { ExclusiveExperimentCondition } from './exclusiveExperimentCondition';\nimport { PageTitleCondition } from './pageTitleCondition';\nimport { PageUrlCondition } from './pageUrlCondition';\nimport { SdkLanguageCondition } from './sdkLanguageCondition';\nimport { TargetExperimentCondition } from './targetExperimentCondition';\nimport { ConditionDataType, ConditionType } from './types';\nimport { VisitorCodeCondition } from './visitorCodeCondition';\n\nexport class ConditionFactory {\n static createCondition(\n data: ConditionDataType,\n ): Result<ConditionType, KameleoonError> {\n const { targetingType } = data;\n\n switch (targetingType) {\n case TargetingType.CUSTOM_DATUM:\n return Ok(new CustomDataCondition(data));\n case TargetingType.EXCLUSIVE_EXPERIMENT:\n return Ok(new ExclusiveExperimentCondition());\n case TargetingType.TARGET_EXPERIMENT:\n return Ok(new TargetExperimentCondition(data));\n case TargetingType.DEVICE_TYPE:\n return Ok(new DeviceCondition(data));\n case TargetingType.BROWSER:\n return Ok(new BrowserCondition(data));\n case TargetingType.PAGE_URL:\n return Ok(new PageUrlCondition(data));\n case TargetingType.PAGE_TITLE:\n return Ok(new PageTitleCondition(data));\n case TargetingType.CONVERSIONS:\n return Ok(new ConversionCondition(data));\n case TargetingType.VISITOR_CODE:\n return Ok(new VisitorCodeCondition(data));\n case TargetingType.SDK_LANGUAGE:\n return Ok(new SdkLanguageCondition(data));\n default:\n return Err(\n new KameleoonError(\n KameleoonException.TargetingCondition,\n targetingType,\n ),\n );\n }\n }\n}\n"],"mappings":"s0DAea,CAAAA,gBAAgB,kCAAAC,EAAA,EAAAC,eAAA,MAAAD,CAAA,SAAAE,YAAA,CAAAF,CAAA,QAAAG,GAAA,mBAA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C,CAElC,GAAAwB,UAAG,EACR,GAAI,CAAAC,8BAAc,CAChBC,kCAAkB,CAACC,kBAAkB,CACrC1B,CAAa,CACd,CAGT,CAAC,IAAAP,CAAA,IAAAkC,OAAA,CAAAnC,gBAAA,CAAAA,gBAAA"}
@@ -0,0 +1,10 @@
1
+ import { Result } from 'ts-res';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
+ import { EvaluationDataType } from 'src/targeting/types';
4
+ import { ConditionDataType, ICondition } from './types';
5
+ export declare class ConversionCondition implements ICondition {
6
+ private conditionValue?;
7
+ constructor({ goalId }: ConditionDataType);
8
+ evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
9
+ private checkCondition;
10
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConversionCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var ConversionCondition=/*#__PURE__*/function(){function a(b){var c=b.goalId;_classCallCheck(this,a),_defineProperty(this,"conditionValue",void 0),this.conditionValue=c}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.targetingData,c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Conversion];if(c){var d=c.goalId;return(0,_tsRes.Ok)(this.checkCondition(d))}return(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){return!!this.conditionValue&&(-1===this.conditionValue||a===this.conditionValue);// --- Note ---
2
+ // `goalId` with value `-1` means any goal conversion
3
+ }}]),a}();exports.ConversionCondition=ConversionCondition;
4
+ //# sourceMappingURL=conversionCondition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversionCondition.js","names":["ConversionCondition","a","b","goalId","_classCallCheck","_defineProperty","conditionValue","_createClass","key","value","evaluate","targetingData","conversionData","KameleoonData","Conversion","Ok","checkCondition","exports"],"sources":["../../../src/targeting/conditions/conversionCondition.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class ConversionCondition implements ICondition {\n private conditionValue?: number | null;\n\n constructor({ goalId }: ConditionDataType) {\n this.conditionValue = goalId;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const conversionData = targetingData?.[KameleoonData.Conversion];\n\n if (conversionData) {\n const { goalId } = conversionData;\n\n return Ok(this.checkCondition(goalId));\n }\n\n return Ok(false);\n }\n\n private checkCondition(goalId: number): boolean {\n if (!this.conditionValue) {\n return false;\n }\n\n // --- Note ---\n // `goalId` with value `-1` means any goal conversion\n if (this.conditionValue === -1) {\n return true;\n }\n\n return goalId === this.conditionValue;\n }\n}\n"],"mappings":"85CAMa,CAAAA,mBAAmB,yBAG9B,SAAAC,EAAAC,CAAA,CAA2C,IAA7B,CAAAC,CAAM,CAAAD,CAAA,CAANC,MAAM,CAAAC,eAAA,MAAAH,CAAA,EAAAI,eAAA,+BAClB,IAAI,CAACC,cAAc,CAAGH,CACxB,CAAC,OAAAI,YAAA,CAAAN,CAAA,GAAAO,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAT,CAAA,CAEwD,IADtD,CAAAU,CAAa,CAAAV,CAAA,CAAbU,aAAa,CAEPC,CAAc,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAEhE,GAAIF,CAAc,CAAE,CAClB,GAAQ,CAAAT,CAAM,CAAKS,CAAc,CAAzBT,MAAM,CAEd,MAAO,GAAAY,SAAE,EAAC,IAAI,CAACC,cAAc,CAACb,CAAM,CAAC,CACvC,CAEA,MAAO,GAAAY,SAAE,KACX,CAAC,GAAAP,GAAA,kBAAAC,KAAA,CAED,SAAAO,eAAuBb,CAAc,CAAW,SACzC,IAAI,CAACG,cAAc,GAMI,CAAC,CAAC,GAA1B,IAAI,CAACA,cAAqB,EAIvBH,CAAM,GAAK,IAAI,CAACG,cAAc,EANrC;AACA;AAMF,CAAC,IAAAL,CAAA,IAAAgB,OAAA,CAAAjB,mBAAA,CAAAA,mBAAA"}
@@ -1,16 +1,14 @@
1
1
  import { Result } from 'ts-res';
2
- import { KameleoonError } from '../../kameleoonError';
3
- import { EvaluationDataType } from '../types';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
+ import { EvaluationDataType } from 'src/targeting/types';
4
4
  import { ConditionDataType, ICondition } from './types';
5
5
  export declare class CustomDataCondition implements ICondition {
6
6
  private customDataIndex;
7
- private matchType;
8
- private inverseResult;
9
- private conditionValue;
7
+ private matchType?;
8
+ private conditionValue?;
10
9
  private error?;
11
- constructor({ customDataIndex, valueMatchType, isInclude, value, }: ConditionDataType);
10
+ constructor({ customDataIndex, valueMatchType, value }: ConditionDataType);
12
11
  evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
13
12
  private checkCondition;
14
- private parseRegExp;
15
13
  private parseArray;
16
14
  }
@@ -1,115 +1,8 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CustomDataCondition = void 0;
7
- var _tsRes = require("ts-res");
8
- var _kameleoonData = require("../../kameleoonData");
9
- var _kameleoonError = require("../../kameleoonError");
10
- var _types = require("../types");
11
- 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; }
12
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
13
- 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); }
14
- class CustomDataCondition {
15
- constructor({
16
- customDataIndex,
17
- valueMatchType,
18
- isInclude,
19
- value
20
- }) {
21
- _defineProperty(this, "customDataIndex", void 0);
22
- _defineProperty(this, "matchType", void 0);
23
- _defineProperty(this, "inverseResult", void 0);
24
- _defineProperty(this, "conditionValue", void 0);
25
- _defineProperty(this, "error", void 0);
26
- this.customDataIndex = Number(customDataIndex);
27
- this.inverseResult = !(isInclude ?? true);
28
- this.matchType = valueMatchType;
29
- this.conditionValue = value;
30
- }
31
- evaluate({
32
- targetingData
33
- }) {
34
- const isCustomData = data => data.type === _kameleoonData.KameleoonData.CustomData;
35
- const filteredData = targetingData.map(item => item.data).filter(isCustomData).filter(item => item.index === this.customDataIndex);
36
- if (filteredData.length) {
37
- const lastDataItem = filteredData[filteredData.length - 1];
38
- const {
39
- value: customDataValue
40
- } = lastDataItem;
41
- const result = this.inverseResult ? !this.checkCondition(customDataValue) : this.checkCondition(customDataValue);
42
- if (this.error) {
43
- return (0, _tsRes.Err)(this.error);
44
- }
45
- return (0, _tsRes.Ok)(result);
46
- }
47
- return (0, _tsRes.Ok)(this.matchType === _types.MatchTypeCustomData.UNDEFINED);
48
- }
49
- checkCondition(customDataValue) {
50
- if (this.conditionValue === null && this.matchType !== _types.MatchTypeCustomData.TRUE && this.matchType !== _types.MatchTypeCustomData.FALSE) {
51
- return false;
52
- }
53
-
54
- // --- Note ---
55
- // `MatchTypeCustomData.TRUE` and `MatchTypeCustomData.FALSE` do not use condition value
56
- // so we can safely assume that `this.conditionValue` is a string at this point
57
- const conditionValue = this.conditionValue;
58
-
59
- // --- Note ---
60
- // `AMONG_VALUES` is checked separately to avoid recursion overhead
61
- // for `JSON.parse` inside `this.parseArray`
62
- if (this.matchType === _types.MatchTypeCustomData.AMONG_VALUES) {
63
- const result = this.parseArray(conditionValue);
64
- if (!result.ok) {
65
- this.error = result.error;
66
- return false;
67
- }
68
- const resultData = new Set(result.data);
69
- return Array.isArray(customDataValue) ? customDataValue.some(value => resultData.has(value)) : result.data.includes(customDataValue);
70
- }
71
- if (Array.isArray(customDataValue)) {
72
- return customDataValue.some(value => this.checkCondition(value));
73
- }
74
- switch (this.matchType) {
75
- case _types.MatchTypeCustomData.CONTAINS:
76
- return customDataValue.includes(conditionValue);
77
- case _types.MatchTypeCustomData.EXACT:
78
- return customDataValue === this.conditionValue;
79
- case _types.MatchTypeCustomData.REGULAR_EXPRESSION:
80
- return this.parseRegExp(conditionValue).test(customDataValue);
81
- case _types.MatchTypeCustomData.LOWER:
82
- return Number(customDataValue) < Number(this.conditionValue);
83
- case _types.MatchTypeCustomData.EQUAL:
84
- return Number(customDataValue) === Number(this.conditionValue);
85
- case _types.MatchTypeCustomData.GREATER:
86
- return Number(customDataValue) > Number(this.conditionValue);
87
- case _types.MatchTypeCustomData.TRUE:
88
- return customDataValue.toLowerCase() === 'true';
89
- case _types.MatchTypeCustomData.FALSE:
90
- return customDataValue.toLowerCase() === 'false';
91
- default:
92
- return false;
93
- }
94
- }
95
- parseRegExp(value) {
96
- if (value[0] === '/') {
97
- const [_, expression, flags] = value.split('/');
98
- return new RegExp(expression, flags);
99
- }
100
- return new RegExp(value);
101
- }
102
- parseArray(value) {
103
- try {
104
- const result = JSON.parse(value);
105
- if (Array.isArray(result)) {
106
- return (0, _tsRes.Ok)(result);
107
- }
108
- } catch (err) {
109
- return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck, err, value));
110
- }
111
- return (0, _tsRes.Ok)([]);
112
- }
113
- }
114
- exports.CustomDataCondition = CustomDataCondition;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomDataCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_utilities=require("../../utilities"),_types=require("../types");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var CustomDataCondition=/*#__PURE__*/function(){function a(b){var c=b.customDataIndex,d=b.valueMatchType,e=b.value;_classCallCheck(this,a),_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),this.customDataIndex=+c,this.matchType=d,this.conditionValue=e}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b,c=a.targetingData,d=null===c||void 0===c||null===(b=c[_kameleoonData.KameleoonData.CustomData])||void 0===b?void 0:b[this.customDataIndex];if(d){var e=d.value,f=this.checkCondition(e);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(f)}return(0,_tsRes.Ok)(this.matchType===_types.MatchTypeCustomData.UNDEFINED)}},{key:"checkCondition",value:function checkCondition(a){var b=this;if("string"!=typeof this.conditionValue&&this.matchType!==_types.MatchTypeCustomData.TRUE&&this.matchType!==_types.MatchTypeCustomData.FALSE)return!1;// --- Note ---
2
+ // `MatchTypeCustomData.TRUE` and `MatchTypeCustomData.FALSE` do not use condition value
3
+ // so we can safely assume that `this.conditionValue` is a string at this point
4
+ var c=this.conditionValue;// --- Note ---
5
+ // `AMONG_VALUES` is checked separately to avoid recursion overhead
6
+ // for `JSON.parse` inside `this.parseArray`
7
+ if(this.matchType===_types.MatchTypeCustomData.AMONG_VALUES){var d=this.parseArray(c);if(!d.ok)return this.error=d.error,!1;var e=new Set(d.data);return Array.isArray(a)?a.some(function(a){return e.has(a)}):d.data.includes(a)}if(Array.isArray(a))return a.some(function(a){return b.checkCondition(a)});switch(this.matchType){case _types.MatchTypeCustomData.CONTAINS:return a.includes(c);case _types.MatchTypeCustomData.EXACT:return a===this.conditionValue;case _types.MatchTypeCustomData.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(c).test(a);case _types.MatchTypeCustomData.LOWER:return+a<+this.conditionValue;case _types.MatchTypeCustomData.EQUAL:return+a===+this.conditionValue;case _types.MatchTypeCustomData.GREATER:return+a>+this.conditionValue;case _types.MatchTypeCustomData.TRUE:return"true"===a.toLowerCase();case _types.MatchTypeCustomData.FALSE:return"false"===a.toLowerCase();default:return!1;}}},{key:"parseArray",value:function parseArray(a){try{var b=JSON.parse(a);if(Array.isArray(b))return(0,_tsRes.Ok)(b)}catch(b){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck,b,a))}return(0,_tsRes.Ok)([])}}]),a}();exports.CustomDataCondition=CustomDataCondition;
115
8
  //# sourceMappingURL=customDataCondition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customDataCondition.js","names":["_tsRes","require","_kameleoonData","_kameleoonError","_types","_defineProperty","obj","key","value","_toPropertyKey","Object","defineProperty","enumerable","configurable","writable","arg","_toPrimitive","String","input","hint","prim","Symbol","toPrimitive","undefined","res","call","TypeError","Number","CustomDataCondition","constructor","customDataIndex","valueMatchType","isInclude","inverseResult","matchType","conditionValue","evaluate","targetingData","isCustomData","data","type","KameleoonData","CustomData","filteredData","map","item","filter","index","length","lastDataItem","customDataValue","result","checkCondition","error","Err","Ok","MatchTypeCustomData","UNDEFINED","TRUE","FALSE","AMONG_VALUES","parseArray","ok","resultData","Set","Array","isArray","some","has","includes","CONTAINS","EXACT","REGULAR_EXPRESSION","parseRegExp","test","LOWER","EQUAL","GREATER","toLowerCase","_","expression","flags","split","RegExp","JSON","parse","err","KameleoonError","KameleoonException","AmongValuesCheck","exports"],"sources":["../../../src/targeting/conditions/customDataCondition.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport {\n KameleoonData,\n CustomDataType,\n KameleoonDataItemType,\n} from '../../kameleoonData';\nimport { KameleoonError, KameleoonException } from '../../kameleoonError';\nimport { EvaluationDataType, MatchTypeCustomData } from '../types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class CustomDataCondition implements ICondition {\n private customDataIndex: number;\n private matchType: MatchTypeCustomData | null;\n private inverseResult: boolean;\n private conditionValue: string | null;\n private error?: KameleoonError;\n\n constructor({\n customDataIndex,\n valueMatchType,\n isInclude,\n value,\n }: ConditionDataType) {\n this.customDataIndex = Number(customDataIndex);\n this.inverseResult = !(isInclude ?? true);\n this.matchType = valueMatchType;\n this.conditionValue = value;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const isCustomData = (\n data: KameleoonDataItemType,\n ): data is CustomDataType => data.type === KameleoonData.CustomData;\n\n const filteredData = targetingData\n .map((item) => item.data)\n .filter(isCustomData)\n .filter((item) => item.index === this.customDataIndex);\n\n if (filteredData.length) {\n const lastDataItem = filteredData[filteredData.length - 1];\n const { value: customDataValue } = lastDataItem;\n const result = this.inverseResult\n ? !this.checkCondition(customDataValue)\n : this.checkCondition(customDataValue);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n return Ok(this.matchType === MatchTypeCustomData.UNDEFINED);\n }\n\n private checkCondition(customDataValue: CustomDataType['value']): boolean {\n if (\n this.conditionValue === null &&\n this.matchType !== MatchTypeCustomData.TRUE &&\n this.matchType !== MatchTypeCustomData.FALSE\n ) {\n return false;\n }\n\n // --- Note ---\n // `MatchTypeCustomData.TRUE` and `MatchTypeCustomData.FALSE` do not use condition value\n // so we can safely assume that `this.conditionValue` is a string at this point\n const conditionValue = this.conditionValue as string;\n\n // --- Note ---\n // `AMONG_VALUES` is checked separately to avoid recursion overhead\n // for `JSON.parse` inside `this.parseArray`\n if (this.matchType === MatchTypeCustomData.AMONG_VALUES) {\n const result = this.parseArray(conditionValue);\n\n if (!result.ok) {\n this.error = result.error;\n\n return false;\n }\n\n const resultData = new Set(result.data);\n\n return Array.isArray(customDataValue)\n ? customDataValue.some((value) => resultData.has(value))\n : result.data.includes(customDataValue);\n }\n\n if (Array.isArray(customDataValue)) {\n return customDataValue.some((value) => this.checkCondition(value));\n }\n\n switch (this.matchType) {\n case MatchTypeCustomData.CONTAINS:\n return customDataValue.includes(conditionValue);\n case MatchTypeCustomData.EXACT:\n return customDataValue === this.conditionValue;\n case MatchTypeCustomData.REGULAR_EXPRESSION:\n return this.parseRegExp(conditionValue).test(customDataValue);\n case MatchTypeCustomData.LOWER:\n return Number(customDataValue) < Number(this.conditionValue);\n case MatchTypeCustomData.EQUAL:\n return Number(customDataValue) === Number(this.conditionValue);\n case MatchTypeCustomData.GREATER:\n return Number(customDataValue) > Number(this.conditionValue);\n case MatchTypeCustomData.TRUE:\n return customDataValue.toLowerCase() === 'true';\n case MatchTypeCustomData.FALSE:\n return customDataValue.toLowerCase() === 'false';\n default:\n return false;\n }\n }\n\n private parseRegExp(value: string): RegExp {\n if (value[0] === '/') {\n const [_, expression, flags] = value.split('/');\n\n return new RegExp(expression, flags);\n }\n\n return new RegExp(value);\n }\n\n private parseArray(value: string): Result<string[], KameleoonError> {\n try {\n const result = JSON.parse(value);\n\n if (Array.isArray(result)) {\n return Ok(result);\n }\n } catch (err) {\n return Err(\n new KameleoonError(KameleoonException.AmongValuesCheck, err, value),\n );\n }\n\n return Ok([]);\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAKA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAmE,SAAAI,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,gB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,KAAK,CAAC,GAAG,CAAC;MAE/C,OAAO,IAAIC,MAAM,CAACH,UAAU,EAAEC,KAAK,CAAC;IACtC;IAEA,OAAO,IAAIE,MAAM,CAAC3E,KAAK,CAAC;EAC1B;EAEQqD,UAAUA,CAACrD,KAAa,EAAoC;IAClE,IAAI;MACF,MAAM2C,MAAM,GAAGiC,IAAI,CAACC,KAAK,CAAC7E,KAAK,CAAC;MAEhC,IAAIyD,KAAK,CAACC,OAAO,CAACf,MAAM,CAAC,EAAE;QACzB,OAAO,IAAAI,SAAE,EAACJ,MAAM,CAAC;MACnB;IACF,CAAC,CAAC,OAAOmC,GAAG,EAAE;MACZ,OAAO,IAAAhC,UAAG,EACR,IAAIiC,8BAAc,CAACC,kCAAkB,CAACC,gBAAgB,EAAEH,GAAG,EAAE9E,KAAK,CAAC,CACpE;IACH;IAEA,OAAO,IAAA+C,SAAE,EAAC,EAAE,CAAC;EACf;AACF;AAACmC,OAAA,CAAA9D,mBAAA,GAAAA,mBAAA"}
1
+ {"version":3,"file":"customDataCondition.js","names":["CustomDataCondition","a","b","customDataIndex","valueMatchType","value","_classCallCheck","_defineProperty","matchType","conditionValue","_createClass","key","evaluate","targetingData","customData","KameleoonData","CustomData","customDataValue","result","checkCondition","error","Err","Ok","MatchTypeCustomData","UNDEFINED","TRUE","FALSE","AMONG_VALUES","parseArray","ok","resultData","Set","data","Array","isArray","some","has","includes","CONTAINS","EXACT","REGULAR_EXPRESSION","Utilities","parseRegExp","test","LOWER","EQUAL","GREATER","toLowerCase","JSON","parse","err","KameleoonError","KameleoonException","AmongValuesCheck","exports"],"sources":["../../../src/targeting/conditions/customDataCondition.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { CustomDataType, KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { EvaluationDataType, MatchTypeCustomData } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class CustomDataCondition implements ICondition {\n private customDataIndex: number;\n private matchType?: MatchTypeCustomData | null;\n private conditionValue?: string | null;\n private error?: KameleoonError;\n\n constructor({ customDataIndex, valueMatchType, value }: ConditionDataType) {\n this.customDataIndex = Number(customDataIndex);\n this.matchType = valueMatchType;\n this.conditionValue = value;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const customData =\n targetingData?.[KameleoonData.CustomData]?.[this.customDataIndex];\n\n if (customData) {\n const { value: customDataValue } = customData;\n const result = this.checkCondition(customDataValue);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n return Ok(this.matchType === MatchTypeCustomData.UNDEFINED);\n }\n\n private checkCondition(customDataValue: CustomDataType['value']): boolean {\n if (\n typeof this.conditionValue !== 'string' &&\n this.matchType !== MatchTypeCustomData.TRUE &&\n this.matchType !== MatchTypeCustomData.FALSE\n ) {\n return false;\n }\n\n // --- Note ---\n // `MatchTypeCustomData.TRUE` and `MatchTypeCustomData.FALSE` do not use condition value\n // so we can safely assume that `this.conditionValue` is a string at this point\n const conditionValue = this.conditionValue as string;\n\n // --- Note ---\n // `AMONG_VALUES` is checked separately to avoid recursion overhead\n // for `JSON.parse` inside `this.parseArray`\n if (this.matchType === MatchTypeCustomData.AMONG_VALUES) {\n const result = this.parseArray(conditionValue);\n\n if (!result.ok) {\n this.error = result.error;\n\n return false;\n }\n\n const resultData = new Set(result.data);\n\n return Array.isArray(customDataValue)\n ? customDataValue.some((value) => resultData.has(value))\n : result.data.includes(customDataValue);\n }\n\n if (Array.isArray(customDataValue)) {\n return customDataValue.some((value) => this.checkCondition(value));\n }\n\n switch (this.matchType) {\n case MatchTypeCustomData.CONTAINS:\n return customDataValue.includes(conditionValue);\n case MatchTypeCustomData.EXACT:\n return customDataValue === this.conditionValue;\n case MatchTypeCustomData.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(conditionValue).test(customDataValue);\n case MatchTypeCustomData.LOWER:\n return Number(customDataValue) < Number(this.conditionValue);\n case MatchTypeCustomData.EQUAL:\n return Number(customDataValue) === Number(this.conditionValue);\n case MatchTypeCustomData.GREATER:\n return Number(customDataValue) > Number(this.conditionValue);\n case MatchTypeCustomData.TRUE:\n return customDataValue.toLowerCase() === 'true';\n case MatchTypeCustomData.FALSE:\n return customDataValue.toLowerCase() === 'false';\n default:\n return false;\n }\n }\n\n private parseArray(value: string): Result<string[], KameleoonError> {\n try {\n const result = JSON.parse(value);\n\n if (Array.isArray(result)) {\n return Ok(result);\n }\n } catch (err) {\n return Err(\n new KameleoonError(KameleoonException.AmongValuesCheck, err, value),\n );\n }\n\n return Ok([]);\n }\n}\n"],"mappings":"+gDAOa,CAAAA,mBAAmB,yBAM9B,SAAAC,EAAAC,CAAA,CAA2E,IAA7D,CAAAC,CAAe,CAAAD,CAAA,CAAfC,eAAe,CAAEC,CAAc,CAAAF,CAAA,CAAdE,cAAc,CAAEC,CAAK,CAAAH,CAAA,CAALG,KAAK,CAAAC,eAAA,MAAAL,CAAA,EAAAM,eAAA,gCAAAA,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,sBAClD,IAAI,CAACJ,eAAe,EAAUA,CAAgB,CAC9C,IAAI,CAACK,SAAS,CAAGJ,CAAc,CAC/B,IAAI,CAACK,cAAc,CAAGJ,CACxB,CAAC,OAAAK,YAAA,CAAAT,CAAA,GAAAU,GAAA,YAAAN,KAAA,CAED,SAAAO,SAAAX,CAAA,CAEwD,KAAAC,CAAA,CADtDW,CAAa,CAAAZ,CAAA,CAAbY,aAAa,CAEPC,CAAU,QACdD,CAAa,WAAbA,CAAa,UAAAX,CAAA,CAAbW,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,YAAAd,CAAA,QAAzCA,CAAA,CAA4C,IAAI,CAACC,eAAe,CAAC,CAEnE,GAAIW,CAAU,CAAE,IACC,CAAAG,CAAe,CAAKH,CAAU,CAArCT,KAAK,CACPa,CAAM,CAAG,IAAI,CAACC,cAAc,CAACF,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CAAE7C,CAAK,CAAC,CAEvE,CAEA,MAAO,GAAAiB,SAAE,EAAC,EAAE,CACd,CAAC,IAAArB,CAAA,IAAAqD,OAAA,CAAAtD,mBAAA,CAAAA,mBAAA"}
@@ -0,0 +1,9 @@
1
+ import { Result } from 'ts-res';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
+ import { EvaluationDataType } from 'src/targeting/types';
4
+ import { ConditionDataType, ICondition } from './types';
5
+ export declare class DeviceCondition implements ICondition {
6
+ private device?;
7
+ constructor({ device }: ConditionDataType);
8
+ evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DeviceCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var DeviceCondition=/*#__PURE__*/function(){function a(b){var c=b.device;_classCallCheck(this,a),_defineProperty(this,"device",void 0),this.device=c}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.targetingData,c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Device];if(c){var d=c.device;return(0,_tsRes.Ok)(d===this.device)}return(0,_tsRes.Ok)(!1)}}]),a}();exports.DeviceCondition=DeviceCondition;
2
+ //# sourceMappingURL=deviceCondition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deviceCondition.js","names":["DeviceCondition","a","b","device","_classCallCheck","_defineProperty","_createClass","key","value","evaluate","targetingData","deviceData","KameleoonData","Device","Ok","exports"],"sources":["../../../src/targeting/conditions/deviceCondition.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { DeviceType, KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class DeviceCondition implements ICondition {\n private device?: DeviceType | null;\n\n constructor({ device }: ConditionDataType) {\n this.device = device;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const deviceData = targetingData?.[KameleoonData.Device];\n\n if (deviceData) {\n const { device } = deviceData;\n\n return Ok(device === this.device);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"05CAMa,CAAAA,eAAe,yBAG1B,SAAAC,EAAAC,CAAA,CAA2C,IAA7B,CAAAC,CAAM,CAAAD,CAAA,CAANC,MAAM,CAAAC,eAAA,MAAAH,CAAA,EAAAI,eAAA,uBAClB,IAAI,CAACF,MAAM,CAAGA,CAChB,CAAC,OAAAG,YAAA,CAAAL,CAAA,GAAAM,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAR,CAAA,CAEwD,IADtD,CAAAS,CAAa,CAAAT,CAAA,CAAbS,aAAa,CAEPC,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,MAAM,CAAC,CAExD,GAAIF,CAAU,CAAE,CACd,GAAQ,CAAAR,CAAM,CAAKQ,CAAU,CAArBR,MAAM,CAEd,MAAO,GAAAW,SAAE,EAACX,CAAM,GAAK,IAAI,CAACA,MAAM,CAClC,CAEA,MAAO,GAAAW,SAAE,KACX,CAAC,IAAAb,CAAA,IAAAc,OAAA,CAAAf,eAAA,CAAAA,eAAA"}
@@ -1,9 +1,7 @@
1
1
  import { Result } from 'ts-res';
2
- import { KameleoonError } from '../../kameleoonError';
3
- import { EvaluationDataType } from '../types';
4
- import { ConditionDataType, ICondition } from './types';
2
+ import { KameleoonError } from 'src/kameleoonError';
3
+ import { EvaluationDataType } from 'src/targeting/types';
4
+ import { ICondition } from './types';
5
5
  export declare class ExclusiveExperimentCondition implements ICondition {
6
- private inverseResult;
7
- constructor({ isInclude }: ConditionDataType);
8
6
  evaluate({ experimentId, variationData, }: EvaluationDataType): Result<boolean, KameleoonError>;
9
7
  }