Skip to content

versedbcom/versedb-node

Repository files navigation

VerseDB TypeScript SDK

The official TypeScript/JavaScript SDK for the VerseDB public API — search and browse a database of 1M+ comics (series, issues, creators, characters, publishers, story arcs), look up barcodes, and manage your collection and lists.

Published on npm as @versedbcom/sdk. The code is generated from the VerseDB OpenAPI spec via Speakeasy and republished automatically whenever the API changes.

Installation

npm install @versedbcom/sdk

Quickstart

Get a personal API token at versedb.com/my/apps/custom.

import { VerseDB } from "@versedbcom/sdk";

const vdb = new VerseDB({ token: process.env.VERSEDB_TOKEN });

const { result } = await vdb.series.listSeries({ q: "batman", limit: 20 });
console.log(result.data);

That's it — no base URL, bearer headers, or JSON parsing. The client targets https://versedb.com/api/v1.

Why use the SDK instead of raw HTTP?

  • Typed models and autocomplete. Series, Issue, Creator, and the rest are generated types — mediums, publication types, and issue formats are enums, not magic strings.
  • Pagination handled. List endpoints accept page/limit and return typed meta paging info (currentPage, lastPage, total) — no untyped next_page_url strings.
  • Rate limits won't surprise you. Every response exposes the X-RateLimit-* headers as typed values, 429s surface as typed errors carrying Retry-After, and automatic backoff is one retryConfig option away (see Retries below). Limits: reads 300/hr free, 1,000/hr PRO; writes 150/hr free, 500/hr PRO.
  • Typed errors. 401, 403 (missing scope), 409, and 422 surface as catchable, typed errors instead of raw responses.
  • Auth set once on the client, not per request.
  • Stays in sync. Regenerated from the spec on every API change; v1 evolves additively, so new fields and endpoints arrive as non-breaking minor bumps.

Recipes

Runnable versions live in examples/.

Barcode lookup → collection sync

Requires the lookup:barcode and write:collection scopes.

const { result } = await vdb.barcodeLookup.lookupByUPC({ upc: "75960608936800111" });

await vdb.userCollections.addIssueToCollection({
  issueId: result.data!.id!,
  body: { condition: "NM", pricePaid: 4.99 },
});

Pre-1995 barcodes are not unique — a 409 response carries a matches array for the user to pick from.

Lists

Requires the write:list scope.

const { result } = await vdb.lists.createList({
  title: "Essential X-Men",
  entityType: "issues",
});

await vdb.lists.addItemToList({
  listId: result.data!.id!,
  body: { entityId: 5432 },
});

Token scopes

Scope Grants
read:public Catalog reads (default)
lookup:barcode UPC/ISBN lookup
write:collection Manage your collection
write:list Manage your lists

Scopes are chosen when creating a token at /my/apps/custom; a missing scope surfaces as a typed 403 error.

API reference

Showcase

ComicTagger's VerseDB talker uses the v1 API end to end — barcode lookup and catalog reads while tagging comic archives.

Contributing

The SDK source is generated — see CONTRIBUTING.md before opening a PR.

License

MIT

Summary

VerseDB API Documentation: REST API for accessing comic book data, managing collections, and building integrations with VerseDB.

Table of Contents

SDK Installation

The SDK can be installed with either npm, pnpm, bun or yarn package managers.

NPM

npm add @versedbcom/sdk

PNPM

pnpm add @versedbcom/sdk

Bun

bun add @versedbcom/sdk

Yarn

yarn add @versedbcom/sdk

Note

This package is published as an ES Module (ESM) only. For applications using CommonJS, use await import("@versedbcom/sdk") to import and use this package.

Requirements

For supported JavaScript runtimes, please consult RUNTIMES.md.

SDK Example Usage

Example

import { VerseDB } from "@versedbcom/sdk";

