@wiajs/req 1.7.7

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +1023 -0
  2. package/LICENSE +7 -0
  3. package/MIGRATION_GUIDE.md +3 -0
  4. package/README.md +1645 -0
  5. package/SECURITY.md +6 -0
  6. package/dist/node/req.cjs +4397 -0
  7. package/dist/node/req.mjs +3551 -0
  8. package/dist/web/req.mjs +2609 -0
  9. package/index.d.cts +545 -0
  10. package/index.d.ts +565 -0
  11. package/index.js +43 -0
  12. package/lib/adapters/README.md +37 -0
  13. package/lib/adapters/adapters.js +57 -0
  14. package/lib/adapters/fetch.js +229 -0
  15. package/lib/adapters/http.js +552 -0
  16. package/lib/adapters/xhr.js +200 -0
  17. package/lib/axios.js +89 -0
  18. package/lib/cancel/CancelToken.js +106 -0
  19. package/lib/cancel/CanceledError.js +20 -0
  20. package/lib/cancel/isCancel.js +4 -0
  21. package/lib/core/Axios.js +359 -0
  22. package/lib/core/AxiosError.js +89 -0
  23. package/lib/core/AxiosHeaders.js +243 -0
  24. package/lib/core/InterceptorManager.js +59 -0
  25. package/lib/core/README.md +8 -0
  26. package/lib/core/buildFullPath.js +18 -0
  27. package/lib/core/dispatchRequest.js +72 -0
  28. package/lib/core/mergeConfig.js +98 -0
  29. package/lib/core/settle.js +21 -0
  30. package/lib/core/transformData.js +22 -0
  31. package/lib/defaults/index.js +136 -0
  32. package/lib/defaults/transitional.js +6 -0
  33. package/lib/env/README.md +3 -0
  34. package/lib/env/classes/FormData.js +2 -0
  35. package/lib/env/data.js +1 -0
  36. package/lib/helpers/AxiosTransformStream.js +116 -0
  37. package/lib/helpers/AxiosURLSearchParams.js +50 -0
  38. package/lib/helpers/HttpStatusCode.js +69 -0
  39. package/lib/helpers/README.md +7 -0
  40. package/lib/helpers/ZlibHeaderTransformStream.js +22 -0
  41. package/lib/helpers/bind.js +6 -0
  42. package/lib/helpers/buildURL.js +42 -0
  43. package/lib/helpers/callbackify.js +14 -0
  44. package/lib/helpers/combineURLs.js +11 -0
  45. package/lib/helpers/composeSignals.js +37 -0
  46. package/lib/helpers/cookies.js +29 -0
  47. package/lib/helpers/deprecatedMethod.js +18 -0
  48. package/lib/helpers/formDataToJSON.js +78 -0
  49. package/lib/helpers/formDataToStream.js +77 -0
  50. package/lib/helpers/fromDataURI.js +44 -0
  51. package/lib/helpers/isAbsoluteURL.js +13 -0
  52. package/lib/helpers/isAxiosError.js +11 -0
  53. package/lib/helpers/isURLSameOrigin.js +50 -0
  54. package/lib/helpers/null.js +2 -0
  55. package/lib/helpers/parseHeaders.js +61 -0
  56. package/lib/helpers/parseProtocol.js +5 -0
  57. package/lib/helpers/progressEventReducer.js +54 -0
  58. package/lib/helpers/readBlob.js +13 -0
  59. package/lib/helpers/resolveConfig.js +45 -0
  60. package/lib/helpers/speedometer.js +40 -0
  61. package/lib/helpers/spread.js +26 -0
  62. package/lib/helpers/throttle.js +41 -0
  63. package/lib/helpers/toFormData.js +175 -0
  64. package/lib/helpers/toURLEncodedForm.js +15 -0
  65. package/lib/helpers/trackStream.js +75 -0
  66. package/lib/helpers/validator.js +84 -0
  67. package/lib/platform/browser/classes/Blob.js +2 -0
  68. package/lib/platform/browser/classes/FormData.js +2 -0
  69. package/lib/platform/browser/classes/URLSearchParams.js +3 -0
  70. package/lib/platform/browser/index.js +19 -0
  71. package/lib/platform/common/utils.js +37 -0
  72. package/lib/platform/index.js +6 -0
  73. package/lib/platform/node/classes/FormData.js +2 -0
  74. package/lib/platform/node/classes/URLSearchParams.js +3 -0
  75. package/lib/platform/node/index.js +16 -0
  76. package/lib/req.js +67 -0
  77. package/lib/utils.js +635 -0
  78. package/package.json +214 -0
