SDK & Integration

The generic Entries module

Atualizado em 226 visualizações

kookee.entries is the module underneath all the others. kookee.blog, kookee.help, kookee.changelog, kookee.pages and kookee.announcements are thin wrappers around it that fill in the entry type and narrow the return type — every one of their reads ends up here.

Two reasons to use it directly:

  • Filters the typed modules lack. Only entries.list() takes category, tags and filter for every type; blog.list() has no filter, and announcements.list() takes none of the three.

  • One code path across every type. A universal search box, a sitemap, an "everything we published this month" feed — anything that treats blog posts, help articles and changelog entries as the same kind of thing is simpler written once against entries than five times against five modules.

If you only ever read one type and it has its own module, use the module. The typed return (BlogEntryDetail rather than GenericEntryDetail) is worth having. See Working with the Blog module and its siblings.

Listing entries

type is the only required option, and it is the type's slug — 'blog', 'help_article', 'changelog', 'page' or 'announcement':

TypeScript
const posts = await kookee.entries.list({ type: 'blog', page: 1, limit: 10 });

You get back a PaginatedResponse<GenericEntryListItem>: { data, total, limit, page, totalPages }.

The full option set:

  • type — the entry type slug. Required.

  • page / limit — pagination.

  • locale — which language to read.

  • fallback — false turns off falling back to the project's default locale. Defaults to true.

  • category — a category slug, not an id.

  • tags — an array of tag slugs. Matches entries carrying any of them.

  • search — substring match against title, excerpt and body.

  • filter — structured field filters, keyed by field slug.

TypeScript
// Help articles in one category
const articles = await kookee.entries.list({ type: 'help_article', category: 'getting-started' });

// Blog posts tagged either way, in French, no fallback to the default locale
const posts = await kookee.entries.list({
  type: 'blog',
  tags: ['release', 'engineering'],
  locale: 'fr',
  fallback: false,
});

// Only changelog entries that are new features
const features = await kookee.entries.list({ type: 'changelog', filter: { changelogType: 'feature' } });

A category or tags slug that does not exist is not an error — you get an empty page back. That is worth remembering when a filter silently returns nothing: check the slug before checking the content.

List items do not include contentHtml. Use excerptHtml or excerptText for previews, and fetch the entry itself when you need the body.

Fetching one entry

TypeScript
// By slug — the type is required, because slugs are only unique within a type
const entry = await kookee.entries.getBySlug('my-post', { type: 'blog' });

// By id — no type needed, the id already identifies it
const byId = await kookee.entries.getById('entry-uuid');

Both take locale and fallback as well:

TypeScript
const french = await kookee.entries.getBySlug('my-post', { type: 'blog', locale: 'fr' });

Both return a GenericEntryDetail, which is the list item plus contentHtml — the rendered body. See Rendering content and styling code blocks for what to do with it.

entries.getById() returns whatever the id is. The typed modules check the type: kookee.blog.getById() given the id of a help article rejects with ENTRY_NOT_FOUND and status 404, the same as for an id that does not exist.

Translations

Two methods, one return type:

TypeScript
const translations = await kookee.entries.getTranslationsBySlug('my-post');
const sameThing = await kookee.entries.getTranslationsById('entry-uuid');

The result is an object keyed by locale, not an array. This trips people up, so it is worth being blunt about:

TypeScript
type EntryTranslationsMap = Record<string, EntryTranslationSummary>;

interface EntryTranslationSummary {
  id: string;
  slug: string | null;
  locale: string;
  title: string;
}

So a response looks like this:

JSON
{
  "en": { "id": "…", "slug": "my-post", "locale": "en", "title": "My post" },
  "fr": { "id": "…", "slug": "mon-article", "locale": "fr", "title": "Mon article" }
}

translations.map(...) does not exist on an object and will throw. Iterate with Object.entries(), Object.values() or a direct lookup:

TypeScript
// A language switcher
for (const [locale, translation] of Object.entries(translations)) {
  console.log(locale, translation.title, translation.slug);
}

// Just the list
const languages = Object.values(translations).map((t) => t.locale);

// Does a French version exist?
const french = translations.fr;
if (french?.slug) {
  redirect(`/fr/blog/${french.slug}`);
}

Note that slug is nullable — announcements are a type that does not use slugs — so guard it before building a URL.

These endpoints return a narrow summary, not full entries. To render a translation, take its slug or id and fetch it. More in Multi-language content and locale fallback.

Comments, reactions, tags and categories

TypeScript
// Comments on any entry
const comments = await kookee.entries.getComments('entry-id', { page: 1, limit: 20 });

// React to any entry
const result = await kookee.entries.react('entry-id', { reactionType: 'heart', action: 'add' });
// result.reactions → { heart: 12, fire: 3 }

