Skip to main content

Content SDK

@forjacms/client is the official TypeScript SDK for consuming the Forja CMS content API. It provides typed methods for all public endpoints, pagination helpers, and structured error handling.

Features

  • Typed responses — every API response has a TypeScript interface
  • Resource-based API — organized by domain: blogs, pages, navigation, taxonomy, analytics, CV, legal, media, social
  • Pagination helpersfetchNext(), fetchAll(), and async iteration
  • Error mapping — HTTP errors mapped to typed error classes
  • Runtime-agnostic — works in Node.js, browsers, Deno, and edge runtimes (uses fetch)
  • Custom fetch — inject your own fetch for testing or platform compatibility

Installation

npm install @forjacms/client

Quick Start

import { ForjaClient } from '@forjacms/client';

const forja = new ForjaClient({
baseUrl: 'https://your-forja-instance.com/api/v1',
apiKey: 'your-read-api-key',
siteId: 'your-site-uuid',
});

// Fetch published blogs
const blogs = await forja.blogs.listPublished({ page: 1, pageSize: 10 });

// Fetch site info
const site = await forja.site.get();

// Fetch navigation tree
const nav = await forja.navigation.getTree('menu-id', { locale: 'en' });

Configuration

OptionTypeRequiredDescription
baseUrlstringYesFull URL to the Forja API (e.g. https://cms.example.com/api/v1)
apiKeystringYesAPI key with at least Read permission
siteIdstringYesUUID of the site to query
fetchtypeof fetchNoCustom fetch implementation (defaults to globalThis.fetch)
API Key Permissions

All consumer SDK methods require a Read API key at minimum. Create one in the admin dashboard under Settings > API Keys.

Available Resources

The ForjaClient instance exposes the following resource namespaces:

ResourceAccessorDescription
Blogsforja.blogsPublished blog posts, featured lists, category filtering, RSS
Pagesforja.pagesCMS pages by route, sections, localizations
Navigationforja.navigationMenus, navigation trees, menu items
Taxonomyforja.taxonomyTags, categories, content associations
Analyticsforja.analyticsPageview tracking, reports, per-page stats
CVforja.cvSkills, CV entries (work, education, etc.)
Legalforja.legalLegal documents, cookie consent, consent groups
Siteforja.siteSite configuration and metadata
Mediaforja.mediaMedia assets and variants
Socialforja.socialSocial media links
Projectsforja.projectsPortfolio projects with localizations, links, media, skill associations
Redirectsforja.redirectsURL redirect lookup for SSR middleware

The forja.site resource also provides forja.site.listLocales() for fetching available locales.

See the full Resource Reference for method signatures and examples.

TypeScript Support

All response types are exported from the package and can be imported directly:

import type {
BlogListItem,
BlogDetailResponse,
PageDetailResponse,
NavigationTree,
SiteResponse,
MediaResponse,
PaginationMeta,
} from '@forjacms/client';

Custom Fetch

Pass a custom fetch implementation for environments that do not provide a global fetch, or for injecting test doubles:

import { ForjaClient } from '@forjacms/client';
import nodeFetch from 'node-fetch';

const forja = new ForjaClient({
baseUrl: 'https://cms.example.com/api/v1',
apiKey: 'dk_read_...',
siteId: 'your-site-uuid',
fetch: nodeFetch as unknown as typeof fetch,
});
Runtime Compatibility

In modern Node.js (18+), Deno, Bun, and all browsers, globalThis.fetch is available natively. The fetch option is only needed for older Node.js versions or for injecting mocks in tests.