befly 3.23.0 → 3.23.3

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/config.js CHANGED
@@ -25,6 +25,7 @@ const configSchema = z
25
25
  uploadMaxSize: z.int().min(1),
26
26
  tz: z.string().refine((value) => isValidTimeZone(value), "无效的时区"),
27
27
  publicDir: noTrimString.min(1),
28
+ excludeApisLog: z.array(noTrimString),
28
29
 
29
30
  logger: z
30
31
  .object({
@@ -11,6 +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/*Report"],
14
15
  "logger": {
15
16
  "debug": 1,
16
17
  "excludeFields": ["password", "token", "secret"],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.23.0",
4
- "gitHead": "323ac9336929e2beaab435e9865194e22a884c82",
3
+ "version": "3.23.3",
4
+ "gitHead": "07488ee8ed999cc97608d322752d5ec22d7cbeca",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [
@@ -55,6 +55,7 @@
55
55
  "fast-xml-parser": "^5.7.2",
56
56
  "nodemailer": "^8.0.6",
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,11 @@ export function apiHandler(apis, hooks, context) {
106
125
  logData["body"] = ctx.body;
107
126
  }
108
127
 
109
- Logger.info("请求", logData);
128
+ const shouldSkipRequestLog = excludeApisLogMatchers.some((isMatch) => isMatch(ctx.apiPath));
129
+
130
+ if (!shouldSkipRequestLog) {
131
+ Logger.info("请求", logData);
132
+ }
110
133
 
111
134
  // 5. 执行 API handler
112
135
  const result = await ctx.apiHandler(context, ctx);
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) {