befly 3.23.1 → 3.23.4
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.
- package/checks/api.js +1 -1
- package/configs/beflyConfig.json +1 -1
- package/package.json +4 -3
- package/router/api.js +20 -1
- package/utils/is.js +1 -1
package/checks/api.js
CHANGED
|
@@ -9,7 +9,7 @@ z.config(z.locales.zhCN());
|
|
|
9
9
|
|
|
10
10
|
const noTrimString = z.string().refine(isNoTrimStringAllowEmpty, "不允许首尾空格");
|
|
11
11
|
const lowerCamelRegex = /^_?[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/;
|
|
12
|
-
const apiPathRegex = /^\/api\/
|
|
12
|
+
const apiPathRegex = /^\/api\/[a-z][a-zA-Z0-9]*(?:\/[a-z][a-zA-Z0-9]*)*$/;
|
|
13
13
|
|
|
14
14
|
function addIssue(context, path, message) {
|
|
15
15
|
context.addIssue({
|
package/configs/beflyConfig.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"apiHost": "http://127.0.0.1",
|
|
12
12
|
"publicDir": "./public",
|
|
13
13
|
"publicHost": "http://127.0.0.1:3000",
|
|
14
|
-
"excludeApisLog": ["/api/core/tongJi
|
|
14
|
+
"excludeApisLog": ["/api/core/tongJi/*Report"],
|
|
15
15
|
"logger": {
|
|
16
16
|
"debug": 1,
|
|
17
17
|
"excludeFields": ["password", "token", "secret"],
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.23.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.23.4",
|
|
4
|
+
"gitHead": "c0dee6d07f7e0682306767dc403daa66e34ce6d9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|
|
@@ -53,8 +53,9 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"fast-xml-parser": "^5.7.2",
|
|
56
|
-
"nodemailer": "^8.0.
|
|
56
|
+
"nodemailer": "^8.0.7",
|
|
57
57
|
"pathe": "^2.0.3",
|
|
58
|
+
"picomatch": "^4.0.4",
|
|
58
59
|
"ua-parser-js": "^2.0.9",
|
|
59
60
|
"zod": "^4.0.0"
|
|
60
61
|
},
|
package/router/api.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* 处理 /api/* 路径的请求
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import picomatch from "picomatch";
|
|
7
|
+
|
|
6
8
|
import { Logger } from "../lib/logger.js";
|
|
7
9
|
// 相对导入
|
|
8
10
|
import { setCorsOptions } from "../utils/cors.js";
|
|
@@ -10,6 +12,21 @@ import { getClientIp } from "../utils/getClientIp.js";
|
|
|
10
12
|
import { FinalResponse } from "../utils/response.js";
|
|
11
13
|
import { genShortId } from "../utils/util.js";
|
|
12
14
|
|
|
15
|
+
function createExcludeApisLogMatchers(excludeApisLog) {
|
|
16
|
+
return excludeApisLog.map((pattern) => {
|
|
17
|
+
try {
|
|
18
|
+
return picomatch(pattern);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(`excludeApisLog glob 无效: ${pattern}`, {
|
|
21
|
+
cause: error,
|
|
22
|
+
code: "validation",
|
|
23
|
+
subsystem: "config",
|
|
24
|
+
operation: "excludeApisLog"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
13
30
|
/**
|
|
14
31
|
* API处理器工厂函数
|
|
15
32
|
* @param apis - API路由映射表
|
|
@@ -17,6 +34,8 @@ import { genShortId } from "../utils/util.js";
|
|
|
17
34
|
* @param context - 应用上下文
|
|
18
35
|
*/
|
|
19
36
|
export function apiHandler(apis, hooks, context) {
|
|
37
|
+
const excludeApisLogMatchers = createExcludeApisLogMatchers(context.config.excludeApisLog);
|
|
38
|
+
|
|
20
39
|
return async (req, server) => {
|
|
21
40
|
// 1. 生成请求 ID
|
|
22
41
|
const requestId = genShortId();
|
|
@@ -106,7 +125,7 @@ export function apiHandler(apis, hooks, context) {
|
|
|
106
125
|
logData["body"] = ctx.body;
|
|
107
126
|
}
|
|
108
127
|
|
|
109
|
-
const shouldSkipRequestLog =
|
|
128
|
+
const shouldSkipRequestLog = excludeApisLogMatchers.some((isMatch) => isMatch(ctx.apiPath));
|
|
110
129
|
|
|
111
130
|
if (!shouldSkipRequestLog) {
|
|
112
131
|
Logger.info("请求", logData);
|
package/utils/is.js
CHANGED
|
@@ -5,7 +5,7 @@ import { join } from "pathe";
|
|
|
5
5
|
import { DECIMAL_KIND_TYPES, ENUM_KIND_TYPES, FLOAT_KIND_TYPES, INT_KIND_TYPES, JSON_KIND_TYPES, STRING_KIND_TYPES, TEXT_KIND_TYPES } from "../configs/constConfig.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* 判断值是否为 plain object(原型为 Object.prototype 或 null
|
|
8
|
+
* 判断值是否为 plain object(原型为 Object.prototype 或 null)123。
|
|
9
9
|
*/
|
|
10
10
|
export function isPlainObject(value) {
|
|
11
11
|
if (typeof value !== "object" || value === null) {
|