mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
fix: correctly sign SPM documents (#627)
- Sign and email correct SPM document - Optimise signing SPM documents
This commit is contained in:
@ -11,7 +11,6 @@ import { mailer } from '@documenso/email/mailer';
|
|||||||
import { render } from '@documenso/email/render';
|
import { render } from '@documenso/email/render';
|
||||||
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
import { DocumentSelfSignedEmailTemplate } from '@documenso/email/templates/document-self-signed';
|
||||||
import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email';
|
import { FROM_ADDRESS, FROM_NAME, SERVICE_USER_EMAIL } from '@documenso/lib/constants/email';
|
||||||
import { sealDocument } from '@documenso/lib/server-only/document/seal-document';
|
|
||||||
import { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf';
|
import { insertFieldInPDF } from '@documenso/lib/server-only/pdf/insert-field-in-pdf';
|
||||||
import { alphaid } from '@documenso/lib/universal/id';
|
import { alphaid } from '@documenso/lib/universal/id';
|
||||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||||
@ -26,6 +25,7 @@ import {
|
|||||||
SendStatus,
|
SendStatus,
|
||||||
SigningStatus,
|
SigningStatus,
|
||||||
} from '@documenso/prisma/client';
|
} from '@documenso/prisma/client';
|
||||||
|
import { signPdf } from '@documenso/signing';
|
||||||
|
|
||||||
const ZCreateSinglePlayerDocumentSchema = z.object({
|
const ZCreateSinglePlayerDocumentSchema = z.object({
|
||||||
documentData: z.object({
|
documentData: z.object({
|
||||||
@ -99,12 +99,11 @@ export const createSinglePlayerDocument = async (
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const pdfBytes = await doc.save();
|
const unsignedPdfBytes = await doc.save();
|
||||||
|
|
||||||
const {
|
const signedPdfBuffer = await signPdf({ pdf: Buffer.from(unsignedPdfBytes) });
|
||||||
document: { id: documentId },
|
|
||||||
token,
|
const { token } = await prisma.$transaction(
|
||||||
} = await prisma.$transaction(
|
|
||||||
async (tx) => {
|
async (tx) => {
|
||||||
const token = alphaid();
|
const token = alphaid();
|
||||||
|
|
||||||
@ -115,12 +114,10 @@ export const createSinglePlayerDocument = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const documentDataBytes = Buffer.from(pdfBytes);
|
|
||||||
|
|
||||||
const { id: documentDataId } = await putFile({
|
const { id: documentDataId } = await putFile({
|
||||||
name: `${documentName}.pdf`,
|
name: `${documentName}.pdf`,
|
||||||
type: 'application/pdf',
|
type: 'application/pdf',
|
||||||
arrayBuffer: async () => Promise.resolve(documentDataBytes),
|
arrayBuffer: async () => Promise.resolve(signedPdfBuffer),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create document.
|
// Create document.
|
||||||
@ -180,11 +177,6 @@ export const createSinglePlayerDocument = async (
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
await sealDocument({
|
|
||||||
documentId,
|
|
||||||
sendEmail: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const template = createElement(DocumentSelfSignedEmailTemplate, {
|
const template = createElement(DocumentSelfSignedEmailTemplate, {
|
||||||
documentName: documentName,
|
documentName: documentName,
|
||||||
assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000',
|
assetBaseUrl: process.env.NEXT_PUBLIC_WEBAPP_URL || 'http://localhost:3000',
|
||||||
@ -203,7 +195,7 @@ export const createSinglePlayerDocument = async (
|
|||||||
subject: 'Document signed',
|
subject: 'Document signed',
|
||||||
html: render(template),
|
html: render(template),
|
||||||
text: render(template, { plainText: true }),
|
text: render(template, { plainText: true }),
|
||||||
attachments: [{ content: Buffer.from(pdfBytes), filename: documentName }],
|
attachments: [{ content: signedPdfBuffer, filename: documentName }],
|
||||||
});
|
});
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
|
|||||||
Reference in New Issue
Block a user