@protobase/server 0.40.9 → 0.41.0
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/admin-options.d.ts +3 -1
- package/dist/assistant/write-record-tools.d.ts +8 -4
- package/dist/assistant/write-record-tools.js +21 -8
- package/dist/create-admin.js +3 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +4 -1
- package/dist/mcp/mcp-authenticator.js +4 -3
- package/dist/mcp/mcp-tools.d.ts +6 -2
- package/dist/mcp/mcp-tools.js +1 -1
- package/dist/mcp/mcp-writes.d.ts +7 -0
- package/dist/mcp/mcp-writes.js +16 -0
- package/dist/mobile-release/release-app.d.ts +43 -0
- package/dist/mobile-release/release-app.js +41 -0
- package/dist/mobile-release/release.d.ts +33 -0
- package/dist/mobile-release/release.js +34 -0
- package/dist/mobile-release/shell-update.js +25 -0
- package/dist/mobile-release/signing-key.d.ts +14 -0
- package/dist/mobile-release/signing-key.js +32 -0
- package/dist/package.js +1 -1
- package/package.json +4 -4
package/dist/admin-options.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { SourceOption } from "./sources/source-settings.js";
|
|
|
7
7
|
import { CorsOrigins } from "./api-cors.js";
|
|
8
8
|
import { AssistantOptions } from "./assistant/assistant-settings.js";
|
|
9
9
|
import { LocaleOption } from "./locale/locale-option.js";
|
|
10
|
+
import { McpWrites } from "./mcp/mcp-writes.js";
|
|
10
11
|
import { RuntimeOptions } from "./runtime/runtime-settings.js";
|
|
11
12
|
import { ResolveOptions, RoleLimit } from "@protobase/schema";
|
|
12
13
|
//#region src/admin-options.d.ts
|
|
@@ -57,12 +58,13 @@ export type AdminOptions = {
|
|
|
57
58
|
* `run_read_only_query`, which reads the whole database as the app's database role, outside the access rules.
|
|
58
59
|
* `writes: true` offers `create_record` and `update_record`, through the REST API's access rules, `validate` and write
|
|
59
60
|
* hooks; the person approves each write in their client, and a client that cannot ask is refused.
|
|
61
|
+
* `writes: { resources: ['tasks'] }` offers them on the listed resources only, and refuses a write to any other.
|
|
60
62
|
* `false`: the host serves its own MCP endpoint at `auth.mcp.path`, in front of this app. This app then answers 404
|
|
61
63
|
* there and needs no `forAudience`, while the OAuth provider's discovery stays.
|
|
62
64
|
*/
|
|
63
65
|
mcp?: {
|
|
64
66
|
sql?: boolean;
|
|
65
|
-
writes?:
|
|
67
|
+
writes?: McpWrites;
|
|
66
68
|
} | false;
|
|
67
69
|
/**
|
|
68
70
|
* The websites whose browser code may call the API (`/api/*` but `/api/auth/*`) besides the app's own origins (see
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { AssistantTool } from "./tools.js";
|
|
2
2
|
//#region src/assistant/write-record-tools.d.ts
|
|
3
|
+
/** The resources the write tools may change: any the caller may write, or only those listed. */
|
|
4
|
+
export type WriteRecordToolsInput = {
|
|
5
|
+
resources?: string[];
|
|
6
|
+
};
|
|
3
7
|
/** Creates a record of a resource once the user approves it, under the caller's access rules. */
|
|
4
|
-
export declare const createRecordTool: () => AssistantTool;
|
|
8
|
+
export declare const createRecordTool: (input?: WriteRecordToolsInput) => AssistantTool;
|
|
5
9
|
/** Updates one record by its key once the user approves it, under the caller's access rules. */
|
|
6
|
-
export declare const updateRecordTool: () => AssistantTool;
|
|
7
|
-
/** `create_record` and `update_record
|
|
8
|
-
export declare const writeRecordTools: () => AssistantTool[];
|
|
10
|
+
export declare const updateRecordTool: (input?: WriteRecordToolsInput) => AssistantTool;
|
|
11
|
+
/** `create_record` and `update_record`, on the resources `input` allows. */
|
|
12
|
+
export declare const writeRecordTools: (input?: WriteRecordToolsInput) => AssistantTool[];
|
|
9
13
|
//#endregion
|
|
@@ -11,15 +11,24 @@ const dataParameter = {
|
|
|
11
11
|
description: "Field names to values, as list_resources gives the fields."
|
|
12
12
|
};
|
|
13
13
|
const dataOf = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
14
|
+
const resourceParameterFor = ({ resources }) => resources ? {
|
|
15
|
+
...resourceParameter,
|
|
16
|
+
description: `The resource's name: one of ${resources.join(", ")}.`
|
|
17
|
+
} : resourceParameter;
|
|
18
|
+
const onlyNote = ({ resources }) => resources ? ` It writes only ${resources.join(", ")}.` : "";
|
|
19
|
+
const outside = ({ resources }, resource) => resources && !resources.includes(resource) ? JSON.stringify({
|
|
20
|
+
error: "forbidden",
|
|
21
|
+
message: `Writes over MCP reach only ${resources.join(", ")}, not ${resource}; nothing was written.`
|
|
22
|
+
}) : void 0;
|
|
14
23
|
const notApproved = (answer) => `The user did not approve this change (${answer}); nothing was written.`;
|
|
15
24
|
/** Creates a record of a resource once the user approves it, under the caller's access rules. */
|
|
16
|
-
const createRecordTool = () => defineTool({
|
|
25
|
+
const createRecordTool = (input = {}) => defineTool({
|
|
17
26
|
name: "create_record",
|
|
18
|
-
description:
|
|
27
|
+
description: `Creates a record of a resource and returns it as JSON ({ record, etag }). The user approves each write in their client first; nothing is written without it.${onlyNote(input)}`,
|
|
19
28
|
parameters: {
|
|
20
29
|
type: "object",
|
|
21
30
|
properties: {
|
|
22
|
-
resource:
|
|
31
|
+
resource: resourceParameterFor(input),
|
|
23
32
|
data: dataParameter
|
|
24
33
|
},
|
|
25
34
|
required: ["resource", "data"]
|
|
@@ -29,6 +38,8 @@ const createRecordTool = () => defineTool({
|
|
|
29
38
|
const resource = resourceOf(args);
|
|
30
39
|
const data = dataOf(args.data);
|
|
31
40
|
if (!resource || !data) return "Pass the resource and data as { \"resource\": \"<name>\", \"data\": { \"<field>\": <value> } }.";
|
|
41
|
+
const refusal = outside(input, resource);
|
|
42
|
+
if (refusal) return refusal;
|
|
32
43
|
const answer = await context.approve({
|
|
33
44
|
title: `Create a record in ${resource}?`,
|
|
34
45
|
code: JSON.stringify(data, null, 2),
|
|
@@ -39,13 +50,13 @@ const createRecordTool = () => defineTool({
|
|
|
39
50
|
}
|
|
40
51
|
});
|
|
41
52
|
/** Updates one record by its key once the user approves it, under the caller's access rules. */
|
|
42
|
-
const updateRecordTool = () => defineTool({
|
|
53
|
+
const updateRecordTool = (input = {}) => defineTool({
|
|
43
54
|
name: "update_record",
|
|
44
|
-
description:
|
|
55
|
+
description: `Updates fields of one record of a resource by its key and returns it as JSON ({ record, etag }). Pass the etag get_record gave to fail when someone changed the record since. The user approves each write in their client first; nothing is written without it.${onlyNote(input)}`,
|
|
45
56
|
parameters: {
|
|
46
57
|
type: "object",
|
|
47
58
|
properties: {
|
|
48
|
-
resource:
|
|
59
|
+
resource: resourceParameterFor(input),
|
|
49
60
|
key: keyParameter,
|
|
50
61
|
data: {
|
|
51
62
|
...dataParameter,
|
|
@@ -68,6 +79,8 @@ const updateRecordTool = () => defineTool({
|
|
|
68
79
|
const key = keyOf(args.key);
|
|
69
80
|
const data = dataOf(args.data);
|
|
70
81
|
if (!resource || key === void 0 || !data) return "Pass the resource, key and data as { \"resource\": \"<name>\", \"key\": \"<key>\", \"data\": { \"<field>\": <value> } }.";
|
|
82
|
+
const refusal = outside(input, resource);
|
|
83
|
+
if (refusal) return refusal;
|
|
71
84
|
const shownKey = Array.isArray(key) ? key.join(",") : String(key);
|
|
72
85
|
const answer = await context.approve({
|
|
73
86
|
title: `Update ${resource} ${shownKey}?`,
|
|
@@ -79,7 +92,7 @@ const updateRecordTool = () => defineTool({
|
|
|
79
92
|
return context.records.update(resource, key, data, { etag }).then((record) => JSON.stringify(record), refused);
|
|
80
93
|
}
|
|
81
94
|
});
|
|
82
|
-
/** `create_record` and `update_record
|
|
83
|
-
const writeRecordTools = () => [createRecordTool(), updateRecordTool()];
|
|
95
|
+
/** `create_record` and `update_record`, on the resources `input` allows. */
|
|
96
|
+
const writeRecordTools = (input = {}) => [createRecordTool(input), updateRecordTool(input)];
|
|
84
97
|
//#endregion
|
|
85
98
|
export { createRecordTool, updateRecordTool, writeRecordTools };
|
package/dist/create-admin.js
CHANGED
|
@@ -23,6 +23,7 @@ import { realtimePath, restPath, storagePath, supabaseFunctionsPath, supabasePat
|
|
|
23
23
|
import { goTruePath } from "./gotrue/keys.js";
|
|
24
24
|
import { authBasePath } from "./better-auth/auth-base-path.js";
|
|
25
25
|
import { mcpDiscovery } from "./better-auth/mcp/discovery-routes.js";
|
|
26
|
+
import { checkMcpWrites } from "./mcp/mcp-writes.js";
|
|
26
27
|
import { mcpAuthenticator } from "./mcp/mcp-authenticator.js";
|
|
27
28
|
import { mcpToolContext } from "./mcp/mcp-context.js";
|
|
28
29
|
import { mcpHandler } from "./mcp/mcp-handler.js";
|
|
@@ -127,6 +128,7 @@ const createAdmin = ({ resources: appResources, views: appViews = [], pages = []
|
|
|
127
128
|
checkRoleLimits(registry, options.roles?.limits ?? []);
|
|
128
129
|
checkOwnerFields(registry, authenticate.userIdType, auth);
|
|
129
130
|
const mcpAuthenticate = mcpAuthenticator(authenticate, auth?.mcp, options.mcp);
|
|
131
|
+
if (options.mcp) checkMcpWrites(registry, options.mcp.writes);
|
|
130
132
|
checkPositionAfter(registry);
|
|
131
133
|
checkParents(registry);
|
|
132
134
|
checkPages(pageModels, {
|
|
@@ -300,7 +302,7 @@ const createAdmin = ({ resources: appResources, views: appViews = [], pages = []
|
|
|
300
302
|
const tools = mcpTools({
|
|
301
303
|
db,
|
|
302
304
|
sql: options.mcp !== false && options.mcp?.sql === true,
|
|
303
|
-
writes: options.mcp !== false && options.mcp?.writes
|
|
305
|
+
writes: options.mcp !== false && options.mcp?.writes || false
|
|
304
306
|
});
|
|
305
307
|
const server = (session) => mcpServer({
|
|
306
308
|
info: {
|
package/dist/index.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { Conversation, ConversationsOptions, conversationKey, createConversation
|
|
|
43
43
|
import { ApprovalAnswer, ApprovalRequest, requestApproval } from "./assistant/approval.js";
|
|
44
44
|
import { AssistantTool, ReadableResources, ToolAnnotations, ToolContext, defineTool } from "./assistant/tools.js";
|
|
45
45
|
import { AssistantOptions, AssistantSettings, assistantRoles, assistantSettings, assistantVariables, seesAssistant } from "./assistant/assistant-settings.js";
|
|
46
|
+
import { McpWrites } from "./mcp/mcp-writes.js";
|
|
46
47
|
import { RuntimeOptions, runtimeUrl, runtimeVariable, seesRuntime } from "./runtime/runtime-settings.js";
|
|
47
48
|
import { AdminOptions } from "./admin-options.js";
|
|
48
49
|
import { CreateAdminInput, createAdmin } from "./create-admin.js";
|
|
@@ -89,7 +90,7 @@ import { WidgetOptions, maxWidgetPropsBytes, widget } from "./assistant/widget.j
|
|
|
89
90
|
import { QueryOptions, QueryResult, runReadOnlyQuery, runReadWriteQuery } from "./assistant/run-query.js";
|
|
90
91
|
import { readOnlyQueryTool, readWriteQueryTool } from "./assistant/query-tools.js";
|
|
91
92
|
import { getRecordTool, listRecordsTool, listResourcesTool, readRecordTools } from "./assistant/record-tools.js";
|
|
92
|
-
import { createRecordTool, updateRecordTool, writeRecordTools } from "./assistant/write-record-tools.js";
|
|
93
|
+
import { WriteRecordToolsInput, createRecordTool, updateRecordTool, writeRecordTools } from "./assistant/write-record-tools.js";
|
|
93
94
|
import { McpServerInput, mcpServer } from "./mcp/mcp-server.js";
|
|
94
95
|
import { McpToolsInput, mcpTools } from "./mcp/mcp-tools.js";
|
|
95
96
|
import { McpGateInput, mcpGate, sessionOf } from "./mcp/mcp-gate.js";
|
|
@@ -124,4 +125,7 @@ import { isSchedule } from "./jobs/schedule.js";
|
|
|
124
125
|
import { DrainResult, JobsRuntime, StartJobsOptions, startJobs } from "./jobs/runtime.js";
|
|
125
126
|
import { jobsDrainApp } from "./jobs/drain-route.js";
|
|
126
127
|
import { checkJobsSchema, jobsSchema, jobsSchemaMigration } from "./jobs/schema.js";
|
|
127
|
-
|
|
128
|
+
import { MobileRelease, ReleaseFile, ServedReleaseFile, composeRelease, releaseManifest } from "./mobile-release/release.js";
|
|
129
|
+
import { MobileReleaseAppInput, OfferedRelease, mobileReleaseApp } from "./mobile-release/release-app.js";
|
|
130
|
+
import { mobileSigningKeyVariable, readSigningKey } from "./mobile-release/signing-key.js";
|
|
131
|
+
export { type Admin, type AdminAuth, type AdminOptions, type ApiFunction, type ApiKeys, type ApiKeysOptions, type AppIcons, type AppIdentity, type ApplyOptions, type ApplyResult, type ApprovalAnswer, type ApprovalRequest, type AssistantBackend, type AssistantOptions, type AssistantSettings, type AssistantTool, type AuditEvent, type AuditQueue, type Authenticator, type BetterAuthAuthenticator, type BetterAuthAuthenticatorOptions, type Caller, type CallerOptions, type CapturedRow, type CascadingKey, type ChatMessage, type ChatTextPart, type CheckAiInput, type CleanupEntry, type CleanupReport, type CleanupSchedule, type CoalescedChange, type CommentItem, type CommentUsers, type Completion, type CompletionOptions, type Conversation, type ConversationRecord, type ConversationStore, type ConversationsOptions, type CorsOptions, type CorsOrigins, type CreateAdminInput, type CreateAuthOptions, type DrainResult, type EmailComponent, type EmailOptions, type EmailTemplate, type EncryptionStatus, type EncryptionTools, type EncryptionToolsInput, type EnqueueOptions, type ErrorReporter, type ErrorReportingOptions, type ErrorReportingSettings, type EventData, type EventsOptions, FatalJobError, type FieldApplied, type FieldStatus, type FileCleanupInput, type FileLimits, type FileObject, type FileProvider, type FileRef, type FileStore, type FileVariantObject, type FilesOptions, type FunctionApp, type FunctionCaller, type FunctionContext, type FunctionEnv, type FunctionHandler, type FunctionOptions, type FunctionRecords, type FunctionSocket, type FunctionSource, type HistoryOptions, HttpProblem, type IssueTokenOptions, type JobContext, type JobDefinition, type JobOptions, type JobsRuntime, type JwtOptions, type JwtVerifyOptions, type KeyFunctionContext, type LinkedAccount, type ListParams, type LocalFilesOptions, type MailMessage, type Mailer, type MapLayer, type MapOptions, type MapSettings, type McpGateInput, type McpHandlerInput, type McpRoutesInput, type McpServerInput, type McpToolsInput, type McpWrites, type MemberInput, MissingCredentials, type MobileConfig, type MobileRelease, type MobileReleaseAppInput, ModelError, type ModelSettings, type NewOrganization, type NewUser, type OfferedRelease, type OperatorProvider, type OrganizationRole, type OrganizationsOptions, type PipelineHook, type PlatformSignIn, type PluginOption, type PluginRef, type PngIcon, type ProjectConfig, type ProtectedFunctionOptions, type PublicFunctionContext, type PublicFunctionEnv, type PublicFunctionHandler, type PublicFunctionOptions, type QueryOptions, type QueryResult, type ReadableResources, type ReasoningDetail, type ReasoningEffort, type RebindOption, type RecordKeyInput, type RecordPage, type ReleaseFile, type RenderedEmail, type ResourceChange, type ResourceSource, type RoleDefinition, type RolesInput, type RunContext, type RuntimeOptions, type S3Bucket, type S3FilesOptions, type S3ListPage, type S3Object, type ScanGuardMode, type ScheduledDelete, type ServedReleaseFile, type Session, type SessionOrganization, type Sharp, type SignInPolicy, type SignInRule, type SignatureOptions, type SocketEvents, type SourceOption, type SourceRef, type StaffAccessRule, type StaffSignIn, type StandardSchema, type StandardWebhookOptions, type StartJobsOptions, type StoreFileInput, type StoredMember, type StoredObject, type StoredOrganization, type StoredUser, type StrayValues, type SubscriptionDefinition, type SubscriptionEvent, type SubscriptionOptions, type TenantValue, type ToolAnnotations, type ToolCall, type ToolContext, type ToolRecord, type ToolRecords, type ToolSpec, type TrustedApp, type TurnOptions, type UnreadableEntry, type User, type UserCreatedHook, type ViewSource, type WebhooksOptions, type WidgetOptions, type WriteEvent, type WriteOperation, type WriteRecordToolsInput, addAppRoleToOwners, addMember, apiKeyCaller, apiKeySettings, apiKeyVariables, aspectRatio, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, authSchemaMigration, authStoreTables, backgroundSettled, badRequest, beforeSignInPluginsVariable, betterAuthAuthenticator, betterAuthTokens, capSocketMessages, changesMigration, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkQueryRunner, checkSourceNames, checkViewQueries, checkWebhooksSchema, coalesce, commentsMigration, composeRelease, computedMigration, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createEncryptionTools, createFileCleanup, createOrganization, createRecordTool, createUser, defaultAppName, defaultSignInPolicy, defineConfig, defineEmail, defineFunction, defineJob, defineTool, deleteUser, errorReportingSettings, errorReportingVariable, eventMatcher, fileConversationStore, fileSize, fileType, forbidden, formatUri, functionApp, getRecordTool, goTruePath, handleDroppedConnections, hasUsers, honorSocketMessageCaps, imageSize, isBackgroundWork, isCaptured, isJobDefinition, isOAuthWellKnownPath, isSchedule, issueToken, jobDefinitions, jobsDrainApp, jobsSchema, jobsSchemaMigration, jwtAuthenticator, jwtVerifier, limitedFileStore, listOrganizations, listRecordsTool, listResourcesTool, listUsers, localFileStore, localFiles, mapSettings, mapStyleUrl, mapStyleVariable, maxTokenTtlSeconds, maxWidgetPropsBytes, mcpGate, mcpHandler, mcpRoutes, mcpServer, mcpToolContext, mcpTools, mergeConfig, migrationCommand, mobileReleaseApp, mobileSigningKeyVariable, newWebhookSecret, normalizeRoles, notFound, oauthWellKnownPaths, objectKey, parseColumns, parseRoles, passwordLength, pluginOptions, pluginsBeforeSignIn, pluginsFor, pluginsVariable, pngIcons, processor, queryRunnerMigration, readJson, readOnlyQueryTool, readOperatorSettings, readOutbox, readPlatformSignIn, readRecordTools, readSigningKey, readWriteQueryTool, readableResources, realtimeLimits, recordOf, releaseManifest, removeMember, renderVariant, requestApproval, requireEnv, resourceChange, roleChoices, runInBackground, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, s3FileStore, s3Files, seesAssistant, seesRuntime, sessionOf, setMemberRoles, setUserBanned, setUserRole, signInPolicyMethods, socketMessageCapOf, sourceOptions, sourcesFor, sourcesVariable, startErrorReporting, startJobs, storageCleanupSchedule, storageProvider, storeFile, storeUsage, streamChatCompletion, subscription, supabasePath, thumbHash, unauthorized, updateRecordTool, variantPath, verifySignature, verifyStandardWebhook, waitUntil, webauthnPath, webhooks, webhooksMigration, widget, withCacheBreakpoints, withTrustedApps, writeRecordTools };
|
package/dist/index.js
CHANGED
|
@@ -95,4 +95,7 @@ import { aspectRatio, fileSize, fileType, imageSize, processor } from "./files/p
|
|
|
95
95
|
import { defineEmail } from "./mail/define-email.js";
|
|
96
96
|
import { startJobs } from "./jobs/runtime.js";
|
|
97
97
|
import { jobsDrainApp } from "./jobs/drain-route.js";
|
|
98
|
-
|
|
98
|
+
import { composeRelease, releaseManifest } from "./mobile-release/release.js";
|
|
99
|
+
import { mobileReleaseApp } from "./mobile-release/release-app.js";
|
|
100
|
+
import { mobileSigningKeyVariable, readSigningKey } from "./mobile-release/signing-key.js";
|
|
101
|
+
export { FatalJobError, HttpProblem, MissingCredentials, ModelError, addAppRoleToOwners, addMember, apiKeyCaller, apiKeySettings, apiKeyVariables, aspectRatio, assistantProtocolRoutes, assistantRoles, assistantSettings, assistantVariables, authSchemaMigration, authStoreTables, backgroundSettled, badRequest, beforeSignInPluginsVariable, betterAuthAuthenticator, betterAuthTokens, capSocketMessages, changesMigration, checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkQueryRunner, checkSourceNames, checkViewQueries, checkWebhooksSchema, coalesce, commentsMigration, composeRelease, computedMigration, configExports, consoleAuditQueue, conversationKey, createAdmin, createAuth, createConversations, createEncryptionTools, createFileCleanup, createOrganization, createRecordTool, createUser, defaultAppName, defaultSignInPolicy, defineConfig, defineEmail, defineFunction, defineJob, defineTool, deleteUser, errorReportingSettings, errorReportingVariable, eventMatcher, fileConversationStore, fileSize, fileType, forbidden, formatUri, functionApp, getRecordTool, goTruePath, handleDroppedConnections, hasUsers, honorSocketMessageCaps, imageSize, isBackgroundWork, isCaptured, isJobDefinition, isOAuthWellKnownPath, isSchedule, issueToken, jobDefinitions, jobsDrainApp, jobsSchema, jobsSchemaMigration, jwtAuthenticator, jwtVerifier, limitedFileStore, listOrganizations, listRecordsTool, listResourcesTool, listUsers, localFileStore, localFiles, mapSettings, mapStyleUrl, mapStyleVariable, maxTokenTtlSeconds, maxWidgetPropsBytes, mcpGate, mcpHandler, mcpRoutes, mcpServer, mcpToolContext, mcpTools, mergeConfig, migrationCommand, mobileReleaseApp, mobileSigningKeyVariable, newWebhookSecret, normalizeRoles, notFound, oauthWellKnownPaths, objectKey, parseColumns, parseRoles, passwordLength, pluginOptions, pluginsBeforeSignIn, pluginsFor, pluginsVariable, pngIcons, processor, queryRunnerMigration, readJson, readOnlyQueryTool, readOperatorSettings, readOutbox, readPlatformSignIn, readRecordTools, readSigningKey, readWriteQueryTool, readableResources, realtimeLimits, recordOf, releaseManifest, removeMember, renderVariant, requestApproval, requireEnv, resourceChange, roleChoices, runInBackground, runReadOnlyQuery, runReadWriteQuery, runTurn, runtimeUrl, runtimeVariable, s3FileStore, s3Files, seesAssistant, seesRuntime, sessionOf, setMemberRoles, setUserBanned, setUserRole, signInPolicyMethods, socketMessageCapOf, sourceOptions, sourcesFor, sourcesVariable, startErrorReporting, startJobs, storageCleanupSchedule, storageProvider, storeFile, storeUsage, streamChatCompletion, subscription, supabasePath, thumbHash, unauthorized, updateRecordTool, variantPath, verifySignature, verifyStandardWebhook, waitUntil, webauthnPath, webhooks, webhooksMigration, widget, withCacheBreakpoints, withTrustedApps, writeRecordTools };
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { isMcpWrites } from "./mcp-writes.js";
|
|
1
2
|
//#region src/mcp/mcp-authenticator.ts
|
|
2
3
|
const hasAudiences = (authenticate) => typeof authenticate.forAudience === "function";
|
|
3
|
-
const isMcpOptions = (options) => options === void 0 || options === false || typeof options === "object" && options !== null && !Array.isArray(options) && Object.entries(options).every(([name, value]) =>
|
|
4
|
+
const isMcpOptions = (options) => options === void 0 || options === false || typeof options === "object" && options !== null && !Array.isArray(options) && Object.entries(options).every(([name, value]) => value === void 0 || name === "sql" && typeof value === "boolean" || name === "writes" && isMcpWrites(value));
|
|
4
5
|
/**
|
|
5
6
|
* The authenticator of the MCP endpoint's tokens, when MCP is on (`createAuth({ mcp })`); none when the host serves its
|
|
6
7
|
* own (`options.mcp: false`). Stops the server at startup when `options.mcp` is neither `false` nor
|
|
7
|
-
* `{ sql?: boolean; writes?: boolean }`, when it is set without MCP, or when `authenticate` cannot verify tokens for
|
|
8
|
+
* `{ sql?: boolean; writes?: boolean | { resources: string[] } }`, when it is set without MCP, or when `authenticate` cannot verify tokens for
|
|
8
9
|
* another audience.
|
|
9
10
|
*/
|
|
10
11
|
const mcpAuthenticator = (authenticate, mcp, options) => {
|
|
11
|
-
if (!isMcpOptions(options)) throw new Error("options.mcp takes false or { sql?: boolean, writes?: boolean }");
|
|
12
|
+
if (!isMcpOptions(options)) throw new Error("options.mcp takes false or { sql?: boolean, writes?: boolean | { resources: [<resource>, ...] } }");
|
|
12
13
|
if (options === false) return void 0;
|
|
13
14
|
if (options && !mcp) throw new Error("options.mcp needs createAuth({ mcp }) passed as auth");
|
|
14
15
|
if (!mcp) return void 0;
|
package/dist/mcp/mcp-tools.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Session } from "../types.js";
|
|
2
2
|
import { AssistantTool } from "../assistant/tools.js";
|
|
3
|
+
import { McpWrites } from "./mcp-writes.js";
|
|
3
4
|
import { Db } from "@protobase/query";
|
|
4
5
|
//#region src/mcp/mcp-tools.d.ts
|
|
5
6
|
export type McpToolsInput = {
|
|
6
7
|
db: Db;
|
|
7
8
|
/** Offers `run_read_only_query` to callers who see the assistant (`admin` or `ai`); it reads outside the access rules. */
|
|
8
9
|
sql: boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Offers `create_record` and `update_record`, on the listed resources only when given `{ resources }`; each write still
|
|
12
|
+
* needs the caller's role and their approval in the client.
|
|
13
|
+
*/
|
|
14
|
+
writes: McpWrites;
|
|
11
15
|
};
|
|
12
16
|
/**
|
|
13
17
|
* The default MCP tools for a caller: the record tools, the write tools when `writes` is on, and read-only SQL when `sql`
|
package/dist/mcp/mcp-tools.js
CHANGED
|
@@ -9,7 +9,7 @@ import { writeRecordTools } from "../assistant/write-record-tools.js";
|
|
|
9
9
|
*/
|
|
10
10
|
const mcpTools = ({ db, sql, writes }) => (session) => [
|
|
11
11
|
...readRecordTools(),
|
|
12
|
-
...writes ? writeRecordTools(
|
|
12
|
+
...writes === false ? [] : writeRecordTools(writes === true ? {} : { resources: writes.resources }),
|
|
13
13
|
...sql && seesAssistant(session.user.roles) ? [readOnlyQueryTool(db)] : []
|
|
14
14
|
];
|
|
15
15
|
//#endregion
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/mcp/mcp-writes.ts
|
|
2
|
+
const isResourceList = (value) => Array.isArray(value) && value.length > 0 && value.every((name) => typeof name === "string" && name !== "");
|
|
3
|
+
const isMcpWrites = (value) => {
|
|
4
|
+
if (typeof value === "boolean") return true;
|
|
5
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
6
|
+
const entries = Object.entries(value);
|
|
7
|
+
return entries.length === 1 && entries[0][0] === "resources" && isResourceList(entries[0][1]);
|
|
8
|
+
};
|
|
9
|
+
/** Stops startup when `options.mcp.writes` names a resource the app does not have. */
|
|
10
|
+
const checkMcpWrites = (registry, writes) => {
|
|
11
|
+
if (typeof writes !== "object") return;
|
|
12
|
+
const unknown = writes.resources.filter((name) => !registry.find(name));
|
|
13
|
+
if (unknown.length > 0) throw new Error(`options.mcp.writes names resources the app does not have: ${unknown.join(", ")}`);
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { checkMcpWrites, isMcpWrites };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MobileRelease } from "./release.js";
|
|
2
|
+
//#region src/mobile-release/release-app.d.ts
|
|
3
|
+
/** The release a server offers: its files, the native fingerprint of the binaries it runs on and the API origin it calls. */
|
|
4
|
+
export type OfferedRelease = MobileRelease & {
|
|
5
|
+
fingerprint: string;
|
|
6
|
+
origin: string;
|
|
7
|
+
};
|
|
8
|
+
export type MobileReleaseAppInput = {
|
|
9
|
+
/** `undefined` when the server serves no release, such as the API alone, whose app files a host serves. */
|
|
10
|
+
release?: OfferedRelease;
|
|
11
|
+
/** The server's Protobase version, which the shell a device runs must work with. */
|
|
12
|
+
serverVersion: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The live updater's routes. `GET /api/mobile/release` tells a device the release it should run: the server's own,
|
|
16
|
+
* when it runs on the device's binary, and whether the update is required. `GET /api/mobile/releases/<bundle id>?href=`
|
|
17
|
+
* serves the release's manifest and files, each with its sha256 in `X-Checksum` and, signed, its `X-Signature`, which
|
|
18
|
+
* the updater checks each file against: it never checks a file against the manifest.
|
|
19
|
+
*/
|
|
20
|
+
export declare const mobileReleaseApp: ({ release, serverVersion }: MobileReleaseAppInput) => import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, {
|
|
21
|
+
"/api/mobile/release": {
|
|
22
|
+
$get: {
|
|
23
|
+
input: {};
|
|
24
|
+
output: {};
|
|
25
|
+
outputFormat: string;
|
|
26
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
} & {
|
|
30
|
+
"/api/mobile/releases/:bundleId": {
|
|
31
|
+
$get: {
|
|
32
|
+
input: {
|
|
33
|
+
param: {
|
|
34
|
+
bundleId: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
output: {};
|
|
38
|
+
outputFormat: string;
|
|
39
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
}, "/", "/api/mobile/releases/:bundleId">;
|
|
43
|
+
//#endregion
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { badRequest, notFound, problemResponse } from "../problem.js";
|
|
2
|
+
import { isShellVersion, shellUpdateRequired } from "./shell-update.js";
|
|
3
|
+
import { Hono } from "hono";
|
|
4
|
+
import { mobileReleaseBasePath, mobileReleaseParams, mobileReleasePath, mobileReleasesPath } from "@protobase/schema/internal";
|
|
5
|
+
import { getMimeType } from "hono/utils/mime";
|
|
6
|
+
//#region src/mobile-release/release-app.ts
|
|
7
|
+
/**
|
|
8
|
+
* The live updater's routes. `GET /api/mobile/release` tells a device the release it should run: the server's own,
|
|
9
|
+
* when it runs on the device's binary, and whether the update is required. `GET /api/mobile/releases/<bundle id>?href=`
|
|
10
|
+
* serves the release's manifest and files, each with its sha256 in `X-Checksum` and, signed, its `X-Signature`, which
|
|
11
|
+
* the updater checks each file against: it never checks a file against the manifest.
|
|
12
|
+
*/
|
|
13
|
+
const mobileReleaseApp = ({ release, serverVersion }) => new Hono().get(mobileReleasePath, (c) => {
|
|
14
|
+
const problem = (error) => problemResponse(error, c.req.path);
|
|
15
|
+
const fingerprint = c.req.query(mobileReleaseParams.fingerprint);
|
|
16
|
+
const shellVersion = c.req.query(mobileReleaseParams.shellVersion);
|
|
17
|
+
if (!fingerprint) return problem(badRequest("invalid-fingerprint", `${mobileReleaseParams.fingerprint} must name the native fingerprint of the app`));
|
|
18
|
+
if (!shellVersion || !isShellVersion(shellVersion)) return problem(badRequest("invalid-shell-version", `${mobileReleaseParams.shellVersion} must be the x.y.z Protobase version of the shell the app runs`));
|
|
19
|
+
const offered = release?.fingerprint === fingerprint ? release : void 0;
|
|
20
|
+
const answer = {
|
|
21
|
+
bundleId: offered?.bundleId ?? null,
|
|
22
|
+
url: offered ? `${offered.origin}${mobileReleaseBasePath(offered.bundleId)}` : null,
|
|
23
|
+
required: shellUpdateRequired(shellVersion, serverVersion)
|
|
24
|
+
};
|
|
25
|
+
return c.json(answer, 200, {
|
|
26
|
+
"cache-control": "no-store",
|
|
27
|
+
"access-control-allow-origin": "*"
|
|
28
|
+
});
|
|
29
|
+
}).get(`${mobileReleasesPath}/:bundleId`, (c) => {
|
|
30
|
+
const href = c.req.query("href") ?? "";
|
|
31
|
+
const file = release && c.req.param("bundleId") === release.bundleId ? release.files.get(href) : void 0;
|
|
32
|
+
if (!file) return problemResponse(notFound("The release has no such file, or is no longer served"), c.req.path);
|
|
33
|
+
return c.body(file.content, 200, {
|
|
34
|
+
"content-type": getMimeType(href) ?? "application/octet-stream",
|
|
35
|
+
"cache-control": "public, max-age=31536000, immutable",
|
|
36
|
+
"x-checksum": file.checksum,
|
|
37
|
+
...file.signature && { "x-signature": file.signature }
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//#endregion
|
|
41
|
+
export { mobileReleaseApp };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { KeyObject } from "node:crypto";
|
|
2
|
+
//#region src/mobile-release/release.d.ts
|
|
3
|
+
/** A file of a release: its path inside the app's files, such as `assets/index-abc123.js`, and its bytes. */
|
|
4
|
+
export type ReleaseFile = {
|
|
5
|
+
href: string;
|
|
6
|
+
content: Uint8Array;
|
|
7
|
+
};
|
|
8
|
+
/** A file as the updater gets it: its bytes, their sha256 in hex and, with a signing key, their signature. */
|
|
9
|
+
export type ServedReleaseFile = {
|
|
10
|
+
content: Uint8Array;
|
|
11
|
+
checksum: string;
|
|
12
|
+
signature?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A release of the app's files: its bundle id, a hash of its manifest and of the signing key's public key, and every
|
|
16
|
+
* file by `href`, the manifest included.
|
|
17
|
+
*/
|
|
18
|
+
export type MobileRelease = {
|
|
19
|
+
bundleId: string;
|
|
20
|
+
files: Map<string, ServedReleaseFile>;
|
|
21
|
+
};
|
|
22
|
+
/** The updater's manifest of `files`: each one's `href`, sha256 in hex and size, in the order of their hrefs. */
|
|
23
|
+
export declare const releaseManifest: (files: ReleaseFile[]) => {
|
|
24
|
+
href: string;
|
|
25
|
+
checksum: string;
|
|
26
|
+
sizeInBytes: number;
|
|
27
|
+
}[];
|
|
28
|
+
/**
|
|
29
|
+
* The release of `files`, each hashed and, with `signingKey`, signed once here. Its manifest is served as a file of
|
|
30
|
+
* its own, so a file of the app may not have the manifest's name.
|
|
31
|
+
*/
|
|
32
|
+
export declare const composeRelease: (files: ReleaseFile[], signingKey?: KeyObject) => MobileRelease;
|
|
33
|
+
//#endregion
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { releaseManifestFile } from "@protobase/schema/internal";
|
|
2
|
+
import { createHash, createPublicKey, sign } from "node:crypto";
|
|
3
|
+
//#region src/mobile-release/release.ts
|
|
4
|
+
const sha256 = (content) => createHash("sha256").update(content).digest("hex");
|
|
5
|
+
/** The updater's manifest of `files`: each one's `href`, sha256 in hex and size, in the order of their hrefs. */
|
|
6
|
+
const releaseManifest = (files) => [...files].sort((a, b) => a.href < b.href ? -1 : a.href > b.href ? 1 : 0).map(({ href, content }) => ({
|
|
7
|
+
href,
|
|
8
|
+
checksum: sha256(content),
|
|
9
|
+
sizeInBytes: content.byteLength
|
|
10
|
+
}));
|
|
11
|
+
const signature = (content, key) => sign("sha256", content, key).toString("base64");
|
|
12
|
+
const signer = (signingKey) => signingKey ? createPublicKey(signingKey).export({
|
|
13
|
+
type: "spki",
|
|
14
|
+
format: "der"
|
|
15
|
+
}) : /* @__PURE__ */ new Uint8Array();
|
|
16
|
+
/**
|
|
17
|
+
* The release of `files`, each hashed and, with `signingKey`, signed once here. Its manifest is served as a file of
|
|
18
|
+
* its own, so a file of the app may not have the manifest's name.
|
|
19
|
+
*/
|
|
20
|
+
const composeRelease = (files, signingKey) => {
|
|
21
|
+
if (files.some((file) => file.href === releaseManifestFile)) throw new Error(`The app's files have a ${releaseManifestFile}, the name of the updater's manifest: rename it`);
|
|
22
|
+
const manifest = new TextEncoder().encode(JSON.stringify(releaseManifest(files)));
|
|
23
|
+
const served = (content) => ({
|
|
24
|
+
content,
|
|
25
|
+
checksum: sha256(content),
|
|
26
|
+
...signingKey && { signature: signature(content, signingKey) }
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
bundleId: createHash("sha256").update(manifest).update(signer(signingKey)).digest("hex").slice(0, 16),
|
|
30
|
+
files: new Map([...files.map(({ href, content }) => [href, served(content)]), [releaseManifestFile, served(manifest)]])
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { composeRelease, releaseManifest };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/mobile-release/shell-update.ts
|
|
2
|
+
const versionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
3
|
+
const parseVersion = (value) => {
|
|
4
|
+
const match = versionPattern.exec(value);
|
|
5
|
+
return match ? {
|
|
6
|
+
major: Number(match[1]),
|
|
7
|
+
minor: Number(match[2])
|
|
8
|
+
} : void 0;
|
|
9
|
+
};
|
|
10
|
+
/** Whether `value` is an x.y.z version, as a shell's Protobase version is. */
|
|
11
|
+
const isShellVersion = (value) => parseVersion(value) !== void 0;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a device running a shell of Protobase `shell` must update before it goes on: its shell no longer works with
|
|
14
|
+
* the API of a server of Protobase `server`. It works on the same major, and below 1.0, where a minor may break, on the
|
|
15
|
+
* same minor, as a bundle does on a runtime.
|
|
16
|
+
*/
|
|
17
|
+
const shellUpdateRequired = (shell, server) => {
|
|
18
|
+
const own = parseVersion(server);
|
|
19
|
+
if (!own) throw new Error(`The server's own Protobase version ${JSON.stringify(server)} is no x.y.z version`);
|
|
20
|
+
const running = parseVersion(shell);
|
|
21
|
+
if (!running) throw new Error(`The shell's Protobase version ${JSON.stringify(shell)} is no x.y.z version`);
|
|
22
|
+
return running.major !== own.major || own.major === 0 && running.minor !== own.minor;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { isShellVersion, shellUpdateRequired };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { KeyObject } from "node:crypto";
|
|
2
|
+
//#region src/mobile-release/signing-key.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The environment variable holding the RSA private key, PEM, that signs every file of the mobile release, for an app
|
|
5
|
+
* whose updater has the matching public key. The key is whoever deploys the app's: the signature guards the way from
|
|
6
|
+
* the server to the device (proxies, a CDN, a router), not a server that is broken into.
|
|
7
|
+
*/
|
|
8
|
+
export declare const mobileSigningKeyVariable = "PROTOBASE_MOBILE_SIGNING_KEY";
|
|
9
|
+
/**
|
|
10
|
+
* The signing key in `PROTOBASE_MOBILE_SIGNING_KEY`, `undefined` when it is unset. Its newlines may be written `\n`, as
|
|
11
|
+
* in an env file that holds one line per value. A key that is not PEM, not RSA or under 2048 bits stops startup.
|
|
12
|
+
*/
|
|
13
|
+
export declare const readSigningKey: (env: Record<string, string | undefined>) => KeyObject | undefined;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createPrivateKey } from "node:crypto";
|
|
2
|
+
//#region src/mobile-release/signing-key.ts
|
|
3
|
+
/**
|
|
4
|
+
* The environment variable holding the RSA private key, PEM, that signs every file of the mobile release, for an app
|
|
5
|
+
* whose updater has the matching public key. The key is whoever deploys the app's: the signature guards the way from
|
|
6
|
+
* the server to the device (proxies, a CDN, a router), not a server that is broken into.
|
|
7
|
+
*/
|
|
8
|
+
const mobileSigningKeyVariable = "PROTOBASE_MOBILE_SIGNING_KEY";
|
|
9
|
+
const minimumBits = 2048;
|
|
10
|
+
/**
|
|
11
|
+
* The signing key in `PROTOBASE_MOBILE_SIGNING_KEY`, `undefined` when it is unset. Its newlines may be written `\n`, as
|
|
12
|
+
* in an env file that holds one line per value. A key that is not PEM, not RSA or under 2048 bits stops startup.
|
|
13
|
+
*/
|
|
14
|
+
const readSigningKey = (env) => {
|
|
15
|
+
const value = env[mobileSigningKeyVariable]?.trim();
|
|
16
|
+
if (!value) return void 0;
|
|
17
|
+
const key = parsePrivateKey(value.replace(/\\n/g, "\n"));
|
|
18
|
+
if (key.asymmetricKeyType !== "rsa") throw new Error(`${mobileSigningKeyVariable} must be an RSA private key, which the app's updater verifies, not ${key.asymmetricKeyType ?? "another kind of key"}`);
|
|
19
|
+
const bits = key.asymmetricKeyDetails?.modulusLength ?? 0;
|
|
20
|
+
if (bits < minimumBits) throw new Error(`${mobileSigningKeyVariable} must be an RSA key of at least ${minimumBits} bits, not ${bits}`);
|
|
21
|
+
return key;
|
|
22
|
+
};
|
|
23
|
+
const parsePrivateKey = (pem) => {
|
|
24
|
+
try {
|
|
25
|
+
return createPrivateKey(pem);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error && String(error.code).startsWith("ERR_OSSL_")) throw new Error(`${mobileSigningKeyVariable} is no PEM private key: give the whole key, from -----BEGIN PRIVATE KEY----- to its END line`);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { mobileSigningKeyVariable, readSigningKey };
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
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": {
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@better-auth/passkey": "^1.7.12",
|
|
37
37
|
"@better-auth/sso": "^1.7.12",
|
|
38
38
|
"@modelcontextprotocol/server": "^2.3.1",
|
|
39
|
-
"@protobase/layout": "0.
|
|
40
|
-
"@protobase/query": "0.
|
|
41
|
-
"@protobase/schema": "0.
|
|
39
|
+
"@protobase/layout": "0.41.0",
|
|
40
|
+
"@protobase/query": "0.41.0",
|
|
41
|
+
"@protobase/schema": "0.41.0",
|
|
42
42
|
"@react-email/render": "^2.1.0",
|
|
43
43
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
44
44
|
"@sentry/core": "^11.7.0",
|