mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
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.
75 lines
2.0 KiB
TypeScript
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));
|
|
};
|