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

searchbase-sdk

v1.0.1

Published

JavaScript SDK for Searchbase API

Readme

searchbase-sdk

searchbase-sdk is a TypeScript/JavaScript SDK for interacting with the Searchbase API. It provides an easy-to-use interface for performing searches and retrieving results from your Searchbase indexes.

Table of Contents

Installation

You can install searchbase-sdk using npm:


npm install searchbase-sdk

Or using yarn:


yarn add searchbase-sdk

Usage

Here's a basic example of how to use the searchbase-sdk SDK:


import SearchbaseSDK from 'searchbase-sdk';

const sdk = new SearchbaseSDK('your-api-token');

async function performSearch() {

  try {

    const response = await sdk.search({

      index: 'your-index',

      filters: [{ field: 'category', op: '==', value: 'electronics' }],

      limit: 10

    });

    console.log(response);

  } catch (error) {

    console.error(error);

  }

}

performSearch();

API Reference

SearchbaseSDK

The main class for interacting with the Searchbase API.

Constructor


constructor(apiToken: string)

Creates a new instance of the SearchbaseSDK.

  • apiToken: Your Searchbase API token.

Methods

search

async search(options: SearchOptions): Promise<SearchResponse>

Performs a search operation.

  • options: An object containing search parameters. See SearchOptions for details.

Returns a Promise that resolves to a SearchResponse object.

searchAll

async *searchAll(options: Omit<SearchOptions, "limit" | "offset">): AsyncGenerator<SearchResult[], void, unknown>

Performs a search operation and retrieves all results, paginating automatically.

  • options: An object containing search parameters, excluding limit and offset.

Returns an AsyncGenerator that yields arrays of SearchResult objects.

Filter

An interface representing a search filter.


interface Filter {

  field: string;

  op: string;

  value: any;

}
  • field: The field to filter on.

  • op: The operation to perform (e.g., '==', '>', '<', etc.).

  • value: The value to filter by.

Sort

An interface representing a sort option.


interface Sort {

  field: string;

  direction: SortDirection;

}

enum SortDirection {

  ASC = "ASC",

  DESC = "DESC",

}
  • field: The field to sort by.

  • direction: The sort direction (ascending or descending).

SearchOptions

An interface representing the options for a search operation.


interface SearchOptions {

  index: string;

  filters?: Filter[];

  sort?: Sort[];

  select?: string[];

  limit?: number;

  offset?: number;

}
  • index: The name of the index to search.

  • filters: An optional array of Filter objects.

  • sort: An optional array of Sort objects.

  • select: An optional array of field names to include in the results.

  • limit: An optional limit on the number of results to return.

  • offset: An optional offset for pagination.

SearchResponse

An interface representing the response from a search operation.


interface SearchResponse {

  total: number;

  range: Range;

  records: SearchResult[];

}

interface Range {

  start: number;

  end: number;

}

interface SearchResult {

  id: string;

  title: string;

  url: string;

  rent: number;

  bedrooms: number;

  bathrooms: number;

  source: string;

  neighborhood: number;

  originalNeighborhood: string;

  thumbnailURLs: string[];

  createdAt: Timestamp;

}

interface Timestamp {

  _seconds: number;

  _nanoseconds: number;

}
  • total: The total number of results for the search query.

  • range: An object containing the start and end indices of the returned results.

  • records: An array of SearchResult objects.

Error Handling

The SDK uses a custom SearchError class for error handling. All errors thrown by the SDK will be instances of this class. You can catch these errors and handle them appropriately in your application.


try {

  const response = await sdk.search(/* ... */);

  // Handle successful response

} catch (error) {

  if (error instanceof SearchError) {

    console.error('Search error:', error.message);

  } else {

    console.error('Unexpected error:', error);

  }

}

Examples

Basic Search


const response = await sdk.search({

  index: 'products',

  filters: [

    { field: 'category', op: '==', value: 'electronics' },

    { field: 'price', op: '<', value: 1000 }

  ],

  sort: [{ field: 'price', direction: SortDirection.ASC }],

  limit: 20

});

console.log(`Found ${response.total} results`);

response.records.forEach(record => {

  console.log(`${record.title} - $${record.price}`);

});

Retrieving All Results


const allResults = sdk.searchAll({

  index: 'products',

  filters: [{ field: 'inStock', op: '==', value: true }]

});

for await (const batch of allResults) {

  batch.forEach(record => {

    console.log(`Processing: ${record.id}`);

    // Process each record

  });

}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.