@accurix/centrinfo-widget 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
1
  # @accurix/centrinfo-widget
2
2
 
3
3
  The embeddable **Centrinfo public chat widget** — a style-isolated chat client
4
- that drops onto any website. The current standalone CDN bundle is about 35 KB
5
- gzipped and can dock bottom-right or bottom-left.
4
+ that drops onto any website and can dock bottom-right or bottom-left.
6
5
 
7
6
  Built with Preact inside a **Shadow DOM** web component, so it can't break the
8
7
  host site's CSS and the host's CSS can't break it. It talks to the Centrinfo
@@ -18,7 +17,7 @@ Zero-JS, via `data-*` on the script:
18
17
 
19
18
  ```html
20
19
  <script
21
- src="https://cdn.accurix.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js"
20
+ src="https://cdn.accurixtech.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js"
22
21
  data-token="pub_8f3k…"
23
22
  defer
24
23
  ></script>
@@ -28,7 +27,7 @@ Or call `init` yourself:
28
27
 
29
28
  ```html
30
29
  <script
31
- src="https://cdn.accurix.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js"
30
+ src="https://cdn.accurixtech.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js"
32
31
  defer
33
32
  ></script>
34
33
  <script>
@@ -53,40 +52,144 @@ const widget = init({ token: 'pub_8f3k…' });
53
52
  | Option | Type | Default | Notes |
54
53
  | ------------------------------------------------------------- | ----------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------- |
55
54
  | `token` **(required)** | string | — | The org's `pub_*` token. It _is_ the org identity. |
55
+ | `analyticsContextToken` | string | — | Server-signed governed analytics context. It must expire within 15 minutes and be scoped to this public widget token. |
56
+ | `identityToken` | string | — | Short-lived customer identity JWT. Authenticated history is scoped to its verified external user ID. |
57
+ | `getIdentityToken` | function | — | Returns a fresh customer identity JWT before authenticated requests. Prefer this for expiring tokens. |
56
58
  | `apiBaseUrl` | string | prod API | Override for staging / self-host. |
57
59
  | `accentColor` | string | brand green | Any CSS color — drives the launcher, header, user bubbles & send button (a darker shade for the gradient is derived automatically). |
