@ywfe/fe-tools 1.2.1-beta.29 → 1.2.1-beta.3

Sign up to get free protection for your applications and to get access to all the features.
package/index.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default as request } from './request'
2
2
  export { default as userInputToJson } from './userInputToJson'
3
- export { default as JSON2String } from './JSON2String'
package/lib/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { default as request } from './request';
2
2
  export { default as userInputToJson } from './userInputToJson';
3
- export { default as JSON2String } from './JSON2String';
@@ -4,5 +4,5 @@ interface userInput {
4
4
  }
5
5
  declare function userInputToJson({ input }: {
6
6
  input: userInput;
7
- }): Promise<any>;
7
+ }): Promise<string>;
8
8
  export default userInputToJson;
@@ -8706,28 +8706,29 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8706
8706
 
8707
8707
  function request(_a) {
8708
8708
  return __awaiter(this, arguments, void 0, function (_b) {
8709
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8709
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8710
8710
  var input = _b.input;
8711
8711
  return __generator(this, function (_c) {
8712
8712
  switch (_c.label) {
8713
8713
  case 0:
8714
- method = input.method || "GET";
8714
+ method = input.method || 'GET';
8715
8715
  basePathMap = new Map([
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"],
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'],
8720
8720
  ]);
8721
8721
  getBasePath = function () {
8722
- var env = "{{env}}";
8722
+ var env = '{{env}}';
8723
8723
  return basePathMap.get(env);
8724
8724
  };
8725
8725
  isValidURL = function (url) {
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%_.&#126;+]*)*" + // port and path
8730
- "(\#[-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%_.&#126;+]*)*' + // port and path
8730
+ '(\\?[;&a-z\\d%_.&#126;+=-]*)?' + // query string
8731
+ '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8731
8732
  return !!pattern.test(url);
8732
8733
  };
8733
8734
  prefix = getBasePath();
@@ -8735,27 +8736,20 @@ function request(_a) {
8735
8736
  fetchOption = {
8736
8737
  method: method,
8737
8738
  headers: {
8738
- "Content-type": "application/json",
8739
- "x-token": "{{token}}",
8739
+ 'Content-type': 'application/json',
8740
+ 'x-token': '{{token}}',
8740
8741
  },
8741
8742
  };
8742
- if (method.toUpperCase() === "POST") {
8743
+ if (method.toUpperCase() === 'POST') {
8743
8744
  fetchOption.body = JSON.stringify(input.params);
8744
8745
  }
8745
- else if (method.toUpperCase() === "GET") {
8746
+ else if (method.toUpperCase() === 'GET') {
8746
8747
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8747
8748
  }
8748
8749
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8749
8750
  case 1:
8750
- response = _c.sent();
8751
- if (!response.ok) {
8752
- message = "An error has occured: ".concat(response.status);
8753
- return [2 /*return*/, { success: false, message: message }];
8754
- }
8755
- return [4 /*yield*/, response.json()];
8756
- case 2:
8757
- result = _c.sent();
8758
- return [2 /*return*/, result];
8751
+ res = _c.sent();
8752
+ return [2 /*return*/, res.json()];
8759
8753
  }
8760
8754
  });
8761
8755
  });
@@ -8763,50 +8757,25 @@ function request(_a) {
8763
8757
 
8764
8758
  function userInputToJson(_a) {
8765
8759
  return __awaiter(this, arguments, void 0, function (_b) {
8766
- var res, result;
8767
8760
  var input = _b.input;
8768
8761
  return __generator(this, function (_c) {
8769
8762
  switch (_c.label) {
8770
8763
  case 0:
8771
- console.log("input", input);
8764
+ input.userInput, input.rules;
8772
8765
  return [4 /*yield*/, request({
8773
8766
  input: {
8774
8767
  url: "https://fc-typechat.ywwl.com/userInputToJson",
8775
- method: "GET",
8776
- params: input,
8777
- },
8768
+ method: "GET"
8769
+ }
8778
8770
  })];
8779
8771
  case 1:
8780
- res = _c.sent();
8781
- if (res.success) {
8782
- result = res.data;
8783
- return [2 /*return*/, result.success ? result.data : result];
8784
- }
8785
- else {
8786
- return [2 /*return*/, res.success ? res.data : res];
8787
- }
8772
+ _c.sent();
8773
+ return [2 /*return*/, "2"];
8788
8774
  }
8789
8775
  });
8790
8776
  });
8791
8777
  }
8792
8778
 
8793
- // Ctrl-S保存代码
8794
- function JSON2String(_a) {
8795
- var input = _a.input;
8796
- var data = input.data;
8797
- var result = { content: '' };
8798
- try {
8799
- var str = JSON.stringify(data);
8800
- result.content = '```json' + str + 'json```';
8801
- return result;
8802
- }
8803
- catch (error) {
8804
- result.content = '```json' + '{}' + 'json```';
8805
- return result;
8806
- }
8807
- }
8808
-
8809
- exports.JSON2String = JSON2String;
8810
8779
  exports.request = request;
8811
8780
  exports.userInputToJson = userInputToJson;
8812
8781
  //# sourceMappingURL=ywfe-tools.cjs.map