SDK
TypeScript SDK — Installatie
Installeer de OptimoCMS TypeScript SDK en bouw type-safe integraties. Ondersteunt Node.js 18+, retries, pagination en alle API endpoints.
TypeScript SDK
De officiële TypeScript SDK biedt een type-safe, ergonomische interface voor de OptimoCMS API.
Installatie
npm install @optimocms/sdkOf met yarn/pnpm:
yarn add @optimocms/sdk
pnpm add @optimocms/sdkVereisten
| Omgeving | Minimale versie |
|---|---|
| Node.js | 18.0+ |
| TypeScript | 5.0+ (optioneel, maar aanbevolen) |
| Browser | Elk met ES2020 module support (Chrome 80+, Firefox 80+, Safari 14+, Edge 80+) |
Module formaten
De SDK levert zowel ESM als CJS bundles:
// ESM (aanbevolen)
import { OptimoCMS } from '@optimocms/sdk';
// CommonJS
const { OptimoCMS } = require('@optimocms/sdk');Client setup
import { OptimoCMS } from '@optimocms/sdk';
const cms = new OptimoCMS({
apiKey: process.env.OPTIMOCMS_API_KEY!,
});Configuratie-opties
const cms = new OptimoCMS({
apiKey: process.env.OPTIMOCMS_API_KEY!,
// Basis-URL (standaard: https://api.optimocms.com)
baseUrl: 'https://api.optimocms.com',
// Request timeout in ms (standaard: 30000)
timeout: 30_000,
// Automatische retry bij 429/5xx (standaard: 3)
maxRetries: 3,
});| Optie | Type | Standaard | Beschrijving |
|---|---|---|---|
apiKey | string | — | Verplicht. Je API key |
baseUrl | string | https://api.optimocms.com | API basis-URL |
timeout | number | 30000 | Request timeout in milliseconden |
maxRetries | number | 3 | Max retries bij rate limit of server errors |
Browser gebruik
De SDK werkt ook in de browser. Gebruik nooit je API key direct in client-side code — maak een backend proxy:
// Backend (Node.js) — /api/sites.ts
import { OptimoCMS } from '@optimocms/sdk';
const cms = new OptimoCMS({ apiKey: process.env.OPTIMOCMS_API_KEY! });
export async function GET() {
const sites = await cms.sites.list();
return Response.json(sites);
}// Frontend (browser)
const response = await fetch('/api/sites');
const sites = await response.json();Beschikbare modules
Na initialisatie heb je toegang tot alle API modules:
cms.sites // Sites beheren
cms.pages // Pagina CRUD
cms.media // Media uploaden en beheren
cms.analytics // Analytics ophalen
cms.ai // AI generatie en vertaling
cms.booking // Boekingen
cms.reservation // Reserveringen
cms.shop // Producten, bestellingen, coupons
cms.loyalty // Loyaliteitspunten
cms.webhooks // Webhook configuratie
cms.forms // Formulier inzendingen
cms.push // Push notificaties
cms.reviews // Reviews
cms.recruitment // Vacatures
cms.batch // Bulk operaties
cms.jobs // Async job pollingTypeScript types
Alle request en response types zijn volledig getypeerd en geëxporteerd:
import type {
Site,
SiteSummary,
Page,
PageDetail,
PageSummary,
CreatePageInput,
UpdatePageInput,
MediaItem,
AnalyticsSummary,
Product,
Booking,
OptimoCMSError,
PaginatedResponse,
} from '@optimocms/sdk';Try it — curl equivalent:
# De SDK verbergt deze details, maar dit is wat er onder de motorkap gebeurt
curl https://api.optimocms.com/v1/sites \
-H "X-Api-Key: optimo_live_abc123def456"Try it — MCP equivalent:
Gebruik de list_sites tool.Volgende stappen
- Foutafhandeling — Typed errors, retry strategie en 429 handling
- Paginering — Async iterators en cursor-based paginering
- Authenticatie — Scopes en rate limits
- API Referentie — Alle endpoints