@protobase/cli 0.81.6 → 0.81.7

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.
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.81.6";
2
+ var version = "0.81.7";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.81.6",
3
+ "version": "0.81.7",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,13 +43,13 @@
43
43
  "dependencies": {
44
44
  "@better-auth/core": "^1.7.12",
45
45
  "@hono/node-server": "^2.1.3",
46
- "@protobase/config": "0.81.6",
47
- "@protobase/layout": "0.81.6",
48
- "@protobase/query": "0.81.6",
49
- "@protobase/schema": "0.81.6",
50
- "@protobase/server": "0.81.6",
51
- "@protobase/ui": "0.81.6",
52
- "@protobase/workflows": "0.81.6",
46
+ "@protobase/config": "0.81.7",
47
+ "@protobase/layout": "0.81.7",
48
+ "@protobase/query": "0.81.7",
49
+ "@protobase/schema": "0.81.7",
50
+ "@protobase/server": "0.81.7",
51
+ "@protobase/ui": "0.81.7",
52
+ "@protobase/workflows": "0.81.7",
53
53
  "@react-email/render": "^2.1.0",
54
54
  "@scalar/hono-api-reference": "^0.12.10",
55
55
  "@sentry/vite-plugin": "^11.10.0",
@@ -4,15 +4,15 @@
4
4
 
5
5
  A signed-in user's browser reaches a TCP service only the app's server can reach, such as one on the workspace's private network, over an ordinary WebSocket.
6
6
 
7
- A TCP bridge lets a page of the app talk to a TCP service that only the app's server can reach, such as a server's VNC or SSH port, or a database, on the workspace's private network. The browser opens an ordinary WebSocket to the app, and the server connects to the service and passes the bytes through both ways. The user's device joins no network and installs no VPN client.
8
-
9
- A bridge only carries bytes. A console, a terminal or a database tool that speaks the service's protocol is a page or plugin of your own built on it.
10
-
11
7
  :::caution[Beta]
12
8
  <gap>A bridge token opens a bridge only on the server process that issued it because a token store shared between processes is not implemented.</gap>
13
9
  <gap>A page that signs in with a bearer token instead of the session cookie cannot open a bridge from a browser because function sockets do not take a token without a header.</gap>
14
10
  :::
15
11
 
12
+ A TCP bridge lets a page of the app talk to a TCP service that only the app's server can reach, such as a server's VNC or SSH port, or a database, on the workspace's private network. The browser opens an ordinary WebSocket to the app, and the server connects to the service and passes the bytes through both ways. The user's device joins no network and installs no VPN client.
13
+
14
+ A bridge only carries bytes. A console, a terminal or a database tool that speaks the service's protocol is a page or plugin of your own built on it.
15
+
16
16
  ## The access rule
17
17
 
18
18
  A bridge is an [API function](../guides/api-functions.md) whose handler is `tcpBridge({ target })`. `target(name, context)` is the app's access rule: given the name a page asks for, such as a server's record key, it answers where the caller may connect, `{ host, port, expiresInSeconds? }`, or `undefined` when they may not. `context` is the function's [context](../guides/api-functions.md#the-context), with the caller's `session` and `records`, so the rule can read a record as the caller. The function's own `roles` or `capability` decide who may call it at all.
@@ -45,10 +45,10 @@ export default defineFunction({ roles: ['mechanic', 'admin'] }, workshopConsole)
45
45
  ## Opening a bridge
46
46
 
47
47
  1. `POST /api/functions/<name>` with `{ "target": "<name>" }` runs the rule. It answers `201` with `{ token, open_by, expires_at }`, or a `404` problem for a target the caller may not reach, without connecting anywhere. A user has at most 20 tokens waiting to be used; asking for another drops their oldest.
48
- 2. A WebSocket to `/api/functions/<name>?token=<token>`, before `open_by`, 30 seconds after the token was issued, opens the bridge. The token opens one bridge, for the same caller only; a token used before, too late, or by someone else is a `404`. The rule runs again, then the server connects to the target, and a target that does not answer within 10 seconds is a `502` that names no address.
48
+ 2. A WebSocket to `/api/functions/<name>?token=<token>`, before `open_by`, 30 seconds after the token was issued, opens the bridge. The token opens one bridge, for the same caller only; a token used before, too late, or by someone else is a `404`. The rule runs again, then the server connects to the target, and a target that does not answer within 10 seconds is a `502` that names no address. A bridge whose `expires_at` passes, or whose target is withdrawn, while the rule runs or the server connects does not open either.
49
49
  3. Each binary message is written to the service as it is, and what the service sends comes back as binary messages, in order. A text message closes the bridge with `1003`.
50
50
 
51
- `client.bridges.open(name, target)` of [`@protobase/client`](client.md) does both steps and resolves to `{ socket, expiresAt }`, with the socket's binary as `ArrayBuffer`s:
51
+ `client.bridges.open(name, target)` of [`@protobase/client`](client.md) does both steps and resolves to `{ socket, expiresAt }`, with the socket's binary as `ArrayBuffer`s, as soon as the socket exists; wait for its `open` event before sending:
52
52
 
53
53
  ```ts title="docs-examples/bridges/open-truing-stand.ts"
54
54
  import { createClient } from '@protobase/client'
@@ -56,10 +56,15 @@ import { createClient } from '@protobase/client'
56
56
  const client = createClient()
57
57
 
58
58
  // A page of the app opens the truing stand's bridge and hands its bytes to a viewer of its own, such as a VNC client.
59
+ // `open` resolves as soon as the socket exists, so this waits for it to open before handing out its sender.
59
60
  export const openTruingStand = async (show: (bytes: Uint8Array) => void) => {
60
61
  const { socket, expiresAt } = await client.bridges.open('workshop-console', 'truing-stand')
61
62
  socket.onmessage = (event) => show(new Uint8Array(event.data as ArrayBuffer))
62
63
  socket.onclose = (event) => console.log('closed', event.code, event.reason, 'expires at', expiresAt)
64
+ await new Promise<void>((resolve, reject) => {
65
+ socket.addEventListener('open', () => resolve(), { once: true })
66
+ socket.addEventListener('close', () => reject(new Error('The truing stand could not be reached')), { once: true })
67
+ })
63
68
  return (bytes: ArrayBuffer) => socket.send(bytes)
64
69
  }
65
70
  ```
@@ -75,6 +80,6 @@ export const openTruingStand = async (show: (bytes: Uint8Array) => void) => {
75
80
 
76
81
  - **Expiry.** The server closes a bridge at its `expires_at`, whatever the rule answers since.
77
82
  - **The user leaves.** Closing the page closes the socket and the TCP connection with it. A client that vanishes without closing, such as a laptop gone to sleep, is closed once it misses a ping, within a minute. The caller is [checked again every minute](../guides/api-functions.md#who-may-open-one), as on every function socket.
78
- - **The app withdraws the target.** The rule runs again every minute while a bridge is open, and an `undefined` or a different `host` and `port` closes it. To close the open bridges to a target at once, call `withdraw(name)` on the bridge, such as `workshopConsole.withdraw('stock-db')`, from code in the same process.
83
+ - **The app withdraws the target.** The rule runs again every minute while a bridge is open, and an `undefined` or a different `host` and `port` closes it. To close the bridges to a target at once, open or still opening, call `withdraw(name)` on the bridge, such as `workshopConsole.withdraw('stock-db')`, from code in the same process.
79
84
 
80
- Data flows at the pace of the slower side: the server reads the next message only once the service took the last one, and reads from the service only once the page's socket took the last chunk.
85
+ Data flows at the pace of the slower side, one chunk in flight each way. The server writes the next message to the service once the service's connection has room again; until then later messages wait as on any function socket, which [stops reading from the page](../guides/api-functions.md#slow-readers-and-large-messages) above 1 MiB of them. It reads from the service again only once the page's socket took the last chunk.