openreplay/tracker/tracker-axios
dependabot[bot] 72325c6991
chore(deps): bump the npm_and_yarn group across 4 directories with 12 updates (#2657)
Bumps the npm_and_yarn group with 6 updates in the /frontend directory:

| Package | From | To |
| --- | --- | --- |
| [postcss](https://github.com/postcss/postcss) | `8.4.38` | `8.4.39` |
| [webpack](https://github.com/webpack/webpack) | `5.92.1` | `5.94.0` |
| [dompurify](https://github.com/cure53/DOMPurify) | `2.5.0` | `2.5.7` |
| [elliptic](https://github.com/indutny/elliptic) | `6.5.5` | `6.5.7` |
| [express](https://github.com/expressjs/express) | `4.19.2` | `4.21.1` |
| [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) | `4.3.6` | `4.5.0` |

Bumps the npm_and_yarn group with 3 updates in the /spot directory: [postcss](https://github.com/postcss/postcss), [rollup](https://github.com/rollup/rollup) and [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite).
Bumps the npm_and_yarn group with 1 update in the /tracker/tracker-axios directory: [axios](https://github.com/axios/axios).
Bumps the npm_and_yarn group with 1 update in the /tracker/tracker-testing-playground directory: [axios](https://github.com/axios/axios).


Updates `postcss` from 8.4.38 to 8.4.39
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.4.38...8.4.39)

Updates `webpack` from 5.92.1 to 5.94.0
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v5.92.1...v5.94.0)

Updates `dompurify` from 2.5.0 to 2.5.7
- [Release notes](https://github.com/cure53/DOMPurify/releases)
- [Commits](https://github.com/cure53/DOMPurify/compare/2.5.0...2.5.7)

Updates `elliptic` from 6.5.5 to 6.5.7
- [Commits](https://github.com/indutny/elliptic/compare/v6.5.5...v6.5.7)

Updates `express` from 4.19.2 to 4.21.1
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/4.21.1/History.md)
- [Commits](https://github.com/expressjs/express/compare/4.19.2...4.21.1)

Updates `fast-xml-parser` from 4.3.6 to 4.5.0
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](https://github.com/NaturalIntelligence/fast-xml-parser/compare/v4.3.6...v4.5.0)

Updates `path-to-regexp` from 0.1.7 to 0.1.10
- [Release notes](https://github.com/pillarjs/path-to-regexp/releases)
- [Changelog](https://github.com/pillarjs/path-to-regexp/blob/master/History.md)
- [Commits](https://github.com/pillarjs/path-to-regexp/compare/v0.1.7...v0.1.10)

Updates `send` from 0.18.0 to 0.19.0
- [Release notes](https://github.com/pillarjs/send/releases)
- [Changelog](https://github.com/pillarjs/send/blob/master/HISTORY.md)
- [Commits](https://github.com/pillarjs/send/compare/0.18.0...0.19.0)

Updates `serve-static` from 1.15.0 to 1.16.2
- [Release notes](https://github.com/expressjs/serve-static/releases)
- [Changelog](https://github.com/expressjs/serve-static/blob/v1.16.2/HISTORY.md)
- [Commits](https://github.com/expressjs/serve-static/compare/v1.15.0...v1.16.2)

Updates `postcss` from 8.4.41 to 8.4.47
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.4.38...8.4.39)

Updates `rollup` from 4.21.0 to 4.24.0
- [Release notes](https://github.com/rollup/rollup/releases)
- [Changelog](https://github.com/rollup/rollup/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rollup/rollup/compare/v4.21.0...v4.24.0)

Updates `vite` from 5.4.2 to 5.4.9
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/v5.4.9/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v5.4.9/packages/vite)

Updates `axios` from 0.26.1 to 1.7.7
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.26.1...v1.7.7)

Updates `axios` from 0.27.2 to 1.7.7
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.26.1...v1.7.7)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: direct:development
  dependency-group: npm_and_yarn
- dependency-name: webpack
  dependency-type: direct:development
  dependency-group: npm_and_yarn
- dependency-name: dompurify
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: elliptic
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: express
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: fast-xml-parser
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: path-to-regexp
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: send
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: serve-static
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: postcss
  dependency-type: direct:production
  dependency-group: npm_and_yarn
- dependency-name: rollup
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: vite
  dependency-type: indirect
  dependency-group: npm_and_yarn
- dependency-name: axios
  dependency-type: direct:development
  dependency-group: npm_and_yarn
- dependency-name: axios
  dependency-type: direct:production
  dependency-group: npm_and_yarn
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-10-18 13:51:43 +02:00
..
src fix(tracker-fetch;tracker-axios):prevent multiple plugin use on the same app/axios instance 2022-12-16 12:10:14 +01:00
.gitignore v1.1.0 (#31) 2021-06-11 23:31:29 +05:30
.npmignore v1.1.0 (#31) 2021-06-11 23:31:29 +05:30
LICENSE MIT license for OpenReplay protocol 2022-08-30 19:04:32 +02:00
package.json chore(deps): bump the npm_and_yarn group across 4 directories with 12 updates (#2657) 2024-10-18 13:51:43 +02:00
README.md tracker doc fix 2024-07-31 09:42:12 +02:00
tsconfig-cjs.json v1.1.0 (#31) 2021-06-11 23:31:29 +05:30
tsconfig.json feat(tracker-axios): 3.4.0 capture headers 2021-10-01 19:47:34 +02:00

this plugin is deprecated, all network tracking apis are moved into the main tracker codebase


OpenReplay Tracker Axios plugin

Tracker plugin to support tracking of the Axios requests.

Installation

npm i @openreplay/tracker-axios

Usage

Initialize the @openreplay/tracker package as usual and load the plugin into it.

import Tracker from '@openreplay/tracker';
import trackerAxios from '@openreplay/tracker-axios';

const tracker = new Tracker({
  projectKey: YOUR_PROJECT_KEY,
});
// .start() returns a promise
tracker.start().then(sessionData => ... ).catch(e => ... )

tracker.use(trackerAxios({ /* options here*/ }));

Options:

{
	instance: AxiosInstance;                       // default: axios
  failuresOnly: boolean;                         // default: false
  captureWhen: (AxiosRequestConfig) => boolean;  // default: () => true
  sessionTokenHeader: string;                    // default: undefined
  ignoreHeaders: Array<string> | boolean,        // default [ 'Cookie', 'Set-Cookie', 'Authorization' ]
  sanitiser: (RequestResponseData) => RequestResponseData | null, // default: undefined

}

By default plugin connects to the static axios instance, but you can specify one with the instance option.

Set failuresOnly option to true if you want to record only failed requests, when the axios' promise is rejected. You can also regulate axios failing behaviour with the validateStatus option.

captureWhen parameter allows you to set a filter on request should be captured. The function will be called with the axios config object and expected to return true or false.

In case you use OpenReplay integrations (sentry, bugsnag or others), you can use sessionTokenHeader option to specify the header name. This header will be appended automatically to the each axios request and will contain OpenReplay session identificator value.

You can define list of headers that you don't want to capture with the ignoreHeaders options. Set its value to false if you want to catch them all (true if opposite). By default plugin ignores the list of headers that might be sensetive such as [ 'Cookie', 'Set-Cookie', 'Authorization' ].

Sanitise sensitive data from fetch request/response or ignore request comletely with sanitiser. You can redact fields on the request object by modifying then returning it from the function:

interface RequestData {
  body: BodyInit | null | undefined; // whatewer you've put in the init.body in fetch(url, init)
  headers: Record<string, string>;
}

interface ResponseData {
  body: string | Object | null;  // Object if response is of JSON type
  headers: Record<string, string>;
}

interface RequestResponseData {
  readonly status: number;
  readonly method: string;
  url: string;
  request: RequestData;
  response: ResponseData;
}

sanitiser: (data: RequestResponseData) => { // sanitise the body or headers
  if (data.url === "/auth") {
    data.request.body = null
  }

  if (data.request.headers['x-auth-token']) { // can also use ignoreHeaders option instead
    data.request.headers['x-auth-token'] = 'SANITISED';
  }

  // Sanitise response
  if (data.status < 400 && data.response.body.token) {
    data.response.body.token = "<TOKEN>"  
  }

  return data
}

// OR

sanitiser: data => { // ignore requests that start with /secure
  if (data.url.startsWith("/secure")) {
    return null
  }
  return data
}

// OR

sanitiser: data => { // sanitise request url: replace all numbers
  data.url = data.url.replace(/\d/g, "*")
  return data
}