DocumentationTypeScript SDK

TypeScript SDK

v1

A typed client for Node.js 20.3+ and modern server runtimes. Zero runtime dependencies.

castrook · 0.5.0TypeScript SDK + CLI · MIT
Download

Install

Shell
npm install castrook@0.5.0

Initialize on your server

TypeScript
import { Castrook, CastrookError } from 'castrook';

const castrook = new Castrook({
  apiKey: process.env.CASTROOK_API_KEY!,
  baseURL: 'https://castrook.com/api/v1',
});

The default API base is https://castrook.com/api/v1. For OAuth server integrations use new Castrook({ accessToken }) with a REST-bound token; a grant issued for MCP cannot be reused for another resource.

Publish with a typed response

TypeScript
const { data: post } = await castrook.posts.create({
  text: 'Hello from Castrook.',
  account_ids: [account.id],
  media: {
    type: 'video',
    url: 'https://your-cdn.com/hello.mp4',
  },
}, { idempotencyKey: 'my-first-post-v1' });

console.log(post.id, post.status); // queued

Walk a list

TypeScript
for await (const post of castrook.paginate(cursor =>
  castrook.posts.list({ cursor })
)) {
  console.log(post.id, post.status, post.targets);
}

Available resources

ResourceMethods
accountslist, createTest, assignProfile, publishingOptions, listBoards, listBoardSections, acceptAnalyticsPolicy, disconnect
postslist, create, get, cancel
commentslist, reply
webhookslist, create, disable
deliverieslist
logslist
usageget
profileslist, create, get, update, delete
connectSessionscreate, get, revoke
medialist, get, createUpload, complete, upload, delete
analyticsposts, summary, refresh

Responses preserve the API’s { data, meta? } envelope. CastrookError exposes the API error code, details and request ID, with isUsageLimit(), isAccountLimit() and isRateLimit() checks for plan limit errors. The client supports request cancellation and retries safe requests, but never retries an allowance or account limit error; set maxRetries: 0 to disable retries.

Other clients

Use the Python SDK, CLI or MCP with the same REST behavior. Versions 0.2 and 0.3 of @castrook/sdk remain downloadable compatibility artifacts; new projects use castrook.

Machine-readable SDK guide · Machine manifest