@restless-stream/core 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 +109 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Use this package when you need framework-neutral TypeScript support. Use `@restl
|
|
|
11
11
|
- A Restless Stream account and API key.
|
|
12
12
|
- A runtime with `fetch` for REST and SSE support.
|
|
13
13
|
- A runtime with `WebSocket` for WebSocket helpers, or an explicit `WebSocket` implementation passed in options.
|
|
14
|
-
- Node.js `>=
|
|
14
|
+
- Node.js `>=24` for local development and package tests.
|
|
15
15
|
|
|
16
16
|
Do not expose long-lived API keys in public browser applications. For browser clients, prefer backend-created stream or direct-session URLs.
|
|
17
17
|
|
|
@@ -346,6 +346,114 @@ type ErrorEvent = {
|
|
|
346
346
|
| `RestlessClient`, `RestlessStreamsClient`, `RestlessDirectClient`, `RestlessUrlBuilder` | Client interfaces. |
|
|
347
347
|
| Stream, direct, snippet, and runtime types | Request, response, event, URL, and snippet types exported from `types.ts`. |
|
|
348
348
|
|
|
349
|
+
## Appendix: Creating an API Key
|
|
350
|
+
|
|
351
|
+
API keys authenticate requests to the Restless Stream management API and runtime streams. Keys start with `rs_` followed by a hex string:
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
rs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### Create a key in the dashboard
|
|
358
|
+
|
|
359
|
+
1. Sign in at [restlessapi.stream](https://restlessapi.stream) and go to **API Keys** in the dashboard.
|
|
360
|
+
|
|
361
|
+

|
|
362
|
+
|
|
363
|
+
2. Click **Create API Key**, enter a name and optional description, and set an optional expiry date.
|
|
364
|
+
|
|
365
|
+

|
|
366
|
+
|
|
367
|
+
3. Copy the key immediately — it is shown only once after creation.
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
export RESTLESS_API_KEY="rs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Pass the key to the client
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
import { createRestlessClient } from '@restless-stream/core';
|
|
377
|
+
|
|
378
|
+
const client = createRestlessClient({
|
|
379
|
+
apiKey: process.env.RESTLESS_API_KEY,
|
|
380
|
+
});
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
## Sample Responses
|
|
384
|
+
|
|
385
|
+
### `streams.list()`
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
const page = await client.streams.list({ limit: 5, offset: 0 });
|
|
389
|
+
console.log(page);
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
**Response:**
|
|
393
|
+
|
|
394
|
+
```json
|
|
395
|
+
{
|
|
396
|
+
"streams": [],
|
|
397
|
+
"paginationInfo": {
|
|
398
|
+
"hasNextPage": false
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### `streams.validateApiKey()`
|
|
404
|
+
|
|
405
|
+
```ts
|
|
406
|
+
const result = await client.streams.validateApiKey();
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
**Response:**
|
|
410
|
+
|
|
411
|
+
```json
|
|
412
|
+
{
|
|
413
|
+
"id": "rs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
|
414
|
+
"affected": true
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### `streams.subscribeSse()` — direct mode, live event
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
const sseUrl =
|
|
422
|
+
'https://stream.restlessapi.stream/?url=' +
|
|
423
|
+
encodeURIComponent('https://httpbin.org/get') +
|
|
424
|
+
'&pollingInterval=15';
|
|
425
|
+
|
|
426
|
+
for await (const event of client.streams.subscribeSse({ sseUrl, reconnect: false })) {
|
|
427
|
+
console.log(event);
|
|
428
|
+
break; // receive one event then stop
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Event received:**
|
|
433
|
+
|
|
434
|
+
```json
|
|
435
|
+
{
|
|
436
|
+
"type": "update",
|
|
437
|
+
"meta": {
|
|
438
|
+
"timestamp": "2026-06-07T00:49:36.562+00:00",
|
|
439
|
+
"attempt_id": "a59d80d4-7d36-4019-b2c6-40cc8b8742ce",
|
|
440
|
+
"status": 200,
|
|
441
|
+
"latency_ms": 43
|
|
442
|
+
},
|
|
443
|
+
"data": {
|
|
444
|
+
"args": {},
|
|
445
|
+
"headers": {
|
|
446
|
+
"Accept": "*/*",
|
|
447
|
+
"Host": "httpbin.org",
|
|
448
|
+
"User-Agent": "Mozilla/5.0 (compatible; OurInternalService/1.0)",
|
|
449
|
+
"X-Amzn-Trace-Id": "Root=1-6a24c020-316d1d396470c0900ce68495"
|
|
450
|
+
},
|
|
451
|
+
"origin": "140.82.14.127",
|
|
452
|
+
"url": "https://httpbin.org/get"
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
```
|
|
456
|
+
|
|
349
457
|
## Development
|
|
350
458
|
|
|
351
459
|
```bash
|