@protobase/cli 0.38.0 → 0.39.1

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.38.0";
2
+ var version = "0.39.1";
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.38.0",
3
+ "version": "0.39.1",
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.38.0",
40
- "@protobase/query": "0.38.0",
41
- "@protobase/schema": "0.38.0",
42
- "@protobase/server": "0.38.0",
43
- "@protobase/ui": "0.38.0",
39
+ "@protobase/layout": "0.39.1",
40
+ "@protobase/query": "0.39.1",
41
+ "@protobase/schema": "0.39.1",
42
+ "@protobase/server": "0.39.1",
43
+ "@protobase/ui": "0.39.1",
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
 
@@ -116,6 +116,10 @@ Each item has `id`, `name`, `slug`, `price` and `image`, of published products o
116
116
 
117
117
  A field rule goes from the field to the roles: `cost_price` above is hidden from every role that reads products but those holding `costs.read`. Use it for the few sensitive columns of a resource that many roles read, such as a screening result (`f.text().access({ read: roles.can('screening.read') })`). A field list goes from the role to the fields: use it for a role that should see only some columns, such as an integration or anonymous visitors, so a new column stays hidden from it. When both apply, a field needs both.
118
118
 
119
+ ### Write-only fields
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 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
+
119
123
  ## Records that belong to another
120
124
 
121
125
  A record often belongs to another one through a relation, such as an operation to the VM it runs on, and who may write it follows from who may change that VM. `.parent((r) => r.vm_id, 'update')` says so: writing an operation needs `update` on the record `vm_id` points at, `'read'` needing only to see it, as for a comment on a ticket. A member below may run operations on their own VMs only, with no rule of your own:
@@ -92,7 +92,7 @@ Access is resolved once per request and resource ([`resolveAccess`](https://docs
92
92
  - **Operations**: a denied operation is `403`; a resource the caller can do nothing with does not exist for them (`404` everywhere, absent from `/meta` and the OpenAPI document).
93
93
  - **Readable fields**: the caller works with a restricted model that has only the fields they may read. `filter`, `order_by`, `fields`, `search(...)`, `:facets`, `:aggregate`, `:histogram`, `:series`, `:map`, `:seek` and `:search` bodies are checked against it, so a hidden field is refused exactly like an unknown one (same status, same message and hint, nothing that says it exists). List, get, create, update and delete responses contain readable fields only, and queries select only those columns.
94
94
  - **Sensitive fields** are readable fields that no response carries and no request may name, except `:reveal`; they can be written. See [Sensitive fields and audit](#sensitive-fields-and-audit).
95
- - **Writable fields**: only fields the caller may write (and read) are accepted; any other is `400`, worded as unknown (hidden) or read-only. Nobody writes a field blind.
95
+ - **Writable fields**: only fields the caller may write and read are accepted, and [write-only](access.md#write-only-fields)) ones; any other is `400`, worded as unknown (hidden) or read-only.
96
96
  - **Row filters**: a rule that returns a filter (`.own`, `.team`) narrows every read (list, get, aggregates) and the rows a write may target; the database applies it, so it may use columns the caller cannot see. A row outside it is a `404`.
97
97
  - **Record-level rules** (a rule that needs the record, such as `status != 'locked'`) run in the write transaction with the stored record; a filter they return is checked in the database against the row as written, and a miss rolls the write back with `403`.
98
98
  - **`.own` on create**: when the create rule is limited to rows, the owner field is set to the caller unless given, and a row owned by someone else is refused with `403`.
@@ -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