@tracelog/lib 0.5.4 → 0.6.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 +157 -180
- package/dist/browser/tracelog.esm.js +1007 -1357
- package/dist/browser/tracelog.js +2 -2
- package/dist/cjs/api.d.ts +12 -2
- package/dist/cjs/api.js +63 -27
- package/dist/cjs/app.d.ts +2 -2
- package/dist/cjs/app.js +26 -32
- package/dist/cjs/constants/config.constants.d.ts +4 -2
- package/dist/cjs/constants/config.constants.js +6 -18
- package/dist/cjs/constants/index.d.ts +0 -1
- package/dist/cjs/constants/index.js +0 -1
- package/dist/cjs/constants/storage.constants.d.ts +3 -2
- package/dist/cjs/constants/storage.constants.js +4 -4
- package/dist/cjs/handlers/click.handler.js +3 -6
- package/dist/cjs/handlers/error.handler.js +1 -11
- package/dist/cjs/handlers/page-view.handler.js +0 -4
- package/dist/cjs/handlers/performance.handler.js +14 -29
- package/dist/cjs/handlers/scroll.handler.js +7 -6
- package/dist/cjs/handlers/session.handler.js +7 -6
- package/dist/cjs/integrations/google-analytics.integration.js +2 -6
- package/dist/cjs/listeners/activity-listener-manager.js +3 -3
- package/dist/cjs/listeners/input-listener-managers.js +3 -3
- package/dist/cjs/listeners/touch-listener-manager.js +3 -3
- package/dist/cjs/listeners/unload-listener-manager.js +3 -3
- package/dist/cjs/listeners/visibility-listener-manager.js +3 -3
- package/dist/cjs/managers/event.manager.d.ts +2 -1
- package/dist/cjs/managers/event.manager.js +60 -38
- package/dist/cjs/managers/sender.manager.js +29 -36
- package/dist/cjs/managers/session.manager.js +5 -13
- package/dist/cjs/managers/state.manager.d.ts +0 -3
- package/dist/cjs/managers/state.manager.js +1 -43
- package/dist/cjs/managers/storage.manager.d.ts +16 -2
- package/dist/cjs/managers/storage.manager.js +73 -19
- package/dist/cjs/managers/user.manager.d.ts +1 -1
- package/dist/cjs/managers/user.manager.js +2 -2
- package/dist/cjs/public-api.d.ts +3 -3
- package/dist/cjs/public-api.js +1 -1
- package/dist/cjs/test-bridge.d.ts +1 -0
- package/dist/cjs/test-bridge.js +37 -2
- package/dist/cjs/types/config.types.d.ts +15 -18
- package/dist/cjs/types/config.types.js +6 -0
- package/dist/cjs/types/event.types.d.ts +1 -13
- package/dist/cjs/types/index.d.ts +0 -2
- package/dist/cjs/types/index.js +0 -2
- package/dist/cjs/types/mode.types.d.ts +1 -2
- package/dist/cjs/types/mode.types.js +0 -1
- package/dist/cjs/types/queue.types.d.ts +0 -6
- package/dist/cjs/types/state.types.d.ts +2 -0
- package/dist/cjs/types/test-bridge.types.d.ts +2 -2
- package/dist/cjs/types/validation-error.types.d.ts +0 -6
- package/dist/cjs/types/validation-error.types.js +1 -10
- package/dist/cjs/utils/browser/device-detector.utils.js +2 -24
- package/dist/cjs/utils/browser/index.d.ts +1 -0
- package/dist/cjs/utils/browser/index.js +1 -0
- package/dist/cjs/utils/browser/qa-mode.utils.d.ts +13 -0
- package/dist/cjs/utils/browser/qa-mode.utils.js +43 -0
- package/dist/cjs/utils/browser/utm-params.utils.js +0 -15
- package/dist/cjs/utils/data/uuid.utils.d.ts +13 -0
- package/dist/cjs/utils/data/uuid.utils.js +37 -1
- package/dist/cjs/utils/index.d.ts +1 -1
- package/dist/cjs/utils/index.js +1 -1
- package/dist/cjs/utils/logging.utils.d.ts +6 -0
- package/dist/cjs/utils/logging.utils.js +25 -0
- package/dist/cjs/utils/network/index.d.ts +0 -1
- package/dist/cjs/utils/network/index.js +0 -1
- package/dist/cjs/utils/network/url.utils.d.ts +2 -8
- package/dist/cjs/utils/network/url.utils.js +46 -90
- package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -13
- package/dist/cjs/utils/security/sanitize.utils.js +15 -178
- package/dist/cjs/utils/validations/config-validations.utils.d.ts +3 -9
- package/dist/cjs/utils/validations/config-validations.utils.js +48 -94
- package/dist/cjs/utils/validations/event-validations.utils.js +11 -5
- package/dist/cjs/utils/validations/index.d.ts +0 -1
- package/dist/cjs/utils/validations/index.js +0 -1
- package/dist/cjs/utils/validations/metadata-validations.utils.js +0 -1
- package/dist/cjs/utils/validations/type-guards.utils.d.ts +2 -2
- package/dist/cjs/utils/validations/type-guards.utils.js +50 -4
- package/dist/esm/api.d.ts +12 -2
- package/dist/esm/api.js +62 -27
- package/dist/esm/app.d.ts +2 -2
- package/dist/esm/app.js +28 -34
- package/dist/esm/constants/config.constants.d.ts +4 -2
- package/dist/esm/constants/config.constants.js +4 -16
- package/dist/esm/constants/index.d.ts +0 -1
- package/dist/esm/constants/index.js +0 -1
- package/dist/esm/constants/storage.constants.d.ts +3 -2
- package/dist/esm/constants/storage.constants.js +3 -2
- package/dist/esm/handlers/click.handler.js +3 -6
- package/dist/esm/handlers/error.handler.js +1 -11
- package/dist/esm/handlers/page-view.handler.js +0 -4
- package/dist/esm/handlers/performance.handler.js +14 -29
- package/dist/esm/handlers/scroll.handler.js +7 -6
- package/dist/esm/handlers/session.handler.js +7 -6
- package/dist/esm/integrations/google-analytics.integration.js +3 -7
- package/dist/esm/listeners/activity-listener-manager.js +3 -3
- package/dist/esm/listeners/input-listener-managers.js +3 -3
- package/dist/esm/listeners/touch-listener-manager.js +3 -3
- package/dist/esm/listeners/unload-listener-manager.js +3 -3
- package/dist/esm/listeners/visibility-listener-manager.js +3 -3
- package/dist/esm/managers/event.manager.d.ts +2 -1
- package/dist/esm/managers/event.manager.js +62 -40
- package/dist/esm/managers/sender.manager.js +31 -38
- package/dist/esm/managers/session.manager.js +5 -13
- package/dist/esm/managers/state.manager.d.ts +0 -3
- package/dist/esm/managers/state.manager.js +1 -43
- package/dist/esm/managers/storage.manager.d.ts +16 -2
- package/dist/esm/managers/storage.manager.js +73 -19
- package/dist/esm/managers/user.manager.d.ts +1 -1
- package/dist/esm/managers/user.manager.js +2 -2
- package/dist/esm/public-api.d.ts +3 -3
- package/dist/esm/public-api.js +1 -1
- package/dist/esm/test-bridge.d.ts +1 -0
- package/dist/esm/test-bridge.js +37 -2
- package/dist/esm/types/config.types.d.ts +15 -18
- package/dist/esm/types/config.types.js +5 -1
- package/dist/esm/types/event.types.d.ts +1 -13
- package/dist/esm/types/index.d.ts +0 -2
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/mode.types.d.ts +1 -2
- package/dist/esm/types/mode.types.js +0 -1
- package/dist/esm/types/queue.types.d.ts +0 -6
- package/dist/esm/types/state.types.d.ts +2 -0
- package/dist/esm/types/test-bridge.types.d.ts +2 -2
- package/dist/esm/types/validation-error.types.d.ts +0 -6
- package/dist/esm/types/validation-error.types.js +0 -8
- package/dist/esm/utils/browser/device-detector.utils.js +2 -24
- package/dist/esm/utils/browser/index.d.ts +1 -0
- package/dist/esm/utils/browser/index.js +1 -0
- package/dist/esm/utils/browser/qa-mode.utils.d.ts +13 -0
- package/dist/esm/utils/browser/qa-mode.utils.js +39 -0
- package/dist/esm/utils/browser/utm-params.utils.js +0 -15
- package/dist/esm/utils/data/uuid.utils.d.ts +13 -0
- package/dist/esm/utils/data/uuid.utils.js +35 -0
- package/dist/esm/utils/index.d.ts +1 -1
- package/dist/esm/utils/index.js +1 -1
- package/dist/esm/utils/logging.utils.d.ts +6 -0
- package/dist/esm/utils/logging.utils.js +20 -0
- package/dist/esm/utils/network/index.d.ts +0 -1
- package/dist/esm/utils/network/index.js +0 -1
- package/dist/esm/utils/network/url.utils.d.ts +2 -8
- package/dist/esm/utils/network/url.utils.js +45 -88
- package/dist/esm/utils/security/sanitize.utils.d.ts +1 -13
- package/dist/esm/utils/security/sanitize.utils.js +15 -176
- package/dist/esm/utils/validations/config-validations.utils.d.ts +3 -9
- package/dist/esm/utils/validations/config-validations.utils.js +49 -94
- package/dist/esm/utils/validations/event-validations.utils.js +11 -5
- package/dist/esm/utils/validations/index.d.ts +0 -1
- package/dist/esm/utils/validations/index.js +0 -1
- package/dist/esm/utils/validations/metadata-validations.utils.js +0 -1
- package/dist/esm/utils/validations/type-guards.utils.d.ts +2 -2
- package/dist/esm/utils/validations/type-guards.utils.js +50 -4
- package/package.json +1 -1
- package/dist/cjs/app.types.d.ts +0 -2
- package/dist/cjs/app.types.js +0 -12
- package/dist/cjs/constants/api.constants.d.ts +0 -6
- package/dist/cjs/constants/api.constants.js +0 -14
- package/dist/cjs/managers/api.manager.d.ts +0 -13
- package/dist/cjs/managers/api.manager.js +0 -44
- package/dist/cjs/managers/config.builder.d.ts +0 -33
- package/dist/cjs/managers/config.builder.js +0 -116
- package/dist/cjs/managers/config.manager.d.ts +0 -56
- package/dist/cjs/managers/config.manager.js +0 -157
- package/dist/cjs/managers/tags.manager.d.ts +0 -36
- package/dist/cjs/managers/tags.manager.js +0 -171
- package/dist/cjs/types/api.types.d.ts +0 -52
- package/dist/cjs/types/api.types.js +0 -56
- package/dist/cjs/types/tag.types.d.ts +0 -43
- package/dist/cjs/types/tag.types.js +0 -31
- package/dist/cjs/utils/logging/debug-logger.utils.d.ts +0 -14
- package/dist/cjs/utils/logging/debug-logger.utils.js +0 -47
- package/dist/cjs/utils/logging/index.d.ts +0 -1
- package/dist/cjs/utils/logging/index.js +0 -5
- package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +0 -4
- package/dist/cjs/utils/network/fetch-with-timeout.utils.js +0 -25
- package/dist/cjs/utils/validations/url-validations.utils.d.ts +0 -15
- package/dist/cjs/utils/validations/url-validations.utils.js +0 -47
- package/dist/esm/app.types.d.ts +0 -2
- package/dist/esm/app.types.js +0 -1
- package/dist/esm/constants/api.constants.d.ts +0 -6
- package/dist/esm/constants/api.constants.js +0 -11
- package/dist/esm/managers/api.manager.d.ts +0 -13
- package/dist/esm/managers/api.manager.js +0 -41
- package/dist/esm/managers/config.builder.d.ts +0 -33
- package/dist/esm/managers/config.builder.js +0 -112
- package/dist/esm/managers/config.manager.d.ts +0 -56
- package/dist/esm/managers/config.manager.js +0 -153
- package/dist/esm/managers/tags.manager.d.ts +0 -36
- package/dist/esm/managers/tags.manager.js +0 -167
- package/dist/esm/types/api.types.d.ts +0 -52
- package/dist/esm/types/api.types.js +0 -53
- package/dist/esm/types/tag.types.d.ts +0 -43
- package/dist/esm/types/tag.types.js +0 -28
- package/dist/esm/utils/logging/debug-logger.utils.d.ts +0 -14
- package/dist/esm/utils/logging/debug-logger.utils.js +0 -44
- package/dist/esm/utils/logging/index.d.ts +0 -1
- package/dist/esm/utils/logging/index.js +0 -1
- package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +0 -4
- package/dist/esm/utils/network/fetch-with-timeout.utils.js +0 -22
- package/dist/esm/utils/validations/url-validations.utils.d.ts +0 -15
- package/dist/esm/utils/validations/url-validations.utils.js +0 -42
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Manages localStorage with automatic fallback to in-memory storage.
|
|
2
|
+
* Manages localStorage and sessionStorage with automatic fallback to in-memory storage.
|
|
3
3
|
* Provides a consistent interface for storing session data, configuration,
|
|
4
4
|
* and analytics metadata across browser environments.
|
|
5
5
|
*/
|
|
6
6
|
export declare class StorageManager {
|
|
7
7
|
private readonly storage;
|
|
8
|
+
private readonly sessionStorageRef;
|
|
8
9
|
private readonly fallbackStorage;
|
|
10
|
+
private readonly fallbackSessionStorage;
|
|
9
11
|
private hasQuotaExceededError;
|
|
10
12
|
constructor();
|
|
11
13
|
/**
|
|
@@ -34,7 +36,19 @@ export declare class StorageManager {
|
|
|
34
36
|
*/
|
|
35
37
|
hasQuotaError(): boolean;
|
|
36
38
|
/**
|
|
37
|
-
* Initialize localStorage with feature detection
|
|
39
|
+
* Initialize storage (localStorage or sessionStorage) with feature detection
|
|
38
40
|
*/
|
|
39
41
|
private initializeStorage;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves an item from sessionStorage
|
|
44
|
+
*/
|
|
45
|
+
getSessionItem(key: string): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Stores an item in sessionStorage
|
|
48
|
+
*/
|
|
49
|
+
setSessionItem(key: string, value: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Removes an item from sessionStorage
|
|
52
|
+
*/
|
|
53
|
+
removeSessionItem(key: string): void;
|
|
40
54
|
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageManager = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
5
|
/**
|
|
6
|
-
* Manages localStorage with automatic fallback to in-memory storage.
|
|
6
|
+
* Manages localStorage and sessionStorage with automatic fallback to in-memory storage.
|
|
7
7
|
* Provides a consistent interface for storing session data, configuration,
|
|
8
8
|
* and analytics metadata across browser environments.
|
|
9
9
|
*/
|
|
10
10
|
class StorageManager {
|
|
11
11
|
constructor() {
|
|
12
12
|
this.fallbackStorage = new Map();
|
|
13
|
+
this.fallbackSessionStorage = new Map();
|
|
13
14
|
this.hasQuotaExceededError = false;
|
|
14
|
-
this.storage = this.initializeStorage();
|
|
15
|
+
this.storage = this.initializeStorage('localStorage');
|
|
16
|
+
this.sessionStorageRef = this.initializeStorage('sessionStorage');
|
|
15
17
|
if (!this.storage) {
|
|
16
|
-
|
|
18
|
+
(0, utils_1.log)('warn', 'localStorage not available, using memory fallback');
|
|
19
|
+
}
|
|
20
|
+
if (!this.sessionStorageRef) {
|
|
21
|
+
(0, utils_1.log)('warn', 'sessionStorage not available, using memory fallback');
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
/**
|
|
@@ -26,8 +31,8 @@ class StorageManager {
|
|
|
26
31
|
}
|
|
27
32
|
return this.fallbackStorage.get(key) ?? null;
|
|
28
33
|
}
|
|
29
|
-
catch
|
|
30
|
-
|
|
34
|
+
catch {
|
|
35
|
+
// Silent fallback - user already warned in constructor
|
|
31
36
|
return this.fallbackStorage.get(key) ?? null;
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -44,14 +49,12 @@ class StorageManager {
|
|
|
44
49
|
catch (error) {
|
|
45
50
|
if (error instanceof DOMException && error.name === 'QuotaExceededError') {
|
|
46
51
|
this.hasQuotaExceededError = true;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
valueSize: value.length,
|
|
52
|
+
(0, utils_1.log)('error', 'localStorage quota exceeded - data will not persist after reload', {
|
|
53
|
+
error,
|
|
54
|
+
data: { key, valueSize: value.length },
|
|
50
55
|
});
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
debug_logger_utils_1.debugLog.warn('StorageManager', 'Failed to set item, using fallback', { key, error });
|
|
54
|
-
}
|
|
57
|
+
// Else: Silent fallback - user already warned in constructor
|
|
55
58
|
}
|
|
56
59
|
// Always update fallback for consistency
|
|
57
60
|
this.fallbackStorage.set(key, value);
|
|
@@ -65,8 +68,8 @@ class StorageManager {
|
|
|
65
68
|
this.storage.removeItem(key);
|
|
66
69
|
}
|
|
67
70
|
}
|
|
68
|
-
catch
|
|
69
|
-
|
|
71
|
+
catch {
|
|
72
|
+
// Silent - not critical
|
|
70
73
|
}
|
|
71
74
|
// Always clean fallback
|
|
72
75
|
this.fallbackStorage.delete(key);
|
|
@@ -89,10 +92,9 @@ class StorageManager {
|
|
|
89
92
|
}
|
|
90
93
|
keysToRemove.forEach((key) => this.storage.removeItem(key));
|
|
91
94
|
this.fallbackStorage.clear();
|
|
92
|
-
debug_logger_utils_1.debugLog.debug('StorageManager', 'Cleared storage', { itemsRemoved: keysToRemove.length });
|
|
93
95
|
}
|
|
94
96
|
catch (error) {
|
|
95
|
-
|
|
97
|
+
(0, utils_1.log)('error', 'Failed to clear storage', { error });
|
|
96
98
|
this.fallbackStorage.clear();
|
|
97
99
|
}
|
|
98
100
|
}
|
|
@@ -110,14 +112,14 @@ class StorageManager {
|
|
|
110
112
|
return this.hasQuotaExceededError;
|
|
111
113
|
}
|
|
112
114
|
/**
|
|
113
|
-
* Initialize localStorage with feature detection
|
|
115
|
+
* Initialize storage (localStorage or sessionStorage) with feature detection
|
|
114
116
|
*/
|
|
115
|
-
initializeStorage() {
|
|
117
|
+
initializeStorage(type) {
|
|
116
118
|
if (typeof window === 'undefined') {
|
|
117
119
|
return null;
|
|
118
120
|
}
|
|
119
121
|
try {
|
|
120
|
-
const storage = window.localStorage;
|
|
122
|
+
const storage = type === 'localStorage' ? window.localStorage : window.sessionStorage;
|
|
121
123
|
const testKey = '__tracelog_test__';
|
|
122
124
|
storage.setItem(testKey, 'test');
|
|
123
125
|
storage.removeItem(testKey);
|
|
@@ -127,5 +129,57 @@ class StorageManager {
|
|
|
127
129
|
return null;
|
|
128
130
|
}
|
|
129
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves an item from sessionStorage
|
|
134
|
+
*/
|
|
135
|
+
getSessionItem(key) {
|
|
136
|
+
try {
|
|
137
|
+
if (this.sessionStorageRef) {
|
|
138
|
+
return this.sessionStorageRef.getItem(key);
|
|
139
|
+
}
|
|
140
|
+
return this.fallbackSessionStorage.get(key) ?? null;
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
// Silent fallback - user already warned in constructor
|
|
144
|
+
return this.fallbackSessionStorage.get(key) ?? null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Stores an item in sessionStorage
|
|
149
|
+
*/
|
|
150
|
+
setSessionItem(key, value) {
|
|
151
|
+
try {
|
|
152
|
+
if (this.sessionStorageRef) {
|
|
153
|
+
this.sessionStorageRef.setItem(key, value);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error instanceof DOMException && error.name === 'QuotaExceededError') {
|
|
159
|
+
(0, utils_1.log)('error', 'sessionStorage quota exceeded - data will not persist', {
|
|
160
|
+
error,
|
|
161
|
+
data: { key, valueSize: value.length },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
// Else: Silent fallback - user already warned in constructor
|
|
165
|
+
}
|
|
166
|
+
// Always update fallback for consistency
|
|
167
|
+
this.fallbackSessionStorage.set(key, value);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Removes an item from sessionStorage
|
|
171
|
+
*/
|
|
172
|
+
removeSessionItem(key) {
|
|
173
|
+
try {
|
|
174
|
+
if (this.sessionStorageRef) {
|
|
175
|
+
this.sessionStorageRef.removeItem(key);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// Silent - not critical
|
|
180
|
+
}
|
|
181
|
+
// Always clean fallback
|
|
182
|
+
this.fallbackSessionStorage.delete(key);
|
|
183
|
+
}
|
|
130
184
|
}
|
|
131
185
|
exports.StorageManager = StorageManager;
|
|
@@ -12,5 +12,5 @@ export declare class UserManager {
|
|
|
12
12
|
* @param projectId - Project identifier for namespacing
|
|
13
13
|
* @returns Persistent unique user ID
|
|
14
14
|
*/
|
|
15
|
-
static getId(storageManager: StorageManager
|
|
15
|
+
static getId(storageManager: StorageManager): string;
|
|
16
16
|
}
|
|
@@ -16,8 +16,8 @@ class UserManager {
|
|
|
16
16
|
* @param projectId - Project identifier for namespacing
|
|
17
17
|
* @returns Persistent unique user ID
|
|
18
18
|
*/
|
|
19
|
-
static getId(storageManager
|
|
20
|
-
const storageKey =
|
|
19
|
+
static getId(storageManager) {
|
|
20
|
+
const storageKey = constants_1.USER_ID_KEY;
|
|
21
21
|
const storedUserId = storageManager.getItem(storageKey);
|
|
22
22
|
if (storedUserId) {
|
|
23
23
|
return storedUserId;
|
package/dist/cjs/public-api.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './app.constants';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './types';
|
|
3
3
|
export declare const tracelog: {
|
|
4
|
-
init: (
|
|
5
|
-
event: (name: string, metadata?: Record<string, import("./
|
|
4
|
+
init: (config: import("./types").Config) => Promise<void>;
|
|
5
|
+
event: (name: string, metadata?: Record<string, import("./types").MetadataType> | Record<string, import("./types").MetadataType>[]) => void;
|
|
6
6
|
on: <K extends keyof import("./types").EmitterMap>(event: K, callback: import("./types").EmitterCallback<import("./types").EmitterMap[K]>) => void;
|
|
7
7
|
off: <K extends keyof import("./types").EmitterMap>(event: K, callback: import("./types").EmitterCallback<import("./types").EmitterMap[K]>) => void;
|
|
8
8
|
isInitialized: () => boolean;
|
package/dist/cjs/public-api.js
CHANGED
|
@@ -19,7 +19,7 @@ const api_1 = require("./api");
|
|
|
19
19
|
// Constants
|
|
20
20
|
__exportStar(require("./app.constants"), exports);
|
|
21
21
|
// Types
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./types"), exports);
|
|
23
23
|
// TraceLog namespace containing all API methods
|
|
24
24
|
exports.tracelog = {
|
|
25
25
|
init: api_1.init,
|
|
@@ -16,6 +16,7 @@ export declare class TestBridge extends App implements TraceLogTestBridge {
|
|
|
16
16
|
private _isInitializing;
|
|
17
17
|
private _isDestroying;
|
|
18
18
|
constructor(isInitializing: boolean, isDestroying: boolean);
|
|
19
|
+
init(config: any): Promise<void>;
|
|
19
20
|
isInitializing(): boolean;
|
|
20
21
|
sendCustomEvent(name: string, data?: Record<string, unknown> | Record<string, unknown>[]): void;
|
|
21
22
|
getSessionData(): Record<string, unknown> | null;
|
package/dist/cjs/test-bridge.js
CHANGED
|
@@ -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
|
|
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 =
|
|
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,18 +1,5 @@
|
|
|
1
1
|
import { MetadataType } from './common.types';
|
|
2
|
-
|
|
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. */
|
|
@@ -25,14 +12,20 @@ export interface AppConfig {
|
|
|
25
12
|
sensitiveQueryParams?: string[];
|
|
26
13
|
/** Error event sampling rate between 0 and 1. */
|
|
27
14
|
errorSampling?: number;
|
|
28
|
-
/** Logging mode controlling verbosity of client logs. */
|
|
29
|
-
mode?: Mode;
|
|
30
15
|
/** Event sampling rate between 0 and 1. */
|
|
31
16
|
samplingRate?: number;
|
|
32
|
-
/** URL path patterns that should be ignored by tracking. */
|
|
33
|
-
excludedUrlPaths?: string[];
|
|
34
17
|
/** Optional configuration for third-party integrations. */
|
|
35
18
|
integrations?: {
|
|
19
|
+
/** TraceLog integration options. */
|
|
20
|
+
tracelog?: {
|
|
21
|
+
/** Required project ID TraceLog SaaS integration. */
|
|
22
|
+
projectId: string;
|
|
23
|
+
};
|
|
24
|
+
/** Custom integration options. */
|
|
25
|
+
custom?: {
|
|
26
|
+
/** Required API URL for custom integration. */
|
|
27
|
+
apiUrl: string;
|
|
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';
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -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);
|
|
@@ -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
|
}
|
|
@@ -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 {
|
|
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:
|
|
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.
|
|
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
|
|
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
|
-
|
|
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
|
};
|
|
@@ -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;
|