@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
package/lib/index.js
CHANGED
|
@@ -22,7 +22,6 @@ import ConstructedStyleSheets from './modules/constructedStyleSheets.js';
|
|
|
22
22
|
import Selection from './modules/selection.js';
|
|
23
23
|
import Tabs from './modules/tabs.js';
|
|
24
24
|
import { IN_BROWSER, deprecationWarn, DOCS_HOST } from './utils.js';
|
|
25
|
-
import FeatureFlags from './modules/featureFlags.js';
|
|
26
25
|
const DOCS_SETUP = '/installation/javascript-sdk';
|
|
27
26
|
function processOptions(obj) {
|
|
28
27
|
if (obj == null) {
|
|
@@ -53,8 +52,28 @@ function processOptions(obj) {
|
|
|
53
52
|
}
|
|
54
53
|
export default class API {
|
|
55
54
|
constructor(options) {
|
|
55
|
+
var _a;
|
|
56
56
|
this.options = options;
|
|
57
57
|
this.app = null;
|
|
58
|
+
this.checkDoNotTrack = () => {
|
|
59
|
+
return (this.options.respectDoNotTrack &&
|
|
60
|
+
(navigator.doNotTrack == '1' ||
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
window.doNotTrack == '1'));
|
|
63
|
+
};
|
|
64
|
+
this.signalStartIssue = (reason, missingApi) => {
|
|
65
|
+
const doNotTrack = this.checkDoNotTrack();
|
|
66
|
+
const req = new XMLHttpRequest();
|
|
67
|
+
const orig = this.options.ingestPoint || DEFAULT_INGEST_POINT;
|
|
68
|
+
req.open('POST', orig + '/v1/web/not-started');
|
|
69
|
+
req.send(JSON.stringify({
|
|
70
|
+
trackerVersion: '12.0.0',
|
|
71
|
+
projectKey: this.options.projectKey,
|
|
72
|
+
doNotTrack,
|
|
73
|
+
reason,
|
|
74
|
+
missingApi,
|
|
75
|
+
}));
|
|
76
|
+
};
|
|
58
77
|
this.restartCanvasTracking = () => {
|
|
59
78
|
if (this.app === null) {
|
|
60
79
|
return;
|
|
@@ -88,105 +107,118 @@ export default class API {
|
|
|
88
107
|
console.error('OpenReplay: Your website must be publicly accessible and running on SSL in order for OpenReplay to properly capture and replay the user session. You can disable this check by setting `__DISABLE_SECURE_MODE` option to `true` if you are testing in localhost. Keep in mind, that asset files on a local machine are not available to the outside world. This might affect tracking if you use css files.');
|
|
89
108
|
return;
|
|
90
109
|
}
|
|
91
|
-
const doNotTrack =
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.featureFlags = new FeatureFlags(app);
|
|
126
|
-
window.__OPENREPLAY__ = this;
|
|
127
|
-
app.attachStartCallback(() => {
|
|
128
|
-
var _a;
|
|
129
|
-
if ((_a = options.flags) === null || _a === void 0 ? void 0 : _a.onFlagsLoad) {
|
|
130
|
-
this.onFlagsLoad(options.flags.onFlagsLoad);
|
|
110
|
+
const doNotTrack = this.checkDoNotTrack();
|
|
111
|
+
const failReason = [];
|
|
112
|
+
const conditions = [
|
|
113
|
+
'Map',
|
|
114
|
+
'Set',
|
|
115
|
+
'MutationObserver',
|
|
116
|
+
'performance',
|
|
117
|
+
'timing',
|
|
118
|
+
'startsWith',
|
|
119
|
+
'Blob',
|
|
120
|
+
'Worker',
|
|
121
|
+
];
|
|
122
|
+
if (doNotTrack) {
|
|
123
|
+
failReason.push('doNotTrack');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
for (const condition of conditions) {
|
|
127
|
+
if (condition === 'timing') {
|
|
128
|
+
if ('performance' in window && !(condition in performance)) {
|
|
129
|
+
failReason.push(condition);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (condition === 'startsWith') {
|
|
134
|
+
if (!(condition in String.prototype)) {
|
|
135
|
+
failReason.push(condition);
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
if (!(condition in window)) {
|
|
141
|
+
failReason.push(condition);
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
131
144
|
}
|
|
132
|
-
void this.featureFlags.reloadFlags();
|
|
133
|
-
});
|
|
134
|
-
const wOpen = window.open;
|
|
135
|
-
if (options.autoResetOnWindowOpen || options.resetTabOnWindowOpen) {
|
|
136
|
-
app.attachStartCallback(() => {
|
|
137
|
-
var _a;
|
|
138
|
-
const tabId = app.getTabId();
|
|
139
|
-
const sessStorage = (_a = app.sessionStorage) !== null && _a !== void 0 ? _a : window.sessionStorage;
|
|
140
|
-
// @ts-ignore ?
|
|
141
|
-
window.open = function (...args) {
|
|
142
|
-
if (options.autoResetOnWindowOpen) {
|
|
143
|
-
app.resetNextPageSession(true);
|
|
144
|
-
}
|
|
145
|
-
if (options.resetTabOnWindowOpen) {
|
|
146
|
-
sessStorage.removeItem(options.session_tabid_key || '__openreplay_tabid');
|
|
147
|
-
}
|
|
148
|
-
wOpen.call(window, ...args);
|
|
149
|
-
app.resetNextPageSession(false);
|
|
150
|
-
sessStorage.setItem(options.session_tabid_key || '__openreplay_tabid', tabId);
|
|
151
|
-
};
|
|
152
|
-
});
|
|
153
|
-
app.attachStopCallback(() => {
|
|
154
|
-
window.open = wOpen;
|
|
155
|
-
});
|
|
156
145
|
}
|
|
157
146
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
147
|
+
if (failReason.length > 0) {
|
|
148
|
+
const missingApi = failReason.join(',');
|
|
149
|
+
console.error(`OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1. Reason: ${missingApi}`);
|
|
150
|
+
this.signalStartIssue('missing_api', failReason);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const app = new App(options.projectKey, options.sessionToken, options, this.signalStartIssue);
|
|
154
|
+
this.app = app;
|
|
155
|
+
Viewport(app);
|
|
156
|
+
CSSRules(app);
|
|
157
|
+
ConstructedStyleSheets(app);
|
|
158
|
+
Connection(app);
|
|
159
|
+
Console(app, options);
|
|
160
|
+
Exception(app, options);
|
|
161
|
+
Img(app);
|
|
162
|
+
Input(app, options);
|
|
163
|
+
Mouse(app, options.mouse);
|
|
164
|
+
Timing(app, options);
|
|
165
|
+
Performance(app, options);
|
|
166
|
+
Scroll(app);
|
|
167
|
+
Focus(app);
|
|
168
|
+
Fonts(app);
|
|
169
|
+
Network(app, options.network);
|
|
170
|
+
Selection(app);
|
|
171
|
+
Tabs(app);
|
|
172
|
+
window.__OPENREPLAY__ = this;
|
|
173
|
+
if ((_a = options.flags) === null || _a === void 0 ? void 0 : _a.onFlagsLoad) {
|
|
174
|
+
this.onFlagsLoad(options.flags.onFlagsLoad);
|
|
175
|
+
}
|
|
176
|
+
const wOpen = window.open;
|
|
177
|
+
if (options.autoResetOnWindowOpen || options.resetTabOnWindowOpen) {
|
|
178
|
+
app.attachStartCallback(() => {
|
|
179
|
+
var _a;
|
|
180
|
+
const tabId = app.getTabId();
|
|
181
|
+
const sessStorage = (_a = app.sessionStorage) !== null && _a !== void 0 ? _a : window.sessionStorage;
|
|
182
|
+
// @ts-ignore ?
|
|
183
|
+
window.open = function (...args) {
|
|
184
|
+
if (options.autoResetOnWindowOpen) {
|
|
185
|
+
app.resetNextPageSession(true);
|
|
186
|
+
}
|
|
187
|
+
if (options.resetTabOnWindowOpen) {
|
|
188
|
+
sessStorage.removeItem(options.session_tabid_key || '__openreplay_tabid');
|
|
189
|
+
}
|
|
190
|
+
wOpen.call(window, ...args);
|
|
191
|
+
app.resetNextPageSession(false);
|
|
192
|
+
sessStorage.setItem(options.session_tabid_key || '__openreplay_tabid', tabId);
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
app.attachStopCallback(() => {
|
|
196
|
+
window.open = wOpen;
|
|
197
|
+
});
|
|
171
198
|
}
|
|
172
199
|
}
|
|
173
200
|
isFlagEnabled(flagName) {
|
|
174
201
|
return this.featureFlags.isFlagEnabled(flagName);
|
|
175
202
|
}
|
|
176
203
|
onFlagsLoad(callback) {
|
|
177
|
-
|
|
204
|
+
var _a;
|
|
205
|
+
(_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.onFlagsLoad(callback);
|
|
178
206
|
}
|
|
179
207
|
clearPersistFlags() {
|
|
180
|
-
|
|
208
|
+
var _a;
|
|
209
|
+
(_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.clearPersistFlags();
|
|
181
210
|
}
|
|
182
211
|
reloadFlags() {
|
|
183
|
-
|
|
212
|
+
var _a;
|
|
213
|
+
return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.reloadFlags();
|
|
184
214
|
}
|
|
185
215
|
getFeatureFlag(flagName) {
|
|
186
|
-
|
|
216
|
+
var _a;
|
|
217
|
+
return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.getFeatureFlag(flagName);
|
|
187
218
|
}
|
|
188
219
|
getAllFeatureFlags() {
|
|
189
|
-
|
|
220
|
+
var _a;
|
|
221
|
+
return (_a = this.app) === null || _a === void 0 ? void 0 : _a.featureFlags.flags;
|
|
190
222
|
}
|
|
191
223
|
use(fn) {
|
|
192
224
|
return fn(this.app, this.options);
|
|
@@ -197,16 +229,89 @@ export default class API {
|
|
|
197
229
|
}
|
|
198
230
|
return this.app.active();
|
|
199
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Creates a named hook that expects event name, data string and msg direction (up/down),
|
|
234
|
+
* it will skip any message bigger than 5 mb or event name bigger than 255 symbols
|
|
235
|
+
* msg direction is "down" (incoming) by default
|
|
236
|
+
*
|
|
237
|
+
* @returns {(msgType: string, data: string, dir: 'up' | 'down') => void}
|
|
238
|
+
* */
|
|
239
|
+
trackWs(channelName) {
|
|
240
|
+
if (this.app === null) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
return this.app.trackWs(channelName);
|
|
244
|
+
}
|
|
200
245
|
start(startOpts) {
|
|
246
|
+
if (this.browserEnvCheck()) {
|
|
247
|
+
if (this.app === null) {
|
|
248
|
+
return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
|
|
249
|
+
}
|
|
250
|
+
return this.app.start(startOpts);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return Promise.reject('Trying to start not in browser.');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
browserEnvCheck() {
|
|
201
257
|
if (!IN_BROWSER) {
|
|
202
258
|
console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${DOCS_HOST}${DOCS_SETUP}`);
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* start buffering messages without starting the actual session, which gives user 30 seconds to "activate" and record
|
|
265
|
+
* session by calling start() on conditional trigger and we will then send buffered batch, so it won't get lost
|
|
266
|
+
* */
|
|
267
|
+
coldStart(startOpts, conditional) {
|
|
268
|
+
if (this.browserEnvCheck()) {
|
|
269
|
+
if (this.app === null) {
|
|
270
|
+
return Promise.reject('Tracker not initialized');
|
|
271
|
+
}
|
|
272
|
+
void this.app.coldStart(startOpts, conditional);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
203
275
|
return Promise.reject('Trying to start not in browser.');
|
|
204
276
|
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Starts offline session recording. Keep in mind that only user device time will be used for timestamps.
|
|
280
|
+
* (no backend delay sync)
|
|
281
|
+
*
|
|
282
|
+
* @param {Object} startOpts - options for session start, same as .start()
|
|
283
|
+
* @param {Function} onSessionSent - callback that will be called once session is fully sent
|
|
284
|
+
* @returns methods to manipulate buffer:
|
|
285
|
+
*
|
|
286
|
+
* saveBuffer - to save it in localStorage
|
|
287
|
+
*
|
|
288
|
+
* getBuffer - returns current buffer
|
|
289
|
+
*
|
|
290
|
+
* setBuffer - replaces current buffer with given
|
|
291
|
+
* */
|
|
292
|
+
startOfflineRecording(startOpts, onSessionSent) {
|
|
293
|
+
if (this.browserEnvCheck()) {
|
|
294
|
+
if (this.app === null) {
|
|
295
|
+
return Promise.reject('Tracker not initialized');
|
|
296
|
+
}
|
|
297
|
+
return this.app.offlineRecording(startOpts, onSessionSent);
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
return Promise.reject('Trying to start not in browser.');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Uploads the stored session buffer to backend
|
|
305
|
+
* @returns promise that resolves once messages are loaded, it has to be awaited
|
|
306
|
+
* so the session can be uploaded properly
|
|
307
|
+
* @resolve - if messages were loaded into service worker successfully
|
|
308
|
+
* @reject {string} - error message
|
|
309
|
+
* */
|
|
310
|
+
uploadOfflineRecording() {
|
|
205
311
|
if (this.app === null) {
|
|
206
|
-
return
|
|
312
|
+
return;
|
|
207
313
|
}
|
|
208
|
-
|
|
209
|
-
return this.app.start(startOpts);
|
|
314
|
+
return this.app.uploadOfflineRecording();
|
|
210
315
|
}
|
|
211
316
|
stop() {
|
|
212
317
|
if (this.app === null) {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import Message, { CustomEvent, JSException, MouseClick, NetworkRequest, SetPageLocation } from '../common/messages.gen.js';
|
|
2
|
+
import App, { StartOptions } from '../app/index.js';
|
|
3
|
+
import { IFeatureFlag } from './featureFlags.js';
|
|
4
|
+
interface Filter {
|
|
5
|
+
filters: {
|
|
6
|
+
operator: string;
|
|
7
|
+
value: string[];
|
|
8
|
+
type: string;
|
|
9
|
+
source?: string;
|
|
10
|
+
}[];
|
|
11
|
+
operator: string;
|
|
12
|
+
value: string[];
|
|
13
|
+
type: string;
|
|
14
|
+
source?: string;
|
|
15
|
+
}
|
|
16
|
+
export default class ConditionsManager {
|
|
17
|
+
private readonly app;
|
|
18
|
+
private readonly startParams;
|
|
19
|
+
conditions: Condition[];
|
|
20
|
+
hasStarted: boolean;
|
|
21
|
+
constructor(app: App, startParams: StartOptions);
|
|
22
|
+
setConditions(conditions: Condition[]): void;
|
|
23
|
+
fetchConditions(projectId: string, token: string): Promise<void>;
|
|
24
|
+
createConditionFromFilter: (filter: Filter) => Condition | undefined;
|
|
25
|
+
trigger(conditionName: string): void;
|
|
26
|
+
processMessage(message: Message): void;
|
|
27
|
+
processFlags(flag: IFeatureFlag[]): void;
|
|
28
|
+
durationInt: ReturnType<typeof setInterval> | null;
|
|
29
|
+
processDuration(durationMs: number, condName: string): void;
|
|
30
|
+
networkRequest(message: NetworkRequest): void;
|
|
31
|
+
customEvent(message: CustomEvent): void;
|
|
32
|
+
clickEvent(message: MouseClick): void;
|
|
33
|
+
pageLocationEvent(message: SetPageLocation): void;
|
|
34
|
+
jsExceptionEvent(message: JSException): void;
|
|
35
|
+
}
|
|
36
|
+
type CommonCondition = {
|
|
37
|
+
type: 'visited_url' | 'click' | 'custom_event';
|
|
38
|
+
operator: keyof typeof operators;
|
|
39
|
+
value: string[];
|
|
40
|
+
name: string;
|
|
41
|
+
};
|
|
42
|
+
type ExceptionCondition = {
|
|
43
|
+
type: 'exception';
|
|
44
|
+
operator: 'contains' | 'startsWith' | 'endsWith';
|
|
45
|
+
value: string[];
|
|
46
|
+
name: string;
|
|
47
|
+
};
|
|
48
|
+
type FeatureFlagCondition = {
|
|
49
|
+
type: 'feature_flag';
|
|
50
|
+
operator: 'is';
|
|
51
|
+
value: string[];
|
|
52
|
+
name: string;
|
|
53
|
+
};
|
|
54
|
+
type SessionDurationCondition = {
|
|
55
|
+
type: 'session_duration';
|
|
56
|
+
value: number[];
|
|
57
|
+
name: string;
|
|
58
|
+
};
|
|
59
|
+
type SubCondition = {
|
|
60
|
+
type: 'network_request';
|
|
61
|
+
key: 'url' | 'status' | 'method' | 'duration';
|
|
62
|
+
operator: keyof typeof operators;
|
|
63
|
+
value: string[];
|
|
64
|
+
};
|
|
65
|
+
type NetworkRequestCondition = {
|
|
66
|
+
type: 'network_request';
|
|
67
|
+
subConditions: SubCondition[];
|
|
68
|
+
name: string;
|
|
69
|
+
};
|
|
70
|
+
type Condition = CommonCondition | ExceptionCondition | FeatureFlagCondition | SessionDurationCondition | NetworkRequestCondition;
|
|
71
|
+
declare const operators: {
|
|
72
|
+
is: (val: string, target: string[]) => boolean;
|
|
73
|
+
isAny: () => boolean;
|
|
74
|
+
isNot: (val: string, target: string[]) => boolean;
|
|
75
|
+
contains: (val: string, target: string[]) => boolean;
|
|
76
|
+
notContains: (val: string, target: string[]) => boolean;
|
|
77
|
+
startsWith: (val: string, target: string[]) => boolean;
|
|
78
|
+
endsWith: (val: string, target: string[]) => boolean;
|
|
79
|
+
greaterThan: (val: number, target: number) => boolean;
|
|
80
|
+
greaterOrEqual: (val: number, target: number) => boolean;
|
|
81
|
+
lessOrEqual: (val: number, target: number) => boolean;
|
|
82
|
+
lessThan: (val: number, target: number) => boolean;
|
|
83
|
+
};
|
|
84
|
+
export {};
|