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

Sign up to get free protection for your applications and to get access to all the features.
@@ -8704,53 +8704,50 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8704
8704
 
8705
8705
  function request(_a) {
8706
8706
  return __awaiter(this, arguments, void 0, function (_b) {
8707
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8707
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8708
8708
  var input = _b.input;
8709
8709
  return __generator(this, function (_c) {
8710
8710
  switch (_c.label) {
8711
8711
  case 0:
8712
- method = input.method || "GET";
8712
+ method = input.method || 'GET';
8713
8713
  basePathMap = new Map([
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"],
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'],
8718
8718
  ]);
8719
8719
  getBasePath = function () {
8720
- var env = "{{env}}";
8720
+ var env = '{{env}}';
8721
8721
  return basePathMap.get(env);
8722
8722
  };
8723
8723
  isValidURL = function (url) {
8724
- var regex = /^https?:\/\//;
8725
- return regex.test(url);
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
8730
+ return !!pattern.test(url);
8726
8731
  };
8727
8732
  prefix = getBasePath();
8728
8733
  requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8729
- console.log('requestUrl', requestUrl, isValidURL(input.url));
8730
8734
  fetchOption = {
8731
8735
  method: method,
8732
8736
  headers: {
8733
- "Content-type": "application/json",
8734
- "x-token": "{{token}}",
8737
+ 'Content-type': 'application/json',
8738
+ 'x-token': '{{token}}',
8735
8739
  },
8736
8740
  };
8737
- if (method.toUpperCase() === "POST") {
8741
+ if (method.toUpperCase() === 'POST') {
8738
8742
  fetchOption.body = JSON.stringify(input.params);
8739
8743
  }
8740
- else if (method.toUpperCase() === "GET") {
8744
+ else if (method.toUpperCase() === 'GET') {
8741
8745
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8742
8746
  }
8743
8747
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8744
8748
  case 1:
8745
- response = _c.sent();
8746
- if (!response.ok) {
8747
- message = "An error has occured: ".concat(response.status);
8748
- return [2 /*return*/, { success: false, message: message }];
8749
- }
8750
- return [4 /*yield*/, response.json()];
8751
- case 2:
8752
- result = _c.sent();
8753
- return [2 /*return*/, result];
8749
+ res = _c.sent();
8750
+ return [2 /*return*/, res.json()];
8754
8751
  }
8755
8752
  });
8756
8753
  });
@@ -8758,41 +8755,19 @@ function request(_a) {
8758
8755
 
8759
8756
  function userInputToJson(_a) {
8760
8757
  return __awaiter(this, arguments, void 0, function (_b) {
8761
- var res;
8762
8758
  var input = _b.input;
8763
8759
  return __generator(this, function (_c) {
8764
- switch (_c.label) {
8765
- case 0: return [4 /*yield*/, request({
8766
- input: {
8767
- url: "https://fc-typechat.ywwl.com/userInputToJson",
8768
- method: "GET",
8769
- params: input,
8770
- },
8771
- })];
8772
- case 1:
8773
- res = _c.sent();
8774
- console.log('userINput1', res);
8775
- return [2 /*return*/, res];
8776
- }
8760
+ input.userInput, input.rules;
8761
+ //const res = await fetools.request({
8762
+ //input:{
8763
+ //url:"https://fc-typechat.ywwl.com/userInputToJson",
8764
+ //method:"GET"
8765
+ //}
8766
+ //})
8767
+ return [2 /*return*/, "2"];
8777
8768
  });
8778
8769
  });
8779
8770
  }
8780
8771
 
8781
- // Ctrl-S保存代码
8782
- function JSON2String(_a) {
8783
- var input = _a.input;
8784
- var data = input.data;
8785
- var result = { content: '' };
8786
- try {
8787
- var str = JSON.stringify(data);
8788
- result.content = '```json' + str + 'json```';
8789
- return result;
8790
- }
8791
- catch (error) {
8792
- result.content = '```json' + '{}' + 'json```';
8793
- return result;
8794
- }
8795
- }
8796
-
8797
- export { JSON2String, request, userInputToJson };
8772
+ export { request, userInputToJson };
8798
8773
  //# sourceMappingURL=ywfe-tools.esm.js.map