@ekhein/http-request 2.0.8 → 2.0.10

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.
@@ -4,10 +4,13 @@ export declare class HttpRequest {
4
4
  protected readonly instance: AxiosInstance;
5
5
  constructor(options?: HttpRequestConfig);
6
6
  execute<R = any>(options: HttpRequestConfig): Promise<R>;
7
+ get(url: string, params?: any, options?: HttpRequestConfig): Promise<any>;
8
+ post(url: string, body?: any, options?: HttpRequestConfig): Promise<any>;
9
+ form(url: string, form?: any, options?: HttpRequestConfig): Promise<any>;
7
10
  }
8
11
  export declare class NativeClient extends HttpRequest {
9
12
  constructor(options?: NativeClientConfig);
10
- post<R = any>(url: string, body?: any): Promise<R>;
13
+ action<R = any>(url: string, body?: any): Promise<R>;
11
14
  }
12
15
  export declare class SekiroClient extends HttpRequest {
13
16
  constructor(options?: SekiroClientConfig);
@@ -160,11 +160,18 @@ class HttpRequest {
160
160
  }));
161
161
  /* Request Hook */
162
162
  this.instance.interceptors.request.use((_a = options.interceptorHooks) === null || _a === void 0 ? void 0 : _a.requestInterceptor, (_b = options.interceptorHooks) === null || _b === void 0 ? void 0 : _b.requestInterceptorCatch);
163
+ /* Wait */
164
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
165
+ if (request.wait) {
166
+ yield new Promise(resolve => setTimeout(resolve, request.wait));
167
+ }
168
+ return request;
169
+ }));
163
170
  /* Response Hook */
164
171
  this.instance.interceptors.response.use((_c = options.interceptorHooks) === null || _c === void 0 ? void 0 : _c.respondInterceptor, (_d = options.interceptorHooks) === null || _d === void 0 ? void 0 : _d.respondInterceptorCatch);
165
172
  /* Transform */
166
173
  this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () {
167
- if (typeof response.headers == "object") {
174
+ if (typeof (response === null || response === void 0 ? void 0 : response.headers) == "object") {
168
175
  if (response.headers instanceof headers_1.HttpRequestHeaders) {
169
176
  if (response.config.html) {
170
177
  return new jsdom_1.JSDOM(response.data);
@@ -183,6 +190,24 @@ class HttpRequest {
183
190
  .request(options);
184
191
  });
185
192
  }
193
+ get(url, params, options) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ return this
196
+ .execute(Object.assign(Object.assign({}, options), { method: "GET", url, params }));
197
+ });
198
+ }
199
+ post(url, body, options) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ return this
202
+ .execute(Object.assign(Object.assign({}, options), { method: "POST", url, body }));
203
+ });
204
+ }
205
+ form(url, form, options) {
206
+ return __awaiter(this, void 0, void 0, function* () {
207
+ return this
208
+ .execute(Object.assign(Object.assign({}, options), { method: "POST", url, form }));
209
+ });
210
+ }
186
211
  }
187
212
  exports.HttpRequest = HttpRequest;
188
213
  __decorate([
@@ -224,7 +249,7 @@ class NativeClient extends HttpRequest {
224
249
  },
225
250
  });
226
251
  }
227
- post(url, body) {
252
+ action(url, body) {
228
253
  return __awaiter(this, void 0, void 0, function* () {
229
254
  return this.instance
230
255
  .request({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/http-request",
3
- "version": "2.0.8",
3
+ "version": "2.0.10",
4
4
  "license": "MIT",
5
5
  "author": "ekhein",
6
6
  "main": "./dist/index.js",
@@ -24,6 +24,7 @@ export interface ExtendAxiosRequestConfig extends Record<string, any> {
24
24
  form?: any
25
25
  body?: any
26
26
  html?: boolean
27
+ wait?: number
27
28
  resolveBodyOnly?: boolean
28
29
  useProxy?: boolean | HttpLiuGuanProxy | HttpAndroidProxy
29
30
  jar?: CookieJar