@chatsystem/client 1.1.87 → 1.2.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,24 +1,85 @@
1
- # Use the client
1
+ # ChatSystem Client
2
2
 
3
- ## Use it as a react package
3
+ ## React package
4
4
 
5
- - ```js
6
- import { App } from "@chatsystem/client";
7
- <App appToken="YOUR_TOKEN_ID" displayMode="chatbox" />;
8
- ```
5
+ ```tsx
6
+ import { App } from "@chatsystem/client";
9
7
 
10
- ## Use it as a bundled JS script
8
+ <App appToken="YOUR_TOKEN_ID" displayMode="chatbox" />;
9
+ ```
11
10
 
12
- - ```js
13
- <script
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
- ### Parameters
14
+ ### Delegated user identity
22
15
 
23
- - appToken: your appToken, delivered on chatsystem.ai
24
- - displayMode?: either `bubble` if you want the bubble to display, or `chatbox` if you want to see directly the chatbox. Css is overridable.
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
+ data-displayMode="chatbox"
80
+ ></script>
81
+ ```
82
+
83
+ The current bundled-script integration supports anonymous widgets. Delegated
84
+ identity requires the React API until a programmatic script bootstrap is
85
+ released; functions must not be serialized into `data-*` attributes.