@kameleoon/javascript-sdk-core 3.6.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/CHANGELOG.md +369 -0
  2. package/CHANGELOG_INTERNAL.md +3 -0
  3. package/dist/cacheManager/cacheManager.js +1 -1
  4. package/dist/cacheManager/cacheManager.js.map +1 -1
  5. package/dist/cacheManager/index.js +1 -1
  6. package/dist/clientConfiguration/clientConfiguration.d.ts +2 -3
  7. package/dist/clientConfiguration/clientConfiguration.js +1 -1
  8. package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
  9. package/dist/clientConfiguration/constants.js +1 -1
  10. package/dist/clientConfiguration/constants.js.map +1 -1
  11. package/dist/clientConfiguration/index.js +1 -1
  12. package/dist/clientConfiguration/types.d.ts +7 -8
  13. package/dist/clientConfiguration/types.js +1 -1
  14. package/dist/clientConfiguration/types.js.map +1 -1
  15. package/dist/clientSettings/clientSettings.js +1 -1
  16. package/dist/clientSettings/clientSettings.js.map +1 -1
  17. package/dist/clientSettings/index.js +1 -1
  18. package/dist/constants.d.ts +0 -8
  19. package/dist/constants.js +1 -1
  20. package/dist/constants.js.map +1 -1
  21. package/dist/eventSource/constants.js +1 -1
  22. package/dist/eventSource/constants.js.map +1 -1
  23. package/dist/eventSource/eventSource.d.ts +17 -0
  24. package/dist/eventSource/eventSource.js +2 -0
  25. package/dist/eventSource/eventSource.js.map +1 -0
  26. package/dist/eventSource/index.d.ts +2 -2
  27. package/dist/eventSource/index.js +1 -1
  28. package/dist/eventSource/index.js.map +1 -1
  29. package/dist/eventSource/types.d.ts +8 -19
  30. package/dist/eventSource/types.js.map +1 -1
  31. package/dist/hasher/hasher.js +1 -1
  32. package/dist/hasher/hasher.js.map +1 -1
  33. package/dist/hasher/index.js +1 -1
  34. package/dist/hasher/index.js.map +1 -1
  35. package/dist/index.d.ts +7 -6
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/kameleoonClient.d.ts +2 -207
  39. package/dist/kameleoonClient.js +1 -1
  40. package/dist/kameleoonClient.js.map +1 -1
  41. package/dist/kameleoonClientInterface.d.ts +199 -0
  42. package/dist/kameleoonClientInterface.js +2 -0
  43. package/dist/kameleoonClientInterface.js.map +1 -0
  44. package/dist/kameleoonData/applicationVersion.js +1 -1
  45. package/dist/kameleoonData/applicationVersion.js.map +1 -1
  46. package/dist/kameleoonData/browser.js +1 -1
  47. package/dist/kameleoonData/browser.js.map +1 -1
  48. package/dist/kameleoonData/constants.js +1 -1
  49. package/dist/kameleoonData/constants.js.map +1 -1
  50. package/dist/kameleoonData/conversion.js +1 -1
  51. package/dist/kameleoonData/conversion.js.map +1 -1
  52. package/dist/kameleoonData/cookie.js +1 -1
  53. package/dist/kameleoonData/cookie.js.map +1 -1
  54. package/dist/kameleoonData/customData.js +1 -1
  55. package/dist/kameleoonData/customData.js.map +1 -1
  56. package/dist/kameleoonData/dataManager.js +1 -1
  57. package/dist/kameleoonData/dataManager.js.map +1 -1
  58. package/dist/kameleoonData/dataProcessor.d.ts +2 -2
  59. package/dist/kameleoonData/dataProcessor.js +1 -1
  60. package/dist/kameleoonData/dataProcessor.js.map +1 -1
  61. package/dist/kameleoonData/device.js +1 -1
  62. package/dist/kameleoonData/device.js.map +1 -1
  63. package/dist/kameleoonData/geolocation.js +1 -1
  64. package/dist/kameleoonData/geolocation.js.map +1 -1
  65. package/dist/kameleoonData/helpers.js +1 -1
  66. package/dist/kameleoonData/helpers.js.map +1 -1
  67. package/dist/kameleoonData/index.js +1 -1
  68. package/dist/kameleoonData/operatingSystem.js +1 -1
  69. package/dist/kameleoonData/operatingSystem.js.map +1 -1
  70. package/dist/kameleoonData/pageView.js +1 -1
  71. package/dist/kameleoonData/pageView.js.map +1 -1
  72. package/dist/kameleoonData/types.d.ts +2 -2
  73. package/dist/kameleoonData/types.js +1 -1
  74. package/dist/kameleoonData/types.js.map +1 -1
  75. package/dist/kameleoonData/userAgent.js +1 -1
  76. package/dist/kameleoonData/userAgent.js.map +1 -1
  77. package/dist/kameleoonData/visitsData.js +1 -1
  78. package/dist/kameleoonData/visitsData.js.map +1 -1
  79. package/dist/kameleoonError/constants.d.ts +1 -0
  80. package/dist/kameleoonError/constants.js +1 -1
  81. package/dist/kameleoonError/constants.js.map +1 -1
  82. package/dist/kameleoonError/helpers.js.map +1 -1
  83. package/dist/kameleoonError/index.js +1 -1
  84. package/dist/kameleoonError/kameleoonError.d.ts +1 -1
  85. package/dist/kameleoonError/kameleoonError.js +1 -1
  86. package/dist/kameleoonError/kameleoonError.js.map +1 -1
  87. package/dist/kameleoonError/types.d.ts +1 -0
  88. package/dist/kameleoonError/types.js +1 -1
  89. package/dist/kameleoonError/types.js.map +1 -1
  90. package/dist/kameleoonUtils.js +1 -1
  91. package/dist/kameleoonUtils.js.map +1 -1
  92. package/dist/requester/constants.js +1 -1
  93. package/dist/requester/constants.js.map +1 -1
  94. package/dist/requester/index.js +1 -1
  95. package/dist/requester/requester.js +1 -1
  96. package/dist/requester/requester.js.map +1 -1
  97. package/dist/requester/types.js +1 -1
  98. package/dist/requester/types.js.map +1 -1
  99. package/dist/storage/constants.js +1 -1
  100. package/dist/storage/constants.js.map +1 -1
  101. package/dist/storage/index.d.ts +2 -1
  102. package/dist/storage/index.js +1 -1
  103. package/dist/storage/index.js.map +1 -1
  104. package/dist/storage/storage.d.ts +13 -0
  105. package/dist/storage/storage.js +2 -0
  106. package/dist/storage/storage.js.map +1 -0
  107. package/dist/storage/types.d.ts +15 -30
  108. package/dist/storage/types.js.map +1 -1
  109. package/dist/targeting/conditions/applicationVersion.js +1 -1
  110. package/dist/targeting/conditions/applicationVersion.js.map +1 -1
  111. package/dist/targeting/conditions/browser.js +1 -1
  112. package/dist/targeting/conditions/browser.js.map +1 -1
  113. package/dist/targeting/conditions/conditionFactory.js +1 -1
  114. package/dist/targeting/conditions/conditionFactory.js.map +1 -1
  115. package/dist/targeting/conditions/conversion.js +1 -1
  116. package/dist/targeting/conditions/conversion.js.map +1 -1
  117. package/dist/targeting/conditions/cookie.js +1 -1
  118. package/dist/targeting/conditions/cookie.js.map +1 -1
  119. package/dist/targeting/conditions/customData.js +1 -1
  120. package/dist/targeting/conditions/customData.js.map +1 -1
  121. package/dist/targeting/conditions/device.js +1 -1
  122. package/dist/targeting/conditions/device.js.map +1 -1
  123. package/dist/targeting/conditions/exclusiveCampaign.js +1 -1
  124. package/dist/targeting/conditions/exclusiveCampaign.js.map +1 -1
  125. package/dist/targeting/conditions/firstVisit.js +1 -1
  126. package/dist/targeting/conditions/firstVisit.js.map +1 -1
  127. package/dist/targeting/conditions/geolocation.js +1 -1
  128. package/dist/targeting/conditions/geolocation.js.map +1 -1
  129. package/dist/targeting/conditions/index.js +1 -1
  130. package/dist/targeting/conditions/lastVisit.js +1 -1
  131. package/dist/targeting/conditions/lastVisit.js.map +1 -1
  132. package/dist/targeting/conditions/newVisitor.js +1 -1
  133. package/dist/targeting/conditions/newVisitor.js.map +1 -1
  134. package/dist/targeting/conditions/operatingSystem.js +1 -1
  135. package/dist/targeting/conditions/operatingSystem.js.map +1 -1
  136. package/dist/targeting/conditions/pageTitle.js +1 -1
  137. package/dist/targeting/conditions/pageTitle.js.map +1 -1
  138. package/dist/targeting/conditions/pageUrl.js +1 -1
  139. package/dist/targeting/conditions/pageUrl.js.map +1 -1
  140. package/dist/targeting/conditions/previousPage.js +1 -1
  141. package/dist/targeting/conditions/previousPage.js.map +1 -1
  142. package/dist/targeting/conditions/sameDayVisits.js +1 -1
  143. package/dist/targeting/conditions/sameDayVisits.js.map +1 -1
  144. package/dist/targeting/conditions/sdkLanguage.js +1 -1
  145. package/dist/targeting/conditions/sdkLanguage.js.map +1 -1
  146. package/dist/targeting/conditions/segment.js +1 -1
  147. package/dist/targeting/conditions/segment.js.map +1 -1
  148. package/dist/targeting/conditions/targetFeatureFlag.js +1 -1
  149. package/dist/targeting/conditions/targetFeatureFlag.js.map +1 -1
  150. package/dist/targeting/conditions/visitedPages.js +1 -1
  151. package/dist/targeting/conditions/visitedPages.js.map +1 -1
  152. package/dist/targeting/conditions/visitorCode.js +1 -1
  153. package/dist/targeting/conditions/visitorCode.js.map +1 -1
  154. package/dist/targeting/conditions/visits.js +1 -1
  155. package/dist/targeting/conditions/visits.js.map +1 -1
  156. package/dist/targeting/index.js +1 -1
  157. package/dist/targeting/node.js +1 -1
  158. package/dist/targeting/node.js.map +1 -1
  159. package/dist/targeting/tree.js +1 -1
  160. package/dist/targeting/tree.js.map +1 -1
  161. package/dist/targeting/types.js +1 -1
  162. package/dist/targeting/types.js.map +1 -1
  163. package/dist/types.d.ts +14 -26
  164. package/dist/types.js +1 -1
  165. package/dist/types.js.map +1 -1
  166. package/dist/utilities/constants.js +1 -1
  167. package/dist/utilities/constants.js.map +1 -1
  168. package/dist/utilities/index.js +1 -1
  169. package/dist/utilities/types.d.ts +7 -7
  170. package/dist/utilities/types.js +1 -1
  171. package/dist/utilities/types.js.map +1 -1
  172. package/dist/utilities/utilities.js +1 -1
  173. package/dist/utilities/utilities.js.map +1 -1
  174. package/dist/variationConfiguration/index.js +1 -1
  175. package/dist/variationConfiguration/variationConfiguration.d.ts +3 -3
  176. package/dist/variationConfiguration/variationConfiguration.js +1 -1
  177. package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
  178. package/dist/visitorCodeManager/constants.d.ts +3 -0
  179. package/dist/visitorCodeManager/constants.js +2 -0
  180. package/dist/visitorCodeManager/constants.js.map +1 -0
  181. package/dist/visitorCodeManager/index.d.ts +2 -0
  182. package/dist/visitorCodeManager/index.js +1 -1
  183. package/dist/visitorCodeManager/index.js.map +1 -1
  184. package/dist/visitorCodeManager/types.d.ts +7 -0
  185. package/dist/visitorCodeManager/types.js +2 -0
  186. package/dist/visitorCodeManager/types.js.map +1 -0
  187. package/dist/visitorCodeManager/visitorCodeManager.d.ts +11 -8
  188. package/dist/visitorCodeManager/visitorCodeManager.js +1 -1
  189. package/dist/visitorCodeManager/visitorCodeManager.js.map +1 -1
  190. package/package.json +4 -8
  191. package/dist/eventSource/externalEventSource.d.ts +0 -12
  192. package/dist/eventSource/externalEventSource.js +0 -2
  193. package/dist/eventSource/externalEventSource.js.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Conversion=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 Conversion=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=this,c=a.targetingData,d=null===c||void 0===c?void 0:c[_kameleoonData.KameleoonData.Conversion];return this.conditionValue?d?d.length&&-1===this.conditionValue?(0,_tsRes.Ok)(!0):(0,_tsRes.Ok)(d.some(function(a){var c=a.goalId;return c===b.conditionValue})):(0,_tsRes.Ok)(!1):(0,_tsRes.Ok)(!1)}}]),a}();exports.Conversion=Conversion;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Conversion=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class Conversion{constructor(a){let{goalId:b}=a;_defineProperty(this,"conditionValue",void 0),this.conditionValue=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Conversion];return this.conditionValue?c?c.length&&-1===this.conditionValue?(0,_tsRes.Ok)(!0):(0,_tsRes.Ok)(c.some(a=>{let{goalId:b}=a;return b===this.conditionValue})):(0,_tsRes.Ok)(!1):(0,_tsRes.Ok)(!1)}}exports.Conversion=Conversion;
