@tracelog/lib 0.5.5 → 0.6.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 (202) hide show
  1. package/README.md +157 -180
  2. package/dist/browser/tracelog.esm.js +1124 -1377
  3. package/dist/browser/tracelog.esm.js.map +1 -0
  4. package/dist/browser/tracelog.js +2 -2
  5. package/dist/browser/tracelog.js.map +1 -0
  6. package/dist/cjs/api.d.ts +12 -2
  7. package/dist/cjs/api.js +74 -29
  8. package/dist/cjs/app.d.ts +2 -2
  9. package/dist/cjs/app.js +26 -32
  10. package/dist/cjs/constants/config.constants.d.ts +7 -2
  11. package/dist/cjs/constants/config.constants.js +9 -18
  12. package/dist/cjs/constants/index.d.ts +0 -1
  13. package/dist/cjs/constants/index.js +0 -1
  14. package/dist/cjs/constants/storage.constants.d.ts +3 -2
  15. package/dist/cjs/constants/storage.constants.js +4 -4
  16. package/dist/cjs/handlers/click.handler.js +3 -6
  17. package/dist/cjs/handlers/error.handler.js +1 -11
  18. package/dist/cjs/handlers/page-view.handler.js +0 -4
  19. package/dist/cjs/handlers/performance.handler.js +14 -29
  20. package/dist/cjs/handlers/scroll.handler.js +7 -6
  21. package/dist/cjs/handlers/session.handler.js +7 -6
  22. package/dist/cjs/integrations/google-analytics.integration.js +2 -6
  23. package/dist/cjs/listeners/activity-listener-manager.js +3 -3
  24. package/dist/cjs/listeners/input-listener-managers.js +3 -3
  25. package/dist/cjs/listeners/touch-listener-manager.js +3 -3
  26. package/dist/cjs/listeners/unload-listener-manager.js +3 -3
  27. package/dist/cjs/listeners/visibility-listener-manager.js +3 -3
  28. package/dist/cjs/managers/event.manager.d.ts +5 -1
  29. package/dist/cjs/managers/event.manager.js +103 -40
  30. package/dist/cjs/managers/sender.manager.js +29 -36
  31. package/dist/cjs/managers/session.manager.js +5 -13
  32. package/dist/cjs/managers/state.manager.d.ts +0 -3
  33. package/dist/cjs/managers/state.manager.js +1 -43
  34. package/dist/cjs/managers/storage.manager.d.ts +21 -2
  35. package/dist/cjs/managers/storage.manager.js +164 -21
  36. package/dist/cjs/managers/user.manager.d.ts +1 -1
  37. package/dist/cjs/managers/user.manager.js +2 -2
  38. package/dist/cjs/public-api.d.ts +3 -3
  39. package/dist/cjs/public-api.js +1 -1
  40. package/dist/cjs/test-bridge.d.ts +1 -0
  41. package/dist/cjs/test-bridge.js +37 -2
  42. package/dist/cjs/types/config.types.d.ts +17 -20
  43. package/dist/cjs/types/config.types.js +6 -0
  44. package/dist/cjs/types/event.types.d.ts +1 -13
  45. package/dist/cjs/types/index.d.ts +0 -2
  46. package/dist/cjs/types/index.js +0 -2
  47. package/dist/cjs/types/mode.types.d.ts +1 -2
  48. package/dist/cjs/types/mode.types.js +0 -1
  49. package/dist/cjs/types/queue.types.d.ts +0 -6
  50. package/dist/cjs/types/state.types.d.ts +2 -0
  51. package/dist/cjs/types/test-bridge.types.d.ts +2 -2
  52. package/dist/cjs/types/validation-error.types.d.ts +0 -6
  53. package/dist/cjs/types/validation-error.types.js +1 -10
  54. package/dist/cjs/utils/browser/device-detector.utils.js +2 -24
  55. package/dist/cjs/utils/browser/index.d.ts +1 -0
  56. package/dist/cjs/utils/browser/index.js +1 -0
  57. package/dist/cjs/utils/browser/qa-mode.utils.d.ts +13 -0
  58. package/dist/cjs/utils/browser/qa-mode.utils.js +43 -0
  59. package/dist/cjs/utils/browser/utm-params.utils.js +0 -15
  60. package/dist/cjs/utils/data/uuid.utils.d.ts +13 -0
  61. package/dist/cjs/utils/data/uuid.utils.js +37 -1
  62. package/dist/cjs/utils/index.d.ts +1 -1
  63. package/dist/cjs/utils/index.js +1 -1
  64. package/dist/cjs/utils/logging.utils.d.ts +21 -0
  65. package/dist/cjs/utils/logging.utils.js +86 -0
  66. package/dist/cjs/utils/network/index.d.ts +0 -1
  67. package/dist/cjs/utils/network/index.js +0 -1
  68. package/dist/cjs/utils/network/url.utils.d.ts +2 -8
  69. package/dist/cjs/utils/network/url.utils.js +45 -90
  70. package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -13
  71. package/dist/cjs/utils/security/sanitize.utils.js +15 -178
  72. package/dist/cjs/utils/validations/config-validations.utils.d.ts +3 -9
  73. package/dist/cjs/utils/validations/config-validations.utils.js +56 -93
  74. package/dist/cjs/utils/validations/event-validations.utils.js +11 -5
  75. package/dist/cjs/utils/validations/index.d.ts +0 -1
  76. package/dist/cjs/utils/validations/index.js +0 -1
  77. package/dist/cjs/utils/validations/metadata-validations.utils.js +0 -1
  78. package/dist/cjs/utils/validations/type-guards.utils.d.ts +2 -2
  79. package/dist/cjs/utils/validations/type-guards.utils.js +50 -4
  80. package/dist/esm/api.d.ts +12 -2
  81. package/dist/esm/api.js +73 -29
  82. package/dist/esm/app.d.ts +2 -2
  83. package/dist/esm/app.js +28 -34
  84. package/dist/esm/constants/config.constants.d.ts +7 -2
  85. package/dist/esm/constants/config.constants.js +7 -16
  86. package/dist/esm/constants/index.d.ts +0 -1
  87. package/dist/esm/constants/index.js +0 -1
  88. package/dist/esm/constants/storage.constants.d.ts +3 -2
  89. package/dist/esm/constants/storage.constants.js +3 -2
  90. package/dist/esm/handlers/click.handler.js +3 -6
  91. package/dist/esm/handlers/error.handler.js +1 -11
  92. package/dist/esm/handlers/page-view.handler.js +0 -4
  93. package/dist/esm/handlers/performance.handler.js +14 -29
  94. package/dist/esm/handlers/scroll.handler.js +7 -6
  95. package/dist/esm/handlers/session.handler.js +7 -6
  96. package/dist/esm/integrations/google-analytics.integration.js +3 -7
  97. package/dist/esm/listeners/activity-listener-manager.js +3 -3
  98. package/dist/esm/listeners/input-listener-managers.js +3 -3
  99. package/dist/esm/listeners/touch-listener-manager.js +3 -3
  100. package/dist/esm/listeners/unload-listener-manager.js +3 -3
  101. package/dist/esm/listeners/visibility-listener-manager.js +3 -3
  102. package/dist/esm/managers/event.manager.d.ts +5 -1
  103. package/dist/esm/managers/event.manager.js +106 -43
  104. package/dist/esm/managers/sender.manager.js +31 -38
  105. package/dist/esm/managers/session.manager.js +5 -13
  106. package/dist/esm/managers/state.manager.d.ts +0 -3
  107. package/dist/esm/managers/state.manager.js +1 -43
  108. package/dist/esm/managers/storage.manager.d.ts +21 -2
  109. package/dist/esm/managers/storage.manager.js +164 -21
  110. package/dist/esm/managers/user.manager.d.ts +1 -1
  111. package/dist/esm/managers/user.manager.js +2 -2
  112. package/dist/esm/public-api.d.ts +3 -3
  113. package/dist/esm/public-api.js +1 -1
  114. package/dist/esm/test-bridge.d.ts +1 -0
  115. package/dist/esm/test-bridge.js +37 -2
  116. package/dist/esm/types/config.types.d.ts +17 -20
  117. package/dist/esm/types/config.types.js +5 -1
  118. package/dist/esm/types/event.types.d.ts +1 -13
  119. package/dist/esm/types/index.d.ts +0 -2
  120. package/dist/esm/types/index.js +0 -2
  121. package/dist/esm/types/mode.types.d.ts +1 -2
  122. package/dist/esm/types/mode.types.js +0 -1
  123. package/dist/esm/types/queue.types.d.ts +0 -6
  124. package/dist/esm/types/state.types.d.ts +2 -0
  125. package/dist/esm/types/test-bridge.types.d.ts +2 -2
  126. package/dist/esm/types/validation-error.types.d.ts +0 -6
  127. package/dist/esm/types/validation-error.types.js +0 -8
  128. package/dist/esm/utils/browser/device-detector.utils.js +2 -24
  129. package/dist/esm/utils/browser/index.d.ts +1 -0
  130. package/dist/esm/utils/browser/index.js +1 -0
  131. package/dist/esm/utils/browser/qa-mode.utils.d.ts +13 -0
  132. package/dist/esm/utils/browser/qa-mode.utils.js +39 -0
  133. package/dist/esm/utils/browser/utm-params.utils.js +0 -15
  134. package/dist/esm/utils/data/uuid.utils.d.ts +13 -0
  135. package/dist/esm/utils/data/uuid.utils.js +35 -0
  136. package/dist/esm/utils/index.d.ts +1 -1
  137. package/dist/esm/utils/index.js +1 -1
  138. package/dist/esm/utils/logging.utils.d.ts +21 -0
  139. package/dist/esm/utils/logging.utils.js +81 -0
  140. package/dist/esm/utils/network/index.d.ts +0 -1
  141. package/dist/esm/utils/network/index.js +0 -1
  142. package/dist/esm/utils/network/url.utils.d.ts +2 -8
  143. package/dist/esm/utils/network/url.utils.js +44 -88
  144. package/dist/esm/utils/security/sanitize.utils.d.ts +1 -13
  145. package/dist/esm/utils/security/sanitize.utils.js +15 -176
  146. package/dist/esm/utils/validations/config-validations.utils.d.ts +3 -9
  147. package/dist/esm/utils/validations/config-validations.utils.js +57 -93
  148. package/dist/esm/utils/validations/event-validations.utils.js +11 -5
  149. package/dist/esm/utils/validations/index.d.ts +0 -1
  150. package/dist/esm/utils/validations/index.js +0 -1
  151. package/dist/esm/utils/validations/metadata-validations.utils.js +0 -1
  152. package/dist/esm/utils/validations/type-guards.utils.d.ts +2 -2
  153. package/dist/esm/utils/validations/type-guards.utils.js +50 -4
  154. package/package.json +3 -2
  155. package/dist/cjs/app.types.d.ts +0 -2
  156. package/dist/cjs/app.types.js +0 -12
  157. package/dist/cjs/constants/api.constants.d.ts +0 -6
  158. package/dist/cjs/constants/api.constants.js +0 -14
  159. package/dist/cjs/managers/api.manager.d.ts +0 -13
  160. package/dist/cjs/managers/api.manager.js +0 -44
  161. package/dist/cjs/managers/config.builder.d.ts +0 -33
  162. package/dist/cjs/managers/config.builder.js +0 -116
  163. package/dist/cjs/managers/config.manager.d.ts +0 -56
  164. package/dist/cjs/managers/config.manager.js +0 -157
  165. package/dist/cjs/managers/tags.manager.d.ts +0 -36
  166. package/dist/cjs/managers/tags.manager.js +0 -171
  167. package/dist/cjs/types/api.types.d.ts +0 -52
  168. package/dist/cjs/types/api.types.js +0 -56
  169. package/dist/cjs/types/tag.types.d.ts +0 -43
  170. package/dist/cjs/types/tag.types.js +0 -31
  171. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +0 -14
  172. package/dist/cjs/utils/logging/debug-logger.utils.js +0 -47
  173. package/dist/cjs/utils/logging/index.d.ts +0 -1
  174. package/dist/cjs/utils/logging/index.js +0 -5
  175. package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  176. package/dist/cjs/utils/network/fetch-with-timeout.utils.js +0 -25
  177. package/dist/cjs/utils/validations/url-validations.utils.d.ts +0 -15
  178. package/dist/cjs/utils/validations/url-validations.utils.js +0 -47
  179. package/dist/esm/app.types.d.ts +0 -2
  180. package/dist/esm/app.types.js +0 -1
  181. package/dist/esm/constants/api.constants.d.ts +0 -6
  182. package/dist/esm/constants/api.constants.js +0 -11
  183. package/dist/esm/managers/api.manager.d.ts +0 -13
  184. package/dist/esm/managers/api.manager.js +0 -41
  185. package/dist/esm/managers/config.builder.d.ts +0 -33
  186. package/dist/esm/managers/config.builder.js +0 -112
  187. package/dist/esm/managers/config.manager.d.ts +0 -56
  188. package/dist/esm/managers/config.manager.js +0 -153
  189. package/dist/esm/managers/tags.manager.d.ts +0 -36
  190. package/dist/esm/managers/tags.manager.js +0 -167
  191. package/dist/esm/types/api.types.d.ts +0 -52
  192. package/dist/esm/types/api.types.js +0 -53
  193. package/dist/esm/types/tag.types.d.ts +0 -43
  194. package/dist/esm/types/tag.types.js +0 -28
  195. package/dist/esm/utils/logging/debug-logger.utils.d.ts +0 -14
  196. package/dist/esm/utils/logging/debug-logger.utils.js +0 -44
  197. package/dist/esm/utils/logging/index.d.ts +0 -1
  198. package/dist/esm/utils/logging/index.js +0 -1
  199. package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  200. package/dist/esm/utils/network/fetch-with-timeout.utils.js +0 -22
  201. package/dist/esm/utils/validations/url-validations.utils.d.ts +0 -15
  202. package/dist/esm/utils/validations/url-validations.utils.js +0 -42
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TestBridge = void 0;
4
4
  const app_1 = require("./app");
