Public: anyone can read this; the crew can change it.
A listing deal carries the date the listing agreement expires, and the clock and the deal page flag a closing that would fall after it #188
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/174-a-listing-deal-carries-the-date-the-list → main 4 commits fork 3 threads · 3 unresolved
18 files
changed +253
−57
README.md +6 −1
| @@ -81,7 +81,12 @@ phone or email, into **Find a deal** above the clock and press Find (try | ||
| 81 | 81 | `harbor`). The clock, This week and today's reminders narrow to the matches; |
| 82 | 82 | **Clear** brings them back. The **Side** choice beside it narrows to deals |
| 83 | 83 | where you are the buyer's agent or the listing agent. 9 Orchard Row is a |
| 84 | listing in the samples. | |
| 84 | listing in the samples; on a listing, add "Listing agreement expires" as a | |
| 85 | date and the clock and the deal page flag a closing that falls after it (9 | |
| 86 | Orchard Row shows the flag). It is yours alone: it is never on the client | |
| 87 | timeline and no party is drafted anything about it. You see it on the clock, in | |
| 88 | This week and on the deal's page, and the calendar file gives it an alarm 30 | |
| 89 | days ahead. | |
| 85 | 90 | |
| 86 | 91 | ## Opening and shaping a deal |
| 87 | 92 |
contract/openapi.json +15 −9
| @@ -1113,7 +1113,8 @@ | ||
| 1113 | 1113 | "seller", |
| 1114 | 1114 | "lender", |
| 1115 | 1115 | "title", |
| 1116 | "other_agent" | |
| 1116 | "other_agent", | |
| 1117 | "agent" | |
| 1117 | 1118 | ] |
| 1118 | 1119 | }, |
| 1119 | 1120 | "what": { |
| @@ -1164,7 +1165,8 @@ | ||
| 1164 | 1165 | "seller", |
| 1165 | 1166 | "lender", |
| 1166 | 1167 | "title", |
| 1167 | "other_agent" | |
| 1168 | "other_agent", | |
| 1169 | "agent" | |
| 1168 | 1170 | ] |
| 1169 | 1171 | }, |
| 1170 | 1172 | "by": { |
| @@ -1200,7 +1202,7 @@ | ||
| 1200 | 1202 | }, |
| 1201 | 1203 | "conflicts": { |
| 1202 | 1204 | "type": "array", |
| 1203 | "description": "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Empty when the deal is in order or closed.", | |
| 1205 | "description": "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Also the listing agreement's end (a custom date of that label) when the open Closing falls on or after it. Empty when the deal is in order or closed.", | |
| 1204 | 1206 | "items": { |
| 1205 | 1207 | "type": "object", |
| 1206 | 1208 | "properties": { |
| @@ -2335,7 +2337,7 @@ | ||
| 2335 | 2337 | "type": "string", |
| 2336 | 2338 | "minLength": 1, |
| 2337 | 2339 | "maxLength": 100, |
| 2338 | "description": "What the date is. Common labels: Seller disclosures due; HOA documents review ends; Survey due; Repair request deadline; Home warranty ordered; Lead paint inspection ends." | |
| 2340 | "description": "What the date is. Common labels: Seller disclosures due; HOA documents review ends; Survey due; Repair request deadline; Home warranty ordered; Lead paint inspection ends; Listing agreement expires." | |
| 2339 | 2341 | }, |
| 2340 | 2342 | "due": { |
| 2341 | 2343 | "type": "string", |
| @@ -2400,7 +2402,8 @@ | ||
| 2400 | 2402 | "seller", |
| 2401 | 2403 | "lender", |
| 2402 | 2404 | "title", |
| 2403 | "other_agent" | |
| 2405 | "other_agent", | |
| 2406 | "agent" | |
| 2404 | 2407 | ] |
| 2405 | 2408 | }, |
| 2406 | 2409 | "what": { |
| @@ -2527,7 +2530,8 @@ | ||
| 2527 | 2530 | "seller", |
| 2528 | 2531 | "lender", |
| 2529 | 2532 | "title", |
| 2530 | "other_agent" | |
| 2533 | "other_agent", | |
| 2534 | "agent" | |
| 2531 | 2535 | ] |
| 2532 | 2536 | }, |
| 2533 | 2537 | "note": { |
| @@ -3277,7 +3281,8 @@ | ||
| 3277 | 3281 | "seller", |
| 3278 | 3282 | "lender", |
| 3279 | 3283 | "title", |
| 3280 | "other_agent" | |
| 3284 | "other_agent", | |
| 3285 | "agent" | |
| 3281 | 3286 | ] |
| 3282 | 3287 | }, |
| 3283 | 3288 | "what": { |
| @@ -3328,7 +3333,8 @@ | ||
| 3328 | 3333 | "seller", |
| 3329 | 3334 | "lender", |
| 3330 | 3335 | "title", |
| 3331 | "other_agent" | |
| 3336 | "other_agent", | |
| 3337 | "agent" | |
| 3332 | 3338 | ] |
| 3333 | 3339 | }, |
| 3334 | 3340 | "by": { |
| @@ -3364,7 +3370,7 @@ | ||
| 3364 | 3370 | }, |
| 3365 | 3371 | "conflicts": { |
| 3366 | 3372 | "type": "array", |
| 3367 | "description": "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Empty when the deal is in order or closed.", | |
| 3373 | "description": "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Also the listing agreement's end (a custom date of that label) when the open Closing falls on or after it. Empty when the deal is in order or closed.", | |
| 3368 | 3374 | "items": { |
| 3369 | 3375 | "type": "object", |
| 3370 | 3376 | "properties": { |
src/deadlines.ts +21
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | |
| 8 | 8 | import { addBusinessDays, addDays, daysBetween } from "./dates.ts"; |
| 9 | 9 | import { standard } from "./env.ts"; |
| 10 | import type { Side } from "./side.ts"; | |
| 10 | 11 | |
| 11 | 12 | export const PARTY_ROLES = [ |
| 12 | 13 | "buyer", |
| @@ -14,14 +15,18 @@ export const PARTY_ROLES = [ | ||
| 14 | 15 | "lender", |
| 15 | 16 | "title", |
| 16 | 17 | "other_agent", |
| 18 | "agent", | |
| 17 | 19 | ] as const; |
| 18 | 20 | export type PartyRole = (typeof PARTY_ROLES)[number]; |
| 21 | /** The roles a person on a deal can hold: every role but the agent, who is the one using the app and is never added as a party. */ | |
| 22 | export const CONTACT_ROLES: readonly PartyRole[] = PARTY_ROLES.filter((r) => r !== "agent"); | |
| 19 | 23 | export const PARTY_LABEL: Readonly<Record<PartyRole, string>> = { |
| 20 | 24 | buyer: "Buyer", |
| 21 | 25 | seller: "Seller", |
| 22 | 26 | lender: "Lender", |
| 23 | 27 | title: "Title company", |
| 24 | 28 | other_agent: "Other agent", |
| 29 | agent: "Agent", | |
| 25 | 30 | }; |
| 26 | 31 | /** A date is open until it is done or waived; only an open date drafts reminders, flags or conflicts. */ |
| 27 | 32 | export const isOpen = (d: { done_at: string | null; waived_at: string | null }): boolean => d.done_at === null && d.waived_at === null; |
| @@ -32,6 +37,9 @@ export const isWaivable = (kind: string): boolean => kind !== "closing"; | ||
| 32 | 37 | |
| 33 | 38 | export const isPartyRole = (v: unknown): v is PartyRole => |
| 34 | 39 | PARTY_ROLES.includes(v as PartyRole); |
| 40 | /** A role a party can be added in: not the agent. */ | |
| 41 | export const isContactRole = (v: unknown): v is PartyRole => | |
| 42 | CONTACT_ROLES.includes(v as PartyRole); | |
| 35 | 43 | |
| 36 | 44 | export const KINDS = [ |
| 37 | 45 | "earnest", |
| @@ -62,7 +70,13 @@ export interface Suggestion { | ||
| 62 | 70 | readonly label: string; |
| 63 | 71 | /** Days before it is due that its first reminder goes out. */ |
| 64 | 72 | readonly lead: number; |
| 73 | /** The sides of a deal that offer it; every side when absent. */ | |
| 74 | readonly sides?: readonly Side[]; | |
| 75 | /** Who owes it when typed from the suggestion; the form's default when absent. */ | |
| 76 | readonly owes?: PartyRole; | |
| 65 | 77 | } |
| 78 | /** The listing agreement's end: the agent's own paperwork, so only the agent owes it and no client is told of it. */ | |
| 79 | export const LISTING_EXPIRES = "Listing agreement expires"; | |
| 66 | 80 | export const SUGGESTED_DATES: readonly Suggestion[] = [ |
| 67 | 81 | { label: "Seller disclosures due", lead: 3 }, |
| 68 | 82 | { label: "HOA documents review ends", lead: 5 }, |
| @@ -70,7 +84,14 @@ export const SUGGESTED_DATES: readonly Suggestion[] = [ | ||
| 70 | 84 | { label: "Repair request deadline", lead: 2 }, |
| 71 | 85 | { label: "Home warranty ordered", lead: 3 }, |
| 72 | 86 | { label: "Lead paint inspection ends", lead: 3 }, |
| 87 | { label: LISTING_EXPIRES, lead: 30, sides: ["listing", "both"], owes: "agent" }, | |
| 73 | 88 | ]; |
| 89 | /** The suggestions a deal on `side` offers. */ | |
| 90 | export const suggestedFor = (side: Side): readonly Suggestion[] => SUGGESTED_DATES.filter((s) => s.sides === undefined || s.sides.includes(side)); | |
| 91 | /** The agent's own date, matched by its exact label like `leadOfLabel`: no client sees it or is reminded of it. */ | |
| 92 | export const isInternal = (d: { readonly kind: string; readonly label: string }): boolean => d.kind === "custom" && d.label === LISTING_EXPIRES; | |
| 93 | /** Who a date's reminders go to besides whoever owes it: nobody for the agent's own date. */ | |
| 94 | export const notifiedOf = (d: { readonly kind: Kind; readonly label: string }): readonly PartyRole[] => (isInternal(d) ? [] : KIND[d.kind].notify); | |
| 74 | 95 | /** The lead a typed label starts from: its suggestion's when it matches exactly, else the default. */ |
| 75 | 96 | export const leadOfLabel = (label: string): number => |
| 76 | 97 | SUGGESTED_DATES.find((s) => s.label === label)?.lead ?? DEFAULT_LEAD; |
src/deals.ts +14 −6
| @@ -13,13 +13,16 @@ import { | ||
| 13 | 13 | DEFAULT_LENGTHS, |
| 14 | 14 | isClosed, |
| 15 | 15 | isOpen, |
| 16 | isPartyRole, | |
| 16 | isContactRole, | |
| 17 | isInternal, | |
| 17 | 18 | isWaivable, |
| 18 | 19 | KIND, |
| 19 | 20 | LEAD_MAX, |
| 20 | 21 | LEAD_MIN, |
| 21 | 22 | leadOf, |
| 22 | 23 | leadOfLabel, |
| 24 | LISTING_EXPIRES, | |
| 25 | notifiedOf, | |
| 23 | 26 | PARTY_LABEL, |
| 24 | 27 | schedule, |
| 25 | 28 | type Kind, |
| @@ -892,13 +895,15 @@ export function setOwes( | ||
| 892 | 895 | const { dealId, found } = deadlineFor(db, who, input.id, input.dealId); |
| 893 | 896 | if (!found.ok) return within(db, who, OWES_WHAT, dealId, found); |
| 894 | 897 | const { deadline } = found.value; |
| 895 | if (!isPartyRole(input.owes)) | |
| 898 | if (isInternal(found.value.deadline)) | |
| 899 | return within(db, who, OWES_WHAT, dealId, fail("conflict", "The listing agreement is the agent's own date; no one else can owe it.", "owes")); | |
| 900 | if (!isContactRole(input.owes)) | |
| 896 | 901 | return within(db, who, OWES_WHAT, dealId, fail("invalid", "Say which party owes it.", "owes")); |
| 897 | 902 | if (!isOpen(deadline)) |
| 898 | 903 | return within(db, who, OWES_WHAT, dealId, fail("conflict", `This date is ${deadline.waived_at !== null ? "waived" : "done"}; reopen it before changing who owes it.`)); |
| 899 | 904 | if (input.owes === deadline.owes) |
| 900 | 905 | return within(db, who, OWES_WHAT, dealId, fail("invalid", `${PARTY_LABEL[input.owes]} already owes it.`, "owes")); |
| 901 | const told = [input.owes, ...KIND[deadline.kind].notify]; | |
| 906 | const told = [input.owes, ...notifiedOf(deadline)]; | |
| 902 | 907 | db.transaction(() => { |
| 903 | 908 | db.query("UPDATE deadline SET owes = ?1, owes_from = ?2, owes_by = ?3, owes_on = ?4 WHERE id = ?5").run(input.owes as string, deadline.owes, authorOf(who).name, today(zoneOf(db)), deadline.id); |
| 904 | 909 | for (const h of db.query<{ id: number; moment: string; role: string }, [number]>( |
| @@ -1071,7 +1076,10 @@ export function addDeadline( | ||
| 1071 | 1076 | return within(db, who, "date.add", dealId, fail("invalid", "Name the date (up to 100 characters).", "label")); |
| 1072 | 1077 | if (!isDate(input.due)) |
| 1073 | 1078 | return within(db, who, "date.add", dealId, fail("invalid", "The date is a date (YYYY-MM-DD).", "due")); |
| 1074 | if (!isPartyRole(input.owes)) | |
| 1079 | const own = label === LISTING_EXPIRES; | |
| 1080 | if (own && deal.value.side === "buyer") | |
| 1081 | return within(db, who, "date.add", dealId, fail("invalid", "A buyer-side deal has no listing agreement; make it a listing or both-sides deal first.", "label")); | |
| 1082 | if (!own && !isContactRole(input.owes)) | |
| 1075 | 1083 | return within(db, who, "date.add", dealId, fail("invalid", "Say which party owes it.", "owes")); |
| 1076 | 1084 | const what = input.what === undefined || input.what === "" ? "" : line(input.what, 1, 200); |
| 1077 | 1085 | if (what === undefined) |
| @@ -1083,7 +1091,7 @@ export function addDeadline( | ||
| 1083 | 1091 | .query<Deadline, [number, string, string, string, string, number]>( |
| 1084 | 1092 | "INSERT INTO deadline (deal_id, kind, label, due, owes, what, lead_days) VALUES (?1, 'custom', ?2, ?3, ?4, ?5, ?6) RETURNING *", |
| 1085 | 1093 | ) |
| 1086 | .get(deal.value.id, label, input.due, input.owes, what, given ? (input.leadDays as number) : leadOfLabel(label))!; | |
| 1094 | .get(deal.value.id, label, input.due, own ? "agent" : (input.owes as string), what, given ? (input.leadDays as number) : leadOfLabel(label))!; | |
| 1087 | 1095 | return within(db, who, "date.add", dealId, ok(made)); |
| 1088 | 1096 | } |
| 1089 | 1097 | |
| @@ -1129,7 +1137,7 @@ export function addParty( | ||
| 1129 | 1137 | const deal = dealFor(db, who, "update", input.dealId); |
| 1130 | 1138 | const dealId = deal.ok ? deal.value.id : undefined; |
| 1131 | 1139 | if (!deal.ok) return within(db, who, "party.add", Number.isInteger(input.dealId) ? input.dealId : undefined, deal); |
| 1132 | if (!isPartyRole(input.role)) | |
| 1140 | if (!isContactRole(input.role)) | |
| 1133 | 1141 | return within(db, who, "party.add", dealId, fail("invalid", "A party is a buyer, seller, lender, title company or the other agent.")); |
| 1134 | 1142 | const text = partyText(input); |
| 1135 | 1143 | if (!text.ok) return within(db, who, "party.add", dealId, text); |
src/import.ts +8 −4
| @@ -10,7 +10,8 @@ | ||
| 10 | 10 | import type { Database } from "bun:sqlite"; |
| 11 | 11 | import { permit } from "./contract.ts"; |
| 12 | 12 | import { isDate } from "./dates.ts"; |
| 13 | import { KIND, KINDS, isPartyRole, leadOf, leadOfLabel, type Kind, type PartyRole } from "./deadlines.ts"; | |
| 13 | import { sideOf } from "./side.ts"; | |
| 14 | import { KIND, KINDS, isContactRole, isInternal, leadOf, leadOfLabel, type Kind, type PartyRole } from "./deadlines.ts"; | |
| 14 | 15 | import { appointmentPlace, appointmentTime, isAppointment } from "./appointment.ts"; |
| 15 | 16 | import { closingPlace, closingTime } from "./closing.ts"; |
| 16 | 17 | import { NOTE_MAX, REASON_MAX, insertDeal, line, partyText, plan, sameAddress, type NewDeal, type Plan } from "./deals.ts"; |
| @@ -88,7 +89,7 @@ function readDeal(raw: unknown, n: number): Result<DealIn> { | ||
| 88 | 89 | const parties: PartyIn[] = []; |
| 89 | 90 | for (const [i, p] of partiesRaw.entries()) { |
| 90 | 91 | const o = obj(p); |
| 91 | if (!isPartyRole(o.role)) return refuse(n, `party ${i + 1} has no valid role.`, `parties[${i}].role`); | |
| 92 | if (!isContactRole(o.role)) return refuse(n, `party ${i + 1} has no valid role.`, `parties[${i}].role`); | |
| 92 | 93 | const text = partyText(o); |
| 93 | 94 | if (!text.ok) return refuse(n, `party ${i + 1}: ${text.message}`, `parties[${i}]`); |
| 94 | 95 | parties.push({ role: o.role, ...text.value }); |
| @@ -103,7 +104,10 @@ function readDeal(raw: unknown, n: number): Result<DealIn> { | ||
| 103 | 104 | if (!KINDS.includes(o.kind as Kind)) return refuse(n, `date ${i + 1} has an unknown kind.`, `${at}.kind`); |
| 104 | 105 | if (!isDate(o.due)) return refuse(n, `date ${i + 1} (${label}) is not a date (YYYY-MM-DD).`, `${at}.due`); |
| 105 | 106 | const owes = o.owed_by; |
| 106 | if (!isPartyRole(owes)) return refuse(n, `date ${i + 1} (${label}) says no valid party owes it.`, `${at}.owed_by`); | |
| 107 | // The agent's own date is always the agent's, and only a listing has one. | |
| 108 | const own = isInternal({ kind: o.kind as string, label }); | |
| 109 | if (own && sideOf(d.side) === "buyer") return refuse(n, `date ${i + 1} (${label}) is a listing agreement, which a buyer-side deal does not have.`, `${at}.label`); | |
| 110 | if (!own && !isContactRole(owes)) return refuse(n, `date ${i + 1} (${label}) says no valid party owes it.`, `${at}.owed_by`); | |
| 107 | 111 | const note = o.note === undefined || o.note === null || o.note === "" ? "" : line(o.note, 1, NOTE_MAX); |
| 108 | 112 | if (note === undefined) return refuse(n, `the note on date ${i + 1} is up to ${NOTE_MAX} characters.`, `${at}.note`); |
| 109 | 113 | // An inspection's or walkthrough's time and place, as the export wrote them; any other kind carries none. |
| @@ -130,7 +134,7 @@ function readDeal(raw: unknown, n: number): Result<DealIn> { | ||
| 130 | 134 | return refuse(n, `move ${j + 1} of date ${i + 1} (${label}) is not a from and to date, a reason and who moved it.`, `${at}.moves[${j}]`); |
| 131 | 135 | moves.push({ from: m.from, to: m.to, reason, by, at: when }); |
| 132 | 136 | } |
| 133 | dates.push({ label, kind: o.kind as Kind, due: o.due, owes, note, time: time.value, place: place.value, done, waived, waivedBy, moves }); | |
| 137 | dates.push({ label, kind: o.kind as Kind, due: o.due, owes: own ? "agent" : (owes as PartyRole), note, time: time.value, place: place.value, done, waived, waivedBy, moves }); | |
| 134 | 138 | } |
| 135 | 139 | |
| 136 | 140 | const closing = dates.find((x) => x.kind === "closing"); |
src/listing.test.ts added +141
| @@ -0,0 +1,141 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { mkdtempSync } from "node:fs"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { openDb } from "./db.ts"; | |
| 6 | import { LISTING_EXPIRES, suggestedFor } from "./deadlines.ts"; | |
| 7 | import { addDeadline, addParty, createDeal, getDeal, listDeals, markDone, moveDeadline, setOwes } from "./deals.ts"; | |
| 8 | import { exportDeals } from "./export.ts"; | |
| 9 | import { importDeals } from "./import.ts"; | |
| 10 | import { calendar } from "./ics.ts"; | |
| 11 | import { thisWeek } from "./week.ts"; | |
| 12 | import openapi from "../contract/openapi.json"; | |
| 13 | import { conflictLine } from "./order.ts"; | |
| 14 | import { drafts, recipients } from "./reminders.ts"; | |
| 15 | import { agent } from "./env.ts"; | |
| 16 | import { timelineRows } from "./timeline.ts"; | |
| 17 | import { tools } from "./mcp.ts"; | |
| 18 | import type { Who } from "./who.ts"; | |
| 19 | ||
| 20 | const db = openDb(mkdtempSync(join(tmpdir(), "app-listing-"))); | |
| 21 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 22 | ||
| 23 | let n = 0; | |
| 24 | function listing(side: "buyer" | "listing" | "both", expires: string) { | |
| 25 | const made = createDeal(db, alice, { address: `${++n} ${side} Way`, buyer: "Bea Buyer", seller: "Sol Seller", contractDate: "2026-10-01", closingDate: "2026-12-03", side }); | |
| 26 | if (!made.ok) throw new Error(made.message); | |
| 27 | const id = made.value.id; | |
| 28 | const added = addDeadline(db, alice, { dealId: id, label: LISTING_EXPIRES, due: expires, owes: "buyer" }); | |
| 29 | if (!added.ok) throw new Error(added.message); | |
| 30 | const get = () => { const d = getDeal(db, alice, { id }); if (!d.ok) throw new Error(d.message); return d.value; }; | |
| 31 | return { id, expiry: added.value, get }; | |
| 32 | } | |
| 33 | ||
| 34 | test("the suggestion is offered for listing and both, not buyer, with a 30 day lead", () => { | |
| 35 | const labels = (s: "buyer" | "listing" | "both") => suggestedFor(s).map((x) => x.label); | |
| 36 | expect(labels("listing")).toContain(LISTING_EXPIRES); | |
| 37 | expect(labels("both")).toContain(LISTING_EXPIRES); | |
| 38 | expect(labels("buyer")).not.toContain(LISTING_EXPIRES); | |
outdated
|
||
| 39 | const { expiry } = listing("listing", "2026-11-30"); | |
| 40 | expect(expiry.lead_days).toBe(30); | |
| 41 | expect(expiry.owes).toBe("agent"); | |
| 42 | expect(expiry.kind).toBe("custom"); | |
| 43 | }); | |
| 44 | ||
| 45 | test("closing after the expiry is flagged in words, and moving either date clears it", () => { | |
| 46 | const { expiry, get } = listing("listing", "2026-11-30"); | |
| 47 | const closing = get().deadlines.find((d) => d.kind === "closing")!; | |
| 48 | expect(get().conflicts.map(conflictLine)).toEqual(["Closing (Dec 3) falls after the listing agreement expires (Nov 30): extend the listing or move closing."]); | |
| 49 | expect(moveDeadline(db, alice, { id: expiry.id, due: "2026-12-10", reason: "Listing extended" }).ok).toBe(true); | |
| 50 | expect(get().conflicts).toEqual([]); | |
| 51 | expect(moveDeadline(db, alice, { id: expiry.id, due: "2026-12-03", reason: "Back" }).ok).toBe(true); | |
| 52 | expect(get().conflicts.map(conflictLine)[0]).toContain("falls on the day the listing agreement expires"); | |
| 53 | expect(moveDeadline(db, alice, { id: expiry.id, due: "2026-12-04", reason: "Longer" }).ok).toBe(true); | |
| 54 | expect(get().conflicts).toEqual([]); | |
| 55 | expect(moveDeadline(db, alice, { id: closing.id, due: "2026-12-05", reason: "Slipped" }).ok).toBe(true); | |
| 56 | expect(get().conflicts).toHaveLength(1); | |
| 57 | expect(moveDeadline(db, alice, { id: closing.id, due: "2026-12-03", reason: "Back on" }).ok).toBe(true); | |
| 58 | expect(get().conflicts).toEqual([]); | |
| 59 | }); | |
| 60 | ||
| 61 | test("marking the expiry done clears the flag, and an expiry after closing is no out-of-order date", () => { | |
| 62 | const { expiry, get } = listing("both", "2026-11-30"); | |
| 63 | expect(get().conflicts).toHaveLength(1); | |
| 64 | expect(markDone(db, alice, { id: expiry.id, done: true }).ok).toBe(true); | |
| 65 | expect(get().conflicts).toEqual([]); | |
| 66 | const later = listing("listing", "2026-12-20"); | |
| 67 | expect(later.get().conflicts).toEqual([]); | |
| 68 | }); | |
| 69 | ||
| 70 | test("the agent's own date is off the client timeline and tells no party", () => { | |
| 71 | const { id, get } = listing("listing", "2026-11-30"); | |
| 72 | addParty(db, alice, { dealId: id, role: "other_agent", name: "Olive Other", email: "[email protected]" }); | |
| 73 | expect(timelineRows(get(), "2026-11-09").map((r) => r.label)).not.toContain(LISTING_EXPIRES); | |
| 74 | const d = get().deadlines.find((x) => x.label === LISTING_EXPIRES)!; | |
| 75 | for (const m of ["before", "day_of", "late", "moved"] as const) expect(recipients(get(), d, m)).toEqual([]); | |
| 76 | const text = drafts(get(), agent).map((x) => x.subject + x.body).join("\n"); | |
| 77 | expect(text).not.toContain("Listing agreement"); | |
| 78 | expect(addParty(db, alice, { dealId: id, role: "agent", name: "Me" })).toMatchObject({ ok: false }); | |
| 79 | }); | |
| 80 | ||
| 81 | test("the API's deal and MCP's get_deal and move answer carry the conflict", () => { | |
| 82 | const { get } = listing("listing", "2026-11-30"); | |
| 83 | const dealId = get().id; | |
| 84 | const got = tools.find((t) => t.name === "get_deal")!.run(db, alice, { id: dealId }) as { ok: boolean; value: { conflicts: { label: string }[] } }; | |
| 85 | expect(got.value.conflicts.map((c) => c.label)).toEqual([LISTING_EXPIRES]); | |
| 86 | const move = tools.find((t) => t.name === "move_date")!; | |
| 87 | const out = move.run(db, alice, { id: get().deadlines.find((d) => d.kind === "financing")!.id, due: "2026-11-20", reason: "x" }) as { ok: boolean; value: { conflicts: { label: string }[] } }; | |
| 88 | expect(out.value.conflicts.map((c) => c.label)).toContain(LISTING_EXPIRES); | |
| 89 | }); | |
| 90 | ||
| 91 | test("the label is the agent's on every path: no one else can be handed it, and a buyer-side deal has none", () => { | |
| 92 | const { id, expiry, get } = listing("listing", "2026-11-30"); | |
| 93 | expect(setOwes(db, alice, { id: expiry.id, owes: "buyer" })).toMatchObject({ ok: false, field: "owes" }); | |
| 94 | expect(get().deadlines.find((d) => d.id === expiry.id)!.owes).toBe("agent"); | |
| 95 | const survey = addDeadline(db, alice, { dealId: id, label: "Survey due", due: "2026-11-15", owes: "buyer" }); | |
| 96 | if (!survey.ok) throw new Error(survey.message); | |
| 97 | expect(setOwes(db, alice, { id: survey.value.id, owes: "agent" })).toMatchObject({ ok: false, field: "owes" }); | |
| 98 | expect(addDeadline(db, alice, { dealId: id, label: "Other", due: "2026-11-15", owes: "agent" })).toMatchObject({ ok: false, field: "owes" }); | |
| 99 | const buyerSide = createDeal(db, alice, { address: "Buyer Only Way", buyer: "A", seller: "B", contractDate: "2026-10-01", closingDate: "2026-12-03" }); | |
| 100 | if (!buyerSide.ok) throw new Error(buyerSide.message); | |
| 101 | expect(addDeadline(db, alice, { dealId: buyerSide.value.id, label: LISTING_EXPIRES, due: "2026-11-30", owes: "buyer" })).toMatchObject({ ok: false, field: "label" }); | |
| 102 | expect(getDeal(db, alice, { id: buyerSide.value.id }).ok && getDeal(db, alice, { id: buyerSide.value.id })).toMatchObject({ value: { conflicts: [] } }); | |
| 103 | }); | |
| 104 | ||
| 105 | test("import makes the label the agent's, and refuses it on a buyer-side deal", () => { | |
| 106 | const { get } = listing("listing", "2026-11-30"); | |
| 107 | const file = JSON.parse(JSON.stringify(exportDeals([get()], new Date("2026-11-09T00:00:00Z")))); | |
| 108 | file.deals[0].address = "Imported Way"; | |
| 109 | file.deals[0].dates.find((x: { label: string }) => x.label === LISTING_EXPIRES).owed_by = "buyer"; | |
| 110 | const brought = importDeals(db, alice, file); | |
| 111 | if (!brought.ok) throw new Error(brought.message); | |
| 112 | const back = getDeal(db, alice, { id: brought.value.id }); | |
| 113 | if (!back.ok) throw new Error(back.message); | |
| 114 | expect(back.value.deadlines.find((d) => d.label === LISTING_EXPIRES)!.owes).toBe("agent"); | |
| 115 | file.deals[0].address = "Buyer Imported Way"; | |
| 116 | file.deals[0].side = "buyer"; | |
| 117 | expect(importDeals(db, alice, file)).toMatchObject({ ok: false }); | |
| 118 | }); | |
| 119 | ||
| 120 | test("the agent sees it on This week and on the calendar with its own alarm; no one else is drafted anything", () => { | |
| 121 | const { get } = listing("listing", "2026-11-12"); | |
| 122 | const week = thisWeek([get()], "2026-11-09").map((i) => i.deadline.label); | |
| 123 | expect(week).toContain(LISTING_EXPIRES); | |
| 124 | const ics = calendar(get(), "deal-clock.example", new Date("2026-11-09T00:00:00Z")); | |
| 125 | expect(ics).toContain(`SUMMARY:${LISTING_EXPIRES} — `); | |
| 126 | expect(ics).toContain("DESCRIPTION:Agent owes"); | |
| 127 | expect(ics).toContain("Listing agreement expires in 30 days"); | |
| 128 | expect(drafts(get(), agent).filter((x) => x.label === LISTING_EXPIRES)).toEqual([]); | |
| 129 | }); | |
| 130 | ||
| 131 | test("the API schema allows what the sample deals say about who owes a date", () => { | |
| 132 | const schemas = (openapi as unknown as { components: { schemas: Record<string, { properties: { deadlines: { items: { properties: { owes: { enum: string[] } } } } } }> } }).components.schemas; | |
| 133 | const owes = schemas.Deal!.properties.deadlines.items.properties.owes.enum; | |
| 134 | expect(owes).toContain("agent"); | |
| 135 | const fresh = openDb(mkdtempSync(join(tmpdir(), "app-listing-sample-"))); | |
| 136 | const all = listDeals(fresh, alice); | |
| 137 | if (!all.ok) throw new Error(all.message); | |
| 138 | const seen = new Set(all.value.flatMap((d) => d.deadlines.map((x) => x.owes))); | |
| 139 | expect(seen.has("agent")).toBe(true); | |
| 140 | for (const o of seen) expect(owes).toContain(o); | |
| 141 | }); |
src/mcp.ts +5 −5
| @@ -11,7 +11,7 @@ import { restoreSamples, type Result } from "./actions.ts"; | ||
| 11 | 11 | import { today } from "./dates.ts"; |
| 12 | 12 | import { exportDeals } from "./export.ts"; |
| 13 | 13 | import { fail, ok } from "./result.ts"; |
| 14 | import { DEFAULT_LENGTHS, PARTY_ROLES, SUGGESTED_DATES } from "./deadlines.ts"; | |
| 14 | import { CONTACT_ROLES, DEFAULT_LENGTHS, SUGGESTED_DATES } from "./deadlines.ts"; | |
| 15 | 15 | import { |
| 16 | 16 | addDeadline, |
| 17 | 17 | conflictsOf, |
| @@ -89,7 +89,7 @@ export const tools: readonly Tool[] = [ | ||
| 89 | 89 | }, |
| 90 | 90 | { |
| 91 | 91 | name: "get_deal", |
| 92 | description: "One deal by id. conflicts lists the open dates due on or after closing (a slipped contingency); empty when in order.", | |
| 92 | description: "One deal by id. conflicts lists the open dates due on or after closing (a slipped contingency) and a listing agreement that expires on or before closing; empty when in order.", | |
| 93 | 93 | inputSchema: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] }, |
| 94 | 94 | run: (db, who, args) => getDeal(db, who, { id: Number(args.id) }), |
| 95 | 95 | }, |
| @@ -158,7 +158,7 @@ export const tools: readonly Tool[] = [ | ||
| 158 | 158 | "Change which party owes an open date (not one already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were.", |
| 159 | 159 | inputSchema: { |
| 160 | 160 | type: "object", |
| 161 | properties: { id: { type: "integer" }, owes: { enum: [...PARTY_ROLES] } }, | |
| 161 | properties: { id: { type: "integer" }, owes: { enum: [...CONTACT_ROLES] } }, | |
| 162 | 162 | required: ["id", "owes"], |
| 163 | 163 | }, |
| 164 | 164 | run: (db, who, args) => setOwes(db, who, { id: Number(args.id), owes: args.owes }), |
| @@ -410,7 +410,7 @@ export const tools: readonly Tool[] = [ | ||
| 410 | 410 | deal_id: { type: "integer" }, |
| 411 | 411 | label: { type: "string", maxLength: 100 }, |
| 412 | 412 | due: { type: "string", format: "date" }, |
| 413 | owes: { enum: [...PARTY_ROLES] }, | |
| 413 | owes: { enum: [...CONTACT_ROLES] }, | |
| 414 | 414 | details: { type: "string", maxLength: 200 }, |
| 415 | 415 | }, |
| 416 | 416 | required: ["deal_id", "label", "due", "owes"], |
| @@ -475,7 +475,7 @@ export const tools: readonly Tool[] = [ | ||
| 475 | 475 | type: "object", |
| 476 | 476 | properties: { |
| 477 | 477 | deal_id: { type: "integer" }, |
| 478 | role: { enum: [...PARTY_ROLES] }, | |
| 478 | role: { enum: [...CONTACT_ROLES] }, | |
| 479 | 479 | name: { type: "string", maxLength: 100 }, |
| 480 | 480 | email: { type: "string", maxLength: 200 }, |
| 481 | 481 | phone: { type: "string", maxLength: 30, description: "Digits, spaces and + - ( ) . only." }, |
src/order.page.test.ts +4 −4
| @@ -22,13 +22,13 @@ type Deal = { | ||
| 22 | 22 | }; |
| 23 | 23 | const deals = async (): Promise<Deal[]> => (await fetch(`${base}/api/deals`, { headers: alice })).json() as Promise<Deal[]>; |
| 24 | 24 | |
| 25 | test("no sample deal is flagged on a fresh boot", async () => { | |
| 25 | test("on a fresh boot only 9 Orchard Row is flagged, for its listing expiring before closing", async () => { | |
| 26 | 26 | const all = await deals(); |
| 27 | 27 | expect(all.length).toBeGreaterThan(0); |
| 28 | for (const deal of all) expect(deal.conflicts).toEqual([]); | |
| 28 | for (const deal of all) | |
| 29 | expect(deal.conflicts.map((c) => c.label)).toEqual(deal.address === "9 Orchard Row" ? ["Listing agreement expires"] : []); | |
| 29 | 30 | const page = await (await fetch(`${base}/`, { headers: alice })).text(); |
| 30 | expect(page).not.toContain("data-conflict"); | |
| 31 | expect(page).not.toContain("out of order"); | |
| 31 | expect(page).toContain("1 out of order"); | |
| 32 | 32 | }); |
| 33 | 33 | |
| 34 | 34 | test("moving Alder Lane's financing past closing succeeds and shows the flag everywhere", async () => { |
src/order.ts +10 −5
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { short } from "./dates.ts"; |
| 8 | import { isOpen } from "./deadlines.ts"; | |
| 8 | import { isInternal, isOpen, LISTING_EXPIRES } from "./deadlines.ts"; | |
| 9 | 9 | |
| 10 | 10 | /** An open, non-closing date that falls on or after the closing date. */ |
| 11 | 11 | export interface Conflict { |
| @@ -28,11 +28,16 @@ interface Dated { | ||
| 28 | 28 | export function conflicts(deadlines: readonly Dated[]): Conflict[] { |
| 29 | 29 | const closing = deadlines.find((d) => d.kind === "closing"); |
| 30 | 30 | if (closing === undefined || closing.done_at !== null) return []; |
| 31 | return deadlines | |
| 32 | .filter((d) => d.kind !== "closing" && isOpen(d) && d.due >= closing.due) | |
| 31 | const listing = deadlines.find((d) => isInternal(d) && isOpen(d) && closing.due >= d.due); | |
| 32 | const late = deadlines | |
| 33 | .filter((d) => d.kind !== "closing" && !isInternal(d) && isOpen(d) && d.due >= closing.due) | |
| 33 | 34 | .map((d) => ({ deadline_id: d.id, label: d.label, due: d.due, closing: closing.due })); |
| 35 | // The listing's end is meant to come after closing, so it is never "after closing" itself; the other way round is the conflict. | |
| 36 | return listing === undefined ? late : [...late, { deadline_id: listing.id, label: listing.label, due: listing.due, closing: closing.due }]; | |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | /** "Financing (Nov 24) now falls after closing (Nov 20): move one or the other." */ | |
| 39 | /** "Closing (Dec 3) falls after the listing agreement expires (Nov 30): extend the listing or move closing."; otherwise "Financing (Nov 24) now falls after closing (Nov 20): move one or the other." */ | |
| 37 | 40 | export const conflictLine = (c: Conflict): string => |
| 38 | `${c.label} (${short(c.due)}) now falls ${c.due === c.closing ? "on" : "after"} closing (${short(c.closing)}): move one or the other.`; | |
| 41 | c.label === LISTING_EXPIRES | |
| 42 | ? `Closing (${short(c.closing)}) falls ${c.due === c.closing ? "on the day" : "after"} the listing agreement expires (${short(c.due)}): extend the listing or move closing.` | |
| 43 | : `${c.label} (${short(c.due)}) now falls ${c.due === c.closing ? "on" : "after"} closing (${short(c.closing)}): move one or the other.`; |
src/pages/deal.ts +5 −5
| @@ -8,7 +8,7 @@ import { addDays, relative, short, spoken } from "../dates.ts"; | ||
| 8 | 8 | import { canChange, canRemove, closedOn, EMAIL_MAX, fellOn, PHONE_MAX, REASON_MAX, type DealView, type Party, type Plan, type PlannedDate, type Sent } from "../deals.ts"; |
| 9 | 9 | import { matchKnown, type Known } from "../people.ts"; |
| 10 | 10 | import { agent as defaults, standard } from "../env.ts"; |
| 11 | import { DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, SUGGESTED_DATES } from "../deadlines.ts"; | |
| 11 | import { CONTACT_ROLES, DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, suggestedFor } from "../deadlines.ts"; | |
| 12 | 12 | import { escape } from "../http.ts"; |
| 13 | 13 | import { coming, comingLine, type Coming } from "../coming.ts"; |
| 14 | 14 | import { closingLine } from "../closing.ts"; |
| @@ -25,8 +25,8 @@ import { progressLine } from "./progress.ts"; | ||
| 25 | 25 | import { appointmentForm, appointmentText, type AppointmentProblem } from "./appointment.ts"; |
| 26 | 26 | import { badge, conflictLines, nonBusinessLine, noteLine, owesChangedLine, rollForm, draftItem, dueLine, outboxLine, owedBy, releaseForm, sheet, sheetId } from "./sheet.ts"; |
| 27 | 27 | |
| 28 | const roleOptions = (selected?: string): string => | |
| 29 | PARTY_ROLES.map( | |
| 28 | const roleOptions = (selected?: string, roles: readonly (typeof PARTY_ROLES)[number][] = PARTY_ROLES): string => | |
| 29 | roles.map( | |
| 30 | 30 | (r) => `<option value="${r}"${r === selected ? " selected" : ""}>${escape(PARTY_LABEL[r])}</option>`, |
| 31 | 31 | ).join(""); |
| 32 | 32 | |
| @@ -341,7 +341,7 @@ export function dealPage(input: { | ||
| 341 | 341 | <h2>Add a date</h2> |
| 342 | 342 | <p class="muted small">A date the contract adds: an HOA review, a repair deadline, a rate lock.</p> |
| 343 | 343 | <form class="stack" method="post" action="${path}/deadlines"> |
| 344 | <label>What<input class="input" name="label" required maxlength="100" list="suggested-dates" autocomplete="off" placeholder="HOA documents review ends"><datalist id="suggested-dates">${SUGGESTED_DATES.map((s) => `<option value="${escape(s.label)}"></option>`).join("")}</datalist></label> | |
| 344 | <label>What<input class="input" name="label" required maxlength="100" list="suggested-dates" autocomplete="off" placeholder="HOA documents review ends"><datalist id="suggested-dates">${suggestedFor(deal.side).map((s) => `<option value="${escape(s.label)}"></option>`).join("")}</datalist></label> | |
| 345 | 345 | <div class="pair"> |
| 346 | 346 | <label>Date<input class="input" type="date" name="due" required value="${escape(addDays(on, 7))}"></label> |
| 347 | 347 | <label>Owed by<select class="input" name="owes">${roleOptions("buyer")}</select></label> |
| @@ -355,7 +355,7 @@ export function dealPage(input: { | ||
| 355 | 355 | ${pick} |
| 356 | 356 | <form class="stack" method="post" action="${path}/parties"> |
| 357 | 357 | <div class="pair"> |
| 358 | <label>Role<select class="input" name="role">${roleOptions(add?.role ?? "lender")}</select></label> | |
| 358 | <label>Role<select class="input" name="role">${roleOptions(add?.role ?? "lender", CONTACT_ROLES)}</select></label> | |
| 359 | 359 | <label>Name<input class="input" name="name" required maxlength="100" value="${escape(add?.name ?? "")}"></label> |
| 360 | 360 | </div> |
| 361 | 361 | ${contactFields(add?.email ?? "", add?.phone ?? "", add?.message)} |
src/pages/sheet.ts +2 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | |
| 8 | 8 | import { BODY_MAX, canChange, NOTE_MAX, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts"; |
| 9 | 9 | import { doneLine, relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts"; |
| 10 | import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts"; | |
| 10 | import { CONTACT_ROLES, isInternal, isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL } from "../deadlines.ts"; | |
| 11 | 11 | import { escape } from "../http.ts"; |
| 12 | 12 | import { confirmRemove } from "./confirm.ts"; |
| 13 | 13 | import { memoizer, print } from "../memo.ts"; |
| @@ -243,7 +243,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 243 | 243 | ${ |
| 244 | 244 | isOpen(d) |
| 245 | 245 | ? `<form class="move" method="post" action="/deadlines/${d.id}/owes">${hidden({ to })} |
| 246 | <label>Owed by<select class="input" name="owes">${PARTY_ROLES.map((r) => `<option value="${r}"${r === d.owes ? " selected" : ""}>${escape(PARTY_LABEL[r])}</option>`).join("")}</select></label> | |
| 246 | <label>Owed by<select class="input" name="owes">${(isInternal(d) ? ["agent" as const] : CONTACT_ROLES).map((r) => `<option value="${r}"${r === d.owes ? " selected" : ""}>${escape(PARTY_LABEL[r])}</option>`).join("")}</select></label> | |
| 247 | 247 | <button class="button button-quiet">Change who owes it</button> |
| 248 | 248 | </form>` |
| 249 | 249 | : "" |
src/reminders.ts +3 −3
| @@ -14,7 +14,7 @@ import { closingAfterDate } from "./closing.ts"; | ||
| 14 | 14 | import { ANNIVERSARY_YEARS, anniversaryOn, anniversaryWords, checkinOn, checkinRoles, checkinWords } from "./checkin.ts"; |
| 15 | 15 | import { dollars } from "./money.ts"; |
| 16 | 16 | import { memoizer, print } from "./memo.ts"; |
| 17 | import { DEFAULT_LEAD, isOpen, KIND, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 17 | import { DEFAULT_LEAD, isInternal, isOpen, KIND, notifiedOf, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 18 | 18 | import type { DealView, DeadlineView, Move, Moment, Party } from "./deals.ts"; |
| 19 | 19 | |
| 20 | 20 | export interface Agent { |
| @@ -101,7 +101,7 @@ const lastMove = (deadline: DeadlineView): Move | undefined => { | ||
| 101 | 101 | */ |
| 102 | 102 | export function recipients(deal: DealView, deadline: DeadlineView, moment: Moment = "day_of"): Party[] { |
| 103 | 103 | const roles = new Set<PartyRole>( |
| 104 | moment === "late" ? [deadline.owes] : [deadline.owes, ...KIND[deadline.kind].notify], | |
| 104 | moment === "late" ? [deadline.owes] : [deadline.owes, ...notifiedOf(deadline)], | |
| 105 | 105 | ); |
| 106 | 106 | // A cash purchase has no loan, so a lender added by hand is not told. |
| 107 | 107 | if (deal.cash === 1) roles.delete("lender"); |
| @@ -391,7 +391,7 @@ export const standingOf = (moveId: number): number => moveId % SEND_SPAN; | ||
| 391 | 391 | function statusWords(deal: DealView, party: Party, agent: Agent): { subject: string; body: string } { |
| 392 | 392 | const closing = deal.deadlines.find((d) => d.kind === "closing")!; |
| 393 | 393 | const done = deal.deadlines.filter((d) => !isOpen(d)); |
| 394 | const open = deal.deadlines.filter((d) => isOpen(d) && d.id !== closing.id).sort((a, b) => a.due.localeCompare(b.due)); | |
| 394 | const open = deal.deadlines.filter((d) => isOpen(d) && d.id !== closing.id && !isInternal(d)).sort((a, b) => a.due.localeCompare(b.due)); | |
| 395 | 395 | const owner = (d: DeadlineView): string => deal.parties.find((p) => p.role === d.owes)?.name ?? PARTY_LABEL[d.owes]; |
| 396 | 396 | const next = open.slice(0, NEXT_MAX).map((d) => `• ${d.label}: ${spoken(d.due)} (${owner(d)} · ${PARTY_LABEL[d.owes].toLowerCase()})`); |
| 397 | 397 | const more = open.length > NEXT_MAX ? `\n• …and ${open.length - NEXT_MAX} more after that` : ""; |
src/routes.ts +7 −5
| @@ -221,6 +221,8 @@ export const AUDIT_ROW: Schema = { | ||
| 221 | 221 | }; |
| 222 | 222 | const DATE: Schema = { type: "string", format: "date" }; |
| 223 | 223 | const ROLE: Schema = { enum: ["buyer", "seller", "lender", "title", "other_agent"] }; |
| 224 | /** Who owes a date: a party's role, or the agent for their own listing-agreement date. */ | |
| 225 | const OWER: Schema = { enum: ["buyer", "seller", "lender", "title", "other_agent", "agent"] }; | |
| 224 | 226 | const CONTACT: Schema = { type: "string", deprecated: true, description: "Deprecated: the email, else the phone. Read email and phone instead; this reads for one more release." }; |
| 225 | 227 | const PARTY: Schema = { |
| 226 | 228 | type: "object", |
| @@ -322,7 +324,7 @@ export const DEAL: Schema = { | ||
| 322 | 324 | kind: { enum: ["earnest", "inspection", "appraisal", "financing", "title", "walkthrough", "closing", "custom"] }, |
| 323 | 325 | label: { type: "string" }, |
| 324 | 326 | due: DATE, |
| 325 | owes: ROLE, | |
| 327 | owes: OWER, | |
| 326 | 328 | what: { type: "string" }, |
| 327 | 329 | done_at: { type: ["string", "null"] }, |
| 328 | 330 | done_on: { type: ["string", "null"], description: "The day it was marked done, YYYY-MM-DD in the app's local calendar; null while open. Reopening clears it." }, |
| @@ -332,7 +334,7 @@ export const DEAL: Schema = { | ||
| 332 | 334 | owes_changed: { |
| 333 | 335 | type: ["object", "null"], |
| 334 | 336 | description: "The latest change of Owed by: the role it had (from), who changed it (by) and the day (on). Null when it was never changed.", |
| 335 | properties: { from: ROLE, by: { type: "string" }, on: DATE }, | |
| 337 | properties: { from: OWER, by: { type: "string" }, on: DATE }, | |
| 336 | 338 | }, |
| 337 | 339 | moves: { type: "array", items: { type: "object" } }, |
| 338 | 340 | nonBusinessDay: { |
| @@ -346,7 +348,7 @@ export const DEAL: Schema = { | ||
| 346 | 348 | conflicts: { |
| 347 | 349 | type: "array", |
| 348 | 350 | description: |
| 349 | "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Empty when the deal is in order or closed.", | |
| 351 | "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Also the listing agreement's end (a custom date of that label) when the open Closing falls on or after it. Empty when the deal is in order or closed.", | |
| 350 | 352 | items: { |
| 351 | 353 | type: "object", |
| 352 | 354 | properties: { |
| @@ -1795,7 +1797,7 @@ export const routes: readonly Route[] = [ | ||
| 1795 | 1797 | }, |
| 1796 | 1798 | required: ["label", "due", "owes"], |
| 1797 | 1799 | }, |
| 1798 | answer: { type: "object", properties: { id: { type: "integer" }, deal_id: { type: "integer" }, kind: { type: "string" }, label: { type: "string" }, due: { type: "string", format: "date" }, owes: ROLE, what: { type: "string" }, lead_days: { type: "integer" } }, required: ["id", "deal_id", "label", "due", "owes", "lead_days"] }, | |
| 1800 | answer: { type: "object", properties: { id: { type: "integer" }, deal_id: { type: "integer" }, kind: { type: "string" }, label: { type: "string" }, due: { type: "string", format: "date" }, owes: OWER, what: { type: "string" }, lead_days: { type: "integer" } }, required: ["id", "deal_id", "label", "due", "owes", "lead_days"] }, | |
| 1799 | 1801 | }, |
| 1800 | 1802 | }, |
| 1801 | 1803 | { |
| @@ -1834,7 +1836,7 @@ export const routes: readonly Route[] = [ | ||
| 1834 | 1836 | summary: |
| 1835 | 1837 | "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. note sets the agent's working note on the date, one line of up to 200 characters, empty to clear it (400 with field note otherwise); it is internal and never reaches a client timeline, reminder or status update. time and place set when and where an inspection or a final walkthrough is: time as HH:MM on a quarter hour from 07:00 to 20:00 (the agent's local time), place one line of 1 to 200 characters; a field left out stays, blank or null clears it, and any other kind of date is refused (422 with field time). Drafts, the client timeline and the calendar file say them. Send any of them.", |
| 1836 | 1838 | body: { type: "object", properties: { lead_days: { type: "integer", minimum: 1, maximum: 30 }, owes: ROLE, note: { type: "string", maxLength: 200 }, time: { type: ["string", "null"], pattern: "^(0[7-9]|1[0-9]):(00|15|30|45)$|^20:00$", description: "HH:MM on a quarter hour from 07:00 to 20:00, local time; null clears it. Inspection and walkthrough only." }, place: { type: ["string", "null"], maxLength: 200 } } }, |
| 1837 | answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" }, owes: ROLE, note: { type: "string" }, time: { type: ["string", "null"] }, place: { type: ["string", "null"] } }, required: ["id", "lead_days", "owes", "note"] }, | |
| 1839 | answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" }, owes: OWER, note: { type: "string" }, time: { type: ["string", "null"] }, place: { type: ["string", "null"] } }, required: ["id", "lead_days", "owes", "note"] }, | |
| 1838 | 1840 | }, |
| 1839 | 1841 | }, |
| 1840 | 1842 | { |
src/sample.test.ts +1 −1
| @@ -43,7 +43,7 @@ test("a sample a person changed is not untouched", () => { | ||
| 43 | 43 | const state = { |
| 44 | 44 | sample: "9 Orchard Row", |
| 45 | 45 | parties: 3, // lender, title, other agent |
| 46 | customs: 1, | |
| 46 | customs: 2, // repair credit, listing expiry | |
| 47 | 47 | reminders: 0, |
| 48 | 48 | doneAts: ["2026-09-30T17:00:00.000Z", "2026-09-30T17:00:00.000Z", "2026-09-30T17:00:00.000Z", null], |
| 49 | 49 | dues: ["2026-10-01", "2026-10-01", "2026-10-01", "2026-10-09"], |
src/sample.ts +4 −1
| @@ -110,7 +110,10 @@ const SAMPLES: readonly Sample[] = [ | ||
| 110 | 110 | ["other_agent", "Ben Adeyemi, Lantern Realty", "[email protected]"], |
| 111 | 111 | ], |
| 112 | 112 | done: ["earnest", "inspection", "title"], |
| 113 | custom: [["Repair credit agreed", 5, "seller", "Signed amendment for the roof repair credit"]], | |
| 113 | custom: [ | |
| 114 | ["Repair credit agreed", 5, "seller", "Signed amendment for the roof repair credit"], | |
| 115 | ["Listing agreement expires", 14, "agent", "Closing is four days after it ends: extend the listing or move closing"], | |
| 116 | ], | |
| 114 | 117 | moved: ["appraisal", 2, "Appraiser rescheduled — access to the property"], |
| 115 | 118 | notes: [["appraisal", "Appraisal ordered, AMC says Thursday"]], |
| 116 | 119 | }, |
src/suggested.test.ts +2 −2
| @@ -3,7 +3,7 @@ import { afterAll, expect, test } from "bun:test"; | ||
| 3 | 3 | import { mkdtempSync } from "node:fs"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| 6 | import { DEFAULT_LEAD, SUGGESTED_DATES, leadOfLabel } from "./deadlines.ts"; | |
| 6 | import { DEFAULT_LEAD, SUGGESTED_DATES, leadOfLabel, suggestedFor } from "./deadlines.ts"; | |
| 7 | 7 | import { addDeadline, createDeal } from "./deals.ts"; |
| 8 | 8 | import { openDb } from "./db.ts"; |
| 9 | 9 | import { serve } from "./server.ts"; |
| @@ -24,7 +24,7 @@ test("a deal's page offers the suggested dates in a plain datalist, escaped, and | ||
| 24 | 24 | const page = await (await fetch(base + path, { headers })).text(); |
| 25 | 25 | expect(page).toContain('<datalist id="suggested-dates">'); |
| 26 | 26 | const options = [...page.matchAll(/<datalist id="suggested-dates">(.*?)<\/datalist>/gs)][0]![1]!; |
| 27 | expect([...options.matchAll(/<option value="([^"]*)"><\/option>/g)].map((m) => m[1])).toEqual(SUGGESTED_DATES.map((s) => s.label)); | |
| 27 | expect([...options.matchAll(/<option value="([^"]*)"><\/option>/g)].map((m) => m[1])).toEqual(suggestedFor("buyer").map((s) => s.label)); | |
| 28 | 28 | expect(options).not.toMatch(/<(?!\/?option)/); |
| 29 | 29 | expect(page).toMatch(/<label>What<input class="input" name="label"[^>]*list="suggested-dates"/); |
| 30 | 30 | }); |
src/terminal.ts +3 −3
| @@ -71,7 +71,7 @@ import { | ||
| 71 | 71 | import { find, FIND_MAX, query } from "./find.ts"; |
| 72 | 72 | import { mayRestore, restoreSamples } from "./actions.ts"; |
| 73 | 73 | import { conflictLine } from "./order.ts"; |
| 74 | import { isOpen, PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts"; | |
| 74 | import { CONTACT_ROLES, isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 75 | 75 | import { agentOf, getProfile, setProfile, useDefaults, zoneOf } from "./profile.ts"; |
| 76 | 76 | import { permit } from "./contract.ts"; |
| 77 | 77 | import { exportDeals, exportName } from "./export.ts"; |
| @@ -345,11 +345,11 @@ export function terminal( | ||
| 345 | 345 | }); |
| 346 | 346 | } |
| 347 | 347 | if (key === "a") |
| 348 | ask(deal, ["What is the date (e.g. HOA review ends)", "Date (YYYY-MM-DD)", `Owed by (${PARTY_ROLES.join(", ")})`, "Details (optional)"], ([label, due, owes, what]) => | |
| 348 | ask(deal, ["What is the date (e.g. HOA review ends)", "Date (YYYY-MM-DD)", `Owed by (${CONTACT_ROLES.join(", ")})`, "Details (optional)"], ([label, due, owes, what]) => | |
| 349 | 349 | report(addDeadline(db, me, { dealId: deal.id, label, due, owes, what }), () => withConflicts(db, me, deal.id, `Added ${label}.`)), |
| 350 | 350 | ); |
| 351 | 351 | if (key === "p") |
| 352 | ask(deal, [`Role (${PARTY_ROLES.join(", ")})`, "Name", "Email (optional)", "Phone (optional)"], ([role, name, email, phone]) => | |
| 352 | ask(deal, [`Role (${CONTACT_ROLES.join(", ")})`, "Name", "Email (optional)", "Phone (optional)"], ([role, name, email, phone]) => | |
| 353 | 353 | report(addParty(db, me, { dealId: deal.id, role, name, email, phone }), `Added ${name}.`), |
| 354 | 354 | ); |
| 355 | 355 | if (key === "D") { |
src/timeline.ts +2 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { appointmentLine } from "./appointment.ts"; |
| 9 | import { isInternal } from "./deadlines.ts"; | |
| 9 | 10 | import { doneLine, spoken, urgencyOf, type Urgency } from "./dates.ts"; |
| 10 | 11 | import type { DealView } from "./deals.ts"; |
| 11 | 12 | import { guidance, type Guidance } from "./guidance.ts"; |
| @@ -43,7 +44,7 @@ export interface TimelineRow { | ||
| 43 | 44 | } |
| 44 | 45 | |
| 45 | 46 | export function timelineRows(deal: DealView, on: string): TimelineRow[] { |
| 46 | return deal.deadlines.map((d) => { | |
| 47 | return deal.deadlines.filter((d) => !isInternal(d)).map((d) => { | |
| 47 | 48 | const u = urgencyOf(d, on); |
| 48 | 49 | const { name, role } = owner(deal, d); |
| 49 | 50 | return { label: d.label, due: d.due, spoken: spoken(d.due), where: appointmentLine(d), role, name, status: STATUS[u].word, doneLine: u === "done" && d.done_on !== null ? doneLine(d.due, d.done_on) : "", mark: STATUS[u].mark, urgency: u, todo: guidance(d.kind, deal.side, u !== "done" && u !== "waived") }; |
new above
offline
Exact-label matching with no side check: a buyer-side deal can still carry this date. Gate on side.