Files
sign/packages/trpc/server/recipient-router/schema.ts

70 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-12-02 09:38:24 +11:00
import { z } from 'zod';
2024-03-28 13:13:29 +08:00
import {
ZRecipientActionAuthSchema,
ZRecipientActionAuthTypesSchema,
} from '@documenso/lib/types/document-auth';
import { RecipientRole } from '@documenso/prisma/client';
2023-12-02 09:38:24 +11:00
export const ZAddSignersMutationSchema = z
.object({
documentId: z.number(),
2024-02-26 11:59:32 +11:00
teamId: z.number().optional(),
2023-12-02 09:38:24 +11:00
signers: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
2024-03-28 13:13:29 +08:00
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
2023-12-02 09:38:24 +11:00
}),
),
})
.refine(
(schema) => {
const emails = schema.signers.map((signer) => signer.email.toLowerCase());
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Signers must have unique emails', path: ['signers__root'] },
);
export type TAddSignersMutationSchema = z.infer<typeof ZAddSignersMutationSchema>;
export const ZAddTemplateSignersMutationSchema = z
.object({
teamId: z.number().optional(),
templateId: z.number(),
signers: z.array(
z.object({
nativeId: z.number().optional(),
email: z.string().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
actionAuth: ZRecipientActionAuthTypesSchema.optional().nullable(),
}),
),
})
.refine(
(schema) => {
const emails = schema.signers.map((signer) => signer.email.toLowerCase());
return new Set(emails).size === emails.length;
},
// Dirty hack to handle errors when .root is populated for an array type
{ message: 'Signers must have unique emails', path: ['signers__root'] },
);
export type TAddTemplateSignersMutationSchema = z.infer<typeof ZAddTemplateSignersMutationSchema>;
2023-12-02 09:38:24 +11:00
export const ZCompleteDocumentWithTokenMutationSchema = z.object({
token: z.string(),
documentId: z.number(),
2024-03-28 13:13:29 +08:00
authOptions: ZRecipientActionAuthSchema.optional(),
2023-12-02 09:38:24 +11:00
});
export type TCompleteDocumentWithTokenMutationSchema = z.infer<
typeof ZCompleteDocumentWithTokenMutationSchema
>;