Open-source document signature platform. Not affiliated with DocuSign.
TypeScript
Say captured email was captured, not accepted by a provider (#106)
Claude792d24277ae9
diff --git a/src/lib/services/captured-email.ts b/src/lib/services/captured-email.tsnew file mode 100644index 0000000..dbc0684--- /dev/null+++ b/src/lib/services/captured-email.ts@@ -0,0 +1,11 @@+/**+ * The capture email driver writes each message to the local outbox instead of+ * sending it, and gives it a message ID with this prefix. Real providers never+ * use it, so an audit row can tell a captured message from a sent one, including+ * rows recorded before this was written down.+ */+export const CAPTURED_MESSAGE_ID_PREFIX = "capture-";++export function isCapturedMessageId(messageId: string): boolean {+ return messageId.startsWith(CAPTURED_MESSAGE_ID_PREFIX);+}diff --git a/src/lib/services/email.ts b/src/lib/services/email.tsindex 3e84932..ed43c92 100644--- a/src/lib/services/email.ts+++ b/src/lib/services/email.ts@@ -8,6 +8,7 @@ import { getSettings } from "../settings.ts";import { type EmailTemplateKind } from "../types/domain.ts";import { getEnv, isLocalDeployment, type EnvSource } from "../utils/env.ts";import { buildEmailAddresses, type EmailAddresses } from "./email-addresses.ts";+import { CAPTURED_MESSAGE_ID_PREFIX } from "./captured-email.ts";import {assertServiceConfig,ServiceConfigurationError,@@ -228,7 +229,7 @@ function createCaptureEmailService(message: TransactionalEmailMessage,): Promise<EmailDeliveryResult> {const config = await resolveAddresses();- const messageId = `capture-${randomUUID()}`;+ const messageId = `${CAPTURED_MESSAGE_ID_PREFIX}${randomUUID()}`;const filePath = path.join(/*turbopackIgnore: true*/ captureDir,`${String(Date.now())}-${messageId}.json`,diff --git a/src/lib/services/pdf-finalize.test.ts b/src/lib/services/pdf-finalize.test.tsindex cb2bd35..29601b1 100644--- a/src/lib/services/pdf-finalize.test.ts+++ b/src/lib/services/pdf-finalize.test.ts@@ -7,6 +7,7 @@ import type { AuditEventRecord, EnvelopeRecord } from "../schemas/envelope.ts";import type { FieldRecord } from "../schemas/field.ts";import type { SignerRecord } from "../schemas/signer.ts";import {+ computeAuditFingerprint,describeAuditActor,findTypedValueTooLongForField,renderEnvelopeCertificatePdf,@@ -1005,3 +1006,79 @@ test("declined and voided certificates keep same-second events in recorded order);}});++test("a captured email is not described as accepted by a mail provider (issue #106)", async () => {+ const fixture = await makeFixture();+ const emailSent = (id: string, messageId: string): AuditEventRecord => ({+ actorType: "system",+ createdAt: 1_799_999_000,+ envelopeId: fixture.envelope.id,+ event: "email_sent",+ id,+ metadata: {+ messageId,+ recipient: "[email protected]",+ signerId: "signer-1",+ template: "signing_invitation",+ },+ });+ const auditEvents = [+ emailSent("event-captured", "capture-1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed"),+ emailSent("event-provider", "4ef9a417-02e9-4d39-ad75-9611e0fcc33c"),+ ];+ const text = (+ await extractText(+ await renderEnvelopeCertificatePdf(+ {+ auditEvents,+ envelope: fixture.envelope,+ redactForRecipients: false,+ signers: fixture.signers,+ },+ { seal: saveUnsealed },+ ),+ )+ ).replace(/\s+/g, " ");++ assert.ok(+ text.includes(+ "captured locally as capture-1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed, not sent",+ ),+ text,+ );+ assert.ok(+ !text.includes(+ "accepted by the mail provider as capture-1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed",+ ),+ text,+ );+ assert.ok(+ text.includes(+ "accepted by the mail provider as 4ef9a417-02e9-4d39-ad75-9611e0fcc33c",+ ),+ text,+ );+});++test("the new wording leaves the audit fingerprint of a captured email unchanged (issue #106)", () => {+ // Certificates sealed before the fix printed this fingerprint for the same+ // row, so they still match the stored audit trail.+ assert.equal(+ computeAuditFingerprint([+ {+ actorType: "system",+ createdAt: 1_799_999_000,+ envelopeId: "env",+ event: "email_sent",+ id: "event-captured",+ metadata: {+ messageId: "capture-1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed",+ recipient: "[email protected]",+ signerId: "signer-1",+ template: "signing_invitation",+ },+ },+ ]),+ "876cbd8661559c69681db5458f3baf2f8e1c8ccc4c43c9352691608e68b61c32",+ );+});diff --git a/src/lib/services/pdf-finalize.ts b/src/lib/services/pdf-finalize.tsindex 4960dd5..8212d2b 100644--- a/src/lib/services/pdf-finalize.ts+++ b/src/lib/services/pdf-finalize.ts@@ -11,6 +11,7 @@ import type { FieldRecord } from "../schemas/field.ts";import type { SignerRecord } from "../schemas/signer.ts";import { buildSignatureManifestation } from "../signature-meanings.ts";import { describeSignerCorrectedEvent } from "./audit.ts";+import { isCapturedMessageId } from "./captured-email.ts";import { canonicalJson } from "../utils/canonical-json.ts";import { normalizedRectToPdfRect } from "../utils/pdf-coords.ts";import { embedTextFaces, type TextFace } from "./pdf-fonts.ts";@@ -1375,7 +1376,12 @@ function describeEventEvidence(event: AuditEventRecord): string[] {[kind ? `email ${kind.replaceAll("_", " ")}` : "email",recipient ? `to ${recipient}` : null,- messageId ? `accepted by the mail provider as ${messageId}` : null,+ messageId+ ? isCapturedMessageId(messageId)+ ? // The capture driver only wrote it to the local outbox.+ `captured locally as ${messageId}, not sent`+ : `accepted by the mail provider as ${messageId}`+ : null,].filter(Boolean).join(" "),