dpdp-kit 0.4.0 → 0.5.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +12 -9
  3. package/dist/access.d.ts +3 -2
  4. package/dist/audit.d.ts +7 -2
  5. package/dist/{chunk-5TVA2TKG.js → chunk-3DOVLBUB.js} +12 -2
  6. package/dist/chunk-EMNABUCL.js +34 -0
  7. package/dist/{chunk-HXVP446N.js → chunk-FEGA6SOM.js} +817 -149
  8. package/dist/chunk-HGN6TO6R.js +294 -0
  9. package/dist/{chunk-KLMR7S7I.js → chunk-LVT4OKBC.js} +65 -0
  10. package/dist/chunk-M2PDT6DD.js +88 -0
  11. package/dist/chunk-NBVJQDDP.js +16 -0
  12. package/dist/{chunk-2ELTZSW3.js → chunk-VWGKAQCM.js} +18 -3
  13. package/dist/cli.js +48 -5
  14. package/dist/config.d.ts +67 -0
  15. package/dist/data-access.d.ts +8 -0
  16. package/dist/ddl.d.ts +13 -2
  17. package/dist/dpdp.d.ts +155 -9
  18. package/dist/drizzle.d.ts +108 -6
  19. package/dist/drizzle.js +85 -4
  20. package/dist/erasure.d.ts +1 -1
  21. package/dist/errors.d.ts +1 -1
  22. package/dist/evidence.d.ts +91 -0
  23. package/dist/express.d.ts +30 -0
  24. package/dist/express.js +70 -3
  25. package/dist/fastify.js +3 -3
  26. package/dist/guard.d.ts +23 -2
  27. package/dist/hono.d.ts +21 -0
  28. package/dist/hono.js +11 -3
  29. package/dist/http.d.ts +78 -0
  30. package/dist/index.d.ts +7 -3
  31. package/dist/index.js +375 -125
  32. package/dist/mongodb.d.ts +3 -1
  33. package/dist/mongodb.js +99 -1
  34. package/dist/nestjs.js +1 -1
  35. package/dist/next.d.ts +25 -0
  36. package/dist/next.js +14 -0
  37. package/dist/notice.d.ts +139 -0
  38. package/dist/postgres.d.ts +5 -3
  39. package/dist/postgres.js +8 -2
  40. package/dist/prisma.d.ts +4 -2
  41. package/dist/prisma.js +16 -2
  42. package/dist/records.d.ts +24 -1
  43. package/dist/rights.d.ts +35 -2
  44. package/dist/run-audit.d.ts +8 -0
  45. package/dist/stats.d.ts +41 -0
  46. package/dist/store.d.ts +15 -2
  47. package/package.json +5 -1
package/dist/config.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Duration } from "./duration.js";
2
+ import type { NoticeConfig } from "./notice.js";
2
3
  import type { RequestType } from "./records.js";
3
4
  /**
4
5
  * Why you may process data for a purpose.
@@ -26,11 +27,20 @@ export type Basis = "consent" | "legitimate-use";
26
27
  export type Retention = "while-active" | Duration | {
27
28
  afterWithdrawal: Duration;
28
29
  };
30
+ /**
31
+ * Which clause of Section 7 a legitimate use relies on. Only `"7(a)"` (data the person gave
32
+ * voluntarily for a specified purpose) can be objected to: Section 7(a) holds only while the person
33
+ * "has not indicated … that she does not consent", so `consent.object()` stops it.
34
+ */
35
+ export type LegitimateUse = "7(a)" | "7(b)" | "7(c)" | "7(d)" | "7(e)" | "7(f)" | "7(g)" | "7(h)" | "7(i)";
36
+ export declare const LEGITIMATE_USES: readonly LegitimateUse[];
29
37
  export interface PurposeDef {
30
38
  basis: Basis;
31
39
  retain: Retention;
32
40
  /** Plain-language description, as shown to people in the notice. */
33
41
  description?: string;
42
+ /** For a legitimate-use purpose: the clause of Section 7 it relies on. `"7(a)"` purposes accept objections. */
43
+ legitimateUse?: LegitimateUse;
34
44
  }
35
45
  /** Kind of personal data. Free text is allowed; these are the common ones. */
36
46
  export type Category = "contact" | "identity" | "financial" | "health" | "location" | "device" | "biometric" | "behavioural" | (string & {});
@@ -66,6 +76,12 @@ export type EraseWith = "null" | "redact" | {
66
76
  };
