@protobase/cli 0.132.2 → 0.133.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.132.2";
2
+ var version = "0.133.0";
3
3
  //#endregion
4
4
  export { version };
@@ -34,15 +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 pinned organization, or to none
38
- * with `--all-organizations`. The pin is resolved first, so an unknown organization creates nobody.
37
+ * Creates the user (`createUserCommand`) and, with organizations, adds them to the organization `--organization` names,
38
+ * or to none, not to the default organization the other commands pin unless it is named. The organization is resolved
39
+ * first, so an unknown one creates nobody.
39
40
  */
40
41
  const createMemberCommand = async (api, options, deps, out) => {
41
42
  if (options.allOrganizations && !api.organizationsOn) throw new Error("--all-organizations needs organizations: turn on auth.organizations in the config");
42
43
  if (options.allOrganizations && options.organization !== void 0) throw new Error("Pass --organization or --all-organizations, not both");
43
- const pin = options.allOrganizations ? void 0 : await resolveOptionalPin(api, options, "users create");
44
+ const pin = options.organization === void 0 ? void 0 : await resolveOptionalPin(api, options, "users create");
45
+ const joinsNone = api.organizationsOn && !pin;
46
+ if (joinsNone && (options.orgRole !== void 0 || options.appRoles !== void 0)) throw new Error("--org-role and --app-roles need --organization <slug>: without it the user joins no organization");
44
47
  const user = await createUserCommand(api, options, deps, out);
45
- if (options.allOrganizations) out(`${user.email} joins no organization\n`);
48
+ if (joinsNone) out(`${user.email} joins no organization\n`);
46
49
  if (!pin || "every" in pin) return;
47
50
  if (user.first && await api.isMember(pin.organization.id, user.email)) {
48
51
  out(`${user.email} owns ${pin.organization.slug}\n`);
@@ -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; with --all-organizations, none")).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 organizations: owner, admin or member in the organization (default member)").option("--app-roles <roles>", "with organizations: app roles in the organization, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
25
+ pinOptions(users.command("create").description("Create a user; the first user is always an admin. With organizations, they join the organization --organization names, else none")).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.132.2",
3
+ "version": "0.133.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": {
@@ -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.132.2",
47
- "@protobase/layout": "0.132.2",
48
- "@protobase/query": "0.132.2",
49
- "@protobase/schema": "0.132.2",
50
- "@protobase/server": "0.132.2",
51
- "@protobase/ui": "0.132.2",
52
- "@protobase/workflows": "0.132.2",
46
+ "@protobase/config": "0.133.0",
47
+ "@protobase/layout": "0.133.0",
48
+ "@protobase/query": "0.133.0",
49
+ "@protobase/schema": "0.133.0",
50
+ "@protobase/server": "0.133.0",
51
+ "@protobase/ui": "0.133.0",
52
+ "@protobase/workflows": "0.133.0",
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",
@@ -11,7 +11,7 @@ The page of one record, with its sections, related records, galleries, charts an
11
11
  - [Record pages that open another](../reference/ui-config.md#a-record-page-that-opens-another): A record's page opens another address built from its fields in its place, such as a workflow run opening its workflow's page with the run shown.
12
12
  - [Record page opens elsewhere](../reference/ui-config.md#open-elsewhere) (beta): A view can send its record's address to another page its fields name, such as a message opening in its conversation, so search results and links land where the record is read.
13
13
  - [Full-area record pages](../reference/ui-config.md#full-area-record-pages) (beta): A view draws its record pages with a component of its own that fills the area beside the sidebar and under the top bar, such as a chat channel, and links to the standard page.
14
- - [Conversation pages](../reference/ui-config.md#conversation-pages) (beta): A record's page is its conversation, configured with no component of your own: a header with its title, topic and details, its messages grouped by day and author with mentions and edits shown, and a box that sends one, opening on a New messages line at the reader's place, on the web and at mobile width. People react to its messages, edit and delete them, reply in threads beside the conversation and share files that show under their message, by pointer or touch, start or join the record's call from its header, shown beside the messages, or above them at mobile width, and see who else types, in the conversation and in a thread, with or without a realtime relay.
14
+ - [Conversation pages](../reference/ui-config.md#conversation-pages) (beta): A record's page is its conversation, configured with no component of your own: a header with its title, topic and details, its messages grouped by day and author with mentions and edits shown, and a box that sends one, whose hint and empty text can name the record, such as "Message #general", opening on a New messages line at the reader's place, on the web and at mobile width. People react to its messages, edit and delete them, reply in threads beside the conversation and share files that show under their message, by pointer or touch, start or join the record's call from its header, shown beside the messages, or above them at mobile width, and see who else types, in the conversation and in a thread, with or without a realtime relay.
15
15
  - [Read view and edit](../reference/ui-config.md#read-view-and-edit): A record opens as a read-only fact sheet or a form, and Edit opens the form at its own address.
16
16
  - [Unsaved edits](../reference/ui-config.md#editing-a-record): Unsaved changes to a record stay in the browser and can be resumed, and leaving a form, a dialog or a comment with changes asks first.
17
17
  - [Record forms](../reference/ui-config.md#editing-a-record): Relations are picked from a list that narrows as you type, numbers are read as the browser's language writes them, and a refused save says under each field what is wrong.
@@ -112,7 +112,7 @@ bun install
112
112
 
113
113
  ```sh
114
114
  bun run db:up && bun run --cwd tests/apps/erp db:migrate && bun run --cwd tests/apps/erp db:seed --scale small # the ERP's tables and Better Auth's
115
- bun run --cwd tests/apps/erp protobase users create you@example.com --generate-password
115
+ bun run --cwd tests/apps/erp protobase users create you@example.com --organization erp --org-role owner --generate-password
116
116
  bun run --cwd tests/apps/erp dev # prints its address, http://localhost:<port>
117
117
  ```
118
118
 
@@ -26,7 +26,7 @@ Users, sessions and signing keys stay apart from the application's tables, in a
26
26
 
27
27
  ### Migrations
28
28
 
29
- The store's tables come from steps that ship with Protobase, and are part of the project's migrations, committed in the repository like the application's own: the examples carry them as `db/migrations/*_auth.sql`, and their `db:migrate` applies both. Each module of sign-in has its own numbered chain of steps, the only source of its tables: `auth` (users, sessions, accounts, codes and signing keys), `two_factor`, `passkeys`, `sign_in_policy`, `staff_sign_in`, `organizations`, `mcp`, `personal_access_tokens`, `mail_senders` and `platform_devices`. A step is written against the store's [names](#table-and-column-names), so it makes the tables and columns under the names the app configures, and a step that adds columns to another module's table, such as `organizations` adding the organization of each user, session and personal access token, adds them only while that module is on. The store records each step it applied in its `auth_steps` table, one row per module, step and the module whose tables it changes, so the columns one module adds to another's tables are recorded apart from the step's own tables. A store an earlier Protobase made recorded versions instead, in `auth_migrations`, the numbers of the single chain the store had before its modules had chains of their own: the migrations of Protobase 0.130 made `auth_steps` from them, and `auth` step 6 drops `auth_migrations`. A store that still has `auth_migrations` without `auth_steps` is refused: bring the project to Protobase 0.130 first, write and apply its migration there, then upgrade. When an upgrade of Protobase brings new steps, write them as the project's next migration:
29
+ The store's tables come from steps that ship with Protobase, and are part of the project's migrations, committed in the repository like the application's own: the examples carry them as `db/migrations/*_auth.sql`, and their `db:migrate` applies both. Each module of sign-in has its own numbered chain of steps, the only source of its tables: `auth` (users, sessions, accounts, codes and signing keys), `two_factor`, `passkeys`, `sign_in_policy`, `staff_sign_in`, `organizations`, `mcp`, `personal_access_tokens`, `mail_senders` and `platform_devices`. A step is written against the store's [names](#table-and-column-names), so it makes the tables and columns under the names the app configures, and a step that adds columns to another module's table, such as `organizations` adding the organization of each user, session and personal access token, adds them only while that module is on. The store records each step it applied in its `auth_steps` table, one row per module, step and the module whose tables it changes, so the columns one module adds to another's tables are recorded apart from the step's own tables. `auth` step 6 drops `auth_migrations`, the record of versions an earlier Protobase kept; a store that has it without `auth_steps` is refused, and the refusal says how to bring it on. When an upgrade of Protobase brings new steps, write them as the project's next migration:
30
30
 
31
31
  ```sh
32
32
  bun run db:migrate # the database at the project's current schema
@@ -50,7 +50,7 @@ The server never changes the schema, and never compares it with what Better Auth
50
50
 
51
51
  No resource may be over a table of the store, which holds password hashes, sessions, tokens and signing keys: `protobase serve` and `protobase dev` refuse to start with one, naming it, whatever the table is called, and [`protobase scaffold`](cli.md#scaffold) never writes one. The API, the Supabase-compatible endpoints, live updates and MCP read the app's resources only, so none of them reads the store.
52
52
 
53
- A store made before 0.48, when `protobase auth migration` compared the database with Better Auth's tables, has no record of its steps. For it, `protobase auth migration` writes the step that adopts it, once: it runs every step in a scratch schema, in a transaction it rolls back, to find the tables and columns each version makes, records the steps of each version whose tables and columns the store has, with their types, as applied, and writes the steps of the versions whose tables it has none of, such as MCP's for an app that never turned MCP on. The file checks again, when it is applied, that the store has every table and column it adopts, and stops otherwise, naming them. A store that has only some of a version's tables and columns, or has them with other types, is refused, naming what differs: bring it to the schema of Protobase 0.47 first, with that version's `protobase auth migration`. A store set up by Protobase 0.6, with Better Auth's camelCase names, or by `auth:migrate` before it, goes through 0.47 the same way.
53
+ A store made before 0.48, when `protobase auth migration` compared the database with Better Auth's tables, has no record of its steps. For it, `protobase auth migration` writes the step that adopts it, once: it runs every step in a scratch schema, in a transaction it rolls back, to find the tables and columns each version makes, records the steps of each version whose tables and columns the store has, with their types, as applied, and writes the steps of the versions whose tables it has none of, such as MCP's for an app that never turned MCP on. The file checks again, when it is applied, that the store has every table and column it adopts, and stops otherwise, naming them. A store that has only some of a version's tables and columns, or has them with other types, is refused, naming what differs and how to bring it on.
54
54
 
55
55
  ### Table and column names
56
56
 
@@ -806,7 +806,7 @@ The app's own pages are under the profile menu: the switcher, "Manage organizati
806
806
 
807
807
  Every table of the store is either the whole app's or an organization's. `member`, `invitation` and `personal_access_token` hold an organization's rows, each with its `organization_id`; the others, users, sessions, accounts, verifications, two-factor secrets, passkeys, the sign-in policy and the signing keys among them, are the app's. Each index of an organization's table serves one organization, leading with `organization_id`, or the whole app, such as a lookup by a person or an address; a key looked up from outside, such as a token's hash, stays unique across the app. The `db` the app's functions, jobs and hooks get shows them one organization's rows only, unless `db.unscoped('<reason>')` (see [The organization's tables](../guides/api-functions.md#the-organizations-tables)). Sign-in's own queries keep to one organization too, work Better Auth finishes after the response included: an `/api/auth/organization/*` request works in the organization it names as `organizationId`, in a GET's query or a POST's body, else in the session's active one, and a POST naming another in its query is refused with `400` (`CONFLICTING_ORGANIZATIONS`); a membership or token is read in the organization it belongs to; and what is a person's own in every organization, such as their organizations, the invitations to their address, their personal access tokens and a token looked up by its hash, is read across them. A request elsewhere in `/api/auth` works in none. <gap>An `/api/auth/organization/*` request that names its organization by slug alone cannot reach one other than the session's active organization because finding the organization of a slug before the request runs is not implemented.</gap> While organizations are off after being on, the `db` keeps the tables they left to [the default organization](#the-default-organization): a function's for a session of it, a job's enqueued in it, and a hook's, which is about it; a public function and `/api/sb/functions/v1` see none of their rows.
808
808
 
809
- The default organization, `organizations.default`, is the one that stands in for every organization while they are off. [`protobase migration`](cli.md#migration) refuses without it once organizations are on or were ever on, and records it in `protobase.snapshot.json`. Turning organizations off sets `enabled: false` and keeps `default`; the store keeps their tables and columns, as [for any module](#turning-a-module-off).
809
+ The default organization, `organizations.default`, is the one that stands in for every organization while they are off. [`protobase migration`](cli.md#migration) refuses without it once organizations are on or were ever on, and records it in `protobase.snapshot.json`. Turning organizations off sets `enabled: false` and keeps `default`; the store keeps their tables and columns, as [for any module](#turning-a-module-off). On a new store with organizations on, nobody is given it: the first account, which owns every other organization without members, such as those a seed made, is no member of it, so it starts in a seeded organization or in none and names its first one, where the app's setup for a new organization, such as `onOrganizationCreated`, runs. It gains members only as below, when organizations turn on for users there already, or when someone is added to it by name, such as with `protobase users create --organization <slug>`. <gap>An account an earlier release made owner of an empty default organization cannot start elsewhere until it switches once, because removing that membership on upgrade is not implemented.</gap>
810
810
 
811
811
  Turning organizations on for the first time makes the default organization under its id, and each user there already becomes its member, with the organization role `member` and the app role `existingUsersRole`; `protobase migration` refuses without that role, unless the store is new and holds no users. Each personal access token made before then works in the default organization: the migration's `.after.sql` fills them in batches, then makes their `organization_id` required, checked first without a long lock, and builds their index per organization concurrently. Turning organizations on again later fills nothing: a token made while they were off was made in the default organization. One made while they were off on an earlier version has no organization, so the migration refuses, naming it, as below. On a store whose organizations were on before, such as one [`migration baseline`](cli.md#migration) started, the default organization is made when the store lacks it, no one becomes its member, and a token without an organization is not given the default one, which would guess where it works: the migration refuses, naming each such token, so you delete them, or set the organization each works in, in a migration of your own written before it. With organizations on, a personal access token is made in the session's active organization, and refused without one.
812
812
 
@@ -631,7 +631,7 @@ The password is typed at a hidden prompt with confirmation, read from stdin with
631
631
 
632
632
  `delete` asks you to type the email back (or pass `--yes`), and needs a terminal otherwise. `delete`, `set-role` and `disable` refuse to touch the last admin, so the project cannot lock itself out. `disable` bans the user and revokes their sessions; tokens already issued stop working on their next request, and `protobase token` refuses disabled users. With [MCP](auth.md#oauth-for-mcp-clients) on, it also disconnects their MCP clients. `enable` lifts the ban; the clients have to be allowed again. `protobase dev` prints the command that creates the first admin at startup while the user table is empty (see [`dev`](#dev)).
633
633
 
634
- With [organizations](auth.md#organizations), `--role` is the user's global role (none by default), and each command acts on [the pinned organization](#the-pinned-organization): `create` adds the new user to it with `--org-role` (`owner`, `admin`, or `member`, the default) and `--app-roles` there, or to no organization with `--all-organizations`; the first user owns it already when it had no members. `list` lists its members, or every user with `--all-organizations`. `set-role`, `disable`, `enable` and `delete` reach only its members, or any user with `--all-organizations`; they change the whole account, in every organization the user belongs to.
634
+ With [organizations](auth.md#organizations), `--role` is the user's global role (none by default), and `create` adds the new user to the organization `--organization` names, with `--org-role` (`owner`, `admin`, or `member`, the default) and `--app-roles` there, and without it to none, not to the default organization; the first user owns a named organization already when it had no members and is not the default one. The other commands act on [the pinned organization](#the-pinned-organization): `list` lists its members, or every user with `--all-organizations`. `set-role`, `disable`, `enable` and `delete` reach only its members, or any user with `--all-organizations`; they change the whole account, in every organization the user belongs to.
635
635
 
636
636
  ## `organizations`
637
637
 
@@ -648,7 +648,7 @@ For a project with [organizations](auth.md#organizations). The host acts as a su
648
648
 
649
649
  ### The pinned organization
650
650
 
651
- The `users` and `organizations` commands act on one organization: the config's [`auth.organizations.default`](auth.md#the-default-organization), or the one `--organization` names by its slug or id. They print it first, or `Every organization` with `--all-organizations`, which reaches every organization's people. An organization the database does not have is refused, naming it, and so is a project without `auth.organizations.default` unless the command gets `--organization` or `--all-organizations`.
651
+ The `users` and `organizations` commands act on one organization, but for `users create`, which adds a new user only to an organization `--organization` names: the config's [`auth.organizations.default`](auth.md#the-default-organization), or the one `--organization` names by its slug or id. They print it first, or `Every organization` with `--all-organizations`, which reaches every organization's people. An organization the database does not have is refused, naming it, and so is a project without `auth.organizations.default` unless the command gets `--organization` or `--all-organizations`.
652
652
 
653
653
  The pin is a filter, not a boundary: whoever runs a host command holds the database's credentials, so it keeps a command from reaching another organization's people by accident, not on purpose.
654
654
 
@@ -838,8 +838,8 @@ view<typeof channels>('channels').record({
838
838
  | `subtitle` | A text field of the record shown beside its title, such as a channel's topic. |
839
839
  | `members` | A JSON field of the record holding user ids: the header names the other people in it, each with their presence and [status](status.md#in-the-app), the status text in full beside one person and on hover beside several. The record is titled after them everywhere, as the [`members` title rule](#titles-per-reader) does. |
840
840
  | `readPosition` | Where each reader's read position is kept: `{ resource, field, message }`. |
841
- | `placeholder` | The hint in the empty box. |
842
- | `empty` | What the conversation says while it has no messages. |
841
+ | `placeholder` | The hint in the empty box. Each `{{field}}` in it fills from the record, so `'Message #{{name}}'` names the channel; a field the record has no value for fills as nothing, and one the record does not have is refused. |
842
+ | `empty` | What the conversation says while it has no messages, its `{{field}}`s filled from the record as in `placeholder`, such as `'This is the start of #{{name}}.'`. |
843
843
  | `edit` | `true`: a message's author changes its text and mentions in place, as the message resource's update access allows. |
844
844
  | `delete` | `true`: anyone the message resource's delete access allows deletes a message, after confirming; or `{ unless }`, a condition on the message's own fields that keeps it, such as `reply_count > 0`. |
845
845
  | `reactions` | Emoji reactions under each message: `{ resource, field, user, emoji, labels }`. |