@ywfe/fe-tools 1.2.1-beta.22 → 1.2.1-beta.24

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,28 +58,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
58
58
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
59
59
  };
60
60
 
61
- function userInputToJson(_a) {
62
- return __awaiter(this, arguments, void 0, function (_b) {
63
- var res;
64
- var input = _b.input;
65
- return __generator(this, function (_c) {
66
- switch (_c.label) {
67
- case 0:
68
- input.userInput, input.rules;
69
- return [4 /*yield*/, request({
70
- input: {
71
- url: "https://fc-typechat.ywwl.com/userInputToJson",
72
- method: "GET"
73
- }
74
- })];
75
- case 1:
76
- res = _c.sent();
77
- return [2 /*return*/, res];
78
- }
79
- });
80
- });
81
- }
82
-
83
61
  function getAugmentedNamespace(n) {
84
62
  if (n.__esModule) return n;
85
63
  var f = n.default;
@@ -8726,29 +8704,29 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8726
8704
 
8727
8705
  function request(_a) {
8728
8706
  return __awaiter(this, arguments, void 0, function (_b) {
8729
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8707
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8730
8708
  var input = _b.input;
8731
8709
  return __generator(this, function (_c) {
8732
8710
  switch (_c.label) {
8733
8711
  case 0:
8734
- method = input.method || 'GET';
8712
+ method = input.method || "GET";
8735
8713
  basePathMap = new Map([
8736
- ['prod', 'https://gateway.ywwl.com'],
8737
- ['test', 'https://test-gateway.ywwl.com'],
8738
- ['test2', 'https://test2-gateway.ywwl.com'],
8739
- ['dev', 'https://dev-gateway.ywwl.com'],
8714
+ ["prod", "https://gateway.ywwl.com"],
8715
+ ["test", "https://test-gateway.ywwl.com"],
8716
+ ["test2", "https://test2-gateway.ywwl.com"],
8717
+ ["dev", "https://dev-gateway.ywwl.com"],
8740
8718
  ]);
8741
8719
  getBasePath = function () {
8742
- var env = '{{env}}';
8720
+ var env = "{{env}}";
8743
8721
  return basePathMap.get(env);
8744
8722
  };
8745
8723
  isValidURL = function (url) {
8746
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8747
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8748
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8749
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
8750
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
8751
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8724
+ var pattern = new RegExp("^(https?:\\/\\/)?" + // protocol
8725
+ "((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
8726
+ "((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
8727
+ "(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
8728
+ "(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
8729
+ "(\\#[-a-z\\d_]*)?$", "i"); // fragment locator
8752
8730
  return !!pattern.test(url);
8753
8731
  };
8754
8732
  prefix = getBasePath();
@@ -8756,24 +8734,73 @@ function request(_a) {
8756
8734
  fetchOption = {
8757
8735
  method: method,
8758
8736
  headers: {
8759
- 'Content-type': 'application/json',
8760
- 'x-token': '{{token}}',
8737
+ "Content-type": "application/json",
8738
+ "x-token": "{{token}}",
8761
8739
  },
8762
8740
  };
8763
- if (method.toUpperCase() === 'POST') {
8741
+ if (method.toUpperCase() === "POST") {
8764
8742
  fetchOption.body = JSON.stringify(input.params);
8765
8743
  }
8766
- else if (method.toUpperCase() === 'GET') {
8744
+ else if (method.toUpperCase() === "GET") {
8767
8745
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8768
8746
  }
8769
8747
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8748
+ case 1:
8749
+ response = _c.sent();
8750
+ if (!response.ok) {
8751
+ message = "An error has occured: ".concat(response.status);
8752
+ return [2 /*return*/, { success: false, message: message }];
8753
+ }
8754
+ return [4 /*yield*/, response.json()];
8755
+ case 2:
8756
+ result = _c.sent();
8757
+ return [2 /*return*/, result];
8758
+ }
8759
+ });
8760
+ });
8761
+ }
8762
+
8763
+ function userInputToJson(_a) {
8764
+ return __awaiter(this, arguments, void 0, function (_b) {
8765
+ var res, result;
8766
+ var input = _b.input;
8767
+ return __generator(this, function (_c) {
8768
+ switch (_c.label) {
8769
+ case 0:
8770
+ console.log("input", input);
8771
+ return [4 /*yield*/, request({
8772
+ input: {
8773
+ url: "https://fc-typechat.ywwl.com/userInputToJson",
8774
+ method: "GET",
8775
+ params: input,
8776
+ },
8777
+ })];
8770
8778
  case 1:
8771
8779
  res = _c.sent();
8772
- return [2 /*return*/, res.json()];
8780
+ if (res.success) {
8781
+ result = res.data;
8782
+ return [2 /*return*/, result.success ? result.data : result];
8783
+ }
8784
+ else {
8785
+ return [2 /*return*/, res.success ? res.data : res];
8786
+ }
8773
8787
  }
8774
8788
  });
8775
8789
  });
8776
8790
  }
8777
8791
 
8778
- export { request, userInputToJson };
8792
+ // Ctrl-S保存代码
8793
+ function JSON2String(_a) {
8794
+ var input = _a.input;
8795
+ var data = input.data;
8796
+ try {
8797
+ var str = JSON.stringify(data);
8798
+ return '```json' + str + 'json```';
8799
+ }
8800
+ catch (error) {
8801
+ return '```json' + '{}' + 'json```';
8802
+ }
8803
+ }
8804
+
8805
+ export { JSON2String, request, userInputToJson };
8779
8806
  //# sourceMappingURL=ywfe-tools.esm.js.map