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

@openpromo/snapchat

v0.2.0

Published

Type-safe TypeScript SDK for the Snapchat Marketing API (Ads, Media, Creatives, Stats) and OAuth

Downloads

10

Readme

@openpromo/snapchat

Type-safe TypeScript SDK for the Snapchat Marketing API — campaigns, ad squads, ads, media, creatives, audiences, targeting, and stats. Generated directly from the official Snap documentation (developers.snap.com/marketing-api), with OAuth built in.

Install

bun add @openpromo/snapchat

Quick start

import { Snapchat } from "@openpromo/snapchat";

// OAuth — tokens are short-lived (60 min); use refreshToken to renew
const oauth = Snapchat.OAuth({
  clientId: "...",
  clientSecret: "...",
  redirectUri: "https://example.com/callback",
});
const authUrl = oauth.getAuthorizationUrl({
  scopes: [Snapchat.Scopes.Marketing],
});
// → redirect user, capture ?code=, then:
const { access_token } = await oauth.exchangeCode(code);

// Client — one shared HTTP client for the whole Ads API
const snap = Snapchat.createClient({ accessToken: access_token });

// Organizations and ad accounts
const orgs = await snap.organizations.listOrganizations({ with_ad_accounts: true });

// Campaigns — async-iterable pagination via paging.next_link
for await (const campaign of snap.campaigns.listCampaigns({ adAccountId })) {
  console.log(campaign.name);
}

const created = await snap.campaigns.createCampaign({
  adAccountId,
  name: "Spring Sale",
  status: "ACTIVE",
  start_time: "2026-03-01T00:00:00Z",
  buy_model: "AUCTION",
  objective: "WEB_CONVERSION",
});

// Media + creatives + ads
const media = await snap.media.createMedia({ adAccountId, name: "Hero", type: "VIDEO" });
await snap.media.uploadMedia({ mediaId: media.id, file: videoFile });
const creative = await snap.creatives.createCreative({ adAccountId, name: "Creative", top_snap_media_id: media.id });
await snap.ads.createAd({ adSquadId, name: "Ad", creative_id: creative.id });

// Stats
const stats = await snap.measurement.getCampaignStats({ campaignId: created.id, granularity: "DAY" });

Error handling

All failures throw SnapchatApiError (extends the shared runtime ApiError):

try {
  await snap.campaigns.getCampaign({ campaignId: "missing" });
} catch (error) {
  if (error instanceof Snapchat.ApiError) {
    console.log(error.status, error.requestId); // 404, request id for support
  }
}

The client also handles retries with exponential backoff (429/5xx), optional rate limiting, and paging.next_link pagination automatically.

Generated surface

The SDK is documentation-driven codegen — all 214 endpoints across 36 resource pages are generated from the official docs:

bun run codegen         # regenerate from cached docs
bun run codegen:refresh # re-scrape developers.snap.com, then regenerate

Generated output lives in src/generated/ (types + endpoint clients + Effect artifacts + manifest).

Namespace

| Member | Description | | ------ | ----------- | | Snapchat.createClient(opts) | Full Ads API client (campaigns, adSquads, ads, media, creatives, organizations, targeting, measurement, …) | | Snapchat.OAuth(config) | Authorize URL, code exchange, refresh | | Snapchat.Scopes | Marketing, Conversions, Profile scopes | | Snapchat.ApiClient | Core HTTP client (Bearer auth, retry, rate limit, multipart uploads) | | Snapchat.ApiError | Typed error class | | Snapchat.Cursor | Async-iterable pagination cursor |