@ekhein/http-request 1.0.5 → 1.0.6

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
@@ -8,4 +8,4 @@ export declare class HttpRequest {
8
8
  call<R = any>(path: string, data: object): Promise<R>;
9
9
  }
10
10
  export * from './exceptions';
11
- export * from '../types/http-request';
11
+ export type * from '../types/http-request';
package/dist/main.js CHANGED
@@ -35,6 +35,15 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
+ return new (P || (P = Promise))(function (resolve, reject) {
41
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
42
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
43
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
44
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45
+ });
46
+ };
38
47
  Object.defineProperty(exports, "__esModule", { value: true });
39
48
  exports.HttpRequest = void 0;
40
49
  const axios_1 = __importStar(require("axios"));
@@ -50,20 +59,18 @@ const agent_2 = require("./agent");
50
59
  const agent_3 = require("./agent");
51
60
  const exceptions_1 = require("./exceptions");
52
61
  class HttpRequest {
53
- instance;
54
62
  constructor(options) {
63
+ var _a, _b, _c, _d;
55
64
  /* Axios */
56
- this.instance = axios_1.default.create({
57
- ...Object.assign({
58
- ["headers"]: {},
59
- ["retryLimit"]: 3,
60
- }, options, {
61
- ["proxy"]: false,
62
- ["retryCount"]: 0,
63
- })
64
- });
65
+ this.instance = axios_1.default.create(Object.assign({}, Object.assign({
66
+ ["headers"]: {},
67
+ ["retryLimit"]: 3,
68
+ }, options, {
69
+ ["proxy"]: false,
70
+ ["retryCount"]: 0,
71
+ })));
65
72
  /* Set Http Agent */
66
- this.instance.interceptors.request.use(async (request) => {
73
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
67
74
  const jar = Object(request.jar);
68
75
  const cookies = Object({ jar });
69
76
  if (request.useProxy) {
@@ -87,9 +94,9 @@ class HttpRequest {
87
94
  request.httpsAgent = new agent_1.HttpsCookieAgent({ cookies });
88
95
  }
89
96
  return request;
90
- });
97
+ }));
91
98
  /* Set Cookie */
92
- this.instance.interceptors.request.use(async (request) => {
99
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
93
100
  if (request.headers.cookie) {
94
101
  const api = new URL(request.url, request.baseURL);
95
102
  const domain = (0, tldts_1.getDomain)(api.href); /* 一级域名 */
@@ -102,15 +109,15 @@ class HttpRequest {
102
109
  }
103
110
  }
104
111
  return request;
105
- });
112
+ }));
106
113
  /* Set Cookie Jar */
107
- this.instance.interceptors.request.use(async (request) => {
114
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
108
115
  if (!request.jar)
109
116
  request.jar = new tough_cookie_1.CookieJar();
110
117
  return request;
111
- });
118
+ }));
112
119
  /* Headers Format */
113
- this.instance.interceptors.request.use(async (request) => {
120
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
114
121
  if (request.headers) {
115
122
  const headers = Object.entries(request.headers);
116
123
  for (const [key, value] of headers) {
@@ -122,9 +129,9 @@ class HttpRequest {
122
129
  }
123
130
  }
124
131
  return request;
125
- });
132
+ }));
126
133
  /* Set Body */
127
- this.instance.interceptors.request.use(async (request) => {
134
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
128
135
  if (request.body) {
129
136
  request.headers.setContentType("application/json");
130
137
  request.data = request.body;
@@ -134,9 +141,9 @@ class HttpRequest {
134
141
  request.data = request.form;
135
142
  }
136
143
  return request;
137
- });
144
+ }));
138
145
  /* Transform */
139
- this.instance.interceptors.request.use(async (request) => {
146
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
140
147
  if (request.serviceType == 1) { }
141
148
  if (request.serviceType == 2) {
142
149
  const group = String(request.path).split("/").at(-2);
@@ -146,16 +153,16 @@ class HttpRequest {
146
153
  request.params = Object({ group, action, invoke_timeout });
147
154
  }
148
155
  return request;
149
- });
156
+ }));
150
157
  /* Call Custom Hook */
151
- this.instance.interceptors.request.use(options.interceptorHooks?.requestInterceptor, options.interceptorHooks?.requestInterceptorCatch);
158
+ 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);
152
159
  /* Save Origin Config */
153
- this.instance.interceptors.request.use(async (request) => {
160
+ this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
154
161
  request.__origin__ = (0, lodash_1.cloneDeep)(request);
155
162
  return (request);
156
- });
163
+ }));
157
164
  /* Transform */
158
- this.instance.interceptors.response.use(async (response) => {
165
+ this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () {
159
166
  if (response.config.serviceType == 1) {
160
167
  if (http_error_by_code_util_1.HttpErrorByCode[response.data.err])
161
168
  throw new http_error_by_code_util_1.HttpErrorByCode[response.data.err](response.data.msg);
@@ -172,11 +179,11 @@ class HttpRequest {
172
179
  return new jsdom_1.JSDOM(response.data);
173
180
  }
174
181
  return response;
175
- });
182
+ }));
176
183
  /* Call Custom Hook */
