Public: anyone can read this; the crew can change it.
A deal prints as a one-page broker file: price, earnest money, commission, every party, every date with the day it was done, waived or moved, and every message the agent approved #159
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/152-a-deal-prints-as-a-one-page-broker-file → main 2 commits fork 1 thread · 1 unresolved
10 files
changed +349
−24
README.md +1
| @@ -167,6 +167,7 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 167 | 167 | under the date and the MCP tool returns it as the date's `todo` list. Tap Print to make the one-page handout |
| 168 | 168 | for a buyer or seller (the browser's own print works too). In the terminal, open the deal with o and press |
| 169 | 169 | t; over MCP, an agent asks for the `client_timeline` tool. |
| 170 | When a deal closes, Print broker file on its page makes the one page for the brokerage's transaction file: price, earnest money, commission, every party, every date with the day it was done, waived or moved, and every message you approved or declined, in your words; it is yours alone, not the client's handout. In the terminal, open the deal with o and press f. | |
| 170 | 171 | 14. **Fix an address.** On a deal's page, Edit address corrects a typo in |
| 171 | 172 | place: the clock, the client timeline, the calendar file and unsent drafts |
| 172 | 173 | carry the new address, and reminders already sent keep their words. In the |
src/contract.test.ts +15
| @@ -229,3 +229,18 @@ test("the spreadsheet, at GET /deals/csv and GET /api/deals.csv, answers as deal | ||
| 229 | 229 | expect(anon.status).toBe(401); |
| 230 | 230 | } |
| 231 | 231 | }); |
| 232 | ||
| 233 | test("the broker file, at GET /deals/:id/file, answers as deal read says, as every identity", async () => { | |
| 234 | const route = routes.find((r) => r.method === "GET" && r.path === "/deals/:id/file")!; | |
| 235 | const id = dealBy("someone-else"); | |
| 236 | for (const identity of identities(contract)) { | |
| 237 | const who = whoIs(identity); | |
| 238 | const said = `/deals/:id/file as ${identity}`; | |
| 239 | const url = new URL(`http://app.test/deals/${id}/file`); | |
| 240 | const res = await route.handle({ request: new Request(url), url, db, who, params: { id: String(id) } }); | |
| 241 | expect([said, res.status === 200]).toEqual([said, permit(who, "deal", "read") !== "no"]); | |
| 242 | } | |
| 243 | const url = new URL(`http://app.test/deals/${id}/file`); | |
| 244 | const anon = await route.handle({ request: new Request(url), url, db, who: { role: "anon" }, params: { id: String(id) } }); | |
| 245 | expect(anon.status).toBe(401); | |
| 246 | }); |
src/file.test.ts added +125
| @@ -0,0 +1,125 @@ | ||
| 1 | /** The broker file: the agent's whole record of a deal on one page, signed-in only, no controls in print. */ | |
| 2 | import { afterAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { addDeadline, addParty, createDeal, declineReminder, getDeal, markFellThrough, moveDeadline, removeDeadline, sendReminder, waiveDate } from "./deals.ts"; | |
| 7 | import { openDb } from "./db.ts"; | |
| 8 | import { terminal } from "./terminal.ts"; | |
| 9 | import { filePage } from "./pages/file.ts"; | |
| 10 | import { forgetRationing } from "./security.ts"; | |
| 11 | import { serve } from "./server.ts"; | |
| 12 | import { sign, type Who } from "./who.ts"; | |
| 13 | ||
| 14 | const db = openDb(mkdtempSync(join(tmpdir(), "app-file-"))); | |
| 15 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 16 | ||
| 17 | const made = createDeal(db, alice, { openAnyway: true, address: "9 <b>Oak</b> Rd", buyer: "Ann Buyer", seller: "Sam Seller", contractDate: "2026-10-01", closingDate: "2026-11-06" }); | |
| 18 | if (!made.ok) throw new Error(made.message); | |
| 19 | const id = made.value.id; | |
| 20 | const lender = addParty(db, alice, { dealId: id, role: "lender", name: "Lena Lender", contact: "[email protected]" }); | |
| 21 | if (!lender.ok) throw new Error(lender.message); | |
| 22 | const buyer = getDeal(db, alice, { id }); | |
| 23 | if (!buyer.ok) throw new Error(buyer.message); | |
| 24 | const ann = buyer.value.parties.find((p) => p.role === "buyer")!; | |
| 25 | const gone = addDeadline(db, alice, { dealId: id, label: "Gone repair date", due: "2026-10-23", owes: "seller", what: "" }); | |
| 26 | if (!gone.ok) throw new Error("setup"); | |
| 27 | const hoa = addDeadline(db, alice, { dealId: id, label: "HOA review ends", due: "2026-10-20", owes: "buyer", what: "" }); | |
| 28 | const survey = addDeadline(db, alice, { dealId: id, label: "Survey back", due: "2026-10-22", owes: "seller", what: "" }); | |
| 29 | const repair = addDeadline(db, alice, { dealId: id, label: "Repair request", due: "2026-10-24", owes: "buyer", what: "" }); | |
| 30 | if (!hoa.ok || !survey.ok || !repair.ok) throw new Error("setup"); | |
| 31 | moveDeadline(db, alice, { id: hoa.value.id, due: "2026-10-27", reason: "Seller asked for time" }); | |
| 32 | waiveDate(db, alice, { id: survey.value.id, waived: true }); | |
| 33 | const sent = sendReminder(db, alice, { deadlineId: hoa.value.id, partyId: ann.id, moment: "moved", subject: "HOA date moved", body: "Hello Ann,\nthe HOA date is now Oct 27." }); | |
| 34 | if (!sent.ok) throw new Error(sent.message); | |
| 35 | const goneSent = sendReminder(db, alice, { deadlineId: gone.value.id, partyId: getDeal(db, alice, { id }).ok ? ann.id : 0, moment: "day_of", subject: "Gone", body: "x" }); | |
| 36 | if (!goneSent.ok) throw new Error(goneSent.message); | |
| 37 | removeDeadline(db, alice, { dealId: id, id: gone.value.id }); | |
| 38 | const declined = declineReminder(db, alice, { deadlineId: repair.value.id, partyId: ann.id, moment: "day_of", reason: "Called her instead" }); | |
| 39 | if (!declined.ok) throw new Error(declined.message); | |
| 40 | ||
| 41 | const page = (): string => { | |
| 42 | const deal = getDeal(db, alice, { id }); | |
| 43 | if (!deal.ok) throw new Error(deal.message); | |
| 44 | return filePage({ who: alice, deal: deal.value }); | |
| 45 | }; | |
| 46 | ||
| 47 | test("holds the figures, parties, every date's state and the words approved and declined", () => { | |
| 48 | const html = page(); | |
| 49 | expect(html).toContain("Commission rate"); | |
| 50 | expect(html).toContain("Earnest money"); | |
| 51 | expect(html).toContain("Lena Lender"); | |
| 52 | expect(html).toContain("[email protected]"); | |
| 53 | expect(html).toContain("HOA review ends"); | |
| 54 | expect(html).toContain("Seller asked for time"); | |
| 55 | expect(html).toContain("Waived"); | |
| 56 | expect(html).toContain("HOA date moved"); | |
| 57 | expect(html).toContain("the HOA date is now Oct 27."); | |
| 58 | expect(html).toContain("Called her instead"); | |
| 59 | }); | |
| 60 | ||
| 61 | test("a removed date is a row marked Removed, with the day it was due", () => { | |
| 62 | const html = page(); | |
| 63 | expect(html).toContain("Gone repair date · due"); | |
| 64 | expect(html).toMatch(/Gone repair date · due [^<]*· Removed/); | |
| 65 | }); | |
| 66 | ||
| 67 | test("escapes every value and has no forms", () => { | |
| 68 | const html = page(); | |
| 69 | expect(html).toContain("9 <b>Oak</b> Rd"); | |
| 70 | expect(html).not.toContain("<b>Oak</b>"); | |
| 71 | expect(html).not.toContain("<form"); | |
| 72 | }); | |
| 73 | ||
| 74 | test("a fell-through deal shows its reason", () => { | |
| 75 | const fell = markFellThrough(db, alice, { id, fell: true, reason: "Financing collapsed" }); | |
| 76 | if (!fell.ok) throw new Error(fell.message); | |
| 77 | expect(page()).toContain("Financing collapsed"); | |
| 78 | expect(markFellThrough(db, alice, { id, fell: false }).ok).toBe(true); | |
| 79 | }); | |
| 80 | ||
| 81 | test("the print rules hide navigation and stay scoped to the file page", async () => { | |
| 82 | const css = await Bun.file(join(import.meta.dir, "..", "static", "app.css")).text(); | |
| 83 | const print = css.slice(css.indexOf("/* The broker file")); | |
| 84 | const media = print.slice(print.indexOf("@media print")); | |
| 85 | expect(media).toMatch(/\.file-page \.head[\s\S]*display: none/); | |
| 86 | const selectors = [...media.matchAll(/^\s*([^{}@\n]+)\{/gm)].map((m) => m[1]!.trim()); | |
| 87 | for (const sel of selectors) for (const part of sel.split(",")) expect(part.trim()).toStartWith(".file-page"); | |
| 88 | }); | |
| 89 | ||
| 90 | test("answers a signed-in visitor, refuses a signed-out one", async () => { | |
| 91 | const KEY = "a-key-only-the-forge-holds"; | |
| 92 | const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-filesrv-")), identityKey: KEY }); | |
| 93 | afterAll(() => server.stop(true)); | |
| 94 | const base = `http://${server.hostname}:${server.port}`; | |
| 95 | const ident = `u1|alice|user|${Date.now() + 600_000}`; | |
| 96 | const headers = { "x-forge-identity": ident, "x-forge-signature": sign(ident, KEY) }; | |
| 97 | forgetRationing(); | |
| 98 | const out = await fetch(`${base}/deals/1/file`, { headers }); | |
| 99 | expect(out.status).toBe(200); | |
| 100 | expect(await out.text()).toContain("Broker file"); | |
| 101 | const anon = await fetch(`${base}/deals/1/file`); | |
| 102 | expect([401, 403]).toContain(anon.status); | |
| 103 | }); | |
| 104 | ||
| 105 | test("the terminal's f on an open deal shows the broker file, and a guest sees none", () => { | |
| 106 | const agent = { name: "Dana", brokerage: "HP", phone: "555", email: "[email protected]" }; | |
| 107 | const t = terminal(db, alice, { title: "deal-clock", where: "test", agent, on: () => "2026-10-25" }); | |
| 108 | const row = (): string => t.screen().join("\n").split("\n").find((l) => l.startsWith("▸")) ?? ""; | |
| 109 | for (let i = 0; i < 300 && !row().includes("Repair request"); i++) t.press("j"); | |
| 110 | t.press("o"); | |
| 111 | t.press("f"); | |
| 112 | const screen = t.screen().join("\n").replace(/\x1b\[[0-9;]*m/g, ""); | |
| 113 | expect(screen).toContain("Broker file"); | |
| 114 | expect(screen).toContain("Commission rate"); | |
| 115 | expect(screen).toContain("Gone repair date"); | |
| 116 | expect(screen).toContain("Called her instead"); | |
| 117 | t.press("b"); | |
| 118 | expect(t.screen().join("\n")).not.toContain("Broker file"); | |
| 119 | const guest = terminal(db, { role: "anon" }, { title: "deal-clock", where: "test", agent, on: () => "2026-10-25" }); | |
| 120 | guest.press("o"); | |
| 121 | guest.press("f"); | |
| 122 | const seen = guest.screen().join("\n"); | |
| 123 | expect(seen).not.toContain("Commission rate"); | |
| 124 | expect(seen).not.toContain("Lena Lender"); | |
| 125 | }); |
src/pages/deal.ts +1 −1
| @@ -333,7 +333,7 @@ export function dealPage(input: { | ||
| 333 | 333 | ${editFigures} |
| 334 | 334 | ${editClosing} |
| 335 | 335 | </div> |
| 336 | <div class="row"><a class="button button-quiet" href="${path}/timeline">Client timeline</a> <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a></div> | |
| 336 | <div class="row"><a class="button button-quiet" href="${path}/timeline">Client timeline</a> <a class="button button-quiet" href="${path}/file">Print broker file</a> <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a></div> | |
| 337 | 337 | </section> |
| 338 | 338 | <div id="deal" data-live="deal.changed"> |
| 339 | 339 | <p class="progress">${progressLine(deal, on)}</p> |
src/pages/file.ts added +107
| @@ -0,0 +1,107 @@ | ||
| 1 | /** | |
| 2 | * A deal's broker file at `/deals/:id/file`: one printed page for the | |
| 3 | * brokerage's transaction file. The agent's own figures (commission), every | |
| 4 | * party with contact, every date with its due day and state, every message | |
| 5 | * approved and every one declined. It is the agent's page, not the client's: | |
| 6 | * the client timeline leaves these out on purpose. Built only from the | |
| 7 | * DealView the deal page already reads; `fileRecord` is the plain data both | |
| 8 | * this page and the terminal print from. | |
| 9 | */ | |
| 10 | ||
| 11 | import { doneLine, short, spoken } from "../dates.ts"; | |
| 12 | import { closedOn, fellOn, type DealView, type Party } from "../deals.ts"; | |
| 13 | import { PARTY_LABEL } from "../deadlines.ts"; | |
| 14 | import { closingLine } from "../closing.ts"; | |
| 15 | import { commission, dollars, percent } from "../money.ts"; | |
| 16 | import { agent as defaults } from "../env.ts"; | |
| 17 | import { asset, escape } from "../http.ts"; | |
| 18 | import { sentLabel, type Agent } from "../reminders.ts"; | |
| 19 | import { SIDE_LABEL } from "../side.ts"; | |
| 20 | import type { Who } from "../who.ts"; | |
| 21 | import { layout } from "./layout.ts"; | |
| 22 | ||
| 23 | const contactOf = (p: Party): string => { | |
| 24 | const parts = [p.email, p.phone].filter((v) => v !== ""); | |
| 25 | return parts.length > 0 ? parts.join(" · ") : p.contact; | |
| 26 | }; | |
| 27 | ||
| 28 | /** Where one date stands, in words: done on (and how early or late), waived, or open. */ | |
| 29 | export function fileState(d: DealView["deadlines"][number]): string { | |
| 30 | if (d.waived_at !== null) | |
| 31 | return `Waived ${spoken(d.waived_at.slice(0, 10))}${d.waived_by === null ? "" : ` by ${d.waived_by}`}`; | |
| 32 | if (d.done_at !== null) return d.done_on === null ? "Done" : doneLine(d.due, d.done_on); | |
| 33 | return "Open"; | |
| 34 | } | |
| 35 | ||
| 36 | export interface FileRecord { | |
| 37 | readonly facts: readonly (readonly [string, string])[]; | |
| 38 | readonly parties: readonly string[]; | |
| 39 | /** One entry per date, live or removed: its line, then one line per move. */ | |
| 40 | readonly dates: readonly { readonly line: string; readonly moves: readonly string[] }[]; | |
| 41 | readonly sent: readonly { readonly head: string; readonly subject: string; readonly body: string }[]; | |
| 42 | readonly declined: readonly string[]; | |
| 43 | } | |
| 44 | ||
| 45 | /** Everything the broker file says, as plain unescaped text. */ | |
| 46 | export function fileRecord(deal: DealView): FileRecord { | |
| 47 | const outcome = deal.fell_through | |
| 48 | ? `Fell through on ${spoken(fellOn(deal))}${deal.fell_reason ? ` · ${deal.fell_reason}` : ""}${deal.fell_by ? ` (${deal.fell_by})` : ""}` | |
| 49 | : deal.closed | |
| 50 | ? `Closed on ${spoken(closedOn(deal))}` | |
| 51 | : "Open"; | |
| 52 | const live = new Set(deal.deadlines.map((d) => d.id)); | |
| 53 | const live_dates = deal.deadlines.map((d) => ({ | |
| 54 | line: `${d.label} · due ${spoken(d.due)} · ${fileState(d)}`, | |
| 55 | moves: d.moves.map((m) => `Moved ${short(m.from_due)} → ${short(m.to_due)}: ${m.reason} (${m.by_name}, ${short(m.at.slice(0, 10))})`), | |
| 56 | })); | |
| 57 | // A removed date leaves no row of its own; what remains of it is in the messages sent or declined about it. | |
| 58 | const gone = new Map<number, { label: string; due: string }>(); | |
| 59 | for (const m of [...deal.sent, ...deal.declined]) | |
| 60 | if (!live.has(m.deadline_id) && !gone.has(m.deadline_id)) gone.set(m.deadline_id, { label: m.label, due: m.due }); | |
| 61 | const removed = [...gone.values()].map((g) => ({ line: `${g.label} · due ${spoken(g.due)} · Removed`, moves: [] as string[] })); | |
| 62 | return { | |
| 63 | facts: [ | |
| 64 | ["Status", outcome], | |
| 65 | ["Side", SIDE_LABEL[deal.side]], | |
| 66 | ["Sale price", deal.sale_price === null ? "not set" : dollars(deal.sale_price)], | |
| 67 | ["Earnest money", deal.earnest_amount === null ? "not set" : dollars(deal.earnest_amount)], | |
| 68 | ["Commission rate", deal.commission_rate === null ? "not set" : percent(deal.commission_rate)], | |
| 69 | [ | |
| 70 | "Commission at closing", | |
| 71 | deal.commission_rate === null || deal.sale_price === null ? "not set" : dollars(commission(deal.sale_price, deal.commission_rate)), | |
| 72 | ], | |
| 73 | ["Under contract", spoken(deal.contract_date)], | |
| 74 | ["Closing", closingLine(deal).replace(/^Closing /, "")], | |
| 75 | ], | |
| 76 | parties: deal.parties.map((p) => `${PARTY_LABEL[p.role]} · ${p.name}${contactOf(p) === "" ? "" : ` · ${contactOf(p)}`}`), | |
| 77 | dates: [...live_dates, ...removed], | |
| 78 | sent: deal.sent.map((m) => ({ | |
| 79 | head: `${m.party_name}${m.party_role === "" ? "" : ` · ${PARTY_LABEL[m.party_role]}`} · ${m.label}${live.has(m.deadline_id) ? "" : " (date removed)"}, due ${short(m.due)} · ${sentLabel(m.moment)} · approved by ${m.by_name} on ${spoken(m.sent_at.slice(0, 10))}`, | |
| 80 | subject: m.subject, | |
| 81 | body: m.body, | |
| 82 | })), | |
| 83 | declined: deal.declined.map( | |
| 84 | (m) => `${m.party_name} · ${m.label}${live.has(m.deadline_id) ? "" : " (date removed)"}, due ${short(m.due)} · ${sentLabel(m.moment)} · declined by ${m.by_name} on ${spoken(m.at.slice(0, 10))}: ${m.reason}`, | |
| 85 | ), | |
| 86 | }; | |
| 87 | } | |
| 88 | ||
| 89 | export function filePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; deal: DealView }): string { | |
| 90 | const { who, deal } = input; | |
| 91 | const agent = input.agent ?? defaults; | |
| 92 | const path = `/deals/${deal.id}/file`; | |
| 93 | const r = fileRecord(deal); | |
| 94 | const list = (items: string): string => (items === "" ? `<p>None.</p>` : `<ul class="file-list">${items}</ul>`); | |
| 95 | const body = `<p class="crumb file-tools"><a href="/deals/${deal.id}">← Back to the deal</a> · <button type="button" class="button button-small" data-print hidden>Print</button> <span class="muted">or your browser's print (Ctrl/Cmd+P)</span></p> | |
| 96 | <section class="file"> | |
| 97 | <h1>${escape(deal.address)}</h1> | |
| 98 | <p class="summary">Broker file, prepared by ${escape(agent.name)}, ${escape(agent.brokerage)}</p> | |
| 99 | <dl class="file-facts">${r.facts.map(([k, v]) => `<div><dt>${escape(k)}</dt><dd>${escape(v)}</dd></div>`).join("")}</dl> | |
| 100 | <h2>Parties</h2>${list(r.parties.map((p) => `<li>${escape(p)}</li>`).join(""))} | |
| 101 | <h2>Dates</h2><ol class="file-list">${r.dates.map((d) => `<li>${escape(d.line)}${d.moves.map((m) => `<br><span class="file-move">${escape(m)}</span>`).join("")}</li>`).join("")}</ol> | |
| 102 | <h2>Messages approved</h2>${list(r.sent.map((m) => `<li>${escape(m.head)}${m.subject === "" ? `<p>The words were not kept for this one.</p>` : `<p><b>${escape(m.subject)}</b></p><p class="file-words">${escape(m.body)}</p>`}</li>`).join(""))} | |
| 103 | <h2>Messages declined</h2>${list(r.declined.map((d) => `<li>${escape(d)}</li>`).join(""))} | |
| 104 | </section> | |
| 105 | <script src="${asset("print.js")}"></script>`; | |
| 106 | return layout({ body, who, agent, waiting: input.waiting, path, heading: `Broker file · ${deal.address}`, plain: true, bodyClass: "file-page" }); | |
| 107 | } |
src/routes.ts +23 −16
| @@ -102,6 +102,7 @@ import { peoplePage } from "./pages/people.ts"; | ||
| 102 | 102 | import { activityPage } from "./pages/activity.ts"; |
| 103 | 103 | import { ACTIVITY_PAGE, addresses } from "./activity.ts"; |
| 104 | 104 | import { weekPage } from "./pages/week.ts"; |
| 105 | import { filePage } from "./pages/file.ts"; | |
| 105 | 106 | import { timelinePage } from "./pages/timeline.ts"; |
| 106 | 107 | import { welcomePage } from "./pages/welcome.ts"; |
| 107 | 108 | import { dueOn, remindsLine, todaysDrafts, unsent, waitingCount, type Agent, type Draft } from "./reminders.ts"; |
| @@ -460,6 +461,17 @@ const STATUS: Record<Failure, number> = { | ||
| 460 | 461 | const missingDeal = (c: Context) => |
| 461 | 462 | html(missingPage({ who: c.who, waiting: waitingFor(c), path: c.url.pathname, deal: true }), 404); |
| 462 | 463 | |
| 464 | /** The deal a page under `/deals/:id` shows, read through `permit`; else the response that refuses or says it is missing. */ | |
| 465 | function dealOrRefusal(c: Context): DealView | Response { | |
| 466 | const found = getDeal(c.db, c.who, { id: Number(c.params.id) }); | |
| 467 | if (found.ok) return found.value; | |
| 468 | if (found.error !== "signin_required" && found.error !== "forbidden") return missingDeal(c); | |
| 469 | return html( | |
| 470 | refusedPage({ who: c.who, agent: agentFor(c), path: c.url.pathname, heading: "A deal", error: found.error, message: found.message }), | |
| 471 | STATUS[found.error], | |
| 472 | ); | |
| 473 | } | |
| 474 | ||
| 463 | 475 | /** Whether a client wants JSON: anything under the API, or an `accept` that asks for it. */ |
| 464 | 476 | const wantsJson = (request: Request, url: URL): boolean => |
| 465 | 477 | url.pathname === "/api" || |
| @@ -841,22 +853,17 @@ export const routes: readonly Route[] = [ | ||
| 841 | 853 | method: "GET", |
| 842 | 854 | path: "/deals/:id/timeline", |
| 843 | 855 | handle: (c) => { |
| 844 | const found = getDeal(c.db, c.who, { id: Number(c.params.id) }); | |
| 845 | if (!found.ok && found.error !== "signin_required" && found.error !== "forbidden") | |
| 846 | return missingDeal(c); | |
| 847 | if (!found.ok) | |
| 848 | return html( | |
| 849 | refusedPage({ | |
| 850 | who: c.who, | |
| 851 | agent: agentFor(c), | |
| 852 | path: c.url.pathname, | |
| 853 | heading: "A deal", | |
| 854 | error: found.error, | |
| 855 | message: found.message, | |
| 856 | }), | |
| 857 | STATUS[found.error], | |
| 858 | ); | |
| 859 | return html(timelinePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: today() })); | |
| 856 | const found = dealOrRefusal(c); | |
| 857 | return found instanceof Response ? found : html(timelinePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found, on: today() })); | |
| 858 | }, | |
| 859 | }, | |
| 860 | { | |
| 861 | method: "GET", | |
| 862 | path: "/deals/:id/file", | |
| 863 | // The broker file: read as `deal` is read, and never the client's page. | |
| 864 | handle: (c) => { | |
| 865 | const found = dealOrRefusal(c); | |
| 866 | return found instanceof Response ? found : html(filePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found })); | |
| 860 | 867 | }, |
| 861 | 868 | }, |
| 862 | 869 | { |
src/speed.test.ts +1
| @@ -110,6 +110,7 @@ const routes: [string, () => string][] = [ | ||
| 110 | 110 | ["the deal list", () => "/api/deals"], |
| 111 | 111 | ["a deal page", () => `/deals/${firstId}`], |
| 112 | 112 | ["the client timeline", () => `/deals/${firstId}/timeline`], |
| 113 | ["the broker file", () => `/deals/${firstId}/file`], | |
| 113 | 114 | ["the printed week", () => "/week"], |
| 114 | 115 | ["the reminder review", () => "/reminders/today"], |
| 115 | 116 | ]; |
src/terminal.ts +27 −5
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * reminders what goes out today; enter reads a draft, e edits its words, s sends it; h holds it until tomorrow, H lists the held ones and B brings one back |
| 9 | 9 | * people each person on the deals with every open date they owe (P) |
| 10 | 10 | * timeline a deal's dates as a client would get them (t on a deal) |
| 11 | * file a deal's broker file: figures, parties, every date and message (f on a deal) | |
| 11 | 12 | * activity who approved, declined or changed what, newest first (L, admins); m only messages, o older, y newer |
| 12 | 13 | * profile your name, brokerage, phone, email and own line (I); e edits them, U goes back to the defaults |
| 13 | 14 | * deal one deal's dates and parties; a adds a date, p a party, A corrects the address, C sets the closing time and place, M amends the contract, S drafts a status update for the party under the cursor, D removes it, F marks it fell through (or brings it back), Y changes the side (buyer, listing or both) |
| @@ -23,6 +24,7 @@ import type { Database } from "bun:sqlite"; | ||
| 23 | 24 | import { bookLine, tally } from "./book.ts"; |
| 24 | 25 | import { closingLine } from "./closing.ts"; |
| 25 | 26 | import { timelineRows } from "./timeline.ts"; |
| 27 | import { fileRecord } from "./pages/file.ts"; | |
| 26 | 28 | import { isDate, relative, spoken, today, urgencyOf, type Urgency } from "./dates.ts"; |
| 27 | 29 | import { |
| 28 | 30 | addDeadline, |
| @@ -88,7 +90,7 @@ const ACTIVITY_ROWS = 20; | ||
| 88 | 90 | const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2", waived: "2" }; |
| 89 | 91 | const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`; |
| 90 | 92 | |
| 91 | type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline" | "profile" | "activity"; | |
| 93 | type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline" | "file" | "profile" | "activity"; | |
| 92 | 94 | interface Row { |
| 93 | 95 | readonly deal: DealView; |
| 94 | 96 | readonly date: DeadlineView; |
| @@ -562,7 +564,7 @@ export function terminal( | ||
| 562 | 564 | } |
| 563 | 565 | if (key === "j") cursor = Math.min(cursor + 1, Math.max(0, rowCount() - 1)); |
| 564 | 566 | else if (key === "k") cursor = Math.max(cursor - 1, 0); |
| 565 | else if ((view === "messages" || view === "timeline") && (key === "b" || key === "\x1b")) { | |
| 567 | else if ((view === "messages" || view === "timeline" || view === "file") && (key === "b" || key === "\x1b")) { | |
| 566 | 568 | view = "deal"; |
| 567 | 569 | cursor = 0; |
| 568 | 570 | reading = undefined; |
| @@ -570,6 +572,9 @@ export function terminal( | ||
| 570 | 572 | else if (view === "deal" && key === "t") { |
| 571 | 573 | view = "timeline"; |
| 572 | 574 | cursor = 0; |
| 575 | } else if (view === "deal" && key === "f") { | |
| 576 | view = "file"; | |
| 577 | cursor = 0; | |
| 573 | 578 | } else if (view === "deal" && key === "s") { |
| 574 | 579 | view = "messages"; |
| 575 | 580 | cursor = 0; |
| @@ -670,7 +675,7 @@ export function terminal( | ||
| 670 | 675 | } else if (view === "reminders") onReminder(key); |
| 671 | 676 | else if (view === "profile") onProfile(key); |
| 672 | 677 | else if (view === "activity") onActivity(key); |
| 673 | else if (view === "messages" || view === "timeline") return; | |
| 678 | else if (view === "messages" || view === "timeline" || view === "file") return; | |
| 674 | 679 | else if (!(view === "deal" && onDeal(key))) onDate(key); |
| 675 | 680 | cursor = Math.min(cursor, Math.max(0, rowCount() - 1)); |
| 676 | 681 | } |
| @@ -807,6 +812,23 @@ export function terminal( | ||
| 807 | 812 | r.todo.forEach((g) => lines.push(` ${dim(`${g.label === "" ? "" : `${g.label}: `}${g.line}`)}`)); |
| 808 | 813 | }); |
| 809 | 814 | } |
| 815 | } else if (view === "file") { | |
| 816 | const deal = openDeal(); | |
| 817 | if (deal === undefined) lines.push(dim("That deal is gone.")); | |
| 818 | else { | |
| 819 | const r = fileRecord(deal); | |
| 820 | lines.push(bold(`Broker file — ${deal.address}`), dim(`${agentNow().name}, ${agentNow().brokerage}`), ""); | |
| 821 | r.facts.forEach(([k, v]) => lines.push(` ${k.padEnd(22)} ${v}`)); | |
| 822 | lines.push("", bold("Parties"), ...r.parties.map((p) => ` ${p}`)); | |
| 823 | lines.push("", bold("Dates")); | |
| 824 | r.dates.forEach((d) => lines.push(` ${d.line}`, ...d.moves.map((m) => dim(` ${m}`)))); | |
| 825 | lines.push("", bold("Messages approved")); | |
| 826 | if (r.sent.length === 0) lines.push(" None."); | |
| 827 | r.sent.forEach((m) => lines.push(` ${m.head}`, ...(m.subject === "" ? [dim(" (words not kept)")] : [` ${m.subject}`, ...m.body.split("\n").map((l) => ` ${l}`)]))); | |
| 828 | lines.push("", bold("Messages declined")); | |
| 829 | if (r.declined.length === 0) lines.push(" None."); | |
| 830 | r.declined.forEach((d) => lines.push(` ${d}`)); | |
| 831 | } | |
| 810 | 832 | } else if (view === "deal") { |
| 811 | 833 | const deal = openDeal(); |
| 812 | 834 | if (deal === undefined) lines.push(dim("That deal is gone.")); |
| @@ -854,10 +876,10 @@ export function terminal( | ||
| 854 | 876 | : "j/k move · enter read · e edit · s send · n don't send · h tomorrow · u undo · H held · / find · d dates · q quit" |
| 855 | 877 | : view === "messages" |
| 856 | 878 | ? "j/k move · enter read · b back to the deal · d dates · q quit" |
| 857 | : view === "timeline" | |
| 879 | : view === "timeline" || view === "file" | |
| 858 | 880 | ? "b back to the deal · d dates · q quit" |
| 859 | 881 | : view === "deal" |
| 860 | ? "j/k move · t client timeline · s messages · x done · W waive · u reopen/un-waive · m move · N next business day · l remind lead · T note · a add date · p add party · e edit party · A edit address · C closing time and place · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit" | |
| 882 | ? "j/k move · t client timeline · f broker file · s messages · x done · W waive · u reopen/un-waive · m move · N next business day · l remind lead · T note · a add date · p add party · e edit party · A edit address · C closing time and place · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit" | |
| 861 | 883 | : `j/k move · x done · W waive · u reopen · m move · N next business day · l lead · T note · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · P people · I profile · L activity · q quit`; |
| 862 | 884 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 863 | 885 | } |
src/timeline.test.ts +2 −2
| @@ -56,7 +56,7 @@ test("has no forms, scripts, contacts or removed dates, and escapes the address" | ||
| 56 | 56 | |
| 57 | 57 | test("the print rules are scoped to the timeline page", async () => { |
| 58 | 58 | const css = await Bun.file(join(import.meta.dir, "..", "static", "app.css")).text(); |
| 59 | const print = css.slice(css.indexOf("@media print")); | |
| 59 | const print = css.slice(css.indexOf("@media print"), css.indexOf("/* The broker file")); | |
| 60 | 60 | const selectors = [...print.matchAll(/^\s*([^{}@\n]+)\{/gm)].map((m) => m[1]!.trim()); |
| 61 | 61 | expect(selectors.length).toBeGreaterThan(0); |
| 62 | 62 | for (const sel of selectors) for (const part of sel.split(",")) expect(part.trim()).toStartWith(".timeline-page"); |
| @@ -89,7 +89,7 @@ test("offers Print from a static script, with no inline script or handler", asyn | ||
| 89 | 89 | const js = await Bun.file(join(import.meta.dir, "..", "static", "print.js")).text(); |
| 90 | 90 | expect(js).toContain("window.print()"); |
| 91 | 91 | const css = await Bun.file(join(import.meta.dir, "..", "static", "app.css")).text(); |
| 92 | const print = css.slice(css.indexOf("@media print")); | |
| 92 | const print = css.slice(css.indexOf("@media print"), css.indexOf("/* The broker file")); | |
| 93 | 93 | expect(print).toContain("break-inside: avoid"); |
| 94 | 94 | expect(print).toContain(".timeline-tools"); |
| 95 | 95 | expect(print).toContain(".toast"); |
static/app.css +47
| @@ -1028,3 +1028,50 @@ a.marker { | ||
| 1028 | 1028 | margin: 15mm; |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | ||
| 1032 | /* The broker file: plain figures and lists on the screen; on paper, black on white with no tools. */ | |
| 1033 | .file-facts { | |
| 1034 | display: grid; | |
| 1035 | grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); | |
| 1036 | gap: var(); | |
| 1037 | margin: var() 0; | |
| 1038 | } | |
| 1039 | .file-facts dt { | |
| 1040 | font-weight: 600; | |
| 1041 | } | |
| 1042 | .file-facts dd { | |
| 1043 | margin: 0; | |
| 1044 | } | |
| 1045 | .file-list { | |
| 1046 | padding-inline-start: var(); | |
| 1047 | } | |
| 1048 | .file-list li { | |
| 1049 | margin-bottom: var(); | |
| 1050 | } | |
| 1051 | .file-words { | |
| 1052 | white-space: pre-wrap; | |
| 1053 | } | |
| 1054 | @media print { | |
| 1055 | .file-page { | |
| 1056 | background: white; | |
| 1057 | color: black; | |
| 1058 | font-size: 10pt; | |
| 1059 | } | |
| 1060 | .file-page .head, | |
| 1061 | .file-page footer, | |
| 1062 | .file-page .file-tools, | |
| 1063 | .file-page .toast { | |
| 1064 | display: none; | |
| 1065 | } | |
| 1066 | .file-page .page { | |
| 1067 | max-width: none; | |
| 1068 | padding: 0; | |
| 1069 | } | |
| 1070 | .file-page .file-list li { | |
| 1071 | break-inside: avoid; | |
| 1072 | } | |
| 1073 | .file-page h2 { | |
| 1074 | break-after: avoid; | |
| 1075 | font-size: 1rem; | |
| 1076 | } | |
| 1077 | } |
new above
offline
Duplicate import from ../http.ts: merge with
escapeon line 16.