befly 3.21.1 → 3.22.0
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/README.md +7 -0
- package/apis/admin/list.js +1 -1
- package/apis/admin/upd.js +2 -2
- package/apis/dict/all.js +1 -1
- package/apis/dict/detail.js +1 -1
- package/apis/dict/list.js +1 -1
- package/apis/dict/upd.js +1 -1
- package/apis/dictType/upd.js +1 -1
- package/apis/role/all.js +1 -1
- package/apis/role/list.js +1 -1
- package/apis/role/upd.js +1 -1
- package/checks/config.js +1 -3
- package/checks/table.js +2 -15
- package/configs/beflyConfig.json +1 -3
- package/index.js +5 -10
- package/lib/dbHelper.js +201 -736
- package/lib/dbParse.js +1045 -0
- package/lib/dbUtil.js +83 -438
- package/lib/logger.js +21 -45
- package/lib/sqlBuilder.js +78 -294
- package/package.json +2 -2
- package/plugins/mysql.js +2 -1
- package/scripts/syncDb/context.js +62 -47
- package/scripts/syncDb/diff.js +78 -15
- package/scripts/syncDb/index.js +16 -46
- package/scripts/syncDb/report.js +97 -98
- package/tables/admin.json +24 -0
- package/tables/api.json +24 -0
- package/tables/dict.json +24 -0
- package/tables/dictType.json +24 -0
- package/tables/emailLog.json +24 -0
- package/tables/errorReport.json +140 -0
- package/tables/infoReport.json +123 -0
- package/tables/loginLog.json +24 -0
- package/tables/menu.json +24 -0
- package/tables/operateLog.json +24 -0
- package/tables/role.json +24 -0
- package/tables/sysConfig.json +24 -0
- package/utils/loggerUtils.js +9 -14
- package/utils/scanSources.js +3 -3
- package/scripts/syncDb/query.js +0 -26
package/lib/logger.js
CHANGED
|
@@ -19,28 +19,12 @@ const RUNTIME_LOG_DIR = nodePathResolve(INITIAL_CWD, "logs");
|
|
|
19
19
|
const BUILTIN_SENSITIVE_KEYS = ["*password*", "pass", "pwd", "*token*", "access_token", "refresh_token", "accessToken", "refreshToken", "authorization", "cookie", "set-cookie", "*secret*", "apiKey", "api_key", "privateKey", "private_key"];
|
|
20
20
|
|
|
21
21
|
let sanitizeOptions = {
|
|
22
|
-
maxStringLen: 200,
|
|
23
|
-
maxArrayItems: 500,
|
|
24
22
|
sanitizeDepth: 5,
|
|
25
23
|
sanitizeNodes: 5000,
|
|
26
24
|
sanitizeObjectKeys: 500,
|
|
27
25
|
sensitiveKeyMatcher: buildSensitiveKeyMatcher({ builtinPatterns: BUILTIN_SENSITIVE_KEYS, userPatterns: [] })
|
|
28
26
|
};
|
|
29
27
|
|
|
30
|
-
function buildSanitizeOptionsForWriteOptions(writeOptions) {
|
|
31
|
-
if (!writeOptions || writeOptions.truncate !== false) return sanitizeOptions;
|
|
32
|
-
|
|
33
|
-
// 仅关闭“截断”,仍保留敏感字段掩码与结构化清洗(避免泄露敏感信息)。
|
|
34
|
-
return {
|
|
35
|
-
maxStringLen: 200000,
|
|
36
|
-
maxArrayItems: 5000,
|
|
37
|
-
sanitizeDepth: sanitizeOptions.sanitizeDepth,
|
|
38
|
-
sanitizeNodes: sanitizeOptions.sanitizeNodes,
|
|
39
|
-
sanitizeObjectKeys: sanitizeOptions.sanitizeObjectKeys,
|
|
40
|
-
sensitiveKeyMatcher: sanitizeOptions.sensitiveKeyMatcher
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
28
|
let mockInstance = null;
|
|
45
29
|
|
|
46
30
|
let appFileSink = null;
|
|
@@ -381,10 +365,8 @@ export function configure(cfg) {
|
|
|
381
365
|
appFileSink = null;
|
|
382
366
|
errorFileSink = null;
|
|
383
367
|
|
|
384
|
-
//
|
|
368
|
+
// 运行时清洗上限:只保留深度/节点/对象键数量保护。
|
|
385
369
|
sanitizeOptions = {
|
|
386
|
-
maxStringLen: normalizePositiveInt(config.maxStringLen, 200, 20, 200000),
|
|
387
|
-
maxArrayItems: normalizePositiveInt(config.maxArrayItems, 500, 10, 5000),
|
|
388
370
|
sanitizeDepth: normalizePositiveInt(config.sanitizeDepth, 5, 1, 10),
|
|
389
371
|
sanitizeNodes: normalizePositiveInt(config.sanitizeNodes, 5000, 50, 20000),
|
|
390
372
|
sanitizeObjectKeys: normalizePositiveInt(config.sanitizeObjectKeys, 500, 10, 5000),
|
|
@@ -476,16 +458,15 @@ function ensureSinksReady(kind) {
|
|
|
476
458
|
return { fileSink: errorFileSink };
|
|
477
459
|
}
|
|
478
460
|
|
|
479
|
-
function writeJsonl(kind, level, record
|
|
461
|
+
function writeJsonl(kind, level, record) {
|
|
480
462
|
const sinks = ensureSinksReady(kind);
|
|
481
463
|
const time = Date.now();
|
|
482
|
-
const
|
|
483
|
-
const sanitizedRecord = sanitizeLogObject(record, effectiveSanitizeOptions);
|
|
464
|
+
const sanitizedRecord = sanitizeLogObject(record, sanitizeOptions);
|
|
484
465
|
const fileLine = buildJsonLine(level, time, sanitizedRecord);
|
|
485
466
|
sinks.fileSink.enqueue(fileLine);
|
|
486
467
|
}
|
|
487
468
|
|
|
488
|
-
//
|
|
469
|
+
// 对象清洗/脱敏逻辑已下沉到 utils/loggerUtils.js(减少 logger.js 复杂度)。
|
|
489
470
|
|
|
490
471
|
// 日志仅接受 1 个入参(任意类型)。
|
|
491
472
|
// - plain object({})直接作为 record
|
|
@@ -519,16 +500,15 @@ function toRecord(input) {
|
|
|
519
500
|
}
|
|
520
501
|
}
|
|
521
502
|
|
|
522
|
-
function logWrite(level, input
|
|
503
|
+
function logWrite(level, input) {
|
|
523
504
|
// debug!=1/true 则不记录 debug 日志
|
|
524
505
|
if (level === "debug" && config.debug !== 1 && config.debug !== true) return;
|
|
525
506
|
|
|
526
507
|
const record0 = toRecord(input);
|
|
527
508
|
|
|
528
|
-
// 测试场景:mock logger
|
|
509
|
+
// 测试场景:mock logger 走同步写入,并在入口进行清洗/脱敏控制
|
|
529
510
|
if (mockInstance) {
|
|
530
|
-
const
|
|
531
|
-
const sanitized = sanitizeLogObject(record0, effective);
|
|
511
|
+
const sanitized = sanitizeLogObject(record0, sanitizeOptions);
|
|
532
512
|
if (level === "info") {
|
|
533
513
|
mockInstance.info(sanitized);
|
|
534
514
|
} else if (level === "warn") {
|
|
@@ -543,9 +523,9 @@ function logWrite(level, input, options) {
|
|
|
543
523
|
|
|
544
524
|
if (level === "error") {
|
|
545
525
|
// error 仅写入 error 文件
|
|
546
|
-
writeJsonl("error", "error", record0
|
|
526
|
+
writeJsonl("error", "error", record0);
|
|
547
527
|
} else {
|
|
548
|
-
writeJsonl("app", level, record0
|
|
528
|
+
writeJsonl("app", level, record0);
|
|
549
529
|
}
|
|
550
530
|
}
|
|
551
531
|
|
|
@@ -553,41 +533,37 @@ function logWrite(level, input, options) {
|
|
|
553
533
|
* 日志实例(延迟初始化)
|
|
554
534
|
*/
|
|
555
535
|
export const Logger = {
|
|
556
|
-
info(msg, data
|
|
557
|
-
const options = truncate === false ? { truncate: false } : undefined;
|
|
536
|
+
info(msg, data) {
|
|
558
537
|
if (isPlainObject(msg)) {
|
|
559
|
-
logWrite("info", msg
|
|
538
|
+
logWrite("info", msg);
|
|
560
539
|
return;
|
|
561
540
|
}
|
|
562
541
|
|
|
563
|
-
logWrite("info", { msg: msg, data: data }
|
|
542
|
+
logWrite("info", { msg: msg, data: data });
|
|
564
543
|
},
|
|
565
|
-
warn(msg, data
|
|
566
|
-
const options = truncate === false ? { truncate: false } : undefined;
|
|
544
|
+
warn(msg, data) {
|
|
567
545
|
if (isPlainObject(msg)) {
|
|
568
|
-
logWrite("warn", msg
|
|
546
|
+
logWrite("warn", msg);
|
|
569
547
|
return;
|
|
570
548
|
}
|
|
571
549
|
|
|
572
|
-
logWrite("warn", { msg: msg, data: data }
|
|
550
|
+
logWrite("warn", { msg: msg, data: data });
|
|
573
551
|
},
|
|
574
|
-
error(msg, err, data
|
|
575
|
-
const options = truncate === false ? { truncate: false } : undefined;
|
|
552
|
+
error(msg, err, data) {
|
|
576
553
|
if (isPlainObject(msg)) {
|
|
577
|
-
logWrite("error", msg
|
|
554
|
+
logWrite("error", msg);
|
|
578
555
|
return;
|
|
579
556
|
}
|
|
580
557
|
|
|
581
|
-
logWrite("error", { msg: msg, err: err, data: data }
|
|
558
|
+
logWrite("error", { msg: msg, err: err, data: data });
|
|
582
559
|
},
|
|
583
|
-
debug(msg, data
|
|
584
|
-
const options = truncate === false ? { truncate: false } : undefined;
|
|
560
|
+
debug(msg, data) {
|
|
585
561
|
if (isPlainObject(msg)) {
|
|
586
|
-
logWrite("debug", msg
|
|
562
|
+
logWrite("debug", msg);
|
|
587
563
|
return;
|
|
588
564
|
}
|
|
589
565
|
|
|
590
|
-
logWrite("debug", { msg: msg, data: data }
|
|
566
|
+
logWrite("debug", { msg: msg, data: data });
|
|
591
567
|
},
|
|
592
568
|
async flush() {
|
|
593
569
|
await flush();
|