Consent Docs

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.

How-to3 min readFor web, backend and mobile developers

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#

  1. Create a property for the site with the origin http://localhost:4816.
  2. Enable the India (DPDP Act) region rule on the property and publish its banner form.
  3. Create a second form on the same property with two purposes, course-updates-by-email and class-reminders-by-sms. Publish it and note its key.
  4. On Install, choose New key and switch on Also create a secret key for your server. Allow the origin http://localhost:4816.
  5. Under Scopes, grant subjects:read, subjects:export, subjects:withdraw, subjects:erase and subjects:link. Leave it a test key.
  6. 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#

  1. In the sample's folder, create a file named .env with 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
  2. Set SESSION_SECRET to any long random text, such as the output of openssl rand -hex 32.

  3. Install the packages and start the site.

    Shell
    npm install
    npm start
  4. Open http://localhost:4816, sign up and tick one of the two boxes.

  5. Open http://localhost:4816/admin and 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.

  1. In a second terminal, run npm run tunnel and copy the public address it prints.
  2. In the console, open Install → Webhooks and choose Add endpoint. Enter the tunnel address followed by /webhooks/piedap.
  3. Tick the four consent. events, subject_request.received, subject_request.completed and the three subject. events.
  4. Copy the Signing secret into PIEDAP_WEBHOOK_SECRET and restart npm 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.

↑↓ to move, Enter to open