Files
esign/packages/lib/server-only/pdf/generate-audit-log-pdf.ts
zooqueen fb4e3df0e3 rename: @hanzo/sign-* → @hanzo/esign-* (full eSign brand consistency)
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign).
Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files)
and align docker/Dockerfile turbo --scope/--filter to the actual remix
package name @hanzo/esign (was a pre-existing mismatch with -remix that
broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
2026-06-21 19:56:09 -07:00

75 lines
2.0 KiB
TypeScript

import { PDF } from '@libpdf/core';
import { i18n } from '@lingui/core';
import { type TDocumentAuditLog } from '@hanzo/esign-lib/types/document-audit-logs';
import { prisma } from '@hanzo/esign-prisma';
import { ZSupportedLanguageCodeSchema } from '../../constants/i18n';
import { parseDocumentAuditLogData } from '../../utils/document-audit-logs';
import { getTranslations } from '../../utils/i18n';
import { getOrganisationClaimByTeamId } from '../organisation/get-organisation-claims';
import type { GenerateCertificatePdfOptions } from './generate-certificate-pdf';
import { renderAuditLogs } from './render-audit-logs';
type GenerateAuditLogPdfOptions = GenerateCertificatePdfOptions & {
envelopeItems: string[];
additionalAuditLogs?: TDocumentAuditLog[];
};
export const generateAuditLogPdf = async (options: GenerateAuditLogPdfOptions) => {
const {
envelope,
envelopeOwner,
envelopeItems,
recipients,
language,
pageWidth,
pageHeight,
additionalAuditLogs = [],
} = options;
const documentLanguage = ZSupportedLanguageCodeSchema.parse(language);
const [organisationClaim, partialAuditLogs, messages] = await Promise.all([
getOrganisationClaimByTeamId({ teamId: envelope.teamId }),
getAuditLogs(envelope.id),
getTranslations(documentLanguage),
]);
i18n.loadAndActivate({
locale: documentLanguage,
messages,
});
const auditLogs: TDocumentAuditLog[] = [...additionalAuditLogs, ...partialAuditLogs];
const auditLogPages = await renderAuditLogs({
envelope,
envelopeOwner,
envelopeItems,
recipients,
auditLogs,
hidePoweredBy: organisationClaim.flags.hidePoweredBy ?? false,
pageWidth,
pageHeight,
i18n,
});
return await PDF.merge(auditLogPages, {
includeAnnotations: true,
});
};
const getAuditLogs = async (envelopeId: string) => {
const auditLogs = await prisma.documentAuditLog.findMany({
where: {
envelopeId,
},
orderBy: {
createdAt: 'desc',
},
});
return auditLogs.map((auditLog) => parseDocumentAuditLogData(auditLog));
};