@protobase/cli 0.39.0 → 0.39.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.
@@ -0,0 +1,37 @@
1
+ //#region src/build/shell-chunks.ts
2
+ /**
3
+ * The npm package a module id belongs to, as the last `node_modules` segment of its path names it, since Bun's store
4
+ * nests packages as `node_modules/.bun/<package>@<version>/node_modules/<package>`; none for a module outside one.
5
+ */
6
+ const npmPackage = (id) => /.*node_modules[\\/]((?:@[^\\/]+[\\/])?[^\\/]+)/.exec(id)?.[1]?.replace("\\", "/");
7
+ const reactPackages = /* @__PURE__ */ new Set([
8
+ "react",
9
+ "react-dom",
10
+ "scheduler"
11
+ ]);
12
+ /** Whether a module goes in the `react` chunk. */
13
+ const isReactModule = (id) => reactPackages.has(npmPackage(id) ?? "");
14
+ /**
15
+ * Whether a module goes in the `vendor` chunk: a third-party one but React's and the icons'. The icons stay in `app`,
16
+ * since the app picks up a new one on many releases, which would change `vendor` and every lazy chunk that imports it.
17
+ */
18
+ const isVendorModule = (id) => {
19
+ const name = npmPackage(id);
20
+ return name !== void 0 && !reactPackages.has(name) && name !== "lucide-react";
21
+ };
22
+ /**
23
+ * The shell build's `output.codeSplitting`. `react` comes first: without it, `vendor` would take React in as a
24
+ * dependency of the libraries it holds, and lazy chunks would import it from there.
25
+ */
26
+ const shellCodeSplitting = { groups: [{
27
+ name: "react",
28
+ test: isReactModule,
29
+ priority: 2
30
+ }, {
31
+ name: "vendor",
32
+ test: isVendorModule,
33
+ tags: ["$initial"],
34
+ priority: 1
35
+ }] };
36
+ //#endregion
37
+ export { isReactModule, isVendorModule, npmPackage, shellCodeSplitting };
@@ -7,6 +7,7 @@ import { themeLink } from "../project/theme-link.js";
7
7
  import { serviceWorkerFile } from "./service-worker-code.js";
8
8
  import { serviceWorker } from "../project/service-worker.js";
9
9
  import { moveSourceMaps } from "./source-maps.js";
10
+ import { shellCodeSplitting } from "./shell-chunks.js";
10
11
  import { existsSync } from "node:fs";
11
12
  import path from "node:path";
12
13
  import { build } from "vite";
