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

@vncsleal/bandito

v0.1.0

Published

Server-side contextual bandit router

Readme

@vncsleal/bandito

Public SDK + types for Bandito (assign + recordOutcome).

Install

pnpm add @vncsleal/bandito

Quick Start

import { createBanditoClient } from "@vncsleal/bandito";

const bandito = createBanditoClient({
  baseUrl: "https://bandito-server.fly.dev",
  apiKey: process.env.BANDITO_API_KEY,
  timeoutMs: 2000,
});

const decision = await bandito.assign("pricing.hero", {
  context: { device: "desktop", traffic: "paid", region: "na" },
  sessionId: "session-123",
});

await bandito.recordOutcome({
  assignmentId: decision.assignmentId,
  metrics: { conversion: 1, revenue: 120 },
});

Next.js Route Example (Production)

// app/api/experiments/assign/route.ts
import { NextResponse } from "next/server";
import { createBanditoClient, isBanditoHttpError } from "@vncsleal/bandito";

const bandito = createBanditoClient({
  baseUrl: process.env.BANDITO_API_URL!,
  apiKey: process.env.BANDITO_API_KEY!,
  timeoutMs: 2000,
  retries: 1,
});

export async function POST(request: Request) {
  const body = (await request.json()) as {
    experimentId: string;
    sessionId?: string;
    projectId?: string;
    context: { device?: "desktop" | "mobile" | "unknown"; traffic?: "organic" | "paid" | "referral" | "unknown"; region?: "na" | "eu" | "apac" | "unknown" };
  };

  try {
    const decision = await bandito.assign(body.experimentId, {
      context: body.context,
      sessionId: body.sessionId,
      projectId: body.projectId,
    });
    return NextResponse.json(decision);
  } catch (error) {
    if (isBanditoHttpError(error)) {
      return NextResponse.json(
        { error: error.responseText, status: error.status },
        { status: error.status },
      );
    }
    return NextResponse.json({ error: "Unexpected error" }, { status: 500 });
  }
}

Usage

import {
  BanditoHttpError,
  createBanditoClient,
  isBanditoHttpError,
} from "@vncsleal/bandito";

const client = createBanditoClient({
  baseUrl: "https://bandito-server.fly.dev",
  apiKey: process.env.BANDITO_API_KEY,
  timeoutMs: 2000,
  retries: 1,
});

const decision = await client.assign({
  experimentId: "pricing.hero",
  projectId: "project_123",
  context: { device: "desktop", traffic: "paid", region: "na" },
  sessionId: "session-123"
});

await client.recordOutcome({
  assignmentId: decision.assignmentId,
  metrics: { conversion: 1, revenue: 120 }
});

try {
  await client.getResults({ experimentId: "pricing.hero", projectId: "project_123" });
} catch (error) {
  if (isBanditoHttpError(error)) {
    console.error(error.status, error.responseText);
  }
}

Notes:

  • decision.priorSource is "baseline" or "informed".
  • projectId is required only if you are using a master key instead of a project-scoped key.
  • Requires Node.js 18+.
  • ESM-only package ("type": "module").

Auth Modes

  • Project API key (recommended): configure API key mapped to a single project in bandito-server; projectId is optional in SDK calls.
  • Master/Admin flow: if using a broad key, pass projectId in calls so requests are scoped correctly.

API Surface

  • assign(input) or assign(experimentId, input)
  • recordOutcome(outcome)
  • getResults(input) or getResults(experimentId, projectId?)

Error Handling

  • BanditoHttpError provides:
    • status
    • responseText
    • method
    • path

Use isBanditoHttpError(error) for safe narrowing across runtimes/bundlers.