Events
Listen for consent, erasure, rights and access changes to feed your own audit trail, alerts or analytics.
ts
const off = dpdp.on("consent.withdrawn", ({ event, erasure }) => {
analytics.forget(event.subjectId, event.purposes);
});
off(); // stop listeningThe events#
| Event | Fires when | Carries |
|---|---|---|
consent.granted |
consent.grant() saved |
{ event } |
consent.withdrawn |
consent.withdraw() saved |
{ event, erasure, tasks } |
consent.objected |
consent.object() saved |
{ event, erasure, tasks } |
consent.objection-lifted |
consent.liftObjection() saved |
{ event, cancelled, tasks } |
erasure.scheduled |
erasure tasks were saved, from a withdrawal, an account deletion or an erasure request | { plan, tasks } |
retention.ran |
retention.run() finished |
{ report } |
rights.opened |
rights.open() saved |
{ request } |
rights.closed |
a request was resolved or rejected | { request } |
rights.verified |
rights.verifyIdentity() saved |
{ request } |
rights.corrected |
rights.correct() wrote the changes |
{ request, fields } |
rights.nominated |
rights.nominate() saved |
{ nominee } |
access.logged |
access.log() saved, including a refused out-of-purpose read |
{ entries } |
Listeners are typed: the payload matches the event name.
How listeners run#
- After the change is saved. An event never fires for something that failed to save.
- After the call returns. Listeners run on the next turn of the event loop, so a slow webhook doesn't delay
grant()orwithdraw(). - They can't break anything. If a listener throws or rejects, the call that fired it has already succeeded. The error goes to
onListenerError, which defaults toconsole.error:
ts
const dpdp = createDpdp({
config,
store,
onListenerError: (error, event) => logger.warn({ error, event }, "dpdp listener failed"),
});Listeners live in memory, in the process that made the change. For something that must happen exactly once, such as telling a vendor to erase, use processor hooks and the retention runner, which retry and record the result.
Ideas#
- Send a Slack alert when
access.loggedhasoutOfPurposeentries. - Mirror
consent.grantedandconsent.withdrawnto your analytics tool's consent API. - Email the person when
rights.openedfires, acknowledging their request. - Page someone when
retention.ranreports failed tasks.