kb-server 0.0.1-beta.4 → 0.0.1-beta.6
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.
|
@@ -23,15 +23,7 @@ export interface APIErrorResponse {
|
|
|
23
23
|
RequestId: string;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
export type AuthFunction = (
|
|
27
|
-
/**
|
|
28
|
-
* API名称
|
|
29
|
-
*/
|
|
30
|
-
action: string,
|
|
31
|
-
/**
|
|
32
|
-
* Express原始请求
|
|
33
|
-
*/
|
|
34
|
-
req: express.Request) => Promise<Record<string, any> | false> | false | Record<string, any>;
|
|
26
|
+
export type AuthFunction = (action: string, req: express.Request) => Promise<Record<string, any> | boolean> | boolean | Record<string, any>;
|
|
35
27
|
interface IPackAPIOptions {
|
|
36
28
|
authFn?: AuthFunction;
|
|
37
29
|
}
|
|
@@ -25,6 +25,8 @@ const packAPI = (apis, options) => {
|
|
|
25
25
|
try {
|
|
26
26
|
// API 解析
|
|
27
27
|
const { Action, ...params } = req.body || {};
|
|
28
|
+
// temp
|
|
29
|
+
console.log(req.body);
|
|
28
30
|
// 接口未定义
|
|
29
31
|
if (!Action) {
|
|
30
32
|
throw new create_errors_1.CommonErrors.InvalidParameter.EmptyAPIRequest();
|
|
@@ -38,8 +40,10 @@ const packAPI = (apis, options) => {
|
|
|
38
40
|
if (!authResult) {
|
|
39
41
|
throw new create_errors_1.CommonErrors.FailOperation.NoPermission();
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
if (typeof authResult !== "boolean") {
|
|
44
|
+
// 把权限信息写入上下文
|
|
45
|
+
ctx.AuthInfo = authResult || {};
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
// API 处理
|
|
45
49
|
const execution = apiMap.get(Action);
|
|
@@ -2,6 +2,11 @@ import { AuthFunction } from "./api-middleware";
|
|
|
2
2
|
import { APIs } from "./create-api";
|
|
3
3
|
export interface ICreateServerParams {
|
|
4
4
|
apis: APIs;
|
|
5
|
+
/**
|
|
6
|
+
* 鉴权函数
|
|
7
|
+
*
|
|
8
|
+
* 可以通过返回布尔值来定义权限,也可以直接返回数据对象,数据对象会被传递到上下文 ctx 中(AuthInfo)
|
|
9
|
+
*/
|
|
5
10
|
authFn?: AuthFunction;
|
|
6
11
|
}
|
|
7
12
|
export interface ICreateServerOptions {
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kb-server",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.6",
|
|
4
4
|
"description": "A fast server for Node.JS,made by express.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "rm -rf ./dist
|
|
7
|
+
"build": "rm -rf ./dist && tsc",
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|