67
77
  export interface PersonalField<P extends string = string> {
68
78
  category: Category;
79
+ /**
80
+ * How the field is named in the notice, e.g. `"Mobile number"`. Rule 3(b)(i) requires an
81
+ * itemised description of the data. Default: the field name made readable (`phoneNumber` →
82
+ * "Phone number").
83
+ */
84
+ label?: string;
69
85
  /** Every purpose this field is held for. When all of them end, the field must go. */
70
86
  purposes: readonly P[];
71
87
  /** This field can tell you the person is under 18 (e.g. date of birth). Used from v0.3. */
@@ -107,6 +123,33 @@ export interface ProcessorDef<P extends string = string> {
107
123
  * when it's missing.
108
124
  */
109
125
  contract?: string;
126
+ /**
127
+ * Where the processor handles the data, as ISO 3166-1 alpha-2 codes: `["IN"]`, `["IN", "SG"]`.
128
+ * Include every country of its servers and support staff that can reach the data. Section 16
129
+ * lets the Central Government restrict transfers to countries it notifies; list those in
130
+ * `transfers.restricted`. The audit warns when this is missing.
131
+ */
132
+ countries?: readonly string[];
133
+ /**
134
+ * The processor is a foreign State, or an entity under its control or one of its agencies.
135
+ * Rule 15 subjects such transfers to requirements the Central Government specifies by order.
136
+ */
137
+ foreignState?: boolean;
138
+ }
139
+ /** Transfers of personal data outside India (Section 16, Rule 15). */
140
+ export interface TransfersConfig<P extends string = string> {
141
+ /**
142
+ * Countries the Central Government has restricted transfers to by notification (Section 16(1)),
143
+ * as ISO 3166-1 alpha-2 codes. None are notified as of November 2026; keep this list up to date
144
+ * yourself. The audit fails when a processor is in one of them.
145
+ */
146
+ restricted?: readonly string[];
147
+ /**
148
+ * Purposes whose data another law requires to stay in India, e.g. payment data under the RBI's
149
+ * storage directive. Section 16(2) keeps such laws in force. The audit fails when a processor
150
+ * for one of these purposes is anywhere else.
151
+ */
152
+ keepInIndia?: readonly P[];
110
153
  }
111
154
  /**
112
155
  * The security safeguards of Rule 6(1) that live outside your code, written down as evidence.
@@ -132,6 +175,23 @@ export interface RightsConfig {
132
175
  * responses at ninety days; the Rules set no period for the other types, so pick one you can keep.
133
176
  */
134
177
  responseWithin?: Duration | Partial<Record<RequestType, Duration>>;
178
+ /**
179
+ * How people make a request: the means Rule 14(1)(a) requires you to publish prominently, e.g.
180
+ * `"In the app: Settings → Privacy → Your data, or email privacy@chai.example"`. The audit warns
181
+ * when it's missing.
182
+ */
183
+ how?: string;
184
+ /**
185
+ * What you need to identify the person (Rule 14(1)(b)), e.g. `["registered mobile number"]`.
186
+ * Rule 14(5) gives examples: a customer id, an application number, an email address.
187
+ */
188
+ identifiers?: readonly string[];
189
+ /**
190
+ * `"required"`: summaries, erasure and corrections for a request refuse to run until someone
191
+ * records checking the person's identity with `rights.verifyIdentity()`. Default `"optional"`.
192
+ * Use it when requests arrive by email, phone or letter rather than from a signed-in account.
193
+ */
194
+ verify?: "required" | "optional";
135
195
  }
136
196
  export interface FiduciaryDef {
137
197
  name: string;
@@ -154,6 +214,8 @@ export interface DpdpConfig<P extends string = string> {
154
214
  };
155
215
  data: Record<string, TableDef<NoInfer<P>>>;
156
216
  processors?: Record<string, ProcessorDef<NoInfer<P>>>;
217
+ /** Transfers outside India. See `TransfersConfig`. */
218
+ transfers?: TransfersConfig<NoInfer<P>>;
157
219
  /**
158
220
  * How long personal data, traffic data and logs of each processing are kept, at minimum, from the
159
221
  * date of that processing, even after erasure is otherwise due (e.g. the account is deleted).
@@ -170,6 +232,11 @@ export interface DpdpConfig<P extends string = string> {
170
232
  rights?: RightsConfig;
171
233
  /** Security safeguards under Rule 6(1). See `SecurityConfig`. */
172
234
  security?: SecurityConfig;
235
+ /**
236
+ * Build the privacy notice from this config (Section 5, Rule 3). When set, `consent.grant()`
237
+ * records the version of the notice the person saw, and saves the notice as proof.
238
+ */
239
+ notice?: NoticeConfig<NoInfer<P>>;
173
240
  }
