@tracelog/lib 0.0.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +58 -24
  2. package/dist/browser/tracelog.js +1934 -3226
  3. package/dist/cjs/api.d.ts +33 -19
  4. package/dist/cjs/api.js +111 -156
  5. package/dist/cjs/app.constants.d.ts +80 -1
  6. package/dist/cjs/app.constants.js +90 -3
  7. package/dist/cjs/app.d.ts +29 -44
  8. package/dist/cjs/app.js +114 -212
  9. package/dist/cjs/app.types.d.ts +2 -7
  10. package/dist/cjs/app.types.js +10 -21
  11. package/dist/cjs/constants/api.constants.js +11 -5
  12. package/dist/cjs/constants/config.constants.d.ts +75 -0
  13. package/dist/cjs/constants/config.constants.js +178 -0
  14. package/dist/cjs/constants/error.constants.d.ts +29 -0
  15. package/dist/cjs/constants/error.constants.js +50 -0
  16. package/dist/cjs/constants/index.d.ts +3 -6
  17. package/dist/cjs/constants/index.js +3 -6
  18. package/dist/cjs/constants/performance.constants.d.ts +28 -0
  19. package/dist/cjs/constants/performance.constants.js +43 -0
  20. package/dist/cjs/handlers/click.handler.d.ts +1 -0
  21. package/dist/cjs/handlers/click.handler.js +30 -49
  22. package/dist/cjs/handlers/error.handler.d.ts +11 -6
  23. package/dist/cjs/handlers/error.handler.js +91 -51
  24. package/dist/cjs/handlers/page-view.handler.js +38 -29
  25. package/dist/cjs/handlers/performance.handler.d.ts +3 -0
  26. package/dist/cjs/handlers/performance.handler.js +76 -37
  27. package/dist/cjs/handlers/scroll.handler.d.ts +15 -0
  28. package/dist/cjs/handlers/scroll.handler.js +105 -31
  29. package/dist/cjs/handlers/session.handler.d.ts +6 -20
  30. package/dist/cjs/handlers/session.handler.js +38 -326
  31. package/dist/cjs/integrations/google-analytics.integration.d.ts +0 -1
  32. package/dist/cjs/integrations/google-analytics.integration.js +27 -98
  33. package/dist/cjs/listeners/input-listener-managers.d.ts +18 -9
  34. package/dist/cjs/listeners/input-listener-managers.js +24 -33
  35. package/dist/cjs/listeners/touch-listener-manager.d.ts +1 -3
  36. package/dist/cjs/listeners/touch-listener-manager.js +1 -23
  37. package/dist/cjs/listeners/visibility-listener-manager.d.ts +1 -4
  38. package/dist/cjs/listeners/visibility-listener-manager.js +6 -42
  39. package/dist/cjs/managers/api.manager.d.ts +13 -3
  40. package/dist/cjs/managers/api.manager.js +35 -5
  41. package/dist/cjs/managers/config.manager.d.ts +53 -3
  42. package/dist/cjs/managers/config.manager.js +131 -62
  43. package/dist/cjs/managers/event.manager.d.ts +57 -36
  44. package/dist/cjs/managers/event.manager.js +266 -417
  45. package/dist/cjs/managers/sender.manager.d.ts +40 -22
  46. package/dist/cjs/managers/sender.manager.js +200 -198
  47. package/dist/cjs/managers/session.manager.d.ts +80 -66
  48. package/dist/cjs/managers/session.manager.js +267 -522
  49. package/dist/cjs/managers/state.manager.d.ts +33 -0
  50. package/dist/cjs/managers/state.manager.js +79 -6
  51. package/dist/cjs/managers/storage.manager.d.ts +26 -2
  52. package/dist/cjs/managers/storage.manager.js +67 -34
  53. package/dist/cjs/managers/tags.manager.d.ts +31 -7
  54. package/dist/cjs/managers/tags.manager.js +123 -241
  55. package/dist/cjs/managers/user.manager.d.ts +14 -5
  56. package/dist/cjs/managers/user.manager.js +17 -9
  57. package/dist/cjs/public-api.d.ts +10 -1
  58. package/dist/cjs/public-api.js +18 -24
  59. package/dist/cjs/test-bridge.d.ts +48 -0
  60. package/dist/cjs/test-bridge.js +110 -0
  61. package/dist/cjs/types/api.types.d.ts +21 -6
  62. package/dist/cjs/types/api.types.js +21 -6
  63. package/dist/cjs/types/config.types.d.ts +22 -84
  64. package/dist/cjs/types/emitter.types.d.ts +11 -0
  65. package/dist/cjs/types/emitter.types.js +8 -0
  66. package/dist/cjs/types/event.types.d.ts +8 -11
  67. package/dist/cjs/types/index.d.ts +3 -1
  68. package/dist/cjs/types/index.js +3 -1
  69. package/dist/cjs/types/queue.types.d.ts +1 -0
  70. package/dist/cjs/types/session.types.d.ts +0 -64
  71. package/dist/cjs/types/state.types.d.ts +1 -0
  72. package/dist/cjs/types/test-bridge.types.d.ts +38 -0
  73. package/dist/cjs/types/validation-error.types.d.ts +7 -0
  74. package/dist/cjs/types/validation-error.types.js +11 -1
  75. package/dist/cjs/types/window.types.d.ts +1 -8
  76. package/dist/cjs/utils/data/uuid.utils.d.ts +1 -1
  77. package/dist/cjs/utils/data/uuid.utils.js +7 -5
  78. package/dist/cjs/utils/emitter.utils.d.ts +8 -0
  79. package/dist/cjs/utils/emitter.utils.js +33 -0
  80. package/dist/cjs/utils/index.d.ts +1 -0
  81. package/dist/cjs/utils/index.js +1 -0
  82. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +10 -51
  83. package/dist/cjs/utils/logging/debug-logger.utils.js +36 -127
  84. package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +4 -0
  85. package/dist/cjs/utils/network/fetch-with-timeout.utils.js +25 -0
  86. package/dist/cjs/utils/network/index.d.ts +1 -0
  87. package/dist/cjs/utils/network/index.js +1 -0
  88. package/dist/cjs/utils/network/url.utils.js +2 -42
  89. package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -8
  90. package/dist/cjs/utils/security/sanitize.utils.js +7 -41
  91. package/dist/cjs/utils/validations/config-validations.utils.d.ts +7 -0
  92. package/dist/cjs/utils/validations/config-validations.utils.js +77 -22
  93. package/dist/esm/api.d.ts +33 -19
  94. package/dist/esm/api.js +105 -118
  95. package/dist/esm/app.constants.d.ts +80 -1
  96. package/dist/esm/app.constants.js +89 -1
  97. package/dist/esm/app.d.ts +29 -44
  98. package/dist/esm/app.js +115 -213
  99. package/dist/esm/app.types.d.ts +2 -7
  100. package/dist/esm/app.types.js +1 -7
  101. package/dist/esm/constants/api.constants.js +10 -4
  102. package/dist/esm/constants/config.constants.d.ts +75 -0
  103. package/dist/esm/constants/config.constants.js +174 -0
  104. package/dist/esm/constants/error.constants.d.ts +29 -0
  105. package/dist/esm/constants/error.constants.js +47 -0
  106. package/dist/esm/constants/index.d.ts +3 -6
  107. package/dist/esm/constants/index.js +3 -6
  108. package/dist/esm/constants/performance.constants.d.ts +28 -0
  109. package/dist/esm/constants/performance.constants.js +40 -0
  110. package/dist/esm/handlers/click.handler.d.ts +1 -0
  111. package/dist/esm/handlers/click.handler.js +30 -49
  112. package/dist/esm/handlers/error.handler.d.ts +11 -6
  113. package/dist/esm/handlers/error.handler.js +91 -51
  114. package/dist/esm/handlers/page-view.handler.js +38 -29
  115. package/dist/esm/handlers/performance.handler.d.ts +3 -0
  116. package/dist/esm/handlers/performance.handler.js +71 -32
  117. package/dist/esm/handlers/scroll.handler.d.ts +15 -0
  118. package/dist/esm/handlers/scroll.handler.js +106 -32
  119. package/dist/esm/handlers/session.handler.d.ts +6 -20
  120. package/dist/esm/handlers/session.handler.js +38 -326
  121. package/dist/esm/integrations/google-analytics.integration.d.ts +0 -1
  122. package/dist/esm/integrations/google-analytics.integration.js +27 -98
  123. package/dist/esm/listeners/input-listener-managers.d.ts +18 -9
  124. package/dist/esm/listeners/input-listener-managers.js +23 -32
  125. package/dist/esm/listeners/touch-listener-manager.d.ts +1 -3
  126. package/dist/esm/listeners/touch-listener-manager.js +1 -23
  127. package/dist/esm/listeners/visibility-listener-manager.d.ts +1 -4
  128. package/dist/esm/listeners/visibility-listener-manager.js +6 -42
  129. package/dist/esm/managers/api.manager.d.ts +13 -3
  130. package/dist/esm/managers/api.manager.js +34 -3
  131. package/dist/esm/managers/config.manager.d.ts +53 -3
  132. package/dist/esm/managers/config.manager.js +133 -64
  133. package/dist/esm/managers/event.manager.d.ts +57 -36
  134. package/dist/esm/managers/event.manager.js +268 -419
  135. package/dist/esm/managers/sender.manager.d.ts +40 -22
  136. package/dist/esm/managers/sender.manager.js +201 -199
  137. package/dist/esm/managers/session.manager.d.ts +80 -66
  138. package/dist/esm/managers/session.manager.js +269 -524
  139. package/dist/esm/managers/state.manager.d.ts +33 -0
  140. package/dist/esm/managers/state.manager.js +78 -6
  141. package/dist/esm/managers/storage.manager.d.ts +26 -2
  142. package/dist/esm/managers/storage.manager.js +66 -33
  143. package/dist/esm/managers/tags.manager.d.ts +31 -7
  144. package/dist/esm/managers/tags.manager.js +124 -242
  145. package/dist/esm/managers/user.manager.d.ts +14 -5
  146. package/dist/esm/managers/user.manager.js +17 -9
  147. package/dist/esm/public-api.d.ts +10 -1
  148. package/dist/esm/public-api.js +14 -1
  149. package/dist/esm/test-bridge.d.ts +48 -0
  150. package/dist/esm/test-bridge.js +106 -0
  151. package/dist/esm/types/api.types.d.ts +21 -6
  152. package/dist/esm/types/api.types.js +21 -6
  153. package/dist/esm/types/config.types.d.ts +22 -84
  154. package/dist/esm/types/emitter.types.d.ts +11 -0
  155. package/dist/esm/types/emitter.types.js +5 -0
  156. package/dist/esm/types/event.types.d.ts +8 -11
  157. package/dist/esm/types/index.d.ts +3 -1
  158. package/dist/esm/types/index.js +3 -1
  159. package/dist/esm/types/queue.types.d.ts +1 -0
  160. package/dist/esm/types/session.types.d.ts +0 -64
  161. package/dist/esm/types/state.types.d.ts +1 -0
  162. package/dist/esm/types/test-bridge.types.d.ts +38 -0
  163. package/dist/esm/types/validation-error.types.d.ts +7 -0
  164. package/dist/esm/types/validation-error.types.js +9 -0
  165. package/dist/esm/types/window.types.d.ts +1 -8
  166. package/dist/esm/utils/data/uuid.utils.d.ts +1 -1
  167. package/dist/esm/utils/data/uuid.utils.js +7 -5
  168. package/dist/esm/utils/emitter.utils.d.ts +8 -0
  169. package/dist/esm/utils/emitter.utils.js +29 -0
  170. package/dist/esm/utils/index.d.ts +1 -0
  171. package/dist/esm/utils/index.js +1 -0
  172. package/dist/esm/utils/logging/debug-logger.utils.d.ts +10 -51
  173. package/dist/esm/utils/logging/debug-logger.utils.js +36 -127
  174. package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +4 -0
  175. package/dist/esm/utils/network/fetch-with-timeout.utils.js +22 -0
  176. package/dist/esm/utils/network/index.d.ts +1 -0
  177. package/dist/esm/utils/network/index.js +1 -0
  178. package/dist/esm/utils/network/url.utils.js +2 -42
  179. package/dist/esm/utils/security/sanitize.utils.d.ts +1 -8
  180. package/dist/esm/utils/security/sanitize.utils.js +6 -39
  181. package/dist/esm/utils/validations/config-validations.utils.d.ts +7 -0
  182. package/dist/esm/utils/validations/config-validations.utils.js +76 -22
  183. package/package.json +23 -16
  184. package/dist/browser/web-vitals-CCnqwnC8.mjs +0 -198
  185. package/dist/cjs/constants/browser.constants.d.ts +0 -3
  186. package/dist/cjs/constants/browser.constants.js +0 -41
  187. package/dist/cjs/constants/initialization.constants.d.ts +0 -40
  188. package/dist/cjs/constants/initialization.constants.js +0 -48
  189. package/dist/cjs/constants/limits.constants.d.ts +0 -25
  190. package/dist/cjs/constants/limits.constants.js +0 -40
  191. package/dist/cjs/constants/security.constants.d.ts +0 -1
  192. package/dist/cjs/constants/security.constants.js +0 -12
  193. package/dist/cjs/constants/timing.constants.d.ts +0 -22
  194. package/dist/cjs/constants/timing.constants.js +0 -34
  195. package/dist/cjs/constants/validation.constants.d.ts +0 -13
  196. package/dist/cjs/constants/validation.constants.js +0 -31
  197. package/dist/cjs/handlers/network.handler.d.ts +0 -16
  198. package/dist/cjs/handlers/network.handler.js +0 -136
  199. package/dist/cjs/managers/cross-tab-session.manager.d.ts +0 -170
  200. package/dist/cjs/managers/cross-tab-session.manager.js +0 -730
  201. package/dist/cjs/managers/sampling.manager.d.ts +0 -8
  202. package/dist/cjs/managers/sampling.manager.js +0 -53
  203. package/dist/cjs/managers/session-recovery.manager.d.ts +0 -65
  204. package/dist/cjs/managers/session-recovery.manager.js +0 -237
  205. package/dist/cjs/types/web-vitals.types.d.ts +0 -6
  206. package/dist/esm/constants/browser.constants.d.ts +0 -3
  207. package/dist/esm/constants/browser.constants.js +0 -38
  208. package/dist/esm/constants/initialization.constants.d.ts +0 -40
  209. package/dist/esm/constants/initialization.constants.js +0 -45
  210. package/dist/esm/constants/limits.constants.d.ts +0 -25
  211. package/dist/esm/constants/limits.constants.js +0 -37
  212. package/dist/esm/constants/security.constants.d.ts +0 -1
  213. package/dist/esm/constants/security.constants.js +0 -9
  214. package/dist/esm/constants/timing.constants.d.ts +0 -22
  215. package/dist/esm/constants/timing.constants.js +0 -31
  216. package/dist/esm/constants/validation.constants.d.ts +0 -13
  217. package/dist/esm/constants/validation.constants.js +0 -28
  218. package/dist/esm/handlers/network.handler.d.ts +0 -16
  219. package/dist/esm/handlers/network.handler.js +0 -132
  220. package/dist/esm/managers/cross-tab-session.manager.d.ts +0 -170
  221. package/dist/esm/managers/cross-tab-session.manager.js +0 -726
  222. package/dist/esm/managers/sampling.manager.d.ts +0 -8
  223. package/dist/esm/managers/sampling.manager.js +0 -49
  224. package/dist/esm/managers/session-recovery.manager.d.ts +0 -65
  225. package/dist/esm/managers/session-recovery.manager.js +0 -233
  226. package/dist/esm/types/web-vitals.types.d.ts +0 -6
  227. /package/dist/cjs/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
  228. /package/dist/esm/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
