@chatsystem/client 1.1.88 → 1.2.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 +81 -18
- package/dist/index.cjs +51 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.mjs +5505 -5315
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -5
package/README.md
CHANGED
|
@@ -1,24 +1,87 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ChatSystem Client
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## React package
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<App appToken="YOUR_TOKEN_ID" displayMode="chatbox" />;
|
|
8
|
-
```
|
|
5
|
+
```tsx
|
|
6
|
+
import { App } from "@chatsystem/client";
|
|
9
7
|
|
|
10
|
-
|
|
8
|
+
<App appToken="YOUR_TOKEN_ID" displayMode="chatbox" />;
|
|
9
|
+
```
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type="text/javascript"
|
|
15
|
-
src="https://chatsystem.s3.eu-west-3.amazonaws.com/index.js"
|
|
16
|
-
data-appToken="YOUR_TOKEN_ID"
|
|
17
|
-
data-displayMode="chatbox"
|
|
18
|
-
></script>
|
|
19
|
-
```
|
|
11
|
+
`appToken` identifies the public customer installation; it is not a user
|
|
12
|
+
credential. `displayMode` accepts `launcher` or `chatbox`.
|
|
20
13
|
|
|
21
|
-
###
|
|
14
|
+
### Delegated user identity
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
Pass an `identityProvider` when the customer host can recognize its existing
|
|
17
|
+
user session:
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { App, type WidgetIdentityProvider } from "@chatsystem/client";
|
|
21
|
+
|
|
22
|
+
const identityProvider: WidgetIdentityProvider = {
|
|
23
|
+
async getToken({ interactive, reason, requiredCapabilities }) {
|
|
24
|
+
if (interactive) {
|
|
25
|
+
await customerAuth.ensureSignedIn({ reason, requiredCapabilities });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const response = await fetch("/api/chatsystem/identity", {
|
|
29
|
+
credentials: "include",
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) return null;
|
|
32
|
+
return (await response.json()).token ?? null;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
subscribe(onIdentityChanged) {
|
|
36
|
+
return customerAuth.onAuthStateChanged(onIdentityChanged);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
<App
|
|
41
|
+
appToken="YOUR_TOKEN_ID"
|
|
42
|
+
displayMode="chatbox"
|
|
43
|
+
identityProvider={identityProvider}
|
|
44
|
+
/>;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The provider calls a same-origin customer endpoint. That backend endpoint reads
|
|
48
|
+
the customer session and mints a short-lived ChatSystem widget JWT. Never return
|
|
49
|
+
a company API key, customer access token, cookie, password, or SSO token to the
|
|
50
|
+
widget.
|
|
51
|
+
|
|
52
|
+
Without `identityProvider`, the widget stays anonymous and does not announce
|
|
53
|
+
interactive identity-gate compatibility.
|
|
54
|
+
|
|
55
|
+
### Custom API origin
|
|
56
|
+
|
|
57
|
+
Hosted customers should omit `apiUrl`. Internal tests and explicitly supported
|
|
58
|
+
self-hosted deployments may provide it:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
<App
|
|
62
|
+
appToken="YOUR_TOKEN_ID"
|
|
63
|
+
apiUrl="https://api.internal.example"
|
|
64
|
+
displayMode="chatbox"
|
|
65
|
+
/>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The value is scoped to that widget instance. Credentials, query strings,
|
|
69
|
+
fragments, and non-local plain HTTP origins are rejected. Localhost HTTP remains
|
|
70
|
+
available for development.
|
|
71
|
+
|
|
72
|
+
## Bundled JavaScript
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<script
|
|
76
|
+
type="text/javascript"
|
|
77
|
+
src="https://chatsystem.s3.eu-west-3.amazonaws.com/index.js"
|
|
78
|
+
data-appToken="YOUR_TOKEN_ID"
|
|
79
|
+
></script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`data-displayMode` is optional and defaults to `launcher`. Set
|
|
83
|
+
`data-displayMode="chatbox"` when embedding the chat directly in the page.
|
|
84
|
+
|
|
85
|
+
The current bundled-script integration supports anonymous widgets. Delegated
|
|
86
|
+
identity requires the React API until a programmatic script bootstrap is
|
|
87
|
+
released; functions must not be serialized into `data-*` attributes.
|