Skip to content

Headless SDK

@as-community/web is the headless integration package for custom frontends.

Use it when you want the backend contract, moderation helpers, and tenant loading without the packaged web-component UI.

Install

bash
npm install @as-community/web

Constructor

ts
import { ASCommunityClient } from '@as-community/web';

const client = new ASCommunityClient({
  baseUrl: 'https://api.example.com',
  tenantId: 'welt',
  fcmToken: 'firebase-token',
  tenantConfigUrl: 'https://app.example.com/tenants/welt',
});

tenantConfigUrl starts a background load and stores the resolved config on client.tenantConfig.

Result Shape

Comment and moderation methods return a result object:

ts
type ServiceResult<T> = {
  data?: T;
  error?: string;
};

Always check error before using data.

Comment Methods

getComments(articleId, params?)

ts
const result = await client.getComments('article-123', {
  sort: 'score',
  limit: 20,
});

Returns { comments, hasMore, nextCursor }.

getReplies(articleId, commentId, params?)

ts
const result = await client.getReplies('article-123', 'comment-456', {
  limit: 10,
});

Returns { replies, hasMore, nextCursor }.

createComment(articleId, params)

ts
await client.createComment('article-123', {
  content: 'Great article',
});

await client.createComment('article-123', {
  content: 'I agree',
  parentId: 'comment-456',
});

editComment(articleId, commentId, params)

ts
await client.editComment('article-123', 'comment-456', {
  content: 'Updated text',
});

deleteComment(articleId, commentId)

ts
await client.deleteComment('article-123', 'comment-456');

castVote(articleId, commentId, voteType) / removeVote(articleId, commentId)

ts
await client.castVote('article-123', 'comment-456', 'up');
await client.removeVote('article-123', 'comment-456');

Moderation Method

listModerationArticles(limit?)

Fetch distinct article IDs that currently have comments:

ts
const result = await client.listModerationArticles(100);

if (!result.error && result.data) {
  console.log(result.data.articleIds);
  console.log(result.data.count);
}

Tenant Config

loadTenantConfig(url)

ts
const config = await client.loadTenantConfig('https://app.example.com/tenants/welt');
console.log(client.tenantConfig === config); // true

tenantConfig

ts
console.log(client.tenantConfig); // TenantConfig | null

Example: Custom Moderation Queue

ts
const client = new ASCommunityClient({
  baseUrl: 'https://api.example.com',
  tenantId: 'welt',
  fcmToken: await getFirebaseToken(),
});

const articles = await client.listModerationArticles(50);

if (articles.error || !articles.data) {
  throw new Error(articles.error ?? 'Could not load moderation articles');
}

for (const articleId of articles.data.articleIds) {
  const comments = await client.getComments(articleId, { sort: 'new', limit: 20 });
  // render the moderation UI with your own components
}

Re-exports

The package also re-exports:

  • CommentService, CommentStore, sortComments, initialCommentState
  • moderation helpers such as isVisible, canEdit, and getModerationTier
  • tenant schemas and shared contract types