Skip to content

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

TypeScript

Fix the second review round on the API endpoints

Claude1e041f399f71
diff --git a/src/app/api/v1/envelopes/route.ts b/src/app/api/v1/envelopes/route.ts
index c52dec5..5b3dafe 100644
--- a/src/app/api/v1/envelopes/route.ts
+++ b/src/app/api/v1/envelopes/route.ts
@@ -106,8 +106,14 @@ export async function POST(request: Request) {
const fileBytes = new Uint8Array(await file.arrayBuffer());
// A multipart body differs on every send (its boundary is random),
- // so a retry is recognised by what it carries instead.
- fingerprint = `${json}\n${createHash("sha256").update(fileBytes).digest("hex")}`;
+ // so a retry is recognised by what it carries instead, file name
+ // and type included.
+ fingerprint = JSON.stringify([
+ json,
+ file.name,
+ file.type,
+ createHash("sha256").update(fileBytes).digest("hex"),
+ ]);
readPdf = async () => ({
body: fileBytes,
contentType: file.type || "application/pdf",
diff --git a/src/lib/api/envelopes.dbtest.ts b/src/lib/api/envelopes.dbtest.ts
index ad414df..2fc1cf5 100644
--- a/src/lib/api/envelopes.dbtest.ts
+++ b/src/lib/api/envelopes.dbtest.ts
@@ -11,6 +11,7 @@ import type pg from "pg";
import { createApiKey } from "../api-keys.ts";
import { openTestDatabase } from "../db/test-database.ts";
import { EnvelopeMutationError } from "../envelopes.ts";
+import { recordAuditEvent } from "../services/audit.ts";
import {
apiCreateEnvelopeSchema,
createEnvelopeForApi,
@@ -507,3 +508,39 @@ test("a create that fails is not remembered, so its retry runs for real", async
);
assert.equal(called, false);
});
+
+test("a corrected signer does not inherit the first view of the person before", async () => {
+ const actor = await createActor();
+ const envelope = await createEnvelopeForApi(
+ actor,
+ request({ send: { permittedUseConfirmed: true } }),
+ source(),
+ database,
+ );
+ const client = envelope.signers[0]!;
+
+ await recordAuditEvent(
+ {
+ actorEmail: client.email,
+ actorType: "signer",
+ envelopeId: envelope.id,
+ event: "viewed",
+ metadata: { signerEmail: client.email, signerId: client.id },
+ },
+ database,
+ );
+
+ const viewed = await getApiEnvelope(actor.userId, envelope.id, database);
+
+ assert.ok(viewed?.signers[0]?.viewedAt);
+
+ // A correction keeps the signer id and changes the address.
+ await database.query(`update signers set email = $2 where id = $1`, [
+ client.id,
+ ]);
+
+ const corrected = await getApiEnvelope(actor.userId, envelope.id, database);
+
+ assert.equal(corrected?.signers[0]?.viewedAt, null);
+});
diff --git a/src/lib/api/envelopes.ts b/src/lib/api/envelopes.ts
index 86f2017..7ead842 100644
--- a/src/lib/api/envelopes.ts
+++ b/src/lib/api/envelopes.ts
@@ -436,6 +436,8 @@ async function readSigners(
WHERE a.envelope_id = s.envelope_id
AND a.event = 'viewed'
AND a.metadata->>'signerId' = s.id
+ -- A corrected signer keeps the id but not the old person's view.
+ AND lower(a.metadata->>'signerEmail') = lower(s.email)
) AS "viewedAt"
FROM signers s
WHERE s.envelope_id = ANY($1)
diff --git a/src/lib/api/openapi.ts b/src/lib/api/openapi.ts
index 4449ab4..9072703 100644
--- a/src/lib/api/openapi.ts
+++ b/src/lib/api/openapi.ts
@@ -101,6 +101,12 @@ export function buildOpenApiDocument(serverUrl: string) {
requireEmailCode: { type: "boolean" },
signatureMeaning: {
description: "Part 11 installs only.",
+ enum: [
+ "approval",
+ "review",
+ "responsibility",
+ "authorship",
+ ],
type: "string",
},
},
@@ -202,7 +208,7 @@ export function buildOpenApiDocument(serverUrl: string) {
description: "Radio buttons in one group.",
type: "string",
},
- height: { maximum: 1, type: "number" },
+ height: { exclusiveMinimum: 0, maximum: 1, type: "number" },
label: { maxLength: 120, type: "string" },
options: {
description: "Dropdowns only.",
@@ -225,7 +231,7 @@ export function buildOpenApiDocument(serverUrl: string) {
],
type: "string",
},
- width: { maximum: 1, type: "number" },
+ width: { exclusiveMinimum: 0, maximum: 1, type: "number" },
x: { maximum: 1, minimum: 0, type: "number" },
y: { maximum: 1, minimum: 0, type: "number" },
},
@@ -240,7 +246,12 @@ export function buildOpenApiDocument(serverUrl: string) {
description:
"Confirms the envelope is an ordinary business agreement, as the web app's send button does.",
},
- reminderIntervalDays: { maximum: 30, minimum: 1, type: "integer" },
+ reminderIntervalDays: {
+ description: "Days between reminders, or null for none.",
+ maximum: 30,
+ minimum: 1,
+ type: ["integer", "null"],
+ },
signatureLevel: {
enum: ["simple", "advanced", "qualified"],
type: "string",