Setup and Configuration
The Decoupla SDK follows a code-first schema model. You define your data models in TypeScript, which ensures your frontend and backend stay perfectly in sync.
Installation
The package is compatible with both Node.js and Bun. It includes both the programmatic client and the decoupla CLI.
# Using npm
npm install @decoupla/sdk
# Using Bun
bun add @decoupla/sdk
Configuration Source of Truth
Create a decoupla.config.ts in your project root. This file is used by the CLI to sync your schema and can be imported by your app to initialize the client.
import { defineConfig, defineContentType } from '@decoupla/sdk';
// 1. Define your content models
export const Author = defineContentType({
name: 'author',
fields: {
Name: { type: 'string', required: true, isLabel: true },
Bio: { type: 'text' },
},
});
export const BlogPost = defineContentType({
name: 'blog_post',
fields: {
Title: { type: 'string', required: true, isLabel: true },
Author: { type: 'reference', references: [Author], required: true },
ViewCount: { type: 'int' },
},
});
// 2. Export the configuration
export default defineConfig({
workspace: process.env.DECOUPLA_WORKSPACE!,
apiToken: process.env.DECOUPLA_API_TOKEN!,
contentTypes: [Author, BlogPost],
});
API Token
To generate a new API Token for your application, navigate to your Project's API Settings > API Tokens and generate a new token. Make sure to select only the permissions that fit your use case.
Replace the apiToken and workspace with the values from your API Tokens.