@liuhange/dsh-data-sensitivity-classification 2.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.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @liuhange/dsh-data-sensitivity-classification
2
+
3
+ 数据敏感度自动分级插件:自动识别数据字段敏感度等级(公开/内部/机密/绝密),并推荐相应脱敏策略。
4
+
5
+ ## Tool 接口
6
+
7
+ ### `classify_sensitivity`
8
+
9
+ 自动识别数据文件中各字段的敏感度等级,生成分级报告和脱敏策略推荐。
10
+
11
+ **参数:**
12
+ - `filePath` (string, 必填): 待分级数据文件路径
13
+ - `outputPathDir` (string, 可选): 报告输出目录,默认数据文件所在目录
14
+ - `sampleSize` (string, 可选): 样本大小,默认 100
15
+
16
+ **输出:?**
17
+ - `classification_report.json`: 分级 JSON 报告
18
+ - `classification_report.md`: 分级 Markdown 报告(首行 `【数据敏感度分级报告】`)
19
+
20
+ ## 敏感度等级
21
+
22
+ | 等级 | 说明 | 推荐策略 |
23
+ |------|------|---------|
24
+ | Public | 公开 | none(不脱敏) |
25
+ | Internal | 内部 | partial(部分脱敏) |
26
+ | Confidential | 机密 | full(完全脱敏) |
27
+ | Secret | 绝密 | encrypt(加密脱敏) |
28
+
29
+ ## 识别方法
30
+
31
+ 1. 字段名模式匹配:根据字段名正&则表达式匹配
32
+ 2. 字段值样本匹配:字段名未匹配时,取前 N 个样本值匹配正则
33
+ 3. 均未匹配时使用默认等级(Internal)
34
+
35
+ ## 配置节点
36
+
37
+ `business-rules.json` → `sensitivityClassification` 节点。缺失时使用默认规则。正则编译失败的规则自动跳过并记录。
38
+
39
+ ## v1.0 兼容性
40
+
41
+ 本插件为 v2.0 新增,不影响 v1.0 功能。配置缺失时降级到默认分级规则。
@@ -0,0 +1,6 @@
1
+ import type { ClassificationReportJson, InvalidRule } from './types.js';
2
+ export declare class ClassificationReportGenerator {
3
+ writeJson(filePath: string, data: ClassificationReportJson): Promise<void>;
4
+ writeMarkdown(filePath: string, data: ClassificationReportJson, invalidRules: InvalidRule[]): Promise<void>;
5
+ }
6
+ //# sourceMappingURL=classificationReportGenerator.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { SensitivityClassificationConfig } from '@liuhange/dsh-data-asset-shared';
2
+ export declare const defaultClassificationRules: SensitivityClassificationConfig;
3
+ //# sourceMappingURL=defaultClassificationRules.d.ts.map
@@ -0,0 +1,9 @@
1
+ import type { SensitivityClassificationConfig } from '@liuhange/dsh-data-asset-shared';
2
+ import type { MatchResult, InvalidRule } from './types.js';
3
+ export declare class FieldNameMatcher {
4
+ match(fieldName: string, rules: SensitivityClassificationConfig['fieldNameRules']): {
5
+ result: MatchResult;
6
+ invalidRules: InvalidRule[];
7
+ };
8
+ }
9
+ //# sourceMappingURL=fieldNameMatcher.d.ts.map
@@ -0,0 +1,9 @@
1
+ import type { SensitivityClassificationConfig } from '@liuhange/dsh-data-asset-shared';
2
+ import type { MatchResult, InvalidRule } from './types.js';
3
+ export declare class FieldValueMatcher {
4
+ match(sampleValues: unknown[], rules: SensitivityClassificationConfig['fieldValueRules']): {
5
+ result: MatchResult;
6
+ invalidRules: InvalidRule[];
7
+ };
8
+ }
9
+ //# sourceMappingURL=fieldValueMatcher.d.ts.map
@@ -0,0 +1,5 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
2
+ export declare const name = "data-sensitivity-classification";
3
+ export declare const inject: string[];
4
+ export declare function apply(ctx: Context): void;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export declare const invariant = "data-sensitivity-classification";
2
+ export declare function install(): void;
3
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1,11 @@
1
+ import type { SensitivityClassificationConfig } from '@liuhange/dsh-data-asset-shared';
2
+ import type { FieldClassification, InvalidRule } from './types.js';
3
+ export declare class SensitivityClassifier {
4
+ private fieldNameMatcher;
5
+ private fieldValueMatcher;
6
+ classify(fields: string[], fieldSamples: Record<string, unknown[]>, config: SensitivityClassificationConfig): {
7
+ classifications: FieldClassification[];
8
+ invalidRules: InvalidRule[];
9
+ };
10
+ }
11
+ //# sourceMappingURL=sensitivityClassifier.d.ts.map
@@ -0,0 +1,6 @@
1
+ import type { SensitivityClassificationConfig } from '@liuhange/dsh-data-asset-shared';
2
+ import type { SensitivityLevel, RecommendedStrategy } from './types.js';
3
+ export declare class StrategyRecommender {
4
+ recommend(level: SensitivityLevel, levelMapping: SensitivityClassificationConfig['levelMapping']): RecommendedStrategy;
5
+ }
6
+ //# sourceMappingURL=strategyRecommender.d.ts.map
@@ -0,0 +1,40 @@
1
+ export type SensitivityLevel = 'Public' | 'Internal' | 'Confidential' | 'Secret';
2
+ export type RecommendedStrategy = 'none' | 'partial' | 'full' | 'encrypt';
3
+ export interface ClassifySensitivityParams {
4
+ filePath: string;
5
+ outputPathDir?: string;
6
+ sampleSize?: number;
7
+ }
8
+ export interface MatchResult {
9
+ matched: boolean;
10
+ name?: string;
11
+ pattern?: string;
12
+ level?: string;
13
+ }
14
+ export interface InvalidRule {
15
+ ruleName: string;
16
+ reason: string;
17
+ }
18
+ export interface FieldClassification {
19
+ fieldName: string;
20
+ sensitivityLevel: SensitivityLevel;
21
+ identifiedBy: {
22
+ ruleName: string;
23
+ matchType: string;
24
+ };
25
+ recommendedStrategy: RecommendedStrategy;
26
+ }
27
+ export interface ClassificationReportJson {
28
+ fields: FieldClassification[];
29
+ configStatus: string;
30
+ classifiedAt: string;
31
+ }
32
+ export interface ClassifySensitivityResult {
33
+ jsonReportPath: string;
34
+ markdownReportPath: string;
35
+ report: ClassificationReportJson;
36
+ fields: FieldClassification[];
37
+ status: 'SUCCESS' | 'FAILED';
38
+ configStatus: string;
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@liuhange/dsh-data-sensitivity-classification",
3
+ "description": "Data sensitivity classification plugin: auto-identify sensitivity levels (Public/Internal/Confidential/Secret) and recommend masking strategies",
4
+ "version": "2.0.0",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/liuhange789/data-asset-inspector.git",
11
+ "directory": "packages/data-asset/data-sensitivity-classification"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./src/*": "./src/*",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "lib/index.js",
30
+ "lib/invariant.js",
31
+ "lib/types/**/*.d.ts"
32
+ ],
33
+ "license": "MIT",
34
+ "peerDependencies": {
35
+ "@deepseek-ai/cordis": "^0.1.0",
36
+ "@deepseek-ai/dsh-tools": "^0.1.0",
37
+ "@liuhange/dsh-data-asset-shared": "^2.0.0"
38
+ }
39
+ }