@vllnt/convex-helpers 0.2.0 → 0.2.1-canary.2ee4768
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/CHANGELOG.md +64 -5
- package/NOTICE +3 -3
- package/README.md +382 -260
- package/dist/better-auth.d.ts +10 -0
- package/dist/better-auth.d.ts.map +1 -1
- package/dist/better-auth.js +9 -0
- package/dist/better-auth.js.map +1 -1
- package/dist/builders.d.ts +5 -4
- package/dist/builders.d.ts.map +1 -1
- package/dist/builders.js +5 -4
- package/dist/builders.js.map +1 -1
- package/dist/identity.d.ts +25 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +23 -0
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/pagination/types.d.ts +2 -0
- package/dist/mcp/pagination/types.d.ts.map +1 -1
- package/dist/mcp/resources/helpers.d.ts +8 -0
- package/dist/mcp/resources/helpers.d.ts.map +1 -1
- package/dist/mcp/resources/helpers.js +8 -0
- package/dist/mcp/resources/helpers.js.map +1 -1
- package/dist/mcp/resources/types.d.ts +1 -0
- package/dist/mcp/resources/types.d.ts.map +1 -1
- package/dist/mcp/server.d.ts +10 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +10 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/helpers.d.ts +21 -0
- package/dist/mcp/tools/helpers.d.ts.map +1 -1
- package/dist/mcp/tools/helpers.js +21 -0
- package/dist/mcp/tools/helpers.js.map +1 -1
- package/dist/mcp/tools/types.d.ts +13 -3
- package/dist/mcp/tools/types.d.ts.map +1 -1
- package/dist/mcp/types.d.ts +8 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/validators.d.ts +18 -0
- package/dist/mcp/validators.d.ts.map +1 -1
- package/dist/mcp/validators.js +18 -0
- package/dist/mcp/validators.js.map +1 -1
- package/dist/validators.d.ts +6 -7
- package/dist/validators.d.ts.map +1 -1
- package/dist/validators.js +11 -7
- package/dist/validators.js.map +1 -1
- package/docs/API.md +155 -81
- package/llms.txt +75 -39
- package/package.json +20 -18
- package/src/better-auth.ts +10 -0
- package/src/builders.ts +5 -4
- package/src/identity.ts +25 -0
- package/src/index.ts +2 -0
- package/src/mcp/pagination/types.ts +2 -0
- package/src/mcp/resources/helpers.ts +8 -0
- package/src/mcp/resources/types.ts +1 -0
- package/src/mcp/server.ts +10 -0
- package/src/mcp/tools/helpers.ts +21 -0
- package/src/mcp/tools/types.ts +13 -3
- package/src/mcp/types.ts +8 -0
- package/src/mcp/validators.ts +18 -0
- package/src/validators.ts +10 -7
- package/docs/READINESS.md +0 -175
package/src/better-auth.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Does not import better-auth — the host still constructs `betterAuth(...)`.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/** Better Auth options returned by `cookieSettingsForSite` for an HTTPS site. */
|
|
6
7
|
export type CookieSettings = {
|
|
7
8
|
advanced: {
|
|
8
9
|
defaultCookieAttributes: {
|
|
@@ -122,6 +123,15 @@ export function trustedOriginsFromList(
|
|
|
122
123
|
return [site, ...parsed];
|
|
123
124
|
}
|
|
124
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Same as `trustedOriginsFromList`, with the extra origins as one
|
|
128
|
+
* comma-separated string.
|
|
129
|
+
*
|
|
130
|
+
* @param siteUrl - The deployment site URL
|
|
131
|
+
* @param csv - Comma-separated extra origins
|
|
132
|
+
* @param options - `previewPattern`, an exact HTTPS wildcard pattern
|
|
133
|
+
* @returns The origins, or `undefined` when no extra origin parses
|
|
134
|
+
*/
|
|
125
135
|
export function trustedOriginsFromCsv(
|
|
126
136
|
siteUrl: string,
|
|
127
137
|
csv: string,
|
package/src/builders.ts
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
* with them gets extra `ctx` fields (and optionally consumes extra args), e.g.
|
|
5
5
|
* an authenticated user resolved once in a shared `input`.
|
|
6
6
|
*
|
|
7
|
-
* Adapted, with changes, from `convex-helpers/server/customFunctions` 0.1.
|
|
7
|
+
* Adapted, with changes, from `convex-helpers/server/customFunctions` 0.1.136
|
|
8
8
|
* (Apache-2.0, see NOTICE): same signatures and runtime behaviour for
|
|
9
9
|
* `customQuery`, `customMutation`, `customAction` and `customCtx`; the
|
|
10
|
-
* `CustomBuilder`, `Customization` and `Registration` types
|
|
10
|
+
* `CustomBuilder`, `CustomCtx`, `Customization` and `Registration` types
|
|
11
|
+
* follow upstream's.
|
|
11
12
|
* Unlike upstream, a customization must supply both `args` and `input` (the
|
|
12
|
-
* types already require them).
|
|
13
|
-
*
|
|
13
|
+
* types already require them). The repository's parity tests run both side
|
|
14
|
+
* by side.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import type {
|
package/src/identity.ts
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import { ConvexError } from "convex/values";
|
|
7
7
|
|
|
8
|
+
/** The identity fields these helpers read from `ctx.auth.getUserIdentity()`. */
|
|
8
9
|
export type AuthIdentity = {
|
|
9
10
|
isAnonymous?: unknown;
|
|
10
11
|
issuer?: string;
|
|
11
12
|
subject: string;
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
/** The context these helpers take: the host `ctx.auth` plus its trusted issuer. */
|
|
14
16
|
export type AuthCtx = {
|
|
15
17
|
auth: {
|
|
16
18
|
getUserIdentity: () => Promise<AuthIdentity | null>;
|
|
@@ -24,6 +26,12 @@ export type AuthCtx = {
|
|
|
24
26
|
trustedIssuer: string;
|
|
25
27
|
};
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Tells whether an identity carries a literal `isAnonymous: true` claim.
|
|
31
|
+
*
|
|
32
|
+
* @param identity - An identity from `ctx.auth.getUserIdentity()`
|
|
33
|
+
* @returns `true` when the claim is the boolean `true`; `false` proves nothing
|
|
34
|
+
*/
|
|
27
35
|
export function isAnonymousIdentity(identity: AuthIdentity): boolean {
|
|
28
36
|
return identity.isAnonymous === true;
|
|
29
37
|
}
|
|
@@ -47,6 +55,14 @@ function assertTrustedIssuer(ctx: AuthCtx, identity: AuthIdentity): void {
|
|
|
47
55
|
}
|
|
48
56
|
}
|
|
49
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Returns the signed-in identity from the trusted issuer.
|
|
60
|
+
*
|
|
61
|
+
* @param ctx - `{ auth: ctx.auth, trustedIssuer }`
|
|
62
|
+
* @returns The identity
|
|
63
|
+
* @throws {ConvexError} `UNAUTHENTICATED` when signed out, when
|
|
64
|
+
* `trustedIssuer` is unset or empty, or when the issuer differs
|
|
65
|
+
*/
|
|
50
66
|
export async function requireIdentity(ctx: AuthCtx): Promise<AuthIdentity> {
|
|
51
67
|
assertTrustedIssuerConfigured(ctx);
|
|
52
68
|
const identity = await ctx.auth.getUserIdentity();
|
|
@@ -77,6 +93,15 @@ export async function getFromAuth<T extends object>(
|
|
|
77
93
|
return { ...row, isAnonymous: isAnonymousIdentity(identity) };
|
|
78
94
|
}
|
|
79
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Like `getFromAuth`, but throws instead of returning `null`.
|
|
98
|
+
*
|
|
99
|
+
* @param ctx - `{ auth: ctx.auth, trustedIssuer }`
|
|
100
|
+
* @param lookup - Finds the host row for a subject
|
|
101
|
+
* @returns The row plus `isAnonymous`
|
|
102
|
+
* @throws {ConvexError} `USER_NOT_INITIALIZED` when signed out or the row
|
|
103
|
+
* does not exist; `UNAUTHENTICATED` for an issuer problem
|
|
104
|
+
*/
|
|
80
105
|
export async function requireFromAuth<T extends object>(
|
|
81
106
|
ctx: AuthCtx,
|
|
82
107
|
lookup: (subject: string) => Promise<null | T>,
|
package/src/index.ts
CHANGED
|
@@ -16,11 +16,13 @@ export type PaginationConfig = {
|
|
|
16
16
|
twoPhaseDiscovery?: boolean;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
/** Name and description of one tool, as returned by `tools/list_summary`. */
|
|
19
20
|
export type ToolSummary = {
|
|
20
21
|
description: string;
|
|
21
22
|
name: string;
|
|
22
23
|
};
|
|
23
24
|
|
|
25
|
+
/** One page of a paginated tool list; `nextCursor` is set while more pages remain. */
|
|
24
26
|
export type ToolPage<T extends object> = {
|
|
25
27
|
nextCursor?: string;
|
|
26
28
|
tools: T[];
|
|
@@ -7,6 +7,14 @@ type ResourceOptions = {
|
|
|
7
7
|
description?: string;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Exposes a Convex query as an MCP resource. Resources run no lifecycle hooks:
|
|
12
|
+
* authorize inside the query.
|
|
13
|
+
*
|
|
14
|
+
* @param ref - Convex query reference
|
|
15
|
+
* @param options - `args` validator for URI parameters, `description`
|
|
16
|
+
* @returns The resource definition to put in `ServerConfig.resources`
|
|
17
|
+
*/
|
|
10
18
|
export function resource(
|
|
11
19
|
ref: unknown,
|
|
12
20
|
options: ResourceOptions = {},
|
package/src/mcp/server.ts
CHANGED
|
@@ -34,6 +34,16 @@ function addRequestId(response: Response, requestId: string): Response {
|
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Builds an MCP server (Streamable HTTP) that exposes Convex functions as tools
|
|
39
|
+
* and resources.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Auth is required; see `ServerConfig`
|
|
42
|
+
* @returns `{ handler() }`, whose `GET` and `POST` take a Web `Request`
|
|
43
|
+
* @throws {Error} Without `auth.validate`, with both `client` and
|
|
44
|
+
* `auth.convexToken`, without a Convex URL, with an invalid tool timeout
|
|
45
|
+
* or pagination page size, or when tool/resource `args` cannot be converted
|
|
46
|
+
*/
|
|
37
47
|
export function createMCPServer(config: ServerConfig): ConvexMCPServer {
|
|
38
48
|
if (!config.auth?.validate) {
|
|
39
49
|
throw new Error(
|
package/src/mcp/tools/helpers.ts
CHANGED
|
@@ -10,6 +10,13 @@ type ToolOptions = {
|
|
|
10
10
|
timeout?: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Exposes a Convex query as an MCP tool.
|
|
15
|
+
*
|
|
16
|
+
* @param ref - Convex function reference, e.g. `api.tasks.list`
|
|
17
|
+
* @param options - `args` validator, `description`, `tags`, `timeout` (ms), `onError`
|
|
18
|
+
* @returns The tool definition to put in `ServerConfig.tools`
|
|
19
|
+
*/
|
|
13
20
|
export function query(ref: unknown, options: ToolOptions = {}): ToolDef {
|
|
14
21
|
return {
|
|
15
22
|
args: options.args,
|
|
@@ -22,6 +29,13 @@ export function query(ref: unknown, options: ToolOptions = {}): ToolDef {
|
|
|
22
29
|
};
|
|
23
30
|
}
|
|
24
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Exposes a Convex mutation as an MCP tool. Setting `timeout` throws at server creation.
|
|
34
|
+
*
|
|
35
|
+
* @param ref - Convex function reference, e.g. `api.tasks.create`
|
|
36
|
+
* @param options - `args` validator, `description`, `tags`, `onError`
|
|
37
|
+
* @returns The tool definition to put in `ServerConfig.tools`
|
|
38
|
+
*/
|
|
25
39
|
export function mutation(ref: unknown, options: ToolOptions = {}): ToolDef {
|
|
26
40
|
return {
|
|
27
41
|
args: options.args,
|
|
@@ -34,6 +48,13 @@ export function mutation(ref: unknown, options: ToolOptions = {}): ToolDef {
|
|
|
34
48
|
};
|
|
35
49
|
}
|
|
36
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Exposes a Convex action as an MCP tool. Setting `timeout` throws at server creation.
|
|
53
|
+
*
|
|
54
|
+
* @param ref - Convex function reference, e.g. `api.tasks.sync`
|
|
55
|
+
* @param options - `args` validator, `description`, `tags`, `onError`
|
|
56
|
+
* @returns The tool definition to put in `ServerConfig.tools`
|
|
57
|
+
*/
|
|
37
58
|
export function action(ref: unknown, options: ToolOptions = {}): ToolDef {
|
|
38
59
|
return {
|
|
39
60
|
args: options.args,
|
package/src/mcp/tools/types.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ConvexValidator } from "../types.js";
|
|
2
2
|
|
|
3
|
+
/** Kind of Convex function a tool calls. */
|
|
3
4
|
export type FunctionType = "action" | "mutation" | "query";
|
|
4
5
|
|
|
5
6
|
export type HookResult = OnCallResult | undefined;
|
|
6
7
|
export type HookReturn = HookResult | Promise<HookResult> | Promise<void>;
|
|
7
8
|
|
|
9
|
+
/** A Convex function exposed as an MCP tool; build it with `query()`, `mutation()` or `action()`. */
|
|
8
10
|
export type ToolDef = {
|
|
9
11
|
args?: ConvexValidator;
|
|
10
12
|
description?: string;
|
|
@@ -15,6 +17,7 @@ export type ToolDef = {
|
|
|
15
17
|
type: FunctionType;
|
|
16
18
|
};
|
|
17
19
|
|
|
20
|
+
/** What lifecycle hooks receive for one tool call, in the `before`, `success` or `error` phase. */
|
|
18
21
|
export type CallContext = {
|
|
19
22
|
/**
|
|
20
23
|
* Raw bearer credential. Sensitive: use it only to validate the caller, and
|
|
@@ -33,6 +36,7 @@ export type CallContext = {
|
|
|
33
36
|
toolName: string;
|
|
34
37
|
};
|
|
35
38
|
|
|
39
|
+
/** What a lifecycle hook may return: abort the call, inject server-side args, or set the public error message. */
|
|
36
40
|
export type OnCallResult = {
|
|
37
41
|
/** Set true to abort execution. Only checked during "before" phase. */
|
|
38
42
|
abort?: boolean;
|
|
@@ -46,9 +50,10 @@ export type OnCallResult = {
|
|
|
46
50
|
* (server-side wins).
|
|
47
51
|
*
|
|
48
52
|
* Convention: keys MUST use the framework-reserved underscore prefix
|
|
49
|
-
* (e.g., `_mcp_principal`, `_request_id`). Request args
|
|
50
|
-
* keys
|
|
51
|
-
*
|
|
53
|
+
* (e.g., `_mcp_principal`, `_request_id`). Request args never carry
|
|
54
|
+
* `_`-prefixed keys to the hook: the MCP SDK drops undeclared args and the
|
|
55
|
+
* handler rejects any that remain, so this prefix is safe for server-side
|
|
56
|
+
* context injection (auth, tracing, multi-tenancy, audit, etc.).
|
|
52
57
|
*
|
|
53
58
|
* Empty objects and undefined are no-ops (no allocation, no merge).
|
|
54
59
|
*
|
|
@@ -75,6 +80,11 @@ export type OnCallResult = {
|
|
|
75
80
|
message?: string;
|
|
76
81
|
};
|
|
77
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Server-wide hooks; `onToolCall` runs before each tool call and after it
|
|
85
|
+
* succeeds or fails. When a tool sets `onError`, only `onError` runs in the
|
|
86
|
+
* error phase, not `onToolCall`.
|
|
87
|
+
*/
|
|
78
88
|
export type LifecycleHooks = {
|
|
79
89
|
onToolCall?: (ctx: CallContext) => HookReturn;
|
|
80
90
|
};
|
package/src/mcp/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Structural shape of a Convex validator (`v.*`) as read by the MCP schema conversion. */
|
|
1
2
|
export type ConvexValidator = {
|
|
2
3
|
element?: ConvexValidator;
|
|
3
4
|
fields?: Record<string, ConvexValidator>;
|
|
@@ -24,6 +25,11 @@ export type ConvexClient = {
|
|
|
24
25
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Bearer-key authentication for the MCP endpoint. `validate` gates every
|
|
30
|
+
* request (default deny); optional `convexToken` returns a Convex auth token
|
|
31
|
+
* for the key, used for each Convex call.
|
|
32
|
+
*/
|
|
27
33
|
export type AuthConfig = {
|
|
28
34
|
convexToken?: (
|
|
29
35
|
apiKey: string,
|
|
@@ -37,6 +43,7 @@ import type { LifecycleHooks, ToolDef } from "./tools/types.js";
|
|
|
37
43
|
|
|
38
44
|
export type { PaginationConfig, ResourceDef, ToolDef };
|
|
39
45
|
|
|
46
|
+
/** Options for `createMCPServer`: auth (required), tools, resources, Convex target, hooks and pagination. */
|
|
40
47
|
export type ServerConfig = {
|
|
41
48
|
auth: AuthConfig;
|
|
42
49
|
client?: ConvexClient;
|
|
@@ -49,6 +56,7 @@ export type ServerConfig = {
|
|
|
49
56
|
version?: string;
|
|
50
57
|
};
|
|
51
58
|
|
|
59
|
+
/** The value `createMCPServer` returns; `handler()` gives the `GET` and `POST` Web request handlers. */
|
|
52
60
|
export type ConvexMCPServer = {
|
|
53
61
|
handler: () => {
|
|
54
62
|
GET: (request: Request) => Promise<Response>;
|
package/src/mcp/validators.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
|
|
3
3
|
import type { ConvexValidator } from "./types.js";
|
|
4
4
|
|
|
5
|
+
/** Thrown when a Convex validator kind has no MCP (zod/JSON Schema) mapping. */
|
|
5
6
|
export class UnsupportedValidatorError extends Error {
|
|
6
7
|
constructor(kind: string) {
|
|
7
8
|
super(
|
|
@@ -171,6 +172,14 @@ function convertKind(validator: ConvexValidator): z.ZodTypeAny {
|
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Converts one Convex validator to a zod schema.
|
|
177
|
+
*
|
|
178
|
+
* @param validator - A Convex validator (`v.*`)
|
|
179
|
+
* @returns The matching zod schema; it is optional when the validator is
|
|
180
|
+
* optional
|
|
181
|
+
* @throws {UnsupportedValidatorError} For kinds with no mapping
|
|
182
|
+
*/
|
|
174
183
|
export function convertValidator(validator: ConvexValidator): z.ZodTypeAny {
|
|
175
184
|
const base = convertKind(validator);
|
|
176
185
|
if (validator.isOptional === "optional") {
|
|
@@ -179,6 +188,15 @@ export function convertValidator(validator: ConvexValidator): z.ZodTypeAny {
|
|
|
179
188
|
return base;
|
|
180
189
|
}
|
|
181
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Converts a `v.object()` args validator to a zod object schema.
|
|
193
|
+
*
|
|
194
|
+
* @param argumentsValidator - The function's `v.object({...})` args validator
|
|
195
|
+
* @returns A zod object schema
|
|
196
|
+
* @throws {Error} When the validator is not a `v.object()`
|
|
197
|
+
* @throws {UnsupportedValidatorError} When a field's validator kind has no
|
|
198
|
+
* mapping
|
|
199
|
+
*/
|
|
182
200
|
export function convexArgsToZod(
|
|
183
201
|
argumentsValidator: ConvexValidator,
|
|
184
202
|
): z.ZodObject<Record<string, z.ZodTypeAny>> {
|
package/src/validators.ts
CHANGED
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
* Runtime checks against Convex validators, and whole-document validators
|
|
4
4
|
* for schema tables.
|
|
5
5
|
*
|
|
6
|
-
* Adapted, with changes, from `convex-helpers/validators` 0.1.
|
|
7
|
-
* (Apache-2.0, see NOTICE): same behaviour for these functions, which
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* supporting it. The `AddFieldsToValidator` type follows upstream's.
|
|
6
|
+
* Adapted, with changes, from `convex-helpers/validators` 0.1.136
|
|
7
|
+
* (Apache-2.0, see NOTICE): same behaviour for these functions, which the
|
|
8
|
+
* repository's parity tests check side by side, plus one fail-closed
|
|
9
|
+
* difference: the runtime check throws on the `db` option, which checks a
|
|
10
|
+
* `v.id`'s table, instead of supporting it. The `AddFieldsToValidator` type
|
|
11
|
+
* follows upstream's.
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
import type {
|
|
@@ -220,6 +219,10 @@ const checkUnion: Checker<"union"> = (validator, value, walk) => {
|
|
|
220
219
|
const checkRecord: Checker<"record"> = (validator, value, walk) => {
|
|
221
220
|
if (typeof value !== "object" || value === null)
|
|
222
221
|
return { expected: "record" };
|
|
222
|
+
// Arrays and class instances (Date, Map, ...) are not records, as in Convex.
|
|
223
|
+
// For a record, the non-plain object's constructor name is what it got.
|
|
224
|
+
const notPlain = plainObjectFailure(value);
|
|
225
|
+
if (notPlain) return { expected: "record", got: notPlain.expected };
|
|
223
226
|
const keyValidator: AnyValidator = validator.key;
|
|
224
227
|
const entryValidator: AnyValidator = validator.value;
|
|
225
228
|
return firstFailure(Object.entries(value), ([key, entry]) => {
|
package/docs/READINESS.md
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# Publication remediation evidence
|
|
2
|
-
|
|
3
|
-
Status: **not publication-ready**: an independent review is done (2026-10-31, no
|
|
4
|
-
critical or high findings) and its fixes are applied, and the real Better Auth
|
|
5
|
-
login/JWT proof now passes locally (2026-11-03, see below). Publication still
|
|
6
|
-
needs the maintainer's release decision.
|
|
7
|
-
|
|
8
|
-
## Repairs and checks
|
|
9
|
-
|
|
10
|
-
- Origin preview allowlisting no longer bypasses scheme/credential/path
|
|
11
|
-
validation. Wildcards require an exact explicitly configured HTTPS pattern
|
|
12
|
-
with a single prefixed/suffixed wildcard label and fixed DNS suffix. Host
|
|
13
|
-
deployment ownership remains a prerequisite.
|
|
14
|
-
- Local HTTP rejects paths and URL normalization; controls reject before
|
|
15
|
-
trimming.
|
|
16
|
-
- Cookies require a validated HTTPS origin. SameSite=None remains opt-in host
|
|
17
|
-
policy.
|
|
18
|
-
- Retarget callbacks execute sequentially, stop on error and reject pages over
|
|
19
|
-
1000 before side effects. Host authorization and transaction boundaries remain
|
|
20
|
-
mandatory.
|
|
21
|
-
- MCP before-hook throws/timeouts deny dispatch generically. Auth and lifecycle
|
|
22
|
-
callbacks have 10-second deadlines; underlying host work is not cancelled.
|
|
23
|
-
- Raw tool/resource errors and attacker-controlled reserved keys are not logged.
|
|
24
|
-
Host hooks own observability/redaction; explicit hook-returned messages are
|
|
25
|
-
public.
|
|
26
|
-
- `AuthCtx.trustedIssuer` is required; missing/empty configuration and
|
|
27
|
-
mismatched issuer claims fail closed before row callbacks.
|
|
28
|
-
- README/API/llms describe actual shipped surfaces and conditional bootstrap
|
|
29
|
-
safety.
|
|
30
|
-
- Release notes are passed via a file, not interpolated shell source. Stable
|
|
31
|
-
release runs only from a `vX.Y.Z` tag on main that matches `package.json` and
|
|
32
|
-
`CHANGELOG.md`; default workflow permissions are read-only.
|
|
33
|
-
|
|
34
|
-
Commands executed from this repository:
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
pnpm install --frozen-lockfile
|
|
38
|
-
pnpm lint
|
|
39
|
-
pnpm build
|
|
40
|
-
pnpm typecheck
|
|
41
|
-
pnpm test:coverage
|
|
42
|
-
pnpm audit --json
|
|
43
|
-
pnpm audit --prod --json
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
Coverage at the remediation checkpoint: 204 tests (including a real-clock policy
|
|
47
|
-
timeout), 100% statements, branches, functions and lines. Strict lint now
|
|
48
|
-
includes identity integration tests and schema; legacy MCP integration fixtures
|
|
49
|
-
remain excluded, explicitly rather than all tests. Typechecks now include host
|
|
50
|
-
wrappers. Packed runtime imports of all four entries passed, and packed API
|
|
51
|
-
TypeScript checks passed using
|
|
52
|
-
`tsc --ignoreConfig --noEmit --strict --skipLibCheck --module NodeNext --target ES2022`
|
|
53
|
-
against the installed local tarball. No publish command was executed.
|
|
54
|
-
|
|
55
|
-
## Independent review (2026-10-31)
|
|
56
|
-
|
|
57
|
-
A read-only source review found no critical or high issues. Outcome:
|
|
58
|
-
|
|
59
|
-
| Finding | Result |
|
|
60
|
-
| ------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
61
|
-
| Subject-only lookups share a row across issuers (medium) | Fixed: `trustedIssuer` required, fail closed. Regression tests in `identity.e2e.test.ts`. |
|
|
62
|
-
| Optional `trustedIssuer` accepts any issuer (medium) | Fixed with the above. |
|
|
63
|
-
| Resources skip `onToolCall`/`before` hooks (medium) | Documented; an `onResourceRead` hook would be a future minor. |
|
|
64
|
-
| `timeout: 0` means no timeout (low) | Documented, unchanged. |
|
|
65
|
-
| Example injects the raw bearer into args (low) | Fixed: example injects a derived principal; `apiKey` documented as sensitive. |
|
|
66
|
-
| Resources accept `_`-prefixed params (low) | Fixed: rejected before dispatch. Regression test in `server.test.ts`. |
|
|
67
|
-
| No body, stream or deadline caps (low) | Documented as a host/platform duty. |
|
|
68
|
-
| Preview wildcard depends on Better Auth matcher (plausible) | Checked in Better Auth 1.7.12 source: `*` can span `.`. Documented; pattern shape tested. |
|
|
69
|
-
| SameSite=None, cursor secret, no Origin check, Bearer case, `isAnonymous`, `retargetRows` outcome (low) | Documented; no behavior change. |
|
|
70
|
-
|
|
71
|
-
Review limits: source reading only. Real login/JWT behavior was not exercised.
|
|
72
|
-
|
|
73
|
-
## Dependency reachability
|
|
74
|
-
|
|
75
|
-
Development-only advisories (Handlebars, esbuild, deepmerge-ts) are fixed with
|
|
76
|
-
scoped overrides in `package.json` (`handlebars@<4.7.10`,
|
|
77
|
-
`deepmerge-ts@<8.0.0`); other overrides were dropped once the lockfile resolved
|
|
78
|
-
the same versions without them.
|
|
79
|
-
|
|
80
|
-
Remaining: `minimatch` (3.x and 10.x, moderate,
|
|
81
|
-
[GHSA-g3hv-75wg-m249](https://github.com/advisories/GHSA-g3hv-75wg-m249)),
|
|
82
|
-
reached only through `@vllnt/eslint-config` lint tooling. The fix is minimatch
|
|
83
|
-
11, a major outside those packages' ranges, so no override is applied. Not
|
|
84
|
-
imported by package runtime. `pnpm audit --prod` reports zero advisories; this
|
|
85
|
-
is not proof for a host's independently installed optional peers. Convex CLI's
|
|
86
|
-
esbuild 0.27.0 is outside the reported vulnerable range (>=0.27.3 <0.28.1).
|
|
87
|
-
|
|
88
|
-
## Unverified conditions
|
|
89
|
-
|
|
90
|
-
- The Better Auth proof covers only the cases listed under its section below.
|
|
91
|
-
Not exercised: HTTPS cookies (`cookieSettingsForSite`), preview-pattern
|
|
92
|
-
origins, anonymous-to-registered account linking with `retargetRows`, social
|
|
93
|
-
or other plugins, and Better Auth 1.7.x (the component's peer range is
|
|
94
|
-
`<1.7.0`).
|
|
95
|
-
- No publishing, merging, tagging, visibility changes or production access
|
|
96
|
-
performed.
|
|
97
|
-
|
|
98
|
-
## Real local backend proof
|
|
99
|
-
|
|
100
|
-
Executed
|
|
101
|
-
`HOME=$(mktemp -d /tmp/helpers-home.XXXXXX) CONVEX_AGENT_MODE=anonymous node scripts/local-identity-proof.mjs`
|
|
102
|
-
through a managed process with declared 3340/3341 ports. Convex CLI 1.45.0
|
|
103
|
-
configured an anonymous local backend, created CLI-owned bindings in a temporary
|
|
104
|
-
fixture, deployed the indexed mutation and ran 16 simultaneous HTTP mutations.
|
|
105
|
-
All returned the same row ID; a separate query found exactly one row. Exit
|
|
106
|
-
status 0. No cloud account, production deployment or hand-edited generated
|
|
107
|
-
files. Identity injection was synthetic and cannot prove Better Auth login or
|
|
108
|
-
JWT integration. The retained script reproduces this evidence. Stable publishing
|
|
109
|
-
is tag-driven and uses reviewed current versions only.
|
|
110
|
-
|
|
111
|
-
## Real Better Auth login/JWT proof
|
|
112
|
-
|
|
113
|
-
Executed on 2026-11-03:
|
|
114
|
-
|
|
115
|
-
```sh
|
|
116
|
-
node scripts/better-auth-proof.mjs
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
Result: `RESULT: PASS`, 13 assertions, exit status 0, about one minute. The
|
|
120
|
-
script builds a throwaway fixture under `/var/tmp`, installs its dependencies
|
|
121
|
-
there with `npm install --ignore-scripts --before <now - 7 days>` (nothing is
|
|
122
|
-
added to this package), starts an anonymous local Convex backend on ports
|
|
123
|
-
3350/3351 with an isolated `HOME`, generates `BETTER_AUTH_SECRET` randomly and
|
|
124
|
-
passes it over stdin, then deletes the fixture, `HOME` and backend process. No
|
|
125
|
-
cloud account, production deployment or hand-edited generated files. Rerunning
|
|
126
|
-
needs the network for npm and for the local backend download.
|
|
127
|
-
|
|
128
|
-
Pinned local backend: `precompiled-2026-10-22-1447815` (published 2026-10-22),
|
|
129
|
-
selected with the Convex CLI's `convex dev --local-backend-version` flag; the
|
|
130
|
-
script prints `Local backend: <version>`. The CLI's default is a moving
|
|
131
|
-
"latest", so the pin is what makes reruns reproducible.
|
|
132
|
-
Child processes inherit the caller's environment (so proxy and custom CA
|
|
133
|
-
settings still apply) minus every `CONVEX_*` variable, plus the script's own
|
|
134
|
-
`HOME`, ports and `CONVEX_AGENT_MODE=anonymous`, so `CONVEX_DEPLOYMENT`, `CONVEX_URL`,
|
|
135
|
-
`CONVEX_DEPLOY_KEY` and other `CONVEX_*` variables from the caller's shell
|
|
136
|
-
cannot redirect it.
|
|
137
|
-
|
|
138
|
-
Versions used: `convex` 1.48.0, `better-auth` 1.6.33, `@convex-dev/better-auth`
|
|
139
|
-
0.12.6, `jose` 6.2.13 (test token forging only), Node 24.22.1. The fixture
|
|
140
|
-
follows the component's documented setup: `app.use(betterAuth)`,
|
|
141
|
-
`getAuthConfigProvider()`,
|
|
142
|
-
`betterAuth({ plugins: [anonymous(), convex({ authConfig })] })` and
|
|
143
|
-
`registerRoutes`. It copies `src/identity.ts` and `src/better-auth.ts` unchanged
|
|
144
|
-
and calls them from Convex functions, with
|
|
145
|
-
`trustedOrigins: trustedOriginsFromCsv(siteUrl, ...)` configured in Better Auth
|
|
146
|
-
and `trustedIssuer` set to the deployment's site URL.
|
|
147
|
-
|
|
148
|
-
Asserted against real Better Auth sessions and tokens:
|
|
149
|
-
|
|
150
|
-
- Anonymous plugin sign-in and a separate email/password sign-in each issue a
|
|
151
|
-
token from `GET /api/auth/convex/token` with `iss` equal to the deployment
|
|
152
|
-
site URL, `aud` `convex` and `sub` equal to the Better Auth user id. The
|
|
153
|
-
anonymous token carries `isAnonymous: true`; the email token's is not `true`.
|
|
154
|
-
- Convex's `ctx.auth.getUserIdentity()` reports the same issuer, subject and
|
|
155
|
-
`isAnonymous` custom claim.
|
|
156
|
-
- `getOrCreateFromAuth` accepts both, inserts one row per subject, is
|
|
157
|
-
idempotent, and reports `isAnonymous` true and false respectively;
|
|
158
|
-
`getFromAuth` returns `null` before bootstrap and the flagged row after.
|
|
159
|
-
- Rejected: no token (`UNAUTHENTICATED`), `trustedIssuer` mismatch on a valid
|
|
160
|
-
token (`UNAUTHENTICATED`, no row written), payload edited with the signature
|
|
161
|
-
kept, foreign issuer signed with a foreign key, correct issuer signed with a
|
|
162
|
-
foreign key, and a real Better Auth token after it expires (valid just before,
|
|
163
|
-
rejected with "expired" later). Convex tolerates a few seconds of clock skew,
|
|
164
|
-
so the script waits 10 seconds past expiry. Queries can be served from the
|
|
165
|
-
backend cache, so the expiry check uses a mutation.
|
|
166
|
-
- Better Auth refuses a sign-in from an origin outside `trustedOrigins` (403)
|
|
167
|
-
and issues no token after sign-out.
|
|
168
|
-
|
|
169
|
-
The proof can fail: with the issuer check in `src/identity.ts` disabled, the
|
|
170
|
-
mismatch assertion fails and the script exits 1. `convex dev --once --start`
|
|
171
|
-
exits 0 even when the started command fails, so the script requires a result
|
|
172
|
-
marker that is written only after all assertions pass.
|
|
173
|
-
|
|
174
|
-
Findings: none. The helpers accepted every real token and rejected every invalid
|
|
175
|
-
one; no change to `src/` was needed.
|