@liuhange/dsh-data-asset-shared 2.0.0 → 2.0.1
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/lib/index.js +211 -9
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,6 +1,208 @@
|
|
|
1
1
|
import * as fs from "fs";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
//#region lib/types/defaultBusinessRules.js
|
|
4
|
+
const defaultQualityScoringConfig = {
|
|
5
|
+
weights: {
|
|
6
|
+
completeness: .25,
|
|
7
|
+
accuracy: .25,
|
|
8
|
+
consistency: .25,
|
|
9
|
+
timeliness: .25
|
|
10
|
+
},
|
|
11
|
+
thresholds: {
|
|
12
|
+
completeness: 60,
|
|
13
|
+
accuracy: 60,
|
|
14
|
+
consistency: 60,
|
|
15
|
+
timeliness: 60
|
|
16
|
+
},
|
|
17
|
+
completeness: { missingMarkers: [
|
|
18
|
+
"null",
|
|
19
|
+
"undefined",
|
|
20
|
+
"N/A",
|
|
21
|
+
"",
|
|
22
|
+
"NULL",
|
|
23
|
+
"NaN"
|
|
24
|
+
] },
|
|
25
|
+
accuracy: {
|
|
26
|
+
formatRules: [{
|
|
27
|
+
fieldName: "phone",
|
|
28
|
+
pattern: "1[3-9]\\d{9}",
|
|
29
|
+
weight: .5
|
|
30
|
+
}, {
|
|
31
|
+
fieldName: "email",
|
|
32
|
+
pattern: "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
|
|
33
|
+
weight: .5
|
|
34
|
+
}],
|
|
35
|
+
domainRules: [{
|
|
36
|
+
fieldName: "age",
|
|
37
|
+
min: 0,
|
|
38
|
+
max: 150,
|
|
39
|
+
weight: .5
|
|
40
|
+
}, {
|
|
41
|
+
fieldName: "score",
|
|
42
|
+
min: 0,
|
|
43
|
+
max: 100,
|
|
44
|
+
weight: .5
|
|
45
|
+
}]
|
|
46
|
+
},
|
|
47
|
+
consistency: { crossFieldRules: [{
|
|
48
|
+
name: "endDateAfterStartDate",
|
|
49
|
+
fields: ["startDate", "endDate"],
|
|
50
|
+
constraint: "after"
|
|
51
|
+
}] },
|
|
52
|
+
timeliness: {
|
|
53
|
+
timestampField: "updatedAt",
|
|
54
|
+
freshnessThresholdHours: 720
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const defaultLineageConfig = {
|
|
58
|
+
enabled: false,
|
|
59
|
+
storagePath: "lineage",
|
|
60
|
+
hashAlgorithm: "SHA-256"
|
|
61
|
+
};
|
|
62
|
+
const defaultAdvancedMaskingConfig = {
|
|
63
|
+
defaultAlgorithm: "hash",
|
|
64
|
+
fieldAlgorithms: {},
|
|
65
|
+
fpe: {
|
|
66
|
+
key: "",
|
|
67
|
+
radix: 10
|
|
68
|
+
},
|
|
69
|
+
kAnonymity: {
|
|
70
|
+
kValue: 2,
|
|
71
|
+
quasiIdentifiers: [
|
|
72
|
+
"zipCode",
|
|
73
|
+
"age",
|
|
74
|
+
"gender"
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
differentialPrivacy: {
|
|
78
|
+
epsilon: 1,
|
|
79
|
+
totalBudget: 5,
|
|
80
|
+
sensitivity: 1
|
|
81
|
+
},
|
|
82
|
+
hash: {
|
|
83
|
+
algorithm: "SHA-256",
|
|
84
|
+
salt: ""
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const defaultVisualizationConfig = {
|
|
88
|
+
charts: {
|
|
89
|
+
bar: {
|
|
90
|
+
enabled: true,
|
|
91
|
+
title: "脱敏统计"
|
|
92
|
+
},
|
|
93
|
+
comparison: {
|
|
94
|
+
enabled: true,
|
|
95
|
+
title: "清洗前后对比"
|
|
96
|
+
},
|
|
97
|
+
pie: {
|
|
98
|
+
enabled: true,
|
|
99
|
+
title: "数据资产分布"
|
|
100
|
+
},
|
|
101
|
+
radar: {
|
|
102
|
+
enabled: true,
|
|
103
|
+
title: "质量评分"
|
|
104
|
+
},
|
|
105
|
+
flowchart: {
|
|
106
|
+
enabled: true,
|
|
107
|
+
title: "血缘追踪"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
layout: {
|
|
111
|
+
columns: 2,
|
|
112
|
+
responsive: true
|
|
113
|
+
},
|
|
114
|
+
colorScheme: {
|
|
115
|
+
primary: "#4A90D9",
|
|
116
|
+
secondary: "#F5A623",
|
|
117
|
+
success: "#7ED321",
|
|
118
|
+
warning: "#F8E71C",
|
|
119
|
+
danger: "#D0021B",
|
|
120
|
+
background: "#F5F5F5",
|
|
121
|
+
text: "#333333"
|
|
122
|
+
},
|
|
123
|
+
interactions: {
|
|
124
|
+
expandCollapse: true,
|
|
125
|
+
chartSwitch: true,
|
|
126
|
+
tooltip: true
|
|
127
|
+
},
|
|
128
|
+
templateVersion: "1.0"
|
|
129
|
+
};
|
|
130
|
+
const defaultSensitivityClassificationConfig = {
|
|
131
|
+
fieldNameRules: [
|
|
132
|
+
{
|
|
133
|
+
name: "idCard",
|
|
134
|
+
pattern: "id_?card|身份证|identity",
|
|
135
|
+
level: "Secret"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "phone",
|
|
139
|
+
pattern: "phone|手机|mobile|tel",
|
|
140
|
+
level: "Confidential"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "email",
|
|
144
|
+
pattern: "email|邮箱|mail",
|
|
145
|
+
level: "Confidential"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "bankCard",
|
|
149
|
+
pattern: "bank_?card|银行卡|account",
|
|
150
|
+
level: "Secret"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "address",
|
|
154
|
+
pattern: "address|地址|addr",
|
|
155
|
+
level: "Internal"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "name",
|
|
159
|
+
pattern: "^name$|姓名|username",
|
|
160
|
+
level: "Internal"
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "public",
|
|
164
|
+
pattern: "status|type|category|label|tag|level",
|
|
165
|
+
level: "Public"
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
fieldValueRules: [
|
|
169
|
+
{
|
|
170
|
+
name: "idCardValue",
|
|
171
|
+
pattern: "[1-9]\\d{5}(18|19|20)?\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[\\dXx]",
|
|
172
|
+
level: "Secret"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "phoneValue",
|
|
176
|
+
pattern: "1[3-9]\\d{9}",
|
|
177
|
+
level: "Confidential"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "emailValue",
|
|
181
|
+
pattern: "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
|
|
182
|
+
level: "Confidential"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "bankCardValue",
|
|
186
|
+
pattern: "[1-9]\\d{15,18}",
|
|
187
|
+
level: "Secret"
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
levelMapping: {
|
|
191
|
+
Public: "none",
|
|
192
|
+
Internal: "partial",
|
|
193
|
+
Confidential: "full",
|
|
194
|
+
Secret: "encrypt"
|
|
195
|
+
},
|
|
196
|
+
defaultLevel: "Internal"
|
|
197
|
+
};
|
|
198
|
+
const defaultIncrementalSchedulingConfig = {
|
|
199
|
+
incrementalMode: false,
|
|
200
|
+
cronExpression: "0 2 * * *",
|
|
201
|
+
hashAlgorithm: "SHA-256",
|
|
202
|
+
watchDirectory: "input",
|
|
203
|
+
stateFilePath: "state/incremental-state.json",
|
|
204
|
+
lockTimeout: 3600
|
|
205
|
+
};
|
|
4
206
|
const defaultBusinessRules = {
|
|
5
207
|
version: "1.0",
|
|
6
208
|
lastUpdated: "2026-08-17",
|
|
@@ -322,26 +524,26 @@ var ReportGenerator = class {
|
|
|
322
524
|
- 原始行数:${params.originalLineCount}
|
|
323
525
|
- 去重后行数:${params.originalLineCount - params.duplicateRemoved}(删除 ${params.duplicateRemoved} 行重复)
|
|
324
526
|
`;
|
|
325
|
-
if (params.standardizeApplied) report +=
|
|
527
|
+
if (params.standardizeApplied) report += "- 格式标准化:✅ 完成\n";
|
|
326
528
|
report += `- 异常值检测:发现 ${params.anomalyTotalCount} 个异常\n`;
|
|
327
529
|
if (params.anomalies.length > 0) {
|
|
328
530
|
const anomalyText = params.anomalies.slice(0, 5).map((a) => `行${a.line}: ${a.reason}`).join(";");
|
|
329
531
|
report += ` 异常详情:${anomalyText}`;
|
|
330
532
|
if (params.anomalyTotalCount > 5) report += `...等${params.anomalyTotalCount}项`;
|
|
331
|
-
report +=
|
|
533
|
+
report += "\n";
|
|
332
534
|
}
|
|
333
535
|
report += `- 输出文件:${params.outputPath}\n- 状态:✅ 完成`;
|
|
334
536
|
return report;
|
|
335
537
|
}
|
|
336
538
|
generateInventoryReport(params) {
|
|
337
539
|
let report = `【数据资产盘点报告】\n- 目录:${params.directory}\n- 发现数据文件:${params.fileCount} 个\n\n`;
|
|
338
|
-
report +=
|
|
339
|
-
report +=
|
|
540
|
+
report += "| 文件名 | 大小 | 类型 | 价值评估 | 说明 |\n";
|
|
541
|
+
report += "|--------|------|------|----------|------|\n";
|
|
340
542
|
for (const item of params.assetItems) report += `| ${item.fileName} | ${item.size} | ${item.type} | ${item.valueAssessment} | ${item.description} |\n`;
|
|
341
|
-
report +=
|
|
342
|
-
report +=
|
|
343
|
-
report +=
|
|
344
|
-
report +=
|
|
543
|
+
report += "\n---\n【建议】\n";
|
|
544
|
+
report += "1. 高价值数据(★★★★★)建议优先进行清洗和脱敏后交易\n";
|
|
545
|
+
report += "2. 低价值数据建议评估是否值得投入处理成本\n";
|
|
546
|
+
report += "3. 所有数据交易前必须完成合规审查\n";
|
|
345
547
|
return report;
|
|
346
548
|
}
|
|
347
549
|
generatePackagingManual(params) {
|
|
@@ -412,4 +614,4 @@ var AuditLogger = class {
|
|
|
412
614
|
}
|
|
413
615
|
};
|
|
414
616
|
//#endregion
|
|
415
|
-
export { AuditLogger, BusinessRulesLoader, FileFormatAdapter, PathValidator, ReportGenerator, defaultBusinessRules };
|
|
617
|
+
export { AuditLogger, BusinessRulesLoader, FileFormatAdapter, PathValidator, ReportGenerator, defaultAdvancedMaskingConfig, defaultBusinessRules, defaultIncrementalSchedulingConfig, defaultLineageConfig, defaultQualityScoringConfig, defaultSensitivityClassificationConfig, defaultVisualizationConfig };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
{
|
|
2
2
|
"name": "@liuhange/dsh-data-asset-shared",
|
|
3
3
|
"description": "Shared infrastructure for data assetization plugins: business rules loader, file format adapter, report generator, path validator, audit logger",
|
|
4
|
-
"version":
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|