@lcap/axios-fixed 1.13.2

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 (87) hide show
  1. package/.husky/commit-msg +4 -0
  2. package/CHANGELOG.md +1359 -0
  3. package/LICENSE +7 -0
  4. package/MIGRATION_GUIDE.md +3 -0
  5. package/README.md +1784 -0
  6. package/dist/axios.js +4471 -0
  7. package/dist/axios.js.map +1 -0
  8. package/dist/axios.min.js +3 -0
  9. package/dist/axios.min.js.map +1 -0
  10. package/dist/browser/axios.cjs +3909 -0
  11. package/dist/browser/axios.cjs.map +1 -0
  12. package/dist/esm/axios.js +3932 -0
  13. package/dist/esm/axios.js.map +1 -0
  14. package/dist/esm/axios.min.js +3 -0
  15. package/dist/esm/axios.min.js.map +1 -0
  16. package/dist/node/axios.cjs +5242 -0
  17. package/dist/node/axios.cjs.map +1 -0
  18. package/index.d.cts +572 -0
  19. package/index.d.ts +585 -0
  20. package/index.js +43 -0
  21. package/lib/adapters/README.md +37 -0
  22. package/lib/adapters/adapters.js +126 -0
  23. package/lib/adapters/fetch.js +288 -0
  24. package/lib/adapters/http.js +895 -0
  25. package/lib/adapters/xhr.js +200 -0
  26. package/lib/axios.js +89 -0
  27. package/lib/cancel/CancelToken.js +135 -0
  28. package/lib/cancel/CanceledError.js +25 -0
  29. package/lib/cancel/isCancel.js +5 -0
  30. package/lib/core/Axios.js +240 -0
  31. package/lib/core/AxiosError.js +110 -0
  32. package/lib/core/AxiosHeaders.js +314 -0
  33. package/lib/core/InterceptorManager.js +71 -0
  34. package/lib/core/README.md +8 -0
  35. package/lib/core/buildFullPath.js +22 -0
  36. package/lib/core/dispatchRequest.js +81 -0
  37. package/lib/core/mergeConfig.js +106 -0
  38. package/lib/core/settle.js +27 -0
  39. package/lib/core/transformData.js +28 -0
  40. package/lib/defaults/index.js +161 -0
  41. package/lib/defaults/transitional.js +7 -0
  42. package/lib/env/README.md +3 -0
  43. package/lib/env/classes/FormData.js +2 -0
  44. package/lib/env/data.js +1 -0
  45. package/lib/helpers/AxiosTransformStream.js +143 -0
  46. package/lib/helpers/AxiosURLSearchParams.js +58 -0
  47. package/lib/helpers/HttpStatusCode.js +77 -0
  48. package/lib/helpers/README.md +7 -0
  49. package/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  50. package/lib/helpers/bind.js +14 -0
  51. package/lib/helpers/buildURL.js +67 -0
  52. package/lib/helpers/callbackify.js +16 -0
  53. package/lib/helpers/combineURLs.js +15 -0
  54. package/lib/helpers/composeSignals.js +48 -0
  55. package/lib/helpers/cookies.js +53 -0
  56. package/lib/helpers/deprecatedMethod.js +26 -0
  57. package/lib/helpers/estimateDataURLDecodedBytes.js +73 -0
  58. package/lib/helpers/formDataToJSON.js +95 -0
  59. package/lib/helpers/formDataToStream.js +112 -0
  60. package/lib/helpers/fromDataURI.js +53 -0
  61. package/lib/helpers/isAbsoluteURL.js +15 -0
  62. package/lib/helpers/isAxiosError.js +14 -0
  63. package/lib/helpers/isURLSameOrigin.js +14 -0
  64. package/lib/helpers/null.js +2 -0
  65. package/lib/helpers/parseHeaders.js +55 -0
  66. package/lib/helpers/parseProtocol.js +6 -0
  67. package/lib/helpers/progressEventReducer.js +44 -0
  68. package/lib/helpers/readBlob.js +15 -0
  69. package/lib/helpers/resolveConfig.js +61 -0
  70. package/lib/helpers/speedometer.js +55 -0
  71. package/lib/helpers/spread.js +28 -0
  72. package/lib/helpers/throttle.js +44 -0
  73. package/lib/helpers/toFormData.js +223 -0
  74. package/lib/helpers/toURLEncodedForm.js +19 -0
  75. package/lib/helpers/trackStream.js +87 -0
  76. package/lib/helpers/validator.js +99 -0
  77. package/lib/platform/browser/classes/Blob.js +3 -0
  78. package/lib/platform/browser/classes/FormData.js +3 -0
  79. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  80. package/lib/platform/browser/index.js +13 -0
  81. package/lib/platform/common/utils.js +51 -0
  82. package/lib/platform/index.js +7 -0
  83. package/lib/platform/node/classes/FormData.js +3 -0
  84. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  85. package/lib/platform/node/index.js +38 -0
  86. package/lib/utils.js +782 -0
  87. package/package.json +237 -0