60
+ | `themeTokens` | object | — | Enterprise theme tokens for chat surfaces: accent, background, surface, text, muted text, border, shadow, radius, and font family. |
58
61
  | `launcherIcon` | string | chat glyph | Image URL (e.g. the org's logo) shown in the launcher bubble. |
59
62
  | `theme` | `'light' \| 'dark' \| 'auto'` | `'auto'` | `auto` follows the host's `prefers-color-scheme`; `light`/`dark` force it. |
60
63
  | `openByDefault` | boolean | `false` | Open the panel on load. |
61
64
  | `zIndex` | number | very high | Stacking against the host page. |
62
65
  | `demo` | boolean | `false` | Use the built-in mock transport — **no backend/token needed**. |
66
+ | `configRefreshSeconds` | number | `30` | While the panel is open, refresh token branding/actions from `bootstrap`; set `0` to disable. |
63
67
  | `onOpen` / `onClose` / `onMessage` / `onAction` / `onHandoff` | function | — | Event hooks. |
64
68
 
69
+ ```ts
70
+ init({
71
+ token: 'pub_8f3k...',
72
+ themeTokens: {
73
+ accent: '#176b45',
74
+ accentStrong: '#0f5134',
75
+ background: '#f8fafc',
76
+ surface: '#ffffff',
77
+ surfaceMuted: '#f1f5f9',
78
+ text: '#0f172a',
79
+ mutedText: '#64748b',
80
+ border: '#cbd5e1',
81
+ radius: '10px',
82
+ fontFamily: 'Inter, system-ui, sans-serif',
83
+ },
84
+ });
85
+ ```
86
+
65
87
  Persona (agent name/avatar/greeting), the voice toggle, and which lead-gen
66
88
  actions appear all come from the token via `GET /public-chat/bootstrap` — not
67
- from the snippet.
89
+ from the snippet. Open widgets refresh that bootstrap data every 30 seconds, so
90
+ saved dashboard settings reach visitors without a page reload.
91
+
92
+ ## Authenticated history
93
+
94
+ For a logged-in customer, mint a short-lived identity token on the host
95
+ backend and supply `getIdentityToken`. Keep the signing private key on the
96
+ server, and use a stable external user ID for that customer.
97
+
98
+ ```ts
99
+ const widget = init({
100
+ token: 'pub_8f3k...',
101
+ getIdentityToken: async () => {
102
+ const response = await fetch('/api/centrinfo/token', {
103
+ credentials: 'include',
104
+ });
105
+ if (!response.ok) throw new Error('Sign in is required.');
106
+ return response.json();
107
+ },
108
+ });
109
+ ```
110
+
111
+ Authenticated conversations are restored from Centrinfo's backend in a new
112
+ browser or device after the identity token is verified. Anonymous history is
113
+ stored only according to the widget's `persistence` option and cannot be
114
+ loaded through authenticated history.
115
+
116
+ Call `widget.shutdown()` on host-app logout when the page may be shared. It
117
+ removes the local transcript and resets the mounted widget to an anonymous
118
+ session. Retained server history is not deleted and returns only when the same
119
+ verified customer signs in again.
120
+
121
+ When business data chat is enabled for a widget token, responses follow a
122
+ visitor-safe presentation contract:
123
+
124
+ - a normal knowledge, RAG, or web-search answer remains text;
125
+ - a single live value may add a KPI and a comparison or timeline may add an
126
+ expandable chart;
127
+ - charts with more than two points include Zoom out, Reset, and Zoom in
128
+ controls with an exact visible-range announcement; the controls do not take
129
+ over browser zoom or page scrolling;
130
+ - result tables and their row values are never rendered in the public widget;
131
+ the written answer remains available instead;
132
+ - charts include a visible text summary, contained tap/hover details, and an
133
+ accessible expanded view that restores the conversation when closed.
134
+
135
+ For customer-specific analytics, create the signed context on the host
136
+ application's server and pass only the resulting short-lived token as
137
+ `analyticsContextToken`. Values such as `userId`, `businessId`, or `tenantId`
138
+ must be checked by the published data model before they are applied.
139
+
140
+ The signed token payload must contain issued-at and expiry times, an expiry no
141
+ more than 15 minutes after issue, the widget-specific audience, and the
142
+ governed context:
143
+
144
+ ```json
145
+ {
146
+ "iat": 1784304000,
147
+ "exp": 1784304900,
148
+ "aud": "centrinfo-public-chat:<widget-token-id>",
149
+ "context": {
150
+ "userId": "customer-user-id",
151
+ "businessId": "customer-business-id"
152
+ }
153
+ }
154
+ ```
155
+
156
+ Replace `<widget-token-id>` with the backend-issued ID associated with the
157
+ matching public widget token. Sign this payload only on the host application's
158
+ server; never expose the signing secret or mint analytics context tokens in
159
+ browser code.
68
160
 
69
161
  `data-*` attributes for the script install: `data-token`, `data-api-base`,
70
- `data-accent`, `data-theme`, `data-open`, `data-demo`.
162
+ `data-accent`, `data-theme`, `data-open`, `data-demo`,
163
+ `data-config-refresh`.
71
164
 
72
165
  ## Environment
73
166
 
74
167
  The default API origin is baked from `VITE_API_BASE_URL` (see `.env.example`).
75
- Copy `.env.example` → `.env` (gitignored) to override locally; unset falls back
76
- to production (`https://api.accurixtech.com`). Local default is the local API
77
- (`http://api.accurixtech.com/`). A per-`init` `apiBaseUrl` always wins at runtime.
78
- Restart the dev server after editing `.env`.
168
+ Copy `.env.example` → `.env` (gitignored) to override locally; when it is unset,
169
+ the package uses the managed production service. A per-`init` `apiBaseUrl`
170
+ overrides it for development, staging, dedicated-cloud, private-cloud, or
171
+ on-premises environments. Restart the dev server after editing `.env`.
79
172
 
80
173
  ## Develop
81
174
 
82
175
  ```bash
83
- pnpm --filter @accurix/centrinfo-widget dev # playground host site @ :3005 (demo mode)
176
+ pnpm --filter @accurix/centrinfo-widget dev # playground host site @ :3005
84
177
  pnpm --filter @accurix/centrinfo-widget build # → dist/index.{mjs,cjs,d.ts} + dist/cdn/*
85
178
  pnpm --filter @accurix/centrinfo-widget check-types
86
179
  pnpm --filter @accurix/centrinfo-widget test-unit
87
180
  pnpm --filter @accurix/centrinfo-widget verify:release
88
181
  ```
89
182
 
183
+ ### Test analytics without a backend
184
+
185
+ Open `http://localhost:3005/?demo`, open the widget, and use any of these starter prompts:
186
+
187
+ - `Show a demo chart` — renders an expandable three-line order-status chart.
188
+ - `Show a demo KPI` — renders an active-accounts KPI.
189
+ - `Test the hidden table response` — confirms that the explanation appears but public table rows do not enter the DOM.
190
+
191
+ Remove `?demo` to test the real public-chat API and the organization’s published analytics configuration.
192
+
90
193
  ## Release Artifacts
91
194
 
92
195
  `build:npm` uses tsdown to emit the npm package entrypoints:
@@ -103,7 +206,7 @@ pnpm --filter @accurix/centrinfo-widget verify:release
103
206
  Canonical v1 CDN URL:
104
207
 
105
208
  ```text
106
- https://cdn.accurix.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js
209
+ https://cdn.accurixtech.com/centrinfo/js/sdk-centrinfo-widget-v1.0.0/centrinfo-widget.js
107
210
  ```
108
211
 
109
212
  ## Status