@tracelog/lib 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -0
  3. package/dist/browser/tracelog.js +4040 -0
  4. package/dist/browser/web-vitals-CCnqwnC8.mjs +198 -0
  5. package/dist/cjs/api.d.ts +46 -0
  6. package/dist/cjs/api.js +224 -0
  7. package/dist/cjs/app.constants.d.ts +1 -0
  8. package/dist/cjs/app.constants.js +5 -0
  9. package/dist/cjs/app.d.ts +59 -0
  10. package/dist/cjs/app.js +272 -0
  11. package/dist/cjs/app.types.d.ts +6 -0
  12. package/dist/cjs/app.types.js +22 -0
  13. package/dist/cjs/constants/api.constants.d.ts +4 -0
  14. package/dist/cjs/constants/api.constants.js +18 -0
  15. package/dist/cjs/constants/browser.constants.d.ts +3 -0
  16. package/dist/cjs/constants/browser.constants.js +41 -0
  17. package/dist/cjs/constants/index.d.ts +8 -0
  18. package/dist/cjs/constants/index.js +24 -0
  19. package/dist/cjs/constants/initialization.constants.d.ts +40 -0
  20. package/dist/cjs/constants/initialization.constants.js +48 -0
  21. package/dist/cjs/constants/limits.constants.d.ts +25 -0
  22. package/dist/cjs/constants/limits.constants.js +40 -0
  23. package/dist/cjs/constants/security.constants.d.ts +1 -0
  24. package/dist/cjs/constants/security.constants.js +12 -0
  25. package/dist/cjs/constants/storage.constants.d.ts +9 -0
  26. package/dist/cjs/constants/storage.constants.js +22 -0
  27. package/dist/cjs/constants/timing.constants.d.ts +22 -0
  28. package/dist/cjs/constants/timing.constants.js +34 -0
  29. package/dist/cjs/constants/validation.constants.d.ts +13 -0
  30. package/dist/cjs/constants/validation.constants.js +31 -0
  31. package/dist/cjs/handlers/click.handler.d.ts +17 -0
  32. package/dist/cjs/handlers/click.handler.js +199 -0
  33. package/dist/cjs/handlers/error.handler.d.ts +15 -0
  34. package/dist/cjs/handlers/error.handler.js +97 -0
  35. package/dist/cjs/handlers/network.handler.d.ts +16 -0
  36. package/dist/cjs/handlers/network.handler.js +136 -0
  37. package/dist/cjs/handlers/page-view.handler.d.ts +15 -0
  38. package/dist/cjs/handlers/page-view.handler.js +83 -0
  39. package/dist/cjs/handlers/performance.handler.d.ts +19 -0
  40. package/dist/cjs/handlers/performance.handler.js +255 -0
  41. package/dist/cjs/handlers/scroll.handler.d.ts +16 -0
  42. package/dist/cjs/handlers/scroll.handler.js +138 -0
  43. package/dist/cjs/handlers/session.handler.d.ts +29 -0
  44. package/dist/cjs/handlers/session.handler.js +357 -0
  45. package/dist/cjs/integrations/google-analytics.integration.d.ts +18 -0
  46. package/dist/cjs/integrations/google-analytics.integration.js +159 -0
  47. package/dist/cjs/listeners/activity-listener-manager.d.ts +8 -0
  48. package/dist/cjs/listeners/activity-listener-manager.js +32 -0
  49. package/dist/cjs/listeners/index.d.ts +6 -0
  50. package/dist/cjs/listeners/index.js +14 -0
  51. package/dist/cjs/listeners/input-listener-managers.d.ts +15 -0
  52. package/dist/cjs/listeners/input-listener-managers.js +58 -0
  53. package/dist/cjs/listeners/listeners.types.d.ts +4 -0
  54. package/dist/cjs/listeners/listeners.types.js +2 -0
  55. package/dist/cjs/listeners/touch-listener-manager.d.ts +10 -0
  56. package/dist/cjs/listeners/touch-listener-manager.js +56 -0
  57. package/dist/cjs/listeners/unload-listener-manager.d.ts +8 -0
  58. package/dist/cjs/listeners/unload-listener-manager.js +30 -0
  59. package/dist/cjs/listeners/visibility-listener-manager.d.ts +12 -0
  60. package/dist/cjs/listeners/visibility-listener-manager.js +83 -0
  61. package/dist/cjs/managers/api.manager.d.ts +3 -0
  62. package/dist/cjs/managers/api.manager.js +14 -0
  63. package/dist/cjs/managers/config.manager.d.ts +7 -0
  64. package/dist/cjs/managers/config.manager.js +94 -0
  65. package/dist/cjs/managers/cross-tab-session.manager.d.ts +170 -0
  66. package/dist/cjs/managers/cross-tab-session.manager.js +730 -0
  67. package/dist/cjs/managers/event.manager.d.ts +61 -0
  68. package/dist/cjs/managers/event.manager.js +508 -0
  69. package/dist/cjs/managers/sampling.manager.d.ts +8 -0
  70. package/dist/cjs/managers/sampling.manager.js +53 -0
  71. package/dist/cjs/managers/sender.manager.d.ts +46 -0
  72. package/dist/cjs/managers/sender.manager.js +304 -0
  73. package/dist/cjs/managers/session-recovery.manager.d.ts +65 -0
  74. package/dist/cjs/managers/session-recovery.manager.js +237 -0
  75. package/dist/cjs/managers/session.manager.d.ts +72 -0
  76. package/dist/cjs/managers/session.manager.js +587 -0
  77. package/dist/cjs/managers/state.manager.d.ts +5 -0
  78. package/dist/cjs/managers/state.manager.js +23 -0
  79. package/dist/cjs/managers/storage.manager.d.ts +10 -0
  80. package/dist/cjs/managers/storage.manager.js +81 -0
  81. package/dist/cjs/managers/tags.manager.d.ts +12 -0
  82. package/dist/cjs/managers/tags.manager.js +289 -0
  83. package/dist/cjs/managers/user.manager.d.ts +7 -0
  84. package/dist/cjs/managers/user.manager.js +22 -0
  85. package/dist/cjs/public-api.d.ts +1 -0
  86. package/dist/cjs/public-api.js +37 -0
  87. package/dist/cjs/types/api.types.d.ts +21 -0
  88. package/dist/cjs/types/api.types.js +25 -0
  89. package/dist/cjs/types/common.types.d.ts +1 -0
  90. package/dist/cjs/types/common.types.js +2 -0
  91. package/dist/cjs/types/config.types.d.ts +104 -0
  92. package/dist/cjs/types/config.types.js +2 -0
  93. package/dist/cjs/types/device.types.d.ts +6 -0
  94. package/dist/cjs/types/device.types.js +10 -0
  95. package/dist/cjs/types/event.types.d.ts +104 -0
  96. package/dist/cjs/types/event.types.js +25 -0
  97. package/dist/cjs/types/index.d.ts +13 -0
  98. package/dist/cjs/types/index.js +29 -0
  99. package/dist/cjs/types/log.types.d.ts +4 -0
  100. package/dist/cjs/types/log.types.js +2 -0
  101. package/dist/cjs/types/mode.types.d.ts +7 -0
  102. package/dist/cjs/types/mode.types.js +11 -0
  103. package/dist/cjs/types/queue.types.d.ts +23 -0
  104. package/dist/cjs/types/queue.types.js +2 -0
  105. package/dist/cjs/types/session.types.d.ts +65 -0
  106. package/dist/cjs/types/session.types.js +2 -0
  107. package/dist/cjs/types/state.types.d.ts +12 -0
  108. package/dist/cjs/types/state.types.js +2 -0
  109. package/dist/cjs/types/tag.types.d.ts +43 -0
  110. package/dist/cjs/types/tag.types.js +31 -0
  111. package/dist/cjs/types/validation-error.types.d.ts +42 -0
  112. package/dist/cjs/types/validation-error.types.js +68 -0
  113. package/dist/cjs/types/web-vitals.types.d.ts +6 -0
  114. package/dist/cjs/types/web-vitals.types.js +2 -0
  115. package/dist/cjs/types/window.types.d.ts +17 -0
  116. package/dist/cjs/types/window.types.js +2 -0
  117. package/dist/cjs/utils/browser/device-detector.utils.d.ts +6 -0
  118. package/dist/cjs/utils/browser/device-detector.utils.js +71 -0
  119. package/dist/cjs/utils/browser/index.d.ts +2 -0
  120. package/dist/cjs/utils/browser/index.js +18 -0
  121. package/dist/cjs/utils/browser/utm-params.utils.d.ts +6 -0
  122. package/dist/cjs/utils/browser/utm-params.utils.js +37 -0
  123. package/dist/cjs/utils/data/index.d.ts +1 -0
  124. package/dist/cjs/utils/data/index.js +17 -0
  125. package/dist/cjs/utils/data/uuid.utils.d.ts +5 -0
  126. package/dist/cjs/utils/data/uuid.utils.js +18 -0
  127. package/dist/cjs/utils/index.d.ts +6 -0
  128. package/dist/cjs/utils/index.js +22 -0
  129. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +56 -0
  130. package/dist/cjs/utils/logging/debug-logger.utils.js +139 -0
  131. package/dist/cjs/utils/logging/index.d.ts +1 -0
  132. package/dist/cjs/utils/logging/index.js +5 -0
  133. package/dist/cjs/utils/network/index.d.ts +1 -0
  134. package/dist/cjs/utils/network/index.js +17 -0
  135. package/dist/cjs/utils/network/url.utils.d.ts +20 -0
  136. package/dist/cjs/utils/network/url.utils.js +172 -0
  137. package/dist/cjs/utils/security/index.d.ts +1 -0
  138. package/dist/cjs/utils/security/index.js +17 -0
  139. package/dist/cjs/utils/security/sanitize.utils.d.ts +32 -0
  140. package/dist/cjs/utils/security/sanitize.utils.js +319 -0
  141. package/dist/cjs/utils/validations/config-validations.utils.d.ts +42 -0
  142. package/dist/cjs/utils/validations/config-validations.utils.js +297 -0
  143. package/dist/cjs/utils/validations/event-validations.utils.d.ts +12 -0
  144. package/dist/cjs/utils/validations/event-validations.utils.js +30 -0
  145. package/dist/cjs/utils/validations/index.d.ts +5 -0
  146. package/dist/cjs/utils/validations/index.js +21 -0
  147. package/dist/cjs/utils/validations/metadata-validations.utils.d.ts +22 -0
  148. package/dist/cjs/utils/validations/metadata-validations.utils.js +115 -0
  149. package/dist/cjs/utils/validations/type-guards.utils.d.ts +6 -0
  150. package/dist/cjs/utils/validations/type-guards.utils.js +31 -0
  151. package/dist/cjs/utils/validations/url-validations.utils.d.ts +15 -0
  152. package/dist/cjs/utils/validations/url-validations.utils.js +47 -0
  153. package/dist/esm/api.d.ts +46 -0
  154. package/dist/esm/api.js +183 -0
  155. package/dist/esm/app.constants.d.ts +1 -0
  156. package/dist/esm/app.constants.js +1 -0
  157. package/dist/esm/app.d.ts +59 -0
  158. package/dist/esm/app.js +268 -0
  159. package/dist/esm/app.types.d.ts +6 -0
  160. package/dist/esm/app.types.js +6 -0
  161. package/dist/esm/constants/api.constants.d.ts +4 -0
  162. package/dist/esm/constants/api.constants.js +14 -0
  163. package/dist/esm/constants/browser.constants.d.ts +3 -0
  164. package/dist/esm/constants/browser.constants.js +38 -0
  165. package/dist/esm/constants/index.d.ts +8 -0
  166. package/dist/esm/constants/index.js +8 -0
  167. package/dist/esm/constants/initialization.constants.d.ts +40 -0
  168. package/dist/esm/constants/initialization.constants.js +45 -0
  169. package/dist/esm/constants/limits.constants.d.ts +25 -0
  170. package/dist/esm/constants/limits.constants.js +37 -0
  171. package/dist/esm/constants/security.constants.d.ts +1 -0
  172. package/dist/esm/constants/security.constants.js +9 -0
  173. package/dist/esm/constants/storage.constants.d.ts +9 -0
  174. package/dist/esm/constants/storage.constants.js +11 -0
  175. package/dist/esm/constants/timing.constants.d.ts +22 -0
  176. package/dist/esm/constants/timing.constants.js +31 -0
  177. package/dist/esm/constants/validation.constants.d.ts +13 -0
  178. package/dist/esm/constants/validation.constants.js +28 -0
  179. package/dist/esm/handlers/click.handler.d.ts +17 -0
  180. package/dist/esm/handlers/click.handler.js +195 -0
  181. package/dist/esm/handlers/error.handler.d.ts +15 -0
  182. package/dist/esm/handlers/error.handler.js +93 -0
  183. package/dist/esm/handlers/network.handler.d.ts +16 -0
  184. package/dist/esm/handlers/network.handler.js +132 -0
  185. package/dist/esm/handlers/page-view.handler.d.ts +15 -0
  186. package/dist/esm/handlers/page-view.handler.js +79 -0
  187. package/dist/esm/handlers/performance.handler.d.ts +19 -0
  188. package/dist/esm/handlers/performance.handler.js +218 -0
  189. package/dist/esm/handlers/scroll.handler.d.ts +16 -0
  190. package/dist/esm/handlers/scroll.handler.js +134 -0
  191. package/dist/esm/handlers/session.handler.d.ts +29 -0
  192. package/dist/esm/handlers/session.handler.js +353 -0
  193. package/dist/esm/integrations/google-analytics.integration.d.ts +18 -0
  194. package/dist/esm/integrations/google-analytics.integration.js +155 -0
  195. package/dist/esm/listeners/activity-listener-manager.d.ts +8 -0
  196. package/dist/esm/listeners/activity-listener-manager.js +28 -0
  197. package/dist/esm/listeners/index.d.ts +6 -0
  198. package/dist/esm/listeners/index.js +5 -0
  199. package/dist/esm/listeners/input-listener-managers.d.ts +15 -0
  200. package/dist/esm/listeners/input-listener-managers.js +53 -0
  201. package/dist/esm/listeners/listeners.types.d.ts +4 -0
  202. package/dist/esm/listeners/listeners.types.js +1 -0
  203. package/dist/esm/listeners/touch-listener-manager.d.ts +10 -0
  204. package/dist/esm/listeners/touch-listener-manager.js +52 -0
  205. package/dist/esm/listeners/unload-listener-manager.d.ts +8 -0
  206. package/dist/esm/listeners/unload-listener-manager.js +26 -0
  207. package/dist/esm/listeners/visibility-listener-manager.d.ts +12 -0
  208. package/dist/esm/listeners/visibility-listener-manager.js +79 -0
  209. package/dist/esm/managers/api.manager.d.ts +3 -0
  210. package/dist/esm/managers/api.manager.js +10 -0
  211. package/dist/esm/managers/config.manager.d.ts +7 -0
  212. package/dist/esm/managers/config.manager.js +90 -0
  213. package/dist/esm/managers/cross-tab-session.manager.d.ts +170 -0
  214. package/dist/esm/managers/cross-tab-session.manager.js +726 -0
  215. package/dist/esm/managers/event.manager.d.ts +61 -0
  216. package/dist/esm/managers/event.manager.js +504 -0
  217. package/dist/esm/managers/sampling.manager.d.ts +8 -0
  218. package/dist/esm/managers/sampling.manager.js +49 -0
  219. package/dist/esm/managers/sender.manager.d.ts +46 -0
  220. package/dist/esm/managers/sender.manager.js +300 -0
  221. package/dist/esm/managers/session-recovery.manager.d.ts +65 -0
  222. package/dist/esm/managers/session-recovery.manager.js +233 -0
  223. package/dist/esm/managers/session.manager.d.ts +72 -0
  224. package/dist/esm/managers/session.manager.js +583 -0
  225. package/dist/esm/managers/state.manager.d.ts +5 -0
  226. package/dist/esm/managers/state.manager.js +19 -0
  227. package/dist/esm/managers/storage.manager.d.ts +10 -0
  228. package/dist/esm/managers/storage.manager.js +77 -0
  229. package/dist/esm/managers/tags.manager.d.ts +12 -0
  230. package/dist/esm/managers/tags.manager.js +285 -0
  231. package/dist/esm/managers/user.manager.d.ts +7 -0
  232. package/dist/esm/managers/user.manager.js +18 -0
  233. package/dist/esm/public-api.d.ts +1 -0
  234. package/dist/esm/public-api.js +1 -0
  235. package/dist/esm/types/api.types.d.ts +21 -0
  236. package/dist/esm/types/api.types.js +22 -0
  237. package/dist/esm/types/common.types.d.ts +1 -0
  238. package/dist/esm/types/common.types.js +1 -0
  239. package/dist/esm/types/config.types.d.ts +104 -0
  240. package/dist/esm/types/config.types.js +1 -0
  241. package/dist/esm/types/device.types.d.ts +6 -0
  242. package/dist/esm/types/device.types.js +7 -0
  243. package/dist/esm/types/event.types.d.ts +104 -0
  244. package/dist/esm/types/event.types.js +22 -0
  245. package/dist/esm/types/index.d.ts +13 -0
  246. package/dist/esm/types/index.js +13 -0
  247. package/dist/esm/types/log.types.d.ts +4 -0
  248. package/dist/esm/types/log.types.js +1 -0
  249. package/dist/esm/types/mode.types.d.ts +7 -0
  250. package/dist/esm/types/mode.types.js +8 -0
  251. package/dist/esm/types/queue.types.d.ts +23 -0
  252. package/dist/esm/types/queue.types.js +1 -0
  253. package/dist/esm/types/session.types.d.ts +65 -0
  254. package/dist/esm/types/session.types.js +1 -0
  255. package/dist/esm/types/state.types.d.ts +12 -0
  256. package/dist/esm/types/state.types.js +1 -0
  257. package/dist/esm/types/tag.types.d.ts +43 -0
  258. package/dist/esm/types/tag.types.js +28 -0
  259. package/dist/esm/types/validation-error.types.d.ts +42 -0
  260. package/dist/esm/types/validation-error.types.js +59 -0
  261. package/dist/esm/types/web-vitals.types.d.ts +6 -0
  262. package/dist/esm/types/web-vitals.types.js +1 -0
  263. package/dist/esm/types/window.types.d.ts +17 -0
  264. package/dist/esm/types/window.types.js +1 -0
  265. package/dist/esm/utils/browser/device-detector.utils.d.ts +6 -0
  266. package/dist/esm/utils/browser/device-detector.utils.js +67 -0
  267. package/dist/esm/utils/browser/index.d.ts +2 -0
  268. package/dist/esm/utils/browser/index.js +2 -0
  269. package/dist/esm/utils/browser/utm-params.utils.d.ts +6 -0
  270. package/dist/esm/utils/browser/utm-params.utils.js +33 -0
  271. package/dist/esm/utils/data/index.d.ts +1 -0
  272. package/dist/esm/utils/data/index.js +1 -0
  273. package/dist/esm/utils/data/uuid.utils.d.ts +5 -0
  274. package/dist/esm/utils/data/uuid.utils.js +14 -0
  275. package/dist/esm/utils/index.d.ts +6 -0
  276. package/dist/esm/utils/index.js +6 -0
  277. package/dist/esm/utils/logging/debug-logger.utils.d.ts +56 -0
  278. package/dist/esm/utils/logging/debug-logger.utils.js +136 -0
  279. package/dist/esm/utils/logging/index.d.ts +1 -0
  280. package/dist/esm/utils/logging/index.js +1 -0
  281. package/dist/esm/utils/network/index.d.ts +1 -0
  282. package/dist/esm/utils/network/index.js +1 -0
  283. package/dist/esm/utils/network/url.utils.d.ts +20 -0
  284. package/dist/esm/utils/network/url.utils.js +166 -0
  285. package/dist/esm/utils/security/index.d.ts +1 -0
  286. package/dist/esm/utils/security/index.js +1 -0
  287. package/dist/esm/utils/security/sanitize.utils.d.ts +32 -0
  288. package/dist/esm/utils/security/sanitize.utils.js +311 -0
  289. package/dist/esm/utils/validations/config-validations.utils.d.ts +42 -0
  290. package/dist/esm/utils/validations/config-validations.utils.js +289 -0
  291. package/dist/esm/utils/validations/event-validations.utils.d.ts +12 -0
  292. package/dist/esm/utils/validations/event-validations.utils.js +26 -0
  293. package/dist/esm/utils/validations/index.d.ts +5 -0
  294. package/dist/esm/utils/validations/index.js +5 -0
  295. package/dist/esm/utils/validations/metadata-validations.utils.d.ts +22 -0
  296. package/dist/esm/utils/validations/metadata-validations.utils.js +110 -0
  297. package/dist/esm/utils/validations/type-guards.utils.d.ts +6 -0
  298. package/dist/esm/utils/validations/type-guards.utils.js +27 -0
  299. package/dist/esm/utils/validations/url-validations.utils.d.ts +15 -0
  300. package/dist/esm/utils/validations/url-validations.utils.js +42 -0
  301. package/package.json +80 -0
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEventValid = void 0;
4
+ const metadata_validations_utils_1 = require("./metadata-validations.utils");
5
+ const logging_1 = require("../logging");
6
+ /**
7
+ * Validates a complete event with name and optional metadata
8
+ * @param eventName - The event name to validate
9
+ * @param metadata - Optional metadata to validate
10
+ * @returns Validation result with sanitized metadata if valid
11
+ */
12
+ const isEventValid = (eventName, metadata) => {
13
+ const nameValidation = (0, metadata_validations_utils_1.isValidEventName)(eventName);
14
+ if (!nameValidation.valid) {
15
+ logging_1.debugLog.clientError('EventValidation', 'Event name validation failed', { eventName, error: nameValidation.error });
16
+ return nameValidation;
17
+ }
18
+ if (!metadata) {
19
+ return { valid: true };
20
+ }
21
+ const metadataValidation = (0, metadata_validations_utils_1.isValidMetadata)(eventName, metadata, 'customEvent');
22
+ if (!metadataValidation.valid) {
23
+ logging_1.debugLog.clientError('EventValidation', 'Event metadata validation failed', {
24
+ eventName,
25
+ error: metadataValidation.error,
26
+ });
27
+ }
28
+ return metadataValidation;
29
+ };
30
+ exports.isEventValid = isEventValid;
@@ -0,0 +1,5 @@
1
+ export * from './config-validations.utils';
2
+ export * from './event-validations.utils';
3
+ export * from './metadata-validations.utils';
4
+ export * from './type-guards.utils';
5
+ export * from './url-validations.utils';
@@ -0,0 +1,21 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config-validations.utils"), exports);
18
+ __exportStar(require("./event-validations.utils"), exports);
19
+ __exportStar(require("./metadata-validations.utils"), exports);
20
+ __exportStar(require("./type-guards.utils"), exports);
21
+ __exportStar(require("./url-validations.utils"), exports);
@@ -0,0 +1,22 @@
1
+ import { MetadataType } from '../../types';
2
+ /**
3
+ * Validates an event name
4
+ * @param eventName - The event name to validate
5
+ * @returns Validation result with error message if invalid
6
+ */
7
+ export declare const isValidEventName: (eventName: string) => {
8
+ valid: boolean;
9
+ error?: string;
10
+ };
11
+ /**
12
+ * Validates metadata for events
13
+ * @param eventName - The event name (for error messages)
14
+ * @param metadata - The metadata to validate
15
+ * @param type - Type of metadata (globalMetadata or customEvent)
16
+ * @returns Validation result with sanitized metadata if valid
17
+ */
18
+ export declare const isValidMetadata: (eventName: string, metadata: Record<string, unknown>, type?: "globalMetadata" | "customEvent") => {
19
+ valid: boolean;
20
+ error?: string;
21
+ sanitizedMetadata?: Record<string, MetadataType>;
22
+ };
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidMetadata = exports.isValidEventName = void 0;
4
+ const constants_1 = require("../../constants");
5
+ const sanitize_utils_1 = require("../security/sanitize.utils");
6
+ const type_guards_utils_1 = require("./type-guards.utils");
7
+ /**
8
+ * Validates an event name
9
+ * @param eventName - The event name to validate
10
+ * @returns Validation result with error message if invalid
11
+ */
12
+ const isValidEventName = (eventName) => {
13
+ if (typeof eventName !== 'string') {
14
+ return {
15
+ valid: false,
16
+ error: 'Event name must be a string',
17
+ };
18
+ }
19
+ if (eventName.length === 0) {
20
+ return {
21
+ valid: false,
22
+ error: 'Event name cannot be empty',
23
+ };
24
+ }
25
+ if (eventName.length > constants_1.MAX_CUSTOM_EVENT_NAME_LENGTH) {
26
+ return {
27
+ valid: false,
28
+ error: `Event name is too long (max ${constants_1.MAX_CUSTOM_EVENT_NAME_LENGTH} characters)`,
29
+ };
30
+ }
31
+ if (eventName.includes('<') || eventName.includes('>') || eventName.includes('&')) {
32
+ return {
33
+ valid: false,
34
+ error: 'Event name contains invalid characters',
35
+ };
36
+ }
37
+ const reservedWords = ['constructor', 'prototype', '__proto__', 'eval', 'function', 'var', 'let', 'const'];
38
+ if (reservedWords.includes(eventName.toLowerCase())) {
39
+ return {
40
+ valid: false,
41
+ error: 'Event name cannot be a reserved word',
42
+ };
43
+ }
44
+ return { valid: true };
45
+ };
46
+ exports.isValidEventName = isValidEventName;
47
+ /**
48
+ * Validates metadata for events
49
+ * @param eventName - The event name (for error messages)
50
+ * @param metadata - The metadata to validate
51
+ * @param type - Type of metadata (globalMetadata or customEvent)
52
+ * @returns Validation result with sanitized metadata if valid
53
+ */
54
+ const isValidMetadata = (eventName, metadata, type) => {
55
+ const sanitizedMetadata = (0, sanitize_utils_1.sanitizeMetadata)(metadata);
56
+ const intro = type && type === 'customEvent' ? `${type} "${eventName}" metadata error` : `${eventName} metadata error`;
57
+ if (!(0, type_guards_utils_1.isOnlyPrimitiveFields)(sanitizedMetadata)) {
58
+ return {
59
+ valid: false,
60
+ error: `${intro}: object has invalid types. Valid types are string, number, boolean or string arrays.`,
61
+ };
62
+ }
63
+ let jsonString;
64
+ try {
65
+ jsonString = JSON.stringify(sanitizedMetadata);
66
+ }
67
+ catch {
68
+ return {
69
+ valid: false,
70
+ error: `${intro}: object contains circular references or cannot be serialized.`,
71
+ };
72
+ }
73
+ if (jsonString.length > constants_1.MAX_CUSTOM_EVENT_STRING_SIZE) {
74
+ return {
75
+ valid: false,
76
+ error: `${intro}: object is too large (max ${constants_1.MAX_CUSTOM_EVENT_STRING_SIZE / 1024} KB).`,
77
+ };
78
+ }
79
+ const keyCount = Object.keys(sanitizedMetadata).length;
80
+ if (keyCount > constants_1.MAX_CUSTOM_EVENT_KEYS) {
81
+ return {
82
+ valid: false,
83
+ error: `${intro}: object has too many keys (max ${constants_1.MAX_CUSTOM_EVENT_KEYS} keys).`,
84
+ };
85
+ }
86
+ for (const [key, value] of Object.entries(sanitizedMetadata)) {
87
+ if (Array.isArray(value)) {
88
+ if (value.length > constants_1.MAX_CUSTOM_EVENT_ARRAY_SIZE) {
89
+ return {
90
+ valid: false,
91
+ error: `${intro}: array property "${key}" is too large (max ${constants_1.MAX_CUSTOM_EVENT_ARRAY_SIZE} items).`,
92
+ };
93
+ }
94
+ for (const item of value) {
95
+ if (typeof item === 'string' && item.length > 500) {
96
+ return {
97
+ valid: false,
98
+ error: `${intro}: array property "${key}" contains strings that are too long (max 500 characters).`,
99
+ };
100
+ }
101
+ }
102
+ }
103
+ if (typeof value === 'string' && value.length > constants_1.MAX_STRING_LENGTH) {
104
+ return {
105
+ valid: false,
106
+ error: `${intro}: property "${key}" is too long (max ${constants_1.MAX_STRING_LENGTH} characters).`,
107
+ };
108
+ }
109
+ }
110
+ return {
111
+ valid: true,
112
+ sanitizedMetadata,
113
+ };
114
+ };
115
+ exports.isValidMetadata = isValidMetadata;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Checks if an object contains only primitive fields (string, number, boolean, or string arrays)
3
+ * @param object - The object to check
4
+ * @returns True if the object contains only primitive fields
5
+ */
6
+ export declare const isOnlyPrimitiveFields: (object: Record<string, unknown>) => boolean;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isOnlyPrimitiveFields = void 0;
4
+ /**
5
+ * Checks if an object contains only primitive fields (string, number, boolean, or string arrays)
6
+ * @param object - The object to check
7
+ * @returns True if the object contains only primitive fields
8
+ */
9
+ const isOnlyPrimitiveFields = (object) => {
10
+ if (typeof object !== 'object' || object === null) {
11
+ return false;
12
+ }
13
+ for (const value of Object.values(object)) {
14
+ if (value === null || value === undefined) {
15
+ continue;
16
+ }
17
+ const type = typeof value;
18
+ if (type === 'string' || type === 'number' || type === 'boolean') {
19
+ continue;
20
+ }
21
+ if (Array.isArray(value)) {
22
+ if (!value.every((item) => typeof item === 'string')) {
23
+ return false;
24
+ }
25
+ continue;
26
+ }
27
+ return false;
28
+ }
29
+ return true;
30
+ };
31
+ exports.isOnlyPrimitiveFields = isOnlyPrimitiveFields;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Validates if a URL is valid and optionally allows HTTP URLs
3
+ * @param url - The URL to validate
4
+ * @param allowHttp - Whether to allow HTTP URLs (default: false)
5
+ * @returns True if the URL is valid, false otherwise
6
+ */
7
+ export declare const isValidUrl: (url: string, allowHttp?: boolean) => boolean;
8
+ /**
9
+ * Validates a URL field in configuration
10
+ * @param url - The URL to validate
11
+ * @param allowHttp - Whether to allow HTTP URLs
12
+ * @param fieldName - The name of the field being validated
13
+ * @param errors - Array to push errors to
14
+ */
15
+ export declare const validateUrl: (url: unknown, allowHttp: boolean | undefined, fieldName: string, errors: string[]) => void;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateUrl = exports.isValidUrl = void 0;
4
+ /**
5
+ * Validates if a URL is valid and optionally allows HTTP URLs
6
+ * @param url - The URL to validate
7
+ * @param allowHttp - Whether to allow HTTP URLs (default: false)
8
+ * @returns True if the URL is valid, false otherwise
9
+ */
10
+ const isValidUrl = (url, allowHttp = false) => {
11
+ try {
12
+ const parsed = new URL(url);
13
+ const isHttps = parsed.protocol === 'https:';
14
+ const isHttp = parsed.protocol === 'http:';
15
+ return isHttps || (allowHttp && isHttp);
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ };
21
+ exports.isValidUrl = isValidUrl;
22
+ /**
23
+ * Validates a URL field in configuration
24
+ * @param url - The URL to validate
25
+ * @param allowHttp - Whether to allow HTTP URLs
26
+ * @param fieldName - The name of the field being validated
27
+ * @param errors - Array to push errors to
28
+ */
29
+ const validateUrl = (url, allowHttp, fieldName, errors) => {
30
+ if (url !== undefined) {
31
+ if (typeof url === 'string') {
32
+ try {
33
+ const parsed = new URL(url);
34
+ if (parsed.protocol === 'http:' && !allowHttp) {
35
+ errors.push(`${fieldName} using http requires allowHttp=true`);
36
+ }
37
+ }
38
+ catch {
39
+ errors.push(`${fieldName} must be a valid URL`);
40
+ }
41
+ }
42
+ else {
43
+ errors.push(`${fieldName} must be a string`);
44
+ }
45
+ }
46
+ };
47
+ exports.validateUrl = validateUrl;
@@ -0,0 +1,46 @@
1
+ import { MetadataType } from './types/common.types';
2
+ import { AppConfig } from './types/config.types';
3
+ import './types/window.types';
4
+ export * as Types from './app.types';
5
+ export * as Constants from './app.constants';
6
+ /**
7
+ * Initializes the tracelog app with the provided configuration.
8
+ * If already initialized, this function returns early without error.
9
+ * @param appConfig - The configuration object for the app
10
+ * @throws {Error} If initialization is currently in progress
11
+ * @example
12
+ * await init({ id: 'my-project-id' });
13
+ */
14
+ export declare const init: (appConfig: AppConfig) => Promise<void>;
15
+ /**
16
+ * Sends a custom event with the specified name and metadata.
17
+ * @param name - The name of the custom event.
18
+ * @param metadata - Optional metadata to attach to the event.
19
+ * @example
20
+ * // Send a custom event with metadata
21
+ * event('user_signup', { method: 'email', plan: 'premium' });
22
+ * @example
23
+ * // Send a custom event without metadata
24
+ * event('user_login');
25
+ * @remarks
26
+ * This function should be called after the app has been initialized using the `init` function.
27
+ */
28
+ export declare const event: (name: string, metadata?: Record<string, MetadataType>) => void;
29
+ /**
30
+ * Checks if the app has been initialized.
31
+ * @returns true if the app is initialized, false otherwise
32
+ */
33
+ export declare const isInitialized: () => boolean;
34
+ /**
35
+ * Gets the current initialization status for debugging purposes.
36
+ * @returns Object with detailed initialization state
37
+ */
38
+ export declare const getInitializationStatus: () => {
39
+ isInitialized: boolean;
40
+ isInitializing: boolean;
41
+ hasInstance: boolean;
42
+ };
43
+ /**
44
+ * Destroys the current app instance and cleans up resources.
45
+ */
46
+ export declare const destroy: () => void;
@@ -0,0 +1,183 @@
1
+ import { App } from './app';
2
+ import { debugLog } from './utils/logging';
3
+ import { validateAndNormalizeConfig } from './utils/validations';
4
+ import { INITIALIZATION_CONSTANTS } from './constants';
5
+ import './types/window.types';
6
+ export * as Types from './app.types';
7
+ export * as Constants from './app.constants';
8
+ let app = null;
9
+ let isInitializing = false;
10
+ /**
11
+ * Initializes the tracelog app with the provided configuration.
12
+ * If already initialized, this function returns early without error.
13
+ * @param appConfig - The configuration object for the app
14
+ * @throws {Error} If initialization is currently in progress
15
+ * @example
16
+ * await init({ id: 'my-project-id' });
17
+ */
18
+ export const init = async (appConfig) => {
19
+ try {
20
+ debugLog.info('API', 'Library initialization started', { id: appConfig.id });
21
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
22
+ debugLog.clientError('API', 'Browser environment required - this library can only be used in a browser environment', {
23
+ hasWindow: typeof window !== 'undefined',
24
+ hasDocument: typeof document !== 'undefined',
25
+ });
26
+ throw new Error('This library can only be used in a browser environment');
27
+ }
28
+ if (app) {
29
+ debugLog.debug('API', 'Library already initialized, skipping duplicate initialization', {
30
+ projectId: appConfig.id,
31
+ });
32
+ return;
33
+ }
34
+ if (isInitializing) {
35
+ debugLog.debug('API', 'Concurrent initialization detected, waiting for completion', { projectId: appConfig.id });
36
+ let retries = 0;
37
+ const maxRetries = INITIALIZATION_CONSTANTS.MAX_CONCURRENT_RETRIES;
38
+ const retryDelay = INITIALIZATION_CONSTANTS.CONCURRENT_RETRY_DELAY_MS;
39
+ while (isInitializing && retries < maxRetries) {
40
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
41
+ retries++;
42
+ }
43
+ if (app) {
44
+ debugLog.debug('API', 'Concurrent initialization completed successfully', {
45
+ projectId: appConfig.id,
46
+ retriesUsed: retries,
47
+ });
48
+ return;
49
+ }
50
+ if (isInitializing) {
51
+ debugLog.error('API', 'Initialization timeout - concurrent initialization took too long', {
52
+ projectId: appConfig.id,
53
+ retriesUsed: retries,
54
+ maxRetries,
55
+ });
56
+ throw new Error('App initialization timeout - concurrent initialization took too long');
57
+ }
58
+ }
59
+ isInitializing = true;
60
+ debugLog.debug('API', 'Validating and normalizing configuration', { projectId: appConfig.id });
61
+ const validatedConfig = validateAndNormalizeConfig(appConfig);
62
+ debugLog.debug('API', 'Creating App instance', { projectId: validatedConfig.id });
63
+ const instance = new App();
64
+ await instance.init(validatedConfig);
65
+ app = instance;
66
+ debugLog.info('API', 'Library initialization completed successfully', {
67
+ projectId: validatedConfig.id,
68
+ });
69
+ }
70
+ catch (error) {
71
+ // Ensure complete cleanup on initialization failure
72
+ if (app && !app.initialized) {
73
+ // Clean up partially initialized app instance
74
+ try {
75
+ app.destroy();
76
+ }
77
+ catch (cleanupError) {
78
+ debugLog.warn('API', 'Failed to cleanup partially initialized app', { cleanupError });
79
+ }
80
+ }
81
+ app = null;
82
+ debugLog.error('API', 'Initialization failed', { error });
83
+ throw error;
84
+ }
85
+ finally {
86
+ isInitializing = false;
87
+ }
88
+ };
89
+ /**
90
+ * Sends a custom event with the specified name and metadata.
91
+ * @param name - The name of the custom event.
92
+ * @param metadata - Optional metadata to attach to the event.
93
+ * @example
94
+ * // Send a custom event with metadata
95
+ * event('user_signup', { method: 'email', plan: 'premium' });
96
+ * @example
97
+ * // Send a custom event without metadata
98
+ * event('user_login');
99
+ * @remarks
100
+ * This function should be called after the app has been initialized using the `init` function.
101
+ */
102
+ export const event = (name, metadata) => {
103
+ try {
104
+ if (!app) {
105
+ debugLog.clientError('API', 'Custom event failed - Library not initialized. Please call TraceLog.init() first', {
106
+ eventName: name,
107
+ hasMetadata: !!metadata,
108
+ });
109
+ throw new Error('App not initialized');
110
+ }
111
+ debugLog.debug('API', 'Sending custom event', {
112
+ eventName: name,
113
+ hasMetadata: !!metadata,
114
+ metadataKeys: metadata ? Object.keys(metadata) : [],
115
+ });
116
+ app.sendCustomEvent(name, metadata);
117
+ }
118
+ catch (error) {
119
+ debugLog.error('API', 'Event tracking failed', { eventName: name, error, hasMetadata: !!metadata });
120
+ if (error instanceof Error &&
121
+ (error.message === 'App not initialized' || error.message.includes('validation failed'))) {
122
+ throw error;
123
+ }
124
+ }
125
+ };
126
+ /**
127
+ * Checks if the app has been initialized.
128
+ * @returns true if the app is initialized, false otherwise
129
+ */
130
+ export const isInitialized = () => {
131
+ return app !== null;
132
+ };
133
+ /**
134
+ * Gets the current initialization status for debugging purposes.
135
+ * @returns Object with detailed initialization state
136
+ */
137
+ export const getInitializationStatus = () => {
138
+ return {
139
+ isInitialized: app !== null,
140
+ isInitializing: isInitializing,
141
+ hasInstance: app !== null,
142
+ };
143
+ };
144
+ /**
145
+ * Destroys the current app instance and cleans up resources.
146
+ */
147
+ export const destroy = () => {
148
+ try {
149
+ debugLog.info('API', 'Library cleanup initiated');
150
+ if (!app) {
151
+ debugLog.warn('API', 'Cleanup called but Library was not initialized');
152
+ throw new Error('App not initialized');
153
+ }
154
+ app.destroy();
155
+ app = null;
156
+ isInitializing = false;
157
+ debugLog.info('API', 'Library cleanup completed successfully');
158
+ }
159
+ catch (error) {
160
+ debugLog.error('API', 'Cleanup failed', { error, hadApp: !!app, wasInitializing: isInitializing });
161
+ }
162
+ };
163
+ class TestBridge extends App {
164
+ isInitializing() {
165
+ return isInitializing;
166
+ }
167
+ }
168
+ // Auto-inject testing bridge only in development/testing environments
169
+ if (process.env.NODE_ENV === 'dev') {
170
+ if (typeof window !== 'undefined') {
171
+ // Wait for DOM to be ready before injecting
172
+ const injectTestingBridge = () => {
173
+ window.__traceLogBridge = new TestBridge();
174
+ };
175
+ // Inject immediately if DOM is ready, otherwise wait
176
+ if (document.readyState === 'loading') {
177
+ document.addEventListener('DOMContentLoaded', injectTestingBridge);
178
+ }
179
+ else {
180
+ injectTestingBridge();
181
+ }
182
+ }
183
+ }
@@ -0,0 +1 @@
1
+ export { DEFAULT_SESSION_TIMEOUT_MS } from './constants';
@@ -0,0 +1 @@
1
+ export { DEFAULT_SESSION_TIMEOUT_MS } from './constants';
@@ -0,0 +1,59 @@
1
+ import { EventManager } from './managers/event.manager';
2
+ import { AppConfig } from './types/config.types';
3
+ import { StateManager } from './managers/state.manager';
4
+ import { SessionHandler } from './handlers/session.handler';
5
+ import { PageViewHandler } from './handlers/page-view.handler';
6
+ import { ClickHandler } from './handlers/click.handler';
7
+ import { ScrollHandler } from './handlers/scroll.handler';
8
+ import { GoogleAnalyticsIntegration } from './integrations/google-analytics.integration';
9
+ import { StorageManager } from './managers/storage.manager';
10
+ import { PerformanceHandler } from './handlers/performance.handler';
11
+ import { ErrorHandler } from './handlers/error.handler';
12
+ import { NetworkHandler } from './handlers/network.handler';
13
+ export declare class App extends StateManager {
14
+ protected isInitialized: boolean;
15
+ protected googleAnalytics: GoogleAnalyticsIntegration | null;
16
+ protected storageManager: StorageManager;
17
+ protected eventManager: EventManager;
18
+ protected sessionHandler: SessionHandler;
19
+ protected pageViewHandler: PageViewHandler;
20
+ protected clickHandler: ClickHandler;
21
+ protected scrollHandler: ScrollHandler;
22
+ protected performanceHandler: PerformanceHandler;
23
+ protected errorHandler: ErrorHandler;
24
+ protected networkHandler: NetworkHandler;
25
+ protected suppressNextScrollTimer: number | null;
26
+ /**
27
+ * Returns the initialization status of the app
28
+ * @returns true if the app is fully initialized, false otherwise
29
+ */
30
+ get initialized(): boolean;
31
+ init(appConfig: AppConfig): Promise<void>;
32
+ /**
33
+ * Validates that the app is ready to initialize with the provided config
34
+ * This is a lightweight runtime validation layer that ensures the app receives proper config
35
+ * @param appConfig - The validated and normalized configuration
36
+ * @throws {ProjectIdValidationError} If project ID is invalid at runtime
37
+ */
38
+ private validateAppReadiness;
39
+ sendCustomEvent(name: string, metadata?: Record<string, unknown>): void;
40
+ destroy(): void;
41
+ private setState;
42
+ private setApiUrl;
43
+ private setConfig;
44
+ private setUserId;
45
+ private setDevice;
46
+ private setPageUrl;
47
+ private setIntegrations;
48
+ private initHandlers;
49
+ private initStorage;
50
+ private setEventManager;
51
+ private initSessionHandler;
52
+ private initPageViewHandler;
53
+ private onPageViewTrack;
54
+ private initClickHandler;
55
+ private initScrollHandler;
56
+ private initPerformanceHandler;
57
+ private initErrorHandler;
58
+ private initNetworkHandler;
59
+ }