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

@usebadger/sdk

v1.1.0

Published

Official SDK for UseBadger - Gamify your app with badges and rewards

Readme

@usebadger/sdk

Official SDK for UseBadger - Gamify your app with badges and rewards.

Installation

npm install @usebadger/sdk
# or
yarn add @usebadger/sdk

Quick Start

import { BadgerClient } from "@usebadger/sdk";

const client = new BadgerClient({
  appId: "your-app-id",
  appSecret: "your-app-secret",
});

// Track an event
await client.events.sendEvent({
  userId: "user123",
  event: "purchase_completed",
  metadata: { amount: "99.99", product: "premium_plan" },
});

// Manually award a badge to a user
await client.badges.awardBadge("user123", "badge-id");

// Get user information
const user = await client.users.getUser("user123");
const badges = await user.getBadges();

API Reference

Configuration

interface SDKConfig {
  appId: string; // Your UseBadger app ID (required)
  appSecret?: string; // Your app secret for authenticated operations (optional)
}

Authentication

  • appId: Your unique app identifier. Found in your app settings dashboard. This is public and safe to expose in client-side code.
  • appSecret: Your app's secret key for authenticated operations like sending events and awarding badges. Generate this in your app settings dashboard. Keep this secret - never expose it in client-side code, public repositories, or browser environments.

Badges

// Get all badges with optional filtering
const { cursor, badges } = await client.badges.getBadges({
  cursor: "next-page-token",
  category: "onboarding",
  parentBadgeId: "parent-badge-id",
  userId: "user123",
});

// Get a specific badge
const badge = await client.badges.getBadge("badge-id");

// Award a badge to a user
const awardedBadge = await client.badges.awardBadge("user123", "badge-id");

// Get badge conditions
const conditions = await client.badges.getConditions("badge-id");

// Get badge rewards
const rewards = await client.badges.getRewards("badge-id");

// Badge object with convenience methods
const badge = await client.badges.getBadge("badge-id");
const conditions = await badge.getConditions();
const rewards = await badge.getRewards();
const users = await badge.getUsers();
const children = await badge.getChildren();
await badge.award("user123");

Events

// Send an event
const event = await client.events.sendEvent({
  userId: "user123",
  event: "page_view",
  metadata: { page: "/dashboard", referrer: "google.com" },
});

Users

// Get users with optional filtering
const { cursor, users } = await client.users.getUsers({
  cursor: "next-page-token",
  badgeId: "badge-id",
  badgeIds: ["badge1", "badge2"],
});

// Get a specific user
const user = await client.users.getUser("user123");

// Get user badges with filtering
const badges = await client.users.getUserBadges("user123", {
  cursor: "next-page-token",
  status: "all",
  statuses: [
    BadgeStatus.COMPLETE,
    BadgeStatus.INCOMPLETE,
    BadgeStatus.NOT_STARTED,
  ],
  category: "onboarding",
});

// Get a specific user badge
const userBadge = await client.users.getUserBadge("user123", "badge-id");

// Award a badge to a user
const awardedBadge = await client.users.awardUserBadge("user123", "badge-id");

// Get user rewards
const rewards = await client.users.getUserRewards("user123");

// User object with convenience methods
const user = await client.users.getUser("user123");
const userBadges = await user.getBadges({ status: "COMPLETE" });
const rewards = await user.getRewards();

Badge Relationships

// Get all children of a parent badge
const parentBadge = await client.badges.getBadge("sequence-start");
const children = await parentBadge.getChildren();
// You can also recursively get all descendants of a badge
const allChildren = await parentBadge.getChildren({ depth: Infinity });
// You can also get the parent of any badge in a sequence
const parent = await children[0].getParent();

// Track user progress through a badge sequence
const userBadge = await client.users.getUserBadge("user123", "sequence-start");
if (userBadge.current) {
  console.log(`User is at: ${userBadge.current.badgeId}`);
  if (userBadge.next) {
    console.log(`Next target: ${userBadge.next.badgeId} - ${userBadge.next.progress}%`);
  } else {
    console.log("User has completed the entire sequence!");
  }
}

### Webhook Verification

```typescript
app.post("/webhooks", (req, res) => {
  // Verify webhook signature
  const isValid = await client.verifySignature(
    req.body,
    webhookSecret,
    req.headers
  );
});

Types

The SDK provides comprehensive TypeScript types:

import type {
  Badge,
  BadgeCondition,
  BadgeReward,
  Event,
  User,
  UserBadge,
  UserBadgeCondition,
  BadgeVisibility,
  BadgeStatus,
  BadgeConditionType,
  StreakInterval,
} from "@usebadger/sdk";