mirror of
https://github.com/documenso/documenso.git
synced 2025-11-09 20:12:31 +10:00
chore: update envelope handling and improve field positioning in PDF processing
This commit is contained in:
@ -35,6 +35,7 @@ import { getFileServerSide } from '../../universal/upload/get-file.server';
|
|||||||
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
import { putPdfFileServerSide } from '../../universal/upload/put-file.server';
|
||||||
import { extractDerivedDocumentMeta } from '../../utils/document';
|
import { extractDerivedDocumentMeta } from '../../utils/document';
|
||||||
import { createDocumentAuthOptions, createRecipientAuthOptions } from '../../utils/document-auth';
|
import { createDocumentAuthOptions, createRecipientAuthOptions } from '../../utils/document-auth';
|
||||||
|
import type { EnvelopeIdOptions } from '../../utils/envelope';
|
||||||
import { buildTeamWhereQuery } from '../../utils/teams';
|
import { buildTeamWhereQuery } from '../../utils/teams';
|
||||||
import { incrementDocumentId, incrementTemplateId } from '../envelope/increment-id';
|
import { incrementDocumentId, incrementTemplateId } from '../envelope/increment-id';
|
||||||
import { getTeamSettings } from '../team/get-team-settings';
|
import { getTeamSettings } from '../team/get-team-settings';
|
||||||
@ -427,16 +428,19 @@ export const createEnvelope = async ({
|
|||||||
? await makeNormalizedPdf(Buffer.from(buffer))
|
? await makeNormalizedPdf(Buffer.from(buffer))
|
||||||
: Buffer.from(buffer);
|
: Buffer.from(buffer);
|
||||||
|
|
||||||
|
const envelopeOptions: EnvelopeIdOptions = {
|
||||||
|
type: 'envelopeId',
|
||||||
|
id: createdEnvelope.id,
|
||||||
|
};
|
||||||
|
|
||||||
await insertFieldsFromPlaceholdersInPDF(
|
await insertFieldsFromPlaceholdersInPDF(
|
||||||
pdfToProcess,
|
pdfToProcess,
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
{
|
envelopeOptions,
|
||||||
type: 'envelopeId',
|
|
||||||
id: createdEnvelope.id,
|
|
||||||
},
|
|
||||||
requestMetadata,
|
requestMetadata,
|
||||||
envelopeItem.id,
|
envelopeItem.id,
|
||||||
|
createdEnvelope.recipients,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -51,9 +51,9 @@ type PlaceholderInfo = {
|
|||||||
type FieldToCreate = TFieldAndMeta & {
|
type FieldToCreate = TFieldAndMeta & {
|
||||||
envelopeItemId?: string;
|
envelopeItemId?: string;
|
||||||
recipientId: number;
|
recipientId: number;
|
||||||
pageNumber: number;
|
page: number;
|
||||||
pageX: number;
|
positionX: number;
|
||||||
pageY: number;
|
positionY: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
};
|
};
|
||||||
@ -327,9 +327,9 @@ export const insertFieldsFromPlaceholdersInPDF = async (
|
|||||||
...placeholder.fieldAndMeta,
|
...placeholder.fieldAndMeta,
|
||||||
envelopeItemId,
|
envelopeItemId,
|
||||||
recipientId: recipient.id,
|
recipientId: recipient.id,
|
||||||
pageNumber: placeholder.page,
|
page: placeholder.page,
|
||||||
pageX: xPercent,
|
positionX: xPercent,
|
||||||
pageY: yPercent,
|
positionY: yPercent,
|
||||||
width: widthPercent,
|
width: widthPercent,
|
||||||
height: finalHeightPercent,
|
height: finalHeightPercent,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -4,8 +4,7 @@ import type { Recipient } from '@prisma/client';
|
|||||||
import { match } from 'ts-pattern';
|
import { match } from 'ts-pattern';
|
||||||
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||||
import { createDocumentRecipients } from '@documenso/lib/server-only/recipient/create-document-recipients';
|
import { createEnvelopeRecipients } from '@documenso/lib/server-only/recipient/create-envelope-recipients';
|
||||||
import { createTemplateRecipients } from '@documenso/lib/server-only/recipient/create-template-recipients';
|
|
||||||
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-request-metadata';
|
||||||
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||||
import type { EnvelopeIdOptions } from '@documenso/lib/utils/envelope';
|
import type { EnvelopeIdOptions } from '@documenso/lib/utils/envelope';
|
||||||
@ -229,7 +228,7 @@ export const createRecipientsFromPlaceholders = async (
|
|||||||
id: envelope.id,
|
id: envelope.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { recipients } = await createDocumentRecipients({
|
const { recipients } = await createEnvelopeRecipients({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
id: envelopeId,
|
id: envelopeId,
|
||||||
@ -242,11 +241,17 @@ export const createRecipientsFromPlaceholders = async (
|
|||||||
.with(EnvelopeType.TEMPLATE, async () => {
|
.with(EnvelopeType.TEMPLATE, async () => {
|
||||||
const templateId = mapSecondaryIdToTemplateId(envelope.secondaryId ?? '');
|
const templateId = mapSecondaryIdToTemplateId(envelope.secondaryId ?? '');
|
||||||
|
|
||||||
const { recipients } = await createTemplateRecipients({
|
const envelopeId: EnvelopeIdOptions = {
|
||||||
|
type: 'templateId',
|
||||||
|
id: templateId,
|
||||||
|
};
|
||||||
|
|
||||||
|
const { recipients } = await createEnvelopeRecipients({
|
||||||
userId,
|
userId,
|
||||||
teamId,
|
teamId,
|
||||||
templateId,
|
id: envelopeId,
|
||||||
recipients: recipientsToCreateFiltered,
|
recipients: recipientsToCreateFiltered,
|
||||||
|
requestMetadata,
|
||||||
});
|
});
|
||||||
|
|
||||||
return recipients;
|
return recipients;
|
||||||
|
|||||||
Reference in New Issue
Block a user