@protobase/server 0.3.3 → 0.3.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/assistant/assistant-settings.js +2 -1
- package/dist/create-admin.js +4 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- 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 +10 -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 };
|
package/dist/create-admin.js
CHANGED
|
@@ -6,6 +6,7 @@ import { authBasePath } from "./better-auth/create-auth.js";
|
|
|
6
6
|
import { statusRoute } from "./better-auth/status-route.js";
|
|
7
7
|
import { checkShell } from "./check-shell.js";
|
|
8
8
|
import { checkViews } from "./check-views.js";
|
|
9
|
+
import { runtimeUrl } from "./runtime/runtime-settings.js";
|
|
9
10
|
import { createMeta } from "./meta.js";
|
|
10
11
|
import { buildRegistry } from "./registry.js";
|
|
11
12
|
import { batchRoute } from "./routes/batch.js";
|
|
@@ -32,6 +33,7 @@ const createAdmin = ({ resources, views = [], pages = [], userMenu, db, authenti
|
|
|
32
33
|
});
|
|
33
34
|
const systemPath = basePath.slice(0, basePath.lastIndexOf("/"));
|
|
34
35
|
const assistant = assistantSettings(options.assistant, globalThis.process?.env ?? {});
|
|
36
|
+
const runtime = runtimeUrl(options.runtime, globalThis.process?.env ?? {});
|
|
35
37
|
const deps = {
|
|
36
38
|
db,
|
|
37
39
|
registry,
|
|
@@ -49,7 +51,8 @@ const createAdmin = ({ resources, views = [], pages = [], userMenu, db, authenti
|
|
|
49
51
|
...options.defaultAccess && { defaultAccess: options.defaultAccess }
|
|
50
52
|
},
|
|
51
53
|
rowPermissions: (resource) => typeof options.rowPermissions === "object" ? !options.rowPermissions.except.includes(resource) : options.rowPermissions !== false,
|
|
52
|
-
...assistant && { assistant: assistant.kind === "external" ? assistant.url : `${systemPath}/assistant` }
|
|
54
|
+
...assistant && { assistant: assistant.kind === "external" ? assistant.url : `${systemPath}/assistant` },
|
|
55
|
+
...runtime && { runtime }
|
|
53
56
|
};
|
|
54
57
|
const meta = createMeta(deps);
|
|
55
58
|
const onError = createErrorHandler(options.onUnhandledError);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AdminAuth, CreateAuthOptions, UserCreatedHook, createAuth, normalizeRoles } from "./better-auth/create-auth.js";
|
|
2
2
|
import { ResourceSource, configExports } from "./resource-source.js";
|
|
3
3
|
import { AssistantOptions, AssistantSettings, ModelSettings, assistantRoles, assistantSettings, assistantVariables, seesAssistant } from "./assistant/assistant-settings.js";
|
|
4
|
+
import { RuntimeOptions, runtimeUrl, runtimeVariable, seesRuntime } from "./runtime/runtime-settings.js";
|
|
4
5
|
import { Admin, AdminOptions, AuditEvent, AuditQueue, Authenticator, PipelineHook, ScanGuardMode, Session, TenantValue, User, ViewSource, WriteEvent, WriteOperation } from "./types.js";
|
|
5
6
|
import { CreateAdminInput, createAdmin } from "./create-admin.js";
|
|
6
7
|
import { consoleAuditQueue } from "./audit/console-queue.js";
|
|
@@ -20,4 +21,4 @@ import { AssistantTool, ToolContext, defineTool } from "./assistant/tools.js";
|
|
|
20
21
|
import { TurnOptions, runTurn } from "./assistant/turn.js";
|
|
21
22
|
import { QueryOptions, QueryResult, runReadOnlyQuery, runReadWriteQuery } from "./assistant/run-query.js";
|
|
22
23
|
import { readOnlyQueryTool, readWriteQueryTool } from "./assistant/query-tools.js";
|
|
23
|
-
export { type Admin, type AdminAuth, type AdminOptions, type ApprovalAnswer, type ApprovalRequest, type AssistantBackend, type AssistantOptions, type AssistantSettings, type AssistantTool, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type ChatMessage, type ChatTextPart, type Completion, type CompletionOptions, type Conversation, type ConversationRecord, type ConversationStore, type ConversationsOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, ModelError, type ModelSettings, type NewUser, type PipelineHook, type QueryOptions, type QueryResult, type ReasoningDetail, type ReasoningEffort, type ResourceSource, type ScanGuardMode, type Session, type StoredUser, type TenantValue, type ToolCall, type ToolContext, type ToolSpec, type TurnOptions, type User, type UserCreatedHook, type ViewSource, type WriteEvent, type WriteOperation, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, seesAssistant, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
|
|
24
|
+
export { type Admin, type AdminAuth, type AdminOptions, type ApprovalAnswer, type ApprovalRequest, type AssistantBackend, type AssistantOptions, type AssistantSettings, type AssistantTool, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticatorOptions, type ChatMessage, type ChatTextPart, type Completion, type CompletionOptions, type Conversation, type ConversationRecord, type ConversationStore, type ConversationsOptions, type CreateAdminInput, type CreateAuthOptions, HttpProblem, type IssueTokenOptions, type JwtOptions, ModelError, type ModelSettings, type NewUser, type PipelineHook, type QueryOptions, type QueryResult, type ReasoningDetail, type ReasoningEffort, type ResourceSource, type RuntimeOptions, type ScanGuardMode, type Session, type StoredUser, type TenantValue, type ToolCall, type ToolContext, type ToolSpec, type TurnOptions, type User, type UserCreatedHook, type ViewSource, type WriteEvent, type WriteOperation, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
|
package/dist/index.js
CHANGED
|
@@ -13,9 +13,10 @@ import { runTurn } from "./assistant/turn.js";
|
|
|
13
13
|
import { consoleAuditQueue } from "./audit/console-queue.js";
|
|
14
14
|
import { createAuth, normalizeRoles } from "./better-auth/create-auth.js";
|
|
15
15
|
import { createUser, deleteUser, hasUsers, listUsers, parseRoles, roleChoices, setUserBanned, setUserRole } from "./better-auth/users.js";
|
|
16
|
+
import { runtimeUrl, runtimeVariable, seesRuntime } from "./runtime/runtime-settings.js";
|
|
16
17
|
import { createAdmin } from "./create-admin.js";
|
|
17
18
|
import { configExports } from "./resource-source.js";
|
|
18
19
|
import { jwtAuthenticator } from "./auth/jwt.js";
|
|
19
20
|
import { betterAuthAuthenticator } from "./better-auth/authenticator.js";
|
|
20
21
|
import { issueToken, maxTokenTtlSeconds } from "./better-auth/tokens.js";
|
|
21
|
-
export { HttpProblem, ModelError, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, seesAssistant, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
|
|
22
|
+
export { HttpProblem, ModelError, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, badRequest, betterAuthAuthenticator, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createUser, defineTool, deleteUser, fileConversationStore, forbidden, hasUsers, issueToken, jwtAuthenticator, listUsers, maxTokenTtlSeconds, normalizeRoles, notFound, parseRoles, readOnlyQueryTool, readWriteQueryTool, requestApproval, roleChoices, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, seesAssistant, seesRuntime, setUserBanned, setUserRole, streamChatCompletion, unauthorized, withCacheBreakpoints };
|
package/dist/meta.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { seesAssistant } from "./assistant/assistant-settings.js";
|
|
2
2
|
import { sha256Hex, stableJson } from "./hash.js";
|
|
3
3
|
import { requestAccess } from "./request-access.js";
|
|
4
|
+
import { seesRuntime } from "./runtime/runtime-settings.js";
|
|
4
5
|
import { pruneView } from "./view-access.js";
|
|
5
6
|
import { prunePage } from "@protobase/layout";
|
|
6
7
|
import { pickView } from "@protobase/schema";
|
|
@@ -47,7 +48,8 @@ const createMeta = (deps) => {
|
|
|
47
48
|
].filter((op) => resolved.operations[op] && (resolved.recordChecks.includes(op) || resolved.rowFilter[op] !== void 0))
|
|
48
49
|
}])),
|
|
49
50
|
...deps.userMenu && { userMenu: { items: deps.userMenu.items.filter(shown) } },
|
|
50
|
-
...deps.assistant && seesAssistant(session.user.roles) && { assistant: { url: deps.assistant } }
|
|
51
|
+
...deps.assistant && seesAssistant(session.user.roles) && { assistant: { url: deps.assistant } },
|
|
52
|
+
...deps.runtime && seesRuntime(session.user.roles) && { runtime: { url: deps.runtime } }
|
|
51
53
|
};
|
|
52
54
|
return {
|
|
53
55
|
body,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/runtime/runtime-settings.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* `url`: the endpoint that reports the app's runtime version and updates it, such as a hosting platform's. The top
|
|
4
|
+
* bar shows an update button from what it answers. Falls back to `PROTOBASE_RUNTIME_URL`.
|
|
5
|
+
*/
|
|
6
|
+
export type RuntimeOptions = {
|
|
7
|
+
url?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const runtimeVariable = "PROTOBASE_RUNTIME_URL";
|
|
10
|
+
/** Only an admin sees the runtime endpoint: `/meta` names it to nobody else. */
|
|
11
|
+
export declare const seesRuntime: (roles: readonly string[]) => boolean;
|
|
12
|
+
/** The runtime endpoint, when one is set and the option is not `false`. A value that is no http(s) URL stops the server at startup. */
|
|
13
|
+
export declare const runtimeUrl: (option: RuntimeOptions | false | undefined, env: Record<string, string | undefined>) => string | undefined;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { checkedUrl } from "../assistant/assistant-settings.js";
|
|
2
|
+
//#region src/runtime/runtime-settings.ts
|
|
3
|
+
const runtimeVariable = "PROTOBASE_RUNTIME_URL";
|
|
4
|
+
/** Only an admin sees the runtime endpoint: `/meta` names it to nobody else. */
|
|
5
|
+
const seesRuntime = (roles) => roles.includes("admin");
|
|
6
|
+
/** The runtime endpoint, when one is set and the option is not `false`. A value that is no http(s) URL stops the server at startup. */
|
|
7
|
+
const runtimeUrl = (option, env) => {
|
|
8
|
+
if (option === false) return void 0;
|
|
9
|
+
const url = (option?.url ?? env["PROTOBASE_RUNTIME_URL"])?.trim();
|
|
10
|
+
if (!url) return void 0;
|
|
11
|
+
return checkedUrl(url, option?.url === void 0 ? runtimeVariable : "options.runtime.url");
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { runtimeUrl, runtimeVariable, seesRuntime };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssistantOptions } from "./assistant/assistant-settings.js";
|
|
2
|
+
import { RuntimeOptions } from "./runtime/runtime-settings.js";
|
|
2
3
|
import { Hono } from "hono";
|
|
3
4
|
import { PageModel } from "@protobase/layout";
|
|
4
5
|
import { ResolveOptions, ResourceModel, ViewModel } from "@protobase/schema";
|
|
@@ -89,6 +90,8 @@ export type AdminOptions = {
|
|
|
89
90
|
onUnhandledError?: (error: unknown) => void;
|
|
90
91
|
/** The assistant in the admin app's dock: a backend elsewhere or the built-in one (see `AssistantOptions`); `false` turns it off. */
|
|
91
92
|
assistant?: AssistantOptions | false;
|
|
93
|
+
/** The runtime updates endpoint behind the top bar's update button (see `RuntimeOptions`); `false` turns it off. */
|
|
94
|
+
runtime?: RuntimeOptions | false;
|
|
92
95
|
};
|
|
93
96
|
export type ViewSource = {
|
|
94
97
|
toModel(): ViewModel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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": {
|
|
@@ -21,22 +21,23 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsdown",
|
|
26
|
+
"prepack": "tsdown"
|
|
27
|
+
},
|
|
24
28
|
"publishConfig": {
|
|
25
29
|
"access": "public"
|
|
26
30
|
},
|
|
27
31
|
"dependencies": {
|
|
32
|
+
"@protobase/layout": "0.3.5",
|
|
33
|
+
"@protobase/query": "0.3.5",
|
|
34
|
+
"@protobase/schema": "0.3.5",
|
|
28
35
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
29
36
|
"better-auth": "^1.7.7",
|
|
30
37
|
"hono": "^4.13.13",
|
|
31
38
|
"jose": "^6.2.12",
|
|
32
39
|
"kysely": "^0.29.6",
|
|
33
40
|
"nodemailer": "^10.0.16",
|
|
34
|
-
"zod": "^4.6.5"
|
|
35
|
-
"@protobase/query": "0.3.3",
|
|
36
|
-
"@protobase/layout": "0.3.3",
|
|
37
|
-
"@protobase/schema": "0.3.3"
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "tsdown"
|
|
41
|
+
"zod": "^4.6.5"
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
+
}
|