174
241
  /** Purpose names of a config, e.g. `"account" | "marketing_sms"`. */
175
242
  export type PurposeOf<C> = C extends DpdpConfig<infer P> ? P : never;
@@ -14,7 +14,15 @@ export interface DataAccess {
14
14
  eraseFields(table: string, subjectColumn: string, subjectId: string, columns: readonly string[], values?: Readonly<Record<string, ErasedValue>>): Promise<number>;
15
15
  /** Delete the person's rows. Returns rows deleted. */
16
16
  deleteRows(table: string, subjectColumn: string, subjectId: string): Promise<number>;
17
+ /**
18
+ * Write new values to the person's rows, for corrections (Section 12(2)). `where` narrows it to
19
+ * some rows, e.g. `{ id: 42 }` for one address of several. Returns rows changed. Optional:
20
+ * without it, `rights.correct()` isn't available. The built-in data access all have it.
21
+ */
22
+ updateFields?(table: string, subjectColumn: string, subjectId: string, values: Readonly<Record<string, unknown>>, where?: Readonly<Record<string, unknown>>): Promise<number>;
17
23
  }
24
+ /** A value written to a database column: objects and arrays as JSON text. */
25
+ export declare const columnValue: (v: unknown) => unknown;
18
26
  type Row = Record<string, unknown>;
19
27
  /** Data access over plain arrays, for tests and examples. */
20
28
  export declare function memoryData(tables: Record<string, Row[]>): DataAccess & {
package/dist/ddl.d.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  /** The same table as plain SQL, if you don't use drizzle-kit for migrations. */
2
- export declare const CONSENT_EVENTS_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);";
2
+ export declare const CONSENT_EVENTS_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 CONSTRAINT dpdp_consent_events_action_check CHECK (action IN ('grant', 'withdraw', 'object', 'lift-objection')),\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);";
3
3
  /** Rights requests and erasure tasks as plain SQL, if you don't use drizzle-kit for migrations. */
4
4
  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);";
5
5
  /** The access log as plain SQL, if you don't use drizzle-kit for migrations. */
6
6
  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);";
7
7
  /** The breach tables as plain SQL, if you don't use drizzle-kit for migrations. */
8
8
  export declare const BREACH_DDL = "CREATE TABLE IF NOT EXISTS dpdp_breaches (\n id text PRIMARY KEY,\n status text NOT NULL,\n aware_at timestamptz NOT NULL,\n report_due_at timestamptz NOT NULL,\n data jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_breaches_status_idx ON dpdp_breaches (status, aware_at);\nCREATE TABLE IF NOT EXISTS dpdp_breach_notices (\n breach_id text NOT NULL,\n subject_id text NOT NULL,\n status text NOT NULL,\n added_at timestamptz NOT NULL,\n sent_at timestamptz,\n channel text,\n PRIMARY KEY (breach_id, subject_id)\n);\nCREATE INDEX IF NOT EXISTS dpdp_breach_notices_status_idx ON dpdp_breach_notices (breach_id, status, added_at);";
9
+ /** Privacy notices as shown, kept as proof (Section 6(10)), as plain SQL. */
10
+ export declare const PRIVACY_NOTICES_DDL = "CREATE TABLE IF NOT EXISTS dpdp_privacy_notices (\n version text NOT NULL,\n language text NOT NULL,\n kind text NOT NULL,\n content jsonb NOT NULL,\n first_shown_at timestamptz NOT NULL,\n PRIMARY KEY (version, language, kind)\n);";
9
11
  /** Every dpdp-kit table as plain SQL. */
