Add owner inbox UI with address release
Web: "My listings" (listings, requests of a listing, conversation) in three panes on wide screens and one at a time on phones, and a sheet or dialog to release the exact address. Sign-in uses a link printed by `node run` (token in the URL fragment, kept in sessionStorage only). API: GET /api/v1/mine (own listings with request counts and whether an address is saved); inbox rows gain last_dir, needs_reply, preview, effort and grant_until, and can be filtered by listing. Docs: PROTOCOL.md and README describe the owner UI and login. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -176,6 +176,14 @@ export interface Gateway {
|
||||
mailboxes: Map<string, unknown[]>;
|
||||
/** Make POST /api/v1/messages answer with this status and error. */
|
||||
postFails?: { status: number; error: string };
|
||||
/** Plays the node's owner endpoints (/mine, /inbox, .../address); unset, they answer 404. */
|
||||
owner?: (req: {
|
||||
method: string;
|
||||
path: string;
|
||||
query: URLSearchParams;
|
||||
body: string;
|
||||
auth: string;
|
||||
}) => { status: number; body?: unknown } | undefined;
|
||||
close(): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -203,6 +211,22 @@ export async function startGateway(opts: GatewayOptions): Promise<Gateway> {
|
||||
res.writeHead(code, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(body));
|
||||
};
|
||||
// The owner's token-protected routes are played by the test, if it sets `owner`.
|
||||
if (/^\/api\/v1\/(mine|inbox)|^\/api\/v1\/listings\/[0-9a-f]{32}\/address$/.test(url.pathname)) {
|
||||
let body = "";
|
||||
req.on("data", (c) => (body += c));
|
||||
req.on("end", () => {
|
||||
const auth = req.headers.authorization ?? "";
|
||||
const r = gateway.owner?.({ method: req.method ?? "GET", path: url.pathname, query: url.searchParams, body, auth });
|
||||
if (!r) return json(404, { error: "not found" });
|
||||
if (r.status === 204) {
|
||||
res.writeHead(204);
|
||||
return res.end();
|
||||
}
|
||||
json(r.status, r.body ?? null);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (url.pathname === "/api/v1/messages") {
|
||||
if (req.method === "POST") {
|
||||
let body = "";
|
||||
|
||||
Reference in New Issue
Block a user