@kameleoon/javascript-sdk-core 2.10.1 → 3.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 (256) hide show
  1. package/dist/cacheManager/cacheManager.js +1 -11
  2. package/dist/cacheManager/cacheManager.js.map +1 -1
  3. package/dist/clientConfiguration/clientConfiguration.d.ts +52 -0
  4. package/dist/clientConfiguration/clientConfiguration.js +2 -0
  5. package/dist/clientConfiguration/clientConfiguration.js.map +1 -0
  6. package/dist/clientConfiguration/constants.d.ts +2 -0
  7. package/dist/clientConfiguration/constants.js +2 -0
  8. package/dist/clientConfiguration/constants.js.map +1 -0
  9. package/dist/clientConfiguration/index.d.ts +2 -0
  10. package/dist/clientConfiguration/index.js +2 -0
  11. package/dist/clientConfiguration/index.js.map +1 -0
  12. package/dist/{campaignConfiguration → clientConfiguration}/types.d.ts +12 -53
  13. package/dist/clientConfiguration/types.js +2 -0
  14. package/dist/clientConfiguration/types.js.map +1 -0
  15. package/dist/clientSettings/clientSettings.js +1 -1
  16. package/dist/clientSettings/clientSettings.js.map +1 -1
  17. package/dist/constants.d.ts +3 -2
  18. package/dist/constants.js +1 -4
  19. package/dist/constants.js.map +1 -1
  20. package/dist/eventSource/externalEventSource.js +1 -1
  21. package/dist/eventSource/externalEventSource.js.map +1 -1
  22. package/dist/hasher/hasher.d.ts +2 -3
  23. package/dist/hasher/hasher.js +1 -6
  24. package/dist/hasher/hasher.js.map +1 -1
  25. package/dist/hasher/types.d.ts +3 -10
  26. package/dist/hasher/types.js.map +1 -1
  27. package/dist/index.d.ts +7 -6
  28. package/dist/index.js +1 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/kameleoonClient.d.ts +44 -80
  31. package/dist/kameleoonClient.js +1 -18
  32. package/dist/kameleoonClient.js.map +1 -1
  33. package/dist/kameleoonData/applicationVersion.d.ts +26 -0
  34. package/dist/kameleoonData/applicationVersion.js +2 -0
  35. package/dist/kameleoonData/applicationVersion.js.map +1 -0
  36. package/dist/kameleoonData/browser.d.ts +16 -1
  37. package/dist/kameleoonData/browser.js +1 -17
  38. package/dist/kameleoonData/browser.js.map +1 -1
  39. package/dist/kameleoonData/constants.d.ts +4 -0
  40. package/dist/kameleoonData/constants.js +2 -0
  41. package/dist/kameleoonData/constants.js.map +1 -0
  42. package/dist/kameleoonData/conversion.d.ts +14 -1
  43. package/dist/kameleoonData/conversion.js +1 -13
  44. package/dist/kameleoonData/conversion.js.map +1 -1
  45. package/dist/kameleoonData/cookie.d.ts +33 -0
  46. package/dist/kameleoonData/cookie.js +2 -0
  47. package/dist/kameleoonData/cookie.js.map +1 -0
  48. package/dist/kameleoonData/customData.d.ts +14 -1
  49. package/dist/kameleoonData/customData.js +1 -24
  50. package/dist/kameleoonData/customData.js.map +1 -1
  51. package/dist/kameleoonData/dataManager.d.ts +38 -0
  52. package/dist/kameleoonData/dataManager.js +2 -0
  53. package/dist/kameleoonData/dataManager.js.map +1 -0
  54. package/dist/kameleoonData/dataProcessor.d.ts +26 -0
  55. package/dist/kameleoonData/dataProcessor.js +2 -0
  56. package/dist/kameleoonData/dataProcessor.js.map +1 -0
  57. package/dist/kameleoonData/device.d.ts +14 -1
  58. package/dist/kameleoonData/device.js +1 -13
  59. package/dist/kameleoonData/device.js.map +1 -1
  60. package/dist/kameleoonData/geolocation.d.ts +52 -0
  61. package/dist/kameleoonData/geolocation.js +2 -0
  62. package/dist/kameleoonData/geolocation.js.map +1 -0
  63. package/dist/kameleoonData/helpers.d.ts +1 -0
  64. package/dist/kameleoonData/helpers.js +2 -0
  65. package/dist/kameleoonData/helpers.js.map +1 -0
  66. package/dist/kameleoonData/index.d.ts +10 -3
  67. package/dist/kameleoonData/index.js +1 -1
  68. package/dist/kameleoonData/index.js.map +1 -1
  69. package/dist/kameleoonData/operatingSystem.d.ts +34 -0
  70. package/dist/kameleoonData/operatingSystem.js +2 -0
  71. package/dist/kameleoonData/operatingSystem.js.map +1 -0
  72. package/dist/kameleoonData/pageView.d.ts +20 -1
  73. package/dist/kameleoonData/pageView.js +1 -13
  74. package/dist/kameleoonData/pageView.js.map +1 -1
  75. package/dist/kameleoonData/types.d.ts +118 -9
  76. package/dist/kameleoonData/types.js +1 -14
  77. package/dist/kameleoonData/types.js.map +1 -1
  78. package/dist/kameleoonData/userAgent.d.ts +6 -1
  79. package/dist/kameleoonData/userAgent.js +1 -8
  80. package/dist/kameleoonData/userAgent.js.map +1 -1
  81. package/dist/kameleoonData/visitsData.d.ts +34 -0
  82. package/dist/{variationConfiguration/variation.js → kameleoonData/visitsData.js} +2 -7
  83. package/dist/kameleoonData/visitsData.js.map +1 -0
  84. package/dist/kameleoonError/constants.d.ts +5 -4
  85. package/dist/kameleoonError/constants.js +1 -1
  86. package/dist/kameleoonError/constants.js.map +1 -1
  87. package/dist/kameleoonError/kameleoonError.d.ts +5 -4
  88. package/dist/kameleoonError/kameleoonError.js +1 -4
  89. package/dist/kameleoonError/kameleoonError.js.map +1 -1
  90. package/dist/kameleoonError/types.d.ts +8 -3
  91. package/dist/kameleoonError/types.js +1 -1
  92. package/dist/kameleoonError/types.js.map +1 -1
  93. package/dist/kameleoonUtils.js +1 -4
  94. package/dist/kameleoonUtils.js.map +1 -1
  95. package/dist/requester/constants.d.ts +2 -1
  96. package/dist/requester/constants.js +1 -1
  97. package/dist/requester/constants.js.map +1 -1
  98. package/dist/requester/index.d.ts +1 -1
  99. package/dist/requester/index.js +1 -1
  100. package/dist/requester/index.js.map +1 -1
  101. package/dist/requester/requester.d.ts +5 -4
  102. package/dist/requester/requester.js +1 -1
  103. package/dist/requester/requester.js.map +1 -1
  104. package/dist/requester/types.d.ts +73 -8
  105. package/dist/requester/types.js +1 -1
  106. package/dist/requester/types.js.map +1 -1
  107. package/dist/storage/constants.d.ts +1 -0
  108. package/dist/storage/constants.js +1 -4
  109. package/dist/storage/constants.js.map +1 -1
  110. package/dist/storage/index.d.ts +1 -1
  111. package/dist/storage/index.js +1 -1
  112. package/dist/storage/index.js.map +1 -1
  113. package/dist/storage/types.d.ts +5 -8
  114. package/dist/storage/types.js.map +1 -1
  115. package/dist/targeting/conditions/applicationVersion.d.ts +10 -0
  116. package/dist/targeting/conditions/applicationVersion.js +2 -0
  117. package/dist/targeting/conditions/applicationVersion.js.map +1 -0
  118. package/dist/targeting/conditions/{browserCondition.d.ts → browser.d.ts} +1 -1
  119. package/dist/targeting/conditions/browser.js +2 -0
  120. package/dist/targeting/conditions/browser.js.map +1 -0
  121. package/dist/targeting/conditions/conditionFactory.js +1 -1
  122. package/dist/targeting/conditions/conditionFactory.js.map +1 -1
  123. package/dist/targeting/conditions/{conversionCondition.d.ts → conversion.d.ts} +1 -2
  124. package/dist/targeting/conditions/conversion.js +2 -0
  125. package/dist/targeting/conditions/conversion.js.map +1 -0
  126. package/dist/targeting/conditions/cookie.d.ts +15 -0
  127. package/dist/targeting/conditions/cookie.js +2 -0
  128. package/dist/targeting/conditions/cookie.js.map +1 -0
  129. package/dist/targeting/conditions/{customDataCondition.d.ts → customData.d.ts} +1 -1
  130. package/dist/targeting/conditions/customData.js +2 -0
  131. package/dist/targeting/conditions/customData.js.map +1 -0
  132. package/dist/targeting/conditions/{deviceCondition.d.ts → device.d.ts} +1 -1
  133. package/dist/targeting/conditions/{targetExperimentCondition.js → device.js} +2 -2
  134. package/dist/targeting/conditions/device.js.map +1 -0
  135. package/dist/targeting/conditions/{exclusiveExperimentCondition.d.ts → exclusiveCampaign.d.ts} +2 -2
  136. package/dist/targeting/conditions/exclusiveCampaign.js +2 -0
  137. package/dist/targeting/conditions/exclusiveCampaign.js.map +1 -0
  138. package/dist/targeting/conditions/firstVisit.d.ts +12 -0
  139. package/dist/targeting/conditions/firstVisit.js +2 -0
  140. package/dist/targeting/conditions/firstVisit.js.map +1 -0
  141. package/dist/targeting/conditions/geolocation.d.ts +11 -0
  142. package/dist/targeting/conditions/geolocation.js +2 -0
  143. package/dist/targeting/conditions/geolocation.js.map +1 -0
  144. package/dist/targeting/conditions/index.d.ts +22 -10
  145. package/dist/targeting/conditions/index.js +1 -1
  146. package/dist/targeting/conditions/index.js.map +1 -1
  147. package/dist/targeting/conditions/lastVisit.d.ts +12 -0
  148. package/dist/targeting/conditions/lastVisit.js +2 -0
  149. package/dist/targeting/conditions/lastVisit.js.map +1 -0
  150. package/dist/targeting/conditions/newVisitor.d.ts +9 -0
  151. package/dist/targeting/conditions/newVisitor.js +2 -0
  152. package/dist/targeting/conditions/newVisitor.js.map +1 -0
  153. package/dist/targeting/conditions/operatingSystem.d.ts +9 -0
  154. package/dist/targeting/conditions/{deviceCondition.js → operatingSystem.js} +2 -2
  155. package/dist/targeting/conditions/operatingSystem.js.map +1 -0
  156. package/dist/targeting/conditions/{pageTitleCondition.d.ts → pageTitle.d.ts} +1 -1
  157. package/dist/targeting/conditions/pageTitle.js +2 -0
  158. package/dist/targeting/conditions/pageTitle.js.map +1 -0
  159. package/dist/targeting/conditions/{pageUrlCondition.d.ts → pageUrl.d.ts} +1 -1
  160. package/dist/targeting/conditions/pageUrl.js +2 -0
  161. package/dist/targeting/conditions/pageUrl.js.map +1 -0
  162. package/dist/targeting/conditions/previousPage.d.ts +12 -0
  163. package/dist/targeting/conditions/previousPage.js +2 -0
  164. package/dist/targeting/conditions/previousPage.js.map +1 -0
  165. package/dist/targeting/conditions/sameDayVisits.d.ts +11 -0
  166. package/dist/targeting/conditions/sameDayVisits.js +2 -0
  167. package/dist/targeting/conditions/sameDayVisits.js.map +1 -0
  168. package/dist/targeting/conditions/{sdkLanguageCondition.d.ts → sdkLanguage.d.ts} +1 -4
  169. package/dist/targeting/conditions/sdkLanguage.js +2 -0
  170. package/dist/targeting/conditions/sdkLanguage.js.map +1 -0
  171. package/dist/targeting/conditions/segment.d.ts +9 -0
  172. package/dist/targeting/conditions/segment.js +2 -0
  173. package/dist/targeting/conditions/segment.js.map +1 -0
  174. package/dist/targeting/conditions/targetFeatureFlag.d.ts +11 -0
  175. package/dist/targeting/conditions/targetFeatureFlag.js +2 -0
  176. package/dist/targeting/conditions/targetFeatureFlag.js.map +1 -0
  177. package/dist/targeting/conditions/types.d.ts +20 -13
  178. package/dist/targeting/conditions/types.js.map +1 -1
  179. package/dist/targeting/conditions/visitedPages.d.ts +11 -0
  180. package/dist/targeting/conditions/visitedPages.js +2 -0
  181. package/dist/targeting/conditions/visitedPages.js.map +1 -0
  182. package/dist/targeting/conditions/{visitorCodeCondition.d.ts → visitorCode.d.ts} +1 -1
  183. package/dist/targeting/conditions/visitorCode.js +2 -0
  184. package/dist/targeting/conditions/visitorCode.js.map +1 -0
  185. package/dist/targeting/conditions/visits.d.ts +11 -0
  186. package/dist/targeting/conditions/visits.js +2 -0
  187. package/dist/targeting/conditions/visits.js.map +1 -0
  188. package/dist/targeting/index.d.ts +3 -3
  189. package/dist/targeting/index.js +1 -1
  190. package/dist/targeting/index.js.map +1 -1
  191. package/dist/targeting/{targetingNode.d.ts → node.d.ts} +7 -7
  192. package/dist/targeting/node.js +2 -0
  193. package/dist/targeting/node.js.map +1 -0
  194. package/dist/targeting/{targetingTree.d.ts → tree.d.ts} +6 -3
  195. package/dist/targeting/tree.js +2 -0
  196. package/dist/targeting/tree.js.map +1 -0
  197. package/dist/targeting/types.d.ts +30 -8
  198. package/dist/targeting/types.js +1 -1
  199. package/dist/targeting/types.js.map +1 -1
  200. package/dist/types.d.ts +17 -6
  201. package/dist/types.js +1 -41
  202. package/dist/types.js.map +1 -1
  203. package/dist/utilities/index.d.ts +1 -0
  204. package/dist/utilities/index.js +1 -1
  205. package/dist/utilities/index.js.map +1 -1
  206. package/dist/utilities/types.d.ts +61 -6
  207. package/dist/utilities/types.js +1 -1
  208. package/dist/utilities/types.js.map +1 -1
  209. package/dist/utilities/utilities.d.ts +24 -11
  210. package/dist/utilities/utilities.js +1 -1
  211. package/dist/utilities/utilities.js.map +1 -1
  212. package/dist/variationConfiguration/index.d.ts +1 -1
  213. package/dist/variationConfiguration/index.js +1 -1
  214. package/dist/variationConfiguration/index.js.map +1 -1
  215. package/dist/variationConfiguration/types.d.ts +5 -12
  216. package/dist/variationConfiguration/types.js.map +1 -1
  217. package/dist/variationConfiguration/variationConfiguration.d.ts +13 -21
  218. package/dist/variationConfiguration/variationConfiguration.js +1 -65
  219. package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
  220. package/package.json +1 -1
  221. package/dist/campaignConfiguration/campaignConfiguration.d.ts +0 -71
  222. package/dist/campaignConfiguration/campaignConfiguration.js +0 -24
  223. package/dist/campaignConfiguration/campaignConfiguration.js.map +0 -1
  224. package/dist/campaignConfiguration/constants.d.ts +0 -6
  225. package/dist/campaignConfiguration/constants.js +0 -4
  226. package/dist/campaignConfiguration/constants.js.map +0 -1
  227. package/dist/campaignConfiguration/index.d.ts +0 -3
  228. package/dist/campaignConfiguration/index.js +0 -2
  229. package/dist/campaignConfiguration/index.js.map +0 -1
  230. package/dist/campaignConfiguration/types.js +0 -2
  231. package/dist/campaignConfiguration/types.js.map +0 -1
  232. package/dist/targeting/conditions/browserCondition.js +0 -2
  233. package/dist/targeting/conditions/browserCondition.js.map +0 -1
  234. package/dist/targeting/conditions/conversionCondition.js +0 -4
  235. package/dist/targeting/conditions/conversionCondition.js.map +0 -1
  236. package/dist/targeting/conditions/customDataCondition.js +0 -8
  237. package/dist/targeting/conditions/customDataCondition.js.map +0 -1
  238. package/dist/targeting/conditions/deviceCondition.js.map +0 -1
  239. package/dist/targeting/conditions/exclusiveExperimentCondition.js +0 -2
  240. package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +0 -1
  241. package/dist/targeting/conditions/pageTitleCondition.js +0 -2
  242. package/dist/targeting/conditions/pageTitleCondition.js.map +0 -1
  243. package/dist/targeting/conditions/pageUrlCondition.js +0 -2
  244. package/dist/targeting/conditions/pageUrlCondition.js.map +0 -1
  245. package/dist/targeting/conditions/sdkLanguageCondition.js +0 -2
  246. package/dist/targeting/conditions/sdkLanguageCondition.js.map +0 -1
  247. package/dist/targeting/conditions/targetExperimentCondition.d.ts +0 -12
  248. package/dist/targeting/conditions/targetExperimentCondition.js.map +0 -1
  249. package/dist/targeting/conditions/visitorCodeCondition.js +0 -2
  250. package/dist/targeting/conditions/visitorCodeCondition.js.map +0 -1
  251. package/dist/targeting/targetingNode.js +0 -2
  252. package/dist/targeting/targetingNode.js.map +0 -1
  253. package/dist/targeting/targetingTree.js +0 -35
  254. package/dist/targeting/targetingTree.js.map +0 -1
  255. package/dist/variationConfiguration/variation.d.ts +0 -13
  256. package/dist/variationConfiguration/variation.js.map +0 -1
