@ywfe/fe-tools 1.0.2-beta.3 → 1.0.2-beta.5

Sign up to get free protection for your applications and to get access to all the features.
package/JSON2String.ts ADDED
@@ -0,0 +1,13 @@
1
+ interface userInput {
2
+ data?: object;
3
+ }
4
+ function JSON2String({ input }) {
5
+ const { data = {} } = input;
6
+ try {
7
+ return "```json" + JSON.stringify(data) + "json```";
8
+ } catch (error) {
9
+ return "```json" + JSON.stringify({}) + "json```";
10
+ }
11
+ }
12
+
13
+ export default JSON2String
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as request } from './request'
2
+ export { default as userInputToJson } from './userInputToJson'
3
+ export { default as JSON2String } from './JSON2String'
@@ -0,0 +1,5 @@
1
+ declare function JSON2String({ input }: {
2
+ input: any;
3
+ }): string;
4
+ export default JSON2String;
5
+ //# sourceMappingURL=JSON2String.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSON2String.d.ts","sourceRoot":"","sources":["../JSON2String.ts"],"names":[],"mappings":"AAGA,iBAAS,WAAW,CAAC,EAAE,KAAK,EAAE;;CAAA,UAO7B;AAED,eAAe,WAAW,CAAA"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as request } from './request';
2
+ export { default as userInputToJson } from './userInputToJson';
3
+ export { default as JSON2String } from './JSON2String';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,10 @@
1
+ interface RequestOptions {
2
+ url: string;
3
+ method?: string;
4
+ params?: any;
5
+ }
6
+ declare function request({ input }: {
7
+ input: RequestOptions;
8
+ }): Promise<any>;
9
+ export default request;
10
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../request.ts"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,GAAG,EAAC,MAAM,CAAC;IACX,MAAM,CAAC,EAAC,MAAM,CAAC;IACf,MAAM,CAAC,EAAC,GAAG,CAAA;CACZ;AACD,iBAAe,OAAO,CAAC,EAAC,KAAK,EAAC,EAAC;IAAC,KAAK,EAAC,cAAc,CAAA;CAAC,gBAwCpD;AACD,eAAe,OAAO,CAAA"}
@@ -0,0 +1,9 @@
1
+ interface userInput {
2
+ userInput?: string;
3
+ rules?: string;
4
+ }
5
+ declare function userInputToJson({ input }: {
6
+ input: userInput;
7
+ }): Promise<any>;
8
+ export default userInputToJson;
9
+ //# sourceMappingURL=userInputToJson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userInputToJson.d.ts","sourceRoot":"","sources":["../userInputToJson.ts"],"names":[],"mappings":"AACA,UAAU,SAAS;IACjB,SAAS,CAAC,EAAC,MAAM,CAAC;IAClB,KAAK,CAAC,EAAC,MAAM,CAAC;CACf;AACD,iBAAe,eAAe,CAAC,EAAC,KAAK,EAAC,EAAC;IAAC,KAAK,EAAC,SAAS,CAAA;CAAC,gBAWvD;AACD,eAAe,eAAe,CAAA"}
@@ -1,141 +1,5 @@
1
1
  import require$$1 from 'fs';
2
2
 
