@liuhange/dsh-data-asset-shared 2.0.2 → 3.0.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.
@@ -0,0 +1,26 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ export class AuditLogger {
4
+ logDir;
5
+ constructor(logDir) {
6
+ this.logDir = logDir ?? path.resolve(process.cwd(), 'logs');
7
+ }
8
+ log(params) {
9
+ const timestamp = new Date().toISOString();
10
+ const operator = params.operator ?? 'system';
11
+ const logLine = `[${params.pluginName}] ${timestamp} | 操作: ${params.operation} | 操作人: ${operator} | 输入: ${params.inputPath} | 输出: ${params.outputPath} | 结果: ${params.result}`;
12
+ console.log(logLine);
13
+ if (params.writeToFile) {
14
+ this.writeToFile(logLine);
15
+ }
16
+ }
17
+ writeToFile(logLine) {
18
+ if (!fs.existsSync(this.logDir)) {
19
+ fs.mkdirSync(this.logDir, { recursive: true });
20
+ }
21
+ const date = new Date().toISOString().split('T')[0];
22
+ const logFile = path.join(this.logDir, `audit-${date}.log`);
23
+ fs.appendFileSync(logFile, logLine + '\n', 'utf-8');
24
+ }
25
+ }
26
+ //# sourceMappingURL=auditLogger.js.map
@@ -0,0 +1,86 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { defaultBusinessRules } from './defaultBusinessRules.js';
4
+ export class BusinessRulesLoader {
5
+ cachedResult = null;
6
+ configPath;
7
+ constructor(configPath) {
8
+ this.configPath = configPath
9
+ ? path.resolve(configPath)
10
+ : path.resolve(process.cwd(), 'config', 'business-rules.json');
11
+ }
12
+ load() {
13
+ if (this.cachedResult) {
14
+ return this.cachedResult;
15
+ }
16
+ const result = this.loadInternal();
17
+ this.cachedResult = result;
18
+ return result;
19
+ }
20
+ loadInternal() {
21
+ if (!fs.existsSync(this.configPath)) {
22
+ return this.createDefaultResult('DEFAULT_MISSING');
23
+ }
24
+ let raw;
25
+ try {
26
+ raw = fs.readFileSync(this.configPath, 'utf-8');
27
+ }
28
+ catch {
29
+ return this.createDefaultResult('DEFAULT_PARSE');
30
+ }
31
+ let parsed;
32
+ try {
33
+ parsed = JSON.parse(raw);
34
+ }
35
+ catch {
36
+ return this.createDefaultResult('DEFAULT_PARSE');
37
+ }
38
+ if (!this.isBusinessRulesConfig(parsed)) {
39
+ return this.createDefaultResult('DEFAULT_PARSE');
40
+ }
41
+ if (!this.isVersionCompatible(parsed.version)) {
42
+ return this.createDefaultResult('DEFAULT_VERSION');
43
+ }
44
+ if (!this.hasRequiredNodes(parsed)) {
45
+ return this.createDefaultResult('DEFAULT_PARTIAL');
46
+ }
47
+ return {
48
+ config: parsed,
49
+ status: 'CONFIG_LOADED',
50
+ };
51
+ }
52
+ createDefaultResult(status) {
53
+ return {
54
+ config: defaultBusinessRules,
55
+ status,
56
+ };
57
+ }
58
+ isBusinessRulesConfig(value) {
59
+ return (typeof value === 'object' &&
60
+ value !== null &&
61
+ 'version' in value &&
62
+ 'valueAssessment' in value &&
63
+ 'sensitivePatterns' in value &&
64
+ 'cleaningRules' in value &&
65
+ 'compliance' in value &&
66
+ 'packaging' in value);
67
+ }
68
+ isVersionCompatible(version) {
69
+ if (typeof version !== 'string') {
70
+ return false;
71
+ }
72
+ return version.startsWith('1.') || version.startsWith('3.');
73
+ }
74
+ hasRequiredNodes(config) {
75
+ return (config.valueAssessment !== undefined &&
76
+ config.sensitivePatterns !== undefined &&
77
+ config.maskingLevels !== undefined &&
78
+ config.cleaningRules !== undefined &&
79
+ config.compliance !== undefined &&
80
+ config.packaging !== undefined);
81
+ }
82
+ clearCache() {
83
+ this.cachedResult = null;
84
+ }
85
+ }
86
+ //# sourceMappingURL=businessRulesLoader.js.map
@@ -0,0 +1,324 @@
1
+ export const defaultQualityScoringConfig = {
2
+ weights: {
3
+ completeness: 0.25,
4
+ accuracy: 0.25,
5
+ consistency: 0.25,
6
+ timeliness: 0.25,
7
+ },
8
+ thresholds: {
9
+ completeness: 60,
10
+ accuracy: 60,
11
+ consistency: 60,
12
+ timeliness: 60,
13
+ },
14
+ completeness: {
15
+ missingMarkers: ['null', 'undefined', 'N/A', '', 'NULL', 'NaN'],
16
+ },
17
+ accuracy: {
18
+ formatRules: [
19
+ { fieldName: 'phone', pattern: '1[3-9]\\d{9}', weight: 0.5 },
20
+ { fieldName: 'email', pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}', weight: 0.5 },
21
+ ],
22
+ domainRules: [
23
+ { fieldName: 'age', min: 0, max: 150, weight: 0.5 },
24
+ { fieldName: 'score', min: 0, max: 100, weight: 0.5 },
25
+ ],
26
+ },
27
+ consistency: {
28
+ crossFieldRules: [
29
+ { name: 'endDateAfterStartDate', fields: ['startDate', 'endDate'], constraint: 'after' },
30
+ ],
31
+ },
32
+ timeliness: {
33
+ timestampField: 'updatedAt',
34
+ freshnessThresholdHours: 720,
35
+ },
36
+ };
37
+ export const defaultLineageConfig = {
38
+ enabled: false,
39
+ storagePath: 'lineage',
40
+ hashAlgorithm: 'SHA-256',
41
+ };
42
+ export const defaultAdvancedMaskingConfig = {
43
+ defaultAlgorithm: 'hash',
44
+ fieldAlgorithms: {},
45
+ fpe: {
46
+ key: '',
47
+ radix: 10,
48
+ },
49
+ kAnonymity: {
50
+ kValue: 2,
51
+ quasiIdentifiers: ['zipCode', 'age', 'gender'],
52
+ },
53
+ differentialPrivacy: {
54
+ epsilon: 1.0,
55
+ totalBudget: 5.0,
56
+ sensitivity: 1.0,
57
+ },
58
+ hash: {
59
+ algorithm: 'SHA-256',
60
+ salt: '',
61
+ },
62
+ };
63
+ export const defaultVisualizationConfig = {
64
+ charts: {
65
+ bar: { enabled: true, title: '脱敏统计' },
66
+ comparison: { enabled: true, title: '清洗前后对比' },
67
+ pie: { enabled: true, title: '数据资产分布' },
68
+ radar: { enabled: true, title: '质量评分' },
69
+ flowchart: { enabled: true, title: '血缘追踪' },
70
+ },
71
+ layout: {
72
+ columns: 2,
73
+ responsive: true,
74
+ },
75
+ colorScheme: {
76
+ primary: '#4A90D9',
77
+ secondary: '#F5A623',
78
+ success: '#7ED321',
79
+ warning: '#F8E71C',
80
+ danger: '#D0021B',
81
+ background: '#F5F5F5',
82
+ text: '#333333',
83
+ },
84
+ interactions: {
85
+ expandCollapse: true,
86
+ chartSwitch: true,
87
+ tooltip: true,
88
+ },
89
+ templateVersion: '1.0',
90
+ };
91
+ export const defaultSensitivityClassificationConfig = {
92
+ fieldNameRules: [
93
+ { name: 'idCard', pattern: 'id_?card|身份证|identity', level: 'Secret' },
94
+ { name: 'phone', pattern: 'phone|手机|mobile|tel', level: 'Confidential' },
95
+ { name: 'email', pattern: 'email|邮箱|mail', level: 'Confidential' },
96
+ { name: 'bankCard', pattern: 'bank_?card|银行卡|account', level: 'Secret' },
97
+ { name: 'address', pattern: 'address|地址|addr', level: 'Internal' },
98
+ { name: 'name', pattern: '^name$|姓名|username', level: 'Internal' },
99
+ { name: 'public', pattern: 'status|type|category|label|tag|level', level: 'Public' },
100
+ ],
101
+ fieldValueRules: [
102
+ { name: 'idCardValue', 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]', level: 'Secret' },
103
+ { name: 'phoneValue', pattern: '1[3-9]\\d{9}', level: 'Confidential' },
104
+ { name: 'emailValue', pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}', level: 'Confidential' },
105
+ { name: 'bankCardValue', pattern: '[1-9]\\d{15,18}', level: 'Secret' },
106
+ ],
107
+ levelMapping: {
108
+ Public: 'none',
109
+ Internal: 'partial',
110
+ Confidential: 'full',
111
+ Secret: 'encrypt',
112
+ },
113
+ defaultLevel: 'Internal',
114
+ };
115
+ export const defaultIncrementalSchedulingConfig = {
116
+ incrementalMode: false,
117
+ cronExpression: '0 2 * * *',
118
+ hashAlgorithm: 'SHA-256',
119
+ watchDirectory: 'input',
120
+ stateFilePath: 'state/incremental-state.json',
121
+ lockTimeout: 3600,
122
+ };
123
+ export const defaultRegistrationConfig = {
124
+ ruleVersion: '1.0',
125
+ agencies: [
126
+ {
127
+ id: 'beijing',
128
+ name: '北京国际大数据交易所',
129
+ location: '北京',
130
+ specialties: ['医疗', '健康', '生物'],
131
+ contact: '北京国际大数据交易所官网',
132
+ basis: '医疗数据登记案例集中',
133
+ },
134
+ {
135
+ id: 'shanghai',
136
+ name: '上海数据交易所',
137
+ location: '上海',
138
+ specialties: ['金融', '征信', '支付'],
139
+ contact: '上海数据交易所官网',
140
+ basis: '金融数据交易活跃度最高',
141
+ },
142
+ {
143
+ id: 'shenzhen',
144
+ name: '深圳数据交易所',
145
+ location: '深圳',
146
+ specialties: ['交通', '物流', '地理'],
147
+ contact: '深圳数据交易所官网',
148
+ basis: '交通数据登记案例较多',
149
+ },
150
+ ],
151
+ dataTypeMapping: {
152
+ '金融': 'shanghai',
153
+ '征信': 'shanghai',
154
+ '支付': 'shanghai',
155
+ '医疗': 'beijing',
156
+ '健康': 'beijing',
157
+ '生物': 'beijing',
158
+ '交通': 'shenzhen',
159
+ '物流': 'shenzhen',
160
+ '地理': 'shenzhen',
161
+ },
162
+ defaultRecommendation: {
163
+ agency: null,
164
+ basis: '根据数据属性匹配',
165
+ message: '建议咨询专业机构',
166
+ },
167
+ registrationFee: 5000,
168
+ registrationSteps: ['申请', '受理', '审查', '公示', '异议', '存证', '凭证'],
169
+ };
170
+ export const defaultPolicyReferences = [
171
+ {
172
+ stage: 'INVENTORY',
173
+ stageLabel: '盘点',
174
+ documents: [
175
+ { name: '中华人民共和国数据安全法', docNumber: '主席令第八十四号', coreRequirement: '数据分类分级保护' },
176
+ { name: '数据产权登记工作指引(试行)', docNumber: '国数综政策〔2026〕35号', coreRequirement: '数据产权三权分置' },
177
+ ],
178
+ },
179
+ {
180
+ stage: 'CLEANING',
181
+ stageLabel: '清洗',
182
+ documents: [
183
+ { name: '企业数据资源相关会计处理暂行规定', docNumber: '财会〔2023〕11号', coreRequirement: '数据资源入表条件' },
184
+ { name: '数据资产评估指导意见', docNumber: '中评协〔2023〕17号', coreRequirement: '六维质量评价标准' },
185
+ ],
186
+ },
187
+ {
188
+ stage: 'MASKING',
189
+ stageLabel: '脱敏',
190
+ documents: [
191
+ { name: '中华人民共和国个人信息保护法', docNumber: '主席令第九十一号', coreRequirement: '匿名化后不再属于个人信息' },
192
+ { name: '关于完善数据流通安全治理的实施方案', docNumber: '发改数据〔2025〕18号', coreRequirement: '脱敏后可按一般数据流通' },
193
+ ],
194
+ },
195
+ {
196
+ stage: 'PACKAGING',
197
+ stageLabel: '包装',
198
+ documents: [
199
+ { name: '数据产权登记工作指引(试行)', docNumber: '国数综政策〔2026〕35号', coreRequirement: '登记凭证可用于入表、融资、入股' },
200
+ ],
201
+ },
202
+ {
203
+ stage: 'PRECHECK',
204
+ stageLabel: '登记预检',
205
+ documents: [
206
+ { name: '数据产权登记工作指引(试行)', docNumber: '国数综政策〔2026〕35号', coreRequirement: '不予登记情形' },
207
+ ],
208
+ },
209
+ {
210
+ stage: 'DOC_GENERATION',
211
+ stageLabel: '材料生成',
212
+ documents: [
213
+ { name: '数据产权登记工作指引(试行)', docNumber: '国数综政策〔2026〕35号', coreRequirement: '7步登记流程审查重点' },
214
+ ],
215
+ },
216
+ {
217
+ stage: 'AGENCY_MATCHING',
218
+ stageLabel: '机构匹配',
219
+ documents: [
220
+ { name: '数据产权登记工作指引(试行)', docNumber: '国数综政策〔2026〕35号', coreRequirement: '登记机构名录' },
221
+ ],
222
+ },
223
+ ];
224
+ export const defaultBusinessRules = {
225
+ version: '1.0',
226
+ lastUpdated: '2026-08-17',
227
+ valueAssessment: {
228
+ highValue: {
229
+ keywords: ['供应链', '销售明细', '设备工况', '交易流水'],
230
+ score: 5,
231
+ label: '★★★★★',
232
+ recommendation: '优先交易,建议入表',
233
+ },
234
+ mediumValue: {
235
+ keywords: ['用户行为', '产品数据', '行业报告'],
236
+ score: 3,
237
+ label: '★★★',
238
+ recommendation: '脱敏后交易',
239
+ },
240
+ lowValue: {
241
+ keywords: ['日志', '备份', '临时'],
242
+ score: 1,
243
+ label: '★',
244
+ recommendation: '评估处理成本',
245
+ },
246
+ defaultValue: {
247
+ score: 3,
248
+ label: '★★★',
249
+ recommendation: '需进一步评估',
250
+ },
251
+ },
252
+ sensitivePatterns: {
253
+ idCard: {
254
+ 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]',
255
+ level: 'FULL',
256
+ },
257
+ phone: {
258
+ pattern: '1[3-9]\\d{9}',
259
+ level: 'PARTIAL',
260
+ },
261
+ bankCard: {
262
+ pattern: '[1-9]\\d{15,18}',
263
+ level: 'PARTIAL',
264
+ },
265
+ email: {
266
+ pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}',
267
+ level: 'PARTIAL',
268
+ },
269
+ },
270
+ maskingLevels: {
271
+ FULL: {
272
+ description: '完全匿名化',
273
+ applyTo: ['idCard'],
274
+ },
275
+ PARTIAL: {
276
+ description: '假名化,保留前3后4',
277
+ applyTo: ['phone', 'bankCard'],
278
+ },
279
+ GENERALIZE: {
280
+ description: '泛化处理',
281
+ applyTo: ['email'],
282
+ },
283
+ },
284
+ cleaningRules: {
285
+ missingValueStrategy: {
286
+ government: 'interpolation',
287
+ financial: 'manual_review',
288
+ behavior: 'mode_fill',
289
+ },
290
+ qualityThreshold: {
291
+ A: { missingRate: 0.05, errorRate: 0.01, label: '优秀' },
292
+ B: { missingRate: 0.10, errorRate: 0.03, label: '良好' },
293
+ C: { missingRate: 0.20, errorRate: 0.05, label: '合格' },
294
+ D: { missingRate: 0.20, errorRate: 0.05, label: '不合格', action: '不建议交易' },
295
+ },
296
+ },
297
+ compliance: {
298
+ policies: [
299
+ { name: '数据产权登记工作指引', doc: '国数综政策〔2026〕35号', check: '数据来源可登记' },
300
+ { name: '数据流通安全治理', doc: '发改数据〔2025〕18号', check: '来源合法性' },
301
+ { name: '数据脱敏工具标准', doc: 'YD/T 6225-2024', check: '脱敏效果达标' },
302
+ ],
303
+ },
304
+ packaging: {
305
+ complianceStatements: [
306
+ '本数据产品已完成脱敏处理',
307
+ '不包含个人身份信息',
308
+ '数据来源合法',
309
+ '建议交易前完成数据产权登记',
310
+ ],
311
+ pricingRules: [
312
+ { valueLevel: '★★★★★', suggestion: '根据数据质量、稀缺性和应用场景综合定价,建议高价交易' },
313
+ { valueLevel: '★★★★', suggestion: '根据数据质量和应用场景定价,建议中高价交易' },
314
+ { valueLevel: '★★★', suggestion: '根据数据质量和应用场景综合定价' },
315
+ { valueLevel: '★★', suggestion: '建议低价交易或内部使用' },
316
+ { valueLevel: '★', suggestion: '建议评估处理成本后决定是否交易' },
317
+ ],
318
+ defaultDescription: '适用于数据分析、模型训练、行业研究等场景',
319
+ version: 'V1.0',
320
+ },
321
+ registration: defaultRegistrationConfig,
322
+ policyReferences: defaultPolicyReferences,
323
+ };
324
+ //# sourceMappingURL=defaultBusinessRules.js.map
@@ -0,0 +1,98 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ export class FileFormatAdapter {
4
+ detectFormat(filePath) {
5
+ const ext = path.extname(filePath).toLowerCase().slice(1);
6
+ if (ext === 'csv' || ext === 'json' || ext === 'txt' || ext === 'xlsx') {
7
+ return ext;
8
+ }
9
+ return 'unknown';
10
+ }
11
+ async read(filePath) {
12
+ const format = this.detectFormat(filePath);
13
+ const fullPath = path.resolve(filePath);
14
+ if (!fs.existsSync(fullPath)) {
15
+ throw new Error(`错误:文件不存在 - ${fullPath}`);
16
+ }
17
+ const stats = fs.statSync(fullPath);
18
+ const isLargeFile = stats.size >= 10 * 1024 * 1024;
19
+ switch (format) {
20
+ case 'csv':
21
+ return this.readCsv(fullPath);
22
+ case 'json':
23
+ return this.readJson(fullPath);
24
+ case 'xlsx':
25
+ return this.readXlsx(fullPath);
26
+ case 'txt':
27
+ case 'unknown':
28
+ default:
29
+ return this.readTxt(fullPath, format, isLargeFile);
30
+ }
31
+ }
32
+ async write(filePath, lines, format) {
33
+ const fullPath = path.resolve(filePath);
34
+ const dir = path.dirname(fullPath);
35
+ if (!fs.existsSync(dir)) {
36
+ fs.mkdirSync(dir, { recursive: true });
37
+ }
38
+ switch (format) {
39
+ case 'csv':
40
+ this.writeCsv(fullPath, lines);
41
+ break;
42
+ case 'json':
43
+ this.writeJson(fullPath, lines);
44
+ break;
45
+ case 'xlsx':
46
+ this.writeXlsx(fullPath, lines);
47
+ break;
48
+ case 'txt':
49
+ case 'unknown':
50
+ default:
51
+ fs.writeFileSync(fullPath, lines.join('\n'), 'utf-8');
52
+ break;
53
+ }
54
+ }
55
+ readTxt(filePath, format, _isLargeFile) {
56
+ const content = fs.readFileSync(filePath, 'utf-8');
57
+ const lines = content.split('\n').filter(line => line.trim());
58
+ return { lines, format, raw: content };
59
+ }
60
+ readCsv(filePath) {
61
+ const content = fs.readFileSync(filePath, 'utf-8');
62
+ const lines = content.split('\n').filter(line => line.trim());
63
+ return { lines, format: 'csv', raw: content };
64
+ }
65
+ readJson(filePath) {
66
+ const content = fs.readFileSync(filePath, 'utf-8');
67
+ const parsed = JSON.parse(content);
68
+ if (Array.isArray(parsed)) {
69
+ const lines = parsed.map(item => JSON.stringify(item));
70
+ return { lines, format: 'json', raw: parsed };
71
+ }
72
+ const lines = [JSON.stringify(parsed)];
73
+ return { lines, format: 'json', raw: parsed };
74
+ }
75
+ readXlsx(filePath) {
76
+ const content = fs.readFileSync(filePath, 'utf-8');
77
+ const lines = content.split('\n').filter(line => line.trim());
78
+ return { lines, format: 'xlsx', raw: content };
79
+ }
80
+ writeCsv(filePath, lines) {
81
+ fs.writeFileSync(filePath, lines.join('\n'), 'utf-8');
82
+ }
83
+ writeJson(filePath, lines) {
84
+ const objects = lines.map((line) => {
85
+ try {
86
+ return JSON.parse(line);
87
+ }
88
+ catch {
89
+ return line;
90
+ }
91
+ });
92
+ fs.writeFileSync(filePath, JSON.stringify(objects, null, 2), 'utf-8');
93
+ }
94
+ writeXlsx(filePath, lines) {
95
+ fs.writeFileSync(filePath, lines.join('\n'), 'utf-8');
96
+ }
97
+ }
98
+ //# sourceMappingURL=fileFormatAdapter.js.map
package/lib/index.js CHANGED
@@ -6,4 +6,7 @@ export { FileFormatAdapter } from './fileFormatAdapter.js';
6
6
  export { ReportGenerator } from './reportGenerator.js';
