dpdp-scanner 1.0.0-test → 1.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,134 @@
1
+ import { Confidence, PiiType } from 'dpdp-india';
2
+ export { Confidence, PiiType } from 'dpdp-india';
3
+
4
+ /** What kind of personal data a field or value is. */
5
+ type Category = "government-id" | "name" | "contact" | "address" | "date-of-birth" | "children" | "demographic" | "financial" | "health" | "biometric" | "location" | "online-identifier";
6
+ /** How much harm a leak would do. Drives the report order and `--fail-on`. */
7
+ type Sensitivity = "high" | "medium" | "low";
8
+ /** Where a schema field was read from. */
9
+ type SchemaSource = "sql" | "prisma" | "graphql" | "django" | "sqlalchemy" | "typeorm" | "mongoose" | "sequelize" | "drizzle" | "rails" | "laravel" | "json-schema" | "openapi";
10
+ /** A field name that looks like personal data, before we know where it is. */
11
+ interface FieldMatch {
12
+ category: Category;
13
+ /** Plain-English name, e.g. "Aadhaar number". */
14
+ label: string;
15
+ sensitivity: Sensitivity;
16
+ confidence: Confidence;
17
+ /** Advice for this kind of data, if any. */
18
+ note?: string;
19
+ }
20
+ /** A column, property or attribute in a schema or model. */
21
+ interface SchemaField {
22
+ /** Table, model, type or schema name, when there is one. */
23
+ table?: string;
24
+ field: string;
25
+ line: number;
26
+ source: SchemaSource;
27
+ }
28
+ /** A schema field that holds personal data. */
29
+ interface FieldFinding extends SchemaField, FieldMatch {
30
+ file: string;
31
+ }
32
+ /** A personal data value written into a file, such as a real-looking Aadhaar number in a fixture. */
33
+ interface ValueFinding {
34
+ file: string;
35
+ line: number;
36
+ column: number;
37
+ type: PiiType;
38
+ category: Category;
39
+ label: string;
40
+ sensitivity: Sensitivity;
41
+ confidence: Confidence;
42
+ /** Masked, never the real value. */
43
+ preview: string;
44
+ }
45
+ interface CategorySummary {
46
+ category: Category;
47
+ label: string;
48
+ sensitivity: Sensitivity;
49
+ fields: number;
50
+ values: number;
51
+ }
52
+ interface Report {
53
+ /** The paths that were scanned. */
54
+ paths: string[];
55
+ /** Files read (binary, oversized and skipped folders don't count). */
56
+ files: number;
57
+ /** Files that contained at least one schema or model. */
58
+ schemaFiles: number;
59
+ fields: FieldFinding[];
60
+ values: ValueFinding[];
61
+ /** One row per category found, most sensitive first. */
62
+ summary: CategorySummary[];
63
+ /** Advice for what was found, one line each. */
64
+ notes: string[];
65
+ }
66
+ interface ScanOptions {
67
+ /** Ignore matches below this confidence. Default "medium". */
68
+ minConfidence?: Confidence;
69
+ /** Look at schemas and models. Default true. */
70
+ schemas?: boolean;
71
+ /** Look for personal data values written in files. Default true. */
72
+ values?: boolean;
73
+ /** Extra folder or file names to skip, on top of node_modules, .git, dist and similar. */
74
+ exclude?: string[];
75
+ /** Skip files larger than this many bytes. Default 2 MB. */
76
+ maxFileSize?: number;
77
+ }
78
+
79
+ /** Folders that hold dependencies, build output or tool caches, never your own data model. */
80
+ declare const SKIP_DIRS: string[];
81
+ /** Find personal data values (Aadhaar, PAN, phone…) written in a piece of text. */
82
+ declare function findValues(text: string, file: string, minConfidence?: Confidence): ValueFinding[];
83
+ /** Find personal data fields in one file's schemas and models. */
84
+ declare function findFields(text: string, file: string, minConfidence?: Confidence): FieldFinding[];
85
+ /** Group findings by category, most sensitive first, and collect the advice that applies. */
86
+ declare function summarize(fields: FieldFinding[], values: ValueFinding[]): Pick<Report, "summary" | "notes">;
87
+ /** Scan files and folders for personal data in schemas, models and file contents. */
88
+ declare function scan(paths: string[], options?: ScanOptions): Promise<Report>;
89
+
90
+ /** Display name and sensitivity for each category. Order = report order (most sensitive first). */
91
+ declare const CATEGORIES: Record<Category, {
92
+ label: string;
93
+ sensitivity: Sensitivity;
94
+ }>;
95
+ /** One line of advice per category, shown once in the report when that category is found. */
96
+ declare const CATEGORY_NOTES: Partial<Record<Category, string>>;
97
+ /** "aadhaarNumber", "AADHAAR_NO", "aadhaar-number" → ["aadhaar", "number"]. */
98
+ declare function words(name: string): string[];
99
+ /**
100
+ * Does this field name look like personal data? Returns what kind, or null.
101
+ * Pass the table or model name too: a bare `name` column only counts in a table of people.
102
+ */
103
+ declare function classifyField(field: string, table?: string): FieldMatch | null;
104
+
105
+ declare function sqlFields(src: string): SchemaField[];
106
+ declare function prismaFields(src: string): SchemaField[];
107
+ declare function graphqlFields(src: string): SchemaField[];
108
+ declare function pythonFields(src: string): SchemaField[];
109
+ declare function jsFields(src: string): SchemaField[];
110
+ declare function railsFields(src: string): SchemaField[];
111
+ declare function laravelFields(src: string): SchemaField[];
112
+ /** Every key under a "properties" object, at any depth. Works for JSON Schema and OpenAPI (JSON). */
113
+ declare function jsonSchemaFields(src: string): SchemaField[];
114
+ /** OpenAPI / JSON Schema written in YAML: keys indented under a `properties:` line. */
115
+ declare function yamlSchemaFields(src: string): SchemaField[];
116
+ /** Pick the right reader for a file. Returns [] for files that don't declare a schema. */
117
+ declare function extractFields(path: string, src: string): SchemaField[];
118
+
119
+ type Format = "table" | "json" | "markdown" | "sarif";
120
+ declare function toTable(report: Report, opts?: {
121
+ limit?: number;
122
+ }): string;
123
+ declare function toJson(report: Report): string;
124
+ /** A personal data inventory you can hand to a DPO, auditor or legal team. */
125
+ declare function toMarkdown(report: Report, opts?: {
126
+ title?: string;
127
+ date?: Date;
128
+ }): string;
129
+ /** SARIF 2.1.0, for GitHub code scanning (Security tab) and other tools that read it. */
130
+ declare function toSarif(report: Report, version?: string): string;
131
+ /** True when the report has findings at `level` sensitivity or above ("any" = anything at all). */
132
+ declare function shouldFail(report: Report, level: Sensitivity | "any"): boolean;
133
+
134
+ export { CATEGORIES, CATEGORY_NOTES, type Category, type CategorySummary, type FieldFinding, type FieldMatch, type Format, type Report, SKIP_DIRS, type ScanOptions, type SchemaField, type SchemaSource, type Sensitivity, type ValueFinding, classifyField, extractFields, findFields, findValues, graphqlFields, jsFields, jsonSchemaFields, laravelFields, prismaFields, pythonFields, railsFields, scan, shouldFail, sqlFields, summarize, toJson, toMarkdown, toSarif, toTable, words, yamlSchemaFields };
@@ -0,0 +1,134 @@
1
+ import { Confidence, PiiType } from 'dpdp-india';
2
+ export { Confidence, PiiType } from 'dpdp-india';
3
+
4
+ /** What kind of personal data a field or value is. */
5
+ type Category = "government-id" | "name" | "contact" | "address" | "date-of-birth" | "children" | "demographic" | "financial" | "health" | "biometric" | "location" | "online-identifier";
6
+ /** How much harm a leak would do. Drives the report order and `--fail-on`. */
7
+ type Sensitivity = "high" | "medium" | "low";
8
+ /** Where a schema field was read from. */
9
+ type SchemaSource = "sql" | "prisma" | "graphql" | "django" | "sqlalchemy" | "typeorm" | "mongoose" | "sequelize" | "drizzle" | "rails" | "laravel" | "json-schema" | "openapi";
10
+ /** A field name that looks like personal data, before we know where it is. */
11
+ interface FieldMatch {
12
+ category: Category;
13
+ /** Plain-English name, e.g. "Aadhaar number". */
14
+ label: string;
15
+ sensitivity: Sensitivity;
16
+ confidence: Confidence;
17
+ /** Advice for this kind of data, if any. */
18
+ note?: string;
19
+ }
20
+ /** A column, property or attribute in a schema or model. */
21
+ interface SchemaField {
22
+ /** Table, model, type or schema name, when there is one. */
23
+ table?: string;
24
+ field: string;
25
+ line: number;
26
+ source: SchemaSource;
27
+ }
28
+ /** A schema field that holds personal data. */
29
+ interface FieldFinding extends SchemaField, FieldMatch {
30
+ file: string;
31
+ }
32
+ /** A personal data value written into a file, such as a real-looking Aadhaar number in a fixture. */
33
+ interface ValueFinding {
34
+ file: string;
35
+ line: number;
36
+ column: number;
37
+ type: PiiType;
38
+ category: Category;
39
+ label: string;
40
+ sensitivity: Sensitivity;
41
+ confidence: Confidence;
42
+ /** Masked, never the real value. */
43
+ preview: string;
44
+ }
45
+ interface CategorySummary {
46
+ category: Category;
47
+ label: string;
48
+ sensitivity: Sensitivity;
49
+ fields: number;
50
+ values: number;
51
+ }
52
+ interface Report {
53
+ /** The paths that were scanned. */
54
+ paths: string[];
55
+ /** Files read (binary, oversized and skipped folders don't count). */
56
+ files: number;
57
+ /** Files that contained at least one schema or model. */
58
+ schemaFiles: number;
59
+ fields: FieldFinding[];
60
+ values: ValueFinding[];
61
+ /** One row per category found, most sensitive first. */
62
+ summary: CategorySummary[];
63
+ /** Advice for what was found, one line each. */
64
+ notes: string[];
65
+ }
66
+ interface ScanOptions {
67
+ /** Ignore matches below this confidence. Default "medium". */
68
+ minConfidence?: Confidence;
69
+ /** Look at schemas and models. Default true. */
70
+ schemas?: boolean;
71
+ /** Look for personal data values written in files. Default true. */
72
+ values?: boolean;
73
+ /** Extra folder or file names to skip, on top of node_modules, .git, dist and similar. */
74
+ exclude?: string[];
75
+ /** Skip files larger than this many bytes. Default 2 MB. */
76
+ maxFileSize?: number;
77
+ }
78
+
79
+ /** Folders that hold dependencies, build output or tool caches, never your own data model. */
80
+ declare const SKIP_DIRS: string[];
81
+ /** Find personal data values (Aadhaar, PAN, phone…) written in a piece of text. */
82
+ declare function findValues(text: string, file: string, minConfidence?: Confidence): ValueFinding[];
83
+ /** Find personal data fields in one file's schemas and models. */
84
+ declare function findFields(text: string, file: string, minConfidence?: Confidence): FieldFinding[];
85
+ /** Group findings by category, most sensitive first, and collect the advice that applies. */
86
+ declare function summarize(fields: FieldFinding[], values: ValueFinding[]): Pick<Report, "summary" | "notes">;
87
+ /** Scan files and folders for personal data in schemas, models and file contents. */
88
+ declare function scan(paths: string[], options?: ScanOptions): Promise<Report>;
89
+
90
+ /** Display name and sensitivity for each category. Order = report order (most sensitive first). */
91
+ declare const CATEGORIES: Record<Category, {
92
+ label: string;
93
+ sensitivity: Sensitivity;
94
+ }>;
95
+ /** One line of advice per category, shown once in the report when that category is found. */
96
+ declare const CATEGORY_NOTES: Partial<Record<Category, string>>;
97
+ /** "aadhaarNumber", "AADHAAR_NO", "aadhaar-number" → ["aadhaar", "number"]. */
98
+ declare function words(name: string): string[];
99
+ /**
100
+ * Does this field name look like personal data? Returns what kind, or null.
101
+ * Pass the table or model name too: a bare `name` column only counts in a table of people.
102
+ */
103
+ declare function classifyField(field: string, table?: string): FieldMatch | null;
104
+
105
+ declare function sqlFields(src: string): SchemaField[];
106
+ declare function prismaFields(src: string): SchemaField[];
107
+ declare function graphqlFields(src: string): SchemaField[];
108
+ declare function pythonFields(src: string): SchemaField[];
109
+ declare function jsFields(src: string): SchemaField[];
110
+ declare function railsFields(src: string): SchemaField[];
111
+ declare function laravelFields(src: string): SchemaField[];
112
+ /** Every key under a "properties" object, at any depth. Works for JSON Schema and OpenAPI (JSON). */
113
+ declare function jsonSchemaFields(src: string): SchemaField[];
114
+ /** OpenAPI / JSON Schema written in YAML: keys indented under a `properties:` line. */
115
+ declare function yamlSchemaFields(src: string): SchemaField[];
116
+ /** Pick the right reader for a file. Returns [] for files that don't declare a schema. */
117
+ declare function extractFields(path: string, src: string): SchemaField[];
118
+
119
+ type Format = "table" | "json" | "markdown" | "sarif";
120
+ declare function toTable(report: Report, opts?: {
121
+ limit?: number;
122
+ }): string;
123
+ declare function toJson(report: Report): string;
124
+ /** A personal data inventory you can hand to a DPO, auditor or legal team. */
125
+ declare function toMarkdown(report: Report, opts?: {
126
+ title?: string;
127
+ date?: Date;
128
+ }): string;
129
+ /** SARIF 2.1.0, for GitHub code scanning (Security tab) and other tools that read it. */
130
+ declare function toSarif(report: Report, version?: string): string;
131
+ /** True when the report has findings at `level` sensitivity or above ("any" = anything at all). */
132
+ declare function shouldFail(report: Report, level: Sensitivity | "any"): boolean;
133
+
134
+ export { CATEGORIES, CATEGORY_NOTES, type Category, type CategorySummary, type FieldFinding, type FieldMatch, type Format, type Report, SKIP_DIRS, type ScanOptions, type SchemaField, type SchemaSource, type Sensitivity, type ValueFinding, classifyField, extractFields, findFields, findValues, graphqlFields, jsFields, jsonSchemaFields, laravelFields, prismaFields, pythonFields, railsFields, scan, shouldFail, sqlFields, summarize, toJson, toMarkdown, toSarif, toTable, words, yamlSchemaFields };