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

@cherry_ai/api

v0.2.0

Published

Cherry JS SDK for context collection and ad fetching

Readme

@cherry_ai/api

Publisher SDK for Cherry ads.

CherryContext.collect() gathers device signals. Cherry.getAds() reads cherryContext from your server request and POSTs to Cherry.

Install

pnpm add @cherry_ai/api
npm install @cherry_ai/api

Client — chat UI

import { CherryContext } from "@cherry_ai/api";

const cherryContext = new CherryContext().collect({
  sessionId: chatSession.id,
  user: { userId: currentUser.id },
});

fetch("/api/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ messages, cherryContext }),
});

sessionId (UUID) and user.userId are required. Device fields (ua, timezone, locale) are collected automatically in the browser. You can pass them explicitly to override.

Server — fetch ads

import { Cherry, CherryError } from "@cherry_ai/api";

const cherry = new Cherry({ apiKey: process.env.CHERRY_API_KEY! });

app.post("/api/chat", async (req, res) => {
  const { messages } = req.body;

  const adPromise = cherry
    .getAds(req, messages, [
      { placement: "below_response", placementId: "main" },
    ])
    .catch((error) => {
      if (error instanceof CherryError) {
        return { ads: [] };
      }
      throw error;
    });

  // stream your LLM response...

  const { ads } = await adPromise;
  res.write(`data: ${JSON.stringify({ type: "done", ads })}\n\n`);
  res.end();
});

getAds throws CherryError with statusCode. Wrap with try/catch or Promise.allSettled so chat is not blocked.

| Case | statusCode | |------|--------------| | Missing apiKey | 401 | | Missing cherryContext | 400 | | Cherry API 400 / 401 / 5xx | body statusCode or HTTP status | | Timeout | 408 | | Network | 503 |

Next.js route handler

import { Cherry } from "@cherry_ai/api";

const cherry = new Cherry({ apiKey: process.env.CHERRY_API_KEY! });

export async function POST(request: Request) {
  const body = await request.json();
  try {
    const { ads } = await cherry.getAds(
      { body, headers: Object.fromEntries(request.headers) },
      body.messages,
      [{ placement: "below_response", placementId: "main" }],
    );
    return Response.json({ ads });
  } catch {
    return Response.json({ ads: [] });
  }
}

new Cherry(opts)

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiKey | string | required for getAds | Cherry API key (chk_...) | | baseUrl | string | http://api-dev.cherry.scribbledao.com | Cherry API origin | | timeoutMs | number | 3000 | Request timeout | | relevancy | number | 0.5 | Min relevancy (0–1) | | excludedTopics | string[] | [] | Topics to skip |

Point baseUrl at a local api.cherry with { baseUrl: "http://localhost:3010" }.

cherry.getAds(req, messages, placements, overrides?)

Reads cherryContext from req.body, forwards the end-user IP as x-forwarded-for (x-forwarded-forx-real-ip → socket), and POSTs camelCase JSON to {baseUrl}/ads with x-cherry-api-key.

overrides is a partial TCherryOptions (apiKey, baseUrl, timeoutMs, relevancy, excludedTopics) applied for that call only.

Placements: above_response | below_response | loader_text | loader_div | left_response | right_response.

Empty fill is { ads: [] } (HTTP 200). That is success, not an error.

Data flow

┌──────────────────┐   cherryContext in body    ┌──────────────────┐   POST /ads   ┌────────────┐
│   Client code    │ ─────────────────────────▶ │  Your server     │ ───────────▶  │ Cherry API │
│ CherryContext    │                            │ cherry.getAds()  │               │            │
└──────────────────┘                            └──────────────────┘               └────────────┘

Development

Run from this repo (pkg.cherry):

pnpm install
pnpm check
pnpm test
pnpm build

Releasing

Changesets live in this repo only. Until 1.0.0: patch = fix, minor = feature or breaking, major = 1.0.0.

pnpm changeset              # add a changeset on a feature branch
pnpm changeset:status       # preview the bump

On merge to main, CI opens a chore: update version PR (pnpm changeset:version). Merging that PR publishes to npm (pnpm changeset:publish), tags vX.Y.Z, and creates a GitHub Release. Set the GitHub Actions secret NPM_TOKEN.