Skip to content

TypeScript SDK

@chelsea/sdk is a TypeScript client for the REST API. Its types are generated from Chelsea’s OpenAPI document by openapi-typescript, and its requests go through openapi-fetch. Every path, parameter, body and answer is typed, so a call the API doesn’t accept doesn’t compile.

Add the package folder from a copy of the repository:

Terminal window
bun add ./chelsea/packages/sdk

The package ships TypeScript source. Bun runs it as is; other runtimes need a toolchain that compiles TypeScript from node_modules.

import { createChelseaClient, discoverInstance } from "@chelsea/sdk";
const instance = await discoverInstance("chelsea.example.com");
const chelsea = createChelseaClient({ baseUrl: instance.resource, token: process.env.CHELSEA_TOKEN ?? "" });

discoverInstance reads the install’s public instance document and refuses an address that isn’t a Chelsea install, uses plain http outside your own computer, or redirects. If you already know the address, skip it and pass https://chelsea.example.com/api/v1 as baseUrl.

The token is an API token.

import { createChelseaClient, readChelseaError } from "@chelsea/sdk";
const chelsea = createChelseaClient({
baseUrl: "https://chelsea.example.com/api/v1",
token: process.env.CHELSEA_TOKEN ?? "",
});
const result = await chelsea.GET("/me/tasks");
if (result.error) throw readChelseaError(result.error, result.response);
for (const task of result.data.data.today) {
console.info(`#${task.number} ${task.title}`);
}

A call never throws on an HTTP error. It resolves to { data, error, response }, with error set when the status isn’t 2xx. readChelseaError(error, response) turns that into a ChelseaApiError with status, code, message and the raw body. Treat code as an open set, as the error reference explains. A network failure rejects the call itself.