@benchme/site-kit 0.3.1
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/README.md +3 -0
- package/dist/auth-routes.d.ts +23 -0
- package/dist/auth-routes.js +97 -0
- package/dist/auth-routes.js.map +1 -0
- package/dist/auth-service.d.ts +45 -0
- package/dist/auth-service.js +91 -0
- package/dist/auth-service.js.map +1 -0
- package/dist/html.d.ts +33 -0
- package/dist/html.js +44 -0
- package/dist/html.js.map +1 -0
- package/dist/http-mailer.d.ts +14 -0
- package/dist/http-mailer.js +23 -0
- package/dist/http-mailer.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +25 -0
- package/dist/mcp-server.js +65 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/tool-registry.d.ts +15 -0
- package/dist/tool-registry.js +14 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/users-repo.d.ts +45 -0
- package/dist/users-repo.js +54 -0
- package/dist/users-repo.js.map +1 -0
- package/dist/workspace-scope.d.ts +16 -0
- package/dist/workspace-scope.js +28 -0
- package/dist/workspace-scope.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "@fastify/cookie";
|
|
2
|
+
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
3
|
+
import { type AuthService } from "./auth-service.js";
|
|
4
|
+
import { type ShellCtx } from "./html.js";
|
|
5
|
+
export type SessionUser = {
|
|
6
|
+
email: string;
|
|
7
|
+
displayName: string;
|
|
8
|
+
};
|
|
9
|
+
export type AuthRoutesDeps = {
|
|
10
|
+
auth: AuthService;
|
|
11
|
+
/** Cookie name — one per site so two sites in one browser never share a session. */
|
|
12
|
+
cookie: string;
|
|
13
|
+
/** Build the page shell context for a request (site name, nav, user). */
|
|
14
|
+
shellCtx: (req: FastifyRequest, flash?: string) => Promise<ShellCtx>;
|
|
15
|
+
};
|
|
16
|
+
/** Reads the session cookie into a user, or null. */
|
|
17
|
+
export declare function sessionUser(auth: AuthService, cookie: string): (req: FastifyRequest) => Promise<SessionUser | null>;
|
|
18
|
+
/** Redirects to /login when no session; returns the shell ctx otherwise. */
|
|
19
|
+
export declare function requireSession(d: AuthRoutesDeps): (req: FastifyRequest, reply: FastifyReply) => Promise<ShellCtx | null>;
|
|
20
|
+
/** Resolve a caller for the REST surface: bearer api token first, session cookie second. */
|
|
21
|
+
export declare function apiUser(auth: AuthService, cookie: string): (req: FastifyRequest) => Promise<import("./users-repo.js").UserRow | null>;
|
|
22
|
+
/** /signup /verify /login /logout /account /account/token — identical on every site. */
|
|
23
|
+
export declare function registerAuthRoutes(app: FastifyInstance, d: AuthRoutesDeps): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import "@fastify/cookie";
|
|
2
|
+
import { AuthError } from "./auth-service.js";
|
|
3
|
+
import { authPages, shell } from "./html.js";
|
|
4
|
+
const form = (req) => (req.body ?? {});
|
|
5
|
+
const q = (req) => (req.query ?? {});
|
|
6
|
+
/** Reads the session cookie into a user, or null. */
|
|
7
|
+
export function sessionUser(auth, cookie) {
|
|
8
|
+
return async (req) => {
|
|
9
|
+
const u = await auth.userForSession(req.workspaceId, req.cookies[cookie]);
|
|
10
|
+
return u ? { email: u.email, displayName: u.displayName } : null;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Redirects to /login when no session; returns the shell ctx otherwise. */
|
|
14
|
+
export function requireSession(d) {
|
|
15
|
+
return async (req, reply) => {
|
|
16
|
+
const c = await d.shellCtx(req);
|
|
17
|
+
if (!c.user) {
|
|
18
|
+
reply.redirect(`${req.prefix}/login`, 302);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return c;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** Resolve a caller for the REST surface: bearer api token first, session cookie second. */
|
|
25
|
+
export function apiUser(auth, cookie) {
|
|
26
|
+
return async (req) => {
|
|
27
|
+
const bearer = (req.headers.authorization ?? "").replace(/^Bearer\s+/i, "");
|
|
28
|
+
return (await auth.userForApiToken(req.workspaceId, bearer || undefined)) ?? (await auth.userForSession(req.workspaceId, req.cookies[cookie]));
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** /signup /verify /login /logout /account /account/token — identical on every site. */
|
|
32
|
+
export function registerAuthRoutes(app, d) {
|
|
33
|
+
const html = (reply, body) => reply.type("text/html; charset=utf-8").send(body);
|
|
34
|
+
const cookieOpts = (req, expires) => ({ path: `${req.prefix || ""}/`, httpOnly: true, sameSite: "lax", expires });
|
|
35
|
+
const authErr = async (req, reply, err, title, page) => {
|
|
36
|
+
if (err instanceof AuthError)
|
|
37
|
+
return reply.code(err.status).type("text/html").send(shell(await d.shellCtx(req), title, page));
|
|
38
|
+
throw err;
|
|
39
|
+
};
|
|
40
|
+
app.get("/signup", async (req, reply) => html(reply, shell(await d.shellCtx(req), "Sign up", authPages.signup(req.prefix))));
|
|
41
|
+
app.post("/signup", async (req, reply) => {
|
|
42
|
+
const f = form(req);
|
|
43
|
+
try {
|
|
44
|
+
await d.auth.signup(req.workspaceId, f.email ?? "", f.password ?? "", f.name ?? "");
|
|
45
|
+
return html(reply, shell(await d.shellCtx(req), "Verify", authPages.verify(req.prefix, (f.email ?? "").trim().toLowerCase())));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
return authErr(req, reply, err, "Sign up", authPages.signup(req.prefix, err.message));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
app.get("/verify", async (req, reply) => html(reply, shell(await d.shellCtx(req), "Verify", authPages.verify(req.prefix, q(req).email ?? ""))));
|
|
52
|
+
app.post("/verify", async (req, reply) => {
|
|
53
|
+
const f = form(req);
|
|
54
|
+
try {
|
|
55
|
+
await d.auth.verify(req.workspaceId, f.email ?? "", f.code ?? "");
|
|
56
|
+
return html(reply, shell(await d.shellCtx(req, "Email verified. You can sign in now."), "Sign in", authPages.login(req.prefix)));
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
return authErr(req, reply, err, "Verify", authPages.verify(req.prefix, f.email ?? "", err.message));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
app.get("/login", async (req, reply) => html(reply, shell(await d.shellCtx(req), "Sign in", authPages.login(req.prefix))));
|
|
63
|
+
app.post("/login", async (req, reply) => {
|
|
64
|
+
const f = form(req);
|
|
65
|
+
try {
|
|
66
|
+
const s = await d.auth.login(req.workspaceId, f.email ?? "", f.password ?? "");
|
|
67
|
+
reply.setCookie(d.cookie, s.token, cookieOpts(req, s.expiresAt));
|
|
68
|
+
return reply.redirect(`${req.prefix}/`, 303);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
return authErr(req, reply, err, "Sign in", authPages.login(req.prefix, err.message));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
app.post("/logout", async (req, reply) => {
|
|
75
|
+
const token = req.cookies[d.cookie];
|
|
76
|
+
if (token)
|
|
77
|
+
await d.auth.logout(req.workspaceId, token);
|
|
78
|
+
reply.clearCookie(d.cookie, { path: `${req.prefix || ""}/` });
|
|
79
|
+
return reply.redirect(`${req.prefix}/`, 303);
|
|
80
|
+
});
|
|
81
|
+
const guard = requireSession(d);
|
|
82
|
+
app.get("/account", async (req, reply) => {
|
|
83
|
+
const c = await guard(req, reply);
|
|
84
|
+
if (!c || !c.user)
|
|
85
|
+
return;
|
|
86
|
+
const full = await d.auth.userForSession(req.workspaceId, req.cookies[d.cookie]);
|
|
87
|
+
return html(reply, shell(c, "Account", authPages.account(req.prefix, { email: c.user.email, displayName: c.user.displayName, apiToken: full?.apiToken ?? null })));
|
|
88
|
+
});
|
|
89
|
+
app.post("/account/token", async (req, reply) => {
|
|
90
|
+
const c = await guard(req, reply);
|
|
91
|
+
if (!c || !c.user)
|
|
92
|
+
return;
|
|
93
|
+
await d.auth.issueApiToken(req.workspaceId, c.user.email);
|
|
94
|
+
return reply.redirect(`${req.prefix}/account`, 303);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=auth-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-routes.js","sourceRoot":"","sources":["../src/auth-routes.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,CAAC;AAEzB,OAAO,EAAE,SAAS,EAAoB,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAiB,MAAM,WAAW,CAAC;AAa5D,MAAM,IAAI,GAAG,CAAC,GAAmB,EAAK,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAM,CAAC;AAC/D,MAAM,CAAC,GAAG,CAAC,GAAmB,EAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAM,CAAC;AAE7D,qDAAqD;AACrD,MAAM,UAAU,WAAW,CAAC,IAAiB,EAAE,MAAc;IAC3D,OAAO,KAAK,EAAE,GAAmB,EAA+B,EAAE;QAChE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1E,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,CAAC,CAAC;AACJ,CAAC;AAED,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,CAAiB;IAC9C,OAAO,KAAK,EAAE,GAAmB,EAAE,KAAmB,EAA4B,EAAE;QAClF,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACZ,KAAK,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AC,IAAI;YAAE,OAAO;QAC1B,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1D,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,MAAM,UAAU,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { UserRow, UsersRepo } from "./users-repo.js";
|
|
2
|
+
/** Delivers mail to the workspace inbox (the mail app); one method so tests can capture it. */
|
|
3
|
+
export interface Mailer {
|
|
4
|
+
deliver(ws: string, msg: {
|
|
5
|
+
to: string;
|
|
6
|
+
subject: string;
|
|
7
|
+
body: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export declare class AuthError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly status: number;
|
|
13
|
+
constructor(code: string, message: string, status?: number);
|
|
14
|
+
}
|
|
15
|
+
/** What the verification mail says — each site words its own. */
|
|
16
|
+
export type VerificationCopy = {
|
|
17
|
+
subject: string;
|
|
18
|
+
body: (code: string) => string;
|
|
19
|
+
};
|
|
20
|
+
export type AuthDeps = {
|
|
21
|
+
users: UsersRepo;
|
|
22
|
+
mailer: Mailer;
|
|
23
|
+
sessionTtlSeconds: number;
|
|
24
|
+
verification: VerificationCopy;
|
|
25
|
+
/** Prefix of issued api tokens (e.g. "whk", "hdk") so a token names its site. */
|
|
26
|
+
tokenPrefix: string;
|
|
27
|
+
now?: () => Date;
|
|
28
|
+
};
|
|
29
|
+
/** Signup → verification mail → verify → login → session. Passwords hashed with scrypt. Shared by every site. */
|
|
30
|
+
export declare class AuthService {
|
|
31
|
+
private readonly d;
|
|
32
|
+
private readonly now;
|
|
33
|
+
constructor(d: AuthDeps);
|
|
34
|
+
signup(ws: string, email: string, password: string, displayName: string): Promise<UserRow>;
|
|
35
|
+
sendVerification(ws: string, email: string): Promise<void>;
|
|
36
|
+
verify(ws: string, email: string, code: string): Promise<void>;
|
|
37
|
+
login(ws: string, email: string, password: string): Promise<{
|
|
38
|
+
token: string;
|
|
39
|
+
expiresAt: Date;
|
|
40
|
+
}>;
|
|
41
|
+
logout(ws: string, token: string): Promise<void>;
|
|
42
|
+
userForSession(ws: string, token: string | undefined): Promise<UserRow | null>;
|
|
43
|
+
userForApiToken(ws: string, token: string | undefined): Promise<UserRow | null>;
|
|
44
|
+
issueApiToken(ws: string, email: string): Promise<string>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { randomBytes, randomInt, scrypt as scryptCb, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const scrypt = promisify(scryptCb);
|
|
4
|
+
export class AuthError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
status;
|
|
7
|
+
constructor(code, message, status = 400) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.name = "AuthError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Signup → verification mail → verify → login → session. Passwords hashed with scrypt. Shared by every site. */
|
|
15
|
+
export class AuthService {
|
|
16
|
+
d;
|
|
17
|
+
now;
|
|
18
|
+
constructor(d) {
|
|
19
|
+
this.d = d;
|
|
20
|
+
this.now = d.now ?? (() => new Date());
|
|
21
|
+
}
|
|
22
|
+
async signup(ws, email, password, displayName) {
|
|
23
|
+
const normalized = email.trim().toLowerCase();
|
|
24
|
+
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalized))
|
|
25
|
+
throw new AuthError("BAD_EMAIL", "enter a valid email address");
|
|
26
|
+
if (password.length < 8)
|
|
27
|
+
throw new AuthError("WEAK_PASSWORD", "password must be at least 8 characters");
|
|
28
|
+
if (await this.d.users.getUser(ws, normalized))
|
|
29
|
+
throw new AuthError("EXISTS", "an account with that email already exists", 409);
|
|
30
|
+
const user = await this.d.users.createUser(ws, normalized, await hash(password), displayName.trim() || normalized);
|
|
31
|
+
await this.sendVerification(ws, normalized);
|
|
32
|
+
return user;
|
|
33
|
+
}
|
|
34
|
+
async sendVerification(ws, email) {
|
|
35
|
+
const code = String(randomInt(100000, 999999));
|
|
36
|
+
await this.d.users.setVerificationCode(ws, email, code, new Date(this.now().getTime() + 30 * 60_000));
|
|
37
|
+
await this.d.mailer.deliver(ws, { to: email, subject: this.d.verification.subject, body: this.d.verification.body(code) });
|
|
38
|
+
}
|
|
39
|
+
async verify(ws, email, code) {
|
|
40
|
+
const ok = await this.d.users.consumeVerificationCode(ws, email.trim().toLowerCase(), code.trim(), this.now());
|
|
41
|
+
if (!ok)
|
|
42
|
+
throw new AuthError("BAD_CODE", "that code is wrong or has expired");
|
|
43
|
+
}
|
|
44
|
+
async login(ws, email, password) {
|
|
45
|
+
const user = await this.d.users.getUser(ws, email.trim().toLowerCase());
|
|
46
|
+
if (!user || !(await matches(password, user.passwordHash)))
|
|
47
|
+
throw new AuthError("BAD_CREDENTIALS", "wrong email or password", 401);
|
|
48
|
+
if (!user.verifiedAt)
|
|
49
|
+
throw new AuthError("UNVERIFIED", "verify your email before signing in", 403);
|
|
50
|
+
const token = randomBytes(24).toString("hex");
|
|
51
|
+
const expiresAt = new Date(this.now().getTime() + this.d.sessionTtlSeconds * 1000);
|
|
52
|
+
await this.d.users.createSession(ws, token, user.email, expiresAt);
|
|
53
|
+
return { token, expiresAt };
|
|
54
|
+
}
|
|
55
|
+
async logout(ws, token) {
|
|
56
|
+
await this.d.users.deleteSession(ws, token);
|
|
57
|
+
}
|
|
58
|
+
async userForSession(ws, token) {
|
|
59
|
+
if (!token)
|
|
60
|
+
return null;
|
|
61
|
+
const email = await this.d.users.getSessionEmail(ws, token, this.now());
|
|
62
|
+
if (!email)
|
|
63
|
+
return null;
|
|
64
|
+
const u = await this.d.users.getUser(ws, email);
|
|
65
|
+
return u ? { email: u.email, displayName: u.displayName, verifiedAt: u.verifiedAt, apiToken: u.apiToken } : null;
|
|
66
|
+
}
|
|
67
|
+
async userForApiToken(ws, token) {
|
|
68
|
+
if (!token)
|
|
69
|
+
return null;
|
|
70
|
+
return this.d.users.getUserByApiToken(ws, token);
|
|
71
|
+
}
|
|
72
|
+
async issueApiToken(ws, email) {
|
|
73
|
+
const token = `${this.d.tokenPrefix}_${randomBytes(18).toString("hex")}`;
|
|
74
|
+
await this.d.users.setApiToken(ws, email, token);
|
|
75
|
+
return token;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function hash(password) {
|
|
79
|
+
const salt = randomBytes(16).toString("hex");
|
|
80
|
+
const key = (await scrypt(password, salt, 32));
|
|
81
|
+
return `${salt}:${key.toString("hex")}`;
|
|
82
|
+
}
|
|
83
|
+
async function matches(password, stored) {
|
|
84
|
+
const [salt, hex] = stored.split(":");
|
|
85
|
+
if (!salt || !hex)
|
|
86
|
+
return false;
|
|
87
|
+
const key = (await scrypt(password, salt, 32));
|
|
88
|
+
const expected = Buffer.from(hex, "hex");
|
|
89
|
+
return key.length === expected.length && timingSafeEqual(key, expected);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=auth-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-service.js","sourceRoot":"","sources":["../src/auth-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,IAAI,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAOnC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEvB;IAEA;IAHX,YACW,IAAY,EACrB,OAAe,EACN,SAAS,GAAG;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJN,SAAI,GAAJ,IAAI,CAAQ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E,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"}
|
package/dist/html.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** Escape for HTML text and attribute values. */
|
|
2
|
+
export declare function esc(s: unknown): string;
|
|
3
|
+
export declare function money(cents: number): string;
|
|
4
|
+
export type NavLink = {
|
|
5
|
+
href: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
export type ShellCtx = {
|
|
9
|
+
/** The site's name in the header. */
|
|
10
|
+
site: string;
|
|
11
|
+
/** Header colour, so each site looks like its own product. */
|
|
12
|
+
accent: string;
|
|
13
|
+
prefix: string;
|
|
14
|
+
nav: NavLink[];
|
|
15
|
+
user: {
|
|
16
|
+
email: string;
|
|
17
|
+
displayName: string;
|
|
18
|
+
} | null;
|
|
19
|
+
flash?: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
/** The page shell every site shares: header with nav + auth links, flash, main. */
|
|
22
|
+
export declare function shell(ctx: ShellCtx, title: string, body: string): string;
|
|
23
|
+
/** The auth pages every site shares (signup / verify / login / account). */
|
|
24
|
+
export declare const authPages: {
|
|
25
|
+
signup: (p: string, error?: string) => string;
|
|
26
|
+
verify: (p: string, email: string, error?: string) => string;
|
|
27
|
+
login: (p: string, error?: string) => string;
|
|
28
|
+
account: (p: string, user: {
|
|
29
|
+
email: string;
|
|
30
|
+
displayName: string;
|
|
31
|
+
apiToken: string | null;
|
|
32
|
+
}) => string;
|
|
33
|
+
};
|
package/dist/html.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Escape for HTML text and attribute values. */
|
|
2
|
+
export function esc(s) {
|
|
3
|
+
return String(s).replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
4
|
+
}
|
|
5
|
+
export function money(cents) {
|
|
6
|
+
return `$${(cents / 100).toFixed(2)}`;
|
|
7
|
+
}
|
|
8
|
+
const STYLE = (accent) => `body{font:15px/1.5 system-ui,sans-serif;margin:0;color:#1b1b1b;background:#fafafa}
|
|
9
|
+
header{background:${accent};color:#fff;padding:.6rem 1rem;display:flex;gap:1rem;align-items:center;flex-wrap:wrap}
|
|
10
|
+
header a{color:#fff;text-decoration:none}header .sp{flex:1}
|
|
11
|
+
main{max-width:64rem;margin:1.5rem auto;padding:0 1rem}
|
|
12
|
+
table{border-collapse:collapse;width:100%;background:#fff}td,th{border:1px solid #ddd;padding:.35em .6em;text-align:left;vertical-align:top}th{background:#eef2f7}
|
|
13
|
+
form.card{background:#fff;border:1px solid #ddd;padding:1rem;max-width:28rem}label{display:block;margin:.5rem 0 .2rem}input,select,textarea{width:100%;padding:.4em;box-sizing:border-box}
|
|
14
|
+
button{margin-top:.8rem;padding:.5em 1em;background:${accent};color:#fff;border:0;border-radius:4px;cursor:pointer}
|
|
15
|
+
.flash{background:#fff4d6;border:1px solid #e6c97a;padding:.5rem .8rem;margin-bottom:1rem}.muted{color:#666}code{background:#eee;padding:.1em .3em;border-radius:3px}
|
|
16
|
+
nav.pager a{margin-right:1rem}.tag{display:inline-block;padding:0 .4em;border-radius:3px;background:#e8edf3;font-size:.9em}`;
|
|
17
|
+
/** The page shell every site shares: header with nav + auth links, flash, main. */
|
|
18
|
+
export function shell(ctx, title, body) {
|
|
19
|
+
const p = ctx.prefix;
|
|
20
|
+
const nav = ctx.nav.map((n) => `<a href="${p}${n.href}">${esc(n.label)}</a>`).join("");
|
|
21
|
+
const who = ctx.user
|
|
22
|
+
? `<span>${esc(ctx.user.displayName)}</span><a href="${p}/account">Account</a><form method="post" action="${p}/logout" style="margin:0"><button style="margin:0;padding:.3em .7em">Sign out</button></form>`
|
|
23
|
+
: `<a href="${p}/login">Sign in</a><a href="${p}/signup">Sign up</a>`;
|
|
24
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="robots" content="noindex,nofollow">
|
|
25
|
+
<meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(title)} — ${esc(ctx.site)}</title><style>${STYLE(ctx.accent)}</style></head>
|
|
26
|
+
<body><header><a href="${p}/"><strong>${esc(ctx.site)}</strong></a>${nav}<span class="sp"></span>${who}</header>
|
|
27
|
+
<main>${ctx.flash ? `<div class="flash">${esc(ctx.flash)}</div>` : ""}${body}</main></body></html>`;
|
|
28
|
+
}
|
|
29
|
+
/** The auth pages every site shares (signup / verify / login / account). */
|
|
30
|
+
export const authPages = {
|
|
31
|
+
signup: (p, error) => `<h1>Create an account</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/signup">
|
|
32
|
+
<label>Name</label><input name="name" required><label>Email</label><input name="email" type="email" required><label>Password (8+ characters)</label><input name="password" type="password" required>
|
|
33
|
+
<button>Sign up</button></form><p class="muted">A verification code is sent to the workspace inbox; enter it on the next screen.</p>`,
|
|
34
|
+
verify: (p, email, error) => `<h1>Verify your email</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<p>We sent a 6-digit code to <strong>${esc(email)}</strong>. Check the workspace inbox.</p>
|
|
35
|
+
<form class="card" method="post" action="${p}/verify"><input type="hidden" name="email" value="${esc(email)}"><label>Code</label><input name="code" required pattern="[0-9]{6}"><button>Verify</button></form>`,
|
|
36
|
+
login: (p, error) => `<h1>Sign in</h1>${error ? `<div class="flash">${esc(error)}</div>` : ""}<form class="card" method="post" action="${p}/login">
|
|
37
|
+
<label>Email</label><input name="email" type="email" required><label>Password</label><input name="password" type="password" required><button>Sign in</button></form>
|
|
38
|
+
<p class="muted">No account? <a href="${p}/signup">Sign up</a>.</p>`,
|
|
39
|
+
account: (p, user) => `<h1>Account</h1><p>${esc(user.displayName)} · ${esc(user.email)}</p>
|
|
40
|
+
<h2>API token</h2><p>Use it as <code>Authorization: Bearer <token></code> against <code>${esc(p)}/api/v1/…</code>.</p>
|
|
41
|
+
<p>${user.apiToken ? `<code>${esc(user.apiToken)}</code>` : "<em>none yet</em>"}</p>
|
|
42
|
+
<form method="post" action="${p}/account/token"><button>${user.apiToken ? "Rotate token" : "Create token"}</button></form>`,
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=html.js.map
|
package/dist/html.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../src/html.ts"],"names":[],"mappings":"AAAA,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;AAcD,MAAM,KAAK,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC;oBACd,MAAM;;;;;sDAK4B,MAAM;;4HAEgE,CAAC;AAE7H,mFAAmF;AACnF,MAAM,UAAU,KAAK,CAAC,GAAa,EAAE,KAAa,EAAE,IAAY;IAC9D,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC;IACrB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM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K,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,4CAA4C,CAAC;;wCAErH,CAAC,2BAA2B;IAClE,OAAO,EAAE,CAAC,CAAS,EAAE,IAAqE,EAAE,EAAE,CAAC,sBAAsB,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;gGACjE,GAAG,CAAC,CAAC,CAAC;KACjG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,mBAAmB;8BACjD,CAAC,2BAA2B,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,cAAc,kBAAkB;CAC1H,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Mailer } from "./auth-service.js";
|
|
2
|
+
/** Delivers to the mail app's internal endpoint, authenticated by the shared internal secret. */
|
|
3
|
+
export declare class HttpMailer implements Mailer {
|
|
4
|
+
private readonly mailUrl;
|
|
5
|
+
private readonly secret;
|
|
6
|
+
private readonly from;
|
|
7
|
+
private readonly fetchImpl;
|
|
8
|
+
constructor(mailUrl: string, secret: string, from: string, fetchImpl?: typeof fetch);
|
|
9
|
+
deliver(ws: string, msg: {
|
|
10
|
+
to: string;
|
|
11
|
+
subject: string;
|
|
12
|
+
body: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Delivers to the mail app's internal endpoint, authenticated by the shared internal secret. */
|
|
2
|
+
export class HttpMailer {
|
|
3
|
+
mailUrl;
|
|
4
|
+
secret;
|
|
5
|
+
from;
|
|
6
|
+
fetchImpl;
|
|
7
|
+
constructor(mailUrl, secret, from, fetchImpl = fetch) {
|
|
8
|
+
this.mailUrl = mailUrl;
|
|
9
|
+
this.secret = secret;
|
|
10
|
+
this.from = from;
|
|
11
|
+
this.fetchImpl = fetchImpl;
|
|
12
|
+
}
|
|
13
|
+
async deliver(ws, msg) {
|
|
14
|
+
const res = await this.fetchImpl(`${this.mailUrl.replace(/\/+$/, "")}/internal/deliver`, {
|
|
15
|
+
method: "POST",
|
|
16
|
+
headers: { "content-type": "application/json", "x-benchme-internal-secret": this.secret },
|
|
17
|
+
body: JSON.stringify({ workspaceId: ws, from: this.from, ...msg }),
|
|
18
|
+
});
|
|
19
|
+
if (!res.ok)
|
|
20
|
+
throw new Error(`mail delivery failed: ${res.status} ${await res.text().catch(() => "")}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=http-mailer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-mailer.js","sourceRoot":"","sources":["../src/http-mailer.ts"],"names":[],"mappings":"AAEA,iGAAiG;AACjG,MAAM,OAAO,UAAU;IAEF;IACA;IACA;IACA;IAJnB,YACmB,OAAe,EACf,MAAc,EACd,IAAY,EACZ,YAA0B,KAAK;QAH/B,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAAsB;IAC/C,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,EAAU,EAAE,GAAkD;QAC1E,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,mBAAmB,EAAE;YACvF,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,IAAI,CAAC,MAAM,EAAE;YACzF,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,GAAG,GAAG,EAAE,CAAC;SACnE,CAAC,CAAC;QACH,IAAI,CAAC,GAAG,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,CAAC,MAAM,IAAI,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1G,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { registerWorkspaceScope, header } from "./workspace-scope.js";
|
|
2
|
+
export { PgUsersRepo, type UserRow, type UsersRepo } from "./users-repo.js";
|
|
3
|
+
export { AuthError, AuthService, type AuthDeps, type Mailer, type VerificationCopy } from "./auth-service.js";
|
|
4
|
+
export { HttpMailer } from "./http-mailer.js";
|
|
5
|
+
export { ToolRegistry, type ToolDef } from "./tool-registry.js";
|
|
6
|
+
export { DomainError, buildMcpServer, registerMcp, type McpDeps } from "./mcp-server.js";
|
|
7
|
+
export { esc, money, shell, authPages, type NavLink, type ShellCtx } from "./html.js";
|
|
8
|
+
export { registerAuthRoutes, requireSession, sessionUser, apiUser, type AuthRoutesDeps, type SessionUser } from "./auth-routes.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { registerWorkspaceScope, header } from "./workspace-scope.js";
|
|
2
|
+
export { PgUsersRepo } from "./users-repo.js";
|
|
3
|
+
export { AuthError, AuthService } from "./auth-service.js";
|
|
4
|
+
export { HttpMailer } from "./http-mailer.js";
|
|
5
|
+
export { ToolRegistry } from "./tool-registry.js";
|
|
6
|
+
export { DomainError, buildMcpServer, registerMcp } from "./mcp-server.js";
|
|
7
|
+
export { esc, money, shell, authPages } from "./html.js";
|
|
8
|
+
export { registerAuthRoutes, requireSession, sessionUser, apiUser } from "./auth-routes.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,EAAgC,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,WAAW,EAAqD,MAAM,mBAAmB,CAAC;AAC9G,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAgB,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAgB,MAAM,iBAAiB,CAAC;AACzF,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAA+B,MAAM,WAAW,CAAC;AACtF,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAyC,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
|
+
import type { ToolRegistry } from "./tool-registry.js";
|
|
4
|
+
/** Thrown by a tool/domain operation to render a structured error (never a 500). */
|
|
5
|
+
export declare class DomainError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
readonly status: number;
|
|
8
|
+
constructor(code: string, message: string, status?: number);
|
|
9
|
+
}
|
|
10
|
+
export type McpDeps<C> = {
|
|
11
|
+
serverName: string;
|
|
12
|
+
version: string;
|
|
13
|
+
tools: ToolRegistry<C>;
|
|
14
|
+
/** Build the tool context for one request's workspace. */
|
|
15
|
+
context: (workspaceId: string) => C;
|
|
16
|
+
};
|
|
17
|
+
/** A fresh MCP server bound to one workspace (stateless per request). */
|
|
18
|
+
export declare function buildMcpServer<C>(d: McpDeps<C>, ctx: C): McpServer;
|
|
19
|
+
/**
|
|
20
|
+
* Streamable HTTP at /mcp inside its own Fastify plugin scope (it replaces the
|
|
21
|
+
* content-type parsers so JSON-RPC bodies reach the transport untouched).
|
|
22
|
+
* Stateless: every request builds a server for the request's workspace, so a
|
|
23
|
+
* workspace's tools never see another's rows.
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerMcp<C>(app: FastifyInstance, d: McpDeps<C>): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
3
|
+
/** Thrown by a tool/domain operation to render a structured error (never a 500). */
|
|
4
|
+
export class DomainError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
status;
|
|
7
|
+
constructor(code, message, status = 422) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.name = "DomainError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** A fresh MCP server bound to one workspace (stateless per request). */
|
|
15
|
+
export function buildMcpServer(d, ctx) {
|
|
16
|
+
const server = new McpServer({ name: d.serverName, version: d.version });
|
|
17
|
+
for (const tool of d.tools.list()) {
|
|
18
|
+
server.tool(tool.name, tool.description, tool.input, async (args) => {
|
|
19
|
+
try {
|
|
20
|
+
const result = await tool.handler(args, ctx);
|
|
21
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
22
|
+
}
|
|
23
|
+
catch (err) {
|
|
24
|
+
if (err instanceof DomainError) {
|
|
25
|
+
return { isError: true, content: [{ type: "text", text: JSON.stringify({ error: err.code, message: err.message }) }] };
|
|
26
|
+
}
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return server;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Streamable HTTP at /mcp inside its own Fastify plugin scope (it replaces the
|
|
35
|
+
* content-type parsers so JSON-RPC bodies reach the transport untouched).
|
|
36
|
+
* Stateless: every request builds a server for the request's workspace, so a
|
|
37
|
+
* workspace's tools never see another's rows.
|
|
38
|
+
*/
|
|
39
|
+
export function registerMcp(app, d) {
|
|
40
|
+
app.removeAllContentTypeParsers();
|
|
41
|
+
app.addContentTypeParser("*", { parseAs: "buffer" }, (_req, body, done) => done(null, body));
|
|
42
|
+
app.addContentTypeParser("application/json", { parseAs: "string" }, (_req, body, done) => {
|
|
43
|
+
try {
|
|
44
|
+
done(null, body.length ? JSON.parse(body) : {});
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
done(err);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
app.addContentTypeParser("application/x-www-form-urlencoded", { parseAs: "string" }, (_req, body, done) => {
|
|
51
|
+
done(null, Object.fromEntries(new URLSearchParams(body)));
|
|
52
|
+
});
|
|
53
|
+
app.all("/mcp", async (req, reply) => {
|
|
54
|
+
const server = buildMcpServer(d, d.context(req.workspaceId));
|
|
55
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
56
|
+
reply.hijack();
|
|
57
|
+
reply.raw.on("close", () => {
|
|
58
|
+
void transport.close();
|
|
59
|
+
void server.close();
|
|
60
|
+
});
|
|
61
|
+
await server.connect(transport);
|
|
62
|
+
await transport.handleRequest(req.raw, reply.raw, req.body);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAInG,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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f,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;YACzB,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
/** One MCP tool: a name, a description the model reads, an input schema, and a handler over the site's context. */
|
|
3
|
+
export type ToolDef<C, S extends z.ZodRawShape = z.ZodRawShape> = {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
input: S;
|
|
7
|
+
/** Returns a JSON-serialisable result; a thrown DomainError becomes an isError result. */
|
|
8
|
+
handler: (args: z.infer<z.ZodObject<S>>, ctx: C) => Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
/** Registry (Open/Closed): a tool is added by registering a ToolDef, never by editing the server. */
|
|
11
|
+
export declare class ToolRegistry<C> {
|
|
12
|
+
private readonly tools;
|
|
13
|
+
register<S extends z.ZodRawShape>(def: ToolDef<C, S>): this;
|
|
14
|
+
list(): ToolDef<C>[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Registry (Open/Closed): a tool is added by registering a ToolDef, never by editing the server. */
|
|
2
|
+
export class ToolRegistry {
|
|
3
|
+
tools = new Map();
|
|
4
|
+
register(def) {
|
|
5
|
+
if (this.tools.has(def.name))
|
|
6
|
+
throw new Error(`duplicate tool: ${def.name}`);
|
|
7
|
+
this.tools.set(def.name, def);
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
list() {
|
|
11
|
+
return [...this.tools.values()];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=tool-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-registry.js","sourceRoot":"","sources":["../src/tool-registry.ts"],"names":[],"mappings":"AAWA,qGAAqG;AACrG,MAAM,OAAO,YAAY;IACN,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEvD,QAAQ,CAA0B,GAAkB;QAClD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAA4B,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Pool } from "@benchme/core";
|
|
2
|
+
export type UserRow = {
|
|
3
|
+
email: string;
|
|
4
|
+
displayName: string;
|
|
5
|
+
verifiedAt: Date | null;
|
|
6
|
+
apiToken: string | null;
|
|
7
|
+
};
|
|
8
|
+
/** Signup state per workspace: users, verification codes, sessions, api tokens. */
|
|
9
|
+
export interface UsersRepo {
|
|
10
|
+
createUser(ws: string, email: string, passwordHash: string, displayName: string): Promise<UserRow>;
|
|
11
|
+
getUser(ws: string, email: string): Promise<(UserRow & {
|
|
12
|
+
passwordHash: string;
|
|
13
|
+
}) | null>;
|
|
14
|
+
setVerificationCode(ws: string, email: string, code: string, expiresAt: Date): Promise<void>;
|
|
15
|
+
consumeVerificationCode(ws: string, email: string, code: string, now: Date): Promise<boolean>;
|
|
16
|
+
createSession(ws: string, token: string, email: string, expiresAt: Date): Promise<void>;
|
|
17
|
+
getSessionEmail(ws: string, token: string, now: Date): Promise<string | null>;
|
|
18
|
+
deleteSession(ws: string, token: string): Promise<void>;
|
|
19
|
+
setApiToken(ws: string, email: string, token: string): Promise<void>;
|
|
20
|
+
getUserByApiToken(ws: string, token: string): Promise<UserRow | null>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The same four tables (users, verification_codes, sessions + api_token on
|
|
24
|
+
* users) under any app schema — every site owns its signups, none share rows.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PgUsersRepo implements UsersRepo {
|
|
27
|
+
private readonly pool;
|
|
28
|
+
private readonly s;
|
|
29
|
+
constructor(pool: Pool, schema: string);
|
|
30
|
+
createUser(ws: string, email: string, passwordHash: string, displayName: string): Promise<UserRow>;
|
|
31
|
+
getUser(ws: string, email: string): Promise<{
|
|
32
|
+
passwordHash: string;
|
|
33
|
+
email: string;
|
|
34
|
+
displayName: string;
|
|
35
|
+
verifiedAt: Date | null;
|
|
36
|
+
apiToken: string | null;
|
|
37
|
+
} | null>;
|
|
38
|
+
setVerificationCode(ws: string, email: string, code: string, expiresAt: Date): Promise<void>;
|
|
39
|
+
consumeVerificationCode(ws: string, email: string, code: string, now: Date): Promise<boolean>;
|
|
40
|
+
createSession(ws: string, token: string, email: string, expiresAt: Date): Promise<void>;
|
|
41
|
+
getSessionEmail(ws: string, token: string, now: Date): Promise<string | null>;
|
|
42
|
+
deleteSession(ws: string, token: string): Promise<void>;
|
|
43
|
+
setApiToken(ws: string, email: string, token: string): Promise<void>;
|
|
44
|
+
getUserByApiToken(ws: string, token: string): Promise<UserRow | null>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const toUser = (r) => ({ email: r.email, displayName: r.display_name, verifiedAt: r.verified_at, apiToken: r.api_token });
|
|
2
|
+
const SCHEMA = /^[a-z_][a-z0-9_]*$/;
|
|
3
|
+
/**
|
|
4
|
+
* The same four tables (users, verification_codes, sessions + api_token on
|
|
5
|
+
* users) under any app schema — every site owns its signups, none share rows.
|
|
6
|
+
*/
|
|
7
|
+
export class PgUsersRepo {
|
|
8
|
+
pool;
|
|
9
|
+
s;
|
|
10
|
+
constructor(pool, schema) {
|
|
11
|
+
this.pool = pool;
|
|
12
|
+
if (!SCHEMA.test(schema))
|
|
13
|
+
throw new Error(`invalid schema name: ${schema}`);
|
|
14
|
+
this.s = schema;
|
|
15
|
+
}
|
|
16
|
+
async createUser(ws, email, passwordHash, displayName) {
|
|
17
|
+
const r = await this.pool.query(`INSERT INTO ${this.s}.users (workspace_id, email, password_hash, display_name) VALUES ($1, $2, $3, $4) RETURNING *`, [ws, email, passwordHash, displayName]);
|
|
18
|
+
return toUser(r.rows[0]);
|
|
19
|
+
}
|
|
20
|
+
async getUser(ws, email) {
|
|
21
|
+
const r = await this.pool.query(`SELECT * FROM ${this.s}.users WHERE workspace_id = $1 AND email = $2`, [ws, email]);
|
|
22
|
+
const row = r.rows[0];
|
|
23
|
+
return row ? { ...toUser(row), passwordHash: row.password_hash } : null;
|
|
24
|
+
}
|
|
25
|
+
async setVerificationCode(ws, email, code, expiresAt) {
|
|
26
|
+
await this.pool.query(`INSERT INTO ${this.s}.verification_codes (workspace_id, email, code, expires_at) VALUES ($1, $2, $3, $4)
|
|
27
|
+
ON CONFLICT (workspace_id, email) DO UPDATE SET code = EXCLUDED.code, expires_at = EXCLUDED.expires_at`, [ws, email, code, expiresAt]);
|
|
28
|
+
}
|
|
29
|
+
async consumeVerificationCode(ws, email, code, now) {
|
|
30
|
+
const r = await this.pool.query(`DELETE FROM ${this.s}.verification_codes WHERE workspace_id = $1 AND email = $2 AND code = $3 AND expires_at > $4`, [ws, email, code, now]);
|
|
31
|
+
if (!r.rowCount)
|
|
32
|
+
return false;
|
|
33
|
+
await this.pool.query(`UPDATE ${this.s}.users SET verified_at = COALESCE(verified_at, $3) WHERE workspace_id = $1 AND email = $2`, [ws, email, now]);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
async createSession(ws, token, email, expiresAt) {
|
|
37
|
+
await this.pool.query(`INSERT INTO ${this.s}.sessions (workspace_id, token, email, expires_at) VALUES ($1, $2, $3, $4)`, [ws, token, email, expiresAt]);
|
|
38
|
+
}
|
|
39
|
+
async getSessionEmail(ws, token, now) {
|
|
40
|
+
const r = await this.pool.query(`SELECT email FROM ${this.s}.sessions WHERE workspace_id = $1 AND token = $2 AND expires_at > $3`, [ws, token, now]);
|
|
41
|
+
return r.rows[0]?.email ?? null;
|
|
42
|
+
}
|
|
43
|
+
async deleteSession(ws, token) {
|
|
44
|
+
await this.pool.query(`DELETE FROM ${this.s}.sessions WHERE workspace_id = $1 AND token = $2`, [ws, token]);
|
|
45
|
+
}
|
|
46
|
+
async setApiToken(ws, email, token) {
|
|
47
|
+
await this.pool.query(`UPDATE ${this.s}.users SET api_token = $3 WHERE workspace_id = $1 AND email = $2`, [ws, email, token]);
|
|
48
|
+
}
|
|
49
|
+
async getUserByApiToken(ws, token) {
|
|
50
|
+
const r = await this.pool.query(`SELECT * FROM ${this.s}.users WHERE workspace_id = $1 AND api_token = $2`, [ws, token]);
|
|
51
|
+
return r.rows[0] ? toUser(r.rows[0]) : null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=users-repo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"users-repo.js","sourceRoot":"","sources":["../src/users-repo.ts"],"names":[],"mappings":"AAkBA,MAAM,MAAM,GAAG,CAAC,CAAO,EAAW,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;AAEzI,MAAM,MAAM,GAAG,oBAAoB,CAAC;AAEpC;;;GAGG;AACH,MAAM,OAAO,WAAW;IAGH;IAFF,CAAC,CAAS;IAC3B,Y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AC,EAAU,EAAE,KAAa,EAAE,KAAa;QACxD,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,kEAAkE,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;IAChI,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,EAAU,EAAE,KAAa;QAC/C,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAO,iBAAiB,IAAI,CAAC,CAAC,mDAAmD,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;QAC/H,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FastifyInstance, FastifyRequest } from "fastify";
|
|
2
|
+
declare module "fastify" {
|
|
3
|
+
interface FastifyRequest {
|
|
4
|
+
/** Bound by the gateway (signed); every tenant query is scoped by it. */
|
|
5
|
+
workspaceId: string;
|
|
6
|
+
/** The public path prefix the gateway stripped ("/w/<id>/<app>"), for links + cookie paths. */
|
|
7
|
+
prefix: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Trust the workspace ONLY from the gateway's signed header. A request without
|
|
12
|
+
* it (or with a bad signature) never reaches a tenant query. Paths in
|
|
13
|
+
* `unscopedPrefixes` (internal endpoints authenticated some other way) skip it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerWorkspaceScope(app: FastifyInstance, gatewaySecret: string, unscopedPrefixes?: readonly string[]): void;
|
|
16
|
+
export declare function header(req: FastifyRequest, name: string): string | undefined;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FORWARDED_PREFIX_HEADER, WORKSPACE_HEADER, WORKSPACE_SIG_HEADER, isWorkspaceId, verifyWorkspaceHeader } from "@benchme/core";
|
|
2
|
+
const UNSCOPED = new Set(["/healthz", "/readyz"]);
|
|
3
|
+
/**
|
|
4
|
+
* Trust the workspace ONLY from the gateway's signed header. A request without
|
|
5
|
+
* it (or with a bad signature) never reaches a tenant query. Paths in
|
|
6
|
+
* `unscopedPrefixes` (internal endpoints authenticated some other way) skip it.
|
|
7
|
+
*/
|
|
8
|
+
export function registerWorkspaceScope(app, gatewaySecret, unscopedPrefixes = []) {
|
|
9
|
+
app.decorateRequest("workspaceId", "");
|
|
10
|
+
app.decorateRequest("prefix", "");
|
|
11
|
+
app.addHook("onRequest", async (req, reply) => {
|
|
12
|
+
const path = req.url.split("?")[0] ?? "";
|
|
13
|
+
if (UNSCOPED.has(path) || unscopedPrefixes.some((p) => path.startsWith(p)))
|
|
14
|
+
return;
|
|
15
|
+
const id = header(req, WORKSPACE_HEADER);
|
|
16
|
+
const sig = header(req, WORKSPACE_SIG_HEADER);
|
|
17
|
+
if (!id || !isWorkspaceId(id) || !sig || !verifyWorkspaceHeader(gatewaySecret, id, sig)) {
|
|
18
|
+
return reply.code(401).send({ error: "NO_WORKSPACE", message: "requests must come through the benchme gateway" });
|
|
19
|
+
}
|
|
20
|
+
req.workspaceId = id;
|
|
21
|
+
req.prefix = header(req, FORWARDED_PREFIX_HEADER) ?? "";
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function header(req, name) {
|
|
25
|
+
const v = req.headers[name];
|
|
26
|
+
return Array.isArray(v) ? v[0] : v;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=workspace-scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-scope.js","sourceRoot":"","sources":["../src/workspace-scope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAY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CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAmB,EAAE,IAAY;IACtD,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@benchme/site-kit",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -b",
|
|
16
|
+
"test": "vitest run"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@benchme/core": "0.3.1",
|
|
20
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
21
|
+
"fastify": "^5.2.0",
|
|
22
|
+
"zod": "^3.24.0",
|
|
23
|
+
"@fastify/cookie": "^11.0.0"
|
|
24
|
+
},
|
|
25
|
+
"description": "benchme site plumbing: gateway workspace scope, per-site signup/sessions/api tokens, MCP server registration, page shell",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/orabenchmarks/benchme.git",
|
|
29
|
+
"directory": "packages/site-kit"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
]
|
|
38
|
+
}
|