@protobase/cli 0.81.4 → 0.81.6
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/dist/cli/package.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/SKILL.md +1 -0
- package/skills/protobase/references/features/api-functions.md +1 -0
- package/skills/protobase/references/reference/client.md +1 -1
- package/skills/protobase/references/reference/data-config.md +1 -1
- package/skills/protobase/references/reference/notifications.md +1 -1
- package/skills/protobase/references/reference/tcp-bridges.md +80 -0
package/dist/cli/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.81.
|
|
3
|
+
"version": "0.81.6",
|
|
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.
|
|
47
|
-
"@protobase/layout": "0.81.
|
|
48
|
-
"@protobase/query": "0.81.
|
|
49
|
-
"@protobase/schema": "0.81.
|
|
50
|
-
"@protobase/server": "0.81.
|
|
51
|
-
"@protobase/ui": "0.81.
|
|
52
|
-
"@protobase/workflows": "0.81.
|
|
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",
|
|
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",
|
|
@@ -103,6 +103,7 @@ Reference:
|
|
|
103
103
|
- When using components and action handlers of your own in layouts → read [Custom components](references/reference/custom-components.md)
|
|
104
104
|
- When building or loading plugins → read [Plugins](references/reference/plugins.md)
|
|
105
105
|
- When using resources another Protobase API serves → read [Remote resources](references/reference/remote-resources.md)
|
|
106
|
+
- When a signed-in user's page must reach a TCP service only the app's server can reach, such as one on the private network → read [TCP bridges](references/reference/tcp-bridges.md)
|
|
106
107
|
- When an app keeps tables its users add in its own database (`userTables`) → read [User tables](references/reference/user-tables.md)
|
|
107
108
|
- When setting the app's tokens, colors and fonts → read [Theme](references/reference/theme.md)
|
|
108
109
|
- When setting the app's name, icon, home-screen icons or install colours → read [App identity](references/reference/app-identity.md)
|
|
@@ -10,6 +10,7 @@ Endpoints of your own beside the REST API.
|
|
|
10
10
|
- [Roles for functions](../guides/api-functions.md#roles): A function can be limited to roles or a capability; in an app with roles, one with neither is open only to roles that hold everything.
|
|
11
11
|
- [Public functions and webhooks](../guides/api-functions.md#public-functions-and-webhooks): A function can be open to anyone, with helpers that check webhook signatures.
|
|
12
12
|
- [WebSockets](../guides/api-functions.md#websockets): A function can accept a WebSocket, and the caller is checked again every minute.
|
|
13
|
+
- [TCP bridges](../reference/tcp-bridges.md) (beta): A signed-in user's page reaches a TCP service on the app's private network, such as a server's console or a database, over a WebSocket, as an access rule the app writes allows, without a VPN client.
|
|
13
14
|
- [Calling a function](../guides/api-functions.md#calling-a-function): The typed client's `invoke` calls a function with the signed-in user's token, from an action or any page.
|
|
14
15
|
- [Work after the response](../guides/api-functions.md#work-after-the-response): A function can answer at once and finish its work afterwards, which a graceful stop waits for.
|
|
15
16
|
- [Hono apps](../guides/api-functions.md#hono-apps): A function with several routes can be a Hono app.
|
|
@@ -17,7 +17,7 @@ const { record, etag } = await api.get(orders, id)
|
|
|
17
17
|
await api.update(orders, id, { status: 'shipped' }, etag) // 412 rejects with PreconditionFailedError
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket).
|
|
20
|
+
Pass a resource builder to get its record type ([`InferRecord`](https://docs.protobase.net/api/schema/type-aliases/inferrecord/)), or a name for loose records. Filters are AIP-160 text or [`where`](https://docs.protobase.net/api/schema/variables/where/) results (printed with [`printFilter`](https://docs.protobase.net/api/schema/functions/printfilter/)), and a list whose query string passes 4,000 characters goes by `:search`. Errors are `ApiError` (`status`, `slug`, `errors`, `filterErrors` with spans, `blockedBy` for a delete other records point at), which `isApiError(error)` tells apart. Also: `search`, `create`, `remove`, `facets`, `series`, `histogram`, `map(resource, { latitude, longitude, zoom, filter?, orderBy?, fields? })` (the records in a map's view, or buckets of them, see [`:map`](api.md#maps)), `seek`, `reveal(resource, key, field)` (a [sensitive field](data-config.md#sensitive-fields)'s value), `generate(resource, key, action)` (runs an [AI action](ai.md#ai-actions) and resolves to the record as written), `meta(etag?, { signal? })`, `invoke(name, { body?, method?, path?, query? })` (one of the app's [API functions](../guides/api-functions.md#calling-a-function); its answer as parsed JSON, text, or a `Blob` for any other type), `history(resource, key, { pageSize?, pageToken? })` (a page of a record's [changes](history.md), newest first), `comments(resource, key, { pageSize?, pageToken? })`, `comment(resource, key, { body, mentions? })` and `mentionable(resource, key, query)` (a record's [comments](comments.md#the-endpoints), adding one, and the people it may mention), `form(name)`, `formChallenge(name)` and `submitForm(name, values, proof)` (a [public form](forms.md#routes)), `upload(resource, field, file, { onProgress?, signal? })` (a file for a [file field](files.md#uploading); its `value` goes in the next write, and `onProgress` uses XMLHttpRequest, since fetch reports no upload progress), `live({ onChanges, onResync, onRetry? })` (hears which records of the [live](live.md) resources change until the function it returns is called, connecting again by itself; every caller of one client shares one stream), `channel(resource, key)` (a record's [channel](channels.md#from-a-page), with its presence and broadcasts, every channel of the client on one socket), `bridges.open(name, target)` (a [TCP bridge](tcp-bridges.md#opening-a-bridge)'s socket, with when the server closes it).
|
|
21
21
|
|
|
22
22
|
With an absolute `baseUrl`, such as another app's `https://desk.example.com/api/v1`, the `url` of each [file](files.md) in a record the client answers is absolute too, on that API's origin, where the API answers a path on its own origin. `routedClient(own, sourceOf)` is one client over several APIs: each call about a resource goes to the client `sourceOf(resource)` gives, else to `own`, as the admin app does for [remote resources](remote-resources.md), and `sourceMeta(meta, source)` keeps the part of another API's `/meta` an app draws.
|
|
23
23
|
|
|
@@ -276,7 +276,7 @@ The rollup's records have these fields, all read-only:
|
|
|
276
276
|
|
|
277
277
|
Records the source soft deleted are left out. The migration creates the table in the rollup's schema, with a unique index on `(bucket, by...)` and an index on `(group, bucket)` per group, so a list filtered on the bucket, on a group or on both passes the [scan guard](api.md#safety). It writes `rollups.<table>_refresh(from timestamptz)`, which recomputes every bucket from the one `from` falls in, in one statement: it upserts their counts and sums and deletes those left without records. `select rollups.readings_hourly_refresh(now() - interval '2 hours')` brings the example up to date. When the rollup's declaration changes, the migration drops its table and creates and fills it again. The table and function of a rollup the config no longer has stay; a migration of your own drops them, in a deploy after the one that stops reading them.
|
|
278
278
|
|
|
279
|
-
Only the database writes a rollup's rows: creates, updates and deletes are refused whatever its rules say, and it cannot have soft delete, a manual order, an author, a parent or `.openExisting()`. Its access is its own `.access()`: the source's rules do not reach it, so give it rules that let read only those who may see every record of a group. Its tenant is the source's, which is why `by` includes it. The server does not start while a role reads only some of the source's records that a bucket mixes with others: `.own` or `.team` while `by` does not include the source's owner field, or a role's filter on fields outside `by`. <gap>A time rollup cannot group by an optional field because a bucket key with empty parts is not implemented.</gap> <gap>A time rollup cannot roll up a resource whose reads follow a parent because applying the parent's access to buckets is not implemented.</gap> <gap>
|
|
279
|
+
Only the database writes a rollup's rows: creates, updates and deletes are refused whatever its rules say, and it cannot have soft delete, a manual order, an author, a parent or `.openExisting()`. Its access is its own `.access()`: the source's rules do not reach it, so give it rules that let read only those who may see every record of a group. Its tenant is the source's, which is why `by` includes it. The server does not start while the source has its own `read` or `list` rule in `.access()`, whatever the rule returns, or while a role reads only some of the source's records that a bucket mixes with others: `.own` or `.team` while `by` does not include the source's owner field, or a role's filter on fields outside `by`. <gap>A time rollup cannot group by an optional field because a bucket key with empty parts is not implemented.</gap> <gap>A time rollup cannot roll up a resource whose reads follow a parent because applying the parent's access to buckets is not implemented.</gap> <gap>A time rollup cannot roll up a resource with its own `read` or `list` access rule because declaring the fields such a rule filters on is not implemented.</gap>
|
|
280
280
|
|
|
281
281
|
The server does not start while a rollup's table or function is missing or out of date, with a message that names the rollup; the migration fixes that. It stops with an error, without writing anything, when the table already exists as the project's own.
|
|
282
282
|
|
|
@@ -318,7 +318,7 @@ A send, as [above](#push-relay), with a credential that is not one of the relay'
|
|
|
318
318
|
|
|
319
319
|
The relay writes the credential's origin into every notification, over anything the send held: `origin` in the APNs payload, beside `url` and `user`, and in FCM's data. The mobile app opens a notification in the workspace of that origin, so one workspace cannot make a notification open another.
|
|
320
320
|
|
|
321
|
-
A credential sends to at most 20,000 devices in each clock hour, counting every handle of each send. A send that would go over is a `429` with a `Retry-After` until the next hour, and the workspace retries its devices.
|
|
321
|
+
A credential sends to at most 20,000 devices in each UTC clock hour, counting every handle of each send. A send that would go over is a `429` with a `Retry-After` until the next UTC hour, when the count starts again, and the workspace retries its devices.
|
|
322
322
|
|
|
323
323
|
## Your own parts
|
|
324
324
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<!-- Generated by scripts/protobase-skill.ts from docs/website/src/content/docs/reference/tcp-bridges.mdx: run `bun run docs:skill`, do not edit. -->
|
|
2
|
+
|
|
3
|
+
# TCP bridges
|
|
4
|
+
|
|
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
|
+
|
|
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
|
+
:::caution[Beta]
|
|
12
|
+
<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
|
+
<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
|
+
:::
|
|
15
|
+
|
|
16
|
+
## The access rule
|
|
17
|
+
|
|
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.
|
|
19
|
+
|
|
20
|
+
```ts title="docs-examples/bridges/workshop-console.ts"
|
|
21
|
+
import { defineFunction, tcpBridge } from '@protobase/server'
|
|
22
|
+
|
|
23
|
+
// The workshop's machines on the private network, by the name a page asks for.
|
|
24
|
+
const machines: Record<string, { host: string; port: number }> = {
|
|
25
|
+
'truing-stand': { host: '10.20.0.11', port: 5900 },
|
|
26
|
+
'stock-db': { host: '10.20.0.2', port: 5432 },
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// /api/functions/workshop-console: mechanics reach the truing stand's screen for an hour at a time; only admins reach
|
|
30
|
+
// the stock database, and only for ten minutes.
|
|
31
|
+
export const workshopConsole = tcpBridge({
|
|
32
|
+
target: (name, { session }) => {
|
|
33
|
+
const machine = machines[name]
|
|
34
|
+
if (!machine) return
|
|
35
|
+
if (name !== 'stock-db') return machine
|
|
36
|
+
return session.user.roles.includes('admin') ? { ...machine, expiresInSeconds: 600 } : undefined
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export default defineFunction({ roles: ['mechanic', 'admin'] }, workshopConsole)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`host` is any host name or address the server can reach. `expiresInSeconds` is how long the bridge stays open, from when its token was issued: a whole number of seconds up to a day, an hour by default.
|
|
44
|
+
|
|
45
|
+
## Opening a bridge
|
|
46
|
+
|
|
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.
|
|
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
|
+
|
|
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:
|
|
52
|
+
|
|
53
|
+
```ts title="docs-examples/bridges/open-truing-stand.ts"
|
|
54
|
+
import { createClient } from '@protobase/client'
|
|
55
|
+
|
|
56
|
+
const client = createClient()
|
|
57
|
+
|
|
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
|
+
export const openTruingStand = async (show: (bytes: Uint8Array) => void) => {
|
|
60
|
+
const { socket, expiresAt } = await client.bridges.open('workshop-console', 'truing-stand')
|
|
61
|
+
socket.onmessage = (event) => show(new Uint8Array(event.data as ArrayBuffer))
|
|
62
|
+
socket.onclose = (event) => console.log('closed', event.code, event.reason, 'expires at', expiresAt)
|
|
63
|
+
return (bytes: ArrayBuffer) => socket.send(bytes)
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## When a bridge closes
|
|
68
|
+
|
|
69
|
+
| Close code | Why |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `1000` | The service closed the connection. |
|
|
72
|
+
| `1008` | The bridge reached `expires_at`; open a new one with a new token. The app withdrew the target. The caller signed out or lost the function's roles. |
|
|
73
|
+
| `1011` | The connection to the service failed. |
|
|
74
|
+
| `1003` | The page sent a text message. |
|
|
75
|
+
|
|
76
|
+
- **Expiry.** The server closes a bridge at its `expires_at`, whatever the rule answers since.
|
|
77
|
+
- **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.
|
|
79
|
+
|
|
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.
|