@protobase/cli 0.108.0 → 0.109.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.
- package/dist/cli/package.js +1 -1
- package/dist/doctor/index-issues.js +14 -3
- package/dist/doctor/run.js +5 -2
- package/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -1
- package/skills/protobase/references/reference/auth.md +17 -3
- package/skills/protobase/references/reference/cli.md +6 -0
- package/skills/protobase/references/reference/config/sign-in.md +3 -2
- package/skills/protobase/references/reference/files.md +1 -1
- package/skills/protobase/references/reference/supabase-storage.md +2 -0
package/dist/cli/package.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { uncoveredColumns } from "@protobase/query";
|
|
1
|
+
import { uncoveredColumns, uncoveredFileColumns } from "@protobase/query";
|
|
2
2
|
//#region src/doctor/index-issues.ts
|
|
3
3
|
const kinds = {
|
|
4
4
|
btree: "index",
|
|
5
5
|
trigram: "pg_trgm index",
|
|
6
6
|
digits: "pg_trgm index",
|
|
7
|
-
gin: "GIN index"
|
|
7
|
+
gin: "GIN index",
|
|
8
|
+
file: "index"
|
|
8
9
|
};
|
|
9
10
|
const served = (column) => column.need === "digits" ? `the digits of "${column.column}"` : `the column "${column.column}"`;
|
|
10
11
|
/**
|
|
@@ -32,5 +33,15 @@ const indexIssues = (model, table, shapes) => {
|
|
|
32
33
|
suggestion: `${column.suggestion};`
|
|
33
34
|
}));
|
|
34
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* The file columns of `model` the file cleanup reads every row of before it deletes a file, as no index looks a file up
|
|
38
|
+
* there: a warning each, since the API refuses nothing for it.
|
|
39
|
+
*/
|
|
40
|
+
const fileIndexIssues = (model, table) => uncoveredFileColumns(model, table).map((column) => ({
|
|
41
|
+
severity: "warning",
|
|
42
|
+
resource: model.name,
|
|
43
|
+
message: `no index looks up the files of "${column.column}", so each file cleanup reads every row of the table to check that none holds a file it deletes`,
|
|
44
|
+
suggestion: `${column.suggestion};`
|
|
45
|
+
}));
|
|
35
46
|
//#endregion
|
|
36
|
-
export { indexIssues };
|
|
47
|
+
export { fileIndexIssues, indexIssues };
|
package/dist/doctor/run.js
CHANGED
|
@@ -7,7 +7,7 @@ import { loadDataConfig } from "../project/load-data-config.js";
|
|
|
7
7
|
import { readOnlyDb } from "../db/read-only-db.js";
|
|
8
8
|
import { builtInIndexIssues, builtInModels } from "./built-in-models.js";
|
|
9
9
|
import { checkResource } from "./check.js";
|
|
10
|
-
import { indexIssues } from "./index-issues.js";
|
|
10
|
+
import { fileIndexIssues, indexIssues } from "./index-issues.js";
|
|
11
11
|
import { unplannedBlocks } from "./page-shapes.js";
|
|
12
12
|
import { readShapes } from "./read-shapes.js";
|
|
13
13
|
import { relationIssues } from "./relation-issues.js";
|
|
@@ -44,7 +44,10 @@ const runDoctor = async (options, out) => {
|
|
|
44
44
|
views: [...builtIn.views, ...config.views],
|
|
45
45
|
pages: config.pages
|
|
46
46
|
});
|
|
47
|
-
const indexes = await Promise.all(models.map(async (model) =>
|
|
47
|
+
const indexes = await Promise.all(models.map(async (model) => {
|
|
48
|
+
const table = await tableIndexes(db, model);
|
|
49
|
+
return [...indexIssues(model, table, shapes), ...fileIndexIssues(model, table)];
|
|
50
|
+
})).then((found) => found.map((issues, i) => i < builtIn.models.length ? builtInIndexIssues(issues) : issues)).finally(() => db.destroy());
|
|
48
51
|
const issues = [...userTables.issues, ...models.flatMap((model, i) => [
|
|
49
52
|
...checkResource(model, tables),
|
|
50
53
|
...relationIssues(model, models),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.109.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": {
|
|
@@ -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.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.109.1",
|
|
47
|
+
"@protobase/layout": "0.109.1",
|
|
48
|
+
"@protobase/query": "0.109.1",
|
|
49
|
+
"@protobase/schema": "0.109.1",
|
|
50
|
+
"@protobase/server": "0.109.1",
|
|
51
|
+
"@protobase/ui": "0.109.1",
|
|
52
|
+
"@protobase/workflows": "0.109.1",
|
|
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",
|
|
@@ -33,7 +33,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
33
33
|
- [OpenID Connect providers](../reference/auth.md#platform-sign-in-providers): A host adds OpenID Connect providers for people who already have an account, each with its own id, name and ways to sign in.
|
|
34
34
|
- [Devices](../reference/auth.md#device-accounts): A provider that signs in phones links each device as an account of its own, which the person signs out for good from the Devices tab.
|
|
35
35
|
- [Token sign-in](../reference/auth.md#token-sign-in): A client that holds a fresh ID token from that provider for this app signs in with it once, in place of an emailed code, and gets the app's own session, with the app's second step when one is on.
|
|
36
|
-
- [Being an OpenID provider](../reference/auth.md#openid-provider-for-other-apps): The app vouches for its people's verified addresses to other apps its admin registers, which sign them in without asking them to allow it, and lets a phone app get a sign-in token for each of those apps, or for any app at the origins it names by pattern, without a browser.
|
|
36
|
+
- [Being an OpenID provider](../reference/auth.md#openid-provider-for-other-apps): The app vouches for its people's verified addresses to other apps its admin registers, or its config declares, such as its own phone app, which sign them in without asking them to allow it, and lets a phone app get a sign-in token for each of those apps, or for any app at the origins it names by pattern, without a browser.
|
|
37
37
|
- [Grant subjects](../reference/auth.md#grant-subjects): Each sign-in of a phone app gets a subject of its own instead of the person's id, and names its device, so the apps it signs in to see every device apart.
|
|
38
38
|
- [Staff sign-in](../reference/auth.md#staff-sign-in): The team that runs an app signs in as a person to help them, with a reason and a log entry.
|
|
39
39
|
- [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
|
|
@@ -896,7 +896,7 @@ auth: { mcp: true, oauth: { api: true } }
|
|
|
896
896
|
|
|
897
897
|
## OpenID provider for other apps
|
|
898
898
|
|
|
899
|
-
With `openIdProvider`, the app is an OpenID provider for the clients its admins register, such as other apps that let people sign in with it: a person signs in on the app's own pages, as they always do, and the client gets an ID token that says who they are. Nobody is asked to allow a client, since only an admin
|
|
899
|
+
With `openIdProvider`, the app is an OpenID provider for the clients its admins register and those its config declares, such as other apps that let people sign in with it: a person signs in on the app's own pages, as they always do, and the client gets an ID token that says who they are. Nobody is asked to allow a client, since only an admin or the app's developer adds one. A phone app the admin registers can also get ID tokens for every app at the origins `audiences` names, with no registration per app, through the [token exchange](#token-exchange).
|
|
900
900
|
|
|
901
901
|
```ts
|
|
902
902
|
auth: { openIdProvider: true }
|
|
@@ -905,7 +905,7 @@ auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.exam
|
|
|
905
905
|
|
|
906
906
|
- **Audiences** are https origins, exact (`https://shop.example.com`) or with one leading wildcard label (`https://*.example.app`, which stands for `shop.example.app` but not `example.app` or `a.b.example.app`). A wildcard needs two labels after it, and a pattern takes no port, path, query or user info; anything else stops the app at start. An app at such an origin gets ID tokens only from the token exchange: no browser is ever sent there, so an authorize whose client id or redirect URI is on such a host is refused (`400 invalid_request`), and so is registering a client with a redirect URI there (`400 REDIRECT_ON_AUDIENCE_HOST`).
|
|
907
907
|
|
|
908
|
-
- **Only registered clients.** Nothing registers itself: `/api/auth/oauth2/register` is closed, and so are the provider's own client management, consent, userinfo, introspection and logout endpoints. A client the admin did not register through the API below is refused with `400 invalid_client` at authorize and at the token endpoint, before anything else, and so is a client in the store from elsewhere, such as one an MCP client registered while the app had `mcp` on. A redirect URI must be one the client registered, character for character, so the person's browser is never sent with a code, or an error, to an address of someone else's.
|
|
908
|
+
- **Only registered clients.** Nothing registers itself: `/api/auth/oauth2/register` is closed, and so are the provider's own client management, consent, userinfo, introspection and logout endpoints. A client the admin did not register through the API below, and the config does not [declare](#declared-clients), is refused with `400 invalid_client` at authorize and at the token endpoint, before anything else, and so is a client in the store from elsewhere, such as one an MCP client registered while the app had `mcp` on. A redirect URI must be one the client registered, character for character, so the person's browser is never sent with a code, or an error, to an address of someone else's.
|
|
909
909
|
- **Not with `mcp`.** MCP clients register themselves, and the provider of this mode is separate from MCP's, so the server refuses to start with both. Serve them from separate apps.
|
|
910
910
|
- **Discovery** is at `/.well-known/openid-configuration`, with the app's `url` as issuer, and the keys at `/api/auth/jwks`. A client uses the authorization code flow with PKCE, with `openid email profile`, and a `nonce`.
|
|
911
911
|
- **The ID token** is signed with the app's [signing keys](#signing-keys) (EdDSA) and lives 5 minutes. It carries `iss` (the app's `url`), `aud` (the client's id, alone), `sub` (the person's user id in this app, or the [grant's subject](#grant-subjects)), `email`, `email_verified`, and `name` when the person has one. It has no `jti`. Another Protobase app takes it as its [platform sign-in provider](#platform-sign-in-providers), through its pages or by [token sign-in](#token-sign-in).
|
|
@@ -915,6 +915,20 @@ auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.exam
|
|
|
915
915
|
|
|
916
916
|
With `subject: 'grant'`, an ID token's `sub` names the client's grant, never the person's id: the client's tokens from one sign-in at the app. A fresh sign-in is a new grant with a new subject, and the grant's refresh tokens and token exchanges keep it. So each sign-in of a phone app is a device of its own to the apps that take its tokens, such as an app whose platform provider signs in [device accounts](#device-accounts), and signing one device out there leaves the others. The subject is a hash of the grant, so it says nothing of the person and stays when the app's [secret changes](#changing-the-secret); `email` and `email_verified` still say who they are. The default, `subject: 'user'`, keeps the person's user id.
|
|
917
917
|
|
|
918
|
+
### Declared clients
|
|
919
|
+
|
|
920
|
+
The app's own clients, such as its phone app, can be declared in the config instead, with the fields the admin API takes and the client id the client ships with, so every deploy has them with no admin account and no manual step:
|
|
921
|
+
|
|
922
|
+
```ts
|
|
923
|
+
auth: { openIdProvider: { clients: [{ clientId: 'example-phone', name: 'Phone', redirectUris: ['com.example.phone:/signed-in'], type: 'public', exchange: true }] } }
|
|
924
|
+
```
|
|
925
|
+
|
|
926
|
+
- A declared client works as a registered `public` one does: discovery, the authorization code flow with PKCE, ID tokens, and, with `exchange: true`, refresh tokens and the [token exchange](#token-exchange), to and from registered clients alike. The admin API neither lists nor deletes it.
|
|
927
|
+
- Its record is written on its first request and rewritten when the config changes it.
|
|
928
|
+
- Removed from the config, it is refused with `400 invalid_client` from the next deploy on, its refresh tokens included. Declaring the same id again brings back its tokens that have not expired.
|
|
929
|
+
- The app refuses to start with an id declared twice, a field missing, or a redirect URI the provider cannot send a browser to: one with a fragment, plain `http` other than to a loopback address, or one on a host of `audiences`. An id an admin also registered a client under is refused with `400 invalid_client` rather than served as either: delete the registered one.
|
|
930
|
+
- <gap>A declared client cannot be `confidential` because a store for declared clients' secrets is not implemented.</gap>
|
|
931
|
+
|
|
918
932
|
### Registering clients
|
|
919
933
|
|
|
920
934
|
An admin registers, lists and deletes the clients with their own session; anyone else is refused with `403 ADMIN_ONLY`:
|
|
@@ -952,7 +966,7 @@ grant_type=urn:ietf:params:oauth:grant-type:token-exchange
|
|
|
952
966
|
```
|
|
953
967
|
|
|
954
968
|
- **The subject is the caller's own person.** `subject_token` must be a live access token this app issued to the calling client itself: not an ID token, a refresh token or another client's token, not expired, revoked or from a session that ended. Otherwise it answers `400 invalid_grant`. A client without `exchange` gets `400 unauthorized_client`.
|
|
955
|
-
- **The audience is another registered client, or an origin of `audiences`**: not the caller, not an unknown client and not one the admin did not register (`400 invalid_target`). An origin is matched as the URL parser writes it, label by label, so `http://`, a port, a path or trailing slash, user info, upper case, an extra label (`a.b.example.app`) and look-alikes (`example.app.evil.com`, `evilexample.app`) are refused.
|
|
969
|
+
- **The audience is another registered or [declared](#declared-clients) client, or an origin of `audiences`**: not the caller, not an unknown client and not one the admin did not register or the config does not declare (`400 invalid_target`). An origin is matched as the URL parser writes it, label by label, so `http://`, a port, a path or trailing slash, user info, upper case, an extra label (`a.b.example.app`) and look-alikes (`example.app.evil.com`, `evilexample.app`) are refused.
|
|
956
970
|
- **An ID token only.** The answer is an ID token for that client or origin alone, living 5 minutes, with the claims of the client's own sign-in; one for an origin has that origin as `aud`, and a `jti`. No access or refresh token for the other client leaves the app. `requested_token_type` and `subject_token_type` take only the values above (`400 invalid_request`).
|
|
957
971
|
- **The device name:** `device_name=<name>` names the device the caller runs on, such as `Ana's phone`; the ID token carries it as the `device_name` claim, trimmed and cut to 64 characters, which another app shows for a [device account](#device-accounts). Without it, or blank, the claim is left out.
|
|
958
972
|
- **A banned person, or one whose address is not verified,** gets none (`400 invalid_grant`). A ban after the token was issued is caught by the other app, which checks its own account at sign-in.
|
|
@@ -128,6 +128,12 @@ Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config modul
|
|
|
128
128
|
GET /seller?order_by=name asc (the seller list's order)
|
|
129
129
|
fix: mark "name" .sortable() in data.ts, or sort the list by a sortable field
|
|
130
130
|
```
|
|
131
|
+
- warning: a file field whose column no index looks files up in, so each [file cleanup](files.md#deleting-files) reads every row of the table before it deletes a file. The fix is an index on the file without its query part, which a partial index cannot be, as soft-deleted rows still hold their files:
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
warning photos: no index looks up the files of "photo", so each file cleanup reads every row of the table to check that none holds a file it deletes
|
|
135
|
+
fix: create index on "photos" ((split_part("photo", '?', 1)));
|
|
136
|
+
```
|
|
131
137
|
- warning: enum values differ
|
|
132
138
|
|
|
133
139
|
Doctor also lists, as a note it does not count, each custom component of a page that declares no [reads](custom-components.md#reads), since it reads outside the page's plan.
|
|
@@ -319,13 +319,14 @@ export default defineConfig({ auth: { mcp: true, oauth: { api: true } } })
|
|
|
319
319
|
|
|
320
320
|
## auth.openIdProvider
|
|
321
321
|
|
|
322
|
-
- **Type:** `true | { connectPage?: string; audiences?: string[]; subject?: 'user' | 'grant' }`
|
|
322
|
+
- **Type:** `true | { connectPage?: string; audiences?: string[]; subject?: 'user' | 'grant'; clients?: { clientId: string; name: string; redirectUris: string[]; type: 'public'; exchange?: boolean }[] }`
|
|
323
323
|
- **Default:** off
|
|
324
324
|
|
|
325
|
-
Makes the app an OpenID provider for the clients its admins register at `/api/auth/openid-provider/clients
|
|
325
|
+
Makes the app an OpenID provider for the clients its admins register at `/api/auth/openid-provider/clients` and those `clients` declares, such as other apps that sign people in with it: they get an ID token with the person's `sub`, `email` and `email_verified`, without asking the person to allow them, and nothing else can register. A client allowed to exchange gets ID tokens for the other clients, and for the origins `audiences` names as patterns such as `https://*.example.app`, without a browser. `connectPage` is the page people sign in on (default `/-/connect`). `subject: 'grant'` makes an ID token's `sub` the client's grant, new on each fresh sign-in and kept across its refresh tokens and exchanges, never the person's id ([Grant subjects](../auth.md#grant-subjects); default `user`). `clients` declares the app's own public clients, such as its phone app, under the ids written there, with the fields the admin API takes: they work from the first request on, with no admin registering them, and stop once removed ([Declared clients](../auth.md#declared-clients)). Not with [`auth.mcp`](#authmcp); the server refuses to start with both. See [OpenID provider for other apps](../auth.md#openid-provider-for-other-apps).
|
|
326
326
|
|
|
327
327
|
```ts
|
|
328
328
|
export default defineConfig({ auth: { openIdProvider: true } })
|
|
329
|
+
export default defineConfig({ auth: { openIdProvider: { clients: [{ clientId: 'example-phone', name: 'Phone', redirectUris: ['com.example.phone:/signed-in'], type: 'public', exchange: true }] } } })
|
|
329
330
|
```
|
|
330
331
|
|
|
331
332
|
## auth.personalAccessTokens
|
|
@@ -392,7 +392,7 @@ Files are deleted by schedule, never in the write itself, so a restore of the da
|
|
|
392
392
|
- A write that **replaces or clears** a file, or **deletes a row** (not a soft delete), schedules the delete of each file it took out of its row, with its variants, once it commits, so its transaction never waits on the storage. It is due after the provider's retention: `files.retention`, 1 day by default, or 0 for a public provider. When the storage refuses the entry, the write still stands, the file stays in storage, and the error goes to the default export of `hooks/error.ts`.
|
|
393
393
|
- Every **upload** schedules one too, due an hour after its ticket expires, so a file nobody saved, or whose write rolled back, goes as well.
|
|
394
394
|
- Each scheduled delete is a small JSON object in the provider's own storage, in a `.cleanup/` folder, named after its due time and saying what to delete: `.cleanup/2026-10-12T03-00-00Z-<uuid>.json` holding `{ "provider": "private", "path": "1/2992db9c-….jpg", "due": "…" }`.
|
|
395
|
-
- A **cleanup run** handles the entries that are due. Right before deleting, it checks every file column of every resource for the file: one that a row holds again (a rolled-back write, a restore, a copied value) is kept, and its entry dropped. Two runs at once do no harm.
|
|
395
|
+
- A **cleanup run** handles the entries that are due. Right before deleting, it checks every file column of every resource for the file: one that a row holds again (a rolled-back write, a restore, a copied value) is kept, and its entry dropped. Two runs at once do no harm. It looks the files up by `split_part(column, '?', 1)`, the file without its query part, which an index on that expression serves; [`protobase doctor`](cli.md#doctor) warns of each file column without one and writes it.
|
|
396
396
|
|
|
397
397
|
A run happens:
|
|
398
398
|
|
|
@@ -49,6 +49,8 @@ Public buckets are served at `/api/sb/storage/v1/object/public/<bucket>/<name>`
|
|
|
49
49
|
- `object/list/<bucket>`, `object/move`, `object/copy` and `object/info/...`.
|
|
50
50
|
- `bucket`: list, get, create, update, empty and delete.
|
|
51
51
|
|
|
52
|
+
A list walks the folder's level entry by entry on the storage schema's `(bucket_id, name collate "C")` index: a folder below it costs one read however many objects it holds, so the top of a big bucket lists as fast as any folder.
|
|
53
|
+
|
|
52
54
|
A download is sent with the type it was uploaded with, `nosniff` and a sandboxing Content-Security-Policy, so an uploaded page cannot run on the app's origin, and `?download` makes it an attachment.
|
|
53
55
|
|
|
54
56
|
Not yet:
|