dpdp-kit 0.4.1 → 0.5.1

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 (49) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/README.md +20 -10
  4. package/dist/access.d.ts +3 -2
  5. package/dist/audit.d.ts +7 -2
  6. package/dist/{chunk-5TVA2TKG.js → chunk-3DOVLBUB.js} +12 -2
  7. package/dist/chunk-EMNABUCL.js +34 -0
  8. package/dist/{chunk-HXVP446N.js → chunk-FEGA6SOM.js} +817 -149
  9. package/dist/chunk-HGN6TO6R.js +294 -0
  10. package/dist/{chunk-KLMR7S7I.js → chunk-LVT4OKBC.js} +65 -0
  11. package/dist/chunk-M2PDT6DD.js +88 -0
  12. package/dist/chunk-NBVJQDDP.js +16 -0
  13. package/dist/{chunk-2ELTZSW3.js → chunk-VWGKAQCM.js} +18 -3
  14. package/dist/cli.js +48 -5
  15. package/dist/config.d.ts +67 -0
  16. package/dist/data-access.d.ts +8 -0
  17. package/dist/ddl.d.ts +13 -2
  18. package/dist/dpdp.d.ts +155 -9
  19. package/dist/drizzle.d.ts +108 -6
  20. package/dist/drizzle.js +85 -4
  21. package/dist/erasure.d.ts +1 -1
  22. package/dist/errors.d.ts +1 -1
  23. package/dist/evidence.d.ts +91 -0
  24. package/dist/express.d.ts +30 -0
  25. package/dist/express.js +70 -3
  26. package/dist/fastify.js +3 -3
  27. package/dist/guard.d.ts +23 -2
  28. package/dist/hono.d.ts +21 -0
  29. package/dist/hono.js +11 -3
  30. package/dist/http.d.ts +78 -0
  31. package/dist/index.d.ts +7 -3
  32. package/dist/index.js +375 -125
  33. package/dist/mongodb.d.ts +3 -1
  34. package/dist/mongodb.js +99 -1
  35. package/dist/nestjs.js +1 -1
  36. package/dist/next.d.ts +25 -0
  37. package/dist/next.js +14 -0
  38. package/dist/notice.d.ts +139 -0
  39. package/dist/postgres.d.ts +5 -3
  40. package/dist/postgres.js +8 -2
  41. package/dist/prisma.d.ts +4 -2
  42. package/dist/prisma.js +16 -2
  43. package/dist/records.d.ts +24 -1
  44. package/dist/rights.d.ts +35 -2
  45. package/dist/run-audit.d.ts +8 -0
  46. package/dist/stats.d.ts +41 -0
  47. package/dist/store.d.ts +15 -2
  48. package/package.json +9 -3
  49. /package/{LICENSE → LICENSE-MIT} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.1
4
+
5
+ **Dual licence.** dpdp-kit is now available under MIT or Apache-2.0, at your option (`LICENSE-MIT`, `LICENSE-APACHE`). Apache-2.0 adds an explicit patent grant. Versions up to 0.5.0 remain MIT. No changes to the library.
6
+
7
+ ## 0.5.0
8
+
9
+ **Notices, objections, complete rights requests, transfers, an HTTP API and an evidence report.** A 0.4 app that changes nothing keeps working: everything new is opt-in, and new audit warnings don't fail `--strict` until 0.6.
10
+
11
+ ### Added
12
+
13
+ - **Privacy notices** (Section 5, Rule 3), with `notice` in the config:
14
+ - `dpdp.notice.build()` / `show()` build the notice from the config: each consent purpose with its description, the itemised data (`label` on fields), the links Rule 3(c) requires and how to complain to the Board.
15
+ - English is built in; other languages come from `notice.translations`, which you supply. The audit checks each translation is complete.
16
+ - Each notice is versioned by its content, per language and kind (`"consent"` or `"existing-users"`), and saved the first time it's shown (`dpdp_privacy_notices`), as proof under Section 6(10). Reusing a version label for different text throws `notice-version-conflict`.
17
+ - `consent.grant()` records the version and language shown, when `config.notice` is set and you don't pass a `noticeVersion`.
18
+ - **Objections** (Section 7(a)): `legitimateUse: "7(a)"` … `"7(i)"` on legitimate-use purposes.
19
+ - `consent.object()` and `consent.liftObjection()` add `object` and `lift-objection` events to the same hash chain.
20
+ - `has()` is false for an objected 7(a) purpose; guards answer `reason: "objected"`; `access.review()` reports `objected` reads; `rights.summary()` lists `objections`.
21
+ - An objection plans erasure like a withdrawal (fields, never rows). Lifting it cancels the tasks it scheduled that haven't run (new task status `cancelled`).
22
+ - **Rights requests, completed** (Sections 11 to 14, Rule 14):
23
+ - `rights.correct(requestId, { "users.phone": "…" }, { where })` writes a correction through the new optional `DataAccess.updateFields` (all built-in data access have it) and records which fields changed, never the values.
24
+ - `rights.verifyIdentity()` records the identity check; `rights: { verify: "required" }` makes summaries, erasure and corrections for a request wait for it.
25
+ - `rights.acknowledgement()` gives the reference, due date and contact to send; `rights.how()` and `rights.how` / `rights.identifiers` in the config publish Rule 14(1) information.
26
+ - `rights.nominate()`, `nominees()` and `revokeNominee()` (Section 14). `resolve`, `reject`, `erase` and `correct` take `by`, recorded in the history.
27
+ - New events: `rights.verified`, `rights.corrected`, `rights.nominated`.
28
+ - **Cross-border transfers** (Section 16, Rule 15): `countries` and `foreignState` on processors, and `transfers: { restricted, keepInIndia }`. The audit errors on a processor in a restricted country, or abroad for a purpose that must stay in India. `rights.summary().sharedWith` lists countries.
29
+ - **HTTP API** for a privacy centre, a consent screen or a mobile app: `dpdpRouter` (`dpdp-kit/express`), `dpdpRoutes` (`dpdp-kit/hono`) and `createHandlers` (new `dpdp-kit/next`, Web `Request`/`Response` only), over `handle()`.
30
+ - Routes for the notice, consents, objections, the person's data, rights requests and nominees, plus optional `/admin` routes for your privacy team.
31
+ - The person comes only from your authentication; POST must be JSON; bodies are limited; `limitWrites` can refuse floods; errors answer `{ error: code }` only. Paths it doesn't serve go on to your own handlers.
32
+ - **Evidence report**: `dpdp.evidence({ from, to })` and `formatEvidence()`: the data map, processors and countries, Rule 6 safeguards, Rule 14 information, notices shown, consent counts, rights requests, erasure, the access review and breaches, ending with what needs attention. The built-in stores count consent events and tasks in the database. `npx dpdp-kit evidence` writes the config-only parts.
33
+ - **New audit checks**: errors for invalid clauses, countries, notice links, descriptions and translations (only when you use those settings); warnings `legitimate-use-clause-missing`, `rights-how-missing`, `processor-countries-missing`, `foreign-state-transfer` and `notice-label-missing`. Warnings new in 0.5 are reported but don't fail `--strict` until 0.6 (`Issue.since`).
34
+ - **Releases from GitHub Actions** with npm provenance.
35
+
36
+ ### Upgrading from 0.4.x
37
+
38
+ 1. **Storage.**
39
+ - Plain SQL or Drizzle tables from `DPDP_DDL`: run `MIGRATE_0_5_DDL` once (from `dpdp-kit/postgres` or `dpdp-kit/drizzle`). It lets the consent table accept objections and creates `dpdp_privacy_notices`. It's safe to run twice. Drizzle users can instead add `privacyNotices` to their schema and generate a migration.
40
+ - Prisma: add the new `DpdpPrivacyNotice` model from `PRISMA_MODELS` and run `prisma migrate dev`.
41
+ - MongoDB: nothing to do.
42
+ 2. **Types that grew.** `ConsentAction` adds `"object" | "lift-objection"`, `ErasureReason` adds `"objection"`, `TaskStatus` adds `"cancelled"`, and there are new events and error codes. A `switch` that lists every case needs the new ones. `consent.history()` now includes objections when there are any.
43
+ 3. **Guards** may answer `{ error: "consent_required", reason: "objected" }` for a 7(a) purpose the person objected to.
44
+ 4. **`rights.erase({ requestId })`** now needs an open `erasure` request for that person, checked before anything is scheduled. `summary(subjectId, { requestId })` checks that the request is the person's and open. With `verify: "required"`, both also need the identity check.
45
+ 5. **Custom stores and data access.** `NoticeStore`, `StatsStore` and `DataAccess.updateFields` are optional: without them, saved notices, database counts in the evidence report and corrections aren't available, and everything else works.
46
+ 6. **Audit.** Run `npx dpdp-kit audit` and fill in what the new warnings ask for (`legitimateUse` on each legitimate use, `rights.how`, `countries` on processors) before 0.6, when they start failing `--strict`.
47
+
3
48
  ## 0.4.1
4
49
 
5
50
  The GitHub Action's description is now short enough for the GitHub Marketplace (under 125 characters), so this release can be listed there. No changes to the library.
package/LICENSE-APACHE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -10,6 +10,9 @@
10
10
 
11
11
  - **Declare why you hold each piece of personal data**, in one typed config file. A misspelt purpose is a type error.
12
12
  - **Keep consent records that show tampering.** Each person's grants and withdrawals form a hash chain, with the notice version and language they saw.
13
+ - **Build the privacy notice from the config** (from 0.5). Itemised data, purposes and the links Rule 3 requires, in English and the translations you supply; each consent records the version shown, and the notice is saved as proof.
14
+ - **Serve the privacy routes** (from 0.5). `dpdpRouter` for Express, `dpdpRoutes` for Hono and `dpdp-kit/next` for Next.js: consents, objections, the person's data, rights requests and nominees, for any frontend to call with `fetch`.
15
+ - **Export the evidence** (from 0.5). `dpdp.evidence()` and `formatEvidence()`: one Markdown report of the data map, safeguards, notices shown, consent counts, rights requests, erasure, the access review and breaches, ending with what needs attention. `dpdp-kit evidence --static` does the config-only parts.
13
16
  - **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.
14
17
  - **Handle a breach on time.** Record it, find and tell the people affected, and track the Board's 72-hour deadline (Section 8(6), Rule 7).
15
18
  - **Show who touched what.** An access log records who read whose data and why, flags reads outside a field's purpose, and keeps a year of entries, as Rule 6 requires. Encryption, tokens and masking for Aadhaar, PAN and other identifiers come in `dpdp-kit/protect`.
