@modern-js/create-request 2.25.1 → 2.26.0

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.
@@ -17,13 +17,19 @@ _export(exports, {
17
17
  return createRequest;
18
18
  }
19
19
  });
20
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
20
  const _pathtoregexp = require("path-to-regexp");
22
- const _querystring = /* @__PURE__ */ _interop_require_default._(require("query-string"));
21
+ const _querystring = require("query-string");
23
22
  const _handleRes = require("./handleRes");
24
23
  let realRequest;
25
24
  let realAllowedHeaders;
26
- const originFetch = (...params) => fetch(...params).then(_handleRes.handleRes);
25
+ const originFetch = (...params) => {
26
+ var _init_method;
27
+ const [url, init] = params;
28
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
29
+ init.body = void 0;
30
+ }
31
+ return fetch(url, init).then(_handleRes.handleRes);
32
+ };
27
33
  const configure = (options) => {
28
34
  const { request, interceptor, allowedHeaders } = options;
29
35
  realRequest = request || originFetch;
@@ -68,7 +74,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
68
74
  });
69
75
  }
70
76
  const finalPath = getFinalPath(payload.params);
71
- finalURL = payload.query ? `${finalPath}?${_querystring.default.stringify(payload.query)}` : finalPath;
77
+ finalURL = payload.query ? `${finalPath}?${(0, _querystring.stringify)(payload.query)}` : finalPath;
72
78
  headers = payload.headers || {};
73
79
  body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
74
80
  if (payload.data) {
@@ -81,19 +87,15 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
81
87
  body = payload.formData;
82
88
  } else if (payload.formUrlencoded) {
83
89
  headers["Content-Type"] = "application/x-www-form-urlencoded";
84
- if (typeof payload.formUrlencoded === "object" && // eslint-disable-next-line @typescript-eslint/ban-ts-comment
85
- // @ts-expect-error
90
+ if (typeof payload.formUrlencoded === "object" && // @ts-expect-error
86
91
  // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
87
92
  !(payload.formUrlencoded instanceof URLSearchParams)) {
88
- body = _querystring.default.stringify(payload.formUrlencoded);
93
+ body = (0, _querystring.stringify)(payload.formUrlencoded);
89
94
  } else {
90
95
  body = payload.formUrlencoded;
91
96
  }
92
97
  }
93
98
  }
94
- if (method.toLowerCase() === "get") {
95
- body = void 0;
96
- }
97
99
  headers.accept = `application/json,*/*;q=0.8`;
98
100
  return fetcher(finalURL, {
99
101
  method,
package/dist/cjs/node.js CHANGED
@@ -21,11 +21,18 @@ const _interop_require_default = require("@swc/helpers/_/_interop_require_defaul
21
21
  const _nodefetch = /* @__PURE__ */ _interop_require_default._(require("node-fetch"));
22
22
  const _pathtoregexp = require("path-to-regexp");
23
23
  const _runtimenode = require("@modern-js/utils/runtime-node");
24
- const _querystring = /* @__PURE__ */ _interop_require_default._(require("query-string"));
24
+ const _querystring = require("query-string");
25
25
  const _handleRes = require("./handleRes");
26
26
  let realRequest;
27
27
  let realAllowedHeaders = [];
28
- const originFetch = (...params) => (0, _nodefetch.default)(...params).then(_handleRes.handleRes);
28
+ const originFetch = (...params) => {
29
+ var _init_method;
30
+ const [, init] = params;
31
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
32
+ init.body = void 0;
33
+ }
34
+ return (0, _nodefetch.default)(...params).then(_handleRes.handleRes);
35
+ };
29
36
  const configure = (options) => {
30
37
  const { request, interceptor, allowedHeaders } = options;
31
38
  realRequest = request || originFetch;
@@ -68,7 +75,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
68
75
  });
69
76
  }
70
77
  const plainPath = getFinalPath(payload.params);
71
- const finalPath = payload.query ? `${plainPath}?${_querystring.default.stringify(payload.query)}` : plainPath;
78
+ const finalPath = payload.query ? `${plainPath}?${(0, _querystring.stringify)(payload.query)}` : plainPath;
72
79
  headers = payload.headers || {};
73
80
  for (const key of realAllowedHeaders) {
74
81
  if (typeof webRequestHeaders[key] !== "undefined") {
@@ -86,16 +93,13 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
86
93
  } else if (payload.formUrlencoded) {
87
94
  headers["Content-Type"] = "application/x-www-form-urlencoded";
88
95
  if (typeof payload.formUrlencoded === "object") {
89
- body = _querystring.default.stringify(payload.formUrlencoded);
96
+ body = (0, _querystring.stringify)(payload.formUrlencoded);
90
97
  } else {
91
98
  body = payload.formUrlencoded;
92
99
  }
93
100
  }
94
101
  url = `http://localhost:${port}${finalPath}`;
95
102
  }
96
- if (method.toLowerCase() === "get") {
97
- body = void 0;
98
- }
99
103
  const fetcher = realRequest || originFetch;
