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

@levered_dev/sdk

v0.2.0

Published

JavaScript/TypeScript SDK for Levered — automatic variant optimization with multi-armed and contextual bandits

Downloads

245

Readme

@levered_dev/sdk

TypeScript SDK for Levered — variant optimization with multi-armed and contextual bandits.

Install

npm install @levered_dev/sdk

Basic Usage

import { LeveredClient } from '@levered_dev/sdk';

const client = new LeveredClient({
  apiUrl: 'https://api.levered.dev',
  onExposure: (event) => {
    // Log to your warehouse (BigQuery, Snowflake, Postgres, etc.)
    analytics.track('variant_exposure', event);
  },
  onError: (err) => {
    console.error('Levered SDK error:', err);
  },
});

const result = await client.getVariant({
  anonymousId: 'user-abc-123',
  optimizationId: 'your-optimization-uuid',
  context: { device_type: 'mobile', source: 'email' }, // optional, for CMAB
});

if (result) {
  // Use result.variant — e.g. { headline: "Save 20%", cta_text: "Get Started" }
  renderPage(result.variant);
} else {
  // Fallback — API unavailable or model not trained yet
  renderPage({ headline: 'Welcome', cta_text: 'Sign Up' });
}

React

import { LeveredProvider, useVariant } from '@levered_dev/sdk/react';

function App() {
  return (
    <LeveredProvider
      apiUrl="https://api.levered.dev"
      anonymousId={getSessionId()}
      onExposure={(event) => analytics.track('exposure', event)}
    >
      <HeroSection />
    </LeveredProvider>
  );
}

function HeroSection() {
  const { variant, isLoading } = useVariant({
    optimizationId: 'your-optimization-uuid',
    fallback: { headline: 'Welcome', cta_text: 'Sign Up' },
    context: { device_type: 'mobile' },
  });

  return (
    <section>
      <h1>{variant.headline}</h1>
      <button>{variant.cta_text}</button>
    </section>
  );
}

Configuration

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiUrl | string | — | Base URL of the Levered API (required) | | onExposure | (event) => void | — | Called when a user is exposed to a variant | | onError | (error) => void | — | Called when a request fails after all retries | | timeoutMs | number | 2000 | Request timeout in ms | | maxRetries | number | 2 | Retry attempts with exponential backoff (200ms, 400ms) | | cacheTtlMs | number | 60000 | In-memory cache TTL in ms. Set to 0 to disable |

How It Works

  1. getVariant() calls POST /api/v2/optimizations/:id/serve with the anonymous ID and optional context.
  2. The API returns the best variant(s) ranked by expected reward from the bandit model.
  3. The SDK fires onExposure so you can log the exposure to your warehouse.
  4. Responses are cached in-memory (1 min default) to avoid redundant requests.
  5. On network failure, retries up to maxRetries times with exponential backoff, then returns null.

Exposure Logging

You are responsible for logging exposures to your data warehouse. The onExposure callback receives:

{
  anonymousId: string;       // The user/session ID you provided
  optimizationId: string;    // UUID of the optimization
  variant: Record<string, string | number | boolean>;  // The assigned variant
  context: Record<string, unknown>;  // Context sent with the request
  timestamp: string;         // ISO-8601 timestamp
}

Log this to your BigQuery/Snowflake/Postgres exposures table. Levered reads from your warehouse to train models — it does not store your behavioral data.