@estokad/sdk
v0.1.6
Published
Framework-agnostic TypeScript client for the Estokad content API.
Readme
@estokad/sdk
Framework-agnostic TypeScript client for the Estokad content API. End-to-end typed: your defineType() schemas drive the response types, no codegen step.
Install
pnpm add @estokad/sdkQuickstart
import { createClient } from '@estokad/sdk'
const cms = createClient({
workspace: 'my-workspace',
apiUrl: 'https://api.estokad.com',
apiKey: process.env.ESTOKAD_API_KEY!,
})
// Fetch a list
const articles = await cms.list('article', { first: 20 })
// Fetch by id or slug
const article = await cms.fetch('article', 'launch-week-day-1')
// Singleton
const settings = await cms.singleton('siteSettings').fetch()
// Mutations (require write or management scope)
await cms.update('article', article.id, { title: 'Updated' })
await cms.publish('article', article.id)Typing your responses
Declare a ContentTypes interface and the SDK becomes fully typed:
import type { ContentTypes } from '@estokad/sdk'
declare module '@estokad/sdk' {
interface ContentTypes {
article: {
title: string
body: string
publishedAt: string | null
}
siteSettings: {
siteName: string
ga4MeasurementId: string
}
}
}
// Now `articles[0].title` is typed as `string`, no `any` anywhere.In a real project, the type generation step is automatic — see @estokad/cli estokad pull which writes a .estokad/types.ts declaration file alongside your schemas/*.ts files.
Errors
import {
EstokadError,
NotFoundError,
ValidationError,
RateLimitError,
UnauthorizedError,
} from '@estokad/sdk'
try {
await cms.update('article', id, { title: '' })
} catch (err) {
if (err instanceof ValidationError) {
console.error('field issues:', err.issues)
} else if (err instanceof RateLimitError) {
console.error('retry after seconds:', err.retryAfter)
}
}GraphQL escape hatch
const result = await cms.gql<{ article: { title: string } }>(
`query($id: ID!) { article(id: $id) { title } }`,
{ id: 'launch-week-day-1' },
)Framework adapters
Don't use this directly — use one of the adapters:
@estokad/nextfor Next.js (App Router + draft mode + visual edit).@estokad/nuxtfor Nuxt 3.@estokad/sveltefor SvelteKit.
Each wraps createClient with the framework's preferred conventions (cookies, server-side fetch, etc.).
Documentation
Full reference at docs.estokad.com. AI-friendly index at docs.estokad.com/llms.txt.
License
Apache-2.0. Estokad is a Samarkand Industries OÜ product.