2
2
  //# sourceMappingURL=conversion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"conversion.js","names":["Conversion","a","b","goalId","_classCallCheck","_defineProperty","conditionValue","_createClass","key","value","evaluate","targetingData","conversionData","KameleoonData","length","Ok","some","exports"],"sources":["../../../src/targeting/conditions/conversion.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 Conversion 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 (!this.conditionValue) {\n return Ok(false);\n }\n\n if (conversionData) {\n if (conversionData.length && this.conditionValue === -1) {\n return Ok(true);\n }\n\n return Ok(\n conversionData.some(({ goalId }) => goalId === this.conditionValue),\n );\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"q5CAMa,CAAAA,UAAU,YAGrB,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,KAAAC,CAAA,MADtDS,CAAa,CAAAV,CAAA,CAAbU,aAAa,CAEPC,CAAc,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACb,UAAU,CAAC,OAE3D,KAAI,CAACM,cAAc,CAIpBM,CAAc,CACZA,CAAc,CAACE,MAAM,EAA4B,CAAC,CAAC,GAA1B,IAAI,CAACR,cAAqB,CAC9C,GAAAS,SAAE,KAAM,CAGV,GAAAA,SAAE,EACPH,CAAc,CAACI,IAAI,CAAC,SAAAf,CAAA,KAAG,CAAAE,CAAM,CAAAF,CAAA,CAANE,MAAM,OAAO,CAAAA,CAAM,GAAKD,CAAI,CAACI,cAAc,EAAC,CACpE,CAGI,GAAAS,SAAE,KAAO,CAbP,GAAAA,SAAE,KAcb,CAAC,IAAAd,CAAA,IAAAgB,OAAA,CAAAjB,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"conversion.js","names":["Conversion","constructor","a","goalId","_defineProperty","conditionValue","evaluate","targetingData","conversionData","KameleoonData","length","Ok","some","exports"],"sources":["../../../src/targeting/conditions/conversion.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 Conversion 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 (!this.conditionValue) {\n return Ok(false);\n }\n\n if (conversionData) {\n if (conversionData.length && this.conditionValue === -1) {\n return Ok(true);\n }\n\n return Ok(\n conversionData.some(({ goalId }) => goalId === this.conditionValue),\n );\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"4qBAMO,KAAM,CAAAA,UAAiC,CAG5CC,WAAWA,CAAAC,CAAA,CAAgC,IAA/B,CAAEC,MAAM,CAANA,CAA0B,CAAC,CAAAD,CAAA,CAAAE,eAAA,+BACvC,IAAI,CAACC,cAAc,CAAGF,CACxB,CAEOG,QAAQA,CAAAJ,CAAA,CAEyC,IAFxC,CACdK,aAAa,CAAbA,CACkB,CAAC,CAAAL,CAAA,CACnB,KAAM,CAAAM,CAAc,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACT,UAAU,CAAC,CAAC,MAE5D,KAAI,CAACK,cAAc,CAIpBG,CAAc,CACZA,CAAc,CAACE,MAAM,EAA4B,CAAC,CAAC,GAA1B,IAAI,CAACL,cAAqB,CAC9C,GAAAM,SAAE,IAAK,CAAC,CAGV,GAAAA,SAAE,EACPH,CAAc,CAACI,IAAI,CAACV,CAAA,MAAC,CAAEC,MAAM,CAANA,CAAO,CAAC,CAAAD,CAAA,OAAK,CAAAC,CAAM,GAAK,IAAI,CAACE,cAAc,EACpE,CAAC,CAGI,GAAAM,SAAE,IAAM,CAAC,CAbP,GAAAA,SAAE,IAAM,CAcnB,CACF,CAACE,OAAA,CAAAb,UAAA,CAAAA,UAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cookie=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_utilities=require("../../utilities");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 Cookie=function(){function a(b){var c=b.name,d=b.value,e=b.nameMatchType,f=b.valueMatchType;_classCallCheck(this,a),_defineProperty(this,"cookie",void 0),_defineProperty(this,"keyMatchType",void 0),_defineProperty(this,"valueMatchType",void 0),this.cookie={key:null!==c&&void 0!==c?c:void 0,value:null!==d&&void 0!==d?d:void 0},this.keyMatchType=e,this.valueMatchType=f}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b,c=this,d=a.targetingData,e=!this.cookie.key&&!this.cookie.value,f=!!this.valueMatchType&&!!this.keyMatchType;if(e||!f)return(0,_tsRes.Ok)(!1);var g=this.extractCookie(),h=(null===d||void 0===d||null===(b=d[_kameleoonData.KameleoonData.Cookie])||void 0===b?void 0:b.cookie)||[];return(0,_tsRes.Ok)(g.some(function(a){return c.checkCondition(a)})||h.some(function(a){return c.checkCondition(a)}))}},{key:"extractCookie",value:function extractCookie(){return"undefined"!=typeof document&&document.cookie?_kameleoonData.Cookie.fromString(document.cookie).data.cookie:[]}},{key:"checkCondition",value:function checkCondition(a){var b=this.keyMatchType,c=a.key,d=a.value;if(b===_types.NameMatchType.OPTIONAL){var e=this.cookie;return!!this.isOptionalCookie(e)&&this.compareCookieValue(d,e.value)}var f,g=this.cookie,h=g.key,i=g.value;return b===_types.NameMatchType.EXACT?f=c===h:b===_types.NameMatchType.CONTAINS?f=c.includes(h):b===_types.NameMatchType.REGULAR_EXPRESSION?f=_utilities.Utilities.parseRegExp(h).test(c):(0,_kameleoonError.exhaustCheck)(b),f&&this.compareCookieValue(d,i)}},{key:"compareCookieValue",value:function compareCookieValue(a,b){var c=this.valueMatchType;return c===_types.ValueMatchType.EXACT?a===b:c===_types.ValueMatchType.CONTAINS?a.includes(b):c===_types.ValueMatchType.REGULAR_EXPRESSION&&_utilities.Utilities.parseRegExp(b).test(a)}},{key:"isOptionalCookie",value:function isOptionalCookie(a){var b=a.value;return"undefined"!=typeof b}}]),a}();exports.Cookie=Cookie;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cookie=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_utilities=require("../../utilities");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class Cookie{constructor(a){let{name:b,value:c,nameMatchType:d,valueMatchType:e}=a;_defineProperty(this,"cookie",void 0),_defineProperty(this,"keyMatchType",void 0),_defineProperty(this,"valueMatchType",void 0),this.cookie={key:null!==b&&void 0!==b?b:void 0,value:null!==c&&void 0!==c?c:void 0},this.keyMatchType=d,this.valueMatchType=e}evaluate(a){var b;let{targetingData:c}=a;const d=!this.cookie.key&&!this.cookie.value,e=!!this.valueMatchType&&!!this.keyMatchType;if(d||!e)return(0,_tsRes.Ok)(!1);const f=this.extractCookie(),g=(null===c||void 0===c||null===(b=c[_kameleoonData.KameleoonData.Cookie])||void 0===b?void 0:b.cookie)||[];return(0,_tsRes.Ok)(f.some(a=>this.checkCondition(a))||g.some(a=>this.checkCondition(a)))}extractCookie(){return"undefined"!=typeof document&&document.cookie?_kameleoonData.Cookie.fromString(document.cookie).data.cookie:[]}checkCondition(a){const b=this.keyMatchType,{key:c,value:d}=a;if(b===_types.NameMatchType.OPTIONAL){const a=this.cookie;return!!this.isOptionalCookie(a)&&this.compareCookieValue(d,a.value)}const{key:e,value:f}=this.cookie;let g;return b===_types.NameMatchType.EXACT?g=c===e:b===_types.NameMatchType.CONTAINS?g=c.includes(e):b===_types.NameMatchType.REGULAR_EXPRESSION?g=_utilities.Utilities.parseRegExp(e).test(c):(0,_kameleoonError.exhaustCheck)(b),g&&this.compareCookieValue(d,f)}compareCookieValue(a,b){const c=this.valueMatchType;return c===_types.ValueMatchType.EXACT?a===b:c===_types.ValueMatchType.CONTAINS?a.includes(b):!(c!==_types.ValueMatchType.REGULAR_EXPRESSION)&&_utilities.Utilities.parseRegExp(b).test(a)}isOptionalCookie(a){const{value:b}=a;return"undefined"!=typeof b}}exports.Cookie=Cookie;
2
2
  //# sourceMappingURL=cookie.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cookie.js","names":["Cookie","a","b","name","value","nameMatchType","valueMatchType","_classCallCheck","_defineProperty","cookie","key","keyMatchType","_createClass","evaluate","c","targetingData","isEmptyCookie","isValidMatchType","Ok","extractedCookie","extractCookie","cookieData","KameleoonData","some","pair","checkCondition","document","CookieData","fromString","data","dataCookie","cookieMatchType","NameMatchType","OPTIONAL","conditionCookie","isOptionalCookie","compareCookieValue","keyMatch","g","compareKey","compareValue","EXACT","CONTAINS","includes","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exhaustCheck","ValueMatchType","exports"],"sources":["../../../src/targeting/conditions/cookie.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { Cookie as CookieData, KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport {\n EvaluationDataType,\n NameMatchType,\n ValueMatchType,\n} from 'src/targeting/types';\nimport { CookieType, OptionalCookieType } from 'src/kameleoonData/types';\nimport { Utilities } from 'src/utilities';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class Cookie implements ICondition {\n private cookie: Partial<CookieType>;\n private keyMatchType?: NameMatchType | null;\n private valueMatchType?: ValueMatchType | null;\n\n constructor({\n name,\n value,\n nameMatchType,\n valueMatchType,\n }: ConditionDataType) {\n this.cookie = {\n key: name ?? undefined,\n value: value ?? undefined,\n };\n this.keyMatchType = nameMatchType;\n this.valueMatchType = valueMatchType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const isEmptyCookie = !this.cookie.key && !this.cookie.value;\n const isValidMatchType =\n Boolean(this.valueMatchType) && Boolean(this.keyMatchType);\n\n if (isEmptyCookie || !isValidMatchType) {\n return Ok(false);\n }\n\n const extractedCookie = this.extractCookie();\n const cookieData = targetingData?.[KameleoonData.Cookie]?.cookie || [];\n\n return Ok(\n extractedCookie.some((pair) => this.checkCondition(pair)) ||\n cookieData.some((pair) => this.checkCondition(pair)),\n );\n }\n\n private extractCookie(): CookieType[] {\n if (typeof document !== 'undefined' && document.cookie) {\n return CookieData.fromString(document.cookie).data.cookie;\n }\n\n return [];\n }\n\n private checkCondition(dataCookie: CookieType): boolean {\n const cookieMatchType = this.keyMatchType!;\n const { key, value } = dataCookie;\n\n if (cookieMatchType === NameMatchType.OPTIONAL) {\n const conditionCookie = this.cookie;\n\n return this.isOptionalCookie(conditionCookie)\n ? this.compareCookieValue(value, conditionCookie.value)\n : false;\n }\n\n const { key: compareKey, value: compareValue } = this.cookie as CookieType;\n\n let keyMatch: boolean;\n\n switch (cookieMatchType) {\n case NameMatchType.EXACT:\n keyMatch = key === compareKey;\n break;\n case NameMatchType.CONTAINS:\n keyMatch = key.includes(compareKey);\n break;\n case NameMatchType.REGULAR_EXPRESSION:\n keyMatch = Utilities.parseRegExp(compareKey).test(key);\n break;\n default:\n exhaustCheck(cookieMatchType);\n }\n\n return keyMatch && this.compareCookieValue(value, compareValue);\n }\n\n private compareCookieValue(value: string, compareValue: string): boolean {\n const valueMatchType = this.valueMatchType!;\n\n switch (valueMatchType) {\n case ValueMatchType.EXACT:\n return value === compareValue;\n case ValueMatchType.CONTAINS:\n return value.includes(compareValue);\n case ValueMatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(compareValue).test(value);\n default:\n return false;\n }\n }\n\n private isOptionalCookie(\n cookie: Partial<CookieType>,\n ): cookie is OptionalCookieType {\n const { value } = cookie;\n\n return typeof value !== 'undefined';\n }\n}\n"],"mappings":"kgDAYa,CAAAA,MAAM,YAKjB,SAAAC,EAAAC,CAAA,CAKsB,IAJpB,CAAAC,CAAI,CAAAD,CAAA,CAAJC,IAAI,CACJC,CAAK,CAAAF,CAAA,CAALE,KAAK,CACLC,CAAa,CAAAH,CAAA,CAAbG,aAAa,CACbC,CAAc,CAAAJ,CAAA,CAAdI,cAAc,CAAAC,eAAA,MAAAN,CAAA,EAAAO,eAAA,uBAAAA,eAAA,6BAAAA,eAAA,+BAEd,IAAI,CAACC,MAAM,CAAG,CACZC,GAA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c,GACf2C,qBAAc,CAACR,KAAK,CAChBrC,CAAK,GAAKoC,CAAY,CAFzBlC,CAAc,GAGf2C,qBAAc,CAACP,QAAQ,CACnBtC,CAAK,CAACuC,QAAQ,CAACH,CAAY,CAAC,CAJ/BlC,CAAc,GAKf2C,qBAAc,CAACL,kBAAkB,EAC7BC,oBAAS,CAACC,WAAW,CAACN,CAAY,CAAC,CAACO,IAAI,CAAC3C,CAAK,CAI3D,CAAC,GAAAM,GAAA,oBAAAN,KAAA,CAED,SAAA+B,iBACE1B,CAA2B,CACG,CAC9B,GAAQ,CAAAL,CAAK,CAAKK,CAAM,CAAhBL,KAAK,CAEb,MAAwB,WAAW,EAA5B,MAAO,CAAAA,CAChB,CAAC,IAAAH,CAAA,IAAAiD,OAAA,CAAAlD,MAAA,CAAAA,MAAA"}
