@openreplay/tracker 11.0.6 → 12.0.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/CHANGELOG.md +4 -2
- package/cjs/app/index.d.ts +84 -6
- package/cjs/app/index.js +427 -58
- package/cjs/app/logger.d.ts +7 -17
- package/cjs/app/logger.js +11 -19
- package/cjs/app/messages.gen.d.ts +2 -0
- package/cjs/app/messages.gen.js +20 -1
- package/cjs/app/observer/iframe_observer.js +4 -1
- package/cjs/app/observer/shadow_root_observer.js +4 -1
- package/cjs/app/observer/top_observer.js +7 -4
- package/cjs/common/interaction.d.ts +5 -2
- package/cjs/common/messages.gen.d.ts +17 -2
- package/cjs/index.d.ts +45 -2
- package/cjs/index.js +237 -106
- package/cjs/modules/Network/beaconProxy.js +4 -1
- package/cjs/modules/Network/fetchProxy.js +24 -1
- package/cjs/modules/Network/index.js +6 -3
- package/cjs/modules/Network/xhrProxy.js +24 -1
- package/cjs/modules/conditionsManager.d.ts +84 -0
- package/cjs/modules/conditionsManager.js +343 -0
- package/cjs/modules/exception.js +4 -1
- package/cjs/modules/featureFlags.d.ts +1 -1
- package/cjs/modules/featureFlags.js +36 -46
- package/cjs/modules/network.js +5 -2
- package/cjs/modules/tagWatcher.d.ts +21 -0
- package/cjs/modules/tagWatcher.js +77 -0
- package/cjs/modules/userTesting/index.js +30 -4
- package/cjs/modules/userTesting/recorder.js +71 -88
- package/coverage/clover.xml +577 -544
- package/coverage/coverage-final.json +8 -8
- package/coverage/lcov-report/index.html +28 -28
- package/coverage/lcov-report/main/app/canvas.ts.html +97 -46
- package/coverage/lcov-report/main/app/guards.ts.html +1 -1
- package/coverage/lcov-report/main/app/index.html +19 -19
- package/coverage/lcov-report/main/app/index.ts.html +62 -35
- package/coverage/lcov-report/main/app/logger.ts.html +1 -1
- package/coverage/lcov-report/main/app/messages.gen.ts.html +32 -5
- package/coverage/lcov-report/main/app/nodes.ts.html +17 -5
- package/coverage/lcov-report/main/app/observer/iframe_observer.ts.html +1 -1
- package/coverage/lcov-report/main/app/observer/iframe_offsets.ts.html +1 -1
- package/coverage/lcov-report/main/app/observer/index.html +1 -1
- package/coverage/lcov-report/main/app/observer/shadow_root_observer.ts.html +1 -1
- package/coverage/lcov-report/main/app/observer/top_observer.ts.html +1 -1
- package/coverage/lcov-report/main/app/sanitizer.ts.html +1 -1
- package/coverage/lcov-report/main/app/session.ts.html +1 -1
- package/coverage/lcov-report/main/app/ticker.ts.html +1 -1
- package/coverage/lcov-report/main/index.html +9 -9
- package/coverage/lcov-report/main/index.ts.html +27 -6
- package/coverage/lcov-report/main/modules/Network/beaconProxy.ts.html +1 -1
- package/coverage/lcov-report/main/modules/Network/fetchProxy.ts.html +1 -1
- package/coverage/lcov-report/main/modules/Network/index.html +1 -1
- package/coverage/lcov-report/main/modules/Network/index.ts.html +1 -1
- package/coverage/lcov-report/main/modules/Network/networkMessage.ts.html +1 -1
- package/coverage/lcov-report/main/modules/Network/utils.ts.html +1 -1
- package/coverage/lcov-report/main/modules/Network/xhrProxy.ts.html +1 -1
- package/coverage/lcov-report/main/modules/attributeSender.ts.html +1 -1
- package/coverage/lcov-report/main/modules/axiosSpy.ts.html +1 -1
- package/coverage/lcov-report/main/modules/conditionsManager.ts.html +92 -38
- package/coverage/lcov-report/main/modules/connection.ts.html +1 -1
- package/coverage/lcov-report/main/modules/console.ts.html +1 -1
- package/coverage/lcov-report/main/modules/constructedStyleSheets.ts.html +1 -1
- package/coverage/lcov-report/main/modules/cssrules.ts.html +1 -1
- package/coverage/lcov-report/main/modules/exception.ts.html +1 -1
- package/coverage/lcov-report/main/modules/featureFlags.ts.html +1 -1
- package/coverage/lcov-report/main/modules/focus.ts.html +1 -1
- package/coverage/lcov-report/main/modules/fonts.ts.html +1 -1
- package/coverage/lcov-report/main/modules/img.ts.html +1 -1
- package/coverage/lcov-report/main/modules/index.html +21 -21
- package/coverage/lcov-report/main/modules/input.ts.html +1 -1
- package/coverage/lcov-report/main/modules/mouse.ts.html +1 -1
- package/coverage/lcov-report/main/modules/network.ts.html +1 -1
- package/coverage/lcov-report/main/modules/performance.ts.html +1 -1
- package/coverage/lcov-report/main/modules/scroll.ts.html +1 -1
- package/coverage/lcov-report/main/modules/selection.ts.html +1 -1
- package/coverage/lcov-report/main/modules/tabs.ts.html +1 -1
- package/coverage/lcov-report/main/modules/tagWatcher.ts.html +54 -27
- package/coverage/lcov-report/main/modules/timing.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/SignalManager.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/dnd.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/index.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/index.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/recorder.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/styles.ts.html +1 -1
- package/coverage/lcov-report/main/modules/userTesting/utils.ts.html +1 -1
- package/coverage/lcov-report/main/modules/viewport.ts.html +1 -1
- package/coverage/lcov-report/main/utils.ts.html +1 -1
- package/coverage/lcov-report/webworker/BatchWriter.ts.html +1 -1
- package/coverage/lcov-report/webworker/MessageEncoder.gen.ts.html +17 -5
- package/coverage/lcov-report/webworker/PrimitiveEncoder.ts.html +1 -1
- package/coverage/lcov-report/webworker/QueueSender.ts.html +1 -1
- package/coverage/lcov-report/webworker/index.html +7 -7
- package/coverage/lcov-report/webworker/index.ts.html +1 -1
- package/coverage/lcov.info +1100 -1033
- package/lib/app/index.d.ts +84 -6
- package/lib/app/index.js +387 -44
- package/lib/app/logger.d.ts +7 -17
- package/lib/app/logger.js +11 -19
- package/lib/app/messages.gen.d.ts +2 -0
- package/lib/app/messages.gen.js +17 -0
- package/lib/common/interaction.d.ts +5 -2
- package/lib/common/messages.gen.d.ts +17 -2
- package/lib/common/tsconfig.tsbuildinfo +1 -1
- package/lib/index.d.ts +45 -2
- package/lib/index.js +191 -86
- package/lib/modules/conditionsManager.d.ts +84 -0
- package/lib/modules/conditionsManager.js +340 -0
- package/lib/modules/featureFlags.d.ts +1 -1
- package/lib/modules/featureFlags.js +36 -46
- package/lib/modules/tagWatcher.d.ts +21 -0
- package/lib/modules/tagWatcher.js +74 -0
- package/lib/modules/userTesting/recorder.js +71 -88
- package/package.json +1 -1
- package/tsconfig-base.json +3 -2
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ConditionsManager {
|
|
4
|
+
constructor(app, startParams) {
|
|
5
|
+
this.app = app;
|
|
6
|
+
this.startParams = startParams;
|
|
7
|
+
this.conditions = [];
|
|
8
|
+
this.hasStarted = false;
|
|
9
|
+
this.createConditionFromFilter = (filter) => {
|
|
10
|
+
if (filter.value.length) {
|
|
11
|
+
const resultCondition = mapCondition(filter);
|
|
12
|
+
if (resultCondition.type) {
|
|
13
|
+
return resultCondition;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
this.durationInt = null;
|
|
19
|
+
}
|
|
20
|
+
setConditions(conditions) {
|
|
21
|
+
this.conditions = conditions;
|
|
22
|
+
}
|
|
23
|
+
async fetchConditions(projectId, token) {
|
|
24
|
+
try {
|
|
25
|
+
const r = await fetch(`${this.app.options.ingestPoint}/v1/web/conditions/${projectId}`, {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${token}`,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const { conditions } = (await r.json());
|
|
32
|
+
const mappedConditions = [];
|
|
33
|
+
conditions.forEach((c) => {
|
|
34
|
+
const filters = c.filters;
|
|
35
|
+
filters.forEach((filter) => {
|
|
36
|
+
let cond;
|
|
37
|
+
if (filter.type === 'fetch') {
|
|
38
|
+
cond = {
|
|
39
|
+
type: 'network_request',
|
|
40
|
+
subConditions: [],
|
|
41
|
+
name: c.name,
|
|
42
|
+
};
|
|
43
|
+
filter.filters.forEach((f) => {
|
|
44
|
+
const subCond = this.createConditionFromFilter(f);
|
|
45
|
+
if (subCond) {
|
|
46
|
+
;
|
|
47
|
+
cond.subConditions.push(subCond);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
cond = this.createConditionFromFilter(filter);
|
|
53
|
+
}
|
|
54
|
+
if (cond) {
|
|
55
|
+
if (cond.type === 'session_duration') {
|
|
56
|
+
this.processDuration(cond.value[0], c.name);
|
|
57
|
+
}
|
|
58
|
+
mappedConditions.push(Object.assign(Object.assign({}, cond), { name: c.name }));
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
this.conditions = mappedConditions;
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
this.app.debug.error('Critical: cannot fetch start conditions');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
trigger(conditionName) {
|
|
69
|
+
if (this.hasStarted)
|
|
70
|
+
return;
|
|
71
|
+
try {
|
|
72
|
+
this.hasStarted = true;
|
|
73
|
+
void this.app.start(this.startParams, undefined, conditionName);
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
this.app.debug.error(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
processMessage(message) {
|
|
80
|
+
if (this.hasStarted)
|
|
81
|
+
return;
|
|
82
|
+
switch (message[0]) {
|
|
83
|
+
case 78 /* Type.JSException */:
|
|
84
|
+
this.jsExceptionEvent(message);
|
|
85
|
+
break;
|
|
86
|
+
case 27 /* Type.CustomEvent */:
|
|
87
|
+
this.customEvent(message);
|
|
88
|
+
break;
|
|
89
|
+
case 69 /* Type.MouseClick */:
|
|
90
|
+
this.clickEvent(message);
|
|
91
|
+
break;
|
|
92
|
+
case 4 /* Type.SetPageLocation */:
|
|
93
|
+
this.pageLocationEvent(message);
|
|
94
|
+
break;
|
|
95
|
+
case 83 /* Type.NetworkRequest */:
|
|
96
|
+
this.networkRequest(message);
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
processFlags(flag) {
|
|
103
|
+
const flagConds = this.conditions.filter((c) => c.type === 'feature_flag');
|
|
104
|
+
if (flagConds.length) {
|
|
105
|
+
flagConds.forEach((flagCond) => {
|
|
106
|
+
const operator = operators[flagCond.operator];
|
|
107
|
+
if (operator && flag.find((f) => operator(f.key, flagCond.value))) {
|
|
108
|
+
this.trigger(flagCond.name);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
processDuration(durationMs, condName) {
|
|
114
|
+
this.durationInt = setInterval(() => {
|
|
115
|
+
const sessionLength = performance.now();
|
|
116
|
+
if (sessionLength > durationMs) {
|
|
117
|
+
this.trigger(condName);
|
|
118
|
+
}
|
|
119
|
+
}, 1000);
|
|
120
|
+
this.app.attachStopCallback(() => {
|
|
121
|
+
if (this.durationInt) {
|
|
122
|
+
clearInterval(this.durationInt);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
networkRequest(message) {
|
|
127
|
+
// method - 2, url - 3, status - 6, duration - 8
|
|
128
|
+
const reqConds = this.conditions.filter((c) => c.type === 'network_request');
|
|
129
|
+
if (!reqConds.length)
|
|
130
|
+
return;
|
|
131
|
+
reqConds.forEach((reqCond) => {
|
|
132
|
+
const validSubConditions = reqCond.subConditions.filter((c) => c.operator !== 'isAny');
|
|
133
|
+
if (validSubConditions.length) {
|
|
134
|
+
const allPass = validSubConditions.every((subCond) => {
|
|
135
|
+
let value;
|
|
136
|
+
switch (subCond.key) {
|
|
137
|
+
case 'url':
|
|
138
|
+
value = message[3];
|
|
139
|
+
break;
|
|
140
|
+
case 'status':
|
|
141
|
+
value = message[6];
|
|
142
|
+
break;
|
|
143
|
+
case 'method':
|
|
144
|
+
value = message[2];
|
|
145
|
+
break;
|
|
146
|
+
case 'duration':
|
|
147
|
+
value = message[8];
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
const operator = operators[subCond.operator];
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
if (operator && operator(value, subCond.value)) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
if (allPass) {
|
|
159
|
+
this.trigger(reqCond.name);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else if (validSubConditions.length === 0 && reqCond.subConditions.length) {
|
|
163
|
+
this.trigger(reqCond.name);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
customEvent(message) {
|
|
168
|
+
// name - 1, payload - 2
|
|
169
|
+
const evConds = this.conditions.filter((c) => c.type === 'custom_event');
|
|
170
|
+
if (evConds.length) {
|
|
171
|
+
evConds.forEach((evCond) => {
|
|
172
|
+
const operator = operators[evCond.operator];
|
|
173
|
+
if (operator &&
|
|
174
|
+
(operator(message[1], evCond.value) || operator(message[2], evCond.value))) {
|
|
175
|
+
this.trigger(evCond.name);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
clickEvent(message) {
|
|
181
|
+
// label - 3, selector - 4
|
|
182
|
+
const clickCond = this.conditions.filter((c) => c.type === 'click');
|
|
183
|
+
if (clickCond.length) {
|
|
184
|
+
clickCond.forEach((click) => {
|
|
185
|
+
const operator = operators[click.operator];
|
|
186
|
+
if (operator && (operator(message[3], click.value) || operator(message[4], click.value))) {
|
|
187
|
+
this.trigger(click.name);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
pageLocationEvent(message) {
|
|
193
|
+
// url - 1
|
|
194
|
+
const urlConds = this.conditions.filter((c) => c.type === 'visited_url');
|
|
195
|
+
if (urlConds) {
|
|
196
|
+
urlConds.forEach((urlCond) => {
|
|
197
|
+
const operator = operators[urlCond.operator];
|
|
198
|
+
if (operator && operator(message[1], urlCond.value)) {
|
|
199
|
+
this.trigger(urlCond.name);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
jsExceptionEvent(message) {
|
|
205
|
+
// name - 1, message - 2, payload - 3
|
|
206
|
+
const testedValues = [message[1], message[2], message[3]];
|
|
207
|
+
const exceptionConds = this.conditions.filter((c) => c.type === 'exception');
|
|
208
|
+
if (exceptionConds) {
|
|
209
|
+
exceptionConds.forEach((exceptionCond) => {
|
|
210
|
+
const operator = operators[exceptionCond.operator];
|
|
211
|
+
if (operator && testedValues.some((val) => operator(val, exceptionCond.value))) {
|
|
212
|
+
this.trigger(exceptionCond.name);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.default = ConditionsManager;
|
|
219
|
+
const operators = {
|
|
220
|
+
is: (val, target) => target.some((t) => val.includes(t)),
|
|
221
|
+
isAny: () => true,
|
|
222
|
+
isNot: (val, target) => !target.some((t) => val.includes(t)),
|
|
223
|
+
contains: (val, target) => target.some((t) => val.includes(t)),
|
|
224
|
+
notContains: (val, target) => !target.some((t) => val.includes(t)),
|
|
225
|
+
startsWith: (val, target) => target.some((t) => val.startsWith(t)),
|
|
226
|
+
endsWith: (val, target) => target.some((t) => val.endsWith(t)),
|
|
227
|
+
greaterThan: (val, target) => val > target,
|
|
228
|
+
greaterOrEqual: (val, target) => val >= target,
|
|
229
|
+
lessOrEqual: (val, target) => val <= target,
|
|
230
|
+
lessThan: (val, target) => val < target,
|
|
231
|
+
};
|
|
232
|
+
const mapCondition = (condition) => {
|
|
233
|
+
const opMap = {
|
|
234
|
+
on: 'is',
|
|
235
|
+
notOn: 'isNot',
|
|
236
|
+
'\u003e': 'greaterThan',
|
|
237
|
+
'\u003c': 'lessThan',
|
|
238
|
+
'\u003d': 'is',
|
|
239
|
+
'\u003c=': 'lessOrEqual',
|
|
240
|
+
'\u003e=': 'greaterOrEqual',
|
|
241
|
+
};
|
|
242
|
+
const mapOperator = (operator) => {
|
|
243
|
+
const keys = Object.keys(opMap);
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
if (keys.includes(operator))
|
|
246
|
+
return opMap[operator];
|
|
247
|
+
};
|
|
248
|
+
let con = {
|
|
249
|
+
type: '',
|
|
250
|
+
operator: '',
|
|
251
|
+
value: condition.value,
|
|
252
|
+
key: '',
|
|
253
|
+
};
|
|
254
|
+
switch (condition.type) {
|
|
255
|
+
case 'click':
|
|
256
|
+
con = {
|
|
257
|
+
type: 'click',
|
|
258
|
+
operator: mapOperator(condition.operator),
|
|
259
|
+
value: condition.value,
|
|
260
|
+
key: '',
|
|
261
|
+
};
|
|
262
|
+
break;
|
|
263
|
+
case 'location':
|
|
264
|
+
con = {
|
|
265
|
+
type: 'visited_url',
|
|
266
|
+
// @ts-ignore
|
|
267
|
+
operator: condition.operator,
|
|
268
|
+
value: condition.value,
|
|
269
|
+
key: '',
|
|
270
|
+
};
|
|
271
|
+
break;
|
|
272
|
+
case 'custom':
|
|
273
|
+
con = {
|
|
274
|
+
type: 'custom_event',
|
|
275
|
+
// @ts-ignore
|
|
276
|
+
operator: condition.operator,
|
|
277
|
+
value: condition.value,
|
|
278
|
+
key: '',
|
|
279
|
+
};
|
|
280
|
+
break;
|
|
281
|
+
case 'metadata':
|
|
282
|
+
con = {
|
|
283
|
+
// @ts-ignore
|
|
284
|
+
type: condition.source === 'featureFlag' ? 'feature_flag' : condition.type,
|
|
285
|
+
// @ts-ignore
|
|
286
|
+
operator: condition.operator,
|
|
287
|
+
value: condition.value,
|
|
288
|
+
key: '',
|
|
289
|
+
};
|
|
290
|
+
break;
|
|
291
|
+
case 'error':
|
|
292
|
+
con = {
|
|
293
|
+
type: 'exception',
|
|
294
|
+
// @ts-ignore
|
|
295
|
+
operator: condition.operator,
|
|
296
|
+
value: condition.value,
|
|
297
|
+
key: '',
|
|
298
|
+
};
|
|
299
|
+
break;
|
|
300
|
+
case 'duration':
|
|
301
|
+
con = {
|
|
302
|
+
type: 'session_duration',
|
|
303
|
+
// @ts-ignore
|
|
304
|
+
value: condition.value[0],
|
|
305
|
+
key: '',
|
|
306
|
+
};
|
|
307
|
+
break;
|
|
308
|
+
case 'fetchUrl':
|
|
309
|
+
con = {
|
|
310
|
+
type: 'network_request',
|
|
311
|
+
key: 'url',
|
|
312
|
+
operator: condition.operator,
|
|
313
|
+
value: condition.value,
|
|
314
|
+
};
|
|
315
|
+
break;
|
|
316
|
+
case 'fetchStatusCode':
|
|
317
|
+
con = {
|
|
318
|
+
type: 'network_request',
|
|
319
|
+
key: 'status',
|
|
320
|
+
operator: mapOperator(condition.operator),
|
|
321
|
+
value: condition.value,
|
|
322
|
+
};
|
|
323
|
+
break;
|
|
324
|
+
case 'fetchMethod':
|
|
325
|
+
con = {
|
|
326
|
+
type: 'network_request',
|
|
327
|
+
key: 'method',
|
|
328
|
+
operator: mapOperator(condition.operator),
|
|
329
|
+
value: condition.value,
|
|
330
|
+
};
|
|
331
|
+
break;
|
|
332
|
+
case 'fetchDuration':
|
|
333
|
+
con = {
|
|
334
|
+
type: 'network_request',
|
|
335
|
+
key: 'duration',
|
|
336
|
+
operator: mapOperator(condition.operator),
|
|
337
|
+
value: condition.value,
|
|
338
|
+
};
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
// @ts-ignore
|
|
342
|
+
return con;
|
|
343
|
+
};
|
package/cjs/modules/exception.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getExceptionMessageFromEvent = exports.getExceptionMessage = void 0;
|
|
4
7
|
const messages_gen_js_1 = require("../app/messages.gen.js");
|
|
5
|
-
const error_stack_parser_1 = require("error-stack-parser");
|
|
8
|
+
const error_stack_parser_1 = __importDefault(require("error-stack-parser"));
|
|
6
9
|
function getDefaultStack(e) {
|
|
7
10
|
return [
|
|
8
11
|
{
|
|
@@ -18,7 +18,7 @@ export default class FeatureFlags {
|
|
|
18
18
|
getFeatureFlag(flagName: string): IFeatureFlag | undefined;
|
|
19
19
|
isFlagEnabled(flagName: string): boolean;
|
|
20
20
|
onFlagsLoad(cb: (flags: IFeatureFlag[]) => void): void;
|
|
21
|
-
reloadFlags(): Promise<void>;
|
|
21
|
+
reloadFlags(token?: string): Promise<void>;
|
|
22
22
|
handleFlags(flags: IFeatureFlag[]): void;
|
|
23
23
|
clearPersistFlags(): void;
|
|
24
24
|
diffPersist(flags: IFeatureFlag[]): IFeatureFlag[];
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
class FeatureFlags {
|
|
13
4
|
constructor(app) {
|
|
@@ -29,45 +20,44 @@ class FeatureFlags {
|
|
|
29
20
|
onFlagsLoad(cb) {
|
|
30
21
|
this.onFlagsCb = cb;
|
|
31
22
|
}
|
|
32
|
-
reloadFlags() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
persistFlags[flagObj.key] = { key: flagObj.key, value: flagObj.value };
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const sessionInfo = this.app.session.getInfo();
|
|
44
|
-
const userInfo = this.app.session.userInfo;
|
|
45
|
-
const requestObject = {
|
|
46
|
-
projectID: sessionInfo.projectID,
|
|
47
|
-
userID: sessionInfo.userID,
|
|
48
|
-
metadata: sessionInfo.metadata,
|
|
49
|
-
referrer: document.referrer,
|
|
50
|
-
os: userInfo.userOS,
|
|
51
|
-
device: userInfo.userDevice,
|
|
52
|
-
country: userInfo.userCountry,
|
|
53
|
-
state: userInfo.userState,
|
|
54
|
-
city: userInfo.userCity,
|
|
55
|
-
browser: userInfo.userBrowser,
|
|
56
|
-
persistFlags: persistFlags,
|
|
57
|
-
};
|
|
58
|
-
const resp = yield fetch(this.app.options.ingestPoint + '/v1/web/feature-flags', {
|
|
59
|
-
method: 'POST',
|
|
60
|
-
headers: {
|
|
61
|
-
'Content-Type': 'application/json',
|
|
62
|
-
Authorization: `Bearer ${this.app.session.getSessionToken()}`,
|
|
63
|
-
},
|
|
64
|
-
body: JSON.stringify(requestObject),
|
|
23
|
+
async reloadFlags(token) {
|
|
24
|
+
const persistFlagsStr = this.app.sessionStorage.getItem(this.storageKey);
|
|
25
|
+
const persistFlags = {};
|
|
26
|
+
if (persistFlagsStr) {
|
|
27
|
+
const persistArray = persistFlagsStr.split(';').filter(Boolean);
|
|
28
|
+
persistArray.forEach((flag) => {
|
|
29
|
+
const flagObj = JSON.parse(flag);
|
|
30
|
+
persistFlags[flagObj.key] = { key: flagObj.key, value: flagObj.value };
|
|
65
31
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
32
|
+
}
|
|
33
|
+
const sessionInfo = this.app.session.getInfo();
|
|
34
|
+
const userInfo = this.app.session.userInfo;
|
|
35
|
+
const requestObject = {
|
|
36
|
+
projectID: sessionInfo.projectID,
|
|
37
|
+
userID: sessionInfo.userID,
|
|
38
|
+
metadata: sessionInfo.metadata,
|
|
39
|
+
referrer: document.referrer,
|
|
40
|
+
os: userInfo.userOS,
|
|
41
|
+
device: userInfo.userDevice,
|
|
42
|
+
country: userInfo.userCountry,
|
|
43
|
+
state: userInfo.userState,
|
|
44
|
+
city: userInfo.userCity,
|
|
45
|
+
browser: userInfo.userBrowser,
|
|
46
|
+
persistFlags: persistFlags,
|
|
47
|
+
};
|
|
48
|
+
const authToken = token !== null && token !== void 0 ? token : this.app.session.getSessionToken();
|
|
49
|
+
const resp = await fetch(this.app.options.ingestPoint + '/v1/web/feature-flags', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
Authorization: `Bearer ${authToken}`,
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify(requestObject),
|
|
70
56
|
});
|
|
57
|
+
if (resp.status === 200) {
|
|
58
|
+
const data = await resp.json();
|
|
59
|
+
return this.handleFlags(data.flags);
|
|
60
|
+
}
|
|
71
61
|
}
|
|
72
62
|
handleFlags(flags) {
|
|
73
63
|
var _a;
|
package/cjs/modules/network.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const messages_gen_js_1 = require("../app/messages.gen.js");
|
|
4
7
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const axiosSpy_js_1 = require("./axiosSpy.js");
|
|
6
|
-
const index_js_1 = require("./Network/index.js");
|
|
8
|
+
const axiosSpy_js_1 = __importDefault(require("./axiosSpy.js"));
|
|
9
|
+
const index_js_1 = __importDefault(require("./Network/index.js"));
|
|
7
10
|
function getXHRRequestDataObject(xhr) {
|
|
8
11
|
// @ts-ignore this is 3x faster than using Map<XHR, XHRRequestData>
|
|
9
12
|
if (!xhr.__or_req_data__) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const WATCHED_TAGS_KEY = "__or__watched_tags__";
|
|
2
|
+
declare class TagWatcher {
|
|
3
|
+
private readonly sessionStorage;
|
|
4
|
+
private readonly errLog;
|
|
5
|
+
private readonly onTag;
|
|
6
|
+
intervals: Record<string, ReturnType<typeof setInterval>>;
|
|
7
|
+
tags: {
|
|
8
|
+
id: number;
|
|
9
|
+
selector: string;
|
|
10
|
+
}[];
|
|
11
|
+
observer: IntersectionObserver;
|
|
12
|
+
constructor(sessionStorage: Storage, errLog: (args: any[]) => void, onTag: (tag: number) => void);
|
|
13
|
+
fetchTags(ingest: string, token: string): Promise<void>;
|
|
14
|
+
setTags(tags: {
|
|
15
|
+
id: number;
|
|
16
|
+
selector: string;
|
|
17
|
+
}[]): void;
|
|
18
|
+
onTagRendered(tagId: number): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
}
|
|
21
|
+
export default TagWatcher;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WATCHED_TAGS_KEY = void 0;
|
|
4
|
+
exports.WATCHED_TAGS_KEY = '__or__watched_tags__';
|
|
5
|
+
class TagWatcher {
|
|
6
|
+
constructor(sessionStorage, errLog, onTag) {
|
|
7
|
+
var _a;
|
|
8
|
+
this.sessionStorage = sessionStorage;
|
|
9
|
+
this.errLog = errLog;
|
|
10
|
+
this.onTag = onTag;
|
|
11
|
+
this.intervals = {};
|
|
12
|
+
this.tags = [];
|
|
13
|
+
const tags = JSON.parse((_a = sessionStorage.getItem(exports.WATCHED_TAGS_KEY)) !== null && _a !== void 0 ? _a : '[]');
|
|
14
|
+
this.setTags(tags);
|
|
15
|
+
this.observer = new IntersectionObserver((entries) => {
|
|
16
|
+
entries.forEach((entry) => {
|
|
17
|
+
if (entry.isIntersecting) {
|
|
18
|
+
if (entry.target) {
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const tag = entry.target.__or_watcher_tagname;
|
|
21
|
+
if (tag) {
|
|
22
|
+
this.onTagRendered(tag);
|
|
23
|
+
}
|
|
24
|
+
this.observer.unobserve(entry.target);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async fetchTags(ingest, token) {
|
|
31
|
+
return fetch(`${ingest}/v1/web/tags`, {
|
|
32
|
+
method: 'GET',
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: `Bearer ${token}`,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
.then((r) => r.json())
|
|
38
|
+
.then(({ tags }) => {
|
|
39
|
+
if (tags && tags.length) {
|
|
40
|
+
this.setTags(tags);
|
|
41
|
+
const tagString = JSON.stringify(tags);
|
|
42
|
+
this.sessionStorage.setItem(exports.WATCHED_TAGS_KEY, tagString || '');
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.catch((e) => this.errLog(e));
|
|
46
|
+
}
|
|
47
|
+
setTags(tags) {
|
|
48
|
+
this.tags = tags;
|
|
49
|
+
this.intervals = {};
|
|
50
|
+
tags.forEach((tag) => {
|
|
51
|
+
this.intervals[tag.id] = setInterval(() => {
|
|
52
|
+
const possibleEls = document.querySelectorAll(tag.selector);
|
|
53
|
+
if (possibleEls.length > 0) {
|
|
54
|
+
const el = possibleEls[0];
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
el.__or_watcher_tagname = tag.id;
|
|
57
|
+
this.observer.observe(el);
|
|
58
|
+
}
|
|
59
|
+
}, 500);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
onTagRendered(tagId) {
|
|
63
|
+
if (this.intervals[tagId]) {
|
|
64
|
+
clearInterval(this.intervals[tagId]);
|
|
65
|
+
}
|
|
66
|
+
this.onTag(tagId);
|
|
67
|
+
}
|
|
68
|
+
clear() {
|
|
69
|
+
this.tags.forEach((tag) => {
|
|
70
|
+
clearInterval(this.intervals[tag.id]);
|
|
71
|
+
});
|
|
72
|
+
this.tags = [];
|
|
73
|
+
this.intervals = {};
|
|
74
|
+
this.observer.disconnect();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.default = TagWatcher;
|
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const styles = require("./styles.js");
|
|
4
|
-
const recorder_js_1 = require("./recorder.js");
|
|
5
|
-
const dnd_js_1 = require("./dnd.js");
|
|
29
|
+
const styles = __importStar(require("./styles.js"));
|
|
30
|
+
const recorder_js_1 = __importStar(require("./recorder.js"));
|
|
31
|
+
const dnd_js_1 = __importDefault(require("./dnd.js"));
|
|
6
32
|
const utils_js_1 = require("./utils.js");
|
|
7
|
-
const SignalManager_js_1 = require("./SignalManager.js");
|
|
33
|
+
const SignalManager_js_1 = __importDefault(require("./SignalManager.js"));
|
|
8
34
|
class UserTestManager {
|
|
9
35
|
constructor(app, storageKey) {
|
|
10
36
|
this.app = app;
|