@ekhein/http-request 1.0.8 → 1.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.
package/dist/main.js CHANGED
@@ -44,14 +44,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
44
44
  step((generator = generator.apply(thisArg, _arguments || [])).next());
45
45
  });
46
46
  };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
47
50
  Object.defineProperty(exports, "__esModule", { value: true });
48
51
  exports.HttpRequest = exports.HttpRequestHeaders = void 0;
49
52
  const axios_1 = __importStar(require("axios"));
53
+ const tldts_1 = __importDefault(require("tldts"));
54
+ const cookie = __importStar(require("cookie"));
50
55
  const jsdom_1 = require("jsdom");
51
56
  const lodash_1 = require("lodash");
52
57
  const tough_cookie_1 = require("tough-cookie");
53
- const cookie_1 = require("cookie");
54
- const tldts_1 = require("tldts");
55
58
  const common_1 = require("@nestjs/common");
56
59
  const http_error_by_code_util_1 = require("@nestjs/common/utils/http-error-by-code.util");
57
60
  const libs_1 = require("./libs");
@@ -101,15 +104,17 @@ class HttpRequest {
101
104
  }));
102
105
  /* Set Cookie */
103
106
  this.instance.interceptors.request.use((request) => __awaiter(this, void 0, void 0, function* () {
107
+ var _a;
104
108
  if (request.headers.cookie) {
105
109
  const api = new URL(request.url, request.baseURL);
106
- const domain = (0, tldts_1.getDomain)(api.href); /* 一级域名 */
107
- const cookies = (0, cookie_1.parse)(request.headers.cookie);
108
- const website = Array(api.protocol, domain).join("//");
110
+ const parsed = tldts_1.default.parse(api.href);
111
+ const cookies = cookie.parse(request.headers.cookie);
112
+ const domain1 = String((_a = parsed.domain) !== null && _a !== void 0 ? _a : parsed.hostname); /* 顶级域名 */
113
+ const website = Array(api.protocol, domain1).join("//");
109
114
  const entries = Object.entries(cookies);
110
115
  for (const [key, value] of entries) {
111
- const cookie = new tough_cookie_1.Cookie({ key, value, domain });
112
- request.jar.setCookieSync(cookie, website);
116
+ const cookie = new tough_cookie_1.Cookie(Object.assign(Object.assign({}, parsed), { key, value }));
117
+ yield request.jar.setCookie(cookie, website);
113
118
  }
114
119
  }
115
120
  return request;
@@ -230,14 +235,14 @@ class HttpRequest {
230
235
  .request(options);
231
236
  });
232
237
  }
233
- post(url, data, opts) {
234
- return __awaiter(this, void 0, void 0, function* () {
238
+ post(url_1, data_1) {
239
+ return __awaiter(this, arguments, void 0, function* (url, data, opts = {}) {
235
240
  return this.instance
236
241
  .request(Object.assign(Object.assign({}, opts), { method: "POST", serviceType: 1, url, data }));
237
242
  });
238
243
  }
239
- call(path, data, opts) {
240
- return __awaiter(this, void 0, void 0, function* () {
244
+ call(path_1, data_1) {
245
+ return __awaiter(this, arguments, void 0, function* (path, data, opts = {}) {
241
246
  return this.instance
242
247
  .request(Object.assign(Object.assign({}, opts), { method: "POST", serviceType: 2, path, data }));
243
248
  });
package/dist/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/test.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const main_1 = require("./main");
4
+ const request = new main_1.HttpRequest({
5
+ baseURL: "http://a.b.c.goofish.com"
6
+ });
7
+ request.execute({
8
+ url: "/api/test",
9
+ headers: {
10
+ cookie: "a=1;b=2"
11
+ }
12
+ })
13
+ .catch(e => { });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekhein/http-request",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "license": "MIT",
5
5
  "author": "ekhein",
6
6
  "main": "./dist/main.js",
@@ -18,6 +18,7 @@
18
18
  "@types/jsdom": "^21.1.7",
19
19
  "@types/lodash": "^4.17.20",
20
20
  "@types/node": "^22.15.18",
21
+ "@types/tldjs": "^2.3.4",
21
22
  "tsx": "^4.19.4",
22
23
  "typescript": "^5.8.3"
23
24
  },
@@ -30,6 +31,7 @@
30
31
  "jsdom": "^25.0.1",
31
32
  "lodash": "^4.17.21",
32
33
  "proxy-agent": "^6.5.0",
34
+ "tldjs": "^2.3.2",
33
35
  "tldts": "^7.0.16",
34
36
  "tough-cookie": "^6.0.0"
35
37
  },