100
104
  if (method.toLowerCase() === "get") {
101
105
  body = void 0;
@@ -1,9 +1,9 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
- import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { compile, pathToRegexp } from "path-to-regexp";
6
- import qs from "query-string";
6
+ import { stringify } from "query-string";
7
7
  import { handleRes } from "./handleRes";
8
8
  var realRequest;
9
9
  var realAllowedHeaders;
@@ -11,7 +11,12 @@ var originFetch = function() {
11
11
  for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
12
12
  params[_key] = arguments[_key];
13
13
  }
14
- return fetch.apply(void 0, _to_consumable_array(params)).then(handleRes);
14
+ var _init_method;
15
+ var _params = _sliced_to_array(params, 2), url = _params[0], init = _params[1];
16
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
17
+ init.body = void 0;
18
+ }
19
+ return fetch(url, init).then(handleRes);
15
20
  };
16
21
  export var configure = function(options) {
17
22
  var request = options.request, interceptor = options.interceptor, allowedHeaders = options.allowedHeaders;
@@ -62,7 +67,7 @@ export var createRequest = function(path, method, port) {
62
67
  });
63
68
  }
64
69
  finalPath = getFinalPath(payload.params);
65
- finalURL = payload.query ? "".concat(finalPath, "?").concat(qs.stringify(payload.query)) : finalPath;
70
+ finalURL = payload.query ? "".concat(finalPath, "?").concat(stringify(payload.query)) : finalPath;
66
71
  headers = payload.headers || {};
67
72
  body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
68
73
  if (payload.data) {
@@ -75,19 +80,15 @@ export var createRequest = function(path, method, port) {
75
80
  body = payload.formData;
76
81
  } else if (payload.formUrlencoded) {
77
82
  headers["Content-Type"] = "application/x-www-form-urlencoded";
78
- if (typeof payload.formUrlencoded === "object" && // eslint-disable-next-line @typescript-eslint/ban-ts-comment
79
- // @ts-expect-error
83
+ if (typeof payload.formUrlencoded === "object" && // @ts-expect-error
80
84
  // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
81
85
  !_instanceof(payload.formUrlencoded, URLSearchParams)) {
82
- body = qs.stringify(payload.formUrlencoded);
86
+ body = stringify(payload.formUrlencoded);
83
87
  } else {
84
88
  body = payload.formUrlencoded;
85
89
  }
86
90
  }
87
91
  }
88
- if (method.toLowerCase() === "get") {
89
- body = void 0;
90
- }
91
92
  headers.accept = "application/json,*/*;q=0.8";
92
93
  return [
93
94
  2,
package/dist/esm/node.js CHANGED
@@ -1,8 +1,9 @@
1
+ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
1
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
2
3
  import nodeFetch from "node-fetch";
3
4
  import { compile, pathToRegexp } from "path-to-regexp";
4
5
  import { useHeaders } from "@modern-js/utils/runtime-node";
5
- import qs from "query-string";
6
+ import { stringify } from "query-string";
6
7
  import { handleRes } from "./handleRes";
7
8
  var realRequest;
8
9
  var realAllowedHeaders = [];
@@ -10,6 +11,11 @@ var originFetch = function() {
10
11
  for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
11
12
  params[_key] = arguments[_key];
12
13
  }
14
+ var _init_method;
15
+ var _params = _sliced_to_array(params, 2), init = _params[1];
16
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
17
+ init.body = void 0;
18
+ }
13
19
  return nodeFetch.apply(void 0, _to_consumable_array(params)).then(handleRes);
14
20
  };
15
21
  export var configure = function(options) {
@@ -58,7 +64,7 @@ export var createRequest = function(path, method, port) {
58
64
  });
59
65
  }
60
66
  var plainPath = getFinalPath(payload.params);
61
- var finalPath = payload.query ? "".concat(plainPath, "?").concat(qs.stringify(payload.query)) : plainPath;
67
+ var finalPath = payload.query ? "".concat(plainPath, "?").concat(stringify(payload.query)) : plainPath;
62
68
  headers = payload.headers || {};
63
69
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
64
70
  try {
@@ -93,16 +99,13 @@ export var createRequest = function(path, method, port) {
93
99
  } else if (payload.formUrlencoded) {
94
100
  headers["Content-Type"] = "application/x-www-form-urlencoded";
95
101
  if (typeof payload.formUrlencoded === "object") {
96
- body = qs.stringify(payload.formUrlencoded);
102
+ body = stringify(payload.formUrlencoded);
97
103
  } else {
98
104
  body = payload.formUrlencoded;
99
105
  }
100
106
  }
101
107
  url = "http://localhost:".concat(port).concat(finalPath);
102
108
  }
103
- if (method.toLowerCase() === "get") {
104
- body = void 0;
105
- }
106
109
  var fetcher = realRequest || originFetch;
