axios 1.6.7 → 1.7.0-beta.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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

@@ -0,0 +1,57 @@
1
+ import platform from "../platform/index.js";
2
+ import utils from "../utils.js";
3
+ import isURLSameOrigin from "./isURLSameOrigin.js";
4
+ import cookies from "./cookies.js";
5
+ import buildFullPath from "../core/buildFullPath.js";
6
+ import mergeConfig from "../core/mergeConfig.js";
7
+ import AxiosHeaders from "../core/AxiosHeaders.js";
8
+ import buildURL from "./buildURL.js";
9
+
10
+ export default (config) => {
11
+ const newConfig = mergeConfig({}, config);
12
+
13
+ let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
14
+
15
+ newConfig.headers = headers = AxiosHeaders.from(headers);
16
+
17
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
18
+
19
+ // HTTP basic authentication
20
+ if (auth) {
21
+ headers.set('Authorization', 'Basic ' +
22
+ btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
23
+ );
24
+ }
25
+
26
+ let contentType;
27
+
28
+ if (utils.isFormData(data)) {
29
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
30
+ headers.setContentType(undefined); // Let the browser set it
31
+ } else if ((contentType = headers.getContentType()) !== false) {
32
+ // fix semicolon duplication issue for ReactNative FormData implementation
33
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
34
+ headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
35
+ }
36
+ }
37
+
38
+ // Add xsrf header
39
+ // This is only done if running in a standard browser environment.
40
+ // Specifically not if we're in a web worker, or react-native.
41
+
42
+ if (platform.hasStandardBrowserEnv) {
43
+ withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
44
+
45
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
46
+ // Add xsrf header
47
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
48
+
49
+ if (xsrfValue) {
50
+ headers.set(xsrfHeaderName, xsrfValue);
51
+ }
52
+ }
53
+ }
54
+
55
+ return newConfig;
56
+ }
57
+
@@ -10,7 +10,9 @@ function throttle(fn, freq) {
10
10
  let timestamp = 0;
11
11
  const threshold = 1000 / freq;
12
12
  let timer = null;
13
- return function throttled(force, args) {
13
+ return function throttled() {
14
+ const force = this === true;
15
+
14
16
  const now = Date.now();
15
17
  if (force || now - timestamp > threshold) {
16
18
  if (timer) {
@@ -18,13 +20,13 @@ function throttle(fn, freq) {
18
20
  timer = null;
19
21
  }
20
22
  timestamp = now;
21
- return fn.apply(null, args);
23
+ return fn.apply(null, arguments);
22
24
  }
23
25
  if (!timer) {
24
26
  timer = setTimeout(() => {
25
27
  timer = null;
26
28
  timestamp = Date.now();
27
- return fn.apply(null, args);
29
+ return fn.apply(null, arguments);
28
30
  }, threshold - (now - timestamp));
29
31
  }
30
32
  };
@@ -0,0 +1,56 @@
1
+
2
+ export const streamChunk = function* (chunk, chunkSize) {
3
+ let len = chunk.byteLength;
4
+
5
+ if (!chunkSize || len < chunkSize) {
6
+ yield chunk;
7
+ return;
8
+ }
9
+
10
+ let pos = 0;
11
+ let end;
12
+
13
+ while (pos < len) {
14
+ end = pos + chunkSize;
15
+ yield chunk.slice(pos, end);
16
+ pos = end;
17
+ }
18
+ }
19
+
20
+ const encoder = new TextEncoder();
21
+
22
+ export const readBytes = async function* (iterable, chunkSize) {
23
+ for await (const chunk of iterable) {
24
+ yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encoder.encode(String(chunk))), chunkSize);
25
+ }
26
+ }
27
+
28
+ export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
29
+ const iterator = readBytes(stream, chunkSize);
30
+
31
+ let bytes = 0;
32
+
33
+ return new ReadableStream({
34
+ type: 'bytes',
35
+
36
+ async pull(controller) {
37
+ const {done, value} = await iterator.next();
38
+
39
+ if (done) {
40
+ controller.close();
41
+ onFinish();
42
+ return;
43
+ }
44
+
45
+ let len = value.byteLength;
46
+ onProgress && onProgress(bytes += len);
47
+ controller.enqueue(new Uint8Array(value));
48
+ },
49
+ cancel(reason) {
50
+ onFinish(reason);
51
+ return iterator.return();
52
+ }
53
+ }, {
54
+ highWaterMark: 2
55
+ })
56
+ }
@@ -40,8 +40,11 @@ const hasStandardBrowserWebWorkerEnv = (() => {
40
40
  );
41
41
  })();
42
42
 
43
+ const origin = hasBrowserEnv && window.location.href || 'http://localhost';
44
+
43
45
  export {
44
46
  hasBrowserEnv,
45
47
  hasStandardBrowserWebWorkerEnv,
46
- hasStandardBrowserEnv
48
+ hasStandardBrowserEnv,
49
+ origin
47
50
  }
