Skip to content

Contentrain/sdk

Repository files navigation

Contentrain SDK

Contentrain SDK

Official SDK for Contentrain - A Headless CMS that combines Git and Serverless Platforms

Website | Documentation | Discord

🚀 Overview

Contentrain SDK provides a seamless integration layer between your applications and Contentrain CMS. It enables developers to build high-quality digital products without being tied to complex SDKs and APIs.

Key Features

  • 🔄 Native Git Integration: Built-in version control and content history tracking
  • Serverless Collections: Store and manage dynamic content on Serverless Platforms
  • 🌐 Multi-language Support: Built-in internationalization capabilities
  • 🔍 Type-safe Queries: Full TypeScript support with automatic type generation
  • 💾 Smart Caching: Built-in LRU caching for optimal performance
  • 🛠️ Framework Agnostic: Works with any JavaScript/TypeScript framework
  • 📦 Zero Dependencies: Minimal core package with optional integrations

📦 Packages

This monorepo contains the following packages:

Core query package for content management operations.

  • Features:
    • High-performance content loading
    • Advanced query capabilities with type safety
    • Built-in LRU caching
    • Relation support
    • Multi-language content handling
    • Serverless collections support

📚 Documentation | 💻 Source | 📦 npm

Official Nuxt.js integration module for Contentrain.

  • Features:
    • Auto-imported composables
    • SSR & SSG support
    • Built-in caching
    • Real-time content updates
    • TypeScript support
    • Nuxt 3 compatibility

📚 Documentation | 💻 Source | 📦 npm

TypeScript types generator for content models.

  • Features:
    • Automatic type generation
    • Watch mode support
    • Custom type transformers
    • Relation type mapping
    • CLI tool
    • Full type safety

📚 Documentation | 💻 Source | 📦 npm

🚀 Quick Start

# Install core package
npm install @contentrain/query

# Optional: Install framework integration
npm install @contentrain/nuxt # for Nuxt.js

# Optional: Install types generator
npm install -D @contentrain/types-generator

💡 Usage Examples

Basic Query Operations

import { ContentrainSDK } from '@contentrain/query';

const sdk = new ContentrainSDK({
  contentDir: './content'
});

// Simple query
const posts = await sdk.query('posts')
  .where('status', 'eq', 'published')
  .orderBy('createdAt', 'desc')
  .limit(10)
  .get();

// With relations
const post = await sdk.query('posts')
  .where('slug', 'eq', 'hello-world')
  .include('author')
  .include('categories')
  .first();

// Multi-language content
const trPosts = await sdk.query('posts')
  .locale('tr')
  .get();

Nuxt.js Integration

// nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@contentrain/nuxt'],
  contentrain: {
    contentDir: './content',
    defaultLocale: 'en'
  }
});

// In your components
const { query, load } = useContentrain();
const { data: posts } = await query('posts').get();

Type Generation

# Generate types from your content models
npx contentrain-generate

# Watch mode
npx contentrain-generate --watch

🌟 Key Benefits

  • Developer Experience: Built by developers, for developers
  • Content Team Collaboration: Seamless workflow between developers and content creators
  • Serverless First: Native support for serverless platforms
  • Type Safety: Full TypeScript support with automatic type generation
  • Performance: Built-in caching and optimization strategies
  • Flexibility: Framework agnostic with official integrations

🔧 Advanced Features

  • Content Schema Builder: Design your content models with JSON or Markdown
  • Asset Management: Built-in support for various file types (SVG, PNG, PDF, JPEG, Video)
  • Webhooks: Create automations with your favorite third-party tools
  • Version Control: Track content history with native Git integration
  • SEO Optimization: Full control over meta titles, descriptions, and OG images

🤝 Contributing

We love our contributors! Please read our Contributing Guide to learn about our development process and how you can propose bugfixes and improvements.

📚 Documentation

💬 Community

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🏢 Company

Contentrain Inc. is based in Beaverton, Oregon, U.S. Visit contentrain.io to learn more about our company and products.