Files
documenso/packages/lib/utils/mask-recipient-tokens-for-document.ts
David Nguyen 7f09ba72f4 feat: add envelopes (#2025)
This PR is handles the changes required to support envelopes. The new
envelope editor/signing page will be hidden during release.

The core changes here is to migrate the documents and templates model to
a centralized envelopes model.

Even though Documents and Templates are removed, from the user
perspective they will still exist as we remap envelopes to documents and
templates.
2025-10-14 21:56:36 +11:00

40 lines
879 B
TypeScript

import type { User } from '@prisma/client';
import type { EnvelopeWithRecipients } from '@documenso/prisma/types/document-with-recipient';
export type MaskRecipientTokensForDocumentOptions<T extends EnvelopeWithRecipients> = {
document: T;
user?: Pick<User, 'id' | 'email'>;
token?: string;
};
export const maskRecipientTokensForDocument = <T extends EnvelopeWithRecipients>({
document,
user,
token,
}: MaskRecipientTokensForDocumentOptions<T>) => {
const maskedRecipients = document.recipients.map((recipient) => {
if (document.userId === user?.id) {
return recipient;
}
if (recipient.email === user?.email) {
return recipient;
}
if (recipient.token === token) {
return recipient;
}
return {
...recipient,
token: '',
};
});
return {
...document,
Recipient: maskedRecipients,
};
};