@kameleoon/javascript-sdk-core 3.6.1 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/CHANGELOG.md +375 -0
  2. package/CHANGELOG_INTERNAL.md +3 -0
  3. package/dist/cacheManager/cacheManager.js +1 -1
  4. package/dist/cacheManager/cacheManager.js.map +1 -1
  5. package/dist/cacheManager/index.js +1 -1
  6. package/dist/clientConfiguration/clientConfiguration.d.ts +2 -3
  7. package/dist/clientConfiguration/clientConfiguration.js +1 -1
  8. package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
  9. package/dist/clientConfiguration/constants.js +1 -1
  10. package/dist/clientConfiguration/constants.js.map +1 -1
  11. package/dist/clientConfiguration/index.js +1 -1
  12. package/dist/clientConfiguration/types.d.ts +8 -9
  13. package/dist/clientConfiguration/types.js +1 -1
  14. package/dist/clientConfiguration/types.js.map +1 -1
  15. package/dist/clientSettings/clientSettings.js +1 -1
  16. package/dist/clientSettings/clientSettings.js.map +1 -1
  17. package/dist/clientSettings/index.js +1 -1
  18. package/dist/constants.d.ts +0 -8
  19. package/dist/constants.js +1 -1
  20. package/dist/constants.js.map +1 -1
  21. package/dist/eventSource/constants.js +1 -1
  22. package/dist/eventSource/constants.js.map +1 -1
  23. package/dist/eventSource/eventSource.d.ts +17 -0
  24. package/dist/eventSource/eventSource.js +2 -0
  25. package/dist/eventSource/eventSource.js.map +1 -0
  26. package/dist/eventSource/index.d.ts +2 -2
  27. package/dist/eventSource/index.js +1 -1
  28. package/dist/eventSource/index.js.map +1 -1
  29. package/dist/eventSource/types.d.ts +8 -19
  30. package/dist/eventSource/types.js.map +1 -1
  31. package/dist/hasher/hasher.js +1 -1
  32. package/dist/hasher/hasher.js.map +1 -1
  33. package/dist/hasher/index.js +1 -1
  34. package/dist/hasher/index.js.map +1 -1
  35. package/dist/index.d.ts +7 -6
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/kameleoonClient.d.ts +2 -207
  39. package/dist/kameleoonClient.js +1 -1
  40. package/dist/kameleoonClient.js.map +1 -1
  41. package/dist/kameleoonClientInterface.d.ts +199 -0
  42. package/dist/kameleoonClientInterface.js +2 -0
  43. package/dist/kameleoonClientInterface.js.map +1 -0
  44. package/dist/kameleoonData/applicationVersion.js +1 -1
  45. package/dist/kameleoonData/applicationVersion.js.map +1 -1
  46. package/dist/kameleoonData/browser.js +1 -1
  47. package/dist/kameleoonData/browser.js.map +1 -1
  48. package/dist/kameleoonData/constants.js +1 -1
  49. package/dist/kameleoonData/constants.js.map +1 -1
  50. package/dist/kameleoonData/conversion.js +1 -1
  51. package/dist/kameleoonData/conversion.js.map +1 -1
  52. package/dist/kameleoonData/cookie.js +1 -1
  53. package/dist/kameleoonData/cookie.js.map +1 -1
  54. package/dist/kameleoonData/customData.js +1 -1
  55. package/dist/kameleoonData/customData.js.map +1 -1
  56. package/dist/kameleoonData/dataManager.js +1 -1
  57. package/dist/kameleoonData/dataManager.js.map +1 -1
  58. package/dist/kameleoonData/dataProcessor.d.ts +2 -2
  59. package/dist/kameleoonData/dataProcessor.js +1 -1
  60. package/dist/kameleoonData/dataProcessor.js.map +1 -1
  61. package/dist/kameleoonData/device.js +1 -1
  62. package/dist/kameleoonData/device.js.map +1 -1
  63. package/dist/kameleoonData/geolocation.js +1 -1
  64. package/dist/kameleoonData/geolocation.js.map +1 -1
  65. package/dist/kameleoonData/helpers.js +1 -1
  66. package/dist/kameleoonData/helpers.js.map +1 -1
  67. package/dist/kameleoonData/index.js +1 -1
  68. package/dist/kameleoonData/operatingSystem.js +1 -1
  69. package/dist/kameleoonData/operatingSystem.js.map +1 -1
  70. package/dist/kameleoonData/pageView.js +1 -1
  71. package/dist/kameleoonData/pageView.js.map +1 -1
  72. package/dist/kameleoonData/types.d.ts +2 -2
  73. package/dist/kameleoonData/types.js +1 -1
  74. package/dist/kameleoonData/types.js.map +1 -1
  75. package/dist/kameleoonData/userAgent.js +1 -1
  76. package/dist/kameleoonData/userAgent.js.map +1 -1
  77. package/dist/kameleoonData/visitsData.js +1 -1
  78. package/dist/kameleoonData/visitsData.js.map +1 -1
  79. package/dist/kameleoonError/constants.d.ts +1 -1
  80. package/dist/kameleoonError/constants.js +1 -1
  81. package/dist/kameleoonError/constants.js.map +1 -1
  82. package/dist/kameleoonError/helpers.js.map +1 -1
  83. package/dist/kameleoonError/index.js +1 -1
  84. package/dist/kameleoonError/kameleoonError.js +1 -1
  85. package/dist/kameleoonError/kameleoonError.js.map +1 -1
  86. package/dist/kameleoonError/types.d.ts +1 -1
  87. package/dist/kameleoonError/types.js +1 -1
  88. package/dist/kameleoonError/types.js.map +1 -1
  89. package/dist/kameleoonUtils.js +1 -1
  90. package/dist/kameleoonUtils.js.map +1 -1
  91. package/dist/requester/constants.d.ts +1 -3
  92. package/dist/requester/constants.js +1 -1
  93. package/dist/requester/constants.js.map +1 -1
  94. package/dist/requester/index.d.ts +1 -1
  95. package/dist/requester/index.js +1 -1
  96. package/dist/requester/index.js.map +1 -1
  97. package/dist/requester/requester.d.ts +0 -3
  98. package/dist/requester/requester.js +1 -1
  99. package/dist/requester/requester.js.map +1 -1
  100. package/dist/requester/types.d.ts +11 -1
  101. package/dist/requester/types.js +1 -1
  102. package/dist/requester/types.js.map +1 -1
  103. package/dist/requester/urlProvider.d.ts +18 -0
  104. package/dist/requester/urlProvider.js +2 -0
  105. package/dist/requester/urlProvider.js.map +1 -0
  106. package/dist/storage/constants.js +1 -1
  107. package/dist/storage/constants.js.map +1 -1
  108. package/dist/storage/index.d.ts +2 -1
  109. package/dist/storage/index.js +1 -1
  110. package/dist/storage/index.js.map +1 -1
  111. package/dist/storage/storage.d.ts +13 -0
  112. package/dist/storage/storage.js +2 -0
  113. package/dist/storage/storage.js.map +1 -0
  114. package/dist/storage/types.d.ts +15 -30
  115. package/dist/storage/types.js.map +1 -1
  116. package/dist/targeting/conditions/applicationVersion.js +1 -1
  117. package/dist/targeting/conditions/applicationVersion.js.map +1 -1
  118. package/dist/targeting/conditions/browser.js +1 -1
  119. package/dist/targeting/conditions/browser.js.map +1 -1
  120. package/dist/targeting/conditions/conditionFactory.js +1 -1
  121. package/dist/targeting/conditions/conditionFactory.js.map +1 -1
  122. package/dist/targeting/conditions/conversion.js +1 -1
  123. package/dist/targeting/conditions/conversion.js.map +1 -1
  124. package/dist/targeting/conditions/cookie.js +1 -1
  125. package/dist/targeting/conditions/cookie.js.map +1 -1
  126. package/dist/targeting/conditions/customData.js +1 -1
  127. package/dist/targeting/conditions/customData.js.map +1 -1
  128. package/dist/targeting/conditions/device.js +1 -1
  129. package/dist/targeting/conditions/device.js.map +1 -1
  130. package/dist/targeting/conditions/exclusiveCampaign.js +1 -1
  131. package/dist/targeting/conditions/exclusiveCampaign.js.map +1 -1
  132. package/dist/targeting/conditions/firstVisit.js +1 -1
  133. package/dist/targeting/conditions/firstVisit.js.map +1 -1
  134. package/dist/targeting/conditions/geolocation.js +1 -1
  135. package/dist/targeting/conditions/geolocation.js.map +1 -1
  136. package/dist/targeting/conditions/index.js +1 -1
  137. package/dist/targeting/conditions/lastVisit.js +1 -1
  138. package/dist/targeting/conditions/lastVisit.js.map +1 -1
  139. package/dist/targeting/conditions/newVisitor.js +1 -1
  140. package/dist/targeting/conditions/newVisitor.js.map +1 -1
  141. package/dist/targeting/conditions/operatingSystem.js +1 -1
  142. package/dist/targeting/conditions/operatingSystem.js.map +1 -1
  143. package/dist/targeting/conditions/pageTitle.js +1 -1
  144. package/dist/targeting/conditions/pageTitle.js.map +1 -1
  145. package/dist/targeting/conditions/pageUrl.js +1 -1
  146. package/dist/targeting/conditions/pageUrl.js.map +1 -1
  147. package/dist/targeting/conditions/previousPage.js +1 -1
  148. package/dist/targeting/conditions/previousPage.js.map +1 -1
  149. package/dist/targeting/conditions/sameDayVisits.js +1 -1
  150. package/dist/targeting/conditions/sameDayVisits.js.map +1 -1
  151. package/dist/targeting/conditions/sdkLanguage.js +1 -1
  152. package/dist/targeting/conditions/sdkLanguage.js.map +1 -1
  153. package/dist/targeting/conditions/segment.js +1 -1
  154. package/dist/targeting/conditions/segment.js.map +1 -1
  155. package/dist/targeting/conditions/targetFeatureFlag.js +1 -1
  156. package/dist/targeting/conditions/targetFeatureFlag.js.map +1 -1
  157. package/dist/targeting/conditions/visitedPages.js +1 -1
  158. package/dist/targeting/conditions/visitedPages.js.map +1 -1
  159. package/dist/targeting/conditions/visitorCode.js +1 -1
  160. package/dist/targeting/conditions/visitorCode.js.map +1 -1
  161. package/dist/targeting/conditions/visits.js +1 -1
  162. package/dist/targeting/conditions/visits.js.map +1 -1
  163. package/dist/targeting/index.js +1 -1
  164. package/dist/targeting/node.js +1 -1
  165. package/dist/targeting/node.js.map +1 -1
  166. package/dist/targeting/tree.js +1 -1
  167. package/dist/targeting/tree.js.map +1 -1
  168. package/dist/targeting/types.js +1 -1
  169. package/dist/targeting/types.js.map +1 -1
  170. package/dist/types.d.ts +14 -26
  171. package/dist/types.js +1 -1
  172. package/dist/types.js.map +1 -1
  173. package/dist/utilities/constants.js +1 -1
  174. package/dist/utilities/constants.js.map +1 -1
  175. package/dist/utilities/index.js +1 -1
  176. package/dist/utilities/types.d.ts +7 -7
  177. package/dist/utilities/types.js +1 -1
  178. package/dist/utilities/types.js.map +1 -1
  179. package/dist/utilities/utilities.js +1 -1
  180. package/dist/utilities/utilities.js.map +1 -1
  181. package/dist/variationConfiguration/index.js +1 -1
  182. package/dist/variationConfiguration/variationConfiguration.d.ts +3 -3
  183. package/dist/variationConfiguration/variationConfiguration.js +1 -1
  184. package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
  185. package/dist/visitorCodeManager/constants.d.ts +3 -0
  186. package/dist/visitorCodeManager/constants.js +2 -0
  187. package/dist/visitorCodeManager/constants.js.map +1 -0
  188. package/dist/visitorCodeManager/index.d.ts +2 -0
  189. package/dist/visitorCodeManager/index.js +1 -1
  190. package/dist/visitorCodeManager/index.js.map +1 -1
  191. package/dist/visitorCodeManager/types.d.ts +7 -0
  192. package/dist/visitorCodeManager/types.js +2 -0
  193. package/dist/visitorCodeManager/types.js.map +1 -0
  194. package/dist/visitorCodeManager/visitorCodeManager.d.ts +11 -8
  195. package/dist/visitorCodeManager/visitorCodeManager.js +1 -1
  196. package/dist/visitorCodeManager/visitorCodeManager.js.map +1 -1
  197. package/package.json +5 -5
  198. package/dist/eventSource/externalEventSource.d.ts +0 -12
  199. package/dist/eventSource/externalEventSource.js +0 -2
  200. package/dist/eventSource/externalEventSource.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,375 @@
