@ywfe/fe-tools 1.2.1-beta.38 → 1.2.1-beta.4

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.
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,9 +4,5 @@ interface userInput {
4
4
  }
5
5
  declare function userInputToJson({ input }: {
6
6
  input: userInput;
7
- }): Promise<{
8
- message: string;
9
- success: boolean;
10
- data: any;
11
- }>;
7
+ }): Promise<string>;
12
8
  export default userInputToJson;
@@ -8706,53 +8706,50 @@ 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 regex = /^https?:\/\//;
8727
- return regex.test(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%_.&#126;+=-]*)?' + // query string
8731
+ '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8732
+ return !!pattern.test(url);
8728
8733
  };
8729
8734
  prefix = getBasePath();
8730
8735
  requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8731
- console.log('requestUrl', requestUrl, isValidURL(input.url));
8732
8736
  fetchOption = {
8733
8737
  method: method,
8734
8738
  headers: {
8735
- "Content-type": "application/json",
8736
- "x-token": "{{token}}",
8739
+ 'Content-type': 'application/json',
8740
+ 'x-token': '{{token}}',
8737
8741
  },
8738
8742
  };
8739
- if (method.toUpperCase() === "POST") {
8743
+ if (method.toUpperCase() === 'POST') {
8740
8744
  fetchOption.body = JSON.stringify(input.params);
8741
8745
  }
8742
- else if (method.toUpperCase() === "GET") {
8746
+ else if (method.toUpperCase() === 'GET') {
8743
8747
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8744
8748
  }
8745
8749
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8746
8750
  case 1:
8747
- response = _c.sent();
8748
- if (!response.ok) {
8749
- message = "An error has occured: ".concat(response.status);
8750
- return [2 /*return*/, { success: false, message: message }];
8751
- }
8752
- return [4 /*yield*/, response.json()];
8753
- case 2:
8754
- result = _c.sent();
8755
- return [2 /*return*/, result];
8751
+ res = _c.sent();
8752
+ return [2 /*return*/, res.json()];
8756
8753
  }
8757
8754
  });
8758
8755
  });
@@ -8760,43 +8757,20 @@ function request(_a) {
8760
8757
 
8761
8758
  function userInputToJson(_a) {
8762
8759
  return __awaiter(this, arguments, void 0, function (_b) {
8763
- var res;
8764
8760
  var input = _b.input;
8765
8761
  return __generator(this, function (_c) {
8766
- switch (_c.label) {
8767
- case 0: return [4 /*yield*/, request({
8768
- input: {
8769
- url: "https://fc-typechat.ywwl.com/userInputToJson",
8770
- method: "GET",
8771
- params: input,
8772
- },
8773
- })];
8774
- case 1:
8775
- res = _c.sent();
8776
- console.log('userINput1', res);
8777
- return [2 /*return*/, res];
8778
- }
8762
+ input.userInput, input.rules;
8763
+ //const res = await fetools.request({
8764
+ //input:{
8765
+ //url:"https://fc-typechat.ywwl.com/userInputToJson",
8766
+ //method:"GET"
8767
+ //}
8768
+ //})
8769
+ return [2 /*return*/, "2"];
8779
8770
  });
8780
8771
  });
8781
8772
  }
8782
8773
 
8783
- // Ctrl-S保存代码
8784
- function JSON2String(_a) {
8785
- var input = _a.input;
8786
- var data = input.data;
8787
- var result = { content: '' };
8788
- try {
8789
- var str = JSON.stringify(data);
8790
- result.content = '```json' + str + 'json```';
8791
- return result;
8792
- }
8793
- catch (error) {
8794
- result.content = '```json' + '{}' + 'json```';
8795
- return result;
8796
- }
8797
- }
8798
-
8799
- exports.JSON2String = JSON2String;
8800
8774
  exports.request = request;
8801
8775
  exports.userInputToJson = userInputToJson;
8802
8776
  //# sourceMappingURL=ywfe-tools.cjs.map