@protobase/cli 0.127.1 → 0.127.2

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.127.1";
2
+ var version = "0.127.2";
3
3
  //#endregion
4
4
  export { version };
@@ -0,0 +1,16 @@
1
+ import { devAddress, devPort } from "../dev/dev-port.js";
2
+ //#region src/config/tool-url.ts
3
+ /**
4
+ * The config of a local tool command that builds sign-in, such as `users create`: with no `url`, the address
5
+ * `protobase dev` serves the project on, its kept port, else one picked and kept now so a later `protobase dev` serves
6
+ * there. Without sign-in, or with a `url`, the config as it is.
7
+ */
8
+ const withDevUrl = async (config, projectDir, port = devPort) => {
9
+ if (!config.auth || config.url) return config;
10
+ return {
11
+ ...config,
12
+ url: devAddress(await port(projectDir, void 0))
13
+ };
14
+ };
15
+ //#endregion
16
+ export { withDevUrl };
@@ -37,6 +37,8 @@ const pickFreePort = async (held = heldOn, random = Math.random) => {
37
37
  }
38
38
  throw new Error(`Found no free port among ${tries} random ones from ${randomPorts.min} to ${randomPorts.max}; pass one with --port <port>`);
39
39
  };
40
+ /** The address `protobase dev` serves on `port`, the app's `url` when it sets none. */
41
+ const devAddress = (port) => `http://localhost:${port}`;
40
42
  /**
41
43
  * The port `protobase dev` serves the project on: `chosen`, saved as the project's port for later runs, else the saved
42
44
  * one, else a free random one, saved.
@@ -53,4 +55,4 @@ const devPort = async (projectDir, chosen, pick = pickFreePort) => {
53
55
  return picked;
54
56
  };
55
57
  //#endregion
56
- export { devPort, devPortFile, pickFreePort, randomPorts, readSavedPort, savePort };
58
+ export { devAddress, devPort, devPortFile, pickFreePort, randomPorts, readSavedPort, savePort };
@@ -1,9 +1,9 @@
1
1
  import { devHost } from "./loopback.js";
2
2
  import path from "node:path";
3
3
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
4
+ import { createServer } from "node:net";
4
5
  import { spawn } from "node:child_process";
5
6
  import { once } from "node:events";
6
- import { createServer } from "node:net";
7
7
  import { tmpdir } from "node:os";
8
8
  //#region src/dev/relay-process.ts
9
9
  /** The address of a relay on the loopback's `port`. */
package/dist/dev/run.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { loadNearestEnvFile } from "./env.js";
2
2
  import { adminAppDir } from "../project/admin-app.js";
3
3
  import { alsoOnIpv6, checkPortFree } from "./loopback.js";
4
+ import { devAddress } from "./dev-port.js";
4
5
  import { apiForward } from "./api-forward.js";
5
6
  import { requireAppFiles } from "./app-files.js";
6
7
  import { checkDatabase } from "./check-database.js";
