Run the sample app
Set up and run Kalpa Learning, a small Node.js and Express site that shows a complete integration, and see where each part lives.
Kalpa Learning is a small online-courses site built to show a complete integration under the DPDP Act. It is plain Node.js and Express with server-rendered pages: no build step and no database. Run it to see every call working before you write your own.
Before you start#
- The sample's source. Your account contact can give it to you.
- Node.js 20.6 or later.
- Access to the console of your deployment.
Set up the console#
- Create a property for the site with the origin
http://localhost:4816. - Enable the India (DPDP Act) region rule on the property and publish its banner form.
- Create a second form on the same property with two purposes,
course-updates-by-emailandclass-reminders-by-sms. Publish it and note its key. - On Install, choose New key and switch on Also create a secret key for your server. Allow the origin
http://localhost:4816. - Under Scopes, grant
subjects:read,subjects:export,subjects:withdraw,subjects:eraseandsubjects:link. Leave it a test key. - Copy the publishable key, the secret key and the identity secret from Key created.
The second form needs no region rule. The sample loads it by key and never shows it as a banner.
Configure and run#
-
In the sample's folder, create a file named
.envwith your values..envConfig PIEDAP_API_URL=https://console.dpconsent.com/consent PIEDAP_PUBLISHABLE_KEY=pk_… PIEDAP_SECRET_KEY=sk_… PIEDAP_IDENTITY_SECRET=idv_… PIEDAP_WEBHOOK_SECRET=whsec_… PIEDAP_ACCOUNT_FORM_KEY=kalpa-account SESSION_SECRET=… PORT=4816 -
Set
SESSION_SECRETto any long random text, such as the output ofopenssl rand -hex 32. -
Install the packages and start the site.
Shell npm install npm start -
Open
http://localhost:4816, sign up and tick one of the two boxes. -
Open
http://localhost:4816/adminand look the new learner up by email address.
The look-up lists the sign-up record. Only the publishable key reaches the browser. Keep .env out of version control.
To match banner records to learners by fingerprint, also set PIEDAP_FINGERPRINT_KEY to the project's fingerprint key, sfk_…. It is optional.
Receive webhooks through a tunnel#
Webhooks are delivered only to an address on the public internet. To receive them on your own machine, open a tunnel.
- In a second terminal, run
npm run tunneland copy the public address it prints. - In the console, open Install → Webhooks and choose Add endpoint. Enter the tunnel address followed by
/webhooks/piedap. - Tick the four
consent.events,subject_request.received,subject_request.completedand the threesubject.events. - Copy the Signing secret into
PIEDAP_WEBHOOK_SECRETand restartnpm start.
Events then appear on /admin/webhooks as they arrive, with "test": true. Without a tunnel, that page has a button that signs a sample event with your webhook secret and posts it to the same route.
What the sample shows#
| In the sample | File | Guide |
|---|---|---|
| The loader tag, first in the page head | src/views/layout.mjs |
Install on a website |
| Sign-up consent recorded by the server, with email, phone and session linked | src/piedap.mjs |
Record consent from your server |
| Banner answers recorded under the learner's account | src/piedap.mjs |
Record consent for signed-in visitors |
| The "Your privacy" page: list, Withdraw all, Delete my data | src/server.mjs |
Find a person's records, Withdraw or erase a person |
| Download my data | src/server.mjs |
Answer an access request |
| The webhook receiver | src/webhooks.mjs |
Receive webhooks |
| Matching an event to a learner | src/webhooks.mjs |
Match events to your users |
The examples folder holds one short file for each task, so a single part can be copied into another app. Run one with node --env-file=.env examples/<file>.mjs.
Not ready for production
The sample stores accounts in a JSON file, and its demo console has no login. Replace both before anything like it goes live.