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

@zensearch/docs-sdk

v0.1.8

Published

JavaScript/TypeScript SDK for ZenSearch Documentation Search

Downloads

79

Readme

@zensearch/docs-sdk

Official JavaScript/TypeScript SDK for ZenSearch Documentation Search.

Installation

npm install @zensearch/docs-sdk
# or
yarn add @zensearch/docs-sdk
# or
pnpm add @zensearch/docs-sdk

Quick Start

import { ZenSearchDocs } from '@zensearch/docs-sdk';

// Initialize with your API key
const client = new ZenSearchDocs({
  apiKey: 'zsk_pk_xxx...', // Publishable key for client-side
  defaultCollection: 'your-collection-id', // Optional
});

// Search documentation
const results = await client.search('how to install');
console.log(results.results);

// Get autocomplete suggestions
const suggestions = await client.autocomplete('auth');
console.log(suggestions.suggestions);

Configuration

const client = new ZenSearchDocs({
  // Required: Your API key (publishable for client-side, secret for server-side)
  apiKey: 'zsk_pk_xxx...',

  // Optional: Custom API base URL
  baseUrl: 'https://api.zensearch.dev',

  // Optional: Default collection to search
  defaultCollection: 'collection-uuid',

  // Optional: Request timeout in milliseconds (default: 30000)
  timeout: 30000,

  // Optional: Custom fetch implementation (for Node.js)
  fetch: customFetch,
});

API Reference

search(query, options?)

Search documentation with various filtering options.

const results = await client.search('authentication', {
  limit: 10,           // Max results (default: 10, max: 100)
  offset: 0,           // Pagination offset
  minScore: 0.5,       // Min relevance score (0-1, default: 0.5)
  highlight: true,     // Enable term highlighting
  section: 'guides',   // Filter by section
  version: '2.0',      // Filter by version
  tags: ['security'],  // Filter by tags
});

Response

{
  results: [
    {
      url: 'https://docs.example.com/auth',
      title: 'Authentication Guide',
      snippet: 'Learn how to implement <mark>authentication</mark>...',
      hierarchy: ['Guides', 'Security', 'Authentication'],
      level: 2,
      score: 0.95,
      suType: 'section',
      highlights: {
        title: '<mark>Authentication</mark> Guide',
        content: 'Learn how to implement <mark>authentication</mark>...',
      },
    },
  ],
  queryId: 'query-uuid',
  tookMs: 42,
  totalHits: 15,
  hasMore: true,
}

autocomplete(query, options?)

Get search suggestions as the user types.

const suggestions = await client.autocomplete('auth', {
  limit: 5,  // Max suggestions (default: 5, max: 20)
});

Response

{
  query: 'auth',
  suggestions: [
    {
      text: 'Authentication',
      type: 'title',
      score: 0.9,
      hierarchy: 'Guides > Security',
      url: 'https://docs.example.com/auth',
    },
    {
      text: 'Authorization',
      type: 'heading',
      score: 0.85,
    },
  ],
}

getDocument(documentId)

Retrieve a specific document by ID.

const doc = await client.getDocument('document-uuid');

trackEvent(event)

Track analytics events for search improvements.

// Track a click on a search result
await client.trackEvent({
  type: 'click',
  queryId: results.queryId,
  url: results.results[0].url,
  position: 1,
});

// Track user feedback
await client.trackEvent({
  type: 'feedback',
  queryId: results.queryId,
  rating: 5,
});

Error Handling

import { ZenSearchDocs, ZenSearchError } from '@zensearch/docs-sdk';

try {
  const results = await client.search('query');
} catch (error) {
  if (error instanceof ZenSearchError) {
    if (error.isAuthError()) {
      console.error('Authentication failed');
    } else if (error.isRateLimitError()) {
      console.error('Rate limit exceeded');
    } else {
      console.error(`Error: ${error.message} (${error.status})`);
    }
  }
}

Request Cancellation

const controller = new AbortController();

// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);

try {
  const results = await client.search('query', {
    signal: controller.signal,
  });
} catch (error) {
  if (error instanceof ZenSearchError && error.status === 408) {
    console.log('Request was cancelled');
  }
}

TypeScript Support

Full TypeScript support with exported types:

import type {
  SearchOptions,
  SearchResponse,
  SearchResult,
  AutocompleteOptions,
  AutocompleteResponse,
  Document,
} from '@zensearch/docs-sdk';

Framework Integration

React

import { useState, useEffect } from 'react';
import { ZenSearchDocs } from '@zensearch/docs-sdk';

const client = new ZenSearchDocs({ apiKey: 'zsk_pk_xxx...' });

function SearchBox() {
  const [query, setQuery] = useState('');
  const [results, setResults] = useState([]);

  useEffect(() => {
    if (query.length < 2) return;

    const controller = new AbortController();

    client.search(query, { signal: controller.signal })
      .then(res => setResults(res.results))
      .catch(() => {});

    return () => controller.abort();
  }, [query]);

  return (
    <div>
      <input value={query} onChange={e => setQuery(e.target.value)} />
      <ul>
        {results.map(r => (
          <li key={r.url}>{r.title}</li>
        ))}
      </ul>
    </div>
  );
}

Node.js / Server-Side

import { ZenSearchDocs } from '@zensearch/docs-sdk';

// Use secret key for server-side
const client = new ZenSearchDocs({
  apiKey: process.env.ZENSEARCH_SECRET_KEY,
});

License

MIT