@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
@@ -1,56 +0,0 @@
1
- import { AppConfig, Config } from '../types';
2
- /**
3
- * Configuration manager responsible for loading and merging application configuration.
4
- *
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.
10
- *
11
- * Supports special project IDs for development and testing:
12
- * - 'skip': Bypasses all network calls, uses defaults
13
- * - 'localhost:8080': Loads config from local development server
14
- */
15
- export declare class ConfigManager {
16
- private static readonly PRODUCTION_DOMAINS;
17
- /**
18
- * Gets complete configuration by loading API config and building final config.
19
- *
20
- * @param apiUrl - Base URL for the configuration API
21
- * @param appConfig - Client-side configuration from init()
22
- * @returns Promise<Config> - Merged configuration object
23
- */
24
- get(apiUrl: string, appConfig: AppConfig): Promise<Config>;
25
- /**
26
- * Loads configuration from API and returns sanitized API config.
27
- * Only returns values explicitly provided by the API.
28
- */
29
- private loadFromApi;
30
- /**
31
- * Builds the configuration URL based on project type and QA mode.
32
- */
33
- private buildConfigUrl;
34
- /**
35
- * Builds request headers based on project configuration.
36
- * Always includes X-TraceLog-Project header for consistent identification.
37
- */
38
- private buildHeaders;
39
- /**
40
- * Parses and validates JSON response from config API.
41
- */
42
- private parseJsonResponse;
43
- /**
44
- * Checks if QA mode is enabled via URL parameter.
45
- */
46
- private isQaModeEnabled;
47
- /**
48
- * Applies QA mode to API config if enabled via URL parameter.
49
- */
50
- private applyQaModeIfEnabled;
51
- /**
52
- * Creates default configuration for skip mode and fallback scenarios.
53
- * Only uses API defaults for fields not provided by the app config.
54
- */
55
- private createDefaultConfig;
56
- }
@@ -1,157 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigManager = void 0;
4
- const constants_1 = require("../constants");
5
- const types_1 = require("../types");
6
- const utils_1 = require("../utils");
7
- const logging_1 = require("../utils/logging");
8
- const config_builder_1 = require("./config.builder");
9
- /**
10
- * Configuration manager responsible for loading and merging application configuration.
11
- *
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.
17
- *
18
- * Supports special project IDs for development and testing:
19
- * - 'skip': Bypasses all network calls, uses defaults
20
- * - 'localhost:8080': Loads config from local development server
21
- */
22
- class ConfigManager {
23
- /**
24
- * Gets complete configuration by loading API config and building final config.
25
- *
26
- * @param apiUrl - Base URL for the configuration API
27
- * @param appConfig - Client-side configuration from init()
28
- * @returns Promise<Config> - Merged configuration object
29
- */
30
- async get(apiUrl, appConfig) {
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-')) {
37
- return this.createDefaultConfig(appConfig);
38
- }
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);
43
- logging_1.debugLog.info('ConfigManager', 'Configuration loaded', {
44
- projectId: config.id,
45
- mode: config.mode,
46
- hasTags: !!config.tags?.length,
47
- hasExclusions: !!config.excludedUrlPaths?.length,
48
- });
49
- return config;
50
- }
51
- /**
52
- * Loads configuration from API and returns sanitized API config.
53
- * Only returns values explicitly provided by the API.
54
- */
55
- async loadFromApi(apiUrl, appConfig) {
56
- try {
57
- const configUrl = this.buildConfigUrl(apiUrl, appConfig);
58
- const headers = this.buildHeaders(appConfig);
59
- const response = await (0, utils_1.fetchWithTimeout)(configUrl, {
60
- method: 'GET',
61
- headers,
62
- timeout: constants_1.REQUEST_TIMEOUT_MS,
63
- });
64
- if (!response.ok) {
65
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
66
- }
67
- const rawData = await this.parseJsonResponse(response);
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
- };
75
- }
76
- catch (error) {
77
- const errorMessage = error instanceof Error ? error.message : 'Unknown error';
78
- logging_1.debugLog.error('ConfigManager', 'Failed to load configuration', {
79
- error: errorMessage,
80
- apiUrl,
81
- projectId: appConfig.id,
82
- });
83
- throw new Error(`Configuration load failed: ${errorMessage}`);
84
- }
85
- }
86
- /**
87
- * Builds the configuration URL based on project type and QA mode.
88
- */
89
- buildConfigUrl(apiUrl, appConfig) {
90
- const isLocalhost = appConfig.id === types_1.SpecialProjectId.Localhost || appConfig.id === types_1.SpecialProjectId.Fail;
91
- if (isLocalhost) {
92
- return `http://${appConfig.id}/config`;
93
- }
94
- const baseUrl = `${apiUrl}/config`;
95
- const isQaMode = this.isQaModeEnabled();
96
- return isQaMode ? `${baseUrl}?qaMode=true` : baseUrl;
97
- }
98
- /**
99
- * Builds request headers based on project configuration.
100
- * Always includes X-TraceLog-Project header for consistent identification.
101
- */
102
- buildHeaders(appConfig) {
103
- return {
104
- 'Content-Type': 'application/json',
105
- 'X-TraceLog-Project': appConfig.id,
106
- };
107
- }
108
- /**
109
- * Parses and validates JSON response from config API.
110
- */
111
- async parseJsonResponse(response) {
112
- const contentType = response.headers.get('content-type');
113
- if (!contentType?.includes('application/json')) {
114
- throw new Error('Invalid response content-type, expected JSON');
115
- }
116
- const rawData = await response.json();
117
- if (!rawData || typeof rawData !== 'object' || Array.isArray(rawData)) {
118
- throw new Error('Invalid response format, expected object');
119
- }
120
- return rawData;
121
- }
122
- /**
123
- * Checks if QA mode is enabled via URL parameter.
124
- */
125
- isQaModeEnabled() {
126
- const params = new URLSearchParams(window.location.search);
127
- return params.get('qaMode') === 'true';
128
- }
129
- /**
130
- * Applies QA mode to API config if enabled via URL parameter.
131
- */
132
- applyQaModeIfEnabled(apiConfig) {
133
- if (this.isQaModeEnabled() && !apiConfig.mode) {
134
- logging_1.debugLog.info('ConfigManager', 'QA mode enabled via URL parameter');
135
- return { ...apiConfig, mode: types_1.Mode.QA };
136
- }
137
- return apiConfig;
138
- }
139
- /**
140
- * Creates default configuration for skip mode and fallback scenarios.
141
- * Only uses API defaults for fields not provided by the app config.
142
- */
143
- createDefaultConfig(appConfig) {
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);
154
- }
155
- }
156
- exports.ConfigManager = ConfigManager;
157
- ConfigManager.PRODUCTION_DOMAINS = [/^https:\/\/.*\.tracelog\.app$/, /^https:\/\/.*\.tracelog\.dev$/];
@@ -1,36 +0,0 @@
1
- import { DeviceType, EventData } from '../types';
2
- import { StateManager } from './state.manager';
3
- export declare class TagsManager extends StateManager {
4
- /**
5
- * Gets matching tag IDs for an event based on configured tag conditions
6
- */
7
- getEventTagsIds(event: EventData, deviceType: DeviceType): string[];
8
- /**
9
- * Evaluates all conditions for a tag using logical operators
10
- */
11
- private evaluateTagConditions;
12
- /**
13
- * Evaluates a single tag condition
14
- */
15
- private evaluateCondition;
16
- /**
17
- * Unified string matching logic for all string-based conditions
18
- */
19
- private matchStringCondition;
20
- /**
21
- * Element-specific matching logic with optimized data extraction
22
- */
23
- private matchElementCondition;
24
- /**
25
- * Exact field matching for element EQUALS operations
26
- */
27
- private matchElementFieldExact;
28
- /**
29
- * Builds searchable element data string with null safety
30
- */
31
- private buildElementDataString;
32
- /**
33
- * Safe regex testing with error handling
34
- */
35
- private testRegex;
36
- }
@@ -1,171 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TagsManager = void 0;
4
- const types_1 = require("../types");
5
- const state_manager_1 = require("./state.manager");
6
- class TagsManager extends state_manager_1.StateManager {
7
- /**
8
- * Gets matching tag IDs for an event based on configured tag conditions
9
- */
10
- getEventTagsIds(event, deviceType) {
11
- const tags = this.get('config')?.tags?.filter((tag) => tag.triggerType === event.type) ?? [];
12
- if (tags.length === 0) {
13
- return [];
14
- }
15
- const context = {
16
- event,
17
- deviceType,
18
- clickData: event.click_data,
19
- };
20
- return tags.filter((tag) => this.evaluateTagConditions(tag, context)).map((tag) => tag.id);
21
- }
22
- /**
23
- * Evaluates all conditions for a tag using logical operators
24
- */
25
- evaluateTagConditions(tag, context) {
26
- const { conditions, logicalOperator = types_1.TagLogicalOperator.OR } = tag;
27
- if (!conditions || conditions.length === 0) {
28
- return false;
29
- }
30
- const results = conditions.map((condition) => this.evaluateCondition(condition, context));
31
- return logicalOperator === types_1.TagLogicalOperator.AND ? results.every(Boolean) : results.some(Boolean);
32
- }
33
- /**
34
- * Evaluates a single tag condition
35
- */
36
- evaluateCondition(condition, context) {
37
- try {
38
- switch (condition.type) {
39
- case types_1.TagConditionType.URL_MATCHES:
40
- return this.matchStringCondition(condition, context.event.page_url);
41
- case types_1.TagConditionType.DEVICE_TYPE:
42
- return this.matchStringCondition(condition, context.deviceType);
43
- case types_1.TagConditionType.UTM_SOURCE:
44
- return this.matchStringCondition(condition, context.event.utm?.source ?? '');
45
- case types_1.TagConditionType.UTM_MEDIUM:
46
- return this.matchStringCondition(condition, context.event.utm?.medium ?? '');
47
- case types_1.TagConditionType.UTM_CAMPAIGN:
48
- return this.matchStringCondition(condition, context.event.utm?.campaign ?? '');
49
- case types_1.TagConditionType.ELEMENT_MATCHES:
50
- return context.clickData ? this.matchElementCondition(condition, context.clickData) : false;
51
- default:
52
- return false;
53
- }
54
- }
55
- catch {
56
- return false;
57
- }
58
- }
59
- /**
60
- * Unified string matching logic for all string-based conditions
61
- */
62
- matchStringCondition(condition, value) {
63
- if (!value &&
64
- condition.operator !== types_1.TagConditionOperator.EXISTS &&
65
- condition.operator !== types_1.TagConditionOperator.NOT_EXISTS) {
66
- return false;
67
- }
68
- const conditionValue = condition.value.toLowerCase();
69
- const targetValue = value.toLowerCase();
70
- switch (condition.operator) {
71
- case types_1.TagConditionOperator.EQUALS:
72
- return targetValue === conditionValue;
73
- case types_1.TagConditionOperator.CONTAINS:
74
- return targetValue.includes(conditionValue);
75
- case types_1.TagConditionOperator.STARTS_WITH:
76
- return targetValue.startsWith(conditionValue);
77
- case types_1.TagConditionOperator.ENDS_WITH:
78
- return targetValue.endsWith(conditionValue);
79
- case types_1.TagConditionOperator.REGEX:
80
- return this.testRegex(conditionValue, targetValue);
81
- case types_1.TagConditionOperator.EXISTS:
82
- return !!value;
83
- case types_1.TagConditionOperator.NOT_EXISTS:
84
- return !value;
85
- default:
86
- return false;
87
- }
88
- }
89
- /**
90
- * Element-specific matching logic with optimized data extraction
91
- */
92
- matchElementCondition(condition, clickData) {
93
- if (condition.operator === types_1.TagConditionOperator.EQUALS) {
94
- return this.matchElementFieldExact(condition, clickData);
95
- }
96
- // Build searchable element data string once
97
- const elementData = this.buildElementDataString(clickData).toLowerCase();
98
- const conditionValue = condition.value.toLowerCase();
99
- switch (condition.operator) {
100
- case types_1.TagConditionOperator.CONTAINS:
101
- return elementData.includes(conditionValue);
102
- case types_1.TagConditionOperator.STARTS_WITH:
103
- return elementData.startsWith(conditionValue);
104
- case types_1.TagConditionOperator.ENDS_WITH:
105
- return elementData.endsWith(conditionValue);
106
- case types_1.TagConditionOperator.REGEX:
107
- return this.testRegex(conditionValue, elementData);
108
- default:
109
- return false;
110
- }
111
- }
112
- /**
113
- * Exact field matching for element EQUALS operations
114
- */
115
- matchElementFieldExact(condition, clickData) {
116
- const conditionValue = condition.value.toLowerCase();
117
- const fields = [
118
- clickData.id,
119
- clickData.class,
120
- clickData.tag,
121
- clickData.text,
122
- clickData.href,
123
- clickData.title,
124
- clickData.alt,
125
- clickData.role,
126
- clickData.ariaLabel,
127
- ];
128
- // Check standard fields
129
- if (fields.some((field) => field && field.toLowerCase() === conditionValue)) {
130
- return true;
131
- }
132
- // Check data attributes
133
- if (clickData.dataAttributes) {
134
- return Object.values(clickData.dataAttributes).some((value) => value.toLowerCase() === conditionValue);
135
- }
136
- return false;
137
- }
138
- /**
139
- * Builds searchable element data string with null safety
140
- */
141
- buildElementDataString(clickData) {
142
- const parts = [
143
- clickData.id,
144
- clickData.class,
145
- clickData.tag,
146
- clickData.text,
147
- clickData.href,
148
- clickData.title,
149
- clickData.alt,
150
- clickData.role,
151
- clickData.ariaLabel,
152
- ].filter(Boolean);
153
- if (clickData.dataAttributes) {
154
- parts.push(...Object.values(clickData.dataAttributes));
155
- }
156
- return parts.join(' ');
157
- }
158
- /**
159
- * Safe regex testing with error handling
160
- */
161
- testRegex(pattern, text) {
162
- try {
163
- const regex = new RegExp(pattern, 'gi');
164
- return regex.test(text);
165
- }
166
- catch {
167
- return false;
168
- }
169
- }
170
- }
171
- exports.TagsManager = TagsManager;
@@ -1,52 +0,0 @@
1
- /**
2
- * Special project IDs for testing and development
3
- *
4
- * All automatically force mode: 'debug' but differ in HTTP behavior:
5
- * - Skip: NO network calls (pure offline testing)
6
- * - Localhost: Makes network calls to local server (integration testing)
7
- * - Fail: Makes network calls that intentionally fail (persistence testing)
8
- */
9
- export declare enum SpecialProjectId {
10
- /**
11
- * Value: 'skip'
12
- *
13
- * Skips ALL HTTP calls - no config fetch, no event sending
14
- * Uses default local config, forces debug mode
15
- * Perfect for pure offline E2E testing
16
- *
17
- * @example
18
- * await TraceLog.init({ id: SpecialProjectId.Skip });
19
- * // or
20
- * await TraceLog.init({ id: 'skip' });
21
- */
22
- Skip = "skip",
23
- /**
24
- * Value: 'localhost:8080'
25
- *
26
- * Makes HTTP calls to local development server on port 8080
27
- * Converts to http://localhost:8080/config for requests
28
- * Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
29
- * Perfect for local development with running middleware
30
- *
31
- * @example
32
- * await TraceLog.init({ id: SpecialProjectId.Localhost });
33
- * // or
34
- * await TraceLog.init({ id: 'localhost:8080' });
35
- * // Makes requests to: http://localhost:8080/config
36
- */
37
- Localhost = "localhost:8080",
38
- /**
39
- * Value: 'localhost:9999'
40
- *
41
- * Makes HTTP calls to non-existent server (port 9999)
42
- * All HTTP requests will fail naturally, triggering persistence
43
- * Forces debug mode, perfect for testing event persistence & recovery
44
- *
45
- * @example
46
- * await TraceLog.init({ id: SpecialProjectId.Fail });
47
- * // or
48
- * await TraceLog.init({ id: 'localhost:9999' });
49
- * // Makes requests to: http://localhost:9999 (will fail)
50
- */
51
- Fail = "localhost:9999"
52
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SpecialProjectId = void 0;
4
- /**
5
- * Special project IDs for testing and development
6
- *
7
- * All automatically force mode: 'debug' but differ in HTTP behavior:
8
- * - Skip: NO network calls (pure offline testing)
9
- * - Localhost: Makes network calls to local server (integration testing)
10
- * - Fail: Makes network calls that intentionally fail (persistence testing)
11
- */
12
- var SpecialProjectId;
13
- (function (SpecialProjectId) {
14
- /**
15
- * Value: 'skip'
16
- *
17
- * Skips ALL HTTP calls - no config fetch, no event sending
18
- * Uses default local config, forces debug mode
19
- * Perfect for pure offline E2E testing
20
- *
21
- * @example
22
- * await TraceLog.init({ id: SpecialProjectId.Skip });
23
- * // or
24
- * await TraceLog.init({ id: 'skip' });
25
- */
26
- SpecialProjectId["Skip"] = "skip";
27
- /**
28
- * Value: 'localhost:8080'
29
- *
30
- * Makes HTTP calls to local development server on port 8080
31
- * Converts to http://localhost:8080/config for requests
32
- * Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
33
- * Perfect for local development with running middleware
34
- *
35
- * @example
36
- * await TraceLog.init({ id: SpecialProjectId.Localhost });
37
- * // or
38
- * await TraceLog.init({ id: 'localhost:8080' });
39
- * // Makes requests to: http://localhost:8080/config
40
- */
41
- SpecialProjectId["Localhost"] = "localhost:8080";
42
- /**
43
- * Value: 'localhost:9999'
44
- *
45
- * Makes HTTP calls to non-existent server (port 9999)
46
- * All HTTP requests will fail naturally, triggering persistence
47
- * Forces debug mode, perfect for testing event persistence & recovery
48
- *
49
- * @example
50
- * await TraceLog.init({ id: SpecialProjectId.Fail });
51
- * // or
52
- * await TraceLog.init({ id: 'localhost:9999' });
53
- * // Makes requests to: http://localhost:9999 (will fail)
54
- */
55
- SpecialProjectId["Fail"] = "localhost:9999";
56
- })(SpecialProjectId || (exports.SpecialProjectId = SpecialProjectId = {}));
@@ -1,43 +0,0 @@
1
- import { EventType } from './event.types';
2
- export declare enum TagLogicalOperator {
3
- AND = "AND",
4
- OR = "OR"
5
- }
6
- export declare enum TagConditionType {
7
- URL_MATCHES = "url_matches",
8
- ELEMENT_MATCHES = "element_matches",
9
- DEVICE_TYPE = "device_type",
10
- ELEMENT_TEXT = "element_text",
11
- ELEMENT_ATTRIBUTE = "element_attribute",
12
- UTM_SOURCE = "utm_source",
13
- UTM_MEDIUM = "utm_medium",
14
- UTM_CAMPAIGN = "utm_campaign"
15
- }
16
- export declare enum TagConditionOperator {
17
- EQUALS = "equals",
18
- CONTAINS = "contains",
19
- STARTS_WITH = "starts_with",
20
- ENDS_WITH = "ends_with",
21
- REGEX = "regex",
22
- GREATER_THAN = "greater_than",
23
- LESS_THAN = "less_than",
24
- EXISTS = "exists",
25
- NOT_EXISTS = "not_exists"
26
- }
27
- export type TagConfig = Pick<Tag, 'key' | 'triggerType' | 'logicalOperator' | 'conditions'> & {
28
- id: string;
29
- };
30
- export interface Tag {
31
- key: string;
32
- name: string;
33
- description?: string;
34
- active: boolean;
35
- triggerType: EventType;
36
- logicalOperator?: TagLogicalOperator;
37
- conditions: TagCondition[];
38
- }
39
- export interface TagCondition {
40
- type: TagConditionType;
41
- operator: TagConditionOperator;
42
- value: string;
43
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TagConditionOperator = exports.TagConditionType = exports.TagLogicalOperator = void 0;
4
- var TagLogicalOperator;
5
- (function (TagLogicalOperator) {
6
- TagLogicalOperator["AND"] = "AND";
7
- TagLogicalOperator["OR"] = "OR";
8
- })(TagLogicalOperator || (exports.TagLogicalOperator = TagLogicalOperator = {}));
9
- var TagConditionType;
10
- (function (TagConditionType) {
11
- TagConditionType["URL_MATCHES"] = "url_matches";
12
- TagConditionType["ELEMENT_MATCHES"] = "element_matches";
13
- TagConditionType["DEVICE_TYPE"] = "device_type";
14
- TagConditionType["ELEMENT_TEXT"] = "element_text";
15
- TagConditionType["ELEMENT_ATTRIBUTE"] = "element_attribute";
16
- TagConditionType["UTM_SOURCE"] = "utm_source";
17
- TagConditionType["UTM_MEDIUM"] = "utm_medium";
18
- TagConditionType["UTM_CAMPAIGN"] = "utm_campaign";
19
- })(TagConditionType || (exports.TagConditionType = TagConditionType = {}));
20
- var TagConditionOperator;
21
- (function (TagConditionOperator) {
22
- TagConditionOperator["EQUALS"] = "equals";
23
- TagConditionOperator["CONTAINS"] = "contains";
24
- TagConditionOperator["STARTS_WITH"] = "starts_with";
25
- TagConditionOperator["ENDS_WITH"] = "ends_with";
26
- TagConditionOperator["REGEX"] = "regex";
27
- TagConditionOperator["GREATER_THAN"] = "greater_than";
28
- TagConditionOperator["LESS_THAN"] = "less_than";
29
- TagConditionOperator["EXISTS"] = "exists";
30
- TagConditionOperator["NOT_EXISTS"] = "not_exists";
31
- })(TagConditionOperator || (exports.TagConditionOperator = TagConditionOperator = {}));
@@ -1,14 +0,0 @@
1
- declare class DebugLogger {
2
- clientError: (ns: string, msg: string, data?: unknown) => void;
3
- clientWarn: (ns: string, msg: string, data?: unknown) => void;
4
- info: (ns: string, msg: string, data?: unknown) => void;
5
- error: (ns: string, msg: string, data?: unknown) => void;
6
- warn: (ns: string, msg: string, data?: unknown) => void;
7
- debug: (ns: string, msg: string, data?: unknown) => void;
8
- verbose: (ns: string, msg: string, data?: unknown) => void;
9
- private log;
10
- private shouldShow;
11
- private getMethod;
12
- }
13
- export declare const debugLog: DebugLogger;
14
- export {};
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debugLog = void 0;
4
- const state_manager_1 = require("../../managers/state.manager");
5
- class DebugLogger {
6
- constructor() {
7
- this.clientError = (ns, msg, data) => this.log('CLIENT_ERROR', ns, msg, data);
8
- this.clientWarn = (ns, msg, data) => this.log('CLIENT_WARN', ns, msg, data);
9
- this.info = (ns, msg, data) => this.log('INFO', ns, msg, data);
10
- this.error = (ns, msg, data) => this.log('ERROR', ns, msg, data);
11
- this.warn = (ns, msg, data) => this.log('WARN', ns, msg, data);
12
- this.debug = (ns, msg, data) => this.log('DEBUG', ns, msg, data);
13
- this.verbose = (ns, msg, data) => this.log('VERBOSE', ns, msg, data);
14
- }
15
- log(level, ns, msg, data) {
16
- const mode = (0, state_manager_1.getGlobalState)()?.config?.mode;
17
- if (!this.shouldShow(level, mode))
18
- return;
19
- const formattedMsg = `[TraceLog:${ns}] ${msg}`;
20
- const method = this.getMethod(level);
21
- if (data !== undefined) {
22
- console[method](formattedMsg, data);
23
- }
24
- else {
25
- console[method](formattedMsg);
26
- }
27
- }
28
- shouldShow(level, mode) {
29
- if (['CLIENT_ERROR', 'ERROR'].includes(level))
30
- return true;
31
- if (!mode)
32
- return level === 'CLIENT_WARN';
33
- if (mode === 'qa')
34
- return ['INFO', 'CLIENT_ERROR', 'CLIENT_WARN'].includes(level);
35
- if (mode === 'debug')
36
- return true; // Debug mode shows all logs
37
- return false;
38
- }
39
- getMethod(level) {
40
- if (['CLIENT_ERROR', 'ERROR'].includes(level))
41
- return 'error';
42
- if (['CLIENT_WARN', 'WARN'].includes(level))
43
- return 'warn';
44
- return 'log';
45
- }
46
- }
47
- exports.debugLog = new DebugLogger();
@@ -1 +0,0 @@
1
- export { debugLog } from './debug-logger.utils';
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debugLog = void 0;
4
- var debug_logger_utils_1 = require("./debug-logger.utils");
5
- Object.defineProperty(exports, "debugLog", { enumerable: true, get: function () { return debug_logger_utils_1.debugLog; } });