@_solaris/messenger-widget 0.4.14 → 0.5.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 +70 -35
- package/dist/messenger.cjs +24 -24
- package/dist/messenger.embed.js +31 -31
- package/dist/messenger.js +1686 -1612
- package/dist/style.css +1 -1
- package/dist/types/core/transport.d.ts +5 -8
- package/dist/types/embed.d.ts +5 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,8 +17,13 @@ npm i @_solaris/messenger-widget vue
|
|
|
17
17
|
import { Messenger } from '@_solaris/messenger-widget';
|
|
18
18
|
import '@_solaris/messenger-widget/style.css';
|
|
19
19
|
|
|
20
|
-
//
|
|
21
|
-
// <Messenger :base-url="..." :widget-id="..." :
|
|
20
|
+
// Linked mode (merchant identifies the user):
|
|
21
|
+
// <Messenger :base-url="..." :widget-id="..." :token="merchantJwt" display-mode="floating" />
|
|
22
|
+
//
|
|
23
|
+
// Visitor mode (anonymous): omit `:token` — the widget calls POST /client/session
|
|
24
|
+
// on boot and persists a brispr-issued JWT in localStorage. Requires the widget's
|
|
25
|
+
// `security.allow_unauthenticated=true` server-side.
|
|
26
|
+
// <Messenger :base-url="..." :widget-id="..." display-mode="floating" />
|
|
22
27
|
//
|
|
23
28
|
// UI language: pass `language` ('fr' | 'en'). When omitted, it falls back to
|
|
24
29
|
// the authenticated customer's `language`, then the widget config's
|
|
@@ -32,15 +37,42 @@ import '@_solaris/messenger-widget/style.css';
|
|
|
32
37
|
// :context="{ customer: { name: 'Jane', email: 'jane@acme.io', plan: 'pro', seats: 12 } }"
|
|
33
38
|
```
|
|
34
39
|
|
|
40
|
+
### Auth model
|
|
41
|
+
|
|
42
|
+
The widget sends `Authorization: Bearer <jwt>` on every call. The JWT comes
|
|
43
|
+
from one of two sources, depending on whether `token` is passed:
|
|
44
|
+
|
|
45
|
+
- **linked** (merchant backend signs): sign a JWT HS256 with the widget secret,
|
|
46
|
+
claims `{ sub: <external_id>, wid: <widget_id>, kind: "linked", exp }`.
|
|
47
|
+
Pass the resulting JWT as `token`. Renew before `exp` (typical TTL 1h–24h
|
|
48
|
+
per merchant policy).
|
|
49
|
+
- **visitor** (omit `token`): the widget calls `POST /client/session` once, the
|
|
50
|
+
server creates a `customers` row (`identity_type='visitor'`) and returns a
|
|
51
|
+
30-day JWT. The widget persists it in `localStorage[brispr_token_<wid>]`
|
|
52
|
+
for cross-reload continuity. Server-side opt-in via
|
|
53
|
+
`widgets.security.allow_unauthenticated`.
|
|
54
|
+
|
|
35
55
|
It also exports the individual presentational components, the design tokens and
|
|
36
56
|
helpers — used by the WeWeb "conversation admin" plugin which supplies its own
|
|
37
|
-
WeWeb-managed data instead of the built-in
|
|
57
|
+
WeWeb-managed data instead of the built-in JWT/SSE transport:
|
|
38
58
|
|
|
39
59
|
```js
|
|
40
60
|
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
MessageList,
|
|
62
|
+
Bubble,
|
|
63
|
+
Composer,
|
|
64
|
+
ApprovalCard,
|
|
65
|
+
FormCard,
|
|
66
|
+
ArtifactRenderer,
|
|
67
|
+
AIAvatar,
|
|
68
|
+
HumanAvatar,
|
|
69
|
+
TeamAvatars,
|
|
70
|
+
AttachmentPreview,
|
|
71
|
+
tokens,
|
|
72
|
+
renderMarkdown,
|
|
73
|
+
uuid,
|
|
74
|
+
createStore,
|
|
75
|
+
createTransport,
|
|
44
76
|
} from '@_solaris/messenger-widget';
|
|
45
77
|
```
|
|
46
78
|
|
|
@@ -49,34 +81,37 @@ import {
|
|
|
49
81
|
```html
|
|
50
82
|
<script src="https://your-cdn/messenger.embed.js"></script>
|
|
51
83
|
<script>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
Messenger.init({
|
|
85
|
+
baseUrl: 'https://messenger.your-saas.com',
|
|
86
|
+
widgetId: '…',
|
|
87
|
+
token: '…', // optional — JWT HS256 signed by your backend with
|
|
88
|
+
// the widget secret. Omit to run in visitor mode
|
|
89
|
+
// (anonymous, brispr-issued token persisted in
|
|
90
|
+
// localStorage, server-side opt-in required).
|
|
91
|
+
displayMode: 'floating', // 'floating' | 'sheet' | 'embedded'
|
|
92
|
+
language: 'en', // optional — 'fr' | 'en'; else customer.language / widget.default_language
|
|
93
|
+
// Optional agent context. `context.customer` is a flat object pushed
|
|
94
|
+
// once to PATCH /customers/me on boot so the agent has it as context.
|
|
95
|
+
// `name`/`email` map to the customer's columns; any other key is a
|
|
96
|
+
// named variable value (server keeps variables you don't pass):
|
|
97
|
+
context: {
|
|
98
|
+
customer: {
|
|
99
|
+
name: 'Jane Doe',
|
|
100
|
+
email: 'jane@acme.io',
|
|
101
|
+
plan: 'pro',
|
|
102
|
+
seats: 12,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
// Messenger.destroy() to tear it down.
|
|
73
107
|
</script>
|
|
74
108
|
```
|
|
75
109
|
|
|
76
|
-
`init()` is idempotent
|
|
77
|
-
|
|
110
|
+
`init()` is idempotent (no-op if re-called with identical options) and requires
|
|
111
|
+
only `baseUrl` + `widgetId` to attempt a boot — without `token`, the widget
|
|
112
|
+
falls back to visitor mode automatically. See
|
|
78
113
|
[examples/weweb-embed.md](examples/weweb-embed.md) for the WeWeb integration
|
|
79
|
-
(reactive
|
|
114
|
+
(reactive JWT via WeWeb variables + workflow).
|
|
80
115
|
|
|
81
116
|
## Build
|
|
82
117
|
|
|
@@ -85,11 +120,11 @@ npm install
|
|
|
85
120
|
npm run build # build:lib + build:embed + build:types → dist/
|
|
86
121
|
```
|
|
87
122
|
|
|
88
|
-
| Output
|
|
89
|
-
|
|
|
90
|
-
| `dist/messenger.js` / `.cjs` + `dist/style.css` | lib
|
|
91
|
-
| `dist/messenger.embed.js`
|
|
92
|
-
| `dist/types/`
|
|
123
|
+
| Output | Target | Vue |
|
|
124
|
+
| ----------------------------------------------- | ------ | --------------- |
|
|
125
|
+
| `dist/messenger.js` / `.cjs` + `dist/style.css` | lib | external (peer) |
|
|
126
|
+
| `dist/messenger.embed.js` | embed | bundled in |
|
|
127
|
+
| `dist/types/` | types | from JSDoc |
|
|
93
128
|
|
|
94
129
|
## License
|
|
95
130
|
|