@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.
- package/README.md +58 -24
- package/dist/browser/tracelog.js +1934 -3226
- package/dist/cjs/api.d.ts +33 -19
- package/dist/cjs/api.js +111 -156
- package/dist/cjs/app.constants.d.ts +80 -1
- package/dist/cjs/app.constants.js +90 -3
- package/dist/cjs/app.d.ts +29 -44
- package/dist/cjs/app.js +114 -212
- package/dist/cjs/app.types.d.ts +2 -7
- package/dist/cjs/app.types.js +10 -21
- package/dist/cjs/constants/api.constants.js +11 -5
- package/dist/cjs/constants/config.constants.d.ts +75 -0
- package/dist/cjs/constants/config.constants.js +178 -0
- package/dist/cjs/constants/error.constants.d.ts +29 -0
- package/dist/cjs/constants/error.constants.js +50 -0
- package/dist/cjs/constants/index.d.ts +3 -6
- package/dist/cjs/constants/index.js +3 -6
- package/dist/cjs/constants/performance.constants.d.ts +28 -0
- package/dist/cjs/constants/performance.constants.js +43 -0
- package/dist/cjs/handlers/click.handler.d.ts +1 -0
- package/dist/cjs/handlers/click.handler.js +30 -49
- package/dist/cjs/handlers/error.handler.d.ts +11 -6
- package/dist/cjs/handlers/error.handler.js +91 -51
- package/dist/cjs/handlers/page-view.handler.js +38 -29
- package/dist/cjs/handlers/performance.handler.d.ts +3 -0
- package/dist/cjs/handlers/performance.handler.js +76 -37
- package/dist/cjs/handlers/scroll.handler.d.ts +15 -0
- package/dist/cjs/handlers/scroll.handler.js +105 -31
- package/dist/cjs/handlers/session.handler.d.ts +6 -20
- package/dist/cjs/handlers/session.handler.js +38 -326
- package/dist/cjs/integrations/google-analytics.integration.d.ts +0 -1
- package/dist/cjs/integrations/google-analytics.integration.js +27 -98
- package/dist/cjs/listeners/input-listener-managers.d.ts +18 -9
- package/dist/cjs/listeners/input-listener-managers.js +24 -33
- package/dist/cjs/listeners/touch-listener-manager.d.ts +1 -3
- package/dist/cjs/listeners/touch-listener-manager.js +1 -23
- package/dist/cjs/listeners/visibility-listener-manager.d.ts +1 -4
- package/dist/cjs/listeners/visibility-listener-manager.js +6 -42
- package/dist/cjs/managers/api.manager.d.ts +13 -3
- package/dist/cjs/managers/api.manager.js +35 -5
- package/dist/cjs/managers/config.manager.d.ts +53 -3
- package/dist/cjs/managers/config.manager.js +131 -62
- package/dist/cjs/managers/event.manager.d.ts +57 -36
- package/dist/cjs/managers/event.manager.js +266 -417
- package/dist/cjs/managers/sender.manager.d.ts +40 -22
- package/dist/cjs/managers/sender.manager.js +200 -198
- package/dist/cjs/managers/session.manager.d.ts +80 -66
- package/dist/cjs/managers/session.manager.js +267 -522
- package/dist/cjs/managers/state.manager.d.ts +33 -0
- package/dist/cjs/managers/state.manager.js +79 -6
- package/dist/cjs/managers/storage.manager.d.ts +26 -2
- package/dist/cjs/managers/storage.manager.js +67 -34
- package/dist/cjs/managers/tags.manager.d.ts +31 -7
- package/dist/cjs/managers/tags.manager.js +123 -241
- package/dist/cjs/managers/user.manager.d.ts +14 -5
- package/dist/cjs/managers/user.manager.js +17 -9
- package/dist/cjs/public-api.d.ts +10 -1
- package/dist/cjs/public-api.js +18 -24
- package/dist/cjs/test-bridge.d.ts +48 -0
- package/dist/cjs/test-bridge.js +110 -0
- package/dist/cjs/types/api.types.d.ts +21 -6
- package/dist/cjs/types/api.types.js +21 -6
- package/dist/cjs/types/config.types.d.ts +22 -84
- package/dist/cjs/types/emitter.types.d.ts +11 -0
- package/dist/cjs/types/emitter.types.js +8 -0
- package/dist/cjs/types/event.types.d.ts +8 -11
- package/dist/cjs/types/index.d.ts +3 -1
- package/dist/cjs/types/index.js +3 -1
- package/dist/cjs/types/queue.types.d.ts +1 -0
- package/dist/cjs/types/session.types.d.ts +0 -64
- package/dist/cjs/types/state.types.d.ts +1 -0
- package/dist/cjs/types/test-bridge.types.d.ts +38 -0
- package/dist/cjs/types/validation-error.types.d.ts +7 -0
- package/dist/cjs/types/validation-error.types.js +11 -1
- package/dist/cjs/types/window.types.d.ts +1 -8
- package/dist/cjs/utils/data/uuid.utils.d.ts +1 -1
- package/dist/cjs/utils/data/uuid.utils.js +7 -5
- package/dist/cjs/utils/emitter.utils.d.ts +8 -0
- package/dist/cjs/utils/emitter.utils.js +33 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/logging/debug-logger.utils.d.ts +10 -51
- package/dist/cjs/utils/logging/debug-logger.utils.js +36 -127
- package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +4 -0
- package/dist/cjs/utils/network/fetch-with-timeout.utils.js +25 -0
- package/dist/cjs/utils/network/index.d.ts +1 -0
- package/dist/cjs/utils/network/index.js +1 -0
- package/dist/cjs/utils/network/url.utils.js +2 -42
- package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -8
- package/dist/cjs/utils/security/sanitize.utils.js +7 -41
- package/dist/cjs/utils/validations/config-validations.utils.d.ts +7 -0
- package/dist/cjs/utils/validations/config-validations.utils.js +77 -22
- package/dist/esm/api.d.ts +33 -19
- package/dist/esm/api.js +105 -118
- package/dist/esm/app.constants.d.ts +80 -1
- package/dist/esm/app.constants.js +89 -1
- package/dist/esm/app.d.ts +29 -44
- package/dist/esm/app.js +115 -213
- package/dist/esm/app.types.d.ts +2 -7
- package/dist/esm/app.types.js +1 -7
- package/dist/esm/constants/api.constants.js +10 -4
- package/dist/esm/constants/config.constants.d.ts +75 -0
- package/dist/esm/constants/config.constants.js +174 -0
- package/dist/esm/constants/error.constants.d.ts +29 -0
- package/dist/esm/constants/error.constants.js +47 -0
- package/dist/esm/constants/index.d.ts +3 -6
- package/dist/esm/constants/index.js +3 -6
- package/dist/esm/constants/performance.constants.d.ts +28 -0
- package/dist/esm/constants/performance.constants.js +40 -0
- package/dist/esm/handlers/click.handler.d.ts +1 -0
- package/dist/esm/handlers/click.handler.js +30 -49
- package/dist/esm/handlers/error.handler.d.ts +11 -6
- package/dist/esm/handlers/error.handler.js +91 -51
- package/dist/esm/handlers/page-view.handler.js +38 -29
- package/dist/esm/handlers/performance.handler.d.ts +3 -0
- package/dist/esm/handlers/performance.handler.js +71 -32
- package/dist/esm/handlers/scroll.handler.d.ts +15 -0
- package/dist/esm/handlers/scroll.handler.js +106 -32
- package/dist/esm/handlers/session.handler.d.ts +6 -20
- package/dist/esm/handlers/session.handler.js +38 -326
- package/dist/esm/integrations/google-analytics.integration.d.ts +0 -1
- package/dist/esm/integrations/google-analytics.integration.js +27 -98
- package/dist/esm/listeners/input-listener-managers.d.ts +18 -9
- package/dist/esm/listeners/input-listener-managers.js +23 -32
- package/dist/esm/listeners/touch-listener-manager.d.ts +1 -3
- package/dist/esm/listeners/touch-listener-manager.js +1 -23
- package/dist/esm/listeners/visibility-listener-manager.d.ts +1 -4
- package/dist/esm/listeners/visibility-listener-manager.js +6 -42
- package/dist/esm/managers/api.manager.d.ts +13 -3
- package/dist/esm/managers/api.manager.js +34 -3
- package/dist/esm/managers/config.manager.d.ts +53 -3
- package/dist/esm/managers/config.manager.js +133 -64
- package/dist/esm/managers/event.manager.d.ts +57 -36
- package/dist/esm/managers/event.manager.js +268 -419
- package/dist/esm/managers/sender.manager.d.ts +40 -22
- package/dist/esm/managers/sender.manager.js +201 -199
- package/dist/esm/managers/session.manager.d.ts +80 -66
- package/dist/esm/managers/session.manager.js +269 -524
- package/dist/esm/managers/state.manager.d.ts +33 -0
- package/dist/esm/managers/state.manager.js +78 -6
- package/dist/esm/managers/storage.manager.d.ts +26 -2
- package/dist/esm/managers/storage.manager.js +66 -33
- package/dist/esm/managers/tags.manager.d.ts +31 -7
- package/dist/esm/managers/tags.manager.js +124 -242
- package/dist/esm/managers/user.manager.d.ts +14 -5
- package/dist/esm/managers/user.manager.js +17 -9
- package/dist/esm/public-api.d.ts +10 -1
- package/dist/esm/public-api.js +14 -1
- package/dist/esm/test-bridge.d.ts +48 -0
- package/dist/esm/test-bridge.js +106 -0
- package/dist/esm/types/api.types.d.ts +21 -6
- package/dist/esm/types/api.types.js +21 -6
- package/dist/esm/types/config.types.d.ts +22 -84
- package/dist/esm/types/emitter.types.d.ts +11 -0
- package/dist/esm/types/emitter.types.js +5 -0
- package/dist/esm/types/event.types.d.ts +8 -11
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/types/index.js +3 -1
- package/dist/esm/types/queue.types.d.ts +1 -0
- package/dist/esm/types/session.types.d.ts +0 -64
- package/dist/esm/types/state.types.d.ts +1 -0
- package/dist/esm/types/test-bridge.types.d.ts +38 -0
- package/dist/esm/types/validation-error.types.d.ts +7 -0
- package/dist/esm/types/validation-error.types.js +9 -0
- package/dist/esm/types/window.types.d.ts +1 -8
- package/dist/esm/utils/data/uuid.utils.d.ts +1 -1
- package/dist/esm/utils/data/uuid.utils.js +7 -5
- package/dist/esm/utils/emitter.utils.d.ts +8 -0
- package/dist/esm/utils/emitter.utils.js +29 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/logging/debug-logger.utils.d.ts +10 -51
- package/dist/esm/utils/logging/debug-logger.utils.js +36 -127
- package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +4 -0
- package/dist/esm/utils/network/fetch-with-timeout.utils.js +22 -0
- package/dist/esm/utils/network/index.d.ts +1 -0
- package/dist/esm/utils/network/index.js +1 -0
- package/dist/esm/utils/network/url.utils.js +2 -42
- package/dist/esm/utils/security/sanitize.utils.d.ts +1 -8
- package/dist/esm/utils/security/sanitize.utils.js +6 -39
- package/dist/esm/utils/validations/config-validations.utils.d.ts +7 -0
- package/dist/esm/utils/validations/config-validations.utils.js +76 -22
- package/package.json +23 -16
- package/dist/browser/web-vitals-CCnqwnC8.mjs +0 -198
- package/dist/cjs/constants/browser.constants.d.ts +0 -3
- package/dist/cjs/constants/browser.constants.js +0 -41
- package/dist/cjs/constants/initialization.constants.d.ts +0 -40
- package/dist/cjs/constants/initialization.constants.js +0 -48
- package/dist/cjs/constants/limits.constants.d.ts +0 -25
- package/dist/cjs/constants/limits.constants.js +0 -40
- package/dist/cjs/constants/security.constants.d.ts +0 -1
- package/dist/cjs/constants/security.constants.js +0 -12
- package/dist/cjs/constants/timing.constants.d.ts +0 -22
- package/dist/cjs/constants/timing.constants.js +0 -34
- package/dist/cjs/constants/validation.constants.d.ts +0 -13
- package/dist/cjs/constants/validation.constants.js +0 -31
- package/dist/cjs/handlers/network.handler.d.ts +0 -16
- package/dist/cjs/handlers/network.handler.js +0 -136
- package/dist/cjs/managers/cross-tab-session.manager.d.ts +0 -170
- package/dist/cjs/managers/cross-tab-session.manager.js +0 -730
- package/dist/cjs/managers/sampling.manager.d.ts +0 -8
- package/dist/cjs/managers/sampling.manager.js +0 -53
- package/dist/cjs/managers/session-recovery.manager.d.ts +0 -65
- package/dist/cjs/managers/session-recovery.manager.js +0 -237
- package/dist/cjs/types/web-vitals.types.d.ts +0 -6
- package/dist/esm/constants/browser.constants.d.ts +0 -3
- package/dist/esm/constants/browser.constants.js +0 -38
- package/dist/esm/constants/initialization.constants.d.ts +0 -40
- package/dist/esm/constants/initialization.constants.js +0 -45
- package/dist/esm/constants/limits.constants.d.ts +0 -25
- package/dist/esm/constants/limits.constants.js +0 -37
- package/dist/esm/constants/security.constants.d.ts +0 -1
- package/dist/esm/constants/security.constants.js +0 -9
- package/dist/esm/constants/timing.constants.d.ts +0 -22
- package/dist/esm/constants/timing.constants.js +0 -31
- package/dist/esm/constants/validation.constants.d.ts +0 -13
- package/dist/esm/constants/validation.constants.js +0 -28
- package/dist/esm/handlers/network.handler.d.ts +0 -16
- package/dist/esm/handlers/network.handler.js +0 -132
- package/dist/esm/managers/cross-tab-session.manager.d.ts +0 -170
- package/dist/esm/managers/cross-tab-session.manager.js +0 -726
- package/dist/esm/managers/sampling.manager.d.ts +0 -8
- package/dist/esm/managers/sampling.manager.js +0 -49
- package/dist/esm/managers/session-recovery.manager.d.ts +0 -65
- package/dist/esm/managers/session-recovery.manager.js +0 -233
- package/dist/esm/types/web-vitals.types.d.ts +0 -6
- /package/dist/cjs/types/{web-vitals.types.js → test-bridge.types.js} +0 -0
- /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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
15
|
-
newValue: key
|
|
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
|
-
|
|
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.
|
|
7
|
-
this.storage
|
|
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', '
|
|
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', '
|
|
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', '
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
|
68
|
-
const
|
|
69
|
-
storage.setItem(
|
|
70
|
-
storage.removeItem(
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
private
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
}
|