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

@klarefi/node

v0.2.0

Published

TypeScript SDK for the Klarefi API: hosted intake sessions, case files, and signed webhooks.

Readme

@klarefi/node

TypeScript SDK for the Klarefi API. Create hosted intake sessions, read case files, and verify signed webhooks. Zero runtime dependencies; Node 18+.

The API surface is documented at klarefi.com/docs/api.

Install

npm install @klarefi/node

Usage

import { Klarefi } from "@klarefi/node";

const klarefi = new Klarefi({
  apiKey: process.env.KLAREFI_API_KEY!, // sk_live_... or sk_test_...
  baseUrl: process.env.KLAREFI_API_BASE_URL, // Optional; defaults to https://api.klarefi.com
  maxRetries: 2, // Optional; retries only safe requests
});

// Hosted intake session (Stripe Checkout pattern): create, then redirect.
const session = await klarefi.sessions.create({
  case_type_id: "pilot_intake",
  external_case_id: "crm-12345",
  prefill: {
    field_values: {
      applicant_name: "Ada Lovelace",
      prior_reference: null,
    },
  },
});
// -> session.signed_url

// Mark your customer-side handoff complete and issue a fresh applicant token.
const handoff = await klarefi.sessions.handoff(session.session_id);
// -> handoff.signed_url, handoff.access_token

// Case status and resolved facts.
const caseFile = await klarefi.cases.retrieve(session.session_id);

// Decision-ready handoff package once the case completes.
const pkg = await klarefi.cases.getPackage(session.session_id);

Connectors

Configure the HTTP APIs the runtime calls to verify facts. Connectors are active as soon as you create or import them. There is no draft/review step, so review the functions before routing live traffic. OpenAPI import is JSON only; convert YAML specs to JSON first.

// Import from a public OpenAPI JSON URL.
await klarefi.connectors.importOpenApi({
  connector_key: "claims_api",
  openapi_url: "https://example.com/openapi.json",
});

// List, inspect, and delete.
const { connectors } = await klarefi.connectors.list();
const one = await klarefi.connectors.get("claims_api");
await klarefi.connectors.delete("claims_api");

Requires an API key with connectors:write scope (connectors:read covers the list and get calls).

Applicant agents

Applicant-plane drivers use either the signed hosted-intake URL or a per-session bearer token returned by sessions.create() or sessions.handoff(). This plane does not use a sk_live_... or sk_test_... API key.

import { IntakeSession } from "@klarefi/node/intake";

const intake = klarefi.sessions.driver({
  sessionId: handoff.session_id,
  accessToken: handoff.access_token,
});

const intakeFromSignedUrl = IntakeSession.fromSignedUrl(
  "https://app.klarefi.com/s/sess_123?token=1700000000.abcdef",
);

let state = await intake.getState();

while (state.next_action.type !== "none") {
  if (state.next_action.type === "fill_form") {
    state = await intake.saveDraft({
      claimant_name: "Ada Lovelace",
    });
  } else if (state.next_action.type === "answer") {
    state = await intake.answer("The claim number is CLM-123.");
  } else if (state.next_action.type === "upload") {
    state = await intake.uploadDocument({
      file: "./policy-card.pdf",
      mimeType: "application/pdf",
    });
  } else {
    const result = await intake.nextAction();
    state = result.state;
  }
}

getView() returns the raw hosted view context when an agent needs the full escape hatch. getState() distills that view into the current phase, next action, open tasks, progress, submit readiness, and uploaded documents.

Webhooks

Register an endpoint in the dashboard (Developer tab), store the signing secret, then verify deliveries with constructEvent, the same pattern as Stripe:

import { constructEvent, KlarefiWebhookSignatureError } from "@klarefi/node";

export async function POST(request: Request) {
  const rawBody = await request.text();

  let event;
  try {
    event = constructEvent(
      rawBody,
      request.headers.get("X-Klarefi-Signature"),
      process.env.KLAREFI_WEBHOOK_SECRET!,
    );
  } catch (error) {
    if (error instanceof KlarefiWebhookSignatureError) {
      return new Response("Invalid signature", { status: 401 });
    }
    throw error;
  }

  if (event.event_type === "v1.case.completed") {
    // Fetch the package, then acknowledge the delivery.
  }

  return Response.json({ received: true });
}

The same helpers are available on a client instance as klarefi.webhooks.constructEvent and klarefi.webhooks.verifySignature.

Errors

Every non-2xx response throws KlarefiApiError with status, code, type, and requestId. Network failures throw KlarefiConnectionError. Both extend KlarefiError.

Retries

The client automatically retries 429, 5xx, and network failures for GET requests and requests carrying an idempotency_key. It uses exponential backoff with jitter and respects Retry-After when the API sends it.

maxRetries defaults to 2, which means up to 3 total attempts. Set maxRetries: 0 to disable automatic retries.

Idempotency

sessions.create and cases.submitDocument generate an idempotency_key automatically when you do not pass one. Pass your own to make retries safe across process restarts.