reactionType is one of the five built-in types, 'fire' | 'heart' | 'rocket' | 'eyes' | 'mindblown', or any custom type matching [a-z0-9_]{1,50}, and action is 'add' or 'remove'. See Reactions, views and engagement data and Reading and rendering comments.

Tags and categories are fetched per type, and both take the type slug as their first argument:

TypeScript
const tags = await kookee.entries.getTags('blog');
// → [{ id, name, slug, color, count }, …]

const categories = await kookee.entries.getCategories('help_article');
// → [{ id, slug, name, description, icon, articleCount }, …]

getTags() includes a count per tag, so you can build a tag cloud without a second pass. getCategories() takes an optional second argument for locale (an exact match; fallback is ignored):

TypeScript
const frenchCategories = await kookee.entries.getCategories('help_article', { locale: 'fr' });

Note the asymmetry: getTags() takes no options object at all, while getCategories() does. That matters for where the abort signal goes, below.

Exporting everything

export() returns every published, public entry in the project as slim rows — the raw material for a sitemap, an RSS feed or an llms.txt:

TypeScript
const rows = await kookee.entries.export();

It pages through the whole set for you and hands back one flat array, so there is no pagination to manage. Two options:

TypeScript
// Only some types
const rows = await kookee.entries.export({ type: ['blog', 'help_article'] });

// With each entry's body as markdown — what llms-full.txt needs
const withBodies = await kookee.entries.export({ markdown: true });

Each row:

TypeScript
interface ExportEntry {
  type: string;
  typeName: string;
  id: string;
  slug: string | null;
  locale: string;
  title: string;
  description: string | null;
  category: { slug: string; name: string } | null;
  publishedAt: string;
  updatedAt: string;
  markdown: string | null;
}

markdown is null unless you asked for it. Because this walks the entire project, call it on a schedule or at build time rather than per request. SEO and metadata for your content covers the builders that consume these rows.

Cancelling requests

Every read method takes an optional AbortSignal as its last positional argument, handed straight to fetch:

TypeScript
const controller = new AbortController();

kookee.entries.list({ type: 'blog', limit: 10 }, controller.signal);

// The reader typed another character, or navigated away
controller.abort();

The signal always comes after the method's own arguments, so its position differs from method to method. Count the arguments each time:

TypeScript
kookee.entries.list({ type: 'blog' }, signal); // 2nd
kookee.entries.getBySlug('my-post', { type: 'blog' }, signal); // 3rd
kookee.entries.getById('entry-uuid', undefined, signal); // 3rd, params skipped
kookee.entries.getTranslationsBySlug('my-post', signal); // 2nd — no params at all
kookee.entries.getComments('entry-id', { limit: 20 }, signal); // 3rd
kookee.entries.getTags('blog', signal); // 2nd — no params at all
kookee.entries.getCategories('blog', undefined, signal); // 3rd
kookee.entries.export({ markdown: true }, signal); // 2nd
kookee.feedback.getById('post-uuid', signal); // 2nd

When a method takes an optional params object and you have nothing to pass, pass undefined explicitly — the signal has to land in the right slot.

Never put the signal on the params object. Params are serialised into the query string, so a signal there is silently dropped and cancels nothing:

TypeScript
// Wrong — the signal is silently dropped
kookee.entries.list({ type: 'blog', signal: controller.signal });

// Right
kookee.entries.list({ type: 'blog' }, controller.signal);

An aborted request rejects with an AbortError, which is not a KookeeApiError. Check for it before you treat a rejection as a real failure, or you will log cancellations as outages:

TypeScript
try {
  const posts = await kookee.entries.list({ type: 'blog' }, controller.signal);
  render(posts.data);
} catch (error) {
  if (error instanceof DOMException && error.name === 'AbortError') return; // expected
  throw error;
}

This is the pattern behind a search-as-you-type box: keep the controller for the in-flight request, abort it when the next keystroke arrives, and swallow the AbortError.

With timeoutMs configured, a request that carries your signal still has the deadline: it stops at whichever comes first, and a deadline rejects with a TimeoutError rather than an AbortError.

Categories on entries

Every entry carries its category twice, on both list and detail responses: categoryId: string | null for the raw id, and a resolved category object so you do not have to join anything client-side.

TypeScript
interface EntryCategoryRef {
  id: string;
  slug: string;
  name: string;
  icon: string | null;
  description: string | null;
}

An entry with no category has category: null and categoryId: null, so guard it:

TypeScript
const articles = await kookee.entries.list({ type: 'help_article' });

for (const article of articles.data) {
  console.log(article.title, '→', article.category?.name ?? 'Uncategorised');
}

The resolved object is what makes category-based URLs cheap, since the slug is already there:

TypeScript
const href = entry.category ? `/help/${entry.category.slug}/${entry.slug}` : `/help/${entry.slug}`;

icon and description are nullable too. See Organizing content with categories and tags.

Fields on entries

Every entry carries a fields array — the built-in fields for its type (a changelog's type badge and version, an announcement's type) plus the custom fields marked Include in the public API. Three helpers read it, and each returns undefined when the field is missing or unset, so an entry type that has no such field needs no special case:

TypeScript
import { fieldOptionKey, fieldStringValue, findField } from '@kookee/sdk';

const entry = await kookee.entries.getBySlug('v1-0-0', { type: 'changelog' });

// Select fields: the stable option key
fieldOptionKey(entry.fields, 'changelogType'); // 'feature'

// Text-ish fields: the string value
fieldStringValue(entry.fields, 'version'); // '1.0.0'

// The whole row, when you need displayValue or color too
const type = findField(entry.fields, 'changelogType');
type?.displayValue; // 'New Feature' — translated, safe to render
type?.color; // '#22c55e' | null

A field row looks like this:

TypeScript
interface EntryFieldValue {
  fieldId: string;
  slug: string;
  name: string;
  fieldType: 'text' | 'number' | 'date' | 'checkbox' | 'url' | 'email' | 'phone' | 'select' | 'multiSelect';
  value: string | number | boolean | string[];
  displayValue: string;
  color: string | null;
  optionKeys: string[];
}

Branch on option keys, never on displayValue. Keys are stable identifiers that survive a rename and are the same in every language. displayValue is the human-readable label, translated per locale and rewritten whenever someone edits it in the dashboard:

TypeScript
// Good — survives renames and translation
if (fieldOptionKey(entry.fields, 'changelogType') === 'feature') {
  showFeatureBadge();
}

// Fragile — breaks the day someone edits the label, or a French reader arrives
if (findField(entry.fields, 'changelogType')?.displayValue === 'New Feature') {
  showFeatureBadge();
}

Render displayValue, decide on optionKeys. In practice that means one line reading the key for logic and another reading the display value for the label:

tsx
const type = findField(entry.fields, 'changelogType');
const key = fieldOptionKey(entry.fields, 'changelogType');

<span className={key === 'fix' ? 'badge-fix' : 'badge-feature'} style={{ color: type?.color ?? undefined }}>
  {type?.displayValue}
</span>;

fieldOptionKey() returns the first chosen option, which is what you want for a single-select field. For a multi-select, read findField(...)?.optionKeys and handle the whole array.

Keys belong to built-in options. An option of a custom select field has no key, so its optionKeys is empty: branch on its id instead, which value holds (an array of ids for a multi-select) and which also survives a rename.

Filtering a list uses the same slugs and keys:

TypeScript
const fixes = await kookee.entries.list({ type: 'changelog', filter: { changelogType: 'fix' } });

A custom select field is filtered by an option id, and a text field by its exact value. Other field types cannot be filtered and answer ENTRY_FILTER_NOT_SUPPORTED, and a field that is not public answers ENTRY_FIELD_NOT_FOUND.

Checking the connection with health()

kookee.health() is the one call that touches no content. It verifies that your key reaches the API and resolves to a project:

TypeScript
const health = await kookee.health();
// { status: 'ok', projectId: '70e9ae43-…', timestamp: '2026-01-30T12:00:00.000Z' }
  • status — always 'ok' on a successful response. A broken setup throws rather than returning a different status.

  • projectId — the project your key resolved to. Useful for confirming that a deployment is pointed at the project you think it is.

  • timestamp — an ISO 8601 string of the server's time when it answered.

It takes no arguments and no abort signal. An invalid or missing key gives you a KookeeApiError instead:

TypeScript
import { KookeeApiError } from '@kookee/sdk';

try {
  const health = await kookee.health();
  console.log('Connected to project', health.projectId);
} catch (error) {
  if (error instanceof KookeeApiError) {
    console.error(`Health check failed: ${error.code} (${error.status})`);
  }
  throw error;
}

Use it in a deployment smoke test or a startup check, not on every request — it is a round trip that tells you nothing about your content. Authentication and permission errors covers what to do when it fails.

To confirm the project by its name rather than its id, call kookee.project.get(): it returns { name, defaultLocale, portalUrl, widgetConfigured }, where portalUrl is null while the hosted portal is off. Unlike health(), each call counts as one API request.

  • Reading and rendering comments — the comment shape getComments() returns.

  • Working with the Blog module — the typed wrapper, when you only need one type.

  • Multi-language content and locale fallback — locale, fallback and the translations map.

  • Organizing content with categories and tags — where those slugs come from.

  • SEO and metadata for your content — what export() feeds.

  • Rate limits, plans and error handling — KookeeApiError and what to do with it.

Este artigo foi útil?