Public: anyone can read this; the crew can change it.

A signed-in Tour page walks the sample deals step by step, each step linking straight to the place it names #277

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/deal-clock:mason/275-a-signed-in-tour-page-walks-the-sample-d → main 6 commits fork

  • Merged. mason/275-a-signed-in-tour-page-walks-the-sample-d was merged into main as 233e341.

Review

Sign in to review this change.
21 files changed +395 −69
README.md +3
@@ -18,6 +18,9 @@ weekend or a federal holiday. The samples stay current: every time the
1818 app starts, the ones nobody has touched move forward so the screen always
1919 looks like today.
2020
21 Signed in, the same steps are in the app under **Tour** in the header, each
22 with a link to the page it names. In the terminal press `G` for the same steps.
23
2124 1. **Sign in.** Tap **Sign in** on the first page and use your forge account.
2225 Until you do, you see only what deal-clock does and a still picture of a
2326 made-up deal; no real deal is read. Once in, you land on the clock with
docs/TECHNICAL.md +2
@@ -167,6 +167,8 @@ deal (`b` goes back). Its print rules in `static/app.css` apply to that page onl
167167
168168 `GET /week[?q=]` is This week as a printable sheet (`src/pages/week.ts`; rows and day grouping from `src/week.ts`, shared with the clock's card): `deal` list through `permit`, a sign-in answer signed out, 400 for a bad `q`. It reuses the timeline's print rules.
169169
170 `GET /tour` is the README's five-minute tour as a numbered list for a signed-in viewer (a `deal` list read through `permit`; guests are asked to sign in): the steps live in `src/tour.ts` and a test holds the README to them, `src/pages/tour.ts` renders them, each linking to the sample deal it names by address, or saying the deal was removed. The header's Tour link shows only while the viewer has a sample deal, on every page that has a header (the printed timeline and week sheets have none). The terminal's `G` view lists the same `STEPS` with the same `listDeals` read.
171
170172 `GET /people` (and `GET /api/people`, described in `openapi.json` under the `deal` list cell) groups every party on the deals the viewer may list into people — parties with the same contact, trimmed and case-insensitive, are one, under the newest name — each with the open dates they owe (`src/people.ts`, pure). Dates of a closed deal are not listed. The terminal's `P` view shows the same.
171173
172174 `GET /api/book` (the `deal` list cell) gives the totals the clock's book line shows, as numbers: `open`, `under_contract`, `closing_this_month`, `closed_this_year`, `closed_volume`, `without_price` (`src/book.ts`, pure). Fell-through deals count in none; a closed deal counts on its closing date.
docs/design/areas/tour.md added +7
@@ -0,0 +1,7 @@
1 # Tour
2
3 Classes on `/tour`, the numbered walk through the sample deals. Links reuse `.button` and `.button-quiet`.
4
5 - `.tour-list` — the ordered list of steps; keeps its numbers, no layout shift.
6 - `.tour-step` — one step: a small heading, its words, then `.tour-go`.
7 - `.tour-go` — the line under a step holding its link, or the muted reason there is none.
src/contract.test.ts +10
@@ -156,6 +156,16 @@ test("restoring the samples answers as the table says for the cells it exercises
156156 expect(mayRestore({ role: "user", id: "u", name: "u" }).ok).toBe(false);
157157 });
158158
159 test("the Tour, at GET /tour, answers as deal list says, as every identity", async () => {
160 const { tourPage } = await import("./pages/tour.ts");
161 for (const identity of identities(contract)) {
162 const who = whoIs(identity);
163 const said = `tour as ${identity}`;
164 expect([said, listDeals(db, who).ok]).toEqual([said, permit(who, "deal", "list") !== "no"]);
165 }
166 expect(tourPage({ who: whoIs("user"), deals: [] })).toContain("tour-list");
167 });
168
159169 test("People, at the page, GET /api/people and list_people, answers as deal list says, as every identity", () => {
160170 for (const identity of identities(contract)) {
161171 const who = whoIs(identity);
src/pages/activity.ts +3 −1
@@ -18,6 +18,8 @@ export function activityPage(input: {
1818 who: Who;
1919 agent?: Agent | undefined;
2020 waiting?: number | undefined;
21 /** Whether the viewer has the sample deals: the header offers the Tour. */
22 tour?: boolean | undefined;
2123 db: Database;
2224 /** Up to one more than a page: the extra says there are older rows. */
2325 rows: readonly AuditRow[];
@@ -49,5 +51,5 @@ export function activityPage(input: {
4951 ${rows.length === 0 ? `<p class="muted">Nothing yet.</p>` : `<ul class="stack">${rows.map(line).join("")}</ul>`}
5052 ${next}
5153 ${permit(who, "audit", "list") === "yes" ? `<p><a class="button button-quiet" href="/activity.csv${only ? "?only=messages" : ""}">Download spreadsheet</a></p>` : ""}`;
52 return layout({ body, who, agent, waiting: input.waiting, path: "/activity", heading: "Activity", live: false });
54 return layout({ body, who, agent, waiting: input.waiting, tour: input.tour, path: "/activity", heading: "Activity", live: false });
5355 }
src/pages/clock.ts +6 −2
@@ -145,6 +145,8 @@ export function clock(input: {
145145 who: Who;
146146 /** How many of today's messages wait for approval, for the header. */
147147 waiting?: number | undefined;
148 /** Whether the viewer has the sample deals: the header offers the Tour. */
149 tour?: boolean | undefined;
148150 agent?: Agent | undefined;
149151 deals: readonly DealView[];
150152 on: string;
@@ -154,7 +156,7 @@ export function clock(input: {
154156 side?: SideFilter | undefined;
155157 }): string {
156158 const key = Bun.hash(
157 JSON.stringify([input.who, input.on, input.notice ?? null, input.open ?? null, input.q ?? "", input.side ?? "", input.agent, input.waiting]) +
159 JSON.stringify([input.who, input.on, input.notice ?? null, input.open ?? null, input.q ?? "", input.side ?? "", input.agent, input.waiting, input.tour]) +
158160 input.deals.map(print).join(),
159161 );
160162 return pages(`${input.deals.length}:${key}`, () => render(input));
@@ -164,6 +166,8 @@ function render(input: {
164166 who: Who;
165167 /** How many of today's messages wait for approval, for the header. */
166168 waiting?: number | undefined;
169 /** Whether the viewer has the sample deals: the header offers the Tour. */
170 tour?: boolean | undefined;
167171 agent?: Agent | undefined;
168172 deals: readonly DealView[];
169173 on: string;
@@ -267,5 +271,5 @@ function render(input: {
267271 }
268272 <p class="muted small">Each date reminds its parties a few days before (three unless you set another, per date) and the morning of, and the one who owes a date is asked for an update the morning after it slips. Send records your approval and opens your own Mail or Messages with the words.</p>
269273 </section>`}`;
270 return layout({ body, who, agent, waiting: input.waiting, path: "/", notice, open: opened?.hrefs });
274 return layout({ body, who, agent, waiting: input.waiting, tour: input.tour, path: "/", notice, open: opened?.hrefs });
271275 }
src/pages/deal.ts +6 −2
@@ -232,6 +232,8 @@ export function dealPage(input: {
232232 who: Who;
233233 /** How many of today's messages wait for approval, for the header. */
234234 waiting?: number | undefined;
235 /** Whether the viewer has the sample deals: the header offers the Tour. */
236 tour?: boolean | undefined;
235237 agent?: Agent | undefined;
236238 deal: DealView;
237239 on: string;
@@ -413,7 +415,7 @@ export function dealPage(input: {
413415 })
414416 : ""
415417 }`;
416 return layout({ body, who, agent, sheets: false, waiting: input.waiting, path, heading: deal.address, notice, open: opened?.hrefs });
418 return layout({ body, who, agent, sheets: false, waiting: input.waiting, tour: input.tour, path, heading: deal.address, notice, open: opened?.hrefs });
417419 }
418420
419421 /** What the form was last sent with, what was wrong with it, and the dates it would make. */
@@ -443,6 +445,8 @@ export function newDealPage(input: {
443445 who: Who;
444446 /** How many of today's messages wait for approval, for the header. */
445447 waiting?: number | undefined;
448 /** Whether the viewer has the sample deals: the header offers the Tour. */
449 tour?: boolean | undefined;
446450 agent?: Agent | undefined;
447451 on: string;
448452 notice?: string | undefined;
@@ -515,7 +519,7 @@ export function newDealPage(input: {
515519 <p class="muted small">Reading these from the contract PDF is phase two.</p>
516520 </section>
517521 ${state?.preview === undefined ? "" : previewList(state.preview)}`;
518 return layout({ body, who, agent, waiting: input.waiting, path: "/deals/new", heading: "New deal", notice });
522 return layout({ body, who, agent, waiting: input.waiting, tour: input.tour, path: "/deals/new", heading: "New deal", notice });
519523 }
520524
521525 /** Mark the deal fell through (asks once, takes the reason), or bring it back. */
src/pages/file.ts +2 −2
@@ -88,7 +88,7 @@ export function fileRecord(deal: DealView): FileRecord {
8888 };
8989 }
9090
91 export function filePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; deal: DealView }): string {
91 export function filePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; tour?: boolean | undefined; deal: DealView }): string {
9292 const { who, deal } = input;
9393 const agent = input.agent ?? defaults;
9494 const path = `/deals/${deal.id}/file`;
@@ -105,5 +105,5 @@ export function filePage(input: { who: Who; agent?: Agent | undefined; waiting?:
105105 <h2>Messages declined</h2>${list(r.declined.map((d) => `<li>${escape(d)}</li>`).join(""))}
106106 </section>
107107 <script src="${asset("print.js")}"></script>`;
108 return layout({ body, who, agent, waiting: input.waiting, path, heading: `Broker file · ${deal.address}`, plain: true, bodyClass: "file-page" });
108 return layout({ body, who, agent, waiting: input.waiting, tour: input.tour, path, heading: `Broker file · ${deal.address}`, plain: true, bodyClass: "file-page" });
109109 }
src/pages/layout.ts +4 −2
@@ -43,6 +43,8 @@ export function layout(input: {
4343 open?: readonly string[] | undefined;
4444 /** How many of today's messages wait for approval; the header's Review link says so, and is left out when the count is not known. */
4545 waiting?: number | undefined;
46 /** Whether the viewer has the sample deals: the header offers the Tour. */
47 tour?: boolean | undefined;
4648 /** Whether the page keeps its regions live; false for a page with none. */
4749 live?: boolean;
4850 /** Whether the page has dates that open a sheet in place; false for a page that shows its sheets already. */
@@ -52,7 +54,7 @@ export function layout(input: {
5254 /** A class on <body>, for styles that belong to one page only. */
5355 bodyClass?: string;
5456 }): string {
55 const { body, who, agent = defaults, path, notice, open, plain = false, bodyClass, waiting } = input;
57 const { body, who, agent = defaults, path, notice, open, plain = false, bodyClass, waiting, tour = false } = input;
5658 const pageTitle = input.heading === undefined ? title : `${input.heading} · ${title}`;
5759 const to = encodeURIComponent(path);
5860 const door =
@@ -96,7 +98,7 @@ ${plain || input.live === false ? "" : `<script type="module" src="${asset("live
9698 ? ""
9799 : `<nav class="row">
98100 ${env === "production" ? "" : `<span class="pill" data-env="${escape(env)}">${escape(where)}</span>`}
99 ${who.role === "anon" ? "" : `<a class="button button-quiet" href="/">Clock</a> <a class="button button-quiet" href="/people">People</a> ${waiting === undefined ? "" : `${reviewLink(waiting)} `}<a class="button button-quiet" href="/profile">Profile</a>${permit(who, "audit", "list") === "yes" ? ` <a class="button button-quiet" href="/activity">Activity</a>` : ""}`}
101 ${who.role === "anon" ? "" : `<a class="button button-quiet" href="/">Clock</a> <a class="button button-quiet" href="/people">People</a> ${tour ? `<a class="button button-quiet" href="/tour">Tour</a> ` : ""}${waiting === undefined ? "" : `${reviewLink(waiting)} `}<a class="button button-quiet" href="/profile">Profile</a>${permit(who, "audit", "list") === "yes" ? ` <a class="button button-quiet" href="/activity">Activity</a>` : ""}`}
100102 ${door}
101103 </nav>`
102104 }
src/pages/missing.ts +2 −2
@@ -8,7 +8,7 @@
88 import type { Who } from "../who.ts";
99 import { layout } from "./layout.ts";
1010
11 export function missingPage(input: { who: Who; path: string; deal?: boolean; waiting?: number | undefined }): string {
11 export function missingPage(input: { who: Who; path: string; deal?: boolean; waiting?: number | undefined; tour?: boolean | undefined }): string {
1212 const { who, path, deal = false } = input;
1313 const sentence = deal
1414 ? "This deal is not here; it may have been removed."
@@ -18,5 +18,5 @@ export function missingPage(input: { who: Who; path: string; deal?: boolean; wai
1818 ? `<a class="button" href="/__forge/signin?to=${encodeURIComponent("/")}">Sign in</a>`
1919 : `<a class="button" href="/">Back to the clock</a>`;
2020 const body = `<section class="card narrow"><h1>Nothing here</h1><p>${sentence}</p><p>${way}</p></section>`;
21 return layout({ body, who, path, heading: "Nothing here", live: false, waiting: input.waiting });
21 return layout({ body, who, path, heading: "Nothing here", live: false, waiting: input.waiting, tour: input.tour });
2222 }
src/pages/people.ts +2 −2
@@ -29,7 +29,7 @@ const person = (p: Person, on: string): string => `<section class="card person">
2929 ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`}
3030 </section>`;
3131
32 export function peoplePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; people: readonly Person[]; on: string; q?: string }): string {
32 export function peoplePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; tour?: boolean | undefined; people: readonly Person[]; on: string; q?: string }): string {
3333 const { who, people, on } = input;
3434 const q = input.q ?? "";
3535 const body = `<h1>People</h1>
@@ -40,5 +40,5 @@ export function peoplePage(input: { who: Who; agent?: Agent | undefined; waiting
4040 <button class="btn" type="submit">Find</button>
4141 </form>
4242 ${people.length === 0 ? (q !== "" ? `<p class="muted">No one matches “${escape(q)}”. <a href="/people">Clear</a></p>` : `<p class="muted">No one yet: add a deal and its parties.</p>`) : people.map((p) => person(p, on)).join("")}`;
43 return layout({ body, who, agent: input.agent, waiting: input.waiting, path: "/people", heading: "People", live: false });
43 return layout({ body, who, agent: input.agent, waiting: input.waiting, tour: input.tour, path: "/people", heading: "People", live: false });
4444 }
src/pages/profile.ts +5 −3
@@ -20,6 +20,8 @@ export function profilePage(input: {
2020 who: Who;
2121 /** How many of today's messages wait for approval, for the header. */
2222 waiting?: number | undefined;
23 /** Whether the viewer has the sample deals: the header offers the Tour. */
24 tour?: boolean | undefined;
2325 profile: Profile;
2426 /** Whether the table lets `who` save it. */
2527 mayChange: boolean;
@@ -81,11 +83,11 @@ export function profilePage(input: {
8183 <p class="small"><a href="/deals/export.json" download>Download all my deals</a> <span class="muted">One file with every deal you can read: dates, parties, notes, moves and the words of every message sent.</span></p>
8284 ${bringBack}
8385 </section>`;
84 return layout({ body, who, agent, path: "/profile", heading: "Profile", notice, waiting: input.waiting, live: false });
86 return layout({ body, who, agent, path: "/profile", heading: "Profile", notice, waiting: input.waiting, tour: input.tour, live: false });
8587 }
8688
8789 /** The answer to a file brought back: what came, what was already here, and what is never re-created. */
88 export function broughtBackPage(input: { who: Who; waiting?: number | undefined; agent?: Agent | undefined; brought: number; skipped: number }): string {
90 export function broughtBackPage(input: { who: Who; waiting?: number | undefined; tour?: boolean | undefined; agent?: Agent | undefined; brought: number; skipped: number }): string {
8991 const n = (count: number): string => `${count} deal${count === 1 ? "" : "s"}`;
9092 const body = `<section class="card narrow">
9193 <h1>Bring deals back from a file</h1>
@@ -93,5 +95,5 @@ export function broughtBackPage(input: { who: Who; waiting?: number | undefined;
9395 <p class="muted">The record of messages sent or declined is not brought back, so nothing here says a message went out from this account.</p>
9496 <p><a class="button" href="/">Go to the clock</a></p>
9597 </section>`;
96 return layout({ body, who: input.who, agent: input.agent, path: "/profile", heading: "Bring deals back from a file", waiting: input.waiting, live: false });
98 return layout({ body, who: input.who, agent: input.agent, path: "/profile", heading: "Bring deals back from a file", waiting: input.waiting, tour: input.tour, live: false });
9799 }
src/pages/refused.ts +3 −1
@@ -14,6 +14,8 @@ export function refusedPage(input: {
1414 who: Who;
1515 agent?: Agent | undefined;
1616 waiting?: number | undefined;
17 /** Whether the viewer has the sample deals: the header offers the Tour. */
18 tour?: boolean | undefined;
1719 path: string;
1820 heading: string;
1921 error: Failure;
@@ -24,5 +26,5 @@ export function refusedPage(input: {
2426 error === "signin_required"
2527 ? `<section class="card narrow"><h1>${escape(heading)}</h1><p>${escape(message)}</p><p><a class="button" href="/__forge/signin?to=${encodeURIComponent(path)}">Sign in</a></p></section>`
2628 : `<section class="card narrow"><h1>${escape(heading)}</h1><p>${escape(message)} <a href="/">Back to the clock</a>.</p></section>`;
27 return layout({ body, who, agent, path, heading, waiting: input.waiting });
29 return layout({ body, who, agent, path, heading, waiting: input.waiting, tour: input.tour });
2830 }
src/pages/review.ts +3 −1
@@ -54,6 +54,8 @@ export function reviewPage(input: {
5454 who: Who;
5555 /** How many of today's messages wait for approval, for the header. */
5656 waiting?: number | undefined;
57 /** Whether the viewer has the sample deals: the header offers the Tour. */
58 tour?: boolean | undefined;
5759 agent?: Agent | undefined;
5860 /** The drafts still to send, in the clock's order. */
5961 queue: readonly Draft[];
@@ -79,7 +81,7 @@ export function reviewPage(input: {
7981 draft === undefined
8082 ? `<section class="card narrow"><h1>Review today's reminders</h1><p>${input.settled === undefined || settledLine(input.settled) === "" ? "All of today's reminders are sent or declined." : `All of today's reminders are sent or declined. ${escape(settledLine(input.settled))}`}</p>${nextLine(input.next)}<p>${back}</p></section>`
8183 : form(draft, { q, at, done, position: done + at + 1, total: done + queue.length, error, typed }, back);
82 return layout({ body, who, agent, waiting: input.waiting, path: REVIEW_PATH, heading: "Review today's reminders", notice: input.notice, open: input.open, live: false });
84 return layout({ body, who, agent, waiting: input.waiting, tour: input.tour, path: REVIEW_PATH, heading: "Review today's reminders", notice: input.notice, open: input.open, live: false });
8385 }
8486
8587 /** "Next: Thu Nov 12, Financing reminder to Priya Nair, 9 Orchard Row", linked to the deal; nothing when nothing is coming. */
src/pages/tour.ts added +33
@@ -0,0 +1,33 @@
1 /**
2 * The tour, at `/tour`: the README's five-minute walk as a numbered list,
3 * each step linking to the place it names. Server-rendered, no script.
4 */
5
6 import { escape } from "../http.ts";
7 import { linkFor, STEPS } from "../tour.ts";
8 import type { Agent } from "../reminders.ts";
9 import type { Who } from "../who.ts";
10 import { layout } from "./layout.ts";
11
12 /** A step's words with **bold** and `code` marked up, after escaping everything else. */
13 const words = (text: string): string => escape(text).replace(/\*\*([^*]+)\*\*/g, "<b>$1</b>").replace(/`([^`]+)`/g, "<code>$1</code>");
14
15 export function tourPage(input: {
16 who: Who;
17 agent?: Agent | undefined;
18 waiting?: number | undefined;
19 deals: readonly { id: number; address: string }[];
20 }): string {
21 const items = STEPS.map((s) => {
22 const href = linkFor(s.go, input.deals);
23 const where =
24 href === null
25 ? `<p class="tour-go muted">${escape(s.go.label)}: this sample deal was removed, so there is no page to open.</p>`
26 : `<p class="tour-go"><a class="button button-quiet" href="${escape(href)}">Go to ${escape(s.go.label)}</a></p>`;
27 return `<li class="tour-step"><h2>${escape(s.title)}</h2><p>${words(s.text)}</p>${where}</li>`;
28 }).join("");
29 const body = `<h1>Tour</h1>
30 <p class="summary">Five minutes on the sample deals. Each step has a link to the page it names.</p>
31 <ol class="tour-list">${items}</ol>`;
32 return layout({ body, who: input.who, agent: input.agent, waiting: input.waiting, tour: true, path: "/tour", heading: "Tour", live: false });
33 }
src/routes.ts +59 −50
@@ -105,6 +105,8 @@ import { knownPeople, narrowPeople, people } from "./people.ts";
105105 import { settledOn } from "./settled.ts";
106106 import { reviewHref, reviewPage, type ReviewError, type ReviewField } from "./pages/review.ts";
107107 import { peoplePage } from "./pages/people.ts";
108 import { tourPage } from "./pages/tour.ts";
109 import { hasTourDeals } from "./tour.ts";
108110 import { activityPage } from "./pages/activity.ts";
109111 import { ACTIVITY_PAGE, addresses } from "./activity.ts";
110112 import { weekPage } from "./pages/week.ts";
@@ -536,7 +538,7 @@ const STATUS: Record<Failure, number> = {
536538
537539 /** A deal that is not there, for a reader who may read deals: the product's own 404. */
538540 const missingDeal = (c: Context) =>
539 html(missingPage({ who: c.who, waiting: waitingFor(c), path: c.url.pathname, deal: true }), 404);
541 html(missingPage({ who: c.who, ...headerFor(c), path: c.url.pathname, deal: true }), 404);
540542
541543 /** The deal a page under `/deals/:id` shows, read through `permit`; else the response that refuses or says it is missing. */
542544 function dealOrRefusal(c: Context): DealView | Response {
@@ -558,7 +560,7 @@ const wantsJson = (request: Request, url: URL): boolean =>
558560 /** No route matched: JSON for an API client, the product's page for a person. */
559561 export function notFound(request: Request, url: URL, who: Who, db: Database): Response {
560562 if (wantsJson(request, url)) return json({ error: "not_found" }, 404);
561 return html(missingPage({ who, waiting: waitingIn(db, who, agentOf(db)), path: url.pathname }), 404);
563 return html(missingPage({ who, ...headerIn(db, who, agentOf(db)), path: url.pathname }), 404);
562564 }
563565
564566 /** A result as JSON: the value, or `{ error, message }` with the matching status. */
@@ -621,16 +623,13 @@ function agentFor(c: Context): Agent {
621623 return agent;
622624 }
623625
624 /**
625 * What the header's Review link says: today's drafts waiting for approval,
626 * among the deals this person may list, counted as the review page counts them.
627 */
628 function waitingIn(db: Database, who: Who, agent: Agent): number {
629 if (who.role === "anon") return 0;
626 /** What the header needs beyond the agent: the Review count (today's drafts waiting for approval, counted as the review page counts them), and whether the viewer has the sample deals the Tour walks. */
627 function headerIn(db: Database, who: Who, agent: Agent): { waiting: number; tour: boolean } {
628 if (who.role === "anon") return { waiting: 0, tour: false };
630629 const deals = listDeals(db, who);
631 return deals.ok ? waitingCount(deals.value, dayOf(agent), agent) : 0;
630 return { waiting: deals.ok ? waitingCount(deals.value, dayOf(agent), agent) : 0, tour: deals.ok && hasTourDeals(deals.value) };
632631 }
633 const waitingFor = (c: Context): number => waitingIn(c.db, c.who, agentFor(c));
632 const headerFor = (c: Context) => headerIn(c.db, c.who, agentFor(c));
634633
635634 /** A small count from the query or a form, or 0. */
636635 const count = (value: unknown): number => (typeof value === "string" && /^\d{1,4}$/.test(value) ? Number(value) : 0);
@@ -652,7 +651,7 @@ async function reviewed(c: Context, act: (f: Record<string, string>) => Result<{
652651 const result = act(f);
653652 if (result.ok) return back(said, reviewHref(q, at, settled + 1), said === SENT ? result.value.id : undefined);
654653 if (result.error === "signin_required" || result.error === "forbidden")
655 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]);
654 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]);
656655 const shown = sameDraft(c, f, q, settled, result.error === "invalid" ? { field: fieldOf(result.message), message: result.message } : undefined);
657656 if (result.error !== "invalid" || shown === undefined) return back(result.message, reviewHref(q, at, settled));
658657 return html(shown, STATUS.invalid);
@@ -666,7 +665,7 @@ function sameDraft(c: Context, f: Record<string, string>, q: string, settled: nu
666665 : -1;
667666 if (!queue.ok || same === -1) return undefined;
668667 const typed = { subject: f.subject ?? "", body: f.body ?? "", reason: f.reason ?? "", email: f.email ?? "", phone: f.phone ?? "" };
669 return reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: same, done: settled, error, typed });
668 return reviewPage({ who: c.who, ...headerFor(c), agent: agentFor(c), queue: queue.value, q, at: same, done: settled, error, typed });
670669 }
671670
672671 /**
@@ -686,7 +685,7 @@ async function reviewedContact(c: Context): Promise<Response> {
686685 ? { ok: false, error: "invalid", message: "Add an email or phone to save." }
687686 : editParty(c.db, c.who, { id: party, name: nameOf(c.db, "party", party), email: f.email, phone: f.phone });
688687 if (!result.ok && (result.error === "signin_required" || result.error === "forbidden"))
689 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]);
688 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: reviewHref(q, at, settled), heading: "Review today's reminders", error: result.error, message: result.message }), STATUS[result.error]);
690689 const shown = sameDraft(c, f, q, settled, result.ok ? undefined : { field: "contact", message: result.message });
691690 if (shown === undefined) return back(result.ok ? "Contact saved." : result.message, reviewHref(q, at, settled));
692691 return html(shown, result.ok ? 200 : STATUS.invalid);
@@ -701,7 +700,7 @@ function partyRefused(c: Context, dealId: number, id: number | "new", f: Record<
701700 const found = getDeal(c.db, c.who, { id: dealId });
702701 if (!found.ok) return back(found.message, `/deals/${dealId}`);
703702 const party = { id, role: f.role ?? "", name: f.name ?? "", email: f.email ?? "", phone: f.phone ?? "", message };
704 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), party }), STATUS.invalid);
703 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), party }), STATUS.invalid);
705704 }
706705
707706 const SENT = "Reminder sent.";
@@ -756,11 +755,11 @@ export const routes: readonly Route[] = [
756755 path: "/",
757756 handle: (c) => {
758757 const { notice, open, clear } = readNotice(c.request);
759 if (c.who.role === "anon") return html(welcomePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)) }), 200, clear);
758 if (c.who.role === "anon") return html(welcomePage({ who: c.who, agent: agentFor(c), on: dayOf(agentFor(c)) }), 200, clear);
760759 const deals = listDeals(c.db, c.who);
761760 if (!deals.ok)
762761 return html(
763 refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/", heading: "The clock", error: deals.error, message: deals.message }),
762 refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/", heading: "The clock", error: deals.error, message: deals.message }),
764763 200,
765764 clear,
766765 );
@@ -781,7 +780,7 @@ export const routes: readonly Route[] = [
781780 const side = sideFilter(c.url.searchParams.get("side"));
782781 if (side === undefined)
783782 return html(refusedPage({ who: c.who, agent: agentFor(c), path: "/", heading: "The clock", error: "invalid", message: SIDE_REFUSAL }), 422, clear);
784 return html(clock({ who: c.who, waiting: waitingCount(deals.value, dayOf(agentFor(c)), agentFor(c)), agent: agentFor(c), deals: deals.value, on: dayOf(agentFor(c)), notice, open, q, side }), 200, clear);
783 return html(clock({ who: c.who, waiting: waitingCount(deals.value, dayOf(agentFor(c)), agentFor(c)), tour: hasTourDeals(deals.value), agent: agentFor(c), deals: deals.value, on: dayOf(agentFor(c)), notice, open, q, side }), 200, clear);
785784 },
786785 },
787786 {
@@ -806,6 +805,16 @@ export const routes: readonly Route[] = [
806805 return html(weekPage({ who: c.who, agent: agentFor(c), deals: onSide(find(deals.value, q), side), on: dayOf(agentFor(c)), q, side }));
807806 },
808807 },
808 {
809 method: "GET",
810 path: "/tour",
811 handle: (c) => {
812 const deals = listDeals(c.db, c.who);
813 if (!deals.ok) return html(refusedPage({ who: c.who, agent: agentFor(c), path: "/tour", heading: "Tour", error: deals.error, message: deals.message }), STATUS[deals.error]);
814 const agent = agentFor(c);
815 return html(tourPage({ who: c.who, waiting: waitingCount(deals.value, dayOf(agent), agent), agent, deals: deals.value }));
816 },
817 },
809818 {
810819 method: "GET",
811820 path: "/people",
@@ -813,14 +822,14 @@ export const routes: readonly Route[] = [
813822 const deals = listDeals(c.db, c.who);
814823 if (!deals.ok)
815824 return html(
816 refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/people", heading: "People", error: deals.error, message: deals.message }),
825 refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/people", heading: "People", error: deals.error, message: deals.message }),
817826 STATUS[deals.error],
818827 );
819828 const q = query(c.url.searchParams.get("q"));
820829 if (q === undefined)
821 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/people", heading: "People", error: "invalid", message: FIND_REFUSAL }), 400);
830 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/people", heading: "People", error: "invalid", message: FIND_REFUSAL }), 400);
822831 const everyone = people(deals.value, dayOf(agentFor(c)));
823 return html(peoplePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), people: narrowPeople(everyone, q), on: dayOf(agentFor(c)), q }));
832 return html(peoplePage({ who: c.who, ...headerFor(c), agent: agentFor(c), people: narrowPeople(everyone, q), on: dayOf(agentFor(c)), q }));
824833 },
825834 },
826835 {
@@ -837,10 +846,10 @@ export const routes: readonly Route[] = [
837846 });
838847 const path = "/activity";
839848 if (!got.ok)
840 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path, heading: "Activity", error: got.error, message: got.message }), STATUS[got.error]);
849 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path, heading: "Activity", error: got.error, message: got.message }), STATUS[got.error]);
841850 if (bad)
842 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path, heading: "Activity", error: "invalid", message: "Older is a whole number, and the only filter is messages." }), 400);
843 return html(activityPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), db: c.db, rows: got.value, only: only === "messages" }));
851 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path, heading: "Activity", error: "invalid", message: "Older is a whole number, and the only filter is messages." }), 400);
852 return html(activityPage({ who: c.who, ...headerFor(c), agent: agentFor(c), db: c.db, rows: got.value, only: only === "messages" }));
844853 },
845854 },
846855 {
@@ -850,12 +859,12 @@ export const routes: readonly Route[] = [
850859 const only = c.url.searchParams.get("only");
851860 const path = "/activity.csv";
852861 if (only !== null && only !== "messages")
853 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path, heading: "Activity", error: "invalid", message: "The only filter is messages." }), 400);
862 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path, heading: "Activity", error: "invalid", message: "The only filter is messages." }), 400);
854863 // Every row, a page of the largest size at a time; the first call is the permit check the page makes.
855864 const rows: AuditRow[] = [];
856865 for (let before: number | undefined; ; ) {
857866 const got = listAudit(c.db, c.who, { limit: 500, ...(before === undefined ? {} : { before }), ...(only === "messages" ? { only } : {}) });
858 if (!got.ok) return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path, heading: "Activity", error: got.error, message: got.message }), STATUS[got.error]);
867 if (!got.ok) return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path, heading: "Activity", error: got.error, message: got.message }), STATUS[got.error]);
859868 rows.push(...got.value);
860869 if (got.value.length < 500) break;
861870 before = got.value[got.value.length - 1]!.id;
@@ -909,7 +918,7 @@ export const routes: readonly Route[] = [
909918 path: "/deals/new",
910919 handle: (c) => {
911920 const { notice, clear } = readNotice(c.request);
912 return html(newDealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), notice }), 200, clear);
921 return html(newDealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), notice }), 200, clear);
913922 },
914923 },
915924 {
@@ -936,7 +945,7 @@ export const routes: readonly Route[] = [
936945 const known = all?.ok ? knownPeople(all.value, found.value.id) : undefined;
937946 const wanted = (c.url.searchParams.get("use") ?? "").trim().toLowerCase();
938947 const use = wanted === "" ? undefined : known?.find((k) => k.key === wanted);
939 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice, open, known, use, find: (c.url.searchParams.get("find") ?? "").slice(0, 100) }), 200, clear);
948 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice, open, known, use, find: (c.url.searchParams.get("find") ?? "").slice(0, 100) }), 200, clear);
940949 },
941950 },
942951 {
@@ -955,7 +964,7 @@ export const routes: readonly Route[] = [
955964 path: "/deals/:id/timeline",
956965 handle: (c) => {
957966 const found = dealOrRefusal(c);
958 return found instanceof Response ? found : html(timelinePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found, on: dayOf(agentFor(c)) }));
967 return found instanceof Response ? found : html(timelinePage({ who: c.who, agent: agentFor(c), deal: found, on: dayOf(agentFor(c)) }));
959968 },
960969 },
961970 {
@@ -964,7 +973,7 @@ export const routes: readonly Route[] = [
964973 // The broker file: read as `deal` is read, and never the client's page.
965974 handle: (c) => {
966975 const found = dealOrRefusal(c);
967 return found instanceof Response ? found : html(filePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found }));
976 return found instanceof Response ? found : html(filePage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found }));
968977 },
969978 },
970979 {
@@ -993,9 +1002,9 @@ export const routes: readonly Route[] = [
9931002 const made = createDeal(c.db, c.who, newDeal(fromForm(f)));
9941003 if (made.ok) return back("Deal opened. Every date is on the clock.", `/deals/${made.value.id}`);
9951004 if (made.error === "conflict")
996 return html(newDealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, existing: openDealAt(c.db, c.who, String(f.address)) } }), 409);
1005 return html(newDealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, existing: openDealAt(c.db, c.who, String(f.address)) } }), 409);
9971006 if (made.error !== "invalid") return back(made.message, "/deals/new");
998 return html(newDealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, problem: made } }), 422);
1007 return html(newDealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, problem: made } }), 422);
9991008 },
10001009 },
10011010 {
@@ -1009,11 +1018,11 @@ export const routes: readonly Route[] = [
10091018 if (!may.ok) return back(may.message, "/deals/new");
10101019 const planned = plan(newDeal(fromForm(f)));
10111020 if (!planned.ok)
1012 return html(newDealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, problem: planned } }), 422);
1021 return html(newDealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, problem: planned } }), 422);
10131022 const preview = { plan: planned.value, dates: plannedDates(planned.value) };
10141023 const there = planFor(c.db, c.who, newDeal(fromForm(f)));
10151024 const existing = there.ok ? undefined : openDealAt(c.db, c.who, planned.value.address);
1016 return html(newDealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, preview, existing } }));
1025 return html(newDealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), on: dayOf(agentFor(c)), state: { values: f, preview, existing } }));
10171026 },
10181027 },
10191028 {
@@ -1051,11 +1060,11 @@ export const routes: readonly Route[] = [
10511060 const got = getProfile(c.db, c.who);
10521061 if (!got.ok)
10531062 return html(
1054 refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/profile", heading: "Profile", error: got.error, message: got.message }),
1063 refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/profile", heading: "Profile", error: got.error, message: got.message }),
10551064 STATUS[got.error],
10561065 clear,
10571066 );
1058 return html(profilePage({ who: c.who, waiting: waitingFor(c), profile: got.value, mayChange: permit(c.who, "profile", "update") === "yes", notice }), 200, clear);
1067 return html(profilePage({ who: c.who, ...headerFor(c), profile: got.value, mayChange: permit(c.who, "profile", "update") === "yes", notice }), 200, clear);
10591068 },
10601069 },
10611070 {
@@ -1069,7 +1078,7 @@ export const routes: readonly Route[] = [
10691078 if (saved.error !== "invalid") return back(saved.message, "/profile");
10701079 const profile = getProfile(c.db, c.who);
10711080 if (!profile.ok) return back(saved.message, "/profile");
1072 return html(profilePage({ who: c.who, waiting: waitingFor(c), profile: profile.value, mayChange: true, state: { values: f, problem: saved } }), 422);
1081 return html(profilePage({ who: c.who, ...headerFor(c), profile: profile.value, mayChange: true, state: { values: f, problem: saved } }), 422);
10731082 },
10741083 },
10751084 {
@@ -1078,11 +1087,11 @@ export const routes: readonly Route[] = [
10781087 handle: async (c) => {
10791088 const file = await uploaded(c.request);
10801089 const heading = "Bring deals back from a file";
1081 if (file === undefined) return html(refusedPage({ who: c.who, agent: agentFor(c), waiting: waitingFor(c), path: "/profile", heading, error: "invalid", message: "That file is over 5 MB; nothing was brought back." }), 413);
1082 if (file === null) return html(refusedPage({ who: c.who, agent: agentFor(c), waiting: waitingFor(c), path: "/profile", heading, error: "invalid", message: "Choose a deal-clock file (the one Download all my deals gave you); nothing was brought back." }), 422);
1090 if (file === undefined) return html(refusedPage({ who: c.who, agent: agentFor(c), ...headerFor(c), path: "/profile", heading, error: "invalid", message: "That file is over 5 MB; nothing was brought back." }), 413);
1091 if (file === null) return html(refusedPage({ who: c.who, agent: agentFor(c), ...headerFor(c), path: "/profile", heading, error: "invalid", message: "Choose a deal-clock file (the one Download all my deals gave you); nothing was brought back." }), 422);
10831092 const got = importDeals(c.db, c.who, file);
1084 if (!got.ok) return html(refusedPage({ who: c.who, agent: agentFor(c), waiting: waitingFor(c), path: "/profile", heading, error: got.error, message: `${got.message} Nothing was brought back.` }), STATUS[got.error]);
1085 return html(broughtBackPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), brought: got.value.brought, skipped: got.value.skipped }));
1093 if (!got.ok) return html(refusedPage({ who: c.who, agent: agentFor(c), ...headerFor(c), path: "/profile", heading, error: got.error, message: `${got.message} Nothing was brought back.` }), STATUS[got.error]);
1094 return html(broughtBackPage({ who: c.who, ...headerFor(c), agent: agentFor(c), brought: got.value.brought, skipped: got.value.skipped }));
10861095 },
10871096 },
10881097 {
@@ -1137,7 +1146,7 @@ export const routes: readonly Route[] = [
11371146 if (saved.error !== "invalid" || f.address === undefined) return back(saved.message, `/deals/${id}`);
11381147 const found = getDeal(c.db, c.who, { id });
11391148 if (!found.ok) return back(found.message, `/deals/${id}`);
1140 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), problem: { value: f.address, message: saved.message } }), STATUS.invalid);
1149 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), problem: { value: f.address, message: saved.message } }), STATUS.invalid);
11411150 },
11421151 },
11431152 {
@@ -1152,7 +1161,7 @@ export const routes: readonly Route[] = [
11521161 if (saved.error !== "invalid") return back(saved.message, `/deals/${id}`);
11531162 const found = getDeal(c.db, c.who, { id });
11541163 if (!found.ok) return back(found.message, `/deals/${id}`);
1155 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: saved.message }), STATUS.invalid);
1164 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: saved.message }), STATUS.invalid);
11561165 },
11571166 },
11581167 {
@@ -1168,7 +1177,7 @@ export const routes: readonly Route[] = [
11681177 const found = getDeal(c.db, c.who, { id });
11691178 if (!found.ok) return back(found.message, `/deals/${id}`);
11701179 const values = { sale_price: String(f.sale_price ?? ""), earnest_amount: String(f.earnest_amount ?? ""), commission_rate: String(f.commission_rate ?? "") };
1171 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), figures: { values, field: saved.field, message: saved.message } }), STATUS.invalid);
1180 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), figures: { values, field: saved.field, message: saved.message } }), STATUS.invalid);
11721181 },
11731182 },
11741183 {
@@ -1184,7 +1193,7 @@ export const routes: readonly Route[] = [
11841193 const found = getDeal(c.db, c.who, { id });
11851194 if (!found.ok) return back(found.message, `/deals/${id}`);
11861195 const values = { closing_time: String(f.closing_time ?? ""), closing_place: String(f.closing_place ?? "") };
1187 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), closing: { values, field: saved.field, message: saved.message } }), STATUS.invalid);
1196 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), closing: { values, field: saved.field, message: saved.message } }), STATUS.invalid);
11881197 },
11891198 },
11901199 {
@@ -1286,7 +1295,7 @@ export const routes: readonly Route[] = [
12861295 const found = deal === undefined ? undefined : getDeal(c.db, c.who, { id: deal });
12871296 // A refusal on a real date comes back as that deal's page, saying why; anything else as before.
12881297 if (found?.ok && (set.error === "invalid" || set.error === "conflict"))
1289 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: set.message }), STATUS[set.error]);
1298 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: set.message }), STATUS[set.error]);
12901299 return done(set, backTo(f.to));
12911300 },
12921301 },
@@ -1303,7 +1312,7 @@ export const routes: readonly Route[] = [
13031312 const found = deal === undefined ? undefined : getDeal(c.db, c.who, { id: deal });
13041313 // A refused note comes back as that deal's page, saying why, with what was typed in the field.
13051314 if (found?.ok && set.error === "invalid")
1306 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: set.message, typed: { id, note: typeof f.note === "string" ? f.note : "" } }), STATUS[set.error]);
1315 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), notice: set.message, typed: { id, note: typeof f.note === "string" ? f.note : "" } }), STATUS[set.error]);
13071316 return done(set, backTo(f.to));
13081317 },
13091318 },
@@ -1320,7 +1329,7 @@ export const routes: readonly Route[] = [
13201329 const found = deal === undefined ? undefined : getDeal(c.db, c.who, { id: deal });
13211330 // A refused time or place comes back as that deal's page, naming the field, with what was typed.
13221331 if (found?.ok && set.error === "invalid")
1323 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), appointment: { id, values: { time: String(f.time ?? ""), place: String(f.place ?? "") }, field: set.field, message: set.message } }), STATUS.invalid);
1332 return html(dealPage({ who: c.who, ...headerFor(c), agent: agentFor(c), deal: found.value, on: dayOf(agentFor(c)), appointment: { id, values: { time: String(f.time ?? ""), place: String(f.place ?? "") }, field: set.field, message: set.message } }), STATUS.invalid);
13241333 return done(set, backTo(f.to));
13251334 },
13261335 },
@@ -1411,18 +1420,18 @@ export const routes: readonly Route[] = [
14111420 const { notice, open, clear } = readNotice(c.request);
14121421 const q = query(c.url.searchParams.get("q"));
14131422 if (q === undefined)
1414 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/reminders/today", heading: "Review today's reminders", error: "invalid", message: FIND_REFUSAL }), 400, clear);
1423 return html(refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/reminders/today", heading: "Review today's reminders", error: "invalid", message: FIND_REFUSAL }), 400, clear);
14151424 const queue = reviewQueue(c, q);
14161425 if (!queue.ok)
14171426 return html(
1418 refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/reminders/today", heading: "Review today's reminders", error: queue.error, message: queue.message }),
1427 refusedPage({ who: c.who, ...headerFor(c), agent: agentFor(c), path: "/reminders/today", heading: "Review today's reminders", error: queue.error, message: queue.message }),
14191428 STATUS[queue.error],
14201429 clear,
14211430 );
14221431 const sent = open === undefined ? undefined : listDeals(c.db, c.who);
14231432 const link = open === undefined || !sent?.ok ? undefined : sent.value.flatMap((d) => d.sent).find((m) => m.id === open)?.hrefs ?? [];
14241433 return html(
1425 reviewPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), queue: queue.value, q, at: count(c.url.searchParams.get("at")), done: count(c.url.searchParams.get("done")), notice, open: link, settled: queue.value.length === 0 ? settledOn(c.db, agentFor(c).zone ?? DEFAULT_ZONE, dayOf(agentFor(c))) : undefined, next: queue.value.length === 0 ? nextAfter(c) : undefined }),
1434 reviewPage({ who: c.who, ...headerFor(c), agent: agentFor(c), queue: queue.value, q, at: count(c.url.searchParams.get("at")), done: count(c.url.searchParams.get("done")), notice, open: link, settled: queue.value.length === 0 ? settledOn(c.db, agentFor(c).zone ?? DEFAULT_ZONE, dayOf(agentFor(c))) : undefined, next: queue.value.length === 0 ? nextAfter(c) : undefined }),
14261435 200,
14271436 clear,
14281437 );
src/terminal.test.ts +14
@@ -1006,3 +1006,17 @@ test("the deal view and the week say which other appointment the same day is les
10061006 t.press("w");
10071007 expect(lines(t).join("\n")).toContain("Also at 10:00 am: Inspection, 7 Twin Ln");
10081008 });
1009
1010 test("G lists the ten tour steps from src/tour.ts, a guest is refused, ", () => {
1011 const own = openDb(mkdtempSync(join(tmpdir(), "app-terminal-tour-")));
1012 const t = terminal(own, alice, context);
1013 t.press("G");
1014 const screen = lines(t).join("\n");
1015 expect(screen).toContain("1. Sign in");
1016 expect(screen).toContain("10. Set up your Profile");
1017 expect(screen).toContain("Go to 1418 Alder Lane: /deals/");
1018 expect(screen).not.toContain("**");
1019 const guest = terminal(own, { role: "anon" }, context);
1020 guest.press("G");
1021 expect(lines(guest).join("\n")).not.toContain("10. Set up your Profile");
1022 });
src/terminal.ts +31 −1
@@ -7,6 +7,7 @@
77 * week the open dates overdue or due in the next seven days, by day
88 * 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
99 * people each person on the deals with every open date they owe (P)
10 * tour the five-minute tour on the sample deals, step by step (G)
1011 * timeline a deal's dates as a client would get them (t on a deal)
1112 * file a deal's broker file: figures, parties, every date and message (f on a deal)
1213 * activity who approved, declined or changed what, newest first (L, admins); m only messages, o older, y newer
@@ -84,6 +85,7 @@ import type { AuditRow } from "./audit.ts";
8485 import type { Result } from "./result.ts";
8586 import type { Who } from "./who.ts";
8687 import { narrowPeople, nudgeLine, people } from "./people.ts";
88 import { linkFor, STEPS } from "./tour.ts";
8789 import { reachedAt } from "./outbox.ts";
8890 import { addresses, refusal, when, wording } from "./activity.ts";
8991 import { listAudit } from "./actions.ts";
@@ -100,7 +102,7 @@ const ACTIVITY_ROWS = 20;
100102 const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2", waived: "2" };
101103 const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`;
102104
103 type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline" | "file" | "profile" | "activity";
105 type View = "dates" | "week" | "people" | "tour" | "reminders" | "deal" | "messages" | "timeline" | "file" | "profile" | "activity";
104106 interface Row {
105107 readonly deal: DealView;
106108 readonly date: DeadlineView;
@@ -610,6 +612,9 @@ export function terminal(
610612 } else if (key === "P") {
611613 view = "people";
612614 cursor = 0;
615 } else if (key === "G") {
616 view = "tour";
617 cursor = 0;
613618 } else if (key === "E") {
614619 said = exportAll();
615620 } else if (key === "O" && (view === "dates" || view === "week")) {
@@ -829,6 +834,18 @@ export function terminal(
829834 lines.push(` ${tint(o.urgency, `${spoken(o.due).padEnd(12)} ${relative(o.due, day).padEnd(12)}`)} ${o.label} — ${o.address}`);
830835 }
831836 }
837 } else if (view === "tour") {
838 const listed = listDeals(db, me);
839 if (!listed.ok) lines.push(listed.message);
840 else {
841 lines.push(bold("Tour"), dim("Five minutes on the sample deals."), "");
842 STEPS.forEach((step, i) => {
843 lines.push(bold(`${i + 1}. ${step.title}`));
844 for (const l of wrapWords(step.text.replace(/\*\*/g, "").replace(/`/g, ""), 76)) lines.push(` ${l}`);
845 const href = linkFor(step.go, listed.value);
846 lines.push(dim(href === null ? ` ${step.go.label}: this sample deal was removed, so there is no page to open.` : ` Go to ${step.go.label}: ${href}`), "");
847 });
848 }
832849 } else if (view === "activity") {
833850 const page = activityRows();
834851 if (!page.ok) lines.push(page.message);
@@ -953,6 +970,8 @@ export function terminal(
953970 ? permit(me, "profile", "update") === "yes"
954971 ? "e edit · U use defaults · d dates · q quit"
955972 : "d dates · q quit (only an admin changes the profile)"
973 : view === "tour"
974 ? "G tour · d dates · w this week · r reminders · P people · q quit"
956975 : view === "people"
957976 ? "P people · d dates · w this week · r reminders · q quit"
958977 : view === "reminders"
@@ -979,3 +998,14 @@ export function terminal(
979998 },
980999 };
9811000 }
1001
1002 /** Words broken into lines no longer than `width`. */
1003 function wrapWords(text: string, width: number): string[] {
1004 const out: string[] = [];
1005 let line = "";
1006 for (const w of text.split(" ")) {
1007 if (line !== "" && line.length + 1 + w.length > width) (out.push(line), (line = w));
1008 else line = line === "" ? w : `${line} ${w}`;
1009 }
1010 return line === "" ? out : [...out, line];
1011 }
src/tour.page.test.ts added +104
@@ -0,0 +1,104 @@
1 /** The Tour page: guarded, linked to the sample deals, held to the README's words. */
2 import { afterAll, expect, test } from "bun:test";
3 import { mkdtempSync, readFileSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { forgetRationing } from "./security.ts";
7 import { serve } from "./server.ts";
8 import { missingPage } from "./pages/missing.ts";
9 import { tourPage } from "./pages/tour.ts";
10 import { hasTourDeals, linkFor, readmeForm, STEPS } from "./tour.ts";
11 import { sign, type Who } from "./who.ts";
12
13 const KEY = "a-key-only-the-forge-holds";
14 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-tourpage-")), identityKey: KEY });
15 const base = `http://${server.hostname}:${server.port}`;
16 afterAll(() => server.stop(true));
17 const id = (role: string) => `u1|alice|${role}|${Date.now() + 600_000}`;
18 const as = (role: string) => ({ "x-forge-identity": id(role), "x-forge-signature": sign(id(role), KEY) });
19 const get = (path: string, headers: Record<string, string> = as("user")) => {
20 forgetRationing();
21 return fetch(base + path, { headers });
22 };
23 const deals = async () => (await (await fetch(base + "/api/deals", { headers: as("admin") })).json()) as { id: number; address: string }[];
24
25 test("the README tour is exactly the steps in src/tour.ts", () => {
26 const md = readFileSync(new URL("../README.md", import.meta.url), "utf8");
27 const rest = md.slice(md.indexOf("## A five-minute tour")).split("\n## ")[0]!;
28 const steps = [...rest.matchAll(/^(\d+)\. ([\s\S]*?)(?=^\d+\. |$(?![\s\S]))/gm)].map((m) => m[2]!.replace(/\s+/g, " ").trim());
29 expect(steps).toEqual(STEPS.map(readmeForm));
30 expect(STEPS).toHaveLength(10);
31 });
32
33 test("a guest is asked to sign in and sees no tour", async () => {
34 const r = await get("/tour", {});
35 expect(r.status).toBe(401);
36 expect(await r.text()).not.toContain("tour-list");
37 });
38
39 test("a signed-in viewer sees ten numbered steps, each linking to its page, with the security headers", async () => {
40 const r = await get("/tour");
41 expect(r.status).toBe(200);
42 expect(r.headers.get("content-security-policy")).toBeTruthy();
43 expect(r.headers.get("x-content-type-options")).toBe("nosniff");
44 const page = await r.text();
45 expect(page).toContain('<ol class="tour-list">');
46 expect(page.match(/class="tour-step"/g)).toHaveLength(10);
47 const all = await deals();
48 const harbor = all.find((d) => d.address === "77 Harbor View Dr, Unit 4B")!;
49 const alder = all.find((d) => d.address === "1418 Alder Lane")!;
50 for (const href of [`/deals/${harbor.id}`, `/deals/${alder.id}`, `/deals/${alder.id}/timeline`, "/reminders/today", "/week", "/people", "/profile"])
51 expect(page).toContain(`href="${href}"`);
52 expect(page).toContain("<b>Mark done</b>");
53 });
54
55 test("the header offers Tour to someone who has the samples, and not to a guest", async () => {
56 expect(await (await get("/people")).text()).toContain('href="/tour">Tour</a>');
57 expect(await (await get("/")).text()).toContain('href="/tour">Tour</a>');
58 expect(await (await get("/", {})).text()).not.toContain('href="/tour"');
59 });
60
61 const alice: Who = { role: "user", id: "u1", name: "alice" };
62 const HARBOR = "77 Harbor View Dr, Unit 4B";
63 const REMOVED = "this sample deal was removed";
64
65 test("a step whose deal was removed has no link and says why; the others keep theirs", () => {
66 const html = tourPage({ who: alice, deals: [{ id: 5, address: "1418 Alder Lane" }] });
67 const steps = html.split('<li class="tour-step">').slice(1);
68 expect(steps).toHaveLength(10);
69 for (const step of steps) expect(step.includes('<a class="button') || step.includes(REMOVED)).toBe(true);
70 const harbor = steps.filter((x) => (x.split('class="tour-go')[1] ?? "").includes(HARBOR));
71 expect(harbor).toHaveLength(2);
72 for (const step of harbor) {
73 expect(step).toContain(REMOVED);
74 expect(step).not.toMatch(/href="\/deals\/\d+/);
75 }
76 const alder = steps.filter((x) => (x.split('class="tour-go')[1] ?? "").includes("1418 Alder Lane"));
77 expect(alder).toHaveLength(2);
78 expect(alder.map((x) => /href="(\/deals\/5[^"]*)"/.exec(x)![1])).toEqual(["/deals/5", "/deals/5/timeline"]);
79 for (const step of alder) expect(step).not.toContain(REMOVED);
80 });
81
82 test("hasTourDeals is true only while a sample deal named by the tour is there", () => {
83 expect(hasTourDeals([{ address: "1418 Alder Lane" }])).toBe(true);
84 expect(hasTourDeals([{ address: "12 Oak Lane" }])).toBe(false);
85 expect(hasTourDeals([])).toBe(false);
86 });
87
88 test("the header has no Tour link when the viewer has no sample deal", () => {
89 const html = missingPage({ who: alice, path: "/nope", tour: hasTourDeals([{ address: "12 Oak Lane" }]) });
90 expect(html).not.toContain('href="/tour"');
91 expect(missingPage({ who: alice, path: "/nope", tour: true })).toContain('href="/tour">Tour</a>');
92 });
93
94 test("Tour is in the header of a 404 and of a refused page for a signed-in viewer; handouts have no header", async () => {
95 expect(await (await get("/no-such-page")).text()).toContain('href="/tour">Tour</a>');
96 expect(await (await get("/deals/999999")).text()).toContain('href="/tour">Tour</a>');
97 const id = (await deals())[0]!.id;
98 // The timeline and This week are plain handouts: no navigation at all, so no Tour link and no People link either.
99 for (const path of [`/deals/${id}/timeline`, "/week"]) {
100 const page = await (await get(path)).text();
101 expect(page).not.toContain('href="/people"');
102 expect(page).not.toContain('href="/tour"');
103 }
104 });
src/tour.ts added +90
@@ -0,0 +1,90 @@
1 /**
2 * The five-minute tour, once: the steps the README prints and the /tour page
3 * walks, each with the place it names. A test holds README.md to these words,
4 * so the two cannot drift. Plain data; no page, no database.
5 */
6
7 export const HARBOR = "77 Harbor View Dr, Unit 4B";
8 export const ALDER = "1418 Alder Lane";
9
10 /** Where a step sends the reader: a page of the app, or a sample deal found by its address (and a page under it). */
11 export type Go =
12 | { readonly label: string; readonly page: string }
13 | { readonly label: string; readonly deal: string; readonly then?: string };
14
15 export interface Step {
16 /** The step's heading, without its number or the full stop. */
17 readonly title: string;
18 /** The step in the README's words: **bold** names a button or heading, `code` a command. */
19 readonly text: string;
20 readonly go: Go;
21 }
22
23 export const STEPS: readonly Step[] = [
24 {
25 title: "Sign in",
26 text: "Tap **Sign in** on the first page and use your forge account. Until you do, you see only what deal-clock does and a still picture of a made-up deal; no real deal is read. Once in, you land on the clock with 77 Harbor View Dr, Unit 4B, 1418 Alder Lane, 9 Orchard Row and 2210 Juniper Court.",
27 go: { label: "the clock", page: "/" },
28 },
29 {
30 title: "Read the clock",
31 text: "One lane per open deal. Time runs left to right and today is the dark line down the middle. Every date in a contract is a marker: red is overdue (the inspection on 77 Harbor View Dr), amber is due within three days, teal is coming up, grey is done (the earlier dates on 1418 Alder Lane, which closes in a few days). Under the heading, one line adds up your book, like \"4 open · $1,693,400 under contract · 2 close in November · 3 closed this year, $1,375,000 · $45,328 commission pending · $37,395 earned this year\" (the November count follows the month you open it in). Below the clock, **This week** lists every open date that is overdue or due in the next seven days, with who owes it.",
32 go: { label: "the clock", page: "/" },
33 },
34 {
35 title: "Open a deal",
36 text: "Tap the red inspection marker on 77 Harbor View Dr. A sheet opens with the date, who owes it (the buyer), what is owed, and the reminders for each party. Tap the address to open the deal's page: every date, every party, the messages you have sent. The inspection there reads \"10:30 am · 77 Harbor View Dr, Unit 4B\", the time and place the buyer has to be at.",
37 go: { label: "77 Harbor View Dr, Unit 4B", deal: HARBOR },
38 },
39 {
40 title: "Mark a date done",
41 text: "On 1418 Alder Lane, open a coming date such as Financing and tap **Mark done**. The marker turns grey and its reminders stop. **Reopen** puts it back.",
42 go: { label: "1418 Alder Lane", deal: ALDER },
43 },
44 {
45 title: "Move a date, with a reason",
46 text: "Back on Harbor View, open the inspection marker and tap **Move this date**: pick a new date and say why (\"Inspector delayed\"). The marker jumps, and the sheet lists the move, the reason and who made it. A \"Date changed\" notice is drafted for each party the date concerns. On 9 Orchard Row the appraisal has already been moved; open it to see where from and to, and why.",
47 go: { label: "77 Harbor View Dr, Unit 4B", deal: HARBOR },
48 },
49 {
50 title: "Review and approve today's reminders",
51 text: "Tap **Review** in the header. The first reminder is marked \"Start here\": it is the clock's most pressing one. Each unsent reminder shows the words it would send, already filled in, for a party such as the buyer Samuel Reyes. Edit them if you like, then **Send**, **Don't send** (it asks why) or **Tomorrow**. Send records your approval and offers **Open in Mail** or **Open in Messages**, which open your own app with the words: deal-clock never sends anything itself. The count in the header goes down. Under a deal's dates, **Coming reminders** lists what the app will draft next, by day, party and date; each is drafted for your approval and nothing is sent by itself. The terminal's deal view lists the same.",
52 go: { label: "Review", page: "/reminders/today" },
53 },
54 {
55 title: "Hand the client a timeline",
56 text: "On 1418 Alder Lane's page tap **Client timeline**: its dates in order, who owes each, and what the buyer or seller does for it, with no controls. Tap **Print** for a one-page handout for Maya and Tom Okafor.",
57 go: { label: "1418 Alder Lane, client timeline", deal: ALDER, then: "/timeline" },
58 },
59 {
60 title: "Print the week",
61 text: "Beside the **This week** heading tap **Print this week** for a one-page sheet of the same rows, ready for the Monday office meeting. It starts with the overdue Harbor View inspection, then the days ahead, including the closing on 1418 Alder Lane. Each overdue row names who owes it and whether they were told (\"Last told Nov 6\" or \"Not told yet\"); declined and held drafts don't count.",
62 go: { label: "This week", page: "/week" },
63 },
64 {
65 title: "See People",
66 text: "Open **People** in the header. Each person on your deals appears once, with every open date they owe across all deals, soonest first. Try Priya Nair, the lender on both 1418 Alder Lane and 9 Orchard Row. Each person also shows when you last sent them a reminder or notice, and about what (\"Last heard Nov 6 · Financing, 12 Oak Lane\"), or \"Nothing sent yet\"; declined and held drafts don't count. Type a name, phone, email or address into **Find a person** to narrow the list (try \"priya\"); **Clear** brings everyone back. Tap a number to call or text, an address to write. In the terminal press P, then / to find a person (enter alone clears it); over MCP ask for `list_people`.",
67 go: { label: "People", page: "/people" },
68 },
69 {
70 title: "Set up your Profile",
71 text: "Open **Profile** in the header and type your name, brokerage, phone and email. They appear in the header, on the client timeline and at the foot of every new reminder. (Only an admin can save it; **Use defaults** goes back to the sample agent.)",
72 go: { label: "Profile", page: "/profile" },
73 },
74 ];
75
76 /** The step as the README prints it after its number: "**Title.** text". */
77 export const readmeForm = (s: Step): string => `**${s.title}.** ${s.text}`;
78
79 /** Where a step's link goes, or null when its sample deal is no longer among `deals`. */
80 export function linkFor(go: Go, deals: readonly { readonly id: number; readonly address: string }[]): string | null {
81 if ("page" in go) return go.page;
82 const found = deals.find((d) => d.address === go.deal);
83 return found === undefined ? null : `/deals/${found.id}${go.then ?? ""}`;
84 }
85
86 /** Whether the viewer still has any of the sample deals the tour names. */
87 export function hasTourDeals(deals: readonly { readonly address: string }[]): boolean {
88 const named = new Set(STEPS.flatMap((s) => ("deal" in s.go ? [s.go.deal] : [])));
89 return deals.some((d) => named.has(d.address));
90 }
static/app.css +6
@@ -1040,6 +1040,12 @@ a.marker {
10401040 font-weight: 600;
10411041 }
10421042
1043 .tour-list { padding-inline-start: 1.5rem; max-width: 46rem; }
1044 .tour-step { margin-block: var(--space-4, 1rem); }
1045 .tour-step h2 { font-size: 1rem; margin: 0 0 0.25rem; }
1046 .tour-step p { margin: 0 0 0.5rem; }
1047 .tour-go { margin-block-start: 0.25rem; }
1048
10431049 @media print {
10441050 .timeline-page {
10451051 background: white;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs