@protobase/cli 0.28.3 → 0.29.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.
- package/dist/cli/package.js +1 -1
- package/dist/users/commands.js +1 -1
- package/dist/users/password.js +7 -2
- package/dist/users/register.js +2 -1
- package/package.json +6 -6
- package/skills/protobase/references/guides/api-functions.md +3 -1
- package/skills/protobase/references/reference/access.md +8 -0
- package/skills/protobase/references/reference/auth.md +11 -3
- package/skills/protobase/references/reference/cli.md +2 -2
package/dist/cli/package.js
CHANGED
package/dist/users/commands.js
CHANGED
|
@@ -8,7 +8,7 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
8
8
|
const role = !await api.hasUsers() ? "admin" : options.role;
|
|
9
9
|
const user = await api.createUser({
|
|
10
10
|
email: options.email,
|
|
11
|
-
password,
|
|
11
|
+
...password !== void 0 && { password },
|
|
12
12
|
...role && { role },
|
|
13
13
|
...options.name && { name: options.name },
|
|
14
14
|
...options.githubId && { accounts: [{
|
package/dist/users/password.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
//#region src/users/password.ts
|
|
3
3
|
const rejectPasswordArgument = (value) => {
|
|
4
|
-
if (value === void 0) return;
|
|
4
|
+
if (value === void 0 || value === false) return;
|
|
5
5
|
throw new Error("Passwords are never accepted as arguments (they end up in shell history); type it at the prompt, or use --password-stdin or --generate-password");
|
|
6
6
|
};
|
|
7
7
|
const generatePassword = () => randomBytes(18).toString("base64url");
|
|
@@ -44,7 +44,12 @@ const readHidden = (question) => new Promise((resolve, reject) => {
|
|
|
44
44
|
stdin.on("data", onData);
|
|
45
45
|
});
|
|
46
46
|
const resolvePassword = async (options, deps) => {
|
|
47
|
-
if (
|
|
47
|
+
if ([
|
|
48
|
+
options.passwordStdin,
|
|
49
|
+
options.generatePassword,
|
|
50
|
+
options.noPassword
|
|
51
|
+
].filter(Boolean).length > 1) throw new Error("Use only one of --password-stdin, --generate-password and --no-password");
|
|
52
|
+
if (options.noPassword) return { generated: false };
|
|
48
53
|
if (options.generatePassword) return {
|
|
49
54
|
password: generatePassword(),
|
|
50
55
|
generated: true
|
package/dist/users/register.js
CHANGED
|
@@ -36,7 +36,7 @@ const ask = async (question) => {
|
|
|
36
36
|
const finish = (code) => process.exit(code);
|
|
37
37
|
const registerUsers = (program) => {
|
|
38
38
|
const users = program.command("users").description("Manage the admin users of the project in the current directory");
|
|
39
|
-
users.command("create").description("Create a user; the first user is always an admin").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("--github-id <id>", "link the user to this GitHub user id, so signing in with GitHub finds them whatever their address").option("--organization <organization>", "with organizations: add the user to this one (its slug or id)").option("--org-role <role>", "with --organization: owner, admin or member (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
|
|
39
|
+
users.command("create").description("Create a user; the first user is always an admin").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("--organization <organization>", "with organizations: add the user to this one (its slug or id)").option("--org-role <role>", "with --organization: owner, admin or member (default member)").option("--app-roles <roles>", "with --organization: app roles there, comma separated").addOption(new Option("--password <value>").hideHelp()).action(async (email, opts) => {
|
|
40
40
|
rejectPasswordArgument(opts.password);
|
|
41
41
|
const auth = await loadProjectAuth(process.cwd());
|
|
42
42
|
await createUserCommand(usersApi(auth), {
|
|
@@ -45,6 +45,7 @@ const registerUsers = (program) => {
|
|
|
45
45
|
role: opts.role,
|
|
46
46
|
passwordStdin: opts.passwordStdin,
|
|
47
47
|
generatePassword: opts.generatePassword,
|
|
48
|
+
noPassword: opts.password === false,
|
|
48
49
|
githubId: opts.githubId
|
|
49
50
|
}, {
|
|
50
51
|
stdin: process.stdin,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.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": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@hono/node-server": "^2.1.3",
|
|
37
37
|
"@hono/vite-dev-server": "^0.26.1",
|
|
38
|
-
"@protobase/layout": "0.
|
|
39
|
-
"@protobase/query": "0.
|
|
40
|
-
"@protobase/schema": "0.
|
|
41
|
-
"@protobase/server": "0.
|
|
42
|
-
"@protobase/ui": "0.
|
|
38
|
+
"@protobase/layout": "0.29.0",
|
|
39
|
+
"@protobase/query": "0.29.0",
|
|
40
|
+
"@protobase/schema": "0.29.0",
|
|
41
|
+
"@protobase/server": "0.29.0",
|
|
42
|
+
"@protobase/ui": "0.29.0",
|
|
43
43
|
"@react-email/render": "^2.1.0",
|
|
44
44
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
45
45
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -96,7 +96,9 @@ A refusal or a missing record rejects with the problem the REST API would answer
|
|
|
96
96
|
|
|
97
97
|
### Roles
|
|
98
98
|
|
|
99
|
-
`defineFunction({ roles: ['mechanic', 'desk'] }, handler)` lets in callers with at least one of those roles. Anyone else gets a `403 function-forbidden` problem before the handler runs. Finer rules belong in the resources' [access rules](../reference/access.md)), which `records` already applies.
|
|
99
|
+
`defineFunction({ roles: ['mechanic', 'desk'] }, handler)` lets in callers with at least one of those roles. `defineFunction({ capability: 'vms.update' }, handler)` lets in callers whose roles hold all of that capability ([`roles.holds`](../reference/access.md#wildcards-in-has-can-and-holds))): `*`, `vms.*` or a plain `vms.update`, but not `vms.update.own` or a `vms.update` limited to fields or rows. A wildcard means all of it, so `vms.*` needs a role that holds `vms.*` or `*`. Anyone else gets a `403 function-forbidden` problem before the handler runs. Finer rules belong in the resources' [access rules](../reference/access.md)), which `records` already applies.
|
|
100
|
+
|
|
101
|
+
In an app with [roles](../reference/access.md)) (`options: { roles }`), a function with neither is closed like a resource without a rule: only callers whose roles hold `*`, such as `admin: ['*']`, may call it, unless `defaultAccess` is `allow`. A function for everyone signed in says so with its roles. In an app without roles, every signed-in caller may call it. A `capability` needs the app's roles, and a function takes `roles` or `capability`, not both: the server refuses to start otherwise.
|
|
100
102
|
|
|
101
103
|
## Public functions and webhooks
|
|
102
104
|
|
|
@@ -12,6 +12,7 @@ Roles are defined in code ([`defineRoles`](https://docs.protobase.net/api/schema
|
|
|
12
12
|
- A project without roles (the single-admin case) is **default allow**.
|
|
13
13
|
- `defaultAccess: 'allow'` together with `roles` is an explicit opt-in. Print `accessWarnings(options)` at startup.
|
|
14
14
|
- Every request needs a token, unless the roles define [`anonymous`](#anonymous-access).
|
|
15
|
+
- An [API function](../guides/api-functions.md#roles)) without `roles` or a `capability` is closed the same way: with roles, only a caller holding `*` may call it.
|
|
15
16
|
|
|
16
17
|
## Capabilities
|
|
17
18
|
|
|
@@ -33,6 +34,13 @@ A field is readable when the role's list allows it and the field's own [rule](#f
|
|
|
33
34
|
|
|
34
35
|
**Several roles add up.** A user gets every field one of their roles lists (all of them when a role holds the plain capability) and the rows any of their roles allows. Fields and rows add up separately: someone holding both `erp_sync` and `reseller` above reads `name` on unpublished products too. With Better Auth a session acts with one [active role](auth.md#active-role)) at a time, so this only comes up with an authenticator that hands out several.
|
|
35
36
|
|
|
37
|
+
### Wildcards in has, can and holds
|
|
38
|
+
|
|
39
|
+
A wildcard in a role grants everything it stands for: `*.read` reads every resource. What a check asks for is different, so the checks take wildcards in one place only:
|
|
40
|
+
|
|
41
|
+
- `roles.has(user, 'vms.update')` and `roles.can('vms.update')` ask for one capability, in any scope or limit the role holds it. They refuse a wildcard, at compile time and when called, since `vms.*` would pass for a role holding only `vms.read`: ask for each capability instead.
|
|
42
|
+
- `roles.holds(user, 'vms.*')` asks for all of it, in every row and field: a role holding `*` or `vms.*` passes, one holding `vms.read`, `*.read`, `vms.update.own` or a `vms.update` limited to fields or rows does not. A scope asks for those rows at least: `orders.read.own` passes for a role holding `orders.read.own`, `orders.read` or `*.read`. API functions' `capability` is checked this way.
|
|
43
|
+
|
|
36
44
|
## Anonymous access
|
|
37
45
|
|
|
38
46
|
The role `anonymous` is what a request without a token acts as. A project without it answers such requests `401`, as always.
|
|
@@ -88,12 +88,12 @@ The columns Better Auth needs that the table lacks, filled from what the other s
|
|
|
88
88
|
|
|
89
89
|
## First run
|
|
90
90
|
|
|
91
|
-
Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`) or from code:
|
|
91
|
+
Accounts are never created over the web while the store is empty: there is no setup route, and [open sign-up](#open-sign-up), when an app turns it on, waits for the first admin, so a freshly deployed URL cannot be claimed by whoever reaches it first. The first admin is created on the host, with the CLI (`protobase users create you@example.com --generate-password`, or `--no-password` for an account that signs in by emailed code, passkey or a sign-in provider only) or from code:
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
94
|
import { createUser, hasUsers, listUsers } from '@protobase/server'
|
|
95
95
|
|
|
96
|
-
await createUser(auth, { email, password
|
|
96
|
+
await createUser(auth, { email, password?, name?, role? }) // the first user is always an admin; later ones default to `user`
|
|
97
97
|
await hasUsers(auth) // boolean
|
|
98
98
|
await listUsers(auth) // [{ id, email, role, banned, createdAt }], never passwords
|
|
99
99
|
await setUserRole(auth, { email, role }) // 'admin' | 'user'
|
|
@@ -219,7 +219,15 @@ Admins set how people sign in on the app's **Sign-in policy** page (the profile
|
|
|
219
219
|
| Staff sign-in as a person | On, Email the person, Off | On |
|
|
220
220
|
| Sign in with ... through the platform | On, Off | On |
|
|
221
221
|
|
|
222
|
-
The
|
|
222
|
+
The Default column is the policy of an app that sets none. An app sets its own in code, the policy that applies until an admin saves one, such as emailed codes and passkeys only, with the methods it changes:
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
createAuth({ ..., signInPolicy: { password: 'forbidden' } })
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
It is checked at startup as an admin's save is, so a default that would lock people out stops the app; without mail it applies as a saved policy does (password sign-in is then on). The page shows it, as never changed, until an admin saves a policy. Pair it with `protobase users create --no-password`, so the first admin has no password to fall back on.
|
|
229
|
+
|
|
230
|
+
The server stores the policy in the `sign_in_policy` table, one row per save (the newest applies, the others are its history, with who saved each and when; a newest row that no longer reads, with a rule the method does not take, counts as none, so the app's default applies), and applies it to Better Auth's endpoints; the pages only show what it allows.
|
|
223
231
|
|
|
224
232
|
- **Off:** the server refuses the method with `403` (`SIGN_IN_METHOD_FORBIDDEN`) and the sign-in page leaves it out. Passkeys off also stops adding them; two-factor off stops turning it on, while those who have it keep being asked until they turn it off.
|
|
225
233
|
- **Required:** someone who signs in without it is sent to set it up first. The server holds back API tokens until then (`GET /api/auth/token` answers `403`, `SIGN_IN_SETUP_REQUIRED`), and refuses to turn two-factor authentication off or to remove the last passkey.
|
|
@@ -410,7 +410,7 @@ Runs the [scheduled file deletes](files.md#deleting-files)) that are due: replac
|
|
|
410
410
|
## `users`
|
|
411
411
|
|
|
412
412
|
```sh
|
|
413
|
-
protobase users create <email> [--name <name>] [--role <role>] [--password-stdin | --generate-password] [--github-id <id>]
|
|
413
|
+
protobase users create <email> [--name <name>] [--role <role>] [--password-stdin | --generate-password | --no-password] [--github-id <id>]
|
|
414
414
|
[--organization <slug> [--org-role <role>] [--app-roles <a,b>]]
|
|
415
415
|
protobase users list
|
|
416
416
|
protobase users roles
|
|
@@ -421,7 +421,7 @@ protobase users delete <email> [--yes]
|
|
|
421
421
|
|
|
422
422
|
Run inside a project whose `protobase.config.ts` exports `auth` (Better Auth). There is no web setup page, and [open sign-up](auth.md#open-sign-up)), when a project turns it on, waits for the first admin: the first admin is created here. The first user is always an admin, whatever `--role` says; later users get `--role`, or the project's default role (`createAuth({ roles, defaultRole })`). `protobase users roles` lists the roles of the project; anything else is refused with that list. `set-role` also takes comma separated roles (`sales,accountant`). `--github-id` links the new user to a GitHub user id (the number, not the login), so signing in with GitHub, the app's own provider or the [platform's](auth.md#platform-sign-in-provider)), finds them whatever address GitHub reports; an id that signs in another user already is refused. `createUser(auth, { ..., accounts: [{ providerId, accountId }] })` does the same from code.
|
|
423
423
|
|
|
424
|
-
The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
|
|
424
|
+
The password is typed at a hidden prompt with confirmation, read from stdin with `--password-stdin` (for scripts, e.g. `pass show erp | protobase users create me@example.com --password-stdin`), or generated with `--generate-password` and printed once. `--no-password` makes an account without one, which signs in by [emailed code](auth.md#emailed-sign-in-codes)), passkey or a sign-in provider, as with an app whose [sign-in policy](auth.md#sign-in-policy)) turns passwords off. A password is never accepted as an argument, since it would end up in shell history. `users list` prints email, role and creation date (and `disabled` for banned users), never credentials.
|
|
425
425
|
|
|
426
426
|
`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 within their lifetime (15 minutes by default), and `protobase token` refuses disabled users. `enable` lifts the ban. `protobase dev` prints "No users yet. Create the first admin with: protobase users create you@example.com" at startup while the user table is empty.
|
|
427
427
|
|