@@ -0,0 +1,126 @@
1
+ import utils from '../utils.js';
2
+ import httpAdapter from './http.js';
3
+ import xhrAdapter from './xhr.js';
4
+ import * as fetchAdapter from './fetch.js';
5
+ import AxiosError from "../core/AxiosError.js";
6
+
7
+ /**
8
+ * Known adapters mapping.
9
+ * Provides environment-specific adapters for Axios:
10
+ * - `http` for Node.js
11
+ * - `xhr` for browsers
12
+ * - `fetch` for fetch API-based requests
13
+ *
14
+ * @type {Object<string, Function|Object>}
15
+ */
16
+ const knownAdapters = {
17
+ http: httpAdapter,
18
+ xhr: xhrAdapter,
19
+ fetch: {
20
+ get: fetchAdapter.getFetch,
21
+ }
22
+ };
23
+
24
+ // Assign adapter names for easier debugging and identification
25
+ utils.forEach(knownAdapters, (fn, value) => {
26
+ if (fn) {
27
+ try {
28
+ Object.defineProperty(fn, 'name', { value });
29
+ } catch (e) {
30
+ // eslint-disable-next-line no-empty
31
+ }
32
+ Object.defineProperty(fn, 'adapterName', { value });
33
+ }
34
+ });
35
+
36
+ /**
37
+ * Render a rejection reason string for unknown or unsupported adapters
38
+ *
39
+ * @param {string} reason
40
+ * @returns {string}
41
+ */
42
+ const renderReason = (reason) => `- ${reason}`;
43
+
44
+ /**
45
+ * Check if the adapter is resolved (function, null, or false)
46
+ *
47
+ * @param {Function|null|false} adapter
48
+ * @returns {boolean}
49
+ */
50
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
51
+
52
+ /**
53
+ * Get the first suitable adapter from the provided list.
54
+ * Tries each adapter in order until a supported one is found.
55
+ * Throws an AxiosError if no adapter is suitable.
56
+ *
57
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
58
+ * @param {Object} config - Axios request configuration
59
+ * @throws {AxiosError} If no suitable adapter is available
60
+ * @returns {Function} The resolved adapter function
61
+ */
62
+ function getAdapter(adapters, config) {
63
+ adapters = utils.isArray(adapters) ? adapters : [adapters];
64
+
65
+ const { length } = adapters;
66
+ let nameOrAdapter;
67
+ let adapter;
68
+
69
+ const rejectedReasons = {};
70
+
71
+ for (let i = 0; i < length; i++) {
72
+ nameOrAdapter = adapters[i];
73
+ let id;
74
+
75
+ adapter = nameOrAdapter;
76
+
77
+ if (!isResolvedHandle(nameOrAdapter)) {
78
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
79
+
80
+ if (adapter === undefined) {
81
+ throw new AxiosError(`Unknown adapter '${id}'`);
82
+ }
83
+ }
84
+
85
+ if (adapter && (utils.isFunction(adapter) || (adapter = adapter.get(config)))) {
86
+ break;
87
+ }
88
+
89
+ rejectedReasons[id || '#' + i] = adapter;
90
+ }
91
+
92
+ if (!adapter) {
93
+ const reasons = Object.entries(rejectedReasons)
94
+ .map(([id, state]) => `adapter ${id} ` +
95
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
96
+ );
97
+
98
+ let s = length ?
99
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
100
+ 'as no adapter specified';
101
+
102
+ throw new AxiosError(
103
+ `There is no suitable adapter to dispatch the request ` + s,
104
+ 'ERR_NOT_SUPPORT'
105
+ );
106
+ }
107
+
108
+ return adapter;
109
+ }
110
+
111
+ /**
112
+ * Exports Axios adapters and utility to resolve an adapter
113
+ */
114
+ export default {
115
+ /**
116
+ * Resolve an adapter from a list of adapter names or functions.
117
+ * @type {Function}
118
+ */
119
+ getAdapter,
120
+
121
+ /**
122
+ * Exposes all known adapters
123
+ * @type {Object<string, Function|Object>}
124
+ */
125
+ adapters: knownAdapters
126
+ };
@@ -0,0 +1,288 @@
1
+ import platform from "../platform/index.js";
2
+ import utils from "../utils.js";
3
+ import AxiosError from "../core/AxiosError.js";
4
+ import composeSignals from "../helpers/composeSignals.js";
5
+ import {trackStream} from "../helpers/trackStream.js";
6
+ import AxiosHeaders from "../core/AxiosHeaders.js";
7
+ import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
8
+ import resolveConfig from "../helpers/resolveConfig.js";
9
+ import settle from "../core/settle.js";
10
+
11
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
12
+
13
+ const {isFunction} = utils;
14
+
15
+ const globalFetchAPI = (({Request, Response}) => ({
16
+ Request, Response
17
+ }))(utils.global);
18
+
19
+ const {
20
+ ReadableStream, TextEncoder
21
+ } = utils.global;
22
+
23
+
24
+ const test = (fn, ...args) => {
25
+ try {
26
+ return !!fn(...args);
27
+ } catch (e) {
28
+ return false
29
+ }
30
+ }
31
+
32
+ const factory = (env) => {
33
+ env = utils.merge.call({
34
+ skipUndefined: true
35
+ }, globalFetchAPI, env);
36
+
37
+ const {fetch: envFetch, Request, Response} = env;
38
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
39
+ const isRequestSupported = isFunction(Request);
40
+ const isResponseSupported = isFunction(Response);
41
+
42
+ if (!isFetchSupported) {
43
+ return false;
44
+ }
45
+
46
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
47
+
48
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
49
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
50
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
51
+ );
52
+
53
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
54
+ let duplexAccessed = false;
55
+
56
+ const hasContentType = new Request(platform.origin, {
57
+ body: new ReadableStream(),
58
+ method: 'POST',
59
+ get duplex() {
60
+ duplexAccessed = true;
61
+ return 'half';
62
+ },
63
+ }).headers.has('Content-Type');
64
+
65
+ return duplexAccessed && !hasContentType;
66
+ });
67
+
68
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
69
+ test(() => utils.isReadableStream(new Response('').body));
70
+
71
+ const resolvers = {
72
+ stream: supportsResponseStream && ((res) => res.body)
73
+ };
74
+
75
+ isFetchSupported && ((() => {
76
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
77
+ !resolvers[type] && (resolvers[type] = (res, config) => {
78
+ let method = res && res[type];
79
+
80
+ if (method) {
81
+ return method.call(res);
82
+ }
83
+
84
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
85
+ })
86
+ });
87
+ })());
88
+
89
+ const getBodyLength = async (body) => {
90
+ if (body == null) {
91
+ return 0;
92
+ }
93
+
94
+ if (utils.isBlob(body)) {
95
+ return body.size;
96
+ }
97
+
98
+ if (utils.isSpecCompliantForm(body)) {
99
+ const _request = new Request(platform.origin, {
100
+ method: 'POST',
101
+ body,
102
+ });
103
+ return (await _request.arrayBuffer()).byteLength;
104
+ }
105
+
106
+ if (utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
107
+ return body.byteLength;
108
+ }
109
+
110
+ if (utils.isURLSearchParams(body)) {
111
+ body = body + '';
112
+ }
113
+
114
+ if (utils.isString(body)) {
115
+ return (await encodeText(body)).byteLength;
116
+ }
117
+ }
118
+
119
+ const resolveBodyLength = async (headers, body) => {
120
+ const length = utils.toFiniteNumber(headers.getContentLength());
121
+
122
+ return length == null ? getBodyLength(body) : length;
123
+ }
124
+
125
+ return async (config) => {
126
+ let {
127
+ url,
128
+ method,
129
+ data,
130
+ signal,
131
+ cancelToken,
132
+ timeout,
133
+ onDownloadProgress,
134
+ onUploadProgress,
135
+ responseType,
136
+ headers,
137
+ withCredentials = 'same-origin',
138
+ fetchOptions
139
+ } = resolveConfig(config);
140
+
141
+ let _fetch = envFetch || fetch;
142
+
143
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
144
+
145
+ let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
146
+
147
+ let request = null;
148
+
149
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
150
+ composedSignal.unsubscribe();
151
+ });
152
+
153
+ let requestContentLength;
154
+
155
+ try {
156
+ if (
157
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
158
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
159
+ ) {
160
+ let _request = new Request(url, {
161
+ method: 'POST',
162
+ body: data,
163
+ duplex: "half"
164
+ });
165
+
166
+ let contentTypeHeader;
167
+
168
+ if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
169
+ headers.setContentType(contentTypeHeader)
170
+ }
171
+
172
+ if (_request.body) {
173
+ const [onProgress, flush] = progressEventDecorator(
174
+ requestContentLength,
175
+ progressEventReducer(asyncDecorator(onUploadProgress))
176
+ );
177
+
178
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
179
+ }
180
+ }
181
+
182
+ if (!utils.isString(withCredentials)) {
183
+ withCredentials = withCredentials ? 'include' : 'omit';
184
+ }
185
+
186
+ // Cloudflare Workers throws when credentials are defined
187
+ // see https://github.com/cloudflare/workerd/issues/902
188
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
189
+
190
+ const resolvedOptions = {
191
+ ...fetchOptions,
192
+ signal: composedSignal,
193
+ method: method.toUpperCase(),
194
+ headers: headers.normalize().toJSON(),
195
+ body: data,
196
+ duplex: "half",
197
+ credentials: isCredentialsSupported ? withCredentials : undefined
198
+ };
199
+
200
+ request = isRequestSupported && new Request(url, resolvedOptions);
201
+
202
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
203
+
204
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
205
+
206
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
207
+ const options = {};
208
+
209
+ ['status', 'statusText', 'headers'].forEach(prop => {
210
+ options[prop] = response[prop];
211
+ });
212
+
213
+ const responseContentLength = utils.toFiniteNumber(response.headers.get('content-length'));
214
+
215
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
216
+ responseContentLength,
217
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
218
+ ) || [];
219
+
220
+ response = new Response(
221
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
222
+ flush && flush();
223
+ unsubscribe && unsubscribe();
224
+ }),
225
+ options
226
+ );
227
+ }
228
+
229
+ responseType = responseType || 'text';
230
+
231
+ let responseData = await resolvers[utils.findKey(resolvers, responseType) || 'text'](response, config);
232
+
233
+ !isStreamResponse && unsubscribe && unsubscribe();
234
+
235
+ return await new Promise((resolve, reject) => {
236
+ settle(resolve, reject, {
237
+ data: responseData,
238
+ headers: AxiosHeaders.from(response.headers),
239
+ status: response.status,
240
+ statusText: response.statusText,
241
+ config,
242
+ request
243
+ })
244
+ })
245
+ } catch (err) {
246
+ unsubscribe && unsubscribe();
247
+
248
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
249
+ throw Object.assign(
250
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
251
+ {
252
+ cause: err.cause || err
253
+ }
254
+ )
255
+ }
256
+
257
+ throw AxiosError.from(err, err && err.code, config, request);
258
+ }
259
+ }
260
+ }
261
+
262
+ const seedCache = new Map();
263
+
264
+ export const getFetch = (config) => {
265
+ let env = (config && config.env) || {};
266
+ const {fetch, Request, Response} = env;
267
+ const seeds = [
268
+ Request, Response, fetch
269
+ ];
270
+
271
+ let len = seeds.length, i = len,
272
+ seed, target, map = seedCache;
273
+
274
+ while (i--) {
275
+ seed = seeds[i];
276
+ target = map.get(seed);
277
+
278
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)))
279
+
280
+ map = target;
281
+ }
282
+
283
+ return target;
284
+ };
285
+
286
+ const adapter = getFetch();
287
+
288
+ export default adapter;