dpdp-kit 0.2.0 → 0.3.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/dist/cli.js CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  audit,
4
- checkSchema
5
- } from "./chunk-KVTUMHXO.js";
4
+ checkSchema,
5
+ formatSafeguards,
6
+ safeguardsReport
7
+ } from "./chunk-YOEAZX65.js";
8
+ import "./chunk-67Q5GFD6.js";
6
9
 
7
10
  // src/run-audit.ts
8
11
  import { existsSync } from "fs";
@@ -66,8 +69,14 @@ var flagValue = (argv, flag) => {
66
69
  const i = argv.indexOf(flag);
67
70
  return i >= 0 ? argv[i + 1] : void 0;
68
71
  };
69
- async function runAudit(argv, cwd, log) {
72
+ function configFile(argv, cwd, log) {
70
73
  const explicit = flagValue(argv, "--config");
74
+ const file = findConfig(cwd, explicit);
75
+ if (file && existsSync(file)) return file;
76
+ log(explicit ? `Config file not found: ${explicit}` : `No config found. Create one of: ${CONFIG_FILES.join(", ")}`);
77
+ return void 0;
78
+ }
79
+ async function runAudit(argv, cwd, log) {
71
80
  const schemaFlag = flagValue(argv, "--schema");
72
81
  const strict = argv.includes("--strict");
73
82
  const format = flagValue(argv, "--format") ?? "text";
@@ -75,11 +84,8 @@ async function runAudit(argv, cwd, log) {
75
84
  log(`Unknown --format ${JSON.stringify(format)}. Use "text" or "github".`);
76
85
  return 1;
77
86
  }
78
- const file = findConfig(cwd, explicit);
79
- if (!file || !existsSync(file)) {
80
- log(explicit ? `Config file not found: ${explicit}` : `No config found. Create one of: ${CONFIG_FILES.join(", ")}`);
81
- return 1;
82
- }
87
+ const file = configFile(argv, cwd, log);
88
+ if (!file) return 1;
83
89
  const schemaFile = schemaFlag ? resolve(cwd, schemaFlag) : void 0;
84
90
  if (schemaFile && !existsSync(schemaFile)) {
85
91
  log(`Schema file not found: ${schemaFlag}`);
@@ -95,12 +101,21 @@ async function runAudit(argv, cwd, log) {
95
101
  const failing = issues.filter((i) => i.level === "error" || strict && i.level === "warning");
96
102
  return failing.length > 0 ? 1 : 0;
97
103
  }
104
+ async function runSafeguards(argv, cwd, log) {
105
+ const file = configFile(argv, cwd, log);
106
+ if (!file) return 1;
107
+ const report = safeguardsReport(await loadConfig(file));
108
+ log(formatSafeguards(report));
109
+ const gaps = report.some((s) => s.status === "missing" || s.status === "partly");
110
+ return argv.includes("--strict") && gaps ? 1 : 0;
111
+ }
98
112
 
99
113
  // src/cli.ts
100
114
  var HELP = `dpdp-kit \u2014 DPDP Act tooling for Node.js
101
115
 
102
116
  Usage:
103
117
  dpdp-kit audit [--config <file>] [--schema <file>] [--strict] [--format text|github]
118
+ dpdp-kit safeguards [--config <file>] [--strict]
104
119
 
105
120
  Checks your data map and purposes. With --schema, also compares the data map with your
106
121
  Drizzle schema: personal-looking columns missing from the map, and map entries that no
@@ -111,10 +126,15 @@ Options:
111
126
  --schema <file> Drizzle schema file (Postgres, MySQL or SQLite), e.g. src/db/schema.ts
112
127
  --strict Fail on warnings too
113
128
  --format github Also print GitHub Actions annotations, so problems show on the pull request
129
+
130
+ safeguards reports each security safeguard of Rule 6(1), (a) to (g): what your config records
131
+ and what's missing. With --strict, exits 1 when one is missing.
114
132
  `;
115
133
  var [command, ...rest] = process.argv.slice(2);
116
- if (command === "audit") {
117
- runAudit(rest, process.cwd(), (line) => console.log(line)).then(
134
+ var commands = { audit: runAudit, safeguards: runSafeguards };
135
+ var run = command !== void 0 && Object.hasOwn(commands, command) ? commands[command] : void 0;
136
+ if (run) {
137
+ run(rest, process.cwd(), (line) => console.log(line)).then(
118
138
  (code) => {
119
139
  process.exitCode = code;
120
140
  },
package/dist/config.d.ts CHANGED
@@ -34,12 +34,50 @@ export interface PurposeDef {
34
34
  }
35
35
  /** Kind of personal data. Free text is allowed; these are the common ones. */
36
36
  export type Category = "contact" | "identity" | "financial" | "health" | "location" | "device" | "biometric" | "behavioural" | (string & {});
37
+ /**
38
+ * How a field is protected where it's stored. Rule 6(1)(a) of the DPDP Rules lists "encryption,
39
+ * obfuscation, masking or the use of virtual tokens mapped to that personal data" as safeguards.
40
+ * - `"encrypted"`: stored encrypted (e.g. with `createEncryptor` from `dpdp-kit/protect`).
41
+ * - `"tokenised"`: replaced by a token that maps to the value kept elsewhere (a vault).
42
+ * - `"masked"`: only a masked form is stored (e.g. the last four digits of an Aadhaar number).
43
+ * - `"hashed"`: only a keyed hash is stored, for matching (e.g. `createTokenizer`).
44
+ */
45
+ export type Protection = "encrypted" | "tokenised" | "masked" | "hashed";
46
+ /** A value a field can be set to when it's erased. */
47
+ export type ErasedValue = string | number | boolean | null;
48
+ /** Text written by `erase: "redact"`. */
49
+ export declare const REDACTED = "[erased]";
50
+ /**
51
+ * What a field becomes when it's erased. Default `"null"`.
52
+ * - `"null"`: set to `NULL`. The column must be nullable.
53
+ * - `"redact"`: set to the text `"[erased]"`, for `NOT NULL` text columns.
54
+ * - `{ value }`: a fixed value, or a function of the person and field, for columns with other
55
+ * constraints, e.g. a `NOT NULL UNIQUE` email:
56
+ * `{ value: ({ subjectId }) => \`erased-${subjectId}@invalid\` }`.
57
+ *
58
+ * The replacement must not identify the person: use their internal id, never a hash of their data.
59
+ */
60
+ export type EraseWith = "null" | "redact" | {
61
+ value: ErasedValue | ((field: {
62
+ subjectId: string;
63
+ table: string;
64
+ field: string;
65
+ }) => ErasedValue);
66
+ };
37
67
  export interface PersonalField<P extends string = string> {
38
68
  category: Category;
39
69
  /** Every purpose this field is held for. When all of them end, the field must go. */
40
70
  purposes: readonly P[];
41
71
  /** This field can tell you the person is under 18 (e.g. date of birth). Used from v0.3. */
42
72
  childSignal?: boolean;
73
+ /**
74
+ * How the field is protected at rest (Rule 6(1)(a)). The audit warns when a high-risk
75
+ * identifier (Aadhaar, PAN, passport, bank account, card number, health or biometric data)
76
+ * has none.
77
+ */
78
+ protect?: Protection;
79
+ /** What the field becomes when it's erased. Default `"null"`. See `EraseWith`. */
80
+ erase?: EraseWith;
43
81
  }
44
82
  /**
45
83
  * Another law says you must keep these rows (e.g. tax or KYC records). Section 8(7) requires
@@ -63,6 +101,29 @@ export interface TableDef<P extends string = string> {
63
101
  export interface ProcessorDef<P extends string = string> {
64
102
  purposes: readonly P[];
65
103
  description?: string;
104
+ /**
105
+ * Where your contract with this processor requires reasonable security safeguards, e.g.
106
+ * `"DPA signed 2026-03-01, clause 7"`. Rule 6(1)(f) requires such a provision. The audit warns
107
+ * when it's missing.
108
+ */
109
+ contract?: string;
110
+ }
111
+ /**
112
+ * The security safeguards of Rule 6(1) that live outside your code, written down as evidence.
113
+ * Describe what you actually do, in a sentence; the audit warns about any you leave out.
114
+ */
115
+ export interface SecurityConfig {
116
+ /** Rule 6(1)(b): how access to your computer resources is controlled, e.g. `"SSO, least-privilege IAM roles"`. */
117
+ accessControl?: string;
118
+ /** Rule 6(1)(d): how processing continues after a compromise, e.g. `"Daily encrypted backups, restore tested monthly"`. */
119
+ backups?: string;
120
+ /** Rule 6(1)(g): technical and organisational measures, e.g. `"Annual security training, quarterly access reviews"`. */
121
+ measures?: string;
122
+ /**
123
+ * Rule 6(1)(c) and (e): how long the access log (`dpdp.access`) is kept. Default and minimum
124
+ * `"1y"`: the Rule requires a year of logs to detect and investigate unauthorised access.
125
+ */
126
+ accessLogRetention?: Duration;
66
127
  }
67
128
  export interface RightsConfig {
68
129
  /**
@@ -107,6 +168,8 @@ export interface DpdpConfig<P extends string = string> {
107
168
  */
108
169
  notPersonal?: readonly string[];
109
170
  rights?: RightsConfig;
171
+ /** Security safeguards under Rule 6(1). See `SecurityConfig`. */
172
+ security?: SecurityConfig;
110
173
  }
111
174
  /** Purpose names of a config, e.g. `"account" | "marketing_sms"`. */
112
175
  export type PurposeOf<C> = C extends DpdpConfig<infer P> ? P : never;
@@ -116,3 +179,9 @@ export type PurposeOf<C> = C extends DpdpConfig<infer P> ? P : never;
116
179
  */
117
180
  export declare function defineConfig<const P extends string>(config: DpdpConfig<P>): DpdpConfig<P>;
118
181
  export declare function purposeNames<P extends string>(config: DpdpConfig<P>): P[];
182
+ /** The value a field is set to when it's erased, from its `erase` setting. */
183
+ export declare function erasedValue(erase: EraseWith | undefined, field: {
184
+ subjectId: string;
185
+ table: string;
186
+ field: string;
187
+ }): ErasedValue;
@@ -1,3 +1,4 @@
1
+ import type { ErasedValue } from "./config.js";
1
2
  /**
2
3
  * How dpdp-kit reaches the personal data in your own tables: to show a person what you hold
3
4
  * (Section 11) and to carry out erasure (Section 8(7)). Names are as written in the data map
@@ -6,8 +7,11 @@
6
7
  export interface DataAccess {
7
8
  /** The person's rows, with only the listed columns. */
8
9
  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>;
10
+ /**
11
+ * Erase the listed columns in the person's rows: set each to its value in `values`, or to null
12
+ * when it has none (the field's `erase` setting in the config). Returns rows changed.
13
+ */
14
+ eraseFields(table: string, subjectColumn: string, subjectId: string, columns: readonly string[], values?: Readonly<Record<string, ErasedValue>>): Promise<number>;
11
15
  /** Delete the person's rows. Returns rows deleted. */
12
16
  deleteRows(table: string, subjectColumn: string, subjectId: string): Promise<number>;
13
17
  }
package/dist/dpdp.d.ts CHANGED
@@ -1,5 +1,7 @@
1
+ import { type AccessAction, type AccessEntry, type AccessFilter, type AccessReview } from "./access.js";
1
2
  import type { DpdpConfig } from "./config.js";
2
3
  import type { DataAccess } from "./data-access.js";
4
+ import { type Duration } from "./duration.js";
3
5
  import { type ErasurePlan } from "./erasure.js";
4
6
  import { type NoticeLanguage } from "./languages.js";
5
7
  import { type ErasureTask, type RequestFilter, type RequestType, type RightsRequest, type TaskFilter } from "./records.js";
@@ -21,6 +23,86 @@ export type VerifyResult = {
21
23
  brokenAt: number;
22
24
  reason: "hash-mismatch" | "chain-broken" | "seq-gap";
23
25
  };
26
+ export interface AccessInput<P extends string> {
27
+ /** Who is accessing the data: a staff user's id, a service or job name. */
28
+ actor: string;
29
+ /** Whose data. Pass `subjectIds` instead for a list or an export. */
30
+ subjectId?: string;
31
+ subjectIds?: readonly string[];
32
+ /** Why: one of your purposes. */
33
+ purpose: P;
34
+ /** Default `"read"`. */
35
+ action?: AccessAction;
36
+ /**
37
+ * What is accessed, as data map keys: `"users.phone"`, or `"users"` / `"users.*"` for every
38
+ * personal field of a table. Fields not held for `purpose` are recorded as `outOfPurpose`.
39
+ */
40
+ fields?: readonly string[];
41
+ /** Free text, e.g. a support ticket number. */
42
+ reason?: string;
43
+ /** Details of the request, e.g. IP address, user agent, request id. */
44
+ evidence?: Record<string, string>;
45
+ }
46
+ export interface AccessOptions {
47
+ /**
48
+ * What to do when a log entry reads fields that aren't held for its purpose. `"record"` (default)
49
+ * logs it with `outOfPurpose` for `review()` to report; `"throw"` logs it, then throws
50
+ * `DpdpError("out-of-purpose")` so the caller can refuse.
51
+ */
52
+ outOfPurpose?: "record" | "throw";
53
+ }
54
+ /** What each event carries. Events fire after the change is saved. */
55
+ export interface DpdpEvents {
56
+ "consent.granted": {
57
+ event: ConsentEvent;
58
+ };
59
+ "consent.withdrawn": {
60
+ event: ConsentEvent;
61
+ erasure: ErasurePlan;
62
+ tasks: ErasureTask[];
63
+ };
64
+ "erasure.scheduled": {
65
+ plan: ErasurePlan;
66
+ tasks: ErasureTask[];
67
+ };
68
+ "retention.ran": {
69
+ report: RunReport;
70
+ };
71
+ "rights.opened": {
72
+ request: RightsRequest;
73
+ };
74
+ "rights.closed": {
75
+ request: RightsRequest;
76
+ };
77
+ "access.logged": {
78
+ entries: AccessEntry[];
79
+ };
80
+ "daily.ran": {
81
+ report: DailyReport;
82
+ };
83
+ }
84
+ /** What `daily()` did. A part the store can't do (a custom store without the access log) is listed in `skipped`. */
85
+ export interface DailyReport {
86
+ /** When the run started (ISO 8601). */
87
+ at: string;
88
+ /** Erasure tasks carried out by `retention.run()`. */
89
+ retention?: RunReport;
90
+ /** Access log entries older than the retention period, deleted by `access.prune()`. */
91
+ accessPruned?: number;
92
+ /** `access.review()` of the last day. */
93
+ review?: AccessReview;
94
+ /** Open rights requests past their due date. */
95
+ overdueRequests?: RightsRequest[];
96
+ skipped: Array<"retention" | "access" | "rights">;
97
+ /** Steps that failed. The other steps still ran. */
98
+ errors: Array<{
99
+ step: "retention" | "rights" | "access-prune" | "access-review";
100
+ message: string;
101
+ error: unknown;
102
+ }>;
103
+ }
104
+ export type DpdpEventName = keyof DpdpEvents;
105
+ export type DpdpListener<E extends DpdpEventName> = (payload: DpdpEvents[E]) => void | Promise<void>;
24
106
  export interface DpdpOptions<P extends string> {
25
107
  config: DpdpConfig<P>;
26
108
  /** `memoryStore()`, `drizzleStore(db)`, or your own. Rights and retention need a full `DpdpStore`. */
@@ -36,9 +118,41 @@ export interface DpdpOptions<P extends string> {
36
118
  now?: () => Date;
37
119
  /** Attempts when two writes for the same person race. Default 5. */
38
120
  maxRetries?: number;
121
+ /** Access log behaviour. See `AccessOptions`. */
122
+ access?: AccessOptions;
123
+ /**
124
+ * Called when an event listener throws or rejects. Listeners never break the operation that
125
+ * fired them. Default: `console.error`.
126
+ */
127
+ onListenerError?: (error: unknown, event: DpdpEventName) => void;
39
128
  }
40
129
  export interface Dpdp<P extends string> {
41
130
  readonly config: DpdpConfig<P>;
131
+ /**
132
+ * Listen for an event, e.g. to feed your own audit trail, alerts or analytics. Listeners run after
133
+ * the change is saved, don't delay the call that fired them, and can't make it fail. Returns a
134
+ * function that removes the listener.
135
+ *
136
+ * ```ts
137
+ * dpdp.on("consent.withdrawn", ({ event }) => analytics.forget(event.subjectId, event.purposes));
138
+ * ```
139
+ */
140
+ on<E extends DpdpEventName>(event: E, listener: DpdpListener<E>): () => void;
141
+ /**
142
+ * The daily upkeep in one call: carry out due erasure (`retention.run()`), prune access logs past
143
+ * their retention (`access.prune()`), review the last day of access (`access.review()`), and list
144
+ * overdue rights requests. Run it once a day: from `startDaily()` in `dpdp-kit/schedule`, node-cron,
145
+ * a BullMQ repeatable job, or your platform's cron. Safe to run from several servers at once.
146
+ */
147
+ daily(input?: {
148
+ review?: {
149
+ /** Start of the review (ISO 8601). Default: a day before now. Pass the end of the last successful review so no day is missed. */
150
+ from?: string;
151
+ window?: Duration;
152
+ maxSubjects?: number;
153
+ ignoreActors?: readonly string[];
154
+ };
155
+ }): Promise<DailyReport>;
42
156
  readonly consent: {
43
157
  /** Record that the person agreed to these consent purposes. */
44
158
  grant(subjectId: string, purposes: readonly P[], meta?: ConsentMeta): Promise<ConsentEvent>;
@@ -89,6 +203,38 @@ export interface Dpdp<P extends string> {
89
203
  /** Mark a `manual` or `failed` task as handled by a person. */
90
204
  markDone(taskId: string, note: string): Promise<ErasureTask>;
91
205
  };
206
+ readonly access: {
207
+ /**
208
+ * Record that someone accessed a person's personal data, and why (Rule 6(1)(c)). One entry per
209
+ * person. Needs a store that keeps the access log: `memoryStore()`, `drizzleStore(db)`, or your
210
+ * own `AccessLogStore`.
211
+ */
212
+ log(input: AccessInput<P>): Promise<AccessEntry[]>;
213
+ /** Entries matching the filter, oldest first: for investigating a person, an actor, or a period. */
214
+ list(filter?: AccessFilter): Promise<AccessEntry[]>;
215
+ /**
216
+ * Look for signs of unauthorised access (Rule 6(1)(c)): fields read for a purpose they aren't
217
+ * held for, consent purposes used without consent at the time, and one actor reaching more
218
+ * than `maxSubjects` people (default 100) within `window` (default `"1h"`). Reviews the last day
219
+ * unless `from` / `to` are given. Run it daily.
220
+ */
221
+ review(input?: {
222
+ from?: string;
223
+ to?: string;
224
+ window?: Duration;
225
+ maxSubjects?: number;
226
+ /** Actors exempt from bulk-access findings, e.g. a nightly export job that reaches everyone. */
227
+ ignoreActors?: readonly string[];
228
+ }): Promise<AccessReview>;
229
+ /**
230
+ * Delete entries older than `config.security.accessLogRetention` (default and minimum one year,
231
+ * Rule 6(1)(e)). Run it with the retention runner.
232
+ */
233
+ prune(): Promise<{
234
+ deleted: number;
235
+ before: string;
236
+ }>;
237
+ };
92
238
  readonly rights: {
93
239
  /** Record a request (Sections 11–14). It's due after `config.rights.responseWithin` (default 90 days). */
94
240
  open(subjectId: string, type: RequestType, details?: Record<string, unknown>): Promise<RightsRequest>;
package/dist/drizzle.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type PgDatabase } from "drizzle-orm/pg-core";
2
+ import type { AccessLogStore } from "./access.js";
2
3
  import type { DataAccess } from "./data-access.js";
3
4
  import type { RequestStatus, RequestType, TaskKind, TaskStatus } from "./records.js";
4
5
  import type { Schema } from "./schema-check.js";
@@ -686,15 +687,204 @@ export declare const erasureTasks: import("drizzle-orm/pg-core").PgTableWithColu
686
687
  }>;
687
688
  /** Rights requests and erasure tasks as plain SQL, if you don't use drizzle-kit for migrations. */
688
689
  export declare const RECORDS_DDL = "CREATE TABLE IF NOT EXISTS dpdp_requests (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n type text NOT NULL,\n status text NOT NULL,\n opened_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n closed_at timestamptz,\n details jsonb,\n history jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_requests_subject_idx ON dpdp_requests (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_requests_status_due_idx ON dpdp_requests (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_erasure_tasks (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n reason text NOT NULL,\n kind text NOT NULL,\n table_key text,\n fields jsonb,\n processor text,\n purposes jsonb,\n created_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n status text NOT NULL,\n attempts integer NOT NULL,\n claimed_at timestamptz,\n done_at timestamptz,\n affected integer,\n last_error text,\n note text\n);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_subject_idx ON dpdp_erasure_tasks (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_status_due_idx ON dpdp_erasure_tasks (status, due_at);";
690
+ /**
691
+ * The access log (Rule 6(1)(c) and (e)): who accessed whose personal data, when, for which purpose.
692
+ * Export it from your Drizzle schema with `consentEvents`.
693
+ */
694
+ export declare const accessLog: import("drizzle-orm/pg-core").PgTableWithColumns<{
695
+ name: "dpdp_access_log";
696
+ schema: undefined;
697
+ columns: {
698
+ id: import("drizzle-orm/pg-core").PgColumn<{
699
+ name: "id";
700
+ tableName: "dpdp_access_log";
701
+ dataType: "string";
702
+ columnType: "PgText";
703
+ data: string;
704
+ driverParam: string;
705
+ notNull: true;
706
+ hasDefault: false;
707
+ isPrimaryKey: true;
708
+ isAutoincrement: false;
709
+ hasRuntimeDefault: false;
710
+ enumValues: [string, ...string[]];
711
+ baseColumn: never;
712
+ identity: undefined;
713
+ generated: undefined;
714
+ }, {}, {}>;
715
+ at: import("drizzle-orm/pg-core").PgColumn<{
716
+ name: string;
717
+ tableName: "dpdp_access_log";
718
+ dataType: "date";
719
+ columnType: "PgTimestamp";
720
+ data: Date;
721
+ driverParam: string;
722
+ notNull: true;
723
+ hasDefault: false;
724
+ isPrimaryKey: false;
725
+ isAutoincrement: false;
726
+ hasRuntimeDefault: false;
727
+ enumValues: undefined;
728
+ baseColumn: never;
729
+ identity: undefined;
730
+ generated: undefined;
731
+ }, {}, {}>;
732
+ actor: import("drizzle-orm/pg-core").PgColumn<{
733
+ name: "actor";
734
+ tableName: "dpdp_access_log";
735
+ dataType: "string";
736
+ columnType: "PgText";
737
+ data: string;
738
+ driverParam: string;
739
+ notNull: true;
740
+ hasDefault: false;
741
+ isPrimaryKey: false;
742
+ isAutoincrement: false;
743
+ hasRuntimeDefault: false;
744
+ enumValues: [string, ...string[]];
745
+ baseColumn: never;
746
+ identity: undefined;
747
+ generated: undefined;
748
+ }, {}, {}>;
749
+ subjectId: import("drizzle-orm/pg-core").PgColumn<{
750
+ name: "subject_id";
751
+ tableName: "dpdp_access_log";
752
+ dataType: "string";
753
+ columnType: "PgText";
754
+ data: string;
755
+ driverParam: string;
756
+ notNull: true;
757
+ hasDefault: false;
758
+ isPrimaryKey: false;
759
+ isAutoincrement: false;
760
+ hasRuntimeDefault: false;
761
+ enumValues: [string, ...string[]];
762
+ baseColumn: never;
763
+ identity: undefined;
764
+ generated: undefined;
765
+ }, {}, {}>;
766
+ action: import("drizzle-orm/pg-core").PgColumn<{
767
+ name: "action";
768
+ tableName: "dpdp_access_log";
769
+ dataType: "string";
770
+ columnType: "PgText";
771
+ data: string;
772
+ driverParam: string;
773
+ notNull: true;
774
+ hasDefault: false;
775
+ isPrimaryKey: false;
776
+ isAutoincrement: false;
777
+ hasRuntimeDefault: false;
778
+ enumValues: [string, ...string[]];
779
+ baseColumn: never;
780
+ identity: undefined;
781
+ generated: undefined;
782
+ }, {}, {}>;
783
+ purpose: import("drizzle-orm/pg-core").PgColumn<{
784
+ name: "purpose";
785
+ tableName: "dpdp_access_log";
786
+ dataType: "string";
787
+ columnType: "PgText";
788
+ data: string;
789
+ driverParam: string;
790
+ notNull: true;
791
+ hasDefault: false;
792
+ isPrimaryKey: false;
793
+ isAutoincrement: false;
794
+ hasRuntimeDefault: false;
795
+ enumValues: [string, ...string[]];
796
+ baseColumn: never;
797
+ identity: undefined;
798
+ generated: undefined;
799
+ }, {}, {}>;
800
+ fields: import("drizzle-orm/pg-core").PgColumn<{
801
+ name: "fields";
802
+ tableName: "dpdp_access_log";
803
+ dataType: "json";
804
+ columnType: "PgJsonb";
805
+ data: string[];
806
+ driverParam: unknown;
807
+ notNull: false;
808
+ hasDefault: false;
809
+ isPrimaryKey: false;
810
+ isAutoincrement: false;
811
+ hasRuntimeDefault: false;
812
+ enumValues: undefined;
813
+ baseColumn: never;
814
+ identity: undefined;
815
+ generated: undefined;
816
+ }, {}, {
817
+ $type: string[];
818
+ }>;
819
+ outOfPurpose: import("drizzle-orm/pg-core").PgColumn<{
820
+ name: "out_of_purpose";
821
+ tableName: "dpdp_access_log";
822
+ dataType: "json";
823
+ columnType: "PgJsonb";
824
+ data: string[];
825
+ driverParam: unknown;
826
+ notNull: false;
827
+ hasDefault: false;
828
+ isPrimaryKey: false;
829
+ isAutoincrement: false;
830
+ hasRuntimeDefault: false;
831
+ enumValues: undefined;
832
+ baseColumn: never;
833
+ identity: undefined;
834
+ generated: undefined;
835
+ }, {}, {
836
+ $type: string[];
837
+ }>;
838
+ reason: import("drizzle-orm/pg-core").PgColumn<{
839
+ name: "reason";
840
+ tableName: "dpdp_access_log";
841
+ dataType: "string";
842
+ columnType: "PgText";
843
+ data: string;
844
+ driverParam: string;
845
+ notNull: false;
846
+ hasDefault: false;
847
+ isPrimaryKey: false;
848
+ isAutoincrement: false;
849
+ hasRuntimeDefault: false;
850
+ enumValues: [string, ...string[]];
851
+ baseColumn: never;
852
+ identity: undefined;
853
+ generated: undefined;
854
+ }, {}, {}>;
855
+ evidence: import("drizzle-orm/pg-core").PgColumn<{
856
+ name: "evidence";
857
+ tableName: "dpdp_access_log";
858
+ dataType: "json";
859
+ columnType: "PgJsonb";
860
+ data: Record<string, string>;
861
+ driverParam: unknown;
862
+ notNull: false;
863
+ hasDefault: false;
864
+ isPrimaryKey: false;
865
+ isAutoincrement: false;
866
+ hasRuntimeDefault: false;
867
+ enumValues: undefined;
868
+ baseColumn: never;
869
+ identity: undefined;
870
+ generated: undefined;
871
+ }, {}, {
872
+ $type: Record<string, string>;
873
+ }>;
874
+ };
875
+ dialect: 'pg';
876
+ }>;
877
+ /** The access log as plain SQL, if you don't use drizzle-kit for migrations. */
878
+ export declare const ACCESS_LOG_DDL = "CREATE TABLE IF NOT EXISTS dpdp_access_log (\n id text PRIMARY KEY,\n at timestamptz NOT NULL,\n actor text NOT NULL,\n subject_id text NOT NULL,\n action text NOT NULL,\n purpose text NOT NULL,\n fields jsonb,\n out_of_purpose jsonb,\n reason text,\n evidence jsonb\n);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_at_idx ON dpdp_access_log (at);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_subject_idx ON dpdp_access_log (subject_id, at);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_actor_idx ON dpdp_access_log (actor, at);";
689
879
  /** Every dpdp-kit table as plain SQL. */
690
- export declare const DPDP_DDL = "CREATE TABLE IF NOT EXISTS dpdp_consent_events (\n subject_id text NOT NULL,\n seq integer NOT NULL,\n action text NOT NULL CHECK (action IN ('grant', 'withdraw')),\n purposes jsonb NOT NULL,\n notice_version text,\n language text,\n channel text,\n evidence jsonb,\n at timestamptz NOT NULL,\n prev_hash text,\n hash text NOT NULL,\n PRIMARY KEY (subject_id, seq)\n);\nCREATE TABLE IF NOT EXISTS dpdp_requests (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n type text NOT NULL,\n status text NOT NULL,\n opened_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n closed_at timestamptz,\n details jsonb,\n history jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_requests_subject_idx ON dpdp_requests (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_requests_status_due_idx ON dpdp_requests (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_erasure_tasks (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n reason text NOT NULL,\n kind text NOT NULL,\n table_key text,\n fields jsonb,\n processor text,\n purposes jsonb,\n created_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n status text NOT NULL,\n attempts integer NOT NULL,\n claimed_at timestamptz,\n done_at timestamptz,\n affected integer,\n last_error text,\n note text\n);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_subject_idx ON dpdp_erasure_tasks (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_status_due_idx ON dpdp_erasure_tasks (status, due_at);";
880
+ export declare const DPDP_DDL = "CREATE TABLE IF NOT EXISTS dpdp_consent_events (\n subject_id text NOT NULL,\n seq integer NOT NULL,\n action text NOT NULL CHECK (action IN ('grant', 'withdraw')),\n purposes jsonb NOT NULL,\n notice_version text,\n language text,\n channel text,\n evidence jsonb,\n at timestamptz NOT NULL,\n prev_hash text,\n hash text NOT NULL,\n PRIMARY KEY (subject_id, seq)\n);\nCREATE TABLE IF NOT EXISTS dpdp_requests (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n type text NOT NULL,\n status text NOT NULL,\n opened_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n closed_at timestamptz,\n details jsonb,\n history jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_requests_subject_idx ON dpdp_requests (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_requests_status_due_idx ON dpdp_requests (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_erasure_tasks (\n id text PRIMARY KEY,\n subject_id text NOT NULL,\n reason text NOT NULL,\n kind text NOT NULL,\n table_key text,\n fields jsonb,\n processor text,\n purposes jsonb,\n created_at timestamptz NOT NULL,\n due_at timestamptz NOT NULL,\n status text NOT NULL,\n attempts integer NOT NULL,\n claimed_at timestamptz,\n done_at timestamptz,\n affected integer,\n last_error text,\n note text\n);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_subject_idx ON dpdp_erasure_tasks (subject_id);\nCREATE INDEX IF NOT EXISTS dpdp_erasure_tasks_status_due_idx ON dpdp_erasure_tasks (status, due_at);\nCREATE TABLE IF NOT EXISTS dpdp_access_log (\n id text PRIMARY KEY,\n at timestamptz NOT NULL,\n actor text NOT NULL,\n subject_id text NOT NULL,\n action text NOT NULL,\n purpose text NOT NULL,\n fields jsonb,\n out_of_purpose jsonb,\n reason text,\n evidence jsonb\n);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_at_idx ON dpdp_access_log (at);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_subject_idx ON dpdp_access_log (subject_id, at);\nCREATE INDEX IF NOT EXISTS dpdp_access_log_actor_idx ON dpdp_access_log (actor, at);";
691
881
  type AnyPgDatabase = PgDatabase<any, any, any>;
692
882
  /**
693
883
  * Store on Postgres through Drizzle: consent events, rights requests and erasure tasks. Works with
694
884
  * node-postgres, postgres.js, Neon, PGlite and other Drizzle Postgres drivers. Needs the tables
695
- * `consentEvents`, `rightsRequests` and `erasureTasks` (or `DPDP_DDL`).
885
+ * `consentEvents`, `rightsRequests`, `erasureTasks` and `accessLog` (or `DPDP_DDL`).
696
886
  */
697
- export declare function drizzleStore(db: AnyPgDatabase): DpdpStore;
887
+ export declare function drizzleStore(db: AnyPgDatabase): DpdpStore & AccessLogStore;
698
888
  /**
699
889
  * Read a Drizzle schema module (Postgres, MySQL or SQLite) for `checkSchema()`. Pass the module
700
890
  * itself, so every exported table is found:
@@ -708,8 +898,8 @@ export declare function drizzleSchema(module: Record<string, unknown>): Schema;
708
898
  /**
709
899
  * Data access for your own Postgres tables through Drizzle, for access summaries and erasure.
710
900
  * Pass your schema module if data map names are Drizzle property names (`userId`) rather than
711
- * database column names (`user_id`). Erasure sets fields to NULL, so erasable columns must be
712
- * nullable; a NOT NULL column makes the task fail with the database's message.
901
+ * database column names (`user_id`). Erasure writes each field's `erase` replacement, or NULL;
902
+ * `dpdp-kit audit --schema` checks that each column can take it.
713
903
  */
714
904
  export declare function drizzleData(db: AnyPgDatabase, options?: {
715
905
  schema?: Record<string, unknown>;