@modern-js/create-request 2.35.0 → 2.36.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.
@@ -1,34 +1,39 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- configure: function() {
14
- return configure;
15
- },
16
- createRequest: function() {
17
- return createRequest;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var browser_exports = {};
20
+ __export(browser_exports, {
21
+ configure: () => configure,
22
+ createRequest: () => createRequest
19
23
  });
20
- const _pathtoregexp = require("path-to-regexp");
21
- const _querystring = require("query-string");
22
- const _handleRes = require("./handleRes");
24
+ module.exports = __toCommonJS(browser_exports);
25
+ var import_path_to_regexp = require("path-to-regexp");
26
+ var import_query_string = require("query-string");
27
+ var import_handleRes = require("./handleRes");
23
28
  let realRequest;
24
29
  let realAllowedHeaders;
25
30
  const originFetch = (...params) => {
26
- var _init_method, _init;
31
+ var _init_method;
27
32
  const [url, init] = params;
28
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
33
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
29
34
  init.body = void 0;
30
35
  }
31
- return fetch(url, init).then(_handleRes.handleRes);
36
+ return fetch(url, init).then(import_handleRes.handleRes);
32
37
  };
33
38
  const configure = (options) => {
34
39
  const { request, interceptor, allowedHeaders } = options;
@@ -41,11 +46,11 @@ const configure = (options) => {
41
46
  }
42
47
  };
43
48
  const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch1 = originFetch) => {
44
- const getFinalPath = (0, _pathtoregexp.compile)(path, {
49
+ const getFinalPath = (0, import_path_to_regexp.compile)(path, {
45
50
  encode: encodeURIComponent
46
51
  });
47
52
  const keys = [];
48
- (0, _pathtoregexp.pathToRegexp)(path, keys);
53
+ (0, import_path_to_regexp.pathToRegexp)(path, keys);
49
54
  const sender = async (...args) => {
50
55
  const fetcher = realRequest || originFetch;
51
56
  let body;
@@ -74,7 +79,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
74
79
  });
75
80
  }
76
81
  const finalPath = getFinalPath(payload.params);
77
- finalURL = payload.query ? `${finalPath}?${(0, _querystring.stringify)(payload.query)}` : finalPath;
82
+ finalURL = payload.query ? `${finalPath}?${(0, import_query_string.stringify)(payload.query)}` : finalPath;
78
83
  headers = payload.headers || {};
79
84
  body = payload.data && typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.body;
80
85
  if (payload.data) {
@@ -90,7 +95,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
90
95
  if (typeof payload.formUrlencoded === "object" && // @ts-expect-error
91
96
  // eslint-disable-next-line node/prefer-global/url-search-params,node/no-unsupported-features/node-builtins
92
97
  !(payload.formUrlencoded instanceof URLSearchParams)) {
93
- body = (0, _querystring.stringify)(payload.formUrlencoded);
98
+ body = (0, import_query_string.stringify)(payload.formUrlencoded);
94
99
  } else {
95
100
  body = payload.formUrlencoded;
96
101
  }
@@ -105,3 +110,8 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
105
110
  };
106
111
  return sender;
107
112
  };
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {
115
+ configure,
116
+ createRequest
117
+ });
@@ -1,32 +1,48 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "handleRes", {
6
- enumerable: true,
7
- get: function() {
8
- return handleRes;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var handleRes_exports = {};
20
+ __export(handleRes_exports, {
21
+ handleRes: () => handleRes
10
22
  });
23
+ module.exports = __toCommonJS(handleRes_exports);
11
24
  const handleRes = async (res) => {
12
- var _contentType, _contentType1, _contentType2, _contentType3, _contentType4, _contentType5, _contentType6;
13
25
  const contentType = res.headers.get("content-type");
14
26
  if (!res.ok) {
15
27
  const data = await res.json();
16
28
  res.data = data;
17
29
  throw res;
18
30
  }
19
- if (((_contentType = contentType) === null || _contentType === void 0 ? void 0 : _contentType.includes("application/json")) || ((_contentType1 = contentType) === null || _contentType1 === void 0 ? void 0 : _contentType1.includes("text/json"))) {
31
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
20
32
  return res.json();
21
33
  }
22
- if (((_contentType2 = contentType) === null || _contentType2 === void 0 ? void 0 : _contentType2.includes("text/html")) || ((_contentType3 = contentType) === null || _contentType3 === void 0 ? void 0 : _contentType3.includes("text/plain"))) {
34
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
23
35
  return res.text();
24
36
  }
25
- if ((((_contentType4 = contentType) === null || _contentType4 === void 0 ? void 0 : _contentType4.includes("application/x-www-form-urlencoded")) || ((_contentType5 = contentType) === null || _contentType5 === void 0 ? void 0 : _contentType5.includes("multipart/form-data"))) && res instanceof Response) {
37
+ if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
26
38
  return res.formData();
27
39
  }
28
- if ((_contentType6 = contentType) === null || _contentType6 === void 0 ? void 0 : _contentType6.includes("application/octet-stream")) {
40
+ if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
29
41
  return res.arrayBuffer();
30
42
  }
31
43
  return res.text();
32
44
  };
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ handleRes
48
+ });
package/dist/cjs/node.js CHANGED
@@ -1,56 +1,70 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
6
9
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- configure: function() {
14
- return configure;
15
- },
16
- createRequest: function() {
17
- return createRequest;
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
17
  }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var node_exports = {};