1
+ {"version":3,"file":"cookie.js","names":["Cookie","constructor","a","name","value","nameMatchType","valueMatchType","_defineProperty","cookie","key","keyMatchType","evaluate","b","targetingData","isEmptyCookie","isValidMatchType","Ok","extractedCookie","extractCookie","cookieData","KameleoonData","some","pair","checkCondition","document","CookieData","fromString","data","dataCookie","cookieMatchType","NameMatchType","OPTIONAL","conditionCookie","isOptionalCookie","compareCookieValue","compareKey","compareValue","keyMatch","EXACT","CONTAINS","includes","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exhaustCheck","ValueMatchType","exports"],"sources":["../../../src/targeting/conditions/cookie.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { Cookie as CookieData, KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport {\n EvaluationDataType,\n NameMatchType,\n ValueMatchType,\n} from 'src/targeting/types';\nimport { CookieType, OptionalCookieType } from 'src/kameleoonData/types';\nimport { Utilities } from 'src/utilities';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class Cookie implements ICondition {\n private cookie: Partial<CookieType>;\n private keyMatchType?: NameMatchType | null;\n private valueMatchType?: ValueMatchType | null;\n\n constructor({\n name,\n value,\n nameMatchType,\n valueMatchType,\n }: ConditionDataType) {\n this.cookie = {\n key: name ?? undefined,\n value: value ?? undefined,\n };\n this.keyMatchType = nameMatchType;\n this.valueMatchType = valueMatchType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const isEmptyCookie = !this.cookie.key && !this.cookie.value;\n const isValidMatchType =\n Boolean(this.valueMatchType) && Boolean(this.keyMatchType);\n\n if (isEmptyCookie || !isValidMatchType) {\n return Ok(false);\n }\n\n const extractedCookie = this.extractCookie();\n const cookieData = targetingData?.[KameleoonData.Cookie]?.cookie || [];\n\n return Ok(\n extractedCookie.some((pair) => this.checkCondition(pair)) ||\n cookieData.some((pair) => this.checkCondition(pair)),\n );\n }\n\n private extractCookie(): CookieType[] {\n if (typeof document !== 'undefined' && document.cookie) {\n return CookieData.fromString(document.cookie).data.cookie;\n }\n\n return [];\n }\n\n private checkCondition(dataCookie: CookieType): boolean {\n const cookieMatchType = this.keyMatchType!;\n const { key, value } = dataCookie;\n\n if (cookieMatchType === NameMatchType.OPTIONAL) {\n const conditionCookie = this.cookie;\n\n return this.isOptionalCookie(conditionCookie)\n ? this.compareCookieValue(value, conditionCookie.value)\n : false;\n }\n\n const { key: compareKey, value: compareValue } = this.cookie as CookieType;\n\n let keyMatch: boolean;\n\n switch (cookieMatchType) {\n case NameMatchType.EXACT:\n keyMatch = key === compareKey;\n break;\n case NameMatchType.CONTAINS:\n keyMatch = key.includes(compareKey);\n break;\n case NameMatchType.REGULAR_EXPRESSION:\n keyMatch = Utilities.parseRegExp(compareKey).test(key);\n break;\n default:\n exhaustCheck(cookieMatchType);\n }\n\n return keyMatch && this.compareCookieValue(value, compareValue);\n }\n\n private compareCookieValue(value: string, compareValue: string): boolean {\n const valueMatchType = this.valueMatchType!;\n\n switch (valueMatchType) {\n case ValueMatchType.EXACT:\n return value === compareValue;\n case ValueMatchType.CONTAINS:\n return value.includes(compareValue);\n case ValueMatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(compareValue).test(value);\n default:\n return false;\n }\n }\n\n private isOptionalCookie(\n cookie: Partial<CookieType>,\n ): cookie is OptionalCookieType {\n const { value } = cookie;\n\n return typeof value !== 'undefined';\n }\n}\n"],"mappings":"yxBAYO,KAAM,CAAAA,MAA6B,CAKxCC,WAAWA,CAAAC,CAAA,CAKW,IALV,CACVC,IAAI,CAAJA,CAAI,CACJC,KAAK,CAALA,CAAK,CACLC,aAAa,CAAbA,CAAa,CACbC,cAAc,CAAdA,CACiB,CAAC,CAAAJ,CAAA,CAAAK,eAAA,uBAAAA,eAAA,6BAAAA,eAAA,+BAClB,IAAI,CAACC,MAAM,CAAG,CACZC,GAAG,QAAEN,CAAI,WAAJA,CAAI,CAAJA,CAAI,OAAa,CACtBC,KAAK,QAAEA,CAAK,WAALA,CAAK,CAALA,CAAK,OACd,CAAC,CACD,IAAI,CAACM,YAAY,CAAGL,CAAa,CACjC,IAAI,CAACC,cAAc,CAAGA,CACxB,CAEOK,QAAQA,CAAAT,CAAA,CAEyC,KAAAU,CAAA,IAFxC,CACdC,aAAa,CAAbA,CACkB,CAAC,CAAAX,CAAA,MACb,CAAAY,CAAa,CAAG,CAAC,IAAI,CAACN,MAAM,CAACC,GAAG,EAAI,CAAC,IAAI,CAACD,MAAM,CAACJ,KAAK,CACtDW,CAAgB,CACpB,EAAQ,IAAI,CAACT,cAAc,IAAa,IAAI,CAACI,YAAa,CAE5D,GAAII,CAAa,EAAI,CAACC,CAAgB,CACpC,MAAO,GAAAC,SAAE,IAAM,CAAC,CACjB,KAEK,CAAAC,CAAe,CAAG,IAAI,CAACC,aAAa,CAAC,CAAC,CACtCC,CAAU,CAAG,QAAAN,CAAa,WAAbA,CAAa,UAAAD,CAAA,CAAbC,CAAa,CAAGO,4BAAa,CAACpB,MAAM,CAAC,YAAAY,CAAA,QAArCA,CAAA,CAAuCJ,MAAM,GAAI,EAAE,CAEtE,MAAO,GAAAQ,SAAE,EACPC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CAGtD,GAAAoC,4BAAY,EAAChB,CAAe,CAAC,CAG1BQ,CAAQ,EAAI,IAAI,CAACH,kBAAkB,CAAC9B,CAAK,CAAEgC,CAAY,CAChE,CAEQF,kBAAkBA,CAAC9B,CAAa,CAAEgC,CAAoB,CAAW,CACvE,KAAM,CAAA9B,CAAc,CAAG,IAAI,CAACA,cAAe,CAAC,MAEpC,CAAAA,CAAc,GACfwC,qBAAc,CAACR,KAAK,CAChBlC,CAAK,GAAKgC,CAAY,CAFzB9B,CAAc,GAGfwC,qBAAc,CAACP,QAAQ,CACnBnC,CAAK,CAACoC,QAAQ,CAACJ,CAAY,CAAC,GAJ/B9B,CAAc,GAKfwC,qBAAc,CAACL,kBAAkB,GAC7BC,oBAAS,CAACC,WAAW,CAACP,CAAY,CAAC,CAACQ,IAAI,CAACxC,CAAK,CAI3D,CAEQ6B,gBAAgBA,CACtBzB,CAA2B,CACG,CAC9B,KAAM,CAAEJ,KAAK,CAALA,CAAM,CAAC,CAAGI,CAAM,CAExB,MAAwB,WAAW,EAA5B,MAAO,CAAAJ,CAChB,CACF,CAAC2C,OAAA,CAAA/C,MAAA,CAAAA,MAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=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 CustomData=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?+c:null,this.matchType=d,this.conditionValue=e}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.targetingData;if("number"==typeof this.customDataIndex){var c,d=null===b||void 0===b||null===(c=b[_kameleoonData.KameleoonData.CustomData])||void 0===c?void 0:c[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.ValueMatchType.UNDEFINED)}},{key:"checkCondition",value:function checkCondition(a){var b=this;if("string"!=typeof this.conditionValue&&this.matchType!==_types.ValueMatchType.TRUE&&this.matchType!==_types.ValueMatchType.FALSE)return!1;var c=this.conditionValue;if(this.matchType===_types.ValueMatchType.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.ValueMatchType.CONTAINS:return a.includes(c);case _types.ValueMatchType.EXACT:return a===this.conditionValue;case _types.ValueMatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(c).test(a);case _types.ValueMatchType.LOWER:return+a<+this.conditionValue;case _types.ValueMatchType.EQUAL:return+a===+this.conditionValue;case _types.ValueMatchType.GREATER:return+a>+this.conditionValue;case _types.ValueMatchType.TRUE:return"true"===a.toLowerCase();case _types.ValueMatchType.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.CustomData=CustomData;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_utilities=require("../../utilities"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class CustomData{constructor(a){let{customDataIndex:b,valueMatchType:c,value:d}=a;_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),this.customDataIndex=b?+b:null,this.matchType=c,this.conditionValue=d}evaluate(a){let{targetingData:b}=a;if("number"==typeof this.customDataIndex){var c;const a=null===b||void 0===b||null===(c=b[_kameleoonData.KameleoonData.CustomData])||void 0===c?void 0:c[this.customDataIndex];if(a){const{value:b}=a,c=this.checkCondition(b);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(c)}}return(0,_tsRes.Ok)(this.matchType===_types.ValueMatchType.UNDEFINED)}checkCondition(a){if("string"!=typeof this.conditionValue&&this.matchType!==_types.ValueMatchType.TRUE&&this.matchType!==_types.ValueMatchType.FALSE)return!1;const b=this.conditionValue;if(this.matchType===_types.ValueMatchType.AMONG_VALUES){const c=this.parseArray(b);if(!c.ok)return this.error=c.error,!1;const d=new Set(c.data);return Array.isArray(a)?a.some(a=>d.has(a)):c.data.includes(a)}if(Array.isArray(a))return a.some(a=>this.checkCondition(a));switch(this.matchType){case _types.ValueMatchType.CONTAINS:return a.includes(b);case _types.ValueMatchType.EXACT:return a===this.conditionValue;case _types.ValueMatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(b).test(a);case _types.ValueMatchType.LOWER:return+a<+this.conditionValue;case _types.ValueMatchType.EQUAL:return+a===+this.conditionValue;case _types.ValueMatchType.GREATER:return+a>+this.conditionValue;case _types.ValueMatchType.TRUE:return"true"===a.toLowerCase();case _types.ValueMatchType.FALSE:return"false"===a.toLowerCase();default:return!1}}parseArray(a){try{const 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)([])}}exports.CustomData=CustomData;
2
2
  //# sourceMappingURL=customData.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customData.js","names":["CustomData","a","b","customDataIndex","valueMatchType","value","_classCallCheck","_defineProperty","matchType","conditionValue","_createClass","key","evaluate","targetingData","c","customData","KameleoonData","customDataValue","result","checkCondition","error","Err","Ok","ValueMatchType","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/customData.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, ValueMatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class CustomData implements ICondition {\n private customDataIndex: number | null;\n private matchType?: ValueMatchType | null;\n private conditionValue?: string | null;\n private error?: KameleoonError;\n\n constructor({ customDataIndex, valueMatchType, value }: ConditionDataType) {\n this.customDataIndex = customDataIndex ? Number(customDataIndex) : null;\n this.matchType = valueMatchType;\n this.conditionValue = value;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n if (typeof this.customDataIndex === 'number') {\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\n return Ok(this.matchType === ValueMatchType.UNDEFINED);\n }\n\n private checkCondition(\n customDataValue: CustomDataType['value'] | string,\n ): boolean {\n if (\n typeof this.conditionValue !== 'string' &&\n this.matchType !== ValueMatchType.TRUE &&\n this.matchType !== ValueMatchType.FALSE\n ) {\n return false;\n }\n\n // --- Note ---\n // `ValueMatchType.TRUE` and `ValueMatchType.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 === ValueMatchType.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 ValueMatchType.CONTAINS:\n return customDataValue.includes(conditionValue);\n case ValueMatchType.EXACT:\n return customDataValue === this.conditionValue;\n case ValueMatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(conditionValue).test(customDataValue);\n case ValueMatchType.LOWER:\n return Number(customDataValue) < Number(this.conditionValue);\n case ValueMatchType.EQUAL:\n return Number(customDataValue) === Number(this.conditionValue);\n case ValueMatchType.GREATER:\n return Number(customDataValue) > Number(this.conditionValue);\n case ValueMatchType.TRUE:\n return customDataValue.toLowerCase() === 'true';\n case ValueMatchType.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":"sgDAOa,CAAAA,UAAU,YAMrB,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,CAAGA,CAAe,EAAUA,CAAe,CAAI,IAAI,CACvE,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,IADtD,CAAAY,CAAa,CAAAZ,CAAA,CAA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ClE,GAAI,CACF,GAAM,CAAAa,CAAM,CAAG8B,IAAI,CAACC,KAAK,CAAC5C,CAAK,CAAC,CAEhC,GAAI4B,KAAK,CAACC,OAAO,CAAChB,CAAM,CAAC,CACvB,MAAO,GAAAI,SAAE,EAACJ,CAAM,CAEpB,CAAE,MAAOgC,CAAG,CAAE,CACZ,MAAO,GAAA7B,UAAG,EACR,GAAI,CAAA8B,8BAAc,CAACC,kCAAkB,CAACC,gBAAgB,CAAEH,CAAG,CAAE7C,CAAK,CAAC,CAEvE,CAEA,MAAO,GAAAiB,SAAE,EAAC,EAAE,CACd,CAAC,IAAArB,CAAA,IAAAqD,OAAA,CAAAtD,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"customData.js","names":["CustomData","constructor","a","customDataIndex","valueMatchType","value","_defineProperty","matchType","conditionValue","evaluate","targetingData","c","customData","KameleoonData","customDataValue","result","checkCondition","error","Err","Ok","ValueMatchType","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/customData.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, ValueMatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class CustomData implements ICondition {\n private customDataIndex: number | null;\n private matchType?: ValueMatchType | null;\n private conditionValue?: string | null;\n private error?: KameleoonError;\n\n constructor({ customDataIndex, valueMatchType, value }: ConditionDataType) {\n this.customDataIndex = customDataIndex ? Number(customDataIndex) : null;\n this.matchType = valueMatchType;\n this.conditionValue = value;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n if (typeof this.customDataIndex === 'number') {\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\n return Ok(this.matchType === ValueMatchType.UNDEFINED);\n }\n\n private checkCondition(\n customDataValue: CustomDataType['value'] | string,\n ): boolean {\n if (\n typeof this.conditionValue !== 'string' &&\n this.matchType !== ValueMatchType.TRUE &&\n this.matchType !== ValueMatchType.FALSE\n ) {\n return false;\n }\n\n // --- Note ---\n // `ValueMatchType.TRUE` and `ValueMatchType.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 === ValueMatchType.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 ValueMatchType.CONTAINS:\n return customDataValue.includes(conditionValue);\n case ValueMatchType.EXACT:\n return customDataValue === this.conditionValue;\n case ValueMatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(conditionValue).test(customDataValue);\n case ValueMatchType.LOWER:\n return Number(customDataValue) < Number(this.conditionValue);\n case ValueMatchType.EQUAL:\n return Number(customDataValue) === Number(this.conditionValue);\n case ValueMatchType.GREATER:\n return Number(customDataValue) > Number(this.conditionValue);\n case ValueMatchType.TRUE:\n return customDataValue.toLowerCase() === 'true';\n case ValueMatchType.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":"6xBAOO,KAAM,CAAAA,UAAiC,CAM5CC,WAAWA,CAAAC,CAAA,CAAgE,IAA/D,CAAEC,eAAe,CAAfA,CAAe,CAAEC,cAAc,CAAdA,CAAc,CAAEC,KAAK,CAALA,CAAyB,CAAC,CAAAH,CAAA,CAAAI,eAAA,gCAAAA,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,sBACvE,IAAI,CAACH,eAAe,CAAGA,CAAe,EAAUA,CAAe,CAAI,IAAI,CACvE,IAAI,CAACI,SAAS,CAAGH,CAAc,CAC/B,IAAI,CAACI,cAAc,CAAGH,CACxB,CAEOI,QAAQA,CAAAP,CAAA,CAEyC,IAFxC,CACdQ,aAAa,CAAbA,CACkB,CAAC,CAAAR,CAAA,CACnB,GAAoC,QAAQ,EAAxC,MAAO,KAAI,CAACC,eAA4B,CAAE,KAAAQ,CAAA,CAC5C,KAAM,CAAAC,CAAU,QACdF,CAAa,WAAbA,CAAa,UAAAC,CAAA,CAAbD,CAAa,CAAGG,4BAAa,CAACb,UAAU,CAAC,YAAAW,CAAA,QAAzCA,CAAA,CAA4C,IAAI,CAACR,eAAe,CAAC,CAEnE,GAAIS,CAAU,CAAE,MACR,CAAEP,KAAK,CAAES,CAAgB,CAAC,CAAGF,CAAU,CACvCG,CAAM,CAAG,IAAI,CAACC,cAAc,CAACF,CAAe,CAAC,OAE/C,KAAI,CAACG,KAAK,CACL,GAAAC,UAAG,EAAC,IAAI,CAACD,KAAK,CAAC,CAGjB,GAAAE,SAAE,EAACJ,CAAM,CAClB,CACF,CAEA,MAAO,GAAAI,SAAE,EAAC,IAAI,CAACZ,SAAS,GAAKa,qBAAc,CAACC,SAAS,CACvD,CAE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AAC,CAACgC,IAAI,CAAC1B,CAAe,CAAC,CACpE,IAAK,CAAAM,qBAAc,CAACqB,KAAK,CACvB,MAAO,CAAO3B,CAAe,EAAW,IAAI,CAACN,cAAe,CAC9D,IAAK,CAAAY,qBAAc,CAACsB,KAAK,CACvB,MAAO,CAAO5B,CAAe,IAAa,IAAI,CAACN,cAAe,CAChE,IAAK,CAAAY,qBAAc,CAACuB,OAAO,CACzB,MAAO,CAAO7B,CAAe,EAAW,IAAI,CAACN,cAAe,CAC9D,IAAK,CAAAY,qBAAc,CAACE,IAAI,CACtB,MAAyC,MAAM,GAAxCR,CAAe,CAAC8B,WAAW,CAAC,CAAY,CACjD,IAAK,CAAAxB,qBAAc,CAACG,KAAK,CACvB,MAAyC,OAAO,GAAzCT,CAAe,CAAC8B,WAAW,CAAC,CAAa,CAClD,QACE,QACJ,CACF,CAEQnB,UAAUA,CAACpB,CAAa,CAAoC,CAClE,GAAI,CACF,KAAM,CAAAU,CAAM,CAAG8B,IAAI,CAACC,KAAK,CAACzC,CAAK,CAAC,CAEhC,GAAIyB,KAAK,CAACC,OAAO,CAAChB,CAAM,CAAC,CACvB,MAAO,GAAAI,SAAE,EAACJ,CAAM,CAEpB,CAAE,MAAOgC,CAAG,CAAE,CACZ,MAAO,GAAA7B,UAAG,EACR,GAAI,CAAA8B,8BAAc,CAACC,kCAAkB,CAACC,gBAAgB,CAAEH,CAAG,CAAE1C,CAAK,CACpE,CACF,CAEA,MAAO,GAAAc,SAAE,EAAC,EAAE,CACd,CACF,CAACgC,OAAA,CAAAnD,UAAA,CAAAA,UAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Device=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 Device=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.Device=Device;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Device=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class Device{constructor(a){let{device:b}=a;_defineProperty(this,"device",void 0),this.device=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Device];if(c){const{device:a}=c;return(0,_tsRes.Ok)(a===this.device)}return(0,_tsRes.Ok)(!1)}}exports.Device=Device;
2
2
  //# sourceMappingURL=device.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"device.js","names":["Device","a","b","device","_classCallCheck","_defineProperty","_createClass","key","value","evaluate","targetingData","deviceData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/device.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 Device 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":"i5CAMa,CAAAA,MAAM,YAGjB,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,CAACZ,MAAM,CAAC,CAExD,GAAIW,CAAU,CAAE,CACd,GAAQ,CAAAR,CAAM,CAAKQ,CAAU,CAArBR,MAAM,CAEd,MAAO,GAAAU,SAAE,EAACV,CAAM,GAAK,IAAI,CAACA,MAAM,CAClC,CAEA,MAAO,GAAAU,SAAE,KACX,CAAC,IAAAZ,CAAA,IAAAa,OAAA,CAAAd,MAAA,CAAAA,MAAA"}
1
+ {"version":3,"file":"device.js","names":["Device","constructor","a","device","_defineProperty","evaluate","targetingData","deviceData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/device.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 Device 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":"wqBAMO,KAAM,CAAAA,MAA6B,CAGxCC,WAAWA,CAAAC,CAAA,CAAgC,IAA/B,CAAEC,MAAM,CAANA,CAA0B,CAAC,CAAAD,CAAA,CAAAE,eAAA,uBACvC,IAAI,CAACD,MAAM,CAAGA,CAChB,CAEOE,QAAQA,CAAAH,CAAA,CAEyC,IAFxC,CACdI,aAAa,CAAbA,CACkB,CAAC,CAAAJ,CAAA,CACnB,KAAM,CAAAK,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACR,MAAM,CAAC,CAExD,GAAIO,CAAU,CAAE,CACd,KAAM,CAAEJ,MAAM,CAANA,CAAO,CAAC,CAAGI,CAAU,CAE7B,MAAO,GAAAE,SAAE,EAACN,CAAM,GAAK,IAAI,CAACA,MAAM,CAClC,CAEA,MAAO,GAAAM,SAAE,IAAM,CACjB,CACF,CAACC,OAAA,CAAAV,MAAA,CAAAA,MAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";var _tsRes=require("ts-res");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExclusiveCampaign=void 0;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 ExclusiveCampaign=function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.variationData,c=a.experimentId,d=Object.keys(b),e=!d.length,f=1===d.length&&d[0]===c+"";return(0,_tsRes.Ok)(e||f)}}]),a}();exports.ExclusiveCampaign=ExclusiveCampaign;
1
+ "use strict";var _tsRes=require("ts-res");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ExclusiveCampaign=void 0;class ExclusiveCampaign{evaluate(a){let{variationData:b,experimentId:c}=a;const d=Object.keys(b),e=!d.length,f=1===d.length&&d[0]===c+"";return(0,_tsRes.Ok)(e||f)}}exports.ExclusiveCampaign=ExclusiveCampaign;
2
2
  //# sourceMappingURL=exclusiveCampaign.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exclusiveCampaign.js","names":["_tsRes","require","Object","defineProperty","exports","value","ExclusiveCampaign","_typeof","a","Symbol","iterator","constructor","prototype","_classCallCheck","b","TypeError","_defineProperties","c","d","length","enumerable","configurable","writable","_toPropertyKey","key","_createClass","_toPrimitive","toPrimitive","call","String","Number","evaluate","variationData","experimentId","keys","isEmpty","isExclusive","Ok"],"sources":["../../../src/targeting/conditions/exclusiveCampaign.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ICondition } from './types';\n\nexport class ExclusiveCampaign implements ICondition {\n evaluate({\n variationData,\n experimentId,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const keys = Object.keys(variationData);\n const isEmpty = !keys.length;\n // --- Note ---\n // Checking exclusiveness is done by checking if there is only one experiment id with variation\n // and the next assigned experiment id will overwrite the previous one\n // (thus, still leaving one exclusive experiment)\n const isExclusive = keys.length === 1 && keys[0] === String(experimentId);\n const isSatisfied = isEmpty || isExclusive;\n\n return Ok(isSatisfied);\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,WAAoCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,iBAAA,iBAAAC,QAAAC,CAAA,mCAAAD,OAAA,oBAAAE,MAAA,mBAAAA,MAAA,CAAAC,QAAA,UAAAF,CAAA,gBAAAA,CAAA,WAAAA,CAAA,SAAAA,CAAA,qBAAAC,MAAA,EAAAD,CAAA,CAAAG,WAAA,GAAAF,MAAA,EAAAD,CAAA,GAAAC,MAAA,CAAAG,SAAA,iBAAAJ,CAAA,EAAAD,OAAA,CAAAC,CAAA,WAAAK,gBAAAL,CAAA,CAAAM,CAAA,OAAAN,CAAA,YAAAM,CAAA,YAAAC,SAAA,+CAAAC,kBAAAR,CAAA,CAAAM,CAAA,UAAAG,CAAA,CAAAC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A,CAAZyB,YAAY,CAENC,CAAI,CAAGhC,MAAM,CAACgC,IAAI,CAACF,CAAa,CAAC,CACjCG,CAAO,CAAG,CAACD,CAAI,CAACf,MAAM,CAKtBiB,CAAW,CAAmB,CAAC,GAAjBF,CAAI,CAACf,MAAY,EAAIe,CAAI,CAAC,CAAC,CAAC,GAAYD,CAAY,GAAC,CAGzE,MAAO,GAAAI,SAAE,EAFWF,CAAO,EAAIC,CAAW,CAG5C,CAAC,IAAA5B,CAAA,IAAAJ,OAAA,CAAAE,iBAAA,CAAAA,iBAAA"}