5
+ const api_1 = require("./api");
6
+ const constants_1 = require("./constants");
5
7
  /**
6
8
  * Test bridge for E2E testing
7
9
  */
@@ -12,6 +14,34 @@ class TestBridge extends app_1.App {
12
14
  this._isInitializing = isInitializing;
13
15
  this._isDestroying = isDestroying;
14
16
  }
17
+ async init(config) {
18
+ // Guard: TestBridge should only be used in development
19
+ if (process.env.NODE_ENV !== 'dev') {
20
+ throw new Error('[TraceLog] TestBridge is only available in development mode');
21
+ }
22
+ // First sync with window.tracelog BEFORE initializing
23
+ // This ensures both APIs point to the same instance from the start
24
+ if (!api_1.__setAppInstance) {
25
+ throw new Error('[TraceLog] __setAppInstance is not available (production build?)');
26
+ }
27
+ try {
28
+ (0, api_1.__setAppInstance)(this);
29
+ }
30
+ catch {
31
+ // If __setAppInstance fails (e.g., already initialized), throw clear error
32
+ throw new Error('[TraceLog] TestBridge cannot sync with existing tracelog instance. Call destroy() first.');
33
+ }
34
+ try {
35
+ await super.init(config);
36
+ }
37
+ catch (error) {
38
+ // If init fails, clear the sync
39
+ if (api_1.__setAppInstance) {
40
+ (0, api_1.__setAppInstance)(null);
41
+ }
42
+ throw error;
43
+ }
44
+ }
15
45
  isInitializing() {
16
46
  return this._isInitializing;
17
47
  }
