@protobase/cli 0.46.5 → 0.46.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.46.5";
2
+ var version = "0.46.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.46.5",
3
+ "version": "0.46.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": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.12",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.46.5",
40
- "@protobase/query": "0.46.5",
41
- "@protobase/schema": "0.46.5",
42
- "@protobase/server": "0.46.5",
43
- "@protobase/ui": "0.46.5",
39
+ "@protobase/layout": "0.46.7",
40
+ "@protobase/query": "0.46.7",
41
+ "@protobase/schema": "0.46.7",
42
+ "@protobase/server": "0.46.7",
43
+ "@protobase/ui": "0.46.7",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -11,6 +11,7 @@ Decide who may read and change which records and fields.
11
11
  - [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
12
  - [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.
13
13
  - [Write-only fields](../reference/access.md#write-only-fields): A role can set a field it can never read back, such as a secret only a worker reads. The admin app edits it only where the layout names it, with no stored value to reveal.
14
+ - [Lists across organizations](../reference/access.md#lists-across-organizations) (beta): One list shows the records of every organization someone is a member of, each read with their role there, with the organization as a filter. Opening a record of another organization switches to it.
14
15
  - [Access through a parent record](../reference/access.md#records-that-belong-to-another): Writing a child record can require access to the record it belongs to.
15
16
  - [Anonymous access](../reference/access.md#anonymous-access): Visitors without an account can read listed fields of chosen records, such as a public product catalog, and send the public forms you open to them.
16
17
  - [Public browsing](../reference/access.md#browsing-the-admin-app): With anonymous access on, visitors browse what they may read in the admin app without signing in, read-only, with a Sign in button.
@@ -6,6 +6,7 @@ The sidebar, the user menu, the bottom bar on phones and the global search.
6
6
 
7
7
  - [Sidebar](../reference/sidebar.md): Resources and pages in groups, in the order you set.
8
8
  - [Recent records](../reference/sidebar.md#recent-records): A sidebar entry lists a few records under it with status dots.
9
+ - [The current organization](../reference/sidebar.md#the-current-organization): A sidebar entry opens its list on the organization you work in, which you can clear to see every organization you are a member of.
9
10
  - [User menu](../reference/user-menu.md): Account pages, help links, security settings, the theme switch and Sign out.
10
11
  - [Bottom bar](../reference/bottom-bar.md): On phones, tabs along the bottom for each role's main screens.
11
12
  - [Global search](../reference/client.md#global-search): A search box, also on Cmd+K or Ctrl+K, finds records in every resource and jumps to pages and New forms.
@@ -167,6 +167,29 @@ export const operations = resource('operations')
167
167
  - **The parent is locked until the write commits** (`FOR NO KEY UPDATE`), so a VM handed to someone else or deleted at the same moment is waited for and checked again. That is the cost: writes of records under one parent, and through an `update` parent under one ancestor, run one after another. The server's database role needs `UPDATE` on the parent's table to take the lock. Two writes that lock the same records in opposite orders, such as two batches writing under VM A then B and B then A, can deadlock: Postgres rolls one back, which answers `409` and writes nothing, and the client sends it again.
168
168
  - The record page and `/api/meta` count the check, so the admin app offers no Edit or Delete the server would refuse. `/api/sb/rest/v1` does not use Protobase's access rules at all, so this check is not part of it.
169
169
 
170
+ ## Lists across organizations
171
+
172
+ :::caution[Beta]
173
+ <gap>A list across organizations hears live changes of the session's organization only; changes in the others show once it is read again.</gap>
174
+ :::
175
+
176
+ With [organizations](auth.md#organizations), a session works in one organization and a `.tenant` resource shows only its rows. A resource whose tenant is declared with `across: 'memberships'` lists the rows of every organization the person is a member of instead, so one list shows, say, their apps in each:
177
+
178
+ ```ts
179
+ export const apps = resource('apps')
180
+ .table('platform.apps')
181
+ .fields({ id: f.uuid().filterable(), organization_id: f.relation('organizations').filterable(), name: f.text() })
182
+ .primaryKey((r) => r.id)
183
+ .tenant((r) => r.organization_id, { across: 'memberships' })
184
+ ```
185
+
186
+ - **Lists only.** A list, `:search` and `:seek`, their counts, facets, charts, groups, map and exports read across; the labels and photos they bring are read as their own resource lists, so across when it is declared so too. Reading one record, revealing a field, its history and comments, and every write (creates, updates, deletes, batches, imports and uploads) stay in the organization the session works in: a record of another one is a `404` there, and a create sets the session's organization, as before.
187
+ - **Each organization with the person's role there.** The rows of another organization are read with the role the person would act with there after a switch: the session's active role when they hold it there, globally or as a member, else their first role there. Its row filters apply to its rows only. An organization where that role cannot list the resource is left out, and so is one where it reads fewer of the resource's fields than the session's role, since the list shows the same fields for every row.
188
+ - **Members only.** An organization someone enters with a global role, without being a member, is not read across; the session's own organization always is. An outside app's token, such as an MCP client's, reads its own organization alone.
189
+ - **The tenant field is a filter.** The list has it as any other field, so `organization_id = "..."`, a facet or a column picks organizations. A caller who cannot read the tenant field lists their own organization alone. To open the sidebar entry on the current organization, which the person can then clear, see [The current organization](sidebar.md#the-current-organization).
190
+ - **Rows of another organization are read-only in the list.** Their `permissions` say `update: false` and `delete: false`. The admin app opens one by switching the session to its organization first: a record page the session's organization does not have looks the record up across the lists, for a resource with a key of one filterable field, so the page and everything on it are read in the record's own organization.
191
+ - **Where the memberships come from.** `betterAuthAuthenticator` with `auth` reads them from the store, once per request that lists across organizations. An [authenticator](auth.md#tokens-and-roles) of your own gives them as the session's `memberships`, a function answering `[{ tenant, roles }]`, and must answer only organizations the person is a member of. Without it, as with `jwksUrl` instead of `auth`, a list reads the session's organization alone.
192
+
170
193
  ## Restricted model and row filters
171
194
 
172
195
  [`resolveAccess`](https://docs.protobase.net/api/schema/functions/resolveaccess/) returns everything a request may do. Use [`restrictModel(model, access)`](https://docs.protobase.net/api/schema/functions/restrictmodel/) for everything user-facing (checking filters and sorts, queries, OpenAPI, `/meta`): hidden fields are gone, so they cannot be referenced, searched, sorted or leaked. Key columns always stay, because records are addressed by them.
@@ -516,7 +516,7 @@ It is Better Auth's organization plugin, with its tables named in snake_case (`o
516
516
 
517
517
  **Who gives which role.** Someone may give or take away a member's app role only if they hold it, in that organization or globally, or hold a role whose `grants` list it (`manager` above gives `accountant` without holding it); grants do not chain, and a superuser may give any. Only a superuser changes global roles. The creator of an organization becomes its owner with every app role (`creatorAppRoles`, default `'all'`), so they can give them on; for a role added later, list it in a role owners hold, or run `protobase organizations add-app-role <role> --to owners`.
518
518
 
519
- **The organization in the token.** A new session starts in the organization the person last worked in, else their oldest membership. `/api/auth/token` adds `org` (the organization), `org_role` and `app_roles` (the membership's, narrowed to the active role), read when the token is issued; a removed member's token, or one carrying an app role taken away, [stops working](#when-a-token-stops-working) on its next request. `betterAuthAuthenticator` makes `org` the tenant and `ctx.organization.id`, and adds `app_roles` to the global roles. `POST /api/auth/organization/switch` with `{ organizationId }` moves the session; the next token names the new organization, without signing in again. Someone with a global role may switch into any organization, without being a member, and sees there what those roles allow; each such entry is an `organization.entered` [audit event](api.md#audit-events). `GET /api/auth/organization/search?query=&offset=` lists every organization for them, ordered by slug, 20 at a time with the `total`, narrowed by text in the name or slug; the Organizations page shows it as All organizations. A list across organizations stays a resource without `.tenant`, readable by the global role.
519
+ **The organization in the token.** A new session starts in the organization the person last worked in, else their oldest membership. `/api/auth/token` adds `org` (the organization), `org_role` and `app_roles` (the membership's, narrowed to the active role), read when the token is issued; a removed member's token, or one carrying an app role taken away, [stops working](#when-a-token-stops-working) on its next request. `betterAuthAuthenticator` makes `org` the tenant and `ctx.organization.id`, and adds `app_roles` to the global roles. `POST /api/auth/organization/switch` with `{ organizationId }` moves the session; the next token names the new organization, without signing in again. Someone with a global role may switch into any organization, without being a member, and sees there what those roles allow; each such entry is an `organization.entered` [audit event](api.md#audit-events). `GET /api/auth/organization/search?query=&offset=` lists every organization for them, ordered by slug, 20 at a time with the `total`, narrowed by text in the name or slug; the Organizations page shows it as All organizations. A list across every organization stays a resource without `.tenant`, readable by the global role; a list across the organizations someone is a member of is a `.tenant` resource with `across: 'memberships'` (see [Lists across organizations](access.md#lists-across-organizations)).
520
520
 
521
521
  **Invitations.** Better Auth's `POST /api/auth/organization/invite-member` with `{ organizationId, email, role, appRoles }`; inviting again replaces the earlier invitation, and it works for `invitationDays` (default 7). The email links to `{baseURL}/-/invitation?token=…` (`invitationUrl`), with a token signed with `secret`, since members can read invitation ids; without a mailer, the answer carries the `link` to pass on. The link page shows `GET /api/auth/invitation?token=`, accepts with `POST /api/auth/invitation/accept` for someone signed in as the invited address, and makes an account with `POST /api/auth/invitation/sign-up` (`{ token, name, password? }`) for an address without one. Someone signed in sees the invitations for their own address with Better Auth's `GET /api/auth/organization/list-user-invitations`, on the organizations page, and accepts one there with `POST /api/auth/invitation/accept-own` (`{ invitationId }`). The link page and its sign-up serve [invitations to the app](#users-page) too. [Open sign-up](#open-sign-up) is not available with organizations: an invitation is the address someone vouched for.
522
522
 
@@ -59,7 +59,7 @@ export const repairs = resource('repairs')
59
59
  | `.fields({ ... })` | The columns, by field name. `name: null` ignores a column on purpose (scaffold writes it, so it does not offer the column again). Required. |
60
60
  | `.primaryKey((r) => r.id)` | The key, one field or a list (`(r) => [r.order_id, r.line_no]`). Required; records are addressed by it. |
61
61
  | `.softDelete((r) => r.deleted_at)` | A nullable timestamp or date: deleting sets it, lists leave such rows out, `:undelete` clears it. See [REST API](api.md#routes). |
62
- | `.tenant((r) => r.organization_id)` | The column that separates tenants: every query is limited to the caller's tenant, creates set it, and a request body may not. |
62
+ | `.tenant((r) => r.organization_id, { across? })` | The column that separates tenants: every query is limited to the caller's tenant, creates set it, and a request body may not. With `across: 'memberships'`, lists read every organization the person is a member of, each with their role there; see [Lists across organizations](access.md#lists-across-organizations). |
63
63
  | `.owner((r) => r.owner_id)` | The field holding the owning user's id, which `.own` and `.team` capabilities filter on (see [Access](#access)). The server does not start when its column cannot hold the signed-in users' ids, such as an integer column with Better Auth's text ids; see [user ids](auth.md#roles-and-access-in-the-api). |
64
64
  | `.search((r) => [r.number, r.name])` | The fields that `search("...")` and bare words in a filter match, and what the admin's [global search](client.md#global-search) looks in. Every word of the text must appear in one of them, ignoring case, and part of a word is enough: `port` finds "Portfolio". `r.phone.digitsEnd()` matches only the end of a field's digits instead, ignoring spaces, `+` and dashes, and only words written like phone numbers: `9623`, `47069623` and `+31 6 47069623` find "+31 6 47069623", `4706` and `+316` do not. Each field needs a pg_trgm index (`using gin (name gin_trgm_ops)`), a `digitsEnd` one on `regexp_replace(phone, '[^0-9]', '', 'g')`, or the API refuses the search. |
65
65
  | `.position((r) => r.position, { within?, after? })` | The integer field holding the records' order by hand, 1 the first, which a list's **Reorder** button changes by dragging; with `within: (r) => r.invoice_id`, a filterable relation, each parent's records have an order of their own, sorted in its related section; with `after`, a record never ranks above the records it depends on. The field must be sortable. See [Reordering by hand](ui-config.md#reordering-by-hand) and [Ranked after what they depend on](ui-config.md#ranked-after-what-they-depend-on). |
@@ -6,6 +6,19 @@ How sidebar entries are grouped, and how an entry lists recent records with stat
6
6
 
7
7
  The admin's sidebar has one entry per resource view, grouped by `nav.group` (default: the database schema) and sorted by `nav.order`. A view's [named lists](ui-config.md#more-than-one-list) are entries of their own, placed by their own `nav`. `nav({ hidden: true })` leaves a resource out, for line and link tables; a resource in the [user menu](user-menu.md) is left out too. [Composed pages](layouts.md#setup) have entries of their own, and groups that hold pages come first. A [remote resource](remote-resources.md) has its entry where its source's view places it; while its source cannot be reached, it sits under the source's label, marked "Cannot reach" with the source's name.
8
8
 
9
+ ## The current organization
10
+
11
+ For a resource whose lists read [across organizations](access.md#lists-across-organizations), `nav({ tenant: 'current' })` opens its entry on the organization the session works in, while the person can still clear or widen it:
12
+
13
+ ```ts
14
+ view<typeof apps>('apps')
15
+ .nav({ group: 'Platform', tenant: 'current' })
16
+ .list((r) => ({ columns: [r.name, r.organization_id, r.status], filter: 'isNull(parent_id)' }))
17
+ .filters((r, w) => [w.facets(r.organization_id)])
18
+ ```
19
+
20
+ `/meta` writes the session's organization into the list's opening filter, here `isNull(parent_id) AND organization_id = "<id>"`, and into the filter of its [recent records](#recent-records). Like any opening filter it applies when the address names no filter: the facet shows the organization chosen, and the person picks others or clears it, which lists every organization they are a member of. A link with its own filter replaces it, and switching organization opens the app again on the new one. A [named list](ui-config.md#more-than-one-list) takes `tenant` in its own `nav`. `createAdmin` refuses to start when the view has no `.list(...)`, or the resource has no `.tenant()` on a `.filterable()` field.
21
+
9
22
  ## Recent records
10
23
 
11
24
  An entry can list a few of its records under it, each with a status dot, so the ones that need attention are one click away:
@@ -53,7 +53,7 @@ export const repairsView = view<typeof repairs>('repairs')
53
53
  | `.list((r, d, c) => ({ columns, sort?, search?, filter?, editable?, displays?, default? }))` | The list's columns in order, fields or [related records](#related-records-in-a-list) (`c.related`); the `filter` it [opens with](#a-filter-the-list-opens-with); its starting `sort` as `[[field, 'asc' \| 'desc'], ...]`, on `.sortable()` fields; the fields the search box suggests, among the resource's `.search` fields, which decide what search matches on the server; the columns [edited in their cell](#editing-in-the-list); other ways to show it, see [List displays](#list-displays). `protobase build` fails on a sort or search field outside those. |
54
54
  | `.fields((r) => ({ name: r.name.label(...) }))` | Hints per field, below. Calls add up. |
55
55
  | `.help(text)` | A line under the list's title. |
56
- | `.nav({ group, order, hidden, recent })` | Where the resource sits in the sidebar, and its [recent-record group](sidebar.md#recent-records). |
56
+ | `.nav({ group, order, hidden, recent, tenant })` | Where the resource sits in the sidebar, its [recent-record group](sidebar.md#recent-records), and with `tenant: 'current'` that it opens on [the current organization](sidebar.md#the-current-organization). |
57
57
  | `.icon(name)` | Carried in `/meta` for apps that render their own shell; the admin picks sidebar icons by resource name. |
58
58
  | `.listOf((r) => r.listing_id)` | The list page shows the records this relation points at instead of the resource's own rows, such as the listings among a member's favorites. See [Favorites](#favorites). |
59
59
  | `.signIn({ title, description, benefits?, icon?, signUp? })` | What a visitor who is not signed in is told about the resource, in place of its list and by a card's favorite button. See [Sign-in prompts](#sign-in-prompts). |