1
+ {"version":3,"file":"exclusiveCampaign.js","names":["_tsRes","require","Object","defineProperty","exports","value","ExclusiveCampaign","evaluate","a","variationData","experimentId","keys","isEmpty","length","isExclusive","Ok"],"sources":["../../../src/targeting/conditions/exclusiveCampaign.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ICondition } from './types';\n\nexport class ExclusiveCampaign implements ICondition {\n evaluate({\n variationData,\n experimentId,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const keys = Object.keys(variationData);\n const isEmpty = !keys.length;\n // --- Note ---\n // Checking exclusiveness is done by checking if there is only one experiment id with variation\n // and the next assigned experiment id will overwrite the previous one\n // (thus, still leaving one exclusive experiment)\n const isExclusive = keys.length === 1 && keys[0] === String(experimentId);\n const isSatisfied = isEmpty || isExclusive;\n\n return Ok(isSatisfied);\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,WAAoCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,iBAAA,QAK7B,KAAM,CAAAA,iBAAwC,CACnDC,QAAQA,CAAAC,CAAA,CAGgD,IAH/C,CACPC,aAAa,CAAbA,CAAa,CACbC,YAAY,CAAZA,CACkB,CAAC,CAAAF,CAAA,MACb,CAAAG,CAAI,CAAGT,MAAM,CAACS,IAAI,CAACF,CAAa,CAAC,CACjCG,CAAO,CAAG,CAACD,CAAI,CAACE,MAAM,CAKtBC,CAAW,CAAmB,CAAC,GAAjBH,CAAI,CAACE,MAAY,EAAIF,CAAI,CAAC,CAAC,CAAC,GAAYD,CAAY,GAAC,CAGzE,MAAO,GAAAK,SAAE,EAFWH,CAAO,EAAIE,CAEV,CACvB,CACF,CAACV,OAAA,CAAAE,iBAAA,CAAAA,iBAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirstVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_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 FirstVisit=function(){function a(b){var c=b.matchType,d=b.count,e=b.unitOfTime;_classCallCheck(this,a),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=c,this.conditionValue=d,this.timeUnit=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.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);var d=c.currentVisit,e=c.previousVisits,f=e.length?e[0]:d;return"number"==typeof f?(0,_tsRes.Ok)(this.checkCondition(f)):(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;var b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types.MatchType.GREATER:return c>this.conditionValue;case _types.MatchType.LOWER:return c<this.conditionValue;default:return!1;}}}]),a}();exports.FirstVisit=FirstVisit;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirstVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class FirstVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);const{currentVisit:d,previousVisits:e}=c,f=e.length?e[0]:d;return"number"==typeof f?(0,_tsRes.Ok)(this.checkCondition(f)):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;const b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types.MatchType.GREATER:return c>this.conditionValue;case _types.MatchType.LOWER:return c<this.conditionValue;default:return!1}}}exports.FirstVisit=FirstVisit;
2
2
  //# sourceMappingURL=firstVisit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"firstVisit.js","names":["FirstVisit","a","b","matchType","count","unitOfTime","_classCallCheck","_defineProperty","conditionValue","timeUnit","_createClass","key","value","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","firstVisitTimestamp","length","checkCondition","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/firstVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class FirstVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n const firstVisitTimestamp = previousVisits.length\n ? previousVisits[0]\n : currentVisit;\n\n if (typeof firstVisitTimestamp !== 'number') {\n return Ok(false);\n }\n\n return Ok(this.checkCondition(firstVisitTimestamp));\n }\n\n private checkCondition(firstVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - firstVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"s9CAOa,CAAAA,UAAU,YAKrB,SAAAC,EAAAC,CAAA,CAAiE,IAAnD,CAAAC,CAAS,CAAAD,CAAA,CAATC,SAAS,CAAEC,CAAK,CAAAF,CAAA,CAALE,KAAK,CAAEC,CAAU,CAAAH,CAAA,CAAVG,UAAU,CAAAC,eAAA,MAAAL,CAAA,EAAAM,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBACxC,IAAI,CAACJ,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACK,cAAc,CAAGJ,CAAK,CAC3B,IAAI,CAACK,QAAQ,CAAGJ,CAClB,CAAC,OAAAK,YAAA,CAAAT,CAAA,GAAAU,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAZ,CAAA,CAEwD,IADtD,CAAAa,CAAa,CAAAb,CAAA,CAAba,aAAa,CAEPC,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,CACb,MAAO,GAAAG,SAAE,KAAO,CACjB,GAEO,CAAAC,CAAY,CAAqBJ,CAAU,CAA3CI,YAAY,CAAEC,CAAc,CAAKL,CAAU,CAA7BK,cAAc,CAE9BC,CAAmB,CAAGD,CAAc,CAACE,MAAM,CAC7CF,CAAc,CAAC,CAAC,CAAC,CACjBD,CAAY,OAEmB,QAAQ,EAAvC,MAAO,CAAAE,CAAgC,CAIpC,GAAAH,SAAE,EAAC,IAAI,CAACK,cAAc,CAACF,CAAmB,CAAC,CAAC,CAH1C,GAAAH,SAAE,KAIb,CAAC,GAAAP,GAAA,kBAAAC,KAAA,CAED,SAAAW,eAAuBF,CAA2B,CAAW,CAC3D,GACE,CAAC,IAAI,CAAClB,SAAS,EACgB,QAAQ,EAAvC,MAAO,KAAI,CAACK,cAA2B,EACvC,CAAC,IAAI,CAACC,QAAQ,CAEd,SACD,GAEK,CAAAe,CAAuB,CAAGC,IAAI,CAACC,GAAG,EAAE,CAAGL,CAAmB,CAC1DM,CAAe,CAAGC,oBAAS,CAACC,eAAe,CAC/CL,CAAuB,CACvB,IAAI,CAACf,QAAQ,CACd,CAED,OAAQ,IAAI,CAACN,SAAS,EACpB,IAAK,CAAA2B,gBAAS,CAACC,OAAO,CACpB,MAAO,CAAAJ,CAAe,CAAG,IAAI,CAACnB,cAAc,CAC9C,IAAK,CAAAsB,gBAAS,CAACE,KAAK,CAClB,MAAO,CAAAL,CAAe,CAAG,IAAI,CAACnB,cAAc,CAC9C,QACE,SAAa,CAEnB,CAAC,IAAAP,CAAA,IAAAgC,OAAA,CAAAjC,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"firstVisit.js","names":["FirstVisit","constructor","a","matchType","count","unitOfTime","_defineProperty","conditionValue","timeUnit","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","firstVisitTimestamp","length","checkCondition","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/firstVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class FirstVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n const firstVisitTimestamp = previousVisits.length\n ? previousVisits[0]\n : currentVisit;\n\n if (typeof firstVisitTimestamp !== 'number') {\n return Ok(false);\n }\n\n return Ok(this.checkCondition(firstVisitTimestamp));\n }\n\n private checkCondition(firstVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - firstVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"6uBAOO,KAAM,CAAAA,UAAiC,CAK5CC,WAAWA,CAAAC,CAAA,CAAsD,IAArD,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAK,CAAEC,UAAU,CAAVA,CAA8B,CAAC,CAAAH,CAAA,CAAAI,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBAC7D,IAAI,CAACH,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACI,cAAc,CAAGH,CAAK,CAC3B,IAAI,CAACI,QAAQ,CAAGH,CAClB,CAEOI,QAAQA,CAAAP,CAAA,CAEyC,IAFxC,CACdQ,aAAa,CAAbA,CACkB,CAAC,CAAAR,CAAA,CACnB,KAAM,CAAAS,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,CACb,MAAO,GAAAG,SAAE,IAAM,CAAC,CACjB,KAEK,CAAEC,YAAY,CAAZA,CAAY,CAAEC,cAAc,CAAdA,CAAe,CAAC,CAAGL,CAAU,CAE7CM,CAAmB,CAAGD,CAAc,CAACE,MAAM,CAC7CF,CAAc,CAAC,CAAC,CAAC,CACjBD,CAAY,OAEmB,QAAQ,EAAvC,MAAO,CAAAE,CAAgC,CAIpC,GAAAH,SAAE,EAAC,IAAI,CAACK,cAAc,CAACF,CAAmB,CAAC,CAAC,CAH1C,GAAAH,SAAE,IAAM,CAInB,CAEQK,cAAcA,CAACF,CAA2B,CAAW,CAC3D,GACE,CAAC,IAAI,CAACd,SAAS,EACgB,QAAQ,EAAvC,MAAO,KAAI,CAACI,cAA2B,EACvC,CAAC,IAAI,CAACC,QAAQ,CAEd,SACD,KAEK,CAAAY,CAAuB,CAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAGL,CAAmB,CAC1DM,CAAe,CAAGC,oBAAS,CAACC,eAAe,CAC/CL,CAAuB,CACvB,IAAI,CAACZ,QACP,CAAC,CAED,OAAQ,IAAI,CAACL,SAAS,EACpB,IAAK,CAAAuB,gBAAS,CAACC,OAAO,CACpB,MAAO,CAAAJ,CAAe,CAAG,IAAI,CAAChB,cAAc,CAC9C,IAAK,CAAAmB,gBAAS,CAACE,KAAK,CAClB,MAAO,CAAAL,CAAe,CAAG,IAAI,CAAChB,cAAc,CAC9C,QACE,QACJ,CACF,CACF,CAACsB,OAAA,CAAA7B,UAAA,CAAAA,UAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GeolocationCondition=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 GeolocationCondition=function(){function a(b){var c=b.country,d=b.region,e=b.city;_classCallCheck(this,a),_defineProperty(this,"country",void 0),_defineProperty(this,"region",void 0),_defineProperty(this,"city",void 0),this.country=c,this.region=d,this.city=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.GeolocationData];if(c){var d=c.country,e=c.region,f=c.city,g=[this.country,this.region,this.city],h=g[0],i=g[1],j=g[2];if(!h||!d)return(0,_tsRes.Ok)(!1);return(0,_tsRes.Ok)(d===h&&(!i||e===i)&&(!j||f===j))}return(0,_tsRes.Ok)(!1)}}]),a}();exports.GeolocationCondition=GeolocationCondition;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.GeolocationCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class GeolocationCondition{constructor(a){let{country:b,region:c,city:d}=a;_defineProperty(this,"country",void 0),_defineProperty(this,"region",void 0),_defineProperty(this,"city",void 0),this.country=b,this.region=c,this.city=d}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.GeolocationData];if(c){const{country:a,region:b,city:d}=c,[e,f,g]=[this.country,this.region,this.city];if(!e||!a)return(0,_tsRes.Ok)(!1);return(0,_tsRes.Ok)(a===e&&(!f||b===f)&&(!g||d===g))}return(0,_tsRes.Ok)(!1)}}exports.GeolocationCondition=GeolocationCondition;
2
2
  //# sourceMappingURL=geolocation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geolocation.js","names":["GeolocationCondition","a","b","country","region","city","_classCallCheck","_defineProperty","_createClass","key","value","evaluate","targetingData","geolocationData","KameleoonData","GeolocationData","dataCountry","dataRegion","dataCity","g","conditionCountry","conditionRegion","conditionCity","Ok","exports"],"sources":["../../../src/targeting/conditions/geolocation.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\n// --- Note ---\n// `GeolocationCondition` uses `Condition` in the naming to avoid confusion with\n// native `Geolocation` API\nexport class GeolocationCondition implements ICondition {\n private country?: string | null;\n private region?: string | null;\n private city?: string | null;\n\n constructor({ country, region, city }: ConditionDataType) {\n this.country = country;\n this.region = region;\n this.city = city;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const geolocationData = targetingData?.[KameleoonData.GeolocationData];\n\n if (geolocationData) {\n const {\n country: dataCountry,\n region: dataRegion,\n city: dataCity,\n } = geolocationData;\n const [conditionCountry, conditionRegion, conditionCity] = [\n this.country,\n this.region,\n this.city,\n ];\n\n if (!conditionCountry || !dataCountry) {\n return Ok(false);\n }\n\n const result =\n dataCountry === conditionCountry &&\n (!conditionRegion || dataRegion === conditionRegion) &&\n (!conditionCity || dataCity === conditionCity);\n\n return Ok(result);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"+5CASa,CAAAA,oBAAoB,YAK/B,SAAAC,EAAAC,CAAA,CAA0D,IAA5C,CAAAC,CAAO,CAAAD,CAAA,CAAPC,OAAO,CAAEC,CAAM,CAAAF,CAAA,CAANE,MAAM,CAAEC,CAAI,CAAAH,CAAA,CAAJG,IAAI,CAAAC,eAAA,MAAAL,CAAA,EAAAM,eAAA,wBAAAA,eAAA,uBAAAA,eAAA,qBACjC,IAAI,CAACJ,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACC,IAAI,CAAGA,CACd,CAAC,OAAAG,YAAA,CAAAP,CAAA,GAAAQ,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAV,CAAA,CAEwD,IADtD,CAAAW,CAAa,CAAAX,CAAA,CAAbW,aAAa,CAEPC,CAAe,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,eAAe,CAAC,CAEtE,GAAIF,CAAe,CAAE,IAER,CAAAG,CAAW,CAGlBH,CAAe,CAHjBV,OAAO,CACCc,CAAU,CAEhBJ,CAAe,CAFjBT,MAAM,CACAc,CAAQ,CACZL,CAAe,CADjBR,IAAI,CAAAc,CAAA,CAEqD,CACzD,IAAI,CAAChB,OAAO,CACZ,IAAI,CAACC,MAAM,CACX,IAAI,CAACC,IAAI,CACV,CAJMe,CAAgB,CAAAD,CAAA,IAAEE,CAAe,CAAAF,CAAA,IAAEG,CAAa,CAAAH,CAAA,IAMvD,GAAI,CAACC,CAAgB,EAAI,CAACJ,CAAW,CACnC,MAAO,GAAAO,SAAE,KAAO,CAQlB,MAAO,GAAAA,SAAE,EAJPP,CAAW,GAAKI,CAAgB,GAC/B,CAACC,CAAe,EAAIJ,CAAU,GAAKI,CAAe,CAAC,GACnD,CAACC,CAAa,EAAIJ,CAAQ,GAAKI,CAAa,CAAC,CAGlD,CAEA,MAAO,GAAAC,SAAE,KACX,CAAC,IAAAtB,CAAA,IAAAuB,OAAA,CAAAxB,oBAAA,CAAAA,oBAAA"}
1
+ {"version":3,"file":"geolocation.js","names":["GeolocationCondition","constructor","a","country","region","city","_defineProperty","evaluate","targetingData","geolocationData","KameleoonData","GeolocationData","dataCountry","dataRegion","dataCity","conditionCountry","conditionRegion","conditionCity","Ok","exports"],"sources":["../../../src/targeting/conditions/geolocation.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\n// --- Note ---\n// `GeolocationCondition` uses `Condition` in the naming to avoid confusion with\n// native `Geolocation` API\nexport class GeolocationCondition implements ICondition {\n private country?: string | null;\n private region?: string | null;\n private city?: string | null;\n\n constructor({ country, region, city }: ConditionDataType) {\n this.country = country;\n this.region = region;\n this.city = city;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const geolocationData = targetingData?.[KameleoonData.GeolocationData];\n\n if (geolocationData) {\n const {\n country: dataCountry,\n region: dataRegion,\n city: dataCity,\n } = geolocationData;\n const [conditionCountry, conditionRegion, conditionCity] = [\n this.country,\n this.region,\n this.city,\n ];\n\n if (!conditionCountry || !dataCountry) {\n return Ok(false);\n }\n\n const result =\n dataCountry === conditionCountry &&\n (!conditionRegion || dataRegion === conditionRegion) &&\n (!conditionCity || dataCity === conditionCity);\n\n return Ok(result);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"srBASO,KAAM,CAAAA,oBAA2C,CAKtDC,WAAWA,CAAAC,CAAA,CAA+C,IAA9C,CAAEC,OAAO,CAAPA,CAAO,CAAEC,MAAM,CAANA,CAAM,CAAEC,IAAI,CAAJA,CAAwB,CAAC,CAAAH,CAAA,CAAAI,eAAA,wBAAAA,eAAA,uBAAAA,eAAA,qBACtD,IAAI,CAACH,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACC,IAAI,CAAGA,CACd,CAEOE,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAe,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,eAAe,CAAC,CAEtE,GAAIF,CAAe,CAAE,MACb,CACJN,OAAO,CAAES,CAAW,CACpBR,MAAM,CAAES,CAAU,CAClBR,IAAI,CAAES,CACR,CAAC,CAAGL,CAAe,CACb,CAACM,CAAgB,CAAEC,CAAe,CAAEC,CAAa,CAAC,CAAG,CACzD,IAAI,CAACd,OAAO,CACZ,IAAI,CAACC,MAAM,CACX,IAAI,CAACC,IAAI,CACV,CAED,GAAI,CAACU,CAAgB,EAAI,CAACH,CAAW,CACnC,MAAO,GAAAM,SAAE,IAAM,CAAC,CAQlB,MAAO,GAAAA,SAAE,EAJPN,CAAW,GAAKG,CAAgB,GAC/B,CAACC,CAAe,EAAIH,CAAU,GAAKG,CAAe,CAAC,GACnD,CAACC,CAAa,EAAIH,CAAQ,GAAKG,CAAa,CAE/B,CAClB,CAEA,MAAO,GAAAC,SAAE,IAAM,CACjB,CACF,CAACC,OAAA,CAAAnB,oBAAA,CAAAA,oBAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function get(){return _applicationVersion.ApplicationVersion}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function get(){return _browser.Browser}}),Object.defineProperty(exports,"ConditionDataType",{enumerable:!0,get:function get(){return _types.ConditionDataType}}),Object.defineProperty(exports,"ConditionFactory",{enumerable:!0,get:function get(){return _conditionFactory.ConditionFactory}}),Object.defineProperty(exports,"ConditionType",{enumerable:!0,get:function get(){return _types.ConditionType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function get(){return _conversion.Conversion}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function get(){return _cookie.Cookie}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function get(){return _customData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function get(){return _device.Device}}),Object.defineProperty(exports,"ExclusiveCampaign",{enumerable:!0,get:function get(){return _exclusiveCampaign.ExclusiveCampaign}}),Object.defineProperty(exports,"FirstVisit",{enumerable:!0,get:function get(){return _firstVisit.FirstVisit}}),Object.defineProperty(exports,"GeolocationCondition",{enumerable:!0,get:function get(){return _geolocation.GeolocationCondition}}),Object.defineProperty(exports,"LastVisit",{enumerable:!0,get:function get(){return _lastVisit.LastVisit}}),Object.defineProperty(exports,"NewVisitor",{enumerable:!0,get:function get(){return _newVisitor.NewVisitor}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function get(){return _operatingSystem.OperatingSystem}}),Object.defineProperty(exports,"PageTitle",{enumerable:!0,get:function get(){return _pageTitle.PageTitle}}),Object.defineProperty(exports,"PageUrl",{enumerable:!0,get:function get(){return _pageUrl.PageUrl}}),Object.defineProperty(exports,"PreviousPage",{enumerable:!0,get:function get(){return _previousPage.PreviousPage}}),Object.defineProperty(exports,"SameDayVisits",{enumerable:!0,get:function get(){return _sameDayVisits.SameDayVisits}}),Object.defineProperty(exports,"SdkLanguage",{enumerable:!0,get:function get(){return _sdkLanguage.SdkLanguage}}),Object.defineProperty(exports,"Segment",{enumerable:!0,get:function get(){return _segment.Segment}}),Object.defineProperty(exports,"TargetFeatureFlag",{enumerable:!0,get:function get(){return _targetFeatureFlag.TargetFeatureFlag}}),Object.defineProperty(exports,"VisitedPages",{enumerable:!0,get:function get(){return _visitedPages.VisitedPages}}),Object.defineProperty(exports,"VisitorCode",{enumerable:!0,get:function get(){return _visitorCode.VisitorCode}}),Object.defineProperty(exports,"Visits",{enumerable:!0,get:function get(){return _visits.Visits}});var _device=require("./device"),_conditionFactory=require("./conditionFactory"),_types=require("./types"),_customData=require("./customData"),_exclusiveCampaign=require("./exclusiveCampaign"),_browser=require("./browser"),_pageUrl=require("./pageUrl"),_pageTitle=require("./pageTitle"),_conversion=require("./conversion"),_visitorCode=require("./visitorCode"),_sdkLanguage=require("./sdkLanguage"),_targetFeatureFlag=require("./targetFeatureFlag"),_cookie=require("./cookie"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_segment=require("./segment"),_previousPage=require("./previousPage"),_visitedPages=require("./visitedPages"),_firstVisit=require("./firstVisit"),_lastVisit=require("./lastVisit"),_visits=require("./visits"),_sameDayVisits=require("./sameDayVisits"),_newVisitor=require("./newVisitor"),_applicationVersion=require("./applicationVersion");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _applicationVersion.ApplicationVersion}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _browser.Browser}}),Object.defineProperty(exports,"ConditionDataType",{enumerable:!0,get:function(){return _types.ConditionDataType}}),Object.defineProperty(exports,"ConditionFactory",{enumerable:!0,get:function(){return _conditionFactory.ConditionFactory}}),Object.defineProperty(exports,"ConditionType",{enumerable:!0,get:function(){return _types.ConditionType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _conversion.Conversion}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _cookie.Cookie}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _customData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _device.Device}}),Object.defineProperty(exports,"ExclusiveCampaign",{enumerable:!0,get:function(){return _exclusiveCampaign.ExclusiveCampaign}}),Object.defineProperty(exports,"FirstVisit",{enumerable:!0,get:function(){return _firstVisit.FirstVisit}}),Object.defineProperty(exports,"GeolocationCondition",{enumerable:!0,get:function(){return _geolocation.GeolocationCondition}}),Object.defineProperty(exports,"LastVisit",{enumerable:!0,get:function(){return _lastVisit.LastVisit}}),Object.defineProperty(exports,"NewVisitor",{enumerable:!0,get:function(){return _newVisitor.NewVisitor}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _operatingSystem.OperatingSystem}}),Object.defineProperty(exports,"PageTitle",{enumerable:!0,get:function(){return _pageTitle.PageTitle}}),Object.defineProperty(exports,"PageUrl",{enumerable:!0,get:function(){return _pageUrl.PageUrl}}),Object.defineProperty(exports,"PreviousPage",{enumerable:!0,get:function(){return _previousPage.PreviousPage}}),Object.defineProperty(exports,"SameDayVisits",{enumerable:!0,get:function(){return _sameDayVisits.SameDayVisits}}),Object.defineProperty(exports,"SdkLanguage",{enumerable:!0,get:function(){return _sdkLanguage.SdkLanguage}}),Object.defineProperty(exports,"Segment",{enumerable:!0,get:function(){return _segment.Segment}}),Object.defineProperty(exports,"TargetFeatureFlag",{enumerable:!0,get:function(){return _targetFeatureFlag.TargetFeatureFlag}}),Object.defineProperty(exports,"VisitedPages",{enumerable:!0,get:function(){return _visitedPages.VisitedPages}}),Object.defineProperty(exports,"VisitorCode",{enumerable:!0,get:function(){return _visitorCode.VisitorCode}}),Object.defineProperty(exports,"Visits",{enumerable:!0,get:function(){return _visits.Visits}});var _device=require("./device"),_conditionFactory=require("./conditionFactory"),_types=require("./types"),_customData=require("./customData"),_exclusiveCampaign=require("./exclusiveCampaign"),_browser=require("./browser"),_pageUrl=require("./pageUrl"),_pageTitle=require("./pageTitle"),_conversion=require("./conversion"),_visitorCode=require("./visitorCode"),_sdkLanguage=require("./sdkLanguage"),_targetFeatureFlag=require("./targetFeatureFlag"),_cookie=require("./cookie"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_segment=require("./segment"),_previousPage=require("./previousPage"),_visitedPages=require("./visitedPages"),_firstVisit=require("./firstVisit"),_lastVisit=require("./lastVisit"),_visits=require("./visits"),_sameDayVisits=require("./sameDayVisits"),_newVisitor=require("./newVisitor"),_applicationVersion=require("./applicationVersion");
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_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 LastVisit=function(){function a(b){var c=b.matchType,d=b.count,e=b.unitOfTime;_classCallCheck(this,a),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=c,this.conditionValue=d,this.timeUnit=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.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);var d=c.currentVisit,e=c.previousVisits,f=d?d:e[e.length-1];return"number"==typeof f?(0,_tsRes.Ok)(this.checkCondition(f)):(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;var b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types.MatchType.GREATER:return c>this.conditionValue;case _types.MatchType.LOWER:return c<this.conditionValue;default:return!1;}}}]),a}();exports.LastVisit=LastVisit;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class LastVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);const{currentVisit:d,previousVisits:e}=c,f=d?d:e[e.length-1];return"number"==typeof f?(0,_tsRes.Ok)(this.checkCondition(f)):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;const b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types.MatchType.GREATER:return c>this.conditionValue;case _types.MatchType.LOWER:return c<this.conditionValue;default:return!1}}}exports.LastVisit=LastVisit;
2
2
  //# sourceMappingURL=lastVisit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lastVisit.js","names":["LastVisit","a","b","matchType","count","unitOfTime","_classCallCheck","_defineProperty","conditionValue","timeUnit","_createClass","key","value","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","lastVisitTimestamp","length","checkCondition","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/lastVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class LastVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n const lastVisitTimestamp = currentVisit\n ? currentVisit\n : previousVisits[previousVisits.length - 1];\n\n if (typeof lastVisitTimestamp !== 'number') {\n return Ok(false);\n }\n\n return Ok(this.checkCondition(lastVisitTimestamp));\n }\n\n private checkCondition(lastVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - lastVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"q9CAOa,CAAAA,SAAS,YAKpB,SAAAC,EAAAC,CAAA,CAAiE,IAAnD,CAAAC,CAAS,CAAAD,CAAA,CAATC,SAAS,CAAEC,CAAK,CAAAF,CAAA,CAALE,KAAK,CAAEC,CAAU,CAAAH,CAAA,CAAVG,UAAU,CAAAC,eAAA,MAAAL,CAAA,EAAAM,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBACxC,IAAI,CAACJ,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACK,cAAc,CAAGJ,CAAK,CAC3B,IAAI,CAACK,QAAQ,CAAGJ,CAClB,CAAC,OAAAK,YAAA,CAAAT,CAAA,GAAAU,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAZ,CAAA,CAEwD,IADtD,CAAAa,CAAa,CAAAb,CAAA,CAAba,aAAa,CAEPC,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,CACb,MAAO,GAAAG,SAAE,KAAO,CACjB,GAEO,CAAAC,CAAY,CAAqBJ,CAAU,CAA3CI,YAAY,CAAEC,CAAc,CAAKL,CAAU,CAA7BK,cAAc,CAE9BC,CAAkB,CAAGF,CAAY,CACnCA,CAAY,CACZC,CAAc,CAACA,CAAc,CAACE,MAAM,CAAG,CAAC,CAAC,OAEX,QAAQ,EAAtC,MAAO,CAAAD,CAA+B,CAInC,GAAAH,SAAE,EAAC,IAAI,CAACK,cAAc,CAACF,CAAkB,CAAC,CAAC,CAHzC,GAAAH,SAAE,KAIb,CAAC,GAAAP,GAAA,kBAAAC,KAAA,CAED,SAAAW,eAAuBF,CAA0B,CAAW,CAC1D,GACE,CAAC,IAAI,CAAClB,SAAS,EACgB,QAAQ,EAAvC,MAAO,KAAI,CAACK,cAA2B,EACvC,CAAC,IAAI,CAACC,QAAQ,CAEd,SACD,GAEK,CAAAe,CAAuB,CAAGC,IAAI,CAACC,GAAG,EAAE,CAAGL,CAAkB,CACzDM,CAAe,CAAGC,oBAAS,CAACC,eAAe,CAC/CL,CAAuB,CACvB,IAAI,CAACf,QAAQ,CACd,CAED,OAAQ,IAAI,CAACN,SAAS,EACpB,IAAK,CAAA2B,gBAAS,CAACC,OAAO,CACpB,MAAO,CAAAJ,CAAe,CAAG,IAAI,CAACnB,cAAc,CAC9C,IAAK,CAAAsB,gBAAS,CAACE,KAAK,CAClB,MAAO,CAAAL,CAAe,CAAG,IAAI,CAACnB,cAAc,CAC9C,QACE,SAAa,CAEnB,CAAC,IAAAP,CAAA,IAAAgC,OAAA,CAAAjC,SAAA,CAAAA,SAAA"}
