@rstreamlabs/react 1.10.16 → 2.0.1

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
@@ -57,9 +57,11 @@ export function TunnelInventory() {
57
57
  if (error) return <p>{error.message}</p>;
58
58
  return (
59
59
  <ul data-state={state}>
60
- {tunnels.map((tunnel) => (
61
- <li key={tunnel.id}>{tunnel.name ?? tunnel.id}</li>
62
- ))}
60
+ {tunnels
61
+ .filter((tunnel) => tunnel.id !== undefined)
62
+ .map((tunnel) => (
63
+ <li key={tunnel.id}>{tunnel.name ?? tunnel.id}</li>
64
+ ))}
63
65
  </ul>
64
66
  );
65
67
  }
@@ -68,6 +70,13 @@ export function TunnelInventory() {
68
70
  The hook reconnects automatically and clears state when authentication is not
69
71
  configured.
70
72
 
73
+ The returned arrays use `ListedClient` and `ListedTunnel`, whose fields may
74
+ be absent under field selection. Select `id` for keyed, actionable rows, or
75
+ render anonymous projections without assuming an identifier exists. A denied
76
+ category is empty and does not prevent the other category from updating.
77
+ Every incoming snapshot replaces both arrays. Previously visible data is
78
+ hidden while reconnecting or switching authentication.
79
+
71
80
  ## Shared Provider
72
81
 
73
82
  Use `RstreamProvider` when several components need the same watch stream.
@@ -30,6 +30,7 @@ function useRstream(options) {
30
30
  const [state, setState] = React.useState("disconnected");
31
31
  const [error, setError] = React.useState(null);
32
32
  const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
33
+ const [inventoryKey, setInventoryKey] = React.useState(null);
33
34
  const [clients, setClients] = React.useState([]);
34
35
  const [tunnels, setTunnels] = React.useState([]);
35
36
  const authEnabled = hasAuth(options);
@@ -67,13 +68,19 @@ function useRstream(options) {
67
68
  onEvent: (event) => {
68
69
  if (!runtime.active) return;
69
70
  if (event.type === "state.initial") {
71
+ setInventoryKey(connectionKey);
70
72
  setClients(event.object.clients);
71
73
  setTunnels(event.object.tunnels);
72
74
  } else if (event.type.startsWith("client")) {
73
75
  setClients((previous) => {
74
76
  if (event.type === "client.created") {
75
- return [...previous, event.object];
77
+ return [
78
+ ...previous.filter((item) => item.id !== event.object.id),
79
+ event.object
80
+ ];
76
81
  } else if (event.type === "client.updated") {
82
+ if (!previous.some((client) => client.id === event.object.id))
83
+ return [...previous, event.object];
77
84
  return previous.map((client) => {
78
85
  if (client.id === event.object.id) {
79
86
  return event.object;
@@ -90,8 +97,13 @@ function useRstream(options) {
90
97
  } else if (event.type.startsWith("tunnel")) {
91
98
  setTunnels((previous) => {
92
99
  if (event.type === "tunnel.created") {
93
- return [...previous, event.object];
100
+ return [
101
+ ...previous.filter((item) => item.id !== event.object.id),
102
+ event.object
103
+ ];
94
104
  } else if (event.type === "tunnel.updated") {
105
+ if (!previous.some((tunnel) => tunnel.id === event.object.id))
106
+ return [...previous, event.object];
95
107
  return previous.map((tunnel) => {
96
108
  if (tunnel.id === event.object.id) {
97
109
  return event.object;
@@ -114,6 +126,7 @@ function useRstream(options) {
114
126
  onClose: () => {
115
127
  if (!runtime.active) return;
116
128
  runtime.watch = null;
129
+ setInventoryKey(null);
117
130
  schedule();
118
131
  }
119
132
  });
@@ -167,7 +180,13 @@ function useRstream(options) {
167
180
  return () => clearTimeout(timeout);
168
181
  }
169
182
  }, [authEnabled, connectionKey, state]);
170
- return { state, error, tunnels, clients };
183
+ const visible = authEnabled && inventoryKey === connectionKey && state === "connected";
184
+ return {
185
+ state,
186
+ error,
187
+ tunnels: visible ? tunnels : [],
188
+ clients: visible ? clients : []
189
+ };
171
190
  }
172
191
 
173
192
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useRstream
3
- } from "./chunk-YZQKMOHW.mjs";
3
+ } from "./chunk-AHLVBJB3.mjs";
4
4
 
5
5
  // src/providers/rstream.tsx
6
6
  import * as React from "react";
@@ -36,9 +36,7 @@ declare function useRstream(options?: UseRstreamOptions): {
36
36
  type: "warning" | "danger";
37
37
  } | null;
38
38
  tunnels: {
39
- client_id: string;
40
- status: "online" | "offline";
41
- id: string;
39
+ client_id?: string | undefined;
42
40
  user_id?: string | undefined;
43
41
  workspace_id?: string | undefined;
44
42
  project_id?: string | undefined;
@@ -46,6 +44,8 @@ declare function useRstream(options?: UseRstreamOptions): {
46
44
  plan?: string | undefined;
47
45
  provider?: string | undefined;
48
46
  region?: string | undefined;
47
+ status?: "online" | "offline" | undefined;
48
+ id?: string | undefined;
49
49
  creation_date?: string | Date | undefined;
50
50
  name?: string | undefined;
51
51
  type?: "bytestream" | "datagram" | undefined;
@@ -79,11 +79,12 @@ declare function useRstream(options?: UseRstreamOptions): {
79
79
  challenge_mode?: boolean | undefined;
80
80
  }[];
81
81
  clients: {
82
- id: string;
83
- status: "online" | "offline";
82
+ id?: string | undefined;
83
+ status?: "online" | "offline" | undefined;
84
84
  user_id?: string | undefined;
85
85
  workspace_id?: string | undefined;
86
86
  project_id?: string | undefined;
87
+ endpoint?: string | undefined;
87
88
  cluster_id?: string | undefined;
88
89
  plan?: string | undefined;
89
90
  provider?: string | undefined;
@@ -36,9 +36,7 @@ declare function useRstream(options?: UseRstreamOptions): {
36
36
  type: "warning" | "danger";
37
37
  } | null;
38
38
  tunnels: {
39
- client_id: string;
40
- status: "online" | "offline";
41
- id: string;
39
+ client_id?: string | undefined;
42
40
  user_id?: string | undefined;
43
41
  workspace_id?: string | undefined;
44
42
  project_id?: string | undefined;
@@ -46,6 +44,8 @@ declare function useRstream(options?: UseRstreamOptions): {
46
44
  plan?: string | undefined;
47
45
  provider?: string | undefined;
48
46
  region?: string | undefined;
47
+ status?: "online" | "offline" | undefined;
48
+ id?: string | undefined;
49
49
  creation_date?: string | Date | undefined;
50
50
  name?: string | undefined;
51
51
  type?: "bytestream" | "datagram" | undefined;
@@ -79,11 +79,12 @@ declare function useRstream(options?: UseRstreamOptions): {
79
79
  challenge_mode?: boolean | undefined;
80
80
  }[];
81
81
  clients: {
82
- id: string;
83
- status: "online" | "offline";
82
+ id?: string | undefined;
83
+ status?: "online" | "offline" | undefined;
84
84
  user_id?: string | undefined;
85
85
  workspace_id?: string | undefined;
86
86
  project_id?: string | undefined;
87
+ endpoint?: string | undefined;
87
88
  cluster_id?: string | undefined;
88
89
  plan?: string | undefined;
89
90
  provider?: string | undefined;
@@ -66,6 +66,7 @@ function useRstream(options) {
66
66
  const [state, setState] = React.useState("disconnected");
67
67
  const [error, setError] = React.useState(null);
68
68
  const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
69
+ const [inventoryKey, setInventoryKey] = React.useState(null);
69
70
  const [clients, setClients] = React.useState([]);
70
71
  const [tunnels, setTunnels] = React.useState([]);
71
72
  const authEnabled = hasAuth(options);
@@ -103,13 +104,19 @@ function useRstream(options) {
103
104
  onEvent: (event) => {
104
105
  if (!runtime.active) return;
105
106
  if (event.type === "state.initial") {
107
+ setInventoryKey(connectionKey);
106
108
  setClients(event.object.clients);
107
109
  setTunnels(event.object.tunnels);
108
110
  } else if (event.type.startsWith("client")) {
109
111
  setClients((previous) => {
110
112
  if (event.type === "client.created") {
111
- return [...previous, event.object];
113
+ return [
114
+ ...previous.filter((item) => item.id !== event.object.id),
115
+ event.object
116
+ ];
112
117
  } else if (event.type === "client.updated") {
118
+ if (!previous.some((client) => client.id === event.object.id))
119
+ return [...previous, event.object];
113
120
  return previous.map((client) => {
114
121
  if (client.id === event.object.id) {
115
122
  return event.object;
@@ -126,8 +133,13 @@ function useRstream(options) {
126
133
  } else if (event.type.startsWith("tunnel")) {
127
134
  setTunnels((previous) => {
128
135
  if (event.type === "tunnel.created") {
129
- return [...previous, event.object];
136
+ return [
137
+ ...previous.filter((item) => item.id !== event.object.id),
138
+ event.object
139
+ ];
130
140
  } else if (event.type === "tunnel.updated") {
141
+ if (!previous.some((tunnel) => tunnel.id === event.object.id))
142
+ return [...previous, event.object];
131
143
  return previous.map((tunnel) => {
132
144
  if (tunnel.id === event.object.id) {
133
145
  return event.object;
@@ -150,6 +162,7 @@ function useRstream(options) {
150
162
  onClose: () => {
151
163
  if (!runtime.active) return;
152
164
  runtime.watch = null;
165
+ setInventoryKey(null);
153
166
  schedule();
154
167
  }
155
168
  });
@@ -203,7 +216,13 @@ function useRstream(options) {
203
216
  return () => clearTimeout(timeout);
204
217
  }
205
218
  }, [authEnabled, connectionKey, state]);
206
- return { state, error, tunnels, clients };
219
+ const visible = authEnabled && inventoryKey === connectionKey && state === "connected";
220
+ return {
221
+ state,
222
+ error,
223
+ tunnels: visible ? tunnels : [],
224
+ clients: visible ? clients : []
225
+ };
207
226
  }
208
227
  // Annotate the CommonJS export names for ESM import in node:
209
228
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  import "../chunk-2JFL7TS5.mjs";
2
2
  import {
3
3
  useRstream
4
- } from "../chunk-YZQKMOHW.mjs";
4
+ } from "../chunk-AHLVBJB3.mjs";
5
5
  export {
6
6
  useRstream
7
7
  };
package/dist/index.js CHANGED
@@ -295,6 +295,7 @@ function useRstream(options) {
295
295
  const [state, setState] = React2.useState("disconnected");
296
296
  const [error, setError] = React2.useState(null);
297
297
  const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
298
+ const [inventoryKey, setInventoryKey] = React2.useState(null);
298
299
  const [clients, setClients] = React2.useState([]);
299
300
  const [tunnels, setTunnels] = React2.useState([]);
300
301
  const authEnabled = hasAuth(options);
@@ -332,13 +333,19 @@ function useRstream(options) {
332
333
  onEvent: (event) => {
333
334
  if (!runtime.active) return;
334
335
  if (event.type === "state.initial") {
336
+ setInventoryKey(connectionKey);
335
337
  setClients(event.object.clients);
336
338
  setTunnels(event.object.tunnels);
337
339
  } else if (event.type.startsWith("client")) {
338
340
  setClients((previous) => {
339
341
  if (event.type === "client.created") {
340
- return [...previous, event.object];
342
+ return [
343
+ ...previous.filter((item) => item.id !== event.object.id),
344
+ event.object
345
+ ];
341
346
  } else if (event.type === "client.updated") {
347
+ if (!previous.some((client) => client.id === event.object.id))
348
+ return [...previous, event.object];
342
349
  return previous.map((client) => {
343
350
  if (client.id === event.object.id) {
344
351
  return event.object;
@@ -355,8 +362,13 @@ function useRstream(options) {
355
362
  } else if (event.type.startsWith("tunnel")) {
356
363
  setTunnels((previous) => {
357
364
  if (event.type === "tunnel.created") {
358
- return [...previous, event.object];
365
+ return [
366
+ ...previous.filter((item) => item.id !== event.object.id),
367
+ event.object
368
+ ];
359
369
  } else if (event.type === "tunnel.updated") {
370
+ if (!previous.some((tunnel) => tunnel.id === event.object.id))
371
+ return [...previous, event.object];
360
372
  return previous.map((tunnel) => {
361
373
  if (tunnel.id === event.object.id) {
362
374
  return event.object;
@@ -379,6 +391,7 @@ function useRstream(options) {
379
391
  onClose: () => {
380
392
  if (!runtime.active) return;
381
393
  runtime.watch = null;
394
+ setInventoryKey(null);
382
395
  schedule();
383
396
  }
384
397
  });
@@ -432,7 +445,13 @@ function useRstream(options) {
432
445
  return () => clearTimeout(timeout);
433
446
  }
434
447
  }, [authEnabled, connectionKey, state]);
435
- return { state, error, tunnels, clients };
448
+ const visible = authEnabled && inventoryKey === connectionKey && state === "connected";
449
+ return {
450
+ state,
451
+ error,
452
+ tunnels: visible ? tunnels : [],
453
+ clients: visible ? clients : []
454
+ };
436
455
  }
437
456
 
438
457
  // src/providers/rstream.tsx
package/dist/index.mjs CHANGED
@@ -5,10 +5,10 @@ import "./chunk-2JFL7TS5.mjs";
5
5
  import {
6
6
  RstreamProvider,
7
7
  useRstreamContext
8
- } from "./chunk-UQDRDSGV.mjs";
8
+ } from "./chunk-L4AWANNU.mjs";
9
9
  import {
10
10
  useRstream
11
- } from "./chunk-YZQKMOHW.mjs";
11
+ } from "./chunk-AHLVBJB3.mjs";
12
12
  export {
13
13
  RstreamProvider,
14
14
  WebTTYTerminal,
@@ -10,9 +10,7 @@ declare function useRstreamContext(): {
10
10
  type: "warning" | "danger";
11
11
  } | null;
12
12
  tunnels: {
13
- client_id: string;
14
- status: "online" | "offline";
15
- id: string;
13
+ client_id?: string | undefined;
16
14
  user_id?: string | undefined;
17
15
  workspace_id?: string | undefined;
18
16
  project_id?: string | undefined;
@@ -20,6 +18,8 @@ declare function useRstreamContext(): {
20
18
  plan?: string | undefined;
21
19
  provider?: string | undefined;
22
20
  region?: string | undefined;
21
+ status?: "online" | "offline" | undefined;
22
+ id?: string | undefined;
23
23
  creation_date?: string | Date | undefined;
24
24
  name?: string | undefined;
25
25
  type?: "bytestream" | "datagram" | undefined;
@@ -53,11 +53,12 @@ declare function useRstreamContext(): {
53
53
  challenge_mode?: boolean | undefined;
54
54
  }[];
55
55
  clients: {
56
- id: string;
57
- status: "online" | "offline";
56
+ id?: string | undefined;
57
+ status?: "online" | "offline" | undefined;
58
58
  user_id?: string | undefined;
59
59
  workspace_id?: string | undefined;
60
60
  project_id?: string | undefined;
61
+ endpoint?: string | undefined;
61
62
  cluster_id?: string | undefined;
62
63
  plan?: string | undefined;
63
64
  provider?: string | undefined;
@@ -10,9 +10,7 @@ declare function useRstreamContext(): {
10
10
  type: "warning" | "danger";
11
11
  } | null;
12
12
  tunnels: {
13
- client_id: string;
14
- status: "online" | "offline";
15
- id: string;
13
+ client_id?: string | undefined;
16
14
  user_id?: string | undefined;
17
15
  workspace_id?: string | undefined;
18
16
  project_id?: string | undefined;
@@ -20,6 +18,8 @@ declare function useRstreamContext(): {
20
18
  plan?: string | undefined;
21
19
  provider?: string | undefined;
22
20
  region?: string | undefined;
21
+ status?: "online" | "offline" | undefined;
22
+ id?: string | undefined;
23
23
  creation_date?: string | Date | undefined;
24
24
  name?: string | undefined;
25
25
  type?: "bytestream" | "datagram" | undefined;
@@ -53,11 +53,12 @@ declare function useRstreamContext(): {
53
53
  challenge_mode?: boolean | undefined;
54
54
  }[];
55
55
  clients: {
56
- id: string;
57
- status: "online" | "offline";
56
+ id?: string | undefined;
57
+ status?: "online" | "offline" | undefined;
58
58
  user_id?: string | undefined;
59
59
  workspace_id?: string | undefined;
60
60
  project_id?: string | undefined;
61
+ endpoint?: string | undefined;
61
62
  cluster_id?: string | undefined;
62
63
  plan?: string | undefined;
63
64
  provider?: string | undefined;
@@ -67,6 +67,7 @@ function useRstream(options) {
67
67
  const [state, setState] = React.useState("disconnected");
68
68
  const [error, setError] = React.useState(null);
69
69
  const { reconnectTimeout = 1e3, errorTimeout = 5e3 } = options || {};
70
+ const [inventoryKey, setInventoryKey] = React.useState(null);
70
71
  const [clients, setClients] = React.useState([]);
71
72
  const [tunnels, setTunnels] = React.useState([]);
72
73
  const authEnabled = hasAuth(options);
@@ -104,13 +105,19 @@ function useRstream(options) {
104
105
  onEvent: (event) => {
105
106
  if (!runtime.active) return;
106
107
  if (event.type === "state.initial") {
108
+ setInventoryKey(connectionKey);
107
109
  setClients(event.object.clients);
108
110
  setTunnels(event.object.tunnels);
109
111
  } else if (event.type.startsWith("client")) {
110
112
  setClients((previous) => {
111
113
  if (event.type === "client.created") {
112
- return [...previous, event.object];
114
+ return [
115
+ ...previous.filter((item) => item.id !== event.object.id),
116
+ event.object
117
+ ];
113
118
  } else if (event.type === "client.updated") {
119
+ if (!previous.some((client) => client.id === event.object.id))
120
+ return [...previous, event.object];
114
121
  return previous.map((client) => {
115
122
  if (client.id === event.object.id) {
116
123
  return event.object;
@@ -127,8 +134,13 @@ function useRstream(options) {
127
134
  } else if (event.type.startsWith("tunnel")) {
128
135
  setTunnels((previous) => {
129
136
  if (event.type === "tunnel.created") {
130
- return [...previous, event.object];
137
+ return [
138
+ ...previous.filter((item) => item.id !== event.object.id),
139
+ event.object
140
+ ];
131
141
  } else if (event.type === "tunnel.updated") {
142
+ if (!previous.some((tunnel) => tunnel.id === event.object.id))
143
+ return [...previous, event.object];
132
144
  return previous.map((tunnel) => {
133
145
  if (tunnel.id === event.object.id) {
134
146
  return event.object;
@@ -151,6 +163,7 @@ function useRstream(options) {
151
163
  onClose: () => {
152
164
  if (!runtime.active) return;
153
165
  runtime.watch = null;
166
+ setInventoryKey(null);
154
167
  schedule();
155
168
  }
156
169
  });
@@ -204,7 +217,13 @@ function useRstream(options) {
204
217
  return () => clearTimeout(timeout);
205
218
  }
206
219
  }, [authEnabled, connectionKey, state]);
207
- return { state, error, tunnels, clients };
220
+ const visible = authEnabled && inventoryKey === connectionKey && state === "connected";
221
+ return {
222
+ state,
223
+ error,
224
+ tunnels: visible ? tunnels : [],
225
+ clients: visible ? clients : []
226
+ };
208
227
  }
209
228
 
210
229
  // src/providers/rstream.tsx
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  RstreamProvider,
3
3
  useRstreamContext
4
- } from "../chunk-UQDRDSGV.mjs";
5
- import "../chunk-YZQKMOHW.mjs";
4
+ } from "../chunk-L4AWANNU.mjs";
5
+ import "../chunk-AHLVBJB3.mjs";
6
6
  export {
7
7
  RstreamProvider,
8
8
  useRstreamContext
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rstreamlabs/react",
3
- "version": "1.10.16",
3
+ "version": "2.0.1",
4
4
  "description": "React hooks and components for building rstream-enabled UIs.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,7 +42,8 @@
42
42
  "build": "tsup",
43
43
  "clean": "rm -rf dist",
44
44
  "lint": "eslint \"./**/*.ts*\"",
45
- "type-check": "tsc --noEmit"
45
+ "type-check": "tsc --noEmit",
46
+ "test": "node --test test/*.test.cjs"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@turbo/gen": "^2.10.11",
@@ -55,8 +56,8 @@
55
56
  "typescript-config": "*"
56
57
  },
57
58
  "dependencies": {
58
- "@rstreamlabs/rstream": "3.10.0",
59
- "@rstreamlabs/tunnels": "3.10.2",
59
+ "@rstreamlabs/rstream": "3.11.1",
60
+ "@rstreamlabs/tunnels": "4.0.1",
60
61
  "@rstreamlabs/webtty": "1.11.2",
61
62
  "@xterm/addon-fit": "^0.11.0",
62
63
  "@xterm/addon-unicode11": "^0.9.0",