3
- /******************************************************************************
4
- Copyright (c) Microsoft Corporation.
5
-
6
- Permission to use, copy, modify, and/or distribute this software for any
7
- purpose with or without fee is hereby granted.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- PERFORMANCE OF THIS SOFTWARE.
16
- ***************************************************************************** */
17
- /* global Reflect, Promise, SuppressedError, Symbol */
18
-
19
- function __awaiter(thisArg, _arguments, P, generator) {
20
- function adopt(value) {
21
- return value instanceof P ? value : new P(function (resolve) {
22
- resolve(value);
23
- });
24
- }
25
- return new (P || (P = Promise))(function (resolve, reject) {
26
- function fulfilled(value) {
27
- try {
28
- step(generator.next(value));
29
- } catch (e) {
30
- reject(e);
31
- }
32
- }
33
- function rejected(value) {
34
- try {
35
- step(generator["throw"](value));
36
- } catch (e) {
37
- reject(e);
38
- }
39
- }
40
- function step(result) {
41
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
42
- }
43
- step((generator = generator.apply(thisArg, _arguments || [])).next());
44
- });
45
- }
46
- function __generator(thisArg, body) {
47
- var _ = {
48
- label: 0,
49
- sent: function () {
50
- if (t[0] & 1) throw t[1];
51
- return t[1];
52
- },
53
- trys: [],
54
- ops: []
55
- },
56
- f,
57
- y,
58
- t,
59
- g;
60
- return g = {
61
- next: verb(0),
62
- "throw": verb(1),
63
- "return": verb(2)
64
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
65
- return this;
66
- }), g;
67
- function verb(n) {
68
- return function (v) {
69
- return step([n, v]);
70
- };
71
- }
72
- function step(op) {
73
- if (f) throw new TypeError("Generator is already executing.");
74
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
75
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
76
- if (y = 0, t) op = [op[0] & 2, t.value];
77
- switch (op[0]) {
78
- case 0:
79
- case 1:
80
- t = op;
81
- break;
82
- case 4:
83
- _.label++;
84
- return {
85
- value: op[1],
86
- done: false
87
- };
88
- case 5:
89
- _.label++;
90
- y = op[1];
91
- op = [0];
92
- continue;
93
- case 7:
94
- op = _.ops.pop();
95
- _.trys.pop();
96
- continue;
97
- default:
98
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
99
- _ = 0;
100
- continue;
101
- }
102
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
103
- _.label = op[1];
104
- break;
105
- }
106
- if (op[0] === 6 && _.label < t[1]) {
107
- _.label = t[1];
108
- t = op;
109
- break;
110
- }
111
- if (t && _.label < t[2]) {
112
- _.label = t[2];
113
- _.ops.push(op);
114
- break;
115
- }
116
- if (t[2]) _.ops.pop();
117
- _.trys.pop();
118
- continue;
119
- }
120
- op = body.call(thisArg, _);
121
- } catch (e) {
122
- op = [6, e];
123
- y = 0;
124
- } finally {
125
- f = t = 0;
126
- }
127
- if (op[0] & 5) throw op[1];
128
- return {
129
- value: op[0] ? op[1] : void 0,
130
- done: true
131
- };
132
- }
133
- }
134
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
135
- var e = new Error(message);
136
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
137
- };
138
-
139
3
  var ywfeUtils_esm = {};
140
4
 
141
5
  (function (exports) {
@@ -8746,83 +8610,61 @@ var ywfeUtils_esm = {};
8746
8610
 
8747
8611
  } (ywfeUtils_esm));
8748
8612
 