10
- 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);\nCREATE TABLE IF NOT EXISTS dpdp_breaches (\n id text PRIMARY KEY,\n status text NOT NULL,\n aware_at timestamptz NOT NULL,\n report_due_at timestamptz NOT NULL,\n data jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_breaches_status_idx ON dpdp_breaches (status, aware_at);\nCREATE TABLE IF NOT EXISTS dpdp_breach_notices (\n breach_id text NOT NULL,\n subject_id text NOT NULL,\n status text NOT NULL,\n added_at timestamptz NOT NULL,\n sent_at timestamptz,\n channel text,\n PRIMARY KEY (breach_id, subject_id)\n);\nCREATE INDEX IF NOT EXISTS dpdp_breach_notices_status_idx ON dpdp_breach_notices (breach_id, status, added_at);";
12
+ 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 CONSTRAINT dpdp_consent_events_action_check CHECK (action IN ('grant', 'withdraw', 'object', 'lift-objection')),\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);\nCREATE TABLE IF NOT EXISTS dpdp_breaches (\n id text PRIMARY KEY,\n status text NOT NULL,\n aware_at timestamptz NOT NULL,\n report_due_at timestamptz NOT NULL,\n data jsonb NOT NULL\n);\nCREATE INDEX IF NOT EXISTS dpdp_breaches_status_idx ON dpdp_breaches (status, aware_at);\nCREATE TABLE IF NOT EXISTS dpdp_breach_notices (\n breach_id text NOT NULL,\n subject_id text NOT NULL,\n status text NOT NULL,\n added_at timestamptz NOT NULL,\n sent_at timestamptz,\n channel text,\n PRIMARY KEY (breach_id, subject_id)\n);\nCREATE INDEX IF NOT EXISTS dpdp_breach_notices_status_idx ON dpdp_breach_notices (breach_id, status, added_at);\nCREATE TABLE IF NOT EXISTS dpdp_privacy_notices (\n version text NOT NULL,\n language text NOT NULL,\n kind text NOT NULL,\n content jsonb NOT NULL,\n first_shown_at timestamptz NOT NULL,\n PRIMARY KEY (version, language, kind)\n);";
13
+ /**
14
+ * Upgrades tables created by an earlier version to 0.5: consent events may now record objections
15
+ * (`object`, `lift-objection`), and `dpdp_privacy_notices` keeps notice snapshots. Safe to run more than once, and on tables created by drizzle-kit
16
+ * or Prisma, which have no such constraint. The constraint is added NOT VALID and then validated.
17
+ * Sent as one query, all of it is one transaction, which locks `dpdp_consent_events` until the
18
+ * existing rows are checked: fine for most tables. For a very large one, send the statements one
19
+ * at a time (split on `;\n`), so writes only wait for the short `ADD CONSTRAINT`.
20
+ */
21
+ export declare const MIGRATE_0_5_DDL = "ALTER TABLE dpdp_consent_events DROP CONSTRAINT IF EXISTS dpdp_consent_events_action_check;\nALTER TABLE dpdp_consent_events ADD CONSTRAINT dpdp_consent_events_action_check CHECK (action IN ('grant', 'withdraw', 'object', 'lift-objection')) NOT VALID;\nALTER TABLE dpdp_consent_events VALIDATE CONSTRAINT dpdp_consent_events_action_check;\nCREATE TABLE IF NOT EXISTS dpdp_privacy_notices (\n version text NOT NULL,\n language text NOT NULL,\n kind text NOT NULL,\n content jsonb NOT NULL,\n first_shown_at timestamptz NOT NULL,\n PRIMARY KEY (version, language, kind)\n);";
package/dist/dpdp.d.ts CHANGED
@@ -4,10 +4,12 @@ import type { DpdpConfig } from "./config.js";
4
4
  import type { DataAccess } from "./data-access.js";
5
5
  import { type Duration } from "./duration.js";
6
6
  import { type ErasurePlan } from "./erasure.js";
7
+ import { type EvidenceReport } from "./evidence.js";
7
8
  import { type NoticeLanguage } from "./languages.js";
8
- import { type ErasureTask, type RequestFilter, type RequestType, type RightsRequest, type TaskFilter } from "./records.js";
9
+ import { type NoticeKind, type PrivacyNotice, type SavedNotice } from "./notice.js";
10
+ import { type ErasureTask, type Nominee, type RequestFilter, type RequestType, type RightsRequest, type TaskFilter } from "./records.js";
9
11
  import { type ProcessorHooks, type RunReport } from "./retention.js";
10
- import { type AccessSummary } from "./rights.js";
12
+ import { type AccessSummary, type Acknowledgement, type RightsInfo } from "./rights.js";
11
13
  import { type ConsentEvent, type ConsentStore } from "./store.js";
