@protobase/cli 0.132.3 → 0.133.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/users/commands.js +7 -4
- package/dist/users/register.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/getting-started.md +1 -1
- package/skills/protobase/references/reference/auth.md +3 -3
- package/skills/protobase/references/reference/cli.md +2 -2
package/dist/cli/package.js
CHANGED
package/dist/users/commands.js
CHANGED
|
@@ -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
|
|
38
|
-
*
|
|
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.
|
|
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 (
|
|
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`);
|
package/dist/users/register.js
CHANGED
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "0.133.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.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.133.1",
|
|
47
|
+
"@protobase/layout": "0.133.1",
|
|
48
|
+
"@protobase/query": "0.133.1",
|
|
49
|
+
"@protobase/schema": "0.133.1",
|
|
50
|
+
"@protobase/server": "0.133.1",
|
|
51
|
+
"@protobase/ui": "0.133.1",
|
|
52
|
+
"@protobase/workflows": "0.133.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",
|
|
@@ -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.
|
|
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
|
|
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
|
|
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
|
|