1
+ # Change Log
2
+
3
+ ## 4.0.1 (2024-02-21)
4
+
5
+ ### Patch Changes
6
+
7
+ - Added support for additional Data API servers across the world for even faster network requests
8
+
9
+ ## 4.0.0 (2024-02-16)
10
+
11
+ ### Breaking Changes
12
+
13
+ - Previously deprecated `KameleoonUtils.getVisitorCode()` was removed
14
+
15
+ ### Features
16
+
17
+ Added [External Dependencies](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#external-dependencies) capabilities
18
+
19
+ ## 3.6.1 (2024-02-07)
20
+
21
+ ### Bug fixes
22
+
23
+ - Tracking wasn't sent if consent is required
24
+
25
+ ## 3.6.0 (2024-02-01)
26
+
27
+ ### Features
28
+
29
+ - Add environment support to `getClientConfigurationUrl`
30
+
31
+ ## 3.5.0 (2024-01-18)
32
+
33
+ ### Bug fixes
34
+
35
+ - SDK threw an error reading storage when migrating from older SDK versions
36
+ - React Native SDK visitor code couldn't be read from storage in certain React Native versions
37
+ - React SDK request headers caused CORS errors
38
+
39
+ ### Features
40
+
41
+ - Added new SDK `configuration` parameter [`requestTimeout`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#1-initializing-the-kameleoon-client), which defines maximum time in _milliseconds_ after which any SDK network request will fail
42
+
43
+ ## 3.4.1 (2023-12-15)
44
+
45
+ ### Bug fixes
46
+
47
+ - Fix nonce for `Conversion` data
48
+
49
+ ## 3.4.0 (2023-12-12)
50
+
51
+ ### Features
52
+
53
+ - Updated the `getFeatureFlagVariable` method to return an object of type `FeatureFlagVariableType`
54
+ - Enhanced the `getFeatureFlagVariables` method to include the `key` field in its return value.
55
+
56
+ ### Bug fixes
57
+
58
+ - Custom Data mapping identifier wasn't tracked correctly
59
+
60
+ ## 3.3.0 (2023-12-11)
61
+
62
+ ### Features
63
+
64
+ - [flush](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#flush) and [trackConversion](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#trackConversion) methods now have a new optional parameter `isUniqueIdentifier` used for extra [Kameleoon Cross-device Experimentation](https://developers.kameleoon.com/core-concepts/cross-device-experimentation) capabilities
65
+ - [getVisitorCode](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getvisitorcode) and [setLegalConsent](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#setlegalconsent) methods now have an overload allowing methods to be used without parameters (instead of providing and empty object `{}`)
66
+
67
+ ### Bug fixes
68
+
69
+ - Targeting data cleanup caused `TypeError`
70
+
71
+ ## 3.2.1 (2023-12-04)
72
+
73
+ ### Bug fixes
74
+
75
+ - Client cookie is now set properly
76
+
77
+ ## 3.2.0 (2023-11-30)
78
+
79
+ ### Features
80
+
81
+ - [CustomData session merging](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#using-custom-data-for-session-merging) abilities for [Kameleoon Cross-device Experimentation](https://developers.kameleoon.com/core-concepts/cross-device-experimentation)
82
+
83
+ ## 3.1.0 (2023-11-24)
84
+
85
+ ### Features
86
+
87
+ - Added `setLegalConsent` method to determine the types data Kameleoon includes in tracking requests. This helps you adhere to legal and regulatory requirements while responsibly managing visitor data. You can find more information in the [Consent management policy](https://help.kameleoon.com/consent-management-policy).
88
+
89
+ ## 3.0.0 (2023-11-16)
90
+
91
+ ### Breaking change
92
+
93
+ - SDK stopped the support of the following methods were:
94
+ - `getExperiments`
95
+ - `getVisitorExperiments`
96
+ - `triggerExperiment`
97
+ - Previously deprecated `flushData` method was removed
98
+ - [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getremotevisitordata) method parameters were changed to an object with type [`RemoteVisitorDataParamsType`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#parameters-11) that has a new `filters` field
99
+
100
+ ### Features
101
+
102
+ - New method for retrieving multiple feature flag variables - [`getFeatureFlagVariables`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getfeatureflagvariables)
103
+ - [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getremotevisitordata) is now capable of retrieving information from up to 25 visits along with some additional visit information configured by new `filters` field
104
+ - [`PageView`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#pageview) data items are now stored by unique URL with timestamps of visits - each visitor can have several `PageView` URLs stored
105
+ - [`Conversion`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#conversion) data items are now stored as a list of conversion for each visitor
106
+ - [Cross Device Synchronization](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#synchronizing-custom-data-across-devices) was improved - [`CustomData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#customdata) with `Visitor` scope is always re-sent with tracking calls allowing seamless synchronization using [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getremotevisitordata)
107
+ - [New targeting conditions](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#list-of-supported-targeting-conditions) are now available (some of them may require [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getremotevisitordata) pre-loaded data)
108
+ - `Browser Cookie`
109
+ - `Application Version`
110
+ - `Operating System`
111
+ - `IP Geolocation`
112
+ - `Segment`
113
+ - `Target Feature Flag`
114
+ - `Previous Page`
115
+ - `Number of Page Views`
116
+ - `Time since First Visit`
117
+ - `Time since Last Visit`
118
+ - `Number of Visits Today`
119
+ - `Total Number of Visits`
120
+ - `New or Returning Visitor`
121
+ - New Kameleoon Data types were introduced:
122
+ - [`ApplicationVersion`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#applicationversion)
123
+ - [`Cookie`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#cookie)
124
+ - [`OperatingSystem`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#operatingsystem)
125
+ - [`GeolocationData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#geolocationdata)
126
+
127
+ ### Bug fixes
128
+
129
+ - `SDKParameters` type is now correctly exported from SDK
130
+ - SDK Polling re-tries mechanism was optimized - SDK will now try to obtain configuration again during the next poll after 3 failed configuration loading attempts
131
+ - [`onConfigurationUpdate`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#onconfigurationupdate) callback now fires on successful configuration update in storage (previously fired after network configuration retrieval)
132
+
133
+ ## 2.10.1 (2023-10-20)
134
+
135
+ ### Bug fixes
136
+
137
+ - Fix previous version deploy issue
138
+
139
+ ## 2.10.0 (2023-10-20)
140
+
141
+ ### Features
142
+
143
+ - Added new method [`getVisitorWarehouseAudience`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#getvisitorwarehouseaudience)
144
+
145
+ ## 2.9.1 (2023-10-11)
146
+
147
+ ### Bug fixes
148
+
149
+ - Storage data parse overhead optimization
150
+
151
+ ## 2.9.0 (2023-09-25)
152
+
153
+ ### Features
154
+
155
+ - Added `getClientConfigurationUrl` utility
156
+
157
+ ## 2.8.3 (2023-09-05)
158
+
159
+ ### Bug fixes
160
+
161
+ - `UserAgent` was not exported from SDK
162
+
163
+ ## 2.8.2 (2023-08-31)
164
+
165
+ ### Bug fixes
166
+
167
+ - `Custom Data Condition` now handles index `0` properly
168
+
169
+ ## 2.8.1 (2023-08-25)
170
+
171
+ ### Bug fixes
172
+
173
+ - Multiple `Real Time Update` connections are no longer created
174
+ - `Custom Data Condition` now handles all exceptions properly
175
+
176
+ ## 2.8.0 (2023-08-11)
177
+
178
+ ### Bug fixes
179
+
180
+ - Empty Custom Data is now sending activity tracking event
181
+
182
+ ### Features
183
+
184
+ - Added [Tracking requests rate limit](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/nodejs-sdk#tracking-rate-limit) capabilities
185
+ - Added [Cross Device Custom Data Synchronization](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#cross-device-custom-data-synchronization) capabilities
186
+
187
+ ## 2.7.1 (2023-07-26)
188
+
189
+ ### Bug fixes
190
+
191
+ - [`flush`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#flush) now sends offline tracking requests even if there's no new data to track.
192
+ - Timestamps for offline requests are set correctly.
193
+
194
+ ## 2.7.0 (2023-07-21)
195
+
196
+ ### Features
197
+
198
+ - `flushData` has been deprecated in favor of [`flush`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#flush).
199
+ - [`flush`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#flush) sends failed tracking requests that were stored locally during the offline mode at first and then proceeds with the latest request.
200
+
201
+ ## 2.6.0 (2023-07-17)
202
+
203
+ ### Bug fixes
204
+
205
+ - Typescript `.d.ts` files have proper relative path resolution.
206
+ - Unused tracking parameters are no longer sent.
207
+ - Real-time update events now get the latest configuration.
208
+
209
+ ### Features
210
+
211
+ - When the client is initialized in offline mode, in case of network issues failed tracking requests made by [`flushData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#flushdata), [`trackConversion`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#trackconversion), [`triggerExperiment`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#triggerexperiment), [`getFeatureFlagVariationKey`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#getfeatureflagvariationkey) or [`getFeatureFlagVariable`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#getfeatureflagvariable) will be sent anew once the client is back online.
212
+ - Minor optimization for checking [targeting conditions](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#list-of-supported-targeting-conditions) of a segment.
213
+
214
+ ## 2.5.1 (2023-06-30)
215
+
216
+ ### Bug fixes
217
+
218
+ - tracking data duplications
219
+
220
+ ## 2.5.0 (2023-06-28)
221
+
222
+ ### Bug fixes
223
+
224
+ - Improve error handling for [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#obtain-custom-data-from-kameleoon-data-api)
225
+ - Visitor code is now validated correctly in every method that uses it.
226
+ - Result bundle is now compatible with systems not using `ESM` and `CommonJS`. It's minimized and uses code splitting for `crypto-js` `sha256` function.
227
+ - Parameter `revenue` for [`Conversion`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#conversion) is now optional.
228
+ - Each visitor can now only have one type of associated [`Kameleoon Data Type`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#data-types), except for [`CustomData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#customdata), that a visitor can have one per `customDataIndex`.
229
+
230
+ ### Features
231
+
232
+ - New conditions are now supported: `Device`, `Browser`, `SDKLanguage`, `Page Title`, `Page View`, `Visitor Code`, `Conversion`. See the [full list of supported conditions](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#list-of-supported-targeting-conditions).
233
+ - [`Browser`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#browser) now has new optional parameter `version`.
234
+ - [`flushData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#flush-tracking-data) `visitorCode` parameter is now optional.
235
+ - Custom data that is marked as `local only` on Kameleoon Platform is now only used for targeting (not flushed with tracking requests).
236
+ - JavaScript SDK is now available as a single file from the static server, see the [details](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#installation)
237
+
238
+ ## 2.4.6 (2023-06-02)
239
+
240
+ ### Bug fixes
241
+
242
+ - Custom data true/false match type should work when condition value is `null`
243
+
244
+ ## 2.4.5 (2023-06-01)
245
+
246
+ ### Bug fixes
247
+
248
+ - Empty visitor code is no more allowed
249
+ - Incorrect tracking body upon triggering an experiment
250
+
251
+ ## 2.4.4 (2023-05-31)
252
+
253
+ ### Bug fixes
254
+
255
+ - Improve targeting data cleanup interval handling
256
+
257
+ ## 2.4.3 (2023-05-24)
258
+
259
+ ### Bug fixes
260
+
261
+ - Fixed issue for sending unique `Nonce` parameter on tracking requests
262
+
263
+ ## 2.4.2 (2023-05-21)
264
+
265
+ ### Bug fixes
266
+
267
+ - [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#obtain-custom-data-from-kameleoon-data-api) current visits not being up-to-date
268
+
269
+ ## 2.4.1 (2023-05-20)
270
+
271
+ ### Bug fixes
272
+
273
+ - [`getRemoteVisitorData`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#obtain-custom-data-from-kameleoon-data-api) data parse error
274
+
275
+ ## 2.4.0 (2023-05-19)
276
+
277
+ ### Bug fixes
278
+
279
+ - more meaningful URL names for requester
280
+ - `updateInterval` was set to 30 minutes instead of 60 in some places
281
+
282
+ ### Features
283
+
284
+ - New method `getRemoteVisitorData`
285
+ - New offline mode for `initialize` method
286
+
287
+ ## 2.3.0 (2023-04-28)
288
+
289
+ ### Bug fixes
290
+
291
+ - Unused optional chaining operator in `KameleoonUtils` was removed
292
+ - Experiments methods no more persist assigned variations
293
+
294
+ ### Features
295
+
296
+ - Added retries for client initialization
297
+
298
+ ## 2.2.1 (2023-04-24)
299
+
300
+ ### Bug fixes
301
+
302
+ - Tracking feature flag rule with variation `off` wasn't displayed on result page
303
+
304
+ ## 2.2.0 (2023-04-21)
305
+
306
+ ### Features
307
+
308
+ - `getEngineTrackingCode` method is now public
309
+
310
+ ## 2.1.1 (2023-04-18)
311
+
312
+ ### Bug fixes
313
+
314
+ - visitor code cookie header
315
+
316
+ ## 2.1.0 (2023-04-14)
317
+
318
+ ### Bug fixes
319
+
320
+ - variation calculation logic
321
+ - remove sdk true parameter
322
+ - test regexp
323
+
324
+ ### Features
325
+
326
+ - targeting cleanup interval
327
+ - get experiment variation data
328
+ - get engine tracking code
329
+ - api-ssx migration
330
+ - tracking requests and conditions
331
+
332
+ ## 2.0.0 (2023-04-05)
333
+
334
+ ### Bug fixes
335
+
336
+ - use correct top level domain for data
337
+ - remove kameleoon client headers
338
+
339
+ ### Features
340
+
341
+ - integration of compute edge
342
+ - api-ssx migration
343
+ - tracking requests and conditions
344
+
345
+ ## 1.1.1 (2023-03-24)
346
+
347
+ ### Bug fixes
348
+
349
+ - change broken dependency
350
+
351
+ ## 1.1.0 (2023-03-22)
352
+
353
+ ### Features
354
+
355
+ - License changed from `GPL3.0` to `ISC`
356
+
357
+ ## 1.0.0 (2023-03-21)
358
+
359
+ ### Bug fixes
360
+
361
+ - remove xhr
362
+
363
+ ### Features
364
+
365
+ - add feature flags v2
366
+
367
+ ## 0.0.2 (2022-11-01)
368
+
369
+ ### Bug fixes
370
+
371
+ - remove boolean case condition
372
+
373
+ ## 0.0.1 (2022-10-13)
374
+
375
+ ### Initial release
@@ -0,0 +1,3 @@
1
+ # Internal Change Log
2
+
3
+ All significant internal changes to this project will be documented in this file.
@@ -1,2 +1,2 @@
1
- "use strict";var _types=require("../types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheManager=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f,g,h=[],i=!0,j=!1;try{if(f=(c=c.call(a)).next,0===b){if(Object(c)!==c)return;i=!1}else for(;!(i=(d=f.call(c)).done)&&(h.push(d.value),h.length!==b);i=!0);}catch(a){j=!0,e=a}finally{try{if(!i&&null!=c.return&&(g=c.return(),Object(g)!==g))return}finally{if(j)throw e}}return h}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _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 CacheManager=function(){function a(b){_classCallCheck(this,a),_defineProperty(this,"cacheMap",new Map),_defineProperty(this,"intervalId",null),_defineProperty(this,"cleanupTimeout",void 0),this.cleanupTimeout=b*_types.Milliseconds.Second}return _createClass(a,[{key:"add",value:function add(a){var b=a.key,c=a.data,d=a.lifetime;null===this.intervalId&&this.activate();var e=d*_types.Milliseconds.Second,f={data:c,expirationTime:Date.now()+e};this.cacheMap.set(b,f)}},{key:"getAliveItem",value:function getAliveItem(a){var b=this.cacheMap.get(a);return b&&b.expirationTime>=Date.now()?b.data:(b&&this.cacheMap.delete(a),null)}},{key:"activate",value:function activate(){var a=this;this.intervalId=setInterval(function(){var b,c=Date.now(),d=_createForOfIteratorHelper(a.cacheMap);try{for(d.s();!(b=d.n()).done;){var e=_slicedToArray(b.value,2),f=e[0],g=e[1];g.expirationTime<c&&a.cacheMap.delete(f)}}catch(a){d.e(a)}finally{d.f()}a.cacheMap.size||a.cleanupInterval()},this.cleanupTimeout)}},{key:"cleanupInterval",value:function cleanupInterval(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null)}}]),a}();exports.CacheManager=CacheManager;
1
+ "use strict";var _types=require("../types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.CacheManager=void 0;function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class CacheManager{constructor(a){_defineProperty(this,"cacheMap",new Map),_defineProperty(this,"intervalId",null),_defineProperty(this,"cleanupTimeout",void 0),this.cleanupTimeout=a*_types.Milliseconds.Second}add(a){let{key:b,data:c,lifetime:d}=a;null===this.intervalId&&this.activate();const e=d*_types.Milliseconds.Second,f={data:c,expirationTime:Date.now()+e};this.cacheMap.set(b,f)}getAliveItem(a){const b=this.cacheMap.get(a);return b&&b.expirationTime>=Date.now()?b.data:(b&&this.cacheMap.delete(a),null)}activate(){this.intervalId=setInterval(()=>{const a=Date.now();for(const[b,c]of this.cacheMap)c.expirationTime<a&&this.cacheMap.delete(b);this.cacheMap.size||this.cleanupInterval()},this.cleanupTimeout)}cleanupInterval(){this.intervalId&&(clearInterval(this.intervalId),this.intervalId=null)}}exports.CacheManager=CacheManager;
2
2
  //# sourceMappingURL=cacheManager.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cacheManager.js","names":["_types","require","Object","defineProperty","exports","value","CacheManager","_typeof","a","Symbol","iterator","constructor","prototype","_slicedToArray","b","_arrayWithHoles","_iterableToArrayLimit","_unsupportedIterableToArray","_nonIterableRest","TypeError","c","d","e","f","g","h","i","j","call","next","done","push","length","return","Array","isArray","_createForOfIteratorHelper","s","n","_arrayLikeToArray","toString","slice","name","from","test","_classCallCheck","_defineProperties","enumerable","configurable","writable","_toPropertyKey","key","_createClass","_defineProperty","_toPrimitive","toPrimitive","String","Number","cleanupTimeout","Map","Milliseconds","Second","add","data","lifetime","intervalId","activate","expirationTime","cacheItem","Date","now","cacheMap","set","getAliveItem","get","delete","setInterval","item","size","cleanupInterval","clearInterval"],"sources":["../../src/cacheManager/cacheManager.ts"],"sourcesContent":["import { Milliseconds } from 'src/types';\nimport { AddParametersType, CacheItemType } from './types';\n\ninterface ICacheManager<T> {\n /**\n * Add item to cache\n * @param {AddParametersType<T>} parameters - parameters for adding new item cache\n * @returns {void}\n */\n add({ key, data, lifetime }: AddParametersType<T>): void;\n /**\n * Get item that is not expired from cache\n * @param {string} key - key of item\n * @returns {T} an item that is not expired\n */\n getAliveItem(key: string): T | null;\n}\n\n/**\n * @class\n * CacheManager - a class for managing cache\n */\nexport class CacheManager<T> implements ICacheManager<T> {\n private cacheMap = new Map<string, CacheItemType<T>>();\n private intervalId: NodeJS.Timeout | null = null;\n private cleanupTimeout: number;\n\n /**\n * @param {number} cleanupTimeout - timeout for cleaning cache in seconds\n * generic type `T` is a type of data that will be stored in cache\n * @example\n * ```typescript\n * const cacheManager = new CacheManager<number>(60);\n * ```\n */\n constructor(cleanupTimeout: number) {\n this.cleanupTimeout = cleanupTimeout * Milliseconds.Second;\n }\n\n public add({ key, data, lifetime }: AddParametersType<T>): void {\n if (this.intervalId === null) {\n this.activate();\n }\n\n const expirationTime = lifetime * Milliseconds.Second;\n\n const cacheItem: CacheItemType<T> = {\n data,\n expirationTime: Date.now() + expirationTime,\n };\n\n this.cacheMap.set(key, cacheItem);\n }\n\n public getAliveItem(key: string): T | null {\n const cacheItem = this.cacheMap.get(key);\n\n if (cacheItem && cacheItem.expirationTime >= Date.now()) {\n return cacheItem.data;\n }\n\n cacheItem && this.cacheMap.delete(key);\n\n return null;\n }\n\n private activate(): void {\n this.intervalId = setInterval(() => {\n const now = Date.now();\n\n for (const [key, item] of this.cacheMap) {\n if (item.expirationTime < now) {\n this.cacheMap.delete(key);\n }\n }\n\n if (!this.cacheMap.size) {\n this.cleanupInterval();\n }\n }, this.cleanupTimeout);\n }\n\n private cleanupInterval(): void {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,aAAyCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,YAAA,iBAAAC,QAAAC,CAAA,mCAAAD,OAAA,oBAAAE,MAAA,mBAAAA,MAAA,CAAAC,QAAA,UAAAF,CAAA,gBAAAA,CAAA,WAAAA,CAAA,SAAAA,CAAA,qBAAAC,MAAA,EAAAD,CAAA,CAAAG,WAAA,GAAAF,MAAA,EAAAD,CAAA,GAAAC,MAAA,CAAAG,SAAA,iBAAAJ,CAAA,EAAAD,OAAA,CAAAC,CAAA,WAAAK,eAAAL,CAAA,CAAAM,CAAA,SAAAC,eAAA,CAAAP,CAAA,GAAAQ,qBAAA,CAAAR,CAAA,CAAAM,CAAA,GAAAG,2BAAA,CAAAT,CAAA,CAAAM,CAAA,GAAAI,gBAAA,YAAAA,iBAAA,YAAAC,SAAA,uJAAAH,sBAAAR,CAAA,CAAAM,CAAA,MAAAM,CAAA,OAAAZ,CAAA,0BAAAC,MAAA,EAAAD,CAAA,CAAAC,MAAA,CAAAC,QAAA,GAAAF,CAAA,wBAAAY,CAAA,MAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,IAAAC,CAAA,IAAAC,CAAA,WAAAJ,CAAA,EAAAH,CAAA,CAAAA,CAAA,CAAAQ,IAAA,CAAApB,CAAA,GAAAqB,IAAA,KAAAf,CAAA,KAAAZ,MAAA,CAAAkB,CAAA,IAAAA,CAAA,QAAAM,CAAA,gBAAAA,CAAA,EAAAL,CAAA,CAAAE,CAAA,CAAAK,IAAA,CAAAR,CAAA,GAAAU,IAAA,IAAAL,CAAA,CAAAM,IAAA,CAAAV,CAAA,CAAAhB,KAAA,EAAAoB,C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,CAAAe,0BAAA,CAEI5B,CAAI,CAAC+D,QAAQ,MAAvC,IAAAlD,CAAA,CAAAgB,CAAA,KAAAvB,CAAA,CAAAO,CAAA,CAAAiB,CAAA,IAAAR,IAAA,EAAyC,KAAAR,CAAA,CAAAT,cAAA,CAAAC,CAAA,CAAAT,KAAA,IAA7B8C,CAAG,CAAA7B,CAAA,IAAEuD,CAAI,CAAAvD,CAAA,IACfuD,CAAI,CAACV,cAAc,CAAGG,CAAG,EAC3B9D,CAAI,CAAC+D,QAAQ,CAACI,MAAM,CAACxB,CAAG,CAE5B,CAAC,OAAA3C,CAAA,EAAAa,CAAA,CAAAC,CAAA,CAAAd,CAAA,UAAAa,CAAA,CAAAE,CAAA,GAEIf,CAAI,CAAC+D,QAAQ,CAACO,IAAI,EACrBtE,CAAI,CAACuE,eAAe,EAExB,CAAC,CAAE,IAAI,CAACrB,cAAc,CACxB,CAAC,GAAAP,GAAA,mBAAA9C,KAAA,CAED,SAAA0E,gBAAA,CAAgC,CAC1B,IAAI,CAACd,UAAU,GACjBe,aAAa,CAAC,IAAI,CAACf,UAAU,CAAC,CAC9B,IAAI,CAACA,UAAU,CAAG,IAAI,CAE1B,CAAC,IAAAzD,CAAA,IAAAJ,OAAA,CAAAE,YAAA,CAAAA,YAAA"}
1
+ {"version":3,"file":"cacheManager.js","names":["_types","require","Object","defineProperty","exports","value","CacheManager","_defineProperty","a","b","c","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","d","call","TypeError","String","Number","constructor","cleanupTimeout","Map","Milliseconds","Second","add","key","data","lifetime","intervalId","activate","expirationTime","cacheItem","Date","now","cacheMap","set","getAliveItem","get","delete","setInterval","item","size","cleanupInterval","clearInterval"],"sources":["../../src/cacheManager/cacheManager.ts"],"sourcesContent":["import { Milliseconds } from 'src/types';\nimport { AddParametersType, CacheItemType } from './types';\n\ninterface ICacheManager<T> {\n /**\n * Add item to cache\n * @param {AddParametersType<T>} parameters - parameters for adding new item cache\n * @returns {void}\n */\n add({ key, data, lifetime }: AddParametersType<T>): void;\n /**\n * Get item that is not expired from cache\n * @param {string} key - key of item\n * @returns {T} an item that is not expired\n */\n getAliveItem(key: string): T | null;\n}\n\n/**\n * @class\n * CacheManager - a class for managing cache\n */\nexport class CacheManager<T> implements ICacheManager<T> {\n private cacheMap = new Map<string, CacheItemType<T>>();\n private intervalId: NodeJS.Timeout | null = null;\n private cleanupTimeout: number;\n\n /**\n * @param {number} cleanupTimeout - timeout for cleaning cache in seconds\n * generic type `T` is a type of data that will be stored in cache\n * @example\n * ```typescript\n * const cacheManager = new CacheManager<number>(60);\n * ```\n */\n constructor(cleanupTimeout: number) {\n this.cleanupTimeout = cleanupTimeout * Milliseconds.Second;\n }\n\n public add({ key, data, lifetime }: AddParametersType<T>): void {\n if (this.intervalId === null) {\n this.activate();\n }\n\n const expirationTime = lifetime * Milliseconds.Second;\n\n const cacheItem: CacheItemType<T> = {\n data,\n expirationTime: Date.now() + expirationTime,\n };\n\n this.cacheMap.set(key, cacheItem);\n }\n\n public getAliveItem(key: string): T | null {\n const cacheItem = this.cacheMap.get(key);\n\n if (cacheItem && cacheItem.expirationTime >= Date.now()) {\n return cacheItem.data;\n }\n\n cacheItem && this.cacheMap.delete(key);\n\n return null;\n }\n\n private activate(): void {\n this.intervalId = setInterval(() => {\n const now = Date.now();\n\n for (const [key, item] of this.cacheMap) {\n if (item.expirationTime < now) {\n this.cacheMap.delete(key);\n }\n }\n\n if (!this.cacheMap.size) {\n this.cleanupInterval();\n }\n }, this.cleanupTimeout);\n }\n\n private cleanupInterval(): void {\n if (this.intervalId) {\n clearInterval(this.intervalId);\n this.intervalId = null;\n }\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,aAAyCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,YAAA,iBAAAC,gBAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,SAAAD,CAAA,CAAAE,c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B,CAAC,CAED,IAAI,CAACI,QAAQ,CAACC,GAAG,CAACV,CAAG,CAAEM,CAAS,CAClC,CAEOK,YAAYA,CAACX,CAAW,CAAY,CACzC,KAAM,CAAAM,CAAS,CAAG,IAAI,CAACG,QAAQ,CAACG,GAAG,CAACZ,CAAG,CAAC,CAAC,MAErC,CAAAM,CAAS,EAAIA,CAAS,CAACD,cAAc,EAAIE,IAAI,CAACC,GAAG,CAAC,CAAC,CAC9CF,CAAS,CAACL,IAAI,EAGvBK,CAAS,EAAI,IAAI,CAACG,QAAQ,CAACI,MAAM,CAACb,CAAG,CAAC,CAE/B,IAAI,CACb,CAEQI,QAAQA,CAAA,CAAS,CACvB,IAAI,CAACD,UAAU,CAAGW,WAAW,CAAC,IAAM,CAClC,KAAM,CAAAN,CAAG,CAAGD,IAAI,CAACC,GAAG,CAAC,CAAC,CAEtB,IAAK,KAAM,CAACR,CAAG,CAAEe,CAAI,CAAC,EAAI,KAAI,CAACN,QAAQ,CACjCM,CAAI,CAACV,cAAc,CAAGG,CAAG,EAC3B,IAAI,CAACC,QAAQ,CAACI,MAAM,CAACb,CAAG,CAAC,CAIxB,IAAI,CAACS,QAAQ,CAACO,IAAI,EACrB,IAAI,CAACC,eAAe,CAAC,CAEzB,CAAC,CAAE,IAAI,CAACtB,cAAc,CACxB,CAEQsB,eAAeA,CAAA,CAAS,CAC1B,IAAI,CAACd,UAAU,GACjBe,aAAa,CAAC,IAAI,CAACf,UAAU,CAAC,CAC9B,IAAI,CAACA,UAAU,CAAG,IAAI,CAE1B,CACF,CAAC5B,OAAA,CAAAE,YAAA,CAAAA,YAAA"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"AddParametersType",{enumerable:!0,get:function get(){return _types.AddParametersType}}),Object.defineProperty(exports,"CacheManager",{enumerable:!0,get:function get(){return _cacheManager.CacheManager}});var _cacheManager=require("./cacheManager"),_types=require("./types");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"AddParametersType",{enumerable:!0,get:function(){return _types.AddParametersType}}),Object.defineProperty(exports,"CacheManager",{enumerable:!0,get:function(){return _cacheManager.CacheManager}});var _cacheManager=require("./cacheManager"),_types=require("./types");
2
2
  //# sourceMappingURL=index.js.map
@@ -20,13 +20,12 @@ export declare class ClientConfiguration implements IClientConfiguration {
20
20
  private storage;
21
21
  private offlineTrackingStorage;
22
22
  private requester;
23
- private eventSource?;
24
- private externalEventSource;
23
+ private eventSource;
25
24
  private externalClientConfiguration?;
26
25
  private mappedRules;
27
26
  private dataManager;
28
27
  private visitorCodeManager;
29
- constructor({ settings, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, externalEventSource, externalVisitorCodeManager, }: ClientConfigurationParametersType);
28
+ constructor({ settings, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, eventSource, externalVisitorCodeManager, }: ClientConfigurationParametersType);
30
29
  initialize(): Promise<Result<void, KameleoonError>>;
31
30
  private cleanupHandlers;
32
31
  private handleExternalUpdates;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_eventSource=require("../eventSource"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _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 ClientConfiguration=function(){function a(b){var c=b.settings,d=b.storage,e=b.requester,f=b.dataManager,g=b.externalClientConfiguration,h=b.offlineTrackingStorage,i=b.externalEventSource,j=b.externalVisitorCodeManager;_classCallCheck(this,a),_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalEventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",new Map),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),this.requester=e,this.settings=c,this.lastUpdate=new Date,this.storage=d,this.dataManager=f,this.externalClientConfiguration=g,this.offlineTrackingStorage=h,this.externalEventSource=i,this.visitorCodeManager=j}return _createClass(a,[{key:"initialize",value:function(){function a(){return b.apply(this,arguments)}var b=_asyncToGenerator(_regeneratorRuntime().mark(function a(){var b,c,d,e;return _regeneratorRuntime().wrap(function f(a){for(;1;)switch(a.prev=a.next){case 0:if(this.readStorageData(),b=!!this.externalClientConfiguration,c=this.checkShouldUpdate(b),!c){a.next=12;break}return a.next=6,this.updateClientConfiguration();case 6:if(d=a.sent,d.ok){a.next=9;break}return a.abrupt("return",d);case 9:if(e=d.data,!e){a.next=12;break}return a.abrupt("return",(0,_tsRes.Ok)());case 12:if(!b){a.next=15;break}return this.handleExternalUpdates(),a.abrupt("return",(0,_tsRes.Ok)());case 15:if(this.updateType!==_types.UpdateType.RealTime||this.eventSource){a.next=19;break}return this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),a.abrupt("return",(0,_tsRes.Ok)());case 19:return this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),a.abrupt("return",(0,_tsRes.Ok)());case 21:case"end":return a.stop();}},a,this)}));return a}()},{key:"cleanupHandlers",value:function cleanupHandlers(){this.eventSource&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}},{key:"handleExternalUpdates",value:function handleExternalUpdates(){this.cleanupHandlers(),this.configurationData=this.externalClientConfiguration}},{key:"handleRealTimeUpdates",value:function handleRealTimeUpdates(){var a=this;this.cleanupHandlers(),this.eventSource=new _eventSource.ExternalEventSource(this.settings.siteCode,this.externalEventSource);var b=function updateEventCallback(b){a.updateClientConfiguration(b).then(function(b){b.ok&&a.configurationUpdateCallback&&a.configurationUpdateCallback()})};this.eventSource.open(b)}},{key:"handlePollingUpdates",value:function handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.settings.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}},{key:"onConfigurationUpdate",value:function onConfigurationUpdate(a){this.configurationUpdateCallback=a}},{key:"featureFlags",get:function get(){return this.configurationData.featureFlags}},{key:"configuration",get:function get(){return this.configurationData.configuration}},{key:"segments",get:function get(){var a=new Map;return this.featureFlags.forEach(function(b){b.rules.forEach(function(b){b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),a}},{key:"ruleMap",get:function get(){if(this.mappedRules.size)return this.mappedRules;var a,b=new Map,c=_createForOfIteratorHelper(this.featureFlags);try{for(c.s();!(a=c.n()).done;){var d,e=a.value,f=_createForOfIteratorHelper(e.rules);try{var g=function _loop(){var a=d.value,c=a.id,f=a.experimentId,g=a.variationByExposition,h=new Map;g.forEach(function(a){var b=a.variationKey,c=a.variationId;"number"==typeof c&&h.set(b,c)}),b.set(c,{featureId:e.id,experimentId:f,variations:h})};for(f.s();!(d=f.n()).done;)g()}catch(a){f.e(a)}finally{f.f()}}}catch(a){c.e(a)}finally{c.f()}return this.mappedRules=b,b}},{key:"isConsentRequired",get:function get(){return this.configuration.consentType===_types.ConsentType.Required}},{key:"hasAnyTargetedDeliveryRule",get:function get(){return this.featureFlags.some(function(a){return a.environmentEnabled&&a.rules.some(function(a){return a.type===_types.RuleType.TARGETED_DELIVERY})})}},{key:"checkIntegrity",value:function checkIntegrity(a){if(!a)return!1;var b=Object.keys(a);if(!b.length)return!1;var c=Object.keys(_constants.DEFAULT_CONFIGURATION_DATA);return b.sort().join()===c.sort().join()}},{key:"checkShouldUpdate",value:function checkShouldUpdate(){var a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0],b=this.configurationData,c=b.featureFlags,d=b.configuration,e=this.settings.updateInterval;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=d.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!c.length)return!0;var f=this.lastUpdate.getTime(),g=Date.now()-e;return f<g}},{key:"readStorageData",value:function readStorageData(){var a=this.storage.read();if(a.ok){var b=a.data,c=b.data,d=b.lastUpdate,e=this.checkIntegrity(c);e?(this.configurationData=c,this.lastUpdate=new Date(Date.parse(d))):(this.storage.write({data:_constants.DEFAULT_CONFIGURATION_DATA,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA)}}},{key:"updateClientConfiguration",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;return _regeneratorRuntime().wrap(function l(b){for(;1;)switch(b.prev=b.next){case 0:return b.next=2,this.requester.getClientConfiguration(a);case 2:if(c=b.sent,c.ok){b.next=8;break}if(d=this.configurationData.featureFlags,!d.length){b.next=7;break}return b.abrupt("return",(0,_tsRes.Ok)(!0));case 7:return b.abrupt("return",c);case 8:if(_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester}),e=c.data,f=e.configuration,g=e.customData,this.configurationData=c.data,null!==g&&void 0!==g&&g.length&&(this.dataManager.customDataIndexes=g),this.dataManager.clearTrees(),this.mappedRules.clear(),h=this.updateStorageData(),h.ok){b.next=17;break}return b.abrupt("return",h);case 17:if(i=f.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,j=i!==this.updateType,!j){b.next=23;break}return this.updateType=i,b.next=23,this.initialize();case 23:return k=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule,this.visitorCodeManager.setConsentRequired(k),b.abrupt("return",(0,_tsRes.Ok)(j));case 26:case"end":return b.stop();}},b,this)}));return a}()},{key:"updateStorageData",value:function updateStorageData(){this.lastUpdate=new Date;var a={data:this.configurationData,lastUpdate:this.lastUpdate.toString()};return this.storage.write(a)}}]),a}();exports.ClientConfiguration=ClientConfiguration;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_urlProvider=require("../requester/urlProvider");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class ClientConfiguration{constructor(a){let{settings:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i}=a;_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",new Map),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),this.requester=d,this.settings=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers(),this.configurationData=this.externalClientConfiguration}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(a=>{a.ok&&this.configurationUpdateCallback&&this.configurationUpdateCallback()})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.settings.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}onConfigurationUpdate(a){this.configurationUpdateCallback=a}get featureFlags(){return this.configurationData.featureFlags}get configuration(){return this.configurationData.configuration}get segments(){const a=new Map;return this.featureFlags.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),a}get ruleMap(){if(this.mappedRules.size)return this.mappedRules;const a=new Map;for(const b of this.featureFlags)for(const c of b.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),a.set(d,{featureId:b.id,experimentId:e,variations:g})}return this.mappedRules=a,a}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){return this.featureFlags.some(a=>a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))}checkIntegrity(a){if(!a)return!1;const b=Object.keys(a);if(!b.length)return!1;const c=Object.keys(_constants.DEFAULT_CONFIGURATION_DATA);return b.sort().join()===c.sort().join()}checkShouldUpdate(){let a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];const{featureFlags:b,configuration:c}=this.configurationData,{updateInterval:d}=this.settings;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=c.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!b.length)return!0;const e=this.lastUpdate.getTime(),f=Date.now()-d;return e<f}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);d?(_urlProvider.UrlProvider.setDataApiDomain(b.configuration.dataApiDomain),this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))):(_urlProvider.UrlProvider.setDataApiDomain(_constants.DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain),this.storage.write({data:_constants.DEFAULT_CONFIGURATION_DATA,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA)}}async updateClientConfiguration(a){const b=await this.requester.getClientConfiguration(a);if(!b.ok){const{featureFlags:a}=this.configurationData;return a.length?(0,_tsRes.Ok)(!0):b}_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester});const{configuration:c,customData:d}=b.data;this.configurationData=b.data,null!==d&&void 0!==d&&d.length&&(this.dataManager.customDataIndexes=d),this.dataManager.clearTrees(),this.mappedRules.clear();const e=this.updateStorageData();if(!e.ok)return e;const f=c.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,g=f!==this.updateType;g&&(this.updateType=f,await this.initialize());const h=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=h,(0,_tsRes.Ok)(g)}updateStorageData(){this.lastUpdate=new Date;const a={data:this.configurationData,lastUpdate:this.lastUpdate.toString()};return _urlProvider.UrlProvider.setDataApiDomain(this.configurationData.configuration.dataApiDomain),this.storage.write(a)}}exports.ClientConfiguration=ClientConfiguration;
2
2
  //# sourceMappingURL=clientConfiguration.js.map