@benchme/site-kit 0.10.0 → 0.12.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/auth-routes.js +5 -2
- package/dist/auth-routes.js.map +1 -1
- package/dist/auth-service.d.ts +9 -1
- package/dist/auth-service.js +14 -3
- package/dist/auth-service.js.map +1 -1
- package/dist/domain-error.d.ts +6 -0
- package/dist/domain-error.js +12 -0
- package/dist/domain-error.js.map +1 -0
- package/dist/doors/bridge-credential.d.ts +47 -0
- package/dist/doors/bridge-credential.js +80 -0
- package/dist/doors/bridge-credential.js.map +1 -0
- package/dist/doors/caller.d.ts +25 -0
- package/dist/doors/caller.js +22 -0
- package/dist/doors/caller.js.map +1 -0
- package/dist/doors/door.d.ts +12 -0
- package/dist/doors/door.js +18 -0
- package/dist/doors/door.js.map +1 -0
- package/dist/doors/register-doors.d.ts +44 -0
- package/dist/doors/register-doors.js +92 -0
- package/dist/doors/register-doors.js.map +1 -0
- package/dist/doors/request-door.d.ts +19 -0
- package/dist/doors/request-door.js +29 -0
- package/dist/doors/request-door.js.map +1 -0
- package/dist/doors/session-carrier.d.ts +42 -0
- package/dist/doors/session-carrier.js +44 -0
- package/dist/doors/session-carrier.js.map +1 -0
- package/dist/doors/sign-in-tools.d.ts +23 -0
- package/dist/doors/sign-in-tools.js +69 -0
- package/dist/doors/sign-in-tools.js.map +1 -0
- package/dist/doors/sign-in.d.ts +20 -0
- package/dist/doors/sign-in.js +31 -0
- package/dist/doors/sign-in.js.map +1 -0
- package/dist/html.d.ts +5 -1
- package/dist/html.js +23 -4
- package/dist/html.js.map +1 -1
- package/dist/index.d.ts +18 -3
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/dist/ledger/auth-rules.d.ts +11 -0
- package/dist/ledger/auth-rules.js +21 -0
- package/dist/ledger/auth-rules.js.map +1 -0
- package/dist/ledger/entry.d.ts +219 -0
- package/dist/ledger/entry.js +40 -0
- package/dist/ledger/entry.js.map +1 -0
- package/dist/ledger/ledger-route.d.ts +15 -0
- package/dist/ledger/ledger-route.js +25 -0
- package/dist/ledger/ledger-route.js.map +1 -0
- package/dist/ledger/ledger.d.ts +38 -0
- package/dist/ledger/ledger.js +55 -0
- package/dist/ledger/ledger.js.map +1 -0
- package/dist/ledger/ledgered.d.ts +36 -0
- package/dist/ledger/ledgered.js +108 -0
- package/dist/ledger/ledgered.js.map +1 -0
- package/dist/ledger/rules.d.ts +45 -0
- package/dist/ledger/rules.js +22 -0
- package/dist/ledger/rules.js.map +1 -0
- package/dist/ledger/schema.d.ts +23 -0
- package/dist/ledger/schema.js +56 -0
- package/dist/ledger/schema.js.map +1 -0
- package/dist/mcp-server.d.ts +11 -6
- package/dist/mcp-server.js +24 -15
- package/dist/mcp-server.js.map +1 -1
- package/dist/refusal.d.ts +8 -0
- package/dist/refusal.js +8 -0
- package/dist/refusal.js.map +1 -0
- package/dist/request-header.d.ts +3 -0
- package/dist/request-header.js +6 -0
- package/dist/request-header.js.map +1 -0
- package/dist/users-repo.d.ts +32 -0
- package/dist/users-repo.js +69 -0
- package/dist/users-repo.js.map +1 -1
- package/dist/webmcp.d.ts +19 -2
- package/dist/webmcp.js +25 -4
- package/dist/webmcp.js.map +1 -1
- package/dist/workspace-scope.d.ts +18 -2
- package/dist/workspace-scope.js +36 -8
- package/dist/workspace-scope.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Session = {
|
|
2
|
+
token: string;
|
|
3
|
+
expiresAt: Date;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* How a sign-in made through a tool stays with the caller. A browser keeps a
|
|
7
|
+
* cookie; an MCP client keeps nothing but its session id, so its session is
|
|
8
|
+
* stored under that. The sign-in tools hand the carrier the two things only
|
|
9
|
+
* the site can do (check a password and open a session, close one) and never
|
|
10
|
+
* know which kind of caller they are talking to.
|
|
11
|
+
*/
|
|
12
|
+
export interface SessionCarrier {
|
|
13
|
+
/** The token of the session this request carries, if it carries one. */
|
|
14
|
+
readonly token: string | undefined;
|
|
15
|
+
/** Opens a session with `login` and makes the caller's later requests carry it. `login` takes the token to store it under, when the carrier has one of its own. */
|
|
16
|
+
signIn(login: (bindTo?: string) => Promise<Session>): Promise<void>;
|
|
17
|
+
/** Closes the session the request carries, with `logout`, and stops carrying it. */
|
|
18
|
+
signOut(logout: (token: string) => Promise<void>): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** A browser on the site's pages: the session cookie the pages themselves set, sent again by the page's WebMCP bridge. */
|
|
21
|
+
export declare class CookieCarrier implements SessionCarrier {
|
|
22
|
+
readonly token: string | undefined;
|
|
23
|
+
private readonly setCookie;
|
|
24
|
+
constructor(token: string | undefined, setCookie: (token: string, expires: Date) => void);
|
|
25
|
+
signIn(login: (bindTo?: string) => Promise<Session>): Promise<void>;
|
|
26
|
+
signOut(logout: (token: string) => Promise<void>): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** An MCP client: it repeats the Mcp-Session-Id it was given when it initialized, and its session is stored under that. */
|
|
29
|
+
export declare class McpSessionCarrier implements SessionCarrier {
|
|
30
|
+
readonly token: string;
|
|
31
|
+
constructor(token: string);
|
|
32
|
+
signIn(login: (bindTo?: string) => Promise<Session>): Promise<void>;
|
|
33
|
+
signOut(logout: (token: string) => Promise<void>): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** A request with nowhere to keep a session: a tool call sent without initializing, from no page. It is told so before any password is checked. */
|
|
36
|
+
export declare class NoCarrier implements SessionCarrier {
|
|
37
|
+
readonly token: undefined;
|
|
38
|
+
signIn(): Promise<never>;
|
|
39
|
+
signOut(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** A session id as `newMcpSessionId` makes them; anything else a client sends under that header is not one. */
|
|
42
|
+
export declare const isMcpSessionId: (value: string | undefined) => value is string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DomainError } from "../domain-error.js";
|
|
2
|
+
/** A browser on the site's pages: the session cookie the pages themselves set, sent again by the page's WebMCP bridge. */
|
|
3
|
+
export class CookieCarrier {
|
|
4
|
+
token;
|
|
5
|
+
setCookie;
|
|
6
|
+
constructor(token, setCookie) {
|
|
7
|
+
this.token = token;
|
|
8
|
+
this.setCookie = setCookie;
|
|
9
|
+
}
|
|
10
|
+
async signIn(login) {
|
|
11
|
+
const session = await login();
|
|
12
|
+
this.setCookie(session.token, session.expiresAt);
|
|
13
|
+
}
|
|
14
|
+
async signOut(logout) {
|
|
15
|
+
if (this.token)
|
|
16
|
+
await logout(this.token);
|
|
17
|
+
this.setCookie("", new Date(0));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** An MCP client: it repeats the Mcp-Session-Id it was given when it initialized, and its session is stored under that. */
|
|
21
|
+
export class McpSessionCarrier {
|
|
22
|
+
token;
|
|
23
|
+
constructor(token) {
|
|
24
|
+
this.token = token;
|
|
25
|
+
}
|
|
26
|
+
async signIn(login) {
|
|
27
|
+
await login(this.token);
|
|
28
|
+
}
|
|
29
|
+
async signOut(logout) {
|
|
30
|
+
await logout(this.token);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** A request with nowhere to keep a session: a tool call sent without initializing, from no page. It is told so before any password is checked. */
|
|
34
|
+
export class NoCarrier {
|
|
35
|
+
token = undefined;
|
|
36
|
+
async signIn() {
|
|
37
|
+
throw new DomainError("NO_SESSION", "this connection has nothing to stay signed in with: send `initialize` first and repeat the Mcp-Session-Id header it answers with on every call (or connect with Authorization: Bearer <api token>)", 400);
|
|
38
|
+
}
|
|
39
|
+
async signOut() { }
|
|
40
|
+
}
|
|
41
|
+
const MCP_SESSION_ID = /^mcp-[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
|
|
42
|
+
/** A session id as `newMcpSessionId` makes them; anything else a client sends under that header is not one. */
|
|
43
|
+
export const isMcpSessionId = (value) => value !== undefined && MCP_SESSION_ID.test(value);
|
|
44
|
+
//# sourceMappingURL=session-carrier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-carrier.js","sourceRoot":"","sources":["../../src/doors/session-carrier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAoBjD,0HAA0H;AAC1H,MAAM,OAAO,aAAa;IAEb;IACQ;IAFnB,YACW,KAAyB,EACjB,SAAiD;QADzD,UAAK,GAAL,KAAK,CAAoB;QACjB,cAAS,GAAT,SAAS,CAAwC;IACjE,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,KAA4C;QACvD,MAAM,OAAO,GAAG,MAAM,KAAK,EAAE,CAAC;QAC9B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAwC;QACpD,IAAI,IAAI,CAAC,KAAK;YAAE,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;CACF;AAED,2HAA2H;AAC3H,MAAM,OAAO,iBAAiB;IACP;IAArB,YAAqB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAEtC,KAAK,CAAC,MAAM,CAAC,KAA4C;QACvD,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAwC;QACpD,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;CACF;AAED,mJAAmJ;AACnJ,MAAM,OAAO,SAAS;IACX,KAAK,GAAG,SAAS,CAAC;IAE3B,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,WAAW,CAAC,YAAY,EAAE,oMAAoM,EAAE,GAAG,CAAC,CAAC;IACjP,CAAC;IAED,KAAK,CAAC,OAAO,KAAmB,CAAC;CAClC;AAED,MAAM,cAAc,GAAG,iDAAiD,CAAC;AAEzE,+GAA+G;AAC/G,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAyB,EAAmB,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AuthService } from "../auth-service.js";
|
|
2
|
+
import type { ToolRegistry } from "../tool-registry.js";
|
|
3
|
+
import type { CallerScope } from "./caller.js";
|
|
4
|
+
export type SignInToolsDeps = {
|
|
5
|
+
auth: AuthService;
|
|
6
|
+
callers: CallerScope;
|
|
7
|
+
};
|
|
8
|
+
/** The names of the tools every site with accounts carries, in the order a newcomer calls them. */
|
|
9
|
+
export declare const SIGN_IN_TOOLS: readonly ["sign_up", "verify_email", "sign_in", "sign_out", "whoami"];
|
|
10
|
+
/**
|
|
11
|
+
* Signing up and in, as tools: what the sign-up, verify and sign-in pages do,
|
|
12
|
+
* through the same AuthService, so an agent that only has a site's tools is
|
|
13
|
+
* not stopped at the first write. Registered on the site's own registry, so
|
|
14
|
+
* the MCP server lists them and the pages' WebMCP bridge registers them.
|
|
15
|
+
*
|
|
16
|
+
* Nothing here is easier than the pages: the code still goes to the workspace
|
|
17
|
+
* inbox and has to be read there, and the password is still checked. The
|
|
18
|
+
* session is kept by the request's carrier (an MCP session's id, or the
|
|
19
|
+
* browser's cookie), so no token is handed to the caller to pass around.
|
|
20
|
+
*/
|
|
21
|
+
export declare function registerSignInTools<C extends {
|
|
22
|
+
workspaceId: string;
|
|
23
|
+
}>(tools: ToolRegistry<C>, d: SignInToolsDeps): ToolRegistry<C>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The names of the tools every site with accounts carries, in the order a newcomer calls them. */
|
|
3
|
+
export const SIGN_IN_TOOLS = ["sign_up", "verify_email", "sign_in", "sign_out", "whoami"];
|
|
4
|
+
/**
|
|
5
|
+
* Signing up and in, as tools: what the sign-up, verify and sign-in pages do,
|
|
6
|
+
* through the same AuthService, so an agent that only has a site's tools is
|
|
7
|
+
* not stopped at the first write. Registered on the site's own registry, so
|
|
8
|
+
* the MCP server lists them and the pages' WebMCP bridge registers them.
|
|
9
|
+
*
|
|
10
|
+
* Nothing here is easier than the pages: the code still goes to the workspace
|
|
11
|
+
* inbox and has to be read there, and the password is still checked. The
|
|
12
|
+
* session is kept by the request's carrier (an MCP session's id, or the
|
|
13
|
+
* browser's cookie), so no token is handed to the caller to pass around.
|
|
14
|
+
*/
|
|
15
|
+
export function registerSignInTools(tools, d) {
|
|
16
|
+
const caller = () => {
|
|
17
|
+
const c = d.callers.current();
|
|
18
|
+
if (!c)
|
|
19
|
+
throw new Error("a sign-in tool was called outside a door: no caller is in scope");
|
|
20
|
+
return c;
|
|
21
|
+
};
|
|
22
|
+
return tools
|
|
23
|
+
.register({
|
|
24
|
+
name: "sign_up",
|
|
25
|
+
description: "Create an account on this site. A 6-digit verification code is mailed to the email address: read it in the workspace inbox (the mail app), then call verify_email. Writes on this site need a signed-in account.",
|
|
26
|
+
input: { name: z.string().describe("the account holder's name"), email: z.string().describe("the account's email address"), password: z.string().describe("8 characters or more") },
|
|
27
|
+
handler: async (a, c) => {
|
|
28
|
+
const user = await d.auth.signup(c.workspaceId, a.email, a.password, a.name);
|
|
29
|
+
return { email: user.email, verified: false, next: `a verification code was mailed to ${user.email}: read it in the workspace inbox, then call verify_email` };
|
|
30
|
+
},
|
|
31
|
+
})
|
|
32
|
+
.register({
|
|
33
|
+
name: "verify_email",
|
|
34
|
+
description: "Verify a new account's email address with the 6-digit code mailed to it at sign-up. Then call sign_in.",
|
|
35
|
+
input: { email: z.string(), code: z.string().describe("the 6-digit code from the verification mail") },
|
|
36
|
+
handler: async (a, c) => {
|
|
37
|
+
await d.auth.verify(c.workspaceId, a.email, a.code);
|
|
38
|
+
return { email: a.email.trim().toLowerCase(), verified: true, next: "call sign_in" };
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
.register({
|
|
42
|
+
name: "sign_in",
|
|
43
|
+
description: "Sign in to a verified account. The sign-in stays with this connection (or, in a browser, with the site's pages), so the site's other tools then act as the account.",
|
|
44
|
+
input: { email: z.string(), password: z.string() },
|
|
45
|
+
handler: async (a, c) => {
|
|
46
|
+
await caller().session.signIn((bindTo) => d.auth.login(c.workspaceId, a.email, a.password, bindTo));
|
|
47
|
+
return { signedIn: true, email: a.email.trim().toLowerCase() };
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
.register({
|
|
51
|
+
name: "sign_out",
|
|
52
|
+
description: "Sign out of the account this connection (or browser) is signed in to.",
|
|
53
|
+
input: {},
|
|
54
|
+
handler: async (_a, c) => {
|
|
55
|
+
await caller().session.signOut((token) => d.auth.logout(c.workspaceId, token));
|
|
56
|
+
return { signedIn: false };
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
.register({
|
|
60
|
+
name: "whoami",
|
|
61
|
+
description: "Whether this connection (or browser) is signed in, and to which account.",
|
|
62
|
+
input: {},
|
|
63
|
+
handler: async () => {
|
|
64
|
+
const email = await caller().actor();
|
|
65
|
+
return email ? { signedIn: true, email } : { signedIn: false };
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=sign-in-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-in-tools.js","sourceRoot":"","sources":["../../src/doors/sign-in-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,mGAAmG;AACnG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AAEnG;;;;;;;;;;GAUG;AACH,MAAM,UAAU,mBAAmB,CAAoC,KAA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AAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QAC7B,CAAC;KACF,CAAC;SACD,QAAQ,CAAC;QACR,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,0EAA0E;QACvF,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,KAAK,GAAG,MAAM,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;YACrC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;QACjE,CAAC;KACF,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Door } from "./door.js";
|
|
2
|
+
/**
|
|
3
|
+
* The one reason code a write gets, through any door, when nobody is signed
|
|
4
|
+
* in. It is the code the REST door has always answered with, so nothing a REST
|
|
5
|
+
* caller reads changed when the other doors started asking the same.
|
|
6
|
+
*/
|
|
7
|
+
export declare const SIGN_IN_REQUIRED_CODE = "UNAUTHORIZED";
|
|
8
|
+
/**
|
|
9
|
+
* A write by nobody. Thrown by the site's rules (see `ledgered`), which is
|
|
10
|
+
* where every door ends up, and answered by the door it came through: REST
|
|
11
|
+
* with a 401, a page by sending the visitor to sign in, a tool with an error
|
|
12
|
+
* result. Not a DomainError on purpose: a page's own handler re-renders a
|
|
13
|
+
* rule's refusal in place, and this one is the door's to answer.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SignInRequired extends Error {
|
|
16
|
+
readonly door: Door;
|
|
17
|
+
readonly code = "UNAUTHORIZED";
|
|
18
|
+
readonly status = 401;
|
|
19
|
+
constructor(door: Door);
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one reason code a write gets, through any door, when nobody is signed
|
|
3
|
+
* in. It is the code the REST door has always answered with, so nothing a REST
|
|
4
|
+
* caller reads changed when the other doors started asking the same.
|
|
5
|
+
*/
|
|
6
|
+
export const SIGN_IN_REQUIRED_CODE = "UNAUTHORIZED";
|
|
7
|
+
/** What each door tells a caller it refused, in that door's own terms. */
|
|
8
|
+
const HOW_TO_SIGN_IN = {
|
|
9
|
+
page: "sign in to do that",
|
|
10
|
+
rest: "sign in or send Authorization: Bearer <api token>",
|
|
11
|
+
mcp: "sign in first: call sign_up, then verify_email with the code mailed to the workspace inbox, then sign_in (or connect with Authorization: Bearer <api token>)",
|
|
12
|
+
webmcp: "sign in first: on the site's sign-in page, or call sign_up, then verify_email with the code mailed to the workspace inbox, then sign_in",
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A write by nobody. Thrown by the site's rules (see `ledgered`), which is
|
|
16
|
+
* where every door ends up, and answered by the door it came through: REST
|
|
17
|
+
* with a 401, a page by sending the visitor to sign in, a tool with an error
|
|
18
|
+
* result. Not a DomainError on purpose: a page's own handler re-renders a
|
|
19
|
+
* rule's refusal in place, and this one is the door's to answer.
|
|
20
|
+
*/
|
|
21
|
+
export class SignInRequired extends Error {
|
|
22
|
+
door;
|
|
23
|
+
code = SIGN_IN_REQUIRED_CODE;
|
|
24
|
+
status = 401;
|
|
25
|
+
constructor(door) {
|
|
26
|
+
super(HOW_TO_SIGN_IN[door]);
|
|
27
|
+
this.door = door;
|
|
28
|
+
this.name = "SignInRequired";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=sign-in.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign-in.js","sourceRoot":"","sources":["../../src/doors/sign-in.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAc,CAAC;AAEpD,0EAA0E;AAC1E,MAAM,cAAc,GAAyB;IAC3C,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,mDAAmD;IACzD,GAAG,EAAE,8JAA8J;IACnK,MAAM,EAAE,yIAAyI;CAClJ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGlB;IAFZ,IAAI,GAAG,qBAAqB,CAAC;IAC7B,MAAM,GAAG,GAAG,CAAC;IACtB,YAAqB,IAAU;QAC7B,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QADT,SAAI,GAAJ,IAAI,CAAM;QAE7B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/html.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DoorSet } from "@benchme/core";
|
|
1
2
|
/** Escape for HTML text and attribute values. */
|
|
2
3
|
export declare function esc(s: unknown): string;
|
|
3
4
|
export declare function money(cents: number): string;
|
|
@@ -26,14 +27,17 @@ export type ShellCtx = {
|
|
|
26
27
|
};
|
|
27
28
|
/** The page shell every site shares: header with nav + auth links, flash, main. */
|
|
28
29
|
export declare function shell(ctx: ShellCtx, title: string, body: string): string;
|
|
30
|
+
/** Whether an api token opens any of the open `doors`: the account page offers one only then. */
|
|
31
|
+
export declare const apiTokenOpens: (doors: DoorSet) => boolean;
|
|
29
32
|
/** The auth pages every site shares (signup / verify / login / account). */
|
|
30
33
|
export declare const authPages: {
|
|
31
34
|
signup: (p: string, error?: string) => string;
|
|
32
35
|
verify: (p: string, email: string, error?: string) => string;
|
|
33
36
|
login: (p: string, error?: string) => string;
|
|
37
|
+
/** `doors`: the request's, so the api token is offered, and named, only for the doors it opens there. */
|
|
34
38
|
account: (p: string, user: {
|
|
35
39
|
email: string;
|
|
36
40
|
displayName: string;
|
|
37
41
|
apiToken: string | null;
|
|
38
|
-
}) => string;
|
|
42
|
+
}, doors: DoorSet) => string;
|
|
39
43
|
};
|
package/dist/html.js
CHANGED
|
@@ -26,6 +26,26 @@ export function shell(ctx, title, body) {
|
|
|
26
26
|
<body><header><a href="${p}/"><strong>${esc(ctx.site)}</strong></a>${nav}<span class="sp"></span>${who}</header>
|
|
27
27
|
<main>${ctx.flash ? `<div class="flash">${esc(ctx.flash)}</div>` : ""}${body}</main>${(ctx.scripts ?? []).join("")}</body></html>`;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* What an api token opens, door by door, in the account page's words. A
|
|
31
|
+
* workspace that is not served through a door is never told the token works
|
|
32
|
+
* there, and one served through neither gets no token at all.
|
|
33
|
+
*/
|
|
34
|
+
const TOKEN_USES = [
|
|
35
|
+
{ door: "rest", use: (p) => `against <code>${esc(p)}/api/v1/…</code>` },
|
|
36
|
+
{ door: "mcp", use: (p) => `to connect an MCP client to <code>${esc(p)}/mcp</code>` },
|
|
37
|
+
];
|
|
38
|
+
/** Whether an api token opens any of the open `doors`: the account page offers one only then. */
|
|
39
|
+
export const apiTokenOpens = (doors) => TOKEN_USES.some((u) => doors.has(u.door));
|
|
40
|
+
/** The account page's api token section, naming only the open doors; none when the token would open none. */
|
|
41
|
+
function apiTokenSection(p, apiToken, doors) {
|
|
42
|
+
const uses = TOKEN_USES.filter((u) => doors.has(u.door)).map((u) => u.use(p));
|
|
43
|
+
if (uses.length === 0)
|
|
44
|
+
return "";
|
|
45
|
+
return `<h2>API token</h2><p>Use it as <code>Authorization: Bearer <token></code> ${uses.join(", or ")}.</p>
|
|
46
|
+
<p>${apiToken ? `<code>${esc(apiToken)}</code>` : "<em>none yet</em>"}</p>
|
|
47
|
+
<form method="post" action="${p}/account/token"><button>${apiToken ? "Rotate token" : "Create token"}</button></form>`;
|
|
48
|
+
}
|
|
29
49
|
/** The auth pages every site shares (signup / verify / login / account). */
|
|
30
50
|
export const authPages = {
|
|
31
51
|
signup: (p, error) => `<h1>Create an account</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/signup">
|
|
@@ -36,9 +56,8 @@ export const authPages = {
|
|
|
36
56
|
login: (p, error) => `<h1>Sign in</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/login">
|
|
37
57
|
<label>Email</label><input name="email" type="email" required><label>Password</label><input name="password" type="password" required><button>Sign in</button></form>
|
|
38
58
|
<p class="muted">No account? <a href="${p}/signup">Sign up</a>.</p>`,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<form method="post" action="${p}/account/token"><button>${user.apiToken ? "Rotate token" : "Create token"}</button></form>`,
|
|
59
|
+
/** `doors`: the request's, so the api token is offered, and named, only for the doors it opens there. */
|
|
60
|
+
account: (p, user, doors) => `<h1>Account</h1><p>${esc(user.displayName)} · ${esc(user.email)}</p>
|
|
61
|
+
${apiTokenSection(p, user.apiToken, doors)}`,
|
|
43
62
|
};
|
|
44
63
|
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAEA,iDAAiD;AACjD,MAAM,UAAU,GAAG,CAAC,CAAU;IAC5B,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAW,CAAC,CAAC;AACtI,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC;AAoBD,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC;oBACd,MAAM;;;;;sDAK4B,MAAM;;4HAEgE,CAAC;AAE7H,mFAAmF;AACnF,MAAM,UAAU,KA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C,CAAS,EAAE,KAAa,EAAE,KAAc,EAAE,EAAE,CAAC,6BAA6B,KAAK,CAAC,CAAC,CAAC,sBAAsB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,wCAAwC,GAAG,CAAC,KAAK,CAAC;2CACjJ,CAAC,qDAAqD,GAAG,CAAC,KAAK,CAAC,oGAAoG;IAC7M,KAAK,EAAE,CAAC,CAAS,EAAE,KAAc,EAAE,EAAE,CAAC,mBAAmB,KAAK,CAAC,CAAC,CAAC,sBAAsB,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,4CAA4C,CAAC;;wCAErH,CAAC,2BAA2B;IAClE,yGAAyG;IACzG,OAAO,EAAE,CAAC,CAAS,EAAE,IAAqE,EAAE,KAAc,EAAE,EAAE,CAC5G,sBAAsB,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;EAClE,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE;CAC3C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
export { registerWorkspaceScope, header } from "./workspace-scope.js";
|
|
2
|
-
export { PgUsersRepo, type UserRow, type UsersRepo } from "./users-repo.js";
|
|
2
|
+
export { MemoryUsersRepo, PgUsersRepo, seedAccounts, type SeedAccount, type UserRow, type UsersRepo } from "./users-repo.js";
|
|
3
3
|
export { AuthError, AuthService, type AuthDeps, type Mailer, type VerificationCopy } from "./auth-service.js";
|
|
4
4
|
export { HttpMailer } from "./http-mailer.js";
|
|
5
5
|
export { ToolRegistry, type ToolDef } from "./tool-registry.js";
|
|
6
6
|
export { toolInputJsonSchema, type JsonSchemaObject } from "./tool-schema.js";
|
|
7
|
-
export { DomainError, buildMcpServer, registerMcp, type McpDeps } from "./mcp-server.js";
|
|
7
|
+
export { DomainError, buildMcpServer, newMcpSessionId, registerMcp, type McpDeps } from "./mcp-server.js";
|
|
8
|
+
export { refusalOf, type Refusal } from "./refusal.js";
|
|
9
|
+
export { DOORS, DoorSet, doorOf, type Door } from "./doors/door.js";
|
|
10
|
+
export { BRIDGE_COOKIE, BRIDGE_TOKEN_HEADER, BridgeCredential, bridgeToken } from "./doors/bridge-credential.js";
|
|
11
|
+
export { CallerScope, once, type Caller } from "./doors/caller.js";
|
|
12
|
+
export { MCP_SESSION_HEADER, registerDoors, type Doors, type DoorsDeps } from "./doors/register-doors.js";
|
|
13
|
+
export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
|
|
14
|
+
export { SIGN_IN_TOOLS, registerSignInTools, type SignInToolsDeps } from "./doors/sign-in-tools.js";
|
|
15
|
+
export { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId, type Session, type SessionCarrier } from "./doors/session-carrier.js";
|
|
16
|
+
export { AUTH_LEDGER } from "./ledger/auth-rules.js";
|
|
17
|
+
export { LEDGER_KINDS, LEDGER_OUTCOMES, NOT_FOUND_CODE, READ_ACTION, ledgerEntrySchema, ledgerPageSchema, type LedgerEntry, type LedgerKind, type LedgerOutcome, type LedgerPage, type NewLedgerEntry } from "./ledger/entry.js";
|
|
18
|
+
export { MemoryLedger, PgLedger, type Ledger } from "./ledger/ledger.js";
|
|
19
|
+
export { ledgerPath, registerLedgerRoute } from "./ledger/ledger-route.js";
|
|
20
|
+
export { ledgered, untransacted, type LedgeredDeps } from "./ledger/ledgered.js";
|
|
21
|
+
export { about, authStep, read, unrecorded, write, type LedgerRule, type LedgerRules, type Recorded, type Subject, type Unrecorded } from "./ledger/rules.js";
|
|
22
|
+
export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
|
|
8
23
|
export { esc, money, shell, authPages, type NavLink, type ShellCtx } from "./html.js";
|
|
9
|
-
export {
|
|
24
|
+
export { bridgeScript, webmcpBridge, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
|
|
10
25
|
export { registerAuthRoutes, requireSession, sessionUser, apiUser, type AuthRoutesDeps, type SessionUser } from "./auth-routes.js";
|
|
11
26
|
export { SCHEMA_CONTEXT, comment, digitalDocument, offer, organization, person, place, product, question, webPage, type Availability, } from "./jsonld.js";
|
|
12
27
|
export * from "./nlweb/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
export { registerWorkspaceScope, header } from "./workspace-scope.js";
|
|
2
|
-
export { PgUsersRepo } from "./users-repo.js";
|
|
2
|
+
export { MemoryUsersRepo, PgUsersRepo, seedAccounts } from "./users-repo.js";
|
|
3
3
|
export { AuthError, AuthService } from "./auth-service.js";
|
|
4
4
|
export { HttpMailer } from "./http-mailer.js";
|
|
5
5
|
export { ToolRegistry } from "./tool-registry.js";
|
|
6
6
|
export { toolInputJsonSchema } from "./tool-schema.js";
|
|
7
|
-
export { DomainError, buildMcpServer, registerMcp } from "./mcp-server.js";
|
|
7
|
+
export { DomainError, buildMcpServer, newMcpSessionId, registerMcp } from "./mcp-server.js";
|
|
8
|
+
export { refusalOf } from "./refusal.js";
|
|
9
|
+
export { DOORS, DoorSet, doorOf } from "./doors/door.js";
|
|
10
|
+
export { BRIDGE_COOKIE, BRIDGE_TOKEN_HEADER, BridgeCredential, bridgeToken } from "./doors/bridge-credential.js";
|
|
11
|
+
export { CallerScope, once } from "./doors/caller.js";
|
|
12
|
+
export { MCP_SESSION_HEADER, registerDoors } from "./doors/register-doors.js";
|
|
13
|
+
export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
|
|
14
|
+
export { SIGN_IN_TOOLS, registerSignInTools } from "./doors/sign-in-tools.js";
|
|
15
|
+
export { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId } from "./doors/session-carrier.js";
|
|
16
|
+
export { AUTH_LEDGER } from "./ledger/auth-rules.js";
|
|
17
|
+
export { LEDGER_KINDS, LEDGER_OUTCOMES, NOT_FOUND_CODE, READ_ACTION, ledgerEntrySchema, ledgerPageSchema } from "./ledger/entry.js";
|
|
18
|
+
export { MemoryLedger, PgLedger } from "./ledger/ledger.js";
|
|
19
|
+
export { ledgerPath, registerLedgerRoute } from "./ledger/ledger-route.js";
|
|
20
|
+
export { ledgered, untransacted } from "./ledger/ledgered.js";
|
|
21
|
+
export { about, authStep, read, unrecorded, write } from "./ledger/rules.js";
|
|
22
|
+
export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
|
|
8
23
|
export { esc, money, shell, authPages } from "./html.js";
|
|
9
|
-
export {
|
|
24
|
+
export { bridgeScript, webmcpBridge, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
|
|
10
25
|
export { registerAuthRoutes, requireSession, sessionUser, apiUser } from "./auth-routes.js";
|
|
11
26
|
export { SCHEMA_CONTEXT, comment, digitalDocument, offer, organization, person, place, product, question, webPage, } from "./jsonld.js";
|
|
12
27
|
export * from "./nlweb/index.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,EAAkD,MAAM,iBAAiB,CAAC;AAC7H,OAAO,EAAE,SAAS,EAAE,WAAW,EAAqD,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAA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B,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAyC,MAAM,kBAAkB,CAAC;AACnI,OAAO,EACL,cAAc,EACd,OAAO,EACP,eAAe,EACf,KAAK,EACL,YAAY,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAER,MAAM,aAAa,CAAC;AACrB,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AuthService } from "../auth-service.js";
|
|
2
|
+
import { type LedgerRules } from "./rules.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a site's ledger keeps of signing up and in, whichever door it was done
|
|
5
|
+
* through (the pages' forms and the sign-in tools both call the one
|
|
6
|
+
* AuthService): each step with the account's email, and a refused one with its
|
|
7
|
+
* reason (`EXISTS`, `BAD_CODE`, `BAD_CREDENTIALS`, `UNVERIFIED`). They are
|
|
8
|
+
* `auth` entries: an account is not a change to what the site sells. Looking a
|
|
9
|
+
* session up, which every request does, is not recorded.
|
|
10
|
+
*/
|
|
11
|
+
export declare const AUTH_LEDGER: LedgerRules<AuthService>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { authStep, unrecorded } from "./rules.js";
|
|
2
|
+
const email = (address) => address.trim().toLowerCase();
|
|
3
|
+
/**
|
|
4
|
+
* What a site's ledger keeps of signing up and in, whichever door it was done
|
|
5
|
+
* through (the pages' forms and the sign-in tools both call the one
|
|
6
|
+
* AuthService): each step with the account's email, and a refused one with its
|
|
7
|
+
* reason (`EXISTS`, `BAD_CODE`, `BAD_CREDENTIALS`, `UNVERIFIED`). They are
|
|
8
|
+
* `auth` entries: an account is not a change to what the site sells. Looking a
|
|
9
|
+
* session up, which every request does, is not recorded.
|
|
10
|
+
*/
|
|
11
|
+
export const AUTH_LEDGER = {
|
|
12
|
+
signup: authStep("sign_up", ([address]) => email(address)),
|
|
13
|
+
verify: authStep("verify", ([address]) => email(address)),
|
|
14
|
+
login: authStep("sign_in", ([address]) => email(address)),
|
|
15
|
+
logout: authStep("sign_out", () => null),
|
|
16
|
+
issueApiToken: authStep("issue_token", ([address]) => email(address)),
|
|
17
|
+
sendVerification: unrecorded,
|
|
18
|
+
userForSession: unrecorded,
|
|
19
|
+
userForApiToken: unrecorded,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=auth-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-rules.js","sourceRoot":"","sources":["../../src/ledger/auth-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAC;AAEpE,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAA6B;IACnD,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzD,KAAK,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;IACxC,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrE,gBAAgB,EAAE,UAAU;IAC5B,cAAc,EAAE,UAAU;IAC1B,eAAe,EAAE,UAAU;CAC5B,CAAC"}
|