@tracelog/lib 0.0.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/README.md +58 -24
  2. package/dist/browser/tracelog.js +1934 -3226
  3. package/dist/cjs/api.d.ts +33 -19
  4. package/dist/cjs/api.js +111 -156
  5. package/dist/cjs/app.constants.d.ts +80 -1
  6. package/dist/cjs/app.constants.js +90 -3
  7. package/dist/cjs/app.d.ts +29 -44
  8. package/dist/cjs/app.js +114 -212
  9. package/dist/cjs/app.types.d.ts +2 -7
  10. package/dist/cjs/app.types.js +10 -21
  11. package/dist/cjs/constants/api.constants.js +11 -5
  12. package/dist/cjs/constants/config.constants.d.ts +75 -0
  13. package/dist/cjs/constants/config.constants.js +178 -0
  14. package/dist/cjs/constants/error.constants.d.ts +29 -0
  15. package/dist/cjs/constants/error.constants.js +50 -0
  16. package/dist/cjs/constants/index.d.ts +3 -6
  17. package/dist/cjs/constants/index.js +3 -6
  18. package/dist/cjs/constants/performance.constants.d.ts +28 -0
  19. package/dist/cjs/constants/performance.constants.js +43 -0
  20. package/dist/cjs/handlers/click.handler.d.ts +1 -0
  21. package/dist/cjs/handlers/click.handler.js +30 -49
  22. package/dist/cjs/handlers/error.handler.d.ts +11 -6
  23. package/dist/cjs/handlers/error.handler.js +91 -51
  24. package/dist/cjs/handlers/page-view.handler.js +38 -29
  25. package/dist/cjs/handlers/performance.handler.d.ts +3 -0
  26. package/dist/cjs/handlers/performance.handler.js +76 -37
  27. package/dist/cjs/handlers/scroll.handler.d.ts +15 -0
  28. package/dist/cjs/handlers/scroll.handler.js +105 -31
  29. package/dist/cjs/handlers/session.handler.d.ts +6 -20
  30. package/dist/cjs/handlers/session.handler.js +38 -326
  31. package/dist/cjs/integrations/google-analytics.integration.d.ts +0 -1
  32. package/dist/cjs/integrations/google-analytics.integration.js +27 -98
  33. package/dist/cjs/listeners/input-listener-managers.d.ts +18 -9
  34. package/dist/cjs/listeners/input-listener-managers.js +24 -33
  35. package/dist/cjs/listeners/touch-listener-manager.d.ts +1 -3
  36. package/dist/cjs/listeners/touch-listener-manager.js +1 -23
  37. package/dist/cjs/listeners/visibility-listener-manager.d.ts +1 -4
  38. package/dist/cjs/listeners/visibility-listener-manager.js +6 -42
  39. package/dist/cjs/managers/api.manager.d.ts +13 -3
  40. package/dist/cjs/managers/api.manager.js +35 -5
  41. package/dist/cjs/managers/config.manager.d.ts +53 -3
  42. package/dist/cjs/managers/config.manager.js +131 -62
  43. package/dist/cjs/managers/event.manager.d.ts +57 -36
  44. package/dist/cjs/managers/event.manager.js +266 -417
  45. package/dist/cjs/managers/sender.manager.d.ts +40 -22
  46. package/dist/cjs/managers/sender.manager.js +200 -198
  47. package/dist/cjs/managers/session.manager.d.ts +80 -66
  48. package/dist/cjs/managers/session.manager.js +267 -522
  49. package/dist/cjs/managers/state.manager.d.ts +33 -0
  50. package/dist/cjs/managers/state.manager.js +79 -6
  51. package/dist/cjs/managers/storage.manager.d.ts +26 -2
  52. package/dist/cjs/managers/storage.manager.js +67 -34
  53. package/dist/cjs/managers/tags.manager.d.ts +31 -7
  54. package/dist/cjs/managers/tags.manager.js +123 -241
  55. package/dist/cjs/managers/user.manager.d.ts +14 -5
  56. package/dist/cjs/managers/user.manager.js +17 -9
  57. package/dist/cjs/public-api.d.ts +10 -1
  58. package/dist/cjs/public-api.js +18 -24
  59. package/dist/cjs/test-bridge.d.ts +48 -0
  60. package/dist/cjs/test-bridge.js +110 -0
  61. package/dist/cjs/types/api.types.d.ts +21 -6
  62. package/dist/cjs/types/api.types.js +21 -6
  63. package/dist/cjs/types/config.types.d.ts +22 -84
  64. package/dist/cjs/types/emitter.types.d.ts +11 -0
  65. package/dist/cjs/types/emitter.types.js +8 -0
  66. package/dist/cjs/types/event.types.d.ts +8 -11
  67. package/dist/cjs/types/index.d.ts +3 -1
  68. package/dist/cjs/types/index.js +3 -1
  69. package/dist/cjs/types/queue.types.d.ts +1 -0
  70. package/dist/cjs/types/session.types.d.ts +0 -64
  71. package/dist/cjs/types/state.types.d.ts +1 -0
  72. package/dist/cjs/types/test-bridge.types.d.ts +38 -0
  73. package/dist/cjs/types/validation-error.types.d.ts +7 -0
  74. package/dist/cjs/types/validation-error.types.js +11 -1
  75. package/dist/cjs/types/window.types.d.ts +1 -8
  76. package/dist/cjs/utils/data/uuid.utils.d.ts +1 -1
  77. package/dist/cjs/utils/data/uuid.utils.js +7 -5
  78. package/dist/cjs/utils/emitter.utils.d.ts +8 -0
  79. package/dist/cjs/utils/emitter.utils.js +33 -0
  80. package/dist/cjs/utils/index.d.ts +1 -0
  81. package/dist/cjs/utils/index.js +1 -0
  82. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +10 -51
  83. package/dist/cjs/utils/logging/debug-logger.utils.js +36 -127
  84. package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +4 -0
  85. package/dist/cjs/utils/network/fetch-with-timeout.utils.js +25 -0
  86. package/dist/cjs/utils/network/index.d.ts +1 -0
  87. package/dist/cjs/utils/network/index.js +1 -0
  88. package/dist/cjs/utils/network/url.utils.js +2 -42
  89. package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -8
  90. package/dist/cjs/utils/security/sanitize.utils.js +7 -41
  91. package/dist/cjs/utils/validations/config-validations.utils.d.ts +7 -0
  92. package/dist/cjs/utils/validations/config-validations.utils.js +77 -22
  93. package/dist/esm/api.d.ts +33 -19
  94. package/dist/esm/api.js +105 -118
  95. package/dist/esm/app.constants.d.ts +80 -1
  96. package/dist/esm/app.constants.js +89 -1
  97. package/dist/esm/app.d.ts +29 -44
  98. package/dist/esm/app.js +115 -213
  99. package/dist/esm/app.types.d.ts +2 -7
  100. package/dist/esm/app.types.js +1 -7
  101. package/dist/esm/constants/api.constants.js +10 -4
  102. package/dist/esm/constants/config.constants.d.ts +75 -0
  103. package/dist/esm/constants/config.constants.js +174 -0
  104. package/dist/esm/constants/error.constants.d.ts +29 -0
  105. package/dist/esm/constants/error.constants.js +47 -0
  106. package/dist/esm/constants/index.d.ts +3 -6
  107. package/dist/esm/constants/index.js +3 -6
  108. package/dist/esm/constants/performance.constants.d.ts +28 -0
  109. package/dist/esm/constants/performance.constants.js +40 -0
  110. package/dist/esm/handlers/click.handler.d.ts +1 -0
  111. package/dist/esm/handlers/click.handler.js +30 -49
  112. package/dist/esm/handlers/error.handler.d.ts +11 -6
  113. package/dist/esm/handlers/error.handler.js +91 -51
  114. package/dist/esm/handlers/page-view.handler.js +38 -29
  115. package/dist/esm/handlers/performance.handler.d.ts +3 -0
  116. package/dist/esm/handlers/performance.handler.js +71 -32
  117. package/dist/esm/handlers/scroll.handler.d.ts +15 -0
  118. package/dist/esm/handlers/scroll.handler.js +106 -32
  119. package/dist/esm/handlers/session.handler.d.ts +6 -20
  120. package/dist/esm/handlers/session.handler.js +38 -326
  121. package/dist/esm/integrations/google-analytics.integration.d.ts +0 -1
  122. package/dist/esm/integrations/google-analytics.integration.js +27 -98
  123. package/dist/esm/listeners/input-listener-managers.d.ts +18 -9
  124. package/dist/esm/listeners/input-listener-managers.js +23 -32
  125. package/dist/esm/listeners/touch-listener-manager.d.ts +1 -3
  126. package/dist/esm/listeners/touch-listener-manager.js +1 -23
  127. package/dist/esm/listeners/visibility-listener-manager.d.ts +1 -4
  128. package/dist/esm/listeners/visibility-listener-manager.js +6 -42
  129. package/dist/esm/managers/api.manager.d.ts +13 -3
  130. package/dist/esm/managers/api.manager.js +34 -3
  131. package/dist/esm/managers/config.manager.d.ts +53 -3
  132. package/dist/esm/managers/config.manager.js +133 -64
  133. package/dist/esm/managers/event.manager.d.ts +57 -36
  134. package/dist/esm/managers/event.manager.js +268 -419
  135. package/dist/esm/managers/sender.manager.d.ts +40 -22
  136. package/dist/esm/managers/sender.manager.js +201 -199
  137. package/dist/esm/managers/session.manager.d.ts +80 -66
  138. package/dist/esm/managers/session.manager.js +269 -524
  139. package/dist/esm/managers/state.manager.d.ts +33 -0
  140. package/dist/esm/managers/state.manager.js +78 -6
  141. package/dist/esm/managers/storage.manager.d.ts +26 -2
  142. package/dist/esm/managers/storage.manager.js +66 -33
  143. package/dist/esm/managers/tags.manager.d.ts +31 -7
  144. package/dist/esm/managers/tags.manager.js +124 -242
  145. package/dist/esm/managers/user.manager.d.ts +14 -5
  146. package/dist/esm/managers/user.manager.js +17 -9
  147. package/dist/esm/public-api.d.ts +10 -1
  148. package/dist/esm/public-api.js +14 -1
  149. package/dist/esm/test-bridge.d.ts +48 -0
  150. package/dist/esm/test-bridge.js +106 -0
  151. package/dist/esm/types/api.types.d.ts +21 -6
  152. package/dist/esm/types/api.types.js +21 -6
  153. package/dist/esm/types/config.types.d.ts +22 -84
  154. package/dist/esm/types/emitter.types.d.ts +11 -0
  155. package/dist/esm/types/emitter.types.js +5 -0
  156. package/dist/esm/types/event.types.d.ts +8 -11
  157. package/dist/esm/types/index.d.ts +3 -1
  158. package/dist/esm/types/index.js +3 -1
  159. package/dist/esm/types/queue.types.d.ts +1 -0
  160. package/dist/esm/types/session.types.d.ts +0 -64
  161. package/dist/esm/types/state.types.d.ts +1 -0
  162. package/dist/esm/types/test-bridge.types.d.ts +38 -0
  163. package/dist/esm/types/validation-error.types.d.ts +7 -0
  164. package/dist/esm/types/validation-error.types.js +9 -0
  165. package/dist/esm/types/window.types.d.ts +1 -8
  166. package/dist/esm/utils/data/uuid.utils.d.ts +1 -1
  167. package/dist/esm/utils/data/uuid.utils.js +7 -5
  168. package/dist/esm/utils/emitter.utils.d.ts +8 -0
  169. package/dist/esm/utils/emitter.utils.js +29 -0
  170. package/dist/esm/utils/index.d.ts +1 -0
  171. package/dist/esm/utils/index.js +1 -0
  172. package/dist/esm/utils/logging/debug-logger.utils.d.ts +10 -51
  173. package/dist/esm/utils/logging/debug-logger.utils.js +36 -127
  174. package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +4 -0
  175. package/dist/esm/utils/network/fetch-with-timeout.utils.js +22 -0
  176. package/dist/esm/utils/network/index.d.ts +1 -0
  177. package/dist/esm/utils/network/index.js +1 -0
  178. package/dist/esm/utils/network/url.utils.js +2 -42
  179. package/dist/esm/utils/security/sanitize.utils.d.ts +1 -8
  180. package/dist/esm/utils/security/sanitize.utils.js +6 -39
  181. package/dist/esm/utils/validations/config-validations.utils.d.ts +7 -0
  182. package/dist/esm/utils/validations/config-validations.utils.js +76 -22
  183. package/package.json +23 -16
  184. package/dist/browser/web-vitals-CCnqwnC8.mjs +0 -198
  185. package/dist/cjs/constants/browser.constants.d.ts +0 -3
  186. package/dist/cjs/constants/browser.constants.js +0 -41
  187. package/dist/cjs/constants/initialization.constants.d.ts +0 -40
  188. package/dist/cjs/constants/initialization.constants.js +0 -48
  189. package/dist/cjs/constants/limits.constants.d.ts +0 -25
  190. package/dist/cjs/constants/limits.constants.js +0 -40
  191. package/dist/cjs/constants/security.constants.d.ts +0 -1
  192. package/dist/cjs/constants/security.constants.js +0 -12
  193. package/dist/cjs/constants/timing.constants.d.ts +0 -22
  194. package/dist/cjs/constants/timing.constants.js +0 -34
  195. package/dist/cjs/constants/validation.constants.d.ts +0 -13
  196. package/dist/cjs/constants/validation.constants.js +0 -31
  197. package/dist/cjs/handlers/network.handler.d.ts +0 -16
  198. package/dist/cjs/handlers/network.handler.js +0 -136
  199. package/dist/cjs/managers/cross-tab-session.manager.d.ts +0 -170
  200. package/dist/cjs/managers/cross-tab-session.manager.js +0 -730
  201. package/dist/cjs/managers/sampling.manager.d.ts +0 -8
  202. package/dist/cjs/managers/sampling.manager.js +0 -53
  203. package/dist/cjs/managers/session-recovery.manager.d.ts +0 -65
  204. package/dist/cjs/managers/session-recovery.manager.js +0 -237
  205. package/dist/cjs/types/web-vitals.types.d.ts +0 -6
  206. package/dist/esm/constants/browser.constants.d.ts +0 -3
  207. package/dist/esm/constants/browser.constants.js +0 -38
  208. package/dist/esm/constants/initialization.constants.d.ts +0 -40
  209. package/dist/esm/constants/initialization.constants.js +0 -45
  210. package/dist/esm/constants/limits.constants.d.ts +0 -25
  211. package/dist/esm/constants/limits.constants.js +0 -37
  212. package/dist/esm/constants/security.constants.d.ts +0 -1
  213. package/dist/esm/constants/security.constants.js +0 -9
  214. package/dist/esm/constants/timing.constants.d.ts +0 -22
  215. package/dist/esm/constants/timing.constants.js +0 -31
  216. package/dist/esm/constants/validation.constants.d.ts +0 -13
  217. package/dist/esm/constants/validation.constants.js +0 -28
  218. package/dist/esm/handlers/network.handler.d.ts +0 -16
  219. package/dist/esm/handlers/network.handler.js +0 -132
  220. package/dist/esm/managers/cross-tab-session.manager.d.ts +0 -170
  221. package/dist/esm/managers/cross-tab-session.manager.js +0 -726
  222. package/dist/esm/managers/sampling.manager.d.ts +0 -8
  223. package/dist/esm/managers/sampling.manager.js +0 -49
  224. package/dist/esm/managers/session-recovery.manager.d.ts +0 -65
  225. package/dist/esm/managers/session-recovery.manager.js +0 -233
  226. package/dist/esm/types/web-vitals.types.d.ts +0 -6
  227. /package/dist/cjs/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
  228. /package/dist/esm/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
