@wexio/messenger-widget-react 1.0.0 → 1.0.2

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,15 +1,38 @@
1
- # @wexio/messenger-widget-react
1
+ # Welcome to @wexio/messenger-widget-react 👋
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@wexio/messenger-widget-react.svg)](https://www.npmjs.com/package/@wexio/messenger-widget-react)
4
- [![license](https://img.shields.io/npm/l/@wexio/messenger-widget-react.svg)](./LICENSE)
3
+ [![Version](https://img.shields.io/npm/v/@wexio/messenger-widget-react.svg)](https://www.npmjs.com/package/@wexio/messenger-widget-react)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](./LICENSE)
5
+ [![Documentation](https://img.shields.io/badge/docs-wexio.io-blue.svg)](https://learn.wexio.io)
5
6
 
6
- Native React component for the [Wexio](https://wexio.io) web messenger. Renders inside a Shadow DOM portal so widget styles never collide with the host React app. Same widget runtime as the script-injected iframe and the `<wexio-widget>` web component your visitors see the same widget regardless of which delivery flavour you embed.
7
+ Native React component for the [Wexio](https://wexio.io) web messenger. Renders inside a Shadow DOM portal for full style isolation same `WidgetShell` runtime as the script-injected iframe and the `<wexio-widget>` web component. Same chat, same visitor identity, same backend; the only difference is **where the React tree mounts.**
7
8
 
8
- ## Install
9
+ 🏠 [Website](https://wexio.io)
10
+ 📚 [Developer Docs](https://learn.wexio.io)
11
+
12
+ ## 📂 Description
13
+
14
+ - [Installation](#installation)
15
+ - [Quick start](#quick-start)
16
+ - [Identifying users](#identifying-users)
17
+ - [Props](#props)
18
+ - [Methods](#methods)
19
+ - [Types](#types)
20
+ - [SSR](#ssr)
21
+ - [Browser support](#browser-support)
22
+ - [Troubleshooting](#troubleshooting)
23
+ - [Use with other frameworks](#use-with-other-frameworks)
24
+ - [Author](#author)
25
+ - [License](#-license)
26
+
27
+ ## Installation
9
28
 
10
29
  ```bash
11
30
  yarn add @wexio/messenger-widget-react
12
- # or
31
+ ```
32
+
33
+ or
34
+
35
+ ```bash
13
36
  npm install @wexio/messenger-widget-react
14
37
  ```
15
38
 
@@ -17,6 +40,8 @@ npm install @wexio/messenger-widget-react
17
40
 
18
41
  ## Quick start
19
42
 
43
+ Import the package on every page that should display the messenger (or on a common component used by them) and render the component. This must be done on the client side.
44
+
20
45
  ```tsx
21
46
  import { WexioWidget } from "@wexio/messenger-widget-react";
22
47
 
@@ -30,24 +55,24 @@ export default function App() {
30
55
  }
31
56
  ```
32
57
 
33
- That's it — the widget mounts a floating launcher in the bottom-right corner of the viewport and handles the rest (theme, locale, panel open/close, identity handshake, real-time chat).
58
+ That's it — the widget mounts a floating launcher, handles its own theme/locale/state, and the operator dashboard sees the visitor immediately. The component manages its own lifecycle internally, so re-renders due to host DOM changes won't trigger a re-boot.
34
59
 
35
60
  ## Identifying users
36
61
 
37
- Pass a verified `user` to log a known visitor in (the Wexio equivalent of Intercom's `boot({ user_id, ... })`). Provide ONE proof — a Google FedCM `id_token`, a host-signed `jwt`, or a legacy `userId` + `userHash` HMAC pair:
62
+ Pass a verified `user` to log a known visitor in (the Wexio equivalent of Intercom's `boot({ user_id, ... })`). Provide ONE proof — a Google FedCM `id_token`, a host-signed `jwt`, or the legacy `userId` + `userHash` HMAC pair:
38
63
 
39
64
  ```tsx
40
65
  <WexioWidget
41
66
  publicKey="pk_live_..."
42
67
  user={{
43
- jwt: serverSignedJwt,
68
+ jwt: serverSignedJwt, // host-signed identity token (recommended)
44
69
  name: "Ada Lovelace",
45
70
  email: "ada@example.com",
46
71
  }}
47
72
  />
48
73
  ```
49
74
 
50
- For an unverified pre-fill (skip the prechat form when the visitor's email is already known but you can't sign it), use `prefill` instead:
75
+ For an **unverified pre-fill** (skip the prechat form when the visitor's email is already known but you can't sign it), use `prefill`:
51
76
 
52
77
  ```tsx
53
78
  <WexioWidget publicKey="pk_live_..." prefill={{ email: "ada@example.com" }} />
@@ -61,40 +86,150 @@ For an unverified pre-fill (skip the prechat form when the visitor's email is al
61
86
  | ------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
62
87
  | `publicKey` | `string` | Wexio integration public key (`pk_live_...`). Omit to render in demo mode (bundled mock content for landing pages or Storybook). |
63
88
  | `locale` | `"en" \| "uk"` | UI locale. Defaults to the visitor's browser language. Extend by contributing a new bundle to the source repo. |
64
- | `mode` | `"production"` | Always `"production"` on the public package. (Preview + demo modes are dashboard-only.) |
65
89
  | `user` | [`VisitorIdentity`](#visitoridentity) | Verified identity. See [Identifying users](#identifying-users). |
66
90
  | `prefill` | [`VisitorPrefill`](#visitorprefill) | Unverified pre-fill for the prechat form. |
67
91
  | `config` | [`InjectableWidgetConfig`](#injectablewidgetconfig) | Pre-resolved widget config. Set this if you already have the config server-rendered or fetched app-wide — skips the bootstrap fetch. |
68
- | `lightboxViewport` | `boolean` | Render the media lightbox (image / video gallery) as a viewport-fixed overlay. Set `true` when the widget's host box is very small. |
69
- | `onResize` | `(size: { width: number; height: number }) => void` | Fired whenever the widget's intended dimensions change (open ↔ closed ↔ expanded). |
92
+ | `lightboxViewport` | `boolean` (default `true`) | Render the media lightbox (image / video gallery) as a viewport-fixed overlay. Pass `false` to contain the gallery inside the widget's host box. |
93
+ | `onResize` | `(size: { width: number; height: number }) => void` | Fired whenever the widget's intended dimensions change (open ↔ closed ↔ expanded). Use for host-side layout sync. |
70
94
  | `onClose` | `() => void` | Fired when the visitor taps the close chip. |
71
95
  | `className` | `string` | Pass-through class on the outer host `<div>`. Style this with normal layout CSS. |
72
96
  | `style` | `React.CSSProperties` | Pass-through inline styles for the outer host `<div>`. |
73
97
 
74
- ### Imperative API
98
+ ## Methods
99
+
100
+ The visitor- and operator-facing imperative methods (`show`, `hide`, `update`, `shutdown`, `showSpace`, `showMessages`, `whoami`, `onUnreadCountChange`, etc.) live on `window.WexioWidget` once the component has mounted, mirroring the script loader's surface. A typed React hook (`useWexioWidget()`) ships in a future minor — until then, reach for the global from `useEffect`.
101
+
102
+ ### show / hide / toggle
103
+
104
+ Open or close the messenger panel.
105
+
106
+ ```ts
107
+ window.WexioWidget?.show();
108
+ window.WexioWidget?.hide();
109
+ window.WexioWidget?.toggle();
110
+ ```
111
+
112
+ ### update
113
+
114
+ Patch live config (swap identity, switch theme, change locale).
115
+
116
+ ```ts
117
+ window.WexioWidget?.update({ locale: "uk" });
118
+ ```
119
+
120
+ ### shutdown / boot
121
+
122
+ Wipe session (token, sticky visitor id, prechat flags); `boot` re-initialises. Use on logout / shared devices.
123
+
124
+ ```ts
125
+ window.WexioWidget?.shutdown();
126
+ window.WexioWidget?.boot({ publicKey: "pk_live_..." });
127
+ ```
128
+
129
+ ### showSpace
130
+
131
+ Open the messenger and route to a specific tab.
132
+
133
+ ```ts
134
+ window.WexioWidget?.showSpace("home");
135
+ window.WexioWidget?.showSpace("messages");
136
+ window.WexioWidget?.showSpace("help");
137
+ window.WexioWidget?.showSpace("news");
138
+ window.WexioWidget?.showSpace("profile");
139
+ ```
140
+
141
+ ### showMessages
142
+
143
+ Alias for `showSpace("messages")`.
144
+
145
+ ```ts
146
+ window.WexioWidget?.showMessages();
147
+ ```
148
+
149
+ ### showNewMessage
150
+
151
+ Open ready-to-compose. Optional prefill for the composer.
152
+
153
+ ```ts
154
+ window.WexioWidget?.showNewMessage();
155
+ window.WexioWidget?.showNewMessage("Hi, I have a question about...");
156
+ ```
157
+
158
+ ### showArticle / showNews
159
+
160
+ Deep-link into a help article or news post.
161
+
162
+ ```ts
163
+ window.WexioWidget?.showArticle(articleId);
164
+ window.WexioWidget?.showNews(newsItemId);
165
+ ```
166
+
167
+ ### onShow / onHide
168
+
169
+ Fire a callback when the messenger opens/closes.
170
+
171
+ ```ts
172
+ window.WexioWidget?.onShow(() => {
173
+ console.log("messenger opened");
174
+ });
175
+ window.WexioWidget?.onHide(() => {
176
+ console.log("messenger closed");
177
+ });
178
+ ```
75
179
 
76
- The visitor- and operator-facing imperative methods (`show`, `hide`, `update`, `shutdown`, `showSpace`, `showMessages`, `whoami`, `onUnreadCountChange`, etc.) live on `window.WexioWidget` once the component has mounted, mirroring the script loader's surface. A typed React hook (`useWexioWidget()`) is in progress and ships in a future minor — until then, reach for the global from `useEffect`:
180
+ ### onUnreadCountChange
181
+
182
+ Fires immediately with the current count, then on every change. Common use: badge the host tab title.
77
183
 
78
184
  ```tsx
79
185
  useEffect(() => {
80
- window.WexioWidget?.onUnreadCountChange?.((count) => {
186
+ return window.WexioWidget?.onUnreadCountChange?.((count) => {
81
187
  document.title = count > 0 ? `(${count}) Inbox` : "Inbox";
82
188
  });
83
189
  }, []);
84
190
  ```
85
191
 
86
- See the [full method reference](https://github.com/wexiohub/messenger-widget-react#api) on GitHub.
192
+ ### hideNotifications
193
+
194
+ Suppress launcher peek bubbles on new operator messages.
195
+
196
+ ```ts
197
+ window.WexioWidget?.hideNotifications(true); // suppress
198
+ window.WexioWidget?.hideNotifications(false); // restore
199
+ ```
200
+
201
+ ### whoami / getVisitorId
202
+
203
+ Read the current session.
204
+
205
+ ```ts
206
+ const me = window.WexioWidget?.whoami();
207
+ // → { visitorId, peopleId, displayName, verified } | null
208
+ const visitorId = window.WexioWidget?.getVisitorId();
209
+ ```
210
+
211
+ ### setLocale
212
+
213
+ Programmatic language switch.
214
+
215
+ ```ts
216
+ window.WexioWidget?.setLocale("uk");
217
+ ```
218
+
219
+ ### Future / reserved
220
+
221
+ The following names are reserved on the public surface for upcoming features and are no-ops today (with a `console.warn` in dev builds): `trackEvent`, `startTour`, `startSurvey`, `startChecklist`, `showTicket`. They'll light up when the corresponding backend features ship.
87
222
 
88
223
  ## Types
89
224
 
90
- ### `VisitorIdentity`
225
+ ### VisitorIdentity
91
226
 
92
227
  ```ts
93
228
  interface VisitorIdentity {
94
- googleIdToken?: string; // Google FedCM id_token (preferred)
95
- jwt?: string; // Host-signed JWT
96
- userId?: string; // Legacy HMAC pair…
97
- userHash?: string; // …(HMAC-SHA256(userId, integrationSecret))
229
+ googleIdToken?: string; // Google FedCM id_token (preferred)
230
+ jwt?: string; // Host-signed JWT
231
+ userId?: string; // Legacy HMAC pair…
232
+ userHash?: string; // …(HMAC-SHA256(userId, integrationSecret))
98
233
  name?: string;
99
234
  email?: string;
100
235
  phone?: string;
@@ -102,7 +237,7 @@ interface VisitorIdentity {
102
237
  }
103
238
  ```
104
239
 
105
- ### `VisitorPrefill`
240
+ ### VisitorPrefill
106
241
 
107
242
  ```ts
108
243
  interface VisitorPrefill {
@@ -112,9 +247,9 @@ interface VisitorPrefill {
112
247
  }
113
248
  ```
114
249
 
115
- ### `InjectableWidgetConfig`
250
+ ### InjectableWidgetConfig
116
251
 
117
- The pre-resolved widget config shape (theme, features, blocks, prechat, messenger chrome, sounds, locale strategy). It deliberately excludes `status`, `branding`, and `security.allowedOrigins` — those are server-owned and not host-overridable. Pull the full type from the package:
252
+ The pre-resolved widget config shape (theme, features, blocks, prechat, messenger chrome, sounds, locale strategy). Pull it from the package:
118
253
 
119
254
  ```ts
120
255
  import type { InjectableWidgetConfig } from "@wexio/messenger-widget-react";
@@ -128,6 +263,52 @@ The component renders `null` on the server. The Shadow-DOM portal target mounts
128
263
 
129
264
  Modern evergreen browsers — anything that supports Shadow DOM and ES2020. Internet Explorer is not supported.
130
265
 
131
- ## License
266
+ ## Troubleshooting
267
+
268
+ ### Messenger not showing on page
269
+
270
+ - Check that the correct `publicKey` is being passed.
271
+ - Check the messenger is **active** for your integration on https://app.wexio.io.
272
+ - Confirm the component renders on the client (not during SSR) — `<WexioWidget>` returns `null` until the first `useEffect`.
273
+
274
+ ### No user data attached
275
+
276
+ - Verify you're computing `userHash` server-side as `HMAC-SHA256(userId, integrationSecret)`. Never expose the integration secret to the browser.
277
+ - Confirm the proof you pass in `user` is one of: `googleIdToken`, `jwt`, or `userId` + `userHash`. Passing multiple proofs uses the first one detected (Google → jwt → HMAC).
278
+
279
+ ### TypeScript errors after upgrade
280
+
281
+ The public type surface is locked to `entries/public.ts` in the source repo. If you previously relied on undocumented props (`mode: "preview"`, `configOverride`, `useDummyData`, `previewData`), they are no longer exposed — they were dashboard-only and never meant to ship. Remove them and the build will pass.
282
+
283
+ ## Use with other frameworks
284
+
285
+ The underlying widget runtime is a Web Component, so it works in any modern framework — even without a typed wrapper:
286
+
287
+ ```html
288
+ <wexio-widget public-key="pk_live_..."></wexio-widget>
289
+ <script type="module" src="https://cdn.wexio.io/widget.js"></script>
290
+ ```
291
+
292
+ Typed wrappers are on the roadmap:
293
+
294
+ - `@wexio/messenger-widget-vue` — coming soon
295
+ - `@wexio/messenger-widget-angular` — coming soon
296
+ - `@wexio/messenger-widget-ember` — coming soon
297
+
298
+ For plain HTML / script-injection setups, paste the loader snippet from https://learn.wexio.io.
299
+
300
+ ## Author
301
+
302
+ 👤 **Wexio** ([https://wexio.io](https://wexio.io))
303
+
304
+ ## Show your support
305
+
306
+ Give a ⭐️ if this package helped you!
307
+
308
+ ## 📝 License
309
+
310
+ This project is [MIT](./LICENSE) licensed.
311
+
312
+ ---
132
313
 
133
- [MIT](./LICENSE) © Wexio
314
+ _Created with ❤️ by [Wexio](https://wexio.io)_
@@ -1,9 +1,6 @@
1
1
  import type { CSSProperties } from "react";
2
2
 
3
3
  export type WexioWidgetLocale = "en" | "uk";
4
- /** Public surface — mode is always production. Preview + demo are
5
- * private-only (dashboard embed) and not reachable from npm. */
6
- export type WexioWidgetMode = "production";
7
4
 
8
5
  export type WidgetTab = "home" | "messages" | "help" | "news" | "profile";
9
6
 
@@ -246,9 +243,6 @@ export interface VisitorPrefill {
246
243
  export interface WexioWidgetProps {
247
244
  publicKey?: string;
248
245
  locale?: WexioWidgetLocale;
249
- /** Always `"production"` on the public package. `preview` and `demo`
250
- * modes are dashboard-only and not exposed here. */
251
- mode?: WexioWidgetMode;
252
246
  /**
253
247
  * Log a known user into the widget (the React equivalent of
254
248
  * Intercom's `boot({ user_id, ... })`). Provide ONE proof: