@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
@@ -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';
@@ -20,3 +20,4 @@ __exportStar(require("./logging"), exports);
20
20
  __exportStar(require("./network"), exports);
21
21
  __exportStar(require("./security"), exports);
22
22
  __exportStar(require("./validations"), exports);
23
+ __exportStar(require("./emitter.utils"), exports);
@@ -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 {};
@@ -2,138 +2,47 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debugLog = void 0;
4
4
  const state_manager_1 = require("../../managers/state.manager");
5
- /**
6
- * Debug logger class that extends StateManager for clean access to global state
7
- */
8
5
  class DebugLogger extends state_manager_1.StateManager {
9
- /**
10
- * Client-facing error - Configuration/usage errors by the client
11
- * Console: qa and debug modes | Events: NODE_ENV=dev
12
- */
13
- clientError(namespace, message, data) {
14
- this.logMessage('CLIENT_ERROR', namespace, message, data);
15
- }
16
- /**
17
- * Client-facing warning - Configuration/usage warnings by the client
18
- * Console: qa and debug modes | Events: NODE_ENV=dev
19
- */
20
- clientWarn(namespace, message, data) {
21
- this.logMessage('CLIENT_WARN', namespace, message, data);
22
- }
23
- /**
24
- * General operational information
25
- * Console: qa and debug modes | Events: NODE_ENV=dev
26
- */
27
- info(namespace, message, data) {
28
- this.logMessage('INFO', namespace, message, data);
29
- }
30
- /**
31
- * Internal library errors
32
- * Console: debug mode only | Events: NODE_ENV=dev
33
- */
34
- error(namespace, message, data) {
35
- this.logMessage('ERROR', namespace, message, data);
36
- }
37
- /**
38
- * Internal library warnings
39
- * Console: debug mode only | Events: NODE_ENV=dev
40
- */
41
- warn(namespace, message, data) {
42
- this.logMessage('WARN', namespace, message, data);
43
- }
44
- /**
45
- * Strategic debug information
46
- * Console: debug mode only | Events: NODE_ENV=dev
47
- */
48
- debug(namespace, message, data) {
49
- this.logMessage('DEBUG', namespace, message, data);
50
- }
51
- /**
52
- * Detailed trace information
53
- * Console: debug mode only | Events: NODE_ENV=dev
54
- */
55
- verbose(namespace, message, data) {
56
- this.logMessage('VERBOSE', namespace, message, data);
57
- }
58
- getCurrentMode() {
59
- try {
60
- return this.get('config')?.mode;
61
- }
62
- catch {
63
- return undefined;
64
- }
65
- }
66
- shouldShowLog(level) {
67
- const mode = this.getCurrentMode();
68
- switch (mode) {
69
- case 'qa':
70
- return ['INFO', 'CLIENT_ERROR', 'CLIENT_WARN'].includes(level);
71
- case 'debug':
72
- return true;
73
- default:
74
- return false;
75
- }
76
- }
77
- formatMessage(namespace, message) {
78
- return `[TraceLog:${namespace}] ${message}`;
79
- }
80
- getConsoleMethod(level) {
81
- switch (level) {
82
- case 'CLIENT_ERROR':
83
- case 'ERROR':
84
- return 'error';
85
- case 'CLIENT_WARN':
86
- case 'WARN':
87
- return 'warn';
88
- case 'INFO':
89
- case 'DEBUG':
90
- case 'VERBOSE':
91
- default:
92
- return 'log';
93
- }
94
- }
95
- logMessage(level, namespace, message, data) {
96
- if (!this.shouldShowLog(level)) {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.clientError = (ns, msg, data) => this.log('CLIENT_ERROR', ns, msg, data);
9
+ this.clientWarn = (ns, msg, data) => this.log('CLIENT_WARN', ns, msg, data);
10
+ this.info = (ns, msg, data) => this.log('INFO', ns, msg, data);
11
+ this.error = (ns, msg, data) => this.log('ERROR', ns, msg, data);
12
+ this.warn = (ns, msg, data) => this.log('WARN', ns, msg, data);
13
+ this.debug = (ns, msg, data) => this.log('DEBUG', ns, msg, data);
14
+ this.verbose = (ns, msg, data) => this.log('VERBOSE', ns, msg, data);
15
+ }
16
+ log(level, ns, msg, data) {
17
+ const mode = this.get('config')?.mode;
18
+ if (!this.shouldShow(level, mode))
97
19
  return;
98
- }
99
- const formattedMessage = this.formatMessage(namespace, message);
100
- const consoleMethod = this.getConsoleMethod(level);
20
+ const formattedMsg = `[TraceLog:${ns}] ${msg}`;
21
+ const method = this.getMethod(level);
101
22
  if (data !== undefined) {
102
- console[consoleMethod](formattedMessage, data);
23
+ console[method](formattedMsg, data);
103
24
  }
104
25
  else {
105
- console[consoleMethod](formattedMessage);
106
- }
107
- if (process.env.NODE_ENV === 'dev') {
108
- this.dispatchEvent(level, namespace, message, data);
109
- }
110
- }
111
- /**
112
- * Dispatches tracelog:log events for E2E testing and development debugging
113
- */
114
- dispatchEvent(level, namespace, message, data) {
115
- if (typeof window === 'undefined' || typeof CustomEvent === 'undefined') {
116
- return;
117
- }
118
- try {
119
- const event = new CustomEvent('tracelog:log', {
120
- detail: {
121
- timestamp: new Date().toISOString(),
122
- level,
123
- namespace,
124
- message,
125
- data,
126
- },
127
- });
128
- window.dispatchEvent(event);
129
- }
130
- catch {
131
- console.log(`[TraceLog:${namespace}] ${message}`, data);
132
- }
26
+ console[method](formattedMsg);
27
+ }
28
+ }
29
+ shouldShow(level, mode) {
30
+ if (['CLIENT_ERROR', 'ERROR'].includes(level))
31
+ return true;
32
+ if (!mode)
33
+ return level === 'CLIENT_WARN';
34
+ if (mode === 'qa')
35
+ return ['INFO', 'CLIENT_ERROR', 'CLIENT_WARN'].includes(level);
36
+ if (mode === 'debug')
37
+ return true; // Debug mode shows all logs
38
+ return false;
39
+ }
40
+ getMethod(level) {
41
+ if (['CLIENT_ERROR', 'ERROR'].includes(level))
42
+ return 'error';
43
+ if (['CLIENT_WARN', 'WARN'].includes(level))
44
+ return 'warn';
45
+ return 'log';
133
46
  }
