@ywfe/fe-tools 1.2.1-beta.28 → 1.2.1-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/index.ts +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/userInputToJson.d.ts +1 -1
- package/lib/ywfe-tools.cjs +24 -56
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +25 -56
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/package.json +2 -1
- package/request.ts +34 -40
- package/rollup.config.js +4 -1
- package/userInputToJson.ts +12 -19
- package/JSON2String.ts +0 -17
- package/lib/JSON2String.d.ts +0 -9
- package/lib/ywfe-tools.umd.js +0 -4
- package/lib/ywfe-tools.umd.js.map +0 -1
package/index.ts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/userInputToJson.d.ts
CHANGED
package/lib/ywfe-tools.cjs
CHANGED
@@ -8706,29 +8706,29 @@ 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,
|
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 ||
|
8714
|
+
method = input.method || 'GET';
|
8715
8715
|
basePathMap = new Map([
|
8716
|
-
[
|
8717
|
-
[
|
8718
|
-
[
|
8719
|
-
[
|
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 =
|
8722
|
+
var env = '{{env}}';
|
8723
8723
|
return basePathMap.get(env);
|
8724
8724
|
};
|
8725
8725
|
isValidURL = function (url) {
|
8726
|
-
var pattern = new RegExp(
|
8727
|
-
|
8728
|
-
|
8729
|
-
|
8730
|
-
|
8731
|
-
|
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%_.~+]*)*' + // port and path
|
8730
|
+
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
8731
|
+
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
|
8732
8732
|
return !!pattern.test(url);
|
8733
8733
|
};
|
8734
8734
|
prefix = getBasePath();
|
@@ -8736,27 +8736,20 @@ function request(_a) {
|
|
8736
8736
|
fetchOption = {
|
8737
8737
|
method: method,
|
8738
8738
|
headers: {
|
8739
|
-
|
8740
|
-
|
8739
|
+
'Content-type': 'application/json',
|
8740
|
+
'x-token': '{{token}}',
|
8741
8741
|
},
|
8742
8742
|
};
|
8743
|
-
if (method.toUpperCase() ===
|
8743
|
+
if (method.toUpperCase() === 'POST') {
|
8744
8744
|
fetchOption.body = JSON.stringify(input.params);
|
8745
8745
|
}
|
8746
|
-
else if (method.toUpperCase() ===
|
8746
|
+
else if (method.toUpperCase() === 'GET') {
|
8747
8747
|
requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
|
8748
8748
|
}
|
8749
8749
|
return [4 /*yield*/, fetch(requestUrl, fetchOption)];
|
8750
8750
|
case 1:
|
8751
|
-
|
8752
|
-
|
8753
|
-
message = "An error has occured: ".concat(response.status);
|
8754
|
-
return [2 /*return*/, { success: false, message: message }];
|
8755
|
-
}
|
8756
|
-
return [4 /*yield*/, response.json()];
|
8757
|
-
case 2:
|
8758
|
-
result = _c.sent();
|
8759
|
-
return [2 /*return*/, result];
|
8751
|
+
res = _c.sent();
|
8752
|
+
return [2 /*return*/, res.json()];
|
8760
8753
|
}
|
8761
8754
|
});
|
8762
8755
|
});
|
@@ -8764,50 +8757,25 @@ function request(_a) {
|
|
8764
8757
|
|
8765
8758
|
function userInputToJson(_a) {
|
8766
8759
|
return __awaiter(this, arguments, void 0, function (_b) {
|
8767
|
-
var res, result;
|
8768
8760
|
var input = _b.input;
|
8769
8761
|
return __generator(this, function (_c) {
|
8770
8762
|
switch (_c.label) {
|
8771
8763
|
case 0:
|
8772
|
-
|
8764
|
+
input.userInput, input.rules;
|
8773
8765
|
return [4 /*yield*/, request({
|
8774
8766
|
input: {
|
8775
8767
|
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
8776
|
-
method: "GET"
|
8777
|
-
|
8778
|
-
},
|
8768
|
+
method: "GET"
|
8769
|
+
}
|
8779
8770
|
})];
|
8780
8771
|
case 1:
|
8781
|
-
|
8782
|
-
|
8783
|
-
result = res.data;
|
8784
|
-
return [2 /*return*/, result.success ? result.data : result];
|
8785
|
-
}
|
8786
|
-
else {
|
8787
|
-
return [2 /*return*/, res.success ? res.data : res];
|
8788
|
-
}
|
8772
|
+
_c.sent();
|
8773
|
+
return [2 /*return*/, "2"];
|
8789
8774
|
}
|
8790
8775
|
});
|
8791
8776
|
});
|
8792
8777
|
}
|
8793
8778
|
|
8794
|
-
// Ctrl-S保存代码
|
8795
|
-
function JSON2String(_a) {
|
8796
|
-
var input = _a.input;
|
8797
|
-
var data = input.data;
|
8798
|
-
var result = { content: '' };
|
8799
|
-
try {
|
8800
|
-
var str = JSON.stringify(data);
|
8801
|
-
result.content = '```json' + str + 'json```';
|
8802
|
-
return result;
|
8803
|
-
}
|
8804
|
-
catch (error) {
|
8805
|
-
result.content = '```json' + '{}' + 'json```';
|
8806
|
-
return result;
|
8807
|
-
}
|
8808
|
-
}
|
8809
|
-
|
8810
|
-
exports.JSON2String = JSON2String;
|
8811
8779
|
exports.request = request;
|
8812
8780
|
exports.userInputToJson = userInputToJson;
|
8813
8781
|
//# sourceMappingURL=ywfe-tools.cjs.map
|