@protobase/cli 0.127.0 → 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.
- package/dist/cli/package.js +1 -1
- package/dist/config/tool-url.js +16 -0
- package/dist/dev/dev-port.js +3 -1
- package/dist/dev/relay-process.js +1 -1
- package/dist/dev/run.js +2 -1
- package/dist/migration/load-project.js +5 -3
- package/dist/users/load-auth.js +7 -5
- package/package.json +8 -8
- package/skills/protobase/references/guides/api-functions.md +1 -1
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/auth.md +1 -1
- package/skills/protobase/references/reference/config/app.md +2 -2
package/dist/cli/package.js
CHANGED
|
@@ -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 };
|
package/dist/dev/dev-port.js
CHANGED
|
@@ -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(
|
|
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
|
package/dist/users/load-auth.js
CHANGED
|
@@ -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
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* triggers on them, as the app does,
|
|
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.
|
|
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.
|
|
47
|
-
"@protobase/layout": "0.127.
|
|
48
|
-
"@protobase/query": "0.127.
|
|
49
|
-
"@protobase/schema": "0.127.
|
|
50
|
-
"@protobase/server": "0.127.
|
|
51
|
-
"@protobase/ui": "0.127.
|
|
52
|
-
"@protobase/workflows": "0.127.
|
|
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",
|
|
@@ -423,7 +423,7 @@ export default defineFunction({ longQueries: true }, async (request, { db }) =>
|
|
|
423
423
|
- **One connection kept for it.** Under `protobase dev` and `serve`, those queries run on a connection of their own, which asks for the longer timeout when it logs in, so long work never takes the connections pages need; a second long call waits for it. A PgBouncer of your own in front of the database must list `statement_timeout` in `track_extra_parameters` to pass that on; Protobase Cloud's does.
|
|
424
424
|
- **Room for pages.** Under `protobase dev` and `serve`, function calls and jobs together hold at most one connection less than [`PROTOBASE_DB_CONNECTIONS`](../reference/cli.md#serve), so a long import always leaves one to page and API requests; a call past that waits for a connection of its own.
|
|
425
425
|
- **`records` keep the API's limit,** [`statementTimeoutMs`](../reference/api.md#safety).
|
|
426
|
-
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
|
|
426
|
+
- **A query past its limit** is stopped, and the call answers `504 statement-timeout` naming the call, its limit and the way out, such as `POST /api/functions/import ran a query longer than the database's statement timeout, so the database stopped it. It may also have waited on a lock another transaction held, such as a migration while a deploy runs. Make the query faster, such as with an index or a narrower filter, or give it longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook, `hooks/error.ts`, and the [error tracker](../reference/api.md#error-reporting).
|
|
427
427
|
|
|
428
428
|
## Errors
|
|
429
429
|
|
|
@@ -266,7 +266,7 @@ The API sends no CORS headers until it has something to allow: other websites in
|
|
|
266
266
|
|
|
267
267
|
## Safety
|
|
268
268
|
|
|
269
|
-
- Every request runs in a transaction with `SET LOCAL statement_timeout` (`statementTimeoutMs`, default 1 s), so a slow query fails where it runs instead of holding a connection that other requests wait for. List, search, get, histogram, series, map and seek transactions are read-only. A query that runs longer is stopped: a `504` `statement-timeout` that names the request, its limit and the ways out, such as `GET /api/v1/orders ran a query longer than 1 s, so the database stopped it. Make the query faster, such as with an index or a narrower filter, or move the work into a function or job with longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook (`hooks/error.ts`, `createAdmin`'s `options.onUnhandledError`) and the [error tracker](#error-reporting) like a `500`. A read that needs longer has no way to opt out: give it an index, or move it into a [function](../guides/api-functions.md#long-queries) or [job](jobs.md) with `longQueries`.
|
|
269
|
+
- Every request runs in a transaction with `SET LOCAL statement_timeout` (`statementTimeoutMs`, default 1 s), so a slow query fails where it runs instead of holding a connection that other requests wait for. List, search, get, histogram, series, map and seek transactions are read-only. A query that runs longer is stopped: a `504` `statement-timeout` that names the request, its limit and the ways out, such as `GET /api/v1/orders ran a query longer than 1 s, so the database stopped it. It may also have waited on a lock another transaction held, such as a migration while a deploy runs. Make the query faster, such as with an index or a narrower filter, or move the work into a function or job with longQueries: true, whose queries may run up to 30 s.` It goes to the app's error hook (`hooks/error.ts`, `createAdmin`'s `options.onUnhandledError`) and the [error tracker](#error-reporting) like a `500`. A read that needs longer has no way to opt out: give it an index, or move it into a [function](../guides/api-functions.md#long-queries) or [job](jobs.md) with `longQueries`.
|
|
270
270
|
- Under `protobase dev` and `serve`, a request waits at most 2 seconds for a free database connection. When every connection stays busy that long, it is a `503` `connections-busy` with `Retry-After: 1` that names the request, reported the same way, rather than a request that hangs behind slow ones. A request that finds room for a new connection waits up to 30 seconds for it to open, such as while a database that scaled to zero wakes.
|
|
271
271
|
- **Scan guard**: a list, `:search`, `:seek`, `:map` page, card photos, `:facets` (in `:batchAggregates` too) and `:aggregate` read only columns an index serves, so they stay cheap however many rows match. The server reads each table's valid indexes from the catalog once, then checks every column the caller's filter, the role's row filter, the sort's first field, a facet's or an aggregate's grouped field, the field of [`limit_per`](#first-rows-per-value), a [`read` parent](access.md#records-that-belong-to-another)'s relation read and a [`related()`](#filtering-through-related-records) term's `field`, the columns of the parent's own row filter against the parent's table, and the subfilter's columns and `key` of a term against its resource's table:
|
|
272
272
|
- Comparisons, `in`, null checks, sorts and facets need a btree index with the column as a key, every key before it pinned by the query: by `=` or `in` in the filter (outside `OR` and `NOT`), by the tenant or by soft delete. `(for_sale, status, published_at desc)` serves `for_sale = true AND status = "available"` sorted by `published_at desc`, but not `status` alone. `=` on text may use a pg_trgm index instead.
|
|
@@ -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
|
|
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' })
|