From 8b87ed4afd4e030a2124f75acb7b1909ee0f0956 Mon Sep 17 00:00:00 2001 From: Catalin Pit Date: Thu, 4 Jun 2026 14:51:57 +0300 Subject: [PATCH] refactor: use getRecipientSigningOrder for signingOrder in envelope and recipient functions --- packages/lib/server-only/envelope/create-envelope.ts | 3 ++- .../lib/server-only/envelope/duplicate-envelope.ts | 3 ++- .../recipient/create-envelope-recipients.ts | 4 ++-- .../server-only/recipient/set-document-recipients.ts | 10 +++++++--- .../server-only/recipient/set-template-recipients.ts | 5 +++-- .../recipient/update-envelope-recipients.ts | 4 ++-- .../template/create-document-from-direct-template.ts | 3 ++- .../template/create-document-from-template.ts | 3 ++- 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/lib/server-only/envelope/create-envelope.ts b/packages/lib/server-only/envelope/create-envelope.ts index f1ddbe13e..f07900573 100644 --- a/packages/lib/server-only/envelope/create-envelope.ts +++ b/packages/lib/server-only/envelope/create-envelope.ts @@ -34,6 +34,7 @@ import { getFileServerSide } from '../../universal/upload/get-file.server'; import { putPdfFileServerSide } from '../../universal/upload/put-file.server'; import { extractDerivedDocumentMeta } from '../../utils/document'; import { createDocumentAuthOptions, createRecipientAuthOptions } from '../../utils/document-auth'; +import { getRecipientSigningOrder } from '../../utils/recipients'; import { buildTeamWhereQuery } from '../../utils/teams'; import { incrementDocumentId, incrementTemplateId } from '../envelope/increment-id'; import { assertOrganisationRatesAndLimits } from '../rate-limit/assert-organisation-rates-and-limits'; @@ -431,7 +432,7 @@ export const createEnvelope = async ({ name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, diff --git a/packages/lib/server-only/envelope/duplicate-envelope.ts b/packages/lib/server-only/envelope/duplicate-envelope.ts index bffedb4da..cf26aafa0 100644 --- a/packages/lib/server-only/envelope/duplicate-envelope.ts +++ b/packages/lib/server-only/envelope/duplicate-envelope.ts @@ -7,6 +7,7 @@ import { AppError, AppErrorCode } from '../../errors/app-error'; import { mapEnvelopeToWebhookDocumentPayload, ZWebhookDocumentSchema } from '../../types/webhook-payload'; import { nanoid, prefixedId } from '../../universal/id'; import type { EnvelopeIdOptions } from '../../utils/envelope'; +import { getRecipientSigningOrder } from '../../utils/recipients'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; import { incrementDocumentId, incrementTemplateId } from '../envelope/increment-id'; import { assertOrganisationRatesAndLimits } from '../rate-limit/assert-organisation-rates-and-limits'; @@ -178,7 +179,7 @@ export const duplicateEnvelope = async ({ id, userId, teamId, overrides }: Dupli email: recipient.email, name: recipient.name, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), fields: includeFields ? { diff --git a/packages/lib/server-only/recipient/create-envelope-recipients.ts b/packages/lib/server-only/recipient/create-envelope-recipients.ts index d456b063f..4d8f74105 100644 --- a/packages/lib/server-only/recipient/create-envelope-recipients.ts +++ b/packages/lib/server-only/recipient/create-envelope-recipients.ts @@ -9,7 +9,7 @@ import { EnvelopeType, RecipientRole, SendStatus, SigningStatus } from '@prisma/ import { AppError, AppErrorCode } from '../../errors/app-error'; import type { EnvelopeIdOptions } from '../../utils/envelope'; -import { mapRecipientToLegacyRecipient } from '../../utils/recipients'; +import { getRecipientSigningOrder, mapRecipientToLegacyRecipient } from '../../utils/recipients'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; export interface CreateEnvelopeRecipientsOptions { @@ -99,7 +99,7 @@ export const createEnvelopeRecipients = async ({ name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, diff --git a/packages/lib/server-only/recipient/set-document-recipients.ts b/packages/lib/server-only/recipient/set-document-recipients.ts index c09827ef5..90606a151 100644 --- a/packages/lib/server-only/recipient/set-document-recipients.ts +++ b/packages/lib/server-only/recipient/set-document-recipients.ts @@ -20,7 +20,11 @@ import { AppError, AppErrorCode } from '../../errors/app-error'; import { extractDerivedDocumentEmailSettings } from '../../types/document-email'; import { type EnvelopeIdOptions, mapSecondaryIdToDocumentId } from '../../utils/envelope'; import { logger } from '../../utils/logger'; -import { canRecipientBeModified, isRecipientEmailValidForSending } from '../../utils/recipients'; +import { + canRecipientBeModified, + getRecipientSigningOrder, + isRecipientEmailValidForSending, +} from '../../utils/recipients'; import { renderEmailWithI18N } from '../../utils/render-email-with-i18n'; import { getEmailContext } from '../email/get-email-context'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; @@ -166,7 +170,7 @@ export const setDocumentRecipients = async ({ name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), envelopeId: envelope.id, sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, @@ -176,7 +180,7 @@ export const setDocumentRecipients = async ({ name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), envelopeId: envelope.id, sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, diff --git a/packages/lib/server-only/recipient/set-template-recipients.ts b/packages/lib/server-only/recipient/set-template-recipients.ts index 22b36a88a..ce4acc8fe 100644 --- a/packages/lib/server-only/recipient/set-template-recipients.ts +++ b/packages/lib/server-only/recipient/set-template-recipients.ts @@ -11,6 +11,7 @@ import { type TRecipientActionAuthTypes, ZRecipientAuthOptionsSchema } from '../ import { nanoid } from '../../universal/id'; import { createRecipientAuthOptions } from '../../utils/document-auth'; import { type EnvelopeIdOptions, mapSecondaryIdToTemplateId } from '../../utils/envelope'; +import { getRecipientSigningOrder } from '../../utils/recipients'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; export type SetTemplateRecipientsOptions = { @@ -134,7 +135,7 @@ export const setTemplateRecipients = async ({ userId, teamId, id, recipients }: name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), envelopeId: envelope.id, authOptions, }, @@ -142,7 +143,7 @@ export const setTemplateRecipients = async ({ userId, teamId, id, recipients }: name: recipient.name, email: recipient.email, role: recipient.role, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), envelopeId: envelope.id, authOptions, diff --git a/packages/lib/server-only/recipient/update-envelope-recipients.ts b/packages/lib/server-only/recipient/update-envelope-recipients.ts index d955a9911..1d91b733d 100644 --- a/packages/lib/server-only/recipient/update-envelope-recipients.ts +++ b/packages/lib/server-only/recipient/update-envelope-recipients.ts @@ -11,7 +11,7 @@ import { AppError, AppErrorCode } from '../../errors/app-error'; import { extractLegacyIds } from '../../universal/id'; import type { EnvelopeIdOptions } from '../../utils/envelope'; import { mapFieldToLegacyField } from '../../utils/fields'; -import { canRecipientBeModified } from '../../utils/recipients'; +import { canRecipientBeModified, getRecipientSigningOrder } from '../../utils/recipients'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; export interface UpdateEnvelopeRecipientsOptions { @@ -131,7 +131,7 @@ export const updateEnvelopeRecipients = async ({ name: mergedRecipient.name, email: mergedRecipient.email, role: mergedRecipient.role, - signingOrder: mergedRecipient.signingOrder, + signingOrder: getRecipientSigningOrder(mergedRecipient), envelopeId: envelope.id, sendStatus: mergedRecipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: mergedRecipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, diff --git a/packages/lib/server-only/template/create-document-from-direct-template.ts b/packages/lib/server-only/template/create-document-from-direct-template.ts index 3ae9086a3..b18411b6f 100644 --- a/packages/lib/server-only/template/create-document-from-direct-template.ts +++ b/packages/lib/server-only/template/create-document-from-direct-template.ts @@ -39,6 +39,7 @@ import { extractDocumentAuthMethods, } from '../../utils/document-auth'; import { mapSecondaryIdToTemplateId } from '../../utils/envelope'; +import { getRecipientSigningOrder } from '../../utils/recipients'; import { sendDocument } from '../document/send-document'; import { validateFieldAuth } from '../document/validate-field-auth'; import { incrementDocumentId } from '../envelope/increment-id'; @@ -386,7 +387,7 @@ export const createDocumentFromDirectTemplate = async ({ }), sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: nanoid(), }; }), diff --git a/packages/lib/server-only/template/create-document-from-template.ts b/packages/lib/server-only/template/create-document-from-template.ts index 75c755b50..7c096c8a8 100644 --- a/packages/lib/server-only/template/create-document-from-template.ts +++ b/packages/lib/server-only/template/create-document-from-template.ts @@ -46,6 +46,7 @@ import { } from '../../utils/document-auth'; import type { EnvelopeIdOptions } from '../../utils/envelope'; import { mapSecondaryIdToTemplateId } from '../../utils/envelope'; +import { getRecipientSigningOrder } from '../../utils/recipients'; import { buildTeamWhereQuery } from '../../utils/teams'; import { getEnvelopeWhereInput } from '../envelope/get-envelope-by-id'; import { incrementDocumentId } from '../envelope/increment-id'; @@ -575,7 +576,7 @@ export const createDocumentFromTemplate = async ({ }), sendStatus: recipient.role === RecipientRole.CC ? SendStatus.SENT : SendStatus.NOT_SENT, signingStatus: recipient.role === RecipientRole.CC ? SigningStatus.SIGNED : SigningStatus.NOT_SIGNED, - signingOrder: recipient.signingOrder, + signingOrder: getRecipientSigningOrder(recipient), token: recipient.token, }; }),