134
47
  }
135
- /**
136
- * Singleton debug logger instance
137
- * Provides the same API as before: debugLog.clientError(), debugLog.info(), etc.
138
- */
139
48
  exports.debugLog = new DebugLogger();
@@ -0,0 +1,4 @@
1
+ export interface FetchWithTimeoutOptions extends RequestInit {
2
+ timeout?: number;
3
+ }
4
+ export declare function fetchWithTimeout(url: string, options?: FetchWithTimeoutOptions): Promise<Response>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchWithTimeout = fetchWithTimeout;
4
+ async function fetchWithTimeout(url, options = {}) {
5
+ const { timeout = 10000, ...fetchOptions } = options;
6
+ const controller = new AbortController();
7
+ const timeoutId = setTimeout(() => {
8
+ controller.abort();
9
+ }, timeout);
10
+ try {
11
+ const response = await fetch(url, {
12
+ ...fetchOptions,
13
+ signal: controller.signal,
14
+ });
15
+ clearTimeout(timeoutId);
16
+ return response;
17
+ }
18
+ catch (error) {
19
+ clearTimeout(timeoutId);
20
+ if (error instanceof Error && error.name === 'AbortError') {
21
+ throw new Error(`Request timeout after ${timeout}ms`);
22
+ }
23
+ throw error;
24
+ }
25
+ }
@@ -1 +1,2 @@
1
1
  export * from './url.utils';
2
+ export * from './fetch-with-timeout.utils';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./url.utils"), exports);
18
+ __exportStar(require("./fetch-with-timeout.utils"), exports);
@@ -9,7 +9,6 @@ const logging_1 = require("../logging");
9
9
  * @returns The generated API URL
10
10
  */
