@tracelog/lib 0.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 (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -0
  3. package/dist/browser/tracelog.js +4040 -0
  4. package/dist/browser/web-vitals-CCnqwnC8.mjs +198 -0
  5. package/dist/cjs/api.d.ts +46 -0
  6. package/dist/cjs/api.js +224 -0
  7. package/dist/cjs/app.constants.d.ts +1 -0
  8. package/dist/cjs/app.constants.js +5 -0
  9. package/dist/cjs/app.d.ts +59 -0
  10. package/dist/cjs/app.js +272 -0
  11. package/dist/cjs/app.types.d.ts +6 -0
  12. package/dist/cjs/app.types.js +22 -0
  13. package/dist/cjs/constants/api.constants.d.ts +4 -0
  14. package/dist/cjs/constants/api.constants.js +18 -0
  15. package/dist/cjs/constants/browser.constants.d.ts +3 -0
  16. package/dist/cjs/constants/browser.constants.js +41 -0
  17. package/dist/cjs/constants/index.d.ts +8 -0
  18. package/dist/cjs/constants/index.js +24 -0
  19. package/dist/cjs/constants/initialization.constants.d.ts +40 -0
  20. package/dist/cjs/constants/initialization.constants.js +48 -0
  21. package/dist/cjs/constants/limits.constants.d.ts +25 -0
  22. package/dist/cjs/constants/limits.constants.js +40 -0
  23. package/dist/cjs/constants/security.constants.d.ts +1 -0
  24. package/dist/cjs/constants/security.constants.js +12 -0
  25. package/dist/cjs/constants/storage.constants.d.ts +9 -0
  26. package/dist/cjs/constants/storage.constants.js +22 -0
  27. package/dist/cjs/constants/timing.constants.d.ts +22 -0
  28. package/dist/cjs/constants/timing.constants.js +34 -0
  29. package/dist/cjs/constants/validation.constants.d.ts +13 -0
  30. package/dist/cjs/constants/validation.constants.js +31 -0
  31. package/dist/cjs/handlers/click.handler.d.ts +17 -0
  32. package/dist/cjs/handlers/click.handler.js +199 -0
  33. package/dist/cjs/handlers/error.handler.d.ts +15 -0
  34. package/dist/cjs/handlers/error.handler.js +97 -0
  35. package/dist/cjs/handlers/network.handler.d.ts +16 -0
  36. package/dist/cjs/handlers/network.handler.js +136 -0
  37. package/dist/cjs/handlers/page-view.handler.d.ts +15 -0
  38. package/dist/cjs/handlers/page-view.handler.js +83 -0
  39. package/dist/cjs/handlers/performance.handler.d.ts +19 -0
  40. package/dist/cjs/handlers/performance.handler.js +255 -0
  41. package/dist/cjs/handlers/scroll.handler.d.ts +16 -0
  42. package/dist/cjs/handlers/scroll.handler.js +138 -0
  43. package/dist/cjs/handlers/session.handler.d.ts +29 -0
  44. package/dist/cjs/handlers/session.handler.js +357 -0
  45. package/dist/cjs/integrations/google-analytics.integration.d.ts +18 -0
  46. package/dist/cjs/integrations/google-analytics.integration.js +159 -0
  47. package/dist/cjs/listeners/activity-listener-manager.d.ts +8 -0
  48. package/dist/cjs/listeners/activity-listener-manager.js +32 -0
  49. package/dist/cjs/listeners/index.d.ts +6 -0
  50. package/dist/cjs/listeners/index.js +14 -0
  51. package/dist/cjs/listeners/input-listener-managers.d.ts +15 -0
  52. package/dist/cjs/listeners/input-listener-managers.js +58 -0
  53. package/dist/cjs/listeners/listeners.types.d.ts +4 -0
  54. package/dist/cjs/listeners/listeners.types.js +2 -0
  55. package/dist/cjs/listeners/touch-listener-manager.d.ts +10 -0
  56. package/dist/cjs/listeners/touch-listener-manager.js +56 -0
  57. package/dist/cjs/listeners/unload-listener-manager.d.ts +8 -0
  58. package/dist/cjs/listeners/unload-listener-manager.js +30 -0
  59. package/dist/cjs/listeners/visibility-listener-manager.d.ts +12 -0
  60. package/dist/cjs/listeners/visibility-listener-manager.js +83 -0
  61. package/dist/cjs/managers/api.manager.d.ts +3 -0
  62. package/dist/cjs/managers/api.manager.js +14 -0
  63. package/dist/cjs/managers/config.manager.d.ts +7 -0
  64. package/dist/cjs/managers/config.manager.js +94 -0
  65. package/dist/cjs/managers/cross-tab-session.manager.d.ts +170 -0
  66. package/dist/cjs/managers/cross-tab-session.manager.js +730 -0
  67. package/dist/cjs/managers/event.manager.d.ts +61 -0
  68. package/dist/cjs/managers/event.manager.js +508 -0
  69. package/dist/cjs/managers/sampling.manager.d.ts +8 -0
  70. package/dist/cjs/managers/sampling.manager.js +53 -0
  71. package/dist/cjs/managers/sender.manager.d.ts +46 -0
  72. package/dist/cjs/managers/sender.manager.js +304 -0
  73. package/dist/cjs/managers/session-recovery.manager.d.ts +65 -0
  74. package/dist/cjs/managers/session-recovery.manager.js +237 -0
  75. package/dist/cjs/managers/session.manager.d.ts +72 -0
  76. package/dist/cjs/managers/session.manager.js +587 -0
  77. package/dist/cjs/managers/state.manager.d.ts +5 -0
  78. package/dist/cjs/managers/state.manager.js +23 -0
  79. package/dist/cjs/managers/storage.manager.d.ts +10 -0
  80. package/dist/cjs/managers/storage.manager.js +81 -0
  81. package/dist/cjs/managers/tags.manager.d.ts +12 -0
  82. package/dist/cjs/managers/tags.manager.js +289 -0
  83. package/dist/cjs/managers/user.manager.d.ts +7 -0
  84. package/dist/cjs/managers/user.manager.js +22 -0
  85. package/dist/cjs/public-api.d.ts +1 -0
  86. package/dist/cjs/public-api.js +37 -0
  87. package/dist/cjs/types/api.types.d.ts +21 -0
  88. package/dist/cjs/types/api.types.js +25 -0
  89. package/dist/cjs/types/common.types.d.ts +1 -0
  90. package/dist/cjs/types/common.types.js +2 -0
  91. package/dist/cjs/types/config.types.d.ts +104 -0
  92. package/dist/cjs/types/config.types.js +2 -0
  93. package/dist/cjs/types/device.types.d.ts +6 -0
  94. package/dist/cjs/types/device.types.js +10 -0
  95. package/dist/cjs/types/event.types.d.ts +104 -0
  96. package/dist/cjs/types/event.types.js +25 -0
  97. package/dist/cjs/types/index.d.ts +13 -0
  98. package/dist/cjs/types/index.js +29 -0
  99. package/dist/cjs/types/log.types.d.ts +4 -0
  100. package/dist/cjs/types/log.types.js +2 -0
  101. package/dist/cjs/types/mode.types.d.ts +7 -0
  102. package/dist/cjs/types/mode.types.js +11 -0
  103. package/dist/cjs/types/queue.types.d.ts +23 -0
  104. package/dist/cjs/types/queue.types.js +2 -0
  105. package/dist/cjs/types/session.types.d.ts +65 -0
  106. package/dist/cjs/types/session.types.js +2 -0
  107. package/dist/cjs/types/state.types.d.ts +12 -0
  108. package/dist/cjs/types/state.types.js +2 -0
  109. package/dist/cjs/types/tag.types.d.ts +43 -0
  110. package/dist/cjs/types/tag.types.js +31 -0
  111. package/dist/cjs/types/validation-error.types.d.ts +42 -0
  112. package/dist/cjs/types/validation-error.types.js +68 -0
  113. package/dist/cjs/types/web-vitals.types.d.ts +6 -0
  114. package/dist/cjs/types/web-vitals.types.js +2 -0
  115. package/dist/cjs/types/window.types.d.ts +17 -0
  116. package/dist/cjs/types/window.types.js +2 -0
  117. package/dist/cjs/utils/browser/device-detector.utils.d.ts +6 -0
  118. package/dist/cjs/utils/browser/device-detector.utils.js +71 -0
  119. package/dist/cjs/utils/browser/index.d.ts +2 -0
  120. package/dist/cjs/utils/browser/index.js +18 -0
  121. package/dist/cjs/utils/browser/utm-params.utils.d.ts +6 -0
  122. package/dist/cjs/utils/browser/utm-params.utils.js +37 -0
  123. package/dist/cjs/utils/data/index.d.ts +1 -0
  124. package/dist/cjs/utils/data/index.js +17 -0
  125. package/dist/cjs/utils/data/uuid.utils.d.ts +5 -0
  126. package/dist/cjs/utils/data/uuid.utils.js +18 -0
  127. package/dist/cjs/utils/index.d.ts +6 -0
  128. package/dist/cjs/utils/index.js +22 -0
  129. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +56 -0
  130. package/dist/cjs/utils/logging/debug-logger.utils.js +139 -0
  131. package/dist/cjs/utils/logging/index.d.ts +1 -0
  132. package/dist/cjs/utils/logging/index.js +5 -0
  133. package/dist/cjs/utils/network/index.d.ts +1 -0
  134. package/dist/cjs/utils/network/index.js +17 -0
  135. package/dist/cjs/utils/network/url.utils.d.ts +20 -0
  136. package/dist/cjs/utils/network/url.utils.js +172 -0
  137. package/dist/cjs/utils/security/index.d.ts +1 -0
  138. package/dist/cjs/utils/security/index.js +17 -0
  139. package/dist/cjs/utils/security/sanitize.utils.d.ts +32 -0
  140. package/dist/cjs/utils/security/sanitize.utils.js +319 -0
  141. package/dist/cjs/utils/validations/config-validations.utils.d.ts +42 -0
  142. package/dist/cjs/utils/validations/config-validations.utils.js +297 -0
  143. package/dist/cjs/utils/validations/event-validations.utils.d.ts +12 -0
  144. package/dist/cjs/utils/validations/event-validations.utils.js +30 -0
  145. package/dist/cjs/utils/validations/index.d.ts +5 -0
  146. package/dist/cjs/utils/validations/index.js +21 -0
  147. package/dist/cjs/utils/validations/metadata-validations.utils.d.ts +22 -0
  148. package/dist/cjs/utils/validations/metadata-validations.utils.js +115 -0
  149. package/dist/cjs/utils/validations/type-guards.utils.d.ts +6 -0
  150. package/dist/cjs/utils/validations/type-guards.utils.js +31 -0
  151. package/dist/cjs/utils/validations/url-validations.utils.d.ts +15 -0
  152. package/dist/cjs/utils/validations/url-validations.utils.js +47 -0
  153. package/dist/esm/api.d.ts +46 -0
  154. package/dist/esm/api.js +183 -0
  155. package/dist/esm/app.constants.d.ts +1 -0
  156. package/dist/esm/app.constants.js +1 -0
  157. package/dist/esm/app.d.ts +59 -0
  158. package/dist/esm/app.js +268 -0
  159. package/dist/esm/app.types.d.ts +6 -0
  160. package/dist/esm/app.types.js +6 -0
  161. package/dist/esm/constants/api.constants.d.ts +4 -0
  162. package/dist/esm/constants/api.constants.js +14 -0
  163. package/dist/esm/constants/browser.constants.d.ts +3 -0
  164. package/dist/esm/constants/browser.constants.js +38 -0
  165. package/dist/esm/constants/index.d.ts +8 -0
  166. package/dist/esm/constants/index.js +8 -0
  167. package/dist/esm/constants/initialization.constants.d.ts +40 -0
  168. package/dist/esm/constants/initialization.constants.js +45 -0
  169. package/dist/esm/constants/limits.constants.d.ts +25 -0
  170. package/dist/esm/constants/limits.constants.js +37 -0
  171. package/dist/esm/constants/security.constants.d.ts +1 -0
  172. package/dist/esm/constants/security.constants.js +9 -0
  173. package/dist/esm/constants/storage.constants.d.ts +9 -0
  174. package/dist/esm/constants/storage.constants.js +11 -0
  175. package/dist/esm/constants/timing.constants.d.ts +22 -0
  176. package/dist/esm/constants/timing.constants.js +31 -0
  177. package/dist/esm/constants/validation.constants.d.ts +13 -0
  178. package/dist/esm/constants/validation.constants.js +28 -0
  179. package/dist/esm/handlers/click.handler.d.ts +17 -0
  180. package/dist/esm/handlers/click.handler.js +195 -0
  181. package/dist/esm/handlers/error.handler.d.ts +15 -0
  182. package/dist/esm/handlers/error.handler.js +93 -0
  183. package/dist/esm/handlers/network.handler.d.ts +16 -0
  184. package/dist/esm/handlers/network.handler.js +132 -0
  185. package/dist/esm/handlers/page-view.handler.d.ts +15 -0
  186. package/dist/esm/handlers/page-view.handler.js +79 -0
  187. package/dist/esm/handlers/performance.handler.d.ts +19 -0
  188. package/dist/esm/handlers/performance.handler.js +218 -0
  189. package/dist/esm/handlers/scroll.handler.d.ts +16 -0
  190. package/dist/esm/handlers/scroll.handler.js +134 -0
  191. package/dist/esm/handlers/session.handler.d.ts +29 -0
  192. package/dist/esm/handlers/session.handler.js +353 -0
  193. package/dist/esm/integrations/google-analytics.integration.d.ts +18 -0
  194. package/dist/esm/integrations/google-analytics.integration.js +155 -0
  195. package/dist/esm/listeners/activity-listener-manager.d.ts +8 -0
  196. package/dist/esm/listeners/activity-listener-manager.js +28 -0
  197. package/dist/esm/listeners/index.d.ts +6 -0
  198. package/dist/esm/listeners/index.js +5 -0
  199. package/dist/esm/listeners/input-listener-managers.d.ts +15 -0
  200. package/dist/esm/listeners/input-listener-managers.js +53 -0
  201. package/dist/esm/listeners/listeners.types.d.ts +4 -0
  202. package/dist/esm/listeners/listeners.types.js +1 -0
  203. package/dist/esm/listeners/touch-listener-manager.d.ts +10 -0
  204. package/dist/esm/listeners/touch-listener-manager.js +52 -0
  205. package/dist/esm/listeners/unload-listener-manager.d.ts +8 -0
  206. package/dist/esm/listeners/unload-listener-manager.js +26 -0
  207. package/dist/esm/listeners/visibility-listener-manager.d.ts +12 -0
  208. package/dist/esm/listeners/visibility-listener-manager.js +79 -0
  209. package/dist/esm/managers/api.manager.d.ts +3 -0
  210. package/dist/esm/managers/api.manager.js +10 -0
  211. package/dist/esm/managers/config.manager.d.ts +7 -0
  212. package/dist/esm/managers/config.manager.js +90 -0
  213. package/dist/esm/managers/cross-tab-session.manager.d.ts +170 -0
  214. package/dist/esm/managers/cross-tab-session.manager.js +726 -0
  215. package/dist/esm/managers/event.manager.d.ts +61 -0
  216. package/dist/esm/managers/event.manager.js +504 -0
  217. package/dist/esm/managers/sampling.manager.d.ts +8 -0
  218. package/dist/esm/managers/sampling.manager.js +49 -0
  219. package/dist/esm/managers/sender.manager.d.ts +46 -0
  220. package/dist/esm/managers/sender.manager.js +300 -0
  221. package/dist/esm/managers/session-recovery.manager.d.ts +65 -0
  222. package/dist/esm/managers/session-recovery.manager.js +233 -0
  223. package/dist/esm/managers/session.manager.d.ts +72 -0
  224. package/dist/esm/managers/session.manager.js +583 -0
  225. package/dist/esm/managers/state.manager.d.ts +5 -0
  226. package/dist/esm/managers/state.manager.js +19 -0
  227. package/dist/esm/managers/storage.manager.d.ts +10 -0
  228. package/dist/esm/managers/storage.manager.js +77 -0
  229. package/dist/esm/managers/tags.manager.d.ts +12 -0
  230. package/dist/esm/managers/tags.manager.js +285 -0
  231. package/dist/esm/managers/user.manager.d.ts +7 -0
  232. package/dist/esm/managers/user.manager.js +18 -0
  233. package/dist/esm/public-api.d.ts +1 -0
  234. package/dist/esm/public-api.js +1 -0
  235. package/dist/esm/types/api.types.d.ts +21 -0
  236. package/dist/esm/types/api.types.js +22 -0
  237. package/dist/esm/types/common.types.d.ts +1 -0
  238. package/dist/esm/types/common.types.js +1 -0
  239. package/dist/esm/types/config.types.d.ts +104 -0
  240. package/dist/esm/types/config.types.js +1 -0
  241. package/dist/esm/types/device.types.d.ts +6 -0
  242. package/dist/esm/types/device.types.js +7 -0
  243. package/dist/esm/types/event.types.d.ts +104 -0
  244. package/dist/esm/types/event.types.js +22 -0
  245. package/dist/esm/types/index.d.ts +13 -0
  246. package/dist/esm/types/index.js +13 -0
  247. package/dist/esm/types/log.types.d.ts +4 -0
  248. package/dist/esm/types/log.types.js +1 -0
  249. package/dist/esm/types/mode.types.d.ts +7 -0
  250. package/dist/esm/types/mode.types.js +8 -0
  251. package/dist/esm/types/queue.types.d.ts +23 -0
  252. package/dist/esm/types/queue.types.js +1 -0
  253. package/dist/esm/types/session.types.d.ts +65 -0
  254. package/dist/esm/types/session.types.js +1 -0
  255. package/dist/esm/types/state.types.d.ts +12 -0
  256. package/dist/esm/types/state.types.js +1 -0
  257. package/dist/esm/types/tag.types.d.ts +43 -0
  258. package/dist/esm/types/tag.types.js +28 -0
  259. package/dist/esm/types/validation-error.types.d.ts +42 -0
  260. package/dist/esm/types/validation-error.types.js +59 -0
  261. package/dist/esm/types/web-vitals.types.d.ts +6 -0
  262. package/dist/esm/types/web-vitals.types.js +1 -0
  263. package/dist/esm/types/window.types.d.ts +17 -0
  264. package/dist/esm/types/window.types.js +1 -0
  265. package/dist/esm/utils/browser/device-detector.utils.d.ts +6 -0
  266. package/dist/esm/utils/browser/device-detector.utils.js +67 -0
  267. package/dist/esm/utils/browser/index.d.ts +2 -0
  268. package/dist/esm/utils/browser/index.js +2 -0
  269. package/dist/esm/utils/browser/utm-params.utils.d.ts +6 -0
  270. package/dist/esm/utils/browser/utm-params.utils.js +33 -0
  271. package/dist/esm/utils/data/index.d.ts +1 -0
  272. package/dist/esm/utils/data/index.js +1 -0
  273. package/dist/esm/utils/data/uuid.utils.d.ts +5 -0
  274. package/dist/esm/utils/data/uuid.utils.js +14 -0
  275. package/dist/esm/utils/index.d.ts +6 -0
  276. package/dist/esm/utils/index.js +6 -0
  277. package/dist/esm/utils/logging/debug-logger.utils.d.ts +56 -0
  278. package/dist/esm/utils/logging/debug-logger.utils.js +136 -0
  279. package/dist/esm/utils/logging/index.d.ts +1 -0
  280. package/dist/esm/utils/logging/index.js +1 -0
  281. package/dist/esm/utils/network/index.d.ts +1 -0
  282. package/dist/esm/utils/network/index.js +1 -0
  283. package/dist/esm/utils/network/url.utils.d.ts +20 -0
  284. package/dist/esm/utils/network/url.utils.js +166 -0
  285. package/dist/esm/utils/security/index.d.ts +1 -0
  286. package/dist/esm/utils/security/index.js +1 -0
  287. package/dist/esm/utils/security/sanitize.utils.d.ts +32 -0
  288. package/dist/esm/utils/security/sanitize.utils.js +311 -0
  289. package/dist/esm/utils/validations/config-validations.utils.d.ts +42 -0
  290. package/dist/esm/utils/validations/config-validations.utils.js +289 -0
  291. package/dist/esm/utils/validations/event-validations.utils.d.ts +12 -0
  292. package/dist/esm/utils/validations/event-validations.utils.js +26 -0
  293. package/dist/esm/utils/validations/index.d.ts +5 -0
  294. package/dist/esm/utils/validations/index.js +5 -0
  295. package/dist/esm/utils/validations/metadata-validations.utils.d.ts +22 -0
  296. package/dist/esm/utils/validations/metadata-validations.utils.js +110 -0
  297. package/dist/esm/utils/validations/type-guards.utils.d.ts +6 -0
  298. package/dist/esm/utils/validations/type-guards.utils.js +27 -0
  299. package/dist/esm/utils/validations/url-validations.utils.d.ts +15 -0
  300. package/dist/esm/utils/validations/url-validations.utils.js +42 -0
  301. package/package.json +80 -0
@@ -0,0 +1,268 @@
1
+ import { ApiManager } from './managers/api.manager';
2
+ import { ConfigManager } from './managers/config.manager';
3
+ import { EventManager } from './managers/event.manager';
4
+ import { UserManager } from './managers/user.manager';
5
+ import { StateManager } from './managers/state.manager';
6
+ import { SessionHandler } from './handlers/session.handler';
7
+ import { PageViewHandler } from './handlers/page-view.handler';
8
+ import { ClickHandler } from './handlers/click.handler';
9
+ import { ScrollHandler } from './handlers/scroll.handler';
10
+ import { isEventValid } from './utils/validations';
11
+ import { EventType } from './types/event.types';
12
+ import { GoogleAnalyticsIntegration } from './integrations/google-analytics.integration';
13
+ import { getDeviceType, normalizeUrl } from './utils';
14
+ import { StorageManager } from './managers/storage.manager';
15
+ import { SCROLL_DEBOUNCE_TIME_MS, SCROLL_SUPPRESSION_CONSTANTS } from './constants';
16
+ import { PerformanceHandler } from './handlers/performance.handler';
17
+ import { ErrorHandler } from './handlers/error.handler';
18
+ import { NetworkHandler } from './handlers/network.handler';
19
+ import { ProjectIdValidationError } from './types/validation-error.types';
20
+ import { debugLog } from './utils/logging';
21
+ export class App extends StateManager {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.isInitialized = false;
25
+ this.googleAnalytics = null;
26
+ this.suppressNextScrollTimer = null;
27
+ }
28
+ /**
29
+ * Returns the initialization status of the app
30
+ * @returns true if the app is fully initialized, false otherwise
31
+ */
32
+ get initialized() {
33
+ return this.isInitialized;
34
+ }
35
+ async init(appConfig) {
36
+ if (this.isInitialized) {
37
+ debugLog.debug('App', 'App already initialized, skipping re-initialization', { projectId: appConfig.id });
38
+ return;
39
+ }
40
+ debugLog.info('App', 'App initialization started', { projectId: appConfig.id });
41
+ this.validateAppReadiness(appConfig);
42
+ try {
43
+ this.initStorage();
44
+ await this.setState(appConfig);
45
+ await this.setIntegrations();
46
+ this.setEventManager();
47
+ await this.initHandlers();
48
+ this.isInitialized = true;
49
+ debugLog.info('App', 'App initialization completed successfully', {
50
+ projectId: appConfig.id,
51
+ });
52
+ }
53
+ catch (error) {
54
+ this.isInitialized = false;
55
+ debugLog.error('App', 'App initialization failed', { projectId: appConfig.id, error });
56
+ throw error;
57
+ }
58
+ }
59
+ /**
60
+ * Validates that the app is ready to initialize with the provided config
61
+ * This is a lightweight runtime validation layer that ensures the app receives proper config
62
+ * @param appConfig - The validated and normalized configuration
63
+ * @throws {ProjectIdValidationError} If project ID is invalid at runtime
64
+ */
65
+ validateAppReadiness(appConfig) {
66
+ // Lightweight validation - config should already be validated and normalized by api.ts
67
+ if (!appConfig?.id) {
68
+ debugLog.clientError('App', 'Configuration integrity check failed - missing project ID', {
69
+ hasConfig: !!appConfig,
70
+ hasId: !!appConfig?.id,
71
+ });
72
+ throw new ProjectIdValidationError('Configuration integrity check failed', 'app');
73
+ }
74
+ }
75
+ sendCustomEvent(name, metadata) {
76
+ if (!this.eventManager) {
77
+ debugLog.warn('App', 'Custom event attempted before eventManager initialization', { eventName: name });
78
+ return;
79
+ }
80
+ const { valid, error, sanitizedMetadata } = isEventValid(name, metadata);
81
+ if (valid) {
82
+ debugLog.debug('App', 'Custom event validated and queued', { eventName: name, hasMetadata: !!sanitizedMetadata });
83
+ this.eventManager.track({
84
+ type: EventType.CUSTOM,
85
+ custom_event: {
86
+ name,
87
+ ...(sanitizedMetadata && { metadata: sanitizedMetadata }),
88
+ },
89
+ });
90
+ }
91
+ else {
92
+ const currentMode = this.get('config')?.mode;
93
+ debugLog.clientError('App', `Custom event validation failed: ${error ?? 'unknown error'}`, {
94
+ eventName: name,
95
+ validationError: error,
96
+ hasMetadata: !!metadata,
97
+ mode: currentMode,
98
+ });
99
+ if (currentMode === 'qa' || currentMode === 'debug') {
100
+ throw new Error(`custom event "${name}" validation failed (${error ?? 'unknown error'}). Please, review your event data and try again.`);
101
+ }
102
+ }
103
+ }
104
+ destroy() {
105
+ if (!this.isInitialized) {
106
+ debugLog.warn('App', 'Destroy called but app was not initialized');
107
+ return;
108
+ }
109
+ debugLog.info('App', 'App cleanup started');
110
+ if (this.googleAnalytics) {
111
+ this.googleAnalytics.cleanup();
112
+ }
113
+ if (this.sessionHandler) {
114
+ this.sessionHandler.stopTracking();
115
+ }
116
+ if (this.pageViewHandler) {
117
+ this.pageViewHandler.stopTracking();
118
+ }
119
+ if (this.clickHandler) {
120
+ this.clickHandler.stopTracking();
121
+ }
122
+ if (this.scrollHandler) {
123
+ this.scrollHandler.stopTracking();
124
+ }
125
+ if (this.performanceHandler) {
126
+ this.performanceHandler.stopTracking();
127
+ }
128
+ if (this.errorHandler) {
129
+ this.errorHandler.stopTracking();
130
+ }
131
+ if (this.networkHandler) {
132
+ this.networkHandler.stopTracking();
133
+ }
134
+ if (this.suppressNextScrollTimer) {
135
+ clearTimeout(this.suppressNextScrollTimer);
136
+ this.suppressNextScrollTimer = null;
137
+ }
138
+ if (this.eventManager) {
139
+ this.eventManager.stop();
140
+ }
141
+ this.set('hasStartSession', false);
142
+ this.set('suppressNextScroll', false);
143
+ this.set('sessionId', null);
144
+ this.isInitialized = false;
145
+ debugLog.info('App', 'App cleanup completed successfully');
146
+ }
147
+ async setState(appConfig) {
148
+ this.setApiUrl(appConfig.id, appConfig.allowHttp);
149
+ await this.setConfig(appConfig);
150
+ this.setUserId();
151
+ this.setDevice();
152
+ this.setPageUrl();
153
+ }
154
+ setApiUrl(id, allowHttp = false) {
155
+ const apiManager = new ApiManager();
156
+ this.set('apiUrl', apiManager.getUrl(id, allowHttp));
157
+ }
158
+ async setConfig(appConfig) {
159
+ const configManager = new ConfigManager();
160
+ const config = await configManager.get(this.get('apiUrl'), appConfig);
161
+ this.set('config', config);
162
+ }
163
+ setUserId() {
164
+ const userManager = new UserManager(this.storageManager);
165
+ const userId = userManager.getId();
166
+ this.set('userId', userId);
167
+ }
168
+ setDevice() {
169
+ const device = getDeviceType();
170
+ this.set('device', device);
171
+ }
172
+ setPageUrl() {
173
+ const initialUrl = normalizeUrl(window.location.href, this.get('config').sensitiveQueryParams);
174
+ this.set('pageUrl', initialUrl);
175
+ }
176
+ async setIntegrations() {
177
+ const isIPExcluded = this.get('config').ipExcluded;
178
+ const measurementId = this.get('config').integrations?.googleAnalytics?.measurementId;
179
+ if (!isIPExcluded && measurementId?.trim()) {
180
+ this.googleAnalytics = new GoogleAnalyticsIntegration();
181
+ await this.googleAnalytics.initialize();
182
+ }
183
+ }
184
+ async initHandlers() {
185
+ if (!this.eventManager) {
186
+ throw new Error('EventManager must be initialized before handlers');
187
+ }
188
+ if (!this.storageManager) {
189
+ throw new Error('StorageManager must be initialized before handlers');
190
+ }
191
+ this.initSessionHandler();
192
+ this.initPageViewHandler();
193
+ this.initClickHandler();
194
+ this.initScrollHandler();
195
+ await this.initPerformanceHandler();
196
+ this.initErrorHandler();
197
+ this.initNetworkHandler();
198
+ }
199
+ initStorage() {
200
+ this.storageManager = new StorageManager();
201
+ }
202
+ setEventManager() {
203
+ if (!this.storageManager) {
204
+ throw new Error('StorageManager must be initialized before EventManager');
205
+ }
206
+ this.eventManager = new EventManager(this.storageManager, this.googleAnalytics);
207
+ }
208
+ initSessionHandler() {
209
+ if (!this.storageManager || !this.eventManager) {
210
+ throw new Error('StorageManager and EventManager must be initialized before SessionHandler');
211
+ }
212
+ this.sessionHandler = new SessionHandler(this.storageManager, this.eventManager);
213
+ this.sessionHandler.startTracking();
214
+ }
215
+ initPageViewHandler() {
216
+ if (!this.eventManager) {
217
+ throw new Error('EventManager must be initialized before PageViewHandler');
218
+ }
219
+ const onPageViewTrack = () => this.onPageViewTrack();
220
+ this.pageViewHandler = new PageViewHandler(this.eventManager, onPageViewTrack);
221
+ this.pageViewHandler.startTracking();
222
+ }
223
+ onPageViewTrack() {
224
+ this.set('suppressNextScroll', true);
225
+ if (this.suppressNextScrollTimer) {
226
+ clearTimeout(this.suppressNextScrollTimer);
227
+ this.suppressNextScrollTimer = null;
228
+ }
229
+ this.suppressNextScrollTimer = window.setTimeout(() => {
230
+ this.set('suppressNextScroll', false);
231
+ }, SCROLL_DEBOUNCE_TIME_MS * SCROLL_SUPPRESSION_CONSTANTS.SUPPRESS_MULTIPLIER);
232
+ }
233
+ initClickHandler() {
234
+ if (!this.eventManager) {
235
+ throw new Error('EventManager must be initialized before ClickHandler');
236
+ }
237
+ this.clickHandler = new ClickHandler(this.eventManager);
238
+ this.clickHandler.startTracking();
239
+ }
240
+ initScrollHandler() {
241
+ if (!this.eventManager) {
242
+ throw new Error('EventManager must be initialized before ScrollHandler');
243
+ }
244
+ this.scrollHandler = new ScrollHandler(this.eventManager);
245
+ this.scrollHandler.startTracking();
246
+ }
247
+ async initPerformanceHandler() {
248
+ if (!this.eventManager) {
249
+ throw new Error('EventManager must be initialized before PerformanceHandler');
250
+ }
251
+ this.performanceHandler = new PerformanceHandler(this.eventManager);
252
+ await this.performanceHandler.startTracking();
253
+ }
254
+ initErrorHandler() {
255
+ if (!this.eventManager) {
256
+ throw new Error('EventManager must be initialized before ErrorHandler');
257
+ }
258
+ this.errorHandler = new ErrorHandler(this.eventManager);
259
+ this.errorHandler.startTracking();
260
+ }
261
+ initNetworkHandler() {
262
+ if (!this.eventManager) {
263
+ throw new Error('EventManager must be initialized before NetworkHandler');
264
+ }
265
+ this.networkHandler = new NetworkHandler(this.eventManager);
266
+ this.networkHandler.startTracking();
267
+ }
268
+ }
@@ -0,0 +1,6 @@
1
+ export * from './types/common.types';
2
+ export * from './types/config.types';
3
+ export * from './types/device.types';
4
+ export * from './types/event.types';
5
+ export * from './types/queue.types';
6
+ export * from './types/tag.types';
@@ -0,0 +1,6 @@
1
+ export * from './types/common.types';
2
+ export * from './types/config.types';
3
+ export * from './types/device.types';
4
+ export * from './types/event.types';
5
+ export * from './types/queue.types';
6
+ export * from './types/tag.types';
@@ -0,0 +1,4 @@
1
+ import { ApiConfig, Config } from '../types';
2
+ export declare const API_BASE_URL = "https://api.tracelog.io";
3
+ export declare const DEFAULT_API_CONFIG: ApiConfig;
4
+ export declare const DEFAULT_CONFIG: (config: Config) => Config;
@@ -0,0 +1,14 @@
1
+ import { DEFAULT_SAMPLING_RATE } from './limits.constants';
2
+ import { DEFAULT_SESSION_TIMEOUT_MS } from './timing.constants';
3
+ export const API_BASE_URL = 'https://api.tracelog.io';
4
+ export const DEFAULT_API_CONFIG = {
5
+ samplingRate: DEFAULT_SAMPLING_RATE,
6
+ tags: [],
7
+ excludedUrlPaths: [],
8
+ };
9
+ export const DEFAULT_CONFIG = (config) => ({
10
+ ...DEFAULT_API_CONFIG,
11
+ ...config,
12
+ sessionTimeout: DEFAULT_SESSION_TIMEOUT_MS,
13
+ allowHttp: false,
14
+ });
@@ -0,0 +1,3 @@
1
+ export declare const HTML_DATA_ATTR_PREFIX = "data-tl";
2
+ export declare const INTERACTIVE_SELECTORS: readonly ["button", "a", "input[type=\"button\"]", "input[type=\"submit\"]", "input[type=\"reset\"]", "input[type=\"checkbox\"]", "input[type=\"radio\"]", "select", "textarea", "[role=\"button\"]", "[role=\"link\"]", "[role=\"tab\"]", "[role=\"menuitem\"]", "[role=\"option\"]", "[role=\"checkbox\"]", "[role=\"radio\"]", "[role=\"switch\"]", "[routerLink]", "[ng-click]", "[data-action]", "[data-click]", "[data-navigate]", "[data-toggle]", "[onclick]", ".btn", ".button", ".clickable", ".nav-link", ".menu-item", "[data-testid]", "[tabindex=\"0\"]"];
3
+ export declare const UTM_PARAMS: string[];
@@ -0,0 +1,38 @@
1
+ // Click tracking constants
2
+ export const HTML_DATA_ATTR_PREFIX = 'data-tl';
3
+ // Interactive element selectors for click tracking
4
+ export const INTERACTIVE_SELECTORS = [
5
+ 'button',
6
+ 'a',
7
+ 'input[type="button"]',
8
+ 'input[type="submit"]',
9
+ 'input[type="reset"]',
10
+ 'input[type="checkbox"]',
11
+ 'input[type="radio"]',
12
+ 'select',
13
+ 'textarea',
14
+ '[role="button"]',
15
+ '[role="link"]',
16
+ '[role="tab"]',
17
+ '[role="menuitem"]',
18
+ '[role="option"]',
19
+ '[role="checkbox"]',
20
+ '[role="radio"]',
21
+ '[role="switch"]',
22
+ '[routerLink]',
23
+ '[ng-click]',
24
+ '[data-action]',
25
+ '[data-click]',
26
+ '[data-navigate]',
27
+ '[data-toggle]',
28
+ '[onclick]',
29
+ '.btn',
30
+ '.button',
31
+ '.clickable',
32
+ '.nav-link',
33
+ '.menu-item',
34
+ '[data-testid]',
35
+ '[tabindex="0"]',
36
+ ];
37
+ // UTM parameters for tracking
38
+ export const UTM_PARAMS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
@@ -0,0 +1,8 @@
1
+ export * from './api.constants';
2
+ export * from './browser.constants';
3
+ export * from './initialization.constants';
4
+ export * from './limits.constants';
5
+ export * from './security.constants';
6
+ export * from './storage.constants';
7
+ export * from './timing.constants';
8
+ export * from './validation.constants';
@@ -0,0 +1,8 @@
1
+ export * from './api.constants';
2
+ export * from './browser.constants';
3
+ export * from './initialization.constants';
4
+ export * from './limits.constants';
5
+ export * from './security.constants';
6
+ export * from './storage.constants';
7
+ export * from './timing.constants';
8
+ export * from './validation.constants';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Constants for initialization and reliability patterns
3
+ * These values control initialization behavior, retry logic, and circuit breaker patterns
4
+ */
5
+ export declare const INITIALIZATION_CONSTANTS: {
6
+ /** Maximum number of retries when waiting for concurrent initialization */
7
+ readonly MAX_CONCURRENT_RETRIES: 20;
8
+ /** Delay between retries when waiting for concurrent initialization (ms) */
9
+ readonly CONCURRENT_RETRY_DELAY_MS: 50;
10
+ /** Timeout for overall initialization process (ms) */
11
+ readonly INITIALIZATION_TIMEOUT_MS: 10000;
12
+ };
13
+ export declare const CIRCUIT_BREAKER_CONSTANTS: {
14
+ /** Maximum number of consecutive failures before opening circuit */
15
+ readonly MAX_FAILURES: 10;
16
+ /** Initial backoff delay when circuit opens (ms) */
17
+ readonly INITIAL_BACKOFF_DELAY_MS: 1000;
18
+ /** Maximum backoff delay (ms) */
19
+ readonly MAX_BACKOFF_DELAY_MS: 30000;
20
+ /** Backoff multiplier for exponential backoff */
21
+ readonly BACKOFF_MULTIPLIER: 2;
22
+ /** Time-based recovery period for circuit breaker (ms) */
23
+ readonly RECOVERY_TIME_MS: 30000;
24
+ };
25
+ export declare const SESSION_SYNC_CONSTANTS: {
26
+ /** Timeout for session synchronization operations (ms) */
27
+ readonly SYNC_TIMEOUT_MS: 2000;
28
+ /** Maximum retry attempts for session operations */
29
+ readonly MAX_RETRY_ATTEMPTS: 3;
30
+ /** Delay before cleanup operations (ms) */
31
+ readonly CLEANUP_DELAY_MS: 100;
32
+ };
33
+ export declare const CROSS_TAB_CONSTANTS: {
34
+ /** Flag to prevent concurrent cross-tab manager initialization */
35
+ readonly INITIALIZATION_LOCK_TIMEOUT_MS: 5000;
36
+ };
37
+ export declare const SCROLL_SUPPRESSION_CONSTANTS: {
38
+ /** Multiplier for scroll debounce time when suppressing scroll events */
39
+ readonly SUPPRESS_MULTIPLIER: 2;
40
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Constants for initialization and reliability patterns
3
+ * These values control initialization behavior, retry logic, and circuit breaker patterns
4
+ */
5
+ // Initialization retry constants
6
+ export const INITIALIZATION_CONSTANTS = {
7
+ /** Maximum number of retries when waiting for concurrent initialization */
8
+ MAX_CONCURRENT_RETRIES: 20,
9
+ /** Delay between retries when waiting for concurrent initialization (ms) */
10
+ CONCURRENT_RETRY_DELAY_MS: 50,
11
+ /** Timeout for overall initialization process (ms) */
12
+ INITIALIZATION_TIMEOUT_MS: 10000,
13
+ };
14
+ // Circuit breaker constants
15
+ export const CIRCUIT_BREAKER_CONSTANTS = {
16
+ /** Maximum number of consecutive failures before opening circuit */
17
+ MAX_FAILURES: 10,
18
+ /** Initial backoff delay when circuit opens (ms) */
19
+ INITIAL_BACKOFF_DELAY_MS: 1000,
20
+ /** Maximum backoff delay (ms) */
21
+ MAX_BACKOFF_DELAY_MS: 30000,
22
+ /** Backoff multiplier for exponential backoff */
23
+ BACKOFF_MULTIPLIER: 2,
24
+ /** Time-based recovery period for circuit breaker (ms) */
25
+ RECOVERY_TIME_MS: 30000, // 30 seconds
26
+ };
27
+ // Session management constants
28
+ export const SESSION_SYNC_CONSTANTS = {
29
+ /** Timeout for session synchronization operations (ms) */
30
+ SYNC_TIMEOUT_MS: 2000,
31
+ /** Maximum retry attempts for session operations */
32
+ MAX_RETRY_ATTEMPTS: 3,
33
+ /** Delay before cleanup operations (ms) */
34
+ CLEANUP_DELAY_MS: 100,
35
+ };
36
+ // Cross-tab coordination constants
37
+ export const CROSS_TAB_CONSTANTS = {
38
+ /** Flag to prevent concurrent cross-tab manager initialization */
39
+ INITIALIZATION_LOCK_TIMEOUT_MS: 5000,
40
+ };
41
+ // Scroll suppression constants
42
+ export const SCROLL_SUPPRESSION_CONSTANTS = {
43
+ /** Multiplier for scroll debounce time when suppressing scroll events */
44
+ SUPPRESS_MULTIPLIER: 2,
45
+ };
@@ -0,0 +1,25 @@
1
+ export declare const DEFAULT_MOTION_THRESHOLD = 2;
2
+ export declare const SIGNIFICANT_SCROLL_DELTA = 10;
3
+ export declare const DEFAULT_SAMPLING_RATE = 1;
4
+ export declare const MIN_SAMPLING_RATE = 0;
5
+ export declare const MAX_SAMPLING_RATE = 1;
6
+ export declare const BATCH_SIZE_THRESHOLD = 50;
7
+ export declare const MAX_EVENTS_QUEUE_LENGTH = 500;
8
+ export declare const MIN_SESSION_TIMEOUT_MS = 30000;
9
+ export declare const MAX_SESSION_TIMEOUT_MS = 86400000;
10
+ export declare const MAX_CUSTOM_EVENT_NAME_LENGTH = 120;
11
+ export declare const MAX_CUSTOM_EVENT_STRING_SIZE: number;
12
+ export declare const MAX_CUSTOM_EVENT_KEYS = 10;
13
+ export declare const MAX_CUSTOM_EVENT_ARRAY_SIZE = 10;
14
+ export declare const MAX_TEXT_LENGTH = 255;
15
+ export declare const MAX_STRING_LENGTH = 1000;
16
+ export declare const MAX_ARRAY_LENGTH = 100;
17
+ export declare const MAX_OBJECT_DEPTH = 3;
18
+ export declare const PRECISION_TWO_DECIMALS: 2;
19
+ export declare const PRECISION_FOUR_DECIMALS: 4;
20
+ export declare const WEB_VITALS_SAMPLING: 0.75;
21
+ export declare const WEB_VITALS_LONG_TASK_SAMPLING: 0.2;
22
+ export declare const SYNC_XHR_TIMEOUT_MS = 2000;
23
+ export declare const MAX_FINGERPRINTS = 1000;
24
+ export declare const FINGERPRINT_CLEANUP_MULTIPLIER = 10;
25
+ export declare const CLICK_COORDINATE_PRECISION = 10;
@@ -0,0 +1,37 @@
1
+ // Motion and interaction thresholds
2
+ export const DEFAULT_MOTION_THRESHOLD = 2;
3
+ export const SIGNIFICANT_SCROLL_DELTA = 10;
4
+ // Sampling and rate limits
5
+ export const DEFAULT_SAMPLING_RATE = 1;
6
+ export const MIN_SAMPLING_RATE = 0;
7
+ export const MAX_SAMPLING_RATE = 1;
8
+ // Queue and batch limits
9
+ export const BATCH_SIZE_THRESHOLD = 50;
10
+ export const MAX_EVENTS_QUEUE_LENGTH = 500;
11
+ // Session timeout validation limits
12
+ export const MIN_SESSION_TIMEOUT_MS = 30000; // 30 seconds minimum
13
+ export const MAX_SESSION_TIMEOUT_MS = 86400000; // 24 hours maximum
14
+ // Custom event validation limits
15
+ export const MAX_CUSTOM_EVENT_NAME_LENGTH = 120;
16
+ export const MAX_CUSTOM_EVENT_STRING_SIZE = 8 * 1024; // 8KB
17
+ export const MAX_CUSTOM_EVENT_KEYS = 10;
18
+ export const MAX_CUSTOM_EVENT_ARRAY_SIZE = 10;
19
+ // Text content limits
20
+ export const MAX_TEXT_LENGTH = 255; // For click tracking text content
21
+ // Data sanitization limits
22
+ export const MAX_STRING_LENGTH = 1000;
23
+ export const MAX_ARRAY_LENGTH = 100;
24
+ export const MAX_OBJECT_DEPTH = 3;
25
+ // Precision for numeric metrics
26
+ export const PRECISION_TWO_DECIMALS = 2;
27
+ export const PRECISION_FOUR_DECIMALS = 4;
28
+ // Web vitals sampling
29
+ export const WEB_VITALS_SAMPLING = 0.75;
30
+ export const WEB_VITALS_LONG_TASK_SAMPLING = 0.2;
31
+ // Sync XHR timeout
32
+ export const SYNC_XHR_TIMEOUT_MS = 2000; // 2 seconds
33
+ // Event fingerprint management
34
+ export const MAX_FINGERPRINTS = 1000; // Maximum fingerprints stored before cleanup
35
+ export const FINGERPRINT_CLEANUP_MULTIPLIER = 10; // Cleanup fingerprints older than 10x threshold
36
+ // Click coordinate precision
37
+ export const CLICK_COORDINATE_PRECISION = 10; // Round click coordinates to nearest 10px
@@ -0,0 +1 @@
1
+ export declare const XSS_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
@@ -0,0 +1,9 @@
1
+ // XSS protection patterns
2
+ export const XSS_PATTERNS = [
3
+ /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
4
+ /javascript:/gi,
5
+ /on\w+\s*=/gi,
6
+ /<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,
7
+ /<embed\b[^>]*>/gi,
8
+ /<object\b[^<]*(?:(?!<\/object>)<[^<]*)*<\/object>/gi,
9
+ ];
@@ -0,0 +1,9 @@
1
+ export declare const STORAGE_BASE_KEY = "tl";
2
+ export declare const USER_ID_KEY: (id: string) => string;
3
+ export declare const QUEUE_KEY: (id: string) => string;
4
+ export declare const SESSION_STORAGE_KEY: (id: string) => string;
5
+ export declare const CROSS_TAB_SESSION_KEY: (id: string) => string;
6
+ export declare const TAB_INFO_KEY: (id: string) => string;
7
+ export declare const TAB_SPECIFIC_INFO_KEY: (projectId: string, tabId: string) => string;
8
+ export declare const SESSION_RECOVERY_KEY: (id: string) => string;
9
+ export declare const BROADCAST_CHANNEL_NAME: (id: string) => string;
@@ -0,0 +1,11 @@
1
+ export const STORAGE_BASE_KEY = 'tl';
2
+ export const USER_ID_KEY = (id) => (id ? `${STORAGE_BASE_KEY}:${id}:uid` : `${STORAGE_BASE_KEY}:uid`);
3
+ export const QUEUE_KEY = (id) => (id ? `${STORAGE_BASE_KEY}:${id}:queue` : `${STORAGE_BASE_KEY}:queue`);
4
+ export const SESSION_STORAGE_KEY = (id) => id ? `${STORAGE_BASE_KEY}:${id}:session` : `${STORAGE_BASE_KEY}:session`;
5
+ // Cross-tab session management storage keys
6
+ export const CROSS_TAB_SESSION_KEY = (id) => id ? `${STORAGE_BASE_KEY}:${id}:cross_tab_session` : `${STORAGE_BASE_KEY}:cross_tab_session`;
7
+ export const TAB_INFO_KEY = (id) => id ? `${STORAGE_BASE_KEY}:${id}:tab_info` : `${STORAGE_BASE_KEY}:tab_info`;
8
+ export const TAB_SPECIFIC_INFO_KEY = (projectId, tabId) => `${STORAGE_BASE_KEY}:${projectId}:tab:${tabId}:info`;
9
+ export const SESSION_RECOVERY_KEY = (id) => id ? `${STORAGE_BASE_KEY}:${id}:recovery` : `${STORAGE_BASE_KEY}:recovery`;
10
+ // BroadcastChannel name for cross-tab communication
11
+ export const BROADCAST_CHANNEL_NAME = (id) => id ? `${STORAGE_BASE_KEY}:${id}:broadcast` : `${STORAGE_BASE_KEY}:broadcast`;
@@ -0,0 +1,22 @@
1
+ export declare const DEFAULT_SESSION_TIMEOUT_MS: number;
2
+ export declare const SESSION_HEARTBEAT_INTERVAL_MS = 30000;
3
+ export declare const DEFAULT_THROTTLE_DELAY_MS = 1000;
4
+ export declare const SCROLL_DEBOUNCE_TIME_MS = 250;
5
+ export declare const DEFAULT_VISIBILITY_TIMEOUT_MS = 2000;
6
+ export declare const DUPLICATE_EVENT_THRESHOLD_MS = 1000;
7
+ export declare const EVENT_SENT_INTERVAL_MS = 10000;
8
+ export declare const EVENT_SENT_INTERVAL_TEST_MS = 2500;
9
+ export declare const RETRY_BACKOFF_INITIAL = 1000;
10
+ export declare const RETRY_BACKOFF_MAX = 30000;
11
+ export declare const RATE_LIMIT_INTERVAL = 1000;
12
+ export declare const EVENT_EXPIRY_HOURS = 24;
13
+ export declare const EVENT_PERSISTENCE_MAX_AGE_MS: number;
14
+ export declare const LONG_TASK_THROTTLE_MS = 1000;
15
+ export declare const SESSION_END_PRIORITY_DELAY_MS = 100;
16
+ export declare const TAB_HEARTBEAT_INTERVAL_MS = 5000;
17
+ export declare const TAB_ELECTION_TIMEOUT_MS = 2000;
18
+ export declare const TAB_CLEANUP_DELAY_MS = 1000;
19
+ export declare const SESSION_RECOVERY_WINDOW_MULTIPLIER = 2;
20
+ export declare const MAX_SESSION_RECOVERY_ATTEMPTS = 3;
21
+ export declare const MAX_SESSION_RECOVERY_WINDOW_MS: number;
22
+ export declare const MIN_SESSION_RECOVERY_WINDOW_MS: number;
@@ -0,0 +1,31 @@
1
+ // Session and timeout constants
2
+ export const DEFAULT_SESSION_TIMEOUT_MS = 15 * 60 * 1000;
3
+ export const SESSION_HEARTBEAT_INTERVAL_MS = 30000;
4
+ // Throttling and debouncing constants
5
+ export const DEFAULT_THROTTLE_DELAY_MS = 1000;
6
+ export const SCROLL_DEBOUNCE_TIME_MS = 250;
7
+ export const DEFAULT_VISIBILITY_TIMEOUT_MS = 2000;
8
+ export const DUPLICATE_EVENT_THRESHOLD_MS = 1000;
9
+ // Event processing intervals
10
+ export const EVENT_SENT_INTERVAL_MS = 10000;
11
+ export const EVENT_SENT_INTERVAL_TEST_MS = 2500;
12
+ // Network timing
13
+ export const RETRY_BACKOFF_INITIAL = 1000; // 1 second
14
+ export const RETRY_BACKOFF_MAX = 30000; // 30 seconds
15
+ export const RATE_LIMIT_INTERVAL = 1000; // 1 second
16
+ // Event expiry
17
+ export const EVENT_EXPIRY_HOURS = 24;
18
+ export const EVENT_PERSISTENCE_MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours
19
+ // Performance metrics
20
+ export const LONG_TASK_THROTTLE_MS = DEFAULT_THROTTLE_DELAY_MS;
21
+ // Session end coordination
22
+ export const SESSION_END_PRIORITY_DELAY_MS = 100;
23
+ // Cross-tab session management
24
+ export const TAB_HEARTBEAT_INTERVAL_MS = 5000; // 5 seconds
25
+ export const TAB_ELECTION_TIMEOUT_MS = 2000; // 2 seconds
26
+ export const TAB_CLEANUP_DELAY_MS = 1000; // 1 second
27
+ // Session recovery
28
+ export const SESSION_RECOVERY_WINDOW_MULTIPLIER = 2; // 2x session timeout
29
+ export const MAX_SESSION_RECOVERY_ATTEMPTS = 3;
30
+ export const MAX_SESSION_RECOVERY_WINDOW_MS = 24 * 60 * 60 * 1000; // 24 hours max
31
+ export const MIN_SESSION_RECOVERY_WINDOW_MS = 2 * 60 * 1000; // 2 minutes minimum
@@ -0,0 +1,13 @@
1
+ import { ApiConfig } from '../types';
2
+ export declare const ALLOWED_API_CONFIG_KEYS: Set<keyof ApiConfig>;
3
+ export declare const VALIDATION_MESSAGES: {
4
+ readonly MISSING_PROJECT_ID: "Project ID is required";
5
+ readonly PROJECT_ID_EMPTY_AFTER_TRIM: "Project ID is required";
6
+ readonly INVALID_SESSION_TIMEOUT: "Session timeout must be between 30000ms (30 seconds) and 86400000ms (24 hours)";
7
+ readonly INVALID_SAMPLING_RATE: "Sampling rate must be between 0 and 1";
8
+ readonly INVALID_ERROR_SAMPLING_RATE: "Error sampling must be between 0 and 1";
9
+ readonly INVALID_GOOGLE_ANALYTICS_ID: "Google Analytics measurement ID is required when integration is enabled";
10
+ readonly INVALID_SCROLL_CONTAINER_SELECTORS: "Scroll container selectors must be valid CSS selectors";
11
+ readonly INVALID_GLOBAL_METADATA: "Global metadata must be an object";
12
+ readonly INVALID_SENSITIVE_QUERY_PARAMS: "Sensitive query params must be an array of strings";
13
+ };
@@ -0,0 +1,28 @@
1
+ import { MIN_SESSION_TIMEOUT_MS, MAX_SESSION_TIMEOUT_MS, MIN_SAMPLING_RATE, MAX_SAMPLING_RATE, } from './limits.constants';
2
+ // Allowed API config keys for runtime validation
3
+ export const ALLOWED_API_CONFIG_KEYS = new Set([
4
+ 'mode',
5
+ 'tags',
6
+ 'samplingRate',
7
+ 'excludedUrlPaths',
8
+ 'ipExcluded',
9
+ ]);
10
+ // Validation error messages - standardized across all layers
11
+ export const VALIDATION_MESSAGES = {
12
+ // Project ID validation - consistent message across all layers
13
+ MISSING_PROJECT_ID: 'Project ID is required',
14
+ PROJECT_ID_EMPTY_AFTER_TRIM: 'Project ID is required',
15
+ // Session timeout validation
16
+ INVALID_SESSION_TIMEOUT: `Session timeout must be between ${MIN_SESSION_TIMEOUT_MS}ms (30 seconds) and ${MAX_SESSION_TIMEOUT_MS}ms (24 hours)`,
17
+ // Sampling rate validation
18
+ INVALID_SAMPLING_RATE: `Sampling rate must be between ${MIN_SAMPLING_RATE} and ${MAX_SAMPLING_RATE}`,
19
+ INVALID_ERROR_SAMPLING_RATE: 'Error sampling must be between 0 and 1',
20
+ // Integration validation
21
+ INVALID_GOOGLE_ANALYTICS_ID: 'Google Analytics measurement ID is required when integration is enabled',
22
+ // UI validation
23
+ INVALID_SCROLL_CONTAINER_SELECTORS: 'Scroll container selectors must be valid CSS selectors',
24
+ // Global metadata validation
25
+ INVALID_GLOBAL_METADATA: 'Global metadata must be an object',
26
+ // Array validation
27
+ INVALID_SENSITIVE_QUERY_PARAMS: 'Sensitive query params must be an array of strings',
28
+ };