@protobase/cli 0.106.1 → 0.107.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.106.1";
2
+ var version = "0.107.0";
3
3
  //#endregion
4
4
  export { version };
@@ -1,4 +1,4 @@
1
- import { addAppRoleToOwners, addMember, createOrganization, listOrganizations, listUsers, removeMember, setMemberRoles, setUserRole } from "@protobase/server";
1
+ import { addAppRoleToOwners, addEveryUser, addMember, createOrganization, listOrganizations, removeMember, setMemberRoles } from "@protobase/server";
2
2
  //#region src/organizations/api.ts
3
3
  const organizationsApi = (auth) => ({
4
4
  listOrganizations: () => listOrganizations(auth),
@@ -7,9 +7,7 @@ const organizationsApi = (auth) => ({
7
7
  setMemberRoles: (input) => setMemberRoles(auth, input),
8
8
  removeMember: (input) => removeMember(auth, input),
9
9
  addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
10
- listUsers: () => listUsers(auth),
11
- setUserRole: (input) => setUserRole(auth, input),
12
- membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
10
+ addEveryUser: (organization) => addEveryUser(auth, organization)
13
11
  });
14
12
  //#endregion
15
13
  export { organizationsApi };
@@ -30,33 +30,8 @@ const createOrganizationCommand = async (api, options, out) => {
30
30
  });
31
31
  out(`Created organization ${organization.slug} (${organization.id}), owned by ${options.owner}\n`);
32
32
  if (options.members !== "all") return;
33
- const holdable = api.membershipRoles();
34
- for (const user of await api.listUsers()) {
35
- if (user.email.toLowerCase() === options.owner.toLowerCase()) continue;
36
- const global = user.role.split(",").map((name) => name.trim()).filter(Boolean);
37
- if (global.includes("admin")) {
38
- await api.addMember({
39
- organization: organization.id,
40
- email: user.email,
41
- role: "owner",
42
- appRoles: holdable
43
- });
44
- out(` ${user.email}: owner, with every app role\n`);
45
- continue;
46
- }
47
- const appRoles = global.filter((name) => holdable.includes(name));
48
- await api.addMember({
49
- organization: organization.id,
50
- email: user.email,
51
- role: "member",
52
- appRoles
53
- });
54
- await api.setUserRole({
55
- email: user.email,
56
- role: "user"
57
- });
58
- out(` ${user.email}: member${appRoles.length > 0 ? `, with ${appRoles.join(",")}` : ""}\n`);
59
- }
33
+ for (const user of await api.addEveryUser(organization.id)) if (user.role === "owner") out(` ${user.email}: owner, with every app role\n`);
34
+ else out(` ${user.email}: member${user.appRoles.length > 0 ? `, with ${user.appRoles.join(",")}` : ""}\n`);
60
35
  };
