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,6 +1,6 @@
import { PDFDocument } from '@cantoo/pdf-lib';
import { sValidator } from '@hono/standard-validator';
import { Hono } from 'hono';
import { PDFDocument } from 'pdf-lib';
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT } from '@documenso/lib/constants/app';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';

View File

@ -1,15 +1,6 @@
import type { Context } from 'hono';
import { getSession } from '@documenso/auth/server/lib/utils/get-session';
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
import { prisma } from '@documenso/prisma';
function extractIdFromPath(path: string, prefix: string): string | null {
const regex = new RegExp(`^${prefix}/([^/]+)`);
const match = path.match(regex);
return match ? match[1] : null;
}
// eslint-disable-next-line @typescript-eslint/require-await
export const handleRedirects = async (c: Context): Promise<string | null> => {
const { req } = c;
const path = req.path;
@ -24,152 +15,5 @@ export const handleRedirects = async (c: Context): Promise<string | null> => {
return '/';
}
// Document folder routes.
if (path.startsWith('/documents/f/')) {
const folderId = extractIdFromPath(path, '/documents/f');
if (!folderId) {
return '/';
}
const teamUrl = await hasAccessToFolder(c, folderId);
if (folderId && teamUrl) {
return `/t/${teamUrl}/documents/f/${folderId}`;
}
}
// Document routes.
if (path.startsWith('/documents/')) {
const rawDocumentId = extractIdFromPath(path, '/documents');
const documentId = Number(rawDocumentId);
if (!documentId || isNaN(documentId)) {
return '/';
}
const teamUrl = await hasAccessToDocument(c, documentId);
if (!teamUrl) {
return '/';
}
const queryString = req.url.split('?')[1];
const redirectPath = `/t/${teamUrl}${path}${queryString ? `?${queryString}` : ''}`;
return redirectPath;
}
// Template folder routes.
if (path.startsWith('/templates/f/')) {
const folderId = extractIdFromPath(path, '/templates/f');
if (!folderId) {
return '/';
}
const teamUrl = await hasAccessToFolder(c, folderId);
if (folderId && teamUrl) {
return `/t/${teamUrl}/templates/f/${folderId}`;
}
}
if (path.startsWith('/templates/')) {
const rawTemplateId = extractIdFromPath(path, '/templates');
const templateId = Number(rawTemplateId);
if (!templateId || isNaN(templateId)) {
return '/';
}
const teamUrl = await hasAccessToTemplate(c, templateId);
if (!teamUrl) {
return '/';
}
const queryString = req.url.split('?')[1];
const redirectPath = `/t/${teamUrl}${path}${queryString ? `?${queryString}` : ''}`;
return redirectPath;
}
return null;
};
async function hasAccessToDocument(c: Context, documentId: number): Promise<string | null> {
const session = await getSession(c);
const userId = session.user.id;
const document = await prisma.document.findUnique({
where: {
id: documentId,
team: buildTeamWhereQuery({
userId,
teamId: undefined,
}),
},
select: {
team: {
select: {
url: true,
},
},
},
});
return document ? document.team.url : null;
}
async function hasAccessToFolder(c: Context, folderId: string): Promise<string | null> {
const session = await getSession(c);
const userId = session.user.id;
const folder = await prisma.folder.findUnique({
where: {
id: folderId,
team: buildTeamWhereQuery({
userId,
teamId: undefined,
}),
},
select: {
team: {
select: {
url: true,
},
},
},
});
return folder ? folder.team.url : null;
}
async function hasAccessToTemplate(c: Context, templateId: number): Promise<string | null> {
const session = await getSession(c);
const userId = session.user.id;
const template = await prisma.template.findUnique({
where: {
id: templateId,
team: buildTeamWhereQuery({
userId,
teamId: undefined,
}),
},
select: {
team: {
select: {
url: true,
},
},
},
});
return template ? template.team.url : null;
}