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

@nozle-js/node

v0.2.0

Published

Server-side Node.js SDK for usage tracking, entitlement checks, margin intelligence, and billing management.

Downloads

338

Readme

@nozle-js/node

Server-side Node.js SDK for usage tracking, entitlement checks, margin intelligence, and billing management.

Install

npm install @nozle-js/node

Works with both JavaScript and TypeScript. Requires Node.js 18+.

Quick Start

import { Nozle } from "@nozle-js/node";

const nozle = new Nozle({ apiKey: "sk_live_..." });

// Track usage event
await nozle.track("cust_123", "tokens_used", { tokens: 150, model: "gpt-4o" });

// Entitlement check
const { allowed, reason, used, limit } = await nozle.can("cust_123", "code_completion");

Configuration

const nozle = new Nozle({
  apiKey: "sk_live_...",            // Required
  baseUrl: "https://api.nozle.ai",  // Default: http://localhost:8080
  eventsUrl: "https://lago.nozle.ai", // Default: http://localhost:3000
  timeout: 15_000,                   // Default: 10000ms
});

Usage Tracking

// Basic tracking (auto-resolves subscription)
await nozle.track("cust_123", "api_call", { tokens: 100 });

// With explicit subscription
await nozle.track("cust_123", "api_call", { tokens: 100 }, {
  subscriptionId: "sub_abc",
});

// With custom transaction ID and timestamp
await nozle.track("cust_123", "api_call", { tokens: 100 }, {
  transactionId: "tx_custom_123",
  timestamp: "2025-01-15T10:30:00Z",
});

Subscription auto-resolution: if no subscriptionId is provided, the SDK looks up the customer's active subscription and caches it for subsequent calls.

Entitlement Checks

const result = await nozle.can("cust_123", "code_completion");

if (result.allowed) {
  // Feature is available
  console.log(`${result.remaining} uses remaining`);
} else {
  // Blocked: result.reason is "usage_limit_exceeded" or "below_margin_floor"
  console.log(`Blocked: ${result.reason}`);
}

Response includes cost intelligence:

result.cost_per_use_cents    // Your cost per unit
result.revenue_per_use_cents // What you charge per unit
result.margin_per_use_cents  // Revenue minus cost
result.min_margin_percent    // Configured margin floor (if set)

Margin Intelligence

Requires a secret key (sk_ prefix).

// Overall margin summary
const summary = await nozle.margin.summary();

// Breakdown by dimension
const byCustomer = await nozle.margin.byCustomer();
const byMetric = await nozle.margin.byMetric();
const byPlan = await nozle.margin.byPlan();
const byModel = await nozle.margin.byModel();

// Trend over time
const trend = await nozle.margin.trend({ granularity: "day" });
const weeklyTrend = await nozle.margin.trend({ granularity: "week" });

// With time range
const q1 = await nozle.margin.summary({
  from: "2025-01-01T00:00:00Z",
  to: "2025-03-31T23:59:59Z",
});

Plans & Checkout

// List available plans
const plans = await nozle.plans();

// Create checkout session (returns Stripe client_secret)
const { client_secret, session_id } = await nozle.checkout("cust_123", "pro");

// Create subscription after payment
const { subscription_id, status } = await nozle.subscribe("cust_123", "pro");

TypeScript

All methods and responses are fully typed. Exported types:

import type {
  NozleConfig,
  TrackOptions,
  CanResult,
  Plan,
  CheckoutResult,
  SubscribeResult,
  MarginQueryParams,
  TrendParams,
} from "@nozle-js/node";

License

Proprietary