@tbtop/admin
v0.9.1
Published
Tabletop admin server for Bun, Node and Cloudflare Workers: pages in a TypeScript DSL, rendered by @tbtop/inertia-admin over Inertia.
Readme
@tbtop/admin (Bun/Node, experimental)
The tbtop admin server on Bun/Node: the PHP DSL in TypeScript, the same wire
grammar (packages/contracts), the same React client (packages/client) on the
real @inertiajs/react. Published to npm in lockstep with @tbtop/inertia-admin. Host guide:
docs/.
What exists
- DSL: every PHP builder and method (
src/dsl), same names. Gated by a byte-equal port ofkitchen-sink.jsonand a method-parity test againstdocs/ai/api. - Inertia server protocol (
src/server/inertia), host-agnostic: the page object (HTML on first load, JSON on a visit), asset version 409, partial reloads, 303 redirects,Inertia::location, flash and the errors bag through the session.rootView()+viteTags()stand in for Blade's@inertia/@vite. - Session:
SessionStore { get, set, forget, commit? }, the only view of the host's session. The default reads the user fromSESSION_USER; a login page puts it there (admin.session(request)).cookieSessions({ secret })keeps it in one AES-GCM cookie (no store, runs on Workers), so logout cannot revoke a copied cookie before itsmaxAge(7200 s by default);memorySessions()is a one-server reference store. - i18n: UI locales switched through the session (
POST {prefix}/locale), bundledtbtop-admin::adminstrings (lang/*.json, generated from the PHP lang files bybun run sync:lang), host strings and validation templates per locale. - Uploads: the
uploadfield over aDiskinterface (memoryDisk,localDiskfrom/local-disk,r2Disk). The type is sniffed from the content, SVG passes only through a host sanitizer,sharpImages(/sharp) converts, private files stream through signed expiring URLs, and a submit may only claim paths issued to its session. No media library. - Notifications:
Notification/NotificationActionbuilders, the bell's API under{prefix}/api/notifications,memoryNotifications()andkyselyNotifications()on Laravel'snotificationstable. - Endpoints (
routes/admin.php, minus the media library), as one Webfetchhandler:createAdmin().handle(request)answers pages, endpoints andPOST {prefix}/logoutand/locale, and returnsnullfor URLs it does not own. - Validation: Laravel rules and messages; unknown rules throw. The host
supplies
unique/existsashostRules. - Data: the ORM is the host's. Tables and relations go through a
QueryDriver;/kysely(driver,kyselyRulesforunique/exists, notifications) and/memoryship. - Panel: the
tbtopshared prop as PHP sends it. Sidebar navigation frompage.nav(groups, sections, nesting vianav.parent, gated byauthorize),navigationGroups/navigationItems/userMenuItems, breadcrumbs, the shell as aChromeDefin the DSL, the ⌘K palette, the four navigation layouts and appearance. A 404 under the prefix renders theadmin/errorpage in the shell.createPanels([...])serves several panels from one handler. - MCP:
mcp: { authenticate }exposes the panel to agents atPOST {prefix}/mcp(stateless streamable HTTP, JSON-RPC) with the PHP server's three tools:search,query,execute. The agent acts as the userauthenticatereturns from its token, with that user's gates and validation; the session gate does not run, Origin is checked.mcp: falseon a page,.mcp(false)on an action hide them. - Runtimes: Bun, Node, and Cloudflare Workers (
bun run check:workersruns the core in workerd; CI does too).
The media library is out of scope.
bun install && bun test && bunx tsc --noEmit
bun run check:package # build dist, publint, attw, install the tarball under NodeHost
apps/node-demo is the whole host: server.ts is Bun.serve around
admin.handle, src/client.tsx is the same createInertiaApp boot as
apps/demo. Any Web-standard server (Hono, Elysia, a Start server entry)
mounts the handler the same way.
cd ../client && bun install # the demo compiles the client from source
cd ../node && bun install # and reads this package from source (tsconfig paths)
cd ../../apps/node-demo && bun install
bun run dev # Vite on :5173, the server on :3000
bun run build && bun run start # production on BunSign in at /admin/login with any email: the demo's login page trusts it.
An agent reaches a panel with mcp set like this (the token check is the
host's; repeat the panel's role checks there):
createAdmin({
// ...
mcp: {
authenticate: async (request) => {
const [scheme, token] = (request.headers.get("authorization") ?? "").split(" ");
return scheme === "Bearer" && token ? users.byToken(token) : null;
},
allowedOrigins: ["https://admin.example.com"],
},
});Without allowedOrigins every browser origin is refused; a client that sends
no Origin (a desktop agent, a CLI) goes on to authenticate.