11
11
  const getApiUrl = (id, allowHttp = false) => {
12
- logging_1.debugLog.debug('URLUtils', 'Generating API URL', { projectId: id, allowHttp });
13
12
  const url = new URL(window.location.href);
14
13
  const host = url.hostname;
15
14
  const parts = host.split('.');
@@ -20,14 +19,6 @@ const getApiUrl = (id, allowHttp = false) => {
20
19
  const cleanDomain = parts.slice(-2).join('.');
21
20
  const protocol = allowHttp && url.protocol === 'http:' ? 'http' : 'https';
22
21
  const apiUrl = `${protocol}://${id}.${cleanDomain}`;
23
- logging_1.debugLog.debug('URLUtils', 'Generated API URL', {
24
- originalUrl: window.location.href,
25
- hostname: host,
26
- domainParts: parts.length,
27
- cleanDomain,
28
- protocol,
29
- generatedUrl: apiUrl,
30
- });
31
22
  const isValid = (0, validations_1.isValidUrl)(apiUrl, allowHttp);
32
23
  if (!isValid) {
33
24
  logging_1.debugLog.clientError('URLUtils', 'Generated API URL failed validation', {
@@ -36,7 +27,6 @@ const getApiUrl = (id, allowHttp = false) => {
36
27
  });
37
28
  throw new Error('Invalid URL');
38
29
  }
39
- logging_1.debugLog.debug('URLUtils', 'API URL generation completed successfully', { apiUrl });
40
30
  return apiUrl;
41
31
  };
42
32
  exports.getApiUrl = getApiUrl;
@@ -47,10 +37,6 @@ exports.getApiUrl = getApiUrl;
47
37
  * @returns The normalized URL
48
38
  */
49
39
  const normalizeUrl = (url, sensitiveQueryParams = []) => {
50
- logging_1.debugLog.debug('URLUtils', 'Normalizing URL', {
51
- urlLength: url.length,
52
- sensitiveParamsCount: sensitiveQueryParams.length,
53
- });
54
40
  try {
55
41
  const urlObject = new URL(url);
56
42
  const searchParams = urlObject.searchParams;
@@ -72,16 +58,10 @@ const normalizeUrl = (url, sensitiveQueryParams = []) => {
72
58
  });
73
59
  }
74
60
  if (!hasChanged && url.includes('?')) {
75
- logging_1.debugLog.debug('URLUtils', 'URL normalization - no changes needed');
76
61
  return url;
77
62
  }
78
63
  urlObject.search = searchParams.toString();
79
64
  const result = urlObject.toString();
80
- logging_1.debugLog.debug('URLUtils', 'URL normalization completed', {
81
- hasChanged,
82
- originalLength: url.length,
83
- normalizedLength: result.length,
84
- });
85
65
  return result;
86
66
  }
87
67
  catch (error) {
@@ -100,18 +80,13 @@ exports.normalizeUrl = normalizeUrl;
100
80
  * @returns True if the URL should be excluded
101
81
  */
102
82
  const isUrlPathExcluded = (url, excludedPaths = []) => {
103
- logging_1.debugLog.debug('URLUtils', 'Checking if URL path is excluded', {
104
- urlLength: url.length,
105
- excludedPathsCount: excludedPaths.length,
106
- });
107
83
  if (excludedPaths.length === 0) {
108
- logging_1.debugLog.debug('URLUtils', 'No excluded paths configured');
109
84
  return false;
110
85
  }
111
86
  let path;
112
87
  try {
113
- path = new URL(url, window.location.origin).pathname;
114
- logging_1.debugLog.debug('URLUtils', 'Extracted path from URL', { path });
88
+ const parsedUrl = new URL(url, window.location.origin);
89
+ path = parsedUrl.pathname + (parsedUrl.hash ?? '');
115
90
  }
116
91
  catch (error) {
117
92
  logging_1.debugLog.warn('URLUtils', 'Failed to parse URL for path exclusion check', {
@@ -132,23 +107,14 @@ const isUrlPathExcluded = (url, excludedPaths = []) => {
132
107
  try {
133
108
  if (isRegularExpression(pattern)) {
134
109
  const matches = pattern.test(path);
135
- if (matches) {
136
- logging_1.debugLog.debug('URLUtils', 'Path matched regex pattern', { path, pattern: pattern.toString() });
137
- }
138
110
  return matches;
139
111
  }
140
112
  if (pattern.includes('*')) {
141
113
  const regex = wildcardToRegex(pattern);
142
114
  const matches = regex.test(path);
143
- if (matches) {
144
- logging_1.debugLog.debug('URLUtils', 'Path matched wildcard pattern', { path, pattern, regex: regex.toString() });
145
- }
146
115
  return matches;
147
116
  }
148
117
  const matches = pattern === path;
149
- if (matches) {
150
- logging_1.debugLog.debug('URLUtils', 'Path matched exact pattern', { path, pattern });
151
- }
152
118
  return matches;
153
119
  }
154
120
  catch (error) {
@@ -161,12 +127,6 @@ const isUrlPathExcluded = (url, excludedPaths = []) => {
161
127
  }
162
128
  });
163
129
  const isExcluded = !!matchedPattern;
164
- logging_1.debugLog.debug('URLUtils', 'URL path exclusion check completed', {
165
- path,
166
- isExcluded,
167
- matchedPattern: matchedPattern ?? null,
168
- totalPatternsChecked: excludedPaths.length,
169
- });
170
130
  return isExcluded;
171
131
  };
172
132
  exports.isUrlPathExcluded = isUrlPathExcluded;
@@ -1,5 +1,4 @@
1
- import { MetadataType } from '../../types/common.types';
2
- import { ApiConfig } from '../../types/config.types';
1
+ import { MetadataType, ApiConfig } from '../../types';
3
2
  /**
4
3
  * Sanitizes a string value to prevent XSS attacks
5
4
  * @param value - The string to sanitize
@@ -24,9 +23,3 @@ export declare const sanitizeApiConfig: (data: unknown) => ApiConfig;
24
23
  * @returns The sanitized metadata
25
24
  */
26
25
  export declare const sanitizeMetadata: (metadata: unknown) => Record<string, MetadataType>;
27
- /**
28
- * Sanitizes URL strings for tracking
29
- * @param url - The URL to sanitize
30
- * @returns The sanitized URL
31
- */
32
- export declare const sanitizeUrl: (url: string) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizeUrl = exports.sanitizeMetadata = exports.sanitizeApiConfig = exports.sanitizePathString = exports.sanitizeString = void 0;
3
+ exports.sanitizeMetadata = exports.sanitizeApiConfig = exports.sanitizePathString = exports.sanitizeString = void 0;
4
4
  const constants_1 = require("../../constants");
5
5
  const logging_1 = require("../logging");
6
6
  /**
@@ -211,6 +211,12 @@ const sanitizeApiConfig = (data) => {
211
211
  logging_1.debugLog.warn('Sanitize', 'Tags value is not an array', { value, type: typeof value });
212
212
  }
213
213
  }
214
+ else if (key === 'samplingRate') {
215
+ const sanitizedValue = sanitizeValue(value);
216
+ if (typeof sanitizedValue === 'number') {
217
+ safeData.samplingRate = sanitizedValue;
218
+ }
219
+ }
214
220
  else {
215
221
  const sanitizedValue = sanitizeValue(value);
216
222
  if (sanitizedValue !== null) {
@@ -277,43 +283,3 @@ const sanitizeMetadata = (metadata) => {
277
283
  }
278
284
  };
279
285
  exports.sanitizeMetadata = sanitizeMetadata;
280
- /**
281
- * Sanitizes URL strings for tracking
282
- * @param url - The URL to sanitize
283
- * @returns The sanitized URL
284
- */
285
- const sanitizeUrl = (url) => {
286
- logging_1.debugLog.debug('Sanitize', 'Starting URL sanitization', { urlLength: typeof url === 'string' ? url.length : 0 });
287
- if (typeof url !== 'string') {
288
- logging_1.debugLog.warn('Sanitize', 'URL is not a string', { url, type: typeof url });
289
- return '';
290
- }
291
- try {
292
- // Basic URL validation
293
- const urlObject = new URL(url);
294
- // Only allow http/https protocols
295
- if (!['http:', 'https:'].includes(urlObject.protocol)) {
296
- logging_1.debugLog.warn('Sanitize', 'URL protocol not allowed', {
297
- protocol: urlObject.protocol,
298
- allowedProtocols: ['http:', 'https:'],
299
- });
300
- return '';
301
- }
302
- // Sanitize the URL string
303
- const result = (0, exports.sanitizeString)(urlObject.href);
304
- logging_1.debugLog.debug('Sanitize', 'URL sanitization completed via URL object', {
305
- originalLength: url.length,
306
- sanitizedLength: result.length,
307
- protocol: urlObject.protocol,
308
- });
309
- return result;
310
- }
311
- catch {
312
- // If URL parsing fails, sanitize as string
313
- logging_1.debugLog.warn('Sanitize', 'URL parsing failed, falling back to string sanitization', {
314
- urlPreview: url.slice(0, 100),
315
- });
316
- return (0, exports.sanitizeString)(url);
317
- }
318
- };
319
- exports.sanitizeUrl = sanitizeUrl;
@@ -24,6 +24,12 @@ export declare const validateAndNormalizeConfig: (config: AppConfig) => AppConfi
24
24
  export declare const validateConfig: (config: Config) => {
25
25
  errors: string[];
26
26
  warnings: string[];
27
+ samplingRate: number;
28
+ };
29
+ export declare const normalizeConfig: (config: Config) => {
30
+ config: Config;
31
+ errors: string[];
32
+ warnings: string[];
27
33
  };
28
34
  /**
29
35
  * Validates the final configuration
@@ -33,6 +39,7 @@ export declare const validateConfig: (config: Config) => {
33
39
  export declare const validateFinalConfig: (config: Config) => {
34
40
  errors: string[];
35
41
  warnings: string[];
42
+ samplingRate: number;
36
43
  };
37
44
  /**
38
45
  * Type guard to check if a JSON response is a valid API config
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isValidConfigApiResponse = exports.validateFinalConfig = exports.validateConfig = exports.validateAndNormalizeConfig = exports.validateAppConfig = void 0;
3
+ exports.isValidConfigApiResponse = exports.validateFinalConfig = exports.normalizeConfig = exports.validateConfig = exports.validateAndNormalizeConfig = exports.validateAppConfig = void 0;
4
4
  const constants_1 = require("../../constants");
5
5
  const types_1 = require("../../types");
6
6
  const validation_error_types_1 = require("../../types/validation-error.types");
@@ -87,6 +87,47 @@ const validateAppConfig = (config) => {
87
87
  }
88
88
  };
89
89
  exports.validateAppConfig = validateAppConfig;
90
+ /**
91
+ * Validates CSS selector syntax without executing querySelector (XSS prevention)
92
+ * @param selector - CSS selector to validate
93
+ * @returns True if the selector syntax is valid
94
+ */
95
+ const isValidCssSelectorSyntax = (selector) => {
96
+ // Prevent dangerous characters that could indicate XSS attempts
97
+ if (selector.includes('<') || selector.includes('>') || /on\w+\s*=/i.test(selector)) {
98
+ return false;
99
+ }
100
+ // Safe CSS selector pattern - allows common selector syntax
101
+ const safePattern = /^[a-zA-Z0-9\-_#.[\]="':, >+~*()]+$/;
102
+ if (!safePattern.test(selector)) {
103
+ return false;
104
+ }
105
+ // Check for balanced parentheses
106
+ let parenthesesCount = 0;
107
+ for (const char of selector) {
108
+ if (char === '(')
109
+ parenthesesCount++;
110
+ if (char === ')')
111
+ parenthesesCount--;
112
+ if (parenthesesCount < 0)
113
+ return false;
114
+ }
115
+ if (parenthesesCount !== 0)
116
+ return false;
117
+ // Check for balanced square brackets
118
+ let bracketsCount = 0;
119
+ for (const char of selector) {
120
+ if (char === '[')
121
+ bracketsCount++;
122
+ if (char === ']')
123
+ bracketsCount--;
124
+ if (bracketsCount < 0)
125
+ return false;
126
+ }
127
+ if (bracketsCount !== 0)
128
+ return false;
129
+ return true;
130
+ };
90
131
  /**
91
132
  * Validates scroll container selectors
92
133
  * @param selectors - CSS selectors to validate
@@ -102,16 +143,14 @@ const validateScrollContainerSelectors = (selectors) => {
102
143
  });
103
144
  throw new validation_error_types_1.AppConfigValidationError(constants_1.VALIDATION_MESSAGES.INVALID_SCROLL_CONTAINER_SELECTORS, 'config');
104
145
  }
105
- // Validate CSS selector syntax but handle invalid selectors gracefully
106
- if (typeof document !== 'undefined') {
107
- try {
108
- document.querySelector(selector);
109
- }
110
- catch {
111
- // Invalid CSS selectors are handled gracefully
112
- // they will be ignored by the ScrollHandler and it will fall back to window scrolling
113
- logging_1.debugLog.clientWarn('ConfigValidation', `Invalid CSS selector will be ignored: "${selector}"`);
114
- }
146
+ // Validate CSS selector syntax using regex-based validation (XSS prevention)
147
+ // This validates syntax WITHOUT executing document.querySelector()
148
+ if (!isValidCssSelectorSyntax(selector)) {
149
+ logging_1.debugLog.clientError('ConfigValidation', 'Invalid or potentially unsafe CSS selector', {
150
+ selector,
151
+ reason: 'Failed security validation',
152
+ });
153
+ throw new validation_error_types_1.AppConfigValidationError('Invalid or potentially unsafe CSS selector', 'config');
115
154
  }
116
155
  }
117
156
  };
@@ -176,14 +215,18 @@ exports.validateAndNormalizeConfig = validateAndNormalizeConfig;
176
215
  * @param errors - Array to push errors to
177
216
  */
178
217
  const validateSamplingRate = (samplingRate, errors) => {
179
- if (samplingRate !== undefined) {
180
- if (typeof samplingRate !== 'number') {
181
- errors.push('samplingRate must be a number');
182
- }
183
- else if (samplingRate < 0 || samplingRate > 1) {
184
- errors.push('samplingRate must be between 0 and 1');
185
- }
218
+ if (samplingRate === undefined) {
219
+ return undefined;
220
+ }
221
+ if (typeof samplingRate !== 'number') {
222
+ errors.push('samplingRate must be a number');
223
+ return constants_1.DEFAULT_SAMPLING_RATE;
224
+ }
225
+ if (Number.isNaN(samplingRate) || samplingRate <= 0 || samplingRate > 1) {
226
+ errors.push(constants_1.VALIDATION_MESSAGES.INVALID_SAMPLING_RATE);
227
+ return constants_1.DEFAULT_SAMPLING_RATE;
186
228
  }
229
+ return samplingRate;
187
230
  };
188
231
  /**
189
232
  * Validates excluded URL paths
@@ -247,14 +290,26 @@ const validateConfig = (config) => {
247
290
  }
248
291
  }
249
292
  // No custom API endpoints supported
250
- validateSamplingRate(config.samplingRate, errors);
293
+ const validatedSamplingRate = validateSamplingRate(config.samplingRate, errors) ?? constants_1.DEFAULT_SAMPLING_RATE;
251
294
  if (config.tags !== undefined && !Array.isArray(config.tags)) {
252
295
  errors.push('tags must be an array');
253
296
  }
254
297
  validateExcludedUrlPaths(config.excludedUrlPaths, errors);
255
- return { errors, warnings };
298
+ return { errors, warnings, samplingRate: validatedSamplingRate };
256
299
  };
257
300
  exports.validateConfig = validateConfig;
301
+ const normalizeConfig = (config) => {
302
+ const { errors, warnings, samplingRate } = (0, exports.validateConfig)(config);
303
+ return {
304
+ config: {
305
+ ...config,
306
+ samplingRate,
307
+ },
308
+ errors,
309
+ warnings,
310
+ };
311
+ };
312
+ exports.normalizeConfig = normalizeConfig;
258
313
  /**
259
314
  * Validates the final configuration
260
315
  * @param config - The configuration to validate
@@ -263,10 +318,10 @@ exports.validateConfig = validateConfig;
263
318
  const validateFinalConfig = (config) => {
264
319
  const errors = [];
265
320
  const warnings = [];
266
- validateSamplingRate(config.samplingRate, errors);
321
+ const validatedSamplingRate = validateSamplingRate(config.samplingRate, errors) ?? constants_1.DEFAULT_SAMPLING_RATE;
267
322
  validateExcludedUrlPaths(config.excludedUrlPaths, errors);
268
323
  // No custom API endpoints supported
269
- return { errors, warnings };
324
+ return { errors, warnings, samplingRate: validatedSamplingRate };
270
325
  };
271
326
  exports.validateFinalConfig = validateFinalConfig;
272
327
  /**