@@ -46,7 +76,8 @@ class TestBridge extends app_1.App {
46
76
  if (!storageManager) {
47
77
  throw new Error('Storage manager not available');
48
78
  }
49
- const projectId = this.get('config')?.id;
79
+ const config = this.get('config');
80
+ const projectId = config?.integrations?.tracelog?.projectId ?? config?.integrations?.custom?.apiUrl ?? 'test';
50
81
  const userId = this.get('userId');
51
82
  const sessionId = this.get('sessionId');
52
83
  if (!projectId || !userId) {
@@ -61,7 +92,7 @@ class TestBridge extends app_1.App {
61
92
  timestamp: Date.now(),
62
93
  };
63
94
  // Store in the same format as SenderManager.persistEvents()
64
- const storageKey = `tl:${projectId}:queue:${userId}`;
95
+ const storageKey = `${constants_1.STORAGE_BASE_KEY}:${projectId}:queue:${userId}`;
65
96
  storageManager.setItem(storageKey, JSON.stringify(persistedData));
66
97
  }
67
98
  get(key) {
@@ -106,6 +137,10 @@ class TestBridge extends app_1.App {
106
137
  this._isDestroying = true;
107
138
  try {
108
139
  await super.destroy(force);
140
+ // Clear window.tracelog API reference (only in dev mode)
141
+ if (api_1.__setAppInstance) {
142
+ (0, api_1.__setAppInstance)(null);
143
+ }
109
144
  }
110
145
  finally {
111
146
  this._isDestroying = false;
@@ -1,38 +1,31 @@
1
1
  import { MetadataType } from './common.types';
2
- import { TagConfig } from './tag.types';
3
- import { Mode } from './mode.types';
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. */
9
- tags?: TagConfig[];
10
- /** Determines if IP address is excluded from tracking. */
11
- ipExcluded?: boolean;
12
- }
13
- export interface AppConfig {
14
- /** Project identifier used for tracing. */
15
- id: string;
2
+ export interface Config {
16
3
  /** Session inactivity timeout in milliseconds. @default 900000 */
17
4
  sessionTimeout?: number;
18
5
  /** Metadata appended to every tracked event. */
19
6
  globalMetadata?: Record<string, MetadataType>;
20
7
  /** Selectors defining custom scroll containers to monitor. */
21
8
  scrollContainerSelectors?: string | string[];
22
- /** Enables HTTP requests for testing and development flows. */
23
- allowHttp?: boolean;
24
9
  /** Query parameters to remove before tracking URLs. */
25
10
  sensitiveQueryParams?: string[];
26
11
  /** Error event sampling rate between 0 and 1. */
27
12
  errorSampling?: number;
28
- /** Logging mode controlling verbosity of client logs. */
29
- mode?: Mode;
30
13
  /** Event sampling rate between 0 and 1. */
31
14
  samplingRate?: number;
32
- /** URL path patterns that should be ignored by tracking. */
33
- excludedUrlPaths?: string[];
34
15
  /** Optional configuration for third-party integrations. */
35
16
  integrations?: {
17
+ /** TraceLog integration options. */
18
+ tracelog?: {
19
+ /** Required project ID TraceLog SaaS integration. */
20
+ projectId: string;
21
+ };
22
+ /** Custom integration options. */
23
+ custom?: {
24
+ /** Required API URL for custom integration. */
25
+ apiUrl: string;
26
+ /** Allow HTTP URLs (not recommended for production). @default false */
27
+ allowHttp?: boolean;
28
+ };
36
29
  /** Google Analytics integration options. */
37
30
  googleAnalytics?: {
38
31
  /** Required measurement ID for Google Analytics. */
@@ -40,3 +33,7 @@ export interface AppConfig {
40
33
  };
41
34
  };
42
35
  }
36
+ export declare enum SpecialApiUrl {
37
+ Localhost = "localhost:8080",
38
+ Fail = "localhost:9999"
39
+ }
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SpecialApiUrl = void 0;
4
+ var SpecialApiUrl;
5
+ (function (SpecialApiUrl) {
6
+ SpecialApiUrl["Localhost"] = "localhost:8080";
7
+ SpecialApiUrl["Fail"] = "localhost:9999";
8
+ })(SpecialApiUrl || (exports.SpecialApiUrl = SpecialApiUrl = {}));
@@ -74,15 +74,8 @@ export interface PageViewData {
74
74
  search?: string;
75
75
  hash?: string;
76
76
  }
77
- export interface EventLocation {
78
- country: string;
79
- country_code: string;
80
- }
81
- export interface VitalSample {
82
- type: WebVitalType;
83
- value: number;
84
- }
85
77
  export interface EventData {
78
+ id: string;
86
79
  type: EventType;
87
80
  page_url: string;
88
81
  timestamp: number;
@@ -96,9 +89,4 @@ export interface EventData {
96
89
  session_end_reason?: SessionEndReason;
97
90
  error_data?: ErrorData;
98
91
  utm?: UTM;
99
- location?: EventLocation;
100
- tags?: string[] | {
101
- id: string;
102
- key: string;
103
- }[];
104
92
  }
@@ -1,4 +1,3 @@
1
- export * from './api.types';
2
1
  export * from './common.types';
3
2
  export * from './config.types';
4
3
  export * from './device.types';
@@ -9,7 +8,6 @@ export * from './mode.types';
9
8
  export * from './queue.types';
10
9
  export * from './session.types';
11
10
  export * from './state.types';
12
- export * from './tag.types';
13
11
  export * from './test-bridge.types';
14
12
  export * from './validation-error.types';
15
13
  export * from './window.types';
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./api.types"), exports);
18
17
  __exportStar(require("./common.types"), exports);
19
18
  __exportStar(require("./config.types"), exports);
20
19
  __exportStar(require("./device.types"), exports);
@@ -25,7 +24,6 @@ __exportStar(require("./mode.types"), exports);
25
24
  __exportStar(require("./queue.types"), exports);
26
25
  __exportStar(require("./session.types"), exports);
27
26
  __exportStar(require("./state.types"), exports);
28
- __exportStar(require("./tag.types"), exports);
29
27
  __exportStar(require("./test-bridge.types"), exports);
30
28
  __exportStar(require("./validation-error.types"), exports);
31
29
  __exportStar(require("./window.types"), exports);
@@ -2,6 +2,5 @@
2
2
  * App modes for the TraceLog Library
3
3
  */
4
4
  export declare enum Mode {
5
- QA = "qa",
6
- DEBUG = "debug"
5
+ QA = "qa"
7
6
  }
@@ -7,5 +7,4 @@ exports.Mode = void 0;
7
7
  var Mode;
8
8
  (function (Mode) {
9
9
  Mode["QA"] = "qa";
10
- Mode["DEBUG"] = "debug";
11
10
  })(Mode || (exports.Mode = Mode = {}));
@@ -8,11 +8,6 @@ export interface BaseEventsQueueDto {
8
8
  events: EventData[];
9
9
  global_metadata?: Record<string, MetadataType>;
10
10
  }
11
- export interface ExtendedEventsQueueDto extends BaseEventsQueueDto {
12
- project: string;
13
- source: string;
14
- ip: string;
15
- }
16
11
  export interface PersistedQueueData {
17
12
  userId: string;
18
13
  sessionId: string;
@@ -20,5 +15,4 @@ export interface PersistedQueueData {
20
15
  events: BaseEventsQueueDto['events'];
21
16
  timestamp: number;
22
17
  global_metadata?: BaseEventsQueueDto['global_metadata'];
23
- fallbackMode?: boolean;
24
18
  }
@@ -1,6 +1,8 @@
1
1
  import { Config } from './config.types';
2
2
  import { DeviceType } from './device.types';
3
+ import { Mode } from './mode.types';
3
4
  export interface State {
5
+ mode?: Mode;
4
6
  apiUrl: string;
5
7
  config: Config;
6
8
  sessionId: string | null;
@@ -7,7 +7,7 @@ import { SessionHandler } from '@/handlers/session.handler';
7
7
  import { GoogleAnalyticsIntegration } from '@/integrations/google-analytics.integration';
8
8
  import { EventManager } from '@/managers/event.manager';
9
9
  import { StorageManager as TraceLogStorageManager } from '@/managers/storage.manager';
10
- import { AppConfig } from './config.types';
10
+ import { Config } from './config.types';
11
11
  import { State } from './state.types';
12
12
  /**
13
13
  * Testing bridge interface for E2E tests
@@ -15,7 +15,7 @@ import { State } from './state.types';
15
15
  */
16
16
  export interface TraceLogTestBridge {
17
17
  readonly initialized: boolean;
18
- init(config: AppConfig): Promise<void>;
18
+ init(config: Config): Promise<void>;
19
19
  destroy(): Promise<void>;
20
20
  isInitializing(): boolean;
21
21
  sendCustomEvent(name: string, data?: Record<string, unknown> | Record<string, unknown>[]): void;
@@ -10,12 +10,6 @@ export declare abstract class TraceLogValidationError extends Error {
10
10
  readonly layer: 'config' | 'app' | 'runtime';
11
11
  constructor(message: string, errorCode: string, layer: 'config' | 'app' | 'runtime');
12
12
  }
13
- /**
14
- * Thrown when project ID validation fails
15
- */
16
- export declare class ProjectIdValidationError extends TraceLogValidationError {
17
- constructor(message?: string, layer?: 'config' | 'app' | 'runtime');
18
- }
19
13
  /**
20
14
  * Thrown when app configuration validation fails
21
15
  */
@@ -4,7 +4,7 @@
4
4
  * Provides better error handling and consistency across validation layers
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.InitializationTimeoutError = exports.IntegrationValidationError = exports.SamplingRateValidationError = exports.SessionTimeoutValidationError = exports.AppConfigValidationError = exports.ProjectIdValidationError = exports.TraceLogValidationError = void 0;
7
+ exports.InitializationTimeoutError = exports.IntegrationValidationError = exports.SamplingRateValidationError = exports.SessionTimeoutValidationError = exports.AppConfigValidationError = exports.TraceLogValidationError = void 0;
8
8
  /**
9
9
  * Base class for all TraceLog validation errors
10
10
  */
@@ -21,15 +21,6 @@ class TraceLogValidationError extends Error {
21
21
  }
22
22
  }
23
23
  exports.TraceLogValidationError = TraceLogValidationError;
24
- /**
25
- * Thrown when project ID validation fails
26
- */
27
- class ProjectIdValidationError extends TraceLogValidationError {
28
- constructor(message = 'Project ID is required', layer = 'config') {
29
- super(message, 'PROJECT_ID_INVALID', layer);
30
- }
31
- }
32
- exports.ProjectIdValidationError = ProjectIdValidationError;
33
24
  /**
34
25
  * Thrown when app configuration validation fails
35
26
  */
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDeviceType = void 0;
4
4
  const device_types_1 = require("../../types/device.types");
5
- const logging_1 = require("../logging");
5
+ const logging_utils_1 = require("../logging.utils");
6
6
  let coarsePointerQuery;
7
7
  let noHoverQuery;
8
8
  const initMediaQueries = () => {
@@ -17,22 +17,14 @@ const initMediaQueries = () => {
17
17
  */
18
18
  const getDeviceType = () => {
19
19
  try {
20
- logging_1.debugLog.debug('DeviceDetector', 'Starting device detection');
21
20
  const nav = navigator;
22
21
  if (nav.userAgentData && typeof nav.userAgentData.mobile === 'boolean') {
23
- logging_1.debugLog.debug('DeviceDetector', 'Using modern User-Agent Client Hints API', {
24
- mobile: nav.userAgentData.mobile,
25
- platform: nav.userAgentData.platform,
26
- });
27
22
  if (nav.userAgentData.platform && /ipad|tablet/i.test(nav.userAgentData.platform)) {
28
- logging_1.debugLog.debug('DeviceDetector', 'Device detected as tablet via platform hint');
29
23
  return device_types_1.DeviceType.Tablet;
30
24
  }
31
25
  const result = nav.userAgentData.mobile ? device_types_1.DeviceType.Mobile : device_types_1.DeviceType.Desktop;
32
- logging_1.debugLog.debug('DeviceDetector', 'Device detected via User-Agent hints', { result });
33
26
  return result;
34
27
  }
35
- logging_1.debugLog.debug('DeviceDetector', 'Using fallback detection methods');
36
28
  initMediaQueries();
37
29
  const width = window.innerWidth;
38
30
  const hasCoarsePointer = coarsePointerQuery?.matches ?? false;
@@ -41,30 +33,16 @@ const getDeviceType = () => {
41
33
  const ua = navigator.userAgent.toLowerCase();
42
34
  const isMobileUA = /mobile|android|iphone|ipod|blackberry|iemobile|opera mini/.test(ua);
43
35
  const isTabletUA = /tablet|ipad|android(?!.*mobile)/.test(ua);
44
- const detectionData = {
45
- width,
46
- hasCoarsePointer,
47
- hasNoHover,
48
- hasTouchSupport,
49
- isMobileUA,
50
- isTabletUA,
51
- maxTouchPoints: navigator.maxTouchPoints,
52
- };
53
36
  if (width <= 767 || (isMobileUA && hasTouchSupport)) {
54
- logging_1.debugLog.debug('DeviceDetector', 'Device detected as mobile', detectionData);
55
37
  return device_types_1.DeviceType.Mobile;
56
38
  }
57
39
  if ((width >= 768 && width <= 1024) || isTabletUA || (hasCoarsePointer && hasNoHover && hasTouchSupport)) {
58
- logging_1.debugLog.debug('DeviceDetector', 'Device detected as tablet', detectionData);
59
40
  return device_types_1.DeviceType.Tablet;
60
41
  }
61
- logging_1.debugLog.debug('DeviceDetector', 'Device detected as desktop', detectionData);
62
42
  return device_types_1.DeviceType.Desktop;
63
43
  }
64
44
  catch (error) {
65
- logging_1.debugLog.warn('DeviceDetector', 'Device detection failed, defaulting to desktop', {
66
- error: error instanceof Error ? error.message : error,
67
- });
45
+ (0, logging_utils_1.log)('warn', 'Device detection failed, defaulting to desktop', { error });
68
46
  return device_types_1.DeviceType.Desktop;
69
47
  }
70
48
  };
@@ -1,2 +1,3 @@
1
1
  export * from './device-detector.utils';
2
+ export * from './qa-mode.utils';
2
3
  export * from './utm-params.utils';
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./device-detector.utils"), exports);
18
+ __exportStar(require("./qa-mode.utils"), exports);
18
19
  __exportStar(require("./utm-params.utils"), exports);
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Detects if QA mode should be active based on URL query parameter or sessionStorage
3
+ *
4
+ * Detection flow:
5
+ * 1. Check if already active in sessionStorage
6
+ * 2. Check for ?tlog_mode=qa query parameter
7
+ * 3. If found in URL:
8
+ * - Persist to sessionStorage
9
+ * - Clean param from URL
10
+ *
11
+ * @returns True if QA mode is active, false otherwise
12
+ */
13
+ export declare const detectQaMode: () => boolean;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.detectQaMode = void 0;
4
+ const constants_1 = require("@/constants");
5
+ const logging_utils_1 = require("../logging.utils");
6
+ const QA_MODE_PARAM = 'tlog_mode';
7
+ const QA_MODE_VALUE = 'qa';
8
+ /**
9
+ * Detects if QA mode should be active based on URL query parameter or sessionStorage
10
+ *
11
+ * Detection flow:
12
+ * 1. Check if already active in sessionStorage
13
+ * 2. Check for ?tlog_mode=qa query parameter
14
+ * 3. If found in URL:
15
+ * - Persist to sessionStorage
16
+ * - Clean param from URL
17
+ *
18
+ * @returns True if QA mode is active, false otherwise
19
+ */
20
+ const detectQaMode = () => {
21
+ const stored = sessionStorage.getItem(constants_1.QA_MODE_KEY);
22
+ if (stored === 'true') {
23
+ return true;
24
+ }
25
+ const params = new URLSearchParams(window.location.search);
26
+ const modeParam = params.get(QA_MODE_PARAM);
27
+ const isQaMode = modeParam === QA_MODE_VALUE;
28
+ if (isQaMode) {
29
+ sessionStorage.setItem(constants_1.QA_MODE_KEY, 'true');
30
+ params.delete(QA_MODE_PARAM);
31
+ const newSearch = params.toString();
32
+ const newUrl = `${window.location.pathname}${newSearch ? '?' + newSearch : ''}${window.location.hash}`;
33
+ try {
34
+ window.history.replaceState({}, '', newUrl);
35
+ }
36
+ catch (error) {
37
+ (0, logging_utils_1.log)('warn', 'History API not available, cannot replace URL', { error });
38
+ }
39
+ console.log('%c[TraceLog] QA Mode ACTIVE', 'background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;');
40
+ }
41
+ return isQaMode;
42
+ };
43
+ exports.detectQaMode = detectQaMode;
@@ -2,16 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getUTMParameters = void 0;
4
4
  const constants_1 = require("../../constants");
5
- const logging_1 = require("../logging");
6
5
  /**
7
6
  * Extracts UTM parameters from the current URL
8
7
  * @returns UTM parameters object or undefined if none found
9
8
  */
10
9
  const getUTMParameters = () => {
11
- logging_1.debugLog.debug('UTMParams', 'Extracting UTM parameters from URL', {
12
- url: window.location.href,
13
- search: window.location.search,
14
- });
15
10
  const urlParams = new URLSearchParams(window.location.search);
16
11
  const utmParams = {};
17
12
  constants_1.UTM_PARAMS.forEach((param) => {
@@ -19,19 +14,9 @@ const getUTMParameters = () => {
19
14
  if (value) {
20
15
  const key = param.split('utm_')[1];
21
16
  utmParams[key] = value;
22
- logging_1.debugLog.debug('UTMParams', 'Found UTM parameter', { param, key, value });
23
17
  }
24
18
  });
25
19
  const result = Object.keys(utmParams).length ? utmParams : undefined;
26
- if (result) {
27
- logging_1.debugLog.debug('UTMParams', 'UTM parameters extracted successfully', {
28
- parameterCount: Object.keys(result).length,
29
- parameters: Object.keys(result),
30
- });
31
- }
32
- else {
33
- logging_1.debugLog.debug('UTMParams', 'No UTM parameters found in URL');
34
- }
35
20
  return result;
36
21
  };
37
22
  exports.getUTMParameters = getUTMParameters;
@@ -3,3 +3,16 @@
3
3
  * @returns A UUID string
4
4
  */
5
5
  export declare const generateUUID: () => string;
6
+ /**
7
+ * Generates a unique event ID optimized for high-frequency event tracking
8
+ *
9
+ * Uses a simple hybrid approach:
10
+ * - Timestamp for temporal ordering
11
+ * - Random component for uniqueness across tabs/processes
12
+ *
13
+ * Format: {timestamp}-{random}
14
+ * Example: "1704067200000-a3f9c2b1"
15
+ *
16
+ * @returns Unique event ID string
17
+ */
18
+ export declare const generateEventId: () => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateUUID = void 0;
3
+ exports.generateEventId = exports.generateUUID = void 0;
4
4
  /**
5
5
  * Generates a RFC4122 compliant UUID v4 using native crypto API with fallback
6
6
  * @returns A UUID string
@@ -18,3 +18,39 @@ const generateUUID = () => {
18
18
  });
19
19
  };
20
20
  exports.generateUUID = generateUUID;
21
+ /**
22
+ * Generates a unique event ID optimized for high-frequency event tracking
23
+ *
24
+ * Uses a simple hybrid approach:
25
+ * - Timestamp for temporal ordering
26
+ * - Random component for uniqueness across tabs/processes
27
+ *
28
+ * Format: {timestamp}-{random}
29
+ * Example: "1704067200000-a3f9c2b1"
30
+ *
31
+ * @returns Unique event ID string
32
+ */
33
+ const generateEventId = () => {
34
+ const timestamp = Date.now();
35
+ // Generate 8 random hex chars (32 bits entropy)
36
+ let random = '';
37
+ try {
38
+ if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
39
+ const bytes = crypto.getRandomValues(new Uint8Array(4));
40
+ if (bytes) {
41
+ random = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
42
+ }
43
+ }
44
+ }
45
+ catch {
46
+ // crypto failed, use fallback
47
+ }
48
+ // Fallback to Math.random if crypto unavailable
49
+ if (!random) {
50
+ random = Math.floor(Math.random() * 0xffffffff)
51
+ .toString(16)
52
+ .padStart(8, '0');
53
+ }
54
+ return `${timestamp}-${random}`;
55
+ };
56
+ exports.generateEventId = generateEventId;
@@ -1,7 +1,7 @@
1
1
  export * from './browser';
2
2
  export * from './data';
3
- export * from './logging';
4
3
  export * from './network';
5
4
  export * from './security';
6
5
  export * from './validations';
7
6
  export * from './emitter.utils';
7
+ export * from './logging.utils';
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./browser"), exports);
18
18
  __exportStar(require("./data"), exports);
19
- __exportStar(require("./logging"), exports);
20
19
  __exportStar(require("./network"), exports);
21
20
  __exportStar(require("./security"), exports);
22
21
  __exportStar(require("./validations"), exports);
23
22
  __exportStar(require("./emitter.utils"), exports);
23
+ __exportStar(require("./logging.utils"), exports);
@@ -0,0 +1,21 @@
1
+ export declare const formatLogMsg: (msg: string, error?: unknown) => string;
2
+ /**
3
+ * Safe logging utility that respects production environment
4
+ *
5
+ * @param type - Log level (info, warn, error, debug)
6
+ * @param msg - Message to log
7
+ * @param extra - Optional extra data
8
+ *
9
+ * Production behavior:
10
+ * - debug: Never logged in production
11
+ * - info: Only logged if showToClient=true
12
+ * - warn: Always logged (important for debugging production issues)
13
+ * - error: Always logged
14
+ * - Stack traces are sanitized
15
+ * - Data objects are sanitized
16
+ */
17
+ export declare const log: (type: "info" | "warn" | "error" | "debug", msg: string, extra?: {
18
+ error?: unknown;
19
+ data?: Record<string, unknown>;
20
+ showToClient?: boolean;
21
+ }) => void;