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.
This commit is contained in:
David Nguyen
2025-10-14 21:56:36 +11:00
committed by GitHub
parent 7b17156e56
commit 7f09ba72f4
447 changed files with 33467 additions and 9622 deletions

View File

@ -1,8 +1,11 @@
import { EnvelopeType } from '@prisma/client';
import { P, match } from 'ts-pattern';
import { prisma } from '@documenso/prisma';
import { AppError, AppErrorCode } from '../../errors/app-error';
import { alphaid } from '../../universal/id';
import { unsafeBuildEnvelopeIdQuery } from '../../utils/envelope';
export type CreateSharingIdOptions =
| {
@ -15,12 +18,29 @@ export type CreateSharingIdOptions =
};
export const createOrGetShareLink = async ({ documentId, ...options }: CreateSharingIdOptions) => {
const envelope = await prisma.envelope.findUnique({
where: unsafeBuildEnvelopeIdQuery(
{
type: 'documentId',
id: documentId,
},
EnvelopeType.DOCUMENT,
),
select: {
id: true,
},
});
if (!envelope) {
throw new AppError(AppErrorCode.NOT_FOUND);
}
const email = await match(options)
.with({ token: P.string }, async ({ token }) => {
return await prisma.recipient
.findFirst({
where: {
documentId,
envelopeId: envelope.id,
token,
},
})
@ -32,6 +52,9 @@ export const createOrGetShareLink = async ({ documentId, ...options }: CreateSha
where: {
id: userId,
},
select: {
email: true,
},
})
.then((user) => user?.email);
})
@ -43,14 +66,14 @@ export const createOrGetShareLink = async ({ documentId, ...options }: CreateSha
return await prisma.documentShareLink.upsert({
where: {
documentId_email: {
envelopeId_email: {
envelopeId: envelope.id,
email,
documentId,
},
},
create: {
email,
documentId,
envelopeId: envelope.id,
slug: alphaid(14),
},
update: {},

View File

@ -1,13 +0,0 @@
import { prisma } from '@documenso/prisma';
export type GetShareLinkBySlugOptions = {
slug: string;
};
export const getShareLinkBySlug = async ({ slug }: GetShareLinkBySlugOptions) => {
return await prisma.documentShareLink.findFirstOrThrow({
where: {
slug,
},
});
};