@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.
Files changed (200) hide show
  1. package/README.md +157 -180
  2. package/dist/browser/tracelog.esm.js +1007 -1357
  3. package/dist/browser/tracelog.js +2 -2
  4. package/dist/cjs/api.d.ts +12 -2
  5. package/dist/cjs/api.js +63 -27
  6. package/dist/cjs/app.d.ts +2 -2
  7. package/dist/cjs/app.js +26 -32
  8. package/dist/cjs/constants/config.constants.d.ts +4 -2
  9. package/dist/cjs/constants/config.constants.js +6 -18
  10. package/dist/cjs/constants/index.d.ts +0 -1
  11. package/dist/cjs/constants/index.js +0 -1
  12. package/dist/cjs/constants/storage.constants.d.ts +3 -2
  13. package/dist/cjs/constants/storage.constants.js +4 -4
  14. package/dist/cjs/handlers/click.handler.js +3 -6
  15. package/dist/cjs/handlers/error.handler.js +1 -11
  16. package/dist/cjs/handlers/page-view.handler.js +0 -4
  17. package/dist/cjs/handlers/performance.handler.js +14 -29
  18. package/dist/cjs/handlers/scroll.handler.js +7 -6
  19. package/dist/cjs/handlers/session.handler.js +7 -6
  20. package/dist/cjs/integrations/google-analytics.integration.js +2 -6
  21. package/dist/cjs/listeners/activity-listener-manager.js +3 -3
  22. package/dist/cjs/listeners/input-listener-managers.js +3 -3
  23. package/dist/cjs/listeners/touch-listener-manager.js +3 -3
  24. package/dist/cjs/listeners/unload-listener-manager.js +3 -3
  25. package/dist/cjs/listeners/visibility-listener-manager.js +3 -3
  26. package/dist/cjs/managers/event.manager.d.ts +2 -1
  27. package/dist/cjs/managers/event.manager.js +60 -38
  28. package/dist/cjs/managers/sender.manager.js +29 -36
  29. package/dist/cjs/managers/session.manager.js +5 -13
  30. package/dist/cjs/managers/state.manager.d.ts +0 -3
  31. package/dist/cjs/managers/state.manager.js +1 -43
  32. package/dist/cjs/managers/storage.manager.d.ts +16 -2
  33. package/dist/cjs/managers/storage.manager.js +73 -19
  34. package/dist/cjs/managers/user.manager.d.ts +1 -1
  35. package/dist/cjs/managers/user.manager.js +2 -2
  36. package/dist/cjs/public-api.d.ts +3 -3
  37. package/dist/cjs/public-api.js +1 -1
  38. package/dist/cjs/test-bridge.d.ts +1 -0
  39. package/dist/cjs/test-bridge.js +37 -2
  40. package/dist/cjs/types/config.types.d.ts +15 -18
  41. package/dist/cjs/types/config.types.js +6 -0
  42. package/dist/cjs/types/event.types.d.ts +1 -13
  43. package/dist/cjs/types/index.d.ts +0 -2
  44. package/dist/cjs/types/index.js +0 -2
  45. package/dist/cjs/types/mode.types.d.ts +1 -2
  46. package/dist/cjs/types/mode.types.js +0 -1
  47. package/dist/cjs/types/queue.types.d.ts +0 -6
  48. package/dist/cjs/types/state.types.d.ts +2 -0
  49. package/dist/cjs/types/test-bridge.types.d.ts +2 -2
  50. package/dist/cjs/types/validation-error.types.d.ts +0 -6
  51. package/dist/cjs/types/validation-error.types.js +1 -10
  52. package/dist/cjs/utils/browser/device-detector.utils.js +2 -24
  53. package/dist/cjs/utils/browser/index.d.ts +1 -0
  54. package/dist/cjs/utils/browser/index.js +1 -0
  55. package/dist/cjs/utils/browser/qa-mode.utils.d.ts +13 -0
  56. package/dist/cjs/utils/browser/qa-mode.utils.js +43 -0
  57. package/dist/cjs/utils/browser/utm-params.utils.js +0 -15
  58. package/dist/cjs/utils/data/uuid.utils.d.ts +13 -0
  59. package/dist/cjs/utils/data/uuid.utils.js +37 -1
  60. package/dist/cjs/utils/index.d.ts +1 -1
  61. package/dist/cjs/utils/index.js +1 -1
  62. package/dist/cjs/utils/logging.utils.d.ts +6 -0
  63. package/dist/cjs/utils/logging.utils.js +25 -0
  64. package/dist/cjs/utils/network/index.d.ts +0 -1
  65. package/dist/cjs/utils/network/index.js +0 -1
  66. package/dist/cjs/utils/network/url.utils.d.ts +2 -8
  67. package/dist/cjs/utils/network/url.utils.js +46 -90
  68. package/dist/cjs/utils/security/sanitize.utils.d.ts +1 -13
  69. package/dist/cjs/utils/security/sanitize.utils.js +15 -178
  70. package/dist/cjs/utils/validations/config-validations.utils.d.ts +3 -9
  71. package/dist/cjs/utils/validations/config-validations.utils.js +48 -94
  72. package/dist/cjs/utils/validations/event-validations.utils.js +11 -5
  73. package/dist/cjs/utils/validations/index.d.ts +0 -1
  74. package/dist/cjs/utils/validations/index.js +0 -1
  75. package/dist/cjs/utils/validations/metadata-validations.utils.js +0 -1
  76. package/dist/cjs/utils/validations/type-guards.utils.d.ts +2 -2
  77. package/dist/cjs/utils/validations/type-guards.utils.js +50 -4
  78. package/dist/esm/api.d.ts +12 -2
  79. package/dist/esm/api.js +62 -27
  80. package/dist/esm/app.d.ts +2 -2
  81. package/dist/esm/app.js +28 -34
  82. package/dist/esm/constants/config.constants.d.ts +4 -2
  83. package/dist/esm/constants/config.constants.js +4 -16
  84. package/dist/esm/constants/index.d.ts +0 -1
  85. package/dist/esm/constants/index.js +0 -1
  86. package/dist/esm/constants/storage.constants.d.ts +3 -2
  87. package/dist/esm/constants/storage.constants.js +3 -2
  88. package/dist/esm/handlers/click.handler.js +3 -6
  89. package/dist/esm/handlers/error.handler.js +1 -11
  90. package/dist/esm/handlers/page-view.handler.js +0 -4
  91. package/dist/esm/handlers/performance.handler.js +14 -29
  92. package/dist/esm/handlers/scroll.handler.js +7 -6
  93. package/dist/esm/handlers/session.handler.js +7 -6
  94. package/dist/esm/integrations/google-analytics.integration.js +3 -7
  95. package/dist/esm/listeners/activity-listener-manager.js +3 -3
  96. package/dist/esm/listeners/input-listener-managers.js +3 -3
  97. package/dist/esm/listeners/touch-listener-manager.js +3 -3
  98. package/dist/esm/listeners/unload-listener-manager.js +3 -3
  99. package/dist/esm/listeners/visibility-listener-manager.js +3 -3
  100. package/dist/esm/managers/event.manager.d.ts +2 -1
  101. package/dist/esm/managers/event.manager.js +62 -40
  102. package/dist/esm/managers/sender.manager.js +31 -38
  103. package/dist/esm/managers/session.manager.js +5 -13
  104. package/dist/esm/managers/state.manager.d.ts +0 -3
  105. package/dist/esm/managers/state.manager.js +1 -43
  106. package/dist/esm/managers/storage.manager.d.ts +16 -2
  107. package/dist/esm/managers/storage.manager.js +73 -19
  108. package/dist/esm/managers/user.manager.d.ts +1 -1
  109. package/dist/esm/managers/user.manager.js +2 -2
  110. package/dist/esm/public-api.d.ts +3 -3
  111. package/dist/esm/public-api.js +1 -1
  112. package/dist/esm/test-bridge.d.ts +1 -0
  113. package/dist/esm/test-bridge.js +37 -2
  114. package/dist/esm/types/config.types.d.ts +15 -18
  115. package/dist/esm/types/config.types.js +5 -1
  116. package/dist/esm/types/event.types.d.ts +1 -13
  117. package/dist/esm/types/index.d.ts +0 -2
  118. package/dist/esm/types/index.js +0 -2
  119. package/dist/esm/types/mode.types.d.ts +1 -2
  120. package/dist/esm/types/mode.types.js +0 -1
  121. package/dist/esm/types/queue.types.d.ts +0 -6
  122. package/dist/esm/types/state.types.d.ts +2 -0
  123. package/dist/esm/types/test-bridge.types.d.ts +2 -2
  124. package/dist/esm/types/validation-error.types.d.ts +0 -6
  125. package/dist/esm/types/validation-error.types.js +0 -8
  126. package/dist/esm/utils/browser/device-detector.utils.js +2 -24
  127. package/dist/esm/utils/browser/index.d.ts +1 -0
  128. package/dist/esm/utils/browser/index.js +1 -0
  129. package/dist/esm/utils/browser/qa-mode.utils.d.ts +13 -0
  130. package/dist/esm/utils/browser/qa-mode.utils.js +39 -0
  131. package/dist/esm/utils/browser/utm-params.utils.js +0 -15
  132. package/dist/esm/utils/data/uuid.utils.d.ts +13 -0
  133. package/dist/esm/utils/data/uuid.utils.js +35 -0
  134. package/dist/esm/utils/index.d.ts +1 -1
  135. package/dist/esm/utils/index.js +1 -1
  136. package/dist/esm/utils/logging.utils.d.ts +6 -0
  137. package/dist/esm/utils/logging.utils.js +20 -0
  138. package/dist/esm/utils/network/index.d.ts +0 -1
  139. package/dist/esm/utils/network/index.js +0 -1
  140. package/dist/esm/utils/network/url.utils.d.ts +2 -8
  141. package/dist/esm/utils/network/url.utils.js +45 -88
  142. package/dist/esm/utils/security/sanitize.utils.d.ts +1 -13
  143. package/dist/esm/utils/security/sanitize.utils.js +15 -176
  144. package/dist/esm/utils/validations/config-validations.utils.d.ts +3 -9
  145. package/dist/esm/utils/validations/config-validations.utils.js +49 -94
  146. package/dist/esm/utils/validations/event-validations.utils.js +11 -5
  147. package/dist/esm/utils/validations/index.d.ts +0 -1
  148. package/dist/esm/utils/validations/index.js +0 -1
  149. package/dist/esm/utils/validations/metadata-validations.utils.js +0 -1
  150. package/dist/esm/utils/validations/type-guards.utils.d.ts +2 -2
  151. package/dist/esm/utils/validations/type-guards.utils.js +50 -4
  152. package/package.json +1 -1
  153. package/dist/cjs/app.types.d.ts +0 -2
  154. package/dist/cjs/app.types.js +0 -12
  155. package/dist/cjs/constants/api.constants.d.ts +0 -6
  156. package/dist/cjs/constants/api.constants.js +0 -14
  157. package/dist/cjs/managers/api.manager.d.ts +0 -13
  158. package/dist/cjs/managers/api.manager.js +0 -44
  159. package/dist/cjs/managers/config.builder.d.ts +0 -33
  160. package/dist/cjs/managers/config.builder.js +0 -116
  161. package/dist/cjs/managers/config.manager.d.ts +0 -56
  162. package/dist/cjs/managers/config.manager.js +0 -157
  163. package/dist/cjs/managers/tags.manager.d.ts +0 -36
  164. package/dist/cjs/managers/tags.manager.js +0 -171
  165. package/dist/cjs/types/api.types.d.ts +0 -52
  166. package/dist/cjs/types/api.types.js +0 -56
  167. package/dist/cjs/types/tag.types.d.ts +0 -43
  168. package/dist/cjs/types/tag.types.js +0 -31
  169. package/dist/cjs/utils/logging/debug-logger.utils.d.ts +0 -14
  170. package/dist/cjs/utils/logging/debug-logger.utils.js +0 -47
  171. package/dist/cjs/utils/logging/index.d.ts +0 -1
  172. package/dist/cjs/utils/logging/index.js +0 -5
  173. package/dist/cjs/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  174. package/dist/cjs/utils/network/fetch-with-timeout.utils.js +0 -25
  175. package/dist/cjs/utils/validations/url-validations.utils.d.ts +0 -15
  176. package/dist/cjs/utils/validations/url-validations.utils.js +0 -47
  177. package/dist/esm/app.types.d.ts +0 -2
  178. package/dist/esm/app.types.js +0 -1
  179. package/dist/esm/constants/api.constants.d.ts +0 -6
  180. package/dist/esm/constants/api.constants.js +0 -11
  181. package/dist/esm/managers/api.manager.d.ts +0 -13
  182. package/dist/esm/managers/api.manager.js +0 -41
  183. package/dist/esm/managers/config.builder.d.ts +0 -33
  184. package/dist/esm/managers/config.builder.js +0 -112
  185. package/dist/esm/managers/config.manager.d.ts +0 -56
  186. package/dist/esm/managers/config.manager.js +0 -153
  187. package/dist/esm/managers/tags.manager.d.ts +0 -36
  188. package/dist/esm/managers/tags.manager.js +0 -167
  189. package/dist/esm/types/api.types.d.ts +0 -52
  190. package/dist/esm/types/api.types.js +0 -53
  191. package/dist/esm/types/tag.types.d.ts +0 -43
  192. package/dist/esm/types/tag.types.js +0 -28
  193. package/dist/esm/utils/logging/debug-logger.utils.d.ts +0 -14
  194. package/dist/esm/utils/logging/debug-logger.utils.js +0 -44
  195. package/dist/esm/utils/logging/index.d.ts +0 -1
  196. package/dist/esm/utils/logging/index.js +0 -1
  197. package/dist/esm/utils/network/fetch-with-timeout.utils.d.ts +0 -4
  198. package/dist/esm/utils/network/fetch-with-timeout.utils.js +0 -22
  199. package/dist/esm/utils/validations/url-validations.utils.d.ts +0 -15
  200. 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;