12
14
  export interface ConsentMeta {
13
15
  noticeVersion?: string;
@@ -62,6 +64,16 @@ export interface DpdpEvents {
62
64
  erasure: ErasurePlan;
63
65
  tasks: ErasureTask[];
64
66
  };
67
+ "consent.objected": {
68
+ event: ConsentEvent;
69
+ erasure: ErasurePlan;
70
+ tasks: ErasureTask[];
71
+ };
72
+ "consent.objection-lifted": {
73
+ event: ConsentEvent;
74
+ cancelled: ErasureTask[];
75
+ tasks: ErasureTask[];
76
+ };
65
77
  "erasure.scheduled": {
66
78
  plan: ErasurePlan;
67
79
  tasks: ErasureTask[];
@@ -75,6 +87,16 @@ export interface DpdpEvents {
75
87
  "rights.closed": {
76
88
  request: RightsRequest;
77
89
  };
90
+ "rights.verified": {
91
+ request: RightsRequest;
92
+ };
93
+ "rights.corrected": {
94
+ request: RightsRequest;
95
+ fields: string[];
96
+ };
97
+ "rights.nominated": {
98
+ nominee: Nominee;
99
+ };
78
100
  "access.logged": {
79
101
  entries: AccessEntry[];
80
102
  };
@@ -177,15 +199,35 @@ export interface Dpdp<P extends string> {
177
199
  erasure: ErasurePlan;
178
200
  tasks: ErasureTask[];
179
201
  }>;
202
+ /**
203
+ * Record that the person doesn't want their data used for these Section 7(a) purposes
204
+ * (legitimate uses with `legitimateUse: "7(a)"`). `has()` turns false for them at once, and
205
+ * erasure is planned as for a withdrawal: fields whose purposes have all ended, never whole rows.
206
+ */
207
+ object(subjectId: string, purposes: readonly P[], meta?: ConsentMeta): Promise<{
208
+ event: ConsentEvent;
209
+ erasure: ErasurePlan;
210
+ tasks: ErasureTask[];
211
+ }>;
212
+ /**
213
+ * Record that the person changed their mind about an objection. Erasure tasks the objection
214
+ * scheduled and that haven't run yet are cancelled; data already erased stays erased.
215
+ */
216
+ liftObjection(subjectId: string, purposes: readonly P[], meta?: ConsentMeta): Promise<{
217
+ event: ConsentEvent;
218
+ cancelled: ErasureTask[];
219
+ tasks: ErasureTask[];
220
+ }>;
180
221
  /**
181
222
  * Whether you hold consent, or don't need it, for this purpose. For consent purposes: true when
182
- * the person's latest choice was a grant. For legitimate-use purposes: always true, because
183
- * there's nothing to record. But under Section 7(a) you must stop once the person tells you they
184
- * don't want their data used; v0.1 doesn't record that yet.
223
+ * the person's latest choice was a grant. For Section 7(a) purposes: true unless the person has
224
+ * objected. For other legitimate uses: always true.
185
225
  */
186
226
  has(subjectId: string, purpose: P): Promise<boolean>;
187
227
  /** Consent purposes this person currently has granted. */
188
228
  active(subjectId: string): Promise<P[]>;
229
+ /** Section 7(a) purposes this person currently objects to. */
230
+ objections(subjectId: string): Promise<P[]>;
189
231
  history(subjectId: string): Promise<ConsentEvent[]>;
190
232
  /** Recompute every hash for this person and check nothing was edited, removed or reordered. */
191
233
  verify(subjectId: string): Promise<VerifyResult>;
@@ -247,6 +289,53 @@ export interface Dpdp<P extends string> {
247
289
  before: string;
248
290
  }>;
249
291
  };
292
+ /**
293
+ * One report of what the config declares and what the records show, for an auditor, a lawyer or
294
+ * the Board: the data map, the audit, Rule 6 safeguards, notices shown, consent counts, rights
295
+ * requests, erasure, the access review and breaches. Covers the last 30 days unless `from` and
296
+ * `to` are given; the access review reads every log entry in the period, so keep long periods for
297
+ * smaller logs. `formatEvidence()` turns it into Markdown.
298
+ */
299
+ evidence(input?: {
300
+ from?: string;
301
+ to?: string;
302
+ /** Options for the access review part, as for `access.review()`. */
303
+ review?: {
304
+ window?: Duration;
305
+ maxSubjects?: number;
306
+ ignoreActors?: readonly string[];
307
+ };
308
+ /** How many access findings to list in full. Default 20. */
309
+ examples?: number;
310
+ }): Promise<EvidenceReport>;
311
+ /**
312
+ * Privacy notices built from `config.notice` (Section 5, Rule 3), and the snapshots kept as proof
313
+ * of what people were shown (Section 6(10)).
314
+ */
315
+ readonly notice: {
316
+ /** The notice in a language (default English) and of a kind (default `"consent"`). Doesn't save anything. */
317
+ build(options?: {
318
+ language?: NoticeLanguage;
319
+ kind?: NoticeKind;
320
+ }): PrivacyNotice;
321
+ /**
322
+ * The same as `build()`, and saves the notice as proof the first time it's shown. Call it where
323
+ * you display the notice. `consent.grant()` does this for you.
324
+ */
325
+ show(options?: {
326
+ language?: NoticeLanguage;
327
+ kind?: NoticeKind;
328
+ }): Promise<PrivacyNotice>;
329
+ /** A saved notice, e.g. the one a consent event's `noticeVersion` points to. */
330
+ get(version: string, options?: {
331
+ language?: NoticeLanguage;
332
+ kind?: NoticeKind;
333
+ }): Promise<SavedNotice | undefined>;
334
+ /** Every saved notice, oldest first. */
335
+ list(): Promise<SavedNotice[]>;
336
+ /** Languages the notice is available in: English, then each translation. */
337
+ languages(): NoticeLanguage[];
338
+ };
250
339
  /**
251
340
  * Personal data breaches (Section 8(6), Rule 7): record one, find and tell the people affected,
252
341
  * and track the Board's deadlines. Needs a store that keeps breaches: `memoryStore()`,
@@ -307,10 +396,32 @@ export interface Dpdp<P extends string> {
307
396
  list(filter?: RequestFilter & {
308
397
  overdue?: boolean;
309
398
  }): Promise<RightsRequest[]>;
310
- resolve(id: string, note?: string): Promise<RightsRequest>;
311
- reject(id: string, reason: string): Promise<RightsRequest>;
312
- /** What you hold about the person and who you shared it with (Section 11(1)). Needs `data`. */
313
- summary(subjectId: string): Promise<AccessSummary>;
399
+ /** `by`: who answered, recorded in the history. */
400
+ resolve(id: string, note?: string, options?: {
401
+ by?: string;
402
+ }): Promise<RightsRequest>;
403
+ reject(id: string, reason: string, options?: {
404
+ by?: string;
405
+ }): Promise<RightsRequest>;
406
+ /** What to tell the person now: the reference, when you'll answer, and who to ask meanwhile. */
407
+ acknowledgement(id: string): Promise<Acknowledgement>;
408
+ /**
409
+ * Record that you checked the identity of the person behind a request, e.g.
410
+ * `{ method: "OTP to registered mobile", by: "support:anita" }`. With `rights.verify: "required"`,
411
+ * summaries, erasure and corrections for a request wait for this.
412
+ */
413
+ verifyIdentity(id: string, input: {
414
+ method: string;
415
+ by: string;
416
+ }): Promise<RightsRequest>;
417
+ /**
418
+ * What you hold about the person and who you shared it with (Section 11(1)). Needs `data`. Pass
419
+ * the request it answers as `requestId`: it must be the person's, open, and verified if you
420
+ * require that.
421
+ */
422
+ summary(subjectId: string, options?: {
423
+ requestId?: string;
424
+ }): Promise<AccessSummary>;
314
425
  /**
315
426
  * Erase on request (Section 12(3)): every purpose ends except those in `keepFor`, which you still
316
427
  * need for the specified purpose. Legal holds and `minimumRetention` still apply. Pass the
@@ -319,10 +430,45 @@ export interface Dpdp<P extends string> {
319
430
  erase(subjectId: string, input?: {
320
431
  keepFor?: readonly P[];
321
432
  requestId?: string;
433
+ by?: string;
322
434
  }): Promise<{
323
435
  plan: ErasurePlan;
324
436
  tasks: ErasureTask[];
325
437
  }>;
438
+ /**
439
+ * Correct, complete or update the person's data (Section 12(2)) for an open `correction`
440
+ * request, and resolve it. Keys are data map fields, `"users.phone"`. `where` picks some of the
441
+ * person's rows in one table, e.g. `{ id: 42 }`. The history records which fields changed,
442
+ * never the values. Needs `data` with `updateFields`.
443
+ */
444
+ correct(requestId: string, changes: Readonly<Record<string, unknown>>, options?: {
445
+ where?: Readonly<Record<string, unknown>>;
446
+ by?: string;
447
+ resolve?: boolean;
448
+ }): Promise<{
449
+ request: RightsRequest;
450
+ changed: Record<string, number>;
451
+ }>;
452
+ /**
453
+ * Record someone who may exercise the person's rights if they die or can no longer act
454
+ * (Section 14, Rule 14(4)). Opens and resolves a `nomination` request, or uses the one you pass.
455
+ */
456
+ nominate(subjectId: string, nominee: {
457
+ name: string;
458
+ contact: string;
459
+ relation?: string;
460
+ }, options?: {
461
+ requestId?: string;
462
+ by?: string;
463
+ }): Promise<Nominee>;
464
+ /** The person's current nominees, oldest first. */
465
+ nominees(subjectId: string): Promise<Nominee[]>;
466
+ /** Remove a nominee at the person's request. */
467
+ revokeNominee(subjectId: string, nomineeId: string, options?: {
468
+ by?: string;
469
+ }): Promise<void>;
470
+ /** What Rule 14(1) and 14(3) ask you to publish: how to make a request, identifiers, answer times. */
471
+ how(): RightsInfo;
326
472
  };
327
473
  }