30
+ __export(node_exports, {
31
+ configure: () => configure,
32
+ createRequest: () => createRequest
19
33
  });
20
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
21
- const _nodefetch = /* @__PURE__ */ _interop_require_default._(require("node-fetch"));
22
- const _pathtoregexp = require("path-to-regexp");
23
- const _runtimenode = require("@modern-js/utils/runtime-node");
24
- const _querystring = require("query-string");
25
- const _handleRes = require("./handleRes");
34
+ module.exports = __toCommonJS(node_exports);
35
+ var import_node_fetch = __toESM(require("node-fetch"));
36
+ var import_path_to_regexp = require("path-to-regexp");
37
+ var import_node = require("@modern-js/runtime-utils/node");
38
+ var import_query_string = require("query-string");
39
+ var import_handleRes = require("./handleRes");
26
40
  let realRequest;
27
41
  let realAllowedHeaders = [];
28
42
  const originFetch = (...params) => {
29
- var _init_method, _init;
43
+ var _init_method;
30
44
  const [, init] = params;
31
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
45
+ if ((init === null || init === void 0 ? void 0 : (_init_method = init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
32
46
  init.body = void 0;
33
47
  }
34
- return (0, _nodefetch.default)(...params).then(_handleRes.handleRes);
48
+ return (0, import_node_fetch.default)(...params).then(import_handleRes.handleRes);
35
49
  };
36
50
  const configure = (options) => {
37
51
  const { request, interceptor, allowedHeaders } = options;
38
52
  realRequest = request || originFetch;
39
53
  if (interceptor && !request) {
40
- realRequest = interceptor(_nodefetch.default);
54
+ realRequest = interceptor(import_node_fetch.default);
41
55
  }
42
56
  if (Array.isArray(allowedHeaders)) {
43
57
  realAllowedHeaders = allowedHeaders;
44
58
  }
45
59
  };
46
- const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = _nodefetch.default) => {
47
- const getFinalPath = (0, _pathtoregexp.compile)(path, {
60
+ const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = import_node_fetch.default) => {
61
+ const getFinalPath = (0, import_path_to_regexp.compile)(path, {
48
62
  encode: encodeURIComponent
49
63
  });
50
64
  const keys = [];
51
- (0, _pathtoregexp.pathToRegexp)(path, keys);
65
+ (0, import_path_to_regexp.pathToRegexp)(path, keys);
52
66
  const sender = (...args) => {
53
- const webRequestHeaders = (0, _runtimenode.useHeaders)();
67
+ const webRequestHeaders = (0, import_node.useHeaders)();
54
68
  let body;
55
69
  let headers;
56
70
  let url;
@@ -75,7 +89,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
75
89
  });
76
90
  }
77
91
  const plainPath = getFinalPath(payload.params);
78
- const finalPath = payload.query ? `${plainPath}?${(0, _querystring.stringify)(payload.query)}` : plainPath;
92
+ const finalPath = payload.query ? `${plainPath}?${(0, import_query_string.stringify)(payload.query)}` : plainPath;
79
93
  headers = payload.headers || {};
80
94
  for (const key of realAllowedHeaders) {
81
95
  if (typeof webRequestHeaders[key] !== "undefined") {
@@ -93,7 +107,7 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
93
107
  } else if (payload.formUrlencoded) {
94
108
  headers["Content-Type"] = "application/x-www-form-urlencoded";
95
109
  if (typeof payload.formUrlencoded === "object") {
96
- body = (0, _querystring.stringify)(payload.formUrlencoded);
110
+ body = (0, import_query_string.stringify)(payload.formUrlencoded);
97
111
  } else {
98
112
  body = payload.formUrlencoded;
99
113
  }
@@ -113,3 +127,8 @@ const createRequest = (path, method, port, httpMethodDecider = "functionName", f
113
127
  };
114
128
  return sender;
115
129
  };
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ configure,
133
+ createRequest
134
+ });
package/dist/cjs/types.js CHANGED
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -11,14 +11,14 @@ 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
- var _init_method, _init;
14
+ var _init_method;
15
15
  var _params = _sliced_to_array(params, 2), url = _params[0], init = _params[1];
16
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
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
17
  init.body = void 0;
18
18
  }