package/lib/utils.js CHANGED
@@ -209,6 +209,8 @@ const isFormData = (thing) => {
209
209
  */
210
210
  const isURLSearchParams = kindOfTest('URLSearchParams');
211
211
 
212
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
213
+
212
214
  /**
213
215
  * Trim excess whitespace off the beginning and end of a string
214
216
  *
@@ -597,8 +599,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
597
599
  const noop = () => {}
598
600
 
599
601
  const toFiniteNumber = (value, defaultValue) => {
600
- value = +value;
601
- return Number.isFinite(value) ? value : defaultValue;
602
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
602
603
  }
603
604
 
604
605
  const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
@@ -679,6 +680,10 @@ export default {
679
680
  isBoolean,
680
681
  isObject,
681
682
  isPlainObject,
683
+ isReadableStream,
684
+ isRequest,
685
+ isResponse,
686
+ isHeaders,
682
687
  isUndefined,
683
688
  isDate,
684
689
  isFile,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.6.7",
3
+ "version": "1.7.0-beta.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -80,41 +80,41 @@
80
80
  },
81
81
  "homepage": "https://axios-http.com",
82
82
  "devDependencies": {
83
- "@babel/core": "^7.18.2",
84
- "@babel/preset-env": "^7.18.2",
85
- "@commitlint/cli": "^17.3.0",
86
- "@commitlint/config-conventional": "^17.3.0",
83
+ "@babel/core": "^7.23.9",
84
+ "@babel/preset-env": "^7.23.9",
85
+ "@commitlint/cli": "^17.8.1",
86
+ "@commitlint/config-conventional": "^17.8.1",
87
87
  "@release-it/conventional-changelog": "^5.1.1",
88
88
  "@rollup/plugin-babel": "^5.3.1",
89
89
  "@rollup/plugin-commonjs": "^15.1.0",
90
90
  "@rollup/plugin-json": "^4.1.0",
91
- "@rollup/plugin-multi-entry": "^4.0.0",
91
+ "@rollup/plugin-multi-entry": "^4.1.0",
92
92
  "@rollup/plugin-node-resolve": "^9.0.0",
93
- "abortcontroller-polyfill": "^1.7.3",
93
+ "abortcontroller-polyfill": "^1.7.5",
94
94
  "auto-changelog": "^2.4.0",
95
- "body-parser": "^1.20.0",
96
- "chalk": "^5.2.0",
95
+ "body-parser": "^1.20.2",
96
+ "chalk": "^5.3.0",
97
97
  "coveralls": "^3.1.1",
98
98
  "cross-env": "^7.0.3",
99
99
  "dev-null": "^0.1.1",
100
100
  "dtslint": "^4.2.1",
101
101
  "es6-promise": "^4.2.8",
102
- "eslint": "^8.17.0",
103
- "express": "^4.18.1",
104
- "formdata-node": "^5.0.0",
105
- "formidable": "^2.0.1",
102
+ "eslint": "^8.56.0",
103
+ "express": "^4.18.2",
104
+ "formdata-node": "^5.0.1",
105
+ "formidable": "^2.1.2",
106
106
  "fs-extra": "^10.1.0",
107
107
  "get-stream": "^3.0.0",
108
108
  "gulp": "^4.0.2",
109
109
  "gzip-size": "^7.0.0",
110
- "handlebars": "^4.7.7",
111
- "husky": "^8.0.2",
110
+ "handlebars": "^4.7.8",
111
+ "husky": "^8.0.3",
112
112
  "istanbul-instrumenter-loader": "^3.0.1",
113
- "jasmine-core": "^2.4.1",
113
+ "jasmine-core": "^2.99.1",
114
114
  "karma": "^6.3.17",
115
- "karma-chrome-launcher": "^3.1.1",
115
+ "karma-chrome-launcher": "^3.2.0",
116
116
  "karma-firefox-launcher": "^2.1.2",
117
- "karma-jasmine": "^1.1.1",
117
+ "karma-jasmine": "^1.1.2",
118
118
  "karma-jasmine-ajax": "^0.1.13",
119
119
  "karma-rollup-preprocessor": "^7.0.8",
120
120
  "karma-safari-launcher": "^1.0.0",
@@ -122,12 +122,12 @@
122
122
  "karma-sinon": "^1.0.5",
123
123
  "karma-sourcemap-loader": "^0.3.8",
124
124
  "memoizee": "^0.4.15",
125
- "minimist": "^1.2.7",
126
- "mocha": "^10.0.0",
125
+ "minimist": "^1.2.8",
126
+ "mocha": "^10.3.0",
127
127
  "multer": "^1.4.4",
128
- "pretty-bytes": "^6.0.0",
129
- "release-it": "^15.5.1",
130
- "rollup": "^2.67.0",
128
+ "pretty-bytes": "^6.1.1",
129
+ "release-it": "^15.11.0",
130
+ "rollup": "^2.79.1",
131
131
  "rollup-plugin-auto-external": "^2.0.0",
132
132
  "rollup-plugin-bundle-size": "^1.0.3",
133
133
  "rollup-plugin-terser": "^7.0.2",
@@ -135,7 +135,8 @@
135
135
  "stream-throttle": "^0.1.3",
136
136
  "string-replace-async": "^3.0.2",
137
137
  "terser-webpack-plugin": "^4.2.3",
138
- "typescript": "^4.8.4"
138
+ "typescript": "^4.9.5",
139
+ "@rollup/plugin-alias": "^5.1.0"
139
140
  },
140
141
  "browser": {
141
142
  "./lib/adapters/http.js": "./lib/helpers/null.js",
@@ -146,7 +147,7 @@
146
147
  "unpkg": "dist/axios.min.js",
147
148
  "typings": "./index.d.ts",
148
149
  "dependencies": {
149
- "follow-redirects": "^1.15.4",
150
+ "follow-redirects": "^1.15.6",
150
151
  "form-data": "^4.0.0",
151
152
  "proxy-from-env": "^1.1.0"
152
153
  },