@sinequa/atomic

Labels

User-applied tags on documents — public and private, with a rights model that decides what your interface may offer.

A label is a tag a user puts on documents. Two kinds, and the distinction runs through every call:

Who sees itWho may change it
PublicEveryoneOnly users with the right
PrivateThe user who set itThat user

Every operation takes a publicOnly flag, defaulting to true. So a call that forgets it acts on public labels — which is the kind a user may well not be allowed to touch.

Check the rights first

labels.rights() returns what the current user may do. An interface that offers a "manage public labels" control to someone without the right produces a failed request the user cannot understand.

what may this user do?
const rights = await client.api.labels.rights();

// canEditPublicLabels: may add and remove public labels on documents
// canManagePublicLabels: may rename and delete them altogether
if (rights.canEditPublicLabels) showPublicTagging();
if (rights.canManagePublicLabels) showLabelAdministration();

Tagging documents

Suggest, apply, and remove a private label
src/labels.ts
import { createAtomicClient } from "@sinequa/atomic";

const client = createAtomicClient({
  app: "<your-app>",
  backendUrl: "https://<your-sinequa-server>",
});

await client.initializeConfig();
await client.auth.login();

const rights = await client.api.labels.rights();

/** Autocomplete over existing labels, so users converge on the same vocabulary. */
export function suggest(prefix: string, isPublic = false) {
  // The locale matters: labels can be configured per language.
  return client.api.labels.get(prefix, isPublic, navigator.language);
}

/** Private by default — public tagging needs the right. */
export async function tag(ids: string[], label: string, isPublic = false) {
  if (isPublic && !rights.canEditPublicLabels) {
    throw new Error("You cannot edit public labels.");
  }

  // Note the third argument: omitting it means PUBLIC, not private.
  await client.api.labels.add([label], ids, isPublic);
}

export function untag(ids: string[], label: string, isPublic = false) {
  return client.api.labels.remove([label], ids, isPublic);
}

The calls

Prop

Type

Pitfalls

What's next

On this page