devigo
v0.1.6
Published
Official JavaScript SDK for Devigo Studio. The whitelabel headless CMS built for every site.
Readme
Devigo JavaScript SDK
Official JavaScript SDK for the Devigo CMS. TypeScript-first, zero dependencies, ESM only.
Installation
npm install devigoRequires Node.js 18 or later (uses the native fetch API).
Quick Start
import { createClient } from 'devigo'
const devigo = createClient({
token: 'your-api-token',
baseUrl: 'https://your-site.com',
})
// Fetch a page
const home = await devigo.pages.get('home')
// Fetch a post type collection
const posts = await devigo.posts('blog').list({ limit: 10 })
// Fetch a menu
const header = await devigo.menus.get('header')API Reference
createClient(config)
Creates a new Devigo client instance.
| Parameter | Type | Description |
|-----------|------|-------------|
| config.token | string | Your Devigo API token (required) |
| config.baseUrl | string | Your site's base URL, e.g. https://your-site.com (required) |
Returns a DevigoClient instance.
Pages
devigo.pages.list(): Promise<Page[]>
Fetch all pages.
devigo.pages.get(slug: string): Promise<Page>
Fetch a single page by slug.
Posts
devigo.posts(type: string): PostsResource
Returns a resource scoped to the given post type slug.
devigo.posts(type).list(params?): Promise<PostCollection>
Fetch a paginated list of post entries.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| params.limit | number | — | Max entries to return |
| params.offset | number | — | Number of entries to skip |
devigo.posts(type).get(slug: string): Promise<PostEntry>
Fetch a single post entry by slug.
Menus
devigo.menus.list(): Promise<MenuSummary[]>
Fetch all menus (slug and name only).
devigo.menus.get(slug: string): Promise<Menu>
Fetch a single menu with its full item tree.
Media
devigo.media.list(): Promise<MediaFile[]>
Fetch all media files.
Forms
devigo.forms.get(id: number): Promise<Form>
Fetch a form's field definitions.
devigo.forms.submit(id: number, payload: FormSubmitPayload): Promise<FormSubmitResponse>
Submit a form entry.
await devigo.forms.submit(1, {
name: 'Jane Doe',
email: '[email protected]',
message: 'Hello!',
})Error Handling
The SDK throws typed errors for common API failures:
import { createClient, DevigoNotFoundError, DevigoAuthError } from 'devigo'
try {
const page = await devigo.pages.get('missing-page')
} catch (err) {
if (err instanceof DevigoNotFoundError) {
// 404 — page not found
}
if (err instanceof DevigoAuthError) {
// 401/403 — invalid or expired token
}
}| Error Class | Status | Description |
|-------------|--------|-------------|
| DevigoApiError | any | Base error class for all API errors |
| DevigoNotFoundError | 404 | Resource not found |
| DevigoAuthError | 401/403 | Authentication or authorization failure |
License
UNLICENSED
