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

@ogcio/pii-utils

v0.1.0

Published

Utilities for handling Personally Identifiable Information (PII) in Node.js services.

Readme

@ogcio/pii-utils

Utilities for handling Personally Identifiable Information (PII) in Node.js services.

Each utility is published as a separate subpath export so applications only import what they need.

Prerequisites

  • Node.js >= 24
  • A pepper service implementation (e.g. the built-in AWS adapter, or a custom one)

Installation

npm install @ogcio/pii-utils

If using the AWS Secrets Manager adapter, also install the SDK:

npm install @aws-sdk/client-secrets-manager

pii-hasher

A one-way HMAC-SHA256 hasher for PII values. It produces deterministic, non-reversible hashes using a pepper fetched from a pluggable PepperService, allowing services to compare PII-derived identifiers without retaining the original plaintext.

Import

import {
  createPiiHasher,
  createAwsPepperService,
} from "@ogcio/pii-utils/pii-hasher";

Quick start (AWS)

import {
  createPiiHasher,
  createAwsPepperService,
} from "@ogcio/pii-utils/pii-hasher";
import { SecretsManagerClient } from "@aws-sdk/client-secrets-manager";

const pepperService = createAwsPepperService({
  secretName: "my-app/pii-pepper",
  client: new SecretsManagerClient({ region: "eu-west-1" }),
});

const hasher = createPiiHasher({
  pepperService,
  applicationId: "citizen-portal",
});

const { hash, pepperVersion } = await hasher.hash("[email protected]");
console.log(hash);          // 64-char hex string
console.log(pepperVersion); // e.g. "abc123-def456"

// When shutting down, stop background refresh timers
hasher.dispose();

Quick start (custom provider)

import { createPiiHasher } from "@ogcio/pii-utils/pii-hasher";
import type { PepperService } from "@ogcio/pii-utils/pii-hasher";

const pepperService: PepperService = {
  async fetch() {
    const pepper = Buffer.from(process.env.PEPPER_KEY!, "base64");
    return { value: pepper, version: "env-v1" };
  },
};

const hasher = createPiiHasher({
  pepperService,
  applicationId: "citizen-portal",
});

Configuration

createPiiHasher accepts a PiiHasherConfig object:

| Option | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | pepperService | PepperService | Yes | — | Pluggable pepper provider (e.g. createAwsPepperService()). | | applicationId | string | Yes | — | Application identifier mixed into every hash to scope outputs per application. | | cacheTtlSec | number | No | 300 (5 min) | How long the pepper is cached locally before re-fetching. Minimum 30. |

PepperService interface

interface PepperService {
  fetch(): Promise<{ value: Buffer; version: string }>;
}

Any object implementing fetch() can be used. The return value must include the raw pepper bytes (value) and a version identifier (version).

AWS adapter

createAwsPepperService creates a PepperService backed by AWS Secrets Manager:

| Option | Type | Required | Description | | --- | --- | --- | --- | | secretName | string | Yes | AWS Secrets Manager secret name. | | client | SecretsManagerClient | Yes | Pre-configured AWS SDK client. |

The secret value should be a plain base64-encoded string (not JSON). The adapter decodes it and uses the AWS response VersionId as the pepper version.

How hashing works

Each call to hasher.hash(value) performs the following:

  1. Retrieves (or uses a cached) pepper via the configured PepperService.
  2. Computes HMAC-SHA256(pepper, applicationId + "\0" + value).
  3. Returns the digest as a 64-character lowercase hex string together with the pepper version.

The null-byte separator prevents ambiguous concatenation between the application ID and the value.

Warmup

The pepper is fetched lazily on the first hash() call. To avoid that initial latency and detect errors early (for example during application startup), call warmup():

const hasher = createPiiHasher({
  pepperService,
  applicationId: "citizen-portal",
});

await hasher.warmup(); // fetches + caches the pepper, starts the background refresh timer

// first hash() is now served from cache with no network call
const { hash } = await hasher.hash("[email protected]");

warmup() throws if the pepper cannot be fetched, so any connectivity or permission problems surface immediately at startup rather than on the first user request. It can only be called once per hasher instance — calling it again throws an error.

Pepper caching

The pepper is cached in memory for the duration of cacheTtlSec. A background timer proactively refreshes the cache 10 seconds before expiry so that hot-path calls never block on a network fetch. Background refresh failures are silently suppressed — the existing cached value continues to be used until it expires.

Call hasher.dispose() during graceful shutdown to clear the refresh timer and avoid leaked handles.

Exported types

import type {
  PiiHasher,
  PiiHasherConfig,
  HashResult,
  PepperService,
  AwsPepperServiceConfig,
} from "@ogcio/pii-utils/pii-hasher";

| Type | Description | | --- | --- | | PiiHasher | Interface returned by createPiiHasher with hash(), warmup(), and dispose() methods. | | PiiHasherConfig | Configuration object accepted by createPiiHasher. | | HashResult | Object with hash (hex string) and pepperVersion (string). | | PepperService | Interface for pluggable pepper providers. | | AwsPepperServiceConfig | Configuration object accepted by createAwsPepperService. |


Benchmark

A benchmark harness is included under benchmark/ to compare HMAC and PBKDF2 candidates against the default HMAC-SHA256 implementation. It is not published as part of the package.

npm run benchmark

See benchmark/README.md for the full benchmark contract and candidate list.

Development

npm run build    # Compile TypeScript
npm run test     # Run tests with coverage