npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lotusflare/consent-ts-sdk

v1.0.2

Published

TypeScript SDK for Consent Service

Readme

Consent TypeScript SDK

A TypeScript SDK for interacting with the Consent Service, enabling applications to manage user consent for data access and sharing in a secure and standardized way.

Installation

To install the SDK, first package it locally and then add it to your project:

cd consent-ts-sdk
npm pack

# in your project
yarn add ../consent-ts-sdk/consent-ts-sdk-1.0.0.tgz
# or
npm install ../consent-ts-sdk/consent-ts-sdk-1.0.0.tgz

Quick Start

This section provides a step-by-step guide to integrating the Consent SDK into your TypeScript project.

1. Initialize TokenProvider

The SDK supports multiple authentication strategies for obtaining access tokens. Choose the one that best fits your use case:

Client Credentials Token Provider

Use this provider to obtain tokens using Keycloak client credentials. This is recommended for most server-to-server integrations.

import { TokenProviderFactory } from 'consent-ts-sdk';

// Create a token provider using client credentials
envconst tokenProvider = TokenProviderFactory.createClientCredentialsTokenProvider(
  'https://keycloak-server.example.com'
  'my-realm',
  'my-client-id',
  'my-client-secret',
);

Static Token Provider

Use this provider if you already have a valid access token. This is useful for testing or simple integrations where token management is handled externally.

import { TokenProviderFactory } from 'consent-ts-sdk';

// Create a token provider using a static token
const tokenProvider = TokenProviderFactory.createStaticProvider('your-static-access-token');

JWT Token Provider

Use this provider to sign and obtain tokens using a JWT and your private key. This is suitable for advanced scenarios requiring custom token signing.

import { TokenProviderFactory } from 'consent-ts-sdk';

// Create a token provider using JWT
const tokenProvider = TokenProviderFactory.createJwtTokenProvider(
  'https://keycloak-server.example.com',
  'my-realm',
  'my-client-id',
  '/privateKeyPath',
  'your-key-id'
);

2. Create ConsentClient

The ConsentClient is the main entry point for interacting with the Consent Service. You need to provide a TokenProvider and the base URL of your Consent Service instance.

import { createConsentClient } from 'consent-ts-sdk';

const baseUrl = 'https://your-consent-service.example.com';
const consentClient = createConsentClient(tokenProvider, baseUrl);

3. Check Consent

To check if a user needs to provide consent for specific operations, use the checkConsent method. This method validates whether the user has already granted the necessary permissions or if they need to go through a consent flow.

Key Points:

  • If consent is already granted, the operation can proceed immediately
  • If consent is required, you'll need to initiate a consent intent flow

Response Handling:

  • success: true - Consent check completed successfully
  • response - Contains detailed consent information and status
  • message - Error details if the check failed
import { ConsentCheckRequest } from 'consent-ts-sdk';

const request = new ConsentCheckRequest(
  'myuserId',           // User ID
  'myclientId',         // Client ID
  'auth_code',          // Grant type
  'dpv:AccountManagement number-verification-share-read number-verification-verify-read' // Purpose and scopes
);

const operatorName = 'your-operator';

const result = await consentClient.checkConsent(request, operatorName);

if (result.success) {
  console.log('Consent check successful!');
  console.log('Response:', result.response);
} else {
  console.log('Consent check failed:', result.message);
}

4. Get Consent Intent

If the user has not yet provided consent, initiate a consent intent to generate the consent intent token.

import { GetConsentIntentRequest } from 'consent-ts-sdk';

const getConsentIntentRequest = new GetConsentIntentRequest(
  'myUserId',      // User ID
  'myUserName',    // Username
  'myClientId',    // Client ID
  'dpv:AccountManagement number-verification-share-read number-verification-verify-read', // Purpose and scopes
  result.response  // Response from consent check
);

const intentResult = await consentClient.getConsentIntent(getConsentIntentRequest, operatorName);

console.log('Consent intent result:', intentResult);

5. Confirm Consent

After the user has reviewed and approved the requested consent, confirm their decision by submitting the consent confirmation request.

import { ConsentConfirmRequest } from 'consent-ts-sdk';

const confirmRequest = new ConsentConfirmRequest(
  'testUserId',         // User ID
  'mySpecificationId',  // Specification ID
  'testUserName',       // Username
  'myClientId',         // Client ID
  [
    { name: 'predicate1', agreed: true },
    { name: 'predicate2', agreed: false }
  ]                     // List of predicates representing user choices
);

try {
  const confirmResult = await consentClient.consentConfirm(confirmRequest, operatorName);
  console.log('Consent confirm result:', confirmResult);
} catch (error) {
  console.log('Consent confirm failed:', error);
}