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

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/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/gitlabGet.ts ADDED
@@ -0,0 +1,39 @@
1
+ // Ctrl-S保存代码
2
+ interface RequestOptions {
3
+ url: string;
4
+ method?: string;
5
+ params?: any;
6
+ }
7
+ async function gitlabGet({ input }: { input: RequestOptions }) {
8
+ const method = input.method || "GET";
9
+ const isValidURL = (url: string) => {
10
+ const regex = /^https?:\/\//;
11
+ return regex.test(url);
12
+ };
13
+ const prefix = 'https://git.ywwl.com/api/v4';
14
+ let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
15
+ const API_TOEKN = 'PER-aCLxmYE54ByvzHrY';
16
+ const fetchOption: { [key: string]: any } = {
17
+ method: method,
18
+ headers: {
19
+ "Content-type": "application/json",
20
+ 'PRIVATE-TOKEN': API_TOEKN,
21
+ },
22
+ };
23
+ if (method.toUpperCase() === "POST") {
24
+ fetchOption.body = JSON.stringify(input.params);
25
+ } else if (method.toUpperCase() === "GET") {
26
+ requestUrl = requestUrl;
27
+ }
28
+ const response = await fetch(requestUrl, fetchOption);
29
+ if (!response.ok) {
30
+ const message = `An error has occured: ${response.status}`;
31
+ console.log('req result', message);
32
+ return { success: false, message };
33
+ }
34
+ const result = await response.json();
35
+ console.log('req result', result);
36
+ return result;
37
+ }
38
+
39
+ export default gitlabGet
package/index.ts CHANGED
@@ -1,2 +1,4 @@
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'
4
+ export { default as gitlabGet } from './gitlabGet'
@@ -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;
@@ -0,0 +1,9 @@
1
+ interface RequestOptions {
2
+ url: string;
3
+ method?: string;
4
+ params?: any;
5
+ }
6
+ declare function gitlabGet({ input }: {
7
+ input: RequestOptions;
8
+ }): Promise<any>;
9
+ export default gitlabGet;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,4 @@
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';
4
+ export { default as gitlabGet } from './gitlabGet';
@@ -4,5 +4,9 @@ interface userInput {
4
4
  }
5
5
  declare function userInputToJson({ input }: {
6
6
  input: userInput;
7
- }): Promise<any>;
7
+ }): Promise<{
8
+ message: string;
9
+ success: boolean;
10
+ data: any;
11
+ }>;
8
12
  export default userInputToJson;