1
+ {"version":3,"file":"lastVisit.js","names":["LastVisit","constructor","a","matchType","count","unitOfTime","_defineProperty","conditionValue","timeUnit","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","lastVisitTimestamp","length","checkCondition","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/lastVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class LastVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n const lastVisitTimestamp = currentVisit\n ? currentVisit\n : previousVisits[previousVisits.length - 1];\n\n if (typeof lastVisitTimestamp !== 'number') {\n return Ok(false);\n }\n\n return Ok(this.checkCondition(lastVisitTimestamp));\n }\n\n private checkCondition(lastVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - lastVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"4uBAOO,KAAM,CAAAA,SAAgC,CAK3CC,WAAWA,CAAAC,CAAA,CAAsD,IAArD,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAK,CAAEC,UAAU,CAAVA,CAA8B,CAAC,CAAAH,CAAA,CAAAI,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBAC7D,IAAI,CAACH,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACI,cAAc,CAAGH,CAAK,CAC3B,IAAI,CAACI,QAAQ,C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value:!0}),exports.NewVisitor=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 NewVisitor=function(){function a(b){var c=b.visitorType;_classCallCheck(this,a),_defineProperty(this,"visitorType",void 0),this.visitorType=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.VisitsData];if(!c||!this.visitorType)return(0,_tsRes.Ok)(!1);var d=c.currentVisit,e=c.previousVisits,f=d&&!e.length||!d&&!e.length;switch(this.visitorType){case _types.VisitorType.NEW:return(0,_tsRes.Ok)(f);case _types.VisitorType.RETURNING:return(0,_tsRes.Ok)(!f);default:(0,_kameleoonError.exhaustCheck)(this.visitorType);}}}]),a}();exports.NewVisitor=NewVisitor;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewVisitor=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class NewVisitor{constructor(a){let{visitorType:b}=a;_defineProperty(this,"visitorType",void 0),this.visitorType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c||!this.visitorType)return(0,_tsRes.Ok)(!1);const{currentVisit:d,previousVisits:e}=c,f=d&&!e.length||!d&&!e.length;switch(this.visitorType){case _types.VisitorType.NEW:return(0,_tsRes.Ok)(f);case _types.VisitorType.RETURNING:return(0,_tsRes.Ok)(!f);default:(0,_kameleoonError.exhaustCheck)(this.visitorType)}}}exports.NewVisitor=NewVisitor;
2
2
  //# sourceMappingURL=newVisitor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"newVisitor.js","names":["NewVisitor","a","b","visitorType","_classCallCheck","_defineProperty","_createClass","key","value","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","isNewVisitor","length","VisitorType","NEW","RETURNING","exhaustCheck","exports"],"sources":["../../../src/targeting/conditions/newVisitor.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, VisitorType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class NewVisitor implements ICondition {\n private visitorType?: VisitorType | null;\n\n constructor({ visitorType }: ConditionDataType) {\n this.visitorType = visitorType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData || !this.visitorType) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n // --- Note ---\n // Second case handles situation when user didn't use `addData` that\n // creates new current visit\n const isNewVisitor =\n (currentVisit && !previousVisits.length) ||\n (!currentVisit && !previousVisits.length);\n\n switch (this.visitorType) {\n case VisitorType.NEW:\n return Ok(isNewVisitor);\n case VisitorType.RETURNING:\n return Ok(!isNewVisitor);\n default:\n exhaustCheck(this.visitorType);\n }\n }\n}\n"],"mappings":"g+CAMa,CAAAA,UAAU,YAGrB,SAAAC,EAAAC,CAAA,CAAgD,IAAlC,CAAAC,CAAW,CAAAD,CAAA,CAAXC,WAAW,CAAAC,eAAA,MAAAH,CAAA,EAAAI,eAAA,4BACvB,IAAI,CAACF,WAAW,CAAGA,CACrB,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,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,EAAI,CAAC,IAAI,CAACR,WAAW,CAClC,MAAO,GAAAW,SAAE,KAAO,CACjB,GAEO,CAAAC,CAAY,CAAqBJ,CAAU,CAA3CI,YAAY,CAAEC,CAAc,CAAKL,CAAU,CAA7BK,cAAc,CAK9BC,CAAY,CACfF,CAAY,EAAI,CAACC,CAAc,CAACE,MAAM,EACtC,CAACH,CAAY,EAAI,CAACC,CAAc,CAACE,MAAO,CAE3C,OAAQ,IAAI,CAACf,WAAW,EACtB,IAAK,CAAAgB,kBAAW,CAACC,GAAG,CAClB,MAAO,GAAAN,SAAE,EAACG,CAAY,CAAC,CACzB,IAAK,CAAAE,kBAAW,CAACE,SAAS,CACxB,MAAO,GAAAP,SAAE,EAAC,CAACG,CAAY,CAAC,CAC1B,QACE,GAAAK,4BAAY,EAAC,IAAI,CAACnB,WAAW,CAAC,CAAC,CAErC,CAAC,IAAAF,CAAA,IAAAsB,OAAA,CAAAvB,UAAA,CAAAA,UAAA"}