@@ -57,7 +58,7 @@ const runDev = async (options, out) => {
57
58
  const address = server.httpServer?.address();
58
59
  const port = typeof address === "object" && address ? address.port : options.port;
59
60
  if (server.httpServer) await alsoOnIpv6(server.httpServer, port).catch(closeAndThrow);
60
- const started = await apiChild.start(`http://localhost:${port}`).catch(closeAndThrow);
61
+ const started = await apiChild.start(devAddress(port)).catch(closeAndThrow);
61
62
  apiReady(started);
62
63
  const { anyUsers, authDrift } = started;
63
64
  out(`protobase dev ready at http://localhost:${port}\n project ${options.projectDir}\n api http://localhost:${port}/api/v1 (docs at /api/docs)\n` + (options.jobs === false ? " jobs off: no jobs run and no events are delivered (--no-jobs)\n" : "") + loginLine(anyUsers, process.env.npm_config_user_agent) + authDriftLines(authDrift));
@@ -5,6 +5,7 @@ import { unsubscribeOn } from "../config/unsubscribe-config.js";
5
5
  import { userTablesOn } from "../config/user-tables-config.js";
6
6
  import { projectAuth } from "../config/build-project.js";
7
7
  import { loadSourceConfig } from "../config/source-config.js";
8
+ import { withDevUrl } from "../config/tool-url.js";
8
9
  import { openAppDatabase } from "../project/pg-db.js";
9
10
  import pg from "pg";
10
11
  import { assistantSettings, authStoreTables, configExports } from "@protobase/server";
@@ -12,14 +13,15 @@ import { checkStatusOptions } from "@protobase/server/internal";
12
13
  //#region src/migration/load-project.ts
13
14
  /**
14
15
  * The config of the project in `dir` as `protobase dev` merges it: protobase.config.ts, with the convention's resources
15
- * when it names none, after the configs of `extensions` and the configs it extends, with the `.env` nearest it read.
16
+ * when it names none, after the configs of `extensions` and the configs it extends, with the `.env` nearest it read,
17
+ * and the project's dev address when it sets no `url` (`withDevUrl`).
16
18
  */
17
19
  const loadMigrationConfig = async (dir, extensions = []) => {
18
20
  loadNearestEnvFile(dir);
19
- return loadSourceConfig(dir, {
21
+ return withDevUrl(await loadSourceConfig(dir, {
20
22
  command: "tool",
21
23
  extensions
22
- });
24
+ }), dir);
23
25
  };
24
26
  /**
25
27
  * A merged project config, for what its database needs: its resources' models, a pool on `url`, its auth, and the
@@ -2,20 +2,22 @@ import { loadNearestEnvFile } from "../dev/env.js";
2
2
  import { projectNotifications, projectWorkflows } from "../config/project-parts.js";
3
3
  import { projectAuth } from "../config/build-project.js";
4
4
  import { loadSourceConfig } from "../config/source-config.js";
5
+ import { withDevUrl } from "../config/tool-url.js";
5
6
  import { openAppDatabase } from "../project/pg-db.js";
6
7
  import pg from "pg";
7
8
  import { releaseConnectionsWithUsers, removeDevicesWithUsers, removeHistoryWithUsers } from "@protobase/server";
8
9
  //#region src/users/load-auth.ts
9
10
  /**
10
11
  * The sign-in of the project in `projectDir`, built from its config's `auth` over DATABASE_URL, with only the plugins
11
- * it turns on; `undefined` when sign-in is off. With a device or history store of the app's own (notifications/store.ts,
12
- * notifications/history-store.ts), deleting a user removes their devices or history from it too; the built-in tables go
13
- * with the user by their foreign keys. With workflows, deleting a user revokes their connected accounts and parks the
14
- * triggers on them, as the app does, reporting a token it left valid on stderr.
12
+ * it turns on, at the project's dev address when it sets no `url` (`withDevUrl`); `undefined` when sign-in is off.
13
+ * With a device or history store of the app's own (notifications/store.ts, notifications/history-store.ts), deleting a
14
+ * user removes their devices or history from it too; the built-in tables go with the user by their foreign keys. With
15
+ * workflows, deleting a user revokes their connected accounts and parks the triggers on them, as the app does,
16
+ * reporting a token it left valid on stderr.
15
17
  */
16
18
  const loadSignIn = async (projectDir) => {
17
19
  loadNearestEnvFile(projectDir);
18
- const config = await loadSourceConfig(projectDir, { command: "tool" });
20
+ const config = await withDevUrl(await loadSourceConfig(projectDir, { command: "tool" }), projectDir);
19
21
  if (!config.auth) return;
20
22
  if (!process.env.DATABASE_URL) throw new Error("No database: set DATABASE_URL");
21
23
  const database = openAppDatabase(pg, process.env.DATABASE_URL);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.127.1",
3
+ "version": "0.127.2",
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.127.1",
47
- "@protobase/layout": "0.127.1",
48
- "@protobase/query": "0.127.1",
49
- "@protobase/schema": "0.127.1",
50
- "@protobase/server": "0.127.1",
51
- "@protobase/ui": "0.127.1",
52
- "@protobase/workflows": "0.127.1",
46
+ "@protobase/config": "0.127.2",
47
+ "@protobase/layout": "0.127.2",
48
+ "@protobase/query": "0.127.2",
49
+ "@protobase/schema": "0.127.2",
50
+ "@protobase/server": "0.127.2",
51
+ "@protobase/ui": "0.127.2",
52
+ "@protobase/workflows": "0.127.2",
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",
@@ -116,7 +116,7 @@ The store's migrations then make nothing of the user table, which a migration of
116
116
  | --- | --- |
117
117
  | `PROTOBASE_SECRET` | the app's secret, the default of `secret`: signs cookies and encrypts the token keys; `openssl rand -base64 32`; never committed (`.env.example` has a placeholder) |
118
118
  | `PROTOBASE_PREVIOUS_SECRETS` | the app's secrets before `PROTOBASE_SECRET`, newest first, comma separated, the default of `previousSecrets`; see [Changing the secret](#changing-the-secret) |
119
- | `PROTOBASE_URL` | the app's public URL, the default of `url` (in `protobase dev`, the dev server's own); issuer and audience of the tokens; when tunnelling, the https tunnel URL |
119
+ | `PROTOBASE_URL` | the app's public URL, the default of `url` (in `protobase dev` and the local commands that build sign-in, such as `users create`, the dev server's own); issuer and audience of the tokens; when tunnelling, the https tunnel URL |
120
120
  | `PROTOBASE_TRUSTED_ORIGINS` | extra comma separated origins, the default of `auth.trustedOrigins`; a dev tunnel needs its exact host here, such as `https://my-tunnel.trycloudflare.com`, since none is trusted by default; an entry with `*` trusts every host it matches |
121
121
  | `PROTOBASE_ORIGINS` | the other origins the app is served on, comma separated, passed by the platform; see [Several origins](#several-origins) |
122
122
  | `PROTOBASE_PASSKEY_DOMAIN` | the host new [passkeys](#passkeys) are made for, passed by the platform; default the host of the app's `url` |
@@ -21,10 +21,10 @@ export default defineConfig({ name: 'Property Finder' })
21
21
  ## url
22
22
 
23
23
  - **Type:** `string`
24
- - **Default:** `PROTOBASE_URL`; in `protobase dev`, the dev server's own address
24
+ - **Default:** `PROTOBASE_URL`; in `protobase dev`, the dev server's own address, which the local commands that build sign-in, such as `users create` and `auth migration`, use too
25
25
  - **Environment variable:** `PROTOBASE_URL`
26
26
 
27
- The app's public URL: the issuer and audience of its tokens, and where its emails link to. Sign-in and [`unsubscribe`](jobs-and-events.md#unsubscribe) need it. With `auth` on, `protobase dev`, `serve` and the commands that sign people in stop with a clear message when it is missing. With `unsubscribe: true`, `protobase serve` stops when it is missing too, auth on or off, and when it is not `https://`, but for `localhost` and `127.0.0.1`. Other origins the app is served on are [`auth.origins`](sign-in.md#authorigins).
27
+ The app's public URL: the issuer and audience of its tokens, and where its emails link to. Sign-in and [`unsubscribe`](jobs-and-events.md#unsubscribe) need it. With `auth` on, `protobase serve` stops with a clear message when it is missing. The local commands that build sign-in, such as `users create`, `auth migration` and `migration`, use the address `protobase dev` serves the project on, `http://localhost:` and the port it keeps in `.protobase/dev-port`, and keep a free port there first when dev has kept none, so a later `protobase dev` serves on the address they used. With `unsubscribe: true`, `protobase serve` stops when it is missing too, auth on or off, and when it is not `https://`, but for `localhost` and `127.0.0.1`. Other origins the app is served on are [`auth.origins`](sign-in.md#authorigins).
28
28
 
29
29
  ```ts
30
30
  export default defineConfig({ url: 'https://admin.example.com' })