@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
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { TagConditionOperator, TagConditionType, TagLogicalOperator, } from '../types';
|
|
2
|
-
import { StateManager } from './state.manager';
|
|
3
|
-
export class TagsManager extends StateManager {
|
|
4
|
-
/**
|
|
5
|
-
* Gets matching tag IDs for an event based on configured tag conditions
|
|
6
|
-
*/
|
|
7
|
-
getEventTagsIds(event, deviceType) {
|
|
8
|
-
const tags = this.get('config')?.tags?.filter((tag) => tag.triggerType === event.type) ?? [];
|
|
9
|
-
if (tags.length === 0) {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
const context = {
|
|
13
|
-
event,
|
|
14
|
-
deviceType,
|
|
15
|
-
clickData: event.click_data,
|
|
16
|
-
};
|
|
17
|
-
return tags.filter((tag) => this.evaluateTagConditions(tag, context)).map((tag) => tag.id);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Evaluates all conditions for a tag using logical operators
|
|
21
|
-
*/
|
|
22
|
-
evaluateTagConditions(tag, context) {
|
|
23
|
-
const { conditions, logicalOperator = TagLogicalOperator.OR } = tag;
|
|
24
|
-
if (!conditions || conditions.length === 0) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
const results = conditions.map((condition) => this.evaluateCondition(condition, context));
|
|
28
|
-
return logicalOperator === TagLogicalOperator.AND ? results.every(Boolean) : results.some(Boolean);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Evaluates a single tag condition
|
|
32
|
-
*/
|
|
33
|
-
evaluateCondition(condition, context) {
|
|
34
|
-
try {
|
|
35
|
-
switch (condition.type) {
|
|
36
|
-
case TagConditionType.URL_MATCHES:
|
|
37
|
-
return this.matchStringCondition(condition, context.event.page_url);
|
|
38
|
-
case TagConditionType.DEVICE_TYPE:
|
|
39
|
-
return this.matchStringCondition(condition, context.deviceType);
|
|
40
|
-
case TagConditionType.UTM_SOURCE:
|
|
41
|
-
return this.matchStringCondition(condition, context.event.utm?.source ?? '');
|
|
42
|
-
case TagConditionType.UTM_MEDIUM:
|
|
43
|
-
return this.matchStringCondition(condition, context.event.utm?.medium ?? '');
|
|
44
|
-
case TagConditionType.UTM_CAMPAIGN:
|
|
45
|
-
return this.matchStringCondition(condition, context.event.utm?.campaign ?? '');
|
|
46
|
-
case TagConditionType.ELEMENT_MATCHES:
|
|
47
|
-
return context.clickData ? this.matchElementCondition(condition, context.clickData) : false;
|
|
48
|
-
default:
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Unified string matching logic for all string-based conditions
|
|
58
|
-
*/
|
|
59
|
-
matchStringCondition(condition, value) {
|
|
60
|
-
if (!value &&
|
|
61
|
-
condition.operator !== TagConditionOperator.EXISTS &&
|
|
62
|
-
condition.operator !== TagConditionOperator.NOT_EXISTS) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
const conditionValue = condition.value.toLowerCase();
|
|
66
|
-
const targetValue = value.toLowerCase();
|
|
67
|
-
switch (condition.operator) {
|
|
68
|
-
case TagConditionOperator.EQUALS:
|
|
69
|
-
return targetValue === conditionValue;
|
|
70
|
-
case TagConditionOperator.CONTAINS:
|
|
71
|
-
return targetValue.includes(conditionValue);
|
|
72
|
-
case TagConditionOperator.STARTS_WITH:
|
|
73
|
-
return targetValue.startsWith(conditionValue);
|
|
74
|
-
case TagConditionOperator.ENDS_WITH:
|
|
75
|
-
return targetValue.endsWith(conditionValue);
|
|
76
|
-
case TagConditionOperator.REGEX:
|
|
77
|
-
return this.testRegex(conditionValue, targetValue);
|
|
78
|
-
case TagConditionOperator.EXISTS:
|
|
79
|
-
return !!value;
|
|
80
|
-
case TagConditionOperator.NOT_EXISTS:
|
|
81
|
-
return !value;
|
|
82
|
-
default:
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Element-specific matching logic with optimized data extraction
|
|
88
|
-
*/
|
|
89
|
-
matchElementCondition(condition, clickData) {
|
|
90
|
-
if (condition.operator === TagConditionOperator.EQUALS) {
|
|
91
|
-
return this.matchElementFieldExact(condition, clickData);
|
|
92
|
-
}
|
|
93
|
-
// Build searchable element data string once
|
|
94
|
-
const elementData = this.buildElementDataString(clickData).toLowerCase();
|
|
95
|
-
const conditionValue = condition.value.toLowerCase();
|
|
96
|
-
switch (condition.operator) {
|
|
97
|
-
case TagConditionOperator.CONTAINS:
|
|
98
|
-
return elementData.includes(conditionValue);
|
|
99
|
-
case TagConditionOperator.STARTS_WITH:
|
|
100
|
-
return elementData.startsWith(conditionValue);
|
|
101
|
-
case TagConditionOperator.ENDS_WITH:
|
|
102
|
-
return elementData.endsWith(conditionValue);
|
|
103
|
-
case TagConditionOperator.REGEX:
|
|
104
|
-
return this.testRegex(conditionValue, elementData);
|
|
105
|
-
default:
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Exact field matching for element EQUALS operations
|
|
111
|
-
*/
|
|
112
|
-
matchElementFieldExact(condition, clickData) {
|
|
113
|
-
const conditionValue = condition.value.toLowerCase();
|
|
114
|
-
const fields = [
|
|
115
|
-
clickData.id,
|
|
116
|
-
clickData.class,
|
|
117
|
-
clickData.tag,
|
|
118
|
-
clickData.text,
|
|
119
|
-
clickData.href,
|
|
120
|
-
clickData.title,
|
|
121
|
-
clickData.alt,
|
|
122
|
-
clickData.role,
|
|
123
|
-
clickData.ariaLabel,
|
|
124
|
-
];
|
|
125
|
-
// Check standard fields
|
|
126
|
-
if (fields.some((field) => field && field.toLowerCase() === conditionValue)) {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
// Check data attributes
|
|
130
|
-
if (clickData.dataAttributes) {
|
|
131
|
-
return Object.values(clickData.dataAttributes).some((value) => value.toLowerCase() === conditionValue);
|
|
132
|
-
}
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Builds searchable element data string with null safety
|
|
137
|
-
*/
|
|
138
|
-
buildElementDataString(clickData) {
|
|
139
|
-
const parts = [
|
|
140
|
-
clickData.id,
|
|
141
|
-
clickData.class,
|
|
142
|
-
clickData.tag,
|
|
143
|
-
clickData.text,
|
|
144
|
-
clickData.href,
|
|
145
|
-
clickData.title,
|
|
146
|
-
clickData.alt,
|
|
147
|
-
clickData.role,
|
|
148
|
-
clickData.ariaLabel,
|
|
149
|
-
].filter(Boolean);
|
|
150
|
-
if (clickData.dataAttributes) {
|
|
151
|
-
parts.push(...Object.values(clickData.dataAttributes));
|
|
152
|
-
}
|
|
153
|
-
return parts.join(' ');
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Safe regex testing with error handling
|
|
157
|
-
*/
|
|
158
|
-
testRegex(pattern, text) {
|
|
159
|
-
try {
|
|
160
|
-
const regex = new RegExp(pattern, 'gi');
|
|
161
|
-
return regex.test(text);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
@@ -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,53 +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 var SpecialProjectId;
|
|
10
|
-
(function (SpecialProjectId) {
|
|
11
|
-
/**
|
|
12
|
-
* Value: 'skip'
|
|
13
|
-
*
|
|
14
|
-
* Skips ALL HTTP calls - no config fetch, no event sending
|
|
15
|
-
* Uses default local config, forces debug mode
|
|
16
|
-
* Perfect for pure offline E2E testing
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* await TraceLog.init({ id: SpecialProjectId.Skip });
|
|
20
|
-
* // or
|
|
21
|
-
* await TraceLog.init({ id: 'skip' });
|
|
22
|
-
*/
|
|
23
|
-
SpecialProjectId["Skip"] = "skip";
|
|
24
|
-
/**
|
|
25
|
-
* Value: 'localhost:8080'
|
|
26
|
-
*
|
|
27
|
-
* Makes HTTP calls to local development server on port 8080
|
|
28
|
-
* Converts to http://localhost:8080/config for requests
|
|
29
|
-
* Requires origin to be in ALLOWED_ORIGINS list, forces debug mode
|
|
30
|
-
* Perfect for local development with running middleware
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* await TraceLog.init({ id: SpecialProjectId.Localhost });
|
|
34
|
-
* // or
|
|
35
|
-
* await TraceLog.init({ id: 'localhost:8080' });
|
|
36
|
-
* // Makes requests to: http://localhost:8080/config
|
|
37
|
-
*/
|
|
38
|
-
SpecialProjectId["Localhost"] = "localhost:8080";
|
|
39
|
-
/**
|
|
40
|
-
* Value: 'localhost:9999'
|
|
41
|
-
*
|
|
42
|
-
* Makes HTTP calls to non-existent server (port 9999)
|
|
43
|
-
* All HTTP requests will fail naturally, triggering persistence
|
|
44
|
-
* Forces debug mode, perfect for testing event persistence & recovery
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* await TraceLog.init({ id: SpecialProjectId.Fail });
|
|
48
|
-
* // or
|
|
49
|
-
* await TraceLog.init({ id: 'localhost:9999' });
|
|
50
|
-
* // Makes requests to: http://localhost:9999 (will fail)
|
|
51
|
-
*/
|
|
52
|
-
SpecialProjectId["Fail"] = "localhost:9999";
|
|
53
|
-
})(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,28 +0,0 @@
|
|
|
1
|
-
export var TagLogicalOperator;
|
|
2
|
-
(function (TagLogicalOperator) {
|
|
3
|
-
TagLogicalOperator["AND"] = "AND";
|
|
4
|
-
TagLogicalOperator["OR"] = "OR";
|
|
5
|
-
})(TagLogicalOperator || (TagLogicalOperator = {}));
|
|
6
|
-
export var TagConditionType;
|
|
7
|
-
(function (TagConditionType) {
|
|
8
|
-
TagConditionType["URL_MATCHES"] = "url_matches";
|
|
9
|
-
TagConditionType["ELEMENT_MATCHES"] = "element_matches";
|
|
10
|
-
TagConditionType["DEVICE_TYPE"] = "device_type";
|
|
11
|
-
TagConditionType["ELEMENT_TEXT"] = "element_text";
|
|
12
|
-
TagConditionType["ELEMENT_ATTRIBUTE"] = "element_attribute";
|
|
13
|
-
TagConditionType["UTM_SOURCE"] = "utm_source";
|
|
14
|
-
TagConditionType["UTM_MEDIUM"] = "utm_medium";
|
|
15
|
-
TagConditionType["UTM_CAMPAIGN"] = "utm_campaign";
|
|
16
|
-
})(TagConditionType || (TagConditionType = {}));
|
|
17
|
-
export var TagConditionOperator;
|
|
18
|
-
(function (TagConditionOperator) {
|
|
19
|
-
TagConditionOperator["EQUALS"] = "equals";
|
|
20
|
-
TagConditionOperator["CONTAINS"] = "contains";
|
|
21
|
-
TagConditionOperator["STARTS_WITH"] = "starts_with";
|
|
22
|
-
TagConditionOperator["ENDS_WITH"] = "ends_with";
|
|
23
|
-
TagConditionOperator["REGEX"] = "regex";
|
|
24
|
-
TagConditionOperator["GREATER_THAN"] = "greater_than";
|
|
25
|
-
TagConditionOperator["LESS_THAN"] = "less_than";
|
|
26
|
-
TagConditionOperator["EXISTS"] = "exists";
|
|
27
|
-
TagConditionOperator["NOT_EXISTS"] = "not_exists";
|
|
28
|
-
})(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,44 +0,0 @@
|
|
|
1
|
-
import { getGlobalState } from '../../managers/state.manager';
|
|
2
|
-
class DebugLogger {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.clientError = (ns, msg, data) => this.log('CLIENT_ERROR', ns, msg, data);
|
|
5
|
-
this.clientWarn = (ns, msg, data) => this.log('CLIENT_WARN', ns, msg, data);
|
|
6
|
-
this.info = (ns, msg, data) => this.log('INFO', ns, msg, data);
|
|
7
|
-
this.error = (ns, msg, data) => this.log('ERROR', ns, msg, data);
|
|
8
|
-
this.warn = (ns, msg, data) => this.log('WARN', ns, msg, data);
|
|
9
|
-
this.debug = (ns, msg, data) => this.log('DEBUG', ns, msg, data);
|
|
10
|
-
this.verbose = (ns, msg, data) => this.log('VERBOSE', ns, msg, data);
|
|
11
|
-
}
|
|
12
|
-
log(level, ns, msg, data) {
|
|
13
|
-
const mode = getGlobalState()?.config?.mode;
|
|
14
|
-
if (!this.shouldShow(level, mode))
|
|
15
|
-
return;
|
|
16
|
-
const formattedMsg = `[TraceLog:${ns}] ${msg}`;
|
|
17
|
-
const method = this.getMethod(level);
|
|
18
|
-
if (data !== undefined) {
|
|
19
|
-
console[method](formattedMsg, data);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
console[method](formattedMsg);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
shouldShow(level, mode) {
|
|
26
|
-
if (['CLIENT_ERROR', 'ERROR'].includes(level))
|
|
27
|
-
return true;
|
|
28
|
-
if (!mode)
|
|
29
|
-
return level === 'CLIENT_WARN';
|
|
30
|
-
if (mode === 'qa')
|
|
31
|
-
return ['INFO', 'CLIENT_ERROR', 'CLIENT_WARN'].includes(level);
|
|
32
|
-
if (mode === 'debug')
|
|
33
|
-
return true; // Debug mode shows all logs
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
getMethod(level) {
|
|
37
|
-
if (['CLIENT_ERROR', 'ERROR'].includes(level))
|
|
38
|
-
return 'error';
|
|
39
|
-
if (['CLIENT_WARN', 'WARN'].includes(level))
|
|
40
|
-
return 'warn';
|
|
41
|
-
return 'log';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export const debugLog = new DebugLogger();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { debugLog } from './debug-logger.utils';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { debugLog } from './debug-logger.utils';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export async function fetchWithTimeout(url, options = {}) {
|
|
2
|
-
const { timeout = 10000, ...fetchOptions } = options;
|
|
3
|
-
const controller = new AbortController();
|
|
4
|
-
const timeoutId = setTimeout(() => {
|
|
5
|
-
controller.abort();
|
|
6
|
-
}, timeout);
|
|
7
|
-
try {
|
|
8
|
-
const response = await fetch(url, {
|
|
9
|
-
...fetchOptions,
|
|
10
|
-
signal: controller.signal,
|
|
11
|
-
});
|
|
12
|
-
clearTimeout(timeoutId);
|
|
13
|
-
return response;
|
|
14
|
-
}
|
|
15
|
-
catch (error) {
|
|
16
|
-
clearTimeout(timeoutId);
|
|
17
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
18
|
-
throw new Error(`Request timeout after ${timeout}ms`);
|
|
19
|
-
}
|
|
20
|
-
throw error;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates if a URL is valid and optionally allows HTTP URLs
|
|
3
|
-
* @param url - The URL to validate
|
|
4
|
-
* @param allowHttp - Whether to allow HTTP URLs (default: false)
|
|
5
|
-
* @returns True if the URL is valid, false otherwise
|
|
6
|
-
*/
|
|
7
|
-
export declare const isValidUrl: (url: string, allowHttp?: boolean) => boolean;
|
|
8
|
-
/**
|
|
9
|
-
* Validates a URL field in configuration
|
|
10
|
-
* @param url - The URL to validate
|
|
11
|
-
* @param allowHttp - Whether to allow HTTP URLs
|
|
12
|
-
* @param fieldName - The name of the field being validated
|
|
13
|
-
* @param errors - Array to push errors to
|
|
14
|
-
*/
|
|
15
|
-
export declare const validateUrl: (url: unknown, allowHttp: boolean | undefined, fieldName: string, errors: string[]) => void;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Validates if a URL is valid and optionally allows HTTP URLs
|
|
3
|
-
* @param url - The URL to validate
|
|
4
|
-
* @param allowHttp - Whether to allow HTTP URLs (default: false)
|
|
5
|
-
* @returns True if the URL is valid, false otherwise
|
|
6
|
-
*/
|
|
7
|
-
export const isValidUrl = (url, allowHttp = false) => {
|
|
8
|
-
try {
|
|
9
|
-
const parsed = new URL(url);
|
|
10
|
-
const isHttps = parsed.protocol === 'https:';
|
|
11
|
-
const isHttp = parsed.protocol === 'http:';
|
|
12
|
-
return isHttps || (allowHttp && isHttp);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Validates a URL field in configuration
|
|
20
|
-
* @param url - The URL to validate
|
|
21
|
-
* @param allowHttp - Whether to allow HTTP URLs
|
|
22
|
-
* @param fieldName - The name of the field being validated
|
|
23
|
-
* @param errors - Array to push errors to
|
|
24
|
-
*/
|
|
25
|
-
export const validateUrl = (url, allowHttp, fieldName, errors) => {
|
|
26
|
-
if (url !== undefined) {
|
|
27
|
-
if (typeof url === 'string') {
|
|
28
|
-
try {
|
|
29
|
-
const parsed = new URL(url);
|
|
30
|
-
if (parsed.protocol === 'http:' && !allowHttp) {
|
|
31
|
-
errors.push(`${fieldName} using http requires allowHttp=true`);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
errors.push(`${fieldName} must be a valid URL`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
errors.push(`${fieldName} must be a string`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|