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

@belkajo/privatrail-sdk

v1.0.10

Published

Privacy-first consent logging SDK for Privatrail

Downloads

41

Readme

Privatrail SDK

Privatrail SDK – a lightweight TypeScript client for communicating with the Privatrail API.
This package is currently in development / internal testing phase.


🧩 Overview

The SDK provides a simple way to send consent logs and perform health checks against the Privatrail API.
It is designed to work in server-only environments (Next.js Server Actions, API routes, or Node.js services).


📦 Structure

src/
 ├── client.ts         # Core HTTP client
 ├── logActions.ts     # Convenience functions for consent logging
 ├── types.ts          # Shared types for requests and responses
 └── index.ts          # Export entry

⚙️ Setup

You can include this SDK locally (until it’s published):

pnpm add ../packages/privatrail-sdk

Then import and initialize it in your Next.js or Node project.


🚀 Usage

1. Initialize SDK Settings

Before making any API calls, set the base URL and token.

import { setClientSettings } from "@privatrail/privatrail-sdk";

setClientSettings(
  process.env.PRIVATRAIL_ENDPOINT!, // e.g. https://api.privatrail.local
  process.env.PRIVATRAIL_TOKEN!     // JWT or API token
);

2. Perform a Health Check

import { getHealthz } from "@privatrail/privatrail-sdk";

const health = await getHealthz();
console.log("API status:", health);

Expected response:

{
  "status": "ok",
  "db": "ok",
  "detail": ""
}

3. Log a Consent Change

import { recordLog } from "@privatrail/privatrail-sdk";

await recordLog({
  visitor_id: "abc123",
  policy_version: "1.0",
  client_name: "demo-site",
  channel: "web",
  client_version: "0.1.0",
  client_config: "default",
  changes: [
    {
      purpose: "analytics",
      lawful_basis: "consent",
      granted: true,
      position: 0
    }
  ]
});

This will POST to /api/v1/consent/log using your configured endpoint.


🧠 Internals

ApiClient

A minimal HTTP wrapper with JSON parsing, header handling, and date revival.
Supports GET / POST / PUT etc., and automatically attaches the Authorization header.

logActions

A convenience layer on top of ApiClient, exposing:

  • getHealthz() → quick API status check
  • recordLog(request) → send consent log
  • setClientSettings(baseUrl, token) → configure before calling

🧰 Requirements

  • Node.js ≥ 18
  • fetch API available globally (default in Next.js 14+)

🧪 Development Notes

Build the package locally:

pnpm build

Clean old builds:

pnpm run clean

This will generate compiled output in dist/ ready for internal linking or publishing later.


📄 License

Currently unlicensed (internal use only)
a proper open-source license (e.g. MIT) will be added before public release.


📅 Status

🧱 MVP-level SDK for internal integration testing.
Next steps:

  • Add input validation
  • Add error handling and retry logic
  • Prepare documentation for public release