@ywfe/fe-tools 1.2.1-beta.9 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,35 +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, result;
64
- var input = _b.input;
65
- return __generator(this, function (_c) {
66
- switch (_c.label) {
67
- case 0:
68
- console.log("input", input);
69
- return [4 /*yield*/, request({
70
- input: {
71
- url: "https://fc-typechat.ywwl.com/userInputToJson",
72
- method: "GET",
73
- params: input,
74
- },
75
- })];
76
- case 1:
77
- res = _c.sent();
78
- if (res.success) {
79
- result = res.data;
80
- return [2 /*return*/, result.success ? result.data : result];
81
- }
82
- else {
83
- return [2 /*return*/, res.success ? res.data : res];
84
- }
85
- }
86
- });
87
- });
88
- }
89
-
90
61
  function getAugmentedNamespace(n) {
91
62
  if (n.__esModule) return n;
92
63
  var f = n.default;
@@ -8733,54 +8704,139 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8733
8704
 
8734
8705
  function request(_a) {
8735
8706
  return __awaiter(this, arguments, void 0, function (_b) {
8736
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8707
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8737
8708
  var input = _b.input;
8738
8709
  return __generator(this, function (_c) {
8739
8710
  switch (_c.label) {
8740
8711
  case 0:
8741
- method = input.method || 'GET';
8712
+ method = input.method || "GET";
8742
8713
  basePathMap = new Map([
8743
- ['prod', 'https://gateway.ywwl.com'],
8744
- ['test', 'https://test-gateway.ywwl.com'],
8745
- ['test2', 'https://test2-gateway.ywwl.com'],
8746
- ['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"],
8747
8718
  ]);
8748
8719
  getBasePath = function () {
8749
- var env = '{{env}}';
8720
+ var env = "{{env}}";
8750
8721
  return basePathMap.get(env);
8751
8722
  };
8752
8723
  isValidURL = function (url) {
8753
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8754
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8755
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8756
- '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
8757
- '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
8758
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8759
- return !!pattern.test(url);
8724
+ var regex = /^https?:\/\//;
8725
+ return regex.test(url);
8760
8726
  };
8761
8727
  prefix = getBasePath();
8762
8728
  requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8763
8729
  fetchOption = {
8764
8730
  method: method,
8765
8731
  headers: {
8766
- 'Content-type': 'application/json',
8767
- 'x-token': '{{token}}',
8732
+ "Content-type": "application/json",
8733
+ "x-token": "{{token}}",
8768
8734
  },
8769
8735
  };
8770
- if (method.toUpperCase() === 'POST') {
8736
+ if (method.toUpperCase() === "POST") {
8771
8737
  fetchOption.body = JSON.stringify(input.params);
8772
8738
  }
8773
- else if (method.toUpperCase() === 'GET') {
8739
+ else if (method.toUpperCase() === "GET") {
8774
8740
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8775
8741
  }
8776
8742
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8743
+ case 1:
8744
+ response = _c.sent();
8745
+ if (!response.ok) {
8746
+ message = "An error has occured: ".concat(response.status);
8747
+ console.log('req result', message);
8748
+ return [2 /*return*/, { success: false, message: message }];
8749
+ }
8750
+ return [4 /*yield*/, response.json()];
8751
+ case 2:
8752
+ result = _c.sent();
8753
+ console.log('req result', result);
8754
+ return [2 /*return*/, result];
8755
+ }
8756
+ });
8757
+ });
8758
+ }
8759
+
8760
+ function userInputToJson(_a) {
8761
+ return __awaiter(this, arguments, void 0, function (_b) {
8762
+ var res;
8763
+ var input = _b.input;
8764
+ return __generator(this, function (_c) {
8765
+ switch (_c.label) {
8766
+ case 0: return [4 /*yield*/, request({
8767
+ input: {
8768
+ url: "https://fc-typechat.ywwl.com/userInputToJson",
8769
+ method: "GET",
8770
+ params: input,
8771
+ },
8772
+ })];
8777
8773
  case 1:
8778
8774
  res = _c.sent();
8779
- return [2 /*return*/, res.json()];
8775
+ console.log('userINput1', res);
8776
+ return [2 /*return*/, res];
8777
+ }
8778
+ });
8779
+ });
8780
+ }
8781
+
8782
+ // Ctrl-S保存代码
8783
+ function JSON2String(_a) {
8784
+ var input = _a.input;
8785
+ var data = input.data;
8786
+ try {
8787
+ var str = JSON.stringify(data);
8788
+ return '```json' + str + 'json```';
8789
+ }
8790
+ catch (error) {
8791
+ return '```json' + '{}' + 'json```';
8792
+ }
8793
+ }
8794
+
8795
+ function gitlabGet(_a) {
8796
+ return __awaiter(this, arguments, void 0, function (_b) {
8797
+ var method, isValidURL, prefix, requestUrl, API_TOEKN, fetchOption, response, message, result;
8798
+ var input = _b.input;
8799
+ return __generator(this, function (_c) {
8800
+ switch (_c.label) {
8801
+ case 0:
8802
+ method = input.method || "GET";
8803
+ isValidURL = function (url) {
8804
+ var regex = /^https?:\/\//;
8805
+ return regex.test(url);
8806
+ };
8807
+ prefix = 'https://git.ywwl.com/api/v4';
8808
+ requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8809
+ API_TOEKN = 'PER-aCLxmYE54ByvzHrY';
8810
+ fetchOption = {
8811
+ method: method,
8812
+ headers: {
8813
+ "Content-type": "application/json",
8814
+ 'PRIVATE-TOKEN': API_TOEKN,
8815
+ },
8816
+ };
8817
+ if (method.toUpperCase() === "POST") {
8818
+ fetchOption.body = JSON.stringify(input.params);
8819
+ }
8820
+ else if (method.toUpperCase() === "GET") {
8821
+ requestUrl = requestUrl;
8822
+ }
8823
+ return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8824
+ case 1:
8825
+ response = _c.sent();
8826
+ if (!response.ok) {
8827
+ message = "An error has occured: ".concat(response.status);
8828
+ console.log('req result', message);
8829
+ return [2 /*return*/, { success: false, message: message }];
8830
+ }
8831
+ return [4 /*yield*/, response.json()];
8832
+ case 2:
8833
+ result = _c.sent();
8834
+ console.log('req result', result);
8835
+ return [2 /*return*/, result];
8780
8836
  }
8781
8837
  });
8782
8838
  });
8783
8839
  }
8784
8840
 
8785
- export { request, userInputToJson };
8841
+ export { JSON2String, gitlabGet, request, userInputToJson };
8786
8842
  //# sourceMappingURL=ywfe-tools.esm.js.map