@protobase/server 0.3.4 → 0.4.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/assistant/assistant-settings.js +2 -1
- package/dist/better-auth/admin-only.js +13 -0
- package/dist/better-auth/create-auth.d.ts +2357 -30
- package/dist/better-auth/create-auth.js +70 -24
- package/dist/better-auth/operator-provider.d.ts +29 -0
- package/dist/better-auth/operator-provider.js +130 -0
- package/dist/better-auth/parse-roles.d.ts +7 -0
- package/dist/better-auth/parse-roles.js +12 -0
- package/dist/better-auth/policy-plugin.js +142 -0
- package/dist/better-auth/policy-store.js +65 -0
- package/dist/better-auth/sign-in-enforcement.js +65 -0
- package/dist/better-auth/sign-in-mail.js +78 -0
- package/dist/better-auth/sign-in-policy.d.ts +49 -0
- package/dist/better-auth/sign-in-policy.js +83 -0
- package/dist/better-auth/staff-checks.js +65 -0
- package/dist/better-auth/staff-log.d.ts +14 -0
- package/dist/better-auth/staff-log.js +96 -0
- package/dist/better-auth/staff-plugin.js +61 -0
- package/dist/better-auth/staff-sign-in-endpoints.js +162 -0
- package/dist/better-auth/status-route.js +23 -8
- package/dist/better-auth/tokens.js +1 -1
- package/dist/better-auth/two-factor-challenge.js +23 -0
- package/dist/better-auth/users.d.ts +5 -7
- package/dist/better-auth/users.js +3 -10
- package/dist/create-admin.js +4 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.js +6 -2
- package/dist/meta.js +3 -1
- package/dist/runtime/runtime-settings.d.ts +14 -0
- package/dist/runtime/runtime-settings.js +14 -0
- package/dist/types.d.ts +3 -0
- package/package.json +12 -9
|
@@ -13,6 +13,7 @@ const openRouterModel = "openrouter/auto";
|
|
|
13
13
|
/** The roles that see the assistant: `/meta` names it, and the built-in one answers, only for a caller with one of them. */
|
|
14
14
|
const assistantRoles = ["admin", "ai"];
|
|
15
15
|
const seesAssistant = (roles) => assistantRoles.some((role) => roles.includes(role));
|
|
16
|
+
/** `url` without a trailing slash; anything but an http(s) URL stops the server, naming `source`. */
|
|
16
17
|
const checkedUrl = (url, source) => {
|
|
17
18
|
if (!URL.canParse(url)) throw new Error(`${source} is not a URL; use https://...`);
|
|
18
19
|
const { protocol } = new URL(url);
|
|
@@ -52,4 +53,4 @@ const assistantSettings = (option, env) => {
|
|
|
52
53
|
};
|
|
53
54
|
};
|
|
54
55
|
//#endregion
|
|
55
|
-
export { assistantRoles, assistantSettings, assistantVariables, defaultChatsDirectory, openRouterModel, openRouterUrl, seesAssistant };
|
|
56
|
+
export { assistantRoles, assistantSettings, assistantVariables, checkedUrl, defaultChatsDirectory, openRouterModel, openRouterUrl, seesAssistant };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { parseRoles } from "./parse-roles.js";
|
|
2
|
+
import { APIError, createAuthMiddleware, sessionMiddleware } from "better-auth/api";
|
|
3
|
+
//#region src/better-auth/admin-only.ts
|
|
4
|
+
/** Lets a request through only with the session of an admin; others get `403 ADMIN_ONLY` with `message`. */
|
|
5
|
+
const adminOnly = (message) => createAuthMiddleware({ use: [sessionMiddleware] }, async (ctx) => {
|
|
6
|
+
if (!parseRoles(ctx.context.session.user.role).includes("admin")) throw new APIError("FORBIDDEN", {
|
|
7
|
+
code: "ADMIN_ONLY",
|
|
8
|
+
message
|
|
9
|
+
});
|
|
10
|
+
return { session: ctx.context.session };
|
|
11
|
+
});
|
|
12
|
+
//#endregion
|
|
13
|
+
export { adminOnly };
|