328
474
  type HashedFields = Omit<ConsentEvent, "hash">;
package/dist/drizzle.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import { type PgDatabase } from "drizzle-orm/pg-core";
2
2
  import type { AccessLogStore } from "./access.js";
3
3
  import type { Breach, BreachStore } from "./breach.js";
4
- import type { DataAccess } from "./data-access.js";
4
+ import { type DataAccess } from "./data-access.js";
5
5
  import type { RequestStatus, RequestType, TaskKind, TaskStatus } from "./records.js";
6
+ import type { NoticeKind, NoticeStore, PrivacyNotice } from "./notice.js";
7
+ import { type StatsStore } from "./stats.js";
6
8
  import type { Schema } from "./schema-check.js";
7
9
  import type { DpdpStore } from "./store.js";
8
- export { ACCESS_LOG_DDL, BREACH_DDL, CONSENT_EVENTS_DDL, DPDP_DDL, RECORDS_DDL } from "./ddl.js";
10
+ export { ACCESS_LOG_DDL, BREACH_DDL, CONSENT_EVENTS_DDL, DPDP_DDL, MIGRATE_0_5_DDL, PRIVACY_NOTICES_DDL, RECORDS_DDL } from "./ddl.js";
9
11
  /**
10
12
  * The consent events table. Export it from your Drizzle schema so drizzle-kit creates it:
11
13
  *
@@ -56,14 +58,14 @@ export declare const consentEvents: import("drizzle-orm/pg-core").PgTableWithCol
56
58
  tableName: "dpdp_consent_events";
57
59
  dataType: "string";
58
60
  columnType: "PgText";
59
- data: "grant" | "withdraw";
61
+ data: "grant" | "lift-objection" | "object" | "withdraw";
60
62
  driverParam: string;
61
63
  notNull: true;
62
64
  hasDefault: false;
63
65
  isPrimaryKey: false;
64
66
  isAutoincrement: false;
65
67
  hasRuntimeDefault: false;
66
- enumValues: ["grant", "withdraw"];
68
+ enumValues: ["grant", "withdraw", "object", "lift-objection"];
67
69
  baseColumn: never;
68
70
  identity: undefined;
69
71
  generated: undefined;
@@ -969,6 +971,105 @@ export declare const breaches: import("drizzle-orm/pg-core").PgTableWithColumns<
969
971
  };
970
972
  dialect: 'pg';
971
973
  }>;
974
+ /** Privacy notices as shown, kept as proof (Section 6(10)). Export it from your Drizzle schema with `consentEvents`. */
975
+ export declare const privacyNotices: import("drizzle-orm/pg-core").PgTableWithColumns<{
976
+ name: "dpdp_privacy_notices";
977
+ schema: undefined;
978
+ columns: {
979
+ version: import("drizzle-orm/pg-core").PgColumn<{
980
+ name: "version";
981
+ tableName: "dpdp_privacy_notices";
982
+ dataType: "string";
983
+ columnType: "PgText";
984
+ data: string;
985
+ driverParam: string;
986
+ notNull: true;
987
+ hasDefault: false;
988
+ isPrimaryKey: false;
989
+ isAutoincrement: false;
990
+ hasRuntimeDefault: false;
991
+ enumValues: [string, ...string[]];
992
+ baseColumn: never;
993
+ identity: undefined;
994
+ generated: undefined;
995
+ }, {}, {}>;
996
+ language: import("drizzle-orm/pg-core").PgColumn<{
997
+ name: "language";
998
+ tableName: "dpdp_privacy_notices";
999
+ dataType: "string";
1000
+ columnType: "PgText";
1001
+ data: "as" | "bn" | "brx" | "doi" | "en" | "gu" | "hi" | "kn" | "kok" | "ks" | "mai" | "ml" | "mni" | "mr" | "ne" | "or" | "pa" | "sa" | "sat" | "sd" | "ta" | "te" | "ur";
1002
+ driverParam: string;
1003
+ notNull: true;
1004
+ hasDefault: false;
1005
+ isPrimaryKey: false;
1006
+ isAutoincrement: false;
1007
+ hasRuntimeDefault: false;
1008
+ enumValues: [string, ...string[]];
1009
+ baseColumn: never;
1010
+ identity: undefined;
1011
+ generated: undefined;
1012
+ }, {}, {
1013
+ $type: "as" | "bn" | "brx" | "doi" | "en" | "gu" | "hi" | "kn" | "kok" | "ks" | "mai" | "ml" | "mni" | "mr" | "ne" | "or" | "pa" | "sa" | "sat" | "sd" | "ta" | "te" | "ur";
1014
+ }>;
1015
+ kind: import("drizzle-orm/pg-core").PgColumn<{
1016
+ name: "kind";
1017
+ tableName: "dpdp_privacy_notices";
1018
+ dataType: "string";
1019
+ columnType: "PgText";
1020
+ data: NoticeKind;
1021
+ driverParam: string;
1022
+ notNull: true;
1023
+ hasDefault: false;
1024
+ isPrimaryKey: false;
1025
+ isAutoincrement: false;
1026
+ hasRuntimeDefault: false;
1027
+ enumValues: [string, ...string[]];
1028
+ baseColumn: never;
1029
+ identity: undefined;
1030
+ generated: undefined;
1031
+ }, {}, {
1032
+ $type: NoticeKind;
1033
+ }>;
1034
+ content: import("drizzle-orm/pg-core").PgColumn<{
1035
+ name: "content";
1036
+ tableName: "dpdp_privacy_notices";
1037
+ dataType: "json";
1038
+ columnType: "PgJsonb";
1039
+ data: PrivacyNotice;
1040
+ driverParam: unknown;
1041
+ notNull: true;
1042
+ hasDefault: false;
1043
+ isPrimaryKey: false;
1044
+ isAutoincrement: false;
1045
+ hasRuntimeDefault: false;
1046
+ enumValues: undefined;
1047
+ baseColumn: never;
1048
+ identity: undefined;
1049
+ generated: undefined;
1050
+ }, {}, {
1051
+ $type: PrivacyNotice;
1052
+ }>;
1053
+ firstShownAt: import("drizzle-orm/pg-core").PgColumn<{
1054
+ name: string;
1055
+ tableName: "dpdp_privacy_notices";
1056
+ dataType: "date";
1057
+ columnType: "PgTimestamp";
1058
+ data: Date;
1059
+ driverParam: string;
1060
+ notNull: true;
1061
+ hasDefault: false;
1062
+ isPrimaryKey: false;
1063
+ isAutoincrement: false;
1064
+ hasRuntimeDefault: false;
1065
+ enumValues: undefined;
1066
+ baseColumn: never;
1067
+ identity: undefined;
1068
+ generated: undefined;
1069
+ }, {}, {}>;
1070
+ };
1071
+ dialect: 'pg';
1072
+ }>;
972
1073
  /** The people affected by each breach, and whether they've been told (Rule 7(1)). */
