@openreplay/tracker 4.1.10 → 4.1.11

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 (71) hide show
  1. package/.eslintignore +0 -3
  2. package/README.md +18 -22
  3. package/cjs/app/guards.d.ts +12 -11
  4. package/cjs/app/guards.js +1 -2
  5. package/cjs/app/index.d.ts +8 -11
  6. package/cjs/app/index.js +8 -27
  7. package/cjs/app/logger.d.ts +3 -3
  8. package/cjs/app/messages.d.ts +52 -0
  9. package/cjs/app/messages.gen.d.ts +6 -8
  10. package/cjs/app/messages.gen.js +94 -116
  11. package/cjs/app/messages.js +234 -0
  12. package/cjs/app/nodes.d.ts +1 -1
  13. package/cjs/app/observer/iframe_offsets.d.ts +1 -1
  14. package/cjs/app/observer/observer.js +5 -5
  15. package/cjs/app/observer/top_observer.d.ts +2 -2
  16. package/cjs/app/observer/top_observer.js +1 -1
  17. package/cjs/app/session.d.ts +2 -2
  18. package/cjs/app/ticker.d.ts +1 -1
  19. package/cjs/common/interaction.d.ts +5 -5
  20. package/cjs/common/messages.gen.d.ts +86 -104
  21. package/cjs/index.d.ts +2 -6
  22. package/cjs/index.js +5 -7
  23. package/cjs/modules/cssrules.js +1 -1
  24. package/cjs/modules/focus.js +2 -2
  25. package/cjs/modules/fonts.js +2 -2
  26. package/cjs/modules/img.js +5 -6
  27. package/cjs/modules/input.d.ts +1 -1
  28. package/cjs/modules/input.js +23 -15
  29. package/cjs/modules/mouse.js +1 -1
  30. package/cjs/modules/timing.js +3 -7
  31. package/cjs/modules/viewport.js +1 -3
  32. package/cjs/vendors/finder/finder.d.ts +1 -1
  33. package/lib/app/guards.d.ts +12 -11
  34. package/lib/app/guards.js +1 -2
  35. package/lib/app/index.d.ts +8 -11
  36. package/lib/app/index.js +9 -28
  37. package/lib/app/logger.d.ts +3 -3
  38. package/lib/app/messages.d.ts +52 -0
  39. package/lib/app/messages.gen.d.ts +6 -8
  40. package/lib/app/messages.gen.js +87 -107
  41. package/lib/app/messages.js +181 -0
  42. package/lib/app/nodes.d.ts +1 -1
  43. package/lib/app/observer/iframe_offsets.d.ts +1 -1
  44. package/lib/app/observer/observer.js +5 -5
  45. package/lib/app/observer/top_observer.d.ts +2 -2
  46. package/lib/app/observer/top_observer.js +1 -1
  47. package/lib/app/session.d.ts +2 -2
  48. package/lib/app/ticker.d.ts +1 -1
  49. package/lib/common/interaction.d.ts +5 -5
  50. package/lib/common/messages.gen.d.ts +86 -104
  51. package/lib/common/tsconfig.tsbuildinfo +1 -1
  52. package/lib/index.d.ts +2 -6
  53. package/lib/index.js +6 -8
  54. package/lib/modules/cssrules.js +1 -1
  55. package/lib/modules/focus.js +2 -2
  56. package/lib/modules/fonts.js +2 -2
  57. package/lib/modules/img.js +5 -6
  58. package/lib/modules/input.d.ts +1 -1
  59. package/lib/modules/input.js +23 -15
  60. package/lib/modules/mouse.js +1 -1
  61. package/lib/modules/timing.js +4 -8
  62. package/lib/modules/viewport.js +1 -3
  63. package/lib/vendors/finder/finder.d.ts +1 -1
  64. package/package.json +3 -8
  65. package/tsconfig-base.json +1 -2
  66. package/CHANGELOG.md +0 -19
  67. package/cjs/modules/network.d.ts +0 -28
  68. package/cjs/modules/network.js +0 -203
  69. package/jest.config.js +0 -11
  70. package/lib/modules/network.d.ts +0 -28
  71. package/lib/modules/network.js +0 -200
