Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Never delete a finished envelope before the date its warning gave
Claudeb4e30ec1105c
diff --git a/src/lib/retention.ts b/src/lib/retention.tsindex c4d2171..5aab1aa 100644--- a/src/lib/retention.ts+++ b/src/lib/retention.ts@@ -62,7 +62,10 @@ export type RetentionSweepSummary = {/** How long before deletion a sender is told, and the shortest notice. */export const RETENTION_WARNING_DAYS = 30;-const RETENTION_MIN_NOTICE_DAYS = 7;+// Nothing is deleted until this long after its warning, whatever the+// setting says by then: the date in the warning is never brought forward,+// even when an administrator shortens the period afterwards.+const RETENTION_MIN_NOTICE_DAYS = RETENTION_WARNING_DAYS;function getCurrentUnixTimestamp() {return Math.floor(Date.now() / 1000);@@ -550,7 +553,7 @@ async function warnBeforeRetentionDeletion(/*** Applies the install's retention period to finished envelopes: a warning to* the sender first, deletion once the period has passed and the warning is- * at least a week old.+ * at least RETENTION_MIN_NOTICE_DAYS old.*/async function applyRetentionPeriod(retentionDays: number,diff --git a/src/lib/signature-evidence.dbtest.ts b/src/lib/signature-evidence.dbtest.tsindex ee7f9b5..fb06cc2 100644--- a/src/lib/signature-evidence.dbtest.ts+++ b/src/lib/signature-evidence.dbtest.ts@@ -220,13 +220,26 @@ test("the retention period warns the sender, then deletes", async () => {});assert.ok(first.finishedEnvelopeWarningsSent >= 1);++ // A shorter period set after the warning does not bring the date forward.+ await database.query(`update app_settings set retention_days = 30`);++ const tooSoon = await runRetentionSweep({+ database,+ emailService,+ now: now + 8 * day,+ storageService: storage(),+ });++ assert.equal(tooSoon.finishedEnvelopesDeleted, 0);+ assert.equal(await envelopeOwner(old), owner);assert.ok(sent.includes(`${owner}@example.test`));assert.equal(await envelopeOwner(old), owner);const later = await runRetentionSweep({database,emailService,- now: now + 8 * day,+ now: now + 31 * day,storageService: storage(),});