973
1074
  export declare const breachNotices: import("drizzle-orm/pg-core").PgTableWithColumns<{
974
1075
  name: "dpdp_breach_notices";
@@ -1085,9 +1186,10 @@ type AnyPgDatabase = PgDatabase<any, any, any>;
1085
1186
  /**
1086
1187
  * Store on Postgres through Drizzle: consent events, rights requests and erasure tasks. Works with
1087
1188
  * node-postgres, postgres.js, Neon, PGlite and other Drizzle Postgres drivers. Needs the tables
1088
- * `consentEvents`, `rightsRequests`, `erasureTasks`, `accessLog`, `breaches` and `breachNotices` (or `DPDP_DDL`).
1189
+ * `consentEvents`, `rightsRequests`, `erasureTasks`, `accessLog`, `breaches`, `breachNotices` and
1190
+ * `privacyNotices` (or `DPDP_DDL`).
1089
1191
  */
1090
- export declare function drizzleStore(db: AnyPgDatabase): DpdpStore & AccessLogStore & BreachStore;
1192
+ export declare function drizzleStore(db: AnyPgDatabase): DpdpStore & AccessLogStore & BreachStore & NoticeStore & StatsStore;
1091
1193
  /**
1092
1194
  * Read a Drizzle schema module (Postgres, MySQL or SQLite) for `checkSchema()`. Pass the module
1093
1195
  * itself, so every exported table is found: