@protobase/cli 0.50.1 → 0.51.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.50.1";
2
+ var version = "0.51.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.50.1",
3
+ "version": "0.51.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": {
@@ -41,12 +41,12 @@
41
41
  "dependencies": {
42
42
  "@better-auth/core": "^1.7.12",
43
43
  "@hono/node-server": "^2.1.3",
44
- "@protobase/config": "0.50.1",
45
- "@protobase/layout": "0.50.1",
46
- "@protobase/query": "0.50.1",
47
- "@protobase/schema": "0.50.1",
48
- "@protobase/server": "0.50.1",
49
- "@protobase/ui": "0.50.1",
44
+ "@protobase/config": "0.51.0",
45
+ "@protobase/layout": "0.51.0",
46
+ "@protobase/query": "0.51.0",
47
+ "@protobase/schema": "0.51.0",
48
+ "@protobase/server": "0.51.0",
49
+ "@protobase/ui": "0.51.0",
50
50
  "@react-email/render": "^2.1.0",
51
51
  "@scalar/hono-api-reference": "^0.12.10",
52
52
  "@tailwindcss/vite": "^4.3.3",
@@ -190,6 +190,18 @@ export const apps = resource('apps')
190
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
191
  - **Where the memberships come from.** The authenticator of the app's sign-in (`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 `authenticate: { jwksUrl }` instead of `auth`, a list reads the session's organization alone.
192
192
 
193
+ ## Rules that read the record
194
+
195
+ A rule that reads its record, such as `read: (ctx, record) => record.owner_id === ctx.user.id`, is checked against the stored row wherever one record is read or written: a get, a reveal, history, comments, and every update and delete. The resolver calls each rule once without the record to learn whether it needs one; reading the record then, even as `record?.status` or through a default parameter, counts.
196
+
197
+ A list cannot run such a rule on each row without breaking its pages and counts, so a caller for whom the `read` or `list` rule reads the record may not list: a list, `:search`, `:seek`, their counts, aggregates, charts and map, exports, the labels of the records other lists point at, and the assistant's and MCP's list tool answer `403`, and a blocked delete does not name the resource. An explicit `list` rule beside such a `read` is refused too, since nothing proves it is as narrow. A caller whose verdict does not depend on the record, such as an admin under `ctx.user.roles.includes('admin') || record.owner_id === ctx.user.id`, lists as usual. To list, write the rule as a row filter, which a get and a list apply alike:
198
+
199
+ ```ts
200
+ .access({ read: (ctx) => where.eq('owner_id', ctx.user.id) })
201
+ ```
202
+
203
+ <gap>A resource whose read rule reads the record cannot be listed because declaring a row filter as the rule's list form is not implemented.</gap> <gap>A rollup of a readable record counts and adds up related records that their read rule or row filter hides because rollups are not computed per caller.</gap> These rules apply to `/api/v1` and what is built on it; `/api/sb/rest/v1` and its realtime use the tables' grants and RLS policies only.
204
+
193
205
  ## Restricted model and row filters
194
206
 
195
207
  [`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.
@@ -68,7 +68,7 @@ Making the query role needs `CREATEROLE` once, for the role that applies the mig
68
68
 
69
69
  `assistant/tools.ts` adds tools of the app's own, which the built-in backend offers after its two: its default export is an array of tools, found by that path when the app starts. A tool is `defineTool({ name, description, parameters, run })` from `@protobase/server`: `parameters` is the JSON Schema of its arguments, and `run(args, context)` returns the text the model reads. A name must be 1 to 64 letters, digits, `_` or `-`, and a name taken twice stops the server at startup. A backend elsewhere has its own tools, so the file does nothing there, nor with `assistant: false`. A tool's `annotations` are MCP's tool hints (`readOnlyHint`, `destructiveHint`, ...), which the dock ignores; the same tools can be offered over the app's [MCP endpoint](mcp.md#building-on-it).
70
70
 
71
- `context` holds the user's `session`, `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. `get`, `create`, `update` and `delete` each answer `{ record, etag }`, and `list` a page of records. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
71
+ `context` holds the user's `session`, `locale` (the language they read, `'en'` or `'nl'`, for the texts a tool shows them such as its approvals; set over MCP, absent in the dock), `show(part)` to add a part to the answer, `approve(request)` for an approval card, `conversation` (the dock's, absent over MCP), `resources()` (the resources the user may read, restricted to their fields, with their views), and `records`: `list(resource, params)` with the REST API's list parameters, `get(resource, key)`, `create(resource, data)`, `update(resource, key, data, { etag? })` (without an ETag it updates any version), `delete(resource, key, { etag? })` (soft on a resource with `.softDelete()`) and `softDeleteField(resource)` (the field a delete sets, or `undefined` when a delete removes the record) on the app's resources **as the user**, through their access rules, tenant scope, validation and write hooks, as in the REST API. `get`, `create`, `update` and `delete` each answer `{ record, etag }`, and `list` a page of records. `batch(operations)` runs the operations of a REST [batch write](api.md#batch-writes) in one transaction and answers its `results`; a refusal or a missing record rejects with an `HttpProblem`, whose `detail` a tool can return to the model as text.
72
72
 
73
73
  A tool with a [widget](#widget-parts) creates or finds what it is about, shows a widget with its id, and returns the id and the state at that moment:
74
74
 
@@ -355,7 +355,7 @@ Every builder, option and type that `@protobase/schema` exports has a doc commen
355
355
 
356
356
  Without rules everyone who can sign in may do everything. Rules come in three kinds, and the [Access](access.md) reference explains the defaults:
357
357
 
358
- - **Per operation** (`list`, `read`, `create`, `update`, `delete`): `.access({ update: rule })`. A rule returns `true`, `false`, or an AIP-160 filter that limits the rows, like row-level security. A rule that reads the record (`record.status`) is checked against the stored row.
358
+ - **Per operation** (`list`, `read`, `create`, `update`, `delete`): `.access({ update: rule })`. A rule returns `true`, `false`, or an AIP-160 filter that limits the rows, like row-level security. A rule that reads the record (`record.status`) is checked against the stored row on a get and a write; a caller it reads the record for may not list, so a rule that should list is a filter. See [Rules that read the record](access.md#rules-that-read-the-record).
359
359
  - **Per row**: a filter from a rule, or a `.own` or `.team` capability with `.owner(...)`: `.own` gives the records whose owner is the user, `.team` those owned by the users that `defineRoles(roles, { teamOf: (user) => ids })` returns for them.
360
360
  - **Per field**: `.access({ read, create, update })` on the field. Field rules see only the user, never a record, so the fields a user can read are the same for every row.
361
361
 
@@ -26,4 +26,6 @@ Numbers, amounts and dates use the conventions of the language: English as writt
26
26
 
27
27
  Every built-in screen is translated: the shell with its sidebar, top bar, search, notification bell, profile menu and bottom bar; the list page with all its displays (table, cards, board, calendar, timeline and map), filters, search, sort, imports and exports; the record page with its actions, related lists, history, comments, gallery, saving, conflicts and deleting; the create page and composed pages; saved searches and favorites; the sign-in, sign-up and two-factor screens, the account and sign-in policy pages, and the organization, people and invitation pages; public forms; and the messages, toasts and confirmations around them. So are counts, relative times ("5 minutes ago"), yes, no and the other values the app writes itself, and the notices shown while the app loads.
28
28
 
29
- The texts a plugin or the server writes itself, such as an error message the API sends back or why a plugin could not be loaded, show as they are written.
29
+ The approvals an AI client asks for over [MCP](mcp.md#writes) are translated too, with their buttons and the refusal for a client that cannot ask: in the app's `locale`, or else in the language the client's request accepts.
30
+
31
+ The other texts a plugin or the server writes itself, such as an error message the API sends back or why a plugin could not be loaded, show as they are written.
@@ -70,7 +70,7 @@ export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { writes: true }
70
70
 
71
71
  Each write goes through the REST API as the person: their role's access rules, `validate`, write hooks, events and webhooks apply, so the client can do only what the person may do in the app.
72
72
 
73
- Before each write the client asks the person to approve it, showing the resource and the data, or for a delete the resource, the key and whether the record can be restored, through MCP's form elicitation. For a resource without a soft delete, the approval says plainly that the delete cannot be undone. Nothing is written until they approve, and declining writes nothing. A client's own setting that always allows a tool is not this approval. An approval holds only for the call it was asked for, with the same arguments, by the same person in the same app, organization and client, and only once, within 10 minutes; any other call is asked again. A client that cannot ask, one without form elicitation or one on the 2025 protocol, gets each write refused with a message saying so.
73
+ Before each write the client asks the person to approve it, through MCP's form elicitation. The approval names the record as the record page's breadcrumb does, by the resource's label, its key and its title, such as `Update Task #42 "Fix the sign-in lockout"?`. An update lists each field it changes by its label, with its value before and after (`Status: In flight -> Done`); a create lists the new record's fields by their labels; a delete says whether the record can be restored, and for a resource without a soft delete says plainly that it cannot be undone. Enum values show by their labels, a [sensitive](data-config.md#sensitive-fields) field's value is hidden, and a value is cut at 200 characters. A record or field the person may not read is named by its key or its name in words, and an update or delete of a record changed since its `etag` is refused before asking. The approval, its button and the refusal for a client that cannot ask are in the person's [language](languages.md): the app's `locale`, or else the one the client's request accepts (`Accept-Language`). Nothing is written until they approve, and declining writes nothing. A client's own setting that always allows a tool is not this approval. An approval holds only for the call it was asked for, with the same arguments, by the same person in the same app, organization and client, and only once, within 10 minutes; any other call is asked again. A client that cannot ask, one without form elicitation or one on the 2025 protocol, gets each write refused with a message saying so.
74
74
 
75
75
  <gap>An approval cannot be answered on another server instance or after a restart because a shared approval store is not implemented.</gap> Behind a load balancer, send an MCP client's calls to the same instance.
76
76
 
@@ -125,8 +125,8 @@ The endpoint serves each request on its own, without an MCP session: a `GET` or
125
125
 
126
126
  `@protobase/server` exports the pieces the endpoint is made of, for an MCP server of your own with tools of your own:
127
127
 
128
- - `mcpHandler({ authenticate, resource, scope, server })`: the endpoint as a fetch handler. It checks the host, admits a valid token (`mcpGate`) and serves the request with the server that `server(session)` builds for its caller.
129
- - `mcpServer({ info, tools, context, report, rolesWithoutApproval, approvals })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`: each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`. `approvals` is `mcpApprovals()`, built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire.
128
+ - `mcpHandler({ authenticate, resource, scope, server })`: the endpoint as a fetch handler. It checks the host, admits a valid token (`mcpGate`) and serves the request with the server that `server(session, request)` builds for its caller; `request` is the HTTP request, such as for the language the person reads.
129
+ - `mcpServer({ info, tools, context, report, rolesWithoutApproval, approvals })`: an MCP server offering [assistant tools](assistant.md#the-apps-own-tools), each with its JSON Schema and its `annotations`, MCP's tool hints. `context` is the tools' context without `approve`, with the `locale` its approvals are asked in (English when absent): each call gets its own, which asks the client's user, or approves at once when the session's user holds one of `rolesWithoutApproval`. `approvals` is `mcpApprovals()`, built once and passed to every server the endpoint builds: it keeps the approvals asked for until they are answered or expire.
130
130
  - `mcpTools({ db, sql, writes })`: the default tools for a session; `writes` is `true`, `false` or `{ resources, rolesWithoutApproval }`.
131
131
  - `readRecordTools()`, or `listResourcesTool()`, `listRecordsTool()` and `getRecordTool()`: the read tools alone; `readOnlyQueryTool(db)` is `run_read_only_query`, and `readWriteQueryTool(db)` proposes one write statement that the user approves before it runs.
132
132
  - `writeRecordTools({ resources })`, or `createRecordTool(...)`, `updateRecordTool(...)` and `deleteRecordTool(...)`: the single write tools alone, on the listed resources or, without `resources`, on any; `batchWriteTool({ resources })` is `batch_write` alone.
@@ -23,7 +23,7 @@ The keys are `apiKeys` in `protobase.config.ts`, `{ publishable_key, secret_key
23
23
  | either key and a signed-in user's token | `authenticated` |
24
24
  | the secret key | the app's own role, which owns the tables |
25
25
 
26
- The transaction sets the role with `SET LOCAL ROLE` and the token's claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()`, `auth.role()` and `auth.jwt()` work, and the tables' RLS policies decide what the request may read and write. The `role` claim is the database role, as on Supabase. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them.
26
+ The transaction sets the role with `SET LOCAL ROLE` and the token's claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()`, `auth.role()` and `auth.jwt()` work, and the tables' RLS policies decide what the request may read and write. The resources' access rules (`.access(...)`) do not apply here: a table needs its own grants and policies, and one without a grant to `anon` or `authenticated` refuses them. The `role` claim is the database role, as on Supabase. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them.
27
27
 
28
28
  `/api/sb/rest/v1` serves the tables the app declares as resources, in the `public` schema, under their table names. Any other table is `404`.
29
29