Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Refuse to send a dropdown too small to show its choices readably

Claude7fc8e4a4272a
diff --git a/src/lib/access-code-guesses.dbtest.ts b/src/lib/access-code-guesses.dbtest.ts
index 684d8e8..b0d34a5 100644
--- a/src/lib/access-code-guesses.dbtest.ts
+++ b/src/lib/access-code-guesses.dbtest.ts
@@ -40,7 +40,10 @@ async function createEnvelopeWithAccessCode(code: string) {
const envelopeId = randomUUID();
const signerId = randomUUID();
const now = Math.floor(Date.now() / 1000);
- const link = await issueSigningLink({ expiresInSeconds: 3600, issuedAt: now });
+ const link = await issueSigningLink({
+ expiresInSeconds: 3600,
+ issuedAt: now,
+ });
createdUsers.push(userId);
await database.query(
diff --git a/src/lib/choice-fields.dbtest.ts b/src/lib/choice-fields.dbtest.ts
index fbf1c3e..f873aee 100644
--- a/src/lib/choice-fields.dbtest.ts
+++ b/src/lib/choice-fields.dbtest.ts
@@ -288,3 +288,49 @@ test("the database itself keeps choices and groups where they belong", async ()
await insert("radio", null, "group-1");
await insert("number", null, null);
});
+
+test("a dropdown too small to show its choices readably is not sent", async () => {
+ const { casey, envelopeId, riley, userId } = await createDraft();
+ const choices = [
+ "Approved with the conditions listed in the schedule",
+ "Rejected until the landlord answers the open questions",
+ ];
+ const save = (dropdown: Record<string, unknown>) =>
+ replaceDraftEnvelopeFields(
+ userId,
+ envelopeId,
+ {
+ fields: [
+ field(riley, "signature", 0.1),
+ field(casey, "signature", 0.15),
+ field(riley, "dropdown", 0.3, { options: choices, ...dropdown }),
+ ],
+ },
+ database,
+ );
+ const send = () =>
+ sendDraftEnvelope(
+ userId,
+ envelopeId,
+ { senderEmail: "[email protected]", senderName: "Sam Sender" },
+ { database },
+ );
+
+ await save({ height: 0.012, width: 0.05 });
+ await assert.rejects(
+ send(),
+ (error: unknown) =>
+ error instanceof EnvelopeMutationError &&
+ error.statusCode === 400 &&
+ /dropdown for Riley Recipient on page 1 is too small/.test(error.message),
+ );
+
+ // Wide enough, the dropdown is no reason not to send.
+ await save({ height: 0.03, width: 0.6 });
+ await send().catch((error: unknown) => {
+ assert.doesNotMatch(
+ error instanceof Error ? error.message : String(error),
+ /too small to show its choices/,
+ );
+ });
+});
diff --git a/src/lib/envelopes.ts b/src/lib/envelopes.ts
index 0e158c9..5033124 100644
--- a/src/lib/envelopes.ts
+++ b/src/lib/envelopes.ts
@@ -90,6 +90,7 @@ import {
import { withUserEmailLegalFooter } from "./services/email-legal-footer.ts";
import { buildSigningInvitationEmail } from "./services/signing-invitation-email.ts";
import {
+ findTypedValueTooLongForField,
loadInstallSealer,
storeEnvelopeCertificatePdf,
storeRecipientEnvelopeCertificatePdf,
@@ -1582,6 +1583,40 @@ function describeChoiceProblem(
);
}
+/**
+ * A dropdown whose box is too small to show one of its choices at a
+ * readable size, in words for the sender, or null. A signer cannot shorten
+ * a choice, so a choice that does not fit is drawn as small as it takes,
+ * and on the signed document that can be too small to read. The sender
+ * fixes it before sending instead.
+ */
+async function findUnreadableDropdown(
+ signers: readonly PersistedSignerRecord[],
+ fields: readonly FieldRecord[],
+ pages: Parameters<typeof findTypedValueTooLongForField>[1],
+): Promise<string | null> {
+ for (const field of fields) {
+ if (field.type !== "dropdown" || !field.options?.length) {
+ continue;
+ }
+
+ const tooLong = await findTypedValueTooLongForField(
+ field.options.map((option) => ({ field, value: option })),
+ pages,
+ );
+
+ if (tooLong) {
+ const signerName =
+ signers.find((signer) => signer.id === field.signerId)?.name ??
+ "a signer";
+
+ return `A dropdown for ${signerName} on page ${String(tooLong.page)} is too small to show its choices at a readable size. Make the box bigger or the choices shorter.`;
+ }
+ }
+
+ return null;
+}
+
/** The fields with each group of radio buttons counted once. */
function withRadioGroupsOnce(fields: readonly FieldRecord[]): FieldRecord[] {
const seenGroups = new Set<string>();
@@ -2668,6 +2703,16 @@ export async function sendDraftEnvelope(
throw new EnvelopeMutationError(choiceProblem, 400);
}
+ const unreadableDropdown = await findUnreadableDropdown(
+ signers,
+ fields,
+ await listEnvelopePagesForEnvelopeId(envelopeId, database),
+ );
+
+ if (unreadableDropdown) {
+ throw new EnvelopeMutationError(unreadableDropdown, 400);
+ }
+
// In Part 11 mode each signer signs with their own verified account, and
// the envelope keeps that rule even if the mode is turned off later.
const part11 = (await readStoredSettings(database))?.part11Mode ?? false;