dpdp-kit 0.1.1 → 0.2.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 +138 -11
- package/dist/audit.d.ts +2 -2
- package/dist/chunk-KVTUMHXO.js +491 -0
- package/dist/cli.js +61 -9
- package/dist/config.d.ts +15 -0
- package/dist/data-access.d.ts +19 -0
- package/dist/dpdp.d.ts +60 -3
- package/dist/drizzle.d.ts +505 -4
- package/dist/drizzle.js +268 -3
- package/dist/erasure.d.ts +2 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +375 -24
- package/dist/personal.d.ts +17 -0
- package/dist/records.d.ts +124 -0
- package/dist/retention.d.ts +47 -0
- package/dist/rights.d.ts +49 -0
- package/dist/run-audit.d.ts +12 -0
- package/dist/schema-check.d.ts +22 -0
- package/dist/store.d.ts +9 -2
- package/package.json +1 -1
- package/dist/chunk-HRKHRKV4.js +0 -185
package/dist/rights.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Category, DpdpConfig } from "./config.js";
|
|
2
|
+
import type { DataAccess } from "./data-access.js";
|
|
3
|
+
import { type Duration } from "./duration.js";
|
|
4
|
+
import type { RequestType } from "./records.js";
|
|
5
|
+
/** Default answer time: Rule 14(3) caps grievance responses at ninety days. */
|
|
6
|
+
export declare const DEFAULT_RESPONSE_WITHIN: Duration;
|
|
7
|
+
export declare function responseWithin(config: DpdpConfig<string>, type: RequestType): Duration;
|
|
8
|
+
export declare function dueAt(config: DpdpConfig<string>, type: RequestType, openedAt: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* What a person gets back from an access request (Section 11(1)): (a) the personal data you
|
|
11
|
+
* process and why, and (b) who else it was shared with.
|
|
12
|
+
*/
|
|
13
|
+
export interface AccessSummary {
|
|
14
|
+
subjectId: string;
|
|
15
|
+
generatedAt: string;
|
|
16
|
+
data: Array<{
|
|
17
|
+
/** Key in `config.data`. */
|
|
18
|
+
key: string;
|
|
19
|
+
table: string;
|
|
20
|
+
fields: Array<{
|
|
21
|
+
field: string;
|
|
22
|
+
category: Category;
|
|
23
|
+
purposes: string[];
|
|
24
|
+
}>;
|
|
25
|
+
/** The person's rows, personal fields only. */
|
|
26
|
+
rows: Record<string, unknown>[];
|
|
27
|
+
}>;
|
|
28
|
+
/** Consent purposes currently granted. */
|
|
29
|
+
consents: string[];
|
|
30
|
+
/** Legitimate-use purposes that apply without consent (Section 7). */
|
|
31
|
+
legitimateUses: string[];
|
|
32
|
+
/**
|
|
33
|
+
* Processors that receive data for a purpose that applies to this person (Section 11(1)(b)).
|
|
34
|
+
* Section 11(2) exempts sharing with authorities for preventing or investigating offences;
|
|
35
|
+
* leave those out of `config.processors`.
|
|
36
|
+
*/
|
|
37
|
+
sharedWith: Array<{
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
purposes: string[];
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
export declare function buildAccessSummary(input: {
|
|
44
|
+
config: DpdpConfig<string>;
|
|
45
|
+
data: DataAccess;
|
|
46
|
+
subjectId: string;
|
|
47
|
+
consents: string[];
|
|
48
|
+
now: string;
|
|
49
|
+
}): Promise<AccessSummary>;
|
package/dist/run-audit.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { type Issue } from "./audit.js";
|
|
2
2
|
import type { DpdpConfig } from "./config.js";
|
|
3
|
+
import { type Schema } from "./schema-check.js";
|
|
3
4
|
export declare const CONFIG_FILES: string[];
|
|
4
5
|
export declare function findConfig(cwd: string, explicit?: string): string | undefined;
|
|
5
6
|
/** Load a config file (TypeScript or JavaScript). Accepts a default export or `export const config`. */
|
|
6
7
|
export declare function loadConfig(file: string): Promise<DpdpConfig<string>>;
|
|
7
8
|
export declare function formatIssues(issues: readonly Issue[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* GitHub Actions workflow commands, so each problem shows as an annotation on the pull request.
|
|
11
|
+
* Schema issues point at the schema file and the rest at the config file, relative to the
|
|
12
|
+
* repository root (`GITHUB_WORKSPACE`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatGithubAnnotations(issues: readonly Issue[], files: {
|
|
15
|
+
config: string;
|
|
16
|
+
schema?: string | undefined;
|
|
17
|
+
}, root: string): string;
|
|
18
|
+
/** Load a Drizzle schema file and read its tables. */
|
|
19
|
+
export declare function loadDrizzleSchema(file: string): Promise<Schema>;
|
|
8
20
|
/** Run `dpdp-kit audit`. Returns the exit code: 1 when there are errors (or `--strict` and warnings). */
|
|
9
21
|
export declare function runAudit(argv: readonly string[], cwd: string, log: (line: string) => void): Promise<number>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Issue } from "./audit.js";
|
|
2
|
+
import type { DpdpConfig } from "./config.js";
|
|
3
|
+
/** A column as your ORM sees it: its database name, and the property name in code if different. */
|
|
4
|
+
export interface SchemaColumn {
|
|
5
|
+
name: string;
|
|
6
|
+
key?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SchemaTable {
|
|
9
|
+
name: string;
|
|
10
|
+
columns: readonly SchemaColumn[];
|
|
11
|
+
}
|
|
12
|
+
/** Your database schema in a neutral shape. `drizzleSchema()` builds one from a Drizzle schema. */
|
|
13
|
+
export interface Schema {
|
|
14
|
+
tables: readonly SchemaTable[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Compare the data map with the real schema, both ways:
|
|
18
|
+
* - columns that look personal but aren't in the data map (strong guesses are errors, weak ones
|
|
19
|
+
* warnings), so a new `phone` column can't ship without a purpose;
|
|
20
|
+
* - data map entries whose table or column no longer exists, so the map can't go stale.
|
|
21
|
+
*/
|
|
22
|
+
export declare function checkSchema(config: DpdpConfig<string>, schema: Schema): Issue[];
|
package/dist/store.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NoticeLanguage } from "./languages.js";
|
|
2
|
+
import { type ErasureTask, type RequestStore, type RightsRequest, type TaskStore } from "./records.js";
|
|
2
3
|
export type ConsentAction = "grant" | "withdraw";
|
|
3
4
|
/** One entry in a person's consent record. Entries are only ever added, never changed. */
|
|
4
5
|
export interface ConsentEvent {
|
|
@@ -32,7 +33,13 @@ export interface ConsentStore {
|
|
|
32
33
|
/** All events for a subject, oldest first. */
|
|
33
34
|
events(subjectId: string): Promise<ConsentEvent[]>;
|
|
34
35
|
}
|
|
35
|
-
/**
|
|
36
|
-
export
|
|
36
|
+
/** A store that also keeps rights requests and erasure tasks. Both built-in stores are one. */
|
|
37
|
+
export type DpdpStore = ConsentStore & RequestStore & TaskStore;
|
|
38
|
+
/** Whether a store can keep rights requests and erasure tasks too (custom stores may not). */
|
|
39
|
+
export declare function isDpdpStore(store: ConsentStore): store is DpdpStore;
|
|
40
|
+
/** Keeps everything in memory. For tests and trying the library out; everything is lost on restart. */
|
|
41
|
+
export declare function memoryStore(): DpdpStore & {
|
|
37
42
|
readonly all: Map<string, ConsentEvent[]>;
|
|
43
|
+
readonly requests: Map<string, RightsRequest>;
|
|
44
|
+
readonly tasks: Map<string, ErasureTask>;
|
|
38
45
|
};
|
package/package.json
CHANGED
package/dist/chunk-HRKHRKV4.js
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
// src/duration.ts
|
|
2
|
-
var PATTERN = /^(\d+)(h|d|y)$/;
|
|
3
|
-
var HOUR_MS = 60 * 60 * 1e3;
|
|
4
|
-
var UNIT_MS = { h: HOUR_MS, d: 24 * HOUR_MS, y: 365 * 24 * HOUR_MS };
|
|
5
|
-
function isDuration(value) {
|
|
6
|
-
return typeof value === "string" && PATTERN.test(value);
|
|
7
|
-
}
|
|
8
|
-
function durationMs(value) {
|
|
9
|
-
const match = PATTERN.exec(value);
|
|
10
|
-
if (!match) throw new TypeError(`Not a duration: ${JSON.stringify(value)} (use e.g. "48h", "30d", "1y")`);
|
|
11
|
-
const [, amount, unit] = match;
|
|
12
|
-
return Number(amount) * UNIT_MS[unit];
|
|
13
|
-
}
|
|
14
|
-
function maxDuration(a, b) {
|
|
15
|
-
return durationMs(b) > durationMs(a) ? b : a;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// src/audit.ts
|
|
19
|
-
var ONE_YEAR_MS = durationMs("1y");
|
|
20
|
-
function checkRetention(retain, path, issues) {
|
|
21
|
-
if (retain === "while-active" || isDuration(retain)) return;
|
|
22
|
-
if (retain && typeof retain === "object" && "afterWithdrawal" in retain) {
|
|
23
|
-
if (!isDuration(retain.afterWithdrawal)) {
|
|
24
|
-
issues.push({
|
|
25
|
-
level: "error",
|
|
26
|
-
code: "invalid-duration",
|
|
27
|
-
path: `${path}.afterWithdrawal`,
|
|
28
|
-
message: `${JSON.stringify(retain.afterWithdrawal)} is not a duration. Use e.g. "0d", "30d", "1y".`
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
issues.push({
|
|
34
|
-
level: "error",
|
|
35
|
-
code: "invalid-retention",
|
|
36
|
-
path,
|
|
37
|
-
message: `Retention must be "while-active", a duration like "1y", or { afterWithdrawal: "30d" }.`
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function checkPurposeList(purposes, known, used, path, issues) {
|
|
41
|
-
if (!purposes || purposes.length === 0) {
|
|
42
|
-
issues.push({
|
|
43
|
-
level: "error",
|
|
44
|
-
code: "field-without-purpose",
|
|
45
|
-
path: `${path}.purposes`,
|
|
46
|
-
message: "List at least one purpose. Personal data with no purpose must not be collected."
|
|
47
|
-
});
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
for (const p of purposes) {
|
|
51
|
-
used.add(p);
|
|
52
|
-
if (!known.has(p)) {
|
|
53
|
-
issues.push({
|
|
54
|
-
level: "error",
|
|
55
|
-
code: "unknown-purpose",
|
|
56
|
-
path: `${path}.purposes`,
|
|
57
|
-
message: `Unknown purpose ${JSON.stringify(p)}. Declare it under \`purposes\` or fix the spelling.`
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function audit(config) {
|
|
63
|
-
const issues = [];
|
|
64
|
-
const purposes = config.purposes ?? {};
|
|
65
|
-
const known = new Set(Object.keys(purposes));
|
|
66
|
-
const used = /* @__PURE__ */ new Set();
|
|
67
|
-
if (!config.fiduciary?.name) {
|
|
68
|
-
issues.push({
|
|
69
|
-
level: "error",
|
|
70
|
-
code: "fiduciary-missing",
|
|
71
|
-
path: "fiduciary.name",
|
|
72
|
-
message: "Name the Data Fiduciary (your organisation). It appears on every notice."
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (!config.fiduciary?.grievanceUrl) {
|
|
76
|
-
issues.push({
|
|
77
|
-
level: "warning",
|
|
78
|
-
code: "grievance-missing",
|
|
79
|
-
path: "fiduciary.grievanceUrl",
|
|
80
|
-
message: "Add where people can raise a grievance. Section 8(10) requires a grievance mechanism, and Section 5(1)(ii) requires the notice to say how to use it."
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (known.size === 0) {
|
|
84
|
-
issues.push({ level: "error", code: "no-purposes", path: "purposes", message: "Declare at least one purpose." });
|
|
85
|
-
}
|
|
86
|
-
for (const [name, def] of Object.entries(purposes)) {
|
|
87
|
-
const path = `purposes.${name}`;
|
|
88
|
-
if (def.basis !== "consent" && def.basis !== "legitimate-use") {
|
|
89
|
-
issues.push({
|
|
90
|
-
level: "error",
|
|
91
|
-
code: "invalid-basis",
|
|
92
|
-
path: `${path}.basis`,
|
|
93
|
-
message: `Basis must be "consent" or "legitimate-use".`
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
checkRetention(def.retain, `${path}.retain`, issues);
|
|
97
|
-
if (def.basis === "legitimate-use" && typeof def.retain === "object") {
|
|
98
|
-
issues.push({
|
|
99
|
-
level: "error",
|
|
100
|
-
code: "invalid-retention",
|
|
101
|
-
path: `${path}.retain`,
|
|
102
|
-
message: 'afterWithdrawal only applies to consent purposes (Section 6(4)). Use "while-active" or a duration for a legitimate use.'
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
for (const [key, table] of Object.entries(config.data ?? {})) {
|
|
107
|
-
const path = `data.${key}`;
|
|
108
|
-
if (!table.subject) {
|
|
109
|
-
issues.push({
|
|
110
|
-
level: "error",
|
|
111
|
-
code: "missing-subject-column",
|
|
112
|
-
path: `${path}.subject`,
|
|
113
|
-
message: "Name the column that holds the person's id, so their rows can be found."
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const fields = Object.entries(table.fields ?? {});
|
|
117
|
-
if (fields.length === 0) {
|
|
118
|
-
issues.push({
|
|
119
|
-
level: "warning",
|
|
120
|
-
code: "table-without-fields",
|
|
121
|
-
path: `${path}.fields`,
|
|
122
|
-
message: "No personal fields listed. Remove the table from the map, or list its fields."
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
for (const [field, def] of fields) {
|
|
126
|
-
checkPurposeList(def.purposes, known, used, `${path}.fields.${field}`, issues);
|
|
127
|
-
}
|
|
128
|
-
if (table.legalHold && !isDuration(table.legalHold.keep)) {
|
|
129
|
-
issues.push({
|
|
130
|
-
level: "error",
|
|
131
|
-
code: "invalid-duration",
|
|
132
|
-
path: `${path}.legalHold.keep`,
|
|
133
|
-
message: `${JSON.stringify(table.legalHold.keep)} is not a duration. Use e.g. "8y".`
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
for (const [name, processor] of Object.entries(config.processors ?? {})) {
|
|
138
|
-
checkPurposeList(processor.purposes, known, used, `processors.${name}`, issues);
|
|
139
|
-
}
|
|
140
|
-
for (const name of known) {
|
|
141
|
-
if (!used.has(name)) {
|
|
142
|
-
issues.push({
|
|
143
|
-
level: "warning",
|
|
144
|
-
code: "unused-purpose",
|
|
145
|
-
path: `purposes.${name}`,
|
|
146
|
-
message: "No field or processor uses this purpose. Remove it, or map the data it covers."
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
const minimum = config.minimumRetention;
|
|
151
|
-
if (minimum === void 0) {
|
|
152
|
-
issues.push({
|
|
153
|
-
level: "warning",
|
|
154
|
-
code: "minimum-retention-missing",
|
|
155
|
-
path: "minimumRetention",
|
|
156
|
-
message: 'Set minimumRetention. Rule 8(3) of the DPDP Rules requires keeping personal data, traffic data and logs of each processing for at least one year from the processing ("1y").'
|
|
157
|
-
});
|
|
158
|
-
} else if (!isDuration(minimum)) {
|
|
159
|
-
issues.push({
|
|
160
|
-
level: "error",
|
|
161
|
-
code: "invalid-duration",
|
|
162
|
-
path: "minimumRetention",
|
|
163
|
-
message: `${JSON.stringify(minimum)} is not a duration. Use e.g. "1y".`
|
|
164
|
-
});
|
|
165
|
-
} else if (durationMs(minimum) < ONE_YEAR_MS) {
|
|
166
|
-
issues.push({
|
|
167
|
-
level: "error",
|
|
168
|
-
code: "minimum-retention-too-short",
|
|
169
|
-
path: "minimumRetention",
|
|
170
|
-
message: 'Rule 8(3) of the DPDP Rules requires keeping personal data, traffic data and logs of each processing for at least one year. Use at least "1y".'
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return issues;
|
|
174
|
-
}
|
|
175
|
-
function hasErrors(issues) {
|
|
176
|
-
return issues.some((i) => i.level === "error");
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export {
|
|
180
|
-
isDuration,
|
|
181
|
-
durationMs,
|
|
182
|
-
maxDuration,
|
|
183
|
-
audit,
|
|
184
|
-
hasErrors
|
|
185
|
-
};
|