@lark-apaas/miaoda-core 0.0.1-alpha.1 → 0.0.1-alpha.2
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.
@@ -1,11 +1,38 @@
|
|
1
|
-
import apiProxy from '../api-proxy/core';
|
2
1
|
/**
|
3
2
|
* api panel
|
4
3
|
* 获取open-api.json
|
5
4
|
*/
|
6
|
-
declare function getOpenApiJson(): Promise<
|
5
|
+
declare function getOpenApiJson(): Promise<{}>;
|
7
6
|
/**
|
8
7
|
* 获取日志json
|
9
8
|
*/
|
10
|
-
declare function getLogJson(): Promise<
|
11
|
-
|
9
|
+
declare function getLogJson(): Promise<{}>;
|
10
|
+
/**
|
11
|
+
* GET 请求
|
12
|
+
*/
|
13
|
+
declare function api_get(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
14
|
+
/**
|
15
|
+
* POST 请求
|
16
|
+
*/
|
17
|
+
declare function api_post(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
18
|
+
/**
|
19
|
+
* PUT 请求
|
20
|
+
*/
|
21
|
+
declare function api_put(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
22
|
+
/**
|
23
|
+
* DELETE 请求
|
24
|
+
*/
|
25
|
+
declare function api_delete(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
26
|
+
/**
|
27
|
+
* PATCH 请求
|
28
|
+
*/
|
29
|
+
declare function api_patch(url: any, data: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
30
|
+
/**
|
31
|
+
* HEAD 请求
|
32
|
+
*/
|
33
|
+
declare function api_head(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
34
|
+
/**
|
35
|
+
* OPTIONS 请求
|
36
|
+
*/
|
37
|
+
declare function api_options(url: any, config: any): Promise<import("../api-proxy/core").ApiResponse<any>>;
|
38
|
+
export { getOpenApiJson, getLogJson, api_get, api_post, api_put, api_delete, api_patch, api_head, api_options, };
|
@@ -1,21 +1,84 @@
|
|
1
1
|
import { normalizeBasePath } from "../../../utils/utils.js";
|
2
2
|
import core from "../api-proxy/core.js";
|
3
3
|
async function getOpenApiJson() {
|
4
|
+
let apiJson = {};
|
4
5
|
try {
|
5
6
|
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
6
7
|
const res = await fetch(`${basePath}/openapi.json`);
|
7
|
-
await res.json();
|
8
|
+
apiJson = await res.json();
|
8
9
|
} catch (error) {
|
9
|
-
console.warn('get
|
10
|
+
console.warn('get openapi.json error', error);
|
10
11
|
}
|
12
|
+
return apiJson;
|
11
13
|
}
|
12
14
|
async function getLogJson() {
|
15
|
+
let logJson = {};
|
13
16
|
try {
|
14
17
|
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
15
18
|
const res = await fetch(`${basePath}/log.json`);
|
16
|
-
await res.json();
|
19
|
+
logJson = await res.json();
|
17
20
|
} catch (error) {
|
18
21
|
console.warn('get log.json error', error);
|
19
22
|
}
|
23
|
+
return logJson;
|
20
24
|
}
|
21
|
-
|
25
|
+
async function api_get(url, config) {
|
26
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
27
|
+
return core.get({
|
28
|
+
...config,
|
29
|
+
url: `${basePath}${url}`,
|
30
|
+
method: 'GET'
|
31
|
+
});
|
32
|
+
}
|
33
|
+
async function api_post(url, data, config) {
|
34
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
35
|
+
return core.post({
|
36
|
+
...config,
|
37
|
+
url: `${basePath}${url}`,
|
38
|
+
method: 'POST',
|
39
|
+
data
|
40
|
+
});
|
41
|
+
}
|
42
|
+
async function api_put(url, data, config) {
|
43
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
44
|
+
return core.put({
|
45
|
+
...config,
|
46
|
+
url: `${basePath}${url}`,
|
47
|
+
method: 'PUT',
|
48
|
+
data
|
49
|
+
});
|
50
|
+
}
|
51
|
+
async function api_delete(url, config) {
|
52
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
53
|
+
return core["delete"]({
|
54
|
+
...config,
|
55
|
+
url: `${basePath}${url}`,
|
56
|
+
method: 'DELETE'
|
57
|
+
});
|
58
|
+
}
|
59
|
+
async function api_patch(url, data, config) {
|
60
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
61
|
+
return core.patch({
|
62
|
+
...config,
|
63
|
+
url: `${basePath}${url}`,
|
64
|
+
method: 'PATCH',
|
65
|
+
data
|
66
|
+
});
|
67
|
+
}
|
68
|
+
async function api_head(url, config) {
|
69
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
70
|
+
return core.head({
|
71
|
+
...config,
|
72
|
+
url: `${basePath}${url}`,
|
73
|
+
method: 'HEAD'
|
74
|
+
});
|
75
|
+
}
|
76
|
+
async function api_options(url, config) {
|
77
|
+
const basePath = normalizeBasePath(process.env.CLIENT_BASE_PATH);
|
78
|
+
return core.options({
|
79
|
+
...config,
|
80
|
+
url: `${basePath}${url}`,
|
81
|
+
method: 'OPTIONS'
|
82
|
+
});
|
83
|
+
}
|
84
|
+
export { api_delete, api_get, api_head, api_options, api_patch, api_post, api_put, getLogJson, getOpenApiJson };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { normalizeBasePath } from "../../../utils/utils.js";
|
2
|
-
import {
|
2
|
+
import { api_delete, api_get, api_head, api_options, api_patch, api_post, api_put, getLogJson, getOpenApiJson } from "./api-panel.js";
|
3
3
|
async function getRoutes() {
|
4
4
|
let routes = [
|
5
5
|
{
|
@@ -18,7 +18,13 @@ async function getRoutes() {
|
|
18
18
|
const childApi = {
|
19
19
|
getRoutes,
|
20
20
|
apiProxy: {
|
21
|
-
|
21
|
+
api_get: api_get,
|
22
|
+
api_post: api_post,
|
23
|
+
api_put: api_put,
|
24
|
+
api_delete: api_delete,
|
25
|
+
api_patch: api_patch,
|
26
|
+
api_head: api_head,
|
27
|
+
api_options: api_options,
|
22
28
|
getOpenApiJson: getOpenApiJson,
|
23
29
|
getLogJson: getLogJson
|
24
30
|
}
|
@@ -48,7 +48,13 @@ export interface ParentApi {
|
|
48
48
|
export interface ChildApi {
|
49
49
|
getRoutes: () => Promise<any[]>;
|
50
50
|
apiProxy: {
|
51
|
-
|
51
|
+
api_get: (url: string, config?: any) => Promise<any>;
|
52
|
+
api_post: (url: string, data?: any, config?: any) => Promise<any>;
|
53
|
+
api_put: (url: string, data?: any, config?: any) => Promise<any>;
|
54
|
+
api_delete: (url: string, config?: any) => Promise<any>;
|
55
|
+
api_patch: (url: string, data?: any, config?: any) => Promise<any>;
|
56
|
+
api_head: (url: string, config?: any) => Promise<any>;
|
57
|
+
api_options: (url: string, config?: any) => Promise<any>;
|
52
58
|
getOpenApiJson: () => Promise<any>;
|
53
59
|
getLogJson: () => Promise<any>;
|
54
60
|
};
|