kb-server 0.0.1-beta.4 → 0.0.1-beta.5

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
  }
@@ -38,8 +38,10 @@ const packAPI = (apis, options) => {
38
38
  if (!authResult) {
39
39
  throw new create_errors_1.CommonErrors.FailOperation.NoPermission();
40
40
  }
41
- // 把权限信息写入上下文
42
- ctx.AuthInfo = authResult || {};
41
+ if (typeof authResult !== "boolean") {
42
+ // 把权限信息写入上下文
43
+ ctx.AuthInfo = authResult || {};
44
+ }
43
45
  }
44
46
  // API 处理
45
47
  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,6 +1,6 @@
1
1
  {
2
2
  "name": "kb-server",
3
- "version": "0.0.1-beta.4",
3
+ "version": "0.0.1-beta.5",
4
4
  "description": "A fast server for Node.JS,made by express.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {