feat(eoi): multi-berth EOI generation + berth-range formatter

Plan §4.6 + §1: a render function that compresses every berth marked
is_in_eoi_bundle=true on an interest into a compact range string
("A1-A3, B5-B7"), wired into both EOI generation paths (the Documenso
template-generate call and the in-app pdf-lib AcroForm fill).

- src/lib/templates/berth-range.ts: pure formatBerthRange() with the
  full edge-case set from §4.6 - empty, single, run, gap, multiple
  prefixes, sort/dedup, multi-letter prefixes, non-canonical
  passthrough, long ranges. Sorts by (prefix, number); dedupes; passes
  non-canonical inputs through with a logger warning.
- src/lib/templates/merge-fields.ts: new {{eoi.berthRange}} token
  added to VALID_MERGE_TOKENS allow-list under a fresh `eoi` scope so
  unknown-token validation at template creation time still rejects
  typos.
- src/lib/services/eoi-context.ts: EoiContext gains eoiBerthRange.
  Resolved by joining interest_berths (is_in_eoi_bundle=true) →
  berths and feeding the mooring numbers through formatBerthRange.
- src/lib/services/documenso-payload.ts: formValues now includes
  "Berth Range" alongside the legacy "Berth Number". Multi-berth EOIs
  surface here; single-berth EOIs duplicate the primary.
- src/lib/pdf/fill-eoi-form.ts: in-app AcroForm fill mirrors the
  Documenso payload by populating "Berth Range". Falls back silently
  when older PDFs don't have the field (setText is no-op-on-missing).

15 unit tests on the formatter; existing EoiContext + Documenso
payload tests updated to assert the new field. 1022 -> 1037 passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-05-05 03:03:29 +02:00
parent b1e787e55c
commit e00e812199
8 changed files with 208 additions and 1 deletions

View File

@@ -22,6 +22,12 @@ export interface DocumensoTemplatePayload {
Width: string;
Draft: string;
'Berth Number': string;
/**
* Compact range string of every berth in the interest's EOI bundle
* (e.g. "A1-A3, B5"). Empty when the bundle is empty. Multi-berth
* EOIs surface here; single-berth EOIs duplicate the primary mooring.
*/
'Berth Range': string;
Lease_10: boolean;
Purchase: boolean;
};
@@ -135,6 +141,7 @@ export function buildDocumensoPayload(
Width: context.yacht?.widthFt ?? '',
Draft: context.yacht?.draftFt ?? '',
'Berth Number': context.berth?.mooringNumber ?? '',
'Berth Range': context.eoiBerthRange,
Lease_10: false,
Purchase: true,
},