@schibsted/pulse-sdk 8.0.0-rc.2 → 8.0.0-rc.21

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 (409) hide show
  1. package/dist/cjs/Tracker.js +582 -471
  2. package/dist/cjs/app-integration.js +3 -3
  3. package/dist/cjs/builders/actor.js +6 -6
  4. package/dist/cjs/builders/consents.js +8 -8
  5. package/dist/cjs/builders/device-browser.js +8 -8
  6. package/dist/cjs/builders/device-node.js +3 -3
  7. package/dist/cjs/builders/events-anonymous-node.js +3 -3
  8. package/dist/cjs/builders/events-node.js +7 -7
  9. package/dist/cjs/builders/experimentMetadata.js +2 -2
  10. package/dist/cjs/builders/experiments.js +1 -0
  11. package/dist/cjs/builders/objects/objects-anonymous-browser.js +2 -2
  12. package/dist/cjs/builders/objects/objects-anonymous-node.js +9 -9
  13. package/dist/cjs/builders/objects/objects-browser.js +2 -2
  14. package/dist/cjs/builders/objects/objects-node.js +10 -10
  15. package/dist/cjs/builders/objects/utils.js +3 -3
  16. package/dist/cjs/builders/origin-browser.js +2 -2
  17. package/dist/cjs/builders/origin-node.js +4 -4
  18. package/dist/cjs/builders/session-browser.js +6 -80
  19. package/dist/cjs/cis-sync/cis-browser.js +219 -0
  20. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/cjs/cis-sync}/cis.js +0 -1
  21. package/dist/cjs/cis-sync/eventEmitter.js +37 -0
  22. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/cjs/cis-sync}/index.js +0 -1
  23. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/cjs/cis-sync}/pulse-cookie.js +53 -63
  24. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/cjs/cis-sync}/storage/pulseStorage.js +28 -21
  25. package/dist/cjs/cis-sync/storage/storage.js +24 -0
  26. package/dist/cjs/createPulseTracker.js +4 -4
  27. package/dist/cjs/identity/actor.js +20 -8
  28. package/dist/cjs/identity/advertising.js +1 -1
  29. package/dist/cjs/identity/cis.js +7 -6
  30. package/dist/cjs/index.js +3 -3
  31. package/dist/cjs/leaveTracking/index.js +10 -10
  32. package/dist/cjs/leaveTrackingTpaas/constants.js +2 -7
  33. package/dist/cjs/leaveTrackingTpaas/index.js +70 -46
  34. package/dist/cjs/network-browser.js +3 -3
  35. package/dist/cjs/remoteConfig/index.js +5 -5
  36. package/dist/cjs/session/store.js +96 -0
  37. package/dist/cjs/tpaas-builders/builders/catalogVersion.js +9 -0
  38. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/device.js +50 -72
  39. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/navigationType.js +2 -3
  40. package/dist/cjs/tpaas-builders/builders/pageContent.js +7 -0
  41. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/pageInfo.js +2 -3
  42. package/dist/cjs/tpaas-builders/builders/pageSports.js +7 -0
  43. package/dist/cjs/tpaas-builders/builders/provider.js +19 -0
  44. package/dist/cjs/tpaas-builders/builders/referrer.js +17 -0
  45. package/dist/cjs/tpaas-builders/builders/session.js +5 -0
  46. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/trackerBuilder.js +2 -3
  47. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/user.js +1 -1
  48. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/utm.js +3 -9
  49. package/dist/cjs/tpaas-builders/builders.js +326 -0
  50. package/dist/cjs/tpaas-builders/guards.js +7 -0
  51. package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/index.js +3 -0
  52. package/dist/cjs/tpaas-context/adapters.js +85 -0
  53. package/dist/cjs/tpaas-context/browser.js +51 -0
  54. package/dist/cjs/tpaas-context/index.js +6 -0
  55. package/dist/cjs/tpaas-context/prepare.js +177 -0
  56. package/dist/cjs/tpaas-context/session.js +23 -0
  57. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/cjs/tpaas-context}/types.js +0 -1
  58. package/{node_modules/@schibsted/tpaas-schemas/dist/cjs → dist/cjs/tpaas-schemas}/constants.js +189 -158
  59. package/{node_modules/@schibsted/tpaas-schemas/dist/cjs → dist/cjs/tpaas-schemas}/index.js +1 -0
  60. package/dist/cjs/tpaas-schemas/types.js +2 -0
  61. package/dist/cjs/tracker-proxy/consts.js +29 -7
  62. package/dist/cjs/tracker-proxy/proxy-provider.js +2 -2
  63. package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/index.js +4 -1
  64. package/dist/cjs/utils/xDomainId.js +15 -0
  65. package/dist/cjs/version.js +1 -1
  66. package/dist/cjs/visibility-observer/index.js +9 -7
  67. package/dist/cjs/wrapper/types/event.js +5 -0
  68. package/dist/cjs/wrapper/utils/map-page-to-page-ref.js +13 -0
  69. package/dist/ejs/Tracker.js +558 -447
  70. package/dist/ejs/app-integration.js +1 -1
  71. package/dist/ejs/builders/actor.js +3 -3
  72. package/dist/ejs/builders/consents.js +4 -4
  73. package/dist/ejs/builders/device-browser.js +2 -2
  74. package/dist/ejs/builders/device-node.js +1 -1
  75. package/dist/ejs/builders/events-anonymous-node.js +1 -1
  76. package/dist/ejs/builders/events-node.js +4 -4
  77. package/dist/ejs/builders/experimentMetadata.js +1 -1
  78. package/dist/ejs/builders/experiments.js +1 -1
  79. package/dist/ejs/builders/objects/objects-anonymous-browser.js +1 -1
  80. package/dist/ejs/builders/objects/objects-anonymous-node.js +1 -1
  81. package/dist/ejs/builders/objects/objects-browser.js +1 -1
  82. package/dist/ejs/builders/objects/objects-node.js +1 -1
  83. package/dist/ejs/builders/objects/utils.js +1 -1
  84. package/dist/ejs/builders/origin-browser.js +1 -1
  85. package/dist/ejs/builders/origin-node.js +1 -1
  86. package/dist/ejs/builders/session-browser.js +5 -77
  87. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/cis-browser.js +17 -4
  88. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/cis.js +0 -1
  89. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/eventEmitter.js +0 -1
  90. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/index.js +0 -1
  91. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/pulse-cookie.js +1 -2
  92. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/storage/pulseStorage.js +12 -4
  93. package/{node_modules/@schibsted/pulse-cis-sync/dist/ejs → dist/ejs/cis-sync}/storage/storage.js +6 -2
  94. package/dist/ejs/createPulseTracker.js +1 -1
  95. package/dist/ejs/identity/actor.js +21 -9
  96. package/dist/ejs/identity/advertising.js +1 -1
  97. package/dist/ejs/identity/cis.js +4 -3
  98. package/dist/ejs/index.js +4 -3
  99. package/dist/ejs/leaveTracking/index.js +1 -1
  100. package/dist/ejs/leaveTrackingTpaas/constants.js +1 -5
  101. package/dist/ejs/leaveTrackingTpaas/index.js +65 -41
  102. package/dist/ejs/network-browser.js +1 -1
  103. package/dist/ejs/remoteConfig/index.js +1 -1
  104. package/dist/ejs/session/store.js +90 -0
  105. package/dist/ejs/tpaas-builders/builders/catalogVersion.js +6 -0
  106. package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/device.js +50 -72
  107. package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/navigationType.js +2 -3
  108. package/dist/ejs/tpaas-builders/builders/pageContent.js +3 -0
  109. package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/pageInfo.js +2 -3
  110. package/dist/ejs/tpaas-builders/builders/pageSports.js +3 -0
  111. package/dist/ejs/tpaas-builders/builders/provider.js +16 -0
  112. package/dist/ejs/tpaas-builders/builders/referrer.js +13 -0
  113. package/dist/ejs/tpaas-builders/builders/session.js +1 -0
  114. package/dist/ejs/tpaas-builders/builders/trackerBuilder.js +10 -0
  115. package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/user.js +1 -1
  116. package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/utm.js +3 -9
  117. package/dist/ejs/tpaas-builders/builders.js +259 -0
  118. package/dist/ejs/tpaas-builders/guards.js +4 -0
  119. package/dist/ejs/tpaas-builders/index.js +2 -0
  120. package/dist/ejs/tpaas-context/adapters.js +80 -0
  121. package/dist/ejs/tpaas-context/browser.js +47 -0
  122. package/dist/ejs/tpaas-context/index.js +1 -0
  123. package/dist/ejs/tpaas-context/prepare.js +137 -0
  124. package/dist/ejs/tpaas-context/session.js +19 -0
  125. package/{node_modules/@schibsted/tpaas-schemas/dist/ejs → dist/ejs/tpaas-schemas}/constants.js +187 -156
  126. package/{node_modules/@schibsted/tpaas-schemas/dist/ejs → dist/ejs/tpaas-schemas}/index.js +1 -0
  127. package/dist/ejs/tpaas-schemas/types.js +1 -0
  128. package/dist/ejs/tracker-proxy/consts.js +29 -7
  129. package/dist/ejs/tracker-proxy/proxy-provider.js +1 -1
  130. package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/index.js +1 -0
  131. package/dist/ejs/utils/xDomainId.js +11 -0
  132. package/dist/ejs/version.js +1 -1
  133. package/dist/ejs/visibility-observer/index.js +9 -7
  134. package/dist/ejs/wrapper/types/event.js +4 -1
  135. package/dist/ejs/wrapper/utils/map-page-to-page-ref.js +10 -0
  136. package/dist/types/Tracker.d.ts +198 -93
  137. package/dist/types/builders/actor.d.ts +3 -2
  138. package/dist/types/builders/consents.d.ts +3 -3
  139. package/dist/types/builders/device-node.d.ts +2 -2
  140. package/dist/types/builders/events-anonymous-node.d.ts +4 -4
  141. package/dist/types/builders/events-node.d.ts +5 -5
  142. package/dist/types/builders/experiments.d.ts +1 -0
  143. package/dist/types/builders/index.d.ts +1 -1
  144. package/dist/types/builders/objects/objects-anonymous-node.d.ts +1 -1
  145. package/dist/types/builders/objects/objects-node.d.ts +1 -1
  146. package/dist/types/builders/origin-node.d.ts +1 -1
  147. package/dist/types/builders/session-browser.d.ts +1 -13
  148. package/{node_modules/@schibsted/pulse-cis-sync/dist/types → dist/types/cis-sync}/cis-browser.d.ts +1 -0
  149. package/{node_modules/@schibsted/pulse-cis-sync/dist/types → dist/types/cis-sync}/storage/pulseStorage.d.ts +12 -4
  150. package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/storage/storage.d.ts +2 -1
  151. package/dist/types/config.d.ts +1 -1
  152. package/dist/types/createPulseTracker.d.ts +1 -1
  153. package/dist/types/identity/actor.d.ts +3 -3
  154. package/dist/types/identity/advertising.d.ts +2 -2
  155. package/dist/types/identity/cis.d.ts +4 -4
  156. package/dist/types/index.d.ts +7 -8
  157. package/dist/types/leaveTrackingTpaas/constants.d.ts +1 -5
  158. package/dist/types/leaveTrackingTpaas/index.d.ts +6 -6
  159. package/dist/types/leaveTrackingTpaas/types.d.ts +2 -10
  160. package/dist/types/session/store.d.ts +34 -0
  161. package/dist/types/tpaas-builders/builders/anonymous.d.ts +3 -0
  162. package/dist/types/tpaas-builders/builders/baseEvent.d.ts +3 -0
  163. package/dist/types/tpaas-builders/builders/catalogVersion.d.ts +3 -0
  164. package/dist/types/tpaas-builders/builders/consents.d.ts +5 -0
  165. package/dist/types/tpaas-builders/builders/device.d.ts +5 -0
  166. package/dist/types/tpaas-builders/builders/experiments.d.ts +9 -0
  167. package/dist/types/tpaas-builders/builders/navigationType.d.ts +6 -0
  168. package/dist/types/tpaas-builders/builders/pageContent.d.ts +6 -0
  169. package/dist/types/tpaas-builders/builders/pageInfo.d.ts +7 -0
  170. package/dist/types/tpaas-builders/builders/pageSports.d.ts +6 -0
  171. package/dist/types/tpaas-builders/builders/pageviewId.d.ts +6 -0
  172. package/dist/types/tpaas-builders/builders/provider.d.ts +5 -0
  173. package/dist/types/tpaas-builders/builders/referrer.d.ts +6 -0
  174. package/dist/types/tpaas-builders/builders/session.d.ts +4 -0
  175. package/dist/types/tpaas-builders/builders/time.d.ts +4 -0
  176. package/dist/types/tpaas-builders/builders/trackerBuilder.d.ts +5 -0
  177. package/dist/types/tpaas-builders/builders/user.d.ts +5 -0
  178. package/dist/types/tpaas-builders/builders/utm.d.ts +7 -0
  179. package/dist/types/tpaas-builders/builders.d.ts +141 -0
  180. package/dist/types/tpaas-builders/guards.d.ts +2 -0
  181. package/dist/types/tpaas-builders/index.d.ts +2 -0
  182. package/dist/types/tpaas-context/adapters.d.ts +26 -0
  183. package/dist/types/tpaas-context/browser.d.ts +8 -0
  184. package/dist/types/tpaas-context/index.d.ts +2 -0
  185. package/dist/types/tpaas-context/prepare.d.ts +38 -0
  186. package/dist/types/tpaas-context/session.d.ts +10 -0
  187. package/dist/types/tpaas-context/types.d.ts +66 -0
  188. package/dist/types/tpaas-schemas/constants.d.ts +471 -0
  189. package/dist/types/tpaas-schemas/index.d.ts +5 -0
  190. package/dist/types/tpaas-schemas/types/ITpaasEvent.d.ts +130 -0
  191. package/dist/types/tpaas-schemas/types/schemas/IAnonymousImpressionUIElement.d.ts +58 -0
  192. package/dist/types/tpaas-schemas/types/schemas/ICompletedHealthAction.d.ts +139 -0
  193. package/dist/types/tpaas-schemas/types/schemas/IEngagementAd.d.ts +117 -0
  194. package/dist/types/tpaas-schemas/types/schemas/IEngagementAffiliate.d.ts +144 -0
  195. package/dist/types/tpaas-schemas/types/schemas/IEngagementAudio.d.ts +213 -0
  196. package/dist/types/tpaas-schemas/types/schemas/IEngagementForm.d.ts +111 -0
  197. package/dist/types/tpaas-schemas/types/schemas/IEngagementHealthUIElement.d.ts +133 -0
  198. package/dist/types/tpaas-schemas/types/schemas/IEngagementOffer.d.ts +107 -0
  199. package/dist/types/tpaas-schemas/types/schemas/IEngagementSchoolUIElement.d.ts +107 -0
  200. package/dist/types/tpaas-schemas/types/schemas/IEngagementSportsUIElement.d.ts +157 -0
  201. package/dist/types/tpaas-schemas/types/schemas/IEngagementTeaser.d.ts +114 -0
  202. package/dist/types/tpaas-schemas/types/schemas/IEngagementTvModule.d.ts +133 -0
  203. package/dist/types/tpaas-schemas/types/schemas/IEngagementTvSearch.d.ts +142 -0
  204. package/dist/types/tpaas-schemas/types/schemas/IEngagementUIElement.d.ts +105 -0
  205. package/dist/types/tpaas-schemas/types/schemas/IEngagementVideo.d.ts +238 -0
  206. package/dist/types/tpaas-schemas/types/schemas/IEngagementVideoAd.d.ts +147 -0
  207. package/dist/types/tpaas-schemas/types/schemas/IEngagementWidget.d.ts +91 -0
  208. package/dist/types/tpaas-schemas/types/schemas/IHeartbeatCommercialArticle.d.ts +96 -0
  209. package/dist/types/tpaas-schemas/types/schemas/IImpressionAd.d.ts +115 -0
  210. package/dist/types/tpaas-schemas/types/schemas/IImpressionAdSlot.d.ts +89 -0
  211. package/dist/types/tpaas-schemas/types/schemas/IImpressionAffiliate.d.ts +142 -0
  212. package/dist/types/tpaas-schemas/types/schemas/IImpressionForm.d.ts +113 -0
  213. package/dist/types/tpaas-schemas/types/schemas/IImpressionHealthUIElement.d.ts +138 -0
  214. package/dist/types/tpaas-schemas/types/schemas/IImpressionOffer.d.ts +109 -0
  215. package/dist/types/tpaas-schemas/types/schemas/IImpressionPlayer.d.ts +108 -0
  216. package/dist/types/tpaas-schemas/types/schemas/IImpressionSchoolUIElement.d.ts +109 -0
  217. package/dist/types/tpaas-schemas/types/schemas/IImpressionSportsUIElement.d.ts +159 -0
  218. package/dist/types/tpaas-schemas/types/schemas/IImpressionTeaser.d.ts +112 -0
  219. package/dist/types/tpaas-schemas/types/schemas/IImpressionUIElement.d.ts +107 -0
  220. package/dist/types/tpaas-schemas/types/schemas/IImpressionWidget.d.ts +89 -0
  221. package/dist/types/tpaas-schemas/types/schemas/ILeaveArticle.d.ts +133 -0
  222. package/dist/types/tpaas-schemas/types/schemas/ILeaveAudioPage.d.ts +88 -0
  223. package/dist/types/tpaas-schemas/types/schemas/ILeaveError.d.ts +95 -0
  224. package/dist/types/tpaas-schemas/types/schemas/ILeaveFrontpage.d.ts +83 -0
  225. package/dist/types/tpaas-schemas/types/schemas/ILeaveLandingpage.d.ts +90 -0
  226. package/dist/types/tpaas-schemas/types/schemas/ILeaveListing.d.ts +123 -0
  227. package/dist/types/tpaas-schemas/types/schemas/ILeaveLockedArticle.d.ts +139 -0
  228. package/dist/types/tpaas-schemas/types/schemas/ILeaveLockedAudioPage.d.ts +97 -0
  229. package/dist/types/tpaas-schemas/types/schemas/ILeaveLockedPage.d.ts +90 -0
  230. package/dist/types/tpaas-schemas/types/schemas/ILeaveLockedVideoPage.d.ts +97 -0
  231. package/dist/types/tpaas-schemas/types/schemas/ILeavePage.d.ts +82 -0
  232. package/dist/types/tpaas-schemas/types/schemas/ILeaveSchoolPage.d.ts +84 -0
  233. package/dist/types/tpaas-schemas/types/schemas/ILeaveSportsPage.d.ts +137 -0
  234. package/dist/types/tpaas-schemas/types/schemas/ILeaveVideoPage.d.ts +91 -0
  235. package/dist/types/tpaas-schemas/types/schemas/ILeaveWeather.d.ts +96 -0
  236. package/dist/types/tpaas-schemas/types/schemas/ILoadAd.d.ts +119 -0
  237. package/dist/types/tpaas-schemas/types/schemas/IViewArticle.d.ts +133 -0
  238. package/dist/types/tpaas-schemas/types/schemas/IViewAudioPage.d.ts +87 -0
  239. package/dist/types/tpaas-schemas/types/schemas/IViewError.d.ts +90 -0
  240. package/dist/types/tpaas-schemas/types/schemas/IViewFrontpage.d.ts +80 -0
  241. package/dist/types/tpaas-schemas/types/schemas/IViewHealthPage.d.ts +119 -0
  242. package/dist/types/tpaas-schemas/types/schemas/IViewLandingpage.d.ts +76 -0
  243. package/dist/types/tpaas-schemas/types/schemas/IViewListing.d.ts +118 -0
  244. package/dist/types/tpaas-schemas/types/schemas/IViewLockedArticle.d.ts +139 -0
  245. package/dist/types/tpaas-schemas/types/schemas/IViewLockedAudioPage.d.ts +95 -0
  246. package/dist/types/tpaas-schemas/types/schemas/IViewLockedPage.d.ts +94 -0
  247. package/dist/types/tpaas-schemas/types/schemas/IViewLockedVideoPage.d.ts +95 -0
  248. package/dist/types/tpaas-schemas/types/schemas/IViewPage.d.ts +86 -0
  249. package/dist/types/tpaas-schemas/types/schemas/IViewSchoolPage.d.ts +88 -0
  250. package/dist/types/tpaas-schemas/types/schemas/IViewSportsPage.d.ts +135 -0
  251. package/dist/types/tpaas-schemas/types/schemas/IViewTitle.d.ts +92 -0
  252. package/dist/types/tpaas-schemas/types/schemas/IViewVideoPage.d.ts +87 -0
  253. package/dist/types/tpaas-schemas/types/schemas/IViewWeather.d.ts +94 -0
  254. package/dist/types/tpaas-schemas/types/schemas/index.d.ts +63 -0
  255. package/dist/types/tpaas-schemas/types/templates/IBranded.d.ts +42 -0
  256. package/dist/types/tpaas-schemas/types/templates/IConsents.d.ts +34 -0
  257. package/dist/types/tpaas-schemas/types/templates/IContent.d.ts +56 -0
  258. package/dist/types/tpaas-schemas/types/templates/IDevice.d.ts +62 -0
  259. package/dist/types/tpaas-schemas/types/templates/IEngagement.d.ts +21 -0
  260. package/dist/types/tpaas-schemas/types/templates/IExperiments.d.ts +35 -0
  261. package/dist/types/tpaas-schemas/types/templates/IHealthFood.d.ts +55 -0
  262. package/dist/types/tpaas-schemas/types/templates/IHealthOrigin.d.ts +27 -0
  263. package/dist/types/tpaas-schemas/types/templates/IHealthPhysicalActivity.d.ts +36 -0
  264. package/dist/types/tpaas-schemas/types/templates/IHealthTraining.d.ts +74 -0
  265. package/dist/types/tpaas-schemas/types/templates/IHealthUserData.d.ts +25 -0
  266. package/dist/types/tpaas-schemas/types/templates/ILeave.d.ts +54 -0
  267. package/dist/types/tpaas-schemas/types/templates/ILeaveAudio.d.ts +37 -0
  268. package/dist/types/tpaas-schemas/types/templates/ILeaveStories.d.ts +34 -0
  269. package/dist/types/tpaas-schemas/types/templates/ILocation.d.ts +21 -0
  270. package/dist/types/tpaas-schemas/types/templates/IMetrics.d.ts +32 -0
  271. package/dist/types/tpaas-schemas/types/templates/IPageRef.d.ts +46 -0
  272. package/dist/types/tpaas-schemas/types/templates/IPlacement.d.ts +45 -0
  273. package/dist/types/tpaas-schemas/types/templates/IProvider.d.ts +73 -0
  274. package/dist/types/tpaas-schemas/types/templates/ISchool.d.ts +74 -0
  275. package/dist/types/tpaas-schemas/types/templates/ISession.d.ts +33 -0
  276. package/dist/types/tpaas-schemas/types/templates/ISports.d.ts +98 -0
  277. package/dist/types/tpaas-schemas/types/templates/ISportsUserFeatures.d.ts +28 -0
  278. package/dist/types/tpaas-schemas/types/templates/ITime.d.ts +32 -0
  279. package/dist/types/tpaas-schemas/types/templates/ITracker.d.ts +37 -0
  280. package/dist/types/tpaas-schemas/types/templates/IUser.d.ts +34 -0
  281. package/dist/types/tpaas-schemas/types/templates/IUtmTags.d.ts +38 -0
  282. package/dist/types/tpaas-schemas/types/templates/index.d.ts +27 -0
  283. package/dist/types/tpaas-schemas/types.d.ts +42 -0
  284. package/dist/types/tracker-proxy/consts.d.ts +2 -2
  285. package/dist/types/types.d.ts +21 -17
  286. package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/index.d.ts +1 -0
  287. package/dist/types/utils/xDomainId.d.ts +2 -0
  288. package/dist/types/version.d.ts +1 -1
  289. package/dist/types/visibility-observer/index.d.ts +6 -1
  290. package/dist/types/wrapper/engagement/ui-element/types.d.ts +1 -1
  291. package/dist/types/wrapper/types/base-event.d.ts +1 -1
  292. package/dist/types/wrapper/types/event.d.ts +4 -2
  293. package/dist/types/wrapper/types/utils.d.ts +1 -1
  294. package/dist/types/wrapper/utils/map-page-to-page-ref.d.ts +3 -0
  295. package/dist/types/wrapper/view/article/types.d.ts +1 -1
  296. package/dist/types/wrapper/view/frontpage/types.d.ts +1 -1
  297. package/dist/types/wrapper/view/listing/types.d.ts +1 -1
  298. package/dist/types/wrapper/view/loginposter/types.d.ts +1 -1
  299. package/dist/types/wrapper/view/page/types.d.ts +1 -1
  300. package/dist/types/wrapper/view/salesposter/types.d.ts +1 -1
  301. package/dist/types/wrapper/view/ui-element/types.d.ts +1 -1
  302. package/package.json +21 -20
  303. package/dist/cjs/Tracker.test-d.js +0 -76
  304. package/dist/ejs/Tracker.test-d.js +0 -71
  305. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.d.ts +0 -26
  306. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.js +0 -273
  307. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis-browser.js.map +0 -1
  308. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/cis.js.map +0 -1
  309. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/eventEmitter.js +0 -39
  310. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/eventEmitter.js.map +0 -1
  311. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/index.js.map +0 -1
  312. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/pulse-cookie.js.map +0 -1
  313. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/pulseStorage.d.ts +0 -36
  314. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/pulseStorage.js.map +0 -1
  315. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/storage.js +0 -21
  316. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/storage/storage.js.map +0 -1
  317. package/node_modules/@schibsted/pulse-cis-sync/dist/cjs/types.js.map +0 -1
  318. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis-browser.d.ts +0 -26
  319. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis-browser.js.map +0 -1
  320. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis.d.ts +0 -10
  321. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/cis.js.map +0 -1
  322. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/eventEmitter.d.ts +0 -14
  323. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/eventEmitter.js.map +0 -1
  324. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/index.d.ts +0 -4
  325. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/index.js.map +0 -1
  326. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/pulse-cookie.d.ts +0 -55
  327. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/pulse-cookie.js.map +0 -1
  328. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/pulseStorage.d.ts +0 -36
  329. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/pulseStorage.js.map +0 -1
  330. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/storage.d.ts +0 -6
  331. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/storage/storage.js.map +0 -1
  332. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/types.d.ts +0 -24
  333. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/types.js +0 -2
  334. package/node_modules/@schibsted/pulse-cis-sync/dist/ejs/types.js.map +0 -1
  335. package/node_modules/@schibsted/pulse-cis-sync/dist/types/cis.d.ts +0 -10
  336. package/node_modules/@schibsted/pulse-cis-sync/dist/types/eventEmitter.d.ts +0 -14
  337. package/node_modules/@schibsted/pulse-cis-sync/dist/types/index.d.ts +0 -4
  338. package/node_modules/@schibsted/pulse-cis-sync/dist/types/pulse-cookie.d.ts +0 -55
  339. package/node_modules/@schibsted/pulse-cis-sync/dist/types/storage/storage.d.ts +0 -6
  340. package/node_modules/@schibsted/pulse-cis-sync/dist/types/types.d.ts +0 -24
  341. package/node_modules/@schibsted/pulse-cis-sync/package.json +0 -44
  342. package/node_modules/@schibsted/pulse-utils/package.json +0 -36
  343. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/provider.js +0 -12
  344. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/referrer.js +0 -19
  345. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders/session.js +0 -114
  346. package/node_modules/@schibsted/tpaas-event-builder/dist/cjs/builders.js +0 -272
  347. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/provider.js +0 -9
  348. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/referrer.js +0 -15
  349. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/session.js +0 -108
  350. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders/trackerBuilder.js +0 -11
  351. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/builders.js +0 -215
  352. package/node_modules/@schibsted/tpaas-event-builder/dist/ejs/index.js +0 -1
  353. package/node_modules/@schibsted/tpaas-event-builder/dist/index.d.ts +0 -5403
  354. package/node_modules/@schibsted/tpaas-event-builder/package.json +0 -40
  355. package/node_modules/@schibsted/tpaas-schemas/dist/index.d.ts +0 -6176
  356. package/node_modules/@schibsted/tpaas-schemas/package.json +0 -35
  357. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/cis-sync}/types.js +0 -0
  358. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/anonymous.js +0 -0
  359. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/baseEvent.js +0 -0
  360. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/consents.js +0 -0
  361. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/experiments.js +0 -0
  362. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/pageviewId.js +0 -0
  363. /package/{node_modules/@schibsted/tpaas-event-builder/dist/cjs → dist/cjs/tpaas-builders}/builders/time.js +0 -0
  364. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/cookie-config.js +0 -0
  365. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/cookie.js +0 -0
  366. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/events.js +0 -0
  367. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/get.js +0 -0
  368. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/getRootDomain.js +0 -0
  369. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/merge.js +0 -0
  370. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/objects.js +0 -0
  371. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/omit.js +0 -0
  372. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/randomString.js +0 -0
  373. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/throttle.js +0 -0
  374. /package/{node_modules/@schibsted/pulse-utils/dist/cjs → dist/cjs/utils}/webApi.js +0 -0
  375. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/cis-sync}/types.js +0 -0
  376. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/anonymous.js +0 -0
  377. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/baseEvent.js +0 -0
  378. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/consents.js +0 -0
  379. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/experiments.js +0 -0
  380. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/pageviewId.js +0 -0
  381. /package/{node_modules/@schibsted/tpaas-event-builder/dist/ejs → dist/ejs/tpaas-builders}/builders/time.js +0 -0
  382. /package/dist/{types/Tracker.test-d.d.ts → ejs/tpaas-context/types.js} +0 -0
  383. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/cookie-config.js +0 -0
  384. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/cookie.js +0 -0
  385. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/events.js +0 -0
  386. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/get.js +0 -0
  387. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/getRootDomain.js +0 -0
  388. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/merge.js +0 -0
  389. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/objects.js +0 -0
  390. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/omit.js +0 -0
  391. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/randomString.js +0 -0
  392. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/throttle.js +0 -0
  393. /package/{node_modules/@schibsted/pulse-utils/dist/ejs → dist/ejs/utils}/webApi.js +0 -0
  394. /package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/cis.d.ts +0 -0
  395. /package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/eventEmitter.d.ts +0 -0
  396. /package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/index.d.ts +0 -0
  397. /package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/pulse-cookie.d.ts +0 -0
  398. /package/{node_modules/@schibsted/pulse-cis-sync/dist/cjs → dist/types/cis-sync}/types.d.ts +0 -0
  399. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/cookie-config.d.ts +0 -0
  400. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/cookie.d.ts +0 -0
  401. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/events.d.ts +0 -0
  402. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/get.d.ts +0 -0
  403. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/getRootDomain.d.ts +0 -0
  404. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/merge.d.ts +0 -0
  405. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/objects.d.ts +0 -0
  406. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/omit.d.ts +0 -0
  407. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/randomString.d.ts +0 -0
  408. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/throttle.d.ts +0 -0
  409. /package/{node_modules/@schibsted/pulse-utils/dist/types → dist/types/utils}/webApi.d.ts +0 -0
