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

@liechtenecker_development/clarity-api-client

v0.6.0

Published

Type-safe HTTP + WebSocket client for the Clarity Web Analyser API. Covers runs, templates, plugins, snapshots, AI sessions, costs, and WebSocket-driven live updates.

Readme

@clarity/api-client

Type-safe HTTP + WebSocket client for the Clarity Web Analyser API. Covers runs, templates, plugins, snapshots, AI sessions, costs, and WebSocket-driven live updates.

Published on npm as @liechtenecker_development/clarity-api-client.

Install

npm install @liechtenecker_development/clarity-api-client

Quick start

import { ClarityClient } from "@liechtenecker_development/clarity-api-client";

const client = new ClarityClient({
  baseUrl: "https://your-clarity-host",
  auth: { type: "credential", credential: process.env.CLARITY_API_KEY! },
});

// Trigger a run
const { run } = await client.triggerRun("your-template-slug", {
  inputs: { url: "https://example.com" },
});

// Wait for completion
const { run: finalRun } = await client.waitForRun(run.id, {
  onProgress: (r) => console.log(`status: ${r.status}`),
});

console.log(`score: ${finalRun.overallScore}`);

Authentication

Pass one of these as auth in the constructor:

| Type | Use case | |---|---| | { type: "credential", credential: "clr_..." | "cla_..." } | Personal token or app token — auto-exchanges for a JWT and refreshes before expiry | | { type: "apiKey", apiKey: "..." } | Static Authorization: Bearer … header | | { type: "cookie" } | Browser flows that already have a session cookie | | { type: "custom", getToken: () => Promise<string> } | Provide your own token logic |

Watching runs in real time

waitForRun(id, options) connects via WebSocket when available and falls back to polling when not. The options let you observe both transports:

import type { WsEvent } from "@liechtenecker_development/clarity-api-client";

const ac = new AbortController();

await client.waitForRun(run.id, {
  // Coarse-grained — fires under both WS and polling
  onProgress: (run) => updateRunSummary(run),

  // Fine-grained — only fires while WS is connected
  onEvent: (event: WsEvent) => dispatch(event),

  // Transport visibility — fires on WS connect and on fallback to polling
  onTransportChange: (t) => {
    if (t === "polling") showBanner("Reconnecting…");
    else hideBanner();
  },

  // Cancel cleanly (e.g. on component unmount)
  signal: ac.signal,
});

Retry on WS loss

Combine signal with onTransportChange to abort + restart on WS drop instead of silently degrading to polling:

async function waitWithWsRetry(id: string, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    const ac = new AbortController();
    try {
      return await client.waitForRun(id, {
        signal: ac.signal,
        onTransportChange: (t) => {
          if (t === "polling") ac.abort("ws-lost");
        },
        onEvent: dispatch,
      });
    } catch (err) {
      if (
        err instanceof Error &&
        err.name === "AbortError" &&
        (err as { cause?: unknown }).cause === "ws-lost"
      ) {
        await new Promise((r) => setTimeout(r, 1_000 * (i + 1)));
        continue;
      }
      throw err;
    }
  }
  throw new Error("WS retries exhausted");
}

What's in the API

  • getRuns / getRun / triggerRun / cancelRun / rerunFromAlias / getRunsTree
  • getTemplates / getTemplate / createTemplate / updateTemplate / publishTemplate / unpublishTemplate / deleteTemplate
  • getTemplateSnapshots / createTemplateSnapshot / restoreTemplateSnapshot
  • getPlugins / getPlugin / validatePluginSettings / debugPlugin
  • watchRun (raw WS handle) and waitForRun (promise wrapper, used above)
  • AI session helpers (getAiSessions, createAiSession, updateAiSession, …)
  • Cost reports, app-token management, run-input schema validation, and more

All response shapes are exported as named types — see types.ts in the published bundle for the full surface.

Versioning

Semver. Breaking changes bump the major (or minor while still pre-1.0). See CHANGELOG.md for what shipped in each release.

Code generation

The package ships a small CLI (clarity-codegen) that regenerates per-plugin output types from a running API instance. Configure your plugins with Zod output schemas and run:

npx clarity-codegen --base-url https://your-clarity-host --out src/generated/plugins.ts

License

Private package — internal use only.