@tracelog/lib 0.1.0 → 0.2.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 (228) hide show
  1. package/README.md +58 -24
  2. package/dist/browser/tracelog.js +1928 -3297
  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 +74 -1
  6. package/dist/cjs/app.constants.js +77 -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 +16 -10
  28. package/dist/cjs/handlers/scroll.handler.js +119 -185
  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 +74 -1
  96. package/dist/esm/app.constants.js +76 -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 +16 -10
  118. package/dist/esm/handlers/scroll.handler.js +120 -186
  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 -27
  190. package/dist/cjs/constants/limits.constants.js +0 -43
  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 -27
  211. package/dist/esm/constants/limits.constants.js +0 -40
  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
@@ -1,5 +1,38 @@
1
1
  import { State } from '../types';
2
+ /**
3
+ * Resets the global state to its initial empty state.
4
+ * Used primarily for testing and cleanup scenarios.
5
+ */
6
+ export declare function resetGlobalState(): void;
7
+ /**
8
+ * Abstract base class providing state management capabilities to TraceLog components.
9
+ *
10
+ * All managers and handlers extend this class to access and modify the shared global state.
11
+ * State operations are synchronous and thread-safe within the single-threaded browser environment.
12
+ */
2
13
  export declare abstract class StateManager {
14
+ /**
15
+ * Gets a value from the global state
16
+ */
3
17
  protected get<T extends keyof State>(key: T): State[T];
18
+ /**
19
+ * Sets a value in the global state
20
+ */
4
21
  protected set<T extends keyof State>(key: T, value: State[T]): void;
22
+ /**
23
+ * Gets the entire state object (for debugging purposes)
24
+ */
25
+ protected getState(): Readonly<State>;
26
+ /**
27
+ * Checks if a state key is considered critical for logging
28
+ */
29
+ private isCriticalStateKey;
30
+ /**
31
+ * Determines if a state change should be logged
32
+ */
33
+ private shouldLog;
34
+ /**
35
+ * Formats values for logging (avoiding large object dumps)
36
+ */
37
+ private formatLogValue;
5
38
  }
@@ -1,23 +1,96 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StateManager = void 0;
4
+ exports.resetGlobalState = resetGlobalState;
4
5
  const logging_1 = require("../utils/logging");
6
+ const constants_1 = require("../constants");
7
+ /**
8
+ * Global state store shared across all TraceLog components
9
+ */
5
10
  const globalState = {};
11
+ /**
12
+ * Resets the global state to its initial empty state.
13
+ * Used primarily for testing and cleanup scenarios.
14
+ */
15
+ function resetGlobalState() {
16
+ Object.keys(globalState).forEach((key) => {
17
+ delete globalState[key];
18
+ });
19
+ }
20
+ /**
21
+ * Abstract base class providing state management capabilities to TraceLog components.
22
+ *
23
+ * All managers and handlers extend this class to access and modify the shared global state.
24
+ * State operations are synchronous and thread-safe within the single-threaded browser environment.
25
+ */
6
26
  class StateManager {
27
+ /**
28
+ * Gets a value from the global state
29
+ */
7
30
  get(key) {
8
31
  return globalState[key];
9
32
  }
33
+ /**
34
+ * Sets a value in the global state
35
+ */
10
36
  set(key, value) {
11
37
  const oldValue = globalState[key];
12
- globalState[key] = value;
13
- // Log critical state changes
14
- if (key === 'sessionId' || key === 'config' || key === 'hasStartSession') {
15
- logging_1.debugLog.debug('StateManager', 'Critical state updated', {
38
+ if (key === 'config' && value) {
39
+ const configValue = value;
40
+ if (configValue) {
41
+ const samplingRate = configValue.samplingRate ?? constants_1.DEFAULT_SAMPLING_RATE;
42
+ const normalizedSamplingRate = samplingRate > 0 ? samplingRate : constants_1.DEFAULT_SAMPLING_RATE;
43
+ const hasNormalizedSampling = normalizedSamplingRate !== samplingRate;
44
+ if (hasNormalizedSampling) {
45
+ const normalizedConfig = { ...configValue, samplingRate: normalizedSamplingRate };
46
+ globalState[key] = normalizedConfig;
47
+ }
48
+ else {
49
+ globalState[key] = configValue;
50
+ }
51
+ }
52
+ else {
53
+ globalState[key] = value;
54
+ }
55
+ }
56
+ else {
57
+ globalState[key] = value;
58
+ }
59
+ // Log critical state changes for debugging
60
+ if (this.isCriticalStateKey(key) && this.shouldLog(oldValue, globalState[key])) {
61
+ logging_1.debugLog.debug('StateManager', 'State updated', {
16
62
  key,
17
- oldValue: key === 'config' ? !!oldValue : oldValue,
18
- newValue: key === 'config' ? !!value : value,
63
+ oldValue: this.formatLogValue(key, oldValue),
64
+ newValue: this.formatLogValue(key, globalState[key]),
19
65
  });
20
66
  }
21
67
  }
68
+ /**
69
+ * Gets the entire state object (for debugging purposes)
70
+ */
71
+ getState() {
72
+ return { ...globalState };
73
+ }
74
+ /**
75
+ * Checks if a state key is considered critical for logging
76
+ */
77
+ isCriticalStateKey(key) {
78
+ return key === 'sessionId' || key === 'config' || key === 'hasStartSession';
79
+ }
80
+ /**
81
+ * Determines if a state change should be logged
82
+ */
83
+ shouldLog(oldValue, newValue) {
84
+ return oldValue !== newValue;
85
+ }
86
+ /**
87
+ * Formats values for logging (avoiding large object dumps)
88
+ */
89
+ formatLogValue(key, value) {
90
+ if (key === 'config') {
91
+ return value ? '(configured)' : '(not configured)';
92
+ }
93
+ return value;
94
+ }
22
95
  }
23
96
  exports.StateManager = StateManager;
@@ -1,10 +1,34 @@
1
+ /**
2
+ * Manages localStorage with automatic fallback to in-memory storage.
3
+ * Provides a consistent interface for storing session data, configuration,
4
+ * and analytics metadata across browser environments.
5
+ */
1
6
  export declare class StorageManager {
2
7
  private readonly storage;
3
8
  private readonly fallbackStorage;
4
- private storageAvailable;
5
9
  constructor();
10
+ /**
11
+ * Retrieves an item from storage
12
+ */
6
13
  getItem(key: string): string | null;
14
+ /**
15
+ * Stores an item in storage
16
+ */
7
17
  setItem(key: string, value: string): void;
18
+ /**
19
+ * Removes an item from storage
20
+ */
8
21
  removeItem(key: string): void;
9
- private init;
22
+ /**
23
+ * Clears all TracLog-related items from storage
24
+ */
25
+ clear(): void;
26
+ /**
27
+ * Checks if storage is available
28
+ */
29
+ isAvailable(): boolean;
30
+ /**
31
+ * Initialize localStorage with feature detection
32
+ */
33
+ private initializeStorage;
10
34
  }
@@ -1,22 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StorageManager = void 0;
4
- const logging_1 = require("../utils/logging");
4
+ const debug_logger_utils_1 = require("../utils/logging/debug-logger.utils");
5
+ /**
6
+ * Manages localStorage with automatic fallback to in-memory storage.
7
+ * Provides a consistent interface for storing session data, configuration,
8
+ * and analytics metadata across browser environments.
9
+ */
5
10
  class StorageManager {
6
11
  constructor() {
7
- this.storage = null;
8
12
  this.fallbackStorage = new Map();
9
- this.storageAvailable = false;
10
- this.storage = this.init();
11
- this.storageAvailable = this.storage !== null;
12
- if (!this.storageAvailable) {
13
- logging_1.debugLog.warn('StorageManager', 'localStorage not available, using memory fallback');
13
+ this.storage = this.initializeStorage();
14
+ if (!this.storage) {
15
+ debug_logger_utils_1.debugLog.warn('StorageManager', 'localStorage not available, using memory fallback');
14
16
  }
15
17
  }
18
+ /**
19
+ * Retrieves an item from storage
20
+ */
16
21
  getItem(key) {
17
- if (!this.storageAvailable) {
18
- return this.fallbackStorage.get(key) ?? null;
19
- }
20
22
  try {
21
23
  if (this.storage) {
22
24
  return this.storage.getItem(key);
@@ -24,53 +26,84 @@ class StorageManager {
24
26
  return this.fallbackStorage.get(key) ?? null;
25
27
  }
26
28
  catch (error) {
27
- logging_1.debugLog.warn('StorageManager', 'Storage getItem failed, using memory fallback', { key, error });
28
- this.storageAvailable = false;
29
+ debug_logger_utils_1.debugLog.warn('StorageManager', 'Failed to get item, using fallback', { key, error });
29
30
  return this.fallbackStorage.get(key) ?? null;
30
31
  }
31
32
  }
33
+ /**
34
+ * Stores an item in storage
35
+ */
32
36
  setItem(key, value) {
33
- if (!this.storageAvailable) {
34
- this.fallbackStorage.set(key, value);
35
- return;
36
- }
37
37
  try {
38
38
  if (this.storage) {
39
39
  this.storage.setItem(key, value);
40
40
  return;
41
41
  }
42
- this.fallbackStorage.set(key, value);
43
42
  }
44
43
  catch (error) {
45
- logging_1.debugLog.warn('StorageManager', 'Storage setItem failed, using memory fallback', { key, error });
46
- this.storageAvailable = false;
47
- this.fallbackStorage.set(key, value);
44
+ debug_logger_utils_1.debugLog.warn('StorageManager', 'Failed to set item, using fallback', { key, error });
48
45
  }
46
+ // Always update fallback for consistency
47
+ this.fallbackStorage.set(key, value);
49
48
  }
49
+ /**
50
+ * Removes an item from storage
51
+ */
50
52
  removeItem(key) {
51
- if (!this.storageAvailable) {
52
- this.fallbackStorage.delete(key);
53
- return;
54
- }
55
53
  try {
56
54
  if (this.storage) {
57
55
  this.storage.removeItem(key);
58
- return;
59
56
  }
60
- this.fallbackStorage.delete(key);
61
57
  }
62
58
  catch (error) {
63
- logging_1.debugLog.warn('StorageManager', 'Storage removeItem failed, using memory fallback', { key, error });
64
- this.storageAvailable = false;
65
- this.fallbackStorage.delete(key);
59
+ debug_logger_utils_1.debugLog.warn('StorageManager', 'Failed to remove item', { key, error });
60
+ }
61
+ // Always clean fallback
62
+ this.fallbackStorage.delete(key);
63
+ }
64
+ /**
65
+ * Clears all TracLog-related items from storage
66
+ */
67
+ clear() {
68
+ if (!this.storage) {
69
+ this.fallbackStorage.clear();
70
+ return;
71
+ }
72
+ try {
73
+ const keysToRemove = [];
74
+ for (let i = 0; i < this.storage.length; i++) {
75
+ const key = this.storage.key(i);
76
+ if (key?.startsWith('tracelog_')) {
77
+ keysToRemove.push(key);
78
+ }
79
+ }
80
+ keysToRemove.forEach((key) => this.storage.removeItem(key));
81
+ this.fallbackStorage.clear();
82
+ debug_logger_utils_1.debugLog.debug('StorageManager', 'Cleared storage', { itemsRemoved: keysToRemove.length });
83
+ }
84
+ catch (error) {
85
+ debug_logger_utils_1.debugLog.error('StorageManager', 'Failed to clear storage', { error });
86
+ this.fallbackStorage.clear();
66
87
  }
67
88
  }
68
- init() {
89
+ /**
90
+ * Checks if storage is available
91
+ */
92
+ isAvailable() {
93
+ return this.storage !== null;
94
+ }
95
+ /**
96
+ * Initialize localStorage with feature detection
97
+ */
98
+ initializeStorage() {
99
+ if (typeof window === 'undefined') {
100
+ return null;
101
+ }
69
102
  try {
70
- const test = '__storage_test__';
71
- const storage = window['localStorage'];
72
- storage.setItem(test, test);
73
- storage.removeItem(test);
103
+ const storage = window.localStorage;
104
+ const testKey = '__tracelog_test__';
105
+ storage.setItem(testKey, 'test');
106
+ storage.removeItem(testKey);
74
107
  return storage;
75
108
  }
76
109
  catch {
@@ -1,12 +1,36 @@
1
1
  import { DeviceType, EventData } from '../types';
2
2
  import { StateManager } from './state.manager';
3
3
  export declare class TagsManager extends StateManager {
4
+ /**
5
+ * Gets matching tag IDs for an event based on configured tag conditions
6
+ */
4
7
  getEventTagsIds(event: EventData, deviceType: DeviceType): string[];
5
- private checkEventTypePageView;
6
- private checkEventTypeClick;
7
- private matchUrlMatches;
8
- private matchDeviceType;
9
- private matchElementSelector;
10
- private matchUtmCondition;
11
- private checkElementFieldEquals;
8
+ /**
9
+ * Evaluates all conditions for a tag using logical operators
10
+ */
11
+ private evaluateTagConditions;
12
+ /**
13
+ * Evaluates a single tag condition
14
+ */
15
+ private evaluateCondition;
16
+ /**
17
+ * Unified string matching logic for all string-based conditions
18
+ */
19
+ private matchStringCondition;
20
+ /**
21
+ * Element-specific matching logic with optimized data extraction
22
+ */
23
+ private matchElementCondition;
24
+ /**
25
+ * Exact field matching for element EQUALS operations
26
+ */
27
+ private matchElementFieldExact;
28
+ /**
29
+ * Builds searchable element data string with null safety
30
+ */
31
+ private buildElementDataString;
32
+ /**
33
+ * Safe regex testing with error handling
34
+ */
35
+ private testRegex;
12
36
  }