@protobase/cli 0.110.3 → 0.110.5
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { projectDerived, projectFiles, projectFunctions, projectJobs, projectNotifications, projectOptions, projectResources, projectWebhooks, projectWorkflows } from "./project-parts.js";
|
|
2
2
|
import { userTablesOn } from "./user-tables-config.js";
|
|
3
|
-
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions, workflowPlugins } from "@protobase/server/internal";
|
|
3
|
+
import { buildAppAuth, buildAuthenticator, checkCallsOptions, checkStatusOptions, isOverSignIn, workflowPlugins } from "@protobase/server/internal";
|
|
4
4
|
//#region src/config/build-project.ts
|
|
5
5
|
/**
|
|
6
6
|
* The app's own mailer, the default export of its auth/mailer.ts: what sign-in and the jobs (`context.mail`) both send
|
|
@@ -43,12 +43,15 @@ const workflowConnectionsOf = (workflows) => ({
|
|
|
43
43
|
});
|
|
44
44
|
/**
|
|
45
45
|
* How the API verifies tokens: the default export of the app's auth/authenticate.ts when it has one, such as a
|
|
46
|
-
* `jwtAuthenticator` for tokens of another system
|
|
46
|
+
* `jwtAuthenticator` for tokens of another system, or one made over the app's sign-in (`overSignIn`); otherwise the
|
|
47
|
+
* app's sign-in with the `authenticate` settings.
|
|
47
48
|
*/
|
|
48
49
|
const projectAuthenticate = async (config, auth) => {
|
|
49
50
|
const own = config.sources.map(({ files }) => files.module("auth/authenticate.ts")).findLast(Boolean);
|
|
50
|
-
if (own) return (
|
|
51
|
-
|
|
51
|
+
if (!own) return buildAuthenticator(config.authenticate, auth);
|
|
52
|
+
const exported = (await own()).default;
|
|
53
|
+
if (isOverSignIn(exported)) return exported.overSignIn(buildAuthenticator(config.authenticate, auth));
|
|
54
|
+
return exported;
|
|
52
55
|
};
|
|
53
56
|
/** The app, built from its merged config over its database: every reference loaded, auth and the authenticator made. */
|
|
54
57
|
const buildProject = async (config, database) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.110.
|
|
3
|
+
"version": "0.110.5",
|
|
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.110.
|
|
47
|
-
"@protobase/layout": "0.110.
|
|
48
|
-
"@protobase/query": "0.110.
|
|
49
|
-
"@protobase/schema": "0.110.
|
|
50
|
-
"@protobase/server": "0.110.
|
|
51
|
-
"@protobase/ui": "0.110.
|
|
52
|
-
"@protobase/workflows": "0.110.
|
|
46
|
+
"@protobase/config": "0.110.5",
|
|
47
|
+
"@protobase/layout": "0.110.5",
|
|
48
|
+
"@protobase/query": "0.110.5",
|
|
49
|
+
"@protobase/schema": "0.110.5",
|
|
50
|
+
"@protobase/server": "0.110.5",
|
|
51
|
+
"@protobase/ui": "0.110.5",
|
|
52
|
+
"@protobase/workflows": "0.110.5",
|
|
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",
|
|
@@ -605,7 +605,7 @@ Register the app with the provider as a confidential client with the redirect UR
|
|
|
605
605
|
- **The provider id:** set `PROTOBASE_SIGN_IN_PROVIDER=github` only when the provider's `sub` is the GitHub user id, as Protobase Cloud's is. Its links are then those of Better Auth's own GitHub provider, so an app that later brings its own GitHub app keeps every person's link. Dex's and Keycloak's `sub` is their own id, so keep the default `oidc` for them.
|
|
606
606
|
- **Startup:** the provider's settings are read when the app starts; when they cannot be, the provider is left out until the next start (the status and sign-in page do not offer it) and every other way to sign in works.
|
|
607
607
|
- **Linking by address, safely:** a provider's first sign-in for someone links their account only when the token says the provider verified the address (`email_verified: true`) and the account's own address is verified. Once linked, the link alone finds them: the provider's id and `sub`, whatever address the token carries later. A person linked to one subject of a provider is not linked to a second one by address (`403 PROVIDER_ACCOUNT_LINKED`), unless the provider signs in [devices](#device-accounts). The store holds each provider's account once, and for a provider that links one subject per person, one account per person (unique indexes on the provider and account id, and on the provider and person, auth store migration 11), so two first sign-ins at the same moment link one, whether they bring the same subject or two.
|
|
608
|
-
- The [sign-in policy](#sign-in-policy) has one row for every one of them, and `GET /api/auth/status` names those with a button as `platformProviders: [{ provider, name }]` besides listing them in `socialProviders
|
|
608
|
+
- The [sign-in policy](#sign-in-policy) has one row for every one of them, and `GET /api/auth/status` names those with a button as `platformProviders: [{ provider, name }]` besides listing them in `socialProviders`, and those that take [token sign-in](#token-sign-in), by token alone too, as `tokenProviders: [provider]`, so a client such as a phone app knows before it posts an ID token whether the app takes it, and through which provider.
|
|
609
609
|
|
|
610
610
|
Set the first three together or none: some but not all of them stops the app at start with an error. In the config, `auth.signInProviders` takes a list of the same settings with `scopes`, `tokenSignIn`, `authorizationParams`, `hidden`, `button` and `devices`, and `[]` turns them off whatever the environment says:
|
|
611
611
|
|
|
@@ -759,7 +759,7 @@ The app's own pages are under the profile menu: the switcher, "Manage organizati
|
|
|
759
759
|
|
|
760
760
|
Sign in at `POST /api/auth/sign-in/email` (or with a code or passkey), then `GET /api/auth/token` (with the session cookie) returns `{ token }`, an EdDSA JWT valid for 15 minutes, unless the [sign-in policy](#sign-in-policy) requires something the account has not set up; the keys are at `/api/auth/jwks`. Send it as `Authorization: Bearer <token>`. `/token` is the only way to a token in the browser: the `set-auth-jwt` header of Better Auth's JWT plugin is off. No other answer under `/api/auth` carries the session token (Better Auth's `token` and `session.token`, as in a sign-in, `get-session` or `list-sessions`): the session is the httpOnly cookie's alone, so script on the page never holds it.
|
|
761
761
|
|
|
762
|
-
The app's authenticator, which the config's `authenticate` describes, maps the claims to a session: `sub` is the user id, `roles` come from the `role` claim, the session's [active role](#active-role) of those in the admin plugin's `role` column on the user (a comma separated string; the first user is always `admin`). Access rules see them as `ctx.user.roles`. Without organizations, the tenant is `authenticate.tenant`, never a claim; with them, it is the organization the session works in (`org`, see [organizations](#organizations)). The key set is cached in memory: read once, again every 10 minutes (so removed keys stop being accepted), and again when a token names an unknown `kid` (a rotated key), at most once per 30 seconds however many such tokens arrive (`authenticate: { cache: { refreshMs, minReloadMs } }`). An API that runs apart from the auth server sets `authenticate: { jwksUrl, issuer }`, with `organizations: true` when its tokens carry organizations; that turns its own sign-in off, unless the config sets `auth` too. An authenticator of the app's own, such as `jwtAuthenticator(...)` from `@protobase/server` for the tokens of another system, is the default export of `auth/authenticate.ts`, which replaces the one `authenticate` describes.
|
|
762
|
+
The app's authenticator, which the config's `authenticate` describes, maps the claims to a session: `sub` is the user id, `roles` come from the `role` claim, the session's [active role](#active-role) of those in the admin plugin's `role` column on the user (a comma separated string; the first user is always `admin`). Access rules see them as `ctx.user.roles`. Without organizations, the tenant is `authenticate.tenant`, never a claim; with them, it is the organization the session works in (`org`, see [organizations](#organizations)). The key set is cached in memory: read once, again every 10 minutes (so removed keys stop being accepted), and again when a token names an unknown `kid` (a rotated key), at most once per 30 seconds however many such tokens arrive (`authenticate: { cache: { refreshMs, minReloadMs } }`). An API that runs apart from the auth server sets `authenticate: { jwksUrl, issuer }`, with `organizations: true` when its tokens carry organizations; that turns its own sign-in off, unless the config sets `auth` too. An authenticator of the app's own, such as `jwtAuthenticator(...)` from `@protobase/server` for the tokens of another system, is the default export of `auth/authenticate.ts`, which replaces the one `authenticate` describes. One made over the app's sign-in, such as one that maps the signed-in account to a user of the app's own, is `overSignIn` from `@protobase/server` as that default export: `export default overSignIn((signIn) => withUsers(signIn))` is given the authenticator `authenticate` describes and returns the app's, which the server, `protobase dev` and `protobase doctor` all use.
|
|
763
763
|
|
|
764
764
|
`jwtAuthenticator` accepts asymmetric signature algorithms only unless you pass `algorithms` explicitly (the tests do, for HS256), so a token cannot be forged with a public key used as an HMAC secret; Better Auth signs with its own key pair and publishes the public keys at `/api/auth/jwks`. An expired, tampered, wrongly signed or missing token is a `401` problem with `WWW-Authenticate: Bearer`; with an [anonymous role](access.md#anonymous-access), a missing one on the resources API is served as that role instead.
|
|
765
765
|
|
|
@@ -996,4 +996,4 @@ Only the Better Auth routes under `/api/auth/*` (sign-in, password reset, [open
|
|
|
996
996
|
|
|
997
997
|
Roles are bundles of capabilities (`defineRoles` in `@protobase/schema`: `orders.read.own`, `costs.read`, `*.read`, ...). Export the result as `roles` from `config/roles.ts`, where Protobase finds it, and every operation without an explicit rule needs the matching capability; a capability may be limited to [fields and rows](access.md#capabilities). The token's `roles` become `ctx.user.roles` in rules; the user id (`sub`) is what `.own` compares with the resource's `.owner(...)` field, so it must be the id that field stores. How the API enforces them (hidden fields, row filters, record permissions) is in [the REST API reference](api.md#access).
|
|
998
998
|
|
|
999
|
-
**User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`tests/apps/erp/auth/hooks.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs sets `auth: { generateUserId: 'uuid' }` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as one in `auth/authenticate.ts` that returns the id of a row in its users table, declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
|
|
999
|
+
**User ids.** Better Auth gives a new user a random 32-character text id, so an `.owner(...)` field holds `text`: the server refuses to start (`protobase dev`, `serve`) when one holds integers or UUIDs, naming the field. An app whose owner columns are integers, such as a relation to its own users table, gives the `generateUserId` [hook](#hooks) the next value of that table's sequence, and adds the user's row there, as the ERP example does (`tests/apps/erp/auth/hooks.ts`, with the row added by `db/migrations/019_auth_users.sql` when someone joins an organization). One whose owner columns are UUIDs sets `auth: { generateUserId: 'uuid' }` (see [An existing users table](#an-existing-users-table)). An authenticator that maps the signed-in account to a user of the app's own, such as one in `auth/authenticate.ts` that returns the id of a row in its users table, usually made over the app's sign-in with `overSignIn` ([Tokens and roles](#tokens-and-roles)), declares the type of those ids instead, `Object.assign(authenticate, { userIdType: 'uuid' })` (or `'integer'`, `'bigint'`, `'text'`), and the owner fields are checked against that, by `protobase doctor` too. A request by a user whose id the owner field cannot hold, such as one made before `generateUserId`, fails with an `owner-id-mismatch` problem that names the field.
|