@protobase/cli 0.126.2 → 0.127.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.126.2";
2
+ var version = "0.127.0";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,56 @@
1
+ import { protobaseFolder } from "../project/protobase-folder.js";
2
+ import { heldOn } from "./loopback.js";
3
+ import path from "node:path";
4
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
5
+ //#region src/dev/dev-port.ts
6
+ /** Where `protobase dev` keeps the project's port: `.protobase/` is this machine's and ignores itself in git. */
7
+ const devPortFile = path.join(protobaseFolder, "dev-port");
8
+ const randomPorts = {
9
+ min: 1e4,
10
+ max: 49151
11
+ };
12
+ const tries = 20;
13
+ /** The port saved for the project, undefined when no file holds one, such as a missing or garbled file. */
14
+ const readSavedPort = async (projectDir) => {
15
+ let text;
16
+ try {
17
+ text = await readFile(path.join(projectDir, devPortFile), "utf8");
18
+ } catch (error) {
19
+ if (error.code === "ENOENT") return;
20
+ throw error;
21
+ }
22
+ const trimmed = text.trim();
23
+ if (!/^\d{1,5}$/.test(trimmed)) return;
24
+ const port = Number(trimmed);
25
+ return port >= 1 && port <= 65535 ? port : void 0;
26
+ };
27
+ const savePort = async (projectDir, port) => {
28
+ if (await readSavedPort(projectDir) === port) return;
29
+ await mkdir(path.join(projectDir, protobaseFolder), { recursive: true });
30
+ await writeFile(path.join(projectDir, devPortFile), `${port}\n`);
31
+ };
32
+ /** A random port in `randomPorts` that no process holds on either loopback address, trying a fixed number of them. */
33
+ const pickFreePort = async (held = heldOn, random = Math.random) => {
34
+ for (let tried = 0; tried < tries; tried++) {
35
+ const port = randomPorts.min + Math.floor(random() * (randomPorts.max - randomPorts.min + 1));
36
+ if (!await held(port)) return port;
37
+ }
38
+ throw new Error(`Found no free port among ${tries} random ones from ${randomPorts.min} to ${randomPorts.max}; pass one with --port <port>`);
39
+ };
40
+ /**
41
+ * The port `protobase dev` serves the project on: `chosen`, saved as the project's port for later runs, else the saved
42
+ * one, else a free random one, saved.
43
+ */
44
+ const devPort = async (projectDir, chosen, pick = pickFreePort) => {
45
+ if (chosen !== void 0) {
46
+ await savePort(projectDir, chosen);
47
+ return chosen;
48
+ }
49
+ const saved = await readSavedPort(projectDir);
50
+ if (saved !== void 0) return saved;
51
+ const picked = await pick();
52
+ await savePort(projectDir, picked);
53
+ return picked;
54
+ };
55
+ //#endregion
56
+ export { devPort, devPortFile, pickFreePort, randomPorts, readSavedPort, savePort };
@@ -10,17 +10,36 @@ const listen = (server, port, host) => new Promise((resolve, reject) => {
10
10
  resolve();
11
11
  });
12
12
  });
