@skippr/live-agent-sdk 0.36.0 → 0.38.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 +26 -7
- package/dist/esm/lib-exports.js +275 -115
- package/dist/skippr-sdk.js +110 -110
- package/dist/types/components/LiveAgent.d.ts +1 -0
- package/dist/types/context/LiveAgentContext.d.ts +3 -1
- package/dist/types/hooks/useAuth.d.ts +1 -1
- package/dist/types/hooks/useAvailableModules.d.ts +3 -1
- package/dist/types/hooks/useSession.d.ts +5 -1
- package/dist/types/lib/session.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,6 +89,8 @@ The SDK supports two identity modes, configured per App Key in the Skippr dashbo
|
|
|
89
89
|
|
|
90
90
|
Users log in via email OTP inside the widget. No backend integration needed. The SDK handles the full OTP flow: email input, code verification, and token persistence automatically.
|
|
91
91
|
|
|
92
|
+
> **Best suited for development and testing.** Direct Auth persists tokens in the browser and has no automatic token refresh, so it works in production but isn't what we recommend there. For production, we suggest Secret Mode — your backend vouches for the user and controls token lifetime.
|
|
93
|
+
|
|
92
94
|
**React:**
|
|
93
95
|
|
|
94
96
|
```tsx
|
|
@@ -105,7 +107,11 @@ Skippr.initialize({
|
|
|
105
107
|
|
|
106
108
|
### Secret Mode
|
|
107
109
|
|
|
108
|
-
Your backend signs a JWT with the App Key's identity secret
|
|
110
|
+
Your backend signs a short-lived JWT with the App Key's identity secret. You give the SDK a `getUserToken` callback that returns a freshly signed JWT each time it's called; the SDK exchanges it for a bearer token server-side and skips the login form entirely.
|
|
111
|
+
|
|
112
|
+
Because it's a callback (not a static token), the SDK can keep the session alive without a page reload: it invokes `getUserToken` to bootstrap, again proactively shortly before the current bearer expires, and once more if a request comes back `401`. Your callback should always return a *current* JWT from your source of truth — typically by re-minting it on your backend per call.
|
|
113
|
+
|
|
114
|
+
The bearer's lifetime is the **session token lifetime** you set on the App Key in the dashboard (15 minutes to 24 hours, default 1 hour).
|
|
109
115
|
|
|
110
116
|
**Step 1: Generate a signed JWT on your backend**
|
|
111
117
|
|
|
@@ -134,14 +140,14 @@ const userToken = jwt.sign(
|
|
|
134
140
|
);
|
|
135
141
|
```
|
|
136
142
|
|
|
137
|
-
**Step 2:
|
|
143
|
+
**Step 2: Give the SDK a callback that fetches a fresh token**
|
|
138
144
|
|
|
139
145
|
**React:**
|
|
140
146
|
|
|
141
147
|
```tsx
|
|
142
148
|
<LiveAgent
|
|
143
149
|
appKey="pk_live_your_key"
|
|
144
|
-
|
|
150
|
+
getUserToken={() => fetch('/api/skippr-token').then((r) => r.text())}
|
|
145
151
|
/>
|
|
146
152
|
```
|
|
147
153
|
|
|
@@ -150,10 +156,22 @@ const userToken = jwt.sign(
|
|
|
150
156
|
```js
|
|
151
157
|
Skippr.initialize({
|
|
152
158
|
appKey: 'pk_live_your_key',
|
|
153
|
-
|
|
159
|
+
getUserToken: () => fetch('/api/skippr-token').then((r) => r.text()),
|
|
154
160
|
});
|
|
155
161
|
```
|
|
156
162
|
|
|
163
|
+
The callback runs whenever the SDK needs a token, so each call should return a newly minted JWT (e.g. from the `/api/skippr-token` endpoint on your backend that signs the JWT shown in Step 1).
|
|
164
|
+
|
|
165
|
+
#### Static token (testing)
|
|
166
|
+
|
|
167
|
+
If you already hold a signed JWT and just want to drop it in, pass it as a static `userToken` string instead of a callback. The SDK exchanges it for a bearer token the same way.
|
|
168
|
+
|
|
169
|
+
```tsx
|
|
170
|
+
<LiveAgent appKey="pk_live_your_key" userToken={signedJwt} />
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
> **Best suited for quick tests.** A static token can't be re-minted, so once it expires the session cannot refresh — for production use the `getUserToken` callback above. When both are provided, `getUserToken` wins.
|
|
174
|
+
|
|
157
175
|
## Custom Components
|
|
158
176
|
|
|
159
177
|
Any component rendered inside `<LiveAgent>` can use the `useLiveAgent` hook to access session state and controls:
|
|
@@ -189,7 +207,8 @@ Self-contained widget component. Renders a floating button that opens a sidebar
|
|
|
189
207
|
|------|------|---------|-------------|
|
|
190
208
|
| `appKey` | `string` | *required* | Publishable App Key from the Skippr dashboard |
|
|
191
209
|
| `agentId` | `string` | — | Pin the widget to a specific module (pass that module's id). Omit to let the user pick from all your active modules at runtime. |
|
|
192
|
-
| `
|
|
210
|
+
| `getUserToken` | `() => Promise<string>` | — | Async callback returning a freshly signed JWT for secret mode. The SDK calls it to bootstrap, again proactively before the bearer expires, and once more on a `401` to re-bootstrap. |
|
|
211
|
+
| `userToken` | `string` | — | Static signed JWT for secret mode (testing). Exchanged for a bearer token but can't be refreshed once expired. `getUserToken` takes precedence when both are set. |
|
|
193
212
|
| `position` | `'left' \| 'right'` | `'right'` | Side of the screen for the widget |
|
|
194
213
|
| `variant` | `'floating' \| 'sidebar'` | `'floating'` | Widget display mode |
|
|
195
214
|
| `minimizable` | `boolean` | `true` | Whether the widget can be minimized |
|
|
@@ -278,8 +297,8 @@ Available on `window.Skippr` when using the script tag bundle.
|
|
|
278
297
|
|
|
279
298
|
| Method | Description |
|
|
280
299
|
|--------|-------------|
|
|
281
|
-
| `Skippr.initialize(config)` | Mount the widget. Accepts `appKey` (required), `agentId` (optional — omit for picker), `userToken`, `position`, `variant`, `minimizable`, `captureMode`, `agentControls`. |
|
|
282
|
-
| `Skippr.logout()` |
|
|
300
|
+
| `Skippr.initialize(config)` | Mount the widget. Accepts `appKey` (required), `agentId` (optional — omit for picker), `getUserToken`, `userToken`, `position`, `variant`, `minimizable`, `captureMode`, `agentControls`. |
|
|
301
|
+
| `Skippr.logout()` | Revoke the current session server-side, clear stored auth tokens, and show the login form (direct auth mode) |
|
|
283
302
|
| `Skippr.destroy()` | Remove the widget from the page and clear auth tokens |
|
|
284
303
|
|
|
285
304
|
|