@protobase/cli 0.60.1 → 0.62.0

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.60.1";
2
+ var version = "0.62.0";
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.60.1",
3
+ "version": "0.62.0",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -42,12 +42,12 @@
42
42
  "dependencies": {
43
43
  "@better-auth/core": "^1.7.12",
44
44
  "@hono/node-server": "^2.1.3",
45
- "@protobase/config": "0.60.1",
46
- "@protobase/layout": "0.60.1",
47
- "@protobase/query": "0.60.1",
48
- "@protobase/schema": "0.60.1",
49
- "@protobase/server": "0.60.1",
50
- "@protobase/ui": "0.60.1",
45
+ "@protobase/config": "0.62.0",
46
+ "@protobase/layout": "0.62.0",
47
+ "@protobase/query": "0.62.0",
48
+ "@protobase/schema": "0.62.0",
49
+ "@protobase/server": "0.62.0",
50
+ "@protobase/ui": "0.62.0",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -7,6 +7,7 @@ Decide who may read and change which records and fields.
7
7
  - [Roles and capabilities](../reference/access.md#capabilities): Roles defined in code grant capabilities per resource and action. A project with roles denies anything not granted.
8
8
  - [Field and row limits](../reference/access.md#capabilities): A role can be limited to listed fields and to rows that match a filter. A field added later stays hidden from that role until it is listed, and the server does not start with a limit on a field or resource that does not exist.
9
9
  - [Capability checks](../reference/access.md#wildcards-in-has-can-and-holds): Your code asks whether a user holds one capability, or all of a wildcard such as `vms.*`, and a check that could pass by accident is refused.
10
+ - [Named grants for secrets](../reference/access.md#resources-that-need-named-grants): A resource that holds secrets, such as webhook subscriptions, can be left out of wildcards like `*.read`, so only admins and roles that name it reach it.
10
11
  - [Field rules](../reference/access.md#field-rules-or-field-lists): Single fields, such as a cost price, can be hidden from every role that lacks a given capability.
11
12
  - [Owned records](../reference/data-config.md#access): Users can be limited to the records they own, or that their team owns, through an owner field. The server does not start when that field cannot hold the users' ids.
12
13
  - [Rules on the stored record](../reference/data-config.md#access): A rule can read the record as it is stored, such as one that refuses changes to a locked invoice.
@@ -25,7 +25,7 @@ Sign-in methods, users, roles, organizations and tokens.
25
25
  - [Staff sign-in](../reference/auth.md#staff-sign-in): The team that runs an app signs in as a person to help them, with a reason and a log entry.
26
26
  - [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
27
27
  - [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
28
- - [Status](../reference/status.md) (beta): People set themselves busy or do not disturb, with a text of their own such as "Having lunch" and a time it clears, from the user menu; the people they share an organization with see it beside their name.
28
+ - [Status](../reference/status.md) (beta): People set themselves busy or do not disturb, with a text of their own such as "Having lunch" and a time it clears, from the user menu; the people they share an organization with see it beside their name, with your app's online or away mark on the members page and in the sidebar.
29
29
  - [API tokens](../reference/auth.md#tokens-and-roles): A signed-in session gets short-lived tokens for the API.
30
30
  - [Immediate revocation](../reference/auth.md#when-a-token-stops-working): A ban, removed role or ended session takes effect on the next request.
31
31
  - [Signing key rotation](../reference/auth.md#signing-keys): The keys that sign the tokens are replaced every 30 days on their own, and old ones keep verifying the tokens they signed for a week.
@@ -37,11 +37,23 @@ A field is readable when the role's list allows it and the field's own [rule](#f
37
37
 
38
38
  ### Wildcards in has, can and holds
39
39
 
40
- A wildcard in a role grants everything it stands for: `*.read` reads every resource. What a check asks for is different, so the checks take wildcards in one place only:
40
+ A wildcard in a role grants everything it stands for: `*.read` reads every resource, except those that hold secrets and take only [named grants](#resources-that-need-named-grants). What a check asks for is different, so the checks take wildcards in one place only:
41
41
 
42
42
  - `roles.has(user, 'vms.update')` and `roles.can('vms.update')` ask for one capability, in any scope or limit the role holds it. They refuse a wildcard, at compile time and when called, since `vms.*` would pass for a role holding only `vms.read`: ask for each capability instead.
43
43
  - `roles.holds(user, 'vms.*')` asks for all of it, in every row and field: a role holding `*` or `vms.*` passes, one holding `vms.read`, `*.read`, `vms.update.own` or a `vms.update` limited to fields or rows does not. A scope asks for those rows at least: `orders.read.own` passes for a role holding `orders.read.own`, `orders.read` or `*.read`. API functions' `capability` is checked this way.
44
44
 
45
+ ### Resources that need named grants
46
+
47
+ A resource with `.explicitGrants()` is left out of wildcards over resources: only `*` itself and capabilities that name it, such as `webhook_subscriptions.read` or `webhook_subscriptions.*`, grant it, never `*.read` or `*.*`. A role written as "read everything" then reads nothing of it. The [webhook resources](webhooks.md#subscriptions-in-the-admin-app) are such resources, since their URLs and secrets let whoever reads them call the receivers. Mark a resource of your own this way when its records hold secrets.
48
+
49
+ ```ts
50
+ defineRoles({
51
+ admin: ['*'],
52
+ viewer: ['*.read'], // reads no webhook subscription
53
+ integrations: ['*.read', 'webhook_subscriptions.*', 'webhook_deliveries.read', 'webhook_deliveries.update'],
54
+ })
55
+ ```
56
+
45
57
  ## Anonymous access
46
58
 
47
59
  The role `anonymous` is what a request without a token acts as. A project without it answers such requests `401`, as always.
@@ -69,6 +69,7 @@ export const repairs = resource('repairs')
69
69
  | `.validate((record) => issues)` | A rule over the whole record, run after the field checks on every create and update. It returns `[{ field, message }]` or `undefined`; issues answer `400` with the field named. |
70
70
  | `.access({ ... })` | Rules per operation. See [Access](#access). |
71
71
  | `.events((e, r) => [...])` | What changes of its records mean, such as `orders.created`, captured in the database for every write. See [Events](events.md). |
72
+ | `.explicitGrants()` | Leaves the resource out of role wildcards such as `*.read`: only `*` and capabilities that name it grant it. For resources whose records hold secrets. See [Resources that need named grants](access.md#resources-that-need-named-grants). |
72
73
  | `.history()` | Keeps every change of its records with who made it, shown on the record page and listed for admins as Activity. See [Record history](history.md). |
73
74
  | `.comments()` | Lets whoever may read a record comment on it and @mention others who may, who are emailed; shown on the record page and listed for admins. See [Record comments](comments.md). |
74
75
 
@@ -106,8 +106,20 @@ export default defineUi({ marks: { unread: useUnreadMarks } })
106
106
  | `strong` | The record's title shows bold and in the foreground colour, not muted. |
107
107
  | `count` | A small badge at the end of the row, the pill of the notification bell's count; `99+` above 99, none at 0. |
108
108
  | `label` | Added to the record's name for screen readers and its tooltip, such as "3 mentions". |
109
+ | `person` | The user id of the one person the record stands for, such as the other person in a direct message. The row shows their online or away dot, from the app's [presence](status.md#in-the-app), and their busy or do-not-disturb mark beside its title, and adds them and their status text to its name and tooltip. |
109
110
 
110
- The records keep the group's order. A mark is presentation only: it is no field, filter or sort key, and the server computes nothing for it; what it counts comes from the requests the hook makes as the reader. Icon sidebars show no records, so no marks either. A group whose name no UI config registers, such as a plugin's that is turned off, shows its records unmarked. <gap>A marks hook that throws cannot be confined to its own group because an error boundary around a group's marks is not implemented, so it stops the sidebar as a throwing component would.</gap>
111
+ A direct message's mark names the other person:
112
+
113
+ ```tsx
114
+ const useConversationMarks = () => {
115
+ // conversation_partners: a resource of the project's own, the other person in each of the reader's direct messages
116
+ const partners = useList('conversation_partners', { pageSize: 100 })
117
+ if (partners.isPending) return
118
+ return Object.fromEntries(partners.items.map((row) => [String(row.conversation_id), { person: String(row.user_id) }]))
119
+ }
120
+ ```
121
+
122
+ A row shows one person's presence; a row for a group names no one and shows none. The records keep the group's order. A mark is presentation only: it is no field, filter or sort key, and the server computes nothing for it; what it counts comes from the requests the hook makes as the reader. Icon sidebars show no records, so no marks either. A group whose name no UI config registers, such as a plugin's that is turned off, shows its records unmarked. <gap>A marks hook that throws cannot be confined to its own group because an error boundary around a group's marks is not implemented, so it stops the sidebar as a throwing component would.</gap>
111
123
 
112
124
  ### Checks
113
125
 
@@ -64,19 +64,59 @@ Your own server code asks the same question with `onDoNotDisturb(db, statusNames
64
64
 
65
65
  ## In the app
66
66
 
67
- The organization's members page shows each member's status beside their name. `useMembers()` from `@protobase/ui` gives each member their `status` when they have one, beside their name and photo, and `useStatuses()` the statuses alone. `StatusMark` draws a status beside a name: a mark for busy, one for do not disturb, and the text, in full or, with `textShown="hover"`, on hover. Who is online or away is each app's own, from its [presence](channels.md#presence); pass its mark as `presence`, and `StatusMark` draws it first, so the two sit side by side:
67
+ The members page and the sidebar can show who is online or away beside each person's status. Who is online or away is your app's own, from its [presence](channels.md#presence), and you give it to Protobase once, as `presence` in `protobase.ui.tsx`: a React hook that answers each person's presence, `'online'` or `'away'`, by their user id, and leaves out someone with no page open. Protobase calls it once while the app shows, so it may use your own [channels](channels.md) and live updates, and the marks follow it without a reload; Protobase opens no connection of its own for it, and a channel shares the socket the page already has.
68
68
 
69
69
  ```tsx
70
- import { StatusMark, useMembers } from '@protobase/ui'
70
+ // protobase.ui.tsx
71
+ import { useEffect, useState } from 'react'
72
+ import { defineUi, useClient, type Presence } from '@protobase/ui'
73
+
74
+ // Each page of the app tracks itself on the channel of its workspace's record: online, or away when the tab is hidden.
75
+ const usePeoplePresence = () => {
76
+ const client = useClient()
77
+ const [presence, setPresence] = useState<Record<string, Presence>>()
78
+ useEffect(() => {
79
+ const lobby = client.channel('workspaces', 1)
80
+ const track = () => void lobby.track({ away: document.hidden })
81
+ const stop = lobby.onPresence((entries) => {
82
+ const byUser: Record<string, Presence> = {}
83
+ for (const entry of entries) {
84
+ const user = entry.user === null ? undefined : String(entry.user)
85
+ // Someone with one page in view is online, whatever their other pages say.
86
+ if (user === undefined || byUser[user] === 'online') continue
87
+ byUser[user] = (entry.state as { away: boolean }).away ? 'away' : 'online'
88
+ }
89
+ setPresence(byUser)
90
+ })
91
+ track()
92
+ document.addEventListener('visibilitychange', track)
93
+ return () => {
94
+ document.removeEventListener('visibilitychange', track)
95
+ stop()
96
+ lobby.leave()
97
+ }
98
+ }, [client])
99
+ return presence
100
+ }
101
+
102
+ export default defineUi({ presence: usePeoplePresence })
103
+ ```
104
+
105
+ The organization's members page then shows each member as online or away beside their status, and a sidebar record whose mark names a person, such as a direct message, shows that person's presence and status beside its title, with the status text on hover and in the row's name (see [Marks per reader](sidebar.md#marks-per-reader)). Someone the hook leaves out shows no presence, and without the hook nothing shows but the statuses. <gap>A sidebar row cannot show the presence of several people, such as a group conversation's, because a mark naming more than one person is not implemented.</gap>
106
+
107
+ `useMembers()` from `@protobase/ui` gives each member their `status` when they have one, beside their name and photo, `useStatuses()` the statuses alone, and `usePresence()` the presence your hook gives, by user id. `StatusMark` draws them beside a name: the online or away dot for `presence`, a mark for busy, one for do not disturb, and the text, in full or, with `textShown="hover"`, on hover:
108
+
109
+ ```tsx
110
+ import { StatusMark, useMembers, usePresence } from '@protobase/ui'
71
111
 
72
- export const Person = ({ id, online }: { id: string; online: boolean }) => {
112
+ export const Person = ({ id }: { id: string }) => {
73
113
  const person = useMembers().member(id)
114
+ const presence = usePresence()?.[id]
74
115
  if (!person) return null
75
- const dot = <span role="img" aria-label={online ? 'Online' : 'Away'} className={online ? 'size-2 rounded-full bg-success' : 'size-2 rounded-full bg-muted'} />
76
116
  return (
77
117
  <span className="flex items-center gap-1.5">
78
118
  {person.name}
79
- <StatusMark status={person.status} presence={dot} textShown="hover" />
119
+ <StatusMark status={person.status} presence={presence} textShown="hover" />
80
120
  </span>
81
121
  )
82
122
  }
@@ -116,7 +116,7 @@ It adds two pages, over a `webhooks` schema that [`protobase migration`](cli.md#
116
116
  - **Webhook subscriptions** (`webhook_subscriptions`, the table `webhooks.subscriptions`): a name, the events (`orders.created orders.large`, or `orders.*`), the URL, a filter, extra headers, full or thin payload, and whether it is enabled. The server sets the tenant and the owner, the person who made it, and makes the secret, which only a [reveal](api.md#sensitive-fields-and-audit) shows. Saving checks the events and the filter against the resources, and refuses a URL whose host is a private, loopback or link-local address.
117
117
  - **Webhook deliveries** (`webhook_deliveries`, a view over the delivery jobs): the deliveries that wait for their next try or failed for good, with their last error. A delivery leaves the list once it succeeds.
118
118
 
119
- Both are scoped to the tenant like any resource with `.tenant()`, and their access decides who may do what: `webhook_subscriptions.create`, `webhook_deliveries.update` and so on, as for the app's own resources.
119
+ Both are scoped to the tenant like any resource with `.tenant()`, and their access decides who may do what: `webhook_subscriptions.create`, `webhook_deliveries.update` and so on, as for the app's own resources. A role's wildcard over resources, such as `*.read`, grants none of them: their URLs and secrets let whoever reads them call the receivers, so with roles only admins (`*`) and roles that [name them](access.md#resources-that-need-named-grants) manage webhook subscriptions.
120
120
 
121
121
  A subscription made here **delivers as its owner**, with the role they act with now in its tenant (the [active role](auth.md#active-role) they last chose, else their first): only records and fields it may read. Letting people make subscriptions therefore grants them nothing they could not read already. The roles are read from the app's sign-in; a project that signs people in otherwise exports its own, `async ({ id, tenant }) => [...]`, as the default of `webhooks/owner-roles.ts`.
122
122