feat: allow adding audit logs to compeleted document

This commit is contained in:
Lucas Smith
2025-05-19 09:10:08 +10:00
parent 99b0ad574e
commit 607f22513a
11 changed files with 391 additions and 10 deletions

View File

@ -17,6 +17,7 @@ import type { RequestMetadata } from '../../universal/extract-request-metadata';
import { getFileServerSide } from '../../universal/upload/get-file.server';
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
import { fieldsContainUnsignedRequiredField } from '../../utils/advanced-fields-helpers';
import { getAuditLogPdf } from '../htmltopdf/get-audit-log-pdf';
import { getCertificatePdf } from '../htmltopdf/get-certificate-pdf';
import { addRejectionStampToPdf } from '../pdf/add-rejection-stamp-to-pdf';
import { flattenAnnotations } from '../pdf/flatten-annotations';
@ -53,6 +54,7 @@ export const sealDocument = async ({
teamGlobalSettings: {
select: {
includeSigningCertificate: true,
includeAuditLog: true,
},
},
},
@ -124,6 +126,13 @@ export const sealDocument = async ({
}).catch(() => null)
: null;
const auditLogData =
(document.team?.teamGlobalSettings?.includeAuditLog ?? false)
? await getAuditLogPdf({
documentId,
}).catch(() => null)
: null;
const doc = await PDFDocument.load(pdfData);
// Normalize and flatten layers that could cause issues with the signature
@ -146,6 +155,16 @@ export const sealDocument = async ({
});
}
if (auditLogData) {
const auditLog = await PDFDocument.load(auditLogData);
const auditLogPages = await doc.copyPages(auditLog, auditLog.getPageIndices());
auditLogPages.forEach((page) => {
doc.addPage(page);
});
}
for (const field of fields) {
document.useLegacyFieldInsertion
? await legacy_insertFieldInPDF(doc, field)