package/dist/cjs/app.js CHANGED
@@ -10,263 +10,165 @@ const session_handler_1 = require("./handlers/session.handler");
10
10
  const page_view_handler_1 = require("./handlers/page-view.handler");
11
11
  const click_handler_1 = require("./handlers/click.handler");
12
12
  const scroll_handler_1 = require("./handlers/scroll.handler");
13
- const validations_1 = require("./utils/validations");
14
- const event_types_1 = require("./types/event.types");
13
+ const types_1 = require("./types");
15
14
  const google_analytics_integration_1 = require("./integrations/google-analytics.integration");
16
15
  const utils_1 = require("./utils");
17
16
  const storage_manager_1 = require("./managers/storage.manager");
18
- const constants_1 = require("./constants");
17
+ const config_constants_1 = require("./constants/config.constants");
19
18
  const performance_handler_1 = require("./handlers/performance.handler");
20
19
  const error_handler_1 = require("./handlers/error.handler");
21
- const network_handler_1 = require("./handlers/network.handler");
22
- const validation_error_types_1 = require("./types/validation-error.types");
23
- const logging_1 = require("./utils/logging");
20
+ /**
21
+ * Main application class for TraceLog analytics
22
+ * Orchestrates event tracking, session management, and integrations
23
+ */
24
24
  class App extends state_manager_1.StateManager {
25
25
  constructor() {
26
26
  super(...arguments);
27
27
  this.isInitialized = false;
28
- this.googleAnalytics = null;
29
28
  this.suppressNextScrollTimer = null;
29
+ this.emitter = new utils_1.Emitter();
30
+ this.managers = {};
31
+ this.handlers = {};
32
+ this.integrations = {};
30
33
  }
31
- /**
32
- * Returns the initialization status of the app
33
- * @returns true if the app is fully initialized, false otherwise
34
- */
35
34
  get initialized() {
36
35
  return this.isInitialized;
37
36
  }
38
37
  async init(appConfig) {
39
38
  if (this.isInitialized) {
40
- logging_1.debugLog.debug('App', 'App already initialized, skipping re-initialization', { projectId: appConfig.id });
41
39
  return;
42
40
  }
43
- logging_1.debugLog.info('App', 'App initialization started', { projectId: appConfig.id });
44
- this.validateAppReadiness(appConfig);
41
+ if (!appConfig.id?.trim()) {
42
+ throw new Error('Project ID is required');
43
+ }
44
+ this.managers.storage = new storage_manager_1.StorageManager();
45
45
  try {
46
- this.initStorage();
47
- await this.setState(appConfig);
48
- await this.setIntegrations();
49
- this.setEventManager();
50
- await this.initHandlers();
51
- this.isInitialized = true;
52
- logging_1.debugLog.info('App', 'App initialization completed successfully', {
53
- projectId: appConfig.id,
46
+ await this.setupState(appConfig);
47
+ await this.setupIntegrations();
48
+ this.managers.event = new event_manager_1.EventManager(this.managers.storage, this.integrations.googleAnalytics, this.emitter);
49
+ this.initializeHandlers();
50
+ await this.managers.event.recoverPersistedEvents().catch(() => {
51
+ utils_1.debugLog.warn('App', 'Failed to recover persisted events');
54
52
  });
53
+ this.isInitialized = true;
55
54
  }
56
55
  catch (error) {
57
- this.isInitialized = false;
58
- logging_1.debugLog.error('App', 'App initialization failed', { projectId: appConfig.id, error });
59
- throw error;
60
- }
61
- }
62
- /**
63
- * Validates that the app is ready to initialize with the provided config
64
- * This is a lightweight runtime validation layer that ensures the app receives proper config
65
- * @param appConfig - The validated and normalized configuration
66
- * @throws {ProjectIdValidationError} If project ID is invalid at runtime
67
- */
68
- validateAppReadiness(appConfig) {
69
- // Lightweight validation - config should already be validated and normalized by api.ts
70
- if (!appConfig?.id) {
71
- logging_1.debugLog.clientError('App', 'Configuration integrity check failed - missing project ID', {
72
- hasConfig: !!appConfig,
73
- hasId: !!appConfig?.id,
74
- });
75
- throw new validation_error_types_1.ProjectIdValidationError('Configuration integrity check failed', 'app');
56
+ await this.destroy(true);
57
+ throw new Error(`TraceLog initialization failed: ${error}`);
76
58
  }
77
59
  }
78
60
  sendCustomEvent(name, metadata) {
79
- if (!this.eventManager) {
80
- logging_1.debugLog.warn('App', 'Custom event attempted before eventManager initialization', { eventName: name });
61
+ if (!this.managers.event) {
81
62
  return;
82
63
  }
83
- const { valid, error, sanitizedMetadata } = (0, validations_1.isEventValid)(name, metadata);
84
- if (valid) {
85
- logging_1.debugLog.debug('App', 'Custom event validated and queued', { eventName: name, hasMetadata: !!sanitizedMetadata });
86
- this.eventManager.track({
87
- type: event_types_1.EventType.CUSTOM,
88
- custom_event: {
89
- name,
90
- ...(sanitizedMetadata && { metadata: sanitizedMetadata }),
91
- },
92
- });
93
- }
94
- else {
95
- const currentMode = this.get('config')?.mode;
96
- logging_1.debugLog.clientError('App', `Custom event validation failed: ${error ?? 'unknown error'}`, {
97
- eventName: name,
98
- validationError: error,
99
- hasMetadata: !!metadata,
100
- mode: currentMode,
101
- });
102
- if (currentMode === 'qa' || currentMode === 'debug') {
103
- throw new Error(`custom event "${name}" validation failed (${error ?? 'unknown error'}). Please, review your event data and try again.`);
64
+ const { valid, error, sanitizedMetadata } = (0, utils_1.isEventValid)(name, metadata);
65
+ if (!valid) {
66
+ const config = this.get('config');
67
+ if (config?.mode === 'qa' || config?.mode === 'debug') {
68
+ throw new Error(`Custom event "${name}" validation failed: ${error}`);
104
69
  }
70
+ return;
105
71
  }
72
+ this.managers.event.track({
73
+ type: types_1.EventType.CUSTOM,
74
+ custom_event: {
75
+ name,
76
+ ...(sanitizedMetadata && { metadata: sanitizedMetadata }),
77
+ },
78
+ });
79
+ }
80
+ on(event, callback) {
81
+ this.emitter.on(event, callback);
82
+ }
83
+ off(event, callback) {
84
+ this.emitter.off(event, callback);
106
85
  }
107
- destroy() {
108
- if (!this.isInitialized) {
109
- logging_1.debugLog.warn('App', 'Destroy called but app was not initialized');
86
+ async destroy(force = false) {
87
+ if (!this.isInitialized && !force) {
110
88
  return;
111
89
  }
112
- logging_1.debugLog.info('App', 'App cleanup started');
113
- if (this.googleAnalytics) {
114
- this.googleAnalytics.cleanup();
115
- }
116
- if (this.sessionHandler) {
117
- this.sessionHandler.stopTracking();
118
- }
119
- if (this.pageViewHandler) {
120
- this.pageViewHandler.stopTracking();
121
- }
122
- if (this.clickHandler) {
123
- this.clickHandler.stopTracking();
124
- }
125
- if (this.scrollHandler) {
126
- this.scrollHandler.stopTracking();
127
- }
128
- if (this.performanceHandler) {
129
- this.performanceHandler.stopTracking();
130
- }
131
- if (this.errorHandler) {
132
- this.errorHandler.stopTracking();
133
- }
134
- if (this.networkHandler) {
135
- this.networkHandler.stopTracking();
136
- }
90
+ this.integrations.googleAnalytics?.cleanup();
91
+ const handlerCleanups = Object.values(this.handlers)
92
+ .filter(Boolean)
93
+ .map(async (handler) => {
94
+ try {
95
+ await handler.stopTracking();
96
+ }
97
+ catch {
98
+ utils_1.debugLog.warn('App', 'Failed to stop tracking');
99
+ }
100
+ });
101
+ await Promise.allSettled(handlerCleanups);
137
102
  if (this.suppressNextScrollTimer) {
138
103
  clearTimeout(this.suppressNextScrollTimer);
139
104
  this.suppressNextScrollTimer = null;
140
105
  }
141
- if (this.eventManager) {
142
- this.eventManager.stop();
143
- }
106
+ this.managers.event?.stop();
107
+ this.emitter.removeAllListeners();
144
108
  this.set('hasStartSession', false);
145
109
  this.set('suppressNextScroll', false);
146
110
  this.set('sessionId', null);
147
111
  this.isInitialized = false;
148
- logging_1.debugLog.info('App', 'App cleanup completed successfully');
149
- }
150
- async setState(appConfig) {
151
- this.setApiUrl(appConfig.id, appConfig.allowHttp);
152
- await this.setConfig(appConfig);
153
- this.setUserId();
154
- this.setDevice();
155
- this.setPageUrl();
112
+ this.handlers = {};
156
113
  }
157
- setApiUrl(id, allowHttp = false) {
158
- const apiManager = new api_manager_1.ApiManager();
159
- this.set('apiUrl', apiManager.getUrl(id, allowHttp));
160
- }
161
- async setConfig(appConfig) {
114
+ async setupState(appConfig) {
115
+ // Set API URL
116
+ const apiUrl = (0, api_manager_1.getApiUrlForProject)(appConfig.id, appConfig.allowHttp);
117
+ this.set('apiUrl', apiUrl);
118
+ // Get remote configuration
162
119
  const configManager = new config_manager_1.ConfigManager();
163
- const config = await configManager.get(this.get('apiUrl'), appConfig);
164
- this.set('config', config);
165
- }
166
- setUserId() {
167
- const userManager = new user_manager_1.UserManager(this.storageManager);
168
- const userId = userManager.getId();
120
+ const config = await configManager.get(apiUrl, appConfig);
121
+ const { config: normalizedConfig } = (0, utils_1.normalizeConfig)(config);
122
+ this.set('config', normalizedConfig);
123
+ // Set user ID
124
+ const userId = user_manager_1.UserManager.getId(this.managers.storage, normalizedConfig.id);
169
125
  this.set('userId', userId);
170
- }
171
- setDevice() {
172
- const device = (0, utils_1.getDeviceType)();
173
- this.set('device', device);
174
- }
175
- setPageUrl() {
176
- const initialUrl = (0, utils_1.normalizeUrl)(window.location.href, this.get('config').sensitiveQueryParams);
177
- this.set('pageUrl', initialUrl);
178
- }
179
- async setIntegrations() {
180
- const isIPExcluded = this.get('config').ipExcluded;
181
- const measurementId = this.get('config').integrations?.googleAnalytics?.measurementId;
182
- if (!isIPExcluded && measurementId?.trim()) {
183
- this.googleAnalytics = new google_analytics_integration_1.GoogleAnalyticsIntegration();
184
- await this.googleAnalytics.initialize();
185
- }
186
- }
187
- async initHandlers() {
188
- if (!this.eventManager) {
189
- throw new Error('EventManager must be initialized before handlers');
190
- }
191
- if (!this.storageManager) {
192
- throw new Error('StorageManager must be initialized before handlers');
193
- }
194
- this.initSessionHandler();
195
- this.initPageViewHandler();
196
- this.initClickHandler();
197
- this.initScrollHandler();
198
- await this.initPerformanceHandler();
199
- this.initErrorHandler();
200
- this.initNetworkHandler();
201
- }
202
- initStorage() {
203
- this.storageManager = new storage_manager_1.StorageManager();
204
- }
205
- setEventManager() {
206
- if (!this.storageManager) {
207
- throw new Error('StorageManager must be initialized before EventManager');
208
- }
209
- this.eventManager = new event_manager_1.EventManager(this.storageManager, this.googleAnalytics);
210
- }
211
- initSessionHandler() {
212
- if (!this.storageManager || !this.eventManager) {
213
- throw new Error('StorageManager and EventManager must be initialized before SessionHandler');
214
- }
215
- this.sessionHandler = new session_handler_1.SessionHandler(this.storageManager, this.eventManager);
216
- this.sessionHandler.startTracking();
217
- }
218
- initPageViewHandler() {
219
- if (!this.eventManager) {
220
- throw new Error('EventManager must be initialized before PageViewHandler');
221
- }
222
- const onPageViewTrack = () => this.onPageViewTrack();
223
- this.pageViewHandler = new page_view_handler_1.PageViewHandler(this.eventManager, onPageViewTrack);
224
- this.pageViewHandler.startTracking();
225
- }
226
- onPageViewTrack() {
227
- this.set('suppressNextScroll', true);
228
- if (this.suppressNextScrollTimer) {
229
- clearTimeout(this.suppressNextScrollTimer);
230
- this.suppressNextScrollTimer = null;
231
- }
232
- this.suppressNextScrollTimer = window.setTimeout(() => {
233
- this.set('suppressNextScroll', false);
234
- }, constants_1.SCROLL_DEBOUNCE_TIME_MS * constants_1.SCROLL_SUPPRESSION_CONSTANTS.SUPPRESS_MULTIPLIER);
235
- }
236
- initClickHandler() {
237
- if (!this.eventManager) {
238
- throw new Error('EventManager must be initialized before ClickHandler');
239
- }
240
- this.clickHandler = new click_handler_1.ClickHandler(this.eventManager);
241
- this.clickHandler.startTracking();
242
- }
243
- initScrollHandler() {
244
- if (!this.eventManager) {
245
- throw new Error('EventManager must be initialized before ScrollHandler');
246
- }
247
- this.scrollHandler = new scroll_handler_1.ScrollHandler(this.eventManager);
248
- this.scrollHandler.startTracking();
249
- }
250
- async initPerformanceHandler() {
251
- if (!this.eventManager) {
252
- throw new Error('EventManager must be initialized before PerformanceHandler');
253
- }
254
- this.performanceHandler = new performance_handler_1.PerformanceHandler(this.eventManager);
255
- await this.performanceHandler.startTracking();
256
- }
257
- initErrorHandler() {
258
- if (!this.eventManager) {
259
- throw new Error('EventManager must be initialized before ErrorHandler');
126
+ // Set device and page info
127
+ this.set('device', (0, utils_1.getDeviceType)());
128
+ const pageUrl = (0, utils_1.normalizeUrl)(window.location.href, normalizedConfig.sensitiveQueryParams);
129
+ this.set('pageUrl', pageUrl);
130
+ }
131
+ async setupIntegrations() {
132
+ const config = this.get('config');
133
+ const measurementId = config.integrations?.googleAnalytics?.measurementId;
134
+ if (!config.ipExcluded && measurementId?.trim()) {
135
+ try {
136
+ this.integrations.googleAnalytics = new google_analytics_integration_1.GoogleAnalyticsIntegration();
137
+ await this.integrations.googleAnalytics.initialize();
138
+ }
139
+ catch {
140
+ this.integrations.googleAnalytics = undefined;
141
+ }
260
142
  }
261
- this.errorHandler = new error_handler_1.ErrorHandler(this.eventManager);
262
- this.errorHandler.startTracking();
263
143
  }
264
- initNetworkHandler() {
265
- if (!this.eventManager) {
266
- throw new Error('EventManager must be initialized before NetworkHandler');
267
- }
268
- this.networkHandler = new network_handler_1.NetworkHandler(this.eventManager);
269
- this.networkHandler.startTracking();
144
+ initializeHandlers() {
145
+ this.handlers.session = new session_handler_1.SessionHandler(this.managers.storage, this.managers.event);
146
+ this.handlers.session.startTracking().catch((error) => {
147
+ utils_1.debugLog.error('App', 'Session handler failed to start', {
148
+ message: error instanceof Error ? error.message : 'Unknown error',
149
+ });
150
+ });
151
+ const onPageView = () => {
152
+ this.set('suppressNextScroll', true);
153
+ if (this.suppressNextScrollTimer) {
154
+ clearTimeout(this.suppressNextScrollTimer);
155
+ }
156
+ this.suppressNextScrollTimer = window.setTimeout(() => {
157
+ this.set('suppressNextScroll', false);
158
+ }, config_constants_1.SCROLL_DEBOUNCE_TIME_MS * config_constants_1.SCROLL_SUPPRESS_MULTIPLIER);
159
+ };
160
+ this.handlers.pageView = new page_view_handler_1.PageViewHandler(this.managers.event, onPageView);
161
+ this.handlers.pageView.startTracking();
162
+ this.handlers.click = new click_handler_1.ClickHandler(this.managers.event);
163
+ this.handlers.click.startTracking();
164
+ this.handlers.scroll = new scroll_handler_1.ScrollHandler(this.managers.event);
165
+ this.handlers.scroll.startTracking();
166
+ this.handlers.performance = new performance_handler_1.PerformanceHandler(this.managers.event);
167
+ this.handlers.performance.startTracking().catch(() => {
168
+ utils_1.debugLog.warn('App', 'Failed to start performance tracking');
169
+ });
170
+ this.handlers.error = new error_handler_1.ErrorHandler(this.managers.event);
171
+ this.handlers.error.startTracking();
270
172
  }
271
173
  }
272
174
  exports.App = App;
@@ -1,7 +1,2 @@
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/mode.types';
6
- export * from './types/queue.types';
7
- export * from './types/tag.types';
1
+ export { Mode, EventType, DeviceType, ScrollDirection, ErrorType, TagConditionOperator, TagLogicalOperator, TagConditionType, } from './types';
2
+ export type { ScrollData, ClickData, CustomEventData, MetadataType, WebVitalsData, ErrorData, PageViewData, UTM, EventData, AppConfig, ApiConfig, ExtendedEventsQueueDto, TagConfig, BaseEventsQueueDto, WebVitalType, SessionEndReason, } from './types';
@@ -1,23 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types/common.types"), exports);
18
- __exportStar(require("./types/config.types"), exports);
19
- __exportStar(require("./types/device.types"), exports);
20
- __exportStar(require("./types/event.types"), exports);
21
- __exportStar(require("./types/mode.types"), exports);
22
- __exportStar(require("./types/queue.types"), exports);
23
- __exportStar(require("./types/tag.types"), exports);
3
+ exports.TagConditionType = exports.TagLogicalOperator = exports.TagConditionOperator = exports.ErrorType = exports.ScrollDirection = exports.DeviceType = exports.EventType = exports.Mode = void 0;
4
+ var types_1 = require("./types");
5
+ Object.defineProperty(exports, "Mode", { enumerable: true, get: function () { return types_1.Mode; } });
6
+ Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return types_1.EventType; } });
7
+ Object.defineProperty(exports, "DeviceType", { enumerable: true, get: function () { return types_1.DeviceType; } });
8
+ Object.defineProperty(exports, "ScrollDirection", { enumerable: true, get: function () { return types_1.ScrollDirection; } });
9
+ Object.defineProperty(exports, "ErrorType", { enumerable: true, get: function () { return types_1.ErrorType; } });
10
+ Object.defineProperty(exports, "TagConditionOperator", { enumerable: true, get: function () { return types_1.TagConditionOperator; } });
11
+ Object.defineProperty(exports, "TagLogicalOperator", { enumerable: true, get: function () { return types_1.TagLogicalOperator; } });
12
+ Object.defineProperty(exports, "TagConditionType", { enumerable: true, get: function () { return types_1.TagConditionType; } });
@@ -1,17 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_CONFIG = exports.DEFAULT_API_CONFIG = void 0;
4
- const limits_constants_1 = require("./limits.constants");
5
- const timing_constants_1 = require("./timing.constants");
4
+ const config_constants_1 = require("./config.constants");
6
5
  exports.DEFAULT_API_CONFIG = {
7
- samplingRate: limits_constants_1.DEFAULT_SAMPLING_RATE,
8
- tags: [],
6
+ samplingRate: config_constants_1.DEFAULT_SAMPLING_RATE,
9
7
  excludedUrlPaths: [],
8
+ tags: [],
9
+ ipExcluded: false,
10
10
  };
11
11
  const DEFAULT_CONFIG = (config) => ({
12
12
  ...exports.DEFAULT_API_CONFIG,
13
13
  ...config,
14
- sessionTimeout: timing_constants_1.DEFAULT_SESSION_TIMEOUT_MS,
15
14
  allowHttp: false,
15
+ sessionTimeout: config_constants_1.DEFAULT_SESSION_TIMEOUT,
16
+ samplingRate: config.samplingRate && config.samplingRate > config_constants_1.MIN_SAMPLING_RATE && config.samplingRate <= config_constants_1.MAX_SAMPLING_RATE
17
+ ? config.samplingRate
18
+ : config_constants_1.DEFAULT_SAMPLING_RATE,
19
+ excludedUrlPaths: config.excludedUrlPaths ?? [],
20
+ tags: config.tags ?? [],
21
+ ipExcluded: config.ipExcluded ?? false,
16
22
  });
17
23
  exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Consolidated configuration constants for TraceLog
3
+ * This file centralizes all timing, limits, browser, and initialization constants
4
+ */
5
+ export declare const DEFAULT_SESSION_TIMEOUT: number;
6
+ export declare const DUPLICATE_EVENT_THRESHOLD_MS = 1000;
7
+ export declare const EVENT_SENT_INTERVAL_MS = 10000;
8
+ export declare const SCROLL_DEBOUNCE_TIME_MS = 250;
9
+ export declare const DEFAULT_VISIBILITY_TIMEOUT_MS = 2000;
10
+ export declare const EVENT_EXPIRY_HOURS = 24;
11
+ export declare const EVENT_PERSISTENCE_MAX_AGE_MS: number;
12
+ export declare const MAX_EVENTS_QUEUE_LENGTH = 500;
13
+ export declare const MAX_RETRIES = 3;
14
+ export declare const RETRY_DELAY_MS = 5000;
15
+ export declare const REQUEST_TIMEOUT_MS = 10000;
16
+ export declare const MAX_METADATA_SIZE = 5000;
17
+ export declare const DEFAULT_MOTION_THRESHOLD = 2;
18
+ export declare const SIGNIFICANT_SCROLL_DELTA = 10;
19
+ export declare const MIN_SCROLL_DEPTH_CHANGE = 5;
20
+ export declare const SCROLL_MIN_EVENT_INTERVAL_MS = 500;
21
+ export declare const MAX_SCROLL_EVENTS_PER_SESSION = 120;
22
+ export declare const DEFAULT_SAMPLING_RATE = 1;
23
+ export declare const MIN_SAMPLING_RATE = 0;
24
+ export declare const MAX_SAMPLING_RATE = 1;
25
+ export declare const BATCH_SIZE_THRESHOLD = 50;
26
+ export declare const MIN_SESSION_TIMEOUT_MS = 30000;
27
+ export declare const MAX_SESSION_TIMEOUT_MS = 86400000;
28
+ export declare const MAX_CUSTOM_EVENT_NAME_LENGTH = 120;
29
+ export declare const MAX_CUSTOM_EVENT_STRING_SIZE: number;
30
+ export declare const MAX_CUSTOM_EVENT_KEYS = 10;
31
+ export declare const MAX_CUSTOM_EVENT_ARRAY_SIZE = 10;
32
+ export declare const MAX_TEXT_LENGTH = 255;
33
+ export declare const MAX_STRING_LENGTH = 1000;
34
+ export declare const MAX_ARRAY_LENGTH = 100;
35
+ export declare const MAX_OBJECT_DEPTH = 3;
36
+ export declare const PRECISION_TWO_DECIMALS: 2;
37
+ export declare const SYNC_XHR_TIMEOUT_MS = 2000;
38
+ export declare const MAX_FINGERPRINTS = 1000;
39
+ export declare const FINGERPRINT_CLEANUP_MULTIPLIER = 10;
40
+ export declare const MAX_FINGERPRINTS_HARD_LIMIT = 2000;
41
+ export declare const HTML_DATA_ATTR_PREFIX = "data-tl";
42
+ 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\"]"];
43
+ export declare const UTM_PARAMS: string[];
44
+ export declare const INITIALIZATION_MAX_CONCURRENT_RETRIES = 20;
45
+ export declare const INITIALIZATION_CONCURRENT_RETRY_DELAY_MS = 50;
46
+ export declare const INITIALIZATION_TIMEOUT_MS = 10000;
47
+ export declare const SESSION_SYNC_TIMEOUT_MS = 2000;
48
+ export declare const SESSION_MAX_RETRY_ATTEMPTS = 3;
49
+ export declare const SESSION_CLEANUP_DELAY_MS = 100;
50
+ export declare const CROSS_TAB_INITIALIZATION_LOCK_TIMEOUT_MS = 5000;
51
+ export declare const TAB_HEARTBEAT_INTERVAL_MS = 5000;
52
+ export declare const TAB_ELECTION_TIMEOUT_MS = 2000;
53
+ export declare const TAB_CLEANUP_DELAY_MS = 1000;
54
+ export declare const SESSION_RECOVERY_WINDOW_MULTIPLIER = 2;
55
+ export declare const MAX_SESSION_RECOVERY_ATTEMPTS = 3;
56
+ export declare const MAX_SESSION_RECOVERY_WINDOW_MS: number;
57
+ export declare const MIN_SESSION_RECOVERY_WINDOW_MS: number;
58
+ export declare const SCROLL_SUPPRESS_MULTIPLIER = 2;
59
+ export declare const RETRY_BACKOFF_INITIAL = 1000;
60
+ export declare const RETRY_BACKOFF_MAX = 30000;
61
+ export declare const RATE_LIMIT_INTERVAL = 1000;
62
+ export declare const MAX_RETRY_ATTEMPTS = 10;
63
+ export declare const ALLOWED_API_CONFIG_KEYS: Set<"mode" | "samplingRate" | "excludedUrlPaths" | keyof import("../types").ExclusiveApiConfig>;
64
+ export declare const VALIDATION_MESSAGES: {
65
+ readonly MISSING_PROJECT_ID: "Project ID is required";
66
+ readonly PROJECT_ID_EMPTY_AFTER_TRIM: "Project ID is required";
67
+ readonly INVALID_SESSION_TIMEOUT: "Session timeout must be between 30000ms (30 seconds) and 86400000ms (24 hours)";
68
+ readonly INVALID_SAMPLING_RATE: "Sampling rate must be greater than 0 and less than or equal to 1";
69
+ readonly INVALID_ERROR_SAMPLING_RATE: "Error sampling must be between 0 and 1";
70
+ readonly INVALID_GOOGLE_ANALYTICS_ID: "Google Analytics measurement ID is required when integration is enabled";
71
+ readonly INVALID_SCROLL_CONTAINER_SELECTORS: "Scroll container selectors must be valid CSS selectors";
72
+ readonly INVALID_GLOBAL_METADATA: "Global metadata must be an object";
73
+ readonly INVALID_SENSITIVE_QUERY_PARAMS: "Sensitive query params must be an array of strings";
74
+ };
75
+ export declare const XSS_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];