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

@spoar/client

v2.0.0-next.1

Published

Typed read and admin client for the v2 analytics API: one chainable scope, one method per route.

Downloads

212

Readme

@spoar/client

The typed client for the v2 analytics API. One chainable scope per project, one method per read route, and the admin routes under their own namespaces. Every call resolves to a Result and never throws.

Install

bun add @spoar/client@next

Quick start

import { createClient } from "@spoar/client";

const api = createClient({
  endpoint: "https://api.analytics.remcostoeten.nl",
  token: process.env.RA_READ_TOKEN,
  projects: ["skriuw", "dora"],
});

const nl = api.skriuw.period("7d").human().where({ country: "NL" });

const [stats, pages, series] = await Promise.all([
  nl.stats(),
  nl.breakdown("page", { metrics: ["visitors", "bounce_rate"], limit: 50 }),
  nl.timeseries("visitors", { compare: "previous" }),
]);

if (!pages.ok) console.error(pages.error.code, pages.error.message);
else console.table(pages.value.data);

Scopes

The client itself is the combined scope over every project the caller may read, on the routes under /v2. api.project("skriuw"), or api.skriuw for a name passed in projects, is the scope over one project under /v2/projects/skriuw. A project named like a client method is still reachable through project().

Links return a new scope and leave the old one untouched, so one scope can feed many reads.

| Link | Sets | | --- | --- | | period("24h" \| "7d" \| "30d" \| "90d" \| "12mo" \| "all") | period, clearing an explicit range | | between(from, to) | from and to, as Date or ISO 8601 strings, clearing period | | traffic("human" \| "bots" \| "internal" \| "all"), human() | traffic | | environment("production" \| "preview" \| "all") | environment | | where({ country: "NL", page: "!/admin" }) | one filter[<dimension>] per key; a leading ! excludes | | exclude({ page: "/admin" }) | the same filters, negated | | apply(options) | a plain options object, for URL state | | toQuery() | the exact query string the API receives |

Dimensions are the registry names (page, route, referrer_domain, country, browser, device, utm_source, event, release, ...) plus prop:<key>, trait:<key> and group:<type>. On the combined scope project is a dimension too. Metrics are visitors, sessions, pageviews, events, bounce_rate, session_duration, pages_per_session, time_on_page, scroll_depth, conversion_rate, and sum:prop.<key> or avg:prop.<key> over a numeric prop. All of them are literal types, so a typo fails the typecheck.

Reads

Every terminal is named after its route and takes only that route's own options; the scope supplies the rest.

| Method | Route | | --- | --- | | stats() | stats | | timeseries(metric, { interval, compare }) | timeseries | | breakdown(dimension, { metrics, limit, cursor }) | breakdown/:dimension | | realtime({ include, limit }), realtimeEvents({ limit, after }) | realtime, realtime/events | | liveEvents({ signal }) | an async iterable over realtime/events, following the cursor | | paths(page, { direction, limit, cursor }) | paths | | retention({ interval }), lifecycle({ interval }), stickiness() | retention, lifecycle, stickiness | | heatmap({ metric, timezone }), map({ level, limit, cursor }) | heatmap, map | | speed(...), speedTimeseries(...), speedRoutes(...), speedElements(...) | speed/* | | issues({ status, limit, cursor }) | issues | | events({ name, limit, cursor }), visitors(...), sessions(...) | events, visitors, sessions | | query(sql, params) | query |

A project scope adds realtimeVisitors, realtimeSessions, overview, annotations, issue, issueEvents, updateIssue, errorRules, createErrorRule, removeErrorRule, visitor, visitorVisits, updateVisitor and sessionEvents. The combined scope adds projectBreakdown, people and person.

scope.download has the list routes as files: breakdown, paths, map, events, visitors, sessions, and on a project visitorVisits and sessionEvents. Each takes { format: "csv" | "sql", limit } and answers the file's text.

Admin

api.projects, api.tokens, api.alerts, api.annotations, api.sql and api.system hold the routes that are not reads: project settings and keys, API tokens, alert targets and deliveries, annotations, saved queries with explain, schema and history, and health, session, metrics and runJob. mail, webhook and discord build alert targets.

Auth and errors

Pass token for an at_ API token, or credentials: "include" from a browser signed in to the dashboard. A public project needs neither. A token that is the empty string answers NO_TOKEN without a request, which is what an unset environment variable looks like.

Every method resolves to { ok: true, value } or { ok: false, error }. error.code is a code from the API's error catalog, or NO_TOKEN, NETWORK, TIMEOUT, ABORTED, BAD_URL or BAD_RESPONSE when no answer came back. error.status, error.details and error.requestId carry what the API sent.

Example

examples/dashboard is a small React app on this client: stats, a timeseries chart, breakdowns, a country table and a live event stream for one project, each view from one scope method. bun run --cwd examples/dashboard dev serves it on port 3301.

Development

bun run --cwd packages/client typecheck
bun run --cwd packages/client test
bun run --cwd packages/client build

Tests run against a fake fetch and assert the exact path and query of every method.


xxx, Remco Stoeten MIT