@rstreamlabs/react 1.7.16 → 1.7.18

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.
Files changed (2) hide show
  1. package/README.md +39 -12
  2. package/package.json +3 -2
package/README.md CHANGED
@@ -18,12 +18,12 @@ The package has a peer dependency on React 18 or 19.
18
18
 
19
19
  ## Exports
20
20
 
21
- | Import path | Contents |
22
- | --- | --- |
23
- | `@rstreamlabs/react` | Hooks, providers, and components. |
24
- | `@rstreamlabs/react/hooks` | `useRstream`. |
25
- | `@rstreamlabs/react/providers` | `RstreamProvider`, `useRstreamContext`. |
26
- | `@rstreamlabs/react/components` | `WebTTYTerminal`. |
21
+ | Import path | Contents |
22
+ | ------------------------------- | --------------------------------------- |
23
+ | `@rstreamlabs/react` | Hooks, providers, and components. |
24
+ | `@rstreamlabs/react/hooks` | `useRstream`. |
25
+ | `@rstreamlabs/react/providers` | `RstreamProvider`, `useRstreamContext`. |
26
+ | `@rstreamlabs/react/components` | `WebTTYTerminal`. |
27
27
 
28
28
  ## Live Tunnel State
29
29
 
@@ -35,9 +35,21 @@ React state.
35
35
 
36
36
  import { useRstream } from "@rstreamlabs/react/hooks";
37
37
 
38
- export function TunnelInventory({ token }: { token: string }) {
38
+ async function createWatchToken() {
39
+ const response = await fetch("/api/rstream/watch-token", {
40
+ method: "POST",
41
+ cache: "no-store",
42
+ });
43
+ if (!response.ok) {
44
+ throw new Error("Failed to create watch token.");
45
+ }
46
+ const { token } = await response.json();
47
+ return token;
48
+ }
49
+
50
+ export function TunnelInventory() {
39
51
  const { state, error, tunnels } = useRstream({
40
- auth: token,
52
+ auth: createWatchToken,
41
53
  engine: "project-endpoint.cluster.example.rstream.test:443",
42
54
  transport: "sse",
43
55
  });
@@ -66,16 +78,28 @@ Use `RstreamProvider` when several components need the same watch stream.
66
78
  import { RstreamProvider } from "@rstreamlabs/react/providers";
67
79
  import { useRstreamContext } from "@rstreamlabs/react/providers";
68
80
 
81
+ async function createWatchToken() {
82
+ const response = await fetch("/api/rstream/watch-token", {
83
+ method: "POST",
84
+ cache: "no-store",
85
+ });
86
+ if (!response.ok) {
87
+ throw new Error("Failed to create watch token.");
88
+ }
89
+ const { token } = await response.json();
90
+ return token;
91
+ }
92
+
69
93
  function TunnelsTable() {
70
94
  const { tunnels } = useRstreamContext();
71
95
  return <pre>{JSON.stringify(tunnels, null, 2)}</pre>;
72
96
  }
73
97
 
74
- export function Dashboard({ token }: { token: string }) {
98
+ export function Dashboard() {
75
99
  return (
76
100
  <RstreamProvider
77
101
  options={{
78
- auth: token,
102
+ auth: createWatchToken,
79
103
  engine: "project-endpoint.cluster.example.rstream.test:443",
80
104
  }}
81
105
  >
@@ -114,8 +138,11 @@ state synchronized with the remote session.
114
138
 
115
139
  ## Security Notes
116
140
 
117
- Browser applications should receive short-lived tokens from a backend endpoint.
118
- Do not embed personal access tokens or application client secrets in React code.
141
+ Browser watch streams should receive a fresh short-lived watch token from a
142
+ backend endpoint for each connection attempt. The token is sent to the engine as
143
+ `rstream.token` on `/api/sse` or `/api/websocket`, so it must be an `auth` or
144
+ `app` token with bounded lifetime and tunnel list-only resources. Do not embed
145
+ personal access tokens or application client secrets in React code.
119
146
 
120
147
  ## Development
121
148
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/react",
3
- "version": "1.7.16",
3
+ "version": "1.7.18",
4
4
  "description": "React hooks and components for building rstream-enabled UIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,7 +55,8 @@
55
55
  "typescript": "5.9.3"
56
56
  },
57
57
  "dependencies": {
58
- "@rstreamlabs/tunnels": "1.0.11",
58
+ "@rstreamlabs/rstream": "3.0.0",
59
+ "@rstreamlabs/tunnels": "3.0.0",
59
60
  "@rstreamlabs/webtty": "1.6.5",
60
61
  "@xterm/addon-fit": "^0.11.0",
61
62
  "@xterm/addon-unicode11": "^0.9.0",