@restless-stream/react 0.1.1 → 0.1.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 +88 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -252,6 +252,94 @@ function DirectSessionEvents({ session }: { session: { sseUrl?: string | null }
|
|
|
252
252
|
| `UseManagedStreamOptions` | Managed stream hook options type. |
|
|
253
253
|
| `UseDirectStreamOptions` | Direct stream hook options type. |
|
|
254
254
|
|
|
255
|
+
## Appendix: Creating an API Key
|
|
256
|
+
|
|
257
|
+
API keys are used by the core client passed to `RestlessProvider`, or by your backend when generating stream URLs. Keys start with `rs_` followed by a hex string:
|
|
258
|
+
|
|
259
|
+
```
|
|
260
|
+
rs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Create a key in the dashboard
|
|
264
|
+
|
|
265
|
+
1. Sign in at [restlessapi.stream](https://restlessapi.stream) and go to **API Keys** in the dashboard.
|
|
266
|
+
|
|
267
|
+

|
|
268
|
+
|
|
269
|
+
2. Click **Create API Key**, enter a name and optional description, and set an optional expiry date.
|
|
270
|
+
|
|
271
|
+

|
|
272
|
+
|
|
273
|
+
3. Copy the key immediately — it is shown only once after creation.
|
|
274
|
+
|
|
275
|
+
> **Browser safety:** Do not embed long-lived API keys in public browser bundles. Create stream URLs or direct sessions on your backend and pass the SSE URL to React components.
|
|
276
|
+
|
|
277
|
+
### Pass the key to the provider (trusted environments only)
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
import { RestlessProvider } from '@restless-stream/react';
|
|
281
|
+
|
|
282
|
+
export function App({ sseUrl }: { sseUrl: string }) {
|
|
283
|
+
return (
|
|
284
|
+
<RestlessProvider apiKey={process.env.RESTLESS_API_KEY}>
|
|
285
|
+
{/* children */}
|
|
286
|
+
</RestlessProvider>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Sample Responses
|
|
292
|
+
|
|
293
|
+
The `useStreamSubscription` hook result object has the following shape when connected to a direct-mode SSE URL:
|
|
294
|
+
|
|
295
|
+
```ts
|
|
296
|
+
const {
|
|
297
|
+
status, // 'idle' | 'connecting' | 'open' | 'reconnecting' | 'closed' | 'error'
|
|
298
|
+
events, // StreamEvent[] — bounded buffer of received events
|
|
299
|
+
latestEvent, // StreamEvent | null
|
|
300
|
+
error, // Error | null
|
|
301
|
+
isConnected, // boolean
|
|
302
|
+
connect, // () => void
|
|
303
|
+
disconnect, // () => void
|
|
304
|
+
reset, // () => void
|
|
305
|
+
} = useStreamSubscription({ sseUrl, maxEvents: 100 });
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
**Example `latestEvent` value** (after an update from `https://httpbin.org/get`):
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{
|
|
312
|
+
"type": "update",
|
|
313
|
+
"meta": {
|
|
314
|
+
"timestamp": "2026-06-07T00:49:36.562+00:00",
|
|
315
|
+
"attempt_id": "a59d80d4-7d36-4019-b2c6-40cc8b8742ce",
|
|
316
|
+
"status": 200,
|
|
317
|
+
"latency_ms": 43
|
|
318
|
+
},
|
|
319
|
+
"data": {
|
|
320
|
+
"args": {},
|
|
321
|
+
"headers": {
|
|
322
|
+
"Accept": "*/*",
|
|
323
|
+
"Host": "httpbin.org",
|
|
324
|
+
"User-Agent": "Mozilla/5.0 (compatible; OurInternalService/1.0)",
|
|
325
|
+
"X-Amzn-Trace-Id": "Root=1-6a24c020-316d1d396470c0900ce68495"
|
|
326
|
+
},
|
|
327
|
+
"origin": "140.82.14.127",
|
|
328
|
+
"url": "https://httpbin.org/get"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**`status` progression for a successful connection:**
|
|
334
|
+
|
|
335
|
+
| Step | `status` |
|
|
336
|
+
|------|----------|
|
|
337
|
+
| Before `enabled` | `idle` |
|
|
338
|
+
| Opening connection | `connecting` |
|
|
339
|
+
| First event received | `open` |
|
|
340
|
+
| After disconnect | `closed` |
|
|
341
|
+
| After error | `error` |
|
|
342
|
+
|
|
255
343
|
## Development
|
|
256
344
|
|
|
257
345
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restless-stream/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Lightweight React bindings for the Restless Stream SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"react": ">=18.2 <20"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@restless-stream/core": "0.1.
|
|
45
|
+
"@restless-stream/core": "0.1.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@testing-library/react": "^16.3.0",
|