@accurix/centrinfo-widget 1.0.0 → 1.0.1

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
@@ -53,6 +52,7 @@ 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
56
  | `apiBaseUrl` | string | prod API | Override for staging / self-host. |
57
57
  | `accentColor` | string | brand green | Any CSS color — drives the launcher, header, user bubbles & send button (a darker shade for the gradient is derived automatically). |
58
58
  | `launcherIcon` | string | chat glyph | Image URL (e.g. the org's logo) shown in the launcher bubble. |
@@ -60,33 +60,86 @@ const widget = init({ token: 'pub_8f3k…' });
60
60
  | `openByDefault` | boolean | `false` | Open the panel on load. |
61
61
  | `zIndex` | number | very high | Stacking against the host page. |
62
62
  | `demo` | boolean | `false` | Use the built-in mock transport — **no backend/token needed**. |
63
+ | `configRefreshSeconds` | number | `30` | While the panel is open, refresh token branding/actions from `bootstrap`; set `0` to disable. |
63
64
  | `onOpen` / `onClose` / `onMessage` / `onAction` / `onHandoff` | function | — | Event hooks. |
64
65
 
65
66
  Persona (agent name/avatar/greeting), the voice toggle, and which lead-gen
66
67
  actions appear all come from the token via `GET /public-chat/bootstrap` — not
67
- from the snippet.
68
+ from the snippet. Open widgets refresh that bootstrap data every 30 seconds, so
69
+ saved dashboard settings reach visitors without a page reload.
70
+
71
+ When business data chat is enabled for a widget token, responses follow a
72
+ visitor-safe presentation contract:
73
+
74
+ - a normal knowledge, RAG, or web-search answer remains text;
75
+ - a single live value may add a KPI and a comparison or timeline may add an
76
+ expandable chart;
77
+ - charts with more than two points include Zoom out, Reset, and Zoom in
78
+ controls with an exact visible-range announcement; the controls do not take
79
+ over browser zoom or page scrolling;
80
+ - result tables and their row values are never rendered in the public widget;
81
+ the written answer remains available instead;
82
+ - charts include a visible text summary, contained tap/hover details, and an
83
+ accessible expanded view that restores the conversation when closed.
84
+
85
+ For customer-specific analytics, create the signed context on the host
86
+ application's server and pass only the resulting short-lived token as
87
+ `analyticsContextToken`. Values such as `userId`, `businessId`, or `tenantId`
88
+ must be checked by the published data model before they are applied.
89
+
90
+ The signed token payload must contain issued-at and expiry times, an expiry no
91
+ more than 15 minutes after issue, the widget-specific audience, and the
92
+ governed context:
93
+
94
+ ```json
95
+ {
96
+ "iat": 1784304000,
97
+ "exp": 1784304900,
98
+ "aud": "centrinfo-public-chat:<widget-token-id>",
99
+ "context": {
100
+ "userId": "customer-user-id",
101
+ "businessId": "customer-business-id"
102
+ }
103
+ }
104
+ ```
105
+
106
+ Replace `<widget-token-id>` with the backend-issued ID associated with the
107
+ matching public widget token. Sign this payload only on the host application's
108
+ server; never expose the signing secret or mint analytics context tokens in
109
+ browser code.
68
110
 
69
111
  `data-*` attributes for the script install: `data-token`, `data-api-base`,
70
- `data-accent`, `data-theme`, `data-open`, `data-demo`.
112
+ `data-accent`, `data-theme`, `data-open`, `data-demo`,
113
+ `data-config-refresh`.
71
114
 
72
115
  ## Environment
73
116
 
74
117
  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`.
118
+ Copy `.env.example` → `.env` (gitignored) to override locally; when it is unset,
119
+ the package uses the managed production service. A per-`init` `apiBaseUrl`
120
+ overrides it for development, staging, dedicated-cloud, private-cloud, or
121
+ on-premises environments. Restart the dev server after editing `.env`.
79
122
 
80
123
  ## Develop
81
124
 
82
125
  ```bash
83
- pnpm --filter @accurix/centrinfo-widget dev # playground host site @ :3005 (demo mode)
126
+ pnpm --filter @accurix/centrinfo-widget dev # playground host site @ :3005
84
127
  pnpm --filter @accurix/centrinfo-widget build # → dist/index.{mjs,cjs,d.ts} + dist/cdn/*
85
128
  pnpm --filter @accurix/centrinfo-widget check-types
86
129
  pnpm --filter @accurix/centrinfo-widget test-unit
87
130
  pnpm --filter @accurix/centrinfo-widget verify:release
88
131
  ```
89
132
 
133
+ ### Test analytics without a backend
134
+
135
+ Open `http://localhost:3005/?demo`, open the widget, and use any of these starter prompts:
136
+
137
+ - `Show a demo chart` — renders an expandable three-line order-status chart.
138
+ - `Show a demo KPI` — renders an active-accounts KPI.
139
+ - `Test the hidden table response` — confirms that the explanation appears but public table rows do not enter the DOM.
140
+
141
+ Remove `?demo` to test the real public-chat API and the organization’s published analytics configuration.
142
+
90
143
  ## Release Artifacts
91
144
 
92
145
  `build:npm` uses tsdown to emit the npm package entrypoints: