@tracelog/lib 0.4.0 → 0.5.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/dist/browser/tracelog.js +620 -658
- package/dist/cjs/api.d.ts +1 -53
- package/dist/cjs/api.js +0 -59
- package/dist/cjs/app.constants.d.ts +1 -1
- package/dist/cjs/app.d.ts +1 -5
- package/dist/cjs/app.js +4 -12
- package/dist/cjs/constants/api.constants.d.ts +5 -2
- package/dist/cjs/constants/api.constants.js +5 -14
- package/dist/cjs/constants/config.constants.d.ts +3 -3
- package/dist/cjs/constants/config.constants.js +3 -3
- package/dist/cjs/constants/error.constants.d.ts +7 -2
- package/dist/cjs/constants/error.constants.js +13 -2
- package/dist/cjs/handlers/click.handler.js +0 -6
- package/dist/cjs/handlers/error.handler.js +9 -0
- package/dist/cjs/handlers/scroll.handler.js +0 -5
- package/dist/cjs/handlers/session.handler.js +5 -2
- package/dist/cjs/integrations/google-analytics.integration.d.ts +1 -1
- package/dist/cjs/integrations/google-analytics.integration.js +2 -1
- package/dist/cjs/managers/api.manager.d.ts +1 -1
- package/dist/cjs/managers/api.manager.js +3 -3
- package/dist/cjs/managers/config.builder.d.ts +33 -0
- package/dist/cjs/managers/config.builder.js +116 -0
- package/dist/cjs/managers/config.manager.d.ts +13 -14
- package/dist/cjs/managers/config.manager.js +52 -58
- package/dist/cjs/managers/event.manager.d.ts +1 -46
- package/dist/cjs/managers/event.manager.js +15 -70
- package/dist/cjs/managers/sender.manager.d.ts +1 -28
- package/dist/cjs/managers/sender.manager.js +43 -73
- package/dist/cjs/managers/session.manager.d.ts +2 -49
- package/dist/cjs/managers/session.manager.js +42 -83
- package/dist/cjs/managers/state.manager.d.ts +1 -28
- package/dist/cjs/managers/state.manager.js +5 -33
- package/dist/cjs/managers/storage.manager.d.ts +6 -0
- package/dist/cjs/managers/storage.manager.js +18 -1
- package/dist/cjs/public-api.d.ts +1 -1
- package/dist/cjs/test-bridge.d.ts +3 -2
- package/dist/cjs/test-bridge.js +34 -7
- package/dist/cjs/types/api.types.d.ts +24 -8
- package/dist/cjs/types/api.types.js +24 -8
- package/dist/cjs/types/event.types.d.ts +2 -4
- package/dist/cjs/types/event.types.js +0 -1
- package/dist/cjs/types/test-bridge.types.d.ts +2 -1
- package/dist/cjs/utils/logging/debug-logger.utils.d.ts +1 -2
- package/dist/cjs/utils/logging/debug-logger.utils.js +2 -3
- package/dist/cjs/utils/validations/config-validations.utils.d.ts +1 -26
- package/dist/cjs/utils/validations/config-validations.utils.js +5 -117
- package/dist/cjs/utils/validations/event-validations.utils.d.ts +2 -2
- package/dist/cjs/utils/validations/metadata-validations.utils.d.ts +3 -3
- package/dist/cjs/utils/validations/metadata-validations.utils.js +41 -3
- package/dist/esm/api.d.ts +1 -53
- package/dist/esm/api.js +0 -59
- package/dist/esm/app.constants.d.ts +1 -1
- package/dist/esm/app.d.ts +1 -5
- package/dist/esm/app.js +5 -13
- package/dist/esm/constants/api.constants.d.ts +5 -2
- package/dist/esm/constants/api.constants.js +5 -13
- package/dist/esm/constants/config.constants.d.ts +3 -3
- package/dist/esm/constants/config.constants.js +3 -3
- package/dist/esm/constants/error.constants.d.ts +7 -2
- package/dist/esm/constants/error.constants.js +12 -1
- package/dist/esm/handlers/click.handler.js +0 -6
- package/dist/esm/handlers/error.handler.js +10 -1
- package/dist/esm/handlers/scroll.handler.js +0 -5
- package/dist/esm/handlers/session.handler.js +5 -2
- package/dist/esm/integrations/google-analytics.integration.d.ts +1 -1
- package/dist/esm/integrations/google-analytics.integration.js +2 -1
- package/dist/esm/managers/api.manager.d.ts +1 -1
- package/dist/esm/managers/api.manager.js +3 -3
- package/dist/esm/managers/config.builder.d.ts +33 -0
- package/dist/esm/managers/config.builder.js +112 -0
- package/dist/esm/managers/config.manager.d.ts +13 -14
- package/dist/esm/managers/config.manager.js +54 -60
- package/dist/esm/managers/event.manager.d.ts +1 -46
- package/dist/esm/managers/event.manager.js +15 -70
- package/dist/esm/managers/sender.manager.d.ts +1 -28
- package/dist/esm/managers/sender.manager.js +44 -74
- package/dist/esm/managers/session.manager.d.ts +2 -49
- package/dist/esm/managers/session.manager.js +42 -83
- package/dist/esm/managers/state.manager.d.ts +1 -28
- package/dist/esm/managers/state.manager.js +4 -33
- package/dist/esm/managers/storage.manager.d.ts +6 -0
- package/dist/esm/managers/storage.manager.js +18 -1
- package/dist/esm/public-api.d.ts +1 -1
- package/dist/esm/test-bridge.d.ts +3 -2
- package/dist/esm/test-bridge.js +34 -7
- package/dist/esm/types/api.types.d.ts +24 -8
- package/dist/esm/types/api.types.js +24 -8
- package/dist/esm/types/event.types.d.ts +2 -4
- package/dist/esm/types/event.types.js +0 -1
- package/dist/esm/types/test-bridge.types.d.ts +2 -1
- package/dist/esm/utils/logging/debug-logger.utils.d.ts +1 -2
- package/dist/esm/utils/logging/debug-logger.utils.js +3 -4
- package/dist/esm/utils/validations/config-validations.utils.d.ts +1 -26
- package/dist/esm/utils/validations/config-validations.utils.js +5 -114
- package/dist/esm/utils/validations/event-validations.utils.d.ts +2 -2
- package/dist/esm/utils/validations/metadata-validations.utils.d.ts +3 -3
- package/dist/esm/utils/validations/metadata-validations.utils.js +41 -3
- package/package.json +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigBuilder = void 0;
|
|
4
|
+
const config_constants_1 = require("../constants/config.constants");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const logging_1 = require("../utils/logging");
|
|
7
|
+
/**
|
|
8
|
+
* Centralized configuration builder
|
|
9
|
+
* Single source of truth for merging and building final configuration
|
|
10
|
+
*/
|
|
11
|
+
class ConfigBuilder {
|
|
12
|
+
/**
|
|
13
|
+
* Builds final configuration from app config and API config
|
|
14
|
+
* Applies clear precedence: API overrides client, with defaults as fallback
|
|
15
|
+
*/
|
|
16
|
+
static build(appConfig, apiConfig = {}) {
|
|
17
|
+
// Resolve mode first as it affects other settings (like errorSampling)
|
|
18
|
+
const finalMode = this.resolveMode(appConfig, apiConfig.mode);
|
|
19
|
+
const config = {
|
|
20
|
+
// Core identifiers
|
|
21
|
+
id: appConfig.id,
|
|
22
|
+
// Session configuration
|
|
23
|
+
sessionTimeout: this.resolveSessionTimeout(appConfig.sessionTimeout),
|
|
24
|
+
// Mode configuration (resolved first)
|
|
25
|
+
mode: finalMode,
|
|
26
|
+
// Sampling configuration (depends on mode)
|
|
27
|
+
samplingRate: this.resolveSamplingRate(apiConfig.samplingRate, appConfig.samplingRate),
|
|
28
|
+
errorSampling: this.resolveErrorSampling(appConfig.errorSampling, finalMode),
|
|
29
|
+
// Filtering configuration
|
|
30
|
+
excludedUrlPaths: apiConfig.excludedUrlPaths ?? appConfig.excludedUrlPaths ?? [],
|
|
31
|
+
tags: apiConfig.tags ?? [],
|
|
32
|
+
ipExcluded: apiConfig.ipExcluded ?? false,
|
|
33
|
+
// Client-only configuration
|
|
34
|
+
globalMetadata: appConfig.globalMetadata ?? {},
|
|
35
|
+
scrollContainerSelectors: appConfig.scrollContainerSelectors,
|
|
36
|
+
sensitiveQueryParams: appConfig.sensitiveQueryParams ?? [],
|
|
37
|
+
integrations: appConfig.integrations,
|
|
38
|
+
// Security configuration
|
|
39
|
+
allowHttp: appConfig.allowHttp ?? false,
|
|
40
|
+
};
|
|
41
|
+
logging_1.debugLog.debug('ConfigBuilder', 'Configuration built', {
|
|
42
|
+
projectId: config.id,
|
|
43
|
+
mode: config.mode,
|
|
44
|
+
samplingRate: config.samplingRate,
|
|
45
|
+
errorSampling: config.errorSampling,
|
|
46
|
+
hasTags: !!config.tags?.length,
|
|
47
|
+
hasExclusions: !!config.excludedUrlPaths?.length,
|
|
48
|
+
});
|
|
49
|
+
return config;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Resolves session timeout with validation
|
|
53
|
+
* Returns default if undefined or out of valid range
|
|
54
|
+
*/
|
|
55
|
+
static resolveSessionTimeout(timeout) {
|
|
56
|
+
if (timeout === undefined) {
|
|
57
|
+
return config_constants_1.DEFAULT_SESSION_TIMEOUT;
|
|
58
|
+
}
|
|
59
|
+
if (timeout < config_constants_1.MIN_SESSION_TIMEOUT_MS || timeout > config_constants_1.MAX_SESSION_TIMEOUT_MS) {
|
|
60
|
+
logging_1.debugLog.warn('ConfigBuilder', 'Invalid session timeout, using default', {
|
|
61
|
+
provided: timeout,
|
|
62
|
+
min: config_constants_1.MIN_SESSION_TIMEOUT_MS,
|
|
63
|
+
max: config_constants_1.MAX_SESSION_TIMEOUT_MS,
|
|
64
|
+
default: config_constants_1.DEFAULT_SESSION_TIMEOUT,
|
|
65
|
+
});
|
|
66
|
+
return config_constants_1.DEFAULT_SESSION_TIMEOUT;
|
|
67
|
+
}
|
|
68
|
+
return timeout;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolves sampling rate with validation
|
|
72
|
+
* Priority: API config > app config > default
|
|
73
|
+
*/
|
|
74
|
+
static resolveSamplingRate(apiRate, appRate) {
|
|
75
|
+
const rate = apiRate ?? appRate;
|
|
76
|
+
if (rate === undefined) {
|
|
77
|
+
return config_constants_1.DEFAULT_SAMPLING_RATE;
|
|
78
|
+
}
|
|
79
|
+
if (rate < config_constants_1.MIN_SAMPLING_RATE || rate > config_constants_1.MAX_SAMPLING_RATE) {
|
|
80
|
+
logging_1.debugLog.warn('ConfigBuilder', 'Invalid sampling rate, using default', {
|
|
81
|
+
provided: rate,
|
|
82
|
+
default: config_constants_1.DEFAULT_SAMPLING_RATE,
|
|
83
|
+
});
|
|
84
|
+
return config_constants_1.DEFAULT_SAMPLING_RATE;
|
|
85
|
+
}
|
|
86
|
+
return rate;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Resolves error sampling rate based on mode
|
|
90
|
+
* In debug/qa modes: uses provided value or defaults to full sampling (1.0)
|
|
91
|
+
* In production: uses provided value or defaults to 10% sampling (0.1)
|
|
92
|
+
*/
|
|
93
|
+
static resolveErrorSampling(appErrorSampling, apiMode) {
|
|
94
|
+
const isDebugMode = apiMode === types_1.Mode.DEBUG || apiMode === types_1.Mode.QA;
|
|
95
|
+
if (isDebugMode) {
|
|
96
|
+
// In debug mode, respect explicit value or default to full sampling
|
|
97
|
+
return appErrorSampling ?? 1;
|
|
98
|
+
}
|
|
99
|
+
return appErrorSampling ?? 0.1; // Default to 10% sampling in production
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolves mode with special project ID handling
|
|
103
|
+
* Priority: Special project ID > API mode > app mode
|
|
104
|
+
*/
|
|
105
|
+
static resolveMode(appConfig, apiMode) {
|
|
106
|
+
// Force DEBUG mode for special project IDs
|
|
107
|
+
if (appConfig.id === types_1.SpecialProjectId.Skip ||
|
|
108
|
+
appConfig.id === types_1.SpecialProjectId.Fail ||
|
|
109
|
+
appConfig.id.toLowerCase().startsWith('skip-')) {
|
|
110
|
+
return types_1.Mode.DEBUG;
|
|
111
|
+
}
|
|
112
|
+
// API mode takes precedence over app mode
|
|
113
|
+
return apiMode ?? appConfig.mode;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.ConfigBuilder = ConfigBuilder;
|
|
@@ -2,20 +2,20 @@ import { AppConfig, Config } from '../types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Configuration manager responsible for loading and merging application configuration.
|
|
4
4
|
*
|
|
5
|
-
* Handles
|
|
6
|
-
* 1.
|
|
7
|
-
* 2.
|
|
8
|
-
*
|
|
5
|
+
* Handles configuration from two sources:
|
|
6
|
+
* 1. API configuration (server-side settings)
|
|
7
|
+
* 2. App configuration (client initialization settings)
|
|
8
|
+
*
|
|
9
|
+
* Uses ConfigBuilder for centralized merge logic.
|
|
9
10
|
*
|
|
10
11
|
* Supports special project IDs for development and testing:
|
|
11
12
|
* - 'skip': Bypasses all network calls, uses defaults
|
|
12
|
-
* - 'localhost:
|
|
13
|
+
* - 'localhost:8080': Loads config from local development server
|
|
13
14
|
*/
|
|
14
15
|
export declare class ConfigManager {
|
|
15
|
-
private static readonly LOCALHOST_PATTERN;
|
|
16
16
|
private static readonly PRODUCTION_DOMAINS;
|
|
17
17
|
/**
|
|
18
|
-
* Gets complete configuration by
|
|
18
|
+
* Gets complete configuration by loading API config and building final config.
|
|
19
19
|
*
|
|
20
20
|
* @param apiUrl - Base URL for the configuration API
|
|
21
21
|
* @param appConfig - Client-side configuration from init()
|
|
@@ -23,7 +23,8 @@ export declare class ConfigManager {
|
|
|
23
23
|
*/
|
|
24
24
|
get(apiUrl: string, appConfig: AppConfig): Promise<Config>;
|
|
25
25
|
/**
|
|
26
|
-
* Loads configuration from API and
|
|
26
|
+
* Loads configuration from API and returns sanitized API config.
|
|
27
|
+
* Only returns values explicitly provided by the API.
|
|
27
28
|
*/
|
|
28
29
|
private loadFromApi;
|
|
29
30
|
/**
|
|
@@ -32,26 +33,24 @@ export declare class ConfigManager {
|
|
|
32
33
|
private buildConfigUrl;
|
|
33
34
|
/**
|
|
34
35
|
* Builds request headers based on project configuration.
|
|
36
|
+
* Always includes X-TraceLog-Project header for consistent identification.
|
|
35
37
|
*/
|
|
36
38
|
private buildHeaders;
|
|
37
39
|
/**
|
|
38
40
|
* Parses and validates JSON response from config API.
|
|
39
41
|
*/
|
|
40
42
|
private parseJsonResponse;
|
|
41
|
-
/**
|
|
42
|
-
* Validates localhost project ID format and port range.
|
|
43
|
-
*/
|
|
44
|
-
private validateLocalhostProjectId;
|
|
45
43
|
/**
|
|
46
44
|
* Checks if QA mode is enabled via URL parameter.
|
|
47
45
|
*/
|
|
48
46
|
private isQaModeEnabled;
|
|
49
47
|
/**
|
|
50
|
-
*
|
|
48
|
+
* Applies QA mode to API config if enabled via URL parameter.
|
|
51
49
|
*/
|
|
52
|
-
private
|
|
50
|
+
private applyQaModeIfEnabled;
|
|
53
51
|
/**
|
|
54
52
|
* Creates default configuration for skip mode and fallback scenarios.
|
|
53
|
+
* Only uses API defaults for fields not provided by the app config.
|
|
55
54
|
*/
|
|
56
55
|
private createDefaultConfig;
|
|
57
56
|
}
|
|
@@ -5,43 +5,52 @@ const constants_1 = require("../constants");
|
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const utils_1 = require("../utils");
|
|
7
7
|
const logging_1 = require("../utils/logging");
|
|
8
|
+
const config_builder_1 = require("./config.builder");
|
|
8
9
|
/**
|
|
9
10
|
* Configuration manager responsible for loading and merging application configuration.
|
|
10
11
|
*
|
|
11
|
-
* Handles
|
|
12
|
-
* 1.
|
|
13
|
-
* 2.
|
|
14
|
-
*
|
|
12
|
+
* Handles configuration from two sources:
|
|
13
|
+
* 1. API configuration (server-side settings)
|
|
14
|
+
* 2. App configuration (client initialization settings)
|
|
15
|
+
*
|
|
16
|
+
* Uses ConfigBuilder for centralized merge logic.
|
|
15
17
|
*
|
|
16
18
|
* Supports special project IDs for development and testing:
|
|
17
19
|
* - 'skip': Bypasses all network calls, uses defaults
|
|
18
|
-
* - 'localhost:
|
|
20
|
+
* - 'localhost:8080': Loads config from local development server
|
|
19
21
|
*/
|
|
20
22
|
class ConfigManager {
|
|
21
23
|
/**
|
|
22
|
-
* Gets complete configuration by
|
|
24
|
+
* Gets complete configuration by loading API config and building final config.
|
|
23
25
|
*
|
|
24
26
|
* @param apiUrl - Base URL for the configuration API
|
|
25
27
|
* @param appConfig - Client-side configuration from init()
|
|
26
28
|
* @returns Promise<Config> - Merged configuration object
|
|
27
29
|
*/
|
|
28
30
|
async get(apiUrl, appConfig) {
|
|
29
|
-
// Handle skip mode - no network calls
|
|
30
|
-
|
|
31
|
+
// Handle skip mode - no network calls for config
|
|
32
|
+
// Support 'skip' or any ID starting with 'skip-' (e.g., 'skip-1', 'skip-2')
|
|
33
|
+
// Also handle 'fail' mode (SpecialProjectId.Fail) - skip config but fail event sends
|
|
34
|
+
if (appConfig.id === types_1.SpecialProjectId.Skip ||
|
|
35
|
+
appConfig.id === types_1.SpecialProjectId.Fail ||
|
|
36
|
+
appConfig.id.toLowerCase().startsWith('skip-')) {
|
|
31
37
|
return this.createDefaultConfig(appConfig);
|
|
32
38
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
39
|
+
const apiConfig = await this.loadFromApi(apiUrl, appConfig);
|
|
40
|
+
// Apply QA mode from URL parameter if set
|
|
41
|
+
const finalApiConfig = this.applyQaModeIfEnabled(apiConfig);
|
|
42
|
+
const config = config_builder_1.ConfigBuilder.build(appConfig, finalApiConfig);
|
|
35
43
|
logging_1.debugLog.info('ConfigManager', 'Configuration loaded', {
|
|
36
|
-
projectId:
|
|
37
|
-
mode:
|
|
38
|
-
hasTags: !!
|
|
39
|
-
hasExclusions: !!
|
|
44
|
+
projectId: config.id,
|
|
45
|
+
mode: config.mode,
|
|
46
|
+
hasTags: !!config.tags?.length,
|
|
47
|
+
hasExclusions: !!config.excludedUrlPaths?.length,
|
|
40
48
|
});
|
|
41
|
-
return
|
|
49
|
+
return config;
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
|
-
* Loads configuration from API and
|
|
52
|
+
* Loads configuration from API and returns sanitized API config.
|
|
53
|
+
* Only returns values explicitly provided by the API.
|
|
45
54
|
*/
|
|
46
55
|
async loadFromApi(apiUrl, appConfig) {
|
|
47
56
|
try {
|
|
@@ -56,7 +65,13 @@ class ConfigManager {
|
|
|
56
65
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
57
66
|
}
|
|
58
67
|
const rawData = await this.parseJsonResponse(response);
|
|
59
|
-
|
|
68
|
+
const apiConfig = (0, utils_1.sanitizeApiConfig)(rawData);
|
|
69
|
+
// Only merge defaults for fields that are arrays (to ensure they're never undefined)
|
|
70
|
+
return {
|
|
71
|
+
...apiConfig,
|
|
72
|
+
excludedUrlPaths: apiConfig.excludedUrlPaths ?? constants_1.DEFAULT_API_CONFIG.excludedUrlPaths,
|
|
73
|
+
tags: apiConfig.tags ?? constants_1.DEFAULT_API_CONFIG.tags,
|
|
74
|
+
};
|
|
60
75
|
}
|
|
61
76
|
catch (error) {
|
|
62
77
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
@@ -72,9 +87,8 @@ class ConfigManager {
|
|
|
72
87
|
* Builds the configuration URL based on project type and QA mode.
|
|
73
88
|
*/
|
|
74
89
|
buildConfigUrl(apiUrl, appConfig) {
|
|
75
|
-
const isLocalhost = appConfig.id.
|
|
90
|
+
const isLocalhost = appConfig.id === types_1.SpecialProjectId.Localhost || appConfig.id === types_1.SpecialProjectId.Fail;
|
|
76
91
|
if (isLocalhost) {
|
|
77
|
-
this.validateLocalhostProjectId(appConfig.id);
|
|
78
92
|
return `http://${appConfig.id}/config`;
|
|
79
93
|
}
|
|
80
94
|
const baseUrl = `${apiUrl}/config`;
|
|
@@ -83,15 +97,13 @@ class ConfigManager {
|
|
|
83
97
|
}
|
|
84
98
|
/**
|
|
85
99
|
* Builds request headers based on project configuration.
|
|
100
|
+
* Always includes X-TraceLog-Project header for consistent identification.
|
|
86
101
|
*/
|
|
87
102
|
buildHeaders(appConfig) {
|
|
88
|
-
|
|
103
|
+
return {
|
|
89
104
|
'Content-Type': 'application/json',
|
|
105
|
+
'X-TraceLog-Project': appConfig.id,
|
|
90
106
|
};
|
|
91
|
-
if (appConfig.id.startsWith(types_1.SpecialProjectId.Localhost)) {
|
|
92
|
-
headers['X-TraceLog-Project'] = appConfig.id;
|
|
93
|
-
}
|
|
94
|
-
return headers;
|
|
95
107
|
}
|
|
96
108
|
/**
|
|
97
109
|
* Parses and validates JSON response from config API.
|
|
@@ -107,18 +119,6 @@ class ConfigManager {
|
|
|
107
119
|
}
|
|
108
120
|
return rawData;
|
|
109
121
|
}
|
|
110
|
-
/**
|
|
111
|
-
* Validates localhost project ID format and port range.
|
|
112
|
-
*/
|
|
113
|
-
validateLocalhostProjectId(projectId) {
|
|
114
|
-
if (!ConfigManager.LOCALHOST_PATTERN.test(projectId)) {
|
|
115
|
-
throw new Error(`Invalid localhost format. Expected 'localhost:PORT', got '${projectId}'`);
|
|
116
|
-
}
|
|
117
|
-
const port = parseInt(projectId.split(':')[1], 10);
|
|
118
|
-
if (port < 1 || port > 65535) {
|
|
119
|
-
throw new Error(`Port must be between 1 and 65535, got ${port}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
122
|
/**
|
|
123
123
|
* Checks if QA mode is enabled via URL parameter.
|
|
124
124
|
*/
|
|
@@ -127,37 +127,31 @@ class ConfigManager {
|
|
|
127
127
|
return params.get('qaMode') === 'true';
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
*
|
|
130
|
+
* Applies QA mode to API config if enabled via URL parameter.
|
|
131
131
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const apiConfig = { ...constants_1.DEFAULT_API_CONFIG, ...safeApiConfig };
|
|
135
|
-
const mergedConfig = (0, constants_1.DEFAULT_CONFIG)({ ...appConfig, ...apiConfig });
|
|
136
|
-
const { config: normalizedConfig } = (0, utils_1.normalizeConfig)(mergedConfig);
|
|
137
|
-
// Apply QA mode if enabled via URL parameter
|
|
138
|
-
if (this.isQaModeEnabled() && !normalizedConfig.mode) {
|
|
139
|
-
normalizedConfig.mode = types_1.Mode.QA;
|
|
132
|
+
applyQaModeIfEnabled(apiConfig) {
|
|
133
|
+
if (this.isQaModeEnabled() && !apiConfig.mode) {
|
|
140
134
|
logging_1.debugLog.info('ConfigManager', 'QA mode enabled via URL parameter');
|
|
135
|
+
return { ...apiConfig, mode: types_1.Mode.QA };
|
|
141
136
|
}
|
|
142
|
-
|
|
143
|
-
const errorSampling = Object.values(types_1.Mode).includes(normalizedConfig.mode)
|
|
144
|
-
? 1 // Full sampling for debug/qa modes
|
|
145
|
-
: (normalizedConfig.errorSampling ?? 0.1); // Default sampling for production
|
|
146
|
-
return { ...normalizedConfig, errorSampling };
|
|
137
|
+
return apiConfig;
|
|
147
138
|
}
|
|
148
139
|
/**
|
|
149
140
|
* Creates default configuration for skip mode and fallback scenarios.
|
|
141
|
+
* Only uses API defaults for fields not provided by the app config.
|
|
150
142
|
*/
|
|
151
143
|
createDefaultConfig(appConfig) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
144
|
+
// Only use DEFAULT_API_CONFIG for fields not provided in appConfig
|
|
145
|
+
const apiConfig = {
|
|
146
|
+
// Only use defaults if app config doesn't provide these values
|
|
147
|
+
tags: constants_1.DEFAULT_API_CONFIG.tags,
|
|
148
|
+
ipExcluded: constants_1.DEFAULT_API_CONFIG.ipExcluded,
|
|
149
|
+
...(appConfig.samplingRate === undefined && { samplingRate: constants_1.DEFAULT_API_CONFIG.samplingRate }),
|
|
150
|
+
// Don't override excludedUrlPaths if provided by app config
|
|
151
|
+
// ConfigBuilder will handle the fallback to [] if both are undefined
|
|
152
|
+
};
|
|
153
|
+
return config_builder_1.ConfigBuilder.build(appConfig, apiConfig);
|
|
159
154
|
}
|
|
160
155
|
}
|
|
161
156
|
exports.ConfigManager = ConfigManager;
|
|
162
|
-
ConfigManager.LOCALHOST_PATTERN = /^localhost:\d{1,5}$/;
|
|
163
157
|
ConfigManager.PRODUCTION_DOMAINS = [/^https:\/\/.*\.tracelog\.app$/, /^https:\/\/.*\.tracelog\.dev$/];
|
|
@@ -3,16 +3,6 @@ import { Emitter } from '../utils';
|
|
|
3
3
|
import { StateManager } from './state.manager';
|
|
4
4
|
import { StorageManager } from './storage.manager';
|
|
5
5
|
import { GoogleAnalyticsIntegration } from '../integrations/google-analytics.integration';
|
|
6
|
-
/**
|
|
7
|
-
* EventManager - Core event tracking and queue management
|
|
8
|
-
*
|
|
9
|
-
* Responsibilities:
|
|
10
|
-
* - Track user events (clicks, scrolls, page views, custom events)
|
|
11
|
-
* - Queue events and batch send them to the analytics API
|
|
12
|
-
* - Handle deduplication of similar events
|
|
13
|
-
* - Manage event sending intervals and retry logic
|
|
14
|
-
* - Integrate with Google Analytics when configured
|
|
15
|
-
*/
|
|
16
6
|
export declare class EventManager extends StateManager {
|
|
17
7
|
private readonly googleAnalytics;
|
|
18
8
|
private readonly dataSender;
|
|
@@ -22,45 +12,16 @@ export declare class EventManager extends StateManager {
|
|
|
22
12
|
private lastEventTime;
|
|
23
13
|
private sendIntervalId;
|
|
24
14
|
constructor(storeManager: StorageManager, googleAnalytics?: GoogleAnalyticsIntegration | null, emitter?: Emitter | null);
|
|
25
|
-
/**
|
|
26
|
-
* Recovers persisted events from localStorage
|
|
27
|
-
* Should be called after initialization to recover any events that failed to send
|
|
28
|
-
*/
|
|
29
15
|
recoverPersistedEvents(): Promise<void>;
|
|
30
|
-
|
|
31
|
-
* Track user events with automatic deduplication and queueing
|
|
32
|
-
*/
|
|
33
|
-
track({ type, page_url, from_page_url, scroll_data, click_data, custom_event, web_vitals, error_data, session_end_reason, session_start_recovered, }: Partial<EventData>): void;
|
|
16
|
+
track({ type, page_url, from_page_url, scroll_data, click_data, custom_event, web_vitals, error_data, session_end_reason, }: Partial<EventData>): void;
|
|
34
17
|
stop(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Flush all queued events immediately (async)
|
|
37
|
-
*/
|
|
38
18
|
flushImmediately(): Promise<boolean>;
|
|
39
|
-
/**
|
|
40
|
-
* Flush all queued events immediately (sync)
|
|
41
|
-
*/
|
|
42
19
|
flushImmediatelySync(): boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Queue management and sending intervals
|
|
45
|
-
*/
|
|
46
20
|
getQueueLength(): number;
|
|
47
21
|
private clearSendInterval;
|
|
48
|
-
/**
|
|
49
|
-
* Shared flush implementation for both sync and async modes
|
|
50
|
-
*/
|
|
51
22
|
private flushEvents;
|
|
52
|
-
/**
|
|
53
|
-
* Send queued events to the API
|
|
54
|
-
*/
|
|
55
23
|
private sendEventsQueue;
|
|
56
|
-
/**
|
|
57
|
-
* Build the payload for sending events to the API
|
|
58
|
-
* Includes basic deduplication and sorting
|
|
59
|
-
*/
|
|
60
24
|
private buildEventsPayload;
|
|
61
|
-
/**
|
|
62
|
-
* Helper methods for event processing
|
|
63
|
-
*/
|
|
64
25
|
private buildEventPayload;
|
|
65
26
|
private isEventExcluded;
|
|
66
27
|
private isDuplicateEvent;
|
|
@@ -71,12 +32,6 @@ export declare class EventManager extends StateManager {
|
|
|
71
32
|
private handleGoogleAnalyticsIntegration;
|
|
72
33
|
private shouldSample;
|
|
73
34
|
private removeProcessedEvents;
|
|
74
|
-
/**
|
|
75
|
-
* Emit event for external listeners
|
|
76
|
-
*/
|
|
77
35
|
private emitEvent;
|
|
78
|
-
/**
|
|
79
|
-
* Emit events queue for external listeners
|
|
80
|
-
*/
|
|
81
36
|
private emitEventsQueue;
|
|
82
37
|
}
|