const verseDB = new VerseDB({
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await verseDB.activity.getActivityFeed({
    perPage: 20,
  });

  console.log(result);
}

run();

Authentication

Per-Client Security Schemes

This SDK supports the following security scheme globally:

Name Type Scheme
token http HTTP Bearer

To authenticate with the API the token parameter must be set when initializing the SDK client instance. For example:

import { VerseDB } from "@versedbcom/sdk";

const verseDB = new VerseDB({
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await verseDB.activity.getActivityFeed({
    perPage: 20,
  });

  console.log(result);
}

run();

Available Resources and Operations

Available methods

Standalone functions

All the methods listed above are available as standalone functions. These functions are ideal for use in applications running in the browser, serverless runtimes or other environments where application bundle size is a primary concern. When using a bundler to build your application, all unused functionality will be either excluded from the final bundle or tree-shaken away.

To read more about standalone functions, check FUNCTIONS.md.

Available standalone functions

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:

import { VerseDB } from "@versedbcom/sdk";

const verseDB = new VerseDB({
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await verseDB.activity.getActivityFeed({
    perPage: 20,
  }, {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  });

  console.log(result);
}

run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:

import { VerseDB } from "@versedbcom/sdk";

const verseDB = new VerseDB({
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await verseDB.activity.getActivityFeed({
    perPage: 20,
  });

  console.log(result);
}

run();

Error Handling

VerseDbError is the base class for all HTTP error responses. It has the following properties:

Property Type Description
error.message string Error message
error.statusCode number HTTP response status code eg 404
error.headers Headers HTTP response headers
error.body string HTTP body. Can be empty string if no body is returned.
error.rawResponse Response Raw HTTP response
error.data$ Optional. Some errors may contain structured data. See Error Classes.

Example

import { VerseDB } from "@versedbcom/sdk";
import * as errors from "@versedbcom/sdk/models/errors";

const verseDB = new VerseDB({
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  try {
    const result = await verseDB.activity.getActivityFeed({
      perPage: 20,
    });

    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.VerseDbError) {
      console.log(error.message);
      console.log(error.statusCode);
      console.log(error.body);
      console.log(error.headers);

      // Depending on the method different errors may be thrown
      if (error instanceof errors.GetActivityFeedUnauthorizedError) {
        console.log(error.data$.message); // string
      }
    }
  }
}

run();

Error Classes

Primary error:

Less common errors (245)

Network errors:

Inherit from VerseDbError:

* Check the method documentation to see if the error is applicable.

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by passing a URL to the serverURL: string optional parameter when initializing the SDK client instance. For example:

import { VerseDB } from "@versedbcom/sdk";

const verseDB = new VerseDB({
  serverURL: "https://versedb.com",
  token: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await verseDB.activity.getActivityFeed({
    perPage: 20,
  });

  console.log(result);
}

run();

Custom HTTP Client

The TypeScript SDK makes API calls using an HTTPClient that wraps the native Fetch API. This client is a thin wrapper around fetch and provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.

The HTTPClient constructor takes an optional fetcher argument that can be used to integrate a third-party HTTP client or when writing tests to mock out the HTTP client and feed in fixtures.

The following example shows how to:

  • route requests through a proxy server using undici's ProxyAgent
  • use the "beforeRequest" hook to add a custom header and a timeout to requests
  • use the "requestError" hook to log errors
import { VerseDB } from "@versedbcom/sdk";
import { ProxyAgent } from "undici";
import { HTTPClient } from "@versedbcom/sdk/lib/http";

const dispatcher = new ProxyAgent("http://proxy.example.com:8080");

const httpClient = new HTTPClient({
  // 'fetcher' takes a function that has the same signature as native 'fetch'.
  fetcher: (input, init) =>
    // 'dispatcher' is specific to undici and not part of the standard Fetch API.
    fetch(input, { ...init, dispatcher } as RequestInit),
});

httpClient.addHook("beforeRequest", (request) => {
  const nextRequest = new Request(request, {
    signal: request.signal || AbortSignal.timeout(5000)
  });

  nextRequest.headers.set("x-custom-header", "custom value");

  return nextRequest;
});

httpClient.addHook("requestError", (error, request) => {
  console.group("Request Error");
  console.log("Reason:", `${error}`);
  console.log("Endpoint:", `${request.method} ${request.url}`);
  console.groupEnd();
});

const sdk = new VerseDB({ httpClient: httpClient });

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches console's interface as an SDK option.

Warning

Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

import { VerseDB } from "@versedbcom/sdk";

const sdk = new VerseDB({ debugLogger: console });

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors