TypeScript SDK
v1A typed client for Node.js 20.3+ and modern server runtimes. Zero runtime dependencies.
Install
npm install castrook@0.5.0Initialize on your server
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
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); // queuedWalk a list
for await (const post of castrook.paginate(cursor =>
castrook.posts.list({ cursor })
)) {
console.log(post.id, post.status, post.targets);
}Available resources
| Resource | Methods |
|---|---|
accounts | list, createTest, assignProfile, publishingOptions, listBoards, listBoardSections, acceptAnalyticsPolicy, disconnect |
posts | list, create, get, cancel |
comments | list, reply |
webhooks | list, create, disable |
deliveries | list |
logs | list |
usage | get |
profiles | list, create, get, update, delete |
connectSessions | create, get, revoke |
media | list, get, createUpload, complete, upload, delete |
analytics | posts, 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.