@protobase/cli 0.106.2 → 0.107.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/resource-count.js +11 -0
- package/dist/doctor/run.js +2 -1
- package/dist/organizations/api.js +2 -4
- package/dist/organizations/commands.js +2 -27
- package/dist/users/commands.js +9 -4
- package/dist/users/users-api.js +1 -1
- package/package.json +8 -8
- package/skills/protobase/references/features/start-a-project.md +1 -0
- package/skills/protobase/references/reference/auth.md +2 -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.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());
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addAppRoleToOwners, addMember, createOrganization, listOrganizations,
|
|
1
|
+
import { addAppRoleToOwners, addEveryUser, addMember, createOrganization, listOrganizations, removeMember, setMemberRoles } from "@protobase/server";
|
|
2
2
|
//#region src/organizations/api.ts
|
|
3
3
|
const organizationsApi = (auth) => ({
|
|
4
4
|
listOrganizations: () => listOrganizations(auth),
|
|
@@ -7,9 +7,7 @@ const organizationsApi = (auth) => ({
|
|
|
7
7
|
setMemberRoles: (input) => setMemberRoles(auth, input),
|
|
8
8
|
removeMember: (input) => removeMember(auth, input),
|
|
9
9
|
addAppRoleToOwners: (appRole) => addAppRoleToOwners(auth, appRole),
|
|
10
|
-
|
|
11
|
-
setUserRole: (input) => setUserRole(auth, input),
|
|
12
|
-
membershipRoles: () => auth.roleDefinitions.names.filter((name) => name !== "admin" && name !== "user")
|
|
10
|
+
addEveryUser: (organization) => addEveryUser(auth, organization)
|
|
13
11
|
});
|
|
14
12
|
//#endregion
|
|
15
13
|
export { organizationsApi };
|
|
@@ -30,33 +30,8 @@ const createOrganizationCommand = async (api, options, out) => {
|
|
|
30
30
|
});
|
|
31
31
|
out(`Created organization ${organization.slug} (${organization.id}), owned by ${options.owner}\n`);
|
|
32
32
|
if (options.members !== "all") return;
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
if (user.email.toLowerCase() === options.owner.toLowerCase()) continue;
|
|
36
|
-
const global = user.role.split(",").map((name) => name.trim()).filter(Boolean);
|
|
37
|
-
if (global.includes("admin")) {
|
|
38
|
-
await api.addMember({
|
|
39
|
-
organization: organization.id,
|
|
40
|
-
email: user.email,
|
|
41
|
-
role: "owner",
|
|
42
|
-
appRoles: holdable
|
|
43
|
-
});
|
|
44
|
-
out(` ${user.email}: owner, with every app role\n`);
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const appRoles = global.filter((name) => holdable.includes(name));
|
|
48
|
-
await api.addMember({
|
|
49
|
-
organization: organization.id,
|
|
50
|
-
email: user.email,
|
|
51
|
-
role: "member",
|
|
52
|
-
appRoles
|
|
53
|
-
});
|
|
54
|
-
await api.setUserRole({
|
|
55
|
-
email: user.email,
|
|
56
|
-
role: "user"
|
|
57
|
-
});
|
|
58
|
-
out(` ${user.email}: member${appRoles.length > 0 ? `, with ${appRoles.join(",")}` : ""}\n`);
|
|
59
|
-
}
|
|
33
|
+
for (const user of await api.addEveryUser(organization.id)) if (user.role === "owner") out(` ${user.email}: owner, with every app role\n`);
|
|
34
|
+
else out(` ${user.email}: member${user.appRoles.length > 0 ? `, with ${user.appRoles.join(",")}` : ""}\n`);
|
|
60
35
|
};
|
|
61
36
|
const addMemberCommand = async (api, options, out) => {
|
|
62
37
|
const appRoles = parseRoleList(options.appRoles);
|
package/dist/users/commands.js
CHANGED
|
@@ -25,15 +25,20 @@ const createUserCommand = async (api, options, deps, out) => {
|
|
|
25
25
|
out(`Created ${user.role} ${user.email}${shownAs(user.role, labels)}${options.githubId ? `, linked to GitHub user ${options.githubId}` : ""}\n`);
|
|
26
26
|
if (generated) out(`Password (shown once): ${password}\n`);
|
|
27
27
|
};
|
|
28
|
+
/** Prints every user, oldest first, a page at a time as the store pages them; the first page sets the columns' width. */
|
|
28
29
|
const listUsersCommand = async (api, out) => {
|
|
29
|
-
|
|
30
|
-
if (users.length === 0) {
|
|
30
|
+
let page = await api.listUsers();
|
|
31
|
+
if (page.users.length === 0) {
|
|
31
32
|
out("No users yet. Create the first admin with: protobase users create you@example.com\n");
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
|
-
const width = Math.max(...users.map((user) => user.email.length), 5);
|
|
35
|
+
const width = Math.max(...page.users.map((user) => user.email.length), 5);
|
|
35
36
|
out(`${"EMAIL".padEnd(width)} ${"ROLE".padEnd(8)} CREATED\n`);
|
|
36
|
-
for (
|
|
37
|
+
for (;;) {
|
|
38
|
+
for (const user of page.users) out(`${user.email.padEnd(width)} ${user.role.padEnd(8)} ${user.createdAt}${user.banned ? " disabled" : ""}\n`);
|
|
39
|
+
if (!page.next) return;
|
|
40
|
+
page = await api.listUsers(page.next);
|
|
41
|
+
}
|
|
37
42
|
};
|
|
38
43
|
const listRolesCommand = async (api, out) => {
|
|
39
44
|
const { roles, defaultRole } = await api.roles();
|
package/dist/users/users-api.js
CHANGED
|
@@ -8,7 +8,7 @@ const usersApi = (auth) => ({
|
|
|
8
8
|
labels: auth.roleDefinitions.labels
|
|
9
9
|
}),
|
|
10
10
|
createUser: (input) => createUser(auth, input),
|
|
11
|
-
listUsers: () => listUsers(auth),
|
|
11
|
+
listUsers: (after) => listUsers(auth, after && { after }),
|
|
12
12
|
deleteUser: (email) => deleteUser(auth, email),
|
|
13
13
|
setUserRole: (input) => setUserRole(auth, input),
|
|
14
14
|
setUserBanned: (input) => setUserBanned(auth, input)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.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.107.1",
|
|
47
|
+
"@protobase/layout": "0.107.1",
|
|
48
|
+
"@protobase/query": "0.107.1",
|
|
49
|
+
"@protobase/schema": "0.107.1",
|
|
50
|
+
"@protobase/server": "0.107.1",
|
|
51
|
+
"@protobase/ui": "0.107.1",
|
|
52
|
+
"@protobase/workflows": "0.107.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",
|
|
@@ -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.
|
|
@@ -152,13 +152,13 @@ const auth = await loadProjectAuth(process.cwd()) // the project's fo
|
|
|
152
152
|
|
|
153
153
|
await createUser(auth, { email, password?, name?, role? }) // the first user is always an admin; later ones default to `user`
|
|
154
154
|
await hasUsers(auth) // boolean
|
|
155
|
-
await listUsers(auth)
|
|
155
|
+
await listUsers(auth, { after?, size? }) // a page, oldest first: { users: [{ id, email, role, banned, createdAt }], next? }, never passwords
|
|
156
156
|
await setUserRole(auth, { email, role }) // a role of auth.roles, or several comma separated
|
|
157
157
|
await setUserBanned(auth, { email, banned }) // banning ends the user's sessions and blocks sign-in
|
|
158
158
|
await deleteUser(auth, email) // with sessions and accounts
|
|
159
159
|
```
|
|
160
160
|
|
|
161
|
-
The last active admin cannot be deleted, demoted or banned: those functions throw instead, and Better Auth's admin endpoints answer `400 LAST_ADMIN`, so every caller is protected. An account created by `createUser` or an admin counts as having a verified address, since whoever created it vouches for it; that lets it sign in with an [emailed code](#emailed-sign-in-codes).
|
|
161
|
+
`listUsers` answers a page of `size` users (500 unless told), as Postgres pages them by creation; pass its `next` as `after` for the page after, until a page has no `next`. The last active admin cannot be deleted, demoted or banned: those functions throw instead, and Better Auth's admin endpoints answer `400 LAST_ADMIN`, so every caller is protected. An account created by `createUser` or an admin counts as having a verified address, since whoever created it vouches for it; that lets it sign in with an [emailed code](#emailed-sign-in-codes).
|
|
162
162
|
|
|
163
163
|
Until a user exists sign-in fails, and `GET /api/auth/status` (public) answers `{ "needsAdmin": true, "signInMethods": ["password", "passkey"], "passwordReset": false, "socialProviders": [] }` so a login page can say what to do. The admin app's page then shows the `users create` command to run on the host. A hosting platform where nobody runs commands on the host sets `PROTOBASE_FIRST_ADMIN_URL` to its own page where the first user is added, such as its console's; the status then also answers `firstAdminUrl`, and the page links there in place of the command. `signInMethods` lists the ways to sign in the [sign-in policy](#sign-in-policy) leaves on (`password`, `emailCode`, `passkey`), `passwordReset` is whether [reset mail](#password-reset) can be sent and passwords are on, `signInFirst`, when there, says the page leads with an [emailed code](#emailed-sign-in-codes), `signUp`, when there, says anyone can [make an account](#open-sign-up), and `staffSignIn`, when there, names the provider of [staff sign-in](#staff-sign-in). Further users are created by an admin on the [Users page](#users-page), or with `createUser` on the host. The auth store holds a connection pool; scripts that call these functions end the process themselves.
|
|
164
164
|
|
|
@@ -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
|
+
```
|
|
@@ -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` |
|