feat(eoi): template-aware generate-EOI dialog

The EOI dialog now lists "Documenso Standard EOI" (default) plus any
seeded in-app EOI templates and routes the submit to the dual-path
generate-and-sign endpoint with the correct pathway:

  - "documenso-template" sentinel id → pathway: documenso-template
  - any other template id → pathway: inapp

Signers are derived server-side from EoiContext for both pathways when
the template type is EOI (interest's client + hardcoded developer +
approver), so the dialog doesn't collect them. Non-EOI templates still
require explicit signers.

Drops the legacy `client.yachtLengthFt` prerequisite check (yacht is now
a first-class entity) and replaces it with hasYacht based on
interest.yachtId. Tests updated; 646/646 green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-26 13:42:08 +02:00
parent 2ff24a7132
commit f4ec51002c
4 changed files with 171 additions and 58 deletions

View File

@@ -817,10 +817,34 @@ async function generateAndSignViaInApp(
signers: GenerateAndSignInput['signers'],
meta: AuditMeta,
) {
if (!signers || signers.length === 0) {
const template = await getTemplateById(templateId, portId);
// For EOI templates, signers default to the same set the Documenso template
// pathway uses (interest's client + hardcoded developer + approver), so the
// UI doesn't need to collect them. Non-EOI templates still require explicit
// signers since they have no canonical recipient list.
let resolvedSigners = signers;
if ((!resolvedSigners || resolvedSigners.length === 0) && template.templateType === 'eoi') {
if (!context.interestId) {
throw new ValidationError(
'interestId is required when generating an EOI without explicit signers',
);
}
const eoiCtx = await buildEoiContext(context.interestId, portId);
resolvedSigners = [
{
name: eoiCtx.client.fullName,
email: eoiCtx.client.primaryEmail ?? '',
role: 'signer',
signingOrder: 1,
},
{ name: 'David Mizrahi', email: 'dm@portnimara.com', role: 'signer', signingOrder: 2 },
{ name: 'Abbie May', email: 'sales@portnimara.com', role: 'approver', signingOrder: 3 },
];
}
if (!resolvedSigners || resolvedSigners.length === 0) {
throw new ValidationError('signers are required for inapp pathway');
}
const template = await getTemplateById(templateId, portId);
// EOI templates fill the same source PDF as the Documenso template (so both
// pathways yield the same document). Other template types stay on the
@@ -845,7 +869,7 @@ async function generateAndSignViaInApp(
const documensoDoc = await documensoCreate(
template.name,
pdfBase64,
signers.map((s) => ({
resolvedSigners.map((s) => ({
name: s.name,
email: s.email,
role: s.role,
@@ -873,7 +897,11 @@ async function generateAndSignViaInApp(
entityType: 'document',
entityId: documentRecord.id,
newValue: { status: 'sent', documensoId: documensoDoc.id },
metadata: { action: 'generate_and_sign', pathway: 'inapp', signerCount: signers.length },
metadata: {
action: 'generate_and_sign',
pathway: 'inapp',
signerCount: resolvedSigners.length,
},
ipAddress: meta.ipAddress,
userAgent: meta.userAgent,
});