dpdp-kit 0.1.2 → 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 +104 -10
- package/dist/audit.d.ts +1 -1
- package/dist/{chunk-MX5FRZQT.js → chunk-KVTUMHXO.js} +36 -0
- package/dist/cli.js +21 -3
- package/dist/config.d.ts +10 -0
- package/dist/data-access.d.ts +19 -0
- package/dist/dpdp.d.ts +60 -3
- package/dist/drizzle.d.ts +494 -4
- package/dist/drizzle.js +254 -3
- package/dist/erasure.d.ts +2 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +367 -22
- 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 +9 -0
- package/dist/store.d.ts +9 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
- **Declare why you hold each piece of personal data**, in one typed config file. A misspelt purpose is a type error.
|
|
8
8
|
- **Keep consent records that show tampering.** Each person's grants and withdrawals form a hash chain, with the notice version and language they saw.
|
|
9
9
|
- **Know what to erase.** When consent is withdrawn or an account is deleted, get a plan: which fields go, which stay (and why), which tables are under a legal hold, which third parties to tell.
|
|
10
|
-
- **Check it in CI.** `dpdp-kit audit` fails the build when the data map is inconsistent.
|
|
10
|
+
- **Check it in CI.** `dpdp-kit audit` fails the build when the data map is inconsistent, and the GitHub Action puts each problem on the pull request.
|
|
11
11
|
- **Catch drift.** `dpdp-kit audit --schema` reads your Drizzle schema and fails the build when someone adds a `phone`, `email` or `aadhaar_number` column without saying what it's for, or when the data map points at columns that no longer exist. Compliance that can't quietly fall out of date.
|
|
12
12
|
|
|
13
13
|
## Node-native
|
|
@@ -124,14 +124,49 @@ notPersonal: ["products.name", "branches.*"], // database table and column names
|
|
|
124
124
|
|
|
125
125
|
From code, `checkSchema(config, drizzleSchema(schema))` returns the same issues. `drizzleSchema` comes from `dpdp-kit/drizzle`. Matching is by column name, so it can't see personal data hidden inside a JSON column or a vaguely named field. Review those by hand.
|
|
126
126
|
|
|
127
|
+
### In GitHub Actions
|
|
128
|
+
|
|
129
|
+
Add the audit to any workflow. Problems show up as annotations on the pull request, plus a summary on the run page:
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
# .github/workflows/dpdp.yml
|
|
133
|
+
name: DPDP
|
|
134
|
+
on: [pull_request]
|
|
135
|
+
jobs:
|
|
136
|
+
audit:
|
|
137
|
+
runs-on: ubuntu-latest
|
|
138
|
+
steps:
|
|
139
|
+
- uses: actions/checkout@v4
|
|
140
|
+
- uses: actions/setup-node@v4
|
|
141
|
+
with:
|
|
142
|
+
node-version: 22
|
|
143
|
+
- run: npm ci # so your config can import dpdp-kit
|
|
144
|
+
- uses: yogesh2902/dpdp-kit@main
|
|
145
|
+
with:
|
|
146
|
+
schema: src/db/schema.ts # optional: also check for drift
|
|
147
|
+
# config: dpdp.config.ts # default: found automatically
|
|
148
|
+
# strict: true # fail on warnings too
|
|
149
|
+
# working-directory: apps/api # for monorepos
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The Action runs the dpdp-kit your project installed, falling back to `npx dpdp-kit@latest`. It sets `errors` and `warnings` outputs. Annotations need dpdp-kit 0.2.0 or later; with 0.1.x the check still runs and fails the build, without annotations. Outside GitHub, `npx dpdp-kit audit --format github` prints the same annotation lines.
|
|
153
|
+
|
|
127
154
|
## 3. Record consent
|
|
128
155
|
|
|
129
156
|
```ts
|
|
130
157
|
import { createDpdp } from "dpdp-kit";
|
|
131
|
-
import { drizzleStore } from "dpdp-kit/drizzle";
|
|
158
|
+
import { drizzleData, drizzleStore } from "dpdp-kit/drizzle";
|
|
159
|
+
import * as schema from "./db/schema";
|
|
132
160
|
import config from "./dpdp.config";
|
|
133
161
|
|
|
134
|
-
export const dpdp = createDpdp({
|
|
162
|
+
export const dpdp = createDpdp({
|
|
163
|
+
config,
|
|
164
|
+
store: drizzleStore(db), // consent records, rights requests, erasure tasks
|
|
165
|
+
data: drizzleData(db, { schema }), // reads and erases personal data in your own tables
|
|
166
|
+
processors: { // optional: tell third parties to stop or erase
|
|
167
|
+
msg91: { stop: ({ subjectId }) => msg91.optOut(subjectId), erase: ({ subjectId }) => msg91.deleteContact(subjectId) },
|
|
168
|
+
},
|
|
169
|
+
});
|
|
135
170
|
|
|
136
171
|
await dpdp.consent.grant(userId, ["marketing_sms", "analytics"], {
|
|
137
172
|
noticeVersion: "2026-11",
|
|
@@ -173,9 +208,63 @@ await dpdp.erasure.plan(userId, { reason: "account-deletion" });
|
|
|
173
208
|
|
|
174
209
|
**"Erase" is not "delete this second".** Every plan carries `minimumRetention` from your config. Under Rule 8(3), stop using the data now, keep a restricted copy only for the Seventh Schedule purposes, and delete it once a year has passed since its last processing. The Rule's own example is an e-book platform that keeps order details and logs for a year "even if X deletes her account".
|
|
175
210
|
|
|
176
|
-
|
|
211
|
+
### Carrying it out
|
|
212
|
+
|
|
213
|
+
`withdraw()` schedules the plan as dated tasks, and `erasure.deleteAccount(userId)` plans and schedules an account deletion. Then run the retention runner on a schedule; once a day is plenty:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
const report = await dpdp.retention.run(); // { done, failed, manual }
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
| Task | When it runs | What it does |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| `processor-stop` | straight away | calls the processor's `stop` hook (Section 6(6)) |
|
|
222
|
+
| `erase-fields` | after `minimumRetention` (and `afterWithdrawal`) | sets the fields to `NULL` in the person's rows |
|
|
223
|
+
| `delete-rows` | after `minimumRetention` | deletes the person's rows (account deletion) |
|
|
224
|
+
| held table | after the legal hold (`keep`) | then anonymises (`NULL`s) or deletes, as `then` says |
|
|
225
|
+
| `processor-erase` | after `minimumRetention` | calls the processor's `erase` hook (Section 8(7)(b)) |
|
|
226
|
+
|
|
227
|
+
- **Safe to run from several servers.** Each task is claimed atomically, so it runs once.
|
|
228
|
+
- **Failures are retried**, up to 5 times. `lastError` keeps the database's message for developers, for example when a column is `NOT NULL`.
|
|
229
|
+
- **A processor with no hook** gives a `manual` task. Handle it yourself (email their support), then `retention.markDone(taskId, "ticket 4411")`.
|
|
230
|
+
- **Consent records are never erased.** Section 6(10) makes you prove consent, and Rule 8(3) requires keeping records of processing.
|
|
231
|
+
- **Erasure sets columns to `NULL`**, so erasable columns must be nullable. Data access currently covers Postgres.
|
|
232
|
+
|
|
233
|
+
## 5. Rights requests
|
|
177
234
|
|
|
178
|
-
|
|
235
|
+
People can ask to see their data (Section 11), correct or erase it (Section 12), raise a grievance (Section 13) or name a nominee (Section 14). Each request is recorded with a due date:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const request = await dpdp.rights.open(userId, "grievance", { text: "I keep getting promo SMS" });
|
|
239
|
+
// request.dueAt is 90 days out: Rule 14(3) caps grievance responses at ninety days
|
|
240
|
+
|
|
241
|
+
await dpdp.rights.list({ overdue: true }); // your inbox of late answers
|
|
242
|
+
await dpdp.rights.resolve(request.id, "Promo SMS turned off");
|
|
243
|
+
await dpdp.rights.reject(otherId, "Duplicate of an earlier grievance");
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Access (Section 11):** `summary()` reads the person's personal fields from your tables, with the purposes each is held for, their consents, and the processors their data goes to:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
const summary = await dpdp.rights.summary(userId);
|
|
250
|
+
// { data: [{ table: "users", fields: [...], rows: [{ phone: "98…", name: "Asha" }] }],
|
|
251
|
+
// consents: ["order_updates"], legitimateUses: ["account"],
|
|
252
|
+
// sharedWith: [{ name: "msg91", purposes: ["order_updates"] }] }
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**Erasure (Section 12(3)):** every purpose ends except those you still need for the specified purpose. Legal holds and `minimumRetention` still apply:
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
await dpdp.rights.erase(userId, { keepFor: ["account"], requestId: request.id }); // schedules, resolves the request
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Corrections and nominations are recorded with the request (`details`); your app applies them, then calls `resolve()`. Set your own answer times in the config. The Rules set ninety days for grievances only, and the audit fails above that:
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
rights: { responseWithin: { grievance: "30d", access: "30d" } },
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## 6. Guard routes
|
|
179
268
|
|
|
180
269
|
```ts
|
|
181
270
|
// Express
|
|
@@ -193,18 +282,22 @@ Without consent, the middleware responds `403 { error: "consent_required", purpo
|
|
|
193
282
|
|
|
194
283
|
### Drizzle (Postgres)
|
|
195
284
|
|
|
196
|
-
Add the
|
|
285
|
+
Add the tables to your schema so drizzle-kit creates them:
|
|
197
286
|
|
|
198
287
|
```ts
|
|
199
288
|
// schema.ts
|
|
200
|
-
export { consentEvents } from "dpdp-kit/drizzle";
|
|
289
|
+
export { consentEvents, erasureTasks, rightsRequests } from "dpdp-kit/drizzle";
|
|
201
290
|
```
|
|
202
291
|
|
|
203
|
-
If you don't use drizzle-kit, run `
|
|
292
|
+
If you don't use drizzle-kit, run `DPDP_DDL` (exported from `dpdp-kit/drizzle`). This works with any Drizzle Postgres driver: node-postgres, postgres.js, Neon, PGlite.
|
|
293
|
+
|
|
294
|
+
> **Upgrading from 0.1.x?** Add `rightsRequests` and `erasureTasks` to your schema and generate a migration, or run `RECORDS_DDL`. `withdraw()` now schedules erasure tasks, so it needs the `dpdp_erasure_tasks` table.
|
|
295
|
+
|
|
296
|
+
`drizzleData(db, { schema })` reaches your own tables. Pass your schema module when the data map uses Drizzle property names (`userId`) rather than column names (`user_id`).
|
|
204
297
|
|
|
205
298
|
### Anything else
|
|
206
299
|
|
|
207
|
-
Implement `
|
|
300
|
+
Implement `DpdpStore`: consent events (`lastEvent`, `insert`, `events`), requests and tasks (see `RequestStore` and `TaskStore`). `insert` must throw `SeqConflictError` on a duplicate `(subjectId, seq)`, and `claimTask` must be atomic. A store with only the three consent methods still works for consent; rights and retention then throw `store-unsupported`. Implement `DataAccess` (`read`, `eraseFields`, `deleteRows`) for another database. `memoryStore()` and `memoryData()` are included for tests.
|
|
208
301
|
|
|
209
302
|
## How the consent record works
|
|
210
303
|
|
|
@@ -221,7 +314,8 @@ Section 6(10) puts the burden on you: if consent is questioned in a proceeding,
|
|
|
221
314
|
|---|---|
|
|
222
315
|
| **v0.1** | Config and types, `audit` + CLI, consent records, erasure plans, Drizzle store, Express/Hono guards |
|
|
223
316
|
| **v0.1.2** | Schema drift check: `audit --schema`, `checkSchema`, `drizzleSchema`, `notPersonal` |
|
|
224
|
-
| v0.2 |
|
|
317
|
+
| **v0.2.0** | Rights requests (Sections 11–14, Rule 14), retention runner that carries out erasure (Section 8(7), Rule 8(3), legal holds), processor hooks, `drizzleData`, GitHub Action with pull request annotations |
|
|
318
|
+
| later | Recording objections to a Section 7(a) use, React notice that meets Rule 3 + privacy centre, MySQL and SQLite data access |
|
|
225
319
|
| v0.3 | Breach records with deadlines (Section 8(6), Rule 7: people and the Board without delay, detailed report to the Board within 72 hours), children and guardian consent (Section 9, Rule 10), inactivity erasure with 48 hours' warning for large e-commerce, gaming and social media platforms (Rule 8(1)–(2), Third Schedule), Consent Manager interop (Sections 6(7)–6(9), Rule 4), Prisma store |
|
|
226
320
|
|
|
227
321
|
## When the Rules apply
|
package/dist/audit.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { DpdpConfig } from "./config.js";
|
|
|
2
2
|
export type IssueLevel = "error" | "warning";
|
|
3
3
|
export interface Issue {
|
|
4
4
|
level: IssueLevel;
|
|
5
|
-
code: "no-purposes" | "invalid-basis" | "invalid-retention" | "invalid-duration" | "unknown-purpose" | "field-without-purpose" | "table-without-fields" | "missing-subject-column" | "unused-purpose" | "minimum-retention-missing" | "minimum-retention-too-short" | "grievance-missing" | "fiduciary-missing" | "invalid-not-personal" | "unknown-table" | "unknown-column" | "unmapped-personal-column" | "stale-not-personal";
|
|
5
|
+
code: "no-purposes" | "invalid-basis" | "invalid-retention" | "invalid-duration" | "unknown-purpose" | "field-without-purpose" | "table-without-fields" | "missing-subject-column" | "unused-purpose" | "minimum-retention-missing" | "minimum-retention-too-short" | "grievance-missing" | "fiduciary-missing" | "invalid-not-personal" | "unknown-table" | "unknown-column" | "unmapped-personal-column" | "stale-not-personal" | "grievance-response-too-long" | "invalid-request-type";
|
|
6
6
|
/** Where in the config (`data.users.fields.phone`), or in the schema (`schema.users.phone`). */
|
|
7
7
|
path: string;
|
|
8
8
|
message: string;
|
|
@@ -15,6 +15,16 @@ function maxDuration(a, b) {
|
|
|
15
15
|
return durationMs(b) > durationMs(a) ? b : a;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
// src/records.ts
|
|
19
|
+
var REQUEST_TYPES = ["access", "correction", "erasure", "grievance", "nomination"];
|
|
20
|
+
function isRunnable(task, { now, staleBefore, maxAttempts }) {
|
|
21
|
+
if (task.dueAt > now) return false;
|
|
22
|
+
if (task.status === "pending") return true;
|
|
23
|
+
if (task.status === "failed") return task.attempts < maxAttempts;
|
|
24
|
+
if (task.status === "running") return (task.claimedAt ?? "") < staleBefore;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
// src/audit.ts
|
|
19
29
|
var ONE_YEAR_MS = durationMs("1y");
|
|
20
30
|
function checkRetention(retain, path, issues) {
|
|
@@ -157,6 +167,30 @@ function audit(config) {
|
|
|
157
167
|
});
|
|
158
168
|
}
|
|
159
169
|
}
|
|
170
|
+
const within = config.rights?.responseWithin;
|
|
171
|
+
if (within !== void 0) {
|
|
172
|
+
const entries = typeof within === "string" ? [["", within]] : Object.entries(within);
|
|
173
|
+
for (const [type, value] of entries) {
|
|
174
|
+
const path = type ? `rights.responseWithin.${type}` : "rights.responseWithin";
|
|
175
|
+
if (type && !REQUEST_TYPES.includes(type)) {
|
|
176
|
+
issues.push({
|
|
177
|
+
level: "error",
|
|
178
|
+
code: "invalid-request-type",
|
|
179
|
+
path,
|
|
180
|
+
message: `Unknown request type. Use one of: ${REQUEST_TYPES.join(", ")}.`
|
|
181
|
+
});
|
|
182
|
+
} else if (!isDuration(value)) {
|
|
183
|
+
issues.push({ level: "error", code: "invalid-duration", path, message: `${JSON.stringify(value)} is not a duration. Use e.g. "30d".` });
|
|
184
|
+
} else if ((type === "" || type === "grievance") && durationMs(value) > durationMs("90d")) {
|
|
185
|
+
issues.push({
|
|
186
|
+
level: "error",
|
|
187
|
+
code: "grievance-response-too-long",
|
|
188
|
+
path,
|
|
189
|
+
message: 'Rule 14(3) of the DPDP Rules requires answering grievances within ninety days. Use at most "90d".'
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
160
194
|
const minimum = config.minimumRetention;
|
|
161
195
|
if (minimum === void 0) {
|
|
162
196
|
issues.push({
|
|
@@ -447,6 +481,8 @@ export {
|
|
|
447
481
|
isDuration,
|
|
448
482
|
durationMs,
|
|
449
483
|
maxDuration,
|
|
484
|
+
REQUEST_TYPES,
|
|
485
|
+
isRunnable,
|
|
450
486
|
audit,
|
|
451
487
|
hasErrors,
|
|
452
488
|
tokenize,
|
package/dist/cli.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
audit,
|
|
4
4
|
checkSchema
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-KVTUMHXO.js";
|
|
6
6
|
|
|
7
7
|
// src/run-audit.ts
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
|
-
import { resolve } from "path";
|
|
9
|
+
import { relative, resolve } from "path";
|
|
10
10
|
import { pathToFileURL } from "url";
|
|
11
11
|
var CONFIG_FILES = ["dpdp.config.ts", "dpdp.config.mts", "dpdp.config.js", "dpdp.config.mjs"];
|
|
12
12
|
function findConfig(cwd, explicit) {
|
|
@@ -39,6 +39,15 @@ function formatIssues(issues) {
|
|
|
39
39
|
lines.push("", `${errors.length} error(s), ${warnings.length} warning(s)`);
|
|
40
40
|
return lines.join("\n");
|
|
41
41
|
}
|
|
42
|
+
var escapeData = (text) => text.replace(/%/g, "%25").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
|
|
43
|
+
var escapeProperty = (text) => escapeData(text).replace(/:/g, "%3A").replace(/,/g, "%2C");
|
|
44
|
+
function formatGithubAnnotations(issues, files, root) {
|
|
45
|
+
return issues.map((issue) => {
|
|
46
|
+
const file = issue.path.startsWith("schema.") && files.schema ? files.schema : files.config;
|
|
47
|
+
const props = [`file=${escapeProperty(relative(root, file))}`, `title=${escapeProperty(`dpdp-kit: ${issue.path}`)}`];
|
|
48
|
+
return `::${issue.level} ${props.join(",")}::${escapeData(issue.message)}`;
|
|
49
|
+
}).join("\n");
|
|
50
|
+
}
|
|
42
51
|
async function loadDrizzleSchema(file) {
|
|
43
52
|
const mod = await loadModule(file);
|
|
44
53
|
let drizzleSchema;
|
|
@@ -61,6 +70,11 @@ async function runAudit(argv, cwd, log) {
|
|
|
61
70
|
const explicit = flagValue(argv, "--config");
|
|
62
71
|
const schemaFlag = flagValue(argv, "--schema");
|
|
63
72
|
const strict = argv.includes("--strict");
|
|
73
|
+
const format = flagValue(argv, "--format") ?? "text";
|
|
74
|
+
if (format !== "text" && format !== "github") {
|
|
75
|
+
log(`Unknown --format ${JSON.stringify(format)}. Use "text" or "github".`);
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
64
78
|
const file = findConfig(cwd, explicit);
|
|
65
79
|
if (!file || !existsSync(file)) {
|
|
66
80
|
log(explicit ? `Config file not found: ${explicit}` : `No config found. Create one of: ${CONFIG_FILES.join(", ")}`);
|
|
@@ -74,6 +88,9 @@ async function runAudit(argv, cwd, log) {
|
|
|
74
88
|
const config = await loadConfig(file);
|
|
75
89
|
const issues = audit(config);
|
|
76
90
|
if (schemaFile) issues.push(...checkSchema(config, await loadDrizzleSchema(schemaFile)));
|
|
91
|
+
if (format === "github" && issues.length > 0) {
|
|
92
|
+
log(formatGithubAnnotations(issues, { config: file, schema: schemaFile }, process.env.GITHUB_WORKSPACE ?? cwd));
|
|
93
|
+
}
|
|
77
94
|
log(formatIssues(issues));
|
|
78
95
|
const failing = issues.filter((i) => i.level === "error" || strict && i.level === "warning");
|
|
79
96
|
return failing.length > 0 ? 1 : 0;
|
|
@@ -83,7 +100,7 @@ async function runAudit(argv, cwd, log) {
|
|
|
83
100
|
var HELP = `dpdp-kit \u2014 DPDP Act tooling for Node.js
|
|
84
101
|
|
|
85
102
|
Usage:
|
|
86
|
-
dpdp-kit audit [--config <file>] [--schema <file>] [--strict]
|
|
103
|
+
dpdp-kit audit [--config <file>] [--schema <file>] [--strict] [--format text|github]
|
|
87
104
|
|
|
88
105
|
Checks your data map and purposes. With --schema, also compares the data map with your
|
|
89
106
|
Drizzle schema: personal-looking columns missing from the map, and map entries that no
|
|
@@ -93,6 +110,7 @@ Options:
|
|
|
93
110
|
--config <file> Config file (default: dpdp.config.ts / .mts / .js / .mjs)
|
|
94
111
|
--schema <file> Drizzle schema file (Postgres, MySQL or SQLite), e.g. src/db/schema.ts
|
|
95
112
|
--strict Fail on warnings too
|
|
113
|
+
--format github Also print GitHub Actions annotations, so problems show on the pull request
|
|
96
114
|
`;
|
|
97
115
|
var [command, ...rest] = process.argv.slice(2);
|
|
98
116
|
if (command === "audit") {
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Duration } from "./duration.js";
|
|
2
|
+
import type { RequestType } from "./records.js";
|
|
2
3
|
/**
|
|
3
4
|
* Why you may process data for a purpose.
|
|
4
5
|
* - `"consent"`: the person agreed (Section 6(1)). They can withdraw at any time, as easily as
|
|
@@ -63,6 +64,14 @@ export interface ProcessorDef<P extends string = string> {
|
|
|
63
64
|
purposes: readonly P[];
|
|
64
65
|
description?: string;
|
|
65
66
|
}
|
|
67
|
+
export interface RightsConfig {
|
|
68
|
+
/**
|
|
69
|
+
* How long you give yourself to answer a rights request, from when it's raised. One duration for
|
|
70
|
+
* every type, or one per type. Default `"90d"`. Rule 14(3) of the DPDP Rules caps grievance
|
|
71
|
+
* responses at ninety days; the Rules set no period for the other types, so pick one you can keep.
|
|
72
|
+
*/
|
|
73
|
+
responseWithin?: Duration | Partial<Record<RequestType, Duration>>;
|
|
74
|
+
}
|
|
66
75
|
export interface FiduciaryDef {
|
|
67
76
|
name: string;
|
|
68
77
|
/**
|
|
@@ -97,6 +106,7 @@ export interface DpdpConfig<P extends string = string> {
|
|
|
97
106
|
* or `"products.*"` for a whole table. Use database table and column names.
|
|
98
107
|
*/
|
|
99
108
|
notPersonal?: readonly string[];
|
|
109
|
+
rights?: RightsConfig;
|
|
100
110
|
}
|
|
101
111
|
/** Purpose names of a config, e.g. `"account" | "marketing_sms"`. */
|
|
102
112
|
export type PurposeOf<C> = C extends DpdpConfig<infer P> ? P : never;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How dpdp-kit reaches the personal data in your own tables: to show a person what you hold
|
|
3
|
+
* (Section 11) and to carry out erasure (Section 8(7)). Names are as written in the data map
|
|
4
|
+
* (`config.data[...].table`, `subject` and field names); an implementation maps them to columns.
|
|
5
|
+
*/
|
|
6
|
+
export interface DataAccess {
|
|
7
|
+
/** The person's rows, with only the listed columns. */
|
|
8
|
+
read(table: string, subjectColumn: string, subjectId: string, columns: readonly string[]): Promise<Record<string, unknown>[]>;
|
|
9
|
+
/** Set the listed columns to null in the person's rows. Returns rows changed. */
|
|
10
|
+
eraseFields(table: string, subjectColumn: string, subjectId: string, columns: readonly string[]): Promise<number>;
|
|
11
|
+
/** Delete the person's rows. Returns rows deleted. */
|
|
12
|
+
deleteRows(table: string, subjectColumn: string, subjectId: string): Promise<number>;
|
|
13
|
+
}
|
|
14
|
+
type Row = Record<string, unknown>;
|
|
15
|
+
/** Data access over plain arrays, for tests and examples. */
|
|
16
|
+
export declare function memoryData(tables: Record<string, Row[]>): DataAccess & {
|
|
17
|
+
readonly tables: Record<string, Row[]>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
package/dist/dpdp.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import type { DpdpConfig } from "./config.js";
|
|
2
|
+
import type { DataAccess } from "./data-access.js";
|
|
2
3
|
import { type ErasurePlan } from "./erasure.js";
|
|
3
4
|
import { type NoticeLanguage } from "./languages.js";
|
|
4
|
-
import type
|
|
5
|
+
import { type ErasureTask, type RequestFilter, type RequestType, type RightsRequest, type TaskFilter } from "./records.js";
|
|
6
|
+
import { type ProcessorHooks, type RunReport } from "./retention.js";
|
|
7
|
+
import { type AccessSummary } from "./rights.js";
|
|
8
|
+
import { type ConsentEvent, type ConsentStore } from "./store.js";
|
|
5
9
|
export interface ConsentMeta {
|
|
6
10
|
noticeVersion?: string;
|
|
7
11
|
language?: NoticeLanguage;
|
|
@@ -19,7 +23,15 @@ export type VerifyResult = {
|
|
|
19
23
|
};
|
|
20
24
|
export interface DpdpOptions<P extends string> {
|
|
21
25
|
config: DpdpConfig<P>;
|
|
26
|
+
/** `memoryStore()`, `drizzleStore(db)`, or your own. Rights and retention need a full `DpdpStore`. */
|
|
22
27
|
store: ConsentStore;
|
|
28
|
+
/**
|
|
29
|
+
* How to reach the personal data in your tables, for access summaries and erasure:
|
|
30
|
+
* `drizzleData(db)` from `dpdp-kit/drizzle`, or your own `DataAccess`.
|
|
31
|
+
*/
|
|
32
|
+
data?: DataAccess;
|
|
33
|
+
/** Hooks for each processor in `config.processors`, to stop or erase on their side. */
|
|
34
|
+
processors?: Partial<Record<string, ProcessorHooks>>;
|
|
23
35
|
/** Clock, for tests. */
|
|
24
36
|
now?: () => Date;
|
|
25
37
|
/** Attempts when two writes for the same person race. Default 5. */
|
|
@@ -31,12 +43,13 @@ export interface Dpdp<P extends string> {
|
|
|
31
43
|
/** Record that the person agreed to these consent purposes. */
|
|
32
44
|
grant(subjectId: string, purposes: readonly P[], meta?: ConsentMeta): Promise<ConsentEvent>;
|
|
33
45
|
/**
|
|
34
|
-
* Record that the person withdrew consent. Returns
|
|
35
|
-
*
|
|
46
|
+
* Record that the person withdrew consent. Returns the erasure plan and, when the store keeps
|
|
47
|
+
* tasks, schedules it: `retention.run()` carries the tasks out when they're due.
|
|
36
48
|
*/
|
|
37
49
|
withdraw(subjectId: string, purposes: readonly P[], meta?: ConsentMeta): Promise<{
|
|
38
50
|
event: ConsentEvent;
|
|
39
51
|
erasure: ErasurePlan;
|
|
52
|
+
tasks: ErasureTask[];
|
|
40
53
|
}>;
|
|
41
54
|
/**
|
|
42
55
|
* Whether you hold consent, or don't need it, for this purpose. For consent purposes: true when
|
|
@@ -56,6 +69,50 @@ export interface Dpdp<P extends string> {
|
|
|
56
69
|
plan(subjectId: string, input: {
|
|
57
70
|
reason: "account-deletion";
|
|
58
71
|
}): Promise<ErasurePlan>;
|
|
72
|
+
/** Turn a plan into dated tasks for `retention.run()`. */
|
|
73
|
+
schedule(plan: ErasurePlan): Promise<ErasureTask[]>;
|
|
74
|
+
/** Plan and schedule erasure for a deleted account. */
|
|
75
|
+
deleteAccount(subjectId: string): Promise<{
|
|
76
|
+
plan: ErasurePlan;
|
|
77
|
+
tasks: ErasureTask[];
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
readonly retention: {
|
|
81
|
+
/**
|
|
82
|
+
* Carry out every due erasure task: null out or delete rows through `data`, and call processor
|
|
83
|
+
* hooks. Run it on a schedule (a daily cron is plenty). Safe to run from several processes.
|
|
84
|
+
*/
|
|
85
|
+
run(input?: {
|
|
86
|
+
limit?: number;
|
|
87
|
+
}): Promise<RunReport>;
|
|
88
|
+
tasks(filter?: TaskFilter): Promise<ErasureTask[]>;
|
|
89
|
+
/** Mark a `manual` or `failed` task as handled by a person. */
|
|
90
|
+
markDone(taskId: string, note: string): Promise<ErasureTask>;
|
|
91
|
+
};
|
|
92
|
+
readonly rights: {
|
|
93
|
+
/** Record a request (Sections 11–14). It's due after `config.rights.responseWithin` (default 90 days). */
|
|
94
|
+
open(subjectId: string, type: RequestType, details?: Record<string, unknown>): Promise<RightsRequest>;
|
|
95
|
+
get(id: string): Promise<RightsRequest | undefined>;
|
|
96
|
+
/** Requests, oldest first. `overdue: true` gives open requests past their due date. */
|
|
97
|
+
list(filter?: RequestFilter & {
|
|
98
|
+
overdue?: boolean;
|
|
99
|
+
}): Promise<RightsRequest[]>;
|
|
100
|
+
resolve(id: string, note?: string): Promise<RightsRequest>;
|
|
101
|
+
reject(id: string, reason: string): Promise<RightsRequest>;
|
|
102
|
+
/** What you hold about the person and who you shared it with (Section 11(1)). Needs `data`. */
|
|
103
|
+
summary(subjectId: string): Promise<AccessSummary>;
|
|
104
|
+
/**
|
|
105
|
+
* Erase on request (Section 12(3)): every purpose ends except those in `keepFor`, which you still
|
|
106
|
+
* need for the specified purpose. Legal holds and `minimumRetention` still apply. Pass the
|
|
107
|
+
* request id to resolve it.
|
|
108
|
+
*/
|
|
109
|
+
erase(subjectId: string, input?: {
|
|
110
|
+
keepFor?: readonly P[];
|
|
111
|
+
requestId?: string;
|
|
112
|
+
}): Promise<{
|
|
113
|
+
plan: ErasurePlan;
|
|
114
|
+
tasks: ErasureTask[];
|
|
115
|
+
}>;
|
|
59
116
|
};
|
|
60
117
|
}
|
|
61
118
|
type HashedFields = Omit<ConsentEvent, "hash">;
|