1
+ {"version":3,"file":"newVisitor.js","names":["NewVisitor","constructor","a","visitorType","_defineProperty","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","currentVisit","previousVisits","isNewVisitor","length","VisitorType","NEW","RETURNING","exhaustCheck","exports"],"sources":["../../../src/targeting/conditions/newVisitor.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, VisitorType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class NewVisitor implements ICondition {\n private visitorType?: VisitorType | null;\n\n constructor({ visitorType }: ConditionDataType) {\n this.visitorType = visitorType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData || !this.visitorType) {\n return Ok(false);\n }\n\n const { currentVisit, previousVisits } = visitsData;\n\n // --- Note ---\n // Second case handles situation when user didn't use `addData` that\n // creates new current visit\n const isNewVisitor =\n (currentVisit && !previousVisits.length) ||\n (!currentVisit && !previousVisits.length);\n\n switch (this.visitorType) {\n case VisitorType.NEW:\n return Ok(isNewVisitor);\n case VisitorType.RETURNING:\n return Ok(!isNewVisitor);\n default:\n exhaustCheck(this.visitorType);\n }\n }\n}\n"],"mappings":"uvBAMO,KAAM,CAAAA,UAAiC,CAG5CC,WAAWA,CAAAC,CAAA,CAAqC,IAApC,CAAEC,WAAW,CAAXA,CAA+B,CAAC,CAAAD,CAAA,CAAAE,eAAA,4BAC5C,IAAI,CAACD,WAAW,CAAGA,CACrB,CAEOE,QAAQA,CAAAH,CAAA,CAEyC,IAFxC,CACdI,aAAa,CAAbA,CACkB,CAAC,CAAAJ,CAAA,CACnB,KAAM,CAAAK,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,EAAI,CAAC,IAAI,CAACJ,WAAW,CAClC,MAAO,GAAAO,SAAE,IAAM,CAAC,CACjB,KAEK,CAAEC,YAAY,CAAZA,CAAY,CAAEC,cAAc,CAAdA,CAAe,CAAC,CAAGL,CAAU,CAK7CM,CAAY,CACfF,CAAY,EAAI,CAACC,CAAc,CAACE,MAAM,EACtC,CAACH,CAAY,EAAI,CAACC,CAAc,CAACE,MAAO,CAE3C,OAAQ,IAAI,CAACX,WAAW,EACtB,IAAK,CAAAY,kBAAW,CAACC,GAAG,CAClB,MAAO,GAAAN,SAAE,EAACG,CAAY,CAAC,CACzB,IAAK,CAAAE,kBAAW,CAACE,SAAS,CACxB,MAAO,GAAAP,SAAE,EAAC,CAACG,CAAY,CAAC,CAC1B,QACE,GAAAK,4BAAY,EAAC,IAAI,CAACf,WAAW,CACjC,CACF,CACF,CAACgB,OAAA,CAAAnB,UAAA,CAAAA,UAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OperatingSystem=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 OperatingSystem=function(){function a(b){var c=b.os;_classCallCheck(this,a),_defineProperty(this,"operatingSystem",void 0),this.operatingSystem=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.OperatingSystem];if(c){var d=c.operatingSystem;return(0,_tsRes.Ok)(d===this.operatingSystem)}return(0,_tsRes.Ok)(!1)}}]),a}();exports.OperatingSystem=OperatingSystem;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OperatingSystem=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class OperatingSystem{constructor(a){let{os:b}=a;_defineProperty(this,"operatingSystem",void 0),this.operatingSystem=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.OperatingSystem];if(c){const{operatingSystem:a}=c;return(0,_tsRes.Ok)(a===this.operatingSystem)}return(0,_tsRes.Ok)(!1)}}exports.OperatingSystem=OperatingSystem;
2
2
  //# sourceMappingURL=operatingSystem.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"operatingSystem.js","names":["OperatingSystem","a","b","os","_classCallCheck","_defineProperty","operatingSystem","_createClass","key","value","evaluate","targetingData","operatingSystemData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/operatingSystem.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 { OperatingSystemType } from 'src/kameleoonData/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class OperatingSystem implements ICondition {\n private operatingSystem?: OperatingSystemType | null;\n\n constructor({ os }: ConditionDataType) {\n this.operatingSystem = os;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const operatingSystemData = targetingData?.[KameleoonData.OperatingSystem];\n\n if (operatingSystemData) {\n const { operatingSystem } = operatingSystemData;\n\n return Ok(operatingSystem === this.operatingSystem);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"05CAOa,CAAAA,eAAe,YAG1B,SAAAC,EAAAC,CAAA,CAAuC,IAAzB,CAAAC,CAAE,CAAAD,CAAA,CAAFC,EAAE,CAAAC,eAAA,MAAAH,CAAA,EAAAI,eAAA,gCACd,IAAI,CAACC,eAAe,CAAGH,CACzB,CAAC,OAAAI,YAAA,CAAAN,CAAA,GAAAO,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAT,CAAA,CAEwD,IADtD,CAAAU,CAAa,CAAAV,CAAA,CAAbU,aAAa,CAEPC,CAAmB,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACb,eAAe,CAAC,CAE1E,GAAIY,CAAmB,CAAE,CACvB,GAAQ,CAAAN,CAAe,CAAKM,CAAmB,CAAvCN,eAAe,CAEvB,MAAO,GAAAQ,SAAE,EAACR,CAAe,GAAK,IAAI,CAACA,eAAe,CACpD,CAEA,MAAO,GAAAQ,SAAE,KACX,CAAC,IAAAb,CAAA,IAAAc,OAAA,CAAAf,eAAA,CAAAA,eAAA"}
1
+ {"version":3,"file":"operatingSystem.js","names":["OperatingSystem","constructor","a","os","_defineProperty","operatingSystem","evaluate","targetingData","operatingSystemData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/operatingSystem.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 { OperatingSystemType } from 'src/kameleoonData/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class OperatingSystem implements ICondition {\n private operatingSystem?: OperatingSystemType | null;\n\n constructor({ os }: ConditionDataType) {\n this.operatingSystem = os;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const operatingSystemData = targetingData?.[KameleoonData.OperatingSystem];\n\n if (operatingSystemData) {\n const { operatingSystem } = operatingSystemData;\n\n return Ok(operatingSystem === this.operatingSystem);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"irBAOO,KAAM,CAAAA,eAAsC,CAGjDC,WAAWA,CAAAC,CAAA,CAA4B,IAA3B,CAAEC,EAAE,CAAFA,CAAsB,CAAC,CAAAD,CAAA,CAAAE,eAAA,gCACnC,IAAI,CAACC,eAAe,CAAGF,CACzB,CAEOG,QAAQA,CAAAJ,CAAA,CAEyC,IAFxC,CACdK,aAAa,CAAbA,CACkB,CAAC,CAAAL,CAAA,CACnB,KAAM,CAAAM,CAAmB,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACT,eAAe,CAAC,CAE1E,GAAIQ,CAAmB,CAAE,CACvB,KAAM,CAAEH,eAAe,CAAfA,CAAgB,CAAC,CAAGG,CAAmB,CAE/C,MAAO,GAAAE,SAAE,EAACL,CAAe,GAAK,IAAI,CAACA,eAAe,CACpD,CAEA,MAAO,GAAAK,SAAE,IAAM,CACjB,CACF,CAACC,OAAA,CAAAX,eAAA,CAAAA,eAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageTitle=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_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 PageTitle=function(){function a(b){var c=b.matchType,d=b.title;_classCallCheck(this,a),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=c,this.conditionValue=d}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=this,c=a.targetingData,d=null===c||void 0===c?void 0:c[_kameleoonData.KameleoonData.PageView];return d?(0,_tsRes.Ok)(Object.values(d).some(function(a){return b.checkCondition(a.title)})):(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1;}}}]),a}();exports.PageTitle=PageTitle;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageTitle=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class PageTitle{constructor(a){let{matchType:b,title:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];return c?(0,_tsRes.Ok)(Object.values(c).some(a=>this.checkCondition(a.title))):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1}}}exports.PageTitle=PageTitle;
2
2
  //# sourceMappingURL=pageTitle.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pageTitle.js","names":["PageTitle","a","b","matchType","title","_classCallCheck","_defineProperty","conditionValue","_createClass","key","value","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","values","some","data","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageTitle.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageTitle implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, title }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = title;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.values(pageViewData).some((data) => {\n return this.checkCondition(data.title);\n }),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(title: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return title.includes(this.conditionValue);\n case MatchType.EXACT:\n return title === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(this.conditionValue).test(title);\n default:\n return false;\n }\n }\n}\n"],"mappings":"q9CAOa,CAAAA,SAAS,YAIpB,SAAAC,EAAAC,CAAA,CAAqD,IAAvC,CAAAC,CAAS,CAAAD,CAAA,CAATC,SAAS,CAAEC,CAAK,CAAAF,CAAA,CAALE,KAAK,CA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Title","constructor","a","matchType","title","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","values","some","data","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageTitle.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageTitle implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, title }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = title;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.values(pageViewData).some((data) => {\n return this.checkCondition(data.title);\n }),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(title: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return title.includes(this.conditionValue);\n case MatchType.EXACT:\n return title === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(this.conditionValue).test(title);\n default:\n return false;\n }\n }\n}\n"],"mappings":"4uBAOO,KAAM,CAAAA,SAAgC,CAI3CC,WAAWA,CAAAC,CAAA,CAA0C,IAAzC,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAyB,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BACjD,IAAI,CAACF,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACG,cAAc,CAAGF,CACxB,CAEOG,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAY,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,CAAC,MAEzD,CAAAF,CAAY,CACP,GAAAG,SAAE,EACPC,MAAM,CAACC,MAAM,CAACL,CAAY,CAAC,CAACM,IAAI,CAAEC,CAAI,EAC7B,IAAI,CAACC,cAAc,CAACD,CAAI,CAACZ,KAAK,CACtC,CACH,CAAC,CAGI,GAAAQ,SAAE,IAAM,CACjB,CAEQK,cAAcA,CAACb,CAAa,CAAW,CAC7C,GAAI,CAAC,IAAI,CAACD,SAAS,EAAI,CAAC,IAAI,CAACG,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAe,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAf,CAAK,CAACgB,QAAQ,CAAC,IAAI,CAACd,cAAc,CAAC,CAC5C,IAAK,CAAAY,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAjB,CAAK,GAAK,IAAI,CAACE,cAAc,CACtC,IAAK,CAAAY,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,oBAAS,CAACC,WAAW,CAAC,IAAI,CAAClB,cAAc,CAAC,CAACmB,IAAI,CAACrB,CAAK,CAAC,CAC/D,QACE,QACJ,CACF,CACF,CAACsB,OAAA,CAAA1B,SAAA,CAAAA,SAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageUrl=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_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 PageUrl=function(){function a(b){var c=b.matchType,d=b.url;_classCallCheck(this,a),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=c,this.conditionValue=d}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=this,c=a.targetingData,d=null===c||void 0===c?void 0:c[_kameleoonData.KameleoonData.PageView];return d?(0,_tsRes.Ok)(Object.keys(d).some(function(a){return b.checkCondition(a)})):(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1;}}}]),a}();exports.PageUrl=PageUrl;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageUrl=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class PageUrl{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];return c?(0,_tsRes.Ok)(Object.keys(c).some(a=>this.checkCondition(a))):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1}}}exports.PageUrl=PageUrl;
2
2
  //# sourceMappingURL=pageUrl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pageUrl.js","names":["PageUrl","a","b","matchType","url","_classCallCheck","_defineProperty","conditionValue","_createClass","key","value","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","keys","some","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageUrl.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageUrl implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, url }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = url;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.keys(pageViewData).some((url) => this.checkCondition(url)),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(url: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return url.includes(this.conditionValue);\n case MatchType.EXACT:\n return url === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(this.conditionValue).test(url);\n default:\n return false;\n }\n }\n}\n"],"mappings":"m9CAOa,CAAAA,OAAO,YAIlB,SAAAC,EAAAC,CAAA,CAAmD,IAArC,CAAAC,CAAS,CAAAD,CAAA,CAATC,SAAS,CAAEC,CAAG,CAAAF,CAAA,CAAHE,GAAG,CAAAC,eAAA,MAAAJ,CAAA,EAAAK,eAAA,0BAAAA,eAAA,+BAC1B,IAAI,CAACH,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACI,cAAc,CAAGH,CACxB,CAAC,OAAAI,YAAA,CAAAP,CAAA,GAAAQ,GAAA,YAAAC,KAAA,CAED,SAAAC,SAAAV,CAAA,CAEwD,KAAAC,CAAA,MADtDU,CAAa,CAAAX,CAAA,CAAbW,aAAa,CAEPC,CAAY,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,OAExD,CAAAF,CAAY,CACP,GAAAG,SAAE,EACPC,MAAM,CAACC,IAAI,CAACL,CAAY,CAAC,CAACM,IAAI,CAAC,SAACf,CAAG,QAAK,CAAAF,CAAI,CAACkB,cAAc,CAAChB,CAAG,CAAC,EAAC,CAClE,CAGI,GAAAY,SAAE,KACX,CAAC,GAAAP,GAAA,kBAAAC,KAAA,CAED,SAAAU,eAAuBhB,CAAW,CAAW,CAC3C,GAAI,CAAC,IAAI,CAACD,SAAS,EAAI,CAAC,IAAI,CAACI,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACJ,SAAS,EACpB,IAAK,CAAAkB,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAlB,CAAG,CAACmB,QAAQ,CAAC,IAAI,CAAChB,cAAc,CAAC,CAC1C,IAAK,CAAAc,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAApB,CAAG,GAAK,IAAI,CAACG,cAAc,CACpC,IAAK,CAAAc,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,oBAAS,CAACC,WAAW,CAAC,IAAI,CAACpB,cAAc,CAAC,CAACqB,IAAI,CAACxB,CAAG,CAAC,CAC7D,QACE,SAAa,CAEnB,CAAC,IAAAH,CAAA,IAAA4B,OAAA,CAAA7B,OAAA,CAAAA,OAAA"}
1
+ {"version":3,"file":"pageUrl.js","names":["PageUrl","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","keys","some","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Utilities","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageUrl.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageUrl implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, url }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = url;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.keys(pageViewData).some((url) => this.checkCondition(url)),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(url: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return url.includes(this.conditionValue);\n case MatchType.EXACT:\n return url === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Utilities.parseRegExp(this.conditionValue).test(url);\n default:\n return false;\n }\n }\n}\n"],"mappings":"0uBAOO,KAAM,CAAAA,OAA8B,CAIzCC,WAAWA,CAAAC,CAAA,CAAwC,IAAvC,CAAEC,SAAS,CAATA,CAAS,CAAEC,GAAG,CAAHA,CAAuB,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BAC/C,IAAI,CAACF,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACG,cAAc,CAAGF,CACxB,CAEOG,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAY,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,CAAC,MAEzD,CAAAF,CAAY,CACP,GAAAG,SAAE,EACPC,MAAM,CAACC,IAAI,CAACL,CAAY,CAAC,CAACM,IAAI,CAAEX,CAAG,EAAK,IAAI,CAACY,cAAc,CAACZ,CAAG,CAAC,CAClE,CAAC,CAGI,GAAAQ,SAAE,IAAM,CACjB,CAEQI,cAAcA,CAACZ,CAAW,CAAW,CAC3C,GAAI,CAAC,IAAI,CAACD,SAAS,EAAI,CAAC,IAAI,CAACG,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAc,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAd,CAAG,CAACe,QAAQ,CAAC,IAAI,CAACb,cAAc,CAAC,CAC1C,IAAK,CAAAW,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAhB,CAAG,GAAK,IAAI,CAACE,cAAc,CACpC,IAAK,CAAAW,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,oBAAS,CAACC,WAAW,CAAC,IAAI,CAACjB,cAAc,CAAC,CAACkB,IAAI,CAACpB,CAAG,CAAC,CAC7D,QACE,QACJ,CACF,CACF,CAACqB,OAAA,CAAAzB,OAAA,CAAAA,OAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_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 PreviousPage=function(){function a(b){var c=b.matchType,d=b.url;_classCallCheck(this,a),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.conditionValue=d,this.matchType=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.PageView];if(!c)return(0,_tsRes.Ok)(!1);var d=this.getSecondLatestPageView(Object.values(c));if(!d)return(0,_tsRes.Ok)(!1);var e=d.urlAddress;return(0,_tsRes.Ok)(this.checkCondition(e))}},{key:"checkCondition",value:function checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1;}}},{key:"getSecondLatestPageView",value:function getSecondLatestPageView(a){if(!(2>a.length)){var b,c;return a.forEach(function(a){var d,e,f=a.timestamps[a.timestamps.length-1],g=a.timestamps[a.timestamps.length-2];if(!b&&!c)return b=a,void(g&&(c=a));var h=null!==(d=b.timestamps[b.timestamps.length-1])&&void 0!==d?d:0;if(f>h){var i,j;c=b,b=a;var k=null===(i=c)||void 0===i?void 0:i.timestamps[(null===(j=c)||void 0===j?void 0:j.timestamps.length)-1];return void(g&&g>k&&(c=a))}var l;if(b.urlAddress===(null===(e=c)||void 0===e?void 0:e.urlAddress))l=c.timestamps[c.timestamps.length-2];else{var m,n,o;l=null!==(m=null===(n=c)||void 0===n?void 0:n.timestamps[(null===(o=c)||void 0===o?void 0:o.timestamps.length)-1])&&void 0!==m?m:0}f&&f>l&&(c=a)}),c}}}]),a}();exports.PreviousPage=PreviousPage;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");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||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){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)}class PreviousPage{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.conditionValue=c,this.matchType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];if(!c)return(0,_tsRes.Ok)(!1);const d=this.getSecondLatestPageView(Object.values(c));if(!d)return(0,_tsRes.Ok)(!1);const e=d.urlAddress;return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1}}getSecondLatestPageView(a){if(2>a.length)return;let b,c;return a.forEach(a=>{var d,e;const f=a.timestamps[a.timestamps.length-1],g=a.timestamps[a.timestamps.length-2];if(!b&&!c)return b=a,void(g&&(c=a));const h=null!==(d=b.timestamps[b.timestamps.length-1])&&void 0!==d?d:0;if(f>h){var i,j;c=b,b=a;const d=null===(i=c)||void 0===i?void 0:i.timestamps[(null===(j=c)||void 0===j?void 0:j.timestamps.length)-1];return void(g&&g>d&&(c=a))}let k;if(b.urlAddress===(null===(e=c)||void 0===e?void 0:e.urlAddress))k=c.timestamps[c.timestamps.length-2];else{var l,m,n;k=null!==(l=null===(m=c)||void 0===m?void 0:m.timestamps[(null===(n=c)||void 0===n?void 0:n.timestamps.length)-1])&&void 0!==l?l:0}f&&f>k&&(c=a)}),c}}exports.PreviousPage=PreviousPage;
2
2
  //# sourceMappingURL=previousPage.js.map