@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
@@ -2,20 +2,35 @@
2
2
  * Special project IDs for testing and development
3
3
  *
4
4
  * Both automatically force mode: 'debug' but differ in HTTP behavior:
5
- * - HttpSkip: NO network calls (pure offline testing)
6
- * - HttpLocal: Makes network calls to local server (integration testing)
5
+ * - Skip: NO network calls (pure offline testing)
6
+ * - Localhost: Makes network calls to local server (integration testing)
7
7
  */
8
8
  export declare enum SpecialProjectId {
9
9
  /**
10
+ * Value: 'skip'
11
+ *
10
12
  * Skips ALL HTTP calls - no config fetch, no event sending
11
13
  * Uses default local config, forces debug mode
12
14
  * Perfect for pure offline E2E testing
15
+ *
16
+ * @example
17
+ * await TraceLog.init({ id: SpecialProjectId.Skip });
18
+ * // or
19
+ * await TraceLog.init({ id: 'skip' });
13
20
  */
14
- HttpSkip = "http-skip",
21
+ Skip = "skip",
15
22
  /**
16
- * Makes HTTP calls to window.location.origin instead of production API
17
- * Fetches config and sends events to local server, forces debug mode
23
+ * Value: 'localhost:' (used as prefix)
24
+ *
25
+ * Makes HTTP calls to local development server
26
+ * Must specify full address: 'localhost:PORT' (e.g., 'localhost:3000')
27
+ * Converts to http://localhost:PORT/config for requests
28
+ * Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
18
29
  * Perfect for local development with running middleware
30
+ *
31
+ * @example
32
+ * await TraceLog.init({ id: 'localhost:3000' });
33
+ * // Makes requests to: http://localhost:3000/config
19
34
  */
20
- HttpLocal = "http-local"
35
+ Localhost = "localhost:"
21
36
  }
@@ -2,21 +2,36 @@
2
2
  * Special project IDs for testing and development
3
3
  *
4
4
  * Both automatically force mode: 'debug' but differ in HTTP behavior:
5
- * - HttpSkip: NO network calls (pure offline testing)
6
- * - HttpLocal: Makes network calls to local server (integration testing)
5
+ * - Skip: NO network calls (pure offline testing)
6
+ * - Localhost: Makes network calls to local server (integration testing)
7
7
  */
8
8
  export var SpecialProjectId;
9
9
  (function (SpecialProjectId) {
10
10
  /**
11
+ * Value: 'skip'
12
+ *
11
13
  * Skips ALL HTTP calls - no config fetch, no event sending
12
14
  * Uses default local config, forces debug mode
13
15
  * Perfect for pure offline E2E testing
16
+ *
17
+ * @example
18
+ * await TraceLog.init({ id: SpecialProjectId.Skip });
19
+ * // or
20
+ * await TraceLog.init({ id: 'skip' });
14
21
  */
15
- SpecialProjectId["HttpSkip"] = "http-skip";
22
+ SpecialProjectId["Skip"] = "skip";
16
23
  /**
17
- * Makes HTTP calls to window.location.origin instead of production API
18
- * Fetches config and sends events to local server, forces debug mode
24
+ * Value: 'localhost:' (used as prefix)
25
+ *
26
+ * Makes HTTP calls to local development server
27
+ * Must specify full address: 'localhost:PORT' (e.g., 'localhost:3000')
28
+ * Converts to http://localhost:PORT/config for requests
29
+ * Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
19
30
  * Perfect for local development with running middleware
31
+ *
32
+ * @example
33
+ * await TraceLog.init({ id: 'localhost:3000' });
34
+ * // Makes requests to: http://localhost:3000/config
20
35
  */
21
- SpecialProjectId["HttpLocal"] = "http-local";
36
+ SpecialProjectId["Localhost"] = "localhost:";
22
37
  })(SpecialProjectId || (SpecialProjectId = {}));
@@ -1,103 +1,41 @@
1
1
  import { MetadataType } from './common.types';
2
2
  import { TagConfig } from './tag.types';
3
3
  import { Mode } from './mode.types';
4
- export type Config = ApiConfig & AppConfig;
5
- export interface ApiConfig {
6
- /**
7
- * Logging mode for the library.
8
- * - 'qa': Shows client-facing logs only (INFO, CLIENT_WARN, CLIENT_ERROR)
9
- * - 'debug': Shows all logs including internal library errors
10
- */
11
- mode?: Mode;
12
- /**
13
- * Sampling rate as a percentage (0-1) to control how many events are sent.
14
- * A value of 1 means all events are sent, while 0.5 means only half of events are sent.
15
- */
16
- samplingRate?: number;
17
- /**
18
- * Array of tag configurations for categorizing and filtering events.
19
- * Tags help organize and segment tracking data for analysis.
20
- */
4
+ export type Config = AppConfig & ExclusiveApiConfig;
5
+ export type ApiConfig = SharedConfig & ExclusiveApiConfig;
6
+ export type SharedConfig = Pick<AppConfig, 'mode' | 'samplingRate' | 'excludedUrlPaths'>;
7
+ export interface ExclusiveApiConfig {
8
+ /** Tag definitions used to categorize tracked events. */
21
9
  tags?: TagConfig[];
22
- /**
23
- * Array of URL path patterns to exclude from tracking.
24
- * Events will not be sent for pages matching these patterns.
25
- */
26
- excludedUrlPaths?: string[];
27
- /**
28
- * Flag to indicate if IP addresses should be excluded from tracking.
29
- * When true, IP addresses will not be collected or sent with events.
30
- * This is useful for privacy compliance and reducing data exposure.
31
- */
10
+ /** Determines if IP address is excluded from tracking. */
32
11
  ipExcluded?: boolean;
33
12
  }
34
13
  export interface AppConfig {
35
- /**
36
- * Unique project identifier.
37
- */
14
+ /** Project identifier used for tracing. */
38
15
  id: string;
39
- /**
40
- * Session timeout in milliseconds. After this period of inactivity,
41
- * a new session will be started for subsequent events.
42
- *
43
- * **Timeout Guidelines:**
44
- * - **15 minutes (default)**: Recommended for most applications, aligns with security best practices
45
- * - **30 minutes**: Standard for content-heavy sites (matches Google Analytics default)
46
- * - **45-60 minutes**: Consider for sites with long-form content, videos, or documentation
47
- * - **5-10 minutes**: Use for security-sensitive applications requiring frequent re-authentication
48
- *
49
- * **Impact on Analytics:**
50
- * - Shorter timeouts = Higher session count, higher bounce rate, potentially lower conversion rates
51
- * - Longer timeouts = Lower session count, more accurate user journey tracking, better conversion attribution
52
- *
53
- * **When to Adjust:**
54
- * - Match your application's auto-logout timeout if applicable
55
- * - Increase for content where users frequently pause (tutorials, long articles, videos)
56
- * - Decrease for applications with sensitive data or frequent security requirements
57
- * - Monitor bounce rates and conversion funnels when changing this value
58
- *
59
- * @default 900000 (15 minutes)
60
- * @min 30000 (30 seconds)
61
- * @max 86400000 (24 hours)
62
- */
16
+ /** Session inactivity timeout in milliseconds. @default 900000 */
63
17
  sessionTimeout?: number;
64
- /**
65
- * Metadata that will be automatically attached to all tracking events.
66
- * These key-value pairs provide additional context for every event sent.
67
- */
18
+ /** Metadata appended to every tracked event. */
68
19
  globalMetadata?: Record<string, MetadataType>;
69
- /**
70
- * CSS selectors for custom scroll containers. Can be a single selector string
71
- * or an array of selectors. Used to track scroll events within specific elements
72
- * instead of the default window scroll.
73
- */
20
+ /** Selectors defining custom scroll containers to monitor. */
74
21
  scrollContainerSelectors?: string | string[];
75
- /**
76
- * Allow HTTP requests to be made. This is useful for testing and development.
77
- */
22
+ /** Enables HTTP requests for testing and development flows. */
78
23
  allowHttp?: boolean;
79
- /**
80
- * Array of query parameters to be removed from the URL.
81
- */
24
+ /** Query parameters to remove before tracking URLs. */
82
25
  sensitiveQueryParams?: string[];
83
- /**
84
- * Sampling rate for error events (0-1).
85
- * Controls how many error and network error events are captured.
86
- * @default 0.1 for production, 1.0 for qa/debug mode
87
- */
26
+ /** Error event sampling rate between 0 and 1. */
88
27
  errorSampling?: number;
89
- /**
90
- * Optional integrations configuration.
91
- */
28
+ /** Logging mode controlling verbosity of client logs. */
29
+ mode?: Mode;
30
+ /** Event sampling rate between 0 and 1. */
31
+ samplingRate?: number;
32
+ /** URL path patterns that should be ignored by tracking. */
33
+ excludedUrlPaths?: string[];
34
+ /** Optional configuration for third-party integrations. */
92
35
  integrations?: {
93
- /**
94
- * Google Analytics integration configuration.
95
- */
36
+ /** Google Analytics integration options. */
96
37
  googleAnalytics?: {
97
- /**
98
- * Google Analytics measurement ID.
99
- * Required for initializing the Google Analytics integration.
100
- */
38
+ /** Required measurement ID for Google Analytics. */
101
39
  measurementId: string;
102
40
  };
103
41
  };
@@ -0,0 +1,11 @@
1
+ import { EventData } from './event.types';
2
+ import { BaseEventsQueueDto } from './queue.types';
3
+ export type EmitterCallback<T = any> = (data: T) => void;
4
+ export declare enum EmitterEvent {
5
+ EVENT = "event",
6
+ QUEUE = "queue"
7
+ }
8
+ export interface EmitterMap {
9
+ [EmitterEvent.EVENT]: EventData;
10
+ [EmitterEvent.QUEUE]: BaseEventsQueueDto;
11
+ }
@@ -0,0 +1,5 @@
1
+ export var EmitterEvent;
2
+ (function (EmitterEvent) {
3
+ EmitterEvent["EVENT"] = "event";
4
+ EmitterEvent["QUEUE"] = "queue";
5
+ })(EmitterEvent || (EmitterEvent = {}));
@@ -40,12 +40,7 @@ export interface ClickData {
40
40
  ariaLabel?: string;
41
41
  dataAttributes?: Record<string, string>;
42
42
  }
43
- export interface ClickCoordinates {
44
- x: number;
45
- y: number;
46
- relativeX: number;
47
- relativeY: number;
48
- }
43
+ export type ClickCoordinates = Pick<ClickData, 'x' | 'y' | 'relativeX' | 'relativeY'>;
49
44
  export interface ClickTrackingElementData {
50
45
  element: HTMLElement;
51
46
  name: string;
@@ -62,11 +57,9 @@ export interface WebVitalsData {
62
57
  export interface ErrorData {
63
58
  type: ErrorType;
64
59
  message: string;
65
- method?: string;
66
- url?: string;
67
- status?: number;
68
- statusText?: string;
69
- duration?: number;
60
+ filename?: string;
61
+ line?: number;
62
+ column?: number;
70
63
  }
71
64
  export interface UTM {
72
65
  source?: string;
@@ -82,6 +75,10 @@ export interface PageViewData {
82
75
  search?: string;
83
76
  hash?: string;
84
77
  }
78
+ export interface VitalSample {
79
+ type: WebVitalType;
80
+ value: number;
81
+ }
85
82
  export interface EventData {
86
83
  type: EventType;
87
84
  page_url: string;
@@ -2,12 +2,14 @@ export * from './api.types';
2
2
  export * from './common.types';
3
3
  export * from './config.types';
4
4
  export * from './device.types';
5
+ export * from './emitter.types';
5
6
  export * from './event.types';
6
7
  export * from './log.types';
7
8
  export * from './mode.types';
8
9
  export * from './queue.types';
10
+ export * from './session.types';
9
11
  export * from './state.types';
10
12
  export * from './tag.types';
13
+ export * from './test-bridge.types';
11
14
  export * from './validation-error.types';
12
- export * from './web-vitals.types';
13
15
  export * from './window.types';
@@ -2,12 +2,14 @@ export * from './api.types';
2
2
  export * from './common.types';
3
3
  export * from './config.types';
4
4
  export * from './device.types';
5
+ export * from './emitter.types';
5
6
  export * from './event.types';
6
7
  export * from './log.types';
7
8
  export * from './mode.types';
8
9
  export * from './queue.types';
10
+ export * from './session.types';
9
11
  export * from './state.types';
10
12
  export * from './tag.types';
13
+ export * from './test-bridge.types';
11
14
  export * from './validation-error.types';
12
- export * from './web-vitals.types';
13
15
  export * from './window.types';
@@ -20,4 +20,5 @@ export interface PersistedQueueData {
20
20
  events: BaseEventsQueueDto['events'];
21
21
  timestamp: number;
22
22
  global_metadata?: BaseEventsQueueDto['global_metadata'];
23
+ fallbackMode?: boolean;
23
24
  }
@@ -1,65 +1 @@
1
1
  export type SessionEndReason = 'inactivity' | 'page_unload' | 'manual_stop' | 'orphaned_cleanup' | 'tab_closed';
2
- export interface SessionEndConfig {
3
- enablePageUnloadHandlers: boolean;
4
- syncTimeoutMs: number;
5
- maxRetries: number;
6
- debugMode: boolean;
7
- }
8
- export interface SessionEndResult {
9
- success: boolean;
10
- reason: SessionEndReason;
11
- timestamp: number;
12
- eventsFlushed: number;
13
- method: 'async' | 'sync';
14
- }
15
- export interface SessionEndStats {
16
- totalSessionEnds: number;
17
- successfulEnds: number;
18
- failedEnds: number;
19
- duplicatePrevented: number;
20
- reasonCounts: Record<SessionEndReason, number>;
21
- }
22
- export interface CrossTabSessionConfig {
23
- tabHeartbeatIntervalMs: number;
24
- tabElectionTimeoutMs: number;
25
- debugMode: boolean;
26
- }
27
- export interface TabInfo {
28
- id: string;
29
- lastHeartbeat: number;
30
- isLeader: boolean;
31
- sessionId: string;
32
- startTime: number;
33
- }
34
- export interface CrossTabMessage {
35
- type: 'heartbeat' | 'session_start' | 'session_end' | 'tab_closing' | 'election_request' | 'election_response';
36
- tabId: string;
37
- sessionId?: string;
38
- timestamp: number;
39
- data?: Record<string, unknown>;
40
- }
41
- export interface SessionRecoveryConfig {
42
- recoveryWindowMs: number;
43
- maxRecoveryAttempts: number;
44
- contextPreservation: boolean;
45
- }
46
- export interface SessionContext {
47
- sessionId: string;
48
- startTime: number;
49
- lastActivity: number;
50
- tabCount: number;
51
- recoveryAttempts: number;
52
- metadata?: Record<string, unknown>;
53
- }
54
- export interface RecoveryAttempt {
55
- sessionId: string;
56
- timestamp: number;
57
- attempt: number;
58
- context: SessionContext;
59
- }
60
- export interface SessionHealth {
61
- recoveryAttempts: number;
62
- sessionTimeouts: number;
63
- crossTabConflicts: number;
64
- lastHealthCheck: number;
65
- }
@@ -9,4 +9,5 @@ export interface State {
9
9
  pageUrl: string;
10
10
  hasStartSession: boolean;
11
11
  suppressNextScroll: boolean;
12
+ scrollEventCount?: number;
12
13
  }
@@ -0,0 +1,38 @@
1
+ import { ClickHandler } from '@/handlers/click.handler';
2
+ import { ErrorHandler } from '@/handlers/error.handler';
3
+ import { PageViewHandler } from '@/handlers/page-view.handler';
4
+ import { PerformanceHandler } from '@/handlers/performance.handler';
5
+ import { ScrollHandler } from '@/handlers/scroll.handler';
6
+ import { SessionHandler } from '@/handlers/session.handler';
7
+ import { GoogleAnalyticsIntegration } from '@/integrations/google-analytics.integration';
8
+ import { EventManager } from '@/managers/event.manager';
9
+ import { StorageManager as TraceLogStorageManager } from '@/managers/storage.manager';
10
+ import { AppConfig } from './config.types';
11
+ import { State } from './state.types';
12
+ /**
13
+ * Testing bridge interface for E2E tests
14
+ * Only available when NODE_ENV=dev
15
+ */
16
+ export interface TraceLogTestBridge {
17
+ readonly initialized: boolean;
18
+ init(config: AppConfig): Promise<void>;
19
+ destroy(): Promise<void>;
20
+ isInitializing(): boolean;
21
+ sendCustomEvent(name: string, data?: Record<string, unknown>): void;
22
+ on(event: string, callback: (data: any) => void): void;
23
+ off(event: string, callback: (data: any) => void): void;
24
+ getSessionData(): Record<string, unknown> | null;
25
+ setSessionTimeout(timeout: number): void;
26
+ getQueueLength(): number;
27
+ forceInitLock(enabled?: boolean): void;
28
+ get<T extends keyof State>(key: T): State[T];
29
+ getStorageManager(): TraceLogStorageManager | null;
30
+ getEventManager(): EventManager | null;
31
+ getSessionHandler(): SessionHandler | null;
32
+ getPageViewHandler(): PageViewHandler | null;
33
+ getClickHandler(): ClickHandler | null;
34
+ getScrollHandler(): ScrollHandler | null;
35
+ getPerformanceHandler(): PerformanceHandler | null;
36
+ getErrorHandler(): ErrorHandler | null;
37
+ getGoogleAnalytics(): GoogleAnalyticsIntegration | null;
38
+ }
@@ -40,3 +40,10 @@ export declare class SamplingRateValidationError extends TraceLogValidationError
40
40
  export declare class IntegrationValidationError extends TraceLogValidationError {
41
41
  constructor(message: string, layer?: 'config' | 'app' | 'runtime');
42
42
  }
43
+ /**
44
+ * Thrown when initialization exceeds the maximum allowed timeout
45
+ */
46
+ export declare class InitializationTimeoutError extends TraceLogValidationError {
47
+ readonly timeoutMs: number;
48
+ constructor(message: string, timeoutMs: number, layer?: 'config' | 'app' | 'runtime');
49
+ }
@@ -57,3 +57,12 @@ export class IntegrationValidationError extends TraceLogValidationError {
57
57
  super(message, 'INTEGRATION_INVALID', layer);
58
58
  }
59
59
  }
60
+ /**
61
+ * Thrown when initialization exceeds the maximum allowed timeout
62
+ */
63
+ export class InitializationTimeoutError extends TraceLogValidationError {
64
+ constructor(message, timeoutMs, layer = 'runtime') {
65
+ super(message, 'INITIALIZATION_TIMEOUT', layer);
66
+ this.timeoutMs = timeoutMs;
67
+ }
68
+ }
@@ -1,11 +1,4 @@
1
- import type { App } from '../app';
2
- /**
3
- * Testing bridge interface for E2E tests
4
- * Only available when NODE_ENV=dev
5
- */
6
- export interface TraceLogTestBridge extends App {
7
- isInitializing(): boolean;
8
- }
1
+ import { TraceLogTestBridge } from './test-bridge.types';
9
2
  declare global {
10
3
  interface Window {
11
4
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Generates a RFC4122 compliant UUID v4
2
+ * Generates a RFC4122 compliant UUID v4 using native crypto API with fallback
3
3
  * @returns A UUID string
4
4
  */
5
5
  export declare const generateUUID: () => string;
@@ -1,14 +1,16 @@
1
- import { debugLog } from '../logging';
2
1
  /**
3
- * Generates a RFC4122 compliant UUID v4
2
+ * Generates a RFC4122 compliant UUID v4 using native crypto API with fallback
4
3
  * @returns A UUID string
5
4
  */
6
5
  export const generateUUID = () => {
7
- const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
6
+ // Use native crypto.randomUUID() if available (modern browsers)
7
+ if (typeof crypto !== 'undefined' && crypto.randomUUID) {
8
+ return crypto.randomUUID();
9
+ }
10
+ // Fallback for older browsers
11
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
8
12
  const r = (Math.random() * 16) | 0;
9
13
  const v = c === 'x' ? r : (r & 0x3) | 0x8;
10
14
  return v.toString(16);
11
15
  });
12
- debugLog.verbose('UUIDUtils', 'Generated new UUID', { uuid });
13
- return uuid;
14
16
  };
@@ -0,0 +1,8 @@
1
+ import { EmitterCallback, EmitterMap } from '@/types';
2
+ export declare class Emitter {
3
+ private readonly listeners;
4
+ on<K extends keyof EmitterMap>(event: K, callback: EmitterCallback<EmitterMap[K]>): void;
5
+ off<K extends keyof EmitterMap>(event: K, callback: EmitterCallback<EmitterMap[K]>): void;
6
+ emit<K extends keyof EmitterMap>(event: K, data: EmitterMap[K]): void;
7
+ removeAllListeners(): void;
8
+ }
@@ -0,0 +1,29 @@
1
+ export class Emitter {
2
+ constructor() {
3
+ this.listeners = new Map();
4
+ }
5
+ on(event, callback) {
6
+ if (!this.listeners.has(event)) {
7
+ this.listeners.set(event, []);
8
+ }
9
+ this.listeners.get(event).push(callback);
10
+ }
11
+ off(event, callback) {
12
+ const callbacks = this.listeners.get(event);
13
+ if (callbacks) {
14
+ const index = callbacks.indexOf(callback);
15
+ if (index > -1) {
16
+ callbacks.splice(index, 1);
17
+ }
18
+ }
19
+ }
20
+ emit(event, data) {
21
+ const callbacks = this.listeners.get(event);
22
+ if (callbacks) {
23
+ callbacks.forEach((callback) => callback(data));
24
+ }
25
+ }
26
+ removeAllListeners() {
27
+ this.listeners.clear();
28
+ }
29
+ }
@@ -4,3 +4,4 @@ export * from './logging';
4
4
  export * from './network';
5
5
  export * from './security';
6
6
  export * from './validations';
7
+ export * from './emitter.utils';
@@ -4,3 +4,4 @@ export * from './logging';
4
4
  export * from './network';
5
5
  export * from './security';
6
6
  export * from './validations';
7
+ export * from './emitter.utils';
@@ -1,56 +1,15 @@
1
1
  import { StateManager } from '../../managers/state.manager';
2
- /**
3
- * Debug logger class that extends StateManager for clean access to global state
4
- */
5
2
  declare class DebugLogger extends StateManager {
6
- /**
7
- * Client-facing error - Configuration/usage errors by the client
8
- * Console: qa and debug modes | Events: NODE_ENV=dev
9
- */
10
- clientError(namespace: string, message: string, data?: unknown): void;
11
- /**
12
- * Client-facing warning - Configuration/usage warnings by the client
13
- * Console: qa and debug modes | Events: NODE_ENV=dev
14
- */
15
- clientWarn(namespace: string, message: string, data?: unknown): void;
16
- /**
17
- * General operational information
18
- * Console: qa and debug modes | Events: NODE_ENV=dev
19
- */
20
- info(namespace: string, message: string, data?: unknown): void;
21
- /**
22
- * Internal library errors
23
- * Console: debug mode only | Events: NODE_ENV=dev
24
- */
25
- error(namespace: string, message: string, data?: unknown): void;
26
- /**
27
- * Internal library warnings
28
- * Console: debug mode only | Events: NODE_ENV=dev
29
- */
30
- warn(namespace: string, message: string, data?: unknown): void;
31
- /**
32
- * Strategic debug information
33
- * Console: debug mode only | Events: NODE_ENV=dev
34
- */
35
- debug(namespace: string, message: string, data?: unknown): void;
36
- /**
37
- * Detailed trace information
38
- * Console: debug mode only | Events: NODE_ENV=dev
39
- */
40
- verbose(namespace: string, message: string, data?: unknown): void;
41
- private getCurrentMode;
42
- private shouldShowLog;
43
- private formatMessage;
44
- private getConsoleMethod;
45
- private logMessage;
46
- /**
47
- * Dispatches tracelog:log events for E2E testing and development debugging
48
- */
49
- private dispatchEvent;
3
+ clientError: (ns: string, msg: string, data?: unknown) => void;
4
+ clientWarn: (ns: string, msg: string, data?: unknown) => void;
5
+ info: (ns: string, msg: string, data?: unknown) => void;
6
+ error: (ns: string, msg: string, data?: unknown) => void;
7
+ warn: (ns: string, msg: string, data?: unknown) => void;
8
+ debug: (ns: string, msg: string, data?: unknown) => void;
9
+ verbose: (ns: string, msg: string, data?: unknown) => void;
10
+ private log;
11
+ private shouldShow;
12
+ private getMethod;
50
13
  }
51
- /**
52
- * Singleton debug logger instance
53
- * Provides the same API as before: debugLog.clientError(), debugLog.info(), etc.
54
- */
55
14
  export declare const debugLog: DebugLogger;
56
15
  export {};