Localess
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

ParameterTypeDefaultDescription
version'draft'Client defaultSet 'draft' to fetch unpublished content for this call
localestring—ISO 639-1 locale code (e.g., 'en', 'de')
resolveReferencebooleanfalseFill content.references with the referenced documents
resolveLinkbooleanfalseFill content.links with the linked documents' metadata
resolveAssetbooleanfalseFill content.assets with metadata (alt text, dimensions…) for the assets used

Resolution is one level deep — a resolved reference's own references aren't followed — and targets that can't be resolved are omitted rather than raising an error.

Every fetching method also accepts signal (an AbortSignal) and fetchInit — see Timeouts and retries and Framework fetch options.

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,
});
ParameterTypeDescription
kind'DOCUMENT' | 'FOLDER'Filter results by content kind
parentSlugstringFilter by parent slug (e.g., 'legal/policy')
excludeChildrenbooleanWhen 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)TypeDefaultDescription
version'draft' | undefinedClient default'draft' for preview, omit for published

On this page