JavaScript SDK
@cstar.help/js is the foundation. Anywhere fetch runs (Node, Deno, Bun, browsers), this
works. The React and Svelte SDKs are thin reactive wrappers on top of it.
Latest on npm: 0.21.1
- Bare resources: single-object methods return the unwrapped object:
const t = await cstar.tickets.create(…); t.id(no moret.data.id). List methods still return{ data, pagination, hasMore }. Readcstar.lastMeta.requestIdfor support escalations. - Nine entry points: root (admin) plus
/auth,/chat,/library,/community,/quickhelp,/proactive,/webhook(Web Crypto), and/webhook/node(Node‑only). - Test/Live mode for anonymous clients: pass
publishableKeyonLibraryClient/CommunityClient/QuickHelpClientto scope an environment. - Typed errors everywhere: every public method throws a
CStarErrorsubclass dispatched by HTTP status, includingCStarRateLimitError(withretryAfter) andCStarFeatureDisabledError(withfeature+enableUrl). - Release notes: see what changed in each version, breaking changes first, in the changelog.
Installation
npm install @cstar.help/js If you're using @cstar.help/react or @cstar.help/svelte, you already have this. It's included automatically as a dependency.
Want something running first? The cStar starter is a small custom help desk you clone, give a key and run.
Browse by topic
Drilling into something specific? Jump straight to the page you need. Topics with a dedicated sub-page are linked; the rest scroll to the matching section below.
Foundation
hasMore.Request meta client.lastMeta, request IDs, debugging round-trips.Retry & rate limits Exponential backoff, the rate-limit headers, recovery.Idempotency One key, one request: the same request gets its first response back, a new body a 422.Admin resources
cstar.tickets: list, get, create, update, delete, messages.Customers cstar.customers: CRUD, custom fields, tags.Articles cstar.articles: knowledge-base CRUD, publishing.Categories cstar.categories: group articles, control nav.Webhooks cstar.webhooks: register endpoints, send test events.Members cstar.members: list seats, manage invites.Analytics cstar.analytics: CSAT, response times, agent stats.Anonymous clients
AuthClient: sign-in by emailed link or a per-team password, with sessions.Chat ChatClient: customer chat with HMAC identify.Public library LibraryClient: public knowledge base, no auth.Community CommunityClient: public forum reads + writes.QuickHelp QuickHelpClient: embed contextual help anywhere.Proactive ProactiveClient: trigger campaigns from your app.Realtime + offline
Three Client Types
The SDK provides three clients for different use cases:
- CStarClient: Server-side admin API. Full CRUD for tickets, customers,
articles, webhooks. Requires a secret API key (
sk_live_*) andteamId. - ChatClient: Customer-facing chat widget. Real-time messaging with HMAC
identity verification. Uses
teamSlug. - LibraryClient: Public knowledge base. No auth required. Browse categories,
articles, and search. Uses
teamSlug.
CStarClient (Admin API)
import { CStarClient } from '@cstar.help/js';
const cstar = new CStarClient({
apiKey: 'sk_live_your_key',
teamId: 'your-team-id', // Required. See /whoami endpoint below
// Optional: override base URL (defaults to https://www.cstar.help)
// baseUrl: 'https://custom-domain.com'
}); Finding Your Team ID
Use the /whoami endpoint to discover your teamId from your API key.
curl -H "Authorization: Bearer sk_live_your_key" \
https://www.cstar.help/api/v1/auth/whoami {
"success": true,
"data": {
"teamId": "your-team-uuid",
"teamName": "Acme Corp",
"teamSlug": "acme",
"keyType": "secret",
"environment": "live"
}
} Or use the CLI: cstar status (after cstar login).
TypeScript Types
The SDK is fully typed. Click to expand any type definition.
Tickets
// List tickets with filters
const { data, pagination } = await cstar.tickets.list({
status: 'open',
priority: 'high',
page: 1,
pageSize: 20
});
// Get a single ticket (includes messages)
const ticket = await cstar.tickets.get('tkt_abc123');
// Create a ticket
const newTicket = await cstar.tickets.create({
title: 'Bug report: login page',
priority: 'high',
customerName: 'Jane Smith'
});
// Update a ticket
await cstar.tickets.update('tkt_abc123', {
status: 'resolved'
});
// Metadata: merged on update (existing keys preserved)
await cstar.tickets.create({
title: 'Bug report',
metadata: { source: 'sdk', version: '1.0' }
});
await cstar.tickets.update('tkt_abc123', {
metadata: { priority_override: 'p0' }
// Result: { source: 'sdk', version: '1.0', priority_override: 'p0' }
// Set a key to null to remove it
});
// Delete a ticket: .delete() and .del() are aliases (both work)
await cstar.tickets.delete('tkt_abc123');
// or: await cstar.tickets.del('tkt_abc123'); Customers
// List customers
const { data } = await cstar.customers.list({
status: 'active',
search: 'jane'
});
// Get customer details
const customer = await cstar.customers.get('cus_abc123');
// Create a customer
const newCustomer = await cstar.customers.create({
name: 'Jane Smith',
email: 'jane@example.com',
tags: ['vip', 'enterprise']
});
// Update a customer
await cstar.customers.update('cus_abc123', {
sentiment: 'happy'
}); Articles
// List published articles (the list filter is 'category', a category UUID)
const { data } = await cstar.articles.list({
status: 'published',
category: '3f2b6c1e-8a4d-4f7b-9c2e-1d5a7b9e0f12'
});
// Get an article
const article = await cstar.articles.get('art_abc123');
// Create an article (write side uses categoryId; get one from cstar.categories.list())
const draft = await cstar.articles.create({
title: 'How to reset your password',
content: '# Password Reset\n\nFollow these steps...',
categoryId: '550e8400-e29b-41d4-a716-446655440040',
status: 'draft'
});
// Publish an article
await cstar.articles.update('art_abc123', {
status: 'published',
isPublic: true
}); Note on slugs: When creating an article, the slug you provide is
used as a prefix. cStar appends a unique suffix (e.g., reset-password-mn46zcig) to
prevent collisions. The final slug is returned in the response.
Categories
// List categories
const { data } = await cstar.categories.list();
// List only public categories
const { data: publicCats } = await cstar.categories.list({ isPublic: true });
// Create a category
const category = await cstar.categories.create({
name: 'Getting Started',
description: 'Onboarding and setup guides',
isPublic: true,
sortOrder: 0
});
// slug is auto-generated from name: "getting-started"
// Update a category
await cstar.categories.update(category.id, {
description: 'Updated description',
sortOrder: 1
});
// Delete a category
await cstar.categories.del(category.id); Auto-Pagination
Every list method has a listAutoPaginating() variant that returns an async iterator.
It automatically fetches the next page when you exhaust the current one. No manual page tracking needed.
// Iterate through ALL tickets automatically
for await (const ticket of cstar.tickets.listAutoPaginating({ pageSize: 50 })) {
console.log(ticket.title);
// Break early if you only need a subset
if (someCondition) break;
}
// Works on every resource
for await (const customer of cstar.customers.listAutoPaginating({ status: 'active' })) {
console.log(customer.name);
} Messages
// List messages for a ticket
const messages = await cstar.tickets.messages.list('tkt_abc123');
// Add a message
await cstar.tickets.messages.create('tkt_abc123', {
content: 'Thanks for reaching out! Let me look into this.',
sender: 'agent',
senderName: 'Bob (Support)'
}); Webhooks
// List webhooks
const webhooks = await cstar.webhooks.list();
// Create a webhook
const webhook = await cstar.webhooks.create({
name: 'Slack Integration',
url: 'https://your-app.com/webhook',
events: ['ticket.created', 'ticket.closed']
});
// Save the secret! Only shown once.
console.log('Webhook secret:', webhook.secret);
// Trigger a test event
await cstar.webhooks.test(webhook.id, { event: 'ticket.created' }); Webhook Verification
// Node.js. On edge runtimes, Deno or Bun use
// await constructEventAsync(...) from '@cstar.help/js/webhook'.
import { constructEvent } from '@cstar.help/js/webhook/node';
// In your webhook handler (Express, Next.js, etc.)
const event = constructEvent(
requestBody, // Raw request body string
signature, // X-Signature header (alias: cstar-signature)
webhookSecret // Your webhook secret
);
console.log(event.type); // 'ticket.created'
console.log(event.data); // { ticket, customer? } for ticket events Customer Authentication
Sign end-customers in at your team with an emailed link, plus an optional password for later visits. Every token is cStar's own and works at your team only. Use this for custom widget integrations or headless support experiences. The customer auth guide has the rest.
import { AuthClient } from '@cstar.help/js/auth';
// storage is optional: it keeps the session between page loads
const auth = new AuthClient({ teamSlug: 'acme', storage: localStorage });
// Sign up: no password. cStar emails a sign-in link (same reply for new and known emails)
const result = await auth.signup({
email: 'jane@example.com',
name: 'Jane Doe',
});
console.log(result.message); // 'If this address can sign in here, a link is on its way.'
// On the page the sign-in link returns to
const session = await auth.completeSignIn();
// Optional: choose a password (at least 8 characters) for later visits
await auth.setPassword('securepass123');
// Log in a customer who has set a password
await auth.login({
email: 'jane@example.com',
password: 'securepass123',
});
// Check session state
console.log(auth.isAuthenticated); // true
console.log(auth.getCustomer()); // { id, email, name, ... }
console.log(await auth.getAccessToken()); // a Bearer, refreshed when it is due
// Log out: ends the session here and on the server
await auth.logout(); Public Knowledge Base
Query your public knowledge base. No authentication required. Use this to build custom help centers or embed articles in your app.
import { LibraryClient } from '@cstar.help/js/library';
// Seeded with a test key (cstar seed)? Add publishableKey: 'pk_test_...' to read test articles.
const library = new LibraryClient({ teamSlug: 'acme' });
// List categories
const categories = await library.categories();
// List articles (with optional category filter)
const articles = await library.articles({ categorySlug: 'billing', limit: 10 });
// Get a single article by slug
const article = await library.article('reset-password');
// Full-text search
const results = await library.search('reset password', { limit: 5 });
// Get most popular articles by view count
const popular = await library.popularArticles(5);
// Get aggregate stats
const stats = await library.stats();
// { totalArticles: 42, totalCategories: 6, totalViews: 1200 }
// Record a view for analytics
await library.recordView('reset-password');
// Submit article feedback ("Was this helpful?")
await library.submitFeedback('reset-password', {
isHelpful: true,
feedbackText: 'Very clear instructions!',
}); Chat Client
Customer-facing chat for tickets and messages. Real-time delivery is on by default with an automatic polling fallback. No extra configuration required. Requires HMAC identity verification for security.
import { ChatClient } from '@cstar.help/js/chat';
const chat = new ChatClient({
teamSlug: 'acme',
// realtime: true, // default. Set false to disable and poll
// pollingInterval: 3000 // fallback interval in ms (default)
});
// Identify the customer (HMAC signature from your server)
const result = await chat.identify({
externalId: 'user_123',
email: 'jane@example.com',
name: 'Jane Doe',
timestamp: Math.floor(Date.now() / 1000)
}, 'hmac_signature');
// List tickets
const { data: tickets } = await chat.tickets.list();
// Create a ticket
const ticket = await chat.tickets.create({
title: 'Need help',
message: 'Hi, I have a question.'
});
// Send a message
const msg = await chat.messages.send(ticket.id, 'Thanks!');
// Listen for new messages on a ticket
const unsubMessages = chat.onMessage(ticket.id, (message) => {
console.log('New message:', message.content);
});
// Listen for typing indicators on a ticket
const unsubTyping = chat.onTyping(ticket.id, (payload) => {
// An AI agent says what it's doing: "Searching our help library"
console.log(payload.agent_name, payload.activity ?? 'is typing');
});
// Unsubscribe when done
// unsubMessages();
// unsubTyping();
// Clean up
chat.disconnect(); Computing the HMAC Signature
The signature must be computed server-side (never expose your HMAC secret to
the browser). Sign a sorted JSON payload of the customer fields with HMAC-SHA256, and pass the
hex output to identify().
// Server-side: compute the HMAC signature
import crypto from 'crypto';
function computeSignature(customer, hmacSecret) {
// 1. Build payload with only these fields (sorted alphabetically)
const signed = {
email: customer.email,
externalId: customer.externalId,
name: customer.name, // include if provided
timestamp: customer.timestamp // Unix seconds (required)
};
// 2. Remove undefined fields, sort keys, compact JSON
const filtered = Object.fromEntries(
Object.entries(signed)
.filter(([, v]) => v !== undefined)
.sort(([a], [b]) => a.localeCompare(b))
);
const payload = JSON.stringify(filtered);
// Example: {"email":"jane@example.com","externalId":"user_123","name":"Jane Doe","timestamp":1700000000}
// 3. HMAC-SHA256 → hex (no prefix, just the hex string)
return crypto.createHmac('sha256', hmacSecret).update(payload).digest('hex');
}
// Usage in your API route:
const signature = computeSignature({
externalId: 'user_123',
email: 'jane@example.com',
name: 'Jane Doe',
timestamp: Math.floor(Date.now() / 1000)
}, process.env.CSTAR_HMAC_SECRET);
// Send this signature to the browser for chat.identify() Timestamp replay protection: Signatures expire after 5 minutes in production and 1 hour in test mode. A timestamp more than 60 seconds in the future is refused. The HMAC secret is found in your dashboard under Settings → Widget → Identity Verification.
Idempotency
Pass an idempotencyKey as a request option to safely retry create and update calls. Within 24 hours, the same request with the same key gets the first
successful response back instead of a duplicate. The same key with a different body is refused (422 idempotency_key_reused). While the first request is still running, the key answers 409 idempotency_key_in_use with Retry-After: wait that long and send it again. See Idempotency for the full rules.
A key does not make webhooks.create, webhooks.listen or export.create safe to retry: the API ignores it there, and the SDK still retries a
network error or 5xx. Leave the key off those calls (without one the SDK doesn't retry them), or
use a client made with maxRetries: 0. Check webhooks.list() before you
retry webhooks.create. A repeated export.create only reads your data
again (nothing is stored). A repeated webhooks.listen is a second CLI listener:
remove it with webhooks.unlisten(id), or it is swept after 5 minutes without a
heartbeat.
// Safe to retry: same key and same body return the same ticket
const ticket = await cstar.tickets.create(
{ title: 'Order issue' },
{ idempotencyKey: 'order-issue-abc123' }
);
// Network error? Retry with the same key:
const retry = await cstar.tickets.create(
{ title: 'Order issue' },
{ idempotencyKey: 'order-issue-abc123' }
);
// retry.id === ticket.id Error Handling
All API errors throw typed error classes. Rate limit errors include a retryAfter value
in seconds.
import { CStarError, CStarRateLimitError } from '@cstar.help/js';
try {
await cstar.tickets.create({ /* missing title */ });
} catch (err) {
if (err instanceof CStarRateLimitError) {
// 429: back off and retry
console.log(err.retryAfter); // seconds to wait (e.g. 3600)
await sleep(err.retryAfter * 1000);
} else if (err instanceof CStarError) {
console.log(err.code); // 'parameter_missing'
console.log(err.message); // 'title is required'
console.log(err.statusCode); // 400
console.log(err.param); // 'title'
}
} Public Community
Browse and search your public community forum. No authentication required. Import CommunityClient from the @cstar.help/js/community entry point.
Setup
import { CommunityClient } from '@cstar.help/js/community';
const community = new CommunityClient({ teamSlug: 'acme' }); Topics
// List all discussion topics
const topics = await community.topics(); Posts
// List posts with filters
const { posts, count } = await community.posts({
topicSlug: 'feature-requests',
sort: 'votes', // 'recent' | 'votes' | 'comments'
limit: 20,
offset: 0
});
// Get a single post by slug (includes comments)
const { post, comments } = await community.post('dark-mode-support'); Search
// Full-text search across post titles and bodies
const results = await community.search('billing');
// results.data: matching posts
// results.count: total matches Admin Operations (API Key Required)
For server-side management (create, update, delete, vote, follow), use CStarClient.community with your secret API key.
import { CStarClient } from '@cstar.help/js';
const cstar = new CStarClient({ apiKey: 'sk_live_...', teamId: 'tm_...' });
// Create a post (with optional custom fields scoped to the topic)
await cstar.community.posts.create({
title: 'Tutorial Video',
topicId: 'topic_abc',
body: 'Check out this walkthrough',
customFields: { 'video_url_field_id': 'https://youtube.com/watch?v=abc' }
});
// Vote, follow, comment
await cstar.community.posts.vote('post_id');
await cstar.community.posts.follow('post_id');
await cstar.community.posts.createComment('post_id', {
body: 'Great idea!',
isOfficial: true
});