61
36
  const addMemberCommand = async (api, options, out) => {
62
37
  const appRoles = parseRoleList(options.appRoles);
@@ -25,15 +25,20 @@ const createUserCommand = async (api, options, deps, out) => {
25
25
  out(`Created ${user.role} ${user.email}${shownAs(user.role, labels)}${options.githubId ? `, linked to GitHub user ${options.githubId}` : ""}\n`);
26
26
  if (generated) out(`Password (shown once): ${password}\n`);
27
27
  };
28
+ /** Prints every user, oldest first, a page at a time as the store pages them; the first page sets the columns' width. */
28
29
  const listUsersCommand = async (api, out) => {
29
- const users = await api.listUsers();
30
- if (users.length === 0) {
30
+ let page = await api.listUsers();
31
+ if (page.users.length === 0) {
31
32
  out("No users yet. Create the first admin with: protobase users create you@example.com\n");
32
33
  return;
33
34
  }
34
- const width = Math.max(...users.map((user) => user.email.length), 5);
35
+ const width = Math.max(...page.users.map((user) => user.email.length), 5);
35
36
  out(`${"EMAIL".padEnd(width)} ${"ROLE".padEnd(8)} CREATED\n`);
36
- for (const user of users) out(`${user.email.padEnd(width)} ${user.role.padEnd(8)} ${user.createdAt}${user.banned ? " disabled" : ""}\n`);
37
+ for (;;) {
38
+ for (const user of page.users) out(`${user.email.padEnd(width)} ${user.role.padEnd(8)} ${user.createdAt}${user.banned ? " disabled" : ""}\n`);
39
+ if (!page.next) return;
40
+ page = await api.listUsers(page.next);
41
+ }
37
42
  };
38
43
  const listRolesCommand = async (api, out) => {
39
44
  const { roles, defaultRole } = await api.roles();
@@ -8,7 +8,7 @@ const usersApi = (auth) => ({
8
8
  labels: auth.roleDefinitions.labels
9
9
  }),
10
10
  createUser: (input) => createUser(auth, input),
11
- listUsers: () => listUsers(auth),
11
+ listUsers: (after) => listUsers(auth, after && { after }),
12
12
  deleteUser: (email) => deleteUser(auth, email),
13
13
  setUserRole: (input) => setUserRole(auth, input),
14
14
  setUserBanned: (input) => setUserBanned(auth, input)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.106.1",
3
+ "version": "0.107.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.106.1",
47
- "@protobase/layout": "0.106.1",
48
- "@protobase/query": "0.106.1",
49
- "@protobase/schema": "0.106.1",
50
- "@protobase/server": "0.106.1",
51
- "@protobase/ui": "0.106.1",
52
- "@protobase/workflows": "0.106.1",
46
+ "@protobase/config": "0.107.0",
47
+ "@protobase/layout": "0.107.0",
48
+ "@protobase/query": "0.107.0",
49
+ "@protobase/schema": "0.107.0",
50
+ "@protobase/server": "0.107.0",
51
+ "@protobase/ui": "0.107.0",
52
+ "@protobase/workflows": "0.107.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",
@@ -96,7 +96,7 @@ The store's migrations then make nothing of the user table, which a migration of
96
96
  | `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins, passed by the platform; see [CORS](api.md#cors) |
97
97
  | `PROTOBASE_SMTP_URL`, `PROTOBASE_MAIL_FROM` | the mail server and sender for [password reset](#password-reset), [emailed sign-in codes](#emailed-sign-in-codes), emailed [two-factor](#two-factor-authentication) codes and [open sign-up](#open-sign-up), passed by the platform; all four are off without them |
98
98
  | `PROTOBASE_APP_NAME` | the app's name, passed by the platform: it overrides `name` |
99
- | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-providers) for people who have an account, passed by the platform; off without them. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` are optional, and `PROTOBASE_SIGN_IN_TOKENS=true` turns on its [token sign-in](#token-sign-in). `PROTOBASE_SIGN_IN_2_ISSUER` and so on add [more providers](#more-than-one-provider) |
99
+ | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-providers) for people who have an account, passed by the platform; off without them. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN`, `PROTOBASE_SIGN_IN_BUTTON` and `PROTOBASE_SIGN_IN_DEVICES` are optional, and `PROTOBASE_SIGN_IN_TOKENS=true` turns on its [token sign-in](#token-sign-in). `PROTOBASE_SIGN_IN_2_ISSUER` and so on add [more providers](#more-than-one-provider) |
100
100
  | `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the [operator provider](#operator-provider) its staff sign in with to sign in as people, passed by the platform; staff sign-in is off without them. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional |
101
101
  | `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of `protobase serve`, addresses or CIDR ranges, comma separated, such as `172.30.87.1`, the Docker network's gateway in the [compose template](../guides/deploy.md#compose-template); see [Client addresses](#client-addresses) |
102
102
 
@@ -152,13 +152,13 @@ const auth = await loadProjectAuth(process.cwd()) // the project's fo
152
152
 
153
153
  await createUser(auth, { email, password?, name?, role? }) // the first user is always an admin; later ones default to `user`
154
154
  await hasUsers(auth) // boolean
155
- await listUsers(auth) // [{ id, email, role, banned, createdAt }], never passwords
155
+ await listUsers(auth, { after?, size? }) // a page, oldest first: { users: [{ id, email, role, banned, createdAt }], next? }, never passwords
156
156
  await setUserRole(auth, { email, role }) // a role of auth.roles, or several comma separated
157
157
  await setUserBanned(auth, { email, banned }) // banning ends the user's sessions and blocks sign-in
158
158
  await deleteUser(auth, email) // with sessions and accounts
159
159
  ```
160
160
 
161
- The last active admin cannot be deleted, demoted or banned: those functions throw instead, and Better Auth's admin endpoints answer `400 LAST_ADMIN`, so every caller is protected. An account created by `createUser` or an admin counts as having a verified address, since whoever created it vouches for it; that lets it sign in with an [emailed code](#emailed-sign-in-codes).
161
+ `listUsers` answers a page of `size` users (500 unless told), as Postgres pages them by creation; pass its `next` as `after` for the page after, until a page has no `next`. The last active admin cannot be deleted, demoted or banned: those functions throw instead, and Better Auth's admin endpoints answer `400 LAST_ADMIN`, so every caller is protected. An account created by `createUser` or an admin counts as having a verified address, since whoever created it vouches for it; that lets it sign in with an [emailed code](#emailed-sign-in-codes).
162
162
 
163
163
  Until a user exists sign-in fails, and `GET /api/auth/status` (public) answers `{ "needsAdmin": true, "signInMethods": ["password", "passkey"], "passwordReset": false, "socialProviders": [] }` so a login page can say what to do. The admin app's page then shows the `users create` command to run on the host. A hosting platform where nobody runs commands on the host sets `PROTOBASE_FIRST_ADMIN_URL` to its own page where the first user is added, such as its console's; the status then also answers `firstAdminUrl`, and the page links there in place of the command. `signInMethods` lists the ways to sign in the [sign-in policy](#sign-in-policy) leaves on (`password`, `emailCode`, `passkey`), `passwordReset` is whether [reset mail](#password-reset) can be sent and passwords are on, `signInFirst`, when there, says the page leads with an [emailed code](#emailed-sign-in-codes), `signUp`, when there, says anyone can [make an account](#open-sign-up), and `staffSignIn`, when there, names the provider of [staff sign-in](#staff-sign-in). Further users are created by an admin on the [Users page](#users-page), or with `createUser` on the host. The auth store holds a connection pool; scripts that call these functions end the process themselves.
164
164
 
@@ -607,7 +607,7 @@ Register the app with the provider as a confidential client with the redirect UR
607
607
  - **Linking by address, safely:** a provider's first sign-in for someone links their account only when the token says the provider verified the address (`email_verified: true`) and the account's own address is verified. Once linked, the link alone finds them: the provider's id and `sub`, whatever address the token carries later. A person linked to one subject of a provider is not linked to a second one by address (`403 PROVIDER_ACCOUNT_LINKED`), unless the provider signs in [devices](#device-accounts). The store holds each provider's account once, and for a provider that links one subject per person, one account per person (unique indexes on the provider and account id, and on the provider and person, auth store migration 11), so two first sign-ins at the same moment link one, whether they bring the same subject or two.
608
608
  - The [sign-in policy](#sign-in-policy) has one row for every one of them, and `GET /api/auth/status` names those with a button as `platformProviders: [{ provider, name }]` besides listing them in `socialProviders`.
609
609
 
610
- Set the first three together or none: some but not all of them stops the app at start with an error. In the config, `auth.signInProviders` takes a list of the same settings with `scopes`, `tokenSignIn`, `authorizationParams`, `hidden` and `devices`, and `[]` turns them off whatever the environment says:
610
+ Set the first three together or none: some but not all of them stops the app at start with an error. In the config, `auth.signInProviders` takes a list of the same settings with `scopes`, `tokenSignIn`, `authorizationParams`, `hidden`, `button` and `devices`, and `[]` turns them off whatever the environment says:
611
611
 
612
612
  ```ts
613
613
  auth: { signInProviders: [{ issuer, clientId, clientSecret, provider: 'oidc', name: 'Acme SSO', scopes: ['groups'] }] }
@@ -631,6 +631,7 @@ PROTOBASE_SIGN_IN_2_TOKENS=true
631
631
  - **Ids:** each provider has an id of its own; two with one id stop the app at start. A number without every number before it (a `_3_` set without a `_2_` one, or a `_2_` set without the first) stops it too, as does `_1_` or `_02_`.
632
632
  - **Names:** `name` (`PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_2_NAME`) is what people see, apart from the id, so two providers may show the same name.
633
633
  - **Fixed authorization parameters:** `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS` (`authorizationParams` in the config), written as `name=value&other=value`, goes on every authorization request to that provider as given, such as a parameter naming which of its own sign-in methods it must use. A client cannot change or add to them: a sign-in or link with a platform provider that brings `additionalParams` of its own answers `400 AUTHORIZATION_PARAMS_FIXED`. The parameters the sign-in sets itself (`state`, `client_id`, `redirect_uri`, `response_type`, `scope`, `nonce`, `code_challenge`, `code_challenge_method`) cannot be fixed; naming one stops the app at start.
634
+ - **No button:** `PROTOBASE_SIGN_IN_BUTTON=false` (`button: false`) keeps "Continue with {name}" off the sign-in page for a provider with pages. People still sign in through its pages when something sends them there: a [sign-in link](#sign-in-links-and-connected-accounts) (`?sign-in=<provider>`), or a redirect another app starts. `GET /api/auth/status` still lists it in `socialProviders`, so links work, and marks it `button: false` in `platformProviders`. A provider of [token sign-in](#token-sign-in) alone has no button anyway, and naming one stops the app at start. The account page's connected accounts follow `hidden`, not this.
634
635
  - **Kept off the account page:** `PROTOBASE_SIGN_IN_HIDDEN=true` (`hidden: true`) keeps people's links to that provider off the account page: the connected accounts do not list it, `/api/auth/list-accounts` leaves its links out, and connecting it, or disconnecting one of its links by its id, answers `403 PROVIDER_ACCOUNT_HIDDEN`. The link still signs in, and goes when the person is deleted. `GET /api/auth/status` marks it `hidden: true` in `platformProviders`.
635
636
 
636
637
  ### Device accounts
@@ -439,7 +439,7 @@ Serves the API of a bundle from `protobase build` and owns the process around it
439
439
  | `PROTOBASE_SMTP_URL` | the SMTP server for password-reset mail, emailed sign-in and two-factor codes and the app's own [email](email.md), credential included: `smtp://user:password@host:587` (STARTTLS required, `?requireTLS=false` sends in plaintext, see [Email](email.md#configuration)) or `smtps://...:465`; without it they are off ([Password reset](auth.md#password-reset), [Emailed sign-in codes](auth.md#emailed-sign-in-codes)) |
440
440
  | `PROTOBASE_MAIL_FROM` | the sender of that mail, a plain address such as `noreply@admin.example.com`; set with `PROTOBASE_SMTP_URL` or not at all |
441
441
  | `PROTOBASE_APP_NAME` | the app's name, such as `Property Finder`: what its auth emails, its sidebar, its browser tabs and the [installed app](installable-app.md) call it, and the sender's display name of its mail, over the config's [`name`](config/app.md#name) |
442
- | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` are optional, `PROTOBASE_SIGN_IN_TOKENS=true` turns on [token sign-in](auth.md#token-sign-in), and `PROTOBASE_SIGN_IN_2_ISSUER` and so on add more providers ([Platform sign-in providers](auth.md#platform-sign-in-providers)) |
442
+ | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | an OpenID Connect provider people who have an account can sign in with; all three or none. `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS`, `PROTOBASE_SIGN_IN_HIDDEN`, `PROTOBASE_SIGN_IN_BUTTON` and `PROTOBASE_SIGN_IN_DEVICES` are optional, `PROTOBASE_SIGN_IN_TOKENS=true` turns on [token sign-in](auth.md#token-sign-in), and `PROTOBASE_SIGN_IN_2_ISSUER` and so on add more providers ([Platform sign-in providers](auth.md#platform-sign-in-providers)) |
443
443
  | `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET` | the OpenID Connect provider of the operator's staff, for [staff sign-in](auth.md#staff-sign-in) as people of the app; all three or none. `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP` are optional ([Operator provider](auth.md#operator-provider)) |
444
444
  | `PROTOBASE_ORIGINS`, `PROTOBASE_PASSKEY_DOMAIN` | the other origins the app is served on, comma separated, and the host new passkeys are made for ([Several origins](auth.md#several-origins)) |
445
445
  | `PROTOBASE_CORS_ORIGINS` | other websites whose browser code may call the API, `*` or comma separated http and https origins ([CORS](api.md#cors)) |
@@ -167,11 +167,11 @@ export default defineConfig(({ env }) => ({
167
167
 
168
168
  ## auth.signInProviders
169
169
 
170
- - **Type:** `{ issuer: string; clientId?: string; clientSecret?: string; provider?: string; name?: string; scopes?: string[]; authorizationParams?: Record<string, string>; tokenSignIn?: boolean; hidden?: boolean; devices?: boolean }[]`
170
+ - **Type:** `{ issuer: string; clientId?: string; clientSecret?: string; provider?: string; name?: string; scopes?: string[]; authorizationParams?: Record<string, string>; tokenSignIn?: boolean; hidden?: boolean; button?: boolean; devices?: boolean }[]`
171
171
  - **Default:** the providers of the environment variables below, when set
172
- - **Environment variables:** `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET`, and optionally `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS` (`name=value&other=value`), `PROTOBASE_SIGN_IN_TOKENS`, `PROTOBASE_SIGN_IN_HIDDEN` and `PROTOBASE_SIGN_IN_DEVICES` (`true` or `false`); the same with `_2_`, `_3_` and so on after `PROTOBASE_SIGN_IN` for each further provider
172
+ - **Environment variables:** `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET`, and optionally `PROTOBASE_SIGN_IN_PROVIDER`, `PROTOBASE_SIGN_IN_NAME`, `PROTOBASE_SIGN_IN_AUTHORIZATION_PARAMS` (`name=value&other=value`), `PROTOBASE_SIGN_IN_TOKENS`, `PROTOBASE_SIGN_IN_HIDDEN`, `PROTOBASE_SIGN_IN_BUTTON` and `PROTOBASE_SIGN_IN_DEVICES` (`true` or `false`); the same with `_2_`, `_3_` and so on after `PROTOBASE_SIGN_IN` for each further provider
173
173
 
174
- The OpenID Connect providers the platform adds for people who already have an account; they never sign anyone up. Each has its own `provider` id (default `oidc`) and `name` people see; `authorizationParams` go on every authorization request to it, unchangeable by the client; `tokenSignIn: true` lets a client sign in with a fresh ID token it issued for this app ([Token sign-in](../auth.md#token-sign-in), default off); `hidden: true` keeps its links off the account page; `devices: true` makes each device an account of its own ([Devices](../auth.md#device-accounts)). `[]` turns them off whatever the environment says. One is left out when `socialProviders` has a provider with its id. Without `clientSecret` one signs in by token sign-in alone, which `tokenSignIn: true` must then turn on, with tokens for the origin of `url` unless `clientId` names another. See [Platform sign-in providers](../auth.md#platform-sign-in-providers).
174
+ The OpenID Connect providers the platform adds for people who already have an account; they never sign anyone up. Each has its own `provider` id (default `oidc`) and `name` people see; `authorizationParams` go on every authorization request to it, unchangeable by the client; `tokenSignIn: true` lets a client sign in with a fresh ID token it issued for this app ([Token sign-in](../auth.md#token-sign-in), default off); `hidden: true` keeps its links off the account page; `button: false` keeps its button off the sign-in page, so only a sign-in link or another app's redirect starts it; `devices: true` makes each device an account of its own ([Devices](../auth.md#device-accounts)). `[]` turns them off whatever the environment says. One is left out when `socialProviders` has a provider with its id. Without `clientSecret` one signs in by token sign-in alone, which `tokenSignIn: true` must then turn on, with tokens for the origin of `url` unless `clientId` names another. See [Platform sign-in providers](../auth.md#platform-sign-in-providers).
175
175
 
176
176
  ```ts
177
177
  export default defineConfig({ auth: { signInProviders: [] } })