@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@ywfe/fe-tools",
4
- "version": "1.2.1-beta.36",
4
+ "version": "1.2.1-beta.37",
5
5
  "description": "工具函数库",
6
6
  "main": "./lib/ywfe-tools.cjs",
7
7
  "module": "./lib/ywfe-tools.esm.js",
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
@@ -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 {userInput, rules} = input
8
- //const res = await fetools.request({
9
- //input:{
10
- //url:"https://fc-typechat.ywwl.com/userInputToJson",
11
- //method:"GET"
12
- //}
13
- //})
14
- return "2"
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
@@ -1,3 +0,0 @@
1
- // Ctrl-S保存代码
2
- function handler(){return 1}
3
- export default handler
package/lib/handler.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare function handler(): number;
2
- export default handler;