@ekhein/http-request 1.0.14 → 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 CHANGED
@@ -7,7 +7,8 @@ export declare class HttpRequest {
7
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
- call<R = any>(path: string, data: object, opts?: HttpRequestConfig): Promise<R>;
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
@@ -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({}, Object.assign({}, opts, { url, data }, {
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
- call(path_1, data_1) {
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({}, Object.assign({}, opts, { path, data }, {
253
- ["method"]: "POST",
254
- ["serviceType"]: 2,
255
- ["baseURL"]: process.env.SEKIRO_URL,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/http-request",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "license": "MIT",
5
5
  "author": "ekhein",
6
6
  "main": "./dist/main.js",
@@ -15,6 +15,7 @@ export interface HttpPhone4GProxy {
15
15
  export interface HttpServiceTypes {
16
16
  NATIVE: 1
17
17
  SEKIRO: 2
18
+ DEVICE: 3
18
19
  }
19
20
 
20
21
  export interface ExtendInternalAxiosRequestConfig extends HttpRequestConfig, InternalAxiosRequestConfig {