8749
- function request(_a) {
8750
- return __awaiter(this, arguments, void 0, function (_b) {
8751
- var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, res;
8752
- var input = _b.input;
8753
- return __generator(this, function (_c) {
8754
- switch (_c.label) {
8755
- case 0:
8756
- method = input.method || 'GET';
8757
- basePathMap = new Map([
8758
- ['prod', 'https://gateway.ywwl.com'],
8759
- ['test', 'https://test-gateway.ywwl.com'],
8760
- ['test2', 'https://test2-gateway.ywwl.com'],
8761
- ['dev', 'https://dev-gateway.ywwl.com'],
8762
- ]);
8763
- getBasePath = function () {
8764
- var env = '{{env}}';
8765
- return basePathMap.get(env);
8766
- };
8767
- isValidURL = function (url) {
8768
- var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8769
- '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8770
- '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8771
- '(\\:\\d+)?(\\/[-a-z\\d%_.&#126;+]*)*' + // port and path
8772
- '(\\?[;&a-z\\d%_.&#126;+=-]*)?' + // query string
8773
- '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8774
- return !!pattern.test(url);
8775
- };
8776
- prefix = getBasePath();
8777
- requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
8778
- fetchOption = {
8779
- method: method,
8780
- headers: {
8781
- 'Content-type': 'application/json',
8782
- 'x-token': '{{token}}',
8783
- },
8784
- };
8785
- if (method.toUpperCase() === 'POST') {
8786
- fetchOption.body = JSON.stringify(input.params);
8787
- }
8788
- else if (method.toUpperCase() === 'GET') {
8789
- requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
8790
- }
8791
- return [4 /*yield*/, fetch(requestUrl, fetchOption)];
8792
- case 1:
8793
- res = _c.sent();
8794
- return [2 /*return*/, res.json()];
8795
- }
8796
- });
8797
- });
8613
+ // Ctrl-S保存代码
8614
+ async function request({ input }) {
8615
+ const method = input.method || 'GET';
8616
+ const basePathMap = new Map([
8617
+ ['prod', 'https://gateway.ywwl.com'],
8618
+ ['test', 'https://test-gateway.ywwl.com'],
8619
+ ['test2', 'https://test2-gateway.ywwl.com'],
8620
+ ['dev', 'https://dev-gateway.ywwl.com'],
8621
+ ]);
8622
+ const getBasePath = () => {
8623
+ const env = '{{env}}';
8624
+ return basePathMap.get(env);
8625
+ };
8626
+ const isValidURL = (url) => {
8627
+ var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
8628
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
8629
+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
8630
+ '(\\:\\d+)?(\\/[-a-z\\d%_.&#126;+]*)*' + // port and path
8631
+ '(\\?[;&a-z\\d%_.&#126;+=-]*)?' + // query string
8632
+ '(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
8633
+ return !!pattern.test(url);
8634
+ };
8635
+ const prefix = getBasePath();
8636
+ let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
8637
+ const fetchOption = {
8638
+ method: method,
8639
+ headers: {
8640
+ 'Content-type': 'application/json',
8641
+ 'x-token': '{{token}}',
8642
+ },
8643
+ };
8644
+ if (method.toUpperCase() === 'POST') {
8645
+ fetchOption.body = JSON.stringify(input.params);
8646
+ }
8647
+ else if (method.toUpperCase() === 'GET') {
8648
+ requestUrl = `${requestUrl}?${ywfeUtils_esm.querystring.stringify(input.params || {})}`;
8649
+ }
8650
+ const res = await fetch(requestUrl, fetchOption);
8651
+ return res.json();
8798
8652
  }
8799
8653
 
8800
- function userInputToJson(_a) {
8801
- return __awaiter(this, arguments, void 0, function (_b) {
8802
- var res;
8803
- var input = _b.input;
8804
- return __generator(this, function (_c) {
8805
- switch (_c.label) {
8806
- case 0:
8807
- input.userInput, input.rules;
8808
- console.log('cesh');
8809
- return [4 /*yield*/, feTools.request({
8810
- input: {
8811
- url: "https://fc-typechat.ywwl.com/userInputToJson",
8812
- method: "GET"
8813
- }
8814
- })];
8815
- case 1:
8816
- res = _c.sent();
8817
- return [2 /*return*/, res];
8818
- }
8819
- });
8654
+ async function userInputToJson({ input }) {
8655
+ console.log('cesh');
8656
+ //@ts-ignore
8657
+ const res = await feTools.request({
8658
+ input: {
8659
+ url: "https://fc-typechat.ywwl.com/userInputToJson",
8660
+ method: "GET"
8661
+ }
8820
8662
  });
8663
+ return res;
8821
8664
  }
8822
8665
 
8823
- function JSON2String(_a) {
8824
- var input = _a.input;
8825
- var _b = input.data, data = _b === void 0 ? {} : _b;
8666
+ function JSON2String({ input }) {
8667
+ const { data = {} } = input;
8826
8668
  try {
8827
8669
  return "```json" + JSON.stringify(data) + "json```";
8828
8670
  }
@@ -8832,4 +8674,4 @@ function JSON2String(_a) {
8832
8674
  }
8833
8675
 
8834
8676
  export { JSON2String, request, userInputToJson };
8835
- //# sourceMappingURL=bundle.js.map
8677
+ //# sourceMappingURL=ywfe-tools.esm.js.map