package/index.d.ts ADDED
@@ -0,0 +1,565 @@
1
+ // TypeScript Version: 4.7
2
+ export type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
3
+
4
+ interface RawAxiosHeaders {
5
+ [key: string]: AxiosHeaderValue;
6
+ }
7
+
8
+ type MethodsHeaders = Partial<{
9
+ [Key in Method as Lowercase<Key>]: AxiosHeaders;
10
+ } & {common: AxiosHeaders}>;
11
+
12
+ type AxiosHeaderMatcher = string | RegExp | ((this: AxiosHeaders, value: string, name: string) => boolean);
13
+
14
+ type AxiosHeaderParser = (this: AxiosHeaders, value: AxiosHeaderValue, header: string) => any;
15
+
16
+ export class AxiosHeaders {
17
+ constructor(
18
+ headers?: RawAxiosHeaders | AxiosHeaders | string
19
+ );
20
+
21
+ [key: string]: any;
22
+
23
+ set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
24
+ set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
25
+
26
+ get(headerName: string, parser: RegExp): RegExpExecArray | null;
27
+ get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
28
+
29
+ has(header: string, matcher?: AxiosHeaderMatcher): boolean;
30
+
31
+ delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
32
+
33
+ clear(matcher?: AxiosHeaderMatcher): boolean;
34
+
35
+ normalize(format: boolean): AxiosHeaders;
36
+
37
+ concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
38
+
39
+ toJSON(asStrings?: boolean): RawAxiosHeaders;
40
+
41
+ static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
42
+
43
+ static accessor(header: string | string[]): AxiosHeaders;
44
+
45
+ static concat(...targets: Array<AxiosHeaders | RawAxiosHeaders | string | undefined | null>): AxiosHeaders;
46
+
47
+ setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
48
+ getContentType(parser?: RegExp): RegExpExecArray | null;
49
+ getContentType(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
50
+ hasContentType(matcher?: AxiosHeaderMatcher): boolean;
51
+
52
+ setContentLength(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
53
+ getContentLength(parser?: RegExp): RegExpExecArray | null;
54
+ getContentLength(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
55
+ hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
56
+
57
+ setAccept(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
58
+ getAccept(parser?: RegExp): RegExpExecArray | null;
59
+ getAccept(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
60
+ hasAccept(matcher?: AxiosHeaderMatcher): boolean;
61
+
62
+ setUserAgent(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
63
+ getUserAgent(parser?: RegExp): RegExpExecArray | null;
64
+ getUserAgent(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
65
+ hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
66
+
67
+ setContentEncoding(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
68
+ getContentEncoding(parser?: RegExp): RegExpExecArray | null;
69
+ getContentEncoding(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
70
+ hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
71
+
72
+ setAuthorization(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
73
+ getAuthorization(parser?: RegExp): RegExpExecArray | null;
74
+ getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
75
+ hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
76
+
77
+ [Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
78
+ }
79
+
80
+ type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent' | 'Content-Encoding' | 'Authorization';
81
+
82
+ type ContentType = AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
83
+
84
+ export type RawAxiosRequestHeaders = Partial<RawAxiosHeaders & {
85
+ [Key in CommonRequestHeadersList]: AxiosHeaderValue;
86
+ } & {
87
+ 'Content-Type': ContentType
88
+ }>;
89
+
90
+ export type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
91
+
92
+ type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
93
+
94
+ type RawCommonResponseHeaders = {
95
+ [Key in CommonResponseHeadersList]: AxiosHeaderValue;
96
+ } & {
97
+ "set-cookie": string[];
98
+ };
99
+
100
+ export type RawAxiosResponseHeaders = Partial<RawAxiosHeaders & RawCommonResponseHeaders>;
101
+
102
+ export type AxiosResponseHeaders = RawAxiosResponseHeaders & AxiosHeaders;
103
+
104
+ export interface AxiosRequestTransformer {
105
+ (this: InternalAxiosRequestConfig, data: any, headers: AxiosRequestHeaders): any;
106
+ }
107
+
108
+ export interface AxiosResponseTransformer {
109
+ (this: InternalAxiosRequestConfig, data: any, headers: AxiosResponseHeaders, status?: number): any;
110
+ }
111
+
112
+ export interface AxiosAdapter {
113
+ (config: InternalAxiosRequestConfig): AxiosPromise;
114
+ }
115
+
116
+ export interface AxiosBasicCredentials {
117
+ username: string;
118
+ password: string;
119
+ }
120
+
121
+ export interface AxiosProxyConfig {
122
+ host: string;
123
+ port: number;
124
+ auth?: AxiosBasicCredentials;
125
+ protocol?: string;
126
+ }
127
+
128
+ export enum HttpStatusCode {
129
+ Continue = 100,
130
+ SwitchingProtocols = 101,
131
+ Processing = 102,
132
+ EarlyHints = 103,
133
+ Ok = 200,
134
+ Created = 201,
135
+ Accepted = 202,
136
+ NonAuthoritativeInformation = 203,
137
+ NoContent = 204,
138
+ ResetContent = 205,
139
+ PartialContent = 206,
140
+ MultiStatus = 207,
141
+ AlreadyReported = 208,
142
+ ImUsed = 226,
143
+ MultipleChoices = 300,
144
+ MovedPermanently = 301,
145
+ Found = 302,
146
+ SeeOther = 303,
147
+ NotModified = 304,
148
+ UseProxy = 305,
149
+ Unused = 306,
150
+ TemporaryRedirect = 307,
151
+ PermanentRedirect = 308,
152
+ BadRequest = 400,
153
+ Unauthorized = 401,
154
+ PaymentRequired = 402,
155
+ Forbidden = 403,
156
+ NotFound = 404,
157
+ MethodNotAllowed = 405,
158
+ NotAcceptable = 406,
159
+ ProxyAuthenticationRequired = 407,
160
+ RequestTimeout = 408,
161
+ Conflict = 409,
162
+ Gone = 410,
163
+ LengthRequired = 411,
164
+ PreconditionFailed = 412,
165
+ PayloadTooLarge = 413,
166
+ UriTooLong = 414,
167
+ UnsupportedMediaType = 415,
168
+ RangeNotSatisfiable = 416,
169
+ ExpectationFailed = 417,
170
+ ImATeapot = 418,
171
+ MisdirectedRequest = 421,
172
+ UnprocessableEntity = 422,
173
+ Locked = 423,
174
+ FailedDependency = 424,
175
+ TooEarly = 425,
176
+ UpgradeRequired = 426,
177
+ PreconditionRequired = 428,
178
+ TooManyRequests = 429,
179
+ RequestHeaderFieldsTooLarge = 431,
180
+ UnavailableForLegalReasons = 451,
181
+ InternalServerError = 500,
182
+ NotImplemented = 501,
183
+ BadGateway = 502,
184
+ ServiceUnavailable = 503,
185
+ GatewayTimeout = 504,
186
+ HttpVersionNotSupported = 505,
187
+ VariantAlsoNegotiates = 506,
188
+ InsufficientStorage = 507,
189
+ LoopDetected = 508,
190
+ NotExtended = 510,
191
+ NetworkAuthenticationRequired = 511,
192
+ }
193
+
194
+ export type Method =
195
+ | 'get' | 'GET'
196
+ | 'delete' | 'DELETE'
197
+ | 'head' | 'HEAD'
198
+ | 'options' | 'OPTIONS'
199
+ | 'post' | 'POST'
200
+ | 'put' | 'PUT'
201
+ | 'patch' | 'PATCH'
202
+ | 'purge' | 'PURGE'
203
+ | 'link' | 'LINK'
204
+ | 'unlink' | 'UNLINK';
205
+
206
+ export type ResponseType =
207
+ | 'arraybuffer'
208
+ | 'blob'
209
+ | 'document'
210
+ | 'json'
211
+ | 'text'
212
+ | 'stream'
213
+ | 'formdata';
214
+
215
+ export type responseEncoding =
216
+ | 'ascii' | 'ASCII'
217
+ | 'ansi' | 'ANSI'
218
+ | 'binary' | 'BINARY'
219
+ | 'base64' | 'BASE64'
220
+ | 'base64url' | 'BASE64URL'
221
+ | 'hex' | 'HEX'
222
+ | 'latin1' | 'LATIN1'
223
+ | 'ucs-2' | 'UCS-2'
224
+ | 'ucs2' | 'UCS2'
225
+ | 'utf-8' | 'UTF-8'
226
+ | 'utf8' | 'UTF8'
227
+ | 'utf16le' | 'UTF16LE';
228
+
229
+ export interface TransitionalOptions {
230
+ silentJSONParsing?: boolean;
231
+ forcedJSONParsing?: boolean;
232
+ clarifyTimeoutError?: boolean;
233
+ }
234
+
235
+ export interface GenericAbortSignal {
236
+ readonly aborted: boolean;
237
+ onabort?: ((...args: any) => any) | null;
238
+ addEventListener?: (...args: any) => any;
239
+ removeEventListener?: (...args: any) => any;
240
+ }
241
+
242
+ export interface FormDataVisitorHelpers {
243
+ defaultVisitor: SerializerVisitor;
244
+ convertValue: (value: any) => any;
245
+ isVisitable: (value: any) => boolean;
246
+ }
247
+
248
+ export interface SerializerVisitor {
249
+ (
250
+ this: GenericFormData,
251
+ value: any,
252
+ key: string | number,
253
+ path: null | Array<string | number>,
254
+ helpers: FormDataVisitorHelpers
255
+ ): boolean;
256
+ }
257
+
258
+ export interface SerializerOptions {
259
+ visitor?: SerializerVisitor;
260
+ dots?: boolean;
261
+ metaTokens?: boolean;
262
+ indexes?: boolean | null;
263
+ }
264
+
265
+ // tslint:disable-next-line
266
+ export interface FormSerializerOptions extends SerializerOptions {
267
+ }
268
+
269
+ export interface ParamEncoder {
270
+ (value: any, defaultEncoder: (value: any) => any): any;
271
+ }
272
+
273
+ export interface CustomParamsSerializer {
274
+ (params: Record<string, any>, options?: ParamsSerializerOptions): string;
275
+ }
276
+
277
+ export interface ParamsSerializerOptions extends SerializerOptions {
278
+ encode?: ParamEncoder;
279
+ serialize?: CustomParamsSerializer;
280
+ }
281
+
282
+ type MaxUploadRate = number;
283
+
284
+ type MaxDownloadRate = number;
285
+
286
+ type BrowserProgressEvent = any;
287
+
288
+ export interface AxiosProgressEvent {
289
+ loaded: number;
290
+ total?: number;
291
+ progress?: number;
292
+ bytes: number;
293
+ rate?: number;
294
+ estimated?: number;
295
+ upload?: boolean;
296
+ download?: boolean;
297
+ event?: BrowserProgressEvent;
298
+ lengthComputable: boolean;
299
+ }
300
+
301
+ type Milliseconds = number;
302
+
303
+ type AxiosAdapterName = 'fetch' | 'xhr' | 'http' | string;
304
+
305
+ type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
306
+
307
+ export type AddressFamily = 4 | 6 | undefined;
308
+
309
+ export interface LookupAddressEntry {
310
+ address: string;
311
+ family?: AddressFamily;
312
+ }
313
+
314
+ export type LookupAddress = string | LookupAddressEntry;
315
+
316
+ export interface AxiosRequestConfig<D = any> {
317
+ url?: string;
318
+ method?: Method | string;
319
+ baseURL?: string;
320
+ transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
321
+ transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
322
+ headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
323
+ params?: any;
324
+ paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
325
+ data?: D;
326
+ timeout?: Milliseconds;
327
+ timeoutErrorMessage?: string;
328
+ withCredentials?: boolean;
329
+ adapter?: AxiosAdapterConfig | AxiosAdapterConfig[];
330
+ auth?: AxiosBasicCredentials;
331
+ responseType?: ResponseType;
332
+ responseEncoding?: responseEncoding | string;
333
+ xsrfCookieName?: string;
334
+ xsrfHeaderName?: string;
335
+ onUploadProgress?: (progressEvent: AxiosProgressEvent) => void;
336
+ onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void;
337
+ maxContentLength?: number;
338
+ validateStatus?: ((status: number) => boolean) | null;
339
+ maxBodyLength?: number;
340
+ maxRedirects?: number;
341
+ maxRate?: number | [MaxUploadRate, MaxDownloadRate];
342
+ beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>, statusCode: HttpStatusCode}) => void;
343
+ socketPath?: string | null;
344
+ transport?: any;
345
+ httpAgent?: any;
346
+ httpsAgent?: any;
347
+ proxy?: AxiosProxyConfig | false;
348
+ cancelToken?: CancelToken;
349
+ decompress?: boolean;
350
+ transitional?: TransitionalOptions;
351
+ signal?: GenericAbortSignal;
352
+ insecureHTTPParser?: boolean;
353
+ env?: {
354
+ FormData?: new (...args: any[]) => object;
355
+ };
356
+ formSerializer?: FormSerializerOptions;
357
+ family?: AddressFamily;
358
+ lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
359
+ ((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
360
+ withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
361
+ fetchOptions?: Record<string, any>;
362
+ }
363
+
364
+ // Alias
365
+ export type RawAxiosRequestConfig<D = any> = AxiosRequestConfig<D>;
366
+
367
+ export interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
368
+ headers: AxiosRequestHeaders;
369
+ }
370
+
371
+ export interface HeadersDefaults {
372
+ common: RawAxiosRequestHeaders;
373
+ delete: RawAxiosRequestHeaders;
374
+ get: RawAxiosRequestHeaders;
375
+ head: RawAxiosRequestHeaders;
376
+ post: RawAxiosRequestHeaders;
377
+ put: RawAxiosRequestHeaders;
378
+ patch: RawAxiosRequestHeaders;
379
+ options?: RawAxiosRequestHeaders;
380
+ purge?: RawAxiosRequestHeaders;
381
+ link?: RawAxiosRequestHeaders;
382
+ unlink?: RawAxiosRequestHeaders;
383
+ }
384
+
385
+ export interface AxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
386
+ headers: HeadersDefaults;
387
+ }
388
+
389
+ export interface CreateAxiosDefaults<D = any> extends Omit<AxiosRequestConfig<D>, 'headers'> {
390
+ headers?: RawAxiosRequestHeaders | AxiosHeaders | Partial<HeadersDefaults>;
391
+ }
392
+
393
+ export interface AxiosResponse<T = any, D = any> {
394
+ data: T;
395
+ status: number;
396
+ statusText: string;
397
+ headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
398
+ config: InternalAxiosRequestConfig<D>;
399
+ request?: any;
400
+ }
401
+
402
+ export class AxiosError<T = unknown, D = any> extends Error {
403
+ constructor(
404
+ message?: string,
405
+ code?: string,
406
+ config?: InternalAxiosRequestConfig<D>,
407
+ request?: any,
408
+ response?: AxiosResponse<T, D>
409
+ );
410
+
411
+ config?: InternalAxiosRequestConfig<D>;
412
+ code?: string;
413
+ request?: any;
414
+ response?: AxiosResponse<T, D>;
415
+ isAxiosError: boolean;
416
+ status?: number;
417
+ toJSON: () => object;
418
+ cause?: Error;
419
+ static from<T = unknown, D = any>(
420
+ error: Error | unknown,
421
+ code?: string,
422
+ config?: InternalAxiosRequestConfig<D>,
423
+ request?: any,
424
+ response?: AxiosResponse<T, D>,
425
+ customProps?: object,
426
+ ): AxiosError<T, D>;
427
+ static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
428
+ static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
429
+ static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
430
+ static readonly ERR_NETWORK = "ERR_NETWORK";
431
+ static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
432
+ static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
433
+ static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
434
+ static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
435
+ static readonly ERR_INVALID_URL = "ERR_INVALID_URL";
436
+ static readonly ERR_CANCELED = "ERR_CANCELED";
437
+ static readonly ECONNABORTED = "ECONNABORTED";
438
+ static readonly ETIMEDOUT = "ETIMEDOUT";
439
+ }
440
+
441
+ export class CanceledError<T> extends AxiosError<T> {
442
+ }
443
+
444
+ export type AxiosPromise<T = any> = Promise<AxiosResponse<T>>;
445
+
446
+ export interface CancelStatic {
447
+ new (message?: string): Cancel;
448
+ }
449
+
450
+ export interface Cancel {
451
+ message: string | undefined;
452
+ }
453
+
454
+ export interface Canceler {
455
+ (message?: string, config?: AxiosRequestConfig, request?: any): void;
456
+ }
457
+
458
+ export interface CancelTokenStatic {
459
+ new (executor: (cancel: Canceler) => void): CancelToken;
460
+ source(): CancelTokenSource;
461
+ }
462
+
463
+ export interface CancelToken {
464
+ promise: Promise<Cancel>;
465
+ reason?: Cancel;
466
+ throwIfRequested(): void;
467
+ }
468
+
469
+ export interface CancelTokenSource {
470
+ token: CancelToken;
471
+ cancel: Canceler;
472
+ }
473
+
474
+ export interface AxiosInterceptorOptions {
475
+ synchronous?: boolean;
476
+ runWhen?: (config: InternalAxiosRequestConfig) => boolean;
477
+ }
478
+
479
+ export interface AxiosInterceptorManager<V> {
480
+ use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, options?: AxiosInterceptorOptions): number;
481
+ eject(id: number): void;
482
+ clear(): void;
483
+ }
484
+
485
+ export class Axios {
486
+ constructor(config?: AxiosRequestConfig);
487
+ defaults: AxiosDefaults;
488
+ interceptors: {
489
+ request: AxiosInterceptorManager<InternalAxiosRequestConfig>;
490
+ response: AxiosInterceptorManager<AxiosResponse>;
491
+ };
492
+ getUri(config?: AxiosRequestConfig): string;
493
+ request<T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
494
+ get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
495
+ delete<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
496
+ head<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
497
+ options<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
498
+ post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
499
+ put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
500
+ patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
501
+ postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
502
+ putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
503
+ patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
504
+ }
505
+
506
+ export interface AxiosInstance extends Axios {
507
+ <T = any, R = AxiosResponse<T>, D = any>(config: AxiosRequestConfig<D>): Promise<R>;
508
+ <T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
509
+
510
+ defaults: Omit<AxiosDefaults, 'headers'> & {
511
+ headers: HeadersDefaults & {
512
+ [key: string]: AxiosHeaderValue
513
+ }
514
+ };
515
+ }
516
+
517
+ export interface GenericFormData {
518
+ append(name: string, value: any, options?: any): any;
519
+ }
520
+
521
+ export interface GenericHTMLFormElement {
522
+ name: string;
523
+ method: string;
524
+ submit(): void;
525
+ }
526
+
527
+ export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
528
+
529
+ export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
530
+
531
+ export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
532
+
533
+ export function isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
534
+
535
+ export function spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
536
+
537
+ export function isCancel(value: any): value is Cancel;
538
+
539
+ export function all<T>(values: Array<T | Promise<T>>): Promise<T[]>;
540
+
541
+ export function mergeConfig<D = any>(config1: AxiosRequestConfig<D>, config2: AxiosRequestConfig<D>): AxiosRequestConfig<D>;
542
+
543
+ export interface AxiosStatic extends AxiosInstance {
544
+ create(config?: CreateAxiosDefaults): AxiosInstance;
545
+ Cancel: CancelStatic;
546
+ CancelToken: CancelTokenStatic;
547
+ Axios: typeof Axios;
548
+ AxiosError: typeof AxiosError;
549
+ HttpStatusCode: typeof HttpStatusCode;
550
+ readonly VERSION: string;
551
+ isCancel: typeof isCancel;
552
+ all: typeof all;
553
+ spread: typeof spread;
554
+ isAxiosError: typeof isAxiosError;
555
+ toFormData: typeof toFormData;
556
+ formToJSON: typeof formToJSON;
557
+ getAdapter: typeof getAdapter;
558
+ CanceledError: typeof CanceledError;
559
+ AxiosHeaders: typeof AxiosHeaders;
560
+ mergeConfig: typeof mergeConfig;
561
+ }
562
+
563
+ declare const req: AxiosStatic;
564
+
565
+ export default req;
package/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import req from "./lib/req.js";
2
+
3
+ // This module is intended to unwrap Axios default export as named.
4
+ // Keep top-level export same with static properties
5
+ // so that it can keep same with es module or cjs
6
+ const {
7
+ Axios,
8
+ AxiosError,
9
+ CanceledError,
10
+ isCancel,
11
+ CancelToken,
12
+ VERSION,
13
+ all,
14
+ Cancel,
15
+ isAxiosError,
16
+ spread,
17
+ toFormData,
18
+ AxiosHeaders,
19
+ HttpStatusCode,
20
+ formToJSON,
21
+ getAdapter,
22
+ mergeConfig,
23
+ } = req;
24
+
25
+ export {
26
+ req as default,
27
+ Axios,
28
+ AxiosError,
29
+ CanceledError,
30
+ isCancel,
31
+ CancelToken,
32
+ VERSION,
33
+ all,
34
+ Cancel,
35
+ isAxiosError,
36
+ spread,
37
+ toFormData,
38
+ AxiosHeaders,
39
+ HttpStatusCode,
40
+ formToJSON,
41
+ getAdapter,
42
+ mergeConfig,
43
+ };
@@ -0,0 +1,37 @@
1
+ # axios // adapters
2
+
3
+ The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received.
4
+
5
+ ## Example
6
+
7
+ ```js
8
+ var settle = require('./../core/settle');
9
+
10
+ module.exports = function myAdapter(config) {
11
+ // At this point:
12
+ // - config has been merged with defaults
13
+ // - request transformers have already run
14
+ // - request interceptors have already run
15
+
16
+ // Make the request using config provided
17
+ // Upon response settle the Promise
18
+
19
+ return new Promise(function(resolve, reject) {
20
+
21
+ var response = {
22
+ data: responseData,
23
+ status: request.status,
24
+ statusText: request.statusText,
25
+ headers: responseHeaders,
26
+ config: config,
27
+ request: request
28
+ };
29
+
30
+ settle(resolve, reject, response);
31
+
32
+ // From here:
33
+ // - response transformers will run
34
+ // - response interceptors will run
35
+ });
36
+ }
37
+ ```
@@ -0,0 +1,57 @@
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
+ const knownAdapters = {
6
+ http: HttpAdapter,
7
+ xhr: XhrAdapter
8
+ };
9
+ /**
10
+ * define adapter's name and adapterName to http or xhr
11
+ * browser: httpAdapter is null!
12
+ */ utils.forEach(knownAdapters, (val, key)=>{
13
+ if (val) {
14
+ try {
15
+ Object.defineProperty(val, 'name', {
16
+ value: key
17
+ });
18
+ } catch (e) {
19
+ // eslint-disable-next-line no-empty
20
+ }
21
+ Object.defineProperty(val, 'adapterName', {
22
+ value: key
23
+ });
24
+ }
25
+ });
26
+ export default {
27
+ /**
28
+ * get http or xhr adapter
29
+ * @param {*} adapters user pass or ['xhr', 'http']
30
+ * @returns
31
+ */ getAdapter: (adapters)=>{
32
+ adapters = utils.isArray(adapters) ? adapters : [
33
+ adapters
34
+ ];
35
+ const { length } = adapters;
36
+ let nameOrAdapter;
37
+ let adapter;
38
+ // find not null adapter
39
+ for(let i = 0; i < length; i++){
40
+ nameOrAdapter = adapters[i];
41
+ if (adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter) {
42
+ break;
43
+ }
44
+ }
45
+ if (!adapter) {
46
+ if (adapter === false) {
47
+ throw new AxiosError(`Adapter ${nameOrAdapter} is not supported by the environment`, 'ERR_NOT_SUPPORT');
48
+ }
49
+ throw new Error(utils.hasOwnProp(knownAdapters, nameOrAdapter) ? `Adapter '${nameOrAdapter}' is not available in the build` : `Unknown adapter '${nameOrAdapter}'`);
50
+ }
51
+ if (!utils.isFunction(adapter)) {
52
+ throw new TypeError('adapter is not a function');
53
+ }
54
+ return adapter;
55
+ },
56
+ adapters: knownAdapters
57
+ };