@@ -45,7 +46,8 @@ const shellIdentity = async () => {
45
46
  * any deep link. It calls /api on its own origin and loads the project's UI, like every plugin, from what `/meta`
46
47
  * names, and links the project's theme at /protobase.theme.css and its favicon at /protobase.favicon.svg, and registers its service worker. The modules plugins share with it have entries of
47
48
  * their own, which index.html's import map names. With `sourceMapsDir`, each script ends with a `//# debugId=` comment
48
- * and names no map, and its source map, carrying the same debug id, goes to the same place under `sourceMapsDir`.
49
+ * and names no map, and its source map, carrying the same debug id, goes to the same place under `sourceMapsDir`. The
50
+ * scripts split into react, vendor and app chunks (./shell-chunks), so an update mostly downloads only the app's.
49
51
  */
50
52
  const buildShell = async (outDir, sourceMapsDir) => {
51
53
  const sourceMaps = sourceMapsDir !== void 0;
@@ -73,7 +75,10 @@ const buildShell = async (outDir, sourceMapsDir) => {
73
75
  emptyOutDir: true,
74
76
  chunkSizeWarningLimit: 4096,
75
77
  sourcemap: sourceMaps && "hidden",
76
- rolldownOptions: { output: { sourcemapDebugIds: sourceMaps } }
78
+ rolldownOptions: { output: {
79
+ sourcemapDebugIds: sourceMaps,
80
+ codeSplitting: shellCodeSplitting
81
+ } }
77
82
  }
78
83
  }).finally(() => {
79
84
  if (nodeEnv === void 0) delete process.env.NODE_ENV;
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.39.0";
2
+ var version = "0.39.2";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.39.0",
3
+ "version": "0.39.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": {
@@ -36,11 +36,11 @@
36
36
  "@better-auth/core": "^1.7.12",
37
37
  "@hono/node-server": "^2.1.3",
38
38
  "@hono/vite-dev-server": "^0.26.1",
39
- "@protobase/layout": "0.39.0",
40
- "@protobase/query": "0.39.0",
41
- "@protobase/schema": "0.39.0",
42
- "@protobase/server": "0.39.0",
43
- "@protobase/ui": "0.39.0",
39
+ "@protobase/layout": "0.39.2",
40
+ "@protobase/query": "0.39.2",
41
+ "@protobase/schema": "0.39.2",
42
+ "@protobase/server": "0.39.2",
43
+ "@protobase/ui": "0.39.2",
44
44
  "@react-email/render": "^2.1.0",
45
45
  "@scalar/hono-api-reference": "^0.12.10",
46
46
  "@tailwindcss/vite": "^4.3.3",
@@ -40,7 +40,7 @@ Every release pushes two public images to GitHub's registry, for `linux/amd64` a
40
40
  | `ghcr.io/prototeamhq/protobase-dev:<version>` | Bun and the presets at `/opt/protobase/presets/<name>` (`erp`, `real-estate`, `scratch`), with the dependencies they share installed in `/workspace` and Bun's cache in `/opt/bun-cache`. It has no Node: the presets' scripts and the `protobase` command run on Bun. It runs as `bun` (1000) |
41
41
 
42
42
  ```sh
43
- docker run -v "$PWD/dist:/app:ro" -p 8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET ghcr.io/prototeamhq/protobase:0.2.0
43
+ docker run -v "$PWD/dist:/app:ro" -p 127.0.0.1:8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET ghcr.io/prototeamhq/protobase:0.2.0
44
44
  ```
45
45
 
46
46
  In `protobase-dev`, copy a preset into `/workspace` and `bun install --frozen-lockfile` has nothing to do; installed anywhere else, it comes from the cache, without the network.
@@ -85,9 +85,10 @@ APP_DB_PASSWORD=... # openssl rand -hex 24
85
85
  ```sh
86
86
  BETTER_AUTH_SECRET=... # openssl rand -base64 32
87
87
  BETTER_AUTH_URL=http://localhost:8787
88
+ PROTOBASE_TRUSTED_PROXIES=172.30.87.1
88
89
  ```
89
90
 
90
- `BETTER_AUTH_URL` is the address the browser opens, exactly: sign-in from `http://127.0.0.1:8787` is refused as another origin. Add the app's other variables to `app.env` too.
91
+ `BETTER_AUTH_URL` is the address the browser opens, exactly: sign-in from `http://127.0.0.1:8787` is refused as another origin. `PROTOBASE_TRUSTED_PROXIES` is the compose network's gateway, which every connection through the published port comes from, a reverse proxy's included; trusting it lets the sign-in limits count each client by the proxy's `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses))). Add the app's other variables to `app.env` too.
91
92
 
92
93
  ```yaml
93
94
  services:
@@ -137,15 +138,30 @@ configs:
137
138
 
138
139
  volumes:
139
140
  db:
141
+
142
+ networks:
143
+ default:
144
+ ipam:
145
+ config:
146
+ - subnet: 172.30.87.0/24
147
+ gateway: 172.30.87.1
140
148
  ```
141
149
 
142
- `docker compose up -d` starts Postgres, runs `migrate` once and starts the app only when it succeeded. The app and `migrate` connect as `app`, which owns its database but is no superuser (see the [assistant](../reference/assistant.md)) on why that matters); the superuser's password stays in `.env` and the `postgres` service. Postgres runs the init file only on an empty volume. `configs` with `content` needs a recent Compose v2 (tested with 2.39.4).
150
+ `docker compose up -d` starts Postgres, runs `migrate` once and starts the app only when it succeeded. The app and `migrate` connect as `app`, which owns its database but is no superuser (see the [assistant](../reference/assistant.md)) on why that matters); the superuser's password stays in `.env` and the `postgres` service. Postgres runs the init file only on an empty volume. `configs` with `content` needs a recent Compose v2 (tested with 2.39.4). The network's addresses are fixed so that `app.env` can name its gateway: if `172.30.87.0/24` is taken on the host, `up` stops with "Pool overlaps", so pick another range and change the gateway in `app.env` to match.
143
151
 
144
152
  ### Local only by default
145
153
 
146
154
  The template publishes the app on `127.0.0.1:8787` only, so only the machine running it can open `http://localhost:8787`, and it speaks plain HTTP. To try it on a remote server, tunnel it with `ssh -L 8787:localhost:8787 <server>` and open `http://localhost:8787` on your own machine.
147
155
 
148
- Before other machines may reach it, put HTTPS in front: a reverse proxy on the host that forwards to `127.0.0.1:8787`, with `BETTER_AUTH_URL` set to the `https://` address. Only then are the session cookies `Secure` and passwords and codes encrypted on the way. Do not change the port to `8787:8787`: that publishes plain HTTP on every interface, ahead of host firewall rules such as ufw. On Docker Engine older than 28.0, hosts on the same local network can still reach a port published to `127.0.0.1`, so use 28.0 or newer.
156
+ Before other machines may reach it, put HTTPS in front: a reverse proxy on the host that forwards to `127.0.0.1:8787`, such as Caddy with this Caddyfile, which gets the certificate itself and adds the client's address to `X-Forwarded-For`:
157
+
158
+ ```
159
+ app.example.com {
160
+ reverse_proxy 127.0.0.1:8787
161
+ }
162
+ ```
163
+
164
+ Then set `BETTER_AUTH_URL=https://app.example.com` in `app.env` and run `docker compose up -d` to apply it. Only then are the session cookies `Secure` and passwords and codes encrypted on the way. Another proxy must also append the client's address to `X-Forwarded-For` (see [Client addresses](../reference/auth.md#client-addresses))), or every visitor shares one sign-in limit. Do not change the port to `8787:8787`: that publishes plain HTTP on every interface, ahead of host firewall rules such as ufw. On Docker Engine older than 28.0, hosts on the same local network can still reach a port published to `127.0.0.1`, so use 28.0 or newer.
149
165
 
150
166
  ### First admin
151
167
 
@@ -153,7 +169,7 @@ Before other machines may reach it, put HTTPS in front: a reverse proxy on the h
153
169
  docker compose run --rm --no-deps app create-admin /app you@example.com --generate-password
154
170
  ```
155
171
 
156
- Then open `http://localhost:8787` and sign in with that email and the printed password. `--no-deps` keeps compose from running `migrate` first, which during an upgrade would migrate under the old version while it serves; use it with every `docker compose run … app`. Where container logs leave the host, pass the password on stdin instead: `docker compose run --rm --no-deps -T app create-admin /app you@example.com --password-stdin < password.txt`.
172
+ Then open the address in `BETTER_AUTH_URL` and sign in with that email and the printed password: `https://app.example.com` once the proxy is in front, `http://localhost:8787` (or the SSH tunnel) only while `BETTER_AUTH_URL` is still `http://localhost:8787`, since sign-in from any other address is refused as another origin. `--no-deps` keeps compose from running `migrate` first, which during an upgrade would migrate under the old version while it serves; use it with every `docker compose run … app`. Where container logs leave the host, pass the password on stdin instead: `docker compose run --rm --no-deps -T app create-admin /app you@example.com --password-stdin < password.txt`.
157
173
 
158
174
  ### Upgrade
159
175
 
@@ -118,7 +118,7 @@ A field rule goes from the field to the roles: `cost_price` above is hidden from
118
118
 
119
119
  ### Write-only fields
120
120
 
121
- A role writes a field it cannot read only when the field's own `create` or `update` rule allows it: `f.text().access({ read: roles.is('loop'), create: roles.is('admin'), update: roles.is('admin') })` lets `admin` set a value only `loop` reads. A write rule the field follows from its resource never does, so hiding a field from a role does not let everyone who updates the resource overwrite it. The value is in no response, history, export or webhook of the writer, and `/meta` leaves it out, so the admin app offers no editor for it: set it through the API. A file field, or the field a resource orders its records by (`.position()`), is never write-only, and no `reorder` orders by a write-only field.
121
+ A role writes a field it cannot read only when the field's own `create` or `update` rule allows it: `f.text().access({ read: roles.is('loop'), create: roles.is('admin'), update: roles.is('admin') })` lets `admin` set a value only `loop` reads. A write rule the field follows from its resource never does, so hiding a field from a role does not let everyone who updates the resource overwrite it. The value is in no response, history, export or webhook of the writer, and no reveal shows it to them. `/meta` gives the writer the field marked `writeOnly: true`, sensitive and neither filterable nor sortable, and keeps it in the view's record sections and field hints only, so the admin app edits it only where a section of the layout names it: as a password-style input to type a new value in, with no stored value or eye to reveal one, never kept in a form's unsaved changes, and nowhere on the read view. The record's `permissions.fields` lists it as `edit` where the writer may update it. A file field, or the field a resource orders its records by (`.position()`), is never write-only, and no `reorder` orders by a write-only field.
122
122
 
123
123
  ## Records that belong to another
124
124
 
@@ -80,7 +80,7 @@ The columns Better Auth needs that the table lacks, filled from what the other s
80
80
  | `PROTOBASE_APP_NAME` | the app's name, passed by the platform: it overrides `appName` |
81
81
  | `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET` | the [platform sign-in provider](#platform-sign-in-provider) for people who have an account, passed by the platform; off without them. `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME` are optional |
82
82
  | `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 |
83
- | `PROTOBASE_TRUSTED_PROXIES` | the proxies in front of `protobase serve`, addresses or CIDR ranges, comma separated, such as `172.16.0.0/12`; see [Client addresses](#client-addresses) |
83
+ | `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) |
84
84
 
85
85
  - Cookies are `SameSite=Lax`, and `Secure` when `BETTER_AUTH_URL` is https.
86
86
  - Sign-in is rate limited (5 password attempts per minute and client by default, `signInPerMinute`, which also limits [sign-up](#open-sign-up) requests; 3 per minute for emailed codes); [Client addresses](#client-addresses) says how a client is known.
@@ -91,8 +91,8 @@ The columns Better Auth needs that the table lacks, filled from what the other s
91
91
 
92
92
  The rate limits count each client address on its own: an IPv4 address, or an IPv6 address by its /64. `protobase serve` and the runtime image find it themselves and pass it on in `X-Forwarded-For`, replacing whatever the client sent:
93
93
 
94
- - Without `PROTOBASE_TRUSTED_PROXIES`, the client is the address the connection comes from. That fits a server the clients reach directly, such as `docker run -p 8787:8787`.
95
- - Behind a reverse proxy (Caddy, nginx, Traefik, a load balancer), every connection comes from the proxy, so every client would share its one limit, and three emailed codes a minute from anyone would stop everyone signing in. Set `PROTOBASE_TRUSTED_PROXIES` to the proxy's address, or the range it connects from, such as `172.16.0.0/12` for a Docker network, and have the proxy append the address it took the request from to `X-Forwarded-For` (Caddy and Traefik do by default, nginx with `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for`). The client is then the rightmost address in it that is not a trusted proxy, so one the client wrote itself counts for nothing. Behind several proxies, such as a CDN in front of Caddy, trust them all.
94
+ - Without `PROTOBASE_TRUSTED_PROXIES`, the client is the address the connection comes from. That fits clients that reach the server directly, such as a browser on the same machine as `docker run -p 127.0.0.1:8787:8787`.
95
+ - Behind a reverse proxy (Caddy, nginx, Traefik, a load balancer), every connection comes from the proxy, so every client would share its one limit, and three emailed codes a minute from anyone would stop everyone signing in. Set `PROTOBASE_TRUSTED_PROXIES` to the proxy's address, or the Docker network's gateway for a proxy on the host, such as `172.30.87.1` in the deploy guide's [compose template](../guides/deploy.md#compose-template)); a range must not cover the clients themselves, or they all share the one limit again. Have the proxy append the address it took the request from to `X-Forwarded-For` (Caddy and Traefik do by default, nginx with `proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for`). The client is then the rightmost address in it that is not a trusted proxy, so one the client wrote itself counts for nothing. Behind several proxies, such as a CDN in front of Caddy, trust them all.
96
96
 
97
97
  An app served another way than `protobase serve`, such as its own server around `createAdmin`, gets what its server passes: the limits read `X-Forwarded-For` holding one address, and requests without one share a single limit.
98
98
 
@@ -312,7 +312,7 @@ COPY --from=libs /out/ /
312
312
  ```
313
313
 
314
314
  ```sh
315
- docker run --rm -p 8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET \
315
+ docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e BETTER_AUTH_SECRET \
316
316
  -v "$PWD/dist:/app:ro" -v "$PWD/protobase-serve.js:/opt/protobase/protobase-serve.js:ro" \
317
317
  protobase-run --no-install /opt/protobase/protobase-serve.js /app/protobase.config.js
318
318
  ```
@@ -204,6 +204,8 @@ A sensitive field, such as a bank account number, is written like any other fiel
204
204
  iban: f.text().sensitive().access({ read: roles.can('screening.read') }),
205
205
  ```
206
206
 
207
+ A role may also set a sensitive field it cannot read, such as a sealed value only a worker reads, when the field's own `create` or `update` rule allows it: see [write-only fields](access.md#write-only-fields)).
208
+
207
209
  A sensitive field cannot be `.filterable()`, `.sortable()`, aliased, searched, or the key, tenant, owner or soft delete field, and a view may only put it in a record page section: in a list, filter, chart, sidebar, title, recent-record group or action it would always be empty, so the config fails to load.
208
210
 
209
211
  A [webhook subscription](webhooks.md)) delivering `as` a role runs that role's access rules on a captured change, which holds no sensitive field. A rule or row filter that reads one there throws, and the change is kept as failed for that subscription instead of delivered, so decide that access on a field that is not sensitive. A rule that reads the field before it checks the role, such as `record.api_secret == null || ctx.user.roles.includes('admin')`, fails even for `as: { roles: ['admin'] }`: check the role first, as in `ctx.user.roles.includes('admin') || ...`.
@@ -610,7 +610,7 @@ export const repairsView = filtered
610
610
 
611
611
  A custom component draws only its part: the page around it stays the record page, at `/<resource>/<key>`, with its breadcrumbs, Save, the action rail with Edit and Delete, and the related records, and a layout may hold only custom components. The repairs above list the customer's earlier repairs under the bike:
612
612
 
613
- Without a layout the record page shows one section with every field the user may change; its [read view](#read-view-and-edit), which is what a user who may change none gets, shows every field. A section or sidebar card with no field the user may see is left out. The record's title is the page's heading, above the sections, with an enum `status` as a badge beside it unless the sidebar shows it already. `.saveFeedback('button')` shows saving on the Save button instead of a toast (`'toast'`, the default). A [sensitive field](data-config.md#sensitive-fields)) in a section is masked, with an eye button that reveals it.
613
+ Without a layout the record page shows one section with every field the user may change; its [read view](#read-view-and-edit), which is what a user who may change none gets, shows every field. A section or sidebar card with no field the user may see is left out. The record's title is the page's heading, above the sections, with an enum `status` as a badge beside it unless the sidebar shows it already. `.saveFeedback('button')` shows saving on the Save button instead of a toast (`'toast'`, the default). A [sensitive field](data-config.md#sensitive-fields)) in a section is masked, with an eye button that reveals it. A [write-only field](access.md#write-only-fields)) is on the form only where a section names it, never in the section without a layout, and shows as an empty input to set a new value in.
614
614
 
615
615
  A record opened from a list, by its row or its card, shows the fields the list loaded at once, with placeholders for the others, and takes input once the whole record has loaded; actions, custom components, maps and galleries wait for it. What the page shows is read again whenever the browser tab or window regains focus, as are the lists, unless the record has unsaved changes, which keep the version they were made to.
616
616