13
- const hold = async (server, port, host) => {
13
+ const listenOn = async (server, port, host) => {
14
14
  try {
15
15
  await listen(server, port, host);
16
16
  return true;
17
17
  } catch (error) {
18
18
  const { code } = error;
19
- if (code === "EADDRINUSE") throw new Error(`Port ${port} is in use by another server on ${host}, which would answer http://localhost:${port} instead. Stop it, or run on a free port with --port`);
20
19
  if (code && missingFamily.includes(code)) return false;
21
20
  throw error;
22
21
  }
23
22
  };
23
+ const hold = async (server, port, host) => {
24
+ try {
25
+ return await listenOn(server, port, host);
26
+ } catch (error) {
27
+ if (error.code !== "EADDRINUSE") throw error;
28
+ throw new Error(`Port ${port} is in use by another server on ${host}, which would answer http://localhost:${port} instead. Stop it, or run on another port with --port <port>, which the project then keeps`);
29
+ }
30
+ };
31
+ /** The loopback address where another process holds `port`, undefined when neither does. */
32
+ const heldOn = async (port) => {
33
+ for (const host of loopbacks) {
34
+ const probe = createServer();
35
+ try {
36
+ if (await listenOn(probe, port, host)) await new Promise((resolve) => probe.close(resolve));
37
+ } catch (error) {
38
+ if (error.code === "EADDRINUSE") return host;
39
+ throw error;
40
+ }
41
+ }
42
+ };
24
43
  /** Fails when another process holds `port` on either loopback address, before the dev server starts. */
25
44
  const checkPortFree = async (port) => {
26
45
  for (const host of loopbacks) {
@@ -39,4 +58,4 @@ const alsoOnIpv6 = async (httpServer, port) => {
39
58
  return forwarder;
40
59
  };
41
60
  //#endregion
42
- export { alsoOnIpv6, checkPortFree, devHost };
61
+ export { alsoOnIpv6, checkPortFree, devHost, heldOn };
@@ -0,0 +1,21 @@
1
+ //#region src/dev/url-port.ts
2
+ const loopbackHosts = [
3
+ "localhost",
4
+ "127.0.0.1",
5
+ "[::1]"
6
+ ];
7
+ /**
8
+ * A warning when PROTOBASE_URL is this machine on another port than the dev server's: sign-in then refuses the pages
9
+ * the dev server serves, since they come from another origin. Undefined otherwise, such as for a tunnel's URL.
10
+ */
11
+ const urlPortWarning = (env, port) => {
12
+ const value = env.PROTOBASE_URL?.trim();
13
+ if (!value || !URL.canParse(value)) return;
14
+ const url = new URL(value);
15
+ if (!loopbackHosts.includes(url.hostname)) return;
16
+ const urlPort = url.port || (url.protocol === "https:" ? "443" : "80");
17
+ if (urlPort === String(port)) return;
18
+ return `PROTOBASE_URL is ${url.origin}, but protobase dev serves http://localhost:${port}, where sign-in refuses its pages: remove PROTOBASE_URL from .env, so dev uses its own address, or run protobase dev --port ${urlPort} once to keep that port`;
19
+ };
20
+ //#endregion
21
+ export { urlPortWarning };
package/dist/main.js CHANGED
@@ -3,6 +3,7 @@ import { registerBuckets } from "./buckets/register.js";
3
3
  import { defaultConnectionEnv, isConnectionString, resolveConnectionUrl } from "./db/connection-url.js";
4
4
  import { parseHosts } from "./dev/hosts.js";
5
5
  import { loadNearestEnvFile } from "./dev/env.js";
6
+ import { parsePort } from "./mobile/arguments.js";
6
7
  import { placeholderSecretWarning } from "./project/placeholder-secret.js";
7
8
  import { registerOrganizations } from "./organizations/register.js";
8
9
  import { registerFiles } from "./files/register.js";
@@ -83,21 +84,26 @@ const runUiDevAgainst = async (api, options) => {
83
84
  }, out);
84
85
  };
85
86
  const runFullDev = async (envVar, jobs, options) => {
86
- const { runDev } = await import("./dev/run.js");
87
+ const [{ runDev }, { urlPortWarning }] = await Promise.all([import("./dev/run.js"), import("./dev/url-port.js")]);
87
88
  const server = await runDev({
88
89
  ...options,
89
90
  envVar,
90
91
  jobs
91
92
  }, out);
92
93
  warn(placeholderSecretWarning(process.env));
94
+ warn(urlPortWarning(process.env, options.port));
93
95
  return server;
94
96
  };
95
- program.command("dev").description("Serve the admin app and API for the project in the current directory").option("--port <port>", "port for the app and API", "5173").option("--env <variable>", "environment variable holding the database URL", "DATABASE_URL").option("--allowed-hosts <hosts>", "extra Host headers to accept, comma separated; a leading dot matches subdomains (.trycloudflare.com)").option("--cache-dir <dir>", "Vite's dependency cache, so parallel dev servers do not share one").option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).option("--no-jobs", "run none of the app's jobs and deliver none of its events, such as against its hosted database").option("--api <url>", "serve the admin app alone, with the API of the running Protobase instance at this URL; no database or API process").action(async (opts) => {
96
- const [{ resolveExtensions }, { writeProjectTypes }] = await Promise.all([import("./project/extensions.js"), import("./project/project-types.js")]);
97
+ program.command("dev").description("Serve the admin app and API for the project in the current directory").option("--port <port>", "port for the app and API, kept as the project's port (default: the kept one, else a free random one)", parsePort).option("--env <variable>", "environment variable holding the database URL", "DATABASE_URL").option("--allowed-hosts <hosts>", "extra Host headers to accept, comma separated; a leading dot matches subdomains (.trycloudflare.com)").option("--cache-dir <dir>", "Vite's dependency cache, so parallel dev servers do not share one").option("--extend <dir>", "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable", collect, []).option("--no-jobs", "run none of the app's jobs and deliver none of its events, such as against its hosted database").option("--api <url>", "serve the admin app alone, with the API of the running Protobase instance at this URL; no database or API process").action(async (opts) => {
98
+ const [{ resolveExtensions }, { writeProjectTypes }, { devPort }] = await Promise.all([
99
+ import("./project/extensions.js"),
100
+ import("./project/project-types.js"),
101
+ import("./dev/dev-port.js")
102
+ ]);
97
103
  await writeProjectTypes(process.cwd());
98
104
  const shared = {
99
105
  extensions: resolveExtensions(opts.extend),
100
- port: Number(opts.port),
106
+ port: await devPort(process.cwd(), opts.port),
101
107
  projectDir: process.cwd(),
102
108
  cacheDir: opts.cacheDir && path.resolve(opts.cacheDir),
103
109
  allowedHosts: parseHosts(opts.allowedHosts)
@@ -0,0 +1,11 @@
1
+ import { readSavedPort } from "../dev/dev-port.js";
2
+ //#region src/mobile/live-port.ts
3
+ /** The port of the `protobase dev` that `--live` opens: `--port`, else the one dev keeps for the project. */
4
+ const livePort = async (projectDir, chosen) => {
5
+ if (chosen !== void 0) return chosen;
6
+ const saved = await readSavedPort(projectDir);
7
+ if (saved === void 0) throw new Error("--live opens protobase dev, which has kept no port in this project yet: run protobase dev first, or pass --port <port>");
8
+ return saved;
9
+ };
10
+ //#endregion
11
+ export { livePort };
@@ -8,8 +8,12 @@ const registerMobile = (program) => {
8
8
  const api = "--api <url>";
9
9
  const apiHelp = "the server the app calls (default: the app's URL, url or PROTOBASE_URL)";
10
10
  const extend = "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable";
11
- mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--team <id>", "iOS: your Apple Developer team id, which signs the app to run on your iPhone", parseTeamId).option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
12
- const [{ mobileRun }, { resolveExtensions }] = await Promise.all([import("./run.js"), import("../project/extensions.js")]);
11
+ mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--team <id>", "iOS: your Apple Developer team id, which signs the app to run on your iPhone", parseTeamId).option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live (default: the project's kept dev port)", parsePort).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
12
+ const [{ mobileRun }, { resolveExtensions }, { livePort }] = await Promise.all([
13
+ import("./run.js"),
14
+ import("../project/extensions.js"),
15
+ import("./live-port.js")
16
+ ]);
13
17
  await mobileRun({
14
18
  projectDir: process.cwd(),
15
19
  platform: chosen,
@@ -17,7 +21,7 @@ const registerMobile = (program) => {
17
21
  ...opts.api !== void 0 && { api: opts.api },
18
22
  ...opts.target && { target: opts.target },
19
23
  ...opts.team && { team: opts.team },
20
- ...opts.live && { live: opts.port }
24
+ ...opts.live && { live: await livePort(process.cwd(), opts.port) }
21
25
  }, out);
22
26
  });
23
27
  mobile.command("open").description("Generate the native project and open it in Xcode or Android Studio").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.126.2",
3
+ "version": "0.127.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.126.2",
47
- "@protobase/layout": "0.126.2",
48
- "@protobase/query": "0.126.2",
49
- "@protobase/schema": "0.126.2",
50
- "@protobase/server": "0.126.2",
51
- "@protobase/ui": "0.126.2",
52
- "@protobase/workflows": "0.126.2",
46
+ "@protobase/config": "0.127.0",
47
+ "@protobase/layout": "0.127.0",
48
+ "@protobase/query": "0.127.0",
49
+ "@protobase/schema": "0.127.0",
50
+ "@protobase/server": "0.127.0",
51
+ "@protobase/ui": "0.127.0",
52
+ "@protobase/workflows": "0.127.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",
@@ -5,7 +5,7 @@
5
5
  Develop, build and run an app, on servers, in containers and on phones.
6
6
 
7
7
  - [Node and Bun](../reference/cli.md#how-it-runs): The `protobase` command runs on Node 22.12 or later or on Bun, and a bundle runs on both unless it is built for Bun only.
8
- - [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart.
8
+ - [Dev server](../reference/cli.md#dev): The admin app and the API on one port, with changes shown without a restart; each project keeps its own port, so its address and bookmarks stay the same.
9
9
  - [Dev server without jobs](../reference/cli.md#dev): `protobase dev --no-jobs` runs no jobs and delivers no events, webhooks or pushes, to develop against a hosted app's database without doing its work twice.
10
10
  - [UI-only dev server](../reference/cli.md#ui-only) (beta): `protobase dev --api <url>` serves the app's UI from the project with the API of an app already running, such as its staging deploy, with no database.
11
11
  - [Editor types](../reference/cli.md#types): `protobase types` gives the editor and `tsc` the types of the CLI that builds the app, with nothing installed.
@@ -35,7 +35,7 @@ bun install
35
35
  bun run db:up
36
36
  bun run db:migrate
37
37
  bun run protobase users create you@example.com --generate-password
38
- bun run dev # http://localhost:5173
38
+ bun run dev # prints its address, http://localhost:<port>
39
39
  ```
40
40
 
41
41
  ### The first table
@@ -75,7 +75,7 @@ It never writes to the database. The first of the next steps does: `bun run db:m
75
75
  cd shop
76
76
  bun run db:migrate # the first write to the database
77
77
  bun run protobase users create you@example.com --generate-password
78
- bun run dev # http://localhost:5173
78
+ bun run dev # prints its address, http://localhost:<port>
79
79
  ```
80
80
 
81
81
  #### On a Supabase database
@@ -113,10 +113,10 @@ bun install
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
115
  bun run --cwd tests/apps/erp protobase users create you@example.com --generate-password
116
- bun run --cwd tests/apps/erp dev # http://localhost:5173
116
+ bun run --cwd tests/apps/erp dev # prints its address, http://localhost:<port>
117
117
  ```
118
118
 
119
- `PROTOBASE_SECRET` in `tests/apps/erp/.env` signs the session cookies; see [Login with Better Auth](reference/auth.md). `protobase dev` serves the admin app and the API on one port and reloads both on every change ([CLI](reference/cli.md#dev)). Its startup message says how to sign in: while the database has no users, it prints the exact `users create` command for the first admin. It stops with a clear message when another server holds its port; pass `--port 5174` to run a second app beside it.
119
+ `PROTOBASE_SECRET` in `tests/apps/erp/.env` signs the session cookies; see [Login with Better Auth](reference/auth.md). `protobase dev` serves the admin app and the API on one port and reloads both on every change ([CLI](reference/cli.md#dev)). Its startup message says how to sign in: while the database has no users, it prints the exact `users create` command for the first admin. Each example keeps a port of its own, picked on its first run, so they run side by side at addresses that stay the same; it stops with a clear message when another server holds that port, and `--port <port>` changes it.
120
120
 
121
121
  ## Run the real estate example
122
122
 
@@ -125,7 +125,7 @@ bun run --cwd tests/apps/erp dev # http://localhost:517
125
125
  ```sh
126
126
  bun run db:up && bun run --cwd tests/apps/real-estate db:migrate && bun run --cwd tests/apps/real-estate db:seed --scale small
127
127
  bun run --cwd tests/apps/real-estate protobase users create you@example.com --role admin --generate-password
128
- bun run --cwd tests/apps/real-estate dev # http://localhost:5173
128
+ bun run --cwd tests/apps/real-estate dev # prints its address, http://localhost:<port>
129
129
  ```
130
130
 
131
131
  ## Run the property portal example
@@ -134,7 +134,7 @@ bun run --cwd tests/apps/real-estate dev # http://localhost:517
134
134
 
135
135
  ```sh
136
136
  bun run db:up && bun run --cwd tests/apps/property-portal db:migrate && bun run --cwd tests/apps/property-portal db:seed --scale small
137
- bun run --cwd tests/apps/property-portal dev # http://localhost:5173
137
+ bun run --cwd tests/apps/property-portal dev # prints its address, http://localhost:<port>
138
138
  ```
139
139
 
140
140
  ## Commands
@@ -21,12 +21,12 @@ export default defineFunction((_request, { session }) =>
21
21
  )
22
22
  ```
23
23
 
24
- `protobase dev` serves it at `http://localhost:5173/api/functions/hello`. A change reloads it on the next request, and a new file appears after the next change inside the project. `protobase build` bundles the functions into the deploy bundle, and `protobase serve` serves them the same way. Call it with a token:
24
+ `protobase dev` serves it at `/api/functions/hello` of the address it prints, such as `http://localhost:23456/api/functions/hello`. A change reloads it on the next request, and a new file appears after the next change inside the project. `protobase build` bundles the functions into the deploy bundle, and `protobase serve` serves them the same way. Call it with a token:
25
25
 
26
26
  ```sh
27
- curl -H "Authorization: Bearer $(protobase token pip@example.com)" http://localhost:5173/api/functions/hello
27
+ curl -H "Authorization: Bearer $(protobase token pip@example.com)" http://localhost:23456/api/functions/hello
28
28
  # {"message":"Hello, 9f3c…","roles":["admin"]}
29
- curl -i http://localhost:5173/api/functions/hello
29
+ curl -i http://localhost:23456/api/functions/hello
30
30
  # HTTP/1.1 401 Unauthorized, an application/problem+json body like every other refusal
31
31
  ```
32
32
 
@@ -24,7 +24,6 @@ Then a `.env` beside it, which every `protobase` command reads:
24
24
  DATABASE_URL=postgres://user:password@localhost:5432/shop
25
25
  # The app's secret, which signs session cookies: generate your own with openssl rand -base64 32
26
26
  PROTOBASE_SECRET=
27
- PROTOBASE_URL=http://localhost:5173
28
27
  ```
29
28
 
30
29
  Keep `.env` out of version control.
@@ -82,7 +81,7 @@ npx protobase users create you@example.com --generate-password
82
81
  npx protobase dev
83
82
  ```
84
83
 
85
- The first user is always an admin. The password is printed once. `protobase dev` serves the admin and its API at `http://localhost:5173` (`--port` picks another port); sign in there with that email and password.
84
+ The first user is always an admin. The password is printed once. `protobase dev` serves the admin and its API at the address it prints, `http://localhost:<port>` on a port the project keeps (`--port` changes it); sign in there with that email and password.
86
85
 
87
86
  ## Running scaffold again
88
87
 
@@ -122,7 +122,7 @@ protobase dev
122
122
  protobase mobile run android --live
123
123
  ```
124
124
 
125
- With `--live` the app opens the running `protobase dev` instead of its own files, so it reloads as you save. `--port` names the dev server's port, 5173 by default.
125
+ With `--live` the app opens the running `protobase dev` instead of its own files, so it reloads as you save. `--port` names the dev server's port, by default the one `protobase dev` keeps for the project.
126
126
 
127
127
  ## 5. Open the native project
128
128
 
@@ -91,7 +91,7 @@ bun run db:migrate
91
91
 
92
92
  ## 4. Turn push on from the bell
93
93
 
94
- Run `bun run protobase dev`, open `http://localhost:5173` in a desktop browser and sign in. The [bell](../reference/notifications.md#the-bell) in the top bar opens your notifications; at its foot, **Turn on** asks the browser for permission and registers this browser as one of your [devices](../reference/notifications.md#devices). The panel then says that notifications are on for this device.
94
+ Run `bun run protobase dev`, open the address it prints in a desktop browser and sign in. The [bell](../reference/notifications.md#the-bell) in the top bar opens your notifications; at its foot, **Turn on** asks the browser for permission and registers this browser as one of your [devices](../reference/notifications.md#devices). The panel then says that notifications are on for this device.
95
95
 
96
96
  ## 5. See it arrive
97
97
 
@@ -43,7 +43,7 @@ export default defineConfig(({ env }) => ({
43
43
 
44
44
  ## 3. Link a mailbox
45
45
 
46
- Signed in, open the account page (`/-/account`): under **Mailbox** it offers "Connect Gmail". Google asks which account to use and whether the app may send mail as it, then sends you back to the account page, which now says **Connected**. Someone who already signs in with Google still connects here, as their sign-in did not allow sending mail. The Google account may have another address than the one they sign in with. Once connected, the mailbox offers "Connect Gmail again": with the same Google account it gets a fresh link, and with another one it moves the mailbox to that account, as mail goes out through the account connected last.
46
+ Signed in, open the account page (`/-/account`): under **Mailbox** it offers "Connect Gmail". Google asks which account to use and whether the app may send mail as it, then sends you back to the account page, which now says **Connected**. Someone who already signs in with Google still connects here, as their sign-in did not allow sending mail. The Google account may have another address than the one they sign in with. Once connected, the mailbox offers "Connect Gmail again": with the same Google account it gets a fresh link, and with another one it moves the mailbox to that account, as mail goes out through the account connected last. When Gmail no longer accepts the link, the mailbox reads **Not connected** and its **Connect Gmail again** card takes the place of the button. Connecting from the account page brings you back to its **From addresses**.
47
47
 
48
48
  ## 4. Send from it
49
49
 
@@ -187,8 +187,8 @@ Deploy the change soon: until it serves, the admin app still adds fields to the
187
187
  ## `dev`
188
188
 
189
189
  ```sh
190
- protobase dev [--port 5173] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] [--no-jobs] # run inside a project, e.g. bun run --cwd tests/apps/erp dev
191
- protobase dev --api <url> [--port 5173] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # the UI alone, on the API at <url>
190
+ protobase dev [--port <port>] [--env DATABASE_URL] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] [--no-jobs] # run inside a project, e.g. bun run --cwd tests/apps/erp dev
191
+ protobase dev --api <url> [--port <port>] [--cache-dir <dir>] [--allowed-hosts <hosts>] [--extend <dir>] # the UI alone, on the API at <url>
192
192
  ```
193
193
 
194
194
  One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/app/` (`dist/app/` when installed; `index.html` and `main.tsx`, or `main.js`; the command fails with a clear message when they are missing) and hands `/api`, supabase-js's `/api/sb` included, to the Hono app from `createAdmin`, which runs in a process of its own; the CLI's process never loads `@protobase/server`. Open `http://localhost:<port>`; the API reference is at `/api/docs`.
@@ -197,7 +197,7 @@ One port, two processes: Vite serves the admin app from `@protobase/ui`'s `src/a
197
197
 
198
198
  - **Secret:** a `PROTOBASE_SECRET` still set to the placeholder of `.env.example` (`change-me-...`) prints a warning once the server is ready, as `serve` does at start: anyone who knows it can sign session cookies.
199
199
  - **Database:** the URL comes from the variable named by `--env`, read from the environment or the nearest `.env` at or above the project. The connection is checked before anything starts; if it fails, the command names host, port and reason (and, when nothing listens there, points to its `db:up` script when it has one). The API connects with Kysely over the `pg` the config gets: the project's own when it is locked, the CLI's when bundled.
200
- - **Port:** the app listens on `--port` at both `127.0.0.1` and `::1`, since `localhost` is either one depending on the runtime and the browser. When another process holds the port on either address the command stops before it starts and names that address; stop the other server or pass another `--port`.
200
+ - **Port:** each project keeps its own port on this machine, in `.protobase/dev-port`, so its address and bookmarks stay the same from run to run. The first run without `--port` picks a random port from 10000 to 49151 that is free on both loopback addresses and keeps it; `--port <port>` serves on that port and keeps it for the runs after, so one run with `--port` changes it. The app listens on both `127.0.0.1` and `::1`, since `localhost` is either one depending on the runtime and the browser. When another process holds the port on either address the command stops before it starts and names that address; stop the other server or run once with another `--port`. With a `PROTOBASE_URL` on this machine at another port, sign-in refuses the app's pages, so the command warns once it is ready; unset, the app's `url` is the dev server's own address.
201
201
  - **Cache:** Vite's dependency cache is `node_modules/.vite`; two dev servers sharing it can disturb each other's optimisation, so pass `--cache-dir` for a second one (the integration test does).
202
202
  - **Login:** real sign-in only, with the config's `auth`, on by default, or its `authenticate` for tokens of an auth server elsewhere (see [protobase.config.ts](config.md) and [Login with Better Auth](auth.md)). A project with sign-in off and no authenticator fails at startup with a message pointing there, as does one with sign-in on and no `PROTOBASE_SECRET`, one whose auth store has not applied every migration of this version, naming them (see [`auth migration`](#auth-migration)), one with a resource over a table of the auth store, and one with a resource whose [events](events.md) or [history](history.md) lack their triggers, or whose [comments](comments.md) lack their table, or whose [rollup and formula fields](data-config.md#rollups-and-formulas) lack their columns or triggers, which it checks again on every reload (see [`migration`](#migration)), and one with an [AI field or action](ai.md#the-model) and no model key; there is no development login. The `login` line of the startup message says how to sign in: while the auth store has no users, it prints the exact command that creates the first admin, such as `bun run protobase users create you@example.com --generate-password` (the package manager that started `dev`, `npx` otherwise). Against a database that has users already, such as an app's hosted one, sign in as one of them or add one with a new email; its own password is set there. A `warning` line follows for each way the auth store's tables differ from what the app's sign-in needs, such as a column dropped by hand: the one place Protobase compares them, since `serve` reads the store's record of [migrations](auth.md#migrations) alone.
203
203
  - **Mobile releases:** see [below](#mobile-releases).
@@ -721,7 +721,7 @@ Remove `supabase-import/` to import again.
721
721
  ## `mobile`
722
722
 
723
723
  ```sh
724
- protobase mobile run <ios|android> [--api <url>] [--target <id>] [--team <id>] [--live] [--port 5173] [--extend <dir>]
724
+ protobase mobile run <ios|android> [--api <url>] [--target <id>] [--team <id>] [--live] [--port <port>] [--extend <dir>]
725
725
  protobase mobile open <ios|android> [--api <url>] [--extend <dir>]
726
726
  protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [--api <url>] [--out mobile-release] [--extend <dir>]
727
727
  [--team <id> [--certificate <name> --profile <name>]]
@@ -732,7 +732,7 @@ Builds the project in the current directory as an iOS or Android app with Capaci
732
732
 
733
733
  - It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed, and on every run for a package from a local folder, given as `file:` or a path such as `../my-plugin`, which npm copies. When such a folder's dependencies are not the versions installed, it removes the workspace's `node_modules` and `package-lock.json` so npm resolves them again, and stops when a pin is still not met, as when two packages pin one dependency at different versions. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
734
734
  - `--api` is the server the app calls, the app's `url` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
735
- - `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
735
+ - `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files, by default on the port `dev` keeps for the project, and stops when it keeps none yet. `open` opens the native project in Xcode or Android Studio.
736
736
  - `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS archives and exports with xcodebuild for `--team`, letting Xcode create certificates and profiles with the account in its settings, or with the App Store Connect API key in `PROTOBASE_IOS_API_KEY_PATH`, `PROTOBASE_IOS_API_KEY_ID` and `PROTOBASE_IOS_API_KEY_ISSUER`; `--certificate` with `--profile` signs manually through Capacitor's build.
737
737
  - A release calls an https server that is not this machine, and `--app-version` (one to three numbers) and `--build-number` (1 to 2100000000) are required.
738
738
  - npm and Capacitor get the CLI's environment without any variable named in the current directory's `.env*` files, nor the four `PROTOBASE_ANDROID_*` signing variables, which only Gradle gets, and with `CI=true`, which keeps Capacitor's telemetry off. The project's config, its extensions' configs and the web build run inside the CLI with no `PROTOBASE_ANDROID_*` variable left in its environment, even one the project's `.env` sets.
@@ -750,7 +750,7 @@ protobase token <email> [--ttl 15m] [--organization <slug|id>]
750
750
  Prints a bearer token (JWT, signed with the project's Better Auth keys, same claims as a browser token) for an existing user. The lifetime is `30s`, `15m`, `24h`, ... up to 24 hours, default 15 minutes. With [organizations](auth.md#organizations), `--organization` names the one the token works in; without it, the token works where a new session of the user would start. Only the token goes to stdout and errors go to stderr, so it composes in scripts:
751
751
 
752
752
  ```sh
753
- curl -H "Authorization: Bearer $(protobase token me@x)" http://localhost:5173/api/v1/orders?page_size=1
753
+ curl -H "Authorization: Bearer $(protobase token me@x)" http://localhost:23456/api/v1/orders?page_size=1
754
754
  ```
755
755
 
756
756
  ## `skill`
@@ -98,7 +98,7 @@ The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONN
98
98
  ```json
99
99
  {
100
100
  "$schema": "./node_modules/@protobase/config/schema.json",
101
- "url": { "$env": "PROTOBASE_URL", "default": "http://localhost:5173" },
101
+ "url": { "$env": "PROTOBASE_URL" },
102
102
  "timezone": "Europe/Amsterdam",
103
103
  "auth": { "roles": ["admin", "sales"], "trustedOrigins": { "$env": "TUNNEL_URLS", "split": "," } },
104
104
  "jobs": { "send-invoice": { "arguments": { "invoiceId": "bigint" }, "maxAttempts": 5 } },