diff --git a/docs/EDGE_FUNCTIONS.md b/docs/EDGE_FUNCTIONS.md index c91c82122c..3637535518 100644 --- a/docs/EDGE_FUNCTIONS.md +++ b/docs/EDGE_FUNCTIONS.md @@ -3522,6 +3522,8 @@ curl -sS "${SUPABASE_URL}/functions/v1/get-estimate-public-terms" \ > **v2.9096 — a signed paper keeps its link** (finding 698, punch list #458): the update that signs a copy no longer empties `public_token_hash` and `public_token_expires_at`. The link opened again then finds its row, and [get-contract-for-signer](#get-contract-for-signer) answers its `409 already_signed`, which the page draws as **Thank you**; a signature sent twice answers `{ ok: true, alreadySigned: true }`. Before this both read as a dead link, since the row was looked up by a hash it no longer held. Nothing signs twice: the update still takes only a row whose `status` is `sent`, and every road that mints a link writes only an `unsent` or `sent` row. Tests `src/lib/contracts/signedPaperLink.test.ts`. **Deployed** 2026-12-01 (`accept-contract` version 78, 02:43 UTC, read back with `supabase functions list`); the signing road was walked on it at once and passed. +> **v2.9281 — a blank nobody filled prints as a ruled line**: the signed copy this function draws and emails (`sendSignerCopy`, over `paperParagraphs` in [`_shared/personPaperPdf.ts`](../supabase/functions/_shared/personPaperPdf.ts)) prints a name in square brackets, such as `[Company legal name]`, as a line of eighteen underscores, by the one rule in [`_shared/paperRuledBlanks.ts`](../supabase/functions/_shared/paperRuledBlanks.ts). The signing itself is unchanged: the row keeps the words as written, bracket and name, and nothing is kept for such a blank in `blank_values`. **Owes a deploy after v2.9281 merges.** + **A plain paper's blanks (v2.9066, punch list #457):** before a signature is stored the function reads the copy's blanks as the signer's page did. One with no value answers `409 paper_not_ready` and nothing is signed. A signature whose `blankSeal` is not the seal of the values read now, or that carries none, answers `409 paper_changed` (`blanksShownAtSigning`), so a site's code name changed after the page read it, or since v2.9111 the company's legal name, turns the page back to read the paper again. Otherwise the value each blank read is written to `person_contract_documents.blank_values` in the update that signs the copy, and the copy's words stay as the library's. **Deployed** 2026-11-30 (`accept-contract` version 77, 17:09 UTC, read back with `supabase functions list`). The v2.9111 change **deployed** 2026-12-02 (`accept-contract` version 80, 13:59 UTC, read back with `supabase functions list`). > **v2.9054 — whoever made the signing link is told, and a push goes beside the email** (punch list #458, step 2): `sendPaperSignedNotice` ([`_shared/paperSignedNoticeSend.ts`](../supabase/functions/_shared/paperSignedNoticeSend.ts)) first reads `person_contract_documents.link_made_by` by itself, best effort ([`_shared/paperLinkMaker.ts`](../supabase/functions/_shared/paperLinkMaker.ts), migration [`20261130081355`](./migrations/20261130081355_paper_link_made_by.md)). A link made by hand tells its maker in the email sender's place (`paperSignedTeller`), and makes any signed agreement one to tell of, a teammate's or a sub's own too (`paperSignedNoticeDue(row, byHand)`); a paper that only went by email is told of as before. Whoever is told gets a push through their own hours (`sendPushHonouringHours`, kind `paper_signed`, *Tallgrass Supply Co. signed* with the paper's name and no site), to an account that is here, with or without an address, and the email's foot says whether they sent the paper or made its link. The call from the function is unchanged, and so are the eight seconds. A database behind the migration reads no maker and behaves as before. **Deployed** 2026-11-30 (`accept-contract` version 76, 09:06 UTC, read back with `supabase functions list`). `paperLinkMaker.test.ts` and `paperSignedNotice.test.ts` hold it. @@ -3682,6 +3684,8 @@ curl -sS "${SUPABASE_URL}/functions/v1/get-estimate-public-terms" \ > **v2.9129 — a signed copy by email** (punch list #458, call 15): a body with `email_to` emails a signed agreement's PDF to that address and answers `{ ok: true, emailed: true, to, sent_at }`, never a link or a file. It is **Email the signed copy…** on a signed record, for a walk-up off a signing code who gave a mobile and no email, or a copy that went to a wrong address. Only the four roles, never a training account or a digital twin, and an estimator is refused (`copyResendCallerRefusal`, *Only the office emails a signed copy.*); the caller's own client must still read the row. Only a signed agreement (`copyResendPaperRefusal`): an hours statement, a W-9, a certificate and a licence answer `400 not_a_copy`. An address that is not one answers `400 address`. The send is `sendSignedCopyTo` ([`_shared/signedCopyResendSend.ts`](../supabase/functions/_shared/signedCopyResendSend.ts)): the PDF kept for the paper, made when an older one has none, or a form's filled PDF, with `buildSignedCopyEmail`, filed as a sent copy with whoever pressed. A two-party form that waits for the office's half answers `409 office_step`, a paper with no PDF `409 no_pdf`, and a mail that did not go `502`, with the mail service's own reason in the words when it gave one (`copyResendMissWords`). It writes `signed_copy_sent_at` on the signed row and nothing else: `signer_email` stays as the signer gave it. The rules are [`_shared/signedCopyResend.ts`](../supabase/functions/_shared/signedCopyResend.ts), read by the press too; the file sits beside `personPaperSignedCopy.ts` and changes nothing in it, so [accept-contract](#accept-contract) owes no deploy. A request without the key is answered as before. Tests `src/lib/contracts/signedCopyEmail.test.ts`. **Deployed** 2026-12-01 (`person-paper-pdf` version 10, 07:19 UTC, read back with `supabase functions list`). +> **v2.9281 — a blank nobody filled prints as a ruled line**: `paperParagraphs` rules a name in square brackets, such as `[Company legal name]`, as a line of eighteen underscores ([`_shared/paperRuledBlanks.ts`](../supabase/functions/_shared/paperRuledBlanks.ts)), after the app's own blanks are filled and after the words are made plain. It holds for a signed paper's PDF drawn here, for a client's copy, and for the PDF of a paper that is out and not signed, which is then a copy to fill in by pen. A PDF kept before this deploy is handed back as it was drawn. **Owes a deploy after v2.9281 merges.** + **A plain paper's blanks (v2.9066, punch list #457):** `paperParagraphs` (`_shared/personPaperPdf.ts`) fills a copy's blanks from the `blank_values` kept at its signature, so the PDF and the signer's emailed copy print what was signed. A copy not yet signed keeps none, and its PDF shows a blank as written. Since v2.9111 the kernel it carries knows a ninth blank, `{outside_paper_goes_to}`. **Deployed** 2026-11-30 (`person-paper-pdf` version 9, 17:09 UTC, read back with `supabase functions list`). The v2.9111 change **deployed** 2026-12-02 (`person-paper-pdf` version 11, 13:59 UTC, read back with `supabase functions list`). > **v2.9012 — a paper as sent names who was to sign** (finding 603, from the first live walk of the contract editor; the person's go of 2026-11-30): the *For* line of an unsigned paper's PDF named who the paper is with and nobody else, so a company's paper read *For ZZ Test Supply* and did not say who was to sign. It now reads *For ZZ Test Supply, to be signed by ZZ Test Signer*, from the signer's name on the row (`paperPdfAsSentForWords`, `drawPaperPdfAsSentNamed` in [`_shared/personPaperAsSent.ts`](../supabase/functions/_shared/personPaperAsSent.ts)). A person's own paper names a signer only when someone else signs for them, and a trade company's paper names the business its signer signs for. The file's name, the gate, the answer's shape and a signed paper's PDF are unchanged. The press still writes nothing: no row, no log, no kept file. The words live in a file of their own, which this function alone reads, so `accept-contract` and `get-contract-for-signer` are not behind for it; `drawPaperPdfAsSent` in `personPaperSignedCopy.ts` is left where it is and no function calls it now. **Deployed** on 2026-11-30 at 05:42 UTC (version 8), the one deploy that carries v2.9011 too (`supabase functions list` read on 2026-11-30 at 06:28 UTC, in the docs pass after #10416). diff --git a/docs/GLOSSARY.md b/docs/GLOSSARY.md index 8ae905562a..5caa869d02 100644 --- a/docs/GLOSSARY.md +++ b/docs/GLOSSARY.md @@ -1287,6 +1287,10 @@ A **blank** in a plain paper (v2.9059, punch list #457, step 2) is a key in brac Until v2.9068 the app held every paper that carried a blank (`PLAIN_BLANKS_ARE_FILLED`, the app's own switch, kept in `src/lib/contracts/plainBlanksLive.ts` since v2.9066 and false until then), and the signing page still offers no words that show a blank (`showsUnfilledBlank`). Since v2.9066 the three functions fill them (`paperBlanksFor` in `supabase/functions/_shared/paperBlankValues.ts`): the signer's page answers the words filled, the signing keeps what each blank read in `blank_values`, the PDF prints a signed copy from it, and a blank with no value answers `paper_not_ready`. Since v2.9068 that switch is on, a send is held only for a blank that has no value, named with its door (`blankSendHoldWords` in [`blankSendHold.ts`](../src/lib/contracts/blankSendHold.ts), over the functions' own `blankValuesNow` read with the sender's client), and the signed record window shows a signed copy's blanks as the values it kept (`signedCopyWords`). +Since v2.9281 a **blank nobody fills** is a second kind: a name in square brackets a person typed, such as `[Company legal name]`, which the app fills from nowhere and draws as a ruled line of eighteen underscores wherever a signer reads the paper ([`paperRuledBlanks.ts`](../supabase/functions/_shared/paperRuledBlanks.ts), read by the client and by the two functions that draw a paper's PDF). +The line is drawn on the signing page, the signed record, **Read the paper** in the send window, the library's **Preview** and both PDFs (`paperParagraphs`), and never written: the row keeps the bracket and its name, and nothing is kept for it in `blank_values`. +The library's **Edit**, **View** and **History** and the preview's **Download** keep the name. +One rule decides what is a blank (`isRuledBlankName`, `ruledBlanksInText`): a one-line name of 2 to 60 characters that starts with a letter, not a tick box, a footnote, a list mark, a lawyer's mark such as `[sic]` or `[Reserved]`, a bracket that touches a letter, or a Markdown link. Since v2.9099 (finding 707) the three roads that call `send-contract-for-signature` themselves hold such a paper too, a trade company's paper on People → Contracts, a GC-mode partner's paper and a job's **Copy the signing link**, each through `blankHoldForCopy` in [`personPaperSendIo.ts`](../src/lib/contracts/personPaperSendIo.ts) with the door of its own road (`BlankHoldRoad`). Since v2.9081 the company's own two values for a secrecy paper have a home, two rows of `app_settings` set by the owner or a dev on Settings → Company → **The company on our secrecy papers** ([`SecrecyCompanyValuesCard.tsx`](../src/components/settings/SecrecyCompanyValuesCard.tsx) over [`companyPaperValues.ts`](../src/lib/contracts/companyPaperValues.ts)): the company's legal name, which `{company_name}` prints, and who a secrecy paper from outside the company goes to first. Since v2.9111 the functions read both (`COMPANY_BLANK_SETTINGS` in `supabase/functions/_shared/paperBlankValues.ts`, held to the app's two keys by a test), so `{company_name}` and the ninth blank `{outside_paper_goes_to}` fill on the signer's page, at the signing and on the PDF, and a send is held by name while one is not set, with the door *The owner or a dev sets it on Settings, Company, under The company on our secrecy papers.* diff --git a/docs/recent-features/v2.9281.md b/docs/recent-features/v2.9281.md new file mode 100644 index 0000000000..a245b72041 --- /dev/null +++ b/docs/recent-features/v2.9281.md @@ -0,0 +1,58 @@ +# v2.9281 — Papers: a blank nobody filled reads as a ruled line (2026-12-03) + +The owner was asked whether a signer should ever be shown a paper with unfilled blanks like `[Company legal name]`. Their words: *no, make them "__________________"*. + +**Owes prod two function deploys after the merge: `accept-contract` and `person-paper-pdf`.** No migration. The client's half is live with the Pages deploy. + +## What a blank is, as the source had it + +A paper had one kind of blank: a key in braces off the app's list of nine, such as `{code_name}`, put in by **Add a blank** and filled by the functions when the paper is read ([`plainPaperBlanks.ts`](../../src/lib/contracts/plainPaperBlanks.ts), `paperBlanksFor`). A signed copy keeps what each read in `blank_values`. + +A name in square brackets, such as `[Company legal name]`, was plain words to the app. Nothing filled it, at the send or after, and the signer read the brackets. The secrecy papers hold these. + +## What changed + +One kernel decides what is a blank nobody fills and draws it: [`paperRuledBlanks.ts`](../../supabase/functions/_shared/paperRuledBlanks.ts), under `supabase/functions/_shared` so the client and the functions read the one file. The braces kernel is untouched. + +**The line** is eighteen underscores, the string the owner typed. The words before it are kept: *Company:* and then the line. + +**Where the rule holds:** + +- **The signer's page** (`/contract/accept`), a plain paper's box and the full agreement of a paper built from clauses (`ContractBodyDisplay`'s `ruleBlanks`). +- **The PDFs** (`paperParagraphs` in `_shared/personPaperPdf.ts`): the signed copy `accept-contract` draws and emails, and every PDF `person-paper-pdf` draws, a paper that is out and not signed among them. +- **The signed record** window, beside the values a signature kept. +- **Read the paper** in the send window, which draws the paper as the signer reads it. Under the paper it names each blank nothing fills (`ruledBlanksNote`), so the sender still knows what each line stands for. +- **Preview**, the Contract library's page that prints. + +**Where it does not, on purpose:** the library's **Edit**, **View** and **History**, and the preview's **Download**, keep the name in brackets. The office writes there, and that file is for editing. The email carries no words of the paper: the PDF is its copy. + +## What counts as a blank + +A pair of square brackets on one line, holding a name of 2 to 60 characters that starts with a letter and is made of letters, digits, spaces and `' - / & . , #`. These are the paper's own words and stay as typed: + +- a tick box (`[x]`, `[ ]`), a footnote (`[1]`, `[^1]`), a list mark (`[a]`, `[ii]`), an ellipsis; +- a lawyer's or an editor's mark: `[sic]`, `[Reserved]`, `[Signature page follows]`, `[Remainder of page intentionally left blank]`, `[emphasis added]`, `[Seal]`, `[N/A]`; +- a bracket that touches a letter or a digit: `[T]he`, `employee[s]`; +- a bracket that holds a quote mark, a colon, a dollar sign or a sentence's other marks; +- in Markdown, a link, a picture and a link's reference. + +Markdown is ruled after it is made plain words or HTML, never before: a line of underscores in Markdown source is a rule across the page, or a bold mark. + +## What the signed record holds + +Nothing new. The line is drawn, never written. A paper signed with a line still ruled keeps its words as written, bracket and name (`signing_body_html`), and `blank_values` holds nothing for it, since nothing was typed. The signed record window and the signed PDF draw the line there. So the record says that the blank was left empty, and the row still says which blank it was. + +A signer cannot type into a ruled line on the page. Filling one is by pen, on a print. + +## Seen and left + +- A short name in square brackets that an older paper meant as its own words is now a line. One test's placeholder, `[brackets]`, was such a name and now reads `[sic]`. **Read the paper** names every line before a send. +- A signed PDF kept before the deploy is handed back as it was drawn, brackets and all. The signed record window draws the line for the same paper. +- Between the Pages deploy and the two function deploys, a signer reads lines on the page and a new PDF still prints the brackets. +- `/contract/sign`, the job's own contract, is another page with another PDF and is not ruled. +- A paper built from clauses is ruled in its full agreement's words, not in the clauses the database assembles. +- HTML's own writing of a bracket (`[`), and a name cut in two by a tag, are not read as blanks. + +## Tests + +`paperRuledBlanks.test.ts` (38: the rule, the own words, Markdown, HTML), `personPaperPdf.test.ts` (the PDF's paragraphs, the app's blanks filled first), `readThePaper.test.ts` (the note), and render tests for the signer's page, the signed record, the send window and the preview. diff --git a/scripts/lowest-kernels.json b/scripts/lowest-kernels.json index 01f4f0d026..172df9f6c2 100644 --- a/scripts/lowest-kernels.json +++ b/scripts/lowest-kernels.json @@ -241,6 +241,7 @@ "../supabase/functions/_shared/paintedMapLink.ts", "../supabase/functions/_shared/paperBlankValues.ts", "../supabase/functions/_shared/paperChecks.ts", + "../supabase/functions/_shared/paperRuledBlanks.ts", "../supabase/functions/_shared/paperSignedNotice.ts", "../supabase/functions/_shared/paperSigner.ts", "../supabase/functions/_shared/paperSitePrint.ts", diff --git a/src/components/contracts/ContractBodyDisplay.tsx b/src/components/contracts/ContractBodyDisplay.tsx index 4e27f69191..b1d7925d38 100644 --- a/src/components/contracts/ContractBodyDisplay.tsx +++ b/src/components/contracts/ContractBodyDisplay.tsx @@ -1,15 +1,23 @@ import type { CSSProperties } from 'react' import { renderContractBodyToSafeHtml } from '../../lib/renderContractBodyToSafeHtml' +import { ruleBlanksInHtml } from '../../../supabase/functions/_shared/paperRuledBlanks' type ContractBodyDisplayProps = { format: string | null | undefined bodyHtml: string | null | undefined /** Extra style for scroll container (modal views). */ scrollStyles?: CSSProperties + /** + * Draw a blank nobody filled, a name in square brackets like `[Company legal name]`, as a ruled line (v2.9281). + * For a window where a signer reads the paper, or the office reads it as the signer does. The office's own windows + * on the library leave it off and keep the name. + */ + ruleBlanks?: boolean } -export function ContractBodyDisplay({ format, bodyHtml, scrollStyles }: ContractBodyDisplayProps) { - const safe = renderContractBodyToSafeHtml(bodyHtml, format) +export function ContractBodyDisplay({ format, bodyHtml, scrollStyles, ruleBlanks = false }: ContractBodyDisplayProps) { + const drawn = renderContractBodyToSafeHtml(bodyHtml, format) + const safe = ruleBlanks ? ruleBlanksInHtml(drawn) : drawn if (!safe.trim()) return null return ( diff --git a/src/components/contracts/ContractSendWindow.readThePaper.render.test.tsx b/src/components/contracts/ContractSendWindow.readThePaper.render.test.tsx index 65bd6fc244..345ba61990 100644 --- a/src/components/contracts/ContractSendWindow.readThePaper.render.test.tsx +++ b/src/components/contracts/ContractSendWindow.readThePaper.render.test.tsx @@ -121,6 +121,20 @@ describe('ContractSendWindow · a copy whose words are in no version of the pape }) describe('ContractSendWindow · Read the paper', () => { + it('draws a blank nobody fills as the line the signer reads, and names what each line stands for (v2.9281)', async () => { + open({ plan: { kind: 'insert', source: { ...SOURCE, signingBodyHtml: '

Company: [Company legal name]

Site: [address]

' } }, docId: null }) + fireEvent.click(await screen.findByRole('button', { name: 'Read the paper' })) + expect(screen.getByTestId('contract-send-paper-words').textContent).toBe('Company: __________________Site: __________________') + expect(screen.getByTestId('contract-send-ruled-blanks').textContent).toBe('The signer reads a line to write on for each of these 2 blanks: Company legal name and address. Nothing fills them.') + }) + + it('says nothing of lines under a paper with no such blank', async () => { + open({ plan: { kind: 'insert', source: { ...SOURCE, signingBodyHtml: '

Section 4. [Reserved]

' } }, docId: null }) + fireEvent.click(await screen.findByRole('button', { name: 'Read the paper' })) + expect(screen.getByTestId('contract-send-paper-words').textContent).toBe('Section 4. [Reserved]') + expect(screen.queryByTestId('contract-send-ruled-blanks')).toBeNull() + }) + it('a first send shows its plan’s words at once, a change for this send among them, and reads no row', async () => { open({ plan: { kind: 'insert', source: { ...SOURCE, signingBodyHtml: '

Changed for ZZ Test Supply alone.

' } }, docId: null }) const press = await screen.findByRole('button', { name: 'Read the paper' }) diff --git a/src/components/contracts/PersonContractSignedRecordModal.reader.render.test.tsx b/src/components/contracts/PersonContractSignedRecordModal.reader.render.test.tsx index dc09553890..cb5662a974 100644 --- a/src/components/contracts/PersonContractSignedRecordModal.reader.render.test.tsx +++ b/src/components/contracts/PersonContractSignedRecordModal.reader.render.test.tsx @@ -109,6 +109,14 @@ describe('PersonContractSignedRecordModal · the form’s layout and the signatu expect(document.body.textContent).not.toContain('{code_name}') }) + it('shows a blank nobody filled as the line the signer read, beside a blank the signature kept (v2.9281)', async () => { + db.body = '

Project {code_name}. Vendor: [Vendor legal name].

' + db.blanks = { code_name: 'Sample Site A' } + renderWithProviders( {}} />) + expect(await screen.findByText((_, el) => el?.tagName === 'P' && el.textContent === 'Project Sample Site A. Vendor: __________________.')).toBeTruthy() + expect(document.body.textContent).not.toContain('[Vendor legal name]') + }) + it('draws the signature’s image when it opens', async () => { renderWithProviders( {}} />) const image = await screen.findByAltText('Signer signature') diff --git a/src/components/contracts/PersonContractSignedRecordModal.tsx b/src/components/contracts/PersonContractSignedRecordModal.tsx index 052869c784..6e1cc86a72 100644 --- a/src/components/contracts/PersonContractSignedRecordModal.tsx +++ b/src/components/contracts/PersonContractSignedRecordModal.tsx @@ -556,7 +556,7 @@ export function PersonContractSignedRecordModal({
The full agreement
- +
) : null} @@ -574,7 +574,7 @@ export function PersonContractSignedRecordModal({ marginBottom: '0.75rem', }} > - + ) : null} diff --git a/src/components/contracts/SendWindowReadThePaper.tsx b/src/components/contracts/SendWindowReadThePaper.tsx index 206a187cd5..e0975dd107 100644 --- a/src/components/contracts/SendWindowReadThePaper.tsx +++ b/src/components/contracts/SendWindowReadThePaper.tsx @@ -7,7 +7,9 @@ */ import { useCallback, useEffect, useState, type CSSProperties } from 'react' import { formatErrorMessage } from '../../utils/errorHandling' -import { READ_THE_PAPER, type PaperWordsToRead, type ReadThePaperView } from '../../lib/contracts/readThePaper' +import { READ_THE_PAPER, ruledBlanksNote, type PaperWordsToRead, type ReadThePaperView } from '../../lib/contracts/readThePaper' +import { renderContractBodyToSafeHtml } from '../../lib/renderContractBodyToSafeHtml' +import { ruledBlankNamesInHtml } from '../../../supabase/functions/_shared/paperRuledBlanks' import { readPaperWords } from '../../lib/contracts/personPaperSendIo' import { ContractBodyDisplay } from './ContractBodyDisplay' @@ -55,6 +57,8 @@ export function SendWindowReadThePaper({ views, pressFloor }: { views: ReadThePa if (!view) return null const mine = view.source.kind === 'copy' && copy?.docId === view.source.docId ? copy : null const words = view.source.kind === 'held' ? view.source.words : mine?.state === 'read' ? mine.words : null + // The paper is drawn as the signer reads it, a line for each blank nobody fills, so the names are said under it. + const ruledNote = open && words ? ruledBlanksNote(ruledBlankNamesInHtml(renderContractBodyToSafeHtml(words.body, words.format))) : null return (
@@ -92,9 +96,16 @@ export function SendWindowReadThePaper({ views, pressFloor }: { views: ReadThePa
) : words && words.body.trim() ? ( // Paper is light in either theme, as the signer's page draws it. -
- -
+ <> +
+ +
+ {ruledNote ? ( +

+ {ruledNote} +

+ ) : null} + ) : (

{READ_THE_PAPER.noWords}

)} diff --git a/src/content/help/manage-the-contract-library-and-packets.md b/src/content/help/manage-the-contract-library-and-packets.md index 60d7374e18..425610284f 100644 --- a/src/content/help/manage-the-contract-library-and-packets.md +++ b/src/content/help/manage-the-contract-library-and-packets.md @@ -205,6 +205,38 @@ A blank with no value holds the send. The send window names each empty blank and A value can change while a signer has the paper open. Their page then says the paper changed. They press **Reload** and read the new value before they sign. +## A blank nobody fills + +Some blanks are filled by pen, not by the app. Type a name in square brackets where the line should go, like `[Vendor legal name]`. + +The signer never reads the brackets. They read a ruled line to write on. The words before the line stay as you typed them. + +:::example What you type, and what the signer reads +You type: Company: `[Company legal name]` + +The signer reads: Company: __________________ +::: + +The line shows in four places. + +- The signer's page. +- The PDF, signed or still waiting. +- The signed record. +- **Preview**, the page that prints. + +**Edit**, **View** and **History** keep the name in brackets, so you can tell what each line stands for. **Download** on the preview keeps the name too, since that file is for editing. + +**Read the paper** in the send window draws the lines as the signer reads them. Under the paper it names each blank that nothing fills. + +A name is short and starts with a letter. It holds letters, numbers and spaces. These stay as typed, since they are the paper's own words. + +- A tick box, like `[x]`. +- A footnote, like `[1]`. +- A lawyer's mark, like `[sic]`, `[Reserved]` or `[Signature page follows]`. +- A bracket that touches a letter, like `employee[s]`. + +Nothing is typed into a ruled line in the app. A signer who signs here leaves the line empty. To fill it by pen, print the PDF or the preview. + ## Packets: bundles you assign as a set A **packet** is a named bundle of library documents, like *All Teammates*. It was previously called a template. You assign it to a person in one step. diff --git a/src/content/releaseNotes/v2.9281.ts b/src/content/releaseNotes/v2.9281.ts new file mode 100644 index 0000000000..ed124cb141 --- /dev/null +++ b/src/content/releaseNotes/v2.9281.ts @@ -0,0 +1,16 @@ +import type { ReleaseNote } from '../../lib/releaseNotes' + +const note: ReleaseNote = { + version: 'v2.9281', + date: '2026-12-03', + title: 'Papers: a blank nobody filled reads as a ruled line', + kind: 'feature', + highlights: [ + 'A name typed in square brackets, like [Company legal name], is now a blank nobody fills. A signer never reads the brackets. They read a line to write on, with the words before it kept.', + 'The line shows on the signing page, on the signed record, on the PDF and on the Contract library’s Preview, which now prints as a paper to fill in by pen.', + 'Edit, View and History keep the name in brackets. Read the paper in the send window shows the lines and names each blank under the paper.', + 'A bracket that is the paper’s own words stays as typed: a tick box, a footnote, [sic], [Reserved] or [Signature page follows].', + ], +} + +export default note diff --git a/src/lib/contracts/paperRuledBlanks.test.ts b/src/lib/contracts/paperRuledBlanks.test.ts new file mode 100644 index 0000000000..abc10bde14 --- /dev/null +++ b/src/lib/contracts/paperRuledBlanks.test.ts @@ -0,0 +1,175 @@ +// @vitest-environment jsdom +// jsdom, since the page's HTML is made safe by the browser's own parser. +import { describe, expect, it } from 'vitest' +import { + RULED_LINE, + RULED_LINE_HTML, + isRuledBlankName, + ruleBlanksInHtml, + ruleBlanksInText, + ruledBlankNames, + ruledBlanksInText, +} from '../../../supabase/functions/_shared/paperRuledBlanks' +import { contractBodyToPlainText } from '../../../supabase/functions/_shared/jobContractPdf' +import { fillPlainBlanks } from './plainPaperBlanks' +import { renderContractBodyToSafeHtml } from '../renderContractBodyToSafeHtml' + +/** Every name here is a placeholder: the words of a made-up secrecy paper. */ +const L = RULED_LINE + +describe('a blank nobody filled is a ruled line', () => { + it('the line is the one the owner typed: eighteen underscores', () => { + expect(RULED_LINE).toBe('__________________') + expect(RULED_LINE).toHaveLength(18) + }) + + it('rules the four blanks of a secrecy paper, and keeps the words before each', () => { + const paper = ['Company: [Company legal name]', 'Vendor: [Vendor legal name]', 'Project: [code name]', 'Site: [address]'].join('\n') + expect(ruleBlanksInText(paper)).toBe([`Company: ${L}`, `Vendor: ${L}`, `Project: ${L}`, `Site: ${L}`].join('\n')) + expect(ruledBlankNames(paper)).toEqual(['Company legal name', 'Vendor legal name', 'code name', 'address']) + }) + + it('leaves words with no blank exactly as they are', () => { + const paper = 'The Vendor keeps the Project secret for two years.\n\nSigned at the site.' + expect(ruleBlanksInText(paper)).toBe(paper) + expect(ruleBlanksInText('')).toBe('') + expect(ruleBlanksInText(null)).toBe('') + expect(ruledBlankNames(paper)).toEqual([]) + }) + + it('rules a blank in the middle of a sentence, and two in one line', () => { + expect(ruleBlanksInText('This agreement is between [Company legal name] and [Vendor legal name], as of [date].')).toBe(`This agreement is between ${L} and ${L}, as of ${L}.`) + }) + + it('says where each blank stands', () => { + expect(ruledBlanksInText('Site: [address]')).toEqual([{ name: 'address', start: 6, end: 15 }]) + }) + + it('names a blank once however often it is written, case aside', () => { + expect(ruledBlankNames('[Code name] and again [code name], then [address]')).toEqual(['Code name', 'address']) + }) +}) + +describe('a bracket that is the paper’s own words is not ruled', () => { + const own = [ + 'The parties [sic] agree.', + '[Signature page follows]', + '[Signature Page to Follow]', + '[Remainder of page intentionally left blank]', + '[This page intentionally left blank]', + '[Intentionally omitted]', + 'Section 4. [Reserved]', + 'as the court held [emphasis added]', + '[citation omitted]', + '[alteration in original]', + '[Seal]', + '[L.S.]', + 'Fee: [N/A]', + '[Redacted]', + '[Continued on next page]', + '[End of agreement]', + ] + it.each(own)('%s', (words) => { + expect(ruleBlanksInText(words)).toBe(words) + }) + + it('a tick box, a footnote and a list mark keep their brackets', () => { + for (const words of ['[x] Agreed', '[X] Agreed', '[ ] Not agreed', 'as shown[1]', 'see note [12]', 'see note [^3]', '[a] the first, [b] the second', '[i] one, [ii] two, [iv] four', '[...]', '[…]']) { + expect(ruleBlanksInText(words)).toBe(words) + } + }) + + it('a quote’s alterations keep their brackets: a bracket that touches a letter', () => { + for (const words of ['"[T]he Vendor shall"', 'each employee[s]', 'the vendor[s’] duty', 'clause 4[b]']) { + expect(ruleBlanksInText(words)).toBe(words) + } + }) + + it('a bracket that holds a sentence’s marks is words, not a name', () => { + for (const words of ['[the "Company"]', '[see Exhibit A: the site plan]', '[$500 per day]', '[as amended; see above]', '[Is this right?]', '[50% of the fee]']) { + expect(ruleBlanksInText(words)).toBe(words) + } + }) + + it('a run too long to be a name is words', () => { + const long = `[${'the vendor shall keep every drawing and every word of it secret '.repeat(1).trim()}]` + expect(long.length).toBeGreaterThan(62) + expect(ruleBlanksInText(long)).toBe(long) + expect(isRuledBlankName('a'.repeat(60))).toBe(true) + expect(isRuledBlankName('a'.repeat(61))).toBe(false) + }) + + it('a bracket that runs over two lines is words', () => { + const words = 'between [Company\nlegal name] and the Vendor' + expect(ruleBlanksInText(words)).toBe(words) + }) + + it('names with the marks a name carries are blanks', () => { + for (const name of ['Vendor’s legal name', "Owner's rep", 'City, State', 'P.O. box', 'Suite #', 'Day/Month/Year', 'A & B Supply', 'co-signer', 'TBD', 'Date 2']) { + expect(isRuledBlankName(name)).toBe(true) + } + }) +}) + +describe('the app’s own blanks are another kind and are left alone', () => { + it('a key in braces is never ruled', () => { + const paper = 'Project: {code_name}. Company: [Company legal name].' + expect(ruleBlanksInText(paper)).toBe(`Project: {code_name}. Company: ${L}.`) + }) + + it('a paper is filled first and ruled after, and a filled value is untouched', () => { + const filled = fillPlainBlanks('Project: {code_name}. Vendor: [Vendor legal name].', { code_name: 'Sample Site A' }, 'plain').body + expect(ruleBlanksInText(filled)).toBe(`Project: Sample Site A. Vendor: ${L}.`) + }) +}) + +describe('Markdown', () => { + it('a link, a picture and a link’s reference keep their brackets in Markdown source', () => { + const md = { markdown: true } + for (const words of ['[our site](https://example.com)', '![the logo](logo.png)', '[the terms][terms]', '[terms]: https://example.com/terms']) { + expect(ruleBlanksInText(words, md)).toBe(words) + } + expect(ruleBlanksInText('Company: [Company legal name]', md)).toBe(`Company: ${L}`) + // A colon after a blank in the middle of a line is a sentence's own. + expect(ruleBlanksInText('For [Company legal name]: the terms below.', md)).toBe(`For ${L}: the terms below.`) + }) + + it('the PDF’s words are made plain first and ruled after, so Markdown never reads the line as a mark', () => { + const source = '## Parties\n\n**Company:** [Company legal name]\n\n[Vendor legal name] and [code name]' + const plain = contractBodyToPlainText(source, 'markdown') + expect(ruleBlanksInText(plain, { markdown: true })).toBe(`Parties\n\nCompany: ${L}\n\n${L} and ${L}`) + }) + + it('the page’s words are made HTML first and ruled after, so the line is never a rule across the page', () => { + const html = ruleBlanksInHtml(renderContractBodyToSafeHtml('**Company:** [Company legal name]\n\n[address]\n\n[our site](https://example.com)', 'markdown')) + expect(html).toContain(`Company: ${RULED_LINE_HTML}`) + expect(html).toContain(`

${RULED_LINE_HTML}

`) + expect(html).not.toContain('our site') + }) +}) + +describe('a page’s HTML', () => { + it('rules the words between tags and never a tag’s own', () => { + const html = '

Company: [Company legal name]

the [sic] site

' + expect(ruleBlanksInHtml(html)).toBe(`

Company: ${RULED_LINE_HTML}

the [sic] site

`) + }) + + it('reads a name with an ampersand as HTML writes it', () => { + expect(ruleBlanksInHtml('

[A & B Supply legal name]

')).toBe(`

${RULED_LINE_HTML}

`) + }) + + it('a plain paper, drawn for the page, is ruled where its blanks stand', () => { + const html = ruleBlanksInHtml(renderContractBodyToSafeHtml('Company: [Company legal name]\nSite: [address]', 'plain')) + expect(html).toContain(`Company: ${RULED_LINE_HTML}\nSite: ${RULED_LINE_HTML}`) + }) + + it('HTML with no bracket comes back as it is', () => { + expect(ruleBlanksInHtml('

No blank here.

')).toBe('

No blank here.

') + expect(ruleBlanksInHtml(null)).toBe('') + }) + + it('the office’s own window may draw the line with the blank’s name on it', () => { + expect(ruleBlanksInHtml('

Site: [address]

', (b) => `${RULED_LINE}`)).toBe(`

Site: ${RULED_LINE}

`) + }) +}) diff --git a/src/lib/contracts/personPaperPdf.test.ts b/src/lib/contracts/personPaperPdf.test.ts index b43bb0d747..d55ee377f9 100644 --- a/src/lib/contracts/personPaperPdf.test.ts +++ b/src/lib/contracts/personPaperPdf.test.ts @@ -20,6 +20,21 @@ describe('the paper’s words', () => { expect(paperParagraphs({ signing_body_html: '

Placeholder {party} words.

', signing_body_format: 'html', blank_values: { party: 'x' } })).toEqual(['Placeholder {party} words.']) }) + it('prints a blank nobody filled as a line to write on, with the words before it kept (v2.9281)', () => { + const line = '__________________' + expect(paperParagraphs({ signing_body_html: 'Company: [Company legal name]\nVendor: [Vendor legal name]\n\nProject [code name] at [address].', signing_body_format: 'plain' })).toEqual([`Company: ${line}`, `Vendor: ${line}`, `Project ${line} at ${line}.`]) + expect(paperParagraphs({ signing_body_html: '

Company: [Company legal name]

', signing_body_format: 'html' })).toEqual([`Company: ${line}`]) + expect(paperParagraphs({ signing_body_html: '**Company:** [Company legal name]\n\n[Vendor legal name] and [code name]', signing_body_format: 'markdown' })).toEqual([`Company: ${line}`, `${line} and ${line}`]) + }) + + it('fills the app’s own blanks first, and rules only what nobody filled', () => { + const line = '__________________' + const words = 'Project: {code_name}. Vendor: [Vendor legal name].' + expect(paperParagraphs({ signing_body_html: words, signing_body_format: 'plain', blank_values: { code_name: 'Sample Site A' } })).toEqual([`Project: Sample Site A. Vendor: ${line}.`]) + // A value that holds a bracket of its own is a value, and is ruled like any other words: nothing kept says which it was. + expect(paperParagraphs({ signing_body_html: 'Section 4. [Reserved]\n[Signature page follows]', signing_body_format: 'plain' })).toEqual(['Section 4. [Reserved]', '[Signature page follows]']) + }) + it('reads a body of plain words as paragraphs', () => { expect(paperParagraphs({ signing_body_html: 'First.\n\nSecond line one\nSecond line two', signing_body_format: 'plain' })).toEqual(['First.', 'Second line one', 'Second line two']) }) diff --git a/src/lib/contracts/readThePaper.test.ts b/src/lib/contracts/readThePaper.test.ts index d167e4b0d9..900b5447c8 100644 --- a/src/lib/contracts/readThePaper.test.ts +++ b/src/lib/contracts/readThePaper.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from 'vitest' import type { QuickSendPlan } from '../contractsQuickSend' -import { READ_THE_PAPER, readThePaperSource, readThePaperViews } from './readThePaper' +import { READ_THE_PAPER, readThePaperSource, readThePaperViews, ruledBlanksNote } from './readThePaper' const book = (words: string | null, format = 'markdown') => ({ kind: 'book' as const, appliedTemplateDocumentId: 'paper-1', signingBodyHtml: words, signingBodyFormat: format, canonicalDocumentUrl: null }) @@ -65,3 +65,15 @@ describe('what Read the paper offers', () => { expect(readThePaperViews({ source: null, today: { body: 'Today’s words.', format: 'plain' } })).toEqual([]) }) }) + +describe('the note under a paper that holds blanks nobody fills (v2.9281)', () => { + it('says nothing for a paper with none', () => { + expect(ruledBlanksNote([])).toBeNull() + }) + it('names the one blank', () => { + expect(ruledBlanksNote(['address'])).toBe('The signer reads a line to write on where the paper says address. Nothing fills it.') + }) + it('counts and names several', () => { + expect(ruledBlanksNote(['Company legal name', 'Vendor legal name', 'code name', 'address'])).toBe('The signer reads a line to write on for each of these 4 blanks: Company legal name, Vendor legal name, code name and address. Nothing fills them.') + }) +}) diff --git a/src/lib/contracts/readThePaper.ts b/src/lib/contracts/readThePaper.ts index 62ab580daa..0d1e634992 100644 --- a/src/lib/contracts/readThePaper.ts +++ b/src/lib/contracts/readThePaper.ts @@ -14,6 +14,7 @@ * Pure: no React, no supabase. */ import type { QuickSendPlan } from '../contractsQuickSend' +import { andList } from './assemble' export const READ_THE_PAPER = { press: 'Read the paper', @@ -29,6 +30,16 @@ export const READ_THE_PAPER = { tryAgain: 'Try again', } as const +/** + * What the window says under a paper that holds blanks nobody fills (v2.9281). The signer reads each as a line to + * write on, and so does this window, so the note keeps the names the lines stand for. Null when there is none. + */ +export function ruledBlanksNote(names: readonly string[]): string | null { + if (names.length === 0) return null + if (names.length === 1) return `The signer reads a line to write on where the paper says ${names[0]}. Nothing fills it.` + return `The signer reads a line to write on for each of these ${names.length} blanks: ${andList(names)}. Nothing fills them.` +} + /** A paper's words and the format they are written in. */ export type PaperWordsToRead = { body: string; format: string } diff --git a/src/pages/ContractAccept.blanks.render.test.tsx b/src/pages/ContractAccept.blanks.render.test.tsx index 83dcd70412..0120da5efd 100644 --- a/src/pages/ContractAccept.blanks.render.test.tsx +++ b/src/pages/ContractAccept.blanks.render.test.tsx @@ -123,10 +123,45 @@ describe('the sign page and a paper that shows a blank', () => { }) it('offers a paper with no blank as it always did, braces round any other word among them', async () => { - loaded = { ...PLAIN, signing_body_html: '

Placeholder words with {party} and [brackets].

' } + // `[sic]` is the paper's own words. A name in square brackets is a blank nobody fills since v2.9281, drawn below. + loaded = { ...PLAIN, signing_body_html: '

Placeholder words with {party} and brackets [sic].

' } open() - expect(await screen.findByText(/Placeholder words with \{party\} and \[brackets\]\./)).toBeTruthy() + expect(await screen.findByText(/Placeholder words with \{party\} and brackets \[sic\]\./)).toBeTruthy() expect(screen.queryByTestId('paper-shows-blank')).toBeNull() expect(screen.getAllByRole('button').length).toBeGreaterThan(0) }) }) + +/** v2.9281: a name in square brackets is a blank nobody fills. The signer reads a line to write on, never the bracket. */ +describe('the sign page and a blank nobody filled', () => { + const LINE = '__________________' + /** A paragraph by all its words: the line is a piece of its own inside it. */ + const para = (words: string) => (_: string, el: Element | null) => (el?.tagName === 'P' || el?.getAttribute('style')?.includes('pre-wrap') === true) && el.textContent === words + + it('draws each as a ruled line with the words before it kept, and the paper still signs', async () => { + loaded = { ...PLAIN, signing_body_html: '

Company: [Company legal name]

Project [code name] at [address].

' } + open() + expect(await screen.findByText(para(`Company: ${LINE}`))).toBeTruthy() + expect(screen.getByText(para(`Project ${LINE} at ${LINE}.`))).toBeTruthy() + expect(document.querySelectorAll('[data-ruled-blank]')).toHaveLength(3) + expect(document.body.textContent).not.toContain('[Company legal name]') + expect(document.body.textContent).not.toContain('[code name]') + expect(screen.queryByTestId('paper-shows-blank')).toBeNull() + sign('Lena Park') + await waitFor(() => expect(posts).toHaveLength(1)) + expect(posts[0]).toMatchObject({ token: 'tok-9', printedName: 'Lena Park' }) + }) + + it('leaves a bracket that is the paper’s own words as written', async () => { + loaded = { ...PLAIN, signing_body_html: '

Section 4. [Reserved]

[Signature page follows]

' } + open() + expect(await screen.findByText('Section 4. [Reserved]')).toBeTruthy() + expect(screen.getByText('[Signature page follows]')).toBeTruthy() + }) + + it('a plain paper reads the same way', async () => { + loaded = { ...PLAIN, signing_body_format: 'plain', signing_body_html: 'Vendor: [Vendor legal name]' } + open() + expect(await screen.findByText(para(`Vendor: ${LINE}`))).toBeTruthy() + }) +}) diff --git a/src/pages/ContractAccept.tsx b/src/pages/ContractAccept.tsx index 07c18fdc34..0acff7e402 100644 --- a/src/pages/ContractAccept.tsx +++ b/src/pages/ContractAccept.tsx @@ -682,7 +682,7 @@ export default function ContractAccept() { {CLAUSE_SIGN_WORDS[paperLang].full}
- +
@@ -697,6 +697,7 @@ export default function ContractAccept() { diff --git a/src/pages/ContractBookPreview.render.test.tsx b/src/pages/ContractBookPreview.render.test.tsx new file mode 100644 index 0000000000..f69b46a8d6 --- /dev/null +++ b/src/pages/ContractBookPreview.render.test.tsx @@ -0,0 +1,48 @@ +// @vitest-environment jsdom +/** + * The Contract library's Preview, the page that prints (v2.9281). A blank nobody fills, a name in square brackets, is + * drawn as a line to write on, so the page prints as a paper to fill in by hand. **Download** keeps the name, since + * that file is for editing. Every word is a placeholder. + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { cleanup, render, screen } from '@testing-library/react' +import { MemoryRouter } from 'react-router-dom' +import ContractBookPreview from './ContractBookPreview' +import { writeContractPreviewEntry } from '../lib/contractBookPreviewHandoff' +import { buildContractRichTextDocument } from '../lib/contractRichTextDocument' + +// The page makes its Download a file in the browser, and jsdom has no such thing. +beforeEach(() => { + URL.createObjectURL = vi.fn(() => 'blob:zz-test') as unknown as typeof URL.createObjectURL + URL.revokeObjectURL = vi.fn() as unknown as typeof URL.revokeObjectURL +}) +afterEach(() => { + cleanup() + localStorage.clear() +}) + +const ENTRY = { document_name: 'ZZ Test secrecy paper', book_body_html: 'Company: [Company legal name]\nSection 4. [Reserved]', book_body_format: 'plain' } + +function open(entry: typeof ENTRY) { + const key = writeContractPreviewEntry(entry) + return render( + + + , + ) +} + +describe('ContractBookPreview · a blank nobody fills', () => { + it('prints it as a line to write on, and leaves the paper’s own brackets', () => { + open(ENTRY) + expect(screen.getByRole('heading', { name: 'ZZ Test secrecy paper' })).toBeTruthy() + const body = document.querySelector('.cbp-body')?.textContent ?? '' + expect(body).toContain('Company: __________________') + expect(body).not.toContain('[Company legal name]') + expect(body).toContain('Section 4. [Reserved]') + }) + + it('Download keeps the name, since that file is for editing', () => { + expect(buildContractRichTextDocument(ENTRY).content).toContain('[Company legal name]') + }) +}) diff --git a/src/pages/ContractBookPreview.tsx b/src/pages/ContractBookPreview.tsx index 97118b179d..0096d166a7 100644 --- a/src/pages/ContractBookPreview.tsx +++ b/src/pages/ContractBookPreview.tsx @@ -2,6 +2,7 @@ import { useEffect, useMemo, type CSSProperties } from 'react' import { Link, useSearchParams } from 'react-router-dom' import { parseContractPreviewEntry } from '../lib/contractBookPreviewHandoff' import { renderContractBodyToSafeHtml } from '../lib/renderContractBodyToSafeHtml' +import { ruleBlanksInHtml } from '../../supabase/functions/_shared/paperRuledBlanks' import { buildContractRichTextDocument, type ContractBookExportEntry } from '../lib/contractRichTextDocument' /** @@ -99,7 +100,8 @@ export default function ContractBookPreview() { ) } - const bodyHtml = renderContractBodyToSafeHtml(entry.book_body_html, entry.book_body_format) + // The page that prints: a blank nobody fills is a line to write on (v2.9281). Download keeps the name, to edit. + const bodyHtml = ruleBlanksInHtml(renderContractBodyToSafeHtml(entry.book_body_html, entry.book_body_format)) return (
diff --git a/supabase/functions/_shared/paperRuledBlanks.ts b/supabase/functions/_shared/paperRuledBlanks.ts new file mode 100644 index 0000000000..20d8e6be67 --- /dev/null +++ b/supabase/functions/_shared/paperRuledBlanks.ts @@ -0,0 +1,178 @@ +/** + * A blank nobody filled, drawn as a ruled line. The owner was asked whether a signer should ever be shown a paper + * with unfilled blanks like `[Company legal name]`. Their words: *no, make them "__________________"*. + * + * A paper has two kinds of blank. One is a key in braces off the app's own list, `{code_name}`, which the app fills + * at the send (`plainPaperBlanks.ts`); this file reads none of those. The other is a name in square brackets that a + * person typed, `[Company legal name]`. Nothing fills that one: it is plain words to the app. Where a signer reads + * the paper, and on the copy they keep, it is drawn as a line to write on, with the words before it kept: *Company:* + * and then the line. The paper's own words are never changed. The row keeps the bracket and its name as written, so + * the office can still tell which blank a line stands for. + * + * One rule decides what is a blank, so a bracket that is part of a paper's own words is not ruled by mistake: + * + * - It is one line long and holds a name of 2 to 60 characters that starts with a letter. + * - The name is made of letters, digits, spaces and `' - / & . , #`. A bracket that holds a quote mark, a colon, + * a dollar sign or a sentence's other marks is the paper's own words. + * - It is not a tick box (`[x]`, `[ ]`), a footnote (`[1]`, `[^1]`), a list mark (`[a]`, `[ii]`) or an ellipsis. + * - It is not a mark an editor or a lawyer writes in brackets: `[sic]`, `[Reserved]`, `[Signature page follows]`, + * `[Remainder of page intentionally left blank]`, `[emphasis added]`, `[Seal]`, `[N/A]`. + * - It does not touch a letter or a digit: `[T]he` and `employee[s]` are a quote's alterations. + * - In Markdown it is not a link, a picture or a link's reference. + * + * Pure, and it imports nothing, so the edge functions that draw a PDF and the client that draws a page read the one + * file. + */ + +/** The line, as the owner typed it: eighteen underscores. */ +export const RULED_LINE = '__________________' + +/** A name at its longest. A longer run in brackets is a sentence, not a blank's name. */ +export const RULED_NAME_MAX = 60 + +const NAME = /^\p{L}[\p{L}\p{N} '’\-/&.,#]*$/u +const TOUCHES = /[\p{L}\p{N}]/u +const BRACKET = /\[([^[\]\n\r]{1,80})\]/gu + +/** Marks a paper writes in brackets that are its own words. Each is read against the whole name, case aside. */ +const OWN_WORDS: readonly RegExp[] = [ + /^sic$/, + /^n\/?a$/, + /^[ivxlcdm]+$/, + /^seal$/, + /^l\.? ?s\.?$/, + /^reserved$/, + /^redacted$/, + /^continued\b/, + /^end of\b/, + /^signatures? pages?\b/, + /^remainder of\b/, + /^this page\b/, + /^emphasis\b/, + /^alterations?\b/, + /\bintentionally\b/, + /\bomitted$/, + /\bin original$/, +] + +/** Whether the words inside a pair of square brackets name a blank. `inner` is what stands between the brackets. */ +export function isRuledBlankName(inner: string): boolean { + const name = inner.trim() + if (name.length < 2 || name.length > RULED_NAME_MAX) return false + if (!NAME.test(name)) return false + const low = name.toLowerCase() + return !OWN_WORDS.some((own) => own.test(low)) +} + +/** A blank where it stands in a run of words: its name, and where its brackets open and close. */ +export interface RuledBlank { + name: string + start: number + end: number +} + +export interface RuledTextOptions { + /** The words are Markdown source, so a link, a picture and a link's reference keep their brackets. */ + markdown?: boolean + /** The words are HTML's text, where `&` is written `&`. */ + htmlText?: boolean +} + +function startsItsLine(text: string, at: number): boolean { + for (let i = at - 1; i >= 0; i -= 1) { + const c = text[i] + if (c === '\n') return true + if (c !== ' ' && c !== '\t') return false + } + return true +} + +/** Every blank in a run of words, in the order it is read. */ +export function ruledBlanksInText(text: string | null | undefined, options: RuledTextOptions = {}): RuledBlank[] { + const words = text ?? '' + const out: RuledBlank[] = [] + for (const m of words.matchAll(BRACKET)) { + const start = m.index ?? 0 + const end = start + m[0].length + const before = start > 0 ? words.charAt(start - 1) : '' + const after = words.charAt(end) + if ((before && TOUCHES.test(before)) || (after && TOUCHES.test(after))) continue + if (options.markdown) { + if (before === '!' || before === ']' || after === '(' || after === '[') continue + if (after === ':' && startsItsLine(words, start)) continue + } + const written = m[1] ?? '' + const inner = options.htmlText ? written.replace(/&/g, '&') : written + if (!isRuledBlankName(inner)) continue + out.push({ name: inner.trim(), start, end }) + } + return out +} + +function ruleText(text: string, options: RuledTextOptions, draw: (blank: RuledBlank) => string): string { + const blanks = ruledBlanksInText(text, options) + if (blanks.length === 0) return text + let out = '' + let at = 0 + for (const b of blanks) { + out += text.slice(at, b.start) + draw(b) + at = b.end + } + return out + text.slice(at) +} + +/** + * A run of plain words with each blank nobody filled drawn as the line. For a PDF, a print and any other copy that is + * words alone. Markdown source is ruled after it is made plain words (`contractBodyToPlainText`), never before: a + * line of underscores in Markdown source is a rule across the page, or a bold mark. + */ +export function ruleBlanksInText(text: string | null | undefined, options: RuledTextOptions = {}): string { + return ruleText(text ?? '', options, () => RULED_LINE) +} + +/** The line as a page draws it: one piece that never breaks across two lines. */ +export const RULED_LINE_HTML = `${RULED_LINE}` + +/** + * Safe HTML with each blank nobody filled drawn as the line. `safeHtml` is what `renderContractBodyToSafeHtml` + * answers, for any format, so a Markdown link is a link already. Only the words between tags are read, so a bracket + * inside a link's address stays as written. `draw` lets a window that is the office's own draw the line another way, + * with the blank's name on it. + */ +export function ruleBlanksInHtml(safeHtml: string | null | undefined, draw: (blank: RuledBlank) => string = () => RULED_LINE_HTML): string { + const html = safeHtml ?? '' + if (!html.includes('[')) return html + return html + .split(/(<[^>]*>)/) + .map((part) => (part.startsWith('<') ? part : ruleText(part, { htmlText: true }, draw))) + .join('') +} + +function once(blanks: readonly RuledBlank[]): string[] { + const seen = new Set() + const out: string[] = [] + for (const b of blanks) { + const key = b.name.toLowerCase() + if (seen.has(key)) continue + seen.add(key) + out.push(b.name) + } + return out +} + +/** The names of a paper's blanks nobody fills, each once, in the order they are first read. */ +export function ruledBlankNames(text: string | null | undefined, options: RuledTextOptions = {}): string[] { + return once(ruledBlanksInText(text, options)) +} + +/** The same names, read off a page's safe HTML: the words between its tags. */ +export function ruledBlankNamesInHtml(safeHtml: string | null | undefined): string[] { + const html = safeHtml ?? '' + if (!html.includes('[')) return [] + return once( + html + .split(/(<[^>]*>)/) + .filter((part) => !part.startsWith('<')) + .flatMap((part) => ruledBlanksInText(part, { htmlText: true })), + ) +} diff --git a/supabase/functions/_shared/personPaperPdf.ts b/supabase/functions/_shared/personPaperPdf.ts index 2bdff3e695..6643fb02ea 100644 --- a/supabase/functions/_shared/personPaperPdf.ts +++ b/supabase/functions/_shared/personPaperPdf.ts @@ -11,6 +11,7 @@ import { keptBlankValues } from './paperBlankValues.ts' import { fillPlainBlanks } from './plainPaperBlanks.ts' import { contractBodyToPlainText, type PdfLibLike } from './jobContractPdf.ts' +import { ruleBlanksInText } from './paperRuledBlanks.ts' const PAGE_W = 612 const PAGE_H = 792 @@ -93,7 +94,9 @@ export function paperParagraphs(row: PaperWordsRow): string[] { // A plain paper's blanks print as the copy kept them at its signature (punch list #457, step 2d). A copy not yet // signed keeps none, so its PDF shows a blank as written: it is the office's own look at a waiting copy. const words = fillPlainBlanks(row.signing_body_html, keptBlankValues(row.blank_values), row.signing_body_format).body - const text = contractBodyToPlainText(words, row.signing_body_format) + // A blank nobody filled, a name in square brackets, prints as a line to write on (v2.9281). The app's own blanks are + // filled first, and the words are made plain first: a line of underscores in Markdown source is a mark of its own. + const text = ruleBlanksInText(contractBodyToPlainText(words, row.signing_body_format), { markdown: row.signing_body_format === 'markdown' }) if (!text) return [] return text .split(/\n{2,}/)