@ekhein/http-request 1.0.13 → 1.0.15
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/main.d.ts +3 -2
- package/dist/main.js +43 -12
- package/package.json +1 -1
- package/types/http-request.d.ts +1 -0
package/dist/main.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ export declare class HttpRequestHeaders extends AxiosHeaders {
|
|
|
4
4
|
}
|
|
5
5
|
export declare class HttpRequest {
|
|
6
6
|
readonly instance: AxiosInstance;
|
|
7
|
-
constructor(options
|
|
7
|
+
constructor(options?: HttpRequestConfig);
|
|
8
8
|
execute<R = any>(options: HttpRequestConfig): Promise<R>;
|
|
9
9
|
post<R = any>(url: string, data?: any, opts?: HttpRequestConfig): Promise<R>;
|
|
10
|
-
|
|
10
|
+
invoke<R = any>(path: string, data: object, opts?: HttpRequestConfig): Promise<R>;
|
|
11
|
+
call<R = any>(url: string, args?: Array<any>, opts?: HttpRequestConfig): Promise<R>;
|
|
11
12
|
}
|
|
12
13
|
export * from './libs';
|
|
13
14
|
export * from './exceptions';
|
package/dist/main.js
CHANGED
|
@@ -66,7 +66,7 @@ class HttpRequestHeaders extends axios_1.AxiosHeaders {
|
|
|
66
66
|
}
|
|
67
67
|
exports.HttpRequestHeaders = HttpRequestHeaders;
|
|
68
68
|
class HttpRequest {
|
|
69
|
-
constructor(options) {
|
|
69
|
+
constructor(options = {}) {
|
|
70
70
|
var _a, _b, _c, _d;
|
|
71
71
|
/* Axios */
|
|
72
72
|
this.instance = axios_1.default.create(Object.assign({}, Object.assign({
|
|
@@ -157,6 +157,27 @@ class HttpRequest {
|
|
|
157
157
|
}
|
|
158
158
|
return request;
|
|
159
159
|
}));
|
|
160
|
+
/* BaseURL */
|
|
161
|
+
this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
if (request.baseURL)
|
|
163
|
+
return request;
|
|
164
|
+
if (request.serviceType == 1)
|
|
165
|
+
request.baseURL = String(process.env.CORE_URL);
|
|
166
|
+
if (request.serviceType == 2)
|
|
167
|
+
request.baseURL = String(process.env.SEKIRO_URL);
|
|
168
|
+
if (request.serviceType == 3)
|
|
169
|
+
request.baseURL = String("http://*:65000/script").replace("*", request.clientIp);
|
|
170
|
+
return request;
|
|
171
|
+
}));
|
|
172
|
+
/* Validate Status */
|
|
173
|
+
this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
if (request.serviceType == 1) { }
|
|
175
|
+
if (request.serviceType == 2) { }
|
|
176
|
+
if (request.serviceType == 3) {
|
|
177
|
+
request.validateStatus = status => [200, 410, 500, 400].includes(status);
|
|
178
|
+
}
|
|
179
|
+
return request;
|
|
180
|
+
}));
|
|
160
181
|
/* Transform */
|
|
161
182
|
this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
|
|
162
183
|
if (request.serviceType == 1) { }
|
|
@@ -167,6 +188,10 @@ class HttpRequest {
|
|
|
167
188
|
request.url = String("/business-demo/invoke");
|
|
168
189
|
request.params = Object({ group, action, invoke_timeout });
|
|
169
190
|
}
|
|
191
|
+
if (request.serviceType == 3) {
|
|
192
|
+
const args = JSON.stringify(request.args);
|
|
193
|
+
request.form = Object({ args });
|
|
194
|
+
}
|
|
170
195
|
return request;
|
|
171
196
|
}));
|
|
172
197
|
/* Call Custom Hook */
|
|
@@ -192,6 +217,14 @@ class HttpRequest {
|
|
|
192
217
|
throw new common_1.ServiceUnavailableException(response.data.message);
|
|
193
218
|
return response.data.data;
|
|
194
219
|
}
|
|
220
|
+
if (response.config.serviceType == 3) {
|
|
221
|
+
if (response.status == 200)
|
|
222
|
+
return response.data.result;
|
|
223
|
+
const exception = String(response.data.exception);
|
|
224
|
+
const reason = Array.from(response.data.args).at(0);
|
|
225
|
+
const message = Array.from([exception, reason]).join("::");
|
|
226
|
+
throw new common_1.ServiceUnavailableException(message);
|
|
227
|
+
}
|
|
195
228
|
if (response.config.html) {
|
|
196
229
|
return new jsdom_1.JSDOM(response.data);
|
|
197
230
|
}
|
|
@@ -239,21 +272,19 @@ class HttpRequest {
|
|
|
239
272
|
post(url_1, data_1) {
|
|
240
273
|
return __awaiter(this, arguments, void 0, function* (url, data, opts = {}) {
|
|
241
274
|
return this.instance
|
|
242
|
-
.request(Object.assign(
|
|
243
|
-
["method"]: "POST",
|
|
244
|
-
["serviceType"]: 1,
|
|
245
|
-
["baseURL"]: process.env.CORE_URL,
|
|
246
|
-
})));
|
|
275
|
+
.request(Object.assign(Object.assign({}, opts), { method: "POST", serviceType: 1, data, url }));
|
|
247
276
|
});
|
|
248
277
|
}
|
|
249
|
-
|
|
278
|
+
invoke(path_1, data_1) {
|
|
250
279
|
return __awaiter(this, arguments, void 0, function* (path, data, opts = {}) {
|
|
251
280
|
return this.instance
|
|
252
|
-
.request(Object.assign(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
281
|
+
.request(Object.assign(Object.assign({}, opts), { method: "POST", serviceType: 2, data, path }));
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
call(url_1) {
|
|
285
|
+
return __awaiter(this, arguments, void 0, function* (url, args = [], opts = {}) {
|
|
286
|
+
return this.instance
|
|
287
|
+
.request(Object.assign(Object.assign({}, opts), { method: "POST", serviceType: 3, args, url }));
|
|
257
288
|
});
|
|
258
289
|
}
|
|
259
290
|
}
|
package/package.json
CHANGED
package/types/http-request.d.ts
CHANGED