@@ -3,16 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.evaluateActor = exports.userIsLoggedIn = exports.getActor = exports.getUserId = exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = void 0;
7
- const pulse_utils_1 = require("@schibsted/pulse-utils");
6
+ exports.userIsLoggedIn = exports.getUserId = exports.getActor = exports.evaluateActor = exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = void 0;
8
7
  const actor_1 = require("../builders/actor");
8
+ const utils_1 = require("../utils");
9
9
  const warnOnce_1 = __importDefault(require("../warnOnce"));
10
10
  /**
11
11
  * @internal exported for testing
12
12
  */
13
- exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = 'Cis sync initiated with no actor builder and no event available. If you do not use a login system, please indicate' +
14
- ' this using tracker.update({ actor: undefined }), otherwise do tracker.update({ actor: somePromise }) with a' +
15
- ' promise that resolves to the login state.';
13
+ exports.WARN_CIS_SYNC_LOGIN_UNDEFINED = 'No Actor Builder found in event input or tracker builders. Please provide an Actor Builder to ensure the SDK resolves logged-in and logged-out scenarios correctly.';
16
14
  /**
17
15
  * Get the actor id (userId) from the current browser. A promise is returned
18
16
  * because a call may be made to complete the login process.
@@ -33,6 +31,19 @@ const getActor = async (builders) => {
33
31
  return await evaluateActor(builders);
34
32
  };
35
33
  exports.getActor = getActor;
34
+ /**
35
+ * Pinpoints the Actor Builder from the Event payload or the available Builders
36
+ * @param eventInput - The event input which may contain an `actor` property
37
+ * @param builders - The builders managed by the SDK.
38
+ */
39
+ function getActorSource(eventInput = {}, builders = {}) {
40
+ if ((0, actor_1.hasActorBuilder)(eventInput)) {
41
+ return eventInput.actor;
42
+ }
43
+ if ((0, actor_1.hasActorBuilder)(builders)) {
44
+ return builders.actor;
45
+ }
46
+ }
36
47
  const userIsLoggedIn = async (builders) => {
37
48
  const actor = await getActor(builders);
38
49
  return !!actor?.id;
@@ -45,8 +56,9 @@ exports.userIsLoggedIn = userIsLoggedIn;
45
56
  * @private
46
57
  */
47
58
  const evaluateActor = async (eventInput = {}, builders = {}) => {
48
- if ((0, actor_1.isActorInput)(eventInput) || (0, actor_1.isActorInput)(builders)) {
49
- const evaluatedActor = await (0, pulse_utils_1.evaluateAndFlatten)(eventInput.actor || builders.actor);
59
+ const actorSource = getActorSource(eventInput, builders);
60
+ if (actorSource) {
61
+ const evaluatedActor = await (0, utils_1.evaluateAndFlatten)(actorSource);
50
62
  if (evaluatedActor) {
51
63
  return evaluatedActor;
52
64
  }
@@ -54,7 +66,7 @@ const evaluateActor = async (eventInput = {}, builders = {}) => {
54
66
  // We allow an empty actor object, because it is a sign that the application is not setting nor updating Actor correctly.
55
67
  // Inferring "id: undefined" as a fallback would mask that bug.
56
68
  // Hence, the warning below.
57
- (0, warnOnce_1.default)('no-actor-builder-and-no-event-present', exports.WARN_CIS_SYNC_LOGIN_UNDEFINED);
69
+ (0, warnOnce_1.default)('no-actor-builder', exports.WARN_CIS_SYNC_LOGIN_UNDEFINED);
58
70
  return {};
59
71
  };
60
72
  exports.evaluateActor = evaluateActor;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAdvertisingIdentifiers = exports.getIncludeAdvertising = exports.getAdId = void 0;
3
+ exports.getIncludeAdvertising = exports.getAdvertisingIdentifiers = exports.getAdId = void 0;
4
4
  const actor_1 = require("./actor");
5
5
  const cis_1 = require("./cis");
6
6
  /**
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.requireCisSyncCallForAdvertisingIds = exports.cisSync = exports.clearCookieJweIfStale = void 0;
4
- const pulse_cis_sync_1 = require("@schibsted/pulse-cis-sync");
5
- Object.defineProperty(exports, "clearCookieJweIfStale", { enumerable: true, get: function () { return pulse_cis_sync_1.clearCookieJweIfStale; } });
3
+ exports.requireCisSyncCallForAdvertisingIds = exports.clearCookieJweIfStale = exports.cisSync = void 0;
4
+ const cis_sync_1 = require("../cis-sync");
5
+ Object.defineProperty(exports, "clearCookieJweIfStale", { enumerable: true, get: function () { return cis_sync_1.clearCookieJweIfStale; } });
6
6
  const version_1 = require("../version");
7
7
  const actor_1 = require("./actor");
8
8
  const requireCisSyncCallForAdvertisingIds = () => {
9
- (0, pulse_cis_sync_1.resetRefreshAfter)(new Date());
9
+ (0, cis_sync_1.resetRefreshAfter)(new Date());
10
10
  };
11
11
  exports.requireCisSyncCallForAdvertisingIds = requireCisSyncCallForAdvertisingIds;
12
12
  /**
@@ -45,14 +45,15 @@ const cisSync = async (data, builders, config) => {
45
45
  // _pulse2data cookie, or just not do the sync.
46
46
  //
47
47
  const actorPromise = (0, actor_1.evaluateActor)(data, builders);
48
- const { cisBaseUrl, cisEnabled, includeAdvertising: includeAdvertisingPromise, isHybrid, nativeJwe, providerId, trackerId, vendors, } = config || {};
48
+ const { adChoicesEnabled, cisBaseUrl, cisEnabled, includeAdvertising: includeAdvertisingPromise, isHybrid, nativeJwe, providerId, trackerId, vendors, } = config || {};
49
49
  const [includeAdvertising, actor] = await Promise.all([includeAdvertisingPromise, actorPromise]);
50
50
  const { id, realm } = actor;
51
51
  if (cisEnabled) {
52
52
  // @ts-expect-error
53
- return (0, pulse_cis_sync_1.syncWithCis)(
53
+ return (0, cis_sync_1.syncWithCis)(
54
54
  // @ts-expect-error
55
55
  id, nativeJwe, cisBaseUrl, realm, providerId, isHybrid ? 'Hybrid' : 'Web', version_1.SDK_VERSION, {
56
+ adChoicesEnabled,
56
57
  includeAdvertising,
57
58
  vendors,
58
59
  trackerId,
package/dist/cjs/index.js CHANGED
@@ -39,19 +39,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.unsubscribe = exports.subscribeWithState = exports.subscribeOnce = exports.subscribe = exports.getPulseTracker = exports.createPulseTracker = exports.Tracker = exports.EventBuilders = void 0;
42
+ exports.Tracker = exports.unsubscribe = exports.subscribeWithState = exports.subscribeOnce = exports.subscribe = exports.getPulseTracker = exports.createPulseTracker = exports.EventBuilders = void 0;
43
43
  const Tracker_1 = __importDefault(require("./Tracker"));
44
44
  exports.Tracker = Tracker_1.default;
45
45
  exports.default = Tracker_1.default;
46
46
  exports.EventBuilders = __importStar(require("./builders"));
47
- __exportStar(require("./Tracker"), exports);
48
- __exportStar(require("@schibsted/tpaas-schemas"), exports);
49
47
  var createPulseTracker_1 = require("./createPulseTracker");
50
48
  Object.defineProperty(exports, "createPulseTracker", { enumerable: true, get: function () { return createPulseTracker_1.createPulseTracker; } });
51
49
  var getPulseTracker_1 = require("./getPulseTracker");
52
50
  Object.defineProperty(exports, "getPulseTracker", { enumerable: true, get: function () { return getPulseTracker_1.getPulseTracker; } });
51
+ __exportStar(require("./Tracker"), exports);
53
52
  var Tracker_2 = require("./Tracker");
54
53
  Object.defineProperty(exports, "subscribe", { enumerable: true, get: function () { return Tracker_2.subscribe; } });
55
54
  Object.defineProperty(exports, "subscribeOnce", { enumerable: true, get: function () { return Tracker_2.subscribeOnce; } });
56
55
  Object.defineProperty(exports, "subscribeWithState", { enumerable: true, get: function () { return Tracker_2.subscribeWithState; } });
57
56
  Object.defineProperty(exports, "unsubscribe", { enumerable: true, get: function () { return Tracker_2.unsubscribe; } });
57
+ __exportStar(require("./tpaas-schemas"), exports);
@@ -44,16 +44,16 @@ exports.trackPageLeave = trackPageLeave;
44
44
  exports.updateViewedContent = updateViewedContent;
45
45
  exports.addEventListeners = addEventListeners;
46
46
  exports.removeEventListeners = removeEventListeners;
47
- const pulse_utils_1 = require("@schibsted/pulse-utils");
48
47
  const logger = __importStar(require("loglevel"));
49
48
  const Tracker_1 = require("../Tracker");
49
+ const utils_1 = require("../utils");
50
50
  const constants_1 = require("./constants");
51
51
  const types_1 = require("./types");
52
52
  let pageLeaveListeners = [];
53
53
  let updateViewedContentListeners = [];
54
54
  let activityListeners = [];
55
55
  let resizeObserver = null;
56
- let throttledUpdateFn = (0, pulse_utils_1.throttle)(() => undefined, 0);
56
+ let throttledUpdateFn = (0, utils_1.throttle)(() => undefined, 0);
57
57
  let startTime = 0;
58
58
  let activityDuration = (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
59
59
  let currentPageLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
@@ -177,7 +177,7 @@ const resetTime = () => Date.now();
177
177
  Update the default Leave event with an event supplied by the brand
178
178
  */
179
179
  function updatePageLeaveEvent(leaveEvent) {
180
- (0, pulse_utils_1.pulseMerge)(currentPageLeaveEvent, leaveEvent);
180
+ (0, utils_1.pulseMerge)(currentPageLeaveEvent, leaveEvent);
181
181
  }
182
182
  /*
183
183
  Send a Leave event only if Page Leave tracking is active in the SDK
@@ -202,7 +202,7 @@ async function trackPageLeave(tracker, providedEvent, eventName) {
202
202
  const endTime = Date.now();
203
203
  const duration = endTime - startTime;
204
204
  const leaveEvent = providedEvent || currentLeaveEventBuilder();
205
- const mergedEvent = (0, pulse_utils_1.pulseMerge)({
205
+ const mergedEvent = (0, utils_1.pulseMerge)({
206
206
  ...currentPageLeaveEvent,
207
207
  engagement: {
208
208
  duration,
@@ -227,7 +227,7 @@ async function trackPageLeave(tracker, providedEvent, eventName) {
227
227
  */
228
228
  function addUpdateViewedContentListeners(objectElement, pageElement, objectResizable) {
229
229
  updateViewedContent(objectElement, pageElement);
230
- throttledUpdateFn = (0, pulse_utils_1.throttle)(() => updateViewedContent(objectElement, pageElement), 500);
230
+ throttledUpdateFn = (0, utils_1.throttle)(() => updateViewedContent(objectElement, pageElement), 500);
231
231
  updateViewedContentListeners = addEventListeners([types_1.BrowserEvents.SCROLL, types_1.BrowserEvents.RESIZE], throttledUpdateFn);
232
232
  if (objectResizable) {
233
233
  if (!resizeObserver) {
@@ -250,7 +250,7 @@ function addUpdateViewedContentListeners(objectElement, pageElement, objectResiz
250
250
  {maxPageViewPercentage} The maximum relative scroll position the user has seen in %.
251
251
  */
252
252
  function updateViewedContent(objectElement, pageElement) {
253
- const { totalHeight: additionalTotalHeight, viewedHeight: additionalViewedHeight } = (0, pulse_utils_1.isFunction)(additionalHeightBuilder)
253
+ const { totalHeight: additionalTotalHeight, viewedHeight: additionalViewedHeight } = (0, utils_1.isFunction)(additionalHeightBuilder)
254
254
  ? additionalHeightBuilder()
255
255
  : { totalHeight: 0, viewedHeight: 0 };
256
256
  const objectScrolledPixels = (0, exports.calculateScrolledPixels)(objectElement) + additionalViewedHeight;
@@ -262,7 +262,7 @@ function updateViewedContent(objectElement, pageElement) {
262
262
  const pageViewPercentage = calculateViewPercentage(pageScrolledPixels, pageElement.scrollHeight + additionalTotalHeight);
263
263
  const maxPageViewPercentage = Math.max(pageViewPercentage, Number(currentPageLeaveEvent.engagement.maxPageViewPercentage));
264
264
  logger.debug('updateViewedContent:before:engagement', { ...currentPageLeaveEvent.engagement });
265
- (0, pulse_utils_1.pulseMerge)(currentPageLeaveEvent.engagement, {
265
+ (0, utils_1.pulseMerge)(currentPageLeaveEvent.engagement, {
266
266
  pageScrollPosition,
267
267
  maxPageScrollPosition,
268
268
  objectViewPercentage,
@@ -274,7 +274,7 @@ function updateViewedContent(objectElement, pageElement) {
274
274
  }
275
275
  const calculateScrolledPixels = (element) => {
276
276
  const rect = element.getBoundingClientRect();
277
- const scrolledPixels = pulse_utils_1.isBrowser ? element.scrollHeight - rect.bottom + window.innerHeight : 0;
277
+ const scrolledPixels = utils_1.isBrowser ? element.scrollHeight - rect.bottom + window.innerHeight : 0;
278
278
  if (scrolledPixels <= 0) {
279
279
  return 0;
280
280
  }
@@ -325,7 +325,7 @@ function resetLastActivity(activityDuration) {
325
325
  */
326
326
  function addEventListeners(events, handler, options) {
327
327
  return events.map((eventName) => {
328
- if (pulse_utils_1.isBrowser) {
328
+ if (utils_1.isBrowser) {
329
329
  window.addEventListener(eventName, handler, options);
330
330
  }
331
331
  return [eventName, handler];
@@ -336,7 +336,7 @@ function addEventListeners(events, handler, options) {
336
336
  */
337
337
  function removeEventListeners(eventListeners, options = {}) {
338
338
  for (const [eventName, listener] of eventListeners) {
339
- if (pulse_utils_1.isBrowser) {
339
+ if (utils_1.isBrowser) {
340
340
  window.removeEventListener(eventName, listener, options);
341
341
  }
342
342
  }
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_PAGE_LEAVE_EVENT = exports.DEFAULT_ACTIVITY_DURATION = void 0;
4
- const DEFAULT_ACTIVITY_DURATION = () => ({
5
- value: 0,
6
- interval: undefined,
7
- timeSinceLastActivity: 0,
8
- });
9
- exports.DEFAULT_ACTIVITY_DURATION = DEFAULT_ACTIVITY_DURATION;
3
+ exports.ACTIVITY_DURATION_LIMIT_MS = exports.DEFAULT_PAGE_LEAVE_EVENT = void 0;
10
4
  const DEFAULT_PAGE_LEAVE_EVENT = () => ({
11
5
  objectViewPercentage: 0,
12
6
  maxObjectViewPercentage: 0,
@@ -16,3 +10,4 @@ const DEFAULT_PAGE_LEAVE_EVENT = () => ({
16
10
  maxPageScrollPosition: 0,
17
11
  });
18
12
  exports.DEFAULT_PAGE_LEAVE_EVENT = DEFAULT_PAGE_LEAVE_EVENT;
13
+ exports.ACTIVITY_DURATION_LIMIT_MS = 30000;
@@ -45,8 +45,8 @@ exports.updateTpaasViewedContent = updateTpaasViewedContent;
45
45
  exports.addEventListeners = addEventListeners;
46
46
  exports.removeEventListeners = removeEventListeners;
47
47
  exports.shouldEnableLeaveTracking = shouldEnableLeaveTracking;
48
- const pulse_utils_1 = require("@schibsted/pulse-utils");
49
48
  const logger = __importStar(require("loglevel"));
49
+ const utils_1 = require("../utils");
50
50
  const constants_1 = require("./constants");
51
51
  const types_1 = require("./types");
52
52
  let currentLeaveSchema;
@@ -55,20 +55,45 @@ let leaveListeners = [];
55
55
  let updateViewedContentListeners = [];
56
56
  let activityListeners = [];
57
57
  let resizeObserver = null;
58
- let throttledUpdateFn = (0, pulse_utils_1.throttle)(() => undefined, 0);
59
- let startTime = 0;
60
- let activityDuration = (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
58
+ let throttledUpdateFn = (0, utils_1.throttle)(() => undefined, 0);
59
+ let durationStartTime = 0;
60
+ let previousActivityTime = 0;
61
+ let activityDurationMs = 0;
61
62
  let currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
62
63
  let additionalHeightBuilder;
64
+ /**
65
+ * Resolves a DOM element from either a CSS selector string or an Element instance.
66
+ */
67
+ function resolveDomElement(element) {
68
+ try {
69
+ return typeof element === 'string' ? document.querySelector(element) : element || null;
70
+ }
71
+ catch (e) {
72
+ logger.error('Error while resolving DOM element', e);
73
+ return null;
74
+ }
75
+ }
63
76
  /*
64
77
  Add leave tracking
65
78
  */
66
79
  function addTpaasLeaveTracking({ objectElement, pageElement, schema, objectResizable, heightBuilder, trackMethod, }) {
67
80
  function _addLeaveTracking() {
81
+ const objectDomElement = resolveDomElement(objectElement);
82
+ if (objectDomElement == null) {
83
+ logger.error('Could not find object element for leave tracking');
84
+ return;
85
+ }
86
+ let pageDomElement = resolveDomElement(pageElement);
87
+ if (pageDomElement == null) {
88
+ logger.warn('Could not find page element for leave tracking, defaulting to document.body');
89
+ pageDomElement = document.body;
90
+ }
68
91
  additionalHeightBuilder = heightBuilder;
69
92
  addTpaasLeaveListeners();
70
- addUpdateEventListeners(objectElement, pageElement || document.body, objectResizable);
71
- startTime = resetTime();
93
+ addUpdateEventListeners(objectDomElement, pageDomElement, objectResizable);
94
+ previousActivityTime = resetTime();
95
+ durationStartTime = resetTime();
96
+ activityDurationMs = 0;
72
97
  currentLeaveSchema = schema;
73
98
  currentTrackMethod = trackMethod;
74
99
  logger.debug('addLeaveTracking:after:state', currentLeaveEvent);
@@ -160,12 +185,9 @@ function removeUpdateEventListeners() {
160
185
  */
161
186
  const resetEventDefaults = () => {
162
187
  currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
163
- startTime = resetTime();
164
- activityDuration = resetActivityDuration();
165
- };
166
- const resetActivityDuration = () => {
167
- clearInterval(activityDuration.interval);
168
- return (0, constants_1.DEFAULT_ACTIVITY_DURATION)();
188
+ durationStartTime = resetTime();
189
+ previousActivityTime = resetTime();
190
+ activityDurationMs = 0;
169
191
  };
170
192
  const resetTpaasViewedContent = () => {
171
193
  currentLeaveEvent = (0, constants_1.DEFAULT_PAGE_LEAVE_EVENT)();
@@ -174,34 +196,43 @@ exports.resetTpaasViewedContent = resetTpaasViewedContent;
174
196
  const resetTime = () => Date.now();
175
197
  /*
176
198
  Send a Leave event only if Page Leave tracking is active in the SDK
177
- The event that is ultimately sent is a merge between the default event
178
- saved in this file and the event supplied by the brand, with preference going
179
- to the brand event. After the event has been sent, leave page tracking is removed
199
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
200
+ After the event has been sent, leave page tracking is removed
180
201
  and must be explicitly re-added if needed.
181
202
  */
182
- function trackTpaasActiveLeave() {
203
+ async function trackTpaasActiveLeave() {
183
204
  if (leaveTpaasTrackingIsActive()) {
184
- trackTpaasLeave();
205
+ await trackTpaasLeave();
185
206
  }
186
207
  }
187
208
  /*
188
209
  Send a Leave event regardless of whether Page Leave tracking is active in the SDK
189
- The event that is ultimately sent is a merge between the default event
190
- saved in this file and the event supplied by the brand, with preference going
191
- to the brand event. After the event has been sent, leave page tracking is removed
210
+ The event that is ultimately sent is the View event saved in the currentTrackMethod callback.
211
+ After the event has been sent, leave page tracking is removed
192
212
  and must be explicitly re-added if needed.
193
213
  */
194
- function trackTpaasLeave() {
214
+ async function trackTpaasLeave() {
195
215
  const leave = getTpaasLeaveObject();
196
- currentTrackMethod(leave);
216
+ // Capture currentTrackMethod and remove tracking synchronously before awaiting.
217
+ // If removal happened after the await, a new trackView* call arriving during the async
218
+ // gap would see tracking still active with the same schema and silently discard its
219
+ // new callback (e.g. a fresh leaveAudioBuilder), causing the next leave event to
220
+ // never fire or to use the wrong builder.
221
+ const trackMethod = currentTrackMethod;
197
222
  removeTpaasLeaveTracking();
223
+ await trackMethod(leave);
198
224
  }
199
225
  function getTpaasLeaveObject() {
200
226
  const endTime = Date.now();
201
- const duration = endTime - startTime;
227
+ // TPaaS leave event requires duration/activity to be at least 1ms, otherwise the event is rejected
228
+ // also, in practice, it's almost impossible to have an activity or duration of 0ms
229
+ // We don't call increaseActivityDuration here because it's possible to call getTpaasLeaveObject multiple times
230
+ // without any activity events in between, which would incorrectly increase the activity duration.
231
+ const durationMs = Math.max(endTime - durationStartTime, 1);
232
+ const lastActivityDuration = calculateActivityGap(endTime);
202
233
  const leave = {
203
- durationMs: duration,
204
- activityDurationMs: activityDuration.value,
234
+ durationMs,
235
+ activityDurationMs: Math.max(activityDurationMs + lastActivityDuration, 1),
205
236
  ...currentLeaveEvent,
206
237
  };
207
238
  logger.debug('trackTpaasLeave: event', leave);
@@ -213,7 +244,7 @@ function getTpaasLeaveObject() {
213
244
  */
214
245
  function addUpdateViewedContentListeners(objectElement, pageElement, objectResizable) {
215
246
  updateTpaasViewedContent(objectElement, pageElement);
216
- throttledUpdateFn = (0, pulse_utils_1.throttle)(() => updateTpaasViewedContent(objectElement, pageElement), 500);
247
+ throttledUpdateFn = (0, utils_1.throttle)(() => updateTpaasViewedContent(objectElement, pageElement), 500);
217
248
  updateViewedContentListeners = addEventListeners([types_1.BrowserEvents.SCROLL, types_1.BrowserEvents.RESIZE], throttledUpdateFn);
218
249
  if (objectResizable) {
219
250
  if (!resizeObserver) {
@@ -236,7 +267,7 @@ function addUpdateViewedContentListeners(objectElement, pageElement, objectResiz
236
267
  {maxPageViewPercentage} The maximum relative scroll position the user has seen in %.
237
268
  */
238
269
  function updateTpaasViewedContent(objectElement, pageElement) {
239
- const { totalHeight: additionalTotalHeight, viewedHeight: additionalViewedHeight } = (0, pulse_utils_1.isFunction)(additionalHeightBuilder)
270
+ const { totalHeight: additionalTotalHeight, viewedHeight: additionalViewedHeight } = (0, utils_1.isFunction)(additionalHeightBuilder)
240
271
  ? additionalHeightBuilder()
241
272
  : { totalHeight: 0, viewedHeight: 0 };
242
273
  const objectScrolledPixels = (0, exports.calculateScrolledPixels)(objectElement) + additionalViewedHeight;
@@ -260,7 +291,7 @@ function updateTpaasViewedContent(objectElement, pageElement) {
260
291
  }
261
292
  const calculateScrolledPixels = (element) => {
262
293
  const rect = element.getBoundingClientRect();
263
- const scrolledPixels = pulse_utils_1.isBrowser ? element.scrollHeight - rect.bottom + window.innerHeight : 0;
294
+ const scrolledPixels = utils_1.isBrowser ? element.scrollHeight - rect.bottom + window.innerHeight : 0;
264
295
  if (scrolledPixels <= 0) {
265
296
  return 0;
266
297
  }
@@ -276,18 +307,10 @@ exports.calculateScrollPosition = calculateScrollPosition;
276
307
  'mousedown', 'mousemove', 'keydown', 'scroll' and/or 'touchstart' browser events.
277
308
  */
278
309
  function addUpdateActivityDurationListeners() {
279
- if (activityDuration.interval !== undefined) {
280
- // If the interval is already set, do not set it again
310
+ // if there are already listeners for activity, do not add more
311
+ if (activityListeners.length > 0) {
281
312
  return;
282
313
  }
283
- const interval = 1000;
284
- const activityTimeout = 30 * 1000;
285
- activityDuration.interval = window.setInterval(() => {
286
- activityDuration.timeSinceLastActivity += interval;
287
- if (activityDuration.timeSinceLastActivity < activityTimeout) {
288
- activityDuration.value += interval;
289
- }
290
- }, interval);
291
314
  const activityEvents = [
292
315
  types_1.BrowserEvents.SCROLL,
293
316
  types_1.BrowserEvents.MOUSEDOWN,
@@ -296,21 +319,22 @@ function addUpdateActivityDurationListeners() {
296
319
  types_1.BrowserEvents.TOUCHSTART,
297
320
  ];
298
321
  activityListeners = addEventListeners(activityEvents, () => {
299
- activityDuration = resetLastActivity(activityDuration);
322
+ increaseActivityDuration(Date.now());
300
323
  }, { passive: true });
301
324
  }
302
- function resetLastActivity(activityDuration) {
303
- return {
304
- ...activityDuration,
305
- timeSinceLastActivity: 0,
306
- };
325
+ function calculateActivityGap(activityEndTime) {
326
+ return Math.min(activityEndTime - previousActivityTime, constants_1.ACTIVITY_DURATION_LIMIT_MS);
327
+ }
328
+ function increaseActivityDuration(activityEndTime) {
329
+ activityDurationMs += calculateActivityGap(activityEndTime);
330
+ previousActivityTime = resetTime();
307
331
  }
308
332
  /*
309
333
  Add listeners to a set of browser events.
310
334
  */
311
335
  function addEventListeners(events, handler, options) {
312
336
  return events.map((eventName) => {
313
- if (pulse_utils_1.isBrowser) {
337
+ if (utils_1.isBrowser) {
314
338
  window.addEventListener(eventName, handler, options);
315
339
  }
316
340
  return [eventName, handler];
@@ -321,7 +345,7 @@ function addEventListeners(events, handler, options) {
321
345
  */
322
346
  function removeEventListeners(eventListeners, options = {}) {
323
347
  for (const [eventName, listener] of eventListeners) {
324
- if (pulse_utils_1.isBrowser) {
348
+ if (utils_1.isBrowser) {
325
349
  window.removeEventListener(eventName, listener, options);
326
350
  }
327
351
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = send;
4
- const pulse_utils_1 = require("@schibsted/pulse-utils");
5
- const supportsBeacon = () => pulse_utils_1.isBrowser && Boolean(window.navigator.sendBeacon);
4
+ const utils_1 = require("./utils");
5
+ const supportsBeacon = () => utils_1.isBrowser && Boolean(window.navigator.sendBeacon);
6
6
  function send(url, data, sdkConfig) {
7
7
  // if there is as large number of events, only send 10 in each request
8
8
  const eventChunks = Array.isArray(data)
@@ -17,7 +17,7 @@ function send(url, data, sdkConfig) {
17
17
  return acc;
18
18
  }, [[]])
19
19
  : [[data]];
20
- if (pulse_utils_1.isBrowser && supportsBeacon() && (sdkConfig.useBeaconWhenAvailable || sdkConfig.useBeacon)) {
20
+ if (utils_1.isBrowser && supportsBeacon() && (sdkConfig.useBeaconWhenAvailable || sdkConfig.useBeacon)) {
21
21
  const result = eventChunks.reduce((previousStatus, eventChunk) => previousStatus && window.navigator.sendBeacon(url, JSON.stringify(eventChunk)), true);
22
22
  if (result) {
23
23
  return Promise.resolve(true);
@@ -11,8 +11,8 @@ exports.clearInMemoryConfig = clearInMemoryConfig;
11
11
  exports.shouldSyncRemoteConfig = shouldSyncRemoteConfig;
12
12
  exports.resolveConfigServicesByTag = resolveConfigServicesByTag;
13
13
  exports.syncRemoteConfig = syncRemoteConfig;
14
- const pulse_utils_1 = require("@schibsted/pulse-utils");
15
14
  const loglevel_1 = __importDefault(require("loglevel"));
15
+ const utils_1 = require("../utils");
16
16
  const CIS_KEY = 'cis';
17
17
  const COLLECTOR_KEY = 'collector';
18
18
  const getRemoteConfigStorageKey = '_pulse.internal.remote.config';
@@ -36,7 +36,7 @@ async function fetchRemoteConfigWithRetry(url, retries = 3) {
36
36
  }
37
37
  function readConfigFromStorage() {
38
38
  try {
39
- return JSON.parse(pulse_utils_1.webApi.localStorage?.getItem(getRemoteConfigStorageKey) ?? '');
39
+ return JSON.parse(utils_1.webApi.localStorage?.getItem(getRemoteConfigStorageKey) ?? '');
40
40
  }
41
41
  catch (_err) {
42
42
  return null;
@@ -51,7 +51,7 @@ function writeConfigToStorage(config, url) {
51
51
  updatedAt: new Date().toISOString(),
52
52
  },
53
53
  };
54
- pulse_utils_1.webApi.localStorage?.setItem(getRemoteConfigStorageKey, JSON.stringify(configPersistence));
54
+ utils_1.webApi.localStorage?.setItem(getRemoteConfigStorageKey, JSON.stringify(configPersistence));
55
55
  return configPersistence;
56
56
  }
57
57
  catch (_err) {
@@ -60,7 +60,7 @@ function writeConfigToStorage(config, url) {
60
60
  }
61
61
  function clearConfigFromStorage() {
62
62
  try {
63
- pulse_utils_1.webApi.localStorage?.removeItem(getRemoteConfigStorageKey);
63
+ utils_1.webApi.localStorage?.removeItem(getRemoteConfigStorageKey);
64
64
  return true;
65
65
  }
66
66
  catch (_err) {
@@ -86,7 +86,7 @@ function shouldSyncRemoteConfig(url, config, metadata) {
86
86
  url !== metadata?.remoteConfigUrl);
87
87
  }
88
88
  function resolveConfigServicesByTag(tag, config) {
89
- if ((0, pulse_utils_1.isString)(tag) && config) {
89
+ if ((0, utils_1.isString)(tag) && config) {
90
90
  let services = config.scopes?.[tag]?.services || null;
91
91
  if (!services && tag !== 'default') {
92
92
  services = config.scopes.default.services;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.touchSession = exports.readSession = exports.generateSessionSDRN = void 0;
4
+ const uuid_1 = require("uuid");
5
+ const utils_1 = require("../utils");
6
+ const { USE_LOCALSTORAGE } = utils_1.cookieConfig;
7
+ const SESSION_STORAGE_KEY = '_pulsesession';
8
+ const SESSION_MAX_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes
9
+ /**
10
+ * @private
11
+ */
12
+ const generateSessionSDRN = (sessionId) => `${utils_1.SESSION_SDRN_PREFIX}${sessionId}`;
13
+ exports.generateSessionSDRN = generateSessionSDRN;
14
+ // Return parsed json from cookie (or localStorage if enabled), or undefined.
15
+ const readAndParse = () => {
16
+ try {
17
+ const storedSession = (0, utils_1.readCookie)(SESSION_STORAGE_KEY);
18
+ if (storedSession) {
19
+ return JSON.parse(storedSession);
20
+ }
21
+ }
22
+ catch (_e) {
23
+ // If localStorage/cookie is not available, we treat it as if
24
+ // the value is undefined.
25
+ // If data is unparseable, we also ignore it.
26
+ return undefined;
27
+ }
28
+ return undefined;
29
+ };
30
+ /**
31
+ * Reads the stored session. Any invalid or unreadable data is ignored.
32
+ * @private
33
+ */
34
+ const readSession = () => {
35
+ const storedSession = readAndParse();
36
+ if (storedSession) {
37
+ const [sessionSdrn, startTimeMs, lastEventTimeMs] = storedSession;
38
+ const startTime = new Date(startTimeMs);
39
+ const lastEventTime = new Date(lastEventTimeMs);
40
+ if (sessionSdrn && !Number.isNaN(startTime.getTime()) && !Number.isNaN(lastEventTime.getTime())) {
41
+ return {
42
+ // the session is stored as an SDRN, for compatibility with legacy events and older SDK versions
43
+ sessionId: sessionSdrn.replace(utils_1.SESSION_SDRN_PREFIX, ''),
44
+ startTime,
45
+ lastEventTime,
46
+ };
47
+ }
48
+ }
49
+ return undefined;
50
+ };
51
+ exports.readSession = readSession;
52
+ const writeSession = ({ sessionId, startTime, lastEventTime }) => {
53
+ try {
54
+ // SDK v8 (supporting TPaaS events) needs to be compatible with legacy events AND older SDK versions
55
+ // as a result, we can't store just the sessionId, we need the full SDRN in there
56
+ const sessionToStore = [
57
+ (0, exports.generateSessionSDRN)(sessionId),
58
+ startTime.getTime(),
59
+ lastEventTime.getTime(),
60
+ ];
61
+ const halfHourInDays = 1.0 / (24 * 2);
62
+ (0, utils_1.writeCookie)(SESSION_STORAGE_KEY, JSON.stringify(sessionToStore), (0, utils_1.getRootDomain)(), halfHourInDays);
63
+ // Delete old localStorage-based session if needed
64
+ if (!USE_LOCALSTORAGE) {
65
+ // removeItem will do nothing to a non-existing item.
66
+ utils_1.webApi.localStorage?.removeItem(SESSION_STORAGE_KEY);
67
+ }
68
+ }
69
+ catch (_e) {
70
+ // If we can't write the session, we just move on in life
71
+ }
72
+ };
73
+ const updateSession = (createdAt, session) => {
74
+ if (!session || session.lastEventTime.getTime() < createdAt.getTime() - SESSION_MAX_INTERVAL_MS) {
75
+ return { sessionId: (0, uuid_1.v4)(), startTime: createdAt, lastEventTime: createdAt, isFirstEvent: true };
76
+ }
77
+ // Never move lastEventTime backwards, or the session would expire early.
78
+ // In case the order of events is not strictly chronological, this ensures the session remains valid.
79
+ const lastEventTime = createdAt.getTime() > session.lastEventTime.getTime() ? createdAt : session.lastEventTime;
80
+ return { ...session, lastEventTime, isFirstEvent: false };
81
+ };
82
+ /**
83
+ * Registers an event created at `createdAt` in the stored session: extends the current session,
84
+ * or starts a new one when it expired, and stores the result.
85
+ *
86
+ * Call it synchronously, together with capturing `createdAt`, before any asynchronous work,
87
+ * so sessions are updated in the order events are tracked.
88
+ *
89
+ * @private
90
+ */
91
+ const touchSession = (createdAt) => {
92
+ const session = updateSession(createdAt, (0, exports.readSession)());
93
+ writeSession(session);
94
+ return session;
95
+ };
96
+ exports.touchSession = touchSession;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.builder = builder;
4
+ const tpaas_schemas_1 = require("../../tpaas-schemas");
5
+ function builder() {
6
+ return {
7
+ catalogVersion: tpaas_schemas_1.CATALOG_VERSION,
8
+ };
9
+ }