@accurix/centrinfo
v0.4.0
Published
Modular Centrinfo customer experience SDK for chat and governed analytics.
Maintainers
Readme
@accurix/centrinfo
One modular SDK for Centrinfo chat and governed customer analytics. Import only the feature entry points used by the host application.
pnpm add @accurix/centrinfoimport { createCentrinfo } from '@accurix/centrinfo';
import { chat } from '@accurix/centrinfo/chat';
import { liveboards } from '@accurix/centrinfo/liveboards';
const centrinfo = createCentrinfo({
publicWidgetToken: 'pub_...',
applicationId: '...',
theme: {
accent: '#2563eb',
background: '#f8fafc',
surface: '#ffffff',
text: '#101827',
border: '#dbe4ee',
radius: '16px',
fontFamily: 'Avenir Next, sans-serif',
},
getIdentityToken: async () => {
const response = await fetch('/api/centrinfo/token', {
credentials: 'include',
});
if (!response.ok) throw new Error('Sign in is required.');
return response.json();
},
features: [chat(), liveboards()],
});
await centrinfo.chat.mountFloating();
centrinfo.liveboards.mount('#customer-dashboard', {
liveboardId: '...',
});
// Or switch between every Liveboard assigned to this SDK application.
centrinfo.liveboards.mountCollection('#customer-dashboards', {
navigation: 'tabs',
});For a full-page conversation:
await centrinfo.chat.mountFullPage('#support', {
persistence: 'session',
sidebar: 'collapsed',
userLabel: 'Alex Kim',
userDetail: '[email protected]',
userAvatarUrl: 'https://customer-app.example/alex.png',
assistantAvatarUrl: 'https://customer-app.example/assistant.png',
attachments: true,
});Full-page chat is a separate AI workspace UI from the floating messenger. Its
conversation rail defaults to collapsed, so it can sit beside the host
application's own sidebar. The returned handle can control it:
const chatApp = await centrinfo.chat.mountFullPage('#support');
chatApp.expandSidebar();
chatApp.collapseSidebar();
chatApp.hideSidebar();Styling and branding
Pass theme to createCentrinfo when chat and Liveboards should inherit the
same customer-portal look. The SDK uses Shadow DOM isolation for embedded
surfaces, so host CSS should not be required for normal styling.
const centrinfo = createCentrinfo({
publicWidgetToken: 'pub_...',
applicationId: '...',
getIdentityToken,
features: [chat(), liveboards()],
theme: {
accent: '#2563eb',
accentStrong: '#1d4ed8',
accentSoft: 'rgba(37, 99, 235, 0.1)',
background: '#f8fafc',
surface: '#ffffff',
surfaceMuted: '#f1f5f9',
text: '#101827',
mutedText: '#52647a',
subtleText: '#7a8da3',
border: '#dbe4ee',
radius: '16px',
fontFamily: 'Avenir Next, sans-serif',
},
});Full-page chat also accepts customer-session presentation fields:
await centrinfo.chat.mountFullPage('#support', {
sidebar: 'collapsed',
header: true,
userLabel: currentUser.name,
userDetail: currentUser.email,
userAvatarUrl: currentUser.avatarUrl,
assistantAvatarUrl: '/brand/assistant-avatar.png',
attachments: true,
});attachments: true allows image, PDF, text, and CSV attachments where the
configured application and backend permit extraction. The assistant avatar can
also come from the SDK application settings in Centrinfo; the explicit
assistantAvatarUrl option is only a host-side fallback.
Liveboard collection navigation shows only the assigned Liveboards by default.
Pass navigationLabel only when the host application wants an extra visible
label above those tabs.
The host backend must create short-lived identity tokens. Private signing keys must never be shipped to the browser.
import { signCentrinfoIdentityToken } from '@accurix/centrinfo/server';
const token = await signCentrinfoIdentityToken({
privateKeyPem: process.env.CENTRINFO_SIGNING_PRIVATE_KEY!,
applicationId: '...',
subject: session.user.id,
accountId: session.user.accountId,
context: {
businessId: session.user.businessId,
},
expiresInSeconds: 600,
});Chat history and logout
Use the same stable externalUserId every time a customer signs in. Centrinfo
uses that verified identity to restore retained floating-chat and full-page-chat
conversations from the backend, including in another browser or device.
Anonymous chat history is browser-local. It is never returned as another user's authenticated history.
Call the unified runtime logout method when the host application signs out:
centrinfo.logout();This unmounts authenticated chat surfaces and clears the active identity from
the SDK. The user's server-side history remains available for their next
verified sign-in. Use a chat handle's shutdown() only when you also need to
erase that surface's local cache, such as on a shared or kiosk device.
History remains subject to the widget token's configured retention period and
message limit. A different externalUserId creates a separate history scope.
