Node.js
Content
Fetch content, links, and translations with the @localess/client TypeScript SDK.
Fetching Content
getContentBySlug<T>(slug, params?)
Fetch a content document by its slug path. Supports generic typing for full type safety.
// Basic usage
const content = await client.getContentBySlug('docs/overview');
// With type safety (requires generated types from @localess/cli)
import type { Page } from './.localess/localess';
const content = await client.getContentBySlug<Page>('home', {
locale: 'en',
resolveReference: true,
resolveLink: true,
resolveAsset: true,
});getContentById<T>(id, params?)
Fetch a content document by its unique ID. Accepts the same parameters as getContentBySlug.
const content = await client.getContentById<Page>('FRnIT7CUABoRCdSVVGGs', {
locale: 'de',
version: 'draft',
});Content Fetch Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
version | 'draft' | string | Client default | Override the client's default content version |
locale | string | — | ISO 639-1 locale code (e.g., 'en', 'de') |
resolveReference | boolean | false | Resolve content references inline |
resolveLink | boolean | false | Resolve content links inline |
resolveAsset | boolean | false | Resolve referenced asset metadata inline |
Fetching Content Links
getLinks(params?)
Fetch all content links from the space, optionally filtered by type or parent.
// Fetch all links
const links = await client.getLinks();
// Fetch only documents under a specific parent
const legalLinks = await client.getLinks({
kind: 'DOCUMENT',
parentSlug: 'legal',
excludeChildren: false,
});| Parameter | Type | Description |
|---|---|---|
kind | 'DOCUMENT' | 'FOLDER' | Filter results by content kind |
parentSlug | string | Filter by parent slug (e.g., 'legal/policy') |
excludeChildren | boolean | When true, excludes nested sub-slugs from results |
Fetching Translations
getTranslations(locale, params?)
Fetch all translations for a given locale. Returns a flat key-value map.
const translations = await client.getTranslations('en');
// { "common.submit": "Submit", "nav.home": "Home", ... }
// Override the client's default version for this request
const draftTranslations = await client.getTranslations('en', { version: 'draft' });Parameter (TranslationFetchParams) | Type | Default | Description |
|---|---|---|---|
version | 'draft' | undefined | Client default | 'draft' for preview, omit for published |