@ywfe/fe-tools 1.2.1-beta.4 → 1.2.1-beta.40
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 +14 -0
- package/index.ts +1 -0
- package/lib/JSON2String.d.ts +7 -0
- package/lib/index.d.ts +1 -0
- package/lib/userInputToJson.d.ts +5 -1
- package/lib/ywfe-tools.cjs +52 -28
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +52 -29
- package/lib/ywfe-tools.esm.js.map +1 -1
- package/lib/ywfe-tools.umd.js +4 -0
- package/lib/ywfe-tools.umd.js.map +1 -0
- package/package.json +1 -2
- package/request.ts +36 -36
- package/rollup.config.js +1 -4
- package/tsconfig.json +4 -2
- package/userInputToJson.ts +15 -11
package/lib/ywfe-tools.esm.js
CHANGED
|
@@ -8704,50 +8704,54 @@ 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,
|
|
8707
|
+
var method, basePathMap, getBasePath, isValidURL, prefix, requestUrl, fetchOption, response, message, result;
|
|
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 ||
|
|
8712
|
+
method = input.method || "GET";
|
|
8713
8713
|
basePathMap = new Map([
|
|
8714
|
-
[
|
|
8715
|
-
[
|
|
8716
|
-
[
|
|
8717
|
-
[
|
|
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 =
|
|
8720
|
+
var env = "{{env}}";
|
|
8721
8721
|
return basePathMap.get(env);
|
|
8722
8722
|
};
|
|
8723
8723
|
isValidURL = function (url) {
|
|
8724
|
-
var
|
|
8725
|
-
|
|
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);
|
|
8724
|
+
var regex = /^https?:\/\//;
|
|
8725
|
+
return regex.test(url);
|
|
8731
8726
|
};
|
|
8732
8727
|
prefix = getBasePath();
|
|
8733
8728
|
requestUrl = isValidURL(input.url) ? input.url : "".concat(prefix).concat(input.url);
|
|
8734
8729
|
fetchOption = {
|
|
8735
8730
|
method: method,
|
|
8736
8731
|
headers: {
|
|
8737
|
-
|
|
8738
|
-
|
|
8732
|
+
"Content-type": "application/json",
|
|
8733
|
+
"x-token": "{{token}}",
|
|
8739
8734
|
},
|
|
8740
8735
|
};
|
|
8741
|
-
if (method.toUpperCase() ===
|
|
8736
|
+
if (method.toUpperCase() === "POST") {
|
|
8742
8737
|
fetchOption.body = JSON.stringify(input.params);
|
|
8743
8738
|
}
|
|
8744
|
-
else if (method.toUpperCase() ===
|
|
8739
|
+
else if (method.toUpperCase() === "GET") {
|
|
8745
8740
|
requestUrl = "".concat(requestUrl, "?").concat(ywfeUtils_esm.querystring.stringify(input.params || {}));
|
|
8746
8741
|
}
|
|
8747
8742
|
return [4 /*yield*/, fetch(requestUrl, fetchOption)];
|
|
8748
8743
|
case 1:
|
|
8749
|
-
|
|
8750
|
-
|
|
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];
|
|
8751
8755
|
}
|
|
8752
8756
|
});
|
|
8753
8757
|
});
|
|
@@ -8755,19 +8759,38 @@ function request(_a) {
|
|
|
8755
8759
|
|
|
8756
8760
|
function userInputToJson(_a) {
|
|
8757
8761
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
8762
|
+
var res;
|
|
8758
8763
|
var input = _b.input;
|
|
8759
8764
|
return __generator(this, function (_c) {
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
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
|
+
})];
|
|
8773
|
+
case 1:
|
|
8774
|
+
res = _c.sent();
|
|
8775
|
+
console.log('userINput1', res);
|
|
8776
|
+
return [2 /*return*/, res];
|
|
8777
|
+
}
|
|
8768
8778
|
});
|
|
8769
8779
|
});
|
|
8770
8780
|
}
|
|
8771
8781
|
|
|
8772
|
-
|
|
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
|
+
export { JSON2String, request, userInputToJson };
|
|
8773
8796
|
//# sourceMappingURL=ywfe-tools.esm.js.map
|