@@ -54,7 +57,7 @@ export default defineConfig({
54
57
  fiduciary: { name: "Acme Pvt Ltd", grievanceUrl: "https://acme.in/privacy/grievance" },
55
58
 
56
59
  purposes: {
57
- account: { basis: "legitimate-use", retain: "while-active" },
60
+ account: { basis: "legitimate-use", legitimateUse: "7(a)", retain: "while-active" },
58
61
  order_updates: { basis: "consent", retain: "while-active" },
59
62
  marketing_sms: { basis: "consent", retain: { afterWithdrawal: "0d" } },
60
63
  analytics: { basis: "consent", retain: { afterWithdrawal: "7d" } }, // time for the batch job to run
@@ -79,8 +82,8 @@ export default defineConfig({
79
82
  },
80
83
 
81
84
  processors: {
82
- msg91: { purposes: ["order_updates", "marketing_sms"] },
83
- posthog: { purposes: ["analytics"] },
85
+ msg91: { purposes: ["order_updates", "marketing_sms"], countries: ["IN"] },
86
+ posthog: { purposes: ["analytics"], countries: ["US"] },
84
87
  },
85
88
 
86
89
  minimumRetention: "1y", // Rule 8(3): keep data and logs of each processing at least one year
@@ -205,7 +208,7 @@ await dpdp.consent.history(userId); // every event, oldest first
205
208
  await dpdp.consent.verify(userId); // { ok: true, events: 1 }
206
209
  ```
207
210
 
208
- `has()` answers "do I hold consent, or not need it, for this purpose?". It is always `true` for legitimate-use purposes. Under Section 7(a) you must still stop once the person tells you they don't want their data used; v0.1 doesn't record that yet.
211
+ `has()` answers "do I hold consent, or not need it, for this purpose?". For a consent purpose it is `true` while the latest choice is a grant. For a Section 7(a) purpose (`legitimateUse: "7(a)"`) it is `true` until the person objects with `consent.object()` (from 0.5). Other legitimate uses are always `true`.
209
212
 
210
213
  ## 4. Withdrawals and deletions
211
214
 
@@ -283,7 +286,7 @@ await dpdp.rights.reject(otherId, "Duplicate of an earlier grievance");
283
286
  const summary = await dpdp.rights.summary(userId);
284
287
  // { data: [{ table: "users", fields: [...], rows: [{ phone: "98…", name: "Asha" }] }],
285
288
  // consents: ["order_updates"], legitimateUses: ["account"],
286
- // sharedWith: [{ name: "msg91", purposes: ["order_updates"] }] }
289
+ // sharedWith: [{ name: "msg91", purposes: ["order_updates"], countries: ["IN"] }] }
287
290
  ```
288
291
 
289
292
  **Erasure (Section 12(3)):** every purpose ends except those you still need for the specified purpose. Legal holds and `minimumRetention` still apply:
@@ -292,7 +295,7 @@ const summary = await dpdp.rights.summary(userId);
292
295
  await dpdp.rights.erase(userId, { keepFor: ["account"], requestId: request.id }); // schedules, resolves the request
293
296
  ```
294
297
 
295
- 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:
298
+ From 0.5, `rights.correct(requestId, { "users.phone": "…" })` writes a correction and records which fields changed, `rights.nominate()` keeps nominees (Section 14), `rights.verifyIdentity()` records the identity check (and `rights: { verify: "required" }` makes it a precondition), and `rights.acknowledgement()` gives the reference and due date to send. Put how people make a request in `rights.how` (Rule 14(1)). Set your own answer times in the config. The Rules set ninety days for grievances only, and the audit fails above that:
296
299
 
297
300
  ```ts
298
301
  rights: { responseWithin: { grievance: "30d", access: "30d" } },
@@ -443,7 +446,7 @@ Add the tables to your schema so drizzle-kit creates them:
443
446
 
444
447
  ```ts
445
448
  // schema.ts
446
- export { accessLog, breachNotices, breaches, consentEvents, erasureTasks, rightsRequests } from "dpdp-kit/drizzle";
449
+ export { accessLog, breachNotices, breaches, consentEvents, erasureTasks, privacyNotices, rightsRequests } from "dpdp-kit/drizzle";
447
450
  ```
448
451
 
449
452
  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.
@@ -537,8 +540,8 @@ Section 6(10) puts the burden on you: if consent is questioned in a proceeding,
537
540
  | **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 |
538
541
  | **v0.3.0** | Security safeguards (Rule 6): access log with review and one-year retention, `dpdp-kit/protect` (encryption, virtual tokens, masking), `protect` / `contract` / `security` in the config, `dpdp-kit safeguards`; Fastify and NestJS guards; `logAccess` for every framework; events (`dpdp.on`); `erase` replacements for `NOT NULL` columns; `dpdp.daily()` and `startDaily` |
539
542
  | **v0.4.0** | **Breach records** (Section 8(6), Rule 7) with the 72-hour Board report; **Prisma**, **MongoDB and Mongoose** and plain-SQL Postgres stores and data access; drift checks on Prisma schemas and Mongoose models; example apps run in CI |
540
- | next (0.5) | Notices that meet Rule 3 from the config, recording objections to a Section 7(a) use, an HTTP API with Express, Hono and Next.js adapters, completing rights requests, cross-border transfer records (Section 16) |
541
- | after (0.6) | MySQL and SQLite data access, React and React Native consent screens, Next.js and Expo example apps |
543
+ | **v0.5.0** | **Notices** that meet Rule 3, built from the config and saved as proof; **objections** to a Section 7(a) use; rights requests completed (corrections, identity checks, nominees, acknowledgements); **cross-border transfers** (Section 16); an **HTTP API** for Express, Hono and Next.js; the **evidence report**; npm releases with provenance |
544
+ | next (0.6) | React and React Native consent screens on the HTTP API, MySQL and SQLite data access, Next.js and Expo example apps |
542
545
  | later | Children and guardian consent (Section 9, Rule 10), inactivity erasure (Rule 8(1)–(2), Third Schedule), erasure beyond SQL (files, caches, search indexes), Consent Manager interop (Sections 6(7)–6(9), Rule 4) |
543
546
 
544
547
  ## When the Rules apply
@@ -560,4 +563,11 @@ Report a wrong or outdated reference as an issue. It's treated as a bug.
560
563
 
561
564
  ## Licence
562
565
 
563
- MIT
566
+ Licensed under either of
567
+
568
+ - the MIT licence ([LICENSE-MIT](LICENSE-MIT)), or
569
+ - the Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE)),
570
+
571
+ at your option. Versions up to 0.5.0 were published under MIT only.
572
+
573
+ Unless you explicitly state otherwise, any contribution you intentionally submit for inclusion in dpdp-kit, as defined in the Apache-2.0 licence, is dual-licensed as above, without any additional terms or conditions.
package/dist/access.d.ts CHANGED
@@ -69,7 +69,7 @@ export declare function resolveFields(config: DpdpConfig<string>, keys: readonly
69
69
  };
70
70
  /** The fields that aren't held for `purpose` according to the data map. */
71
71
  export declare function fieldsOutsidePurpose(config: DpdpConfig<string>, fields: readonly string[], purpose: string): string[];
72
- export type AccessFindingKind = "out-of-purpose" | "no-consent" | "bulk-access";
72
+ export type AccessFindingKind = "out-of-purpose" | "no-consent" | "objected" | "bulk-access";
73
73
  export interface AccessFinding {
74
74
  kind: AccessFindingKind;
75
75
  actor: string;
@@ -105,7 +105,8 @@ export interface ReviewInput {
105
105
  }
106
106
  /**
107
107
  * Look through access log entries for signs of unauthorised access (Rule 6(1)(c)): fields read for
108
- * a purpose they aren't held for, consent purposes used without consent at the time, and one actor
108
+ * a purpose they aren't held for, consent purposes used without consent at the time, Section 7(a)
109
+ * purposes used after the person objected, and one actor
109
110
  * reaching an unusual number of people in a short time.
110
111
  */
111
112
  export declare function reviewAccess(input: ReviewInput): Promise<AccessReview>;
package/dist/audit.d.ts CHANGED
@@ -1,11 +1,16 @@
1
- import type { DpdpConfig } from "./config.js";
1
+ 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" | "contact-missing" | "fiduciary-missing" | "invalid-not-personal" | "unknown-table" | "unknown-column" | "unmapped-personal-column" | "stale-not-personal" | "grievance-response-too-long" | "invalid-request-type" | "unprotected-high-risk-field" | "processor-contract-missing" | "security-measure-missing" | "access-log-retention-too-short" | "invalid-erase" | "erase-not-null" | "erase-type-mismatch" | "held-rows-cascade" | "held-link-lost" | "held-rows-block-delete";
5
+ code: "no-purposes" | "invalid-basis" | "invalid-retention" | "invalid-legitimate-use" | "legitimate-use-clause-missing" | "invalid-duration" | "unknown-purpose" | "field-without-purpose" | "table-without-fields" | "missing-subject-column" | "unused-purpose" | "minimum-retention-missing" | "minimum-retention-too-short" | "grievance-missing" | "contact-missing" | "fiduciary-missing" | "invalid-not-personal" | "unknown-table" | "unknown-column" | "unmapped-personal-column" | "stale-not-personal" | "grievance-response-too-long" | "invalid-request-type" | "rights-how-missing" | "invalid-rights-verify" | "unprotected-high-risk-field" | "processor-contract-missing" | "security-measure-missing" | "access-log-retention-too-short" | "invalid-erase" | "erase-not-null" | "erase-type-mismatch" | "held-rows-cascade" | "held-link-lost" | "held-rows-block-delete" | "invalid-country" | "transfer-restricted" | "transfer-outside-india" | "processor-countries-missing" | "foreign-state-transfer" | "notice-link-missing" | "notice-description-missing" | "notice-label-missing" | "notice-translation-incomplete" | "invalid-notice-language";
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;
9
+ /**
10
+ * The version that introduced this check, for warnings added after 0.4. `--strict` doesn't fail
11
+ * on a warning in the minor version that introduced it, so upgrading doesn't break CI.
12
+ */
13
+ since?: string;
9
14
  }
10
15
  /**
11
16
  * Check a config for mistakes. Errors mean the config can't be used; warnings are things a
@@ -3,11 +3,20 @@ import {
3
3
  } from "./chunk-67Q5GFD6.js";
4
4
 
5
5
  // src/guard.ts
6
- var CONSENT_REQUIRED_BODY = (purpose) => ({
6
+ var CONSENT_REQUIRED_BODY = (purpose, reason) => reason === "objected" ? {
7
+ error: "consent_required",
8
+ purpose,
9
+ reason,
10
+ message: "You've asked us not to use your data for this. You can change that in your privacy settings."
11
+ } : {
7
12
  error: "consent_required",
8
13
  purpose,
9
14
  message: "You haven't agreed to this yet. You can turn it on in your privacy settings."
10
- });
15
+ };
16
+ function consentDeniedBody(dpdp, purpose) {
17
+ const def = dpdp.config.purposes[purpose];
18
+ return CONSENT_REQUIRED_BODY(purpose, def?.basis === "legitimate-use" ? "objected" : void 0);
19
+ }
11
20
  async function checkConsent(dpdp, purpose, options, ctx) {
12
21
  const subjectId = await options.subject(ctx);
13
22
  if (!subjectId) return false;
@@ -32,6 +41,7 @@ async function recordAccess(dpdp, options, ctx) {
32
41
 
33
42
  export {
34
43
  CONSENT_REQUIRED_BODY,
44
+ consentDeniedBody,
35
45
  checkConsent,
36
46
  recordAccess
37
47
  };
@@ -0,0 +1,34 @@
1
+ // src/data-access.ts
2
+ var columnValue = (v) => v !== null && typeof v === "object" && !(v instanceof Date) ? JSON.stringify(v) : v;
3
+ function memoryData(tables) {
4
+ const rowsOf = (table) => tables[table] ??= [];
5
+ const mine = (subjectColumn, subjectId) => (row) => String(row[subjectColumn]) === subjectId;
6
+ return {
7
+ tables,
8
+ async read(table, subjectColumn, subjectId, columns) {
9
+ return rowsOf(table).filter(mine(subjectColumn, subjectId)).map((row) => Object.fromEntries(columns.map((c) => [c, row[c] ?? null])));
10
+ },
11
+ async eraseFields(table, subjectColumn, subjectId, columns, values = {}) {
12
+ const rows = rowsOf(table).filter(mine(subjectColumn, subjectId));
13
+ for (const row of rows) for (const c of columns) row[c] = Object.hasOwn(values, c) ? values[c] : null;
14
+ return rows.length;
15
+ },
16
+ async updateFields(table, subjectColumn, subjectId, values, where = {}) {
17
+ const rows = rowsOf(table).filter(
18
+ (row) => mine(subjectColumn, subjectId)(row) && Object.entries(where).every(([k, v]) => String(row[k]) === String(v))
19
+ );
20
+ for (const row of rows) Object.assign(row, structuredClone(values));
21
+ return rows.length;
22
+ },
23
+ async deleteRows(table, subjectColumn, subjectId) {
24
+ const before = rowsOf(table).length;
25
+ tables[table] = rowsOf(table).filter((row) => !mine(subjectColumn, subjectId)(row));
26
+ return before - tables[table].length;
27
+ }
28
+ };
29
+ }
30
+
31
+ export {
32
+ columnValue,
33
+ memoryData
34
+ };