@@ -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,19 +1,91 @@
1
1
  import { debugLog } from '../utils/logging';
2
+ import { DEFAULT_SAMPLING_RATE } from '../constants';
3
+ /**
4
+ * Global state store shared across all TraceLog components
5
+ */
2
6
  const globalState = {};
7
+ /**
8
+ * Resets the global state to its initial empty state.
9
+ * Used primarily for testing and cleanup scenarios.
10
+ */
11
+ export function resetGlobalState() {
12
+ Object.keys(globalState).forEach((key) => {
13
+ delete globalState[key];
14
+ });
15
+ }
16
+ /**
17
+ * Abstract base class providing state management capabilities to TraceLog components.
18
+ *
19
+ * All managers and handlers extend this class to access and modify the shared global state.
20
+ * State operations are synchronous and thread-safe within the single-threaded browser environment.
21
+ */
3
22
  export class StateManager {
23
+ /**
24
+ * Gets a value from the global state
25
+ */
4
26
  get(key) {
5
27
  return globalState[key];
6
28
  }
29
+ /**
30
+ * Sets a value in the global state
31
+ */
7
32
  set(key, value) {
8
33
  const oldValue = globalState[key];
9
- globalState[key] = value;
10
- // Log critical state changes
11
- if (key === 'sessionId' || key === 'config' || key === 'hasStartSession') {
12
- debugLog.debug('StateManager', 'Critical state updated', {
34
+ if (key === 'config' && value) {
35
+ const configValue = value;
36
+ if (configValue) {
37
+ const samplingRate = configValue.samplingRate ?? DEFAULT_SAMPLING_RATE;
38
+ const normalizedSamplingRate = samplingRate > 0 ? samplingRate : DEFAULT_SAMPLING_RATE;
39
+ const hasNormalizedSampling = normalizedSamplingRate !== samplingRate;
40
+ if (hasNormalizedSampling) {
41
+ const normalizedConfig = { ...configValue, samplingRate: normalizedSamplingRate };
42
+ globalState[key] = normalizedConfig;
43
+ }
44
+ else {
45
+ globalState[key] = configValue;
46
+ }
47
+ }
48
+ else {
49
+ globalState[key] = value;
50
+ }
51
+ }
52
+ else {
53
+ globalState[key] = value;
54
+ }
55
+ // Log critical state changes for debugging
56
+ if (this.isCriticalStateKey(key) && this.shouldLog(oldValue, globalState[key])) {
57
+ debugLog.debug('StateManager', 'State updated', {
13
58
  key,
14
- oldValue: key === 'config' ? !!oldValue : oldValue,
15
- newValue: key === 'config' ? !!value : value,
59
+ oldValue: this.formatLogValue(key, oldValue),
60
+ newValue: this.formatLogValue(key, globalState[key]),
16
61
  });
17
62
  }
18
63
  }
64
+ /**
65
+ * Gets the entire state object (for debugging purposes)
66
+ */
67
+ getState() {
68
+ return { ...globalState };
69
+ }
70
+ /**
71
+ * Checks if a state key is considered critical for logging
72
+ */
73
+ isCriticalStateKey(key) {
74
+ return key === 'sessionId' || key === 'config' || key === 'hasStartSession';
75
+ }
76
+ /**
77
+ * Determines if a state change should be logged
78
+ */
79
+ shouldLog(oldValue, newValue) {
80
+ return oldValue !== newValue;
81
+ }
82
+ /**
83
+ * Formats values for logging (avoiding large object dumps)
84
+ */
85
+ formatLogValue(key, value) {
86
+ if (key === 'config') {
87
+ return value ? '(configured)' : '(not configured)';
88
+ }
89
+ return value;
90
+ }
19
91
  }
@@ -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,19 +1,21 @@
1
- import { debugLog } from '../utils/logging';
1
+ import { debugLog } from '../utils/logging/debug-logger.utils';
2
+ /**
3
+ * Manages localStorage with automatic fallback to in-memory storage.
4
+ * Provides a consistent interface for storing session data, configuration,
5
+ * and analytics metadata across browser environments.
6
+ */
2
7
  export class StorageManager {
3
8
  constructor() {
4
- this.storage = null;
5
9
  this.fallbackStorage = new Map();
6
- this.storageAvailable = false;
7
- this.storage = this.init();
8
- this.storageAvailable = this.storage !== null;
9
- if (!this.storageAvailable) {
10
+ this.storage = this.initializeStorage();
11
+ if (!this.storage) {
10
12
  debugLog.warn('StorageManager', 'localStorage not available, using memory fallback');
11
13
  }
12
14
  }
15
+ /**
16
+ * Retrieves an item from storage
17
+ */
13
18
  getItem(key) {
14
- if (!this.storageAvailable) {
15
- return this.fallbackStorage.get(key) ?? null;
16
- }
17
19
  try {
18
20
  if (this.storage) {
19
21
  return this.storage.getItem(key);
@@ -21,53 +23,84 @@ export class StorageManager {
21
23
  return this.fallbackStorage.get(key) ?? null;
22
24
  }
23
25
  catch (error) {
24
- debugLog.warn('StorageManager', 'Storage getItem failed, using memory fallback', { key, error });
25
- this.storageAvailable = false;
26
+ debugLog.warn('StorageManager', 'Failed to get item, using fallback', { key, error });
26
27
  return this.fallbackStorage.get(key) ?? null;
27
28
  }
28
29
  }
30
+ /**
31
+ * Stores an item in storage
32
+ */
29
33
  setItem(key, value) {
30
- if (!this.storageAvailable) {
31
- this.fallbackStorage.set(key, value);
32
- return;
33
- }
34
34
  try {
35
35
  if (this.storage) {
36
36
  this.storage.setItem(key, value);
37
37
  return;
38
38
  }
39
- this.fallbackStorage.set(key, value);
40
39
  }
41
40
  catch (error) {
42
- debugLog.warn('StorageManager', 'Storage setItem failed, using memory fallback', { key, error });
43
- this.storageAvailable = false;
44
- this.fallbackStorage.set(key, value);
41
+ debugLog.warn('StorageManager', 'Failed to set item, using fallback', { key, error });
45
42
  }
43
+ // Always update fallback for consistency
44
+ this.fallbackStorage.set(key, value);
46
45
  }
46
+ /**
47
+ * Removes an item from storage
48
+ */
47
49
  removeItem(key) {
48
- if (!this.storageAvailable) {
49
- this.fallbackStorage.delete(key);
50
- return;
51
- }
52
50
  try {
53
51
  if (this.storage) {
54
52
  this.storage.removeItem(key);
55
- return;
56
53
  }
57
- this.fallbackStorage.delete(key);
58
54
  }
59
55
  catch (error) {
60
- debugLog.warn('StorageManager', 'Storage removeItem failed, using memory fallback', { key, error });
61
- this.storageAvailable = false;
62
- this.fallbackStorage.delete(key);
56
+ debugLog.warn('StorageManager', 'Failed to remove item', { key, error });
57
+ }
58
+ // Always clean fallback
59
+ this.fallbackStorage.delete(key);
60
+ }
61
+ /**
62
+ * Clears all TracLog-related items from storage
63
+ */
64
+ clear() {
65
+ if (!this.storage) {
66
+ this.fallbackStorage.clear();
67
+ return;
68
+ }
69
+ try {
70
+ const keysToRemove = [];
71
+ for (let i = 0; i < this.storage.length; i++) {
72
+ const key = this.storage.key(i);
73
+ if (key?.startsWith('tracelog_')) {
74
+ keysToRemove.push(key);
75
+ }
76
+ }
77
+ keysToRemove.forEach((key) => this.storage.removeItem(key));
78
+ this.fallbackStorage.clear();
79
+ debugLog.debug('StorageManager', 'Cleared storage', { itemsRemoved: keysToRemove.length });
80
+ }
81
+ catch (error) {
82
+ debugLog.error('StorageManager', 'Failed to clear storage', { error });
83
+ this.fallbackStorage.clear();
63
84
  }
64
85
  }
65
- init() {
86
+ /**
87
+ * Checks if storage is available
88
+ */
89
+ isAvailable() {
90
+ return this.storage !== null;
91
+ }
92
+ /**
93
+ * Initialize localStorage with feature detection
94
+ */
95
+ initializeStorage() {
96
+ if (typeof window === 'undefined') {
97
+ return null;
98
+ }
66
99
  try {
67
- const test = '__storage_test__';
68
- const storage = window['localStorage'];
69
- storage.setItem(test, test);
70
- storage.removeItem(test);
100
+ const storage = window.localStorage;
101
+ const testKey = '__tracelog_test__';
102
+ storage.setItem(testKey, 'test');
103
+ storage.removeItem(testKey);
71
104
  return storage;
72
105
  }
73
106
  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
  }