From f4cfc5600f10544ac8ed929ed3d3eb92ba7ac401 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 25 Jun 2026 03:37:14 +0200 Subject: [PATCH] fix(eoi): uppercase Documenso recipient roles at the API boundary The local-fill EOI pathway passed lowercase roles ('signer'/'approver') to createDocument; Documenso's API requires UPPERCASE (CC|SIGNER|VIEWER|APPROVER| ASSISTANT) and rejected them with a 400 "Invalid enum value", surfacing as a 502 DOCUMENSO_UPSTREAM_ERROR on generate. Normalize role to uppercase where safeRecipients is built so both v1 + v2 paths and all callers are covered. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/lib/services/documenso-client.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/services/documenso-client.ts b/src/lib/services/documenso-client.ts index a1a3cb14..d0c553ac 100644 --- a/src/lib/services/documenso-client.ts +++ b/src/lib/services/documenso-client.ts @@ -309,7 +309,14 @@ export async function createDocument( portId?: string, meta?: CreateDocumentMeta, ): Promise { - const safeRecipients = applyRecipientRedirect(recipients); + // Documenso's API requires UPPERCASE recipient roles + // (CC | SIGNER | VIEWER | APPROVER | ASSISTANT). The CRM uses lowercase + // role strings internally ('signer' / 'approver'), so normalize here at the + // API boundary — otherwise create fails with a 400 "Invalid enum value". + const safeRecipients = applyRecipientRedirect(recipients).map((r) => ({ + ...r, + role: typeof r.role === 'string' ? r.role.toUpperCase() : r.role, + })); if (env.EMAIL_REDIRECT_TO) { logger.info( { redirected: safeRecipients.length, original: recipients.map((r) => r.email) },