@protobase/server 0.33.2 → 0.33.3
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/check-owners.js +12 -6
- package/dist/create-admin.js +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/types.d.ts +9 -3
- package/package.json +4 -4
package/dist/check-owners.js
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
//#region src/check-owners.ts
|
|
2
|
+
const holds = (field, id) => field === "text" || field === id || field === "bigint" && id === "integer";
|
|
2
3
|
/**
|
|
3
|
-
* Stops startup on an `.owner()` field that cannot hold the ids of the
|
|
4
|
-
*
|
|
5
|
-
* ids come from the app's own authenticator, which this
|
|
4
|
+
* Stops startup on an `.owner()` field that cannot hold the ids of the signed-in users. The authenticator's
|
|
5
|
+
* `userIdType` declares their type; without it, the auth instance's users have Better Auth's own ids, random text,
|
|
6
|
+
* unless `generateUserId` makes the ids. Without either, the ids come from the app's own authenticator, which this
|
|
7
|
+
* cannot see.
|
|
6
8
|
*/
|
|
7
|
-
const checkOwnerFields = (registry, auth) => {
|
|
9
|
+
const checkOwnerFields = (registry, userIdType, auth) => {
|
|
10
|
+
if (userIdType) return checkAgainst(registry, userIdType, (ownerType) => `the authenticator's users have ${userIdType} ids: make it a ${userIdType} or text column, or declare the authenticator's userIdType`);
|
|
8
11
|
if (!auth || auth.generatesUserIds) return;
|
|
12
|
+
checkAgainst(registry, "text", (ownerType) => `Better Auth's user ids are random text: make it a text column, or give createAuth a generateUserId that makes ${ownerType} ids`);
|
|
13
|
+
};
|
|
14
|
+
const checkAgainst = (registry, userIdType, fix) => {
|
|
9
15
|
for (const entry of registry.entries) {
|
|
10
|
-
if (entry.ownerType === void 0 || entry.ownerType
|
|
11
|
-
throw new Error(`${entry.name}.${entry.model.owner} is the owner of its records, so it holds the signed-in user's id, but it holds ${entry.ownerType} values and
|
|
16
|
+
if (entry.ownerType === void 0 || holds(entry.ownerType, userIdType)) continue;
|
|
17
|
+
throw new Error(`${entry.name}.${entry.model.owner} is the owner of its records, so it holds the signed-in user's id, but it holds ${entry.ownerType} values and ${fix(entry.ownerType)}`);
|
|
12
18
|
}
|
|
13
19
|
};
|
|
14
20
|
//#endregion
|
package/dist/create-admin.js
CHANGED
|
@@ -115,7 +115,7 @@ const createAdmin = ({ resources: appResources, views: appViews = [], pages = []
|
|
|
115
115
|
checkBottomBars(registry, bottomBarModels, pageModels.map((entry) => entry.name), declaredRoles(auth, options.roles));
|
|
116
116
|
checkViews(registry, viewModels, pageModels.map((entry) => entry.name), fieldTypes);
|
|
117
117
|
checkRoleLimits(registry, options.roles?.limits ?? []);
|
|
118
|
-
checkOwnerFields(registry, auth);
|
|
118
|
+
checkOwnerFields(registry, authenticate.userIdType, auth);
|
|
119
119
|
checkPositionAfter(registry);
|
|
120
120
|
checkParents(registry);
|
|
121
121
|
checkPages(pageModels, {
|
package/dist/registry.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import "./resource-source.js";
|
|
2
|
-
import { ResourceModel } from "@protobase/schema";
|
|
2
|
+
import { KeyType, ResourceModel } from "@protobase/schema";
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { JobDefinition } from "./jobs/job-types.js";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { PageModel } from "@protobase/layout";
|
|
4
|
-
import { ResourceModel, ViewModel } from "@protobase/schema";
|
|
4
|
+
import { KeyType, ResourceModel, ViewModel } from "@protobase/schema";
|
|
5
5
|
import { Db } from "@protobase/query";
|
|
6
6
|
//#region src/types.d.ts
|
|
7
7
|
export type TenantValue = string | number;
|
|
@@ -20,8 +20,14 @@ export type Session = {
|
|
|
20
20
|
organization?: SessionOrganization;
|
|
21
21
|
anonymous?: true;
|
|
22
22
|
};
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the caller of a request, or throws a 401 problem (see `unauthorized`). `userIdType` declares the type of
|
|
25
|
+
* the ids of the users it returns, which `.owner()` fields are checked against at startup, such as `'uuid'` for an
|
|
26
|
+
* authenticator that maps the signed-in account to the app's own user row.
|
|
27
|
+
*/
|
|
28
|
+
export type Authenticator = ((request: Request) => Promise<Session> | Session) & {
|
|
29
|
+
userIdType?: KeyType;
|
|
30
|
+
};
|
|
25
31
|
export type AdminEnv = {
|
|
26
32
|
Variables: {
|
|
27
33
|
session: Session;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.3",
|
|
4
4
|
"description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@better-auth/passkey": "^1.7.7",
|
|
34
34
|
"@better-auth/sso": "^1.7.7",
|
|
35
|
-
"@protobase/layout": "0.33.
|
|
36
|
-
"@protobase/query": "0.33.
|
|
37
|
-
"@protobase/schema": "0.33.
|
|
35
|
+
"@protobase/layout": "0.33.3",
|
|
36
|
+
"@protobase/query": "0.33.3",
|
|
37
|
+
"@protobase/schema": "0.33.3",
|
|
38
38
|
"@react-email/render": "^2.1.0",
|
|
39
39
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
40
40
|
"@sentry/core": "^11.7.0",
|