@@ -1,7 +1,7 @@
1
1
  export * from './browser';
2
2
  export * from './data';
3
- export * from './logging';
4
3
  export * from './network';
5
4
  export * from './security';
6
5
  export * from './validations';
7
6
  export * from './emitter.utils';
7
+ export * from './logging.utils';
@@ -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,6 @@
1
+ export declare const formatLogMsg: (msg: string, error?: unknown) => string;
2
+ export declare const log: (type: "info" | "warn" | "error", msg: string, extra?: {
3
+ error?: unknown;
4
+ data?: Record<string, unknown>;
5
+ showToClient?: boolean;
6
+ }) => void;
@@ -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,2 +1 @@
1
1
  export * from './url.utils';
2
- export * from './fetch-with-timeout.utils';
@@ -15,4 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./url.utils"), exports);
18
- __exportStar(require("./fetch-with-timeout.utils"), exports);
@@ -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: (id: string, allowHttp?: boolean) => string;
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.isUrlPathExcluded = exports.normalizeUrl = exports.getApiUrl = void 0;
4
- const validations_1 = require("../validations");
5
- const logging_1 = require("../logging");
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 = (id, allowHttp = false) => {
12
- const url = new URL(window.location.href);
13
- const host = url.hostname;
14
- const parts = host.split('.');
15
- if (parts.length === 0) {
16
- logging_1.debugLog.clientError('URLUtils', 'Invalid hostname - no domain parts found', { hostname: host });
17
- throw new Error('Invalid URL');
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
- const cleanDomain = parts.slice(-2).join('.');
20
- const protocol = allowHttp && url.protocol === 'http:' ? 'http' : 'https';
21
- const apiUrl = `${protocol}://${id}.${cleanDomain}`;
22
- const isValid = (0, validations_1.isValidUrl)(apiUrl, allowHttp);
23
- if (!isValid) {
24
- logging_1.debugLog.clientError('URLUtils', 'Generated API URL failed validation', {
25
- apiUrl,
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 apiUrl;
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
- logging_1.debugLog.warn('URLUtils', 'URL normalization failed, returning original', {
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, ApiConfig } from '../../types';
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