Version: 3.8.68

Installation

Bash
npm install @lynkow/sdk

Quick Start

TypeScript
import { createClient } from '@lynkow/sdk'

const lynkow = createClient({
  siteId: 'your-site-id',
  apiUrl: 'https://api.lynkow.com'
})

const posts = await lynkow.contents.list()

Available Services

  • AnalyticsService — Service for client-side analytics tracking via the Lynkow tracker.js script.

Accessible via lynkow.analytics. This is a browser-only service -- all methods are no-ops when called on the server (SSR/Node.js). The service lazily loads the tracker.js script from the API, which auto-initializes using the site ID. The tracker automatically captures pageviews; use trackPageview() for manual SPA navigation tracking and trackEvent() for custom events.

The service respects the site's consent mode: if consent mode is 'opt-in', tracking only starts after consent is granted. The consent state is read from localStorage (_lkw_consent_mode key).

  • BlocksService — Service for retrieving global site blocks (header, footer, navigation, etc.).

Accessible via lynkow.globals (aliased from lynkow.blocks). Global blocks are reusable, schema-driven content components shared across all pages of the site. They are resolved server-side with DataSources. Responses are cached for 10 minutes (MEDIUM TTL) since global blocks change infrequently.

  • BrandingService — Service for displaying the "Powered by Lynkow" branding badge.

Accessible via lynkow.branding. This is a browser-only service -- all methods are no-ops on the server. The badge HTML and CSS are fetched from the API (cached for 30 minutes, LONG TTL) so they can be updated server-side without SDK changes. The badge automatically adapts to the site's light/dark theme via a MutationObserver.

The badge is shown for sites on the free plan (siteConfig.showBranding === true). It fails silently if the fetch fails (the badge is not critical).

  • CategoriesService — Service for retrieving content categories and their hierarchical structure.

Accessible via lynkow.categories. Categories organize blog articles and can be nested (parent/child). Each category includes a content count and optional image. Responses are cached for 5 minutes (SHORT TTL) when a cache adapter is configured.

  • ConsentService — High-level consent management service with built-in banner UI and preferences modal.

Accessible via lynkow.consent. This is a hybrid service:

  • API methods (getConfig, logConsent) work everywhere (server + browser)

  • UI methods (show, hide, acceptAll, rejectAll, showPreferences, etc.) only work in the browser and are no-ops on the server

Consent choices are persisted in localStorage under the _lkw_consent key (compatible with tracker.js) and expire after 365 days. When consent is granted for a category, any third-party scripts configured for that category are automatically injected into the page.

Emits a 'consent-changed' event (via the SDK event emitter) and a 'lynkow:consent:update' CustomEvent on document whenever consent changes.

  • ContentsService — Service for retrieving published blog articles (contents).

Accessible via lynkow.contents. All methods return only published content visible to the public API. Responses are cached in-memory for 5 minutes (SHORT TTL) when a cache adapter is configured on the client.

  • CookiesService — Low-level service for cookie consent API interactions.

Accessible via lynkow.cookies. Provides raw API methods for fetching consent configuration and logging user preferences. For a higher-level experience with built-in banner UI and preferences modal, use the consent service (lynkow.consent) instead.

Responses are cached for 10 minutes (MEDIUM TTL).

  • EnhancementsService — Service for adding interactive features to content rendered from the Lynkow API.

Accessible via lynkow.enhancements. This is a browser-only service -- all methods are no-ops on the server. Currently provides:

  • Copy button for code blocks (elements with [data-copy-code] attribute)

  • Script activation for inline scripts injected via dangerouslySetInnerHTML

  • Widget iframe auto-resize for embedded Lynkow widgets

  • CSS normalization to ensure content renders correctly with CSS frameworks (Tailwind, etc.)

A MutationObserver automatically detects new content added to the DOM and applies enhancements, making it compatible with SPA frameworks like React/Next.js. Script clones are appended to <head> (not inline) to avoid React DOM reconciliation issues.

  • FormsService — Service for retrieving form schemas and submitting form data.

Accessible via lynkow.forms. Forms are dynamic, CMS-managed forms with configurable fields, validation rules, and spam protection. The service automatically handles honeypot anti-spam fields on submissions. Form schemas are cached for 10 minutes (MEDIUM TTL).

  • LegalService — Service for accessing legal documents (privacy policy, terms of service, etc.).

Accessible via lynkow.legal. Legal documents are regular pages tagged with 'legal'. This service provides convenience methods to access them, but is deprecated in favor of the pages service.

Responses are cached for 5 minutes (SHORT TTL).

  • MediaHelperService — Service for building optimized image URLs using Cloudflare Image Transformations.

Accessible via lynkow.media. This is a pure utility service (no API calls, no caching) that constructs Cloudflare /cdn-cgi/image/ URLs from Lynkow media URLs. Works on both server and browser. Handles both original URLs (/sites/...) and already-transformed URLs (/cdn-cgi/image/...), re-extracting the original path when needed.

  • PagesService — Service for retrieving published pages (Site Blocks of type "page").

Accessible via lynkow.pages. Pages are CMS-managed, schema-driven content blocks (e.g. "About", "Contact", legal pages). Unlike blog articles, pages use DataSource-resolved data instead of a rich text body. Responses are cached for 5 minutes (SHORT TTL) when a cache adapter is configured.

  • PathsService — Service for URL path resolution and static site generation (SSG).

Accessible via lynkow.paths. Provides methods to list all available paths for static generation, resolve a URL path to its content or category, and check for configured redirects. Cached for 5 minutes (SHORT TTL).

  • ReviewsService — Service for retrieving and submitting customer reviews.

Accessible via lynkow.reviews. Only reviews with status 'approved' are returned by the public API. New submissions go through moderation if requireApproval is enabled in the review settings. Anti-spam honeypot fields are injected automatically on submissions. Responses are cached for 5 minutes (SHORT TTL).

  • SeoService — Service for retrieving SEO-related files (sitemap, robots.txt, LLM-optimized content, and individual Markdown exports).

Accessible via lynkow.seo. All methods return plain text (XML, TXT, or Markdown) and are NOT cached by the SDK since they are typically served as route handlers with their own HTTP caching headers.

  • SiteService — Service for retrieving the public site configuration.

Accessible via lynkow.site. Provides site-level metadata such as name, domain, locales, timezone, branding settings, and analytics consent mode. Cached for 10 minutes (MEDIUM TTL) since site configuration rarely changes.

  • TagsService — Service for retrieving content tags.

Accessible via lynkow.tags. Tags are lightweight labels attached to blog articles for cross-cutting classification (unlike categories which are hierarchical). Responses are cached for 5 minutes (SHORT TTL).