dpdp-kit is an open-source Node.js toolkit for India's Digital Personal Data Protection Act. You declare why you hold each piece of personal data in one typed config, and it keeps consent records you can prove, carries out erasure on time, logs who reads what, and fails CI when your schema drifts.
Until now it only spoke Drizzle. 0.4.0 works with the database you already have: Prisma, MongoDB and Mongoose, or any Postgres client. It also adds breach records with the Board's 72-hour deadline.
But the part I want to write about is how I tested it, because that's where the surprises were.
Not legal advice. dpdp-kit helps you put compliance into practice; it doesn't make an app compliant on its own.
The test: a year of Chai & Co
Unit tests check functions. Compliance is about what happens over months: someone withdraws consent today, and the law says their data goes a year later. So I built a small online tea shop, Chai & Co, twice (Express + Prisma + Postgres, and Express + Mongoose + MongoDB), and wrote a script that plays a customer, a support agent and the privacy team through a year of it, over HTTP:
- Asha signs up and agrees to promotional SMS, in Marathi. Ravi agrees to nothing.
- A promo goes out: Asha gets it, Ravi gets a plain 403.
- Support opens both records. Each read is logged with who, why and which fields.
- Asha asks what data the shop holds on her (Section 11) and gets it, with who it's shared with.
- Asha withdraws consent. Promos stop at once; the SMS vendor is told to stop.
- Ravi raises a grievance (due in 90 days) and deletes his account.
- Three months on, the overdue grievance shows up in the daily report.
- A support account is compromised. The two people it read are found from the access log, told, and the Board informed; the report is due in 72 hours.
- A year later, erasure runs: Asha's interests are erased, her phone stays (the account still needs it), Ravi's profile is deleted, his invoice is kept for 8 years under GST.
- Both consent records still verify.
It runs in CI on every change, against the packed npm package. Here's what it caught.
Surprise 1: Prisma shifted every timestamp by 5½ hours
On a Postgres server set to Asia/Kolkata, raw queries through Prisma 7's pg adapter returned timestamptz values shifted by the server's offset: 00:00Z came back as 05:30Z. That broke the consent hash chain (each event's hash covers its timestamp) and every deadline. CI ran Postgres in UTC, so it would never have shown up there.
The fix: the SQL store reads timestamps back as UTC text (to_char(at AT TIME ZONE 'UTC', …)), so no driver can shift them. CI now runs its Postgres in IST. If your servers are in India, they probably are too.
Surprise 2: my own config would have failed a year later
The audit refused my first Chai & Co config: four NOT NULL columns that erasure would set to NULL. That failure would have shown up a year after the withdrawal, when the erasure task runs. The config now says what to write instead:
email: { category: "contact", purposes: ["account"], erase: { value: ({ subjectId }) => `erased-${subjectId}@invalid` } },
name: { category: "identity", purposes: ["account"], erase: "redact" },
Surprise 3: a normal foreign key breaks a legal hold
Account deletion deletes the person's rows but keeps the ones under a legal hold, like invoices. With an ordinary Prisma relation from Order to User:
- the default (
Restrict) makes the deletion fail, forever; -
SetNullkeeps the invoice but loses whose it is, so it's never anonymised; -
Cascadesilently deletes the invoices the law says to keep.
dpdp-kit audit --schema now reads the relations in your Prisma or Drizzle schema and says so, with the fix: keep user_id as a plain, indexed column.
What's new in 0.4.0
Prisma
import { prismaData, prismaSchema, prismaStore } from "dpdp-kit/prisma";
const schema = prismaSchema(readFileSync("prisma/schema.prisma", "utf8"));
const dpdp = createDpdp({ config, store: prismaStore(prisma), data: prismaData(prisma, { schema }) });
dpdp-kit's tables come as Prisma models (PRISMA_MODELS), so prisma migrate creates them. The data map can use model and field names (User, phoneNumber). It works inside prisma.$transaction, so a consent record can commit or roll back with your own writes.
MongoDB and Mongoose
import { mongoData, mongooseSchema, mongoStore } from "dpdp-kit/mongodb";
const db = () => mongoose.connection.db; // so dpdp can be created before connect()
const dpdp = createDpdp({
config,
store: mongoStore(db),
data: mongoData(db, { schema: mongooseSchema(mongoose), ObjectId: mongoose.Types.ObjectId }),
});
Nested fields and arrays of subdocuments work, for the drift check and for erasure (addresses.$[].phone).
Any other Postgres client: dpdp-kit/postgres needs only a function that runs a $1-parameterised query, so node-postgres, postgres.js, Kysely and Knex all work.
Drift checks everywhere:
npx dpdp-kit audit --schema prisma/schema.prisma
npx dpdp-kit audit --schema src/models.ts # Mongoose models
Add an aadhaarNumber field without saying what it's for, and the build fails. It's also a GitHub Action, now on the Marketplace.
Breach records (Section 8(6), Rule 7): record a breach, find who's affected (including everyone a compromised account read), draft the notice to each person, and build the Board's detailed report against the 72-hour clock. dpdp.daily() reminds you of every open deadline.
Try it
The two example apps are in examples/, about 150 lines each. Copy whichever matches your stack.
npm i dpdp-kit
- Docs: https://dpdp-kit.js.org/
- GitHub: https://github.com/yogesh2902/dpdp-kit (a star helps others find it)
Next is 0.5: notices built from the config, in each language you offer, recording objections to a legitimate use, and an HTTP API. If you're building on DPDP, I'd love to hear what you need.
Top comments (0)