7
7
  export { PathValidator } from './pathValidator.js';
8
8
  export { AuditLogger } from './auditLogger.js';
9
+ export { PolicyReferenceResolver } from './policyReferenceResolver.js';
10
+ export { RegistrationNavigationEnhancer } from './registrationNavigationEnhancer.js';
11
+ export { defaultRegistrationConfig, defaultPolicyReferences, } from './defaultBusinessRules.js';
9
12
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,18 @@
1
+ import * as path from 'path';
2
+ export class PathValidator {
3
+ validate(filePath, workingDir) {
4
+ const resolved = path.resolve(filePath);
5
+ if (filePath.includes('..')) {
6
+ throw new Error(`错误:路径不合法 - ${filePath}`);
7
+ }
8
+ const relative = path.relative(workingDir, resolved);
9
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
10
+ throw new Error(`错误:路径不合法 - ${filePath}`);
11
+ }
12
+ return resolved;
13
+ }
14
+ validateDirectory(dirPath, workingDir) {
15
+ return this.validate(dirPath, workingDir);
16
+ }
17
+ }
18
+ //# sourceMappingURL=pathValidator.js.map
@@ -0,0 +1,64 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { defaultPolicyReferences } from './defaultBusinessRules.js';
4
+ export class PolicyReferenceResolver {
5
+ static instance = null;
6
+ cache = new Map();
7
+ references = [];
8
+ configPath;
9
+ constructor(configPath) {
10
+ this.configPath = configPath
11
+ ? path.resolve(configPath)
12
+ : path.resolve(process.cwd(), 'config', 'policy-references.json');
13
+ this.load();
14
+ }
15
+ static getInstance(configPath) {
16
+ if (!PolicyReferenceResolver.instance) {
17
+ PolicyReferenceResolver.instance = new PolicyReferenceResolver(configPath);
18
+ }
19
+ return PolicyReferenceResolver.instance;
20
+ }
21
+ load() {
22
+ try {
23
+ if (fs.existsSync(this.configPath)) {
24
+ const raw = fs.readFileSync(this.configPath, 'utf-8');
25
+ const parsed = JSON.parse(raw);
26
+ if (parsed.policyReferences && Array.isArray(parsed.policyReferences)) {
27
+ this.references = parsed.policyReferences;
28
+ return;
29
+ }
30
+ }
31
+ }
32
+ catch {
33
+ console.warn('[PolicyReferenceResolver] 配置加载失败,使用默认值');
34
+ }
35
+ this.references = defaultPolicyReferences;
36
+ }
37
+ resolve(stage) {
38
+ if (this.cache.has(stage)) {
39
+ return this.cache.get(stage);
40
+ }
41
+ const ref = this.references.find(r => r.stage === stage);
42
+ let documents;
43
+ if (ref && ref.documents && ref.documents.length > 0) {
44
+ documents = ref.documents;
45
+ }
46
+ else {
47
+ console.warn(`[PolicyReferenceResolver] 环节 ${stage} 未配置政策依据,使用占位项`);
48
+ documents = [
49
+ {
50
+ name: '依据文件待补充',
51
+ docNumber: '待配置',
52
+ coreRequirement: '请补充对应政策依据',
53
+ },
54
+ ];
55
+ }
56
+ this.cache.set(stage, documents);
57
+ return documents;
58
+ }
59
+ clearCache() {
60
+ this.cache.clear();
61
+ PolicyReferenceResolver.instance = null;
62
+ }
63
+ }
64
+ //# sourceMappingURL=policyReferenceResolver.js.map
@@ -0,0 +1,107 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { PolicyReferenceResolver } from './policyReferenceResolver.js';
4
+ import { defaultRegistrationConfig } from './defaultBusinessRules.js';
5
+ const PLUGIN_STAGE_MAP = {
6
+ 'data-inventory': 'INVENTORY',
7
+ 'data-cleaning': 'CLEANING',
8
+ 'data-masking': 'MASKING',
9
+ 'data-packaging': 'PACKAGING',
10
+ };
11
+ const NAVIGATION_TEXTS = {
12
+ 'data-inventory': '本数据集已完成盘点,建议下一步申请数据产权登记。登记机构推荐:{agency}',
13
+ 'data-cleaning': '数据质量已达到登记要求(依据《数据资产评估指导意见》六维质量评价标准)。',
14
+ 'data-masking': "脱敏后数据已符合登记审查中的'来源合规性'要求(依据《数据产权登记工作指引》第三章)。",
15
+ 'data-packaging': "本产品说明书可直接用于登记申请材料中的'数据描述'部分。",
16
+ };
17
+ export class RegistrationNavigationEnhancer {
18
+ config;
19
+ configPath;
20
+ constructor(configPath) {
21
+ this.configPath = configPath
22
+ ? path.resolve(configPath)
23
+ : path.resolve(process.cwd(), 'config', 'registration-agencies.json');
24
+ this.config = this.loadConfig();
25
+ }
26
+ loadConfig() {
27
+ try {
28
+ if (fs.existsSync(this.configPath)) {
29
+ const raw = fs.readFileSync(this.configPath, 'utf-8');
30
+ return JSON.parse(raw);
31
+ }
32
+ }
33
+ catch {
34
+ console.warn('[RegistrationNavigationEnhancer] 配置加载失败,使用默认值');
35
+ }
36
+ return defaultRegistrationConfig;
37
+ }
38
+ matchAgency(dataType) {
39
+ const agencyId = this.config.dataTypeMapping[dataType];
40
+ if (agencyId) {
41
+ const agency = this.config.agencies.find(a => a.id === agencyId);
42
+ if (agency)
43
+ return agency.name;
44
+ }
45
+ return this.config.defaultRecommendation.message;
46
+ }
47
+ enhance(report, pluginName, dataType) {
48
+ const stage = PLUGIN_STAGE_MAP[pluginName];
49
+ if (!stage)
50
+ return report;
51
+ const resolver = PolicyReferenceResolver.getInstance();
52
+ const policyDocs = resolver.resolve(stage);
53
+ let navText = NAVIGATION_TEXTS[pluginName] || '';
54
+ if (pluginName === 'data-inventory') {
55
+ const agencyName = this.matchAgency(dataType);
56
+ navText = navText.replace('{agency}', agencyName);
57
+ }
58
+ const policyText = policyDocs
59
+ .map(d => `- 《${d.name}》(${d.docNumber}):${d.coreRequirement}`)
60
+ .join('\n');
61
+ const enhancedReport = `${report}
62
+
63
+ ---
64
+
65
+ ## 登记导航
66
+
67
+ ${navText}
68
+
69
+ ## 政策依据
70
+
71
+ ${policyText}
72
+ `;
73
+ return enhancedReport;
74
+ }
75
+ enhanceAll(orchestrationResult, dataType) {
76
+ return {
77
+ ...orchestrationResult,
78
+ maskingReport: this.enhance(orchestrationResult.maskingReport, 'data-masking', dataType),
79
+ cleaningReport: this.enhance(orchestrationResult.cleaningReport, 'data-cleaning', dataType),
80
+ inventoryReport: this.enhance(orchestrationResult.inventoryReport, 'data-inventory', dataType),
81
+ packagingManual: this.enhance(orchestrationResult.packagingManual, 'data-packaging', dataType),
82
+ };
83
+ }
84
+ matchAgencyResult(dataType) {
85
+ const agencyId = this.config.dataTypeMapping[dataType];
86
+ if (agencyId) {
87
+ const agency = this.config.agencies.find(a => a.id === agencyId);
88
+ if (agency) {
89
+ return {
90
+ agency: agency.id,
91
+ agencyName: agency.name,
92
+ basis: agency.basis,
93
+ dataType,
94
+ ruleVersion: this.config.ruleVersion,
95
+ };
96
+ }
97
+ }
98
+ return {
99
+ agency: null,
100
+ agencyName: this.config.defaultRecommendation.message,
101
+ basis: this.config.defaultRecommendation.basis,
102
+ dataType,
103
+ ruleVersion: this.config.ruleVersion,
104
+ };
105
+ }
106
+ }
107
+ //# sourceMappingURL=registrationNavigationEnhancer.js.map
@@ -0,0 +1,84 @@
1
+ export class ReportGenerator {
2
+ generateMaskingReport(params) {
3
+ const findingsText = Object.keys(params.fieldTypeCounts).length > 0
4
+ ? Object.entries(params.fieldTypeCounts)
5
+ .map(([type, count]) => `发现 ${count} 个${type}类型的敏感数据`)
6
+ .join(';')
7
+ : '无';
8
+ return `【脱敏报告】
9
+ - 处理文件:${params.inputPath}
10
+ - 发现敏感字段:${findingsText}
11
+ - 脱敏策略:${params.strategy}
12
+ - 输出文件:${params.outputPath}
13
+ - 状态:✅ 完成`;
14
+ }
15
+ generateCleaningReport(params) {
16
+ let report = `【数据清洗报告】
17
+ - 文件:${params.inputPath}
18
+ - 原始行数:${params.originalLineCount}
19
+ - 去重后行数:${params.originalLineCount - params.duplicateRemoved}(删除 ${params.duplicateRemoved} 行重复)
20
+ `;
21
+ if (params.standardizeApplied) {
22
+ report += '- 格式标准化:✅ 完成\n';
23
+ }
24
+ report += `- 异常值检测:发现 ${params.anomalyTotalCount} 个异常\n`;
25
+ if (params.anomalies.length > 0) {
26
+ const displayAnomalies = params.anomalies.slice(0, 5);
27
+ const anomalyText = displayAnomalies.map(a => `行${a.line}: ${a.reason}`).join(';');
28
+ report += ` 异常详情:${anomalyText}`;
29
+ if (params.anomalyTotalCount > 5) {
30
+ report += `...等${params.anomalyTotalCount}项`;
31
+ }
32
+ report += '\n';
33
+ }
34
+ report += `- 输出文件:${params.outputPath}\n- 状态:✅ 完成`;
35
+ return report;
36
+ }
37
+ generateInventoryReport(params) {
38
+ let report = `【数据资产盘点报告】\n- 目录:${params.directory}\n- 发现数据文件:${params.fileCount} 个\n\n`;
39
+ report += '| 文件名 | 大小 | 类型 | 价值评估 | 说明 |\n';
40
+ report += '|--------|------|------|----------|------|\n';
41
+ for (const item of params.assetItems) {
42
+ report += `| ${item.fileName} | ${item.size} | ${item.type} | ${item.valueAssessment} | ${item.description} |\n`;
43
+ }
44
+ report += '\n---\n【建议】\n';
45
+ report += '1. 高价值数据(★★★★★)建议优先进行清洗和脱敏后交易\n';
46
+ report += '2. 低价值数据建议评估是否值得投入处理成本\n';
47
+ report += '3. 所有数据交易前必须完成合规审查\n';
48
+ return report;
49
+ }
50
+ generatePackagingManual(params) {
51
+ const manual = params.productManual;
52
+ const complianceText = manual.complianceStatements
53
+ .map(stmt => `✅ ${stmt}`)
54
+ .join('\n');
55
+ return `========================================
56
+ 数据产品说明书
57
+ ========================================
58
+
59
+ 【产品名称】${manual.productName}
60
+ 【版本】${manual.version}
61
+ 【生成日期】${manual.generatedDate}
62
+
63
+ 【数据概览】
64
+ - 源文件:${manual.dataOverview.sourceFile}
65
+ - 数据量:${manual.dataOverview.recordCount} 条记录
66
+ - 文件大小:${manual.dataOverview.fileSizeKb.toFixed(1)} KB
67
+ - 格式:${manual.dataOverview.format}
68
+
69
+ 【数据样例】(前5行)
70
+ ${manual.sampleLines.join('\n')}
71
+
72
+ 【使用场景】
73
+ ${manual.usageScenario}
74
+
75
+ 【合规声明】
76
+ ${complianceText}
77
+
78
+ 【定价建议】
79
+ ${manual.pricingSuggestion}
80
+
81
+ --- 本产品由数据资产化工具包自动生成 ---`;
82
+ }
83
+ }
84
+ //# sourceMappingURL=reportGenerator.js.map
@@ -1,4 +1,4 @@
1
- import type { BusinessRulesConfig } from './types.js';
1
+ import type { BusinessRulesConfig, RegistrationConfig, PolicyReference } from './types.js';
2
2
  export declare const defaultQualityScoringConfig: {
3
3
  weights: {
4
4
  completeness: number;
@@ -136,5 +136,7 @@ export declare const defaultIncrementalSchedulingConfig: {
136
136
  stateFilePath: string;
137
137
  lockTimeout: number;
138
138
  };
139
+ export declare const defaultRegistrationConfig: RegistrationConfig;
140
+ export declare const defaultPolicyReferences: PolicyReference[];
139
141
  export declare const defaultBusinessRules: BusinessRulesConfig;
140
142
  //# sourceMappingURL=defaultBusinessRules.d.ts.map
@@ -9,4 +9,7 @@ export type { MaskingReportParams, CleaningReportParams, InventoryReportParams,
9
9
  export { PathValidator } from './pathValidator.js';
10
10
  export { AuditLogger } from './auditLogger.js';
11
11
  export type { AuditLogParams } from './auditLogger.js';
12
+ export { PolicyReferenceResolver } from './policyReferenceResolver.js';
13
+ export { RegistrationNavigationEnhancer } from './registrationNavigationEnhancer.js';
14
+ export { defaultRegistrationConfig, defaultPolicyReferences, } from './defaultBusinessRules.js';
12
15
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { PolicyStage, PolicyDocument } from './types.js';
2
+ export declare class PolicyReferenceResolver {
3
+ private static instance;
4
+ private cache;
5
+ private references;
6
+ private configPath;
7
+ private constructor();
8
+ static getInstance(configPath?: string): PolicyReferenceResolver;
9
+ private load;
10
+ resolve(stage: PolicyStage): PolicyDocument[];
11
+ clearCache(): void;
12
+ }
13
+ //# sourceMappingURL=policyReferenceResolver.d.ts.map
@@ -0,0 +1,12 @@
1
+ import type { OrchestrationResult, AgencyMatchResult } from './types.js';
2
+ export declare class RegistrationNavigationEnhancer {
3
+ private config;
4
+ private configPath;
5
+ constructor(configPath?: string);
6
+ private loadConfig;
7
+ private matchAgency;
8
+ enhance(report: string, pluginName: string, dataType: string): string;
9
+ enhanceAll(orchestrationResult: OrchestrationResult, dataType: string): OrchestrationResult;
10
+ matchAgencyResult(dataType: string): AgencyMatchResult;
11
+ }
12
+ //# sourceMappingURL=registrationNavigationEnhancer.d.ts.map
@@ -82,6 +82,8 @@ export interface BusinessRulesConfig {
82
82
  visualization?: VisualizationConfig;
83
83
  sensitivityClassification?: SensitivityClassificationConfig;
84
84
  incrementalScheduling?: IncrementalSchedulingConfig;
85
+ registration?: RegistrationConfig;
86
+ policyReferences?: PolicyReference[];
85
87
  }
86
88
  export interface SensitiveField {
87
89
  type: SensitiveFieldType;
@@ -275,4 +277,90 @@ export interface IncrementalSchedulingConfig {
275
277
  stateFilePath: string;
276
278
  lockTimeout: number;
277
279
  }
280
+ export type PolicyStage = 'INVENTORY' | 'CLEANING' | 'MASKING' | 'PACKAGING' | 'PRECHECK' | 'DOC_GENERATION' | 'AGENCY_MATCHING';
281
+ export interface PolicyDocument {
282
+ name: string;
283
+ docNumber: string;
284
+ coreRequirement: string;
285
+ }
286
+ export interface PolicyReference {
287
+ stage: PolicyStage;
288
+ stageLabel: string;
289
+ documents: PolicyDocument[];
290
+ }
291
+ export interface AgencyConfig {
292
+ id: string;
293
+ name: string;
294
+ location: string;
295
+ specialties: string[];
296
+ contact: string;
297
+ basis: string;
298
+ }
299
+ export interface RegistrationConfig {
300
+ ruleVersion: string;
301
+ agencies: AgencyConfig[];
302
+ dataTypeMapping: Record<string, string>;
303
+ defaultRecommendation: {
304
+ agency: string | null;
305
+ basis: string;
306
+ message: string;
307
+ };
308
+ registrationFee: number;
309
+ registrationSteps: string[];
310
+ }
311
+ export interface NavigationField {
312
+ registrationNavigation: string;
313
+ policyReferences: PolicyDocument[];
314
+ }
315
+ export type CheckName = 'NATIONAL_SECURITY' | 'SOURCE_COMPLIANCE' | 'OWNERSHIP_DISPUTE' | 'MATERIAL_AUTHENTICITY';
316
+ export type CheckResult = 'PASS' | 'FAIL' | 'PENDING' | 'UNDETERMINED';
317
+ export type PrecheckConclusion = 'CAN_REGISTER' | 'CANNOT_REGISTER' | 'PENDING_CONFIRMATION';
318
+ export interface PrecheckCheckItem {
319
+ name: CheckName;
320
+ label: string;
321
+ result: CheckResult;
322
+ detail: string;
323
+ }
324
+ export interface PrecheckReport {
325
+ conclusion: PrecheckConclusion;
326
+ checks: PrecheckCheckItem[];
327
+ failedItems: string[];
328
+ policyReferences: PolicyDocument[];
329
+ timestamp: string;
330
+ }
331
+ export type RegistrationDocName = 'DATA_DESCRIPTION' | 'SOURCE_LEGALITY_STATEMENT' | 'OWNERSHIP_EXPLANATION';
332
+ export type DocStatus = 'GENERATED' | 'FAILED' | 'PENDING_FIELDS';
333
+ export interface RegistrationDoc {
334
+ name: RegistrationDocName;
335
+ label: string;
336
+ content: string;
337
+ status: DocStatus;
338
+ missingFields?: string[];
339
+ }
340
+ export interface RegistrationDocPackage {
341
+ docs: RegistrationDoc[];
342
+ packagePath: string;
343
+ policyReferences: PolicyDocument[];
344
+ timestamp: string;
345
+ }
346
+ export interface AgencyMatchResult {
347
+ agency: string | null;
348
+ agencyName: string;
349
+ basis: string;
350
+ dataType: string;
351
+ ruleVersion: string;
352
+ }
353
+ export type StepStatus = 'COMPLETED' | 'CURRENT' | 'PENDING';
354
+ export interface RegistrationStep {
355
+ name: string;
356
+ status: StepStatus;
357
+ description: string;
358
+ }
359
+ export interface RegistrationProgress {
360
+ steps: RegistrationStep[];
361
+ currentStep: number;
362
+ registrationId: string;
363
+ agency: string;
364
+ timestamp: string;
365
+ }
278
366
  //# sourceMappingURL=types.d.ts.map
package/lib/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
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": "2.0.2",
4
+ "version": "3.0.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -26,9 +26,7 @@
26
26
  "./package.json": "./package.json"
27
27
  },
28
28
  "files": [
29
- "lib/index.js",
30
- "lib/invariant.js",
31
- "lib/types/**/*.d.ts"
29
+ "lib/**/*.js", "lib/types/**/*.d.ts"
32
30
  ],
33
31
  "license": "MIT",
34
32
  "scripts": {
@@ -43,5 +41,6 @@
43
41
  "@deepseek-ai/cordis": "^4.0.0",
44
42
  "@deepseek-ai/dsh-tools": "0.0.1-rc.1",
45
43
  "@deepseek-ai/schemastery": "^3.18.0"
46
- }
44
+ },
45
+ "dsh": { "bundle": { "patch": true } }
47
46
  }