@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
package/dist/index.d.ts CHANGED
@@ -2,11 +2,12 @@ export { Ok, Result, Err } from 'ts-res';
2
2
  export { KameleoonClient as KameleoonCore, IKameleoonClient as IKameleoonCore, } from './kameleoonClient';
3
3
  export { KameleoonUtils as KameleoonCoreUtils } from './kameleoonUtils';
4
4
  export { KameleoonException, KameleoonError } from './kameleoonError';
5
- export { ExperimentVariationsType, KameleoonStorageKey, StorageDataType, IExternalStorage, IExternalStorageConstructor, } from './storage';
6
- export { Cookie, VISITOR_CODE_LENGTH, SdkLanguageType } from './constants';
7
- export { CLEANUP_TARGETING_DATA_INTERVAL } from './campaignConfiguration';
8
- export { JSONType } from './campaignConfiguration';
9
- export { Environment, VariableType, ExperimentType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, ExternalPackageInfoType, TrackConversionParamsType, FeatureVariableResultType, InternalSDKConfigurationType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, ServerGetVisitorCodeParametersType, ClientGetVisitorCodeParametersType, MobileGetVisitorCodeParametersType, Milliseconds, } from './types';
10
- export { CustomData, Conversion, Device, Browser, UserAgent, DeviceType, BrowserType, PageView, KameleoonData, KameleoonDataType, PageViewParametersType, ConversionParametersType, } from './kameleoonData';
5
+ export { VisitorDataFiltersType } from './utilities';
6
+ export { FeatureFlagVariationsType, KameleoonStorageKey, StorageDataType, IExternalStorage, IExternalStorageConstructor, } from './storage';
7
+ export { CookieParameter, VISITOR_CODE_LENGTH, SdkLanguageType, } from './constants';
8
+ export { JSONType } from './clientConfiguration';
9
+ export { Environment, VariableType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, ExternalPackageInfoType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, ServerGetVisitorCodeParametersType, ClientGetVisitorCodeParametersType, MobileGetVisitorCodeParametersType, Milliseconds, } from './types';
10
+ export { DEFAULT_CLEANUP_INTERVAL } from './kameleoonData';
11
+ export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, KameleoonData, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './kameleoonData';
11
12
  export { RealTimeEventType, IExternalEventSource, EventSourceOpenParametersType, IExternalEventSourceConstructor, } from './eventSource';
