axios 1.1.3 → 1.3.4
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.
- package/CHANGELOG.md +312 -75
- package/{UPGRADE_GUIDE.md → MIGRATION_GUIDE.md} +1 -1
- package/README.md +64 -25
- package/dist/axios.js +888 -582
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +3191 -0
- package/dist/browser/axios.cjs.map +1 -0
- package/dist/esm/axios.js +889 -626
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +1001 -575
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +528 -0
- package/index.d.ts +116 -56
- package/index.js +12 -3
- package/lib/adapters/adapters.js +59 -0
- package/lib/adapters/http.js +118 -57
- package/lib/adapters/xhr.js +7 -4
- package/lib/axios.js +13 -3
- package/lib/core/Axios.js +10 -8
- package/lib/core/AxiosError.js +1 -1
- package/lib/core/AxiosHeaders.js +102 -80
- package/lib/core/dispatchRequest.js +7 -2
- package/lib/core/mergeConfig.js +50 -46
- package/lib/defaults/index.js +2 -21
- package/lib/env/classes/FormData.js +2 -2
- package/lib/env/data.js +1 -1
- package/lib/helpers/HttpStatusCode.js +71 -0
- package/lib/helpers/ZlibHeaderTransformStream.js +28 -0
- package/lib/helpers/formDataToStream.js +111 -0
- package/lib/helpers/readBlob.js +15 -0
- package/lib/helpers/speedometer.js +1 -1
- package/lib/helpers/toFormData.js +5 -15
- package/lib/platform/browser/classes/Blob.js +3 -0
- package/lib/platform/browser/classes/FormData.js +1 -1
- package/lib/platform/browser/index.js +21 -0
- package/lib/utils.js +107 -9
- package/package.json +86 -14
- package/bin/ssl_hotfix.js +0 -22
- package/gulpfile.js +0 -88
- package/karma.conf.cjs +0 -250
- package/lib/adapters/index.js +0 -33
- package/rollup.config.js +0 -90
- package/tsconfig.json +0 -14
- package/tslint.json +0 -6
package/index.d.ts
CHANGED
@@ -1,30 +1,23 @@
|
|
1
|
-
// TypeScript Version: 4.
|
1
|
+
// TypeScript Version: 4.7
|
2
2
|
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
3
|
-
type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
|
4
3
|
|
5
|
-
|
6
|
-
[
|
7
|
-
};
|
8
|
-
|
9
|
-
interface CommonHeaders {
|
10
|
-
common: AxiosHeaders;
|
4
|
+
interface RawAxiosHeaders {
|
5
|
+
[key: string]: AxiosHeaderValue;
|
11
6
|
}
|
12
7
|
|
13
|
-
type
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
type AxiosHeaderGetter = ((parser?: RegExp) => RegExpExecArray | null) |
|
18
|
-
((matcher?: AxiosHeaderMatcher) => AxiosHeaderValue);
|
8
|
+
type MethodsHeaders = Partial<{
|
9
|
+
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
10
|
+
} & {common: AxiosHeaders}>;
|
19
11
|
|
20
|
-
type
|
12
|
+
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
21
13
|
|
22
14
|
export class AxiosHeaders {
|
23
15
|
constructor(
|
24
|
-
headers?: RawAxiosHeaders | AxiosHeaders
|
25
|
-
defaultHeaders?: RawAxiosHeaders | AxiosHeaders
|
16
|
+
headers?: RawAxiosHeaders | AxiosHeaders
|
26
17
|
);
|
27
18
|
|
19
|
+
[key: string]: any;
|
20
|
+
|
28
21
|
set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
29
22
|
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
|
30
23
|
|
@@ -35,57 +28,87 @@ export class AxiosHeaders {
|
|
35
28
|
|
36
29
|
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
37
30
|
|
38
|
-
clear(): boolean;
|
31
|
+
clear(matcher?: AxiosHeaderMatcher): boolean;
|
39
32
|
|
40
33
|
normalize(format: boolean): AxiosHeaders;
|
41
34
|
|
35
|
+
concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
|
36
|
+
|
42
37
|
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
43
38
|
|
44
39
|
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
45
40
|
|
46
41
|
static accessor(header: string | string[]): AxiosHeaders;
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
43
|
+
static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
|
44
|
+
|
45
|
+
setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
46
|
+
getContentType(parser?: RegExp): RegExpExecArray | null;
|
47
|
+
getContentType(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
48
|
+
hasContentType(matcher?: AxiosHeaderMatcher): boolean;
|
49
|
+
|
50
|
+
setContentLength(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
51
|
+
getContentLength(parser?: RegExp): RegExpExecArray | null;
|
52
|
+
getContentLength(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
53
|
+
hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
setAccept(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
56
|
+
getAccept(parser?: RegExp): RegExpExecArray | null;
|
57
|
+
getAccept(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
58
|
+
hasAccept(matcher?: AxiosHeaderMatcher): boolean;
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
setUserAgent(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
61
|
+
getUserAgent(parser?: RegExp): RegExpExecArray | null;
|
62
|
+
getUserAgent(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
63
|
+
hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
|
59
64
|
|
60
|
-
|
61
|
-
|
62
|
-
|
65
|
+
setContentEncoding(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
66
|
+
getContentEncoding(parser?: RegExp): RegExpExecArray | null;
|
67
|
+
getContentEncoding(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
68
|
+
hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
|
63
69
|
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
setAuthorization(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
71
|
+
getAuthorization(parser?: RegExp): RegExpExecArray | null;
|
72
|
+
getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
|
73
|
+
hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
|
74
|
+
|
75
|
+
[Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
|
67
76
|
}
|
68
77
|
|
69
|
-
|
78
|
+
type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent' | 'Content-Encoding' | 'Authorization';
|
70
79
|
|
71
|
-
|
80
|
+
type ContentType = AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
|
72
81
|
|
73
|
-
export type
|
74
|
-
|
82
|
+
export type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & {
|
83
|
+
[Key in CommonRequestHeadersList]: AxiosHeaderValue;
|
84
|
+
} & {
|
85
|
+
'Content-Type': ContentType
|
75
86
|
}>;
|
76
87
|
|
88
|
+
export type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
|
89
|
+
|
90
|
+
type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
|
91
|
+
|
92
|
+
type RawCommonResponseHeaders = {
|
93
|
+
[Key in CommonResponseHeadersList]: AxiosHeaderValue;
|
94
|
+
} & {
|
95
|
+
"set-cookie": string[];
|
96
|
+
};
|
97
|
+
|
98
|
+
export type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
|
99
|
+
|
77
100
|
export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
78
101
|
|
79
102
|
export interface AxiosRequestTransformer {
|
80
|
-
(this:
|
103
|
+
(this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
81
104
|
}
|
82
105
|
|
83
106
|
export interface AxiosResponseTransformer {
|
84
|
-
(this:
|
107
|
+
(this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
85
108
|
}
|
86
109
|
|
87
110
|
export interface AxiosAdapter {
|
88
|
-
(config:
|
111
|
+
(config: InternalAxiosRequestConfig): AxiosPromise;
|
89
112
|
}
|
90
113
|
|
91
114
|
export interface AxiosBasicCredentials {
|
@@ -260,6 +283,8 @@ type MaxUploadRate = number;
|
|
260
283
|
|
261
284
|
type MaxDownloadRate = number;
|
262
285
|
|
286
|
+
type BrowserProgressEvent = any;
|
287
|
+
|
263
288
|
export interface AxiosProgressEvent {
|
264
289
|
loaded: number;
|
265
290
|
total?: number;
|
@@ -269,24 +294,29 @@ export interface AxiosProgressEvent {
|
|
269
294
|
estimated?: number;
|
270
295
|
upload?: boolean;
|
271
296
|
download?: boolean;
|
297
|
+
event?: BrowserProgressEvent;
|
272
298
|
}
|
273
299
|
|
274
300
|
type Milliseconds = number;
|
275
301
|
|
302
|
+
type AxiosAdapterName = 'xhr' | 'http' | string;
|
303
|
+
|
304
|
+
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
305
|
+
|
276
306
|
export interface AxiosRequestConfig<D = any> {
|
277
307
|
url?: string;
|
278
308
|
method?: Method | string;
|
279
309
|
baseURL?: string;
|
280
310
|
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
281
311
|
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
282
|
-
headers?: RawAxiosRequestHeaders;
|
312
|
+
headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
|
283
313
|
params?: any;
|
284
314
|
paramsSerializer?: ParamsSerializerOptions;
|
285
315
|
data?: D;
|
286
316
|
timeout?: Milliseconds;
|
287
317
|
timeoutErrorMessage?: string;
|
288
318
|
withCredentials?: boolean;
|
289
|
-
adapter?:
|
319
|
+
adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
|
290
320
|
auth?: AxiosBasicCredentials;
|
291
321
|
responseType?: ResponseType;
|
292
322
|
responseEncoding?: responseEncoding | string;
|
@@ -315,6 +345,13 @@ export interface AxiosRequestConfig<D = any> {
|
|
315
345
|
formSerializer?: FormSerializerOptions;
|
316
346
|
}
|
317
347
|
|
348
|
+
// Alias
|
349
|
+
export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
|
350
|
+
|
351
|
+
export interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
|
352
|
+
headers: AxiosRequestHeaders;
|
353
|
+
}
|
354
|
+
|
318
355
|
export interface HeadersDefaults {
|
319
356
|
common: RawAxiosRequestHeaders;
|
320
357
|
delete: RawAxiosRequestHeaders;
|
@@ -334,15 +371,15 @@ export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'hea
|
|
334
371
|
}
|
335
372
|
|
336
373
|
export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
337
|
-
headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
|
374
|
+
headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
|
338
375
|
}
|
339
376
|
|
340
|
-
export interface AxiosResponse<T = any, D = any>
|
377
|
+
export interface AxiosResponse<T = any, D = any> {
|
341
378
|
data: T;
|
342
379
|
status: number;
|
343
380
|
statusText: string;
|
344
381
|
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
345
|
-
config:
|
382
|
+
config: InternalAxiosRequestConfig<D>;
|
346
383
|
request?: any;
|
347
384
|
}
|
348
385
|
|
@@ -350,12 +387,12 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|
350
387
|
constructor(
|
351
388
|
message?: string,
|
352
389
|
code?: string,
|
353
|
-
config?:
|
390
|
+
config?: InternalAxiosRequestConfig<D>,
|
354
391
|
request?: any,
|
355
392
|
response?: AxiosResponse<T, D>
|
356
393
|
);
|
357
394
|
|
358
|
-
config?:
|
395
|
+
config?: InternalAxiosRequestConfig<D>;
|
359
396
|
code?: string;
|
360
397
|
request?: any;
|
361
398
|
response?: AxiosResponse<T, D>;
|
@@ -363,6 +400,14 @@ export class AxiosError<T = unknown, D = any> extends Error {
|
|
363
400
|
status?: number;
|
364
401
|
toJSON: () => object;
|
365
402
|
cause?: Error;
|
403
|
+
static from<T = unknown, D = any>(
|
404
|
+
error: Error | unknown,
|
405
|
+
code?: string,
|
406
|
+
config?: InternalAxiosRequestConfig<D>,
|
407
|
+
request?: any,
|
408
|
+
response?: AxiosResponse<T, D>,
|
409
|
+
customProps?: object,
|
410
|
+
): AxiosError<T, D>;
|
366
411
|
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
367
412
|
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
368
413
|
static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
@@ -412,11 +457,11 @@ export interface CancelTokenSource {
|
|
412
457
|
|
413
458
|
export interface AxiosInterceptorOptions {
|
414
459
|
synchronous?: boolean;
|
415
|
-
runWhen?: (config:
|
460
|
+
runWhen?: (config: InternalAxiosRequestConfig) => boolean;
|
416
461
|
}
|
417
462
|
|
418
463
|
export interface AxiosInterceptorManager<V> {
|
419
|
-
use(onFulfilled?: (value: V) => V | Promise<V
|
464
|
+
use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions): number;
|
420
465
|
eject(id: number): void;
|
421
466
|
clear(): void;
|
422
467
|
}
|
@@ -425,7 +470,7 @@ export class Axios {
|
|
425
470
|
constructor(config?: AxiosRequestConfig);
|
426
471
|
defaults: AxiosDefaults;
|
427
472
|
interceptors: {
|
428
|
-
request: AxiosInterceptorManager<
|
473
|
+
request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
|
429
474
|
response: AxiosInterceptorManager<AxiosResponse>;
|
430
475
|
};
|
431
476
|
getUri(config?: AxiosRequestConfig): string;
|
@@ -463,19 +508,34 @@ export interface GenericHTMLFormElement {
|
|
463
508
|
submit(): void;
|
464
509
|
}
|
465
510
|
|
511
|
+
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
512
|
+
|
513
|
+
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
514
|
+
|
515
|
+
export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
516
|
+
|
517
|
+
export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
518
|
+
|
519
|
+
export function isCancel(value: any): value is Cancel;
|
520
|
+
|
521
|
+
export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
522
|
+
|
466
523
|
export interface AxiosStatic extends AxiosInstance {
|
467
524
|
create(config?: CreateAxiosDefaults): AxiosInstance;
|
468
525
|
Cancel: CancelStatic;
|
469
526
|
CancelToken: CancelTokenStatic;
|
470
527
|
Axios: typeof Axios;
|
471
528
|
AxiosError: typeof AxiosError;
|
529
|
+
HttpStatusCode: typeof HttpStatusCode;
|
472
530
|
readonly VERSION: string;
|
473
|
-
isCancel
|
474
|
-
all
|
475
|
-
spread
|
476
|
-
isAxiosError
|
477
|
-
toFormData
|
478
|
-
formToJSON
|
531
|
+
isCancel: typeof isCancel;
|
532
|
+
all: typeof all;
|
533
|
+
spread: typeof spread;
|
534
|
+
isAxiosError: typeof isAxiosError;
|
535
|
+
toFormData: typeof toFormData;
|
536
|
+
formToJSON: typeof formToJSON;
|
537
|
+
CanceledError: typeof CanceledError;
|
538
|
+
AxiosHeaders: typeof AxiosHeaders;
|
479
539
|
}
|
480
540
|
|
481
541
|
declare const axios: AxiosStatic;
|
package/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import axios from './lib/axios.js';
|
2
2
|
|
3
|
+
// This module is intended to unwrap Axios default export as named.
|
3
4
|
// Keep top-level export same with static properties
|
4
5
|
// so that it can keep same with es module or cjs
|
5
6
|
const {
|
@@ -13,11 +14,15 @@ const {
|
|
13
14
|
Cancel,
|
14
15
|
isAxiosError,
|
15
16
|
spread,
|
16
|
-
toFormData
|
17
|
+
toFormData,
|
18
|
+
AxiosHeaders,
|
19
|
+
HttpStatusCode,
|
20
|
+
formToJSON,
|
21
|
+
mergeConfig
|
17
22
|
} = axios;
|
18
23
|
|
19
|
-
export default axios;
|
20
24
|
export {
|
25
|
+
axios as default,
|
21
26
|
Axios,
|
22
27
|
AxiosError,
|
23
28
|
CanceledError,
|
@@ -28,5 +33,9 @@ export {
|
|
28
33
|
Cancel,
|
29
34
|
isAxiosError,
|
30
35
|
spread,
|
31
|
-
toFormData
|
36
|
+
toFormData,
|
37
|
+
AxiosHeaders,
|
38
|
+
HttpStatusCode,
|
39
|
+
formToJSON,
|
40
|
+
mergeConfig
|
32
41
|
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import utils from '../utils.js';
|
2
|
+
import httpAdapter from './http.js';
|
3
|
+
import xhrAdapter from './xhr.js';
|
4
|
+
import AxiosError from "../core/AxiosError.js";
|
5
|
+
|
6
|
+
const knownAdapters = {
|
7
|
+
http: httpAdapter,
|
8
|
+
xhr: xhrAdapter
|
9
|
+
}
|
10
|
+
|
11
|
+
utils.forEach(knownAdapters, (fn, value) => {
|
12
|
+
if(fn) {
|
13
|
+
try {
|
14
|
+
Object.defineProperty(fn, 'name', {value});
|
15
|
+
} catch (e) {
|
16
|
+
// eslint-disable-next-line no-empty
|
17
|
+
}
|
18
|
+
Object.defineProperty(fn, 'adapterName', {value});
|
19
|
+
}
|
20
|
+
});
|
21
|
+
|
22
|
+
export default {
|
23
|
+
getAdapter: (adapters) => {
|
24
|
+
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
25
|
+
|
26
|
+
const {length} = adapters;
|
27
|
+
let nameOrAdapter;
|
28
|
+
let adapter;
|
29
|
+
|
30
|
+
for (let i = 0; i < length; i++) {
|
31
|
+
nameOrAdapter = adapters[i];
|
32
|
+
if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
if (!adapter) {
|
38
|
+
if (adapter === false) {
|
39
|
+
throw new AxiosError(
|
40
|
+
`Adapter ${nameOrAdapter} is not supported by the environment`,
|
41
|
+
'ERR_NOT_SUPPORT'
|
42
|
+
);
|
43
|
+
}
|
44
|
+
|
45
|
+
throw new Error(
|
46
|
+
utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
|
47
|
+
`Adapter '${nameOrAdapter}' is not available in the build` :
|
48
|
+
`Unknown adapter '${nameOrAdapter}'`
|
49
|
+
);
|
50
|
+
}
|
51
|
+
|
52
|
+
if (!utils.isFunction(adapter)) {
|
53
|
+
throw new TypeError('adapter is not a function');
|
54
|
+
}
|
55
|
+
|
56
|
+
return adapter;
|
57
|
+
},
|
58
|
+
adapters: knownAdapters
|
59
|
+
}
|