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

@figchain/client

v0.1.0

Published

Official JavaScript/TypeScript client for FigChain configuration management

Readme

FigChain JavaScript/TypeScript Client

Official JavaScript/TypeScript client library for FigChain configuration management.

Features

  • Real-time configuration updates - Subscribe to configuration changes with background polling
  • Rule-based rollouts - Evaluate feature flags and configurations based on user context
  • Type-safe models - Full TypeScript support with Avro-based serialization for efficient data transfer
  • Flexible storage - Thread-safe in-memory storage
  • Node.js & Browser - Works in both Node.js and modern browsers
  • Encryption support - End-to-end encryption with X25519/ChaCha20-Poly1305
  • S3 Backup - Optional S3-based configuration backup and bootstrap

Installation

Install using npm:

npm install figchain-client

Or using yarn:

yarn add figchain-client

Quick Start

1. Create a configuration file

Create a client-config.json file in the same directory as your service.

2. Initialize and use the client

import { FigChainClient } from 'figchain-client';

// Load configuration from client-config.json and initialize
const client = await FigChainClient.create('client-config.json');

// Define context for evaluation (e.g., user properties for traffic splitting)
const context = {
  userId: "user123",
  plan: "premium"
};

// Fetch configuration
const config = await client.getFig("your-fig-key", context);

if (config?.enabled) {
  console.log(`Feature enabled with color: ${config.backgroundColor}`);
} else {
  console.log("Feature disabled");
}

// Listen for configuration changes
client.on("your-fig-key", (newConfig) => {
  console.log("Configuration updated:", newConfig);
});

// Clean up resources when done
client.close();

Configuration

Loading from file (recommended)

Create a client-config.json file in the same directory as your service:

// Loads from ./client-config.json
const client = await FigChainClient.create('client-config.json');

// Or specify a custom path
const client = await FigChainClient.create('/path/to/config.json');

// Override specific options
const client = await FigChainClient.create('client-config.json', {
  pollInterval: 30,
  namespaces: ["production"]
});

Programmatic configuration

You can also configure the client entirely through code:

Programmatic configuration

You can also configure the client entirely through code:

const client = new FigChainClient({
  environmentId: "your-environment-id",
  credentialId: "your-credential-id",
  authPrivateKey: "hex-encoded-ed25519-private-key",
  namespaces: ["default"] // Can also pass a string or Set
});

await client.init();

Environment variables

All configuration options can be set via environment variables:

# Required
export FIGCHAIN_ENVIRONMENT_ID="your-environment-id"
export FIGCHAIN_IDENTITY_PRIVATE_KEY="hex-encoded-ed25519-private-key"

# Optional
export FIGCHAIN_URL="https://app.figchain.io/api/"
export FIGCHAIN_NAMESPACES="default,production"
export FIGCHAIN_NAMESPACE="default"  # For single namespace
export FIGCHAIN_POLLING_INTERVAL_MS="60000"
export FIGCHAIN_AS_OF_TIMESTAMP="2026-01-01T00:00:00Z"

# Keys (hex-encoded)
export FIGCHAIN_IDENTITY_PRIVATE_KEY="hex-encoded-ed25519-private-key"
export FIGCHAIN_ENCRYPTION_PRIVATE_KEY="hex-encoded-x25519-private-key"

# S3 Backup
export FIGCHAIN_S3_BACKUP_ENABLED="true"
export FIGCHAIN_S3_BACKUP_BUCKET="my-config-bucket"
export FIGCHAIN_S3_BACKUP_PREFIX="figchain/"
export FIGCHAIN_S3_BACKUP_REGION="us-east-1"
export FIGCHAIN_BOOTSTRAP_STRATEGY="hybrid"

Configuration is loaded in this order (later sources override earlier):

  1. Configuration file (e.g., client-config.json)
  2. Environment variables
  3. Programmatic options passed to constructor/create()

All configuration options

const client = new FigChainClient({
  // Required
  environmentId: "your-environment-id",
  authPrivateKey: "hex-encoded-ed25519-private-key", // for authentication
  credentialId: "your-credential-id", // service account ID

  // Optional
  baseUrl: "https://app.figchain.io/api/",
  namespaces: ["default"], // single string, array, or Set
  pollInterval: 60, // seconds
  asOf: "2026-01-01T00:00:00Z", // point-in-time configuration
  tenantId: "default", // tenant identifier

  // Keys (optional, hex-encoded)
  encryptionPrivateKey: "hex-encoded-x25519-private-key", // for end-to-end encryption

  // S3 Backup (optional)
  s3BackupEnabled: true,
  s3BackupBucket: "my-config-bucket",
  s3BackupPrefix: "figchain/",
  s3BackupRegion: "us-east-1",
  bootstrapStrategy: "hybrid" // 'server', 'server-first', 'hybrid', 's3_backup_only'
});

API Reference

FigChainClient

constructor(options: ConfigOptions)

Creates a new FigChain client instance.

async init(): Promise<void>

Initializes the client, bootstraps configuration, and starts polling for updates.

async getFig<T>(key: string, context?: Context, namespace?: string, defaultValue?: T): Promise<T | undefined>

Retrieves a configuration value by key, evaluating rules against the provided context. Returns the default value if the fig is not found or evaluation fails.

on(key: string, callback: (value: unknown) => void): void

Registers a listener for configuration changes on a specific key.

close(): void

Stops polling and cleans up resources.

Development

  1. Setup Environment:

    npm install
  2. Build:

    npm run build
  3. Run Tests:

    npm test
  4. Clean:

    npm run clean

TypeScript Support

This library is written in TypeScript and includes type definitions. No additional @types packages are needed.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Support