@ywfe/fe-tools 1.2.1-beta.36 → 1.2.1-beta.37
Sign up to get free protection for your applications and to get access to all the features.
- package/JSON2String.ts +17 -0
- package/index.ts +2 -1
- package/lib/JSON2String.d.ts +9 -0
- package/lib/index.d.ts +2 -1
- package/lib/request.d.ts +9 -0
- package/lib/userInputToJson.d.ts +5 -1
- package/lib/ywfe-tools.cjs +8728 -10
- package/lib/ywfe-tools.cjs.map +1 -1
- package/lib/ywfe-tools.esm.js +8727 -10
- 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 -1
- package/request.ts +48 -0
- package/userInputToJson.ts +15 -11
- package/handler.ts +0 -3
- package/lib/handler.d.ts +0 -2
package/package.json
CHANGED
package/request.ts
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
// Ctrl-S保存代码
|
2
|
+
import { querystring } from "@ywfe/utils";
|
3
|
+
interface RequestOptions {
|
4
|
+
url: string;
|
5
|
+
method?: string;
|
6
|
+
params?: any;
|
7
|
+
}
|
8
|
+
async function request({ input }: { input: RequestOptions }) {
|
9
|
+
const method = input.method || "GET";
|
10
|
+
const basePathMap = new Map([
|
11
|
+
["prod", "https://gateway.ywwl.com"],
|
12
|
+
["test", "https://test-gateway.ywwl.com"],
|
13
|
+
["test2", "https://test2-gateway.ywwl.com"],
|
14
|
+
["dev", "https://dev-gateway.ywwl.com"],
|
15
|
+
]);
|
16
|
+
const getBasePath = () => {
|
17
|
+
const env = "{{env}}";
|
18
|
+
return basePathMap.get(env);
|
19
|
+
};
|
20
|
+
const isValidURL = (url:string) => {
|
21
|
+
const regex = /^https?:\/\//;
|
22
|
+
return regex.test(url);
|
23
|
+
};
|
24
|
+
const prefix = getBasePath();
|
25
|
+
let requestUrl = isValidURL(input.url) ? input.url : `${prefix}${input.url}`;
|
26
|
+
console.log('requestUrl',requestUrl,isValidURL(input.url))
|
27
|
+
const fetchOption: { [key: string]: any } = {
|
28
|
+
method: method,
|
29
|
+
headers: {
|
30
|
+
"Content-type": "application/json",
|
31
|
+
"x-token": "{{token}}",
|
32
|
+
},
|
33
|
+
};
|
34
|
+
if (method.toUpperCase() === "POST") {
|
35
|
+
fetchOption.body = JSON.stringify(input.params);
|
36
|
+
} else if (method.toUpperCase() === "GET") {
|
37
|
+
requestUrl = `${requestUrl}?${querystring.stringify(input.params || {})}`;
|
38
|
+
}
|
39
|
+
const response = await fetch(requestUrl, fetchOption);
|
40
|
+
if (!response.ok) {
|
41
|
+
const message = `An error has occured: ${response.status}`;
|
42
|
+
return { success: false, message };
|
43
|
+
}
|
44
|
+
const result = await response.json();
|
45
|
+
return result;
|
46
|
+
}
|
47
|
+
|
48
|
+
export default request
|
package/userInputToJson.ts
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
+
import {request} from './index'
|
1
2
|
// Ctrl-S保存代码
|
2
3
|
interface userInput {
|
3
|
-
userInput?:string
|
4
|
-
rules?:string
|
4
|
+
userInput?: string;
|
5
|
+
rules?: string;
|
5
6
|
}
|
6
|
-
async function userInputToJson({input}:{input:userInput}){
|
7
|
-
const {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
async function userInputToJson({ input }: { input: userInput }) {
|
8
|
+
const res: { message: string; success: boolean; data: any } =
|
9
|
+
await request({
|
10
|
+
input: {
|
11
|
+
url: "https://fc-typechat.ywwl.com/userInputToJson",
|
12
|
+
method: "GET",
|
13
|
+
params: input,
|
14
|
+
},
|
15
|
+
});
|
16
|
+
console.log('userINput1',res)
|
17
|
+
return res
|
18
|
+
|
15
19
|
}
|
16
20
|
export default userInputToJson
|
package/handler.ts
DELETED
package/lib/handler.d.ts
DELETED