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

@sponsored-code/sdk

v3.2.1

Published

Official SDK for the Sponsored Code brand API — manage campaigns and pull impression analytics with an API key.

Downloads

1,230

Readme

npm license sponsoredcode.com

Brand SDK

The official SDK for the Sponsored Code brand API. Launch campaigns and pull their analytics from your own code — no wallet, no browser — with an API key. Fully typed, so your editor's autocomplete doubles as the reference.

npm install @sponsored-code/sdk

Get an API key

In the dashboard, open Settings → API keys and create a key. You'll see the secret (scode_live_…) once — store it safely (a secret manager, or SCODE_API_KEY in your environment). A key is scoped to one team and to read and/or write:

  • read — analytics, impressions, list campaigns
  • write — create, pause, and resume campaigns

Keys are revocable at any time from the same screen.

Quickstart

import { SponsoredCode } from "@sponsored-code/sdk";

const scode = new SponsoredCode({ apiKey: process.env.SCODE_API_KEY });

// Verify the key, and see the team + scopes it grants
const { teamId, team, scopes } = await scode.whoami();

// Pull aggregate analytics
const { totals, geo } = await scode.analytics();
console.log(`${totals.impressions} impressions · $${totals.spendUsd} spent · ${totals.clicks} clicks`);

// Launch a campaign (needs the "write" scope)
const campaign = await scode.campaigns.create({
  brand: "Example",
  tagline: "yield on idle USDC",
  url: "https://example.com",
  bidUsdCpm: 20,
  budgetUsd: 500,
  targetCountries: ["US", "DE"], // optional — omit for everywhere
});

// Pause / resume it later
await scode.campaigns.pause(campaign.id);
await scode.campaigns.resume(campaign.id);

Configuration

new SponsoredCode(options):

| Option | Default | Notes | | --------- | ------- | ----- | | apiKey | process.env.SCODE_API_KEY | Your scode_live_… key. | | baseUrl | process.env.SCODE_APIhttps://api.sponsoredcode.com | Point at another backend in dev. | | fetch | global fetch | Inject a custom transport (tests, proxy). |

Dependency-free and runs anywhere modern fetch exists — Node 18+, Deno, Bun, and edge/serverless runtimes. Your API key is a secret: use the SDK server-side, never in a public browser bundle.

Methods

| Method | Scope | Description | |---|---|---| | whoami() | read | The team and scopes the key resolves to (KeyInfo) — the cheap way to verify a key works. | | analytics() | read | Aggregate analytics for the team (Analytics): totals, a daily series, a geo breakdown, and a per-campaign roll-up. | | impressions({ limit }) | read | The team's most recent impressions, newest first (Impression[]). limit 1–100, default 20. | | campaigns.list() | read | Every campaign in the team (Campaign[]). | | campaigns.create(input) | write | Launch a campaign and return it (Campaign). See CreateCampaignInput below. | | campaigns.pause(id) / campaigns.resume(id) | write | Pause or resume a campaign (Campaign). | | campaigns.setStatus(id, status) | write | Set a campaign to "active" or "paused" directly (Campaign). |

Analytics and impressions are aggregate — counts, spend, and geography for your own campaigns. The SDK never exposes an individual developer's wallet or IP.

Types

Everything is fully typed. The shapes you'll work with:

type Scope = "read" | "write";
type CampaignStatus = "active" | "paused";

type KeyInfo = { teamId: string; team: string; scopes: Scope[] };

type Campaign = {
  id: string;
  teamId: string;
  brand: string;
  tagline: string;
  url: string;
  color: string;
  bidUsdCpm: number;
  budgetUsd: number;
  spentUsd: number;
  status: CampaignStatus;
  targetCountries: string[]; // ISO-3166 alpha-2, uppercase; empty = everywhere
  createdAt: string;
};

type CreateCampaignInput = {
  brand: string;
  tagline: string;
  url: string;
  bidUsdCpm?: number;         // max CPM in USD, default 20
  budgetUsd?: number;
  color?: string;             // hex, default "#2563eb"
  targetCountries?: string[]; // e.g. ["US", "DE"]; omit = everywhere
};

type Totals = {
  impressions: number;
  spendUsd: number;
  reach: number;
  clicks: number;
  ctr: number;
  avgCpm: number;
  activeCampaigns: number;
};

type Analytics = {
  totals: Totals;
  series: { t: string; impressions: number; spendUsd: number }[];
  geo: { country: string; countryCode: string; impressions: number; spendUsd: number }[];
  campaigns: {
    id: string; brand: string; status: CampaignStatus; color: string;
    impressions: number; spendUsd: number; clicks: number; ctr: number;
    budgetUsd: number; spentUsd: number; bidUsdCpm: number;
  }[];
  generatedAt: string;
};

type Impression = {
  id: string;
  ts: string;
  campaignId: string;
  brand: string;
  spendMicros: number;
  spendUsd: number;
};

Errors

Every failure throws a SponsoredCodeError carrying a numeric .status and a stable, machine-readable .code (unauthorized, insufficient_scope, no_campaign, no_api_key, …):

import { SponsoredCode, SponsoredCodeError } from "@sponsored-code/sdk";

try {
  await scode.campaigns.create({ brand: "Example", tagline: "…", url: "https://example.com" });
} catch (err) {
  if (err instanceof SponsoredCodeError && err.code === "insufficient_scope") {
    console.error("This key is read-only — create a read+write key.");
  }
}

License

Source-available — see LICENSE.