feat: add create document beta endpoint (#1584)

This commit is contained in:
David Nguyen
2025-01-16 13:36:00 +11:00
committed by GitHub
parent 5750f2b477
commit 9e03747e43
47 changed files with 2624 additions and 1934 deletions

View File

@@ -193,8 +193,8 @@ export const recipientRouter = router({
deleteDocumentRecipient: authenticatedProcedure
.meta({
openapi: {
method: 'DELETE',
path: '/document/recipient/{recipientId}',
method: 'POST',
path: '/document/recipient/delete',
summary: 'Delete document recipient',
tags: ['Document Recipients'],
},
@@ -367,8 +367,8 @@ export const recipientRouter = router({
deleteTemplateRecipient: authenticatedProcedure
.meta({
openapi: {
method: 'DELETE',
path: '/template/recipient/{recipientId}',
method: 'POST',
path: '/template/recipient/delete',
summary: 'Delete template recipient',
tags: ['Template Recipients'],
},

View File

@@ -14,7 +14,14 @@ export const ZGetRecipientRequestSchema = z.object({
export const ZGetRecipientResponseSchema = ZRecipientSchema;
const ZCreateRecipientSchema = z.object({
/**
* When changing this, ensure everything that uses this schema is updated correctly
* since this will change the Openapi schema.
*
* Example `createDocument` uses this, so you will need to update that function to
* pass along required details.
*/
export const ZCreateRecipientSchema = z.object({
email: z.string().toLowerCase().email().min(1),
name: z.string(),
role: z.nativeEnum(RecipientRole),
@@ -42,11 +49,16 @@ export const ZCreateDocumentRecipientResponseSchema = ZRecipientLiteSchema;
export const ZCreateDocumentRecipientsRequestSchema = z.object({
documentId: z.number(),
recipients: z.array(ZCreateRecipientSchema).refine((recipients) => {
const emails = recipients.map((recipient) => recipient.email.toLowerCase());
recipients: z.array(ZCreateRecipientSchema).refine(
(recipients) => {
const emails = recipients.map((recipient) => recipient.email.toLowerCase());
return new Set(emails).size === emails.length;
}),
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZCreateDocumentRecipientsResponseSchema = z.object({
@@ -62,13 +74,18 @@ export const ZUpdateDocumentRecipientResponseSchema = ZRecipientSchema;
export const ZUpdateDocumentRecipientsRequestSchema = z.object({
documentId: z.number(),
recipients: z.array(ZUpdateRecipientSchema).refine((recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email?.toLowerCase());
recipients: z.array(ZUpdateRecipientSchema).refine(
(recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email?.toLowerCase());
return new Set(emails).size === emails.length;
}),
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZUpdateDocumentRecipientsResponseSchema = z.object({
@@ -100,7 +117,7 @@ export const ZSetDocumentRecipientsRequestSchema = z
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'] },
{ message: 'Recipients must have unique emails', path: ['recipients__root'] },
);
export const ZSetDocumentRecipientsResponseSchema = z.object({
@@ -116,11 +133,16 @@ export const ZCreateTemplateRecipientResponseSchema = ZRecipientLiteSchema;
export const ZCreateTemplateRecipientsRequestSchema = z.object({
templateId: z.number(),
recipients: z.array(ZCreateRecipientSchema).refine((recipients) => {
const emails = recipients.map((recipient) => recipient.email);
recipients: z.array(ZCreateRecipientSchema).refine(
(recipients) => {
const emails = recipients.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
}),
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZCreateTemplateRecipientsResponseSchema = z.object({
@@ -136,13 +158,18 @@ export const ZUpdateTemplateRecipientResponseSchema = ZRecipientSchema;
export const ZUpdateTemplateRecipientsRequestSchema = z.object({
templateId: z.number(),
recipients: z.array(ZUpdateRecipientSchema).refine((recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email);
recipients: z.array(ZUpdateRecipientSchema).refine(
(recipients) => {
const emails = recipients
.filter((recipient) => recipient.email !== undefined)
.map((recipient) => recipient.email);
return new Set(emails).size === emails.length;
}),
return new Set(emails).size === emails.length;
},
{
message: 'Recipients must have unique emails',
},
),
});
export const ZUpdateTemplateRecipientsResponseSchema = z.object({