19
19
  return fetch(url, init).then(handleRes);
20
20
  };
21
- export var configure = function(options) {
21
+ var configure = function(options) {
22
22
  var request = options.request, interceptor = options.interceptor, allowedHeaders = options.allowedHeaders;
23
23
  realRequest = request || originFetch;
24
24
  if (interceptor && !request) {
@@ -28,7 +28,7 @@ export var configure = function(options) {
28
28
  realAllowedHeaders = allowedHeaders;
29
29
  }
30
30
  };
31
- export var createRequest = function(path, method, port) {
31
+ var createRequest = function(path, method, port) {
32
32
  var httpMethodDecider = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "functionName", fetch1 = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : originFetch;
33
33
  var getFinalPath = compile(path, {
34
34
  encode: encodeURIComponent
@@ -47,7 +47,7 @@ export var createRequest = function(path, method, port) {
47
47
  if (httpMethodDecider === "inputParams") {
48
48
  finalURL = path;
49
49
  body = JSON.stringify({
50
- args: args
50
+ args
51
51
  });
52
52
  headers = {
53
53
  "Content-Type": "application/json"
@@ -93,9 +93,9 @@ export var createRequest = function(path, method, port) {
93
93
  return [
94
94
  2,
95
95
  fetcher(finalURL, {
96
- method: method,
97
- body: body,
98
- headers: headers
96
+ method,
97
+ body,
98
+ headers
99
99
  })
100
100
  ];
101
101
  });
@@ -106,3 +106,7 @@ export var createRequest = function(path, method, port) {
106
106
  }();
107
107
  return sender;
108
108
  };
109
+ export {
110
+ configure,
111
+ createRequest
112
+ };
@@ -3,7 +3,7 @@ import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
4
  var handleRes = function() {
5
5
  var _ref = _async_to_generator(function(res) {
6
- var _contentType, _contentType1, _contentType2, _contentType3, _contentType4, _contentType5, _contentType6, contentType, data;
6
+ var contentType, data;
7
7
  return _ts_generator(this, function(_state) {
8
8
  switch (_state.label) {
9
9
  case 0:
@@ -22,25 +22,25 @@ var handleRes = function() {
22
22
  res.data = data;
23
23
  throw res;
24
24
  case 2:
25
- if (((_contentType = contentType) === null || _contentType === void 0 ? void 0 : _contentType.includes("application/json")) || ((_contentType1 = contentType) === null || _contentType1 === void 0 ? void 0 : _contentType1.includes("text/json"))) {
25
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
26
26
  return [
27
27
  2,
28
28
  res.json()
29
29
  ];
30
30
  }
31
- if (((_contentType2 = contentType) === null || _contentType2 === void 0 ? void 0 : _contentType2.includes("text/html")) || ((_contentType3 = contentType) === null || _contentType3 === void 0 ? void 0 : _contentType3.includes("text/plain"))) {
31
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
32
32
  return [
33
33
  2,
34
34
  res.text()
35
35
  ];
36
36
  }
37
- if ((((_contentType4 = contentType) === null || _contentType4 === void 0 ? void 0 : _contentType4.includes("application/x-www-form-urlencoded")) || ((_contentType5 = contentType) === null || _contentType5 === void 0 ? void 0 : _contentType5.includes("multipart/form-data"))) && _instanceof(res, Response)) {
37
+ if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && _instanceof(res, Response)) {
38
38
  return [
39
39
  2,
40
40
  res.formData()
41
41
  ];
42
42
  }
43
- if ((_contentType6 = contentType) === null || _contentType6 === void 0 ? void 0 : _contentType6.includes("application/octet-stream")) {
43
+ if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
44
44
  return [
45
45
  2,
46
46
  res.arrayBuffer()
@@ -57,4 +57,6 @@ var handleRes = function() {
57
57
  return _ref.apply(this, arguments);
58
58
  };
59
59
  }();
60
- export { handleRes };
60
+ export {
61
+ handleRes
62
+ };
package/dist/esm/node.js CHANGED
@@ -2,7 +2,7 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
2
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
3
3
  import nodeFetch from "node-fetch";
4
4
  import { compile, pathToRegexp } from "path-to-regexp";
5
- import { useHeaders } from "@modern-js/utils/runtime-node";
5
+ import { useHeaders } from "@modern-js/runtime-utils/node";
6
6
  import { stringify } from "query-string";
7
7
  import { handleRes } from "./handleRes";
8
8
  var realRequest;
@@ -11,14 +11,14 @@ 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
- var _init_method, _init;
14
+ var _init_method;
15
15
  var _params = _sliced_to_array(params, 2), init = _params[1];
16
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
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
17
  init.body = void 0;
18
18
  }
19
19
  return nodeFetch.apply(void 0, _to_consumable_array(params)).then(handleRes);
20
20
  };
21
- export var configure = function(options) {
21
+ var configure = function(options) {
22
22
  var request = options.request, interceptor = options.interceptor, allowedHeaders = options.allowedHeaders;
23
23
  realRequest = request || originFetch;
24
24
  if (interceptor && !request) {
@@ -28,7 +28,7 @@ export var configure = function(options) {
28
28
  realAllowedHeaders = allowedHeaders;
29
29
  }
30
30
  };
31
- export var createRequest = function(path, method, port) {
31
+ var createRequest = function(path, method, port) {
32
32
  var httpMethodDecider = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "functionName", fetch = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : nodeFetch;
33
33
  var getFinalPath = compile(path, {
34
34
  encode: encodeURIComponent
@@ -112,10 +112,14 @@ export var createRequest = function(path, method, port) {
112
112
  }
113
113
  headers.accept = "application/json,*/*;q=0.8";
114
114
  return fetcher(url, {
115
- method: method,
116
- body: body,
117
- headers: headers
115
+ method,
116
+ body,
117
+ headers
118
118
  });
119
119
  };
120
120
  return sender;
121
121
  };
122
+ export {
123
+ configure,
124
+ createRequest
125
+ };
package/dist/esm/types.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -4,14 +4,14 @@ import { handleRes } from "./handleRes";
4
4
  let realRequest;
5
5
  let realAllowedHeaders;
6
6
  const originFetch = (...params) => {
7
- var _init_method, _init;
7
+ var _init_method;
8
8
  const [url, init] = params;
9
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
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
10
  init.body = void 0;
11
11
  }
12
12
  return fetch(url, init).then(handleRes);
13
13
  };
14
- export const configure = (options) => {
14
+ const configure = (options) => {
15
15
  const { request, interceptor, allowedHeaders } = options;
16
16
  realRequest = request || originFetch;
17
17
  if (interceptor && !request) {
@@ -21,7 +21,7 @@ export const configure = (options) => {
21
21
  realAllowedHeaders = allowedHeaders;
22
22
  }
23
23
  };
24
- export const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch1 = originFetch) => {
24
+ const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch1 = originFetch) => {
25
25
  const getFinalPath = compile(path, {
26
26
  encode: encodeURIComponent
27
27
  });
@@ -86,3 +86,7 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
86
86
  };
87
87
  return sender;
88
88
  };
89
+ export {
90
+ configure,
91
+ createRequest
92
+ };
@@ -1,23 +1,24 @@
1
1
  const handleRes = async (res) => {
2
- var _contentType, _contentType1, _contentType2, _contentType3, _contentType4, _contentType5, _contentType6;
3
2
  const contentType = res.headers.get("content-type");
4
3
  if (!res.ok) {
5
4
  const data = await res.json();
6
5
  res.data = data;
7
6
  throw res;
8
7
  }
9
- if (((_contentType = contentType) === null || _contentType === void 0 ? void 0 : _contentType.includes("application/json")) || ((_contentType1 = contentType) === null || _contentType1 === void 0 ? void 0 : _contentType1.includes("text/json"))) {
8
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/json"))) {
10
9
  return res.json();
11
10
  }
12
- if (((_contentType2 = contentType) === null || _contentType2 === void 0 ? void 0 : _contentType2.includes("text/html")) || ((_contentType3 = contentType) === null || _contentType3 === void 0 ? void 0 : _contentType3.includes("text/plain"))) {
11
+ if ((contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/html")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/plain"))) {
13
12
  return res.text();
14
13
  }
15
- if ((((_contentType4 = contentType) === null || _contentType4 === void 0 ? void 0 : _contentType4.includes("application/x-www-form-urlencoded")) || ((_contentType5 = contentType) === null || _contentType5 === void 0 ? void 0 : _contentType5.includes("multipart/form-data"))) && res instanceof Response) {
14
+ if (((contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/x-www-form-urlencoded")) || (contentType === null || contentType === void 0 ? void 0 : contentType.includes("multipart/form-data"))) && res instanceof Response) {
16
15
  return res.formData();
17
16
  }
18
- if ((_contentType6 = contentType) === null || _contentType6 === void 0 ? void 0 : _contentType6.includes("application/octet-stream")) {
17
+ if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/octet-stream")) {
19
18
  return res.arrayBuffer();
20
19
  }
21
20
  return res.text();
22
21
  };
23
- export { handleRes };
22
+ export {
23
+ handleRes
24
+ };
@@ -1,19 +1,19 @@
1
1
  import nodeFetch from "node-fetch";
2
2
  import { compile, pathToRegexp } from "path-to-regexp";
3
- import { useHeaders } from "@modern-js/utils/runtime-node";
3
+ import { useHeaders } from "@modern-js/runtime-utils/node";
4
4
  import { stringify } from "query-string";
5
5
  import { handleRes } from "./handleRes";
6
6
  let realRequest;
7
7
  let realAllowedHeaders = [];
8
8
  const originFetch = (...params) => {
9
- var _init_method, _init;
9
+ var _init_method;
10
10
  const [, init] = params;
11
- if (((_init = init) === null || _init === void 0 ? void 0 : (_init_method = _init.method) === null || _init_method === void 0 ? void 0 : _init_method.toLowerCase()) === "get") {
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
12
  init.body = void 0;
13
13
  }
14
14
  return nodeFetch(...params).then(handleRes);
15
15
  };
16
- export const configure = (options) => {
16
+ const configure = (options) => {
17
17
  const { request, interceptor, allowedHeaders } = options;
18
18
  realRequest = request || originFetch;
19
19
  if (interceptor && !request) {
@@ -23,7 +23,7 @@ export const configure = (options) => {
23
23
  realAllowedHeaders = allowedHeaders;
24
24
  }
25
25
  };
26
- export const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = nodeFetch) => {
26
+ const createRequest = (path, method, port, httpMethodDecider = "functionName", fetch = nodeFetch) => {
27
27
  const getFinalPath = compile(path, {
28
28
  encode: encodeURIComponent
29
29
  });
@@ -93,3 +93,7 @@ export const createRequest = (path, method, port, httpMethodDecider = "functionN
93
93
  };
94
94
  return sender;
95
95
  };
96
+ export {
97
+ configure,
98
+ createRequest
99
+ };
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.0",
18
+ "version": "2.36.0",
19
19
  "jsnext:source": "./src/node.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/node.js",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "exports": {
29
29
  ".": {
30
- "types": "./dist/types/node.d.ts",
30
+ "types": "./dist/types/browser.d.ts",
31
31
  "node": "./dist/esm/node.js",
32
32
  "default": "./dist/esm/browser.js"
33
33
  },
@@ -64,7 +64,8 @@
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.35.0"
67
+ "@modern-js/runtime-utils": "2.36.0",
68
+ "@modern-js/utils": "2.36.0"
68
69
  },
69
70
  "devDependencies": {
70
71
  "@types/jest": "^29",
@@ -74,9 +75,9 @@
74
75
  "jest": "^29",
75
76
  "nock": "^13.2.1",
76
77
  "typescript": "^5",
77
- "@scripts/jest-config": "2.35.0",
78
- "@scripts/build": "2.35.0",
79
- "@modern-js/types": "2.35.0"
78
+ "@scripts/build": "2.36.0",
79
+ "@modern-js/types": "2.36.0",
80
+ "@scripts/jest-config": "2.36.0"
80
81
  },
81
82
  "sideEffects": false,
82
83
  "publishConfig": {