@@ -1,35 +1,27 @@
1
1
  import { Result } from 'ts-res';
2
- import { ExperimentItemType } from '../campaignConfiguration';
3
2
  import { KameleoonError } from '../kameleoonError';
4
- import { IExternalStorage, VariationDataType, ExperimentVariationsType } from '../storage';
5
- import { FeatureFlagVariationType, GetFeatureFlagVariationParametersType } from './types';
3
+ import { IExternalStorage, VariationDataType } from '../storage';
4
+ import { FeatureFlagVariationType, GetVariationParametersType } from './types';
5
+ import { FeatureFlagVariationsType } from '../storage/types';
6
6
  interface IVariationConfiguration {
7
7
  /**
8
- * @method getAssociatedVariationId - gets the id of a variation assigned to a visitor with `visitorCode` from the storage. If the visitor doesn't have associated variation yet, assigns a new one, stores it and returns it's id.
8
+ * @method getStoredVariations - obtains campaigns with according variations that are *already assigned* and *stored* in the `variationStorage`.
9
9
  */
10
- getAssociatedVariationId: (visitorCode: string, experimentId: number) => Result<number, KameleoonError>;
10
+ getStoredVariations(visitorCode: string): Result<FeatureFlagVariationsType, KameleoonError>;
11
11
  /**
12
- * @method getAssignedVariations - obtains experiments with according variations that are *already assigned* and *stored* in the `variationStorage`. If `getAssociatedVariationId` had not been called before, there will be no variations to get.
12
+ * @method updateStoredVariations - updates stored variations for the visitor
13
13
  */
14
- getAssignedVariations(visitorCode: string): Result<ExperimentVariationsType, KameleoonError>;
14
+ updateStoredVariations: (visitorCode: string, variationData: FeatureFlagVariationsType) => void;
15
15
  /**
16
- * @method getFeatureFlagVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage
16
+ * @method getVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage
17
17
  */
18
- getFeatureFlagVariation: (params: GetFeatureFlagVariationParametersType) => Result<FeatureFlagVariationType, KameleoonError>;
19
- /**
20
- * @method getExperimentVariation - obtains variation for the experiment by calculating the variation for the visitor *without assigning* it to a visitor
21
- */
22
- getExperimentVariation: (visitorCode: string, experiment: ExperimentItemType) => Result<number, KameleoonError>;
18
+ getVariation: (params: GetVariationParametersType) => Result<FeatureFlagVariationType, KameleoonError>;
23
19
  }
