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

documents-client

v1.0.0

Published

Zero-dependency REST client for documents API (adapter-express compatible)

Readme

documents-client

Zero-dependency REST client for the documents API (compatible with @documents/adapter-express).

Installation

npm install documents-client

Configuration

import { DocumentsClient } from 'documents-client';

const client = new DocumentsClient({
  baseUrl: 'https://api.example.com',
  rootPath: '/documents', // default
  getAuthToken: async () => localStorage.getItem('token'),
  timeout: 30000, // default
  headers: { 'X-Custom': 'value' },
});

| Option | Description | | -------------- | --------------------------------------------------------- | | baseUrl | API base URL (required) | | rootPath | Document API prefix (default /documents) | | getAuthToken | Async callback returning Bearer token (required for auth) | | timeout | Request timeout in ms (default 30000) | | headers | Extra headers for all requests |

API Reference

Health

const health = await client.health();
// { status: string, details?: Record<string, unknown> }

List Folder

const result = await client.listFolder('/finance/2024/', {
  recursive: true,
  page: 1,
  size: 50,
  query: 'budget',
  includeContent: false,
  metadata: { semanticType: 'document', tags: ['urgent', '-draft'] }, // - prefix = exclude
});
// PaginatedResult<DocumentDraft | DocumentVersion>

Read Document

const doc = await client.readDocument('/finance/2024/budget', {
  branch: 'main',
  version: 'abc123', // or branch for draft
  accept: 'application/vnd.metadata-and-content+json',
});
// DocumentDraft | DocumentVersion

Version History

const history = await client.readVersionHistory('/finance/2024/budget', 'main');
// DocumentVersion[]

List Branches

const branches = await client.listBranches('/finance/2024/budget');
// BranchSummary[]

Put Document

const draft = await client.writeDocument(
  '/finance/2024/new-doc',
  { content: { blocks: [] }, metadata: { mimeType: 'application/json' } },
  {
    branch: 'main',
    ifMatch: 'previous-hash',
    accept: 'application/vnd.metadata-and-content+json',
  }
);
// DocumentDraft | void

Delete Document / Branch

await client.deleteDocument('/finance/2024/old-doc'); // Delete document and all branches
await client.deleteBranch('/finance/2024/old-doc', 'feature-x'); // Delete branch only

Document Actions

// Commit draft to version
const version = await client.commit('/doc', {
  branch: 'main',
  commitMessage: 'Initial',
});

// Stash branch
const { stashedBranch, draft } = await client.stash('/doc', 'main');

// Revert to head
const draft = await client.revert('/doc', 'main');

// Create branch from branch or version (options.branch = source branch, options.version = source version)
const draft = await client.branch('/doc', 'feature', { branch: 'main' });
const draft2 = await client.branch('/doc', 'snapshot', {
  version: 'abc123',
});

// Generate from template (options match other methods)
await client.generateFromTemplate(
  '/templates/tenant',
  { tenantId: 't1', userId: 'u1' },
  { branch: 'main' }
);

Content Negotiation

  • Accept (read): application/vnd.metadata-and-content+json (default), application/vnd.metadata-only+json
  • Content-Type (put): application/vnd.metadata-and-content+json, application/vnd.metadata-only+json, text/markdown
  • Version history: Accept: application/vnd.document-versions+json
  • Branches: Accept: application/vnd.document-branches+json

Error Handling

import {
  DocumentsClientError,
  PreconditionFailedError,
  PreconditionRequiredError,
  AuthenticationRequiredError,
} from 'documents-client';

try {
  await client.writeDocument('/doc', body, { ifMatch: oldHash });
} catch (err) {
  if (err instanceof PreconditionFailedError) {
    // 412 - optimistic lock conflict
  }
  if (err instanceof PreconditionRequiredError) {
    // 428 - If-Match required
  }
  if (err instanceof DocumentsClientError) {
    console.log(err.status, err.code, err.isNotFound);
  }
}

Example

import { DocumentsClient } from 'documents-client';

const client = new DocumentsClient({
  baseUrl: 'https://api.example.com',
  getAuthToken: () => sessionStorage.getItem('token'),
});

// List root folder
const { items } = await client.listFolder('/');

// Read a document
const doc = await client.readDocument('/projects/readme');
console.log(doc.metadata, doc.content);

// Update and commit
await client.writeDocument(
  '/projects/readme',
  {
    content: doc.content,
    metadata: doc.metadata,
  },
  { ifMatch: doc.hash }
);
await client.commit('/projects/readme', { commitMessage: 'Updated' });

TypeScript

All types are exported from the main package:

import type {
  DocumentDraft,
  DocumentVersion,
  DocumentMetadata,
  PaginatedResult,
  BranchSummary,
} from 'documents-client';

Or import only types:

import type { DocumentDraft } from 'documents-client/types';