177
- this.instance.interceptors.response.use(options.interceptorHooks?.respondInterceptor, options.interceptorHooks?.respondInterceptorCatch);
184
+ 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);
178
185
  /* Handler Timeout */
179
- this.instance.interceptors.response.use(async (response) => response, async (error) => {
186
+ this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () { return response; }), (error) => __awaiter(this, void 0, void 0, function* () {
180
187
  if (error instanceof axios_1.AxiosError) {
181
188
  if (!error.code)
182
189
  throw new exceptions_1.AxiosRetryableError(error.config);
@@ -188,9 +195,9 @@ class HttpRequest {
188
195
  }
189
196
  }
190
197
  throw error;
191
- });
198
+ }));
192
199
  /* Auto Retry */
193
- this.instance.interceptors.response.use(async (response) => response, async (error) => {
200
+ this.instance.interceptors.response.use((response) => __awaiter(this, void 0, void 0, function* () { return response; }), (error) => __awaiter(this, void 0, void 0, function* () {
194
201
  if (error instanceof exceptions_1.AxiosRetryableError) {
195
202
  const retryCount = error.config.__origin__.retryCount++;
196
203
  const retryLimit = error.config.__origin__.retryLimit;
@@ -201,21 +208,26 @@ class HttpRequest {
201
208
  else {
202
209
  throw error;
203
210
  }
204
- });
211
+ }));
205
212
  }
206
- async execute(options) {
207
- return this.instance
208
- .request(options);
213
+ execute(options) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ return this.instance
216
+ .request(options);
217
+ });
209
218
  }
210
- async post(url, data) {
211
- return this.instance
212
- .request({ method: "POST", serviceType: 1, url, data });
219
+ post(url, data) {
220
+ return __awaiter(this, void 0, void 0, function* () {
221
+ return this.instance
222
+ .request({ method: "POST", serviceType: 1, url, data });
223
+ });
213
224
  }
214
- async call(path, data) {
215
- return this.instance
216
- .request({ method: "POST", serviceType: 2, path, data });
225
+ call(path, data) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ return this.instance
228
+ .request({ method: "POST", serviceType: 2, path, data });
229
+ });
217
230
  }
218
231
  }
219
232
  exports.HttpRequest = HttpRequest;
220
233
  __exportStar(require("./exceptions"), exports);
221
- __exportStar(require("../types/http-request"), exports);
@@ -21738,10 +21738,6 @@ exports.LIUGUAN_ADCODE_MAP = {
21738
21738
  }
21739
21739
  };
21740
21740
  class LiuGuanProxy extends proxy_agent_1.ProxyAgent {
21741
- orderNo = "O23113017495247478361"; /* 订单编号 */
21742
- orderPwd = "123456aa.."; /* 订单密码 */
21743
- duplicate = "1"; /* 是否按天去重 - 0:不去重 1:按天去重 */
21744
- switch = "0"; /* 异常自动切换 - 0:自动切换 1:不自动切换,返回代理异常 */
21745
21741
  constructor(opts) {
21746
21742
  super({
21747
21743
  getProxyForUrl: () => {
@@ -21767,6 +21763,10 @@ class LiuGuanProxy extends proxy_agent_1.ProxyAgent {
21767
21763
  return (proxyURL.href);
21768
21764
  },
21769
21765
  });
21766
+ this.orderNo = "O23113017495247478361"; /* 订单编号 */
21767
+ this.orderPwd = "123456aa.."; /* 订单密码 */
21768
+ this.duplicate = "1"; /* 是否按天去重 - 0:不去重 1:按天去重 */
21769
+ this.switch = "0"; /* 异常自动切换 - 0:自动切换 1:不自动切换,返回代理异常 */
21770
21770
  }
21771
21771
  }
21772
21772
  exports.LiuGuanProxy = LiuGuanProxy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/http-request",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "license": "MIT",
5
5
  "author": "ekhein",
6
6
  "main": "./dist/main.js",
@@ -15,7 +15,7 @@
15
15
  "node": ">=18.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/jsdom": "^27.0.0",
18
+ "@types/jsdom": "^21.1.7",
19
19
  "@types/lodash": "^4.17.20",
20
20
  "@types/node": "^22.15.18",
21
21
  "tsx": "^4.19.4",
@@ -26,7 +26,7 @@
26
26
  "axios": "^1.12.2",
27
27
  "cookie": "^1.0.2",
28
28
  "http-cookie-agent": "^7.0.2",
29
- "jsdom": "^27.0.0",
29
+ "jsdom": "^25.0.1",
30
30
  "lodash": "^4.17.21",
31
31
  "proxy-agent": "^6.5.0",
32
32
  "tldts": "^7.0.16",