axios 1.1.3 → 1.2.0-alpha.1
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 +123 -74
- package/{UPGRADE_GUIDE.md → MIGRATION_GUIDE.md} +1 -1
- package/README.md +55 -20
- package/dist/axios.js +356 -211
- 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 +3010 -0
- package/dist/browser/axios.cjs.map +1 -0
- package/dist/esm/axios.js +296 -216
- 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 +224 -166
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +490 -0
- package/index.d.ts +28 -10
- package/index.js +8 -3
- package/karma.conf.cjs +1 -1
- package/lib/adapters/http.js +2 -2
- package/lib/adapters/xhr.js +2 -1
- package/lib/axios.js +7 -3
- package/lib/core/Axios.js +10 -8
- package/lib/core/AxiosHeaders.js +82 -76
- package/lib/core/dispatchRequest.js +4 -0
- package/lib/core/mergeConfig.js +50 -46
- package/lib/defaults/index.js +1 -1
- package/lib/env/data.js +1 -1
- package/lib/utils.js +36 -8
- package/package.json +13 -6
- package/rollup.config.js +37 -10
- package/tsconfig.json +2 -7
- package/tslint.json +6 -1
package/index.d.cts
ADDED
@@ -0,0 +1,490 @@
|
|
1
|
+
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
2
|
+
type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
|
3
|
+
|
4
|
+
type MethodsHeaders = {
|
5
|
+
[Key in axios.Method as Lowercase<Key>]: AxiosHeaders;
|
6
|
+
};
|
7
|
+
|
8
|
+
interface CommonHeaders {
|
9
|
+
common: AxiosHeaders;
|
10
|
+
}
|
11
|
+
|
12
|
+
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
13
|
+
|
14
|
+
type AxiosHeaderSetter = (value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher) => AxiosHeaders;
|
15
|
+
|
16
|
+
type AxiosHeaderGetter = ((parser?: RegExp) => RegExpExecArray | null) |
|
17
|
+
((matcher?: AxiosHeaderMatcher) => AxiosHeaderValue);
|
18
|
+
|
19
|
+
type AxiosHeaderTester = (matcher?: AxiosHeaderMatcher) => boolean;
|
20
|
+
|
21
|
+
type MaxUploadRate = number;
|
22
|
+
|
23
|
+
type MaxDownloadRate = number;
|
24
|
+
|
25
|
+
type Milliseconds = number;
|
26
|
+
|
27
|
+
declare class AxiosHeaders {
|
28
|
+
constructor(
|
29
|
+
headers?: RawAxiosHeaders | AxiosHeaders,
|
30
|
+
defaultHeaders?: RawAxiosHeaders | AxiosHeaders
|
31
|
+
);
|
32
|
+
|
33
|
+
set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
34
|
+
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
|
35
|
+
|
36
|
+
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
37
|
+
get(headerName: string, matcher?: true | AxiosHeaderMatcher): AxiosHeaderValue;
|
38
|
+
|
39
|
+
has(header: string, matcher?: true | AxiosHeaderMatcher): boolean;
|
40
|
+
|
41
|
+
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
42
|
+
|
43
|
+
clear(): boolean;
|
44
|
+
|
45
|
+
normalize(format: boolean): AxiosHeaders;
|
46
|
+
|
47
|
+
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
48
|
+
|
49
|
+
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
50
|
+
|
51
|
+
static accessor(header: string | string[]): AxiosHeaders;
|
52
|
+
|
53
|
+
setContentType: AxiosHeaderSetter;
|
54
|
+
getContentType: AxiosHeaderGetter;
|
55
|
+
hasContentType: AxiosHeaderTester;
|
56
|
+
|
57
|
+
setContentLength: AxiosHeaderSetter;
|
58
|
+
getContentLength: AxiosHeaderGetter;
|
59
|
+
hasContentLength: AxiosHeaderTester;
|
60
|
+
|
61
|
+
setAccept: AxiosHeaderSetter;
|
62
|
+
getAccept: AxiosHeaderGetter;
|
63
|
+
hasAccept: AxiosHeaderTester;
|
64
|
+
|
65
|
+
setUserAgent: AxiosHeaderSetter;
|
66
|
+
getUserAgent: AxiosHeaderGetter;
|
67
|
+
hasUserAgent: AxiosHeaderTester;
|
68
|
+
|
69
|
+
setContentEncoding: AxiosHeaderSetter;
|
70
|
+
getContentEncoding: AxiosHeaderGetter;
|
71
|
+
hasContentEncoding: AxiosHeaderTester;
|
72
|
+
}
|
73
|
+
|
74
|
+
declare class AxiosError<T = unknown, D = any> extends Error {
|
75
|
+
constructor(
|
76
|
+
message?: string,
|
77
|
+
code?: string,
|
78
|
+
config?: axios.AxiosRequestConfig<D>,
|
79
|
+
request?: any,
|
80
|
+
response?: axios.AxiosResponse<T, D>
|
81
|
+
);
|
82
|
+
|
83
|
+
config?: axios.AxiosRequestConfig<D>;
|
84
|
+
code?: string;
|
85
|
+
request?: any;
|
86
|
+
response?: axios.AxiosResponse<T, D>;
|
87
|
+
isAxiosError: boolean;
|
88
|
+
status?: number;
|
89
|
+
toJSON: () => object;
|
90
|
+
cause?: Error;
|
91
|
+
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
92
|
+
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
93
|
+
static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
|
94
|
+
static readonly ERR_NETWORK = "ERR_NETWORK";
|
95
|
+
static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
|
96
|
+
static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
97
|
+
static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
98
|
+
static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
|
99
|
+
static readonly ERR_INVALID_URL = "ERR_INVALID_URL";
|
100
|
+
static readonly ERR_CANCELED = "ERR_CANCELED";
|
101
|
+
static readonly ECONNABORTED = "ECONNABORTED";
|
102
|
+
static readonly ETIMEDOUT = "ETIMEDOUT";
|
103
|
+
}
|
104
|
+
|
105
|
+
declare class CanceledError<T> extends AxiosError<T> {
|
106
|
+
}
|
107
|
+
|
108
|
+
declare class Axios {
|
109
|
+
constructor(config?: axios.AxiosRequestConfig);
|
110
|
+
defaults: axios.AxiosDefaults;
|
111
|
+
interceptors: {
|
112
|
+
request: axios.AxiosInterceptorManager<axios.AxiosRequestConfig>;
|
113
|
+
response: axios.AxiosInterceptorManager<axios.AxiosResponse>;
|
114
|
+
};
|
115
|
+
getUri(config?: axios.AxiosRequestConfig): string;
|
116
|
+
request<T = any, R = axios.AxiosResponse<T>, D = any>(config: axios.AxiosRequestConfig<D>): Promise<R>;
|
117
|
+
get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
118
|
+
delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
119
|
+
head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
120
|
+
options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
121
|
+
post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
122
|
+
put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
123
|
+
patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
124
|
+
postForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
125
|
+
putForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
126
|
+
patchForm<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: D, config?: axios.AxiosRequestConfig<D>): Promise<R>;
|
127
|
+
}
|
128
|
+
|
129
|
+
declare enum HttpStatusCode {
|
130
|
+
Continue = 100,
|
131
|
+
SwitchingProtocols = 101,
|
132
|
+
Processing = 102,
|
133
|
+
EarlyHints = 103,
|
134
|
+
Ok = 200,
|
135
|
+
Created = 201,
|
136
|
+
Accepted = 202,
|
137
|
+
NonAuthoritativeInformation = 203,
|
138
|
+
NoContent = 204,
|
139
|
+
ResetContent = 205,
|
140
|
+
PartialContent = 206,
|
141
|
+
MultiStatus = 207,
|
142
|
+
AlreadyReported = 208,
|
143
|
+
ImUsed = 226,
|
144
|
+
MultipleChoices = 300,
|
145
|
+
MovedPermanently = 301,
|
146
|
+
Found = 302,
|
147
|
+
SeeOther = 303,
|
148
|
+
NotModified = 304,
|
149
|
+
UseProxy = 305,
|
150
|
+
Unused = 306,
|
151
|
+
TemporaryRedirect = 307,
|
152
|
+
PermanentRedirect = 308,
|
153
|
+
BadRequest = 400,
|
154
|
+
Unauthorized = 401,
|
155
|
+
PaymentRequired = 402,
|
156
|
+
Forbidden = 403,
|
157
|
+
NotFound = 404,
|
158
|
+
MethodNotAllowed = 405,
|
159
|
+
NotAcceptable = 406,
|
160
|
+
ProxyAuthenticationRequired = 407,
|
161
|
+
RequestTimeout = 408,
|
162
|
+
Conflict = 409,
|
163
|
+
Gone = 410,
|
164
|
+
LengthRequired = 411,
|
165
|
+
PreconditionFailed = 412,
|
166
|
+
PayloadTooLarge = 413,
|
167
|
+
UriTooLong = 414,
|
168
|
+
UnsupportedMediaType = 415,
|
169
|
+
RangeNotSatisfiable = 416,
|
170
|
+
ExpectationFailed = 417,
|
171
|
+
ImATeapot = 418,
|
172
|
+
MisdirectedRequest = 421,
|
173
|
+
UnprocessableEntity = 422,
|
174
|
+
Locked = 423,
|
175
|
+
FailedDependency = 424,
|
176
|
+
TooEarly = 425,
|
177
|
+
UpgradeRequired = 426,
|
178
|
+
PreconditionRequired = 428,
|
179
|
+
TooManyRequests = 429,
|
180
|
+
RequestHeaderFieldsTooLarge = 431,
|
181
|
+
UnavailableForLegalReasons = 451,
|
182
|
+
InternalServerError = 500,
|
183
|
+
NotImplemented = 501,
|
184
|
+
BadGateway = 502,
|
185
|
+
ServiceUnavailable = 503,
|
186
|
+
GatewayTimeout = 504,
|
187
|
+
HttpVersionNotSupported = 505,
|
188
|
+
VariantAlsoNegotiates = 506,
|
189
|
+
InsufficientStorage = 507,
|
190
|
+
LoopDetected = 508,
|
191
|
+
NotExtended = 510,
|
192
|
+
NetworkAuthenticationRequired = 511,
|
193
|
+
}
|
194
|
+
|
195
|
+
type InternalAxiosError<T = unknown, D = any> = AxiosError<T, D>;
|
196
|
+
|
197
|
+
declare namespace axios {
|
198
|
+
type AxiosError<T = unknown, D = any> = InternalAxiosError<T, D>;
|
199
|
+
|
200
|
+
type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders>;
|
201
|
+
|
202
|
+
type AxiosRequestHeaders = Partial<RawAxiosHeaders & MethodsHeaders & CommonHeaders> & AxiosHeaders;
|
203
|
+
|
204
|
+
type RawAxiosResponseHeaders = Partial<Record<string, string> & {
|
205
|
+
"set-cookie"?: string[]
|
206
|
+
}>;
|
207
|
+
|
208
|
+
type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
|
209
|
+
|
210
|
+
interface AxiosRequestTransformer {
|
211
|
+
(this: AxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
|
212
|
+
}
|
213
|
+
|
214
|
+
interface AxiosResponseTransformer {
|
215
|
+
(this: AxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
|
216
|
+
}
|
217
|
+
|
218
|
+
interface AxiosAdapter {
|
219
|
+
(config: AxiosRequestConfig): AxiosPromise;
|
220
|
+
}
|
221
|
+
|
222
|
+
interface AxiosBasicCredentials {
|
223
|
+
username: string;
|
224
|
+
password: string;
|
225
|
+
}
|
226
|
+
|
227
|
+
interface AxiosProxyConfig {
|
228
|
+
host: string;
|
229
|
+
port: number;
|
230
|
+
auth?: {
|
231
|
+
username: string;
|
232
|
+
password: string;
|
233
|
+
};
|
234
|
+
protocol?: string;
|
235
|
+
}
|
236
|
+
|
237
|
+
type Method =
|
238
|
+
| 'get' | 'GET'
|
239
|
+
| 'delete' | 'DELETE'
|
240
|
+
| 'head' | 'HEAD'
|
241
|
+
| 'options' | 'OPTIONS'
|
242
|
+
| 'post' | 'POST'
|
243
|
+
| 'put' | 'PUT'
|
244
|
+
| 'patch' | 'PATCH'
|
245
|
+
| 'purge' | 'PURGE'
|
246
|
+
| 'link' | 'LINK'
|
247
|
+
| 'unlink' | 'UNLINK';
|
248
|
+
|
249
|
+
type ResponseType =
|
250
|
+
| 'arraybuffer'
|
251
|
+
| 'blob'
|
252
|
+
| 'document'
|
253
|
+
| 'json'
|
254
|
+
| 'text'
|
255
|
+
| 'stream';
|
256
|
+
|
257
|
+
type responseEncoding =
|
258
|
+
| 'ascii' | 'ASCII'
|
259
|
+
| 'ansi' | 'ANSI'
|
260
|
+
| 'binary' | 'BINARY'
|
261
|
+
| 'base64' | 'BASE64'
|
262
|
+
| 'base64url' | 'BASE64URL'
|
263
|
+
| 'hex' | 'HEX'
|
264
|
+
| 'latin1' | 'LATIN1'
|
265
|
+
| 'ucs-2' | 'UCS-2'
|
266
|
+
| 'ucs2' | 'UCS2'
|
267
|
+
| 'utf-8' | 'UTF-8'
|
268
|
+
| 'utf8' | 'UTF8'
|
269
|
+
| 'utf16le' | 'UTF16LE';
|
270
|
+
|
271
|
+
interface TransitionalOptions {
|
272
|
+
silentJSONParsing?: boolean;
|
273
|
+
forcedJSONParsing?: boolean;
|
274
|
+
clarifyTimeoutError?: boolean;
|
275
|
+
}
|
276
|
+
|
277
|
+
interface GenericAbortSignal {
|
278
|
+
readonly aborted: boolean;
|
279
|
+
onabort?: ((...args: any) => any) | null;
|
280
|
+
addEventListener?: (...args: any) => any;
|
281
|
+
removeEventListener?: (...args: any) => any;
|
282
|
+
}
|
283
|
+
|
284
|
+
interface FormDataVisitorHelpers {
|
285
|
+
defaultVisitor: SerializerVisitor;
|
286
|
+
convertValue: (value: any) => any;
|
287
|
+
isVisitable: (value: any) => boolean;
|
288
|
+
}
|
289
|
+
|
290
|
+
interface SerializerVisitor {
|
291
|
+
(
|
292
|
+
this: GenericFormData,
|
293
|
+
value: any,
|
294
|
+
key: string | number,
|
295
|
+
path: null | Array<string | number>,
|
296
|
+
helpers: FormDataVisitorHelpers
|
297
|
+
): boolean;
|
298
|
+
}
|
299
|
+
|
300
|
+
interface SerializerOptions {
|
301
|
+
visitor?: SerializerVisitor;
|
302
|
+
dots?: boolean;
|
303
|
+
metaTokens?: boolean;
|
304
|
+
indexes?: boolean | null;
|
305
|
+
}
|
306
|
+
|
307
|
+
// tslint:disable-next-line
|
308
|
+
interface FormSerializerOptions extends SerializerOptions {
|
309
|
+
}
|
310
|
+
|
311
|
+
interface ParamEncoder {
|
312
|
+
(value: any, defaultEncoder: (value: any) => any): any;
|
313
|
+
}
|
314
|
+
|
315
|
+
interface CustomParamsSerializer {
|
316
|
+
(params: Record<string, any>, options?: ParamsSerializerOptions): string;
|
317
|
+
}
|
318
|
+
|
319
|
+
interface ParamsSerializerOptions extends SerializerOptions {
|
320
|
+
encode?: ParamEncoder;
|
321
|
+
serialize?: CustomParamsSerializer;
|
322
|
+
}
|
323
|
+
|
324
|
+
interface AxiosProgressEvent {
|
325
|
+
loaded: number;
|
326
|
+
total?: number;
|
327
|
+
progress?: number;
|
328
|
+
bytes: number;
|
329
|
+
rate?: number;
|
330
|
+
estimated?: number;
|
331
|
+
upload?: boolean;
|
332
|
+
download?: boolean;
|
333
|
+
}
|
334
|
+
|
335
|
+
interface AxiosRequestConfig<D = any> {
|
336
|
+
url?: string;
|
337
|
+
method?: Method | string;
|
338
|
+
baseURL?: string;
|
339
|
+
transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
|
340
|
+
transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
|
341
|
+
headers?: RawAxiosRequestHeaders;
|
342
|
+
params?: any;
|
343
|
+
paramsSerializer?: ParamsSerializerOptions;
|
344
|
+
data?: D;
|
345
|
+
timeout?: Milliseconds;
|
346
|
+
timeoutErrorMessage?: string;
|
347
|
+
withCredentials?: boolean;
|
348
|
+
adapter?: AxiosAdapter;
|
349
|
+
auth?: AxiosBasicCredentials;
|
350
|
+
responseType?: ResponseType;
|
351
|
+
responseEncoding?: responseEncoding | string;
|
352
|
+
xsrfCookieName?: string;
|
353
|
+
xsrfHeaderName?: string;
|
354
|
+
onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
355
|
+
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
|
356
|
+
maxContentLength?: number;
|
357
|
+
validateStatus?: ((status: number) => boolean) | null;
|
358
|
+
maxBodyLength?: number;
|
359
|
+
maxRedirects?: number;
|
360
|
+
maxRate?: number | [MaxUploadRate, MaxDownloadRate];
|
361
|
+
beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
|
362
|
+
socketPath?: string | null;
|
363
|
+
httpAgent?: any;
|
364
|
+
httpsAgent?: any;
|
365
|
+
proxy?: AxiosProxyConfig | false;
|
366
|
+
cancelToken?: CancelToken;
|
367
|
+
decompress?: boolean;
|
368
|
+
transitional?: TransitionalOptions;
|
369
|
+
signal?: GenericAbortSignal;
|
370
|
+
insecureHTTPParser?: boolean;
|
371
|
+
env?: {
|
372
|
+
FormData?: new (...args: any[]) => object;
|
373
|
+
};
|
374
|
+
formSerializer?: FormSerializerOptions;
|
375
|
+
}
|
376
|
+
|
377
|
+
interface HeadersDefaults {
|
378
|
+
common: RawAxiosRequestHeaders;
|
379
|
+
delete: RawAxiosRequestHeaders;
|
380
|
+
get: RawAxiosRequestHeaders;
|
381
|
+
head: RawAxiosRequestHeaders;
|
382
|
+
post: RawAxiosRequestHeaders;
|
383
|
+
put: RawAxiosRequestHeaders;
|
384
|
+
patch: RawAxiosRequestHeaders;
|
385
|
+
options?: RawAxiosRequestHeaders;
|
386
|
+
purge?: RawAxiosRequestHeaders;
|
387
|
+
link?: RawAxiosRequestHeaders;
|
388
|
+
unlink?: RawAxiosRequestHeaders;
|
389
|
+
}
|
390
|
+
|
391
|
+
interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
392
|
+
headers: HeadersDefaults;
|
393
|
+
}
|
394
|
+
|
395
|
+
interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
|
396
|
+
headers?: RawAxiosRequestHeaders | Partial<HeadersDefaults>;
|
397
|
+
}
|
398
|
+
|
399
|
+
interface AxiosResponse<T = any, D = any> {
|
400
|
+
data: T;
|
401
|
+
status: number;
|
402
|
+
statusText: string;
|
403
|
+
headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
|
404
|
+
config: AxiosRequestConfig<D>;
|
405
|
+
request?: any;
|
406
|
+
}
|
407
|
+
|
408
|
+
type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
|
409
|
+
|
410
|
+
interface CancelStatic {
|
411
|
+
new (message?: string): Cancel;
|
412
|
+
}
|
413
|
+
|
414
|
+
interface Cancel {
|
415
|
+
message: string | undefined;
|
416
|
+
}
|
417
|
+
|
418
|
+
interface Canceler {
|
419
|
+
(message?: string, config?: AxiosRequestConfig, request?: any): void;
|
420
|
+
}
|
421
|
+
|
422
|
+
interface CancelTokenStatic {
|
423
|
+
new (executor: (cancel: Canceler) => void): CancelToken;
|
424
|
+
source(): CancelTokenSource;
|
425
|
+
}
|
426
|
+
|
427
|
+
interface CancelToken {
|
428
|
+
promise: Promise<Cancel>;
|
429
|
+
reason?: Cancel;
|
430
|
+
throwIfRequested(): void;
|
431
|
+
}
|
432
|
+
|
433
|
+
interface CancelTokenSource {
|
434
|
+
token: CancelToken;
|
435
|
+
cancel: Canceler;
|
436
|
+
}
|
437
|
+
|
438
|
+
interface AxiosInterceptorOptions {
|
439
|
+
synchronous?: boolean;
|
440
|
+
runWhen?: (config: AxiosRequestConfig) => boolean;
|
441
|
+
}
|
442
|
+
|
443
|
+
interface AxiosInterceptorManager<V> {
|
444
|
+
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
|
445
|
+
eject(id: number): void;
|
446
|
+
clear(): void;
|
447
|
+
}
|
448
|
+
|
449
|
+
interface AxiosInstance extends Axios {
|
450
|
+
<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
|
451
|
+
<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
|
452
|
+
|
453
|
+
defaults: Omit<AxiosDefaults, 'headers'> & {
|
454
|
+
headers: HeadersDefaults & {
|
455
|
+
[key: string]: AxiosHeaderValue
|
456
|
+
}
|
457
|
+
};
|
458
|
+
}
|
459
|
+
|
460
|
+
interface GenericFormData {
|
461
|
+
append(name: string, value: any, options?: any): any;
|
462
|
+
}
|
463
|
+
|
464
|
+
interface GenericHTMLFormElement {
|
465
|
+
name: string;
|
466
|
+
method: string;
|
467
|
+
submit(): void;
|
468
|
+
}
|
469
|
+
|
470
|
+
interface AxiosStatic extends AxiosInstance {
|
471
|
+
create(config?: CreateAxiosDefaults): AxiosInstance;
|
472
|
+
Cancel: CancelStatic;
|
473
|
+
CancelToken: CancelTokenStatic;
|
474
|
+
Axios: typeof Axios;
|
475
|
+
AxiosError: typeof AxiosError;
|
476
|
+
CanceledError: typeof CanceledError;
|
477
|
+
HttpStatusCode: typeof HttpStatusCode;
|
478
|
+
readonly VERSION: string;
|
479
|
+
isCancel(value: any): value is Cancel;
|
480
|
+
all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
481
|
+
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
482
|
+
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
483
|
+
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
484
|
+
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
485
|
+
}
|
486
|
+
}
|
487
|
+
|
488
|
+
declare const axios: axios.AxiosStatic;
|
489
|
+
|
490
|
+
export = axios;
|
package/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// TypeScript Version: 4.
|
1
|
+
// TypeScript Version: 4.7
|
2
2
|
type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
|
3
3
|
type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
|
4
4
|
|
@@ -21,8 +21,7 @@ type AxiosHeaderTester = (matcher?: AxiosHeaderMatcher) => boolean;
|
|
21
21
|
|
22
22
|
export class AxiosHeaders {
|
23
23
|
constructor(
|
24
|
-
headers?: RawAxiosHeaders | AxiosHeaders
|
25
|
-
defaultHeaders?: RawAxiosHeaders | AxiosHeaders
|
24
|
+
headers?: RawAxiosHeaders | AxiosHeaders
|
26
25
|
);
|
27
26
|
|
28
27
|
set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
@@ -39,12 +38,16 @@ export class AxiosHeaders {
|
|
39
38
|
|
40
39
|
normalize(format: boolean): AxiosHeaders;
|
41
40
|
|
41
|
+
concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;
|
42
|
+
|
42
43
|
toJSON(asStrings?: boolean): RawAxiosHeaders;
|
43
44
|
|
44
45
|
static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
|
45
46
|
|
46
47
|
static accessor(header: string | string[]): AxiosHeaders;
|
47
48
|
|
49
|
+
static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string>): AxiosHeaders;
|
50
|
+
|
48
51
|
setContentType: AxiosHeaderSetter;
|
49
52
|
getContentType: AxiosHeaderGetter;
|
50
53
|
hasContentType: AxiosHeaderTester;
|
@@ -269,6 +272,7 @@ export interface AxiosProgressEvent {
|
|
269
272
|
estimated?: number;
|
270
273
|
upload?: boolean;
|
271
274
|
download?: boolean;
|
275
|
+
event?: ProgressEvent;
|
272
276
|
}
|
273
277
|
|
274
278
|
type Milliseconds = number;
|
@@ -416,7 +420,7 @@ export interface AxiosInterceptorOptions {
|
|
416
420
|
}
|
417
421
|
|
418
422
|
export interface AxiosInterceptorManager<V> {
|
419
|
-
use(onFulfilled?: (value: V) => V | Promise<V
|
423
|
+
use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions): number;
|
420
424
|
eject(id: number): void;
|
421
425
|
clear(): void;
|
422
426
|
}
|
@@ -463,6 +467,18 @@ export interface GenericHTMLFormElement {
|
|
463
467
|
submit(): void;
|
464
468
|
}
|
465
469
|
|
470
|
+
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
471
|
+
|
472
|
+
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
473
|
+
|
474
|
+
export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
475
|
+
|
476
|
+
export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
477
|
+
|
478
|
+
export function isCancel(value: any): value is Cancel;
|
479
|
+
|
480
|
+
export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
|
481
|
+
|
466
482
|
export interface AxiosStatic extends AxiosInstance {
|
467
483
|
create(config?: CreateAxiosDefaults): AxiosInstance;
|
468
484
|
Cancel: CancelStatic;
|
@@ -470,12 +486,14 @@ export interface AxiosStatic extends AxiosInstance {
|
|
470
486
|
Axios: typeof Axios;
|
471
487
|
AxiosError: typeof AxiosError;
|
472
488
|
readonly VERSION: string;
|
473
|
-
isCancel
|
474
|
-
all
|
475
|
-
spread
|
476
|
-
isAxiosError
|
477
|
-
toFormData
|
478
|
-
formToJSON
|
489
|
+
isCancel: typeof isCancel;
|
490
|
+
all: typeof all;
|
491
|
+
spread: typeof spread;
|
492
|
+
isAxiosError: typeof isAxiosError;
|
493
|
+
toFormData: typeof toFormData;
|
494
|
+
formToJSON: typeof formToJSON;
|
495
|
+
CanceledError: typeof CanceledError;
|
496
|
+
AxiosHeaders: typeof AxiosHeaders;
|
479
497
|
}
|
480
498
|
|
481
499
|
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,13 @@ const {
|
|
13
14
|
Cancel,
|
14
15
|
isAxiosError,
|
15
16
|
spread,
|
16
|
-
toFormData
|
17
|
+
toFormData,
|
18
|
+
AxiosHeaders,
|
19
|
+
formToJSON
|
17
20
|
} = axios;
|
18
21
|
|
19
|
-
export default axios;
|
20
22
|
export {
|
23
|
+
axios as default,
|
21
24
|
Axios,
|
22
25
|
AxiosError,
|
23
26
|
CanceledError,
|
@@ -28,5 +31,7 @@ export {
|
|
28
31
|
Cancel,
|
29
32
|
isAxiosError,
|
30
33
|
spread,
|
31
|
-
toFormData
|
34
|
+
toFormData,
|
35
|
+
AxiosHeaders,
|
36
|
+
formToJSON
|
32
37
|
}
|
package/karma.conf.cjs
CHANGED
@@ -129,7 +129,7 @@ module.exports = function(config) {
|
|
129
129
|
);
|
130
130
|
browsers = ['Firefox'];
|
131
131
|
} else if (process.env.GITHUB_ACTIONS === 'true') {
|
132
|
-
console.log('Running ci on
|
132
|
+
console.log('Running ci on GitHub Actions.');
|
133
133
|
browsers = ['FirefoxHeadless', 'ChromeHeadless'];
|
134
134
|
} else {
|
135
135
|
browsers = browsers || ['Chrome'];
|
package/lib/adapters/http.js
CHANGED
@@ -203,7 +203,7 @@ export default function httpAdapter(config) {
|
|
203
203
|
data: convertedData,
|
204
204
|
status: 200,
|
205
205
|
statusText: 'OK',
|
206
|
-
headers:
|
206
|
+
headers: new AxiosHeaders(),
|
207
207
|
config
|
208
208
|
});
|
209
209
|
}
|
@@ -588,4 +588,4 @@ export default function httpAdapter(config) {
|
|
588
588
|
});
|
589
589
|
}
|
590
590
|
|
591
|
-
export const __setProxy = setProxy;
|
591
|
+
export const __setProxy = setProxy;
|
package/lib/adapters/xhr.js
CHANGED
@@ -33,7 +33,8 @@ function progressEventReducer(listener, isDownloadStream) {
|
|
33
33
|
progress: total ? (loaded / total) : undefined,
|
34
34
|
bytes: progressBytes,
|
35
35
|
rate: rate ? rate : undefined,
|
36
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : undefined
|
36
|
+
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
37
|
+
event: e
|
37
38
|
};
|
38
39
|
|
39
40
|
data[isDownloadStream ? 'download' : 'upload'] = true;
|
package/lib/axios.js
CHANGED
@@ -14,6 +14,7 @@ import toFormData from './helpers/toFormData.js';
|
|
14
14
|
import AxiosError from './core/AxiosError.js';
|
15
15
|
import spread from './helpers/spread.js';
|
16
16
|
import isAxiosError from './helpers/isAxiosError.js';
|
17
|
+
import AxiosHeaders from "./core/AxiosHeaders.js";
|
17
18
|
|
18
19
|
/**
|
19
20
|
* Create an instance of Axios
|
@@ -69,8 +70,11 @@ axios.spread = spread;
|
|
69
70
|
// Expose isAxiosError
|
70
71
|
axios.isAxiosError = isAxiosError;
|
71
72
|
|
72
|
-
axios.
|
73
|
-
|
74
|
-
|
73
|
+
axios.AxiosHeaders = AxiosHeaders;
|
74
|
+
|
75
|
+
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
76
|
+
|
77
|
+
axios.default = axios;
|
75
78
|
|
79
|
+
// this module should only have a default export
|
76
80
|
export default axios
|