@impui/imp 1.0.15 → 1.0.16-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.
- package/dist/axios/index.es.js +143 -0
- package/dist/config/index.es.js +127 -0
- package/dist/core/index.es.js +34 -0
- package/dist/gotool/go2/index.es.js +510 -0
- package/dist/gotool/index/index.es.js +164 -0
- package/dist/imph5/index.es.js +324 -0
- package/dist/index.es.js +49 -1
- package/dist/login/index.es.js +711 -0
- package/dist/node_modules/axios/index/index.es.js +38 -0
- package/dist/node_modules/axios/lib/adapters/adapters/index.es.js +71 -0
- package/dist/node_modules/axios/lib/adapters/fetch/index.es.js +219 -0
- package/dist/node_modules/axios/lib/adapters/xhr/index.es.js +141 -0
- package/dist/node_modules/axios/lib/axios/index.es.js +50 -0
- package/dist/node_modules/axios/lib/cancel/CancelToken/index.es.js +99 -0
- package/dist/node_modules/axios/lib/cancel/CanceledError/index.es.js +12 -0
- package/dist/node_modules/axios/lib/cancel/isCancel/index.es.js +6 -0
- package/dist/node_modules/axios/lib/core/Axios/index.es.js +180 -0
- package/dist/node_modules/axios/lib/core/AxiosError/index.es.js +80 -0
- package/dist/node_modules/axios/lib/core/AxiosHeaders/index.es.js +231 -0
- package/dist/node_modules/axios/lib/core/InterceptorManager/index.es.js +65 -0
- package/dist/node_modules/axios/lib/core/buildFullPath/index.es.js +12 -0
- package/dist/node_modules/axios/lib/core/dispatchRequest/index.es.js +52 -0
- package/dist/node_modules/axios/lib/core/mergeConfig/index.es.js +83 -0
- package/dist/node_modules/axios/lib/core/settle/index.es.js +18 -0
- package/dist/node_modules/axios/lib/core/transformData/index.es.js +17 -0
- package/dist/node_modules/axios/lib/defaults/index/index.es.js +116 -0
- package/dist/node_modules/axios/lib/defaults/transitional/index.es.js +8 -0
- package/dist/node_modules/axios/lib/env/data/index.es.js +4 -0
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams/index.es.js +34 -0
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode/index.es.js +77 -0
- package/dist/node_modules/axios/lib/helpers/bind/index.es.js +8 -0
- package/dist/node_modules/axios/lib/helpers/buildURL/index.es.js +34 -0
- package/dist/node_modules/axios/lib/helpers/combineURLs/index.es.js +6 -0
- package/dist/node_modules/axios/lib/helpers/composeSignals/index.es.js +39 -0
- package/dist/node_modules/axios/lib/helpers/cookies/index.es.js +49 -0
- package/dist/node_modules/axios/lib/helpers/formDataToJSON/index.es.js +54 -0
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL/index.es.js +6 -0
- package/dist/node_modules/axios/lib/helpers/isAxiosError/index.es.js +7 -0
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin/index.es.js +11 -0
- package/dist/node_modules/axios/lib/helpers/null/index.es.js +4 -0
- package/dist/node_modules/axios/lib/helpers/parseHeaders/index.es.js +47 -0
- package/dist/node_modules/axios/lib/helpers/parseProtocol/index.es.js +7 -0
- package/dist/node_modules/axios/lib/helpers/progressEventReducer/index.es.js +41 -0
- package/dist/node_modules/axios/lib/helpers/resolveConfig/index.es.js +46 -0
- package/dist/node_modules/axios/lib/helpers/speedometer/index.es.js +36 -0
- package/dist/node_modules/axios/lib/helpers/spread/index.es.js +8 -0
- package/dist/node_modules/axios/lib/helpers/throttle/index.es.js +35 -0
- package/dist/node_modules/axios/lib/helpers/toFormData/index.es.js +117 -0
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm/index.es.js +18 -0
- package/dist/node_modules/axios/lib/helpers/trackStream/index.es.js +80 -0
- package/dist/node_modules/axios/lib/helpers/validator/index.es.js +67 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob/index.es.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData/index.es.js +4 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams/index.es.js +5 -0
- package/dist/node_modules/axios/lib/platform/browser/index/index.es.js +15 -0
- package/dist/node_modules/axios/lib/platform/common/utils/index.es.js +15 -0
- package/dist/node_modules/axios/lib/platform/index/index.es.js +9 -0
- package/dist/node_modules/axios/lib/utils/index.es.js +387 -0
- package/dist/packages/com/dist/browser/index.es/index.es.js +1 -0
- package/dist/packages/com/dist/cache/index.es/index.es.js +145 -0
- package/dist/packages/com/dist/core/index.es/index.es.js +154 -0
- package/dist/packages/com/dist/data/index.es/index.es.js +26 -0
- package/dist/packages/com/dist/date/index.es/index.es.js +194 -0
- package/dist/packages/com/dist/log/index.es/index.es.js +110 -0
- package/dist/packages/com/dist/message/index.es/index.es.js +90 -0
- package/dist/packages/com/dist/req/index.es/index.es.js +35 -0
- package/dist/packages/com/dist/str/index.es/index.es.js +25 -0
- package/dist/packages/com/dist/typetool/index.es/index.es.js +53 -0
- package/dist/packages/com/dist/url/index.es/index.es.js +238 -0
- package/dist/restool/index/index.es.js +266 -0
- package/dist/restool/index.css/index.es.js +4 -0
- package/package.json +2 -3
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import axios from "../lib/axios/index.es.js";
|
|
2
|
+
const {
|
|
3
|
+
Axios,
|
|
4
|
+
AxiosError,
|
|
5
|
+
CanceledError,
|
|
6
|
+
isCancel,
|
|
7
|
+
CancelToken,
|
|
8
|
+
VERSION,
|
|
9
|
+
all,
|
|
10
|
+
Cancel,
|
|
11
|
+
isAxiosError,
|
|
12
|
+
spread,
|
|
13
|
+
toFormData,
|
|
14
|
+
AxiosHeaders,
|
|
15
|
+
HttpStatusCode,
|
|
16
|
+
formToJSON,
|
|
17
|
+
getAdapter,
|
|
18
|
+
mergeConfig
|
|
19
|
+
} = axios;
|
|
20
|
+
export {
|
|
21
|
+
Axios,
|
|
22
|
+
AxiosError,
|
|
23
|
+
AxiosHeaders,
|
|
24
|
+
Cancel,
|
|
25
|
+
CancelToken,
|
|
26
|
+
CanceledError,
|
|
27
|
+
HttpStatusCode,
|
|
28
|
+
VERSION,
|
|
29
|
+
all,
|
|
30
|
+
axios as default,
|
|
31
|
+
formToJSON,
|
|
32
|
+
getAdapter,
|
|
33
|
+
isAxiosError,
|
|
34
|
+
isCancel,
|
|
35
|
+
mergeConfig,
|
|
36
|
+
spread,
|
|
37
|
+
toFormData
|
|
38
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import utils from "../../utils/index.es.js";
|
|
2
|
+
import httpAdapter from "../../helpers/null/index.es.js";
|
|
3
|
+
import xhrAdapter from "../xhr/index.es.js";
|
|
4
|
+
import { getFetch } from "../fetch/index.es.js";
|
|
5
|
+
import AxiosError from "../../core/AxiosError/index.es.js";
|
|
6
|
+
const knownAdapters = {
|
|
7
|
+
http: httpAdapter,
|
|
8
|
+
xhr: xhrAdapter,
|
|
9
|
+
fetch: {
|
|
10
|
+
get: getFetch
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
utils.forEach(knownAdapters, (fn, value) => {
|
|
14
|
+
if (fn) {
|
|
15
|
+
try {
|
|
16
|
+
Object.defineProperty(fn, "name", { value });
|
|
17
|
+
} catch (e) {
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(fn, "adapterName", { value });
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const renderReason = (reason) => `- ${reason}`;
|
|
23
|
+
const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
|
|
24
|
+
function getAdapter(adapters2, config) {
|
|
25
|
+
adapters2 = utils.isArray(adapters2) ? adapters2 : [adapters2];
|
|
26
|
+
const { length } = adapters2;
|
|
27
|
+
let nameOrAdapter;
|
|
28
|
+
let adapter;
|
|
29
|
+
const rejectedReasons = {};
|
|
30
|
+
for (let i = 0; i < length; i++) {
|
|
31
|
+
nameOrAdapter = adapters2[i];
|
|
32
|
+
let id;
|
|
33
|
+
adapter = nameOrAdapter;
|
|
34
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
|
35
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
|
36
|
+
if (adapter === void 0) {
|
|
37
|
+
throw new AxiosError(`Unknown adapter '${id}'`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (adapter && (utils.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
rejectedReasons[id || "#" + i] = adapter;
|
|
44
|
+
}
|
|
45
|
+
if (!adapter) {
|
|
46
|
+
const reasons = Object.entries(rejectedReasons).map(
|
|
47
|
+
([id, state]) => `adapter ${id} ` + (state === false ? "is not supported by the environment" : "is not available in the build")
|
|
48
|
+
);
|
|
49
|
+
let s = length ? reasons.length > 1 ? "since :\n" + reasons.map(renderReason).join("\n") : " " + renderReason(reasons[0]) : "as no adapter specified";
|
|
50
|
+
throw new AxiosError(
|
|
51
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
|
52
|
+
"ERR_NOT_SUPPORT"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return adapter;
|
|
56
|
+
}
|
|
57
|
+
const adapters = {
|
|
58
|
+
/**
|
|
59
|
+
* Resolve an adapter from a list of adapter names or functions.
|
|
60
|
+
* @type {Function}
|
|
61
|
+
*/
|
|
62
|
+
getAdapter,
|
|
63
|
+
/**
|
|
64
|
+
* Exposes all known adapters
|
|
65
|
+
* @type {Object<string, Function|Object>}
|
|
66
|
+
*/
|
|
67
|
+
adapters: knownAdapters
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
adapters as default
|
|
71
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import platform from "../../platform/index/index.es.js";
|
|
2
|
+
import utils from "../../utils/index.es.js";
|
|
3
|
+
import AxiosError from "../../core/AxiosError/index.es.js";
|
|
4
|
+
import composeSignals from "../../helpers/composeSignals/index.es.js";
|
|
5
|
+
import { trackStream } from "../../helpers/trackStream/index.es.js";
|
|
6
|
+
import AxiosHeaders from "../../core/AxiosHeaders/index.es.js";
|
|
7
|
+
import { progressEventDecorator, progressEventReducer, asyncDecorator } from "../../helpers/progressEventReducer/index.es.js";
|
|
8
|
+
import resolveConfig from "../../helpers/resolveConfig/index.es.js";
|
|
9
|
+
import settle from "../../core/settle/index.es.js";
|
|
10
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
11
|
+
const { isFunction } = utils;
|
|
12
|
+
const globalFetchAPI = (({ Request, Response }) => ({
|
|
13
|
+
Request,
|
|
14
|
+
Response
|
|
15
|
+
}))(utils.global);
|
|
16
|
+
const {
|
|
17
|
+
ReadableStream,
|
|
18
|
+
TextEncoder
|
|
19
|
+
} = utils.global;
|
|
20
|
+
const test = (fn, ...args) => {
|
|
21
|
+
try {
|
|
22
|
+
return !!fn(...args);
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const factory = (env) => {
|
|
28
|
+
env = utils.merge.call({
|
|
29
|
+
skipUndefined: true
|
|
30
|
+
}, globalFetchAPI, env);
|
|
31
|
+
const { fetch: envFetch, Request, Response } = env;
|
|
32
|
+
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === "function";
|
|
33
|
+
const isRequestSupported = isFunction(Request);
|
|
34
|
+
const isResponseSupported = isFunction(Response);
|
|
35
|
+
if (!isFetchSupported) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
|
|
39
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === "function" ? /* @__PURE__ */ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
|
|
40
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
41
|
+
let duplexAccessed = false;
|
|
42
|
+
const hasContentType = new Request(platform.origin, {
|
|
43
|
+
body: new ReadableStream(),
|
|
44
|
+
method: "POST",
|
|
45
|
+
get duplex() {
|
|
46
|
+
duplexAccessed = true;
|
|
47
|
+
return "half";
|
|
48
|
+
}
|
|
49
|
+
}).headers.has("Content-Type");
|
|
50
|
+
return duplexAccessed && !hasContentType;
|
|
51
|
+
});
|
|
52
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported && test(() => utils.isReadableStream(new Response("").body));
|
|
53
|
+
const resolvers = {
|
|
54
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
55
|
+
};
|
|
56
|
+
isFetchSupported && (() => {
|
|
57
|
+
["text", "arrayBuffer", "blob", "formData", "stream"].forEach((type) => {
|
|
58
|
+
!resolvers[type] && (resolvers[type] = (res, config) => {
|
|
59
|
+
let method = res && res[type];
|
|
60
|
+
if (method) {
|
|
61
|
+
return method.call(res);
|
|
62
|
+
}
|
|
63
|
+
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
})();
|
|
67
|
+
const getBodyLength = async (body) => {
|
|
68
|
+
if (body == null) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
if (utils.isBlob(body)) {
|
|
72
|
+
return body.size;
|
|
73
|
+
}
|
|
74
|
+
if (utils.isSpecCompliantForm(body)) {
|
|
75
|
+
const _request = new Request(platform.origin, {
|
|
76
|
+
method: "POST",
|
|
77
|
+
body
|
|
78
|
+
});
|
|
79
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
80
|
+
}
|
|
81
|
+
if (utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
|
|
82
|
+
return body.byteLength;
|
|
83
|
+
}
|
|
84
|
+
if (utils.isURLSearchParams(body)) {
|
|
85
|
+
body = body + "";
|
|
86
|
+
}
|
|
87
|
+
if (utils.isString(body)) {
|
|
88
|
+
return (await encodeText(body)).byteLength;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const resolveBodyLength = async (headers, body) => {
|
|
92
|
+
const length = utils.toFiniteNumber(headers.getContentLength());
|
|
93
|
+
return length == null ? getBodyLength(body) : length;
|
|
94
|
+
};
|
|
95
|
+
return async (config) => {
|
|
96
|
+
let {
|
|
97
|
+
url,
|
|
98
|
+
method,
|
|
99
|
+
data,
|
|
100
|
+
signal,
|
|
101
|
+
cancelToken,
|
|
102
|
+
timeout,
|
|
103
|
+
onDownloadProgress,
|
|
104
|
+
onUploadProgress,
|
|
105
|
+
responseType,
|
|
106
|
+
headers,
|
|
107
|
+
withCredentials = "same-origin",
|
|
108
|
+
fetchOptions
|
|
109
|
+
} = resolveConfig(config);
|
|
110
|
+
let _fetch = envFetch || fetch;
|
|
111
|
+
responseType = responseType ? (responseType + "").toLowerCase() : "text";
|
|
112
|
+
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
113
|
+
let request = null;
|
|
114
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
115
|
+
composedSignal.unsubscribe();
|
|
116
|
+
});
|
|
117
|
+
let requestContentLength;
|
|
118
|
+
try {
|
|
119
|
+
if (onUploadProgress && supportsRequestStream && method !== "get" && method !== "head" && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
|
|
120
|
+
let _request = new Request(url, {
|
|
121
|
+
method: "POST",
|
|
122
|
+
body: data,
|
|
123
|
+
duplex: "half"
|
|
124
|
+
});
|
|
125
|
+
let contentTypeHeader;
|
|
126
|
+
if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get("content-type"))) {
|
|
127
|
+
headers.setContentType(contentTypeHeader);
|
|
128
|
+
}
|
|
129
|
+
if (_request.body) {
|
|
130
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
131
|
+
requestContentLength,
|
|
132
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
133
|
+
);
|
|
134
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!utils.isString(withCredentials)) {
|
|
138
|
+
withCredentials = withCredentials ? "include" : "omit";
|
|
139
|
+
}
|
|
140
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
141
|
+
const resolvedOptions = {
|
|
142
|
+
...fetchOptions,
|
|
143
|
+
signal: composedSignal,
|
|
144
|
+
method: method.toUpperCase(),
|
|
145
|
+
headers: headers.normalize().toJSON(),
|
|
146
|
+
body: data,
|
|
147
|
+
duplex: "half",
|
|
148
|
+
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
149
|
+
};
|
|
150
|
+
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
151
|
+
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
|
152
|
+
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
153
|
+
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
154
|
+
const options = {};
|
|
155
|
+
["status", "statusText", "headers"].forEach((prop) => {
|
|
156
|
+
options[prop] = response[prop];
|
|
157
|
+
});
|
|
158
|
+
const responseContentLength = utils.toFiniteNumber(response.headers.get("content-length"));
|
|
159
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
160
|
+
responseContentLength,
|
|
161
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
162
|
+
) || [];
|
|
163
|
+
response = new Response(
|
|
164
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
165
|
+
flush && flush();
|
|
166
|
+
unsubscribe && unsubscribe();
|
|
167
|
+
}),
|
|
168
|
+
options
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
responseType = responseType || "text";
|
|
172
|
+
let responseData = await resolvers[utils.findKey(resolvers, responseType) || "text"](response, config);
|
|
173
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
174
|
+
return await new Promise((resolve, reject) => {
|
|
175
|
+
settle(resolve, reject, {
|
|
176
|
+
data: responseData,
|
|
177
|
+
headers: AxiosHeaders.from(response.headers),
|
|
178
|
+
status: response.status,
|
|
179
|
+
statusText: response.statusText,
|
|
180
|
+
config,
|
|
181
|
+
request
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
} catch (err) {
|
|
185
|
+
unsubscribe && unsubscribe();
|
|
186
|
+
if (err && err.name === "TypeError" && /Load failed|fetch/i.test(err.message)) {
|
|
187
|
+
throw Object.assign(
|
|
188
|
+
new AxiosError("Network Error", AxiosError.ERR_NETWORK, config, request),
|
|
189
|
+
{
|
|
190
|
+
cause: err.cause || err
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const seedCache = /* @__PURE__ */ new Map();
|
|
199
|
+
const getFetch = (config) => {
|
|
200
|
+
let env = config && config.env || {};
|
|
201
|
+
const { fetch: fetch2, Request, Response } = env;
|
|
202
|
+
const seeds = [
|
|
203
|
+
Request,
|
|
204
|
+
Response,
|
|
205
|
+
fetch2
|
|
206
|
+
];
|
|
207
|
+
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
208
|
+
while (i--) {
|
|
209
|
+
seed = seeds[i];
|
|
210
|
+
target = map.get(seed);
|
|
211
|
+
target === void 0 && map.set(seed, target = i ? /* @__PURE__ */ new Map() : factory(env));
|
|
212
|
+
map = target;
|
|
213
|
+
}
|
|
214
|
+
return target;
|
|
215
|
+
};
|
|
216
|
+
getFetch();
|
|
217
|
+
export {
|
|
218
|
+
getFetch
|
|
219
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import utils from "../../utils/index.es.js";
|
|
2
|
+
import settle from "../../core/settle/index.es.js";
|
|
3
|
+
import transitionalDefaults from "../../defaults/transitional/index.es.js";
|
|
4
|
+
import AxiosError from "../../core/AxiosError/index.es.js";
|
|
5
|
+
import CanceledError from "../../cancel/CanceledError/index.es.js";
|
|
6
|
+
import parseProtocol from "../../helpers/parseProtocol/index.es.js";
|
|
7
|
+
import platform from "../../platform/index/index.es.js";
|
|
8
|
+
import AxiosHeaders from "../../core/AxiosHeaders/index.es.js";
|
|
9
|
+
import { progressEventReducer } from "../../helpers/progressEventReducer/index.es.js";
|
|
10
|
+
import resolveConfig from "../../helpers/resolveConfig/index.es.js";
|
|
11
|
+
const isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
12
|
+
const xhrAdapter = isXHRAdapterSupported && function(config) {
|
|
13
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
14
|
+
const _config = resolveConfig(config);
|
|
15
|
+
let requestData = _config.data;
|
|
16
|
+
const requestHeaders = AxiosHeaders.from(_config.headers).normalize();
|
|
17
|
+
let { responseType, onUploadProgress, onDownloadProgress } = _config;
|
|
18
|
+
let onCanceled;
|
|
19
|
+
let uploadThrottled, downloadThrottled;
|
|
20
|
+
let flushUpload, flushDownload;
|
|
21
|
+
function done() {
|
|
22
|
+
flushUpload && flushUpload();
|
|
23
|
+
flushDownload && flushDownload();
|
|
24
|
+
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
|
25
|
+
_config.signal && _config.signal.removeEventListener("abort", onCanceled);
|
|
26
|
+
}
|
|
27
|
+
let request = new XMLHttpRequest();
|
|
28
|
+
request.open(_config.method.toUpperCase(), _config.url, true);
|
|
29
|
+
request.timeout = _config.timeout;
|
|
30
|
+
function onloadend() {
|
|
31
|
+
if (!request) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const responseHeaders = AxiosHeaders.from(
|
|
35
|
+
"getAllResponseHeaders" in request && request.getAllResponseHeaders()
|
|
36
|
+
);
|
|
37
|
+
const responseData = !responseType || responseType === "text" || responseType === "json" ? request.responseText : request.response;
|
|
38
|
+
const response = {
|
|
39
|
+
data: responseData,
|
|
40
|
+
status: request.status,
|
|
41
|
+
statusText: request.statusText,
|
|
42
|
+
headers: responseHeaders,
|
|
43
|
+
config,
|
|
44
|
+
request
|
|
45
|
+
};
|
|
46
|
+
settle(function _resolve(value) {
|
|
47
|
+
resolve(value);
|
|
48
|
+
done();
|
|
49
|
+
}, function _reject(err) {
|
|
50
|
+
reject(err);
|
|
51
|
+
done();
|
|
52
|
+
}, response);
|
|
53
|
+
request = null;
|
|
54
|
+
}
|
|
55
|
+
if ("onloadend" in request) {
|
|
56
|
+
request.onloadend = onloadend;
|
|
57
|
+
} else {
|
|
58
|
+
request.onreadystatechange = function handleLoad() {
|
|
59
|
+
if (!request || request.readyState !== 4) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf("file:") === 0)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setTimeout(onloadend);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
request.onabort = function handleAbort() {
|
|
69
|
+
if (!request) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
reject(new AxiosError("Request aborted", AxiosError.ECONNABORTED, config, request));
|
|
73
|
+
request = null;
|
|
74
|
+
};
|
|
75
|
+
request.onerror = function handleError(event) {
|
|
76
|
+
const msg = event && event.message ? event.message : "Network Error";
|
|
77
|
+
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|
78
|
+
err.event = event || null;
|
|
79
|
+
reject(err);
|
|
80
|
+
request = null;
|
|
81
|
+
};
|
|
82
|
+
request.ontimeout = function handleTimeout() {
|
|
83
|
+
let timeoutErrorMessage = _config.timeout ? "timeout of " + _config.timeout + "ms exceeded" : "timeout exceeded";
|
|
84
|
+
const transitional = _config.transitional || transitionalDefaults;
|
|
85
|
+
if (_config.timeoutErrorMessage) {
|
|
86
|
+
timeoutErrorMessage = _config.timeoutErrorMessage;
|
|
87
|
+
}
|
|
88
|
+
reject(new AxiosError(
|
|
89
|
+
timeoutErrorMessage,
|
|
90
|
+
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
|
91
|
+
config,
|
|
92
|
+
request
|
|
93
|
+
));
|
|
94
|
+
request = null;
|
|
95
|
+
};
|
|
96
|
+
requestData === void 0 && requestHeaders.setContentType(null);
|
|
97
|
+
if ("setRequestHeader" in request) {
|
|
98
|
+
utils.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
|
|
99
|
+
request.setRequestHeader(key, val);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (!utils.isUndefined(_config.withCredentials)) {
|
|
103
|
+
request.withCredentials = !!_config.withCredentials;
|
|
104
|
+
}
|
|
105
|
+
if (responseType && responseType !== "json") {
|
|
106
|
+
request.responseType = _config.responseType;
|
|
107
|
+
}
|
|
108
|
+
if (onDownloadProgress) {
|
|
109
|
+
[downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true);
|
|
110
|
+
request.addEventListener("progress", downloadThrottled);
|
|
111
|
+
}
|
|
112
|
+
if (onUploadProgress && request.upload) {
|
|
113
|
+
[uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress);
|
|
114
|
+
request.upload.addEventListener("progress", uploadThrottled);
|
|
115
|
+
request.upload.addEventListener("loadend", flushUpload);
|
|
116
|
+
}
|
|
117
|
+
if (_config.cancelToken || _config.signal) {
|
|
118
|
+
onCanceled = (cancel) => {
|
|
119
|
+
if (!request) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
|
123
|
+
request.abort();
|
|
124
|
+
request = null;
|
|
125
|
+
};
|
|
126
|
+
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
|
127
|
+
if (_config.signal) {
|
|
128
|
+
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener("abort", onCanceled);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const protocol = parseProtocol(_config.url);
|
|
132
|
+
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
|
133
|
+
reject(new AxiosError("Unsupported protocol " + protocol + ":", AxiosError.ERR_BAD_REQUEST, config));
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
request.send(requestData || null);
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
export {
|
|
140
|
+
xhrAdapter as default
|
|
141
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import utils from "../utils/index.es.js";
|
|
2
|
+
import bind from "../helpers/bind/index.es.js";
|
|
3
|
+
import Axios from "../core/Axios/index.es.js";
|
|
4
|
+
import mergeConfig from "../core/mergeConfig/index.es.js";
|
|
5
|
+
import defaults from "../defaults/index/index.es.js";
|
|
6
|
+
import formDataToJSON from "../helpers/formDataToJSON/index.es.js";
|
|
7
|
+
import CanceledError from "../cancel/CanceledError/index.es.js";
|
|
8
|
+
import CancelToken from "../cancel/CancelToken/index.es.js";
|
|
9
|
+
import isCancel from "../cancel/isCancel/index.es.js";
|
|
10
|
+
import { VERSION } from "../env/data/index.es.js";
|
|
11
|
+
import toFormData from "../helpers/toFormData/index.es.js";
|
|
12
|
+
import AxiosError from "../core/AxiosError/index.es.js";
|
|
13
|
+
import spread from "../helpers/spread/index.es.js";
|
|
14
|
+
import isAxiosError from "../helpers/isAxiosError/index.es.js";
|
|
15
|
+
import AxiosHeaders from "../core/AxiosHeaders/index.es.js";
|
|
16
|
+
import adapters from "../adapters/adapters/index.es.js";
|
|
17
|
+
import HttpStatusCode from "../helpers/HttpStatusCode/index.es.js";
|
|
18
|
+
function createInstance(defaultConfig) {
|
|
19
|
+
const context = new Axios(defaultConfig);
|
|
20
|
+
const instance = bind(Axios.prototype.request, context);
|
|
21
|
+
utils.extend(instance, Axios.prototype, context, { allOwnKeys: true });
|
|
22
|
+
utils.extend(instance, context, null, { allOwnKeys: true });
|
|
23
|
+
instance.create = function create(instanceConfig) {
|
|
24
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
|
25
|
+
};
|
|
26
|
+
return instance;
|
|
27
|
+
}
|
|
28
|
+
const axios = createInstance(defaults);
|
|
29
|
+
axios.Axios = Axios;
|
|
30
|
+
axios.CanceledError = CanceledError;
|
|
31
|
+
axios.CancelToken = CancelToken;
|
|
32
|
+
axios.isCancel = isCancel;
|
|
33
|
+
axios.VERSION = VERSION;
|
|
34
|
+
axios.toFormData = toFormData;
|
|
35
|
+
axios.AxiosError = AxiosError;
|
|
36
|
+
axios.Cancel = axios.CanceledError;
|
|
37
|
+
axios.all = function all(promises) {
|
|
38
|
+
return Promise.all(promises);
|
|
39
|
+
};
|
|
40
|
+
axios.spread = spread;
|
|
41
|
+
axios.isAxiosError = isAxiosError;
|
|
42
|
+
axios.mergeConfig = mergeConfig;
|
|
43
|
+
axios.AxiosHeaders = AxiosHeaders;
|
|
44
|
+
axios.formToJSON = (thing) => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
45
|
+
axios.getAdapter = adapters.getAdapter;
|
|
46
|
+
axios.HttpStatusCode = HttpStatusCode;
|
|
47
|
+
axios.default = axios;
|
|
48
|
+
export {
|
|
49
|
+
axios as default
|
|
50
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import CanceledError from "../CanceledError/index.es.js";
|
|
2
|
+
class CancelToken {
|
|
3
|
+
constructor(executor) {
|
|
4
|
+
if (typeof executor !== "function") {
|
|
5
|
+
throw new TypeError("executor must be a function.");
|
|
6
|
+
}
|
|
7
|
+
let resolvePromise;
|
|
8
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
9
|
+
resolvePromise = resolve;
|
|
10
|
+
});
|
|
11
|
+
const token = this;
|
|
12
|
+
this.promise.then((cancel) => {
|
|
13
|
+
if (!token._listeners) return;
|
|
14
|
+
let i = token._listeners.length;
|
|
15
|
+
while (i-- > 0) {
|
|
16
|
+
token._listeners[i](cancel);
|
|
17
|
+
}
|
|
18
|
+
token._listeners = null;
|
|
19
|
+
});
|
|
20
|
+
this.promise.then = (onfulfilled) => {
|
|
21
|
+
let _resolve;
|
|
22
|
+
const promise = new Promise((resolve) => {
|
|
23
|
+
token.subscribe(resolve);
|
|
24
|
+
_resolve = resolve;
|
|
25
|
+
}).then(onfulfilled);
|
|
26
|
+
promise.cancel = function reject() {
|
|
27
|
+
token.unsubscribe(_resolve);
|
|
28
|
+
};
|
|
29
|
+
return promise;
|
|
30
|
+
};
|
|
31
|
+
executor(function cancel(message, config, request) {
|
|
32
|
+
if (token.reason) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
token.reason = new CanceledError(message, config, request);
|
|
36
|
+
resolvePromise(token.reason);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
|
41
|
+
*/
|
|
42
|
+
throwIfRequested() {
|
|
43
|
+
if (this.reason) {
|
|
44
|
+
throw this.reason;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Subscribe to the cancel signal
|
|
49
|
+
*/
|
|
50
|
+
subscribe(listener) {
|
|
51
|
+
if (this.reason) {
|
|
52
|
+
listener(this.reason);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (this._listeners) {
|
|
56
|
+
this._listeners.push(listener);
|
|
57
|
+
} else {
|
|
58
|
+
this._listeners = [listener];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Unsubscribe from the cancel signal
|
|
63
|
+
*/
|
|
64
|
+
unsubscribe(listener) {
|
|
65
|
+
if (!this._listeners) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const index = this._listeners.indexOf(listener);
|
|
69
|
+
if (index !== -1) {
|
|
70
|
+
this._listeners.splice(index, 1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
toAbortSignal() {
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const abort = (err) => {
|
|
76
|
+
controller.abort(err);
|
|
77
|
+
};
|
|
78
|
+
this.subscribe(abort);
|
|
79
|
+
controller.signal.unsubscribe = () => this.unsubscribe(abort);
|
|
80
|
+
return controller.signal;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
|
84
|
+
* cancels the `CancelToken`.
|
|
85
|
+
*/
|
|
86
|
+
static source() {
|
|
87
|
+
let cancel;
|
|
88
|
+
const token = new CancelToken(function executor(c) {
|
|
89
|
+
cancel = c;
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
token,
|
|
93
|
+
cancel
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export {
|
|
98
|
+
CancelToken as default
|
|
99
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AxiosError from "../../core/AxiosError/index.es.js";
|
|
2
|
+
import utils from "../../utils/index.es.js";
|
|
3
|
+
function CanceledError(message, config, request) {
|
|
4
|
+
AxiosError.call(this, message == null ? "canceled" : message, AxiosError.ERR_CANCELED, config, request);
|
|
5
|
+
this.name = "CanceledError";
|
|
6
|
+
}
|
|
7
|
+
utils.inherits(CanceledError, AxiosError, {
|
|
8
|
+
__CANCEL__: true
|
|
9
|
+
});
|
|
10
|
+
export {
|
|
11
|
+
CanceledError as default
|
|
12
|
+
};
|