Skip to main content

Consent client

Create the consent client, connect it to Consent Ledger, and read receipts.

Part of the API reference for the Consent Ledger LiveKit reference integration.

Functions exported from consent-ledger-livekit. Every function validates its input and throws on bad input instead of guessing. The consent client's methods are asynchronous, except subscribe().


Functions

Function

Returns

Use it to

createConsentClient(options)

ConsentClient

Create the consent client your backend calls

createHttpLedgerClient(options)

HttpLedgerClient

Talk to Consent Ledger's HTTP API

createLedgerConsentAdapter(options)

ConsentLedgerAdapter

Connect the consent client to Consent Ledger, with read-back

proposedLedgerMapping(options?)

LedgerConsentMapping

Turn a decision into a Consent Ledger record

readReceiptFields(record)

ReceiptFields | undefined

Read the decision a receipt describes, wherever the mapping stores it

INTEGRATION_ID

'consent-ledger-livekit'

The identifier written into every new record

createMemoryConsentStore()

ConsentStateStore

Keep current decisions in memory (the default; tests and trials only)

isPermitted(submission)

boolean

Check one current decision without a store read

blockReason(submission)

BlockReason | undefined

Get why one current decision blocks recording


createConsentClient(options)

const consent = createConsentClient({
  ledger,                        // required: a ConsentLedgerAdapter
  store,                         // optional: a ConsentStateStore; in memory if omitted
  confirmationTimeoutMs: 5_000,  // optional: how long submitDecision waits for Consent Ledger (1 to 60,000 ms)
});

The ConsentClient it returns:

Method

Returns

What it does

submitDecision(decision)

Promise<ConsentSubmission>

Saves the decision as current, sends it to Consent Ledger once, and waits up to confirmationTimeoutMs for the receipt. Never retries automatically.

getCurrentDecision(scope)

Promise<ConsentSubmission | undefined>

The participant's current decision for this meeting and purpose, with its receipt status.

refreshConfirmation(scope)

Promise<ConsentSubmission | undefined>

Reads a pending receipt from Consent Ledger again without writing again. Changes it only to confirmed or failed. Returns undefined if no current decision exists.

checkPermission(request)

Promise<ConsentPermission>

Whether every participant in the supplied participantIds list may be recorded, and why not for each one who may not. It checks only the listed participants, not necessarily everyone in the meeting.

endSession(sessionId)

Promise<void>

Ends a meeting: deletes its current decisions. The PostgreSQL store keeps the receipt references.

subscribe(listener)

() => void (unsubscribe)

Calls listener(submission) when a decision becomes current and when its receipt settles. In this process only. Not asynchronous.

scope is { sessionId, participantId, purposeId }. request is { sessionId, purposeId, participantIds } with 1 to 10,000 IDs. See Types and errors for ConsentDecision, ConsentSubmission and ConsentPermission.


createHttpLedgerClient(options)

const ledgerClient = createHttpLedgerClient({
  baseUrl: 'https://api.enzuzo.com',  // the Consent Ledger API base URL
  ledgerId,                           // the ledger's UUID
  readToken,                          // a token with ledger:read; used only for reads
  timeoutMs: 2_000,                   // per request
  fetchImpl,                          // optional: a fetch function, for tests or proxies
});
await ledgerClient.readRecord(recordId);  // { status: 'found', record } or { status: 'not-found' }
await ledgerClient.writeRecord(payload);  // { status: 'accepted', recordId } | 'rejected' | 'unknown'

baseUrl is the API base URL from the Consent Ledger Quickstart Guide. It must use HTTPS (HTTP only for localhost) and have no credentials, query, or fragment.

You rarely call it directly: pass it to createLedgerConsentAdapter. It throws LedgerHttpError with a code (unauthorized, forbidden, timeout, network, rate-limited, and others) for reads that fail.


createLedgerConsentAdapter(options)

const ledger = createLedgerConsentAdapter({
  client: ledgerClient,              // required
  mapping: proposedLedgerMapping(),  // required: decision to Consent Ledger record
  readBackIntervalMs: 100,           // optional: first read-back delay, doubling up to 1 s
});

Writes each decision once and reads it back until the stored record matches exactly. The outcome becomes the receipt status: confirmed, pending (accepted but not readable yet, with its record ID), failed (rejected, or a different record stored), or unknown (the write's outcome is uncertain). A write Consent Ledger accepted (HTTP 202) is not a confirmed receipt and never permits recording by itself.


proposedLedgerMapping(options?)

Turns a decision into a Consent Ledger record. Acceptances are stored with the analytics category; declines and withdrawals with no categories. The original choice, purpose, session, revision, notice version, and participant are kept in the record. The field names and locations are provisional, so read them with readReceiptFields rather than from fixed paths. See the LiveKit receipt reference for an example record.


readReceiptFields(record)

const read = await ledgerClient.readRecord(recordId);
if (read.status === 'found') {
  const fields = readReceiptFields(read.record);
  // { integrationId, submissionId, sessionId, participantId, purposeId, choice, revision, noticeVersion },
  // or undefined if the record was not written by this mapping or a field is missing
}

It describes the record only. Recording permission comes from the participant's current decision in your database, never from a receipt.

Did this answer your question?