@protobase/cli 0.133.2 → 0.133.4
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/dist/users/commands.js +5 -5
- package/dist/users/register.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/history-comments-and-live-updates.md +2 -0
- package/skills/protobase/references/guides/api-functions.md +2 -1
- package/skills/protobase/references/reference/live.md +35 -0
package/dist/cli/package.js
CHANGED
package/dist/users/commands.js
CHANGED
|
@@ -34,18 +34,18 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
|
-
* Creates the user (`createUserCommand`) and, with organizations, adds them to the organization `--organization` names
|
|
38
|
-
*
|
|
37
|
+
* Creates the user (`createUserCommand`) and, with organizations, adds them to the organization `--organization` names;
|
|
38
|
+
* without it none is chosen, not the default organization the other commands pin. The organization is resolved
|
|
39
39
|
* first, so an unknown one creates nobody.
|
|
40
40
|
*/
|
|
41
41
|
const createMemberCommand = async (api, options, deps, out) => {
|
|
42
42
|
if (options.allOrganizations && !api.organizationsOn) throw new Error("--all-organizations needs organizations: turn on auth.organizations in the config");
|
|
43
43
|
if (options.allOrganizations && options.organization !== void 0) throw new Error("Pass --organization or --all-organizations, not both");
|
|
44
44
|
const pin = options.organization === void 0 ? void 0 : await resolveOptionalPin(api, options, "users create");
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
45
|
+
const noneChosen = api.organizationsOn && !pin;
|
|
46
|
+
if (noneChosen && (options.orgRole !== void 0 || options.appRoles !== void 0)) throw new Error("--org-role and --app-roles need --organization <slug>: without it no organization is chosen");
|
|
47
47
|
const user = await createUserCommand(api, options, deps, out);
|
|
48
|
-
if (
|
|
48
|
+
if (noneChosen) out(`No organization chosen with --organization for ${user.email}\n`);
|
|
49
49
|
if (!pin || "every" in pin) return;
|
|
50
50
|
if (user.first && await api.isMember(pin.organization.id, user.email)) {
|
|
51
51
|
out(`${user.email} owns ${pin.organization.slug}\n`);
|
package/dist/users/register.js
CHANGED
|
@@ -22,7 +22,7 @@ const ask = async (question) => {
|
|
|
22
22
|
const finish = (code) => process.exit(code);
|
|
23
23
|
const registerUsers = (program) => {
|
|
24
24
|
const users = program.command("users").description("Manage the admin users of the project in the current directory");
|
|
25
|
-
pinOptions(users.command("create").description("Create a user; the first user is always an admin. With organizations, they join the organization --organization names
|
|
25
|
+
pinOptions(users.command("create").description("Create a user; the first user is always an admin. With organizations, they join the organization --organization names; without it none is chosen")).argument("<email>").option("--name <name>", "display name").option("--role <role>", "role for users after the first (default: the project's default role; see `users roles`)").option("--password-stdin", "read the password from stdin", false).option("--generate-password", "generate a strong password and print it once", false).option("--no-password", "no password: the user signs in by emailed code, passkey or a sign-in provider").option("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--org-role <role>", "with --organization: owner, admin or member there (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
|
|
26
26
|
const { readHidden, rejectPasswordArgument } = await import("./password.js");
|
|
27
27
|
rejectPasswordArgument(opts.password);
|
|
28
28
|
const [{ createMemberCommand }, api] = await Promise.all([import("./commands.js"), projectApi()]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.133.
|
|
3
|
+
"version": "0.133.4",
|
|
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.133.
|
|
47
|
-
"@protobase/layout": "0.133.
|
|
48
|
-
"@protobase/query": "0.133.
|
|
49
|
-
"@protobase/schema": "0.133.
|
|
50
|
-
"@protobase/server": "0.133.
|
|
51
|
-
"@protobase/ui": "0.133.
|
|
52
|
-
"@protobase/workflows": "0.133.
|
|
46
|
+
"@protobase/config": "0.133.4",
|
|
47
|
+
"@protobase/layout": "0.133.4",
|
|
48
|
+
"@protobase/query": "0.133.4",
|
|
49
|
+
"@protobase/schema": "0.133.4",
|
|
50
|
+
"@protobase/server": "0.133.4",
|
|
51
|
+
"@protobase/ui": "0.133.4",
|
|
52
|
+
"@protobase/workflows": "0.133.4",
|
|
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",
|
|
@@ -13,6 +13,8 @@ The changes of each record, comments on it, and pages that refresh as records ch
|
|
|
13
13
|
- [Mentions](../reference/comments.md#mentions): Mentioning a colleague in a comment sends them an email with a link to the record.
|
|
14
14
|
- [Comment moderation](../reference/comments.md#moderation): Admins find and delete comments across the app.
|
|
15
15
|
- [Live updates](../reference/live.md#what-a-page-hears): Open lists and record pages refresh within seconds when a record changes, including changes made outside the API.
|
|
16
|
+
- [Live tokens](../reference/live.md#live-tokens) (in development): A list or record read asked for with `Prefer: live` also returns an encrypted token that holds what the reader read and may read, with the read's snapshot, bound to their session. Subscribing with it is coming soon.
|
|
17
|
+
- [Refreshing access](../reference/live.md#refreshing-access) (in development): An API function tells a person's open pages to read again once their access changed, so they get new tokens.
|
|
16
18
|
- [Live views](../reference/live.md#resources-backed-by-a-view) (experimental): A resource backed by a view updates live when the tables it reads change.
|
|
17
19
|
- [Change stream](../reference/live.md#the-stream): Apps follow record changes over a stream that catches up after a reconnect.
|
|
18
20
|
- [Changes in the write-ahead log](../reference/events.md#what-the-write-ahead-log-carries) (in development): A reader of the database's write-ahead log learns who made each change and, when switched on, each schema change, from logical messages in the change's own transaction, and maps each table to its resource from the change model `protobase build` writes into the bundle's manifest.
|
|
@@ -54,9 +54,10 @@ The second argument of a handler (`c.env` in a [Hono app](#hono-apps)):
|
|
|
54
54
|
| `acceptWebSocket(events)` | Answers a WebSocket upgrade with a socket; return its response. See [WebSockets](#websockets). |
|
|
55
55
|
| `calls.join(member)` | The events of a member's socket in a call, for `acceptWebSocket`. See [Calls](../reference/calls.md). |
|
|
56
56
|
| `channels` | `channels.broadcast({ resource, key, event, payload })` sends to whoever is on a record's [channel](../reference/channels.md#from-the-server), as the server. |
|
|
57
|
+
| `live` | `live.refresh({ user })` tells a person's open pages to read again once their access changed. See [Refreshing access](../reference/live.md#refreshing-access). |
|
|
57
58
|
| `name` | The function's name. |
|
|
58
59
|
|
|
59
|
-
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls`, `channels` and `name`.
|
|
60
|
+
A [public function](#public-functions-and-webhooks) has only `db`, `caller()`, `acceptWebSocket`, `calls`, `channels`, `live` and `name`.
|
|
60
61
|
|
|
61
62
|
### The organization's tables
|
|
62
63
|
|
|
@@ -40,9 +40,44 @@ It is live data, not multiplayer editing: two people editing the same record sti
|
|
|
40
40
|
| `current` | Nothing new up to `cursor`. Sent first, and every 25 seconds. |
|
|
41
41
|
| `changes` | `changes`: `[{ resource, key, operation }]` in commit order, `operation` being `create`, `update`, `delete` or `undelete`. |
|
|
42
42
|
| `resync` | Changes went by that are no longer kept: read everything shown again. |
|
|
43
|
+
| `refresh` | The caller's access changed, through [`live.refresh`](#refreshing-access): read everything shown again. The stream then ends, so the page connects again with `?after=<cursor>` and hears what its access allows now. |
|
|
43
44
|
|
|
44
45
|
Connecting again with `?after=<cursor>` catches up on what was missed while disconnected. [`client.live({ onChanges, onResync })`](client.md) of `@protobase/client` follows the stream and connects again by itself, as the app does. However many callers of one client follow it, they share one stream, so a page with many live views holds one connection, which matters under HTTP/1.1, where a browser opens at most six to a host.
|
|
45
46
|
|
|
47
|
+
## Live tokens
|
|
48
|
+
|
|
49
|
+
:::caution[In development]
|
|
50
|
+
Reads give live tokens, but nothing takes them yet: subscribing with a token is coming soon.
|
|
51
|
+
:::
|
|
52
|
+
|
|
53
|
+
A list or record read of a live resource gives a live token on request: `GET /api/v1/<resource>`, `GET /api/v1/<resource>/<key>`, the list under a record and `:search` take RFC 7240 `Prefer: live`, or `?live=1` where a page cannot set headers. The answer then has `Preference-Applied: live` and the token in `Protobase-Live`. Without the request the server resolves and encrypts nothing. These reads answer `Vary: Prefer`, so a cache keeps the two answers apart, and the API's CORS allows `Prefer` and exposes `Protobase-Live` and `Preference-Applied`.
|
|
54
|
+
|
|
55
|
+
The token is a JWE (`dir`, A256GCM), so its holder can neither read nor change it. It holds:
|
|
56
|
+
|
|
57
|
+
| Claim | |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `resource` | The resource read. |
|
|
60
|
+
| `where` | What the read keeps to, as [filter](api.md#filters) text on the row alone: the soft delete, the tenant, the access row filter, the parents the caller must read, the caller's own filter, and a record read's key. Left out when nothing is kept out. |
|
|
61
|
+
| `fields` | The fields the read returned. |
|
|
62
|
+
| `snapshot` | The read's `pg_current_snapshot()`. The whole read runs in one REPEATABLE READ snapshot, so the token tells exactly which transactions the rows include. |
|
|
63
|
+
| `sub`, `sid` | The signed-in person and their sign-in session, which the token is bound to. |
|
|
64
|
+
| `anonymous` | `true` for a visitor's token, which is bound to no session. |
|
|
65
|
+
| `iat`, `exp` | When it was issued and when it expires. |
|
|
66
|
+
|
|
67
|
+
A signed-in person's token expires when their session ends, after an hour at most. A visitor's token lasts an hour, longer than any cache time of the API, which lets none. An API key, an outside app acting for a person and a caller without a session of the app get no token. The token is sealed with a key derived from the [relay](realtime-relay.md)'s ticket key, so an app without a relay gives none.
|
|
68
|
+
|
|
69
|
+
Conditions that read other rows are evaluated when the token is issued: a parent the caller must read, a `related()` term and a lookup field become the list of keys they match at that moment, such as `in(project_id, 4, 9)`. A record that starts to match one of them later is not in the token, and a role or membership change does not change a token already issued; [refresh](#refreshing-access) the person's pages instead.
|
|
70
|
+
|
|
71
|
+
The server gives no token, and no `Preference-Applied`, when it cannot write the read as conditions on the row alone. <gap>A read cannot get a live token when a record-level read rule decides it, or when it searches a lookup field, because writing those as conditions on the row alone is not implemented.</gap> <gap>A read cannot get a live token longer than 3,000 bytes, such as one whose parents resolve to many keys, because subscribing to a list of keys that long is not implemented.</gap>
|
|
72
|
+
|
|
73
|
+
### Refreshing access
|
|
74
|
+
|
|
75
|
+
:::caution[In development]
|
|
76
|
+
Pages read again on a refresh; the tokens they get are not taken by anything yet.
|
|
77
|
+
:::
|
|
78
|
+
|
|
79
|
+
`live.refresh({ user })`, on the context of an [API function](../guides/api-functions.md), also one served for supabase-js, and of a function a webhook subscription calls, tells the open pages of the user with that id to read everything they show again, which gives them new tokens for their access as it is now. Call it once a change of their roles or memberships has committed. It writes a notice in its own transaction, so a page that reconnects with `?after=` still gets it. In an app without a live resource or calls it does nothing.
|
|
80
|
+
|
|
46
81
|
## Resources backed by a view
|
|
47
82
|
|
|
48
83
|
:::caution[Experimental]
|