tp-react-elements-dev 1.14.14 → 1.15.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/_virtual/index.esm11.js +2 -2
- package/dist/_virtual/index.esm12.js +2 -2
- package/dist/_virtual/index.esm13.js +2 -2
- package/dist/_virtual/index.esm4.js +2 -2
- package/dist/_virtual/index.esm5.js +2 -2
- package/dist/_virtual/index.esm6.js +2 -2
- package/dist/_virtual/index.esm7.js +2 -2
- package/dist/components/Form/FormConstants.esm.js +6 -0
- package/dist/components/Form/FormRender.esm.js +3 -0
- package/dist/components/FormComponents/Select/SingleSelectSearchApi.d.ts +6 -2
- package/dist/components/FormComponents/Select/SingleSelectSearchApi.esm.js +82 -199
- package/dist/components/FormComponents/index.esm.js +2 -2
- package/dist/node_modules/axios/index.esm.js +25 -0
- package/dist/node_modules/axios/lib/adapters/adapters.esm.js +128 -0
- package/dist/node_modules/axios/lib/adapters/fetch.esm.js +288 -0
- package/dist/node_modules/axios/lib/adapters/xhr.esm.js +202 -0
- package/dist/node_modules/axios/lib/axios.esm.js +86 -0
- package/dist/node_modules/axios/lib/cancel/CancelToken.esm.js +133 -0
- package/dist/node_modules/axios/lib/cancel/CanceledError.esm.js +23 -0
- package/dist/node_modules/axios/lib/cancel/isCancel.esm.js +5 -0
- package/dist/node_modules/axios/lib/core/Axios.esm.js +236 -0
- package/dist/node_modules/axios/lib/core/AxiosError.esm.js +108 -0
- package/dist/node_modules/axios/lib/core/AxiosHeaders.esm.js +312 -0
- package/dist/node_modules/axios/lib/core/InterceptorManager.esm.js +69 -0
- package/dist/node_modules/axios/lib/core/buildFullPath.esm.js +22 -0
- package/dist/node_modules/axios/lib/core/dispatchRequest.esm.js +81 -0
- package/dist/node_modules/axios/lib/core/mergeConfig.esm.js +106 -0
- package/dist/node_modules/axios/lib/core/settle.esm.js +27 -0
- package/dist/node_modules/axios/lib/core/transformData.esm.js +28 -0
- package/dist/node_modules/axios/lib/defaults/index.esm.js +159 -0
- package/dist/node_modules/axios/lib/defaults/transitional.esm.js +7 -0
- package/dist/node_modules/axios/lib/env/data.esm.js +3 -0
- package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.esm.js +56 -0
- package/dist/node_modules/axios/lib/helpers/HttpStatusCode.esm.js +77 -0
- package/dist/node_modules/axios/lib/helpers/bind.esm.js +14 -0
- package/dist/node_modules/axios/lib/helpers/buildURL.esm.js +67 -0
- package/dist/node_modules/axios/lib/helpers/combineURLs.esm.js +15 -0
- package/dist/node_modules/axios/lib/helpers/composeSignals.esm.js +48 -0
- package/dist/node_modules/axios/lib/helpers/cookies.esm.js +54 -0
- package/dist/node_modules/axios/lib/helpers/formDataToJSON.esm.js +93 -0
- package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.esm.js +15 -0
- package/dist/node_modules/axios/lib/helpers/isAxiosError.esm.js +14 -0
- package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.esm.js +16 -0
- package/dist/node_modules/axios/lib/helpers/null.esm.js +4 -0
- package/dist/node_modules/axios/lib/helpers/parseHeaders.esm.js +55 -0
- package/dist/node_modules/axios/lib/helpers/parseProtocol.esm.js +6 -0
- package/dist/node_modules/axios/lib/helpers/progressEventReducer.esm.js +46 -0
- package/dist/node_modules/axios/lib/helpers/resolveConfig.esm.js +62 -0
- package/dist/node_modules/axios/lib/helpers/speedometer.esm.js +53 -0
- package/dist/node_modules/axios/lib/helpers/spread.esm.js +28 -0
- package/dist/node_modules/axios/lib/helpers/throttle.esm.js +44 -0
- package/dist/node_modules/axios/lib/helpers/toFormData.esm.js +219 -0
- package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.esm.js +19 -0
- package/dist/node_modules/axios/lib/helpers/trackStream.esm.js +88 -0
- package/dist/node_modules/axios/lib/helpers/validator.esm.js +99 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/Blob.esm.js +3 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/FormData.esm.js +3 -0
- package/dist/node_modules/axios/lib/platform/browser/classes/URLSearchParams.esm.js +5 -0
- package/dist/node_modules/axios/lib/platform/browser/index.esm.js +15 -0
- package/dist/node_modules/axios/lib/platform/common/utils.esm.js +45 -0
- package/dist/node_modules/axios/lib/platform/index.esm.js +9 -0
- package/dist/node_modules/axios/lib/utils.esm.js +782 -0
- package/dist/node_modules/react-date-range/dist/components/Calendar/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DateInput/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DateRange/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DateRangePicker/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DayCell/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/DefinedRange/index.esm.js +1 -1
- package/dist/node_modules/react-date-range/dist/components/InputRangeField/index.esm.js +1 -1
- package/dist/utils/Interface/FormInterface.d.ts +7 -1
- package/package.json +2 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import AxiosError from '../core/AxiosError.esm.js';
|
|
2
|
+
import utils from '../utils.esm.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
|
6
|
+
*
|
|
7
|
+
* @param {string=} message The message.
|
|
8
|
+
* @param {Object=} config The config.
|
|
9
|
+
* @param {Object=} request The request.
|
|
10
|
+
*
|
|
11
|
+
* @returns {CanceledError} The created error.
|
|
12
|
+
*/
|
|
13
|
+
function CanceledError(message, config, request) {
|
|
14
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
|
15
|
+
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
|
|
16
|
+
this.name = 'CanceledError';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
utils.inherits(CanceledError, AxiosError, {
|
|
20
|
+
__CANCEL__: true
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export { CanceledError as default };
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import utils from '../utils.esm.js';
|
|
2
|
+
import buildURL from '../helpers/buildURL.esm.js';
|
|
3
|
+
import InterceptorManager from './InterceptorManager.esm.js';
|
|
4
|
+
import dispatchRequest from './dispatchRequest.esm.js';
|
|
5
|
+
import mergeConfig from './mergeConfig.esm.js';
|
|
6
|
+
import buildFullPath from './buildFullPath.esm.js';
|
|
7
|
+
import validator from '../helpers/validator.esm.js';
|
|
8
|
+
import AxiosHeaders from './AxiosHeaders.esm.js';
|
|
9
|
+
|
|
10
|
+
const validators = validator.validators;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of Axios
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} instanceConfig The default config for the instance
|
|
16
|
+
*
|
|
17
|
+
* @return {Axios} A new instance of Axios
|
|
18
|
+
*/
|
|
19
|
+
class Axios {
|
|
20
|
+
constructor(instanceConfig) {
|
|
21
|
+
this.defaults = instanceConfig || {};
|
|
22
|
+
this.interceptors = {
|
|
23
|
+
request: new InterceptorManager(),
|
|
24
|
+
response: new InterceptorManager()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Dispatch a request
|
|
30
|
+
*
|
|
31
|
+
* @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
|
32
|
+
* @param {?Object} config
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise} The Promise to be fulfilled
|
|
35
|
+
*/
|
|
36
|
+
async request(configOrUrl, config) {
|
|
37
|
+
try {
|
|
38
|
+
return await this._request(configOrUrl, config);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err instanceof Error) {
|
|
41
|
+
let dummy = {};
|
|
42
|
+
|
|
43
|
+
Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
|
|
44
|
+
|
|
45
|
+
// slice off the Error: ... line
|
|
46
|
+
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
|
|
47
|
+
try {
|
|
48
|
+
if (!err.stack) {
|
|
49
|
+
err.stack = stack;
|
|
50
|
+
// match without the 2 top stack lines
|
|
51
|
+
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
|
|
52
|
+
err.stack += '\n' + stack;
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {
|
|
55
|
+
// ignore the case where "stack" is an un-writable property
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_request(configOrUrl, config) {
|
|
64
|
+
/*eslint no-param-reassign:0*/
|
|
65
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
|
66
|
+
if (typeof configOrUrl === 'string') {
|
|
67
|
+
config = config || {};
|
|
68
|
+
config.url = configOrUrl;
|
|
69
|
+
} else {
|
|
70
|
+
config = configOrUrl || {};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
config = mergeConfig(this.defaults, config);
|
|
74
|
+
|
|
75
|
+
const {transitional, paramsSerializer, headers} = config;
|
|
76
|
+
|
|
77
|
+
if (transitional !== undefined) {
|
|
78
|
+
validator.assertOptions(transitional, {
|
|
79
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
|
80
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
|
81
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
|
82
|
+
}, false);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (paramsSerializer != null) {
|
|
86
|
+
if (utils.isFunction(paramsSerializer)) {
|
|
87
|
+
config.paramsSerializer = {
|
|
88
|
+
serialize: paramsSerializer
|
|
89
|
+
};
|
|
90
|
+
} else {
|
|
91
|
+
validator.assertOptions(paramsSerializer, {
|
|
92
|
+
encode: validators.function,
|
|
93
|
+
serialize: validators.function
|
|
94
|
+
}, true);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Set config.allowAbsoluteUrls
|
|
99
|
+
if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
|
|
100
|
+
config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
|
|
101
|
+
} else {
|
|
102
|
+
config.allowAbsoluteUrls = true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
validator.assertOptions(config, {
|
|
106
|
+
baseUrl: validators.spelling('baseURL'),
|
|
107
|
+
withXsrfToken: validators.spelling('withXSRFToken')
|
|
108
|
+
}, true);
|
|
109
|
+
|
|
110
|
+
// Set config.method
|
|
111
|
+
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
|
112
|
+
|
|
113
|
+
// Flatten headers
|
|
114
|
+
let contextHeaders = headers && utils.merge(
|
|
115
|
+
headers.common,
|
|
116
|
+
headers[config.method]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
headers && utils.forEach(
|
|
120
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
|
121
|
+
(method) => {
|
|
122
|
+
delete headers[method];
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
|
127
|
+
|
|
128
|
+
// filter out skipped interceptors
|
|
129
|
+
const requestInterceptorChain = [];
|
|
130
|
+
let synchronousRequestInterceptors = true;
|
|
131
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
132
|
+
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
137
|
+
|
|
138
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const responseInterceptorChain = [];
|
|
142
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
143
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
let promise;
|
|
147
|
+
let i = 0;
|
|
148
|
+
let len;
|
|
149
|
+
|
|
150
|
+
if (!synchronousRequestInterceptors) {
|
|
151
|
+
const chain = [dispatchRequest.bind(this), undefined];
|
|
152
|
+
chain.unshift(...requestInterceptorChain);
|
|
153
|
+
chain.push(...responseInterceptorChain);
|
|
154
|
+
len = chain.length;
|
|
155
|
+
|
|
156
|
+
promise = Promise.resolve(config);
|
|
157
|
+
|
|
158
|
+
while (i < len) {
|
|
159
|
+
promise = promise.then(chain[i++], chain[i++]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return promise;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
len = requestInterceptorChain.length;
|
|
166
|
+
|
|
167
|
+
let newConfig = config;
|
|
168
|
+
|
|
169
|
+
while (i < len) {
|
|
170
|
+
const onFulfilled = requestInterceptorChain[i++];
|
|
171
|
+
const onRejected = requestInterceptorChain[i++];
|
|
172
|
+
try {
|
|
173
|
+
newConfig = onFulfilled(newConfig);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
onRejected.call(this, error);
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
promise = dispatchRequest.call(this, newConfig);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
return Promise.reject(error);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
i = 0;
|
|
187
|
+
len = responseInterceptorChain.length;
|
|
188
|
+
|
|
189
|
+
while (i < len) {
|
|
190
|
+
promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return promise;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
getUri(config) {
|
|
197
|
+
config = mergeConfig(this.defaults, config);
|
|
198
|
+
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
|
199
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Provide aliases for supported request methods
|
|
204
|
+
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
|
205
|
+
/*eslint func-names:0*/
|
|
206
|
+
Axios.prototype[method] = function(url, config) {
|
|
207
|
+
return this.request(mergeConfig(config || {}, {
|
|
208
|
+
method,
|
|
209
|
+
url,
|
|
210
|
+
data: (config || {}).data
|
|
211
|
+
}));
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
|
216
|
+
/*eslint func-names:0*/
|
|
217
|
+
|
|
218
|
+
function generateHTTPMethod(isForm) {
|
|
219
|
+
return function httpMethod(url, data, config) {
|
|
220
|
+
return this.request(mergeConfig(config || {}, {
|
|
221
|
+
method,
|
|
222
|
+
headers: isForm ? {
|
|
223
|
+
'Content-Type': 'multipart/form-data'
|
|
224
|
+
} : {},
|
|
225
|
+
url,
|
|
226
|
+
data
|
|
227
|
+
}));
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Axios.prototype[method] = generateHTTPMethod();
|
|
232
|
+
|
|
233
|
+
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
export { Axios as default };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import utils from '../utils.esm.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create an Error with the specified message, config, error code, request and response.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} message The error message.
|
|
7
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
|
8
|
+
* @param {Object} [config] The config.
|
|
9
|
+
* @param {Object} [request] The request.
|
|
10
|
+
* @param {Object} [response] The response.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Error} The created error.
|
|
13
|
+
*/
|
|
14
|
+
function AxiosError(message, code, config, request, response) {
|
|
15
|
+
Error.call(this);
|
|
16
|
+
|
|
17
|
+
if (Error.captureStackTrace) {
|
|
18
|
+
Error.captureStackTrace(this, this.constructor);
|
|
19
|
+
} else {
|
|
20
|
+
this.stack = (new Error()).stack;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
this.message = message;
|
|
24
|
+
this.name = 'AxiosError';
|
|
25
|
+
code && (this.code = code);
|
|
26
|
+
config && (this.config = config);
|
|
27
|
+
request && (this.request = request);
|
|
28
|
+
if (response) {
|
|
29
|
+
this.response = response;
|
|
30
|
+
this.status = response.status ? response.status : null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
utils.inherits(AxiosError, Error, {
|
|
35
|
+
toJSON: function toJSON() {
|
|
36
|
+
return {
|
|
37
|
+
// Standard
|
|
38
|
+
message: this.message,
|
|
39
|
+
name: this.name,
|
|
40
|
+
// Microsoft
|
|
41
|
+
description: this.description,
|
|
42
|
+
number: this.number,
|
|
43
|
+
// Mozilla
|
|
44
|
+
fileName: this.fileName,
|
|
45
|
+
lineNumber: this.lineNumber,
|
|
46
|
+
columnNumber: this.columnNumber,
|
|
47
|
+
stack: this.stack,
|
|
48
|
+
// Axios
|
|
49
|
+
config: utils.toJSONObject(this.config),
|
|
50
|
+
code: this.code,
|
|
51
|
+
status: this.status
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const prototype = AxiosError.prototype;
|
|
57
|
+
const descriptors = {};
|
|
58
|
+
|
|
59
|
+
[
|
|
60
|
+
'ERR_BAD_OPTION_VALUE',
|
|
61
|
+
'ERR_BAD_OPTION',
|
|
62
|
+
'ECONNABORTED',
|
|
63
|
+
'ETIMEDOUT',
|
|
64
|
+
'ERR_NETWORK',
|
|
65
|
+
'ERR_FR_TOO_MANY_REDIRECTS',
|
|
66
|
+
'ERR_DEPRECATED',
|
|
67
|
+
'ERR_BAD_RESPONSE',
|
|
68
|
+
'ERR_BAD_REQUEST',
|
|
69
|
+
'ERR_CANCELED',
|
|
70
|
+
'ERR_NOT_SUPPORT',
|
|
71
|
+
'ERR_INVALID_URL'
|
|
72
|
+
// eslint-disable-next-line func-names
|
|
73
|
+
].forEach(code => {
|
|
74
|
+
descriptors[code] = {value: code};
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Object.defineProperties(AxiosError, descriptors);
|
|
78
|
+
Object.defineProperty(prototype, 'isAxiosError', {value: true});
|
|
79
|
+
|
|
80
|
+
// eslint-disable-next-line func-names
|
|
81
|
+
AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
82
|
+
const axiosError = Object.create(prototype);
|
|
83
|
+
|
|
84
|
+
utils.toFlatObject(error, axiosError, function filter(obj) {
|
|
85
|
+
return obj !== Error.prototype;
|
|
86
|
+
}, prop => {
|
|
87
|
+
return prop !== 'isAxiosError';
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const msg = error && error.message ? error.message : 'Error';
|
|
91
|
+
|
|
92
|
+
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
|
93
|
+
const errCode = code == null && error ? error.code : code;
|
|
94
|
+
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
|
95
|
+
|
|
96
|
+
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
|
97
|
+
if (error && axiosError.cause == null) {
|
|
98
|
+
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
axiosError.name = (error && error.name) || 'Error';
|
|
102
|
+
|
|
103
|
+
customProps && Object.assign(axiosError, customProps);
|
|
104
|
+
|
|
105
|
+
return axiosError;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { AxiosError as default };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import utils from '../utils.esm.js';
|
|
2
|
+
import parseHeaders from '../helpers/parseHeaders.esm.js';
|
|
3
|
+
|
|
4
|
+
const $internals = Symbol('internals');
|
|
5
|
+
|
|
6
|
+
function normalizeHeader(header) {
|
|
7
|
+
return header && String(header).trim().toLowerCase();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function normalizeValue(value) {
|
|
11
|
+
if (value === false || value == null) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return utils.isArray(value) ? value.map(normalizeValue) : String(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function parseTokens(str) {
|
|
19
|
+
const tokens = Object.create(null);
|
|
20
|
+
const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
|
|
21
|
+
let match;
|
|
22
|
+
|
|
23
|
+
while ((match = tokensRE.exec(str))) {
|
|
24
|
+
tokens[match[1]] = match[2];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return tokens;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
|
|
31
|
+
|
|
32
|
+
function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
|
|
33
|
+
if (utils.isFunction(filter)) {
|
|
34
|
+
return filter.call(this, value, header);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isHeaderNameFilter) {
|
|
38
|
+
value = header;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!utils.isString(value)) return;
|
|
42
|
+
|
|
43
|
+
if (utils.isString(filter)) {
|
|
44
|
+
return value.indexOf(filter) !== -1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (utils.isRegExp(filter)) {
|
|
48
|
+
return filter.test(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function formatHeader(header) {
|
|
53
|
+
return header.trim()
|
|
54
|
+
.toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
|
|
55
|
+
return char.toUpperCase() + str;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildAccessors(obj, header) {
|
|
60
|
+
const accessorName = utils.toCamelCase(' ' + header);
|
|
61
|
+
|
|
62
|
+
['get', 'set', 'has'].forEach(methodName => {
|
|
63
|
+
Object.defineProperty(obj, methodName + accessorName, {
|
|
64
|
+
value: function(arg1, arg2, arg3) {
|
|
65
|
+
return this[methodName].call(this, header, arg1, arg2, arg3);
|
|
66
|
+
},
|
|
67
|
+
configurable: true
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
class AxiosHeaders {
|
|
73
|
+
constructor(headers) {
|
|
74
|
+
headers && this.set(headers);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
set(header, valueOrRewrite, rewrite) {
|
|
78
|
+
const self = this;
|
|
79
|
+
|
|
80
|
+
function setHeader(_value, _header, _rewrite) {
|
|
81
|
+
const lHeader = normalizeHeader(_header);
|
|
82
|
+
|
|
83
|
+
if (!lHeader) {
|
|
84
|
+
throw new Error('header name must be a non-empty string');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const key = utils.findKey(self, lHeader);
|
|
88
|
+
|
|
89
|
+
if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
|
|
90
|
+
self[key || _header] = normalizeValue(_value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const setHeaders = (headers, _rewrite) =>
|
|
95
|
+
utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
|
96
|
+
|
|
97
|
+
if (utils.isPlainObject(header) || header instanceof this.constructor) {
|
|
98
|
+
setHeaders(header, valueOrRewrite);
|
|
99
|
+
} else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
100
|
+
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
101
|
+
} else if (utils.isObject(header) && utils.isIterable(header)) {
|
|
102
|
+
let obj = {}, dest, key;
|
|
103
|
+
for (const entry of header) {
|
|
104
|
+
if (!utils.isArray(entry)) {
|
|
105
|
+
throw TypeError('Object iterator must return a key-value pair');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
obj[key = entry[0]] = (dest = obj[key]) ?
|
|
109
|
+
(utils.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setHeaders(obj, valueOrRewrite);
|
|
113
|
+
} else {
|
|
114
|
+
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get(header, parser) {
|
|
121
|
+
header = normalizeHeader(header);
|
|
122
|
+
|
|
123
|
+
if (header) {
|
|
124
|
+
const key = utils.findKey(this, header);
|
|
125
|
+
|
|
126
|
+
if (key) {
|
|
127
|
+
const value = this[key];
|
|
128
|
+
|
|
129
|
+
if (!parser) {
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (parser === true) {
|
|
134
|
+
return parseTokens(value);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (utils.isFunction(parser)) {
|
|
138
|
+
return parser.call(this, value, key);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (utils.isRegExp(parser)) {
|
|
142
|
+
return parser.exec(value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
throw new TypeError('parser must be boolean|regexp|function');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
has(header, matcher) {
|
|
151
|
+
header = normalizeHeader(header);
|
|
152
|
+
|
|
153
|
+
if (header) {
|
|
154
|
+
const key = utils.findKey(this, header);
|
|
155
|
+
|
|
156
|
+
return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
delete(header, matcher) {
|
|
163
|
+
const self = this;
|
|
164
|
+
let deleted = false;
|
|
165
|
+
|
|
166
|
+
function deleteHeader(_header) {
|
|
167
|
+
_header = normalizeHeader(_header);
|
|
168
|
+
|
|
169
|
+
if (_header) {
|
|
170
|
+
const key = utils.findKey(self, _header);
|
|
171
|
+
|
|
172
|
+
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
|
173
|
+
delete self[key];
|
|
174
|
+
|
|
175
|
+
deleted = true;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (utils.isArray(header)) {
|
|
181
|
+
header.forEach(deleteHeader);
|
|
182
|
+
} else {
|
|
183
|
+
deleteHeader(header);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return deleted;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
clear(matcher) {
|
|
190
|
+
const keys = Object.keys(this);
|
|
191
|
+
let i = keys.length;
|
|
192
|
+
let deleted = false;
|
|
193
|
+
|
|
194
|
+
while (i--) {
|
|
195
|
+
const key = keys[i];
|
|
196
|
+
if(!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
|
|
197
|
+
delete this[key];
|
|
198
|
+
deleted = true;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return deleted;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
normalize(format) {
|
|
206
|
+
const self = this;
|
|
207
|
+
const headers = {};
|
|
208
|
+
|
|
209
|
+
utils.forEach(this, (value, header) => {
|
|
210
|
+
const key = utils.findKey(headers, header);
|
|
211
|
+
|
|
212
|
+
if (key) {
|
|
213
|
+
self[key] = normalizeValue(value);
|
|
214
|
+
delete self[header];
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const normalized = format ? formatHeader(header) : String(header).trim();
|
|
219
|
+
|
|
220
|
+
if (normalized !== header) {
|
|
221
|
+
delete self[header];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
self[normalized] = normalizeValue(value);
|
|
225
|
+
|
|
226
|
+
headers[normalized] = true;
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
concat(...targets) {
|
|
233
|
+
return this.constructor.concat(this, ...targets);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
toJSON(asStrings) {
|
|
237
|
+
const obj = Object.create(null);
|
|
238
|
+
|
|
239
|
+
utils.forEach(this, (value, header) => {
|
|
240
|
+
value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
return obj;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
[Symbol.iterator]() {
|
|
247
|
+
return Object.entries(this.toJSON())[Symbol.iterator]();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
toString() {
|
|
251
|
+
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
getSetCookie() {
|
|
255
|
+
return this.get("set-cookie") || [];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
get [Symbol.toStringTag]() {
|
|
259
|
+
return 'AxiosHeaders';
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
static from(thing) {
|
|
263
|
+
return thing instanceof this ? thing : new this(thing);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
static concat(first, ...targets) {
|
|
267
|
+
const computed = new this(first);
|
|
268
|
+
|
|
269
|
+
targets.forEach((target) => computed.set(target));
|
|
270
|
+
|
|
271
|
+
return computed;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static accessor(header) {
|
|
275
|
+
const internals = this[$internals] = (this[$internals] = {
|
|
276
|
+
accessors: {}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const accessors = internals.accessors;
|
|
280
|
+
const prototype = this.prototype;
|
|
281
|
+
|
|
282
|
+
function defineAccessor(_header) {
|
|
283
|
+
const lHeader = normalizeHeader(_header);
|
|
284
|
+
|
|
285
|
+
if (!accessors[lHeader]) {
|
|
286
|
+
buildAccessors(prototype, _header);
|
|
287
|
+
accessors[lHeader] = true;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
292
|
+
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
|
298
|
+
|
|
299
|
+
// reserved names hotfix
|
|
300
|
+
utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
|
|
301
|
+
let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
|
|
302
|
+
return {
|
|
303
|
+
get: () => value,
|
|
304
|
+
set(headerValue) {
|
|
305
|
+
this[mapped] = headerValue;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
utils.freezeMethods(AxiosHeaders);
|
|
311
|
+
|
|
312
|
+
export { AxiosHeaders as default };
|