@@ -60,35 +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, result;
66
- var input = _b.input;
67
- return __generator(this, function (_c) {
68
- switch (_c.label) {
69
- case 0:
70
- console.log("input", input);
71
- return [4 /*yield*/, request({
72
- input: {
73
- url: "https://fc-typechat.ywwl.com/userInputToJson",
74
- method: "GET",
75
- params: input,
76
- },
77
- })];
78
- case 1:
79
- res = _c.sent();
80
- if (res.success) {
81
- result = res.data;
82
- return [2 /*return*/, result.success ? result.data : result];
83
- }
84
- else {
85
- return [2 /*return*/, res.success ? res.data : res];
86
- }
87
- }
88
- });
89
- });
90
- }
91
-
92
63
  function getAugmentedNamespace(n) {
93
64
  if (n.__esModule) return n;
94
65
  var f = n.default;
@@ -8735,55 +8706,142 @@ var require$$1 = /*@__PURE__*/getAugmentedNamespace(empty$1);
8735
8706
 
8736
8707
  function request(_a) {
8737
8708
  return __awaiter(this, arguments, void 0, function (_b) {
8738
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8709
+ var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
8739
8710
  var input = _b.input;
8740
8711
  return __generator(this, function (_c) {
8741
8712
  switch (_c.label) {
8742
8713
  case 0:
8743
- method = input.method || 'GET';
8714
+ method = input.method || "GET";
8744
8715
  basePathMap = new Map([
8745
- ['prod', 'https://gateway.ywwl.com'],
8746
- ['test', 'https://test-gateway.ywwl.com'],
8747
- ['test2', 'https://test2-gateway.ywwl.com'],
8748
- ['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"],
8749
8720
  ]);
8750
8721
  getBasePath = function () {
8751
- var env = '{{env}}';
8722
+ var env = "{{env}}";
8752
8723
  return basePathMap.get(env);
8753
8724
  };
8754
8725
  isValidURL = function (url) {
8755
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8756
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8757
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8758
- '(\\:\\d+)?(\\/[-a-z\\d%_.&#126;+]*)*' + // port and path
8759
- '(\\?[;&a-z\\d%_.&#126;+=-]*)?' + // query string
8760
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8761
- return !!pattern.test(url);
8726
+ var regex = /^https?:\/\//;
8727
+ return regex.test(url);
8762
8728
  };
8763
8729
  prefix = getBasePath();
8764
8730
  requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8765
8731
  fetchOption = {
8766
8732
  method: method,
8767
8733
  headers: {
8768
- 'Content-type': 'application/json',
8769
- 'x-token': '{{token}}',
8734
+ "Content-type": "application/json",
8735
+ "x-token": "{{token}}",
8770
8736
  },
8771
8737
  };
8772
- if (method.toUpperCase() === 'POST') {
8738
+ if (method.toUpperCase() === "POST") {
8773
8739
  fetchOption.body = JSON.stringify(input.params);
8774
8740
  }
8775
- else if (method.toUpperCase() === 'GET') {
8741
+ else if (method.toUpperCase() === "GET") {
8776
8742
  requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8777
8743
  }
8778
8744
  return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8745
+ case 1:
8746
+ response = _c.sent();
8747
+ if (!response.ok) {
8748
+ message = "An error has occured: ".concat(response.status);
8749
+ console.log('req result', message);
8750
+ return [2 /*return*/, { success: false, message: message }];
8751
+ }
8752
+ return [4 /*yield*/, response.json()];
8753
+ case 2:
8754
+ result = _c.sent();
8755
+ console.log('req result', result);
8756
+ return [2 /*return*/, result];
8757
+ }
8758
+ });
8759
+ });
8760
+ }
8761
+
8762
+ function userInputToJson(_a) {
8763
+ return __awaiter(this, arguments, void 0, function (_b) {
8764
+ var res;
8765
+ var input = _b.input;
8766
+ return __generator(this, function (_c) {
8767
+ switch (_c.label) {
8768
+ case 0: return [4 /*yield*/, request({
8769
+ input: {
8770
+ url: "https://fc-typechat.ywwl.com/userInputToJson",
8771
+ method: "GET",
8772
+ params: input,
8773
+ },
8774
+ })];
8779
8775
  case 1:
8780
8776
  res = _c.sent();
8781
- return [2 /*return*/, res.json()];
8777
+ console.log('userINput1', res);
8778
+ return [2 /*return*/, res];
8779
+ }
8780
+ });
8781
+ });
8782
+ }
8783
+
8784
+ // Ctrl-S保存代码
8785
+ function JSON2String(_a) {
8786
+ var input = _a.input;
8787
+ var data = input.data;
8788
+ try {
8789
+ var str = JSON.stringify(data);
8790
+ return '```json' + str + 'json```';
8791
+ }
8792
+ catch (error) {
8793
+ return '```json' + '{}' + 'json```';
8794
+ }
8795
+ }
8796
+
8797
+ function gitlabGet(_a) {
8798
+ return __awaiter(this, arguments, void 0, function (_b) {
8799
+ var method, isValidURL, prefix, requestUrl, API_TOEKN, fetchOption, response, message, result;
8800
+ var input = _b.input;
8801
+ return __generator(this, function (_c) {
8802
+ switch (_c.label) {
8803
+ case 0:
8804
+ method = input.method || "GET";
8805
+ isValidURL = function (url) {
8806
+ var regex = /^https?:\/\//;
8807
+ return regex.test(url);
8808
+ };
8809
+ prefix = 'https://git.ywwl.com/api/v4';
8810
+ requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8811
+ API_TOEKN = 'PER-aCLxmYE54ByvzHrY';
8812
+ fetchOption = {
8813
+ method: method,
8814
+ headers: {
8815
+ "Content-type": "application/json",
8816
+ 'PRIVATE-TOKEN': API_TOEKN,
8817
+ },
8818
+ };
8819
+ if (method.toUpperCase() === "POST") {
8820
+ fetchOption.body = JSON.stringify(input.params);
8821
+ }
8822
+ else if (method.toUpperCase() === "GET") {
8823
+ requestUrl = requestUrl;
8824
+ }
8825
+ return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8826
+ case 1:
8827
+ response = _c.sent();
8828
+ if (!response.ok) {
8829
+ message = "An error has occured: ".concat(response.status);
8830
+ console.log('req result', message);
8831
+ return [2 /*return*/, { success: false, message: message }];
8832
+ }
8833
+ return [4 /*yield*/, response.json()];
8834
+ case 2:
8835
+ result = _c.sent();
8836
+ console.log('req result', result);
8837
+ return [2 /*return*/, result];
8782
8838
  }
8783
8839
  });
8784
8840
  });
8785
8841
  }
8786
8842
 
8843
+ exports.JSON2String = JSON2String;
8844
+ exports.gitlabGet = gitlabGet;
8787
8845
  exports.request = request;
8788
8846
  exports.userInputToJson = userInputToJson;
8789
8847
  //# sourceMappingURL=ywfe-tools.cjs.map