@openreplay/tracker 5.0.5-beta.1 → 5.0.5-beta.2

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/cjs/app/index.js CHANGED
@@ -33,7 +33,7 @@ class App {
33
33
  this.stopCallbacks = [];
34
34
  this.commitCallbacks = [];
35
35
  this.activityState = ActivityState.NotActive;
36
- this.version = '5.0.5-beta.1'; // TODO: version compatability check inside each plugin.
36
+ this.version = '5.0.5-beta.2'; // TODO: version compatability check inside each plugin.
37
37
  this._usingOldFetchPlugin = false;
38
38
  this.delay = 0;
39
39
  this.projectKey = projectKey;
package/cjs/index.js CHANGED
@@ -140,7 +140,7 @@ class API {
140
140
  // no-cors issue only with text/plain or not-set Content-Type
141
141
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
142
142
  req.send(JSON.stringify({
143
- trackerVersion: '5.0.5-beta.1',
143
+ trackerVersion: '5.0.5-beta.2',
144
144
  projectKey: options.projectKey,
145
145
  doNotTrack,
146
146
  // TODO: add precise reason (an exact API missing)
@@ -3,61 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const messages_gen_js_1 = require("../app/messages.gen.js");
4
4
  const utils_js_1 = require("../utils.js");
5
5
  function default_1(app, instance, opts, sanitize, stringify) {
6
+ app.debug.log('Openreplay: attaching axios spy to instance', instance);
6
7
  function captureResponseData(axiosResponseObj) {
7
8
  const { headers: reqHs, data: reqData, method, url } = axiosResponseObj.config;
8
9
  const { data: rData, headers: rHs, status: globStatus, response } = axiosResponseObj;
9
10
  const { data: resData, headers: resHs, status: resStatus } = response || {};
10
- const ihOpt = opts.ignoreHeaders;
11
- const isHIgnoring = Array.isArray(ihOpt) ? (name) => ihOpt.includes(name) : () => ihOpt;
12
- function writeHeader(hsObj, header) {
13
- if (!isHIgnoring(header[0])) {
14
- hsObj[header[0]] = header[1];
15
- }
16
- }
17
- let requestHs = {};
18
- let responseHs = {};
19
- if (reqHs.toJSON) {
20
- requestHs = reqHs.toJSON();
21
- }
22
- else if (reqHs instanceof Headers) {
23
- reqHs.forEach((v, n) => writeHeader(requestHs, [n, v]));
24
- }
25
- else if (Array.isArray(reqHs)) {
26
- reqHs.forEach((h) => writeHeader(requestHs, h));
27
- }
28
- else if (typeof reqHs === 'object') {
29
- Object.entries(reqHs).forEach((h) => writeHeader(requestHs, h));
30
- }
31
- const usedResHeader = resHs ? resHs : rHs;
32
- if (usedResHeader.toJSON) {
33
- responseHs = usedResHeader.toJSON();
34
- }
35
- else if (usedResHeader instanceof Headers) {
36
- usedResHeader.forEach((v, n) => writeHeader(responseHs, [n, v]));
37
- }
38
- else if (Array.isArray(usedResHeader)) {
39
- usedResHeader.forEach((h) => writeHeader(responseHs, h));
40
- }
41
- else if (typeof usedResHeader === 'object') {
42
- Object.entries(usedResHeader).forEach(([n, v]) => {
43
- if (!isHIgnoring(n))
44
- responseHs[n] = v;
45
- });
46
- }
47
11
  const reqResInfo = sanitize({
48
12
  url,
49
13
  method: method || '',
50
14
  status: globStatus || resStatus || 0,
51
15
  request: {
52
- headers: requestHs,
16
+ headers: reqHs.toJSON(),
53
17
  body: reqData,
54
18
  },
55
19
  response: {
56
- headers: responseHs,
20
+ headers: (resHs === null || resHs === void 0 ? void 0 : resHs.toJSON()) || rHs.toJSON(),
57
21
  body: resData || rData,
58
22
  },
59
23
  });
60
24
  if (!reqResInfo) {
25
+ app.debug.log('Openreplay: empty request/response info, skipping');
61
26
  return;
62
27
  }
63
28
  const requestStart = axiosResponseObj.config.__openreplay_timing;
@@ -65,6 +30,7 @@ function default_1(app, instance, opts, sanitize, stringify) {
65
30
  app.send((0, messages_gen_js_1.NetworkRequest)('xhr', String(method), String(reqResInfo.url), stringify(reqResInfo.request), stringify(reqResInfo.response), reqResInfo.status, requestStart + (0, utils_js_1.getTimeOrigin)(), duration));
66
31
  }
67
32
  function getStartTime(config) {
33
+ app.debug.log('Openreplay: capturing API request', config);
68
34
  config.__openreplay_timing = performance.now();
69
35
  if (opts.sessionTokenHeader) {
70
36
  const header = typeof opts.sessionTokenHeader === 'string'
@@ -87,7 +53,12 @@ function default_1(app, instance, opts, sanitize, stringify) {
87
53
  captureResponseData(error);
88
54
  return Promise.reject(error);
89
55
  }
90
- const reqInt = instance.interceptors.request.use(getStartTime, null, { synchronous: true });
56
+ function logRequestError(ev) {
57
+ app.debug.log('Openreplay: failed API request, skipping', ev);
58
+ }
59
+ const reqInt = instance.interceptors.request.use(getStartTime, logRequestError, {
60
+ synchronous: true,
61
+ });
91
62
  const resInt = instance.interceptors.response.use(captureNetworkRequest, captureNetworkError, {
92
63
  synchronous: true,
93
64
  });
package/lib/app/index.js CHANGED
@@ -30,7 +30,7 @@ export default class App {
30
30
  this.stopCallbacks = [];
31
31
  this.commitCallbacks = [];
32
32
  this.activityState = ActivityState.NotActive;
33
- this.version = '5.0.5-beta.1'; // TODO: version compatability check inside each plugin.
33
+ this.version = '5.0.5-beta.2'; // TODO: version compatability check inside each plugin.
34
34
  this._usingOldFetchPlugin = false;
35
35
  this.delay = 0;
36
36
  this.projectKey = projectKey;
package/lib/index.js CHANGED
@@ -135,7 +135,7 @@ export default class API {
135
135
  // no-cors issue only with text/plain or not-set Content-Type
136
136
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
137
137
  req.send(JSON.stringify({
138
- trackerVersion: '5.0.5-beta.1',
138
+ trackerVersion: '5.0.5-beta.2',
139
139
  projectKey: options.projectKey,
140
140
  doNotTrack,
141
141
  // TODO: add precise reason (an exact API missing)
@@ -1,61 +1,26 @@
1
1
  import { NetworkRequest } from '../app/messages.gen.js';
2
2
  import { getTimeOrigin } from '../utils.js';
3
3
  export default function (app, instance, opts, sanitize, stringify) {
4
+ app.debug.log('Openreplay: attaching axios spy to instance', instance);
4
5
  function captureResponseData(axiosResponseObj) {
5
6
  const { headers: reqHs, data: reqData, method, url } = axiosResponseObj.config;
6
7
  const { data: rData, headers: rHs, status: globStatus, response } = axiosResponseObj;
7
8
  const { data: resData, headers: resHs, status: resStatus } = response || {};
8
- const ihOpt = opts.ignoreHeaders;
9
- const isHIgnoring = Array.isArray(ihOpt) ? (name) => ihOpt.includes(name) : () => ihOpt;
10
- function writeHeader(hsObj, header) {
11
- if (!isHIgnoring(header[0])) {
12
- hsObj[header[0]] = header[1];
13
- }
14
- }
15
- let requestHs = {};
16
- let responseHs = {};
17
- if (reqHs.toJSON) {
18
- requestHs = reqHs.toJSON();
19
- }
20
- else if (reqHs instanceof Headers) {
21
- reqHs.forEach((v, n) => writeHeader(requestHs, [n, v]));
22
- }
23
- else if (Array.isArray(reqHs)) {
24
- reqHs.forEach((h) => writeHeader(requestHs, h));
25
- }
26
- else if (typeof reqHs === 'object') {
27
- Object.entries(reqHs).forEach((h) => writeHeader(requestHs, h));
28
- }
29
- const usedResHeader = resHs ? resHs : rHs;
30
- if (usedResHeader.toJSON) {
31
- responseHs = usedResHeader.toJSON();
32
- }
33
- else if (usedResHeader instanceof Headers) {
34
- usedResHeader.forEach((v, n) => writeHeader(responseHs, [n, v]));
35
- }
36
- else if (Array.isArray(usedResHeader)) {
37
- usedResHeader.forEach((h) => writeHeader(responseHs, h));
38
- }
39
- else if (typeof usedResHeader === 'object') {
40
- Object.entries(usedResHeader).forEach(([n, v]) => {
41
- if (!isHIgnoring(n))
42
- responseHs[n] = v;
43
- });
44
- }
45
9
  const reqResInfo = sanitize({
46
10
  url,
47
11
  method: method || '',
48
12
  status: globStatus || resStatus || 0,
49
13
  request: {
50
- headers: requestHs,
14
+ headers: reqHs.toJSON(),
51
15
  body: reqData,
52
16
  },
53
17
  response: {
54
- headers: responseHs,
18
+ headers: (resHs === null || resHs === void 0 ? void 0 : resHs.toJSON()) || rHs.toJSON(),
55
19
  body: resData || rData,
56
20
  },
57
21
  });
58
22
  if (!reqResInfo) {
23
+ app.debug.log('Openreplay: empty request/response info, skipping');
59
24
  return;
60
25
  }
61
26
  const requestStart = axiosResponseObj.config.__openreplay_timing;
@@ -63,6 +28,7 @@ export default function (app, instance, opts, sanitize, stringify) {
63
28
  app.send(NetworkRequest('xhr', String(method), String(reqResInfo.url), stringify(reqResInfo.request), stringify(reqResInfo.response), reqResInfo.status, requestStart + getTimeOrigin(), duration));
64
29
  }
65
30
  function getStartTime(config) {
31
+ app.debug.log('Openreplay: capturing API request', config);
66
32
  config.__openreplay_timing = performance.now();
67
33
  if (opts.sessionTokenHeader) {
68
34
  const header = typeof opts.sessionTokenHeader === 'string'
@@ -85,7 +51,12 @@ export default function (app, instance, opts, sanitize, stringify) {
85
51
  captureResponseData(error);
86
52
  return Promise.reject(error);
87
53
  }
88
- const reqInt = instance.interceptors.request.use(getStartTime, null, { synchronous: true });
54
+ function logRequestError(ev) {
55
+ app.debug.log('Openreplay: failed API request, skipping', ev);
56
+ }
57
+ const reqInt = instance.interceptors.request.use(getStartTime, logRequestError, {
58
+ synchronous: true,
59
+ });
89
60
  const resInt = instance.interceptors.response.use(captureNetworkRequest, captureNetworkError, {
90
61
  synchronous: true,
91
62
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "5.0.5-beta.1",
4
+ "version": "5.0.5-beta.2",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"