package/jest.config.js DELETED
@@ -1,11 +0,0 @@
1
- /** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2
- const config = {
3
- preset: 'ts-jest',
4
- testEnvironment: 'jsdom',
5
- // .js file extension fix
6
- moduleNameMapper: {
7
- '(.+)\\.js': '$1',
8
- },
9
- }
10
-
11
- export default config
@@ -1,28 +0,0 @@
1
- import type App from '../app/index.js';
2
- type XHRRequestBody = Parameters<XMLHttpRequest['send']>[0];
3
- type FetchRequestBody = RequestInit['body'];
4
- interface RequestData {
5
- body: XHRRequestBody | FetchRequestBody;
6
- headers: Record<string, string>;
7
- }
8
- interface ResponseData {
9
- body: any;
10
- headers: Record<string, string>;
11
- }
12
- interface RequestResponseData {
13
- readonly status: number;
14
- readonly method: string;
15
- url: string;
16
- request: RequestData;
17
- response: ResponseData;
18
- }
19
- type Sanitizer = (data: RequestResponseData) => RequestResponseData | null;
20
- export interface Options {
21
- sessionTokenHeader: string | boolean;
22
- failuresOnly: boolean;
23
- ignoreHeaders: Array<string> | boolean;
24
- capturePayload: boolean;
25
- sanitizer?: Sanitizer;
26
- }
27
- export default function (app: App, opts?: Partial<Options>): void;
28
- export {};
@@ -1,200 +0,0 @@
1
- import { NetworkRequest } from '../app/messages.gen.js';
2
- import { getTimeOrigin } from '../utils.js';
3
- function getXHRRequestDataObject(xhr) {
4
- // @ts-ignore this is 3x faster than using Map<XHR, XHRRequestData>
5
- if (!xhr.__or_req_data__) {
6
- // @ts-ignore
7
- xhr.__or_req_data__ = { body: undefined, headers: {} };
8
- }
9
- // @ts-ignore
10
- return xhr.__or_req_data__;
11
- }
12
- function strMethod(method) {
13
- return typeof method === 'string' ? method.toUpperCase() : 'GET';
14
- }
15
- export default function (app, opts = {}) {
16
- const options = Object.assign({
17
- failuresOnly: false,
18
- ignoreHeaders: ['Cookie', 'Set-Cookie', 'Authorization'],
19
- capturePayload: false,
20
- sessionTokenHeader: false,
21
- }, opts);
22
- const ignoreHeaders = options.ignoreHeaders;
23
- const isHIgnored = Array.isArray(ignoreHeaders)
24
- ? (name) => ignoreHeaders.includes(name)
25
- : () => ignoreHeaders;
26
- const stHeader = options.sessionTokenHeader === true ? 'X-OpenReplay-SessionToken' : options.sessionTokenHeader;
27
- function setSessionTokenHeader(setRequestHeader) {
28
- if (stHeader) {
29
- const sessionToken = app.getSessionToken();
30
- if (sessionToken) {
31
- app.safe(setRequestHeader)(stHeader, sessionToken);
32
- }
33
- }
34
- }
35
- function sanitize(reqResInfo) {
36
- if (!options.capturePayload) {
37
- delete reqResInfo.request.body;
38
- delete reqResInfo.response.body;
39
- }
40
- if (options.sanitizer) {
41
- const resBody = reqResInfo.response.body;
42
- if (typeof resBody === 'string') {
43
- // Parse response in order to have handy view in sanitisation function
44
- try {
45
- reqResInfo.response.body = JSON.parse(resBody);
46
- }
47
- catch (_a) { }
48
- }
49
- return options.sanitizer(reqResInfo);
50
- }
51
- return reqResInfo;
52
- }
53
- function stringify(r) {
54
- if (r && typeof r.body !== 'string') {
55
- try {
56
- r.body = JSON.stringify(r.body);
57
- }
58
- catch (_a) {
59
- r.body = '<unable to stringify>';
60
- app.notify.warn("Openreplay fetch couldn't stringify body:", r.body);
61
- }
62
- }
63
- return JSON.stringify(r);
64
- }
65
- /* ====== Fetch ====== */
66
- const origFetch = window.fetch.bind(window);
67
- window.fetch = (input, init = {}) => {
68
- if (!(typeof input === 'string' || input instanceof URL) || app.isServiceURL(String(input))) {
69
- return origFetch(input, init);
70
- }
71
- setSessionTokenHeader(function (name, value) {
72
- if (init.headers === undefined) {
73
- init.headers = {};
74
- }
75
- if (init.headers instanceof Headers) {
76
- init.headers.append(name, value);
77
- }
78
- else if (Array.isArray(init.headers)) {
79
- init.headers.push([name, value]);
80
- }
81
- else {
82
- init.headers[name] = value;
83
- }
84
- });
85
- const startTime = performance.now();
86
- return origFetch(input, init).then((response) => {
87
- const duration = performance.now() - startTime;
88
- if (options.failuresOnly && response.status < 400) {
89
- return response;
90
- }
91
- const r = response.clone();
92
- r.text()
93
- .then((text) => {
94
- const reqHs = {};
95
- const resHs = {};
96
- if (ignoreHeaders !== true) {
97
- // request headers
98
- const writeReqHeader = ([n, v]) => {
99
- if (!isHIgnored(n)) {
100
- reqHs[n] = v;
101
- }
102
- };
103
- if (init.headers instanceof Headers) {
104
- init.headers.forEach((v, n) => writeReqHeader([n, v]));
105
- }
106
- else if (Array.isArray(init.headers)) {
107
- init.headers.forEach(writeReqHeader);
108
- }
109
- else if (typeof init.headers === 'object') {
110
- Object.entries(init.headers).forEach(writeReqHeader);
111
- }
112
- // response headers
113
- r.headers.forEach((v, n) => {
114
- if (!isHIgnored(n))
115
- resHs[n] = v;
116
- });
117
- }
118
- const method = strMethod(init.method);
119
- const reqResInfo = sanitize({
120
- url: String(input),
121
- method,
122
- status: r.status,
123
- request: {
124
- headers: reqHs,
125
- body: init.body,
126
- },
127
- response: {
128
- headers: resHs,
129
- body: text,
130
- },
131
- });
132
- if (!reqResInfo) {
133
- return;
134
- }
135
- app.send(NetworkRequest('fetch', method, String(reqResInfo.url), stringify(reqResInfo.request), stringify(reqResInfo.response), r.status, startTime + getTimeOrigin(), duration));
136
- })
137
- .catch((e) => app.debug.error('Could not process Fetch response:', e));
138
- return response;
139
- });
140
- };
141
- /* ====== <> ====== */
142
- /* ====== XHR ====== */
143
- const nativeOpen = XMLHttpRequest.prototype.open;
144
- XMLHttpRequest.prototype.open = function (initMethod, url) {
145
- const xhr = this;
146
- setSessionTokenHeader((name, value) => xhr.setRequestHeader(name, value));
147
- let startTime = 0;
148
- xhr.addEventListener('loadstart', (e) => {
149
- startTime = e.timeStamp;
150
- });
151
- xhr.addEventListener('load', app.safe((e) => {
152
- const { headers: reqHs, body: reqBody } = getXHRRequestDataObject(xhr);
153
- const duration = startTime > 0 ? e.timeStamp - startTime : 0;
154
- const hString = ignoreHeaders ? '' : xhr.getAllResponseHeaders(); // might be null (though only if no response received though)
155
- const resHs = hString
156
- ? hString
157
- .split('\r\n')
158
- .map((h) => h.split(':'))
159
- .filter((entry) => !isHIgnored(entry[0]))
160
- .reduce((hds, [name, value]) => (Object.assign(Object.assign({}, hds), { [name]: value })), {})
161
- : {};
162
- const method = strMethod(initMethod);
163
- const reqResInfo = sanitize({
164
- url: String(url),
165
- method,
166
- status: xhr.status,
167
- request: {
168
- headers: reqHs,
169
- body: reqBody,
170
- },
171
- response: {
172
- headers: resHs,
173
- body: xhr.response,
174
- },
175
- });
176
- if (!reqResInfo) {
177
- return;
178
- }
179
- app.send(NetworkRequest('xhr', method, String(reqResInfo.url), stringify(reqResInfo.request), stringify(reqResInfo.response), xhr.status, startTime + getTimeOrigin(), duration));
180
- }));
181
- //TODO: handle error (though it has no Error API nor any useful information)
182
- //xhr.addEventListener('error', (e) => {})
183
- return nativeOpen.apply(this, arguments);
184
- };
185
- const nativeSend = XMLHttpRequest.prototype.send;
186
- XMLHttpRequest.prototype.send = function (body) {
187
- const rdo = getXHRRequestDataObject(this);
188
- rdo.body = body;
189
- return nativeSend.apply(this, arguments);
190
- };
191
- const nativeSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
192
- XMLHttpRequest.prototype.setRequestHeader = function (name, value) {
193
- if (!isHIgnored(name)) {
194
- const rdo = getXHRRequestDataObject(this);
195
- rdo.headers[name] = value;
196
- }
197
- return nativeSetRequestHeader.apply(this, arguments);
198
- };
199
- /* ====== <> ====== */
200
- }