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

contentbay

v0.1.4

Published

Official JavaScript/TypeScript SDK for ContentBay Headless CMS

Readme

contentbay

Official JavaScript/TypeScript SDK for ContentBay Headless CMS

npm version License: MIT

Fetch and query content from your ContentBay workspace with a clean, type-safe API. Works in Node.js, Edge runtimes, and modern browsers.

Installation

npm install contentbay
yarn add contentbay
pnpm add contentbay

Quick Start

import { ContentBay } from 'contentbay';

const cms = new ContentBay({
  spaceId: 'your-workspace-id',
  apiToken: 'cb_live_your-api-token',
});

// Fetch all blog posts
const posts = await cms.getAll('blog-post');

posts.forEach(post => {
  console.log(post.data.title);
});

Configuration

| Option | Type | Required | Default | Description | | ---------- | -------- | -------- | ---------------------------- | ----------------------------------- | | spaceId | string | ✅ | — | Your workspace ID from the dashboard | | apiToken | string | ✅ | — | API token from your dashboard | | apiUrl | string | ❌ | https://api.contentbay.io | Custom API base URL |

const cms = new ContentBay({
  spaceId: 'your-workspace-id',
  apiToken: 'cb_live_your-api-token',
  apiUrl: 'https://your-custom-api.example.com', // optional
});

API Reference

cms.getAll(modelApiId)

Fetch all entries from a content model.

const products = await cms.getAll('product');
// products: ContentEntry[]

cms.get(modelApiId, fields?)

Fetch entries with optional field selection. When fields is provided, only those keys will appear in each entry's data object.

// All fields
const products = await cms.get('product');

// Only name and price
const products = await cms.get('product', ['name', 'price']);
// products[0].data → { name: 'Widget', price: 9.99 }

cms.getOne(modelApiId, entryId)

Fetch a single entry by its ID. Returns null if not found.

const product = await cms.getOne('product', 'clxyz123');

if (product) {
  console.log(product.data.name);
}

cms.query(modelApiId)

Create a query builder for advanced filtering, sorting, and pagination.

const results = await cms.query('product')
  .where('price', '>', 100)
  .where('category', '=', 'electronics')
  .select(['name', 'price', 'image'])
  .orderBy('price', 'desc')
  .limit(10)
  .offset(20)
  .execute();

cms.getModels()

Fetch all content models (schemas) in your workspace.

const models = await cms.getModels();

models.forEach(model => {
  console.log(`${model.name} (${model.apiId})`);
  model.fields.forEach(field => {
    console.log(`  - ${field.name}: ${field.type}`);
  });
});

Query Builder

The query builder provides a fluent API for constructing complex queries:

| Method | Description | | ----------------------------------- | -------------------------------------------- | | .where(field, operator, value) | Add a filter condition (AND logic) | | .select(fields) | Choose which fields to include in data | | .orderBy(field, direction?) | Sort results ('asc' or 'desc') | | .limit(count) | Limit the number of results | | .offset(count) | Skip results (for pagination) | | .execute() | Run the query and return results |

Supported Operators

| Operator | Description | Example | | ------------ | ------------------------ | ------------------------------------ | | = | Equal | .where('status', '=', 'active') | | != | Not equal | .where('status', '!=', 'draft') | | > | Greater than | .where('price', '>', 100) | | < | Less than | .where('price', '<', 50) | | >= | Greater than or equal | .where('stock', '>=', 1) | | <= | Less than or equal | .where('rating', '<=', 5) | | contains | String contains | .where('title', 'contains', 'new') | | startsWith | String starts with | .where('sku', 'startsWith', 'AB') | | endsWith | String ends with | .where('email', 'endsWith', '.com')|

Pagination Example

const pageSize = 10;
const page = 2;

const results = await cms.query('product')
  .limit(pageSize)
  .offset((page - 1) * pageSize)
  .execute();

Error Handling

The SDK provides typed error classes for structured error handling:

import { ContentBay, AuthError, ApiError, ContentBayError } from 'contentbay';

try {
  const posts = await cms.getAll('blog-post');
} catch (error) {
  if (error instanceof AuthError) {
    // Invalid or missing API token
    console.error('Authentication failed:', error.message);
  } else if (error instanceof ApiError) {
    // API request failed
    console.error('API error:', error.message);
  } else if (error instanceof ContentBayError) {
    // Any other SDK error
    console.error('SDK error:', error.code, error.message);
  }
}

| Error Class | Code | When | | ----------------- | ------------ | ------------------------------------- | | AuthError | AUTH_ERROR | Invalid/missing API token or spaceId | | NotFoundError | NOT_FOUND | Resource not found | | ApiError | API_ERROR | General API request failure | | ContentBayError | (varies) | Base class for all SDK errors |

TypeScript Support

This package is written in TypeScript and ships with full type definitions. All interfaces are exported for your convenience:

import type {
  ContentBayConfig,
  ContentEntry,
  ContentModel,
  ContentField,
  WhereOperator,
  OrderDirection,
} from 'contentbay';

License

MIT © ContentBay