@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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.detectQaMode = void 0;
|
|
4
|
+
const constants_1 = require("@/constants");
|
|
5
|
+
const logging_utils_1 = require("../logging.utils");
|
|
6
|
+
const QA_MODE_PARAM = 'tlog_mode';
|
|
7
|
+
const QA_MODE_VALUE = 'qa';
|
|
8
|
+
/**
|
|
9
|
+
* Detects if QA mode should be active based on URL query parameter or sessionStorage
|
|
10
|
+
*
|
|
11
|
+
* Detection flow:
|
|
12
|
+
* 1. Check if already active in sessionStorage
|
|
13
|
+
* 2. Check for ?tlog_mode=qa query parameter
|
|
14
|
+
* 3. If found in URL:
|
|
15
|
+
* - Persist to sessionStorage
|
|
16
|
+
* - Clean param from URL
|
|
17
|
+
*
|
|
18
|
+
* @returns True if QA mode is active, false otherwise
|
|
19
|
+
*/
|
|
20
|
+
const detectQaMode = () => {
|
|
21
|
+
const stored = sessionStorage.getItem(constants_1.QA_MODE_KEY);
|
|
22
|
+
if (stored === 'true') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const params = new URLSearchParams(window.location.search);
|
|
26
|
+
const modeParam = params.get(QA_MODE_PARAM);
|
|
27
|
+
const isQaMode = modeParam === QA_MODE_VALUE;
|
|
28
|
+
if (isQaMode) {
|
|
29
|
+
sessionStorage.setItem(constants_1.QA_MODE_KEY, 'true');
|
|
30
|
+
params.delete(QA_MODE_PARAM);
|
|
31
|
+
const newSearch = params.toString();
|
|
32
|
+
const newUrl = `${window.location.pathname}${newSearch ? '?' + newSearch : ''}${window.location.hash}`;
|
|
33
|
+
try {
|
|
34
|
+
window.history.replaceState({}, '', newUrl);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
(0, logging_utils_1.log)('warn', 'History API not available, cannot replace URL', { error });
|
|
38
|
+
}
|
|
39
|
+
console.log('%c[TraceLog] QA Mode ACTIVE', 'background: #ff9800; color: white; font-weight: bold; padding: 2px 8px; border-radius: 3px;');
|
|
40
|
+
}
|
|
41
|
+
return isQaMode;
|
|
42
|
+
};
|
|
43
|
+
exports.detectQaMode = detectQaMode;
|
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getUTMParameters = void 0;
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
|
-
const logging_1 = require("../logging");
|
|
6
5
|
/**
|
|
7
6
|
* Extracts UTM parameters from the current URL
|
|
8
7
|
* @returns UTM parameters object or undefined if none found
|
|
9
8
|
*/
|
|
10
9
|
const getUTMParameters = () => {
|
|
11
|
-
logging_1.debugLog.debug('UTMParams', 'Extracting UTM parameters from URL', {
|
|
12
|
-
url: window.location.href,
|
|
13
|
-
search: window.location.search,
|
|
14
|
-
});
|
|
15
10
|
const urlParams = new URLSearchParams(window.location.search);
|
|
16
11
|
const utmParams = {};
|
|
17
12
|
constants_1.UTM_PARAMS.forEach((param) => {
|
|
@@ -19,19 +14,9 @@ const getUTMParameters = () => {
|
|
|
19
14
|
if (value) {
|
|
20
15
|
const key = param.split('utm_')[1];
|
|
21
16
|
utmParams[key] = value;
|
|
22
|
-
logging_1.debugLog.debug('UTMParams', 'Found UTM parameter', { param, key, value });
|
|
23
17
|
}
|
|
24
18
|
});
|
|
25
19
|
const result = Object.keys(utmParams).length ? utmParams : undefined;
|
|
26
|
-
if (result) {
|
|
27
|
-
logging_1.debugLog.debug('UTMParams', 'UTM parameters extracted successfully', {
|
|
28
|
-
parameterCount: Object.keys(result).length,
|
|
29
|
-
parameters: Object.keys(result),
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
logging_1.debugLog.debug('UTMParams', 'No UTM parameters found in URL');
|
|
34
|
-
}
|
|
35
20
|
return result;
|
|
36
21
|
};
|
|
37
22
|
exports.getUTMParameters = getUTMParameters;
|
|
@@ -3,3 +3,16 @@
|
|
|
3
3
|
* @returns A UUID string
|
|
4
4
|
*/
|
|
5
5
|
export declare const generateUUID: () => string;
|
|
6
|
+
/**
|
|
7
|
+
* Generates a unique event ID optimized for high-frequency event tracking
|
|
8
|
+
*
|
|
9
|
+
* Uses a simple hybrid approach:
|
|
10
|
+
* - Timestamp for temporal ordering
|
|
11
|
+
* - Random component for uniqueness across tabs/processes
|
|
12
|
+
*
|
|
13
|
+
* Format: {timestamp}-{random}
|
|
14
|
+
* Example: "1704067200000-a3f9c2b1"
|
|
15
|
+
*
|
|
16
|
+
* @returns Unique event ID string
|
|
17
|
+
*/
|
|
18
|
+
export declare const generateEventId: () => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateUUID = void 0;
|
|
3
|
+
exports.generateEventId = exports.generateUUID = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Generates a RFC4122 compliant UUID v4 using native crypto API with fallback
|
|
6
6
|
* @returns A UUID string
|
|
@@ -18,3 +18,39 @@ const generateUUID = () => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
exports.generateUUID = generateUUID;
|
|
21
|
+
/**
|
|
22
|
+
* Generates a unique event ID optimized for high-frequency event tracking
|
|
23
|
+
*
|
|
24
|
+
* Uses a simple hybrid approach:
|
|
25
|
+
* - Timestamp for temporal ordering
|
|
26
|
+
* - Random component for uniqueness across tabs/processes
|
|
27
|
+
*
|
|
28
|
+
* Format: {timestamp}-{random}
|
|
29
|
+
* Example: "1704067200000-a3f9c2b1"
|
|
30
|
+
*
|
|
31
|
+
* @returns Unique event ID string
|
|
32
|
+
*/
|
|
33
|
+
const generateEventId = () => {
|
|
34
|
+
const timestamp = Date.now();
|
|
35
|
+
// Generate 8 random hex chars (32 bits entropy)
|
|
36
|
+
let random = '';
|
|
37
|
+
try {
|
|
38
|
+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
39
|
+
const bytes = crypto.getRandomValues(new Uint8Array(4));
|
|
40
|
+
if (bytes) {
|
|
41
|
+
random = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// crypto failed, use fallback
|
|
47
|
+
}
|
|
48
|
+
// Fallback to Math.random if crypto unavailable
|
|
49
|
+
if (!random) {
|
|
50
|
+
random = Math.floor(Math.random() * 0xffffffff)
|
|
51
|
+
.toString(16)
|
|
52
|
+
.padStart(8, '0');
|
|
53
|
+
}
|
|
54
|
+
return `${timestamp}-${random}`;
|
|
55
|
+
};
|
|
56
|
+
exports.generateEventId = generateEventId;
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./browser"), exports);
|
|
18
18
|
__exportStar(require("./data"), exports);
|
|
19
|
-
__exportStar(require("./logging"), exports);
|
|
20
19
|
__exportStar(require("./network"), exports);
|
|
21
20
|
__exportStar(require("./security"), exports);
|
|
22
21
|
__exportStar(require("./validations"), exports);
|
|
23
22
|
__exportStar(require("./emitter.utils"), exports);
|
|
23
|
+
__exportStar(require("./logging.utils"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.log = exports.formatLogMsg = void 0;
|
|
4
|
+
const formatLogMsg = (msg, error) => {
|
|
5
|
+
if (error) {
|
|
6
|
+
return `[TraceLog] ${msg}: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
|
7
|
+
}
|
|
8
|
+
return `[TraceLog] ${msg}`;
|
|
9
|
+
};
|
|
10
|
+
exports.formatLogMsg = formatLogMsg;
|
|
11
|
+
const log = (type, msg, extra) => {
|
|
12
|
+
const { error, data, showToClient } = extra ?? {};
|
|
13
|
+
const formattedMsg = error ? (0, exports.formatLogMsg)(msg, error) : `[TraceLog] ${msg}`;
|
|
14
|
+
const method = type === 'error' ? 'error' : type === 'warn' ? 'warn' : 'log';
|
|
15
|
+
if (process.env.NODE_ENV !== 'dev' && !showToClient) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (data !== undefined) {
|
|
19
|
+
console[method](formattedMsg, data);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console[method](formattedMsg);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.log = log;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Config } from '@/types';
|
|
1
2
|
/**
|
|
2
3
|
* Generates an API URL based on project ID and current domain
|
|
3
4
|
* @param id - The project ID
|
|
4
5
|
* @returns The generated API URL
|
|
5
6
|
*/
|
|
6
|
-
export declare const getApiUrl: (
|
|
7
|
+
export declare const getApiUrl: (config: Config) => string;
|
|
7
8
|
/**
|
|
8
9
|
* Normalizes a URL by removing sensitive query parameters
|
|
9
10
|
* @param url - The URL to normalize
|
|
@@ -11,10 +12,3 @@ export declare const getApiUrl: (id: string, allowHttp?: boolean) => string;
|
|
|
11
12
|
* @returns The normalized URL
|
|
12
13
|
*/
|
|
13
14
|
export declare const normalizeUrl: (url: string, sensitiveQueryParams?: string[]) => string;
|
|
14
|
-
/**
|
|
15
|
-
* Checks if a URL path should be excluded from tracking
|
|
16
|
-
* @param url - The URL to check
|
|
17
|
-
* @param excludedPaths - Array of patterns to match against
|
|
18
|
-
* @returns True if the URL should be excluded
|
|
19
|
-
*/
|
|
20
|
-
export declare const isUrlPathExcluded: (url: string, excludedPaths?: string[]) => boolean;
|
|
@@ -1,33 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
3
|
+
exports.normalizeUrl = exports.getApiUrl = void 0;
|
|
4
|
+
const logging_utils_1 = require("../logging.utils");
|
|
5
|
+
/**
|
|
6
|
+
* Validates if a URL is valid and optionally allows HTTP URLs
|
|
7
|
+
* @param url - The URL to validate
|
|
8
|
+
* @param allowHttp - Whether to allow HTTP URLs (default: false)
|
|
9
|
+
* @returns True if the URL is valid, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
const isValidUrl = (url, allowHttp = false) => {
|
|
12
|
+
try {
|
|
13
|
+
const parsed = new URL(url);
|
|
14
|
+
const isHttps = parsed.protocol === 'https:';
|
|
15
|
+
const isHttp = parsed.protocol === 'http:';
|
|
16
|
+
return isHttps || (allowHttp && isHttp);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
6
22
|
/**
|
|
7
23
|
* Generates an API URL based on project ID and current domain
|
|
8
24
|
* @param id - The project ID
|
|
9
25
|
* @returns The generated API URL
|
|
10
26
|
*/
|
|
11
|
-
const getApiUrl = (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
const getApiUrl = (config) => {
|
|
28
|
+
const allowHttp = config.allowHttp ?? false;
|
|
29
|
+
if (config.integrations?.tracelog?.projectId) {
|
|
30
|
+
const url = new URL(window.location.href);
|
|
31
|
+
const host = url.hostname;
|
|
32
|
+
const parts = host.split('.');
|
|
33
|
+
if (parts.length === 0) {
|
|
34
|
+
throw new Error('Invalid URL');
|
|
35
|
+
}
|
|
36
|
+
const projectId = config.integrations.tracelog.projectId;
|
|
37
|
+
const cleanDomain = parts.slice(-2).join('.');
|
|
38
|
+
const protocol = allowHttp && url.protocol === 'http:' ? 'http' : 'https';
|
|
39
|
+
const apiUrl = `${protocol}://${projectId}.${cleanDomain}`;
|
|
40
|
+
const isValid = isValidUrl(apiUrl, allowHttp);
|
|
41
|
+
if (!isValid) {
|
|
42
|
+
throw new Error('Invalid URL');
|
|
43
|
+
}
|
|
44
|
+
return apiUrl;
|
|
18
45
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
allowHttp,
|
|
27
|
-
});
|
|
28
|
-
throw new Error('Invalid URL');
|
|
46
|
+
if (config.integrations?.custom?.apiUrl) {
|
|
47
|
+
const apiUrl = config.integrations.custom.apiUrl;
|
|
48
|
+
const isValid = isValidUrl(apiUrl, allowHttp);
|
|
49
|
+
if (!isValid) {
|
|
50
|
+
throw new Error('Invalid URL');
|
|
51
|
+
}
|
|
52
|
+
return apiUrl;
|
|
29
53
|
}
|
|
30
|
-
return
|
|
54
|
+
return '';
|
|
31
55
|
};
|
|
32
56
|
exports.getApiUrl = getApiUrl;
|
|
33
57
|
/**
|
|
@@ -40,7 +64,6 @@ const normalizeUrl = (url, sensitiveQueryParams = []) => {
|
|
|
40
64
|
try {
|
|
41
65
|
const urlObject = new URL(url);
|
|
42
66
|
const searchParams = urlObject.searchParams;
|
|
43
|
-
const originalParamCount = Array.from(searchParams.keys()).length;
|
|
44
67
|
let hasChanged = false;
|
|
45
68
|
const removedParams = [];
|
|
46
69
|
sensitiveQueryParams.forEach((param) => {
|
|
@@ -50,13 +73,6 @@ const normalizeUrl = (url, sensitiveQueryParams = []) => {
|
|
|
50
73
|
removedParams.push(param);
|
|
51
74
|
}
|
|
52
75
|
});
|
|
53
|
-
if (hasChanged) {
|
|
54
|
-
logging_1.debugLog.debug('URLUtils', 'Sensitive parameters removed from URL', {
|
|
55
|
-
removedParams,
|
|
56
|
-
originalParamCount,
|
|
57
|
-
finalParamCount: Array.from(searchParams.keys()).length,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
76
|
if (!hasChanged && url.includes('?')) {
|
|
61
77
|
return url;
|
|
62
78
|
}
|
|
@@ -65,68 +81,8 @@ const normalizeUrl = (url, sensitiveQueryParams = []) => {
|
|
|
65
81
|
return result;
|
|
66
82
|
}
|
|
67
83
|
catch (error) {
|
|
68
|
-
|
|
69
|
-
url: url.slice(0, 100),
|
|
70
|
-
error: error instanceof Error ? error.message : error,
|
|
71
|
-
});
|
|
84
|
+
(0, logging_utils_1.log)('warn', 'URL normalization failed, returning original', { error, data: { url: url.slice(0, 100) } });
|
|
72
85
|
return url;
|
|
73
86
|
}
|
|
74
87
|
};
|
|
75
88
|
exports.normalizeUrl = normalizeUrl;
|
|
76
|
-
/**
|
|
77
|
-
* Checks if a URL path should be excluded from tracking
|
|
78
|
-
* @param url - The URL to check
|
|
79
|
-
* @param excludedPaths - Array of patterns to match against
|
|
80
|
-
* @returns True if the URL should be excluded
|
|
81
|
-
*/
|
|
82
|
-
const isUrlPathExcluded = (url, excludedPaths = []) => {
|
|
83
|
-
if (excludedPaths.length === 0) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
let path;
|
|
87
|
-
try {
|
|
88
|
-
const parsedUrl = new URL(url, window.location.origin);
|
|
89
|
-
path = parsedUrl.pathname + (parsedUrl.hash ?? '');
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
logging_1.debugLog.warn('URLUtils', 'Failed to parse URL for path exclusion check', {
|
|
93
|
-
url: url.slice(0, 100),
|
|
94
|
-
error: error instanceof Error ? error.message : error,
|
|
95
|
-
});
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
const isRegularExpression = (value) => typeof value === 'object' && value !== undefined && typeof value.test === 'function';
|
|
99
|
-
const escapeRegexString = (string_) => string_.replaceAll(/[$()*+.?[\\\]^{|}]/g, '\\$&');
|
|
100
|
-
const wildcardToRegex = (string_) => new RegExp('^' +
|
|
101
|
-
string_
|
|
102
|
-
.split('*')
|
|
103
|
-
.map((element) => escapeRegexString(element))
|
|
104
|
-
.join('.+') +
|
|
105
|
-
'$');
|
|
106
|
-
const matchedPattern = excludedPaths.find((pattern) => {
|
|
107
|
-
try {
|
|
108
|
-
if (isRegularExpression(pattern)) {
|
|
109
|
-
const matches = pattern.test(path);
|
|
110
|
-
return matches;
|
|
111
|
-
}
|
|
112
|
-
if (pattern.includes('*')) {
|
|
113
|
-
const regex = wildcardToRegex(pattern);
|
|
114
|
-
const matches = regex.test(path);
|
|
115
|
-
return matches;
|
|
116
|
-
}
|
|
117
|
-
const matches = pattern === path;
|
|
118
|
-
return matches;
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
logging_1.debugLog.warn('URLUtils', 'Error testing exclusion pattern', {
|
|
122
|
-
pattern,
|
|
123
|
-
path,
|
|
124
|
-
error: error instanceof Error ? error.message : error,
|
|
125
|
-
});
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
const isExcluded = !!matchedPattern;
|
|
130
|
-
return isExcluded;
|
|
131
|
-
};
|
|
132
|
-
exports.isUrlPathExcluded = isUrlPathExcluded;
|
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
import { MetadataType
|
|
1
|
+
import { MetadataType } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* Sanitizes a string value to prevent XSS attacks
|
|
4
4
|
* @param value - The string to sanitize
|
|
5
5
|
* @returns The sanitized string
|
|
6
6
|
*/
|
|
7
7
|
export declare const sanitizeString: (value: string) => string;
|
|
8
|
-
/**
|
|
9
|
-
* Sanitizes a path string for route exclusion checks
|
|
10
|
-
* @param value - The path string to sanitize
|
|
11
|
-
* @returns The sanitized path string
|
|
12
|
-
*/
|
|
13
|
-
export declare const sanitizePathString: (value: string) => string;
|
|
14
|
-
/**
|
|
15
|
-
* Sanitizes API configuration data with strict validation
|
|
16
|
-
* @param data - The API config data to sanitize
|
|
17
|
-
* @returns The sanitized API config
|
|
18
|
-
*/
|
|
19
|
-
export declare const sanitizeApiConfig: (data: unknown) => ApiConfig;
|
|
20
8
|
/**
|
|
21
9
|
* Sanitizes user metadata for custom events
|
|
22
10
|
* @param metadata - The metadata to sanitize
|