@modern-js/create-request 2.15.0 → 2.16.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/cjs/browser.js +27 -43
- package/dist/cjs/handleRes.js +11 -29
- package/dist/cjs/node.js +36 -48
- package/dist/cjs/types.js +4 -15
- package/dist/esm/browser.js +249 -234
- package/dist/esm/handleRes.js +181 -173
- package/dist/esm/node.js +131 -123
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/browser.js +5 -7
- package/dist/esm-node/handleRes.js +5 -7
- package/dist/esm-node/node.js +10 -8
- package/dist/esm-node/types.js +1 -0
- package/package.json +10 -6
package/dist/esm/handleRes.js
CHANGED
|
@@ -1,187 +1,195 @@
|
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(void 0);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
29
|
}
|
|
30
30
|
function _instanceof(left, right) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
32
|
+
return !!right[Symbol.hasInstance](left);
|
|
33
|
+
} else {
|
|
34
|
+
return left instanceof right;
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
|
-
var __generator =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
var __generator = function(thisArg, body) {
|
|
38
|
+
var f, y, t, g, _ = {
|
|
39
|
+
label: 0,
|
|
40
|
+
sent: function() {
|
|
41
|
+
if (t[0] & 1)
|
|
42
|
+
throw t[1];
|
|
43
|
+
return t[1];
|
|
44
|
+
},
|
|
45
|
+
trys: [],
|
|
46
|
+
ops: []
|
|
47
|
+
};
|
|
48
|
+
return g = {
|
|
49
|
+
next: verb(0),
|
|
50
|
+
"throw": verb(1),
|
|
51
|
+
"return": verb(2)
|
|
52
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
53
|
+
return this;
|
|
54
|
+
}), g;
|
|
55
|
+
function verb(n) {
|
|
56
|
+
return function(v) {
|
|
57
|
+
return step([
|
|
58
|
+
n,
|
|
59
|
+
v
|
|
60
|
+
]);
|
|
46
61
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
break;
|
|
75
|
-
case 4:
|
|
76
|
-
_.label++;
|
|
77
|
-
return {
|
|
78
|
-
value: op[1],
|
|
79
|
-
done: false
|
|
80
|
-
};
|
|
81
|
-
case 5:
|
|
82
|
-
_.label++;
|
|
83
|
-
y = op[1];
|
|
84
|
-
op = [
|
|
85
|
-
0
|
|
86
|
-
];
|
|
87
|
-
continue;
|
|
88
|
-
case 7:
|
|
89
|
-
op = _.ops.pop();
|
|
90
|
-
_.trys.pop();
|
|
91
|
-
continue;
|
|
92
|
-
default:
|
|
93
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
94
|
-
_ = 0;
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
98
|
-
_.label = op[1];
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
102
|
-
_.label = t[1];
|
|
103
|
-
t = op;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
if (t && _.label < t[2]) {
|
|
107
|
-
_.label = t[2];
|
|
108
|
-
_.ops.push(op);
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
if (t[2]) _.ops.pop();
|
|
112
|
-
_.trys.pop();
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
op = body.call(thisArg, _);
|
|
116
|
-
} catch (e) {
|
|
62
|
+
}
|
|
63
|
+
function step(op) {
|
|
64
|
+
if (f)
|
|
65
|
+
throw new TypeError("Generator is already executing.");
|
|
66
|
+
while (_)
|
|
67
|
+
try {
|
|
68
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
|
69
|
+
return t;
|
|
70
|
+
if (y = 0, t)
|
|
71
|
+
op = [
|
|
72
|
+
op[0] & 2,
|
|
73
|
+
t.value
|
|
74
|
+
];
|
|
75
|
+
switch (op[0]) {
|
|
76
|
+
case 0:
|
|
77
|
+
case 1:
|
|
78
|
+
t = op;
|
|
79
|
+
break;
|
|
80
|
+
case 4:
|
|
81
|
+
_.label++;
|
|
82
|
+
return {
|
|
83
|
+
value: op[1],
|
|
84
|
+
done: false
|
|
85
|
+
};
|
|
86
|
+
case 5:
|
|
87
|
+
_.label++;
|
|
88
|
+
y = op[1];
|
|
117
89
|
op = [
|
|
118
|
-
|
|
119
|
-
e
|
|
90
|
+
0
|
|
120
91
|
];
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
92
|
+
continue;
|
|
93
|
+
case 7:
|
|
94
|
+
op = _.ops.pop();
|
|
95
|
+
_.trys.pop();
|
|
96
|
+
continue;
|
|
97
|
+
default:
|
|
98
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
99
|
+
_ = 0;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
103
|
+
_.label = op[1];
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
107
|
+
_.label = t[1];
|
|
108
|
+
t = op;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (t && _.label < t[2]) {
|
|
112
|
+
_.label = t[2];
|
|
113
|
+
_.ops.push(op);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (t[2])
|
|
117
|
+
_.ops.pop();
|
|
118
|
+
_.trys.pop();
|
|
119
|
+
continue;
|
|
124
120
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
op = body.call(thisArg, _);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
op = [
|
|
124
|
+
6,
|
|
125
|
+
e
|
|
126
|
+
];
|
|
127
|
+
y = 0;
|
|
128
|
+
} finally {
|
|
129
|
+
f = t = 0;
|
|
130
|
+
}
|
|
131
|
+
if (op[0] & 5)
|
|
132
|
+
throw op[1];
|
|
133
|
+
return {
|
|
134
|
+
value: op[0] ? op[1] : void 0,
|
|
135
|
+
done: true
|
|
136
|
+
};
|
|
137
|
+
}
|
|
131
138
|
};
|
|
132
139
|
var handleRes = function() {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
140
|
+
var _ref = _async_to_generator(function(res) {
|
|
141
|
+
var contentType, data;
|
|
142
|
+
return __generator(this, function(_state) {
|
|
143
|
+
switch (_state.label) {
|
|
144
|
+
case 0:
|
|
145
|
+
contentType = res.headers.get("content-type");
|
|
146
|
+
if (!!res.ok)
|
|
147
|
+
return [
|
|
148
|
+
3,
|
|
149
|
+
2
|
|
150
|
+
];
|
|
151
|
+
return [
|
|
152
|
+
4,
|
|
153
|
+
res.json()
|
|
154
|
+
];
|
|
155
|
+
case 1:
|
|
156
|
+
data = _state.sent();
|
|
157
|
+
res.data = data;
|
|
158
|
+
throw res;
|
|
159
|
+
case 2:
|
|
160
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
|
|
161
|
+
return [
|
|
162
|
+
2,
|
|
163
|
+
res.json()
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
|
|
167
|
+
return [
|
|
168
|
+
2,
|
|
169
|
+
res.text()
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && _instanceof(res, Response)) {
|
|
173
|
+
return [
|
|
174
|
+
2,
|
|
175
|
+
res.formData()
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
|
|
179
|
+
return [
|
|
180
|
+
2,
|
|
181
|
+
res.arrayBuffer()
|
|
182
|
+
];
|
|
183
|
+
}
|
|
184
|
+
return [
|
|
185
|
+
2,
|
|
186
|
+
res.text()
|
|
187
|
+
];
|
|
188
|
+
}
|
|
182
189
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
});
|
|
191
|
+
return function handleRes2(res) {
|
|
192
|
+
return _ref.apply(this, arguments);
|
|
193
|
+
};
|
|
186
194
|
}();
|
|
187
195
|
export { handleRes };
|
package/dist/esm/node.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function _array_without_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return _array_like_to_array(arr);
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
12
|
+
function _iterable_to_array(iter) {
|
|
13
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
14
|
+
return Array.from(iter);
|
|
11
15
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
16
|
+
function _non_iterable_spread() {
|
|
17
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
14
18
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
19
|
+
function _to_consumable_array(arr) {
|
|
20
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
17
21
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
23
|
+
if (!o)
|
|
24
|
+
return;
|
|
25
|
+
if (typeof o === "string")
|
|
26
|
+
return _array_like_to_array(o, minLen);
|
|
27
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
28
|
+
if (n === "Object" && o.constructor)
|
|
29
|
+
n = o.constructor.name;
|
|
30
|
+
if (n === "Map" || n === "Set")
|
|
31
|
+
return Array.from(n);
|
|
32
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
33
|
+
return _array_like_to_array(o, minLen);
|
|
25
34
|
}
|
|
26
35
|
import nodeFetch from "node-fetch";
|
|
27
36
|
import { compile, pathToRegexp } from "path-to-regexp";
|
|
@@ -31,113 +40,112 @@ import { handleRes } from "./handleRes";
|
|
|
31
40
|
var realRequest;
|
|
32
41
|
var realAllowedHeaders = [];
|
|
33
42
|
var originFetch = function() {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
44
|
+
params[_key] = arguments[_key];
|
|
45
|
+
}
|
|
46
|
+
return nodeFetch.apply(void 0, _to_consumable_array(params)).then(handleRes);
|
|
38
47
|
};
|
|
39
|
-
var configure = function(options) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
export var configure = function(options) {
|
|
49
|
+
var request = options.request, interceptor = options.interceptor, allowedHeaders = options.allowedHeaders;
|
|
50
|
+
realRequest = request || originFetch;
|
|
51
|
+
if (interceptor && !request) {
|
|
52
|
+
realRequest = interceptor(nodeFetch);
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(allowedHeaders)) {
|
|
55
|
+
realAllowedHeaders = allowedHeaders;
|
|
56
|
+
}
|
|
48
57
|
};
|
|
49
|
-
var createRequest = function(path, method, port) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
} catch (err) {
|
|
96
|
-
_didIteratorError = true;
|
|
97
|
-
_iteratorError = err;
|
|
98
|
-
} finally{
|
|
99
|
-
try {
|
|
100
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
101
|
-
_iterator.return();
|
|
102
|
-
}
|
|
103
|
-
} finally{
|
|
104
|
-
if (_didIteratorError) {
|
|
105
|
-
throw _iteratorError;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
if (payload.data) {
|
|
110
|
-
headers["Content-Type"] = "application/json";
|
|
111
|
-
body = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
|
|
112
|
-
} else if (payload.body) {
|
|
113
|
-
headers["Content-Type"] = "text/plain";
|
|
114
|
-
body = payload.body;
|
|
115
|
-
} else if (payload.formData) {
|
|
116
|
-
body = payload.formData;
|
|
117
|
-
} else if (payload.formUrlencoded) {
|
|
118
|
-
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
119
|
-
if (typeof payload.formUrlencoded === "object") {
|
|
120
|
-
body = qs.stringify(payload.formUrlencoded);
|
|
121
|
-
} else {
|
|
122
|
-
body = payload.formUrlencoded;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
url = "http://localhost:".concat(port).concat(finalPath);
|
|
58
|
+
export var createRequest = function(path, method, port) {
|
|
59
|
+
var httpMethodDecider = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "functionName", fetch = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : nodeFetch;
|
|
60
|
+
var getFinalPath = compile(path, {
|
|
61
|
+
encode: encodeURIComponent
|
|
62
|
+
});
|
|
63
|
+
var keys = [];
|
|
64
|
+
pathToRegexp(path, keys);
|
|
65
|
+
var sender = function() {
|
|
66
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
67
|
+
args[_key] = arguments[_key];
|
|
68
|
+
}
|
|
69
|
+
var webRequestHeaders = useHeaders();
|
|
70
|
+
var body;
|
|
71
|
+
var headers;
|
|
72
|
+
var url;
|
|
73
|
+
if (httpMethodDecider === "inputParams") {
|
|
74
|
+
url = path;
|
|
75
|
+
body = args;
|
|
76
|
+
headers = {
|
|
77
|
+
"Content-Type": "application/json"
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
var payload = typeof args[args.length - 1] === "object" ? args[args.length - 1] : {};
|
|
81
|
+
payload.params = payload.params || {};
|
|
82
|
+
var requestParams = args[0];
|
|
83
|
+
if (typeof requestParams === "object" && requestParams.params) {
|
|
84
|
+
var params = requestParams.params;
|
|
85
|
+
keys.forEach(function(key2) {
|
|
86
|
+
payload.params[key2.name] = params[key2.name];
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
keys.forEach(function(key2, index) {
|
|
90
|
+
payload.params[key2.name] = args[index];
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
var plainPath = getFinalPath(payload.params);
|
|
94
|
+
var finalPath = payload.query ? "".concat(plainPath, "?").concat(qs.stringify(payload.query)) : plainPath;
|
|
95
|
+
headers = payload.headers || {};
|
|
96
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
97
|
+
try {
|
|
98
|
+
for (var _iterator = realAllowedHeaders[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
99
|
+
var key = _step.value;
|
|
100
|
+
if (typeof webRequestHeaders[key] !== "undefined") {
|
|
101
|
+
headers[key] = webRequestHeaders[key];
|
|
102
|
+
}
|
|
126
103
|
}
|
|
127
|
-
|
|
128
|
-
|
|
104
|
+
} catch (err) {
|
|
105
|
+
_didIteratorError = true;
|
|
106
|
+
_iteratorError = err;
|
|
107
|
+
} finally {
|
|
108
|
+
try {
|
|
109
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
110
|
+
_iterator.return();
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
if (_didIteratorError) {
|
|
114
|
+
throw _iteratorError;
|
|
115
|
+
}
|
|
129
116
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
}
|
|
118
|
+
if (payload.data) {
|
|
119
|
+
headers["Content-Type"] = "application/json";
|
|
120
|
+
body = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
|
|
121
|
+
} else if (payload.body) {
|
|
122
|
+
headers["Content-Type"] = "text/plain";
|
|
123
|
+
body = payload.body;
|
|
124
|
+
} else if (payload.formData) {
|
|
125
|
+
body = payload.formData;
|
|
126
|
+
} else if (payload.formUrlencoded) {
|
|
127
|
+
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
128
|
+
if (typeof payload.formUrlencoded === "object") {
|
|
129
|
+
body = qs.stringify(payload.formUrlencoded);
|
|
130
|
+
} else {
|
|
131
|
+
body = payload.formUrlencoded;
|
|
133
132
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
}
|
|
134
|
+
url = "http://localhost:".concat(port).concat(finalPath);
|
|
135
|
+
}
|
|
136
|
+
if (method.toLowerCase() === "get") {
|
|
137
|
+
body = void 0;
|
|
138
|
+
}
|
|
139
|
+
var fetcher = realRequest || originFetch;
|
|
140
|
+
if (method.toLowerCase() === "get") {
|
|
141
|
+
body = void 0;
|
|
142
|
+
}
|
|
143
|
+
headers.accept = "application/json,*/*;q=0.8";
|
|
144
|
+
return fetcher(url, {
|
|
145
|
+
method,
|
|
146
|
+
body,
|
|
147
|
+
headers
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
return sender;
|
|
142
151
|
};
|
|
143
|
-
export { configure, createRequest };
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|