24
20
  export declare class VariationConfiguration implements IVariationConfiguration {
25
- private experiments;
26
21
  private storage;
27
- constructor(experiments: ExperimentItemType[], externalStorage: IExternalStorage<VariationDataType>);
28
- getAssociatedVariationId: (visitorCode: string, experimentId: number) => Result<number, KameleoonError>;
29
- getAssignedVariations(visitorCode: string): Result<ExperimentVariationsType, KameleoonError>;
30
- getFeatureFlagVariation({ visitorCode, featureFlag, targetingData, packageInfo, campaignConfiguration, withAssignment, }: GetFeatureFlagVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>;
31
- getExperimentVariation(visitorCode: string, experiment: ExperimentItemType): Result<number, KameleoonError>;
32
- private assignVariation;
33
- private updateStorageData;
22
+ constructor(externalStorage: IExternalStorage<VariationDataType>);
23
+ getStoredVariations(visitorCode: string): Result<FeatureFlagVariationsType, KameleoonError>;
24
+ getVariation({ visitorCode, featureFlag, targetingData, packageInfo, clientConfiguration, dataManager, withAssignment, }: GetVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>;
25
+ updateStoredVariations(visitorCode: string, variationData: FeatureFlagVariationsType): Result<void, KameleoonError>;
34
26
  }
35
27
  export {};
@@ -1,66 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariationConfiguration=void 0;var _tsRes=require("ts-res"),_hasher=require("../hasher"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_types=require("../campaignConfiguration/types"),_excluded=["exposition"];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 ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}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 VariationConfiguration=/*#__PURE__*/function(){function a(b,c){var d=this;_classCallCheck(this,a),_defineProperty(this,"experiments",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"getAssociatedVariationId",function(a,b){// TODO:
2
- // --- Variation from storage is not checked anymore
3
- // --- If nothing changes the commented code should be deleted
4
- // along with the `Variation` class and according tests/types
5
- // --- Mind `todo` in `getAssociatedVariationId.spec.ts`
6
- //
7
- // let associatedVariation: VariationType | undefined;
8
- // this.storage.read().and((data) => {
9
- // associatedVariation = data?.[visitorCode]?.[experimentId];
10
- // });
11
- var c=d.experiments.find(function(a){return a.id===b+""});return c?d.assignVariation(a,c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ExperimentConfigurationNotFound,b,a));// const variation = new Variation(associatedVariation);
12
- // if (variation.isValid(experiment?.respoolTime)) {
13
- // return Ok(variation.id);
14
- // }
15
- }),this.experiments=b,this.storage=c}return _createClass(a,[{key:"getAssignedVariations",value:function getAssignedVariations(a){var b=this.storage.read();if(!b.ok)return b;var c=b.data[a];return c?(0,_tsRes.Ok)(c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageRead,a))}},{key:"getFeatureFlagVariation",value:function getFeatureFlagVariation(a){var b=a.visitorCode,c=a.featureFlag,d=a.targetingData,e=a.packageInfo,f=a.campaignConfiguration,g=a.withAssignment,h=_utilities.Utilities.validateVisitorCode(b);if(!h.ok)return(0,_tsRes.Err)(h.error);var i,j=c.rules,k=c.featureKey,l=c.id,m=c.defaultVariationKey,n=_createForOfIteratorHelper(j);try{for(n.s();!(i=n.n()).done;){var o=i.value,p=o.segment,q=o.experimentId,r=o.id,s=o.exposition,t=o.respoolTime,u=o.variationByExposition,v=_utilities.Utilities.checkTargeting({segment:p,visitorCode:b,experimentId:q,targetingData:d,packageInfo:e,campaignConfiguration:f,variationConfiguration:this});if(!v.ok)return v;if(v.data){// --- Note ---
16
- // Calculate new variation (and assign it if `withAssignment` is `true`)
17
- // First the the exposed rule is calculated and then the variation inside of it
18
- var w=_hasher.Hasher.obtainFeatureFlagHashDouble({visitorCode:b,respoolTime:t,campaignId:r+""});if(w<=s){var x,y=0,z=_hasher.Hasher.obtainFeatureFlagHashDouble({visitorCode:b,respoolTime:t,campaignId:q+""}),A=_createForOfIteratorHelper(u);try{for(A.s();!(x=A.n()).done;){var B=x.value;if(y+=B.exposition,z<=y){o.type===_types.RuleType.EXPERIMENTATION&&void 0!==g&&g&&this.updateStorageData({visitorCode:b,experimentId:q+"",// --- Note ---
19
- // For `RuleType.EXPERIMENTATION` `variationId` can not be null
20
- variationId:B.variationId});var C=B.exposition,D=_objectWithoutProperties(B,_excluded);return(0,_tsRes.Ok)(_objectSpread(_objectSpread({},D),{},{rule:o,featureFlagId:l,featureKey:k,experimentId:q}))}}}catch(a){A.e(a)}finally{A.f()}}if(o.type===_types.RuleType.TARGETED_DELIVERY)break}}}catch(a){n.e(a)}finally{n.f()}return(0,_tsRes.Ok)({featureKey:k,featureFlagId:l,experimentId:null,variationKey:m,variationId:null,rule:null})}},{key:"getExperimentVariation",value:function getExperimentVariation(a,b){var c,d=b.id,e=b.respoolTime,f=b.deviations,g=_hasher.Hasher.obtainExperimentHashDouble({visitorCode:a,campaignId:d,respoolTime:e}),h=!0,i=0,j=0,k=_createForOfIteratorHelper(f);try{for(k.s();!(c=k.n()).done;){var l=c.value;if(i+=l.value,i>=g){h=!1,"origin"!==l.variationId&&(j=+l.variationId);break}}}catch(a){k.e(a)}finally{k.f()}return h?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NotAllocated,a)):(0,_tsRes.Ok)(j)}},{key:"assignVariation",value:function assignVariation(a,b){var c=this.getExperimentVariation(a,b);if(!c.ok)return c;var d=this.updateStorageData({visitorCode:a,experimentId:b.id,variationId:c.data});return d.ok?(0,_tsRes.Ok)(c.data):d}},{key:"updateStorageData",value:function updateStorageData(a){var b=a.visitorCode,c=a.experimentId,d=a.variationId,e=this.storage.read();if(!e.ok&&e.error.type===_kameleoonError.KameleoonException.StorageParse)// --- Note ---
21
- // If there is a parsing error we return error
22
- // But if there is `LocalStorageRead` error it means that
23
- // data was read successfully and it's empty, which is not problem
24
- // cause that might be initial `read`
25
- return e;var f=e.ok?e.data:{},g={variationId:d,assignmentDate:new Date().toString()};return f[b]?f[b][c]=g:f[b]=_defineProperty({},c,g),this.storage.write(f)}// --- TODO: commented out in case of future logic rework ---
26
- // --- Mind: `variationId` could cause the `undefined` issue ---
27
- // --- Reference: https://development.kameleoon.net/sdk/javascript-sdk-packages/-/merge_requests/89 ---
28
- // private getAssignedRuleVariation(
29
- // visitorCode: string,
30
- // rule: RuleItemType,
31
- // ): Result<GetAssignedRuleVariationResultType, KameleoonError> {
32
- // const emptyVariation: Omit<VariationByExpositionType, 'exposition'> = {
33
- // variationId: null,
34
- // variationKey: '',
35
- // };
36
- // const { experimentId, variationByExposition } = rule;
37
- // const variationsResult = this.getAssignedVariations(visitorCode);
38
- // // --- Note ---
39
- // // If there is an error, we just want to skip seeking
40
- // // for variation in the storage, not throw an error
41
- // if (!variationsResult.ok) {
42
- // return Ok(emptyVariation);
43
- // }
44
- // const variations = variationsResult.data;
45
- // if (
46
- // experimentId &&
47
- // typeof variations[experimentId].variationId !== undefined
48
- // ) {
49
- // const id = variations[experimentId].variationId;
50
- // const featureFlagVariation = variationByExposition.find(
51
- // (item) => item.variationId == id,
52
- // );
53
- // if (!featureFlagVariation) {
54
- // // --- Note ---
55
- // // This error is not described for public methods as
56
- // // it serves internal purpose of checking whether
57
- // // the persistent variation has been updated and should be re-allocated
58
- // return Err(new KameleoonError(KameleoonException.DataInconsistency));
59
- // }
60
- // const { exposition, ...restParameters } = featureFlagVariation;
61
- // return Ok({ ...restParameters });
62
- // }
63
- // return Ok(emptyVariation);
64
- // }
65
- }]),a}();exports.VariationConfiguration=VariationConfiguration;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariationConfiguration=void 0;var _tsRes=require("ts-res"),_hasher=require("../hasher"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_types=require("../clientConfiguration/types"),_excluded=["exposition"];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 ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}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 VariationConfiguration=function(){function a(b){_classCallCheck(this,a),_defineProperty(this,"storage",void 0),this.storage=b}return _createClass(a,[{key:"getStoredVariations",value:function getStoredVariations(a){var b=this.storage.read();if(!b.ok)return b;var c=b.data[a];return c?(0,_tsRes.Ok)(c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageRead,a))}},{key:"getVariation",value:function getVariation(a){var b=a.visitorCode,c=a.featureFlag,d=a.targetingData,e=a.packageInfo,f=a.clientConfiguration,g=a.dataManager,h=a.withAssignment,i=_utilities.Utilities.validateVisitorCode(b);if(!i.ok)return(0,_tsRes.Err)(i.error);var j,k=c.rules,l=c.featureKey,m=c.id,n=c.defaultVariationKey,o=_createForOfIteratorHelper(k);try{for(o.s();!(j=o.n()).done;){var p=j.value,q=p.segment,r=p.experimentId,s=p.id,t=p.exposition,u=p.respoolTime,v=p.variationByExposition,w=_utilities.Utilities.checkTargeting({segment:q,visitorCode:b,experimentId:r,targetingData:d,packageInfo:e,clientConfiguration:f,dataManager:g,variationConfiguration:this});if(!w.ok)return w;if(w.data){var x=_hasher.Hasher.getHashDouble({visitorCode:b,respoolTime:u,id:s+""});if(x<=t){var y,z=0,A=_hasher.Hasher.getHashDouble({visitorCode:b,respoolTime:u,id:r+""}),B=_createForOfIteratorHelper(v);try{for(B.s();!(y=B.n()).done;){var C=y.value;if(z+=C.exposition,A<=z){void 0!==h&&h&&this.updateStoredVariations(b,_defineProperty({},r,C.variationId));var D=C.exposition,E=_objectWithoutProperties(C,_excluded);return(0,_tsRes.Ok)(_objectSpread(_objectSpread({},E),{},{rule:p,featureFlagId:m,featureKey:l,experimentId:r}))}}}catch(a){B.e(a)}finally{B.f()}}if(p.type===_types.RuleType.TARGETED_DELIVERY)break}}}catch(a){o.e(a)}finally{o.f()}return(0,_tsRes.Ok)({featureKey:l,featureFlagId:m,experimentId:null,variationKey:n,variationId:null,rule:null})}},{key:"updateStoredVariations",value:function updateStoredVariations(a,b){var c=this.storage.read();if(!c.ok&&c.error.type===_kameleoonError.KameleoonException.StorageParse)return c;var d=c.ok?c.data:{};return d[a]?d[a]=_objectSpread(_objectSpread({},d[a]),b):d=_objectSpread(_objectSpread({},d),{},_defineProperty({},a,_objectSpread({},b))),this.storage.write(d)}}]),a}();exports.VariationConfiguration=VariationConfiguration;
66
2
  //# sourceMappingURL=variationConfiguration.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"variationConfiguration.js","names":["VariationConfiguration","a","experiments","externalStorage","d","_classCallCheck","_defineProperty","visitorCode","experimentId","experiment","find","id","assignVariation","Err","KameleoonError","KameleoonException","ExperimentConfigurationNotFound","storage","_createClass","key","value","getAssignedVariations","result","read","ok","data","Ok","StorageRead","getFeatureFlagVariation","featureFlag","targetingData","packageInfo","campaignConfiguration","g","withAssignment","validateResult","Utilities","validateVisitorCode","error","i","rules","featureKey","featureFlagId","defaultVariationKey","n","_createForOfIteratorHelper","s","done","rule","segment","exposition","respoolTime","variationByExposition","targetingResult","checkTargeting","variationConfiguration","ruleHash","Hasher","obtainFeatureFlagHashDouble","campaignId","x","totalDeviation","variationHash","A","variation","type","RuleType","EXPERIMENTATION","updateStorageData","variationId","restParameters","_objectWithoutProperties","_excluded","_objectSpread","e","f","TARGETED_DELIVERY","variationKey","getExperimentVariation","c","deviations","hashDouble","obtainExperimentHashDouble","isUnallocated","resultVariationId","k","deviation","NotAllocated","variationResult","StorageParse","updatedVariationData","updatedVariation","assignmentDate","Date","toString","write","exports"],"sources":["../../src/variationConfiguration/variationConfiguration.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { ExperimentItemType } from 'src/campaignConfiguration';\nimport { Hasher } from 'src/hasher';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport {\n IExternalStorage,\n VariationDataType,\n ExperimentVariationsType,\n} from 'src/storage';\nimport { Utilities } from 'src/utilities';\nimport { RuleType } from 'src/campaignConfiguration/types';\nimport {\n FeatureFlagVariationType,\n GetFeatureFlagVariationParametersType,\n UpdateStorageParamsType,\n} from './types';\n\ninterface IVariationConfiguration {\n /**\n * @method getAssociatedVariationId - gets the id of a variation assigned to a visitor with `visitorCode` from the storage. If the visitor doesn't have associated variation yet, assigns a new one, stores it and returns it's id.\n */\n getAssociatedVariationId: (\n visitorCode: string,\n experimentId: number,\n ) => Result<number, KameleoonError>;\n /**\n * @method getAssignedVariations - obtains experiments with according variations that are *already assigned* and *stored* in the `variationStorage`. If `getAssociatedVariationId` had not been called before, there will be no variations to get.\n */\n getAssignedVariations(\n visitorCode: string,\n ): Result<ExperimentVariationsType, KameleoonError>;\n /**\n * @method getFeatureFlagVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage\n */\n getFeatureFlagVariation: (\n params: GetFeatureFlagVariationParametersType,\n ) => Result<FeatureFlagVariationType, KameleoonError>;\n /**\n * @method getExperimentVariation - obtains variation for the experiment by calculating the variation for the visitor *without assigning* it to a visitor\n */\n getExperimentVariation: (\n visitorCode: string,\n experiment: ExperimentItemType,\n ) => Result<number, KameleoonError>;\n}\n\nexport class VariationConfiguration implements IVariationConfiguration {\n private experiments: ExperimentItemType[];\n private storage: IExternalStorage<VariationDataType>;\n\n constructor(\n experiments: ExperimentItemType[],\n externalStorage: IExternalStorage<VariationDataType>,\n ) {\n this.experiments = experiments;\n this.storage = externalStorage;\n }\n\n public getAssociatedVariationId = (\n visitorCode: string,\n experimentId: number,\n ): Result<number, KameleoonError> => {\n // TODO:\n // --- Variation from storage is not checked anymore\n // --- If nothing changes the commented code should be deleted\n // along with the `Variation` class and according tests/types\n // --- Mind `todo` in `getAssociatedVariationId.spec.ts`\n //\n // let associatedVariation: VariationType | undefined;\n\n // this.storage.read().and((data) => {\n // associatedVariation = data?.[visitorCode]?.[experimentId];\n // });\n\n const experiment = this.experiments.find(\n (experiment) => experiment.id === String(experimentId),\n );\n\n if (!experiment) {\n return Err(\n new KameleoonError(\n KameleoonException.ExperimentConfigurationNotFound,\n experimentId,\n visitorCode,\n ),\n );\n }\n\n // const variation = new Variation(associatedVariation);\n\n // if (variation.isValid(experiment?.respoolTime)) {\n // return Ok(variation.id);\n // }\n\n return this.assignVariation(visitorCode, experiment);\n };\n\n public getAssignedVariations(\n visitorCode: string,\n ): Result<ExperimentVariationsType, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n const experiments = result.data[visitorCode];\n\n if (!experiments) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, visitorCode),\n );\n }\n\n return Ok(experiments);\n }\n\n public getFeatureFlagVariation({\n visitorCode,\n featureFlag,\n targetingData,\n packageInfo,\n campaignConfiguration,\n withAssignment = false,\n }: GetFeatureFlagVariationParametersType): Result<\n FeatureFlagVariationType,\n KameleoonError\n > {\n const validateResult = Utilities.validateVisitorCode(visitorCode);\n\n if (!validateResult.ok) {\n return Err(validateResult.error);\n }\n\n const {\n rules,\n featureKey,\n id: featureFlagId,\n defaultVariationKey,\n } = featureFlag;\n\n for (const rule of rules) {\n const {\n segment,\n experimentId,\n id,\n exposition,\n respoolTime,\n variationByExposition,\n } = rule;\n\n // --- Check targeting ---\n const targetingResult = Utilities.checkTargeting({\n segment,\n visitorCode,\n experimentId,\n targetingData,\n packageInfo,\n campaignConfiguration,\n variationConfiguration: this,\n });\n\n if (!targetingResult.ok) {\n return targetingResult;\n }\n\n if (!targetingResult.data) {\n continue;\n }\n\n // --- Note ---\n // Calculate new variation (and assign it if `withAssignment` is `true`)\n // First the the exposed rule is calculated and then the variation inside of it\n const ruleHash = Hasher.obtainFeatureFlagHashDouble({\n visitorCode,\n respoolTime,\n campaignId: String(id),\n });\n\n if (ruleHash <= exposition) {\n let totalDeviation = 0;\n\n const variationHash = Hasher.obtainFeatureFlagHashDouble({\n visitorCode,\n respoolTime,\n campaignId: String(experimentId),\n });\n\n for (const variation of variationByExposition) {\n totalDeviation += variation.exposition;\n\n if (variationHash <= totalDeviation) {\n // --- Note ---\n // For the `RuleType.EXPERIMENTATION` variation assignment must happen without\n // calculating experiment deviation\n if (rule.type === RuleType.EXPERIMENTATION && withAssignment) {\n this.updateStorageData({\n visitorCode,\n experimentId: String(experimentId),\n // --- Note ---\n // For `RuleType.EXPERIMENTATION` `variationId` can not be null\n variationId: variation.variationId as number,\n });\n }\n\n const { exposition, ...restParameters } = variation;\n\n return Ok({\n ...restParameters,\n rule,\n featureFlagId,\n featureKey,\n experimentId,\n });\n }\n }\n }\n\n if (rule.type === RuleType.TARGETED_DELIVERY) {\n break;\n }\n }\n\n return Ok({\n featureKey,\n featureFlagId,\n experimentId: null,\n variationKey: defaultVariationKey,\n variationId: null,\n rule: null,\n });\n }\n\n public getExperimentVariation(\n visitorCode: string,\n experiment: ExperimentItemType,\n ): Result<number, KameleoonError> {\n const { id, respoolTime, deviations } = experiment;\n\n const hashDouble = Hasher.obtainExperimentHashDouble({\n visitorCode,\n campaignId: id,\n respoolTime,\n });\n\n let isUnallocated = true;\n let totalDeviation = 0;\n let resultVariationId = 0;\n\n for (const deviation of deviations) {\n totalDeviation += deviation.value;\n\n if (totalDeviation >= hashDouble) {\n // --- Note ---\n // If sum of all variations is less than 1 (100%), then there is a chance\n // user will end up outside of any variation\n isUnallocated = false;\n // --- Note ---\n // 'origin' is the default `variationId`, it must return id of 0\n if (deviation.variationId !== 'origin') {\n resultVariationId = Number(deviation.variationId);\n }\n\n break;\n }\n }\n\n if (isUnallocated) {\n return Err(\n new KameleoonError(KameleoonException.NotAllocated, visitorCode),\n );\n }\n\n return Ok(resultVariationId);\n }\n\n private assignVariation(\n visitorCode: string,\n experiment: ExperimentItemType,\n ): Result<number, KameleoonError> {\n const variationResult = this.getExperimentVariation(\n visitorCode,\n experiment,\n );\n\n if (!variationResult.ok) {\n return variationResult;\n }\n\n const result = this.updateStorageData({\n visitorCode,\n experimentId: experiment.id,\n variationId: variationResult.data,\n });\n\n if (!result.ok) {\n return result;\n }\n\n return Ok(variationResult.data);\n }\n\n private updateStorageData({\n visitorCode,\n experimentId,\n variationId,\n }: UpdateStorageParamsType): Result<void, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n // --- Note ---\n // If there is a parsing error we return error\n // But if there is `LocalStorageRead` error it means that\n // data was read successfully and it's empty, which is not problem\n // cause that might be initial `read`\n if (result.error.type === KameleoonException.StorageParse) {\n return result;\n }\n }\n\n const updatedVariationData: VariationDataType = result.ok\n ? result.data\n : {};\n\n const updatedVariation = {\n variationId,\n assignmentDate: new Date().toString(),\n };\n\n if (updatedVariationData[visitorCode]) {\n updatedVariationData[visitorCode][experimentId] = updatedVariation;\n } else {\n updatedVariationData[visitorCode] = {\n [experimentId]: updatedVariation,\n };\n }\n\n return this.storage.write(updatedVariationData);\n }\n\n // --- TODO: commented out in case of future logic rework ---\n // --- Mind: `variationId` could cause the `undefined` issue ---\n // --- Reference: https://development.kameleoon.net/sdk/javascript-sdk-packages/-/merge_requests/89 ---\n // private getAssignedRuleVariation(\n // visitorCode: string,\n // rule: RuleItemType,\n // ): Result<GetAssignedRuleVariationResultType, KameleoonError> {\n // const emptyVariation: Omit<VariationByExpositionType, 'exposition'> = {\n // variationId: null,\n // variationKey: '',\n // };\n // const { experimentId, variationByExposition } = rule;\n\n // const variationsResult = this.getAssignedVariations(visitorCode);\n\n // // --- Note ---\n // // If there is an error, we just want to skip seeking\n // // for variation in the storage, not throw an error\n // if (!variationsResult.ok) {\n // return Ok(emptyVariation);\n // }\n\n // const variations = variationsResult.data;\n\n // if (\n // experimentId &&\n // typeof variations[experimentId].variationId !== undefined\n // ) {\n // const id = variations[experimentId].variationId;\n // const featureFlagVariation = variationByExposition.find(\n // (item) => item.variationId == id,\n // );\n\n // if (!featureFlagVariation) {\n // // --- Note ---\n // // This error is not described for public methods as\n // // it serves internal purpose of checking whether\n // // the persistent variation has been updated and should be re-allocated\n // return Err(new KameleoonError(KameleoonException.DataInconsistency));\n // }\n\n // const { exposition, ...restParameters } = featureFlagVariation;\n\n // return Ok({ ...restParameters });\n // }\n\n // return Ok(emptyVariation);\n // }\n}\n"],"mappings":"iuHA8Ca,CAAAA,sBAAsB,yBAIjC,SAAAC,EACEC,CAAiC,CACjCC,CAAoD,CACpD,KAAAC,CAAA,MAAAC,eAAA,MAAAJ,CAAA,EAAAK,eAAA,4BAAAA,eAAA,wBAAAA,eAAA,iCAKgC,SAChCC,CAAmB,CACnBC,CAAoB,CACe,CACnC;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA,GAAM,CAAAC,CAAU,CAAGL,CAAI,CAACF,WAAW,CAACQ,IAAI,CACtC,SAACD,CAAU,QAAK,CA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EACrC,CAAC,CAUD,MARI,CAAAJ,CAAoB,CAACnF,CAAW,CAAC,CACnCmF,CAAoB,CAACnF,CAAW,CAAC,CAACC,CAAY,CAAC,CAAGmF,CAAgB,CAElED,CAAoB,CAACnF,CAAW,CAAC,CAAAD,eAAA,IAC9BE,CAAY,CAAGmF,CAAgB,CACjC,CAGI,IAAI,CAAC1E,OAAO,CAAC8E,KAAK,CAACL,CAAoB,CAChD,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAEA;AACA;AAEA;AACA;AAAA,IAAAzF,CAAA,IAAA+F,OAAA,CAAAhG,sBAAA,CAAAA,sBAAA"}
