@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
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestBridge = void 0;
|
|
4
|
+
const app_1 = require("./app");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
/**
|
|
7
|
+
* Test bridge for E2E testing
|
|
8
|
+
*/
|
|
9
|
+
class TestBridge extends app_1.App {
|
|
10
|
+
constructor(isInitializing, isDestroying) {
|
|
11
|
+
super();
|
|
12
|
+
this._isDestroying = false;
|
|
13
|
+
this._isInitializing = isInitializing;
|
|
14
|
+
this._isDestroying = isDestroying;
|
|
15
|
+
}
|
|
16
|
+
isInitializing() {
|
|
17
|
+
return this._isInitializing;
|
|
18
|
+
}
|
|
19
|
+
sendCustomEvent(name, data) {
|
|
20
|
+
this.ensureInitialized();
|
|
21
|
+
super.sendCustomEvent(name, data);
|
|
22
|
+
}
|
|
23
|
+
getSessionData() {
|
|
24
|
+
return {
|
|
25
|
+
id: this.get('sessionId'),
|
|
26
|
+
isActive: !!this.get('sessionId'),
|
|
27
|
+
timeout: this.get('config')?.sessionTimeout ?? 15 * 60 * 1000,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
setSessionTimeout(timeout) {
|
|
31
|
+
const config = this.get('config');
|
|
32
|
+
if (config) {
|
|
33
|
+
const { config: normalizedConfig } = (0, utils_1.normalizeConfig)({ ...config, sessionTimeout: timeout });
|
|
34
|
+
this.set('config', normalizedConfig);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
getQueueLength() {
|
|
38
|
+
return this.managers.event?.getQueueLength() ?? 0;
|
|
39
|
+
}
|
|
40
|
+
forceInitLock(enabled = true) {
|
|
41
|
+
this._isInitializing = enabled;
|
|
42
|
+
}
|
|
43
|
+
get(key) {
|
|
44
|
+
return super.get(key);
|
|
45
|
+
}
|
|
46
|
+
// Manager accessors
|
|
47
|
+
getStorageManager() {
|
|
48
|
+
return this.safeAccess(this.managers?.storage);
|
|
49
|
+
}
|
|
50
|
+
getEventManager() {
|
|
51
|
+
return this.safeAccess(this.managers?.event);
|
|
52
|
+
}
|
|
53
|
+
// Handler accessors
|
|
54
|
+
getSessionHandler() {
|
|
55
|
+
return this.safeAccess(this.handlers?.session);
|
|
56
|
+
}
|
|
57
|
+
getPageViewHandler() {
|
|
58
|
+
return this.safeAccess(this.handlers?.pageView);
|
|
59
|
+
}
|
|
60
|
+
getClickHandler() {
|
|
61
|
+
return this.safeAccess(this.handlers?.click);
|
|
62
|
+
}
|
|
63
|
+
getScrollHandler() {
|
|
64
|
+
return this.safeAccess(this.handlers?.scroll);
|
|
65
|
+
}
|
|
66
|
+
getPerformanceHandler() {
|
|
67
|
+
return this.safeAccess(this.handlers?.performance);
|
|
68
|
+
}
|
|
69
|
+
getErrorHandler() {
|
|
70
|
+
return this.safeAccess(this.handlers?.error);
|
|
71
|
+
}
|
|
72
|
+
// Integration accessors
|
|
73
|
+
getGoogleAnalytics() {
|
|
74
|
+
return this.safeAccess(this.integrations?.googleAnalytics);
|
|
75
|
+
}
|
|
76
|
+
async destroy() {
|
|
77
|
+
this.ensureInitialized();
|
|
78
|
+
this.ensureNotDestroying();
|
|
79
|
+
this._isDestroying = true;
|
|
80
|
+
try {
|
|
81
|
+
await super.destroy();
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
this._isDestroying = false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Helper to safely access managers/handlers and convert undefined to null
|
|
89
|
+
*/
|
|
90
|
+
safeAccess(value) {
|
|
91
|
+
return value ?? null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Ensures the app is initialized, throws if not
|
|
95
|
+
*/
|
|
96
|
+
ensureInitialized() {
|
|
97
|
+
if (!this.initialized) {
|
|
98
|
+
throw new Error('App not initialized');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Ensures destroy operation is not in progress, throws if it is
|
|
103
|
+
*/
|
|
104
|
+
ensureNotDestroying() {
|
|
105
|
+
if (this._isDestroying) {
|
|
106
|
+
throw new Error('Destroy operation already in progress');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.TestBridge = TestBridge;
|
|
@@ -2,20 +2,35 @@
|
|
|
2
2
|
* Special project IDs for testing and development
|
|
3
3
|
*
|
|
4
4
|
* Both automatically force mode: 'debug' but differ in HTTP behavior:
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - Skip: NO network calls (pure offline testing)
|
|
6
|
+
* - Localhost: Makes network calls to local server (integration testing)
|
|
7
7
|
*/
|
|
8
8
|
export declare enum SpecialProjectId {
|
|
9
9
|
/**
|
|
10
|
+
* Value: 'skip'
|
|
11
|
+
*
|
|
10
12
|
* Skips ALL HTTP calls - no config fetch, no event sending
|
|
11
13
|
* Uses default local config, forces debug mode
|
|
12
14
|
* Perfect for pure offline E2E testing
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* await TraceLog.init({ id: SpecialProjectId.Skip });
|
|
18
|
+
* // or
|
|
19
|
+
* await TraceLog.init({ id: 'skip' });
|
|
13
20
|
*/
|
|
14
|
-
|
|
21
|
+
Skip = "skip",
|
|
15
22
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
23
|
+
* Value: 'localhost:' (used as prefix)
|
|
24
|
+
*
|
|
25
|
+
* Makes HTTP calls to local development server
|
|
26
|
+
* Must specify full address: 'localhost:PORT' (e.g., 'localhost:3000')
|
|
27
|
+
* Converts to http://localhost:PORT/config for requests
|
|
28
|
+
* Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
|
|
18
29
|
* Perfect for local development with running middleware
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* await TraceLog.init({ id: 'localhost:3000' });
|
|
33
|
+
* // Makes requests to: http://localhost:3000/config
|
|
19
34
|
*/
|
|
20
|
-
|
|
35
|
+
Localhost = "localhost:"
|
|
21
36
|
}
|
|
@@ -5,21 +5,36 @@ exports.SpecialProjectId = void 0;
|
|
|
5
5
|
* Special project IDs for testing and development
|
|
6
6
|
*
|
|
7
7
|
* Both automatically force mode: 'debug' but differ in HTTP behavior:
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
8
|
+
* - Skip: NO network calls (pure offline testing)
|
|
9
|
+
* - Localhost: Makes network calls to local server (integration testing)
|
|
10
10
|
*/
|
|
11
11
|
var SpecialProjectId;
|
|
12
12
|
(function (SpecialProjectId) {
|
|
13
13
|
/**
|
|
14
|
+
* Value: 'skip'
|
|
15
|
+
*
|
|
14
16
|
* Skips ALL HTTP calls - no config fetch, no event sending
|
|
15
17
|
* Uses default local config, forces debug mode
|
|
16
18
|
* Perfect for pure offline E2E testing
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* await TraceLog.init({ id: SpecialProjectId.Skip });
|
|
22
|
+
* // or
|
|
23
|
+
* await TraceLog.init({ id: 'skip' });
|
|
17
24
|
*/
|
|
18
|
-
SpecialProjectId["
|
|
25
|
+
SpecialProjectId["Skip"] = "skip";
|
|
19
26
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
27
|
+
* Value: 'localhost:' (used as prefix)
|
|
28
|
+
*
|
|
29
|
+
* Makes HTTP calls to local development server
|
|
30
|
+
* Must specify full address: 'localhost:PORT' (e.g., 'localhost:3000')
|
|
31
|
+
* Converts to http://localhost:PORT/config for requests
|
|
32
|
+
* Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
|
|
22
33
|
* Perfect for local development with running middleware
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* await TraceLog.init({ id: 'localhost:3000' });
|
|
37
|
+
* // Makes requests to: http://localhost:3000/config
|
|
23
38
|
*/
|
|
24
|
-
SpecialProjectId["
|
|
39
|
+
SpecialProjectId["Localhost"] = "localhost:";
|
|
25
40
|
})(SpecialProjectId || (exports.SpecialProjectId = SpecialProjectId = {}));
|
|
@@ -1,103 +1,41 @@
|
|
|
1
1
|
import { MetadataType } from './common.types';
|
|
2
2
|
import { TagConfig } from './tag.types';
|
|
3
3
|
import { Mode } from './mode.types';
|
|
4
|
-
export type Config =
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* - 'debug': Shows all logs including internal library errors
|
|
10
|
-
*/
|
|
11
|
-
mode?: Mode;
|
|
12
|
-
/**
|
|
13
|
-
* Sampling rate as a percentage (0-1) to control how many events are sent.
|
|
14
|
-
* A value of 1 means all events are sent, while 0.5 means only half of events are sent.
|
|
15
|
-
*/
|
|
16
|
-
samplingRate?: number;
|
|
17
|
-
/**
|
|
18
|
-
* Array of tag configurations for categorizing and filtering events.
|
|
19
|
-
* Tags help organize and segment tracking data for analysis.
|
|
20
|
-
*/
|
|
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. */
|
|
21
9
|
tags?: TagConfig[];
|
|
22
|
-
/**
|
|
23
|
-
* Array of URL path patterns to exclude from tracking.
|
|
24
|
-
* Events will not be sent for pages matching these patterns.
|
|
25
|
-
*/
|
|
26
|
-
excludedUrlPaths?: string[];
|
|
27
|
-
/**
|
|
28
|
-
* Flag to indicate if IP addresses should be excluded from tracking.
|
|
29
|
-
* When true, IP addresses will not be collected or sent with events.
|
|
30
|
-
* This is useful for privacy compliance and reducing data exposure.
|
|
31
|
-
*/
|
|
10
|
+
/** Determines if IP address is excluded from tracking. */
|
|
32
11
|
ipExcluded?: boolean;
|
|
33
12
|
}
|
|
34
13
|
export interface AppConfig {
|
|
35
|
-
/**
|
|
36
|
-
* Unique project identifier.
|
|
37
|
-
*/
|
|
14
|
+
/** Project identifier used for tracing. */
|
|
38
15
|
id: string;
|
|
39
|
-
/**
|
|
40
|
-
* Session timeout in milliseconds. After this period of inactivity,
|
|
41
|
-
* a new session will be started for subsequent events.
|
|
42
|
-
*
|
|
43
|
-
* **Timeout Guidelines:**
|
|
44
|
-
* - **15 minutes (default)**: Recommended for most applications, aligns with security best practices
|
|
45
|
-
* - **30 minutes**: Standard for content-heavy sites (matches Google Analytics default)
|
|
46
|
-
* - **45-60 minutes**: Consider for sites with long-form content, videos, or documentation
|
|
47
|
-
* - **5-10 minutes**: Use for security-sensitive applications requiring frequent re-authentication
|
|
48
|
-
*
|
|
49
|
-
* **Impact on Analytics:**
|
|
50
|
-
* - Shorter timeouts = Higher session count, higher bounce rate, potentially lower conversion rates
|
|
51
|
-
* - Longer timeouts = Lower session count, more accurate user journey tracking, better conversion attribution
|
|
52
|
-
*
|
|
53
|
-
* **When to Adjust:**
|
|
54
|
-
* - Match your application's auto-logout timeout if applicable
|
|
55
|
-
* - Increase for content where users frequently pause (tutorials, long articles, videos)
|
|
56
|
-
* - Decrease for applications with sensitive data or frequent security requirements
|
|
57
|
-
* - Monitor bounce rates and conversion funnels when changing this value
|
|
58
|
-
*
|
|
59
|
-
* @default 900000 (15 minutes)
|
|
60
|
-
* @min 30000 (30 seconds)
|
|
61
|
-
* @max 86400000 (24 hours)
|
|
62
|
-
*/
|
|
16
|
+
/** Session inactivity timeout in milliseconds. @default 900000 */
|
|
63
17
|
sessionTimeout?: number;
|
|
64
|
-
/**
|
|
65
|
-
* Metadata that will be automatically attached to all tracking events.
|
|
66
|
-
* These key-value pairs provide additional context for every event sent.
|
|
67
|
-
*/
|
|
18
|
+
/** Metadata appended to every tracked event. */
|
|
68
19
|
globalMetadata?: Record<string, MetadataType>;
|
|
69
|
-
/**
|
|
70
|
-
* CSS selectors for custom scroll containers. Can be a single selector string
|
|
71
|
-
* or an array of selectors. Used to track scroll events within specific elements
|
|
72
|
-
* instead of the default window scroll.
|
|
73
|
-
*/
|
|
20
|
+
/** Selectors defining custom scroll containers to monitor. */
|
|
74
21
|
scrollContainerSelectors?: string | string[];
|
|
75
|
-
/**
|
|
76
|
-
* Allow HTTP requests to be made. This is useful for testing and development.
|
|
77
|
-
*/
|
|
22
|
+
/** Enables HTTP requests for testing and development flows. */
|
|
78
23
|
allowHttp?: boolean;
|
|
79
|
-
/**
|
|
80
|
-
* Array of query parameters to be removed from the URL.
|
|
81
|
-
*/
|
|
24
|
+
/** Query parameters to remove before tracking URLs. */
|
|
82
25
|
sensitiveQueryParams?: string[];
|
|
83
|
-
/**
|
|
84
|
-
* Sampling rate for error events (0-1).
|
|
85
|
-
* Controls how many error and network error events are captured.
|
|
86
|
-
* @default 0.1 for production, 1.0 for qa/debug mode
|
|
87
|
-
*/
|
|
26
|
+
/** Error event sampling rate between 0 and 1. */
|
|
88
27
|
errorSampling?: number;
|
|
89
|
-
/**
|
|
90
|
-
|
|
91
|
-
|
|
28
|
+
/** Logging mode controlling verbosity of client logs. */
|
|
29
|
+
mode?: Mode;
|
|
30
|
+
/** Event sampling rate between 0 and 1. */
|
|
31
|
+
samplingRate?: number;
|
|
32
|
+
/** URL path patterns that should be ignored by tracking. */
|
|
33
|
+
excludedUrlPaths?: string[];
|
|
34
|
+
/** Optional configuration for third-party integrations. */
|
|
92
35
|
integrations?: {
|
|
93
|
-
/**
|
|
94
|
-
* Google Analytics integration configuration.
|
|
95
|
-
*/
|
|
36
|
+
/** Google Analytics integration options. */
|
|
96
37
|
googleAnalytics?: {
|
|
97
|
-
/**
|
|
98
|
-
* Google Analytics measurement ID.
|
|
99
|
-
* Required for initializing the Google Analytics integration.
|
|
100
|
-
*/
|
|
38
|
+
/** Required measurement ID for Google Analytics. */
|
|
101
39
|
measurementId: string;
|
|
102
40
|
};
|
|
103
41
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventData } from './event.types';
|
|
2
|
+
import { BaseEventsQueueDto } from './queue.types';
|
|
3
|
+
export type EmitterCallback<T = any> = (data: T) => void;
|
|
4
|
+
export declare enum EmitterEvent {
|
|
5
|
+
EVENT = "event",
|
|
6
|
+
QUEUE = "queue"
|
|
7
|
+
}
|
|
8
|
+
export interface EmitterMap {
|
|
9
|
+
[EmitterEvent.EVENT]: EventData;
|
|
10
|
+
[EmitterEvent.QUEUE]: BaseEventsQueueDto;
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmitterEvent = void 0;
|
|
4
|
+
var EmitterEvent;
|
|
5
|
+
(function (EmitterEvent) {
|
|
6
|
+
EmitterEvent["EVENT"] = "event";
|
|
7
|
+
EmitterEvent["QUEUE"] = "queue";
|
|
8
|
+
})(EmitterEvent || (exports.EmitterEvent = EmitterEvent = {}));
|
|
@@ -40,12 +40,7 @@ export interface ClickData {
|
|
|
40
40
|
ariaLabel?: string;
|
|
41
41
|
dataAttributes?: Record<string, string>;
|
|
42
42
|
}
|
|
43
|
-
export
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
relativeX: number;
|
|
47
|
-
relativeY: number;
|
|
48
|
-
}
|
|
43
|
+
export type ClickCoordinates = Pick<ClickData, 'x' | 'y' | 'relativeX' | 'relativeY'>;
|
|
49
44
|
export interface ClickTrackingElementData {
|
|
50
45
|
element: HTMLElement;
|
|
51
46
|
name: string;
|
|
@@ -62,11 +57,9 @@ export interface WebVitalsData {
|
|
|
62
57
|
export interface ErrorData {
|
|
63
58
|
type: ErrorType;
|
|
64
59
|
message: string;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
statusText?: string;
|
|
69
|
-
duration?: number;
|
|
60
|
+
filename?: string;
|
|
61
|
+
line?: number;
|
|
62
|
+
column?: number;
|
|
70
63
|
}
|
|
71
64
|
export interface UTM {
|
|
72
65
|
source?: string;
|
|
@@ -82,6 +75,10 @@ export interface PageViewData {
|
|
|
82
75
|
search?: string;
|
|
83
76
|
hash?: string;
|
|
84
77
|
}
|
|
78
|
+
export interface VitalSample {
|
|
79
|
+
type: WebVitalType;
|
|
80
|
+
value: number;
|
|
81
|
+
}
|
|
85
82
|
export interface EventData {
|
|
86
83
|
type: EventType;
|
|
87
84
|
page_url: string;
|
|
@@ -2,12 +2,14 @@ export * from './api.types';
|
|
|
2
2
|
export * from './common.types';
|
|
3
3
|
export * from './config.types';
|
|
4
4
|
export * from './device.types';
|
|
5
|
+
export * from './emitter.types';
|
|
5
6
|
export * from './event.types';
|
|
6
7
|
export * from './log.types';
|
|
7
8
|
export * from './mode.types';
|
|
8
9
|
export * from './queue.types';
|
|
10
|
+
export * from './session.types';
|
|
9
11
|
export * from './state.types';
|
|
10
12
|
export * from './tag.types';
|
|
13
|
+
export * from './test-bridge.types';
|
|
11
14
|
export * from './validation-error.types';
|
|
12
|
-
export * from './web-vitals.types';
|
|
13
15
|
export * from './window.types';
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -18,12 +18,14 @@ __exportStar(require("./api.types"), exports);
|
|
|
18
18
|
__exportStar(require("./common.types"), exports);
|
|
19
19
|
__exportStar(require("./config.types"), exports);
|
|
20
20
|
__exportStar(require("./device.types"), exports);
|
|
21
|
+
__exportStar(require("./emitter.types"), exports);
|
|
21
22
|
__exportStar(require("./event.types"), exports);
|
|
22
23
|
__exportStar(require("./log.types"), exports);
|
|
23
24
|
__exportStar(require("./mode.types"), exports);
|
|
24
25
|
__exportStar(require("./queue.types"), exports);
|
|
26
|
+
__exportStar(require("./session.types"), exports);
|
|
25
27
|
__exportStar(require("./state.types"), exports);
|
|
26
28
|
__exportStar(require("./tag.types"), exports);
|
|
29
|
+
__exportStar(require("./test-bridge.types"), exports);
|
|
27
30
|
__exportStar(require("./validation-error.types"), exports);
|
|
28
|
-
__exportStar(require("./web-vitals.types"), exports);
|
|
29
31
|
__exportStar(require("./window.types"), exports);
|
|
@@ -1,65 +1 @@
|
|
|
1
1
|
export type SessionEndReason = 'inactivity' | 'page_unload' | 'manual_stop' | 'orphaned_cleanup' | 'tab_closed';
|
|
2
|
-
export interface SessionEndConfig {
|
|
3
|
-
enablePageUnloadHandlers: boolean;
|
|
4
|
-
syncTimeoutMs: number;
|
|
5
|
-
maxRetries: number;
|
|
6
|
-
debugMode: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface SessionEndResult {
|
|
9
|
-
success: boolean;
|
|
10
|
-
reason: SessionEndReason;
|
|
11
|
-
timestamp: number;
|
|
12
|
-
eventsFlushed: number;
|
|
13
|
-
method: 'async' | 'sync';
|
|
14
|
-
}
|
|
15
|
-
export interface SessionEndStats {
|
|
16
|
-
totalSessionEnds: number;
|
|
17
|
-
successfulEnds: number;
|
|
18
|
-
failedEnds: number;
|
|
19
|
-
duplicatePrevented: number;
|
|
20
|
-
reasonCounts: Record<SessionEndReason, number>;
|
|
21
|
-
}
|
|
22
|
-
export interface CrossTabSessionConfig {
|
|
23
|
-
tabHeartbeatIntervalMs: number;
|
|
24
|
-
tabElectionTimeoutMs: number;
|
|
25
|
-
debugMode: boolean;
|
|
26
|
-
}
|
|
27
|
-
export interface TabInfo {
|
|
28
|
-
id: string;
|
|
29
|
-
lastHeartbeat: number;
|
|
30
|
-
isLeader: boolean;
|
|
31
|
-
sessionId: string;
|
|
32
|
-
startTime: number;
|
|
33
|
-
}
|
|
34
|
-
export interface CrossTabMessage {
|
|
35
|
-
type: 'heartbeat' | 'session_start' | 'session_end' | 'tab_closing' | 'election_request' | 'election_response';
|
|
36
|
-
tabId: string;
|
|
37
|
-
sessionId?: string;
|
|
38
|
-
timestamp: number;
|
|
39
|
-
data?: Record<string, unknown>;
|
|
40
|
-
}
|
|
41
|
-
export interface SessionRecoveryConfig {
|
|
42
|
-
recoveryWindowMs: number;
|
|
43
|
-
maxRecoveryAttempts: number;
|
|
44
|
-
contextPreservation: boolean;
|
|
45
|
-
}
|
|
46
|
-
export interface SessionContext {
|
|
47
|
-
sessionId: string;
|
|
48
|
-
startTime: number;
|
|
49
|
-
lastActivity: number;
|
|
50
|
-
tabCount: number;
|
|
51
|
-
recoveryAttempts: number;
|
|
52
|
-
metadata?: Record<string, unknown>;
|
|
53
|
-
}
|
|
54
|
-
export interface RecoveryAttempt {
|
|
55
|
-
sessionId: string;
|
|
56
|
-
timestamp: number;
|
|
57
|
-
attempt: number;
|
|
58
|
-
context: SessionContext;
|
|
59
|
-
}
|
|
60
|
-
export interface SessionHealth {
|
|
61
|
-
recoveryAttempts: number;
|
|
62
|
-
sessionTimeouts: number;
|
|
63
|
-
crossTabConflicts: number;
|
|
64
|
-
lastHealthCheck: number;
|
|
65
|
-
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ClickHandler } from '@/handlers/click.handler';
|
|
2
|
+
import { ErrorHandler } from '@/handlers/error.handler';
|
|
3
|
+
import { PageViewHandler } from '@/handlers/page-view.handler';
|
|
4
|
+
import { PerformanceHandler } from '@/handlers/performance.handler';
|
|
5
|
+
import { ScrollHandler } from '@/handlers/scroll.handler';
|
|
6
|
+
import { SessionHandler } from '@/handlers/session.handler';
|
|
7
|
+
import { GoogleAnalyticsIntegration } from '@/integrations/google-analytics.integration';
|
|
8
|
+
import { EventManager } from '@/managers/event.manager';
|
|
9
|
+
import { StorageManager as TraceLogStorageManager } from '@/managers/storage.manager';
|
|
10
|
+
import { AppConfig } from './config.types';
|
|
11
|
+
import { State } from './state.types';
|
|
12
|
+
/**
|
|
13
|
+
* Testing bridge interface for E2E tests
|
|
14
|
+
* Only available when NODE_ENV=dev
|
|
15
|
+
*/
|
|
16
|
+
export interface TraceLogTestBridge {
|
|
17
|
+
readonly initialized: boolean;
|
|
18
|
+
init(config: AppConfig): Promise<void>;
|
|
19
|
+
destroy(): Promise<void>;
|
|
20
|
+
isInitializing(): boolean;
|
|
21
|
+
sendCustomEvent(name: string, data?: Record<string, unknown>): void;
|
|
22
|
+
on(event: string, callback: (data: any) => void): void;
|
|
23
|
+
off(event: string, callback: (data: any) => void): void;
|
|
24
|
+
getSessionData(): Record<string, unknown> | null;
|
|
25
|
+
setSessionTimeout(timeout: number): void;
|
|
26
|
+
getQueueLength(): number;
|
|
27
|
+
forceInitLock(enabled?: boolean): void;
|
|
28
|
+
get<T extends keyof State>(key: T): State[T];
|
|
29
|
+
getStorageManager(): TraceLogStorageManager | null;
|
|
30
|
+
getEventManager(): EventManager | null;
|
|
31
|
+
getSessionHandler(): SessionHandler | null;
|
|
32
|
+
getPageViewHandler(): PageViewHandler | null;
|
|
33
|
+
getClickHandler(): ClickHandler | null;
|
|
34
|
+
getScrollHandler(): ScrollHandler | null;
|
|
35
|
+
getPerformanceHandler(): PerformanceHandler | null;
|
|
36
|
+
getErrorHandler(): ErrorHandler | null;
|
|
37
|
+
getGoogleAnalytics(): GoogleAnalyticsIntegration | null;
|
|
38
|
+
}
|
|
@@ -40,3 +40,10 @@ export declare class SamplingRateValidationError extends TraceLogValidationError
|
|
|
40
40
|
export declare class IntegrationValidationError extends TraceLogValidationError {
|
|
41
41
|
constructor(message: string, layer?: 'config' | 'app' | 'runtime');
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Thrown when initialization exceeds the maximum allowed timeout
|
|
45
|
+
*/
|
|
46
|
+
export declare class InitializationTimeoutError extends TraceLogValidationError {
|
|
47
|
+
readonly timeoutMs: number;
|
|
48
|
+
constructor(message: string, timeoutMs: number, layer?: 'config' | 'app' | 'runtime');
|
|
49
|
+
}
|
|
@@ -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.IntegrationValidationError = exports.SamplingRateValidationError = exports.SessionTimeoutValidationError = exports.AppConfigValidationError = exports.ProjectIdValidationError = exports.TraceLogValidationError = void 0;
|
|
7
|
+
exports.InitializationTimeoutError = exports.IntegrationValidationError = exports.SamplingRateValidationError = exports.SessionTimeoutValidationError = exports.AppConfigValidationError = exports.ProjectIdValidationError = exports.TraceLogValidationError = void 0;
|
|
8
8
|
/**
|
|
9
9
|
* Base class for all TraceLog validation errors
|
|
10
10
|
*/
|
|
@@ -66,3 +66,13 @@ class IntegrationValidationError extends TraceLogValidationError {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
exports.IntegrationValidationError = IntegrationValidationError;
|
|
69
|
+
/**
|
|
70
|
+
* Thrown when initialization exceeds the maximum allowed timeout
|
|
71
|
+
*/
|
|
72
|
+
class InitializationTimeoutError extends TraceLogValidationError {
|
|
73
|
+
constructor(message, timeoutMs, layer = 'runtime') {
|
|
74
|
+
super(message, 'INITIALIZATION_TIMEOUT', layer);
|
|
75
|
+
this.timeoutMs = timeoutMs;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.InitializationTimeoutError = InitializationTimeoutError;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* Testing bridge interface for E2E tests
|
|
4
|
-
* Only available when NODE_ENV=dev
|
|
5
|
-
*/
|
|
6
|
-
export interface TraceLogTestBridge extends App {
|
|
7
|
-
isInitializing(): boolean;
|
|
8
|
-
}
|
|
1
|
+
import { TraceLogTestBridge } from './test-bridge.types';
|
|
9
2
|
declare global {
|
|
10
3
|
interface Window {
|
|
11
4
|
/**
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateUUID = void 0;
|
|
4
|
-
const logging_1 = require("../logging");
|
|
5
4
|
/**
|
|
6
|
-
* Generates a RFC4122 compliant UUID v4
|
|
5
|
+
* Generates a RFC4122 compliant UUID v4 using native crypto API with fallback
|
|
7
6
|
* @returns A UUID string
|
|
8
7
|
*/
|
|
9
8
|
const generateUUID = () => {
|
|
10
|
-
|
|
9
|
+
// Use native crypto.randomUUID() if available (modern browsers)
|
|
10
|
+
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
|
11
|
+
return crypto.randomUUID();
|
|
12
|
+
}
|
|
13
|
+
// Fallback for older browsers
|
|
14
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
11
15
|
const r = (Math.random() * 16) | 0;
|
|
12
16
|
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
13
17
|
return v.toString(16);
|
|
14
18
|
});
|
|
15
|
-
logging_1.debugLog.verbose('UUIDUtils', 'Generated new UUID', { uuid });
|
|
16
|
-
return uuid;
|
|
17
19
|
};
|
|
18
20
|
exports.generateUUID = generateUUID;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EmitterCallback, EmitterMap } from '@/types';
|
|
2
|
+
export declare class Emitter {
|
|
3
|
+
private readonly listeners;
|
|
4
|
+
on<K extends keyof EmitterMap>(event: K, callback: EmitterCallback<EmitterMap[K]>): void;
|
|
5
|
+
off<K extends keyof EmitterMap>(event: K, callback: EmitterCallback<EmitterMap[K]>): void;
|
|
6
|
+
emit<K extends keyof EmitterMap>(event: K, data: EmitterMap[K]): void;
|
|
7
|
+
removeAllListeners(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Emitter = void 0;
|
|
4
|
+
class Emitter {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.listeners = new Map();
|
|
7
|
+
}
|
|
8
|
+
on(event, callback) {
|
|
9
|
+
if (!this.listeners.has(event)) {
|
|
10
|
+
this.listeners.set(event, []);
|
|
11
|
+
}
|
|
12
|
+
this.listeners.get(event).push(callback);
|
|
13
|
+
}
|
|
14
|
+
off(event, callback) {
|
|
15
|
+
const callbacks = this.listeners.get(event);
|
|
16
|
+
if (callbacks) {
|
|
17
|
+
const index = callbacks.indexOf(callback);
|
|
18
|
+
if (index > -1) {
|
|
19
|
+
callbacks.splice(index, 1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
emit(event, data) {
|
|
24
|
+
const callbacks = this.listeners.get(event);
|
|
25
|
+
if (callbacks) {
|
|
26
|
+
callbacks.forEach((callback) => callback(data));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
removeAllListeners() {
|
|
30
|
+
this.listeners.clear();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Emitter = Emitter;
|