@benchme/site-kit 0.9.1 → 0.11.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-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/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 +23 -0
- package/dist/doors/door.js +30 -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/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/index.d.ts +16 -2
- package/dist/index.js +16 -2
- 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/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 +2 -1
- package/dist/webmcp.js +4 -2
- package/dist/webmcp.js.map +1 -1
- package/package.json +2 -2
package/dist/auth-service.d.ts
CHANGED
|
@@ -34,7 +34,13 @@ export declare class AuthService {
|
|
|
34
34
|
signup(ws: string, email: string, password: string, displayName: string): Promise<UserRow>;
|
|
35
35
|
sendVerification(ws: string, email: string): Promise<void>;
|
|
36
36
|
verify(ws: string, email: string, code: string): Promise<void>;
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* `bindTo` stores the session under a token the caller already holds (an MCP
|
|
39
|
+
* session's id) instead of a fresh one, replacing whoever was signed in
|
|
40
|
+
* under it: a client that cannot keep a cookie stays signed in by what it
|
|
41
|
+
* already repeats on every request.
|
|
42
|
+
*/
|
|
43
|
+
login(ws: string, email: string, password: string, bindTo?: string): Promise<{
|
|
38
44
|
token: string;
|
|
39
45
|
expiresAt: Date;
|
|
40
46
|
}>;
|
|
@@ -43,3 +49,5 @@ export declare class AuthService {
|
|
|
43
49
|
userForApiToken(ws: string, token: string | undefined): Promise<UserRow | null>;
|
|
44
50
|
issueApiToken(ws: string, email: string): Promise<string>;
|
|
45
51
|
}
|
|
52
|
+
/** A password as the users table keeps it: `salt:key`, the key scrypt's of the password with that salt. */
|
|
53
|
+
export declare function hashPassword(password: string, salt: string): Promise<string>;
|
package/dist/auth-service.js
CHANGED
|
@@ -41,14 +41,22 @@ export class AuthService {
|
|
|
41
41
|
if (!ok)
|
|
42
42
|
throw new AuthError("BAD_CODE", "that code is wrong or has expired");
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* `bindTo` stores the session under a token the caller already holds (an MCP
|
|
46
|
+
* session's id) instead of a fresh one, replacing whoever was signed in
|
|
47
|
+
* under it: a client that cannot keep a cookie stays signed in by what it
|
|
48
|
+
* already repeats on every request.
|
|
49
|
+
*/
|
|
50
|
+
async login(ws, email, password, bindTo) {
|
|
45
51
|
const user = await this.d.users.getUser(ws, email.trim().toLowerCase());
|
|
46
52
|
if (!user || !(await matches(password, user.passwordHash)))
|
|
47
53
|
throw new AuthError("BAD_CREDENTIALS", "wrong email or password", 401);
|
|
48
54
|
if (!user.verifiedAt)
|
|
49
55
|
throw new AuthError("UNVERIFIED", "verify your email before signing in", 403);
|
|
50
|
-
const token = randomBytes(24).toString("hex");
|
|
56
|
+
const token = bindTo ?? randomBytes(24).toString("hex");
|
|
51
57
|
const expiresAt = new Date(this.now().getTime() + this.d.sessionTtlSeconds * 1000);
|
|
58
|
+
if (bindTo)
|
|
59
|
+
await this.d.users.deleteSession(ws, bindTo);
|
|
52
60
|
await this.d.users.createSession(ws, token, user.email, expiresAt);
|
|
53
61
|
return { token, expiresAt };
|
|
54
62
|
}
|
|
@@ -76,7 +84,10 @@ export class AuthService {
|
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
async function hash(password) {
|
|
79
|
-
|
|
87
|
+
return hashPassword(password, randomBytes(16).toString("hex"));
|
|
88
|
+
}
|
|
89
|
+
/** A password as the users table keeps it: `salt:key`, the key scrypt's of the password with that salt. */
|
|
90
|
+
export async function hashPassword(password, salt) {
|
|
80
91
|
const key = (await scrypt(password, salt, 32));
|
|
81
92
|
return `${salt}:${key.toString("hex")}`;
|
|
82
93
|
}
|
package/dist/auth-service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-service.js","source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AM,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QACjD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,KAAK,UAAU,IAAI,CAAC,QAAgB;IAClC,OAAO,YAAY,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,2GAA2G;AAC3G,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,QAAgB,EAAE,IAAY;IAC/D,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAW,CAAC;IACzD,OAAO,GAAG,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1C,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,QAAgB,EAAE,MAAc;IACrD,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IAChC,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAW,CAAC;IACzD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Thrown by a tool/domain operation to render a structured error (never a 500). */
|
|
2
|
+
export class DomainError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
constructor(code, message, status = 422) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.name = "DomainError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=domain-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-error.js","sourceRoot":"","sources":["../src/domain-error.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,OAAO,WAAY,SAAQ,KAAK;IAEzB;IAEA;IAHX,YACW,IAAY,EACrB,OAAe,EACN,SAAS,GAAG;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAM;QAGrB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Door } from "./door.js";
|
|
2
|
+
import type { SessionCarrier } from "./session-carrier.js";
|
|
3
|
+
/** Who is asking, for the length of one request. */
|
|
4
|
+
export type Caller = {
|
|
5
|
+
readonly door: Door;
|
|
6
|
+
/** The verifier reading state after the fact: it is shown the rows, and no ledger records that it looked. */
|
|
7
|
+
readonly observer: boolean;
|
|
8
|
+
/** The email of whoever is signed in on this request, or null for nobody. Resolved once, when first asked. */
|
|
9
|
+
actor(): Promise<string | null>;
|
|
10
|
+
/** How a sign-in made on this request stays with the caller. */
|
|
11
|
+
readonly session: SessionCarrier;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Carries a request's caller to whatever the request reaches, without every
|
|
15
|
+
* route, tool and repository method passing it along: a door enters the scope
|
|
16
|
+
* once, and the one place every door shares (the site's rules) reads it.
|
|
17
|
+
* One instance per app.
|
|
18
|
+
*/
|
|
19
|
+
export declare class CallerScope {
|
|
20
|
+
private readonly store;
|
|
21
|
+
run<T>(caller: Caller, fn: () => T): T;
|
|
22
|
+
current(): Caller | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Resolves once and remembers the answer, so a request that asks who is signed in ten times looks it up once. */
|
|
25
|
+
export declare function once<T>(resolve: () => Promise<T>): () => Promise<T>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
/**
|
|
3
|
+
* Carries a request's caller to whatever the request reaches, without every
|
|
4
|
+
* route, tool and repository method passing it along: a door enters the scope
|
|
5
|
+
* once, and the one place every door shares (the site's rules) reads it.
|
|
6
|
+
* One instance per app.
|
|
7
|
+
*/
|
|
8
|
+
export class CallerScope {
|
|
9
|
+
store = new AsyncLocalStorage();
|
|
10
|
+
run(caller, fn) {
|
|
11
|
+
return this.store.run(caller, fn);
|
|
12
|
+
}
|
|
13
|
+
current() {
|
|
14
|
+
return this.store.getStore();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Resolves once and remembers the answer, so a request that asks who is signed in ten times looks it up once. */
|
|
18
|
+
export function once(resolve) {
|
|
19
|
+
let answer;
|
|
20
|
+
return () => (answer ??= resolve());
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=caller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caller.js","sourceRoot":"","sources":["../../src/doors/caller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAerD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACL,KAAK,GAAG,IAAI,iBAAiB,EAAU,CAAC;IAEzD,GAAG,CAAI,MAAc,EAAE,EAAW;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF;AAED,kHAAkH;AAClH,MAAM,UAAU,IAAI,CAAI,OAAyB;IAC/C,IAAI,MAA8B,CAAC;IACnC,OAAO,GAAG,EAAE,CAAC,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ways into a site. A request an agent can make comes through exactly one
|
|
3
|
+
* of them, and the change ledger names it on every entry.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DOORS: readonly ["page", "rest", "mcp", "webmcp"];
|
|
6
|
+
export type Door = (typeof DOORS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* Sent by the page's WebMCP bridge on every tool call it makes. A call to
|
|
9
|
+
* /mcp that carries it came through a tool the page registered (`webmcp`); any
|
|
10
|
+
* other call to /mcp is a direct MCP client (`mcp`). It is a label, never a
|
|
11
|
+
* credential: both doors ask the same of a caller.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DOOR_HEADER = "x-benchme-door";
|
|
14
|
+
export declare const WEBMCP_DOOR_VALUE = "webmcp";
|
|
15
|
+
type Headers = Record<string, string | string[] | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* The door a request came through, read off the path as the app routes it and
|
|
18
|
+
* the bridge's header: /mcp is the MCP server (the page's bridge or a client),
|
|
19
|
+
* /api/ is REST, and anything else an agent can open is a page. The paths that
|
|
20
|
+
* are no door at all (the gateway's own /internal/, the probes) have none.
|
|
21
|
+
*/
|
|
22
|
+
export declare function doorOf(url: string, headers?: Headers): Door | null;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ways into a site. A request an agent can make comes through exactly one
|
|
3
|
+
* of them, and the change ledger names it on every entry.
|
|
4
|
+
*/
|
|
5
|
+
export const DOORS = ["page", "rest", "mcp", "webmcp"];
|
|
6
|
+
/**
|
|
7
|
+
* Sent by the page's WebMCP bridge on every tool call it makes. A call to
|
|
8
|
+
* /mcp that carries it came through a tool the page registered (`webmcp`); any
|
|
9
|
+
* other call to /mcp is a direct MCP client (`mcp`). It is a label, never a
|
|
10
|
+
* credential: both doors ask the same of a caller.
|
|
11
|
+
*/
|
|
12
|
+
export const DOOR_HEADER = "x-benchme-door";
|
|
13
|
+
export const WEBMCP_DOOR_VALUE = "webmcp";
|
|
14
|
+
/**
|
|
15
|
+
* The door a request came through, read off the path as the app routes it and
|
|
16
|
+
* the bridge's header: /mcp is the MCP server (the page's bridge or a client),
|
|
17
|
+
* /api/ is REST, and anything else an agent can open is a page. The paths that
|
|
18
|
+
* are no door at all (the gateway's own /internal/, the probes) have none.
|
|
19
|
+
*/
|
|
20
|
+
export function doorOf(url, headers = {}) {
|
|
21
|
+
const path = url.split("?")[0] ?? "";
|
|
22
|
+
if (path === "/healthz" || path === "/readyz" || path.startsWith("/internal/"))
|
|
23
|
+
return null;
|
|
24
|
+
if (path === "/mcp") {
|
|
25
|
+
const marker = headers[DOOR_HEADER];
|
|
26
|
+
return (Array.isArray(marker) ? marker[0] : marker) === WEBMCP_DOOR_VALUE ? "webmcp" : "mcp";
|
|
27
|
+
}
|
|
28
|
+
return path.startsWith("/api/") ? "rest" : "page";
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=door.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"door.js","sourceRoot":"","sources":["../../src/doors/door.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAGhE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAC5C,MAAM,CAAC,MAAM,iBAAiB,GAAG,QAAQ,CAAC;AAI1C;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW,EAAE,UAAmB,EAAE;IACvD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,IAAI,IAAI,KAAK,UAAU,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5F,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;QACpB,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;QACpC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC;IAC/F,CAAC;IACD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "@fastify/cookie";
|
|
2
|
+
import { type Transactions } from "@benchme/core";
|
|
3
|
+
import type { FastifyInstance } from "fastify";
|
|
4
|
+
import type { AuthService } from "../auth-service.js";
|
|
5
|
+
import type { Ledger } from "../ledger/ledger.js";
|
|
6
|
+
import type { LedgerRules } from "../ledger/rules.js";
|
|
7
|
+
import type { ToolRegistry } from "../tool-registry.js";
|
|
8
|
+
import { CallerScope } from "./caller.js";
|
|
9
|
+
/** The header an MCP client repeats the session id in (the protocol's own). */
|
|
10
|
+
export declare const MCP_SESSION_HEADER = "mcp-session-id";
|
|
11
|
+
export type DoorsDeps = {
|
|
12
|
+
/** The site's change ledger (its own schema's table: `new PgLedger(db, "<app>")`). */
|
|
13
|
+
ledger: Ledger;
|
|
14
|
+
/**
|
|
15
|
+
* The site's `transactions(pool)`. Its pool is the one the site's repositories and accounts are built with, so a
|
|
16
|
+
* write and its ledger entry are one transaction (`untransacted` for a site whose rows are not in Postgres).
|
|
17
|
+
*/
|
|
18
|
+
transactions: Pick<Transactions, "run">;
|
|
19
|
+
auth: AuthService;
|
|
20
|
+
/** The site's session cookie. */
|
|
21
|
+
cookie: string;
|
|
22
|
+
gatewaySecret: string;
|
|
23
|
+
};
|
|
24
|
+
export type Doors = {
|
|
25
|
+
callers: CallerScope;
|
|
26
|
+
ledger: Ledger;
|
|
27
|
+
/** The site's sign-up and sign-in with the ledger kept: hand this one to the routes. */
|
|
28
|
+
auth: AuthService;
|
|
29
|
+
/** The site's rules with the ledger kept, and a sign-in asked of every write: see `ledgered`. */
|
|
30
|
+
ledgered<R extends object>(repo: R, rules: LedgerRules<R>): R;
|
|
31
|
+
/** Adds the sign-in tools to the site's own, so its MCP server and its pages' WebMCP bridge both carry them. */
|
|
32
|
+
withSignIn<C extends {
|
|
33
|
+
workspaceId: string;
|
|
34
|
+
}>(tools: ToolRegistry<C>): ToolRegistry<C>;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Gives a site its doors. Every request is entered in the caller scope with
|
|
38
|
+
* the door it came through and whoever is signed in; the site's rules are
|
|
39
|
+
* wrapped to keep the ledger and to ask a sign-in of every write; a write by
|
|
40
|
+
* nobody is answered by the door it came through; and the verifier gets its
|
|
41
|
+
* route to read the ledger. Call it once, after the workspace scope and
|
|
42
|
+
* before any route is added.
|
|
43
|
+
*/
|
|
44
|
+
export declare function registerDoors(app: FastifyInstance, d: DoorsDeps): Doors;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import "@fastify/cookie";
|
|
2
|
+
import { VERIFIER_SIG_HEADER, verifyVerifierHeader } from "@benchme/core";
|
|
3
|
+
import { AUTH_LEDGER } from "../ledger/auth-rules.js";
|
|
4
|
+
import { registerLedgerRoute } from "../ledger/ledger-route.js";
|
|
5
|
+
import { ledgered } from "../ledger/ledgered.js";
|
|
6
|
+
import { header } from "../workspace-scope.js";
|
|
7
|
+
import { CallerScope, once } from "./caller.js";
|
|
8
|
+
import { doorOf } from "./door.js";
|
|
9
|
+
import { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId } from "./session-carrier.js";
|
|
10
|
+
import { registerSignInTools } from "./sign-in-tools.js";
|
|
11
|
+
import { SignInRequired } from "./sign-in.js";
|
|
12
|
+
/** The header an MCP client repeats the session id in (the protocol's own). */
|
|
13
|
+
export const MCP_SESSION_HEADER = "mcp-session-id";
|
|
14
|
+
/**
|
|
15
|
+
* Gives a site its doors. Every request is entered in the caller scope with
|
|
16
|
+
* the door it came through and whoever is signed in; the site's rules are
|
|
17
|
+
* wrapped to keep the ledger and to ask a sign-in of every write; a write by
|
|
18
|
+
* nobody is answered by the door it came through; and the verifier gets its
|
|
19
|
+
* route to read the ledger. Call it once, after the workspace scope and
|
|
20
|
+
* before any route is added.
|
|
21
|
+
*/
|
|
22
|
+
export function registerDoors(app, d) {
|
|
23
|
+
const callers = new CallerScope();
|
|
24
|
+
const { ledger } = d;
|
|
25
|
+
const units = { ledger, callers, transactions: d.transactions };
|
|
26
|
+
const auth = ledgered(d.auth, AUTH_LEDGER, units);
|
|
27
|
+
// A callback hook on purpose: the rest of the request runs inside `done`, so inside the scope.
|
|
28
|
+
app.addHook("preHandler", (req, reply, done) => {
|
|
29
|
+
const door = doorOf(req.url, req.headers);
|
|
30
|
+
if (!door)
|
|
31
|
+
return done();
|
|
32
|
+
callers.run(callerOf(app, req, reply, door, d), done);
|
|
33
|
+
});
|
|
34
|
+
// The rules refuse a write by nobody (SignInRequired); each door says so its own way. A tool's refusal never
|
|
35
|
+
// gets here: the MCP server turns it into the tool's result.
|
|
36
|
+
app.addHook("onRoute", (route) => {
|
|
37
|
+
const inherited = route.errorHandler;
|
|
38
|
+
route.errorHandler = function (err, req, reply) {
|
|
39
|
+
if (!(err instanceof SignInRequired))
|
|
40
|
+
return (inherited ?? app.errorHandler).call(this, err, req, reply);
|
|
41
|
+
if (err.door === "page")
|
|
42
|
+
return reply.redirect(`${req.prefix}/login`, 302);
|
|
43
|
+
return reply.code(err.status).send({ error: err.code, message: err.message });
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
registerLedgerRoute(app, { ledger, gatewaySecret: d.gatewaySecret });
|
|
47
|
+
return {
|
|
48
|
+
callers,
|
|
49
|
+
ledger,
|
|
50
|
+
auth,
|
|
51
|
+
ledgered: (repo, rules) => ledgered(repo, rules, units),
|
|
52
|
+
withSignIn: (tools) => registerSignInTools(tools, { auth, callers }),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A request's caller: the door, whether it is the verifier's own read, and who
|
|
57
|
+
* is signed in. Every door is asked the same three things, in one order: an
|
|
58
|
+
* api token (`Authorization: Bearer`), the site's session cookie, the MCP
|
|
59
|
+
* session a sign-in tool signed in.
|
|
60
|
+
*/
|
|
61
|
+
function callerOf(app, req, reply, door, d) {
|
|
62
|
+
const ws = req.workspaceId;
|
|
63
|
+
const bearer = (req.headers.authorization ?? "").replace(/^Bearer\s+/i, "");
|
|
64
|
+
const session = carrierOf(app, req, reply, door, d.cookie);
|
|
65
|
+
return {
|
|
66
|
+
door,
|
|
67
|
+
observer: verifyVerifierHeader(d.gatewaySecret, ws, header(req, VERIFIER_SIG_HEADER) ?? ""),
|
|
68
|
+
session,
|
|
69
|
+
actor: once(async () => {
|
|
70
|
+
const user = (await d.auth.userForApiToken(ws, bearer || undefined)) ?? (await d.auth.userForSession(ws, req.cookies[d.cookie])) ?? (await d.auth.userForSession(ws, session.token));
|
|
71
|
+
return user?.email ?? null;
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Where a sign-in made on this request would be kept. An MCP client has its
|
|
77
|
+
* session id. A page's bridge has the browser's cookie jar: the answer to its
|
|
78
|
+
* call is written straight to the socket (the MCP transport owns it), so the
|
|
79
|
+
* cookie goes on the raw response, in the words the pages' own sign-in uses.
|
|
80
|
+
* A page or REST request signs in on the sign-in page, never through a tool.
|
|
81
|
+
*/
|
|
82
|
+
function carrierOf(app, req, reply, door, cookie) {
|
|
83
|
+
const mcpSession = header(req, MCP_SESSION_HEADER);
|
|
84
|
+
if (door === "mcp" && isMcpSessionId(mcpSession))
|
|
85
|
+
return new McpSessionCarrier(mcpSession);
|
|
86
|
+
if (door !== "webmcp")
|
|
87
|
+
return new NoCarrier();
|
|
88
|
+
return new CookieCarrier(req.cookies[cookie], (token, expires) => {
|
|
89
|
+
reply.raw.setHeader("set-cookie", app.serializeCookie(cookie, token, { path: `${req.prefix || ""}/`, httpOnly: true, sameSite: "lax", expires }));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=register-doors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"register-doors.js","sourceRoot":"","sources":["../../src/doors/register-doors.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAqB,MAAM,eAAe,CAAC;AAG7F,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,IAAI,EAAe,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAa,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,cAAc,EAAuB,MAAM,sBAAsB,CAAC;AACxH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AA2BnD;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,GAAoB,EAAE,CAAY;IAC9D,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAClC,MAAM,EAAE,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
+
* 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,KAA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AAE,EAAE;YACvB,MAAM,MAAM,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAC/E,OAAO,EAAE,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"}
|