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).

Access via: lynkow.cookies

Methods

3 methods

clearCache

TypeScript
clearCache(): void

Invalidates the cached cookie consent configuration. Call this if you know the consent settings have changed and want to force a fresh fetch on the next getConfig() call.

Returns: void


getConfig

TypeScript
getConfig(): Promise<CookieConfig>

Retrieves the cookie consent banner configuration from the API, including categories (necessary, analytics, marketing, preferences), banner texts, theming options, and third-party scripts to inject per category. Cached for 10 minutes.

Returns: Promise<CookieConfig>

TypeScript
const config = await lynkow.cookies.getConfig()
if (config.enabled) {
  console.log(config.categories) // [{id: 'necessary', ...}, {id: 'analytics', ...}]
  console.log(config.texts.acceptAll) // "Accept all"
}

logConsent

TypeScript
logConsent(preferences: CookiePreferences, options?: BaseRequestOptions): Promise<ConsentLogResponse>

Records the user's cookie consent preferences to the server for audit trail / GDPR compliance. This is a write operation (POST) and is never cached.

Parameter

Type

Description

preferences

CookiePreferences

A record mapping category IDs to boolean acceptance values<br> (e.g. { necessary: true, analytics: true, marketing: false })

options

BaseRequestOptions

Base request options (custom fetch options)

Returns: Promise<ConsentLogResponse>

TypeScript
const result = await lynkow.cookies.logConsent({
  necessary: true,
  analytics: true,
  marketing: false
})
console.log(result.consentId) // Unique consent record ID