12
13
  export { Header, HttpMethod, TrackParametersType, IExternalRequestDispatcher, GetClientConfigurationResultType, } from './requester';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function get(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function get(){return _kameleoonData.BrowserType}}),Object.defineProperty(exports,"CLEANUP_TARGETING_DATA_INTERVAL",{enumerable:!0,get:function get(){return _campaignConfiguration.CLEANUP_TARGETING_DATA_INTERVAL}}),Object.defineProperty(exports,"ClientGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.ClientGetVisitorCodeParametersType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function get(){return _kameleoonData.Conversion}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function get(){return _kameleoonData.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function get(){return _constants.Cookie}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function get(){return _kameleoonData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function get(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function get(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function get(){return _types.Environment}}),Object.defineProperty(exports,"Err",{enumerable:!0,get:function get(){return _tsRes.Err}}),Object.defineProperty(exports,"EventSourceOpenParametersType",{enumerable:!0,get:function get(){return _eventSource.EventSourceOpenParametersType}}),Object.defineProperty(exports,"ExperimentType",{enumerable:!0,get:function get(){return _types.ExperimentType}}),Object.defineProperty(exports,"ExperimentVariationsType",{enumerable:!0,get:function get(){return _storage.ExperimentVariationsType}}),Object.defineProperty(exports,"ExternalPackageInfoType",{enumerable:!0,get:function get(){return _types.ExternalPackageInfoType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function get(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureVariableResultType",{enumerable:!0,get:function get(){return _types.FeatureVariableResultType}}),Object.defineProperty(exports,"GetClientConfigurationResultType",{enumerable:!0,get:function get(){return _requester.GetClientConfigurationResultType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function get(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function get(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function get(){return _requester.Header}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function get(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function get(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalEventSourceConstructor",{enumerable:!0,get:function get(){return _eventSource.IExternalEventSourceConstructor}}),Object.defineProperty(exports,"IExternalRequestDispatcher",{enumerable:!0,get:function get(){return _requester.IExternalRequestDispatcher}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function get(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IExternalStorageConstructor",{enumerable:!0,get:function get(){return _storage.IExternalStorageConstructor}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function get(){return _kameleoonClient.IKameleoonClient}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function get(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function get(){return _campaignConfiguration.JSONType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function get(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonCoreUtils",{enumerable:!0,get:function get(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function get(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function get(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function get(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function get(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function get(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function get(){return _types.Milliseconds}}),Object.defineProperty(exports,"MobileGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.MobileGetVisitorCodeParametersType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function get(){return _tsRes.Ok}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function get(){return _kameleoonData.PageView}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function get(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"RealTimeEventType",{enumerable:!0,get:function get(){return _eventSource.RealTimeEventType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function get(){return _tsRes.Result}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function get(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function get(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function get(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"ServerGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.ServerGetVisitorCodeParametersType}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function get(){return _storage.StorageDataType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function get(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function get(){return _requester.TrackParametersType}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function get(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function get(){return _constants.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function get(){return _types.VariableType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonError=require("./kameleoonError"),_storage=require("./storage"),_constants=require("./constants"),_campaignConfiguration=require("./campaignConfiguration"),_types=require("./types"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function get(){return _kameleoonData.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function get(){return _kameleoonData.ApplicationVersionDataType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function get(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function get(){return _kameleoonData.BrowserType}}),Object.defineProperty(exports,"ClientGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.ClientGetVisitorCodeParametersType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function get(){return _kameleoonData.Conversion}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function get(){return _kameleoonData.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function get(){return _kameleoonData.Cookie}}),Object.defineProperty(exports,"CookieParameter",{enumerable:!0,get:function get(){return _constants.CookieParameter}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function get(){return _kameleoonData.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function get(){return _kameleoonData.CustomData}}),Object.defineProperty(exports,"DEFAULT_CLEANUP_INTERVAL",{enumerable:!0,get:function get(){return _kameleoonData.DEFAULT_CLEANUP_INTERVAL}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function get(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function get(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function get(){return _types.Environment}}),Object.defineProperty(exports,"Err",{enumerable:!0,get:function get(){return _tsRes.Err}}),Object.defineProperty(exports,"EventSourceOpenParametersType",{enumerable:!0,get:function get(){return _eventSource.EventSourceOpenParametersType}}),Object.defineProperty(exports,"ExternalPackageInfoType",{enumerable:!0,get:function get(){return _types.ExternalPackageInfoType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function get(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureFlagVariationsType",{enumerable:!0,get:function get(){return _storage.FeatureFlagVariationsType}}),Object.defineProperty(exports,"FeatureVariableResultType",{enumerable:!0,get:function get(){return _types.FeatureVariableResultType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function get(){return _kameleoonData.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function get(){return _kameleoonData.GeolocationInfoType}}),Object.defineProperty(exports,"GetClientConfigurationResultType",{enumerable:!0,get:function get(){return _requester.GetClientConfigurationResultType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function get(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function get(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function get(){return _requester.Header}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function get(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function get(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalEventSourceConstructor",{enumerable:!0,get:function get(){return _eventSource.IExternalEventSourceConstructor}}),Object.defineProperty(exports,"IExternalRequestDispatcher",{enumerable:!0,get:function get(){return _requester.IExternalRequestDispatcher}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function get(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IExternalStorageConstructor",{enumerable:!0,get:function get(){return _storage.IExternalStorageConstructor}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function get(){return _kameleoonClient.IKameleoonClient}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function get(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function get(){return _clientConfiguration.JSONType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function get(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonCoreUtils",{enumerable:!0,get:function get(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function get(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function get(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function get(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function get(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function get(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function get(){return _types.Milliseconds}}),Object.defineProperty(exports,"MobileGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.MobileGetVisitorCodeParametersType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function get(){return _tsRes.Ok}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function get(){return _kameleoonData.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function get(){return _kameleoonData.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function get(){return _kameleoonData.PageView}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function get(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"RealTimeEventType",{enumerable:!0,get:function get(){return _eventSource.RealTimeEventType}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function get(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function get(){return _tsRes.Result}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function get(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function get(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function get(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"ServerGetVisitorCodeParametersType",{enumerable:!0,get:function get(){return _types.ServerGetVisitorCodeParametersType}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function get(){return _storage.StorageDataType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function get(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function get(){return _requester.TrackParametersType}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function get(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function get(){return _constants.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function get(){return _types.VariableType}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function get(){return _utilities.VisitorDataFiltersType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester");
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { Ok, Result, Err } from 'ts-res';\nexport {\n KameleoonClient as KameleoonCore,\n IKameleoonClient as IKameleoonCore,\n} from './kameleoonClient';\nexport { KameleoonUtils as KameleoonCoreUtils } from './kameleoonUtils';\nexport { KameleoonException, KameleoonError } from './kameleoonError';\nexport {\n ExperimentVariationsType,\n KameleoonStorageKey,\n StorageDataType,\n IExternalStorage,\n IExternalStorageConstructor,\n} from './storage';\nexport { Cookie, VISITOR_CODE_LENGTH, SdkLanguageType } from './constants';\nexport { CLEANUP_TARGETING_DATA_INTERVAL } from './campaignConfiguration';\nexport { JSONType } from './campaignConfiguration';\nexport {\n Environment,\n VariableType,\n ExperimentType,\n FeatureFlagType,\n SDKCoreParameters,\n SDKConfigurationType,\n ExternalPackageInfoType,\n TrackConversionParamsType,\n FeatureVariableResultType,\n InternalSDKConfigurationType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n ServerGetVisitorCodeParametersType,\n ClientGetVisitorCodeParametersType,\n MobileGetVisitorCodeParametersType,\n Milliseconds,\n} from './types';\nexport {\n CustomData,\n Conversion,\n Device,\n Browser,\n UserAgent,\n DeviceType,\n BrowserType,\n PageView,\n KameleoonData,\n KameleoonDataType,\n PageViewParametersType,\n ConversionParametersType,\n} from './kameleoonData';\nexport {\n RealTimeEventType,\n IExternalEventSource,\n EventSourceOpenParametersType,\n IExternalEventSourceConstructor,\n} from './eventSource';\nexport {\n Header,\n HttpMethod,\n TrackParametersType,\n IExternalRequestDispatcher,\n GetClientConfigurationResultType,\n} from './requester';\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { Ok, Result, Err } from 'ts-res';\nexport {\n KameleoonClient as KameleoonCore,\n IKameleoonClient as IKameleoonCore,\n} from './kameleoonClient';\nexport { KameleoonUtils as KameleoonCoreUtils } from './kameleoonUtils';\nexport { KameleoonException, KameleoonError } from './kameleoonError';\nexport { VisitorDataFiltersType } from './utilities';\nexport {\n FeatureFlagVariationsType,\n KameleoonStorageKey,\n StorageDataType,\n IExternalStorage,\n IExternalStorageConstructor,\n} from './storage';\nexport {\n CookieParameter,\n VISITOR_CODE_LENGTH,\n SdkLanguageType,\n} from './constants';\nexport { JSONType } from './clientConfiguration';\nexport {\n Environment,\n VariableType,\n FeatureFlagType,\n SDKCoreParameters,\n SDKConfigurationType,\n ExternalPackageInfoType,\n TrackConversionParamsType,\n FeatureVariableResultType,\n RemoteVisitorDataParamsType,\n InternalSDKConfigurationType,\n GetFeatureFlagVariableParamsType,\n GetVisitorWarehouseAudienceParamsType,\n ServerGetVisitorCodeParametersType,\n ClientGetVisitorCodeParametersType,\n MobileGetVisitorCodeParametersType,\n Milliseconds,\n} from './types';\nexport { DEFAULT_CLEANUP_INTERVAL } from './kameleoonData';\nexport {\n ApplicationVersion,\n CustomData,\n Conversion,\n Device,\n Cookie,\n Browser,\n UserAgent,\n DeviceType,\n CookieType,\n GeolocationData,\n GeolocationInfoType,\n OperatingSystemType,\n OperatingSystem,\n BrowserType,\n PageView,\n KameleoonData,\n KameleoonDataType,\n PageViewParametersType,\n ConversionParametersType,\n ApplicationVersionDataType,\n} from './kameleoonData';\nexport {\n RealTimeEventType,\n IExternalEventSource,\n EventSourceOpenParametersType,\n IExternalEventSourceConstructor,\n} from './eventSource';\nexport {\n Header,\n HttpMethod,\n TrackParametersType,\n IExternalRequestDispatcher,\n GetClientConfigurationResultType,\n} from './requester';\n"],"mappings":""}
@@ -1,6 +1,6 @@
1
- import { JSONType } from './campaignConfiguration';
1
+ import { JSONType } from './clientConfiguration';
2
2
  import { CustomData, KameleoonDataType } from './kameleoonData';
3
- import { TrackConversionParamsType, ExperimentType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, GetVisitorWarehouseAudienceParamsType } from './types';
3
+ import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType } from './types';
4
4
  /**
5
5
  * @interface an interface of KameleoonClient instance
6
6
  */
@@ -27,38 +27,22 @@ export interface IKameleoonClient {
27
27
  * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
28
28
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
29
29
  * - `KameleoonException.StorageWrite` Couldn't update storage data
30
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
30
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
31
31
  */
32
32
  addData: (visitorCode: string, ...data: KameleoonDataType[]) => void;
33
33
  /**
34
- * @method getRemoteVisitorData - an asynchronous method for retrieving custom data for the latest visit of `visitorCode` from Kameleoon Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.
35
- * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
36
- * @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`
34
+ * @method getRemoteVisitorData - an asynchronous method for retrieving KameleoonData from Data API and optionally adding it to the storage so that other methods could decide whether the current visitor is targeted or not.
35
+ * @param {RemoteVisitorDataParamsType} remoteVisitorDataParameters - `visitorCode`, `shouldAddData` and `filters` parameters
37
36
  * @returns {KameleoonDataType[]} promise resolved to an array of `KameleoonData` instances, only includes custom data
38
37
  * @throws `KameleoonError` with one of the following `type` s:
39
38
  *
40
39
  * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
41
40
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
42
41
  * - `KameleoonException.RemoteData` - Couldn't retrieve data from Kameleoon server
42
+ * - `KameleoonException.VisitAmount` - Visit amount must be a number between 1 and 25
43
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
43
44
  */
44
- getRemoteVisitorData: (visitorCode: string, shouldAddData?: boolean) => Promise<KameleoonDataType[]>;
45
- /**
46
- * @method triggerExperiment - triggers experiment by assigning the variation to the user with `visitorCode`, if the variation is already assigned just returns it's id. Note: returned id `0` indicates default variation. At the same time sends tracking request.
47
- * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
48
- * @param {number} experimentId - id of experiment running for the current visitor
49
- * @returns {number} associated variationId which is successfully searched/assigned
50
- * @throws `KameleoonError` with one of the following `type` s:
51
- *
52
- * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
53
- * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
54
- * - `KameleoonException.ExperimentConfigurationNotFound` No configuration found for provided `experimentId`
55
- * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
56
- * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
57
- * - `KameleoonException.StorageRead` Couldn't find associated experiment by provided `experimentId` and `visitorCode` inside the storage
58
- * - `KameleoonException.NotTargeted` Current visitor is not targeted
59
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
60
- */
61
- triggerExperiment: (visitorCode: string, experimentId: number) => number;
45
+ getRemoteVisitorData: ({ visitorCode, shouldAddData, filters, }: RemoteVisitorDataParamsType) => Promise<KameleoonDataType[]>;
62
46
  /**
63
47
  * @method trackConversion - creates and adds `Conversion` data to the visitor with specified parameters and executes `flush`. Note: it's a helper method for the quick and convenient conversion tracking, however creating and adding `Conversion` manually allows more flexible `Conversion` with `negative` parameter
64
48
  * @param {TrackConversionParamsType} conversionParameters - `visitorCode`, `goalId` and `revenue` parameters for data tracking
@@ -74,56 +58,22 @@ export interface IKameleoonClient {
74
58
  * @method flush - takes visitor associated kameleoon data and sends the data tracking request with collected data,
75
59
  * sent data is removed from `KameleoonClient` instance but not from the storage for correct targeting checks. If no visitor is passed,
76
60
  * then data for all visitors is sent and removed from `KameleoonClient` instance. Moreover, regardless of visitor code input
77
- * the method first attemps to send all previously failed tracking requests which were stored locally during the offline mode.
61
+ * the method first attempts to send all previously failed tracking requests which were stored locally during the offline mode.
78
62
  * @param {string | undefined} visitorCode - unique visitor identification string, can't exceed 255 characters length
79
63
  * @returns {void}
80
64
  * @throws `KameleoonError` with one of the following `type` s:
81
65
  *
82
66
  * - `KameleoonException.VisitorCodeMaxLength` The visitor code length was exceeded
83
67
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
84
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
68
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
85
69
  */
86
70
  flush: (visitorCode: string) => void;
87
- /**
88
- * @deprecated Use flush method instead.
89
- */
90
- flushData: (visitorCode: string) => void;
91
- /**
92
- * @method getExperiments - returns a list of experiments stored in the client configuration
93
- * @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields
94
- * @throws `KameleoonError` with one of the following `type` s:
95
- *
96
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
97
- */
98
- getExperiments: () => ExperimentType[];
99
- /**
100
- * @method getVisitorExperiments - returns a list of experiments that the visitor with `visitorCode` is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated if the experiment will be triggered).
101
- * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
102
- * @param {boolean | undefined} isAllocated - boolean value indicating that only experiments *allocated* for visitor will be returned. Default value is `true`
103
- * @returns {ExperimentType[]} a list of all experiments items with `id` and `name` fields
104
- * @throws `KameleoonError` with one of the following `type` s:
105
- *
106
- * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
107
- * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
108
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
109
- */
110
- getVisitorExperiments: (visitorCode: string, isAllocated?: boolean) => ExperimentType[];
111
- /**
112
- * @method getExperimentVariationData - returns variation data in JSON format for the variation with `variationId`
113
- * @param {number} variationId - id of variation
114
- * @returns {JSONType} variation data in JSON format
115
- * @throws `KameleoonError` with one of the following `type` s:
116
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
117
- * - `KameleoonException.JSONParse` - Couldn't pass JSON value
118
- * - `KameleoonException.VariationNotFound` - No variation found for provided `variationId`
119
- */
120
- getExperimentVariationData: (variationId: number) => JSONType | null;
121
71
  /**
122
72
  * @method getFeatureFlags - returns a list of feature flags stored in the client configuration
123
73
  * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields
124
74
  * @throws `KameleoonError` with one of the following `type` s:
125
75
  *
126
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
76
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
127
77
  */
128
78
  getFeatureFlags: () => FeatureFlagType[];
129
79
  /**
@@ -135,6 +85,7 @@ export interface IKameleoonClient {
135
85
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
136
86
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
137
87
  * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
88
+ * - `KameleoonException.StorageRead` - Couldn't read storage data
138
89
  * - `KameleoonException.NotTargeted` - Current visitor is not targeted
139
90
  */
140
91
  getVisitorFeatureFlags: (visitorCode: string) => FeatureFlagType[];
@@ -147,8 +98,8 @@ export interface IKameleoonClient {
147
98
  *
148
99
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
149
100
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
150
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
151
- * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
101
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
102
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`
152
103
  * - `KameleoonException.DataInconsistency` - Allocated variation was found but there is no feature flag with according `featureKey`.
153
104
  * - `KameleoonException.NotTargeted` - Current visitor is not targeted
154
105
  */
@@ -162,27 +113,43 @@ export interface IKameleoonClient {
162
113
  *
163
114
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
164
115
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
165
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
166
- * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
116
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
117
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`
167
118
  * - `KameleoonException.NotTargeted` - Current visitor is not targeted
168
119
  */
169
120
  getFeatureFlagVariationKey: (visitorCode: string, featureKey: string) => string;
170
121
  /**
171
122
  * @method getFeatureFlagVariable - returns a variable for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
172
123
  * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.
173
- * @returns {FeatureVariableResultType} a variable object containing `type` and `value` fields, `type` can be checked against `FeatureVariableType` enum, if the `type` is `FeatureVariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
124
+ * @returns {FeatureVariableResultType} a variable object containing `type` and `value` fields. You can check the `type` field against `FeatureVariableType` enum. For example, if the `type` is `FeatureVariableType.BOOLEAN` then `value` will be a `boolean` type.
174
125
  * @throws `KameleoonError` with one of the following `type` s:
175
126
  *
176
127
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
177
128
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
178
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
179
- * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `visitorCode` and `featureKey`
129
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
130
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`
180
131
  * - `KameleoonException.FeatureFlagVariableNotFound` - No feature variable was found for provided `visitorCode` and `variableKey`
181
132
  * - `KameleoonException.NotTargeted` - Current visitor is not targeted
182
- * - `KameleoonException.JSONParse` - Couldn't pass JSON value
183
- * - `KameleoonException.NumberParse` - Couldn't pass Number value
133
+ * - `KameleoonException.JSONParse` - Couldn't parse JSON value
134
+ * - `KameleoonException.NumberParse` - Couldn't parse Number value
184
135
  */
185
136
  getFeatureFlagVariable: ({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType) => FeatureVariableResultType;
137
+ /**
138
+ * @method getFeatureFlagVariables - returns a list of variables for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
139
+ * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters
140
+ * @param {string} featureKey - a unique key for feature flag
141
+ * @returns {FeatureVariableResultType[]} a list of variable objects containing `type` and `value` fields. You can check the `type` field against `FeatureVariableType` enum. For example, if the `type` is `FeatureVariableType.BOOLEAN` then `value` will be a `boolean` type.
142
+ * @throws `KameleoonError` with one of the following `type` s:
143
+ *
144
+ * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
145
+ * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
146
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
147
+ * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`
148
+ * - `KameleoonException.FeatureFlagVariationNotFound` - No feature variation was found for provided `visitorCode` and `variationKey`
149
+ * - `KameleoonException.JSONParse` - Couldn't parse JSON value
150
+ * - `KameleoonException.NumberParse` - Couldn't parse Number value
151
+ */
152
+ getFeatureFlagVariables: (visitorCode: string, featureKey: string) => FeatureVariableResultType[];
186
153
  /**
187
154
  * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.
188
155
  * @param {string} key - unique key that the data you try to get is associated with.
@@ -222,7 +189,7 @@ export interface IKameleoonClient {
222
189
  * @returns {void}
223
190
  * @throws `KameleoonError` with one of the following `type` s:
224
191
  *
225
- * - `KameleoonException.Initialization` - Method was executed before `initialize` was done for `kameleoonClient`
192
+ * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
226
193
  */
227
194
  onConfigurationUpdate: (callback: () => void) => void;
228
195
  }
@@ -232,32 +199,29 @@ export interface IKameleoonClient {
232
199
  * for communicating with Kameleoon JavaScript SDK Core, when new instance is created
233
200
  */
234
201
  export declare class KameleoonClient implements IKameleoonClient {
235
- private variationConfiguration?;
236
- private campaignConfiguration;
237
- private variationDataStorage;
202
+ private variationConfiguration;
203
+ private clientConfiguration;
204
+ private dataManager;
238
205
  private offlineTrackingStorage;
239
206
  private trackingCache;
240
207
  private requester;
241
208
  private externalPackageInfo;
242
209
  private isOfflineModeOn?;
210
+ private initialized;
243
211
  /**
244
212
  * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
245
213
  */
246
214
  constructor({ siteCode, configuration, internalConfiguration, }: SDKCoreParameters);
247
215
  initialize(useCache?: boolean): Promise<boolean>;
248
216
  addData(visitorCode: string, ...data: KameleoonDataType[]): void;
249
- getRemoteVisitorData(visitorCode: string, shouldAddData?: boolean): Promise<KameleoonDataType[]>;
250
- triggerExperiment(visitorCode: string, experimentId: number): number;
217
+ getRemoteVisitorData({ visitorCode, shouldAddData, filters, }: RemoteVisitorDataParamsType): Promise<KameleoonDataType[]>;
251
218
  trackConversion({ visitorCode, goalId, revenue, }: TrackConversionParamsType): void;
252
219
  flush(visitorCode?: string): void;
253
- flushData(visitorCode?: string): void;
254
- getExperiments(): ExperimentType[];
255
- getVisitorExperiments(visitorCode: string, isActive?: boolean): ExperimentType[];
256
- getExperimentVariationData(variationId: number): JSONType;
257
220
  getFeatureFlags(): FeatureFlagType[];
258
221
  getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[];
259
222
  getFeatureFlagVariationKey(visitorCode: string, featureKey: string): string;
260
223
  getFeatureFlagVariable({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType): FeatureVariableResultType;
224
+ getFeatureFlagVariables(visitorCode: string, featureKey: string): FeatureVariableResultType[];
261
225
  isFeatureFlagActive(visitorCode: string, featureKey: string): boolean;
262
226
  getRemoteData(key: string): Promise<JSONType>;
263
227
  getVisitorWarehouseAudience({ visitorCode, customDataIndex, warehouseKey, }: GetVisitorWarehouseAudienceParamsType): Promise<CustomData | null>;
@@ -1,19 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_campaignConfiguration=require("./campaignConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration");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 _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct.bind():function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(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 _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)}/**
2
- * @class
3
- * KameleoonClient - a class for creating kameleoon client instance
4
- * for communicating with Kameleoon JavaScript SDK Core, when new instance is created
5
- */var KameleoonClient=/*#__PURE__*/function(){/**
6
- * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
7
- */function a(b){var c=b.siteCode,d=b.configuration,e=b.internalConfiguration;_classCallCheck(this,a),_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"campaignConfiguration",void 0),_defineProperty(this,"variationDataStorage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"isOfflineModeOn",void 0);var f=new _clientSettings.ClientSettings(c,d),g=f.settings,h=e.externalStorage,i=e.externalEventSource,j=e.externalPackageInfo,k=e.externalRequestDispatcher,l=e.externalClientConfiguration,m=new _requester.Requester({siteCode:c,environment:g.environment,packageInfo:j,requestDispatcher:k}),n=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),o=h.initialize(_storage.KameleoonStorageKey.ClientData),p=h.initialize(_storage.KameleoonStorageKey.VariationData),q=h.initialize(_storage.KameleoonStorageKey.OfflineTracking),r=new _campaignConfiguration.CampaignConfiguration({settings:g,storage:o,requester:m,externalClientConfiguration:l,targetingCleanupInterval:null===d||void 0===d?void 0:d.targetingDataCleanupInterval,offlineTrackingStorage:q,externalEventSource:i});this.requester=m,this.trackingCache=n,this.campaignConfiguration=r,this.variationDataStorage=p,this.externalPackageInfo=j,this.offlineTrackingStorage=q}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;return _regeneratorRuntime().wrap(function e(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,this.campaignConfiguration.initialize(a);case 2:return c=b.sent,c.throw(),d=new _variationConfiguration.VariationConfiguration(this.campaignConfiguration.experiments,this.variationDataStorage),this.variationConfiguration=d,this.isOfflineModeOn=a,b.abrupt("return",c.ok);case 8:case"end":return b.stop();}},b,this)}));return a}()},{key:"addData",value:function addData(a){var b;if(_utilities.Utilities.validateVisitorCode(a).throw(),!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];(b=this.campaignConfiguration).addTargetingData.apply(b,[a].concat(d)).throw()}},{key:"getRemoteVisitorData",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g,h,i,j=arguments;return _regeneratorRuntime().wrap(function k(b){for(;1;)switch(b.prev=b.next){case 0:return c=!(1<j.length&&void 0!==j[1])||j[1],b.next=3,this.requester.getVisitorData(a);case 3:d=b.sent,e=d.throw(),f=_utilities.Utilities.parseVisitorData(e),g=_createForOfIteratorHelper(f);try{for(g.s();!(h=g.n()).done;)i=h.value,(c||this.campaignConfiguration.isPersistentCustomData(i))&&this.addData(a,i)}catch(a){g.e(a)}finally{g.f()}return b.abrupt("return",f);case 9:case"end":return b.stop();}},b,this)}));return a}()},{key:"triggerExperiment",value:function triggerExperiment(a,b){var c=this;if(_utilities.Utilities.validateVisitorCode(a).throw(),!this.campaignConfiguration||!this.variationConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);var d=this.campaignConfiguration.experiments.find(function(a){return a.id===b+""});if(!d)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ExperimentConfigurationNotFound,b,a);var e=this.campaignConfiguration.storedTargetingData[a],f=_constants.UNALLOCATED_VARIATION_ID,g=_utilities.Utilities.checkTargeting({visitorCode:a,experimentId:b,targetingData:e,segment:d.segment,campaignConfiguration:this.campaignConfiguration,variationConfiguration:this.variationConfiguration,packageInfo:this.externalPackageInfo}).throw();if(f=this.variationConfiguration.getAssociatedVariationId(a,b).else(function(d){if(d.type===_kameleoonError.KameleoonException.NotAllocated)return _utilities.Utilities.trackExperiment({requester:c.requester,campaignConfiguration:c.campaignConfiguration,isUnallocated:!0,variationId:f,visitorCode:a,experimentId:b,isOfflineModeOn:c.isOfflineModeOn,offlineTrackingStorage:c.offlineTrackingStorage}),_constants.UNALLOCATED_VARIATION_ID;throw d}),_utilities.Utilities.trackExperiment({requester:this.requester,campaignConfiguration:this.campaignConfiguration,isUnallocated:!1,variationId:f,visitorCode:a,experimentId:b,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage}),!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NotTargeted,a);return _utilities.Utilities.updateCache({cacheManager:this.trackingCache,visitorCode:a,experimentId:b,variationId:f}),f}},{key:"trackConversion",value:function trackConversion(a){var b=a.visitorCode,c=a.goalId,d=a.revenue;this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b)}},{key:"flush",value:function flush(a){if(!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a&&_utilities.Utilities.validateVisitorCode(a).throw(),a)return void _utilities.Utilities.trackData({visitorCode:a,campaignConfiguration:this.campaignConfiguration,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage});// --- Note ---
8
- // `Utilities.trackData` executes `Utilities.sendOfflineTracking` asynchronously at first, but
9
- // we need to execute `Utilities.sendOfflineTracking` even if calling `Utilities.trackData` is skipped
10
- // due to lack of unsent data
11
- if(!this.campaignConfiguration.unsentDataVisitors.length)return void _utilities.Utilities.sendOfflineTracking({requester:this.requester,storage:this.offlineTrackingStorage});var b,c=_createForOfIteratorHelper(this.campaignConfiguration.unsentDataVisitors);try{for(c.s();!(b=c.n()).done;){var d=b.value;_utilities.Utilities.trackData({visitorCode:d,campaignConfiguration:this.campaignConfiguration,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage})}}catch(a){c.e(a)}finally{c.f()}}},{key:"flushData",value:function flushData(a){this.flush(a)}},{key:"getExperiments",value:function getExperiments(){if(!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);return this.campaignConfiguration.experiments.map(function(a){var b=a.id,c=a.name;return{id:+b,name:c}})}},{key:"getVisitorExperiments",value:function getVisitorExperiments(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];if(!this.variationConfiguration||!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_utilities.Utilities.validateVisitorCode(a).throw();var c,d=this.campaignConfiguration.experiments,e=[],f=this.campaignConfiguration.storedTargetingData[a],g=_createForOfIteratorHelper(d);try{for(g.s();!(c=g.n()).done;){var h=c.value,i=h.id,j=h.name,k=h.segment,l=_utilities.Utilities.checkTargeting({targetingData:f,visitorCode:a,segment:k,variationConfiguration:this.variationConfiguration,campaignConfiguration:this.campaignConfiguration,experimentId:+i,packageInfo:this.externalPackageInfo}).throw();if(l){// -- If `isActive=false` then return every experiment
12
- if(!b){e.push({id:+i,name:j});continue}// -- Else first check if there are saved variations for the experiment
13
- // if there is at least one than it's active
14
- var m=this.variationConfiguration.getAssignedVariations(a);if(m.ok){var n=m.data[h.id];if(n){e.push({id:+i,name:j});continue}}// -- Second check if the experiment will have an allocated variation upon triggering
15
- // if yes than it's active
16
- var o=this.variationConfiguration.getExperimentVariation(a,h);o.ok&&e.push({id:+i,name:j})}}}catch(a){g.e(a)}finally{g.f()}return e}},{key:"getExperimentVariationData",value:function getExperimentVariationData(a){if(!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);var b,c=this.campaignConfiguration.experiments,d=_createForOfIteratorHelper(c);try{for(d.s();!(b=d.n()).done;){var e=b.value,f=e.variations.find(function(b){return b.id===a+""});if(f)try{return JSON.parse(f.customJson)}catch(a){throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a)}}}catch(a){d.e(a)}finally{d.f()}throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VariationNotFound)}},{key:"getFeatureFlags",value:function getFeatureFlags(){if(!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);return this.campaignConfiguration.featureFlags.map(function(a){var b=a.id,c=a.featureKey;return{id:b,key:c}})}},{key:"getVisitorFeatureFlags",value:function getVisitorFeatureFlags(a){if(!this.variationConfiguration||!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);var b,c=this.campaignConfiguration.featureFlags,d=[],e=this.campaignConfiguration.storedTargetingData[a],f=_createForOfIteratorHelper(c);try{for(f.s();!(b=f.n()).done;){var g=b.value,h=this.variationConfiguration.getFeatureFlagVariation({visitorCode:a,targetingData:e,featureFlag:g,campaignConfiguration:this.campaignConfiguration,packageInfo:this.externalPackageInfo}).throw();if(h.variationKey!==_constants.OFF_VARIATION_KEY){var i=h.featureFlagId,j=h.featureKey;d.push({id:i,key:j})}}}catch(a){f.e(a)}finally{f.f()}return d}},{key:"getFeatureFlagVariationKey",value:function getFeatureFlagVariationKey(a,b){_utilities.Utilities.validateVisitorCode(a).throw();var c=this._getFeatureFlagVariation(a,b).throw(),d=c.variationKey;return d}},{key:"getFeatureFlagVariable",value:function getFeatureFlagVariable(a){var b,c=a.visitorCode,d=a.featureKey,e=a.variableKey;_utilities.Utilities.validateVisitorCode(c).throw();var f=this._getFeatureFlagVariation(c,d).throw(),g=f.variationKey,h=this.campaignConfiguration.featureFlags,i=h.find(function(a){return a.featureKey===d});// --- Note ---
17
- // `_getFeatureFlagVariation` already checks `campaignConfiguration` initialization
18
- if(!i)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,d,c);var j=null===(b=i.variations.find(function(a){return a.key===g}))||void 0===b?void 0:b.variables.find(function(a){return a.key===e});if(!j)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,e,c);var k=_utilities.Utilities.parseFeatureVariable(j).throw();return k}},{key:"isFeatureFlagActive",value:function isFeatureFlagActive(a,b){var c=this.getFeatureFlagVariationKey(a,b);return c!==_constants.OFF_VARIATION_KEY}},{key:"getRemoteData",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c;return _regeneratorRuntime().wrap(function d(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,this.requester.getRemoteData(a);case 2:return c=b.sent,b.abrupt("return",c.throw());case 4:case"end":return b.stop();}},b,this)}));return a}()},{key:"getVisitorWarehouseAudience",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function b(a){var c,d,e,f,g;return _regeneratorRuntime().wrap(function h(b){for(;1;)switch(b.prev=b.next){case 0:return c=a.visitorCode,d=a.customDataIndex,e=a.warehouseKey,_utilities.Utilities.validateVisitorCode(c).throw(),b.next=4,this.getRemoteData(e||c);case 4:if(f=b.sent,f){b.next=7;break}throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData);case 7:if(f[_constants.WAREHOUSE_AUDIENCE_KEY]&&0!==Object.keys(f[_constants.WAREHOUSE_AUDIENCE_KEY]).length){b.next=9;break}return b.abrupt("return",null);case 9:return g=_construct(_kameleoonData.CustomData,[d].concat(_toConsumableArray(Object.keys(f[_constants.WAREHOUSE_AUDIENCE_KEY])))),this.campaignConfiguration.addTargetingData(c,g),b.abrupt("return",g);case 12:case"end":return b.stop();}},b,this)}));return a}()},{key:"onConfigurationUpdate",value:function onConfigurationUpdate(a){if(!this.campaignConfiguration)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.campaignConfiguration.onConfigurationUpdate(a)}},{key:"getEngineTrackingCode",value:function getEngineTrackingCode(a){return _utilities.Utilities.validateVisitorCode(a).throw(),_utilities.Utilities.getTrackingCode(this.trackingCache,a)}},{key:"_getFeatureFlagVariation",value:function _getFeatureFlagVariation(a,b){if(!this.variationConfiguration||!this.campaignConfiguration)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));var c=this.campaignConfiguration.featureFlags,d=c.find(function(a){return a.featureKey===b});if(!d)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b,a));var e=this.campaignConfiguration.storedTargetingData[a],f=this.variationConfiguration.getFeatureFlagVariation({visitorCode:a,featureFlag:d,targetingData:e,withAssignment:!0,campaignConfiguration:this.campaignConfiguration,packageInfo:this.externalPackageInfo}).throw(),g=f.experimentId,h=f.variationId;return"number"==typeof h&&"number"==typeof g&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,visitorCode:a,experimentId:g,variationId:h}),_utilities.Utilities.trackRule({visitorCode:a,requester:this.requester,featureFlagVariation:f,campaignConfiguration:this.campaignConfiguration,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage}),(0,_tsRes.Ok)(f)}}]),a}();exports.KameleoonClient=KameleoonClient;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_clientConfiguration=require("./clientConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration");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 _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct.bind():function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(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 _regeneratorRuntime(){"use strict";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 KameleoonClient=function(){function a(b){var c=b.siteCode,d=b.configuration,e=b.internalConfiguration;_classCallCheck(this,a),_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"isOfflineModeOn",void 0),_defineProperty(this,"initialized",!1);var f=new _clientSettings.ClientSettings(c,d),g=f.settings,h=e.externalStorage,i=e.externalEventSource,j=e.externalPackageInfo,k=e.externalRequestDispatcher,l=e.externalClientConfiguration,m=new _requester.Requester({siteCode:c,environment:g.environment,packageInfo:j,requestDispatcher:k}),n=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),o=h.initialize(_storage.KameleoonStorageKey.ClientData),p=h.initialize(_storage.KameleoonStorageKey.TargetingData),q=h.initialize(_storage.KameleoonStorageKey.VariationData),r=h.initialize(_storage.KameleoonStorageKey.OfflineTracking),s=new _kameleoonData.DataManager({storage:p,targetingCleanupInterval:null===d||void 0===d?void 0:d.targetingDataCleanupInterval}),t=new _clientConfiguration.ClientConfiguration({settings:g,storage:o,dataManager:s,requester:m,externalClientConfiguration:l,offlineTrackingStorage:r,externalEventSource:i}),u=new _variationConfiguration.VariationConfiguration(q);this.variationConfiguration=u,this.requester=m,this.trackingCache=n,this.dataManager=s,this.clientConfiguration=t,this.externalPackageInfo=j,this.offlineTrackingStorage=r}return _createClass(a,[{key:"initialize",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(_regeneratorRuntime().mark(function b(a){var c;return _regeneratorRuntime().wrap(function d(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,this.clientConfiguration.initialize(a);case 2:return c=b.sent,c.throw(),this.isOfflineModeOn=a,this.initialized=!0,b.abrupt("return",c.ok);case 7:case"end":return b.stop();}},b,this)}));return a}()},{key:"addData",value:function addData(a){var b;if(_utilities.Utilities.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];(b=this.dataManager).addData.apply(b,[a].concat(d)).throw()}},{key:"getRemoteVisitorData",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(_regeneratorRuntime().mark(function b(a){var c,d,e,f,g,h,i,j,k,l,m,n;return _regeneratorRuntime().wrap(function o(b){for(;1;)switch(b.prev=b.next){case 0:if(c=a.visitorCode,d=a.shouldAddData,e=void 0===d||d,f=a.filters,g=void 0===f?_constants.DEFAULT_VISITOR_DATA_FILTERS:f,this.initialized){b.next=3;break}throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);case 3:if(_utilities.Utilities.validateVisitorCode(c).throw(),h=g.visitAmount,!("number"==typeof h&&(1>h||25<h))){b.next=7;break}throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);case 7:return b.next=9,this.requester.getVisitorData(c,g);case 9:i=b.sent,j=i.throw(),k=_utilities.Utilities.parseVisitorData({data:j,filters:g,visitorCode:c,variationConfiguration:this.variationConfiguration}),l=_createForOfIteratorHelper(k);try{for(l.s();!(m=l.n()).done;)n=m.value,(e||this.dataManager.isPersistentCustomData(n))&&this.addData(c,n)}catch(a){l.e(a)}finally{l.f()}return b.abrupt("return",k);case 15:case"end":return b.stop();}},b,this)}));return a}()},{key:"trackConversion",value:function trackConversion(a){var b=a.visitorCode,c=a.goalId,d=a.revenue;this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b)}},{key:"flush",value:function flush(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a&&_utilities.Utilities.validateVisitorCode(a).throw(),a)return void _utilities.Utilities.trackData({visitorCode:a,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage});if(!this.dataManager.unsentDataVisitors.length)return void _utilities.Utilities.sendOfflineTracking({requester:this.requester,storage:this.offlineTrackingStorage});var b,c=_createForOfIteratorHelper(this.dataManager.unsentDataVisitors);try{for(c.s();!(b=c.n()).done;){var d=b.value;_utilities.Utilities.trackData({visitorCode:d,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage})}}catch(a){c.e(a)}finally{c.f()}}},{key:"getFeatureFlags",value:function getFeatureFlags(){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);return this.clientConfiguration.featureFlags.map(function(a){var b=a.id,c=a.featureKey;return{id:b,key:c}})}},{key:"getVisitorFeatureFlags",value:function getVisitorFeatureFlags(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);var b,c=this.clientConfiguration.featureFlags,d=[],e=this.dataManager.storedTargetingData[a],f=_createForOfIteratorHelper(c);try{for(f.s();!(b=f.n()).done;){var g=b.value,h=this.variationConfiguration.getVariation({visitorCode:a,targetingData:e,featureFlag:g,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();if(h.variationKey!==_constants.OFF_VARIATION_KEY){var i=h.featureFlagId,j=h.featureKey;d.push({id:i,key:j})}}}catch(a){f.e(a)}finally{f.f()}return d}},{key:"getFeatureFlagVariationKey",value:function getFeatureFlagVariationKey(a,b){_utilities.Utilities.validateVisitorCode(a).throw();var c=this._getFeatureFlagVariation(a,b).throw(),d=c.variationKey;return d}},{key:"getFeatureFlagVariable",value:function getFeatureFlagVariable(a){var b,c=a.visitorCode,d=a.featureKey,e=a.variableKey;_utilities.Utilities.validateVisitorCode(c).throw();var f=this._getFeatureFlagVariation(c,d).throw(),g=f.variationKey,h=this.clientConfiguration.featureFlags,i=h.find(function(a){return a.featureKey===d});if(!i)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,d);var j=null===(b=i.variations.find(function(a){return a.key===g}))||void 0===b?void 0:b.variables.find(function(a){return a.key===e});if(!j)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,e,c);var k=_utilities.Utilities.parseFeatureVariable(j).throw();return k}},{key:"getFeatureFlagVariables",value:function getFeatureFlagVariables(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_utilities.Utilities.validateVisitorCode(a).throw();var c=this._getFeatureFlagVariation(a,b).throw(),d=c.variationKey,e=this.clientConfiguration.featureFlags,f=e.find(function(a){return a.featureKey===b});if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b);var g=f.variations.find(function(a){return a.key===d});if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,a);var h,i=[],j=_createForOfIteratorHelper(g.variables);try{for(j.s();!(h=j.n()).done;){var k=h.value,l=_utilities.Utilities.parseFeatureVariable(k).throw();i.push(l)}}catch(a){j.e(a)}finally{j.f()}return i}},{key:"isFeatureFlagActive",value:function isFeatureFlagActive(a,b){var c=this.getFeatureFlagVariationKey(a,b);return c!==_constants.OFF_VARIATION_KEY}},{key:"getRemoteData",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(_regeneratorRuntime().mark(function b(a){var c;return _regeneratorRuntime().wrap(function d(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,this.requester.getRemoteData(a);case 2:return c=b.sent,b.abrupt("return",c.throw());case 4:case"end":return b.stop();}},b,this)}));return a}()},{key:"getVisitorWarehouseAudience",value:function(){function a(a){return b.apply(this,arguments)}var b=_asyncToGenerator(_regeneratorRuntime().mark(function b(a){var c,d,e,f,g;return _regeneratorRuntime().wrap(function h(b){for(;1;)switch(b.prev=b.next){case 0:return c=a.visitorCode,d=a.customDataIndex,e=a.warehouseKey,_utilities.Utilities.validateVisitorCode(c).throw(),b.next=4,this.getRemoteData(e||c);case 4:if(f=b.sent,f){b.next=7;break}throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData);case 7:if(f[_constants.WAREHOUSE_AUDIENCE_KEY]&&0!==Object.keys(f[_constants.WAREHOUSE_AUDIENCE_KEY]).length){b.next=9;break}return b.abrupt("return",null);case 9:return g=_construct(_kameleoonData.CustomData,[d].concat(_toConsumableArray(Object.keys(f[_constants.WAREHOUSE_AUDIENCE_KEY])))),this.dataManager.addData(c,g),b.abrupt("return",g);case 12:case"end":return b.stop();}},b,this)}));return a}()},{key:"onConfigurationUpdate",value:function onConfigurationUpdate(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.clientConfiguration.onConfigurationUpdate(a)}},{key:"getEngineTrackingCode",value:function getEngineTrackingCode(a){return _utilities.Utilities.validateVisitorCode(a).throw(),_utilities.Utilities.getTrackingCode(this.trackingCache,a)}},{key:"_getFeatureFlagVariation",value:function _getFeatureFlagVariation(a,b){if(!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));var c=this.clientConfiguration.featureFlags,d=c.find(function(a){return a.featureKey===b});if(!d)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b));var e=this.dataManager.storedTargetingData[a],f=this.variationConfiguration.getVariation({visitorCode:a,featureFlag:d,targetingData:e,withAssignment:!0,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw(),g=f.experimentId,h=f.variationId;return"number"==typeof h&&"number"==typeof g&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,visitorCode:a,experimentId:g,variationId:h}),_utilities.Utilities.trackFeatureExperiment({visitorCode:a,requester:this.requester,featureFlagVariation:f,dataManager:this.dataManager,isOfflineModeOn:this.isOfflineModeOn,offlineTrackingStorage:this.offlineTrackingStorage}),(0,_tsRes.Ok)(f)}}]),a}();exports.KameleoonClient=KameleoonClient;
19
2
  //# sourceMappingURL=kameleoonClient.js.map