feat: migrate templates and documents to envelope model

This commit is contained in:
David Nguyen
2025-09-11 18:23:38 +10:00
parent eec2307634
commit bf89bc781b
234 changed files with 8677 additions and 6054 deletions

View File

@ -0,0 +1,53 @@
/**
* Legacy Document schema to confirm backwards API compatibility since
* we migrated Documents to Envelopes.
*/
import { z } from 'zod';
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
import DocumentStatusSchema from '../generated/zod/inputTypeSchemas/DocumentStatusSchema';
import DocumentVisibilitySchema from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
const DocumentSourceSchema = z.enum(['DOCUMENT', 'TEMPLATE', 'TEMPLATE_DIRECT_LINK']);
/////////////////////////////////////////
// DOCUMENT SCHEMA
/////////////////////////////////////////
export const LegacyDocumentSchema = z.object({
visibility: DocumentVisibilitySchema,
status: DocumentStatusSchema,
source: DocumentSourceSchema,
id: z.number(),
qrToken: z
.string()
.describe('The token for viewing the document using the QR code on the certificate.')
.nullable(),
externalId: z
.string()
.describe('A custom external ID you can use to identify the document.')
.nullable(),
userId: z.number().describe('The ID of the user that created this document.'),
teamId: z.number(),
/**
* [DocumentAuthOptions]
*/
authOptions: ZDocumentAuthOptionsSchema.nullable(),
/**
* [DocumentFormValues]
*/
formValues: ZDocumentFormValuesSchema.nullable(),
title: z.string(),
// documentDataId: z.string(), // Todo: Migration
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
completedAt: z.coerce.date().nullable(),
deletedAt: z.coerce.date().nullable(),
templateId: z.number().nullable(),
useLegacyFieldInsertion: z.boolean(),
folderId: z.string().nullable(),
});
export type Document = z.infer<typeof LegacyDocumentSchema>;

View File

@ -1,10 +1,10 @@
import type { Document, DocumentData, Recipient } from '@prisma/client';
import type { DocumentData, Envelope, Recipient } from '@prisma/client';
export type DocumentWithRecipients = Document & {
export type EnvelopeWithRecipients = Envelope & {
recipients: Recipient[];
};
export type DocumentWithRecipient = Document & {
export type EnvelopeWithRecipient = Envelope & {
recipients: Recipient[];
documentData: DocumentData;
};

View File

@ -0,0 +1,35 @@
/**
* Legacy Template schema to confirm backwards API compatibility since
* we removed the "Template" prisma schema model.
*/
import { TemplateType } from '@prisma/client';
import { z } from 'zod';
import { ZDocumentAuthOptionsSchema } from '@documenso/lib/types/document-auth';
import { DocumentVisibilitySchema } from '../generated/zod/inputTypeSchemas/DocumentVisibilitySchema';
export const TemplateTypeSchema = z.nativeEnum(TemplateType);
export const TemplateSchema = z.object({
type: TemplateTypeSchema,
visibility: DocumentVisibilitySchema,
id: z.number(),
externalId: z.string().nullable(),
title: z.string(),
/**
* [DocumentAuthOptions]
*/
authOptions: ZDocumentAuthOptionsSchema.nullable(),
// templateDocumentDataId: z.string(), // Todo: Migration - Removal.
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
publicTitle: z.string(),
publicDescription: z.string(),
useLegacyFieldInsertion: z.boolean(),
userId: z.number(),
teamId: z.number(),
folderId: z.string().nullable(),
});
export type Template = z.infer<typeof TemplateSchema>;