Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Keep a failed reminder from restoring a link a correction replaced
Claude7f971dfd9af6
diff --git a/src/lib/reminders.ts b/src/lib/reminders.tsindex 6a911b0..75bf18c 100644--- a/src/lib/reminders.ts+++ b/src/lib/reminders.ts@@ -552,6 +552,11 @@ async function deliverReminder(WHERE id = $6AND envelope_id = $7AND status = 'notified'+ -- Only while the link is still this reminder's. If the sender+ -- corrected the signer while the email was failing, the row now+ -- holds the corrected person's link, and the old one must stay+ -- dead.+ AND signing_token_hash = $9`,[persisted.previousSigner.signingTokenHash,@@ -562,6 +567,7 @@ async function deliverReminder(persisted.previousSigner.id,persisted.envelopeId,persisted.issuedLink.exp,+ persisted.issuedLink.tokenHash,],);diff --git a/src/lib/signer-correction.dbtest.ts b/src/lib/signer-correction.dbtest.tsindex bd1525b..9f7bcb3 100644--- a/src/lib/signer-correction.dbtest.ts+++ b/src/lib/signer-correction.dbtest.ts@@ -33,6 +33,7 @@ import type {} from "./services/email.ts";import { hashOpaqueToken } from "./services/opaque-tokens.ts";import { renderEnvelopeCertificatePdf } from "./services/pdf-finalize.ts";+import { sendManualEnvelopeNudge } from "./reminders.ts";import { issueSigningLink } from "./services/signing-links.ts";import {createStorageService,@@ -1445,3 +1446,50 @@ test("a missing email configuration rolls the correction back", async () => {assert.equal(stored.consented_at, consentedAt);assert.deepEqual(await auditEvents(envelopeId), []);});++test("a failed reminder does not bring back the link a correction replaced", async () => {+ const { userId } = await createOwner();+ const envelopeId = await createEnvelope({ userId });+ const signer = await createSigner({ envelopeId });+ const { sent, service: correctionService } = recordingEmailService();+ let correctionResult: Awaited<ReturnType<typeof correct>> | undefined;+ const failingReminder: EmailService = {+ async send() {+ // The sender corrects the signer while the reminder is being sent,+ // and then the reminder fails.+ correctionResult = await correct(+ userId,+ envelopeId,+ signer.signerId,+ { email: "[email protected]" },+ correctionService,+ );++ throw new Error("mailbox down");+ },+ async sendBatch() {+ throw new Error("not used");+ },+ };++ await assert.rejects(+ sendManualEnvelopeNudge(+ userId,+ envelopeId,+ { senderEmail: "[email protected]", senderName: "Sam Sender" },+ { database, emailService: failingReminder },+ ),+ /mailbox down/,+ );++ assert.ok(correctionResult);+ const stored = await readSigner(signer.signerId);+ assert.equal(stored.email, "[email protected]");+ assert.notEqual(stored.signing_token_hash, signer.tokenHash);+ assert.equal(sent.length, 1);+ assert.equal(sent[0]?.to, "[email protected]");+ await assert.rejects(getSigningPayloadForToken(signer.token!, { database }), {+ name: "SigningAccessError",+ });+ assert.equal((await verifyAuditChain(envelopeId, database)).ok, true);+});