@protobase/cli 0.107.0 → 0.107.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/doctor/resource-count.js +11 -0
- package/dist/doctor/run.js +2 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/sign-in-and-accounts.md +1 -0
- package/skills/protobase/references/features/start-a-project.md +1 -0
- package/skills/protobase/references/reference/auth.md +7 -2
- package/skills/protobase/references/reference/cli.md +2 -0
- package/skills/protobase/references/reference/config/app.md +13 -1
- package/skills/protobase/references/reference/config/sign-in.md +2 -2
- package/skills/protobase/references/reference/config.md +1 -1
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/doctor/resource-count.ts
|
|
2
|
+
/**
|
|
3
|
+
* Refuses a config with no resources, which has usually lost them by mistake, unless the app says it has none on
|
|
4
|
+
* purpose with `resources: 'none'`; and refuses one that says so but exports some.
|
|
5
|
+
*/
|
|
6
|
+
const checkResourceCount = (count, declared, index) => {
|
|
7
|
+
if (declared === "none" && count > 0) throw new Error(`${index} exports ${count === 1 ? "a resource" : `${count} resources`}, but the config says the app has none (resources: 'none'): remove that key, or the resources`);
|
|
8
|
+
if (declared !== "none" && count === 0) throw new Error(`No resources exported from ${index}; an app with none on purpose says so with resources: 'none' in its config`);
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { checkResourceCount };
|
package/dist/doctor/run.js
CHANGED
|
@@ -11,6 +11,7 @@ import { 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";
|
|
14
|
+
import { checkResourceCount } from "./resource-count.js";
|
|
14
15
|
import { sortIssues } from "./sort-issues.js";
|
|
15
16
|
import { checkServerStartup } from "./startup.js";
|
|
16
17
|
import { userTableModels } from "./user-table-models.js";
|
|
@@ -23,8 +24,8 @@ const format = (issue) => ` ${issue.severity.padEnd(7)} ${issue.resource}: ${is
|
|
|
23
24
|
const runDoctor = async (options, out) => {
|
|
24
25
|
if (!existsSync(path.join(options.configDir, "index.ts"))) throw new Error(`No config in ${options.configDir}: write it with \`protobase scaffold\`, or pass --config <dir>`);
|
|
25
26
|
const config = await loadDataConfig(options.configDir, options.projectDir);
|
|
26
|
-
if (config.models.length === 0) throw new Error(`No resources exported from ${options.configDir}/index.ts`);
|
|
27
27
|
const source = await loadSourceConfig(options.projectDir, { command: "tool" });
|
|
28
|
+
checkResourceCount(config.models.length, source.resources, `${options.configDir}/index.ts`);
|
|
28
29
|
const builtIn = builtInModels(source, config.models);
|
|
29
30
|
const sql = connect(options.url);
|
|
30
31
|
const tables = await introspect(sql, { views: true }).finally(() => sql.end());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.107.
|
|
3
|
+
"version": "0.107.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.107.
|
|
47
|
-
"@protobase/layout": "0.107.
|
|
48
|
-
"@protobase/query": "0.107.
|
|
49
|
-
"@protobase/schema": "0.107.
|
|
50
|
-
"@protobase/server": "0.107.
|
|
51
|
-
"@protobase/ui": "0.107.
|
|
52
|
-
"@protobase/workflows": "0.107.
|
|
46
|
+
"@protobase/config": "0.107.2",
|
|
47
|
+
"@protobase/layout": "0.107.2",
|
|
48
|
+
"@protobase/query": "0.107.2",
|
|
49
|
+
"@protobase/schema": "0.107.2",
|
|
50
|
+
"@protobase/server": "0.107.2",
|
|
51
|
+
"@protobase/ui": "0.107.2",
|
|
52
|
+
"@protobase/workflows": "0.107.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",
|
|
@@ -34,6 +34,7 @@ Sign-in methods, users, roles, organizations and tokens.
|
|
|
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
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.
|
|
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.
|
|
37
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.
|
|
38
39
|
- [Roles](../reference/auth.md#roles): A user holds one or more roles and switches between them without signing in again.
|
|
39
40
|
- [Organizations](../reference/auth.md#organizations): People work in one organization at a time, see only its records, and are invited with their own roles.
|
|
@@ -21,6 +21,7 @@ Start a new app, or an admin over an existing Postgres database, and keep the co
|
|
|
21
21
|
- [Safe re-scaffolding](../reference/cli.md#re-running): Running scaffold again adds only the columns that are not declared yet and leaves your own config code as it is.
|
|
22
22
|
- [Schema drift report](../reference/cli.md#drift-report): After each scaffold, lists declared fields whose column is gone, whose type changed or whose enum values differ, with a suggested fix.
|
|
23
23
|
- [Doctor](../reference/cli.md#doctor): Checks every resource and view against the database, the ones Protobase adds such as webhook subscriptions included, with the reads that lack an index, and prints the fix for each problem. It then runs the server's startup checks, such as the triggers of resources with events, so a project it passes starts.
|
|
24
|
+
- [Apps without resources](../reference/config/app.md#resources): An app with no resources on purpose, such as one that only signs people in, says so with `resources: 'none'`, so doctor accepts it while still catching an app that lost its resources by mistake.
|
|
24
25
|
- [Admin without a view](../guides/table-to-admin.md#1-the-table-as-it-is): A table with an empty view already gives a working admin with every column, sorting, paging, a record page and a New button.
|
|
25
26
|
- [Agent skills](../reference/cli.md#skill): `protobase skill install` writes agent skills that match the installed version into the project, for the coding agents that work on it.
|
|
26
27
|
- [Docs as Markdown](../getting-started.md#docs-as-markdown): Every docs page is also Markdown at its address plus `.md`, for coding agents and chat assistants.
|
|
@@ -900,7 +900,7 @@ With `openIdProvider`, the app is an OpenID provider for the clients its admins
|
|
|
900
900
|
|
|
901
901
|
```ts
|
|
902
902
|
auth: { openIdProvider: true }
|
|
903
|
-
auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.example.app'] } }
|
|
903
|
+
auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.example.app'], subject: 'grant' } }
|
|
904
904
|
```
|
|
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`).
|
|
@@ -908,9 +908,13 @@ auth: { openIdProvider: { connectPage: '/-/connect', audiences: ['https://*.exam
|
|
|
908
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.
|
|
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
|
-
- **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), `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).
|
|
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).
|
|
912
912
|
- **Signing in** goes through the connect page (`connectPage`, default `/-/connect`), which signs the person in and goes straight on to the client. Someone who has not set up what the [sign-in policy](#sign-in-policy) requires is sent to the setup page first, and staff signed in as a person get no token.
|
|
913
913
|
|
|
914
|
+
### Grant subjects
|
|
915
|
+
|
|
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
|
+
|
|
914
918
|
### Registering clients
|
|
915
919
|
|
|
916
920
|
An admin registers, lists and deletes the clients with their own session; anyone else is refused with `403 ADMIN_ONLY`:
|
|
@@ -950,6 +954,7 @@ grant_type=urn:ietf:params:oauth:grant-type:token-exchange
|
|
|
950
954
|
- **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`.
|
|
951
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.
|
|
952
956
|
- **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
|
+
- **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.
|
|
953
958
|
- **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.
|
|
954
959
|
- The token endpoint takes 20 requests a minute per client address.
|
|
955
960
|
|
|
@@ -107,6 +107,8 @@ protobase doctor [connection string | --env VAR] [--config <dir>]
|
|
|
107
107
|
|
|
108
108
|
The URL comes as for [`scaffold`](#scaffold): the connection string, the variable `--env` names, or `DATABASE_URL`, each also read from the nearest `.env`.
|
|
109
109
|
|
|
110
|
+
A config that exports no resource fails, as one that lost its resources by mistake, unless `protobase.config.ts` says the app has none with [`resources: 'none'`](config/app.md#resources); one that says so and exports a resource fails too.
|
|
111
|
+
|
|
110
112
|
Imports `config/index.ts` and the views of `config/*/ui.ts`, as the config module has them by convention, and checks every exported resource against the database, with the resources Protobase adds by what `protobase.config.ts` (read with `command: 'tool'`) and the resources enable: the [webhook](webhooks.md#subscriptions-in-the-admin-app) ones of `webhooks`, Failed jobs, [Activity](history.md) and [Comments](comments.md). The tables [`migration`](#migration) writes for those have every index their reads need, so after the project's migrations they pass; a read of theirs that lacks an index, as on a table an earlier version wrote, is an error and doctor exits 1 until you run `migration` and apply what it writes:
|
|
111
113
|
|
|
112
114
|
- error: missing table or column, field type that does not fit the column (a file field needs a text column), table without a usable key, configured key not backed by a unique index, `.openExisting()` fields that are not the columns of a unique index, relation to a resource the config does not declare
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# App options
|
|
4
4
|
|
|
5
|
-
The config keys of the app itself, its name, public URL, secret, language, time zone, install colours and
|
|
5
|
+
The config keys of the app itself, its name, public URL, secret, language, time zone, install colours, mobile build and whether it has resources, with their types, defaults and environment variables.
|
|
6
6
|
|
|
7
7
|
The keys of the app itself, at the top level of [`protobase.config.ts`](../config.md).
|
|
8
8
|
|
|
@@ -113,3 +113,15 @@ export default defineConfig({
|
|
|
113
113
|
mobile: { appId: 'com.example.shop', plugins: { '@capacitor/camera': '^8.0.0' } },
|
|
114
114
|
})
|
|
115
115
|
```
|
|
116
|
+
|
|
117
|
+
## resources
|
|
118
|
+
|
|
119
|
+
- **Type:** `'none'`
|
|
120
|
+
|
|
121
|
+
Says the app has no resources on purpose, such as an app that only signs people in for other apps. [`protobase doctor`](../cli.md#doctor) refuses an app whose `config/index.ts` exports no resource, since one that lost them by mistake would deploy with nothing to serve; with `resources: 'none'` it accepts one with none, and refuses one that exports a resource. Without the key, doctor keeps refusing an app with none.
|
|
122
|
+
|
|
123
|
+
An app with no resources builds and serves as any other: sign-in, the account page, its API functions and plugins' routes. Its sidebar has no resource entries, and `/` opens the signed-in person's account page when there is no page or resource to open.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
export default defineConfig({ resources: 'none' })
|
|
127
|
+
```
|
|
@@ -319,10 +319,10 @@ export default defineConfig({ auth: { mcp: true, oauth: { api: true } } })
|
|
|
319
319
|
|
|
320
320
|
## auth.openIdProvider
|
|
321
321
|
|
|
322
|
-
- **Type:** `true | { connectPage?: string; audiences?: string[] }`
|
|
322
|
+
- **Type:** `true | { connectPage?: string; audiences?: string[]; subject?: 'user' | 'grant' }`
|
|
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`, 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`). 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).
|
|
325
|
+
Makes the app an OpenID provider for the clients its admins register at `/api/auth/openid-provider/clients`, 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`). 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 } })
|
|
@@ -26,7 +26,7 @@ Each key is described with its type and default in the option pages:
|
|
|
26
26
|
|
|
27
27
|
| Page | Keys |
|
|
28
28
|
| --- | --- |
|
|
29
|
-
| [App options](config/app.md) | `name`, `url`, `secret`, `previousSecrets`, `locale`, `timezone`, `themeColor`, `backgroundColor`, `mobile` |
|
|
29
|
+
| [App options](config/app.md) | `name`, `url`, `secret`, `previousSecrets`, `locale`, `timezone`, `themeColor`, `backgroundColor`, `mobile`, `resources` |
|
|
30
30
|
| [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
|
|
31
31
|
| [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates`, `realtime`, `calls`, `userTables` |
|
|
32
32
|
| [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
|