mirror of
https://github.com/documenso/documenso.git
synced 2025-11-18 02:32:00 +10:00
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.
115 lines
3.1 KiB
TypeScript
115 lines
3.1 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { ZFolderTypeSchema } from '@documenso/lib/types/folder-type';
|
|
import { ZFindSearchParamsSchema } from '@documenso/lib/types/search-params';
|
|
import { DocumentVisibility } from '@documenso/prisma/generated/types';
|
|
|
|
/**
|
|
* Required for empty responses since we currently can't 201 requests for our openapi setup.
|
|
*
|
|
* Without this it will throw an error in Speakeasy SDK when it tries to parse an empty response.
|
|
*/
|
|
export const ZSuccessResponseSchema = z.object({
|
|
success: z.boolean(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZGenericSuccessResponse = {
|
|
success: true,
|
|
} satisfies z.infer<typeof ZSuccessResponseSchema>;
|
|
|
|
export const ZFolderSchema = z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
userId: z.number(),
|
|
teamId: z.number().nullable(),
|
|
parentId: z.string().nullable(),
|
|
pinned: z.boolean(),
|
|
createdAt: z.date(),
|
|
updatedAt: z.date(),
|
|
visibility: z.nativeEnum(DocumentVisibility),
|
|
type: ZFolderTypeSchema,
|
|
});
|
|
|
|
export type TFolder = z.infer<typeof ZFolderSchema>;
|
|
|
|
const ZFolderCountSchema = z.object({
|
|
documents: z.number(),
|
|
templates: z.number(),
|
|
subfolders: z.number(),
|
|
});
|
|
|
|
const ZSubfolderSchema = ZFolderSchema.extend({
|
|
subfolders: z.array(z.any()),
|
|
_count: ZFolderCountSchema,
|
|
});
|
|
|
|
export const ZFolderWithSubfoldersSchema = ZFolderSchema.extend({
|
|
subfolders: z.array(ZSubfolderSchema),
|
|
_count: ZFolderCountSchema,
|
|
});
|
|
|
|
export type TFolderWithSubfolders = z.infer<typeof ZFolderWithSubfoldersSchema>;
|
|
|
|
export const ZCreateFolderSchema = z.object({
|
|
name: z.string(),
|
|
parentId: z.string().optional(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZUpdateFolderSchema = z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
visibility: z.nativeEnum(DocumentVisibility),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export type TUpdateFolderSchema = z.infer<typeof ZUpdateFolderSchema>;
|
|
|
|
export const ZDeleteFolderSchema = z.object({
|
|
id: z.string(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZMoveFolderSchema = z.object({
|
|
id: z.string(),
|
|
parentId: z.string().nullable(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZPinFolderSchema = z.object({
|
|
folderId: z.string(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZUnpinFolderSchema = z.object({
|
|
folderId: z.string(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZGetFoldersSchema = z.object({
|
|
parentId: z.string().nullable().optional(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZGetFoldersResponseSchema = z.object({
|
|
folders: z.array(ZFolderWithSubfoldersSchema),
|
|
breadcrumbs: z.array(ZFolderSchema),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export type TGetFoldersResponse = z.infer<typeof ZGetFoldersResponseSchema>;
|
|
|
|
export const ZFindFoldersRequestSchema = ZFindSearchParamsSchema.extend({
|
|
parentId: z.string().nullable().optional(),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export const ZFindFoldersResponseSchema = z.object({
|
|
data: z.array(ZFolderWithSubfoldersSchema),
|
|
breadcrumbs: z.array(ZFolderSchema),
|
|
type: ZFolderTypeSchema.optional(),
|
|
});
|
|
|
|
export type TFindFoldersResponse = z.infer<typeof ZFindFoldersResponseSchema>;
|