Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Keep an envelope's first thumbnail, and say which limits reset
Claude216326e3bb8c
diff --git a/README.md b/README.mdindex 7682ceb..00d6690 100644--- a/README.md+++ b/README.md@@ -179,7 +179,7 @@ Each free plan has its own monthly allowance, and the smallest one sets the limi| **Database**, on [Neon](https://neon.com/faqs/free-plan-limits-and-quotas) | 1 GB and 100 compute hours | About 400 hours a month with the database awake. It sleeps when nobody is using the site. || **Hosting**, on Vercel Hobby | More than the rows above will use | Any number of people. Vercel [limits Hobby to personal, non-commercial use](https://vercel.com/docs/limits/fair-use-guidelines). |-None of these plans bills you for going over. It stops instead: files cannot be read, email is not sent, or the database pauses, until the month turns over. Move up before you reach a limit, not after.+None of these plans bills you for going over. It stops instead: files cannot be read, email is not sent, or the database pauses. The monthly allowances come back when the month turns over. The two 1 GB limits do not, because stored files and database rows stay until they are deleted: make room by deleting old documents, or by setting how long finished documents are kept under Settings, Organization. Better still, move up before you reach a limit, not after.### Past the free plansdiff --git a/docs/self-hosting.md b/docs/self-hosting.mdindex 8033056..bf68566 100644--- a/docs/self-hosting.md+++ b/docs/self-hosting.md@@ -36,7 +36,7 @@ If the site opens on a page that says to connect a database, the database was no[What it costs](../README.md#what-it-costs), in the README, puts a year of SignuDoc next to DocuSign for teams of 5 to 50.- **Vercel.** The free Hobby plan is enough to run SignuDoc, but Vercel [limits Hobby to personal, non-commercial use](https://vercel.com/docs/limits/fair-use-guidelines). An organization using this for its work belongs on Vercel Pro. Everything here works the same on both.-- **Neon, Vercel Blob and Resend** each have a free plan with limits: see [Neon](https://neon.com/faqs/free-plan-limits-and-quotas), [Vercel Blob](https://vercel.com/docs/vercel-blob/usage-and-pricing) and [Resend](https://resend.com/pricing). The two you are most likely to meet first, at the time of writing, are Resend's 100 emails a day, which is about 20 two-signer documents, and Vercel Blob's 2,000 uploads a month, which is about 250 documents. Every signing invitation, reminder and completed copy is an email, and every PDF, sealed copy and certificate is an upload. [What it costs](../README.md#what-it-costs) in the README works through all of the limits. None of these plans bills you for going over: it stops until the month turns over.+- **Neon, Vercel Blob and Resend** each have a free plan with limits: see [Neon](https://neon.com/faqs/free-plan-limits-and-quotas), [Vercel Blob](https://vercel.com/docs/vercel-blob/usage-and-pricing) and [Resend](https://resend.com/pricing). The two you are most likely to meet first, at the time of writing, are Resend's 100 emails a day, which is about 20 two-signer documents, and Vercel Blob's 2,000 uploads a month, which is about 250 documents. Every signing invitation, reminder and completed copy is an email, and every PDF, sealed copy and certificate is an upload. [What it costs](../README.md#what-it-costs) in the README works through all of the limits. None of these plans bills you for going over. It stops instead, until the month turns over or, for the two 1 GB storage limits, until you delete old documents or move up.### Use your own web addressdiff --git a/src/lib/envelope-thumbnail.dbtest.ts b/src/lib/envelope-thumbnail.dbtest.tsindex 1f52de1..36ba120 100644--- a/src/lib/envelope-thumbnail.dbtest.ts+++ b/src/lib/envelope-thumbnail.dbtest.ts@@ -32,6 +32,12 @@ const THUMBNAIL = Uint8Array.from([0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xd9,]);+// The same, but 480 x 512: a different picture that is just as valid.+const OTHER_THUMBNAIL = Uint8Array.from([+ 0xff, 0xd8, 0xff, 0xc0, 0x00, 0x11, 0x08, 0x02, 0x00, 0x01, 0xe0, 0x03, 0x01,+ 0x22, 0x00, 0x02, 0x11, 0x01, 0x03, 0x11, 0x01, 0xff, 0xd9,+]);+let database: pg.Pool;let storageDir: string;let storageService: StorageService;@@ -177,6 +183,29 @@ test("a browser that already holds the picture is answered without a read from f}});+test("an envelope keeps the first picture it is given", async () => {+ const draft = await insertDraft();++ await saveEnvelopeThumbnailForUser(+ draft.userId,+ draft.envelopeId,+ THUMBNAIL,+ { database, storageService },+ );+ // Accepted, and not kept: a browser that holds the first picture is told+ // it is still good, so it has to stay the one that is stored.+ await saveEnvelopeThumbnailForUser(+ draft.userId,+ draft.envelopeId,+ OTHER_THUMBNAIL,+ { database, storageService },+ );++ const stored = await storageService.getObject(thumbnailKey(draft));++ assert.deepEqual(Array.from(stored.body), Array.from(THUMBNAIL));+});+test("quoting a picture's name does not show it to another account", async () => {const draft = await insertDraft();const stranger = await insertDraft();diff --git a/src/lib/envelopes.ts b/src/lib/envelopes.tsindex b9d0226..3e80510 100644--- a/src/lib/envelopes.ts+++ b/src/lib/envelopes.ts@@ -1547,6 +1547,12 @@ export async function getDraftEnvelopeDocumentForUser(/*** Keeps the picture of the first page that the sender's browser drew. The* bytes are checked before they are stored: see services/thumbnails.ts.+ *+ * An envelope keeps the first picture it is given. Its document never+ * changes, so there is nothing a later picture could show that the first+ * does not, and a browser is told its copy is still good by the envelope+ * alone (buildThumbnailEtag), which only holds while the picture stays the+ * same.*/export async function saveEnvelopeThumbnailForUser(userId: string,@@ -1574,11 +1580,17 @@ export async function saveEnvelopeThumbnailForUser(userId,});- await storageService.putObject({- body,- contentType: THUMBNAIL_CONTENT_TYPE,- key,- });+ // Two uploads that arrive together can both get past this check. Both are+ // drawn from the same page, so whichever is written last is as good.+ const stored = await storageService.headObject(key);++ if (!stored.exists) {+ await storageService.putObject({+ body,+ contentType: THUMBNAIL_CONTENT_TYPE,+ key,+ });+ }// The envelope may have been deleted while the picture was being written:// by its owner, by the cleanup job or with the whole account. Each ofdiff --git a/src/lib/services/thumbnails.ts b/src/lib/services/thumbnails.tsindex dec0b00..35f356c 100644--- a/src/lib/services/thumbnails.ts+++ b/src/lib/services/thumbnails.ts@@ -14,8 +14,9 @@ const THUMBNAIL_MIN_DIMENSION = 16;* The name a browser quotes back to ask whether its copy of a thumbnail is* still good (an ETag).*- * A document never changes once it is uploaded, so neither does the picture- * of its first page, and the name is made from the envelope alone. That lets+ * A document never changes once it is uploaded, and an envelope keeps the+ * first picture it is given (saveEnvelopeThumbnailForUser), so the name is+ * made from the envelope alone. That lets* "your copy is still good" be answered without reading the picture from* file storage, where every read counts against the store's allowance. The* version is here to be raised if thumbnails are ever drawn differently.