@protobase/cli 0.131.0 → 0.131.1
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/config/project-modules.js +5 -2
- package/dist/config/read-only-queries.js +3 -3
- package/dist/dev/entry.js +1 -1
- package/dist/migration/migration-project.js +4 -1
- package/dist/serve/startup-checks.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/reference/assistant.md +1 -1
- package/skills/protobase/references/reference/cli.md +2 -2
- package/skills/protobase/references/reference/mcp.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -30,7 +30,7 @@ const builtModules = (project) => neededModules({
|
|
|
30
30
|
realtime: project.realtime,
|
|
31
31
|
events: project.events,
|
|
32
32
|
userTables: project.userTables,
|
|
33
|
-
readOnlyQueries: readOnlyQueriesOn(project.options
|
|
33
|
+
readOnlyQueries: readOnlyQueriesOn(project.options ?? {}, process.env)
|
|
34
34
|
});
|
|
35
35
|
/** The model the app `project` reads of its database's record of migrations (`runtimeModel`). */
|
|
36
36
|
const builtRuntimeModel = (project) => runtimeModel(project.auth, builtModules(project));
|
|
@@ -57,7 +57,10 @@ const configModules = async (config) => {
|
|
|
57
57
|
realtime: config.realtime,
|
|
58
58
|
events: config.events,
|
|
59
59
|
userTables: userTablesOn(config),
|
|
60
|
-
readOnlyQueries: readOnlyQueriesOn(
|
|
60
|
+
readOnlyQueries: readOnlyQueriesOn({
|
|
61
|
+
assistant: config.assistant,
|
|
62
|
+
mcp: config.mcpEndpoint
|
|
63
|
+
}, process.env)
|
|
61
64
|
});
|
|
62
65
|
};
|
|
63
66
|
//#endregion
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { assistantSettings } from "@protobase/server";
|
|
2
2
|
//#region src/config/read-only-queries.ts
|
|
3
3
|
/**
|
|
4
|
-
* Whether the built-in assistant
|
|
5
|
-
* role of their own, which the query module makes.
|
|
4
|
+
* Whether read-only queries run: those of the built-in assistant, with its key set in `env` or the options, or of the
|
|
5
|
+
* MCP endpoint's `sql`. They run as a role of their own, which the query module makes.
|
|
6
6
|
*/
|
|
7
|
-
const readOnlyQueriesOn = (assistant, env) => assistantSettings(assistant, env)?.kind === "built-in";
|
|
7
|
+
const readOnlyQueriesOn = ({ assistant, mcp }, env) => assistantSettings(assistant, env)?.kind === "built-in" || mcp !== false && mcp?.sql === true;
|
|
8
8
|
//#endregion
|
|
9
9
|
export { readOnlyQueriesOn };
|
package/dist/dev/entry.js
CHANGED
|
@@ -38,7 +38,7 @@ if (store.__protobaseRecordChecked !== modelHash(model)) {
|
|
|
38
38
|
}
|
|
39
39
|
await project.auth?.pinnedOrganization();
|
|
40
40
|
if (project.auth) await checkResourcesOutsideAuthStore(db, resources.map((resource) => resource.toModel()), project.auth);
|
|
41
|
-
if (readOnlyQueriesOn(project.options
|
|
41
|
+
if (readOnlyQueriesOn(project.options ?? {}, process.env)) await checkQueryRoleSafety(db, project.auth ? authStoreTables(project.auth) : {
|
|
42
42
|
tables: [],
|
|
43
43
|
schemas: []
|
|
44
44
|
});
|
|
@@ -42,7 +42,10 @@ const migrationProject = async (config, url) => {
|
|
|
42
42
|
realtime: config.realtime,
|
|
43
43
|
events: config.events,
|
|
44
44
|
userTables: userTablesOn(config),
|
|
45
|
-
readOnlyQueries: readOnlyQueriesOn(
|
|
45
|
+
readOnlyQueries: readOnlyQueriesOn({
|
|
46
|
+
assistant: config.assistant,
|
|
47
|
+
mcp: config.mcpEndpoint
|
|
48
|
+
}, process.env)
|
|
46
49
|
};
|
|
47
50
|
return {
|
|
48
51
|
models,
|
|
@@ -18,7 +18,7 @@ const checkStartup = async (project, db) => {
|
|
|
18
18
|
await checkMigrationRecord(db, builtRuntimeModel(project), protobaseVersion);
|
|
19
19
|
await project.auth?.pinnedOrganization();
|
|
20
20
|
if (project.auth) await checkResourcesOutsideAuthStore(db, models, project.auth);
|
|
21
|
-
if (readOnlyQueriesOn(project.options
|
|
21
|
+
if (readOnlyQueriesOn(project.options ?? {}, process.env)) await checkQueryRoleSafety(db, project.auth ? authStoreTables(project.auth) : {
|
|
22
22
|
tables: [],
|
|
23
23
|
schemas: []
|
|
24
24
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.131.
|
|
3
|
+
"version": "0.131.1",
|
|
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.131.
|
|
47
|
-
"@protobase/layout": "0.131.
|
|
48
|
-
"@protobase/query": "0.131.
|
|
49
|
-
"@protobase/schema": "0.131.
|
|
50
|
-
"@protobase/server": "0.131.
|
|
51
|
-
"@protobase/ui": "0.131.
|
|
52
|
-
"@protobase/workflows": "0.131.
|
|
46
|
+
"@protobase/config": "0.131.1",
|
|
47
|
+
"@protobase/layout": "0.131.1",
|
|
48
|
+
"@protobase/query": "0.131.1",
|
|
49
|
+
"@protobase/schema": "0.131.1",
|
|
50
|
+
"@protobase/server": "0.131.1",
|
|
51
|
+
"@protobase/ui": "0.131.1",
|
|
52
|
+
"@protobase/workflows": "0.131.1",
|
|
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",
|
|
@@ -66,7 +66,7 @@ It lives at `/api/assistant` on the app's own origin and answers with the user's
|
|
|
66
66
|
|
|
67
67
|
Both run **outside Protobase's access rules and tenant scoping**: whoever has the `admin` or `ai` role can read every resource's table, and with approval change everything the app's database role can, since `propose_write_query` still runs as that role. Give the app a database role without superuser rights, and those roles only to people who may see all of the data.
|
|
68
68
|
|
|
69
|
-
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role
|
|
69
|
+
Making the query role needs `CREATEROLE` once, for the role that applies the migrations; that role becomes a member of it and may run the function. The query role bypasses row-level security only when the migrating role may grant that, a superuser or, on Postgres 16 and later, a role with `BYPASSRLS`; otherwise it reads what the tables' policies give it. When the app serves as another database role than the one that migrates, grant that role `usage on schema query` and `execute on function query.run_read_only(text, integer)`. `protobase migration` writes the role when it finds the built-in assistant's key, `PROTOBASE_ASSISTANT_API_KEY` in the `.env` it reads or `assistant.apiKey` of the config, so run it with the key set even when only production has the real one, or when [`mcpEndpoint.sql`](mcp.md#sql-for-admins) is on, whose `run_read_only_query` runs as the same role. The server does not start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks the role, its function or a resource's grants, while the role can read an auth table, or while it may call a `SECURITY DEFINER` function, other than a trigger function, whose owner can read one: the statement would read the auth store through it, so revoke `execute` on such a function from `PUBLIC`, or keep it in a schema without a resource. Adding a resource writes its grants into the next migration, and removing one takes them back.
|
|
70
70
|
|
|
71
71
|
### The app's own tools
|
|
72
72
|
|
|
@@ -681,9 +681,9 @@ Writes what the config and this version of Protobase need beyond the project's `
|
|
|
681
681
|
|
|
682
682
|
A sign-in module the config turns off is [kept](auth.md#turning-a-module-off): on a terminal it asks what becomes of its tables, keep, archive or delete, keep being the default, and without one it needs `--off`. Archive and delete keep it as keep does until [`contract`](#signing-off-an-update) signs the update off. A kept module turned on again goes on from its step; with `DATABASE_URL` set and rows in its tables, it asks on a terminal whether to bring them back, and needs `--force` without one, and the file it writes then applies with `protobase migrate --force`.
|
|
683
683
|
|
|
684
|
-
The snapshot describes the schema the project's migrations make: the sign-in store as the runtime reads it, each module that is on with its tables, columns and indexes under the names the config gives them, its last step, and whether every table whose rows belong to an organization has the column that names it, with `modelHash`, the SHA-256 of exactly that; what the migrations decided, the file it ends at with its id, its `format` and the version of Protobase that wrote it, the modules kept or archived, whether organizations were ever on and the default organization, and in `external` the store's relations Protobase did not make, such as the user view of [`users.keyTable`](auth.md#a-view-over-another-systems-users), which no step alters; and `physical`, every schema, table, column and index name the store has. Its `model.modules` holds each built-in schema, each a module with numbered steps, such as the [jobs schema](jobs.md#the-jobs-schema) (`jobs`), the [change capture](events.md#migrations-and-startup) (`changes`) and its [history](history.md#the-table) and [notices](live.md#the-table) tables (`history`, `notices`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`webhooks`) and their delivery log with `deliveryLog` (`webhook_delivery_log`), the [workflows, versions and runs](workflows.md#turning-them-on) of `workflows` (`workflows`) with their storage configurations and custom steps while those are on (`workflow_storage`, `workflow_custom_steps`), the [devices and history tables](notifications.md#table-names) of `notifications` (`notification_devices`, `notification_history`), each unless a store of the app's own replaces it, the [comments table](comments.md#the-table) (`comments`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`mail_feedback`), written before the change capture whose triggers capture its events, and the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`unsubscribes`), and the [query role](assistant.md#the-built-in-backend) of
|
|
684
|
+
The snapshot describes the schema the project's migrations make: the sign-in store as the runtime reads it, each module that is on with its tables, columns and indexes under the names the config gives them, its last step, and whether every table whose rows belong to an organization has the column that names it, with `modelHash`, the SHA-256 of exactly that; what the migrations decided, the file it ends at with its id, its `format` and the version of Protobase that wrote it, the modules kept or archived, whether organizations were ever on and the default organization, and in `external` the store's relations Protobase did not make, such as the user view of [`users.keyTable`](auth.md#a-view-over-another-systems-users), which no step alters; and `physical`, every schema, table, column and index name the store has. Its `model.modules` holds each built-in schema, each a module with numbered steps, such as the [jobs schema](jobs.md#the-jobs-schema) (`jobs`), the [change capture](events.md#migrations-and-startup) (`changes`) and its [history](history.md#the-table) and [notices](live.md#the-table) tables (`history`, `notices`), the [webhook subscriptions](webhooks.md#subscriptions-in-the-admin-app) of `webhooks` (`webhooks`) and their delivery log with `deliveryLog` (`webhook_delivery_log`), the [workflows, versions and runs](workflows.md#turning-them-on) of `workflows` (`workflows`) with their storage configurations and custom steps while those are on (`workflow_storage`, `workflow_custom_steps`), the [devices and history tables](notifications.md#table-names) of `notifications` (`notification_devices`, `notification_history`), each unless a store of the app's own replaces it, the [comments table](comments.md#the-table) (`comments`), the table of the bounces and complaints of [`mailFeedback`](email.md#bounces-and-complaints) (`mail_feedback`), written before the change capture whose triggers capture its events, and the table of who unsubscribed from bulk mail of [`unsubscribe`](email.md#unsubscribe) (`unsubscribes`), and the [query role](assistant.md#the-built-in-backend) of read-only queries (`query`), each at its last step and the version of the functions over it, with the names it takes from the config, such as the schema `events`, `webhooks.schema` or `workflows.schema` names, the notifications tables' names and columns and the users table they point at, and the triggers of each captured resource at a digest of their statements; it keeps one the config no longer needs as the migrations left it. That part of the file comes from the snapshot alone too, after the store's: the module's steps after its last one, then its functions where the snapshot has another version, then the triggers of each resource whose statements differ, such as one added or one whose field became sensitive; a file that replaces them with a version the code before does not run on says `-- protobase:breaks-older-code`. A name the config changes, such as `events.schema`, `webhooks.schema` or a notifications table's column, is refused, since Protobase does not write renames; so is turning sign-in on under notifications tables made without it, whose user column then points at no users table. With `DATABASE_URL` set, it refuses to write a module from its first step onto a database that has it already, as made by an earlier version's migration, and names `baseline`. The sign-in store's part of the file comes from the snapshot alone, without a database: the [steps](auth.md#migrations) after each module's last one, those a newer Protobase ships included, each followed by its row in `auth_steps`; a snapshot whose store has no `auth_steps` yet, as a Protobase before 0.130 wrote it, is refused, naming 0.130 as the release to migrate through first. Each runs only while `auth_steps` lacks it, so a database that has it already, such as one [`migrate-release`](#release-steps) brought to a newer release, skips it. With `DATABASE_URL` set, the checks of those steps run first against the database's rows, in a read-only transaction, and refuse as the step would, such as on two accounts with one provider and account id. A name the store has that the config changes, such as a table renamed in [`auth.tables`](auth.md#table-and-column-names), is refused with what changed, since Protobase does not write renames: write it by hand with `--custom` and `--record-config`. A store a newer Protobase describes otherwise with no step to apply, such as personal access tokens now holding an organization's rows, gets a file that records it anew and changes nothing in the database. A step whose work cannot run in a transaction leaves it to the file's `.after.sql`, such as the batches that give each personal access token the [default organization](auth.md#the-default-organization) when organizations turn on, and the index it builds concurrently. With organizations on or ever on, the file needs `organizations.default` in the config, and turning them on the first time over a store that may hold users needs `organizations.existingUsersRole`; it refuses without them, as `migration check` reports.
|
|
685
685
|
|
|
686
|
-
The rest of the file is what the config still needs of the database, compared with it, under its own comment and named in the file name as in brackets: with [`userTables`](user-tables.md#the-switch), the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`owned_definitions`). It is compared only with `DATABASE_URL` set, against the database with the project's migrations applied, and the command says so without it. The jobs schema is written when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, or uses the relay, or a resource has events, history, comments or an [AI field](ai.md) or is a [time rollup](data-config.md#keeping-it-up-to-date). The rollups and formulas module is written when a resource has [rollup or formula fields](data-config.md#rollups-and-formulas) or is a [time rollup](data-config.md#time-rollups) (`computed`): the `rollups` schema, then per field and rollup the columns, the functions and triggers that keep the rollups, and the tables, indexes and refresh functions of time rollups; a changed one is dropped and made again, and what sets a rollup's values or fills a time rollup goes in the file's `.after.sql`, which runs once its transaction commits. The `derived` schema is written when a resource has [derived values](derived.md), with each value declared and its fill enqueued, and a value no longer declared loses its state. The schemas of user tables (`user_tables`) are written with [`userTables`](user-tables.md#the-switch); the tables users add inside them are data, made while the app serves. The change capture is written when a resource has events, history, live updates or derived values, another's derived values or live updates read it, or `mailFeedback` is on; its history table with history, and its notices table with live updates. The webhooks, workflows, notifications, [status](status.md), [calls](calls.md), comments, mail feedback and unsubscribe modules, the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) and the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) are written while the config turns their feature on, and none of them while it is off; turning a feature off later leaves its tables as they are. Calls write the notices table too, which rings reach open pages through. The [relay](realtime-relay.md#sessions) module, the trigger that ends a deleted session's sockets and `realtime.members` with the triggers that keep it from channel records that list their members, is written with `realtime.relay`, and for an app with sign-in and a live resource whose conversation page has `members`, after the auth store's steps, since its trigger is on the sessions table. The query module, the role the [assistant's read-only queries](assistant.md#the-built-in-backend) run as with the function they run through, is written last when the command finds the built-in assistant's key (`query`), with the role's grants on each resource's table but those of the auth store: a resource added writes only its grants, and one removed takes them back. It reads the config merged with those of `--extend` as `dev` merges them, and the `.env` nearest the current directory.
|
|
686
|
+
The rest of the file is what the config still needs of the database, compared with it, under its own comment and named in the file name as in brackets: with [`userTables`](user-tables.md#the-switch), the delete of the definitions of tables that resources in code [own now](user-tables.md#taking-a-table-over-as-code) (`owned_definitions`). It is compared only with `DATABASE_URL` set, against the database with the project's migrations applied, and the command says so without it. The jobs schema is written when the config has jobs, `webhooks`, `workflows`, `notifications` or `mailFeedback`, or uses the relay, or a resource has events, history, comments or an [AI field](ai.md) or is a [time rollup](data-config.md#keeping-it-up-to-date). The rollups and formulas module is written when a resource has [rollup or formula fields](data-config.md#rollups-and-formulas) or is a [time rollup](data-config.md#time-rollups) (`computed`): the `rollups` schema, then per field and rollup the columns, the functions and triggers that keep the rollups, and the tables, indexes and refresh functions of time rollups; a changed one is dropped and made again, and what sets a rollup's values or fills a time rollup goes in the file's `.after.sql`, which runs once its transaction commits. The `derived` schema is written when a resource has [derived values](derived.md), with each value declared and its fill enqueued, and a value no longer declared loses its state. The schemas of user tables (`user_tables`) are written with [`userTables`](user-tables.md#the-switch); the tables users add inside them are data, made while the app serves. The change capture is written when a resource has events, history, live updates or derived values, another's derived values or live updates read it, or `mailFeedback` is on; its history table with history, and its notices table with live updates. The webhooks, workflows, notifications, [status](status.md), [calls](calls.md), comments, mail feedback and unsubscribe modules, the `realtime_relay` schema of [`realtime: { processes: 'many' }`](supabase-realtime.md#several-processes) and the `channels` schema of [`realtime: { sqlSends: true }`](channels.md#from-sql) are written while the config turns their feature on, and none of them while it is off; turning a feature off later leaves its tables as they are. Calls write the notices table too, which rings reach open pages through. The [relay](realtime-relay.md#sessions) module, the trigger that ends a deleted session's sockets and `realtime.members` with the triggers that keep it from channel records that list their members, is written with `realtime.relay`, and for an app with sign-in and a live resource whose conversation page has `members`, after the auth store's steps, since its trigger is on the sessions table. The query module, the role the [assistant's read-only queries](assistant.md#the-built-in-backend) and those of [`mcpEndpoint.sql`](mcp.md#sql-for-admins) run as with the function they run through, is written last when the command finds the built-in assistant's key or `mcpEndpoint.sql` is on (`query`), with the role's grants on each resource's table but those of the auth store: a resource added writes only its grants, and one removed takes them back. It reads the config merged with those of `--extend` as `dev` merges them, and the `.env` nearest the current directory.
|
|
687
687
|
|
|
688
688
|
#### Changes that break older code
|
|
689
689
|
|
|
@@ -147,7 +147,7 @@ A definition the save check refuses comes back as `{ "error": "invalid-workflow"
|
|
|
147
147
|
export default defineConfig({ auth: { mcp: true }, mcpEndpoint: { sql: true } })
|
|
148
148
|
```
|
|
149
149
|
|
|
150
|
-
It runs one `SELECT` in a read-only transaction
|
|
150
|
+
It runs one `SELECT` in a read-only transaction as the query role, `<database>_query`, **outside the access rules and tenant scoping**: whoever has one of those roles reads every resource's table through it. Give those roles only to people who may see all of the data. [`protobase migration`](cli.md#migration) writes that role with `mcpEndpoint.sql` on, as it does for the built-in assistant, and the server does not start while the [record of migrations](../guides/deploy.md#the-record-of-migrations) lacks it; the assistant's page says [what it may read](assistant.md#the-built-in-backend).
|
|
151
151
|
|
|
152
152
|
### Writes
|
|
153
153
|
|