@protobase/cli 0.46.14 → 0.47.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.46.14";
2
+ var version = "0.47.0";
3
3
  //#endregion
4
4
  export { version };
package/dist/main.js CHANGED
@@ -16,7 +16,7 @@ import { registerImport } from "./supabase/register.js";
16
16
  import { registerToken, registerUsers } from "./users/register.js";
17
17
  import { ExitSignal } from "./exit-signal.js";
18
18
  import { errorMessage } from "./error-message.js";
19
- import { checkProjectMajor } from "./version/project-version.js";
19
+ import { checkProjectVersion } from "./version/project-version.js";
20
20
  import { statSync } from "node:fs";
21
21
  import path from "node:path";
22
22
  import { Command, InvalidArgumentError } from "commander";
@@ -30,7 +30,7 @@ const uiSection = (value) => {
30
30
  };
31
31
  const collectSection = (value, previous) => [...previous, uiSection(value)];
32
32
  const program = new Command("protobase").description("Protobase command line").version(protobaseVersion, "-v, --version", "print the Protobase version");
33
- program.hook("preAction", () => checkProjectMajor(process.cwd()));
33
+ program.hook("preAction", () => checkProjectVersion(process.cwd()));
34
34
  program.command("scaffold").description("Generate or update config/<resource>/data.ts from a Postgres database").argument("[args...]", "connection string (default: DATABASE_URL from the environment or .env) followed by an optional target: all, schema, schema.table, schema.table.column").option("--env <variable>", "read the connection string from this environment variable").option("--config <dir>", "config folder", "config").option("--yes", "accept all proposals without asking", false).option("--dry-run", "print a diff instead of writing files", false).option("--ui", "also write config/<resource>/ui.ts (names and list)", false).option("--ui-list", "write only the list section of ui.ts", false).option("--ui-section <name>", "write only this ui.ts section (names or list), repeatable", collectSection, []).option("--exclude <table>", "skip a schema or schema.table, repeatable", collect, []).action(async (args, opts) => {
35
35
  loadNearestEnvFile(process.cwd());
36
36
  const [first, ...rest] = args;
@@ -2,6 +2,7 @@ import { protobaseVersion } from "./version.js";
2
2
  import { findPackageDirSync } from "../build/packages/package-dir.js";
3
3
  import { readFileSync } from "node:fs";
4
4
  import path from "node:path";
5
+ import semver from "semver";
5
6
  //#region src/version/project-version.ts
6
7
  const projectPackages = [
7
8
  "@protobase/cli",
@@ -18,15 +19,17 @@ const projectProtobaseVersion = (projectDir) => {
18
19
  if (dir) return JSON.parse(readFileSync(path.join(dir, "package.json"), "utf8")).version;
19
20
  }
20
21
  };
21
- const major = (version) => version.split(".")[0];
22
22
  /**
23
- * Refuses a project of another Protobase major than this CLI's, the one version check the CLI makes: within a major a
24
- * CLI runs every project, whatever its minor. Outside a project, or before its install, there is nothing to check.
23
+ * Refuses a project whose Protobase version this CLI is not compatible with, the one version check the CLI makes: the
24
+ * CLI's version must be in the caret range of the project's, so from 1.0 on the same major and below 1.0, where a minor
25
+ * may break, the same minor, and never older. Outside a project, or before its install, there is nothing to check.
25
26
  */
26
- const checkProjectMajor = (projectDir, cliVersion = protobaseVersion) => {
27
+ const checkProjectVersion = (projectDir, cliVersion = protobaseVersion) => {
27
28
  const project = projectProtobaseVersion(projectDir);
28
- if (project === void 0 || major(project) === major(cliVersion)) return;
29
- throw new Error(`This project is on Protobase ${project}, and this CLI is Protobase ${cliVersion}: run it with a Protobase ${major(project)}.x CLI`);
29
+ if (project === void 0) return;
30
+ const range = `^${project}`;
31
+ if (semver.satisfies(cliVersion, range)) return;
32
+ throw new Error(`This project is on Protobase ${project}, and this CLI is Protobase ${cliVersion}: run it with a Protobase ${range} CLI`);
30
33
  };
31
34
  //#endregion
32
- export { checkProjectMajor, projectProtobaseVersion };
35
+ export { checkProjectVersion, projectProtobaseVersion };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.46.14",
3
+ "version": "0.47.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": {
@@ -39,11 +39,11 @@
39
39
  "@better-auth/core": "^1.7.12",
40
40
  "@hono/node-server": "^2.1.3",
41
41
  "@hono/vite-dev-server": "^0.26.1",
42
- "@protobase/layout": "0.46.14",
43
- "@protobase/query": "0.46.14",
44
- "@protobase/schema": "0.46.14",
45
- "@protobase/server": "0.46.14",
46
- "@protobase/ui": "0.46.14",
42
+ "@protobase/layout": "0.47.0",
43
+ "@protobase/query": "0.47.0",
44
+ "@protobase/schema": "0.47.0",
45
+ "@protobase/server": "0.47.0",
46
+ "@protobase/ui": "0.47.0",
47
47
  "@react-email/render": "^2.1.0",
48
48
  "@scalar/hono-api-reference": "^0.12.10",
49
49
  "@tailwindcss/vite": "^4.3.3",
@@ -10,7 +10,7 @@ Sign-in methods, users, roles, organizations and tokens.
10
10
  - [Users page](../reference/auth.md#users-page): Admins find people, set roles, block them, add accounts and invite people by email.
11
11
  - [Password reset](../reference/auth.md#password-reset): People reset a forgotten password through an emailed link.
12
12
  - [Leaked passwords](../reference/auth.md#leaked-passwords): New passwords that appear in a known data breach are refused, when the app turns the check on.
13
- - [Emailed sign-in codes](../reference/auth.md#emailed-sign-in-codes): People sign in with a code sent to their email. An address with no account is emailed that it has none, so the person tries the one they signed up with.
13
+ - [Emailed sign-in codes](../reference/auth.md#emailed-sign-in-codes): People sign in with a code sent to their email. An address with no account is emailed that it has none, so the person tries the one they signed up with. An app can have the sign-in page lead with the code and put the password behind "Use a password".
14
14
  - [Changing the address](../reference/auth.md#changing-the-address): People move their account to a new email address from the account page, once they enter the code sent there.
15
15
  - [Open sign-up](../reference/auth.md#open-sign-up): Anyone can create an account after confirming an emailed code.
16
16
  - [Passkeys](../reference/auth.md#passkeys): People sign in with their device's face or fingerprint unlock, or with a security key.
@@ -88,7 +88,7 @@ bun run --cwd examples/property-portal dev # http://localhost:5173
88
88
  | `bun run test:watch` | `bun run test` in watch mode |
89
89
  | `bun run test:integration` | the database, subprocess and build tests (projects `integration*`), against the Postgres container, among them the real-Postgres tests (`*.postgres.test.ts`) |
90
90
  | `bun run test:smoke` / `node --run test:smoke` | the CLI on Bun or on Node builds the ERP and serves its bundle, whose `€` must come back intact; part of `test:integration` on Bun |
91
- | `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in the range of `<version>`'s major (`>=0.y.z <1` below 1.0, `^x.y.z` from 1.0) and its own `bun.lock` at exactly `<version>`, which must be on npm |
91
+ | `bun run presets:write <version> <dir>` | writes each preset to `<dir>/<name>`: a standalone copy of its example with the `@protobase` packages in the caret range of `<version>` (`^x.y.z`, which below 1.0 covers only that minor) and its own `bun.lock` at exactly `<version>`, which must be on npm |
92
92
  | `bun run images:context` | the build contexts of the `protobase` and `protobase-dev` images in `dist/images`, at the version in `package.json` (see [Deploy](guides/deploy.md#images)) |
93
93
  | `bun run test:presets` | writes each preset as `bun run presets:write` does it and installs it with Bun from npm (so at a published version), then migrates, seeds, checks, tests and builds it on a database of its own, as a role without superuser rights; needs the Postgres container |
94
94
  | `bun run test:postgres` | the Postgres suite in `tests/postgres/` (Vitest project `postgres`): the ERP's medium seed and the planner's statistics on it, and the jobs and event delivery through PgBouncer; needs the Postgres and PgBouncer containers and `bun run test:db postgres` |
@@ -20,7 +20,7 @@ A Bun workspace of npm packages under the `@protobase` scope, in `packages/<name
20
20
  | `@protobase/presets` | `packages/presets` | none: private, `bun run presets:write` writes a project per preset | Bun | none; each preset depends on the `@protobase` packages of the major it is written at, locked at that version |
21
21
  | `examples/*` | | none | any | `@protobase/*` entry points only |
22
22
 
23
- The presets are written from `examples/erp`, `examples/real-estate` and `examples/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the range of `<version>`'s major, `>=0.y.z <1` below 1.0 (where `^0.y.z` would cover only that minor) and `^x.y.z` from 1.0, so an app takes updates within that major, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
23
+ The presets are written from `examples/erp`, `examples/real-estate` and `examples/scratch` (from scratch) by `bun run presets:write <version> <dir>`, run from a clone of this repository; `npm create protobase` (`packages/create-protobase`) writes them too, without a lockfile. Each is a standalone copy with the `@protobase` packages in the caret range of `<version>`, `^x.y.z`, so an app takes the updates semver calls compatible: within that major from 1.0 on, and within that minor below 1.0, where a minor may break, and its own `bun.lock` at exactly `<version>`. The three declare the same dependencies, so one `node_modules` fits them all, and their `db:migrate` (the auth schema's migrations included), `typecheck` and `test` scripts take their settings from the environment, or a `.env` beside them, and reach nothing outside the project.
24
24
 
25
25
  The JSX runtime belongs to `@protobase/layout` because a layout file names one package in `@jsxImportSource @protobase/layout`, and TypeScript and Vite look up `jsx-runtime` and `jsx-dev-runtime` under it. Each field type is split along the same lines: its Zod builder is `packages/schema/src/fields/<type>.ts` and its SQL parameter conversion `packages/query/src/fields/<type>.ts`.
26
26
 
@@ -113,7 +113,7 @@ await deleteUser(auth, email) // with sessions an
113
113
 
114
114
  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).
115
115
 
116
- 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. `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, `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.
116
+ 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. `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.
117
117
 
118
118
  ## Users page
119
119
 
@@ -258,6 +258,12 @@ With mail configured, the account page's Profile tab offers "Change email": the
258
258
 
259
259
  With mail configured, the sign-in page offers "Email me a sign-in code": the person enters their address, gets a 6-digit code, and signs in with it instead of a password. It is Better Auth's [email OTP](https://www.better-auth.com/docs/plugins/email-otp) plugin: `POST /api/auth/email-otp/send-verification-otp` with `{ email, type: "sign-in" }`, then `POST /api/auth/sign-in/email-otp` with `{ email, otp }`.
260
260
 
261
+ By default the page leads with the password and offers the code below it. For an app whose people mostly never set a password, `signInFirst: 'emailCode'` leads with the code instead: the page asks for the address and "Email me a sign-in code", and the password field, with "Forgot password?", waits behind "Use a password". It applies while the [sign-in policy](#sign-in-policy) leaves both on; `/api/auth/status` then answers `signInFirst: "emailCode"`.
262
+
263
+ ```ts
264
+ createAuth({ ..., signInFirst: 'emailCode' })
265
+ ```
266
+
261
267
  - A code works for 10 minutes, once, and three wrong tries end it; asking again sends a new one and the old one stops working. Codes are stored hashed.
262
268
  - It never creates an account: an address no account uses gets no code but an email saying so, which suggests signing in with the address the person signed up with. The answer is the same either way, so it does not tell who has an account.
263
269
  - Only sign-in codes are mailed this way. The plugin's own email verification and password reset endpoints are off (`404`), and asking for another type of code answers `400`. Its address change is on, as [Changing the address](#changing-the-address) describes.
@@ -56,13 +56,13 @@ Running the workflow by hand with a tag (`gh workflow run release.yml -f tag=v0.
56
56
 
57
57
  ## Bundles and runtimes
58
58
 
59
- The CLI makes one version check, when it starts: the project in the current directory, by the `@protobase` packages installed there, must be of the CLI's own major version. A 0.x CLI runs every 0.x project, whatever its minor, and refuses a 1.x one before any command runs:
59
+ The CLI makes one version check, when it starts: its own version must be in the caret range of the project's, the version of the `@protobase` packages installed in the current directory, which semver calls compatible with it. From 1.0 on that is the same major, and below 1.0, where a minor may break, the same minor, never older than the project's. A 0.14.2 CLI runs a 0.14.0 project and refuses a 0.15.0 or a 1.2.0 one before any command runs:
60
60
 
61
61
  ```
62
- error: This project is on Protobase 1.2.0, and this CLI is Protobase 0.14.2: run it with a Protobase 1.x CLI
62
+ error: This project is on Protobase 1.2.0, and this CLI is Protobase 0.14.2: run it with a Protobase ^1.2.0 CLI
63
63
  ```
64
64
 
65
- Within a major the CLI stays backwards compatible, so a platform builds every app with the newest CLI of the app's major. Nothing else compares versions: not the build, not the serve runtime. `protobase build` writes the version the project is pinned to, the `@protobase/cli` its lockfile installed, into [the manifest](cli.md#the-manifest) as `protobase`, whichever CLI built the bundle, and a host serves the bundle on the runtime of that version. The check is `checkProjectMajor` in `packages/cli/src/version/project-version.ts`.
65
+ Within its caret range the CLI stays backwards compatible, so a platform builds every app with the newest CLI in the caret range of the app's version. Nothing else compares versions: not the build, not the serve runtime. `protobase build` writes the version the project is pinned to, the `@protobase/cli` its lockfile installed, into [the manifest](cli.md#the-manifest) as `protobase`, whichever CLI built the bundle, and a host serves the bundle on the runtime of that version. The check is `checkProjectVersion` in `packages/cli/src/version/project-version.ts`.
66
66
 
67
67
  ## Plugins
68
68