107
110
  if (method.toLowerCase() === "get") {
108
111
  body = void 0;
@@ -1,9 +1,16 @@
1
1
  import { compile, pathToRegexp } from "path-to-regexp";
2
- import qs from "query-string";
2
+ import { stringify } from "query-string";
3
3
  import { handleRes } from "./handleRes";
4
4
  let realRequest;
5
5
  let realAllowedHeaders;
6
- const originFetch = (...params) => fetch(...params).then(handleRes);
6
+ const originFetch = (...params) => {
7
+ var _init_method;
8
+ const [url, init] = params;
9
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
10
+ init.body = void 0;
11
+ }
12
+ return fetch(url, init).then(handleRes);
13
+ };
7
14
  export const configure = (options) => {
8
15
  const { request, interceptor, allowedHeaders } = options;
9
16
  realRequest = request || originFetch;
@@ -48,7 +55,7 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
48
55
  });
49
56
  }
50
57
  const finalPath = getFinalPath(payload.params);
51
- finalURL = payload.query ? `${finalPath}?${qs.stringify(payload.query)}` : finalPath;
58
+ finalURL = payload.query ? `${finalPath}?${stringify(payload.query)}` : finalPath;
52
59
  headers = payload.headers || {};
53
60
  body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
54
61
  if (payload.data) {
@@ -61,19 +68,15 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
61
68
  body = payload.formData;
62
69
  } else if (payload.formUrlencoded) {
63
70
  headers["Content-Type"] = "application/x-www-form-urlencoded";
64
- if (typeof payload.formUrlencoded === "object" && // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
- // @ts-expect-error
71
+ if (typeof payload.formUrlencoded === "object" && // @ts-expect-error
66
72
  // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
67
73
  !(payload.formUrlencoded instanceof URLSearchParams)) {
68
- body = qs.stringify(payload.formUrlencoded);
74
+ body = stringify(payload.formUrlencoded);
69
75
  } else {
70
76
  body = payload.formUrlencoded;
71
77
  }
72
78
  }
73
79
  }
74
- if (method.toLowerCase() === "get") {
75
- body = void 0;
76
- }
77
80
  headers.accept = `application/json,*/*;q=0.8`;
78
81
  return fetcher(finalURL, {
79
82
  method,
@@ -1,11 +1,18 @@
1
1
  import nodeFetch from "node-fetch";
2
2
  import { compile, pathToRegexp } from "path-to-regexp";
3
3
  import { useHeaders } from "@modern-js/utils/runtime-node";
4
- import qs from "query-string";
4
+ import { stringify } from "query-string";
5
5
  import { handleRes } from "./handleRes";
6
6
  let realRequest;
7
7
  let realAllowedHeaders = [];
8
- const originFetch = (...params) => nodeFetch(...params).then(handleRes);
8
+ const originFetch = (...params) => {
9
+ var _init_method;
10
+ const [, init] = params;
11
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
12
+ init.body = void 0;
13
+ }
14
+ return nodeFetch(...params).then(handleRes);
15
+ };
9
16
  export const configure = (options) => {
10
17
  const { request, interceptor, allowedHeaders } = options;
11
18
  realRequest = request || originFetch;
@@ -48,7 +55,7 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
48
55
  });
49
56
  }
50
57
  const plainPath = getFinalPath(payload.params);
51
- const finalPath = payload.query ? `${plainPath}?${qs.stringify(payload.query)}` : plainPath;
58
+ const finalPath = payload.query ? `${plainPath}?${stringify(payload.query)}` : plainPath;
52
59
  headers = payload.headers || {};
53
60
  for (const key of realAllowedHeaders) {
54
61
  if (typeof webRequestHeaders[key] !== "undefined") {
@@ -66,16 +73,13 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
66
73
  } else if (payload.formUrlencoded) {
67
74
  headers["Content-Type"] = "application/x-www-form-urlencoded";
68
75
  if (typeof payload.formUrlencoded === "object") {
69
- body = qs.stringify(payload.formUrlencoded);
76
+ body = stringify(payload.formUrlencoded);
70
77
  } else {
71
78
  body = payload.formUrlencoded;
72
79
  }
73
80
  }
74
81
  url = `http://localhost:${port}${finalPath}`;
75
82
  }
76
- if (method.toLowerCase() === "get") {
77
- body = void 0;
78
- }
79
83
  const fetcher = realRequest || originFetch;
80
84
  if (method.toLowerCase() === "get") {
81
85
  body = void 0;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.25.1",
18
+ "version": "2.26.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -64,7 +64,7 @@
64
64
  "path-to-regexp": "^6.2.0",
65
65
  "query-string": "^7.1.1",
66
66
  "@swc/helpers": "0.5.1",
67
- "@modern-js/utils": "2.25.1"
67
+ "@modern-js/utils": "2.26.0"
68
68
  },
69
69
  "devDependencies": {
70
70
  "@types/jest": "^29",
@@ -74,9 +74,9 @@
74
74
  "jest": "^29",
75
75
  "nock": "^13.2.1",
76
76
  "typescript": "^5",
77
- "@modern-js/types": "2.25.1",
78
- "@scripts/jest-config": "2.25.1",
79
- "@scripts/build": "2.25.1"
77
+ "@modern-js/types": "2.26.0",
78
+ "@scripts/build": "2.26.0",
79
+ "@scripts/jest-config": "2.26.0"
80
80
  },
81
81
  "sideEffects": false,
82
82
  "publishConfig": {