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