1
+ {"version":3,"file":"variationConfiguration.js","names":["VariationConfiguration","a","externalStorage","_classCallCheck","_defineProperty","storage","_createClass","key","value","getStoredVariations","visitorCode","result","read","ok","featureFlagVariations","data","Ok","Err","KameleoonError","KameleoonException","StorageRead","getVariation","featureFlag","targetingData","packageInfo","clientConfiguration","dataManager","h","withAssignment","validateResult","Utilities","validateVisitorCode","error","j","rules","featureKey","featureFlagId","id","defaultVariationKey","o","_createForOfIteratorHelper","s","n","done","rule","segment","experimentId","exposition","respoolTime","variationByExposition","targetingResult","checkTargeting","variationConfiguration","ruleHash","Hasher","getHashDouble","y","totalDeviation","variationHash","B","variation","updateStoredVariations","variationId","restParameters","_objectWithoutProperties","_excluded","_objectSpread","e","f","type","RuleType","TARGETED_DELIVERY","variationKey","variationData","StorageParse","updatedVariationData","write","exports"],"sources":["../../src/variationConfiguration/variationConfiguration.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { Hasher } from 'src/hasher';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { IExternalStorage, VariationDataType } from 'src/storage';\nimport { Utilities } from 'src/utilities';\nimport { RuleType } from 'src/clientConfiguration/types';\nimport { FeatureFlagVariationType, GetVariationParametersType } from './types';\nimport { FeatureFlagVariationsType } from 'src/storage/types';\n\ninterface IVariationConfiguration {\n /**\n * @method getStoredVariations - obtains campaigns with according variations that are *already assigned* and *stored* in the `variationStorage`.\n */\n getStoredVariations(\n visitorCode: string,\n ): Result<FeatureFlagVariationsType, KameleoonError>;\n /**\n * @method updateStoredVariations - updates stored variations for the visitor\n */\n updateStoredVariations: (\n visitorCode: string,\n variationData: FeatureFlagVariationsType,\n ) => void;\n /**\n * @method getVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage\n */\n getVariation: (\n params: GetVariationParametersType,\n ) => Result<FeatureFlagVariationType, KameleoonError>;\n}\n\nexport class VariationConfiguration implements IVariationConfiguration {\n private storage: IExternalStorage<VariationDataType>;\n\n constructor(externalStorage: IExternalStorage<VariationDataType>) {\n this.storage = externalStorage;\n }\n\n public getStoredVariations(\n visitorCode: string,\n ): Result<FeatureFlagVariationsType, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n const featureFlagVariations = result.data[visitorCode];\n\n if (!featureFlagVariations) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, visitorCode),\n );\n }\n\n return Ok(featureFlagVariations);\n }\n\n public getVariation({\n visitorCode,\n featureFlag,\n targetingData,\n packageInfo,\n clientConfiguration,\n dataManager,\n withAssignment = false,\n }: GetVariationParametersType): Result<\n FeatureFlagVariationType,\n KameleoonError\n > {\n const validateResult = Utilities.validateVisitorCode(visitorCode);\n\n if (!validateResult.ok) {\n return Err(validateResult.error);\n }\n\n const {\n rules,\n featureKey,\n id: featureFlagId,\n defaultVariationKey,\n } = featureFlag;\n\n for (const rule of rules) {\n const {\n segment,\n experimentId,\n id,\n exposition,\n respoolTime,\n variationByExposition,\n } = rule;\n\n // --- Check targeting ---\n const targetingResult = Utilities.checkTargeting({\n segment,\n visitorCode,\n experimentId,\n targetingData,\n packageInfo,\n clientConfiguration,\n dataManager,\n variationConfiguration: this,\n });\n\n if (!targetingResult.ok) {\n return targetingResult;\n }\n\n if (!targetingResult.data) {\n continue;\n }\n\n // --- Note ---\n // Calculate new variation (and assign it if `withAssignment` is `true`)\n // First the the exposed rule is calculated and then the variation inside of it\n const ruleHash = Hasher.getHashDouble({\n visitorCode,\n respoolTime,\n id: String(id),\n });\n\n if (ruleHash <= exposition) {\n let totalDeviation = 0;\n\n const variationHash = Hasher.getHashDouble({\n visitorCode,\n respoolTime,\n id: String(experimentId),\n });\n\n for (const variation of variationByExposition) {\n totalDeviation += variation.exposition;\n\n if (variationHash <= totalDeviation) {\n if (withAssignment) {\n this.updateStoredVariations(visitorCode, {\n [experimentId]: variation.variationId,\n });\n }\n\n const { exposition, ...restParameters } = variation;\n\n return Ok({\n ...restParameters,\n rule,\n featureFlagId,\n featureKey,\n experimentId,\n });\n }\n }\n }\n\n if (rule.type === RuleType.TARGETED_DELIVERY) {\n break;\n }\n }\n\n return Ok({\n featureKey,\n featureFlagId,\n experimentId: null,\n variationKey: defaultVariationKey,\n variationId: null,\n rule: null,\n });\n }\n\n public updateStoredVariations(\n visitorCode: string,\n variationData: FeatureFlagVariationsType,\n ): Result<void, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n // --- Note ---\n // If there is a parsing error we return error\n // But if there is `LocalStorageRead` error it means that\n // data was read successfully and it's empty, which is not problem\n // cause that might be initial `read`\n if (result.error.type === KameleoonException.StorageParse) {\n return result;\n }\n }\n\n let updatedVariationData: VariationDataType = result.ok ? result.data : {};\n\n if (updatedVariationData[visitorCode]) {\n updatedVariationData[visitorCode] = {\n ...updatedVariationData[visitorCode],\n ...variationData,\n };\n } else {\n updatedVariationData = {\n ...updatedVariationData,\n [visitorCode]: {\n ...variationData,\n },\n };\n }\n\n return this.storage.write(updatedVariationData);\n }\n}\n"],"mappings":"+tHA+Ba,C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B,GAAM,CAAA9D,CAAM,CAAG,IAAI,CAACN,OAAO,CAACO,IAAI,EAAE,CAElC,GAAI,CAACD,CAAM,CAACE,EAAE,EAMRF,CAAM,CAACqB,KAAK,CAACqC,IAAI,GAAKlD,kCAAkB,CAACuD,YAAY,CACvD,MAAO,CAAA/D,CAAM,CAIjB,GAAI,CAAAgE,CAAuC,CAAGhE,CAAM,CAACE,EAAE,CAAGF,CAAM,CAACI,IAAI,CAAG,CAAC,CAAC,CAgB1E,MAdI,CAAA4D,CAAoB,CAACjE,CAAW,CAAC,CACnCiE,CAAoB,CAACjE,CAAW,CAAC,CAAAwD,aAAA,CAAAA,aAAA,IAC5BS,CAAoB,CAACjE,CAAW,CAAC,EACjC+D,CAAa,CACjB,CAEDE,CAAoB,CAAAT,aAAA,CAAAA,aAAA,IACfS,CAAoB,KAAAvE,eAAA,IACtBM,CAAW,CAAAwD,aAAA,IACPO,CAAa,GAEnB,CAGI,IAAI,CAACpE,OAAO,CAACuE,KAAK,CAACD,CAAoB,CAChD,CAAC,IAAA1E,CAAA,IAAA4E,OAAA,CAAA7E,sBAAA,CAAAA,sBAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kameleoon/javascript-sdk-core",
3
- "version": "2.10.1",
3
+ "version": "3.0.0",
4
4
  "description": "Kameleoon JS SDK Core",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,71 +0,0 @@
1
- import { Result } from 'ts-res';
2
- import { KameleoonError } from '../kameleoonError/kameleoonError';
3
- import { CustomData, KameleoonDataType } from '../kameleoonData';
4
- import { SegmentType, TargetingDataType, TargetingTree } from '../targeting';
5
- import { CampaignConfigurationParametersType, ConfigurationType, ExperimentItemType, FeatureFlagType, UnsentTargetingDataType } from './types';
6
- interface ICampaignConfiguration {
7
- initialize: (useCache?: boolean) => Promise<Result<void, KameleoonError>>;
8
- addTargetingData: (visitorCode: string, ...data: KameleoonDataType[]) => Result<void, KameleoonError>;
9
- getUnsentData: (visitorCode: string) => UnsentTargetingDataType[string] | undefined;
10
- clearUnsentData: (visitorCode: string) => void;
11
- isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;
12
- onConfigurationUpdate: (callback: () => void) => void;
13
- readonly experiments: ExperimentItemType[];
14
- readonly storedTargetingData: TargetingDataType;
15
- readonly featureFlags: FeatureFlagType[];
16
- readonly configuration: ConfigurationType;
17
- readonly unsentDataVisitors: string[];
18
- }
19
- export declare class CampaignConfiguration implements ICampaignConfiguration {
20
- private configurationUpdateCallback?;
21
- private updateConfigurationIntervalId;
22
- private updateType;
23
- private targetingDataIntervalId;
24
- private unsentTargetingData;
25
- private targetingData;
26
- private targetingTrees;
27
- private configurationData;
28
- private settings;
29
- private lastUpdate;
30
- private storage;
31
- private offlineTrackingStorage;
32
- private requester;
33
- private eventSource?;
34
- private externalEventSource;
35
- private externalClientConfiguration?;
36
- private targetingDataLifetime;
37
- private localCustomDataIndexes;
38
- private persistentCustomDataIndexes;
39
- constructor({ settings, storage, requester, externalClientConfiguration, targetingCleanupInterval, offlineTrackingStorage, externalEventSource, }: CampaignConfigurationParametersType);
40
- initialize(useCache?: boolean): Promise<Result<void, KameleoonError>>;
41
- private cleanupHandlers;
42
- private handleExternalUpdates;
43
- private handleRealTimeUpdates;
44
- private handlePollingUpdates;
45
- addTargetingData(visitorCode: string, ...data: KameleoonDataType[]): Result<void, KameleoonError>;
46
- getUnsentData(visitorCode: string): UnsentTargetingDataType[string] | undefined;
47
- clearUnsentData(visitorCode: string): void;
48
- getTargetingTree(segment: SegmentType): TargetingTree;
49
- onConfigurationUpdate(callback: () => void): void;
50
- isPersistentCustomData(dataItem: KameleoonDataType): dataItem is CustomData;
51
- get unsentDataVisitors(): string[];
52
- get storedTargetingData(): TargetingDataType;
53
- get experiments(): ExperimentItemType[];
54
- get featureFlags(): FeatureFlagType[];
55
- get configuration(): ConfigurationType;
56
- private checkShouldUpdate;
57
- private cleanupOutdatedTargetingData;
58
- private readStorageData;
59
- private clearTargetingTrees;
60
- /**
61
- * Updates client configuration
62
- *
63
- * @param useCache - if true, will not update configuration if it is already present (for _offline_ mode)
64
- * @param timeStamp - timestamp for real-time configuration update
65
- *
66
- * @returns `true` if current update type should be toggled (SSE/Polling)
67
- */
68
- private updateClientConfiguration;
69
- private updateStorageData;
70
- }
71
- export {};
@@ -1,24 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CampaignConfiguration=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../kameleoonData"),_targeting=require("../targeting"),_eventSource=require("../eventSource"),_types=require("../types"),_constants=require("./constants"),_types2=require("./types"),_utilities=require("../utilities"),_excluded=["customData"];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 _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{if(f=(c=c.call(a)).next,0===b){if(Object(c)!==c)return;i=!1}else for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _regeneratorRuntime(){"use strict";/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */function a(a,b,c){return Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}),a[b]}function b(a,b,c,e){var f=b&&b.prototype instanceof d?b:d,g=Object.create(f.prototype),h=new m(e||[]);return s(g,"_invoke",{value:i(a,c,h)}),g}function c(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function d(){}function e(){}function f(){}function g(b){["next","throw","return"].forEach(function(c){a(b,c,function(a){return this._invoke(c,a)})})}function h(a,b){function d(e,f,g,h){var i=c(a[e],a,f);if("throw"!==i.type){var j=i.arg,k=j.value;return k&&"object"==_typeof(k)&&r.call(k,"__await")?b.resolve(k.__await).then(function(a){d("next",a,g,h)},function(a){d("throw",a,g,h)}):b.resolve(k).then(function(a){j.value=a,g(j)},function(a){return d("throw",a,g,h)})}h(i.arg)}var e;s(this,"_invoke",{value:function value(a,c){function f(){return new b(function(b,e){d(a,c,b,e)})}return e=e?e.then(f,f):f()}})}function i(a,b,d){var e="suspendedStart";return function(f,g){if("executing"==e)throw new Error("Generator is already running");if("completed"==e){if("throw"===f)throw g;return o()}for(d.method=f,d.arg=g;;){var h=d.delegate;if(h){var i=j(h,d);if(i){if(i===x)continue;return i}}if("next"===d.method)d.sent=d._sent=d.arg;else if("throw"===d.method){if("suspendedStart"==e)throw e="completed",d.arg;d.dispatchException(d.arg)}else"return"===d.method&&d.abrupt("return",d.arg);e="executing";var k=c(a,b,d);if("normal"===k.type){if(e=d.done?"completed":"suspendedYield",k.arg===x)continue;return{value:k.arg,done:d.done}}"throw"===k.type&&(e="completed",d.method="throw",d.arg=k.arg)}}}function j(a,b){var d=b.method,e=a.iterator[d];if(void 0===e)return b.delegate=null,"throw"===d&&a.iterator.return&&(b.method="return",b.arg=void 0,j(a,b),"throw"===b.method)||"return"!==d&&(b.method="throw",b.arg=new TypeError("The iterator does not provide a '"+d+"' method")),x;var f=c(e,a.iterator,b.arg);if("throw"===f.type)return b.method="throw",b.arg=f.arg,b.delegate=null,x;var g=f.arg;return g?g.done?(b[a.resultName]=g.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=void 0),b.delegate=null,x):g:(b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,x)}function k(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function l(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function m(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(k,this),this.reset(!0)}function n(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(r.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=void 0,b.done=!0,b};return d.next=d}}return{next:o}}function o(){return{value:void 0,done:!0}}_regeneratorRuntime=function(){return p};var p={},q=Object.prototype,r=q.hasOwnProperty,s=Object.defineProperty||function(a,b,c){a[b]=c.value},t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag";try{a({},"")}catch(b){a=function(a,b,c){return a[b]=c}}p.wrap=b;var x={},y={};a(y,u,function(){return this});var z=Object.getPrototypeOf,A=z&&z(z(n([])));A&&A!==q&&r.call(A,u)&&(y=A);var B=f.prototype=d.prototype=Object.create(y);return e.prototype=f,s(B,"constructor",{value:f,configurable:!0}),s(f,"constructor",{value:e,configurable:!0}),e.displayName=a(f,w,"GeneratorFunction"),p.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===e||"GeneratorFunction"===(b.displayName||b.name))},p.mark=function(b){return Object.setPrototypeOf?Object.setPrototypeOf(b,f):(b.__proto__=f,a(b,w,"GeneratorFunction")),b.prototype=Object.create(B),b},p.awrap=function(a){return{__await:a}},g(h.prototype),a(h.prototype,v,function(){return this}),p.AsyncIterator=h,p.async=function(a,c,d,e,f){void 0===f&&(f=Promise);var g=new h(b(a,c,d,e),f);return p.isGeneratorFunction(c)?g:g.next().then(function(a){return a.done?a.value:g.next()})},g(B),a(B,w,"Generator"),a(B,u,function(){return this}),a(B,"toString",function(){return"[object Generator]"}),p.keys=function(a){var b=Object(a),c=[];for(var d in b)c.push(d);return c.reverse(),function a(){for(;c.length;){var d=c.pop();if(d in b)return a.value=d,a.done=!1,a}return a.done=!0,a}},p.values=n,m.prototype={constructor:m,reset:function reset(a){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(l),!a)for(var b in this)"t"===b.charAt(0)&&r.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=void 0)},stop:function stop(){this.done=!0;var a=this.tryEntries[0].completion;if("throw"===a.type)throw a.arg;return this.rval},dispatchException:function dispatchException(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=void 0),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=r.call(e,"catchLoc"),h=r.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(!g){if(!h)throw new Error("try statement without catch or finally");if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(this.prev<e.catchLoc)return b(e.catchLoc,!0)}}},abrupt:function abrupt(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&r.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,x):this.complete(f)},complete:function complete(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),x},finish:function finish(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),l(b),x},catch:function _catch(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;l(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function delegateYield(a,b,c){return this.delegate={iterator:n(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=void 0),x}},p}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}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 CampaignConfiguration=/*#__PURE__*/function(){function a(b){var c=b.settings,d=b.storage,e=b.requester,f=b.externalClientConfiguration,g=b.targetingCleanupInterval,h=b.offlineTrackingStorage,i=b.externalEventSource;if(_classCallCheck(this,a),_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types2.UpdateType.Idle),_defineProperty(this,"targetingDataIntervalId",null),_defineProperty(this,"unsentTargetingData",{}),_defineProperty(this,"targetingData",{}),_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalEventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"targetingDataLifetime",_constants.CLEANUP_TARGETING_DATA_INTERVAL*_types.Milliseconds.Minute),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),this.requester=e,this.settings=c,this.lastUpdate=new Date,this.storage=d,this.readStorageData(),this.externalClientConfiguration=f,this.offlineTrackingStorage=h,this.externalEventSource=i,g){this.targetingDataLifetime=g*_types.Milliseconds.Minute;var j=0>g?1:g;// --- Note ---
2
- // We can not make delayed code execution recoverable, as it might lead
3
- // to targeting data storage size overflow
4
- try{this.targetingDataIntervalId=setInterval(this.cleanupOutdatedTargetingData.bind(this),j*_types.Milliseconds.Minute)}catch(a){throw this.targetingDataIntervalId&&clearInterval(this.targetingDataIntervalId),a}}}return _createClass(a,[{key:"initialize",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f;return _regeneratorRuntime().wrap(function g(b){for(;1;)switch(b.prev=b.next){case 0:if(c=!!this.externalClientConfiguration,d=this.checkShouldUpdate(c),!d){b.next=11;break}return b.next=5,this.updateClientConfiguration({useCache:a});case 5:if(e=b.sent,e.ok){b.next=8;break}return b.abrupt("return",e);case 8:if(f=e.data,!f){b.next=11;break}return b.abrupt("return",(0,_tsRes.Ok)());case 11:if(!c){b.next=14;break}return this.handleExternalUpdates(),b.abrupt("return",(0,_tsRes.Ok)());case 14:if(this.updateType!==_types2.UpdateType.RealTime||this.eventSource){b.next=18;break}return this.updateType=_types2.UpdateType.Idle,this.handleRealTimeUpdates(a),b.abrupt("return",(0,_tsRes.Ok)());case 18:return this.updateType===_types2.UpdateType.Polling&&this.handlePollingUpdates(a),b.abrupt("return",(0,_tsRes.Ok)());case 20:case"end":return b.stop();}},b,this)}));return a}()},{key:"cleanupHandlers",value:function cleanupHandlers(){this.eventSource&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}},{key:"handleExternalUpdates",value:function handleExternalUpdates(){this.cleanupHandlers();var a=this.externalClientConfiguration,b=a.configuration,c=a.customData,d=a.experiments,e=a.featureFlagConfigurations;this.configurationData={customData:c,configuration:b,experiments:d,featureFlags:e}}},{key:"handleRealTimeUpdates",value:function handleRealTimeUpdates(a){var b=this;this.cleanupHandlers(),this.eventSource=new _eventSource.ExternalEventSource(this.settings.siteCode,this.externalEventSource);var c=function updateEventCallback(c){b.updateClientConfiguration({useCache:a,timeStamp:c}),b.configurationUpdateCallback&&b.configurationUpdateCallback()};this.eventSource.open(c)}},{key:"handlePollingUpdates",value:function handlePollingUpdates(a){var b=this;this.cleanupHandlers();// --- Note ---
5
- // Same as targeting data interval we don't want to make failed configuration
6
- // retrieval recoverable
7
- try{this.updateConfigurationIntervalId=setInterval(function(){return b.updateClientConfiguration.bind(b)({useCache:a})},this.settings.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}},{key:"addTargetingData",value:function addTargetingData(a){var b=this;a in this.targetingData||(this.targetingData[a]={});for(var c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];d.forEach(function(c){// --- Custom data case ---
8
- if(_utilities.Utilities.isCustomData(c)){var d=_objectSpread(_objectSpread({},c.data),{},{lastActivityTime:Date.now()}),e=(_kameleoonData.KameleoonData.CustomData in b.targetingData[a]);e?b.targetingData[a][d.type][d.index]=d:b.targetingData[a]=_objectSpread(_objectSpread({},b.targetingData[a]),{},_defineProperty({},d.type,_objectSpread(_objectSpread({},b.targetingData[a][d.type]),{},_defineProperty({},d.index,d))))}else{var f=_objectSpread(_objectSpread({},c.data),{},{lastActivityTime:Date.now()}),g=(c.data.type in b.targetingData[a]);g?b.targetingData[a][c.data.type]=f:b.targetingData[a]=_objectSpread(_objectSpread({},b.targetingData[a]),{},_defineProperty({},c.data.type,f))}});// --- Note ---
9
- // `targetingData` should not refresh `lastUpdate` time
10
- var f=this.updateStorageData(this.lastUpdate);return f.ok&&d.forEach(function(c){b.unsentTargetingData[a]||(b.unsentTargetingData[a]=new Map);var d;if(_utilities.Utilities.isCustomData(c)){if(b.localCustomDataIndexes.has(c.data.index))return;d=c.data.index}else d=c.data.type;b.unsentTargetingData[a].set(d,c)}),f}},{key:"getUnsentData",value:function getUnsentData(a){return this.unsentTargetingData[a]}},{key:"clearUnsentData",value:function clearUnsentData(a){var b,c=null===(b=this.unsentTargetingData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){var d,e=new Map,f=_createForOfIteratorHelper(c);try{for(f.s();!(d=f.n()).done;){var g=d.value;this.isPersistentCustomData(g)&&e.set(g.data.index,g)}}catch(a){f.e(a)}finally{f.f()}if(e.size)return void(this.unsentTargetingData[a]=e)}delete this.unsentTargetingData[a]}},{key:"getTargetingTree",value:function getTargetingTree(a){if(!this.targetingTrees.has(a.id)){var b=new _targeting.TargetingTree(a);return this.targetingTrees.set(a.id,new _targeting.TargetingTree(a)),b}return this.targetingTrees.get(a.id)}},{key:"onConfigurationUpdate",value:function onConfigurationUpdate(a){this.configurationUpdateCallback=a}},{key:"isPersistentCustomData",value:function isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}},{key:"unsentDataVisitors",get:function get(){return Object.keys(this.unsentTargetingData)}},{key:"storedTargetingData",get:function get(){return this.targetingData}},{key:"experiments",get:function get(){return this.configurationData.experiments}},{key:"featureFlags",get:function get(){return this.configurationData.featureFlags}},{key:"configuration",get:function get(){return this.configurationData.configuration}},{key:"checkShouldUpdate",value:function checkShouldUpdate(){var a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0],b=this.configurationData,c=b.featureFlags,d=b.experiments,e=b.configuration,f=this.settings.updateInterval;// --- Note ---
11
- // Following `updateType` logic is done for client side
12
- // edge cases where we have previous campaigns on storage already, but we still want
13
- // to initialize SSE/Polling after page reload
14
- if(a)return this.updateType=_types2.UpdateType.Idle,!1;if(this.updateType=e.realTimeUpdate?_types2.UpdateType.RealTime:_types2.UpdateType.Polling,!c.length&&!d.length)return!0;var g=this.lastUpdate.getTime(),h=Date.now()-f;return g<h}},{key:"cleanupOutdatedTargetingData",value:function cleanupOutdatedTargetingData(){for(var a=Date.now(),b=0,c=Object.entries(this.targetingData);b<c.length;b++){var d=_slicedToArray(c[b],2),e=d[0],f=d[1],g=f.customData,h=_objectWithoutProperties(f,_excluded);if(g)for(var i=0,j=Object.entries(g);i<j.length;i++){var k=_slicedToArray(j[i],2),l=k[0],m=k[1];if(m){var n=m.lastActivityTime+this.targetingDataLifetime<a,o=f[_kameleoonData.KameleoonData.CustomData];n&&o&&delete o[+l],o&&!Object.keys(o).length&&delete f[_kameleoonData.KameleoonData.CustomData]}}for(var p=0,q=Object.entries(h);p<q.length;p++){var r=_slicedToArray(q[p],2),s=r[0],t=r[1],u=t.lastActivityTime+this.targetingDataLifetime<a;u&&delete f[s]}Object.keys(this.targetingData[e]).length||delete this.targetingData[e]}// --- Note ---
15
- // `targetingData` should not refresh `lastUpdate` time
16
- this.updateStorageData(this.lastUpdate).throw()}},{key:"readStorageData",value:function readStorageData(){var a=this.storage.read();if(a.ok){var b=a.data,c=b.kameleoonTargetingData,d=b.kameleoonConfiguration,e=b.lastUpdate;this.configurationData=d,this.targetingData=c,this.lastUpdate=new Date(Date.parse(e))}}},{key:"clearTargetingTrees",value:function clearTargetingTrees(){this.targetingTrees.clear()}/**
17
- * Updates client configuration
18
- *
19
- * @param useCache - if true, will not update configuration if it is already present (for _offline_ mode)
20
- * @param timeStamp - timestamp for real-time configuration update
21
- *
22
- * @returns `true` if current update type should be toggled (SSE/Polling)
23
- */},{key:"updateClientConfiguration",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function a(){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t=arguments;return _regeneratorRuntime().wrap(function u(a){for(;1;)switch(a.prev=a.next){case 0:return b=0<t.length&&void 0!==t[0]?t[0]:{},c=b.useCache,d=void 0!==c&&c,e=b.timeStamp,a.next=3,this.requester.getClientConfiguration(e);case 3:if(f=a.sent,f.ok){a.next=9;break}if(g=this.configurationData,h=g.featureFlags,i=g.experiments,!(d&&h.length&&i.length)){a.next=8;break}return a.abrupt("return",(0,_tsRes.Ok)(!0));case 8:return a.abrupt("return",f);case 9:if(_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester}),j=f.data,k=j.configuration,l=j.experiments,m=j.featureFlagConfigurations,n=j.customData,this.configurationData={configuration:k,experiments:l,featureFlags:m,customData:n},null!==n&&void 0!==n&&n.length&&(o=[],p=[],n.forEach(function(a){a.localOnly&&o.push(a.index),a.scope===_types2.CustomDataScope.Visitor&&p.push(a.index)}),o.length&&(this.localCustomDataIndexes=new Set(o)),p.length&&(this.persistentCustomDataIndexes=new Set(p))),this.clearTargetingTrees(),q=this.updateStorageData(new Date),q.ok){a.next=17;break}return a.abrupt("return",q);case 17:if(r=k.realTimeUpdate?_types2.UpdateType.RealTime:_types2.UpdateType.Polling,s=r!==this.updateType,!s){a.next=23;break}return this.updateType=r,a.next=23,this.initialize(d);case 23:return a.abrupt("return",(0,_tsRes.Ok)(s));case 24:case"end":return a.stop();}},a,this)}));return a}()},{key:"updateStorageData",value:function updateStorageData(a){this.lastUpdate=a;var b={kameleoonTargetingData:this.targetingData,kameleoonConfiguration:this.configurationData,lastUpdate:a.toString()};return this.storage.write(b)}}]),a}();exports.CampaignConfiguration=CampaignConfiguration;
24
- //# sourceMappingURL=campaignConfiguration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"campaignConfiguration.js","names":["a","b","c","Object","defineProperty","value","enumerable","configurable","writable","e","f","prototype","d","g","create","h","m","s","i","type","arg","call","forEach","_invoke","j","k","_typeof","r","resolve","__await","then","Error","o","method","delegate","x","sent","_sent","dispatchException","abrupt","done","iterator","return","TypeError","resultName","next","nextLoc","tryLoc","catchLoc","finallyLoc","afterLoc","tryEntries","push","l","completion","reset","n","u","isNaN","length","_regeneratorRuntime","p","q","hasOwnProperty","t","Symbol","v","asyncIterator","w","toStringTag","wrap","y","z","getPrototypeOf","A","B","displayName","isGeneratorFunction","constructor","name","mark","setPrototypeOf","__proto__","awrap","AsyncIterator","async","Promise","keys","reverse","pop","values","prev","charAt","slice","stop","rval","complete","finish","catch","_catch","delegateYield","asyncGeneratorStep","_asyncToGenerator","arguments","apply","_classCallCheck","_defineProperties","_toPropertyKey","key","_createClass","_defineProperty","_toPrimitive","toPrimitive","String","Number","CampaignConfiguration","settings","storage","requester","externalClientConfiguration","targetingCleanupInterval","offlineTrackingStorage","externalEventSource","UpdateType","Idle","Map","DEFAULT_CONFIGURATION_DATA","CLEANUP_TARGETING_DATA_INTERVAL","Milliseconds","Minute","Set","lastUpdate","Date","readStorageData","targetingDataLifetime","cleanupIntervalMinutes","targetingDataIntervalId","setInterval","cleanupOutdatedTargetingData","bind","err","clearInterval","useCache","isExternalConfiguration","shouldUpdate","checkShouldUpdate","updateClientConfiguration","updateResult","ok","isUpdateTypeToggled","data","Ok","handleExternalUpdates","updateType","RealTime","eventSource","handleRealTimeUpdates","Polling","handlePollingUpdates","cleanupHandlers","close","updateConfigurationIntervalId","configuration","customData","experiments","featureFlagConfigurations","configurationData","featureFlags","ExternalEventSource","siteCode","updateEventCallback","timeStamp","configurationUpdateCallback","open","updateInterval","addTargetingData","visitorCode","targetingData","Array","dataItem","Utilities","isCustomData","_objectSpread","lastActivityTime","now","hasCustomDataKey","KameleoonData","CustomData","index","hasDataKey","result","updateStorageData","unsentTargetingData","localCustomDataIndexes","has","set","getUnsentData","clearUnsentData","dataItems","persistentCustomDataIndexes","size","persistentCustomData","_createForOfIteratorHelper","isPersistentCustomData","getTargetingTree","segment","targetingTrees","id","targetingTree","TargetingTree","get","onConfigurationUpdate","callback","skipChecks","realTimeUpdate","lastUpdateTime","getTime","updateWindowEdge","currentTime","entries","_slicedToArray","kameleoonVisitorData","rest","_objectWithoutProperties","_excluded","isDataExpired","existingData","throw","read","kameleoonTargetingData","kameleoonConfiguration","parse","clearTargetingTrees","clear","getClientConfiguration","clientConfigurationResult","sendOfflineTracking","customDataLocalOnlyIndexes","localOnly","scope","CustomDataScope","Visitor","toggleUpdateType","initialize","toString","write","exports"],"sources":["../../src/campaignConfiguration/campaignConfiguration.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError/kameleoonError';\nimport { ClientSettingsType } from 'src/clientSettings/types';\nimport {\n CustomData,\n KameleoonData,\n KameleoonDataType,\n} from 'src/kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from 'src/requester';\nimport { SegmentType, TargetingDataType, TargetingTree } from 'src/targeting';\nimport { ClientDataType } from 'src/storage';\nimport {\n ExternalEventSource,\n IEventSource,\n IExternalEventSourceConstructor,\n} from 'src/eventSource';\nimport { Milliseconds } from 'src/types';\nimport {\n CLEANUP_TARGETING_DATA_INTERVAL,\n DEFAULT_CONFIGURATION_DATA,\n} from './constants';\nimport {\n CampaignConfigurationParametersType,\n ConfigurationDataType,\n ConfigurationType,\n CustomDataScope,\n ExperimentItemType,\n FeatureFlagType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n UpdateClientConfigurationParameters,\n UpdateType,\n} from './types';\nimport { Utilities } from 'src/utilities';\nimport {\n ExistingCustomDataType,\n ExistingDataType,\n} from 'src/kameleoonData/types';\nimport { IExternalStorage, OfflineTracking } from 'src/storage/types';\n\ninterface ICampaignConfiguration {\n initialize: (useCache?: boolean) => Promise<Result<void, KameleoonError>>;\n addTargetingData: (\n visitorCode: string,\n ...data: KameleoonDataType[]\n ) => Result<void, KameleoonError>;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n onConfigurationUpdate: (callback: () => void) => void;\n readonly experiments: ExperimentItemType[];\n readonly storedTargetingData: TargetingDataType;\n readonly featureFlags: FeatureFlagType[];\n readonly configuration: ConfigurationType;\n readonly unsentDataVisitors: string[];\n}\n\nexport class CampaignConfiguration implements ICampaignConfiguration {\n private configurationUpdateCallback?: () => void;\n private updateConfigurationIntervalId: NodeJS.Timer | null = null;\n private updateType: UpdateType = UpdateType.Idle;\n private targetingDataIntervalId: NodeJS.Timer | null = null;\n private unsentTargetingData: UnsentTargetingDataType = {};\n private targetingData: TargetingDataType = {};\n private targetingTrees: Map<string, TargetingTree> = new Map();\n private configurationData: ConfigurationDataType = DEFAULT_CONFIGURATION_DATA;\n private settings: ClientSettingsType;\n private lastUpdate: Date;\n private storage: IExternalStorage<ClientDataType>;\n private offlineTrackingStorage: IExternalStorage<OfflineTracking>;\n private requester: Requester;\n private eventSource?: IEventSource;\n private externalEventSource: IExternalEventSourceConstructor;\n private externalClientConfiguration?: GetClientConfigurationResultType;\n private targetingDataLifetime: number =\n CLEANUP_TARGETING_DATA_INTERVAL * Milliseconds.Minute;\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n\n constructor({\n settings,\n storage,\n requester,\n externalClientConfiguration,\n targetingCleanupInterval,\n offlineTrackingStorage,\n externalEventSource,\n }: CampaignConfigurationParametersType) {\n this.requester = requester;\n this.settings = settings;\n this.lastUpdate = new Date();\n this.storage = storage;\n this.readStorageData();\n this.externalClientConfiguration = externalClientConfiguration;\n this.offlineTrackingStorage = offlineTrackingStorage;\n this.externalEventSource = externalEventSource;\n\n if (targetingCleanupInterval) {\n this.targetingDataLifetime =\n targetingCleanupInterval * Milliseconds.Minute;\n\n const cleanupIntervalMinutes =\n targetingCleanupInterval < 0 ? 1 : targetingCleanupInterval;\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.targetingDataIntervalId = setInterval(\n this.cleanupOutdatedTargetingData.bind(this),\n cleanupIntervalMinutes * Milliseconds.Minute,\n );\n } catch (err) {\n if (this.targetingDataIntervalId) {\n clearInterval(this.targetingDataIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public async initialize(\n useCache?: boolean,\n ): Promise<Result<void, KameleoonError>> {\n const isExternalConfiguration = Boolean(this.externalClientConfiguration);\n const shouldUpdate = this.checkShouldUpdate(isExternalConfiguration);\n\n if (shouldUpdate) {\n const updateResult = await this.updateClientConfiguration({ useCache });\n\n if (!updateResult.ok) {\n return updateResult;\n }\n\n // --- Note ---\n // If update type is being toggled `initialize` will be called again\n // so we don't need to continue execution here\n const isUpdateTypeToggled = updateResult.data;\n\n if (isUpdateTypeToggled) {\n return Ok();\n }\n }\n\n if (isExternalConfiguration) {\n this.handleExternalUpdates();\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.RealTime && !this.eventSource) {\n this.updateType = UpdateType.Idle;\n this.handleRealTimeUpdates(useCache);\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.Polling) {\n this.handlePollingUpdates(useCache);\n }\n\n return Ok();\n }\n\n private cleanupHandlers(): void {\n if (this.eventSource) {\n this.eventSource.close();\n }\n\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n }\n\n private handleExternalUpdates(): void {\n this.cleanupHandlers();\n\n const {\n configuration,\n customData,\n experiments,\n featureFlagConfigurations,\n } = this.externalClientConfiguration!;\n\n this.configurationData = {\n customData,\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n };\n }\n\n private handleRealTimeUpdates(useCache?: boolean): void {\n this.cleanupHandlers();\n\n this.eventSource = new ExternalEventSource(\n this.settings.siteCode,\n this.externalEventSource,\n );\n\n const updateEventCallback = (timeStamp: number) => {\n this.updateClientConfiguration({ useCache, timeStamp });\n\n if (this.configurationUpdateCallback) {\n this.configurationUpdateCallback();\n }\n };\n\n this.eventSource.open(updateEventCallback);\n }\n\n private handlePollingUpdates(useCache?: boolean): void {\n // --- Note ---\n // If `initialize` is called again the interval will be cleared\n // so theoretically we will constantly defer config update\n // but `this.lastUpdate` with `checkShouldUpdate` will prevent that\n this.cleanupHandlers();\n\n // --- Note ---\n // Same as targeting data interval we don't want to make failed configuration\n // retrieval recoverable\n try {\n this.updateConfigurationIntervalId = setInterval(\n () => this.updateClientConfiguration.bind(this)({ useCache }),\n this.settings.updateInterval,\n );\n } catch (err) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n throw err;\n }\n }\n\n public addTargetingData(\n visitorCode: string,\n ...data: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n if (!(visitorCode in this.targetingData)) {\n this.targetingData[visitorCode] = {};\n }\n\n // --- Note ---\n // Following code is optimized for performance:\n // - We don't want to copy the whole object every time we add new data\n // - So we are manually checking the keys existence and mutating targeting data directly\n // - Numerous type casts are required because we can't narrow down nested `this.targetingData` types by using assertion functions\n data.forEach((dataItem) => {\n // --- Custom data case ---\n if (Utilities.isCustomData(dataItem)) {\n const customData = {\n ...dataItem.data,\n lastActivityTime: Date.now(),\n };\n const hasCustomDataKey =\n KameleoonData.CustomData in this.targetingData[visitorCode];\n\n // -- Change directly if `[key]` exists\n if (hasCustomDataKey) {\n (\n this.targetingData[visitorCode][\n customData.type\n ] as ExistingCustomDataType\n )[customData.index] = customData;\n } else {\n // -- Change data by creating new `[key]` and `[index]`\n this.targetingData[visitorCode] = {\n ...this.targetingData[visitorCode],\n [customData.type]: {\n ...this.targetingData[visitorCode][customData.type],\n [customData.index]: customData,\n },\n };\n }\n // --- Other data types case ---\n } else {\n const data = { ...dataItem.data, lastActivityTime: Date.now() };\n const hasDataKey =\n dataItem.data.type in this.targetingData[visitorCode];\n\n // -- Changing data by `[key]` if it exists\n if (hasDataKey) {\n (this.targetingData[visitorCode][\n dataItem.data.type\n ] as ExistingDataType<typeof dataItem.data.type>) = data;\n } else {\n // -- Change data by creating new `[key]`\n this.targetingData[visitorCode] = {\n ...this.targetingData[visitorCode],\n [dataItem.data.type]: data,\n };\n }\n }\n });\n\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n const result = this.updateStorageData(this.lastUpdate);\n\n if (result.ok) {\n data.forEach((dataItem) => {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always defined further in the code\n if (!this.unsentTargetingData[visitorCode]) {\n this.unsentTargetingData[visitorCode] = new Map();\n }\n\n let key: KameleoonData | number;\n\n if (Utilities.isCustomData(dataItem)) {\n if (this.localCustomDataIndexes.has(dataItem.data.index)) {\n return;\n }\n\n key = dataItem.data.index;\n } else {\n key = dataItem.data.type;\n }\n\n this.unsentTargetingData[visitorCode]!.set(key, dataItem);\n });\n }\n\n return result;\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentTargetingData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentTargetingData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentTargetingData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentTargetingData[visitorCode];\n }\n\n public getTargetingTree(segment: SegmentType): TargetingTree {\n if (!this.targetingTrees.has(segment.id)) {\n const targetingTree = new TargetingTree(segment);\n\n this.targetingTrees.set(segment.id, new TargetingTree(segment));\n\n return targetingTree;\n }\n\n return this.targetingTrees.get(segment.id) as TargetingTree;\n }\n\n public onConfigurationUpdate(callback: () => void): void {\n this.configurationUpdateCallback = callback;\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentTargetingData);\n }\n\n get storedTargetingData(): TargetingDataType {\n return this.targetingData;\n }\n\n get experiments(): ExperimentItemType[] {\n return this.configurationData.experiments;\n }\n\n get featureFlags(): FeatureFlagType[] {\n return this.configurationData.featureFlags;\n }\n\n get configuration(): ConfigurationType {\n return this.configurationData.configuration;\n }\n\n private checkShouldUpdate(skipChecks = false): boolean {\n const { featureFlags, experiments, configuration } = this.configurationData;\n const { updateInterval } = this.settings;\n\n // --- Note ---\n // Following `updateType` logic is done for client side\n // edge cases where we have previous campaigns on storage already, but we still want\n // to initialize SSE/Polling after page reload\n if (skipChecks) {\n this.updateType = UpdateType.Idle;\n\n return false;\n }\n\n this.updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n if (!featureFlags.length && !experiments.length) {\n return true;\n }\n\n const lastUpdateTime = this.lastUpdate.getTime();\n const updateWindowEdge = Date.now() - updateInterval;\n\n return lastUpdateTime < updateWindowEdge;\n }\n\n private cleanupOutdatedTargetingData(): void {\n const currentTime = Date.now();\n\n for (const [visitorCode, kameleoonVisitorData] of Object.entries(\n this.targetingData,\n )) {\n const { customData, ...rest } = kameleoonVisitorData;\n\n if (customData) {\n for (const [index, dataItem] of Object.entries(customData)) {\n if (dataItem) {\n const isDataExpired =\n dataItem.lastActivityTime + this.targetingDataLifetime <\n currentTime;\n const existingData = kameleoonVisitorData[KameleoonData.CustomData];\n\n if (isDataExpired && existingData) {\n delete existingData[Number(index)];\n }\n\n if (existingData && !Object.keys(existingData).length) {\n delete kameleoonVisitorData[KameleoonData.CustomData];\n }\n }\n }\n }\n\n for (const [key, dataItem] of Object.entries(rest)) {\n const isDataExpired =\n dataItem.lastActivityTime + this.targetingDataLifetime < currentTime;\n\n if (isDataExpired) {\n delete kameleoonVisitorData[key as KameleoonData];\n }\n }\n\n if (!Object.keys(this.targetingData[visitorCode]).length) {\n delete this.targetingData[visitorCode];\n }\n }\n\n // --- Note ---\n // `targetingData` should not refresh `lastUpdate` time\n this.updateStorageData(this.lastUpdate).throw();\n }\n\n private readStorageData(): void {\n const result = this.storage.read();\n\n if (result.ok) {\n const { kameleoonTargetingData, kameleoonConfiguration, lastUpdate } =\n result.data;\n\n this.configurationData = kameleoonConfiguration;\n this.targetingData = kameleoonTargetingData;\n this.lastUpdate = new Date(Date.parse(lastUpdate));\n }\n }\n\n private clearTargetingTrees(): void {\n this.targetingTrees.clear();\n }\n\n /**\n * Updates client configuration\n *\n * @param useCache - if true, will not update configuration if it is already present (for _offline_ mode)\n * @param timeStamp - timestamp for real-time configuration update\n *\n * @returns `true` if current update type should be toggled (SSE/Polling)\n */\n private async updateClientConfiguration({\n useCache = false,\n timeStamp,\n }: UpdateClientConfigurationParameters = {}): Promise<\n Result<boolean, KameleoonError>\n > {\n const clientConfigurationResult =\n await this.requester.getClientConfiguration(timeStamp);\n\n if (!clientConfigurationResult.ok) {\n const { featureFlags, experiments } = this.configurationData;\n\n if (useCache && featureFlags.length && experiments.length) {\n return Ok(true);\n }\n\n return clientConfigurationResult;\n }\n\n Utilities.sendOfflineTracking({\n storage: this.offlineTrackingStorage,\n requester: this.requester,\n });\n\n // --- Note ---\n // `featureFlags` field is omitted (v1)\n // instead `featureFlagConfigurations` is used (v2)\n const {\n configuration,\n experiments,\n featureFlagConfigurations,\n customData,\n } = clientConfigurationResult.data;\n\n this.configurationData = {\n configuration,\n experiments,\n featureFlags: featureFlagConfigurations,\n customData,\n };\n\n if (customData?.length) {\n const customDataLocalOnlyIndexes: number[] = [];\n const persistentCustomDataIndexes: number[] = [];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n\n this.clearTargetingTrees();\n\n const result = this.updateStorageData(new Date());\n\n if (!result.ok) {\n return result;\n }\n\n const updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n const toggleUpdateType = updateType !== this.updateType;\n\n if (toggleUpdateType) {\n this.updateType = updateType;\n await this.initialize(useCache);\n }\n\n return Ok(toggleUpdateType);\n }\n\n private updateStorageData(lastUpdate: Date): Result<void, KameleoonError> {\n this.lastUpdate = lastUpdate;\n\n const data: ClientDataType = {\n kameleoonTargetingData: this.targetingData,\n kameleoonConfiguration: this.configurationData,\n lastUpdate: lastUpdate.toString(),\n };\n\n return this.storage.write(data);\n }\n}\n"],"mappings":"mqHACA,6JAAAA,GAAA,CAAAC,CAAA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AAA,CAAA,MAAA4G,GAAA,qBAAAvG,KAAA,CAED,SAAA0L,kBAA0B5D,CAAgB,CAAgC,CACxE,IAAI,CAACA,UAAU,CAAGA,CAAU,CAE5B,GAAM,CAAAmB,CAAoB,CAAG,CAC3B+E,sBAAsB,CAAE,IAAI,CAACpD,aAAa,CAC1CqD,sBAAsB,CAAE,IAAI,CAAChE,iBAAiB,CAC9CnC,UAAU,CAAEA,CAAU,CAACiH,QAAQ,EACjC,CAAC,CAED,MAAO,KAAI,CAAC/H,OAAO,CAACgI,KAAK,CAAC/F,CAAI,CAChC,CAAC,IAAAtJ,CAAA,IAAAsP,OAAA,CAAAnI,qBAAA,CAAAA,qBAAA"}
@@ -1,6 +0,0 @@
1
- import { ConfigurationDataType } from '../campaignConfiguration';
2
- /**
3
- * @constant default cleanup interval in minutes
4
- * */
5
- export declare const CLEANUP_TARGETING_DATA_INTERVAL = 30;
6
- export declare const DEFAULT_CONFIGURATION_DATA: ConfigurationDataType;
@@ -1,4 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_CONFIGURATION_DATA=exports.CLEANUP_TARGETING_DATA_INTERVAL=void 0;/**
2
- * @constant default cleanup interval in minutes
3
- * */var CLEANUP_TARGETING_DATA_INTERVAL=30;exports.CLEANUP_TARGETING_DATA_INTERVAL=30;var DEFAULT_CONFIGURATION_DATA={experiments:[],featureFlags:[],customData:[],configuration:{realTimeUpdate:!1}};exports.DEFAULT_CONFIGURATION_DATA=DEFAULT_CONFIGURATION_DATA;
4
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","names":["CLEANUP_TARGETING_DATA_INTERVAL","exports","DEFAULT_CONFIGURATION_DATA","experiments","featureFlags","customData","configuration","realTimeUpdate"],"sources":["../../src/campaignConfiguration/constants.ts"],"sourcesContent":["import { ConfigurationDataType } from 'src/campaignConfiguration';\n\n/**\n * @constant default cleanup interval in minutes\n * */\nexport const CLEANUP_TARGETING_DATA_INTERVAL = 30;\n\nexport const DEFAULT_CONFIGURATION_DATA: ConfigurationDataType = {\n experiments: [],\n featureFlags: [],\n customData: [],\n configuration: {\n realTimeUpdate: false,\n },\n};\n"],"mappings":"sJAEA;AACA;AACA,KACO,GAAM,CAAAA,+BAA+B,CAAG,EAAE,CAACC,OAAA,CAAAD,+BAAA,IAE3C,GAAM,CAAAE,0BAAiD,CAAG,CAC/DC,WAAW,CAAE,EAAE,CACfC,YAAY,CAAE,EAAE,CAChBC,UAAU,CAAE,EAAE,CACdC,aAAa,CAAE,CACbC,cAAc,GAChB,CACF,CAAC,CAACN,OAAA,CAAAC,0BAAA,CAAAA,0BAAA"}
@@ -1,3 +0,0 @@
1
- export { ConfigurationDataType, CampaignConfigurationType, CustomDataConfigurationType, CustomDataScope, VariationByExpositionType, FeatureVariableType, ExperimentItemType, RespoolTimeType, FeatureFlagType, RuleItemType, JSONValue, RuleType, JSONType, } from './types';
2
- export { CampaignConfiguration } from './campaignConfiguration';
3
- export { CLEANUP_TARGETING_DATA_INTERVAL } from './constants';
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"CLEANUP_TARGETING_DATA_INTERVAL",{enumerable:!0,get:function get(){return _constants.CLEANUP_TARGETING_DATA_INTERVAL}}),Object.defineProperty(exports,"CampaignConfiguration",{enumerable:!0,get:function get(){return _campaignConfiguration.CampaignConfiguration}}),Object.defineProperty(exports,"CampaignConfigurationType",{enumerable:!0,get:function get(){return _types.CampaignConfigurationType}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function get(){return _types.ConfigurationDataType}}),Object.defineProperty(exports,"CustomDataConfigurationType",{enumerable:!0,get:function get(){return _types.CustomDataConfigurationType}}),Object.defineProperty(exports,"CustomDataScope",{enumerable:!0,get:function get(){return _types.CustomDataScope}}),Object.defineProperty(exports,"ExperimentItemType",{enumerable:!0,get:function get(){return _types.ExperimentItemType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function get(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureVariableType",{enumerable:!0,get:function get(){return _types.FeatureVariableType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function get(){return _types.JSONType}}),Object.defineProperty(exports,"JSONValue",{enumerable:!0,get:function get(){return _types.JSONValue}}),Object.defineProperty(exports,"RespoolTimeType",{enumerable:!0,get:function get(){return _types.RespoolTimeType}}),Object.defineProperty(exports,"RuleItemType",{enumerable:!0,get:function get(){return _types.RuleItemType}}),Object.defineProperty(exports,"RuleType",{enumerable:!0,get:function get(){return _types.RuleType}}),Object.defineProperty(exports,"VariationByExpositionType",{enumerable:!0,get:function get(){return _types.VariationByExpositionType}});var _types=require("./types"),_campaignConfiguration=require("./campaignConfiguration"),_constants=require("./constants");
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/campaignConfiguration/index.ts"],"sourcesContent":["export {\n ConfigurationDataType,\n CampaignConfigurationType,\n CustomDataConfigurationType,\n CustomDataScope,\n VariationByExpositionType,\n FeatureVariableType,\n ExperimentItemType,\n RespoolTimeType,\n FeatureFlagType,\n RuleItemType,\n JSONValue,\n RuleType,\n JSONType,\n} from './types';\nexport { CampaignConfiguration } from './campaignConfiguration';\nexport { CLEANUP_TARGETING_DATA_INTERVAL } from './constants';\n"],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UpdateType=exports.RuleType=exports.FeatureStatus=exports.FeatureFlagSdkLanguageType=exports.ExperimentType=exports.ExperimentStatus=exports.CustomDataScope=void 0;var UpdateType=/*#__PURE__*/function(a){return a[a.Polling=0]="Polling",a[a.RealTime=1]="RealTime",a[a.Idle=2]="Idle",a}({});exports.UpdateType=UpdateType;var ExperimentType=/*#__PURE__*/function(a){return a.CLASSIC="CLASSIC",a.SERVER_SIDE="SERVER_SIDE",a.DEVELOPER="DEVELOPER",a.MVT="MVT",a.HYBRID="HYBRID",a}({});exports.ExperimentType=ExperimentType;var RuleType=/*#__PURE__*/function(a){return a.PROGRESSIVE_DELIVERY="PROGRESSIVE_DELIVERY",a.TARGETED_DELIVERY="TARGETED_DELIVERY",a.EXPERIMENTATION="EXPERIMENTATION",a}({});exports.RuleType=RuleType;var FeatureFlagSdkLanguageType=/*#__PURE__*/function(a){return a.ANDROID="ANDROID",a.SWIFT="SWIFT",a.JAVA="JAVA",a.CSHARP="CSHARP",a.NODEJS="NODEJS",a.PHP="PHP",a.RUBY="RUBY",a.GO="GO",a.FLUTTER="FLUTTER",a.REACTJS="REACTJS",a}({});exports.FeatureFlagSdkLanguageType=FeatureFlagSdkLanguageType;var FeatureStatus=/*#__PURE__*/function(a){return a.ACTIVATED="ACTIVATED",a.DEACTIVATED="DEACTIVATED",a.SCHEDULED="SCHEDULED",a}({});exports.FeatureStatus=FeatureStatus;var CustomDataScope=/*#__PURE__*/function(a){return a.Visit="VISIT",a.Visitor="VISITOR",a.Page="Page",a}({});exports.CustomDataScope=CustomDataScope;var ExperimentStatus=/*#__PURE__*/function(a){return a.DRAFT="DRAFT",a.ACTIVE="ACTIVE",a.PAUSED="PAUSED",a.SCHEDULED="SCHEDULED",a.STOPPED="STOPPED",a.USED_AS_PERSONALIZATION="USED_AS_PERSONALIZATION",a.DEVIATED="DEVIATED",a}({});exports.ExperimentStatus=ExperimentStatus;
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","names":["UpdateType","Polling","RealTime","Idle","exports","ExperimentType","CLASSIC","SERVER_SIDE","DEVELOPER","MVT","HYBRID","RuleType","PROGRESSIVE_DELIVERY","TARGETED_DELIVERY","EXPERIMENTATION","FeatureFlagSdkLanguageType","ANDROID","SWIFT","JAVA","CSHARP","NODEJS","PHP","RUBY","GO","FLUTTER","REACTJS","FeatureStatus","ACTIVATED","DEACTIVATED","SCHEDULED","CustomDataScope","Visit","Visitor","Page","ExperimentStatus","DRAFT","ACTIVE","PAUSED","STOPPED","USED_AS_PERSONALIZATION","DEVIATED"],"sources":["../../src/campaignConfiguration/types.ts"],"sourcesContent":["import { ClientSettingsType } from 'src/clientSettings';\nimport { IExternalEventSourceConstructor } from 'src/eventSource';\nimport { KameleoonData, KameleoonDataType } from 'src/kameleoonData';\nimport { Requester, GetClientConfigurationResultType } from 'src/requester';\nimport { ClientDataType } from 'src/storage';\nimport { IExternalStorage, OfflineTracking } from 'src/storage/types';\nimport { SegmentType, TargetingDataType } from 'src/targeting';\nimport { VariableType } from 'src/types';\n\nexport type UpdateClientConfigurationParameters = {\n timeStamp?: number;\n useCache?: boolean;\n};\n\nexport type ScheduleType = {\n dateStart: string;\n dateEnd: string;\n};\n\nexport enum UpdateType {\n Polling,\n RealTime,\n Idle,\n}\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | { [x: string]: JSONValue }\n | JSONValue[];\n\nexport type JSONType = Record<string | number | symbol, JSONValue> | null;\n\nexport enum ExperimentType {\n CLASSIC = 'CLASSIC',\n SERVER_SIDE = 'SERVER_SIDE',\n DEVELOPER = 'DEVELOPER',\n MVT = 'MVT',\n HYBRID = 'HYBRID',\n}\n\nexport enum RuleType {\n PROGRESSIVE_DELIVERY = 'PROGRESSIVE_DELIVERY',\n TARGETED_DELIVERY = 'TARGETED_DELIVERY',\n EXPERIMENTATION = 'EXPERIMENTATION',\n}\n\nexport enum FeatureFlagSdkLanguageType {\n ANDROID = 'ANDROID',\n SWIFT = 'SWIFT',\n JAVA = 'JAVA',\n CSHARP = 'CSHARP',\n NODEJS = 'NODEJS',\n PHP = 'PHP',\n RUBY = 'RUBY',\n GO = 'GO',\n FLUTTER = 'FLUTTER',\n REACTJS = 'REACTJS',\n}\n\nexport enum FeatureStatus {\n ACTIVATED = 'ACTIVATED',\n DEACTIVATED = 'DEACTIVATED',\n SCHEDULED = 'SCHEDULED',\n}\n\nexport enum CustomDataScope {\n Visit = 'VISIT',\n Visitor = 'VISITOR',\n Page = 'Page',\n}\n\nexport type ExperimentItemType = {\n id: string;\n name: string;\n type: ExperimentType;\n siteId: string;\n siteCode: string;\n status: ExperimentStatus;\n siteEnabled: boolean;\n variations: ExperimentVariationType[];\n deviations: DeviationType[];\n respoolTime: RespoolTimeType[];\n segment: SegmentType | null;\n};\n\nexport type ExperimentVariationType = {\n id: string;\n customJson: string;\n};\n\nexport type DeviationType = {\n variationId: string;\n value: number;\n};\n\nexport type RespoolTimeType = {\n variationId: string;\n value: number;\n};\n\nexport enum ExperimentStatus {\n DRAFT = 'DRAFT',\n ACTIVE = 'ACTIVE',\n PAUSED = 'PAUSED',\n SCHEDULED = 'SCHEDULED',\n STOPPED = 'STOPPED',\n USED_AS_PERSONALIZATION = 'USED_AS_PERSONALIZATION',\n DEVIATED = 'DEVIATED',\n}\n\nexport type FeatureFlagType = {\n id: number;\n featureKey: string;\n variations: FeatureVariationType[];\n defaultVariationKey: string;\n rules: RuleItemType[];\n};\n\nexport type FeatureVariationType = {\n key: string;\n variables: FeatureVariableType[];\n};\n\nexport type FeatureVariableType = {\n key: string;\n type: VariableType;\n value: string | number | boolean;\n};\n\nexport type RuleItemType = {\n type: RuleType;\n id: number;\n respoolTime: number | null;\n order: number;\n exposition: number;\n experimentId: number;\n variationByExposition: VariationByExpositionType[];\n segment: SegmentType | null;\n};\n\nexport type VariationByExpositionType = {\n variationKey: string;\n variationId: number | null;\n exposition: number;\n};\n\nexport type ConfigurationDataType = {\n experiments: ExperimentItemType[];\n featureFlags: FeatureFlagType[];\n configuration: ConfigurationType;\n customData: CustomDataConfigurationType[];\n};\n\nexport type CustomDataConfigurationType = {\n index: number;\n localOnly: boolean;\n scope: CustomDataScope;\n};\n\nexport type ConfigurationType = {\n realTimeUpdate: boolean;\n};\n\nexport type CampaignConfigurationType = {\n targetingData: TargetingDataType;\n configurationData: ConfigurationDataType;\n};\n\nexport type UnsentVisitorTargetingDataType = Map<\n KameleoonData | number,\n KameleoonDataType\n>;\n\nexport type UnsentTargetingDataType = {\n [visitorCode: string]: UnsentVisitorTargetingDataType | undefined;\n};\n\nexport type CampaignConfigurationParametersType = {\n settings: ClientSettingsType;\n storage: IExternalStorage<ClientDataType>;\n requester: Requester;\n offlineTrackingStorage: IExternalStorage<OfflineTracking>;\n externalClientConfiguration?: GetClientConfigurationResultType;\n externalEventSource: IExternalEventSourceConstructor;\n targetingCleanupInterval?: number;\n};\n"],"mappings":"mPAmBY,CAAAA,UAAU,uBAAVA,CAAU,QAAV,CAAAA,CAAU,CAAVA,CAAU,CAAAC,OAAA,cAAVD,CAAU,CAAVA,CAAU,CAAAE,QAAA,eAAVF,CAAU,CAAVA,CAAU,CAAAG,IAAA,WAAVH,CAAU,MAAAI,OAAA,CAAAJ,UAAA,CAAAA,UAAA,IAeV,CAAAK,cAAc,uBAAdA,CAAc,QAAd,CAAAA,CAAc,CAAAC,OAAA,WAAdD,CAAc,CAAAE,WAAA,eAAdF,CAAc,CAAAG,SAAA,aAAdH,CAAc,CAAAI,GAAA,OAAdJ,CAAc,CAAAK,MAAA,UAAdL,CAAc,MAAAD,OAAA,CAAAC,cAAA,CAAAA,cAAA,IAQd,CAAAM,QAAQ,uBAARA,CAAQ,QAAR,CAAAA,CAAQ,CAAAC,oBAAA,wBAARD,CAAQ,CAAAE,iBAAA,qBAARF,CAAQ,CAAAG,eAAA,mBAARH,CAAQ,MAAAP,OAAA,CAAAO,QAAA,CAAAA,QAAA,IAMR,CAAAI,0BAA0B,uBAA1BA,CAA0B,QAA1B,CAAAA,CAA0B,CAAAC,OAAA,WAA1BD,CAA0B,CAAAE,KAAA,SAA1BF,CAA0B,CAAAG,IAAA,QAA1BH,CAA0B,CAAAI,MAAA,UAA1BJ,CAA0B,CAAAK,MAAA,UAA1BL,CAA0B,CAAAM,GAAA,OAA1BN,CAA0B,CAAAO,IAAA,QAA1BP,CAA0B,CAAAQ,EAAA,MAA1BR,CAA0B,CAAAS,OAAA,WAA1BT,CAA0B,CAAAU,OAAA,WAA1BV,CAA0B,MAAAX,OAAA,CAAAW,0BAAA,CAAAA,0BAAA,IAa1B,CAAAW,aAAa,uBAAbA,CAAa,QAAb,CAAAA,CAAa,CAAAC,SAAA,aAAbD,CAAa,CAAAE,WAAA,eAAbF,CAAa,CAAAG,SAAA,aAAbH,CAAa,MAAAtB,OAAA,CAAAsB,aAAA,CAAAA,aAAA,IAMb,CAAAI,eAAe,uBAAfA,CAAe,QAAf,CAAAA,CAAe,CAAAC,KAAA,SAAfD,CAAe,CAAAE,OAAA,WAAfF,CAAe,CAAAG,IAAA,QAAfH,CAAe,MAAA1B,OAAA,CAAA0B,eAAA,CAAAA,eAAA,IAmCf,CAAAI,gBAAgB,uBAAhBA,CAAgB,QAAhB,CAAAA,CAAgB,CAAAC,KAAA,SAAhBD,CAAgB,CAAAE,MAAA,UAAhBF,CAAgB,CAAAG,MAAA,UAAhBH,CAAgB,CAAAL,SAAA,aAAhBK,CAAgB,CAAAI,OAAA,WAAhBJ,CAAgB,CAAAK,uBAAA,2BAAhBL,CAAgB,CAAAM,QAAA,YAAhBN,CAAgB,MAAA9B,OAAA,CAAA8B,gBAAA,CAAAA,gBAAA"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BrowserCondition=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}var BrowserCondition=/*#__PURE__*/function(){function a(b){var c=b.browser,d=b.version,e=b.versionMatchType;_classCallCheck(this,a),_defineProperty(this,"browser",void 0),_defineProperty(this,"version",void 0),_defineProperty(this,"versionMatchType",void 0),_defineProperty(this,"error",void 0),this.browser=c,this.version=d,this.versionMatchType=e}return _createClass(a,[{key:"evaluate",value:function evaluate(a){var b=a.targetingData,c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.Browser];if(c){var d=this.checkCondition(c);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(d)}return(0,_tsRes.Ok)(!1)}},{key:"checkCondition",value:function checkCondition(a){var b=a.browser,c=a.version;if("string"!=typeof this.browser)return!1;if("string"!=typeof this.version)return b===this.browser;if(!this.versionMatchType||"number"!=typeof c)return!1;var d=parseFloat(this.version);switch(isNaN(d)&&(this.error=new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VersionParse,this.version)),this.versionMatchType){case _types.VersionMatchType.EQUAL:return b===this.browser&&c===d;case _types.VersionMatchType.GREATER:return b===this.browser&&c>d;case _types.VersionMatchType.LOWER:return b===this.browser&&c<d;default:(0,_kameleoonError.exhaustCheck)(this.versionMatchType);}}}]),a}();exports.BrowserCondition=BrowserCondition;
2
- //# sourceMappingURL=browserCondition.js.map