mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
feat: add envelopes api
This commit is contained in:
@ -13,11 +13,21 @@ import {
|
||||
} from './create-envelope-items.types';
|
||||
|
||||
export const createEnvelopeItemsRoute = authenticatedProcedure
|
||||
// Todo: Envelopes - Pending direct uploads
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/item/create-many',
|
||||
// summary: 'Create envelope items',
|
||||
// description: 'Create multiple envelope items for an envelope',
|
||||
// tags: ['Envelope Item'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateEnvelopeItemsRequestSchema)
|
||||
.output(ZCreateEnvelopeItemsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { envelopeId, items } = input;
|
||||
const { envelopeId, data: items } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
|
||||
@ -7,7 +7,7 @@ import { ZDocumentTitleSchema } from '../document-router/schema';
|
||||
|
||||
export const ZCreateEnvelopeItemsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
items: z
|
||||
data: z
|
||||
.object({
|
||||
title: ZDocumentTitleSchema,
|
||||
documentDataId: z.string(),
|
||||
|
||||
@ -9,6 +9,15 @@ import {
|
||||
} from './create-envelope.types';
|
||||
|
||||
export const createEnvelopeRoute = authenticatedProcedure
|
||||
// Todo: Envelopes - Pending direct uploads
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/create',
|
||||
// summary: 'Create envelope',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateEnvelopeRequestSchema)
|
||||
.output(ZCreateEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -24,16 +24,6 @@ import {
|
||||
} from '../document-router/schema';
|
||||
import { ZCreateRecipientSchema } from '../recipient-router/schema';
|
||||
|
||||
// Currently not in use until we allow passthrough documents on create.
|
||||
// export const createEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/create',
|
||||
// summary: 'Create envelope',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZCreateEnvelopeRequestSchema = z.object({
|
||||
title: ZDocumentTitleSchema,
|
||||
type: z.nativeEnum(EnvelopeType),
|
||||
|
||||
@ -12,6 +12,15 @@ import {
|
||||
} from './delete-envelope-item.types';
|
||||
|
||||
export const deleteEnvelopeItemRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/item/delete',
|
||||
summary: 'Delete envelope item',
|
||||
description: 'Delete an envelope item from an envelope',
|
||||
tags: ['Envelope Item'],
|
||||
},
|
||||
})
|
||||
.input(ZDeleteEnvelopeItemRequestSchema)
|
||||
.output(ZDeleteEnvelopeItemResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
|
||||
import { deleteTemplate } from '@documenso/lib/server-only/template/delete-template';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
@ -11,12 +13,19 @@ import {
|
||||
} from './delete-envelope.types';
|
||||
|
||||
export const deleteEnvelopeRoute = authenticatedProcedure
|
||||
// .meta(deleteEnvelopeMeta)
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/delete',
|
||||
summary: 'Delete envelope',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZDeleteEnvelopeRequestSchema)
|
||||
.output(ZDeleteEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId } = ctx;
|
||||
const { envelopeId, envelopeType } = input;
|
||||
const { envelopeId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
@ -24,7 +33,22 @@ export const deleteEnvelopeRoute = authenticatedProcedure
|
||||
},
|
||||
});
|
||||
|
||||
await match(envelopeType)
|
||||
const unsafeEnvelope = await prisma.envelope.findUnique({
|
||||
where: {
|
||||
id: envelopeId,
|
||||
},
|
||||
select: {
|
||||
type: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!unsafeEnvelope) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Envelope not found',
|
||||
});
|
||||
}
|
||||
|
||||
await match(unsafeEnvelope.type)
|
||||
.with(EnvelopeType.DOCUMENT, async () =>
|
||||
deleteDocument({
|
||||
userId: ctx.user.id,
|
||||
|
||||
@ -1,18 +1,7 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
// export const deleteEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/delete',
|
||||
// summary: 'Delete envelope',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZDeleteEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
envelopeType: z.nativeEnum(EnvelopeType),
|
||||
});
|
||||
|
||||
export const ZDeleteEnvelopeResponseSchema = z.void();
|
||||
|
||||
@ -8,7 +8,15 @@ import {
|
||||
} from './distribute-envelope.types';
|
||||
|
||||
export const distributeEnvelopeRoute = authenticatedProcedure
|
||||
// .meta(distributeEnvelopeMeta)
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/distribute',
|
||||
summary: 'Distribute envelope',
|
||||
description: 'Send the envelope to recipients based on your distribution method',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZDistributeEnvelopeRequestSchema)
|
||||
.output(ZDistributeEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -2,16 +2,6 @@ import { z } from 'zod';
|
||||
|
||||
import { ZDocumentMetaUpdateSchema } from '@documenso/lib/types/document-meta';
|
||||
|
||||
// export const distributeEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/distribute',
|
||||
// summary: 'Distribute envelope',
|
||||
// description: 'Send the document out to recipients based on your distribution method',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZDistributeEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string().describe('The ID of the envelope to send.'),
|
||||
meta: ZDocumentMetaUpdateSchema.pick({
|
||||
|
||||
@ -7,6 +7,15 @@ import {
|
||||
} from './duplicate-envelope.types';
|
||||
|
||||
export const duplicateEnvelopeRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/duplicate',
|
||||
summary: 'Duplicate envelope',
|
||||
description: 'Duplicate an envelope with all its settings',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZDuplicateEnvelopeRequestSchema)
|
||||
.output(ZDuplicateEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
import { createEnvelopeFields } from '@documenso/lib/server-only/field/create-envelope-fields';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZCreateEnvelopeFieldsRequestSchema,
|
||||
ZCreateEnvelopeFieldsResponseSchema,
|
||||
} from './create-envelope-fields.types';
|
||||
|
||||
export const createEnvelopeFieldsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/field/create-many',
|
||||
summary: 'Create envelope fields',
|
||||
description: 'Create multiple fields for an envelope',
|
||||
tags: ['Envelope Fields'],
|
||||
},
|
||||
})
|
||||
.input(ZCreateEnvelopeFieldsRequestSchema)
|
||||
.output(ZCreateEnvelopeFieldsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { envelopeId, data: fields } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await createEnvelopeFields({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
fields,
|
||||
requestMetadata: metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
ZClampedFieldHeightSchema,
|
||||
ZClampedFieldPageXSchema,
|
||||
ZClampedFieldPageYSchema,
|
||||
ZClampedFieldWidthSchema,
|
||||
ZFieldPageNumberSchema,
|
||||
ZFieldSchema,
|
||||
} from '@documenso/lib/types/field';
|
||||
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
|
||||
const ZCreateFieldSchema = ZFieldAndMetaSchema.and(
|
||||
z.object({
|
||||
recipientId: z.number().describe('The ID of the recipient to create the field for'),
|
||||
envelopeItemId: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The ID of the envelope item to put the field on. If not provided, field will be placed on the first item.',
|
||||
),
|
||||
pageNumber: ZFieldPageNumberSchema,
|
||||
pageX: ZClampedFieldPageXSchema,
|
||||
pageY: ZClampedFieldPageYSchema,
|
||||
width: ZClampedFieldWidthSchema,
|
||||
height: ZClampedFieldHeightSchema,
|
||||
}),
|
||||
);
|
||||
|
||||
export const ZCreateEnvelopeFieldsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZCreateFieldSchema.array(),
|
||||
});
|
||||
|
||||
export const ZCreateEnvelopeFieldsResponseSchema = z.object({
|
||||
fields: z.array(ZFieldSchema),
|
||||
});
|
||||
|
||||
export type TCreateEnvelopeFieldsRequest = z.infer<typeof ZCreateEnvelopeFieldsRequestSchema>;
|
||||
export type TCreateEnvelopeFieldsResponse = z.infer<typeof ZCreateEnvelopeFieldsResponseSchema>;
|
||||
@ -0,0 +1,125 @@
|
||||
import { EnvelopeType } from '@prisma/client';
|
||||
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
|
||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { canRecipientFieldsBeModified } from '@documenso/lib/utils/recipients';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZDeleteEnvelopeFieldRequestSchema,
|
||||
ZDeleteEnvelopeFieldResponseSchema,
|
||||
} from './delete-envelope-field.types';
|
||||
|
||||
export const deleteEnvelopeFieldRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/field/delete',
|
||||
summary: 'Delete envelope field',
|
||||
description: 'Delete an envelope field',
|
||||
tags: ['Envelope Field'],
|
||||
},
|
||||
})
|
||||
.input(ZDeleteEnvelopeFieldRequestSchema)
|
||||
.output(ZDeleteEnvelopeFieldResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { fieldId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
fieldId,
|
||||
},
|
||||
});
|
||||
|
||||
const unsafeField = await prisma.field.findUnique({
|
||||
where: {
|
||||
id: fieldId,
|
||||
},
|
||||
select: {
|
||||
envelopeId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!unsafeField) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Field not found',
|
||||
});
|
||||
}
|
||||
|
||||
const { envelopeWhereInput } = await getEnvelopeWhereInput({
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: unsafeField.envelopeId,
|
||||
},
|
||||
type: null,
|
||||
userId: user.id,
|
||||
teamId,
|
||||
});
|
||||
|
||||
const envelope = await prisma.envelope.findUnique({
|
||||
where: envelopeWhereInput,
|
||||
include: {
|
||||
recipients: {
|
||||
include: {
|
||||
fields: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const recipientWithFields = envelope?.recipients.find((recipient) =>
|
||||
recipient.fields.some((field) => field.id === fieldId),
|
||||
);
|
||||
const fieldToDelete = recipientWithFields?.fields.find((field) => field.id === fieldId);
|
||||
|
||||
if (!envelope || !recipientWithFields || !fieldToDelete) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Field not found',
|
||||
});
|
||||
}
|
||||
|
||||
if (envelope.completedAt) {
|
||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
message: 'Envelope already complete',
|
||||
});
|
||||
}
|
||||
|
||||
// Check whether the recipient associated with the field can have new fields created.
|
||||
if (!canRecipientFieldsBeModified(recipientWithFields, recipientWithFields.fields)) {
|
||||
throw new AppError(AppErrorCode.INVALID_REQUEST, {
|
||||
message: 'Recipient has already interacted with the document.',
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.$transaction(async (tx) => {
|
||||
const deletedField = await tx.field.delete({
|
||||
where: {
|
||||
id: fieldToDelete.id,
|
||||
envelopeId: envelope.id,
|
||||
},
|
||||
});
|
||||
|
||||
// Handle field deleted audit log.
|
||||
if (envelope.type === EnvelopeType.DOCUMENT) {
|
||||
await tx.documentAuditLog.create({
|
||||
data: createDocumentAuditLogData({
|
||||
type: DOCUMENT_AUDIT_LOG_TYPE.FIELD_DELETED,
|
||||
envelopeId: envelope.id,
|
||||
metadata,
|
||||
data: {
|
||||
fieldId: deletedField.secondaryId,
|
||||
fieldRecipientEmail: recipientWithFields.email,
|
||||
fieldRecipientId: deletedField.recipientId,
|
||||
fieldType: deletedField.type,
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
return deletedField;
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,10 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZDeleteEnvelopeFieldRequestSchema = z.object({
|
||||
fieldId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteEnvelopeFieldResponseSchema = z.void();
|
||||
|
||||
export type TDeleteEnvelopeFieldRequest = z.infer<typeof ZDeleteEnvelopeFieldRequestSchema>;
|
||||
export type TDeleteEnvelopeFieldResponse = z.infer<typeof ZDeleteEnvelopeFieldResponseSchema>;
|
||||
@ -0,0 +1,36 @@
|
||||
import { getFieldById } from '@documenso/lib/server-only/field/get-field-by-id';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZGetEnvelopeFieldRequestSchema,
|
||||
ZGetEnvelopeFieldResponseSchema,
|
||||
} from './get-envelope-field.types';
|
||||
|
||||
export const getEnvelopeFieldRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/field/{fieldId}',
|
||||
summary: 'Get envelope field',
|
||||
description: 'Returns an envelope field given an ID',
|
||||
tags: ['Envelope Field'],
|
||||
},
|
||||
})
|
||||
.input(ZGetEnvelopeFieldRequestSchema)
|
||||
.output(ZGetEnvelopeFieldResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { fieldId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
fieldId,
|
||||
},
|
||||
});
|
||||
|
||||
return await getFieldById({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
fieldId,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeFieldSchema } from '@documenso/lib/types/field';
|
||||
|
||||
export const ZGetEnvelopeFieldRequestSchema = z.object({
|
||||
fieldId: z.number(),
|
||||
});
|
||||
|
||||
export const ZGetEnvelopeFieldResponseSchema = ZEnvelopeFieldSchema;
|
||||
|
||||
export type TGetEnvelopeFieldRequest = z.infer<typeof ZGetEnvelopeFieldRequestSchema>;
|
||||
export type TGetEnvelopeFieldResponse = z.infer<typeof ZGetEnvelopeFieldResponseSchema>;
|
||||
@ -0,0 +1,42 @@
|
||||
import { updateEnvelopeFields } from '@documenso/lib/server-only/field/update-envelope-fields';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZUpdateEnvelopeFieldsRequestSchema,
|
||||
ZUpdateEnvelopeFieldsResponseSchema,
|
||||
} from './update-envelope-fields.types';
|
||||
|
||||
export const updateEnvelopeFieldsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/field/update-many',
|
||||
summary: 'Update envelope fields',
|
||||
description: 'Update multiple envelope fields for an envelope',
|
||||
tags: ['Envelope Field'],
|
||||
},
|
||||
})
|
||||
.input(ZUpdateEnvelopeFieldsRequestSchema)
|
||||
.output(ZUpdateEnvelopeFieldsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId } = ctx;
|
||||
const { envelopeId, data: fields } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await updateEnvelopeFields({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
type: null,
|
||||
fields,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
ZClampedFieldHeightSchema,
|
||||
ZClampedFieldPageXSchema,
|
||||
ZClampedFieldPageYSchema,
|
||||
ZClampedFieldWidthSchema,
|
||||
ZFieldPageNumberSchema,
|
||||
ZFieldSchema,
|
||||
} from '@documenso/lib/types/field';
|
||||
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
|
||||
const ZUpdateFieldSchema = ZFieldAndMetaSchema.and(
|
||||
z.object({
|
||||
id: z.number().describe('The ID of the field to update.'),
|
||||
envelopeItemId: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe(
|
||||
'The ID of the envelope item to put the field on. If not provided, field will be placed on the first item.',
|
||||
),
|
||||
pageNumber: ZFieldPageNumberSchema.optional(),
|
||||
pageX: ZClampedFieldPageXSchema.optional(),
|
||||
pageY: ZClampedFieldPageYSchema.optional(),
|
||||
width: ZClampedFieldWidthSchema.optional(),
|
||||
height: ZClampedFieldHeightSchema.optional(),
|
||||
}),
|
||||
);
|
||||
|
||||
export const ZUpdateEnvelopeFieldsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZUpdateFieldSchema.array(),
|
||||
});
|
||||
|
||||
export const ZUpdateEnvelopeFieldsResponseSchema = z.object({
|
||||
fields: z.array(ZFieldSchema),
|
||||
});
|
||||
|
||||
export type TUpdateEnvelopeFieldsRequest = z.infer<typeof ZUpdateEnvelopeFieldsRequestSchema>;
|
||||
export type TUpdateEnvelopeFieldsResponse = z.infer<typeof ZUpdateEnvelopeFieldsResponseSchema>;
|
||||
@ -0,0 +1,41 @@
|
||||
import { createEnvelopeRecipients } from '@documenso/lib/server-only/recipient/create-envelope-recipients';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZCreateEnvelopeRecipientsRequestSchema,
|
||||
ZCreateEnvelopeRecipientsResponseSchema,
|
||||
} from './create-envelope-recipients.types';
|
||||
|
||||
export const createEnvelopeRecipientsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/create-many',
|
||||
summary: 'Create envelope recipients',
|
||||
description: 'Create multiple recipients for an envelope',
|
||||
tags: ['Envelope Recipients'],
|
||||
},
|
||||
})
|
||||
.input(ZCreateEnvelopeRecipientsRequestSchema)
|
||||
.output(ZCreateEnvelopeRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { envelopeId, data: recipients } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await createEnvelopeRecipients({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
recipients,
|
||||
requestMetadata: metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
import { ZCreateRecipientSchema } from '../../recipient-router/schema';
|
||||
|
||||
export const ZCreateEnvelopeRecipientsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZCreateRecipientSchema.array(),
|
||||
});
|
||||
|
||||
export const ZCreateEnvelopeRecipientsResponseSchema = z.object({
|
||||
recipients: ZEnvelopeRecipientLiteSchema.array(),
|
||||
});
|
||||
|
||||
export type TCreateEnvelopeRecipientsRequest = z.infer<
|
||||
typeof ZCreateEnvelopeRecipientsRequestSchema
|
||||
>;
|
||||
export type TCreateEnvelopeRecipientsResponse = z.infer<
|
||||
typeof ZCreateEnvelopeRecipientsResponseSchema
|
||||
>;
|
||||
@ -0,0 +1,37 @@
|
||||
import { deleteEnvelopeRecipient } from '@documenso/lib/server-only/recipient/delete-envelope-recipient';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZDeleteEnvelopeRecipientRequestSchema,
|
||||
ZDeleteEnvelopeRecipientResponseSchema,
|
||||
} from './delete-envelope-recipient.types';
|
||||
|
||||
export const deleteEnvelopeRecipientRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/delete',
|
||||
summary: 'Delete envelope recipient',
|
||||
description: 'Delete an envelope recipient',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZDeleteEnvelopeRecipientRequestSchema)
|
||||
.output(ZDeleteEnvelopeRecipientResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId, metadata } = ctx;
|
||||
const { recipientId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
await deleteEnvelopeRecipient({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
recipientId,
|
||||
requestMetadata: metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ZDeleteEnvelopeRecipientRequestSchema = z.object({
|
||||
recipientId: z.number(),
|
||||
});
|
||||
|
||||
export const ZDeleteEnvelopeRecipientResponseSchema = z.void();
|
||||
|
||||
export type TDeleteEnvelopeRecipientRequest = z.infer<typeof ZDeleteEnvelopeRecipientRequestSchema>;
|
||||
export type TDeleteEnvelopeRecipientResponse = z.infer<
|
||||
typeof ZDeleteEnvelopeRecipientResponseSchema
|
||||
>;
|
||||
@ -0,0 +1,52 @@
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { buildTeamWhereQuery } from '@documenso/lib/utils/teams';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZGetEnvelopeRecipientRequestSchema,
|
||||
ZGetEnvelopeRecipientResponseSchema,
|
||||
} from './get-envelope-recipient.types';
|
||||
|
||||
export const getEnvelopeRecipientRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/recipient/{recipientId}',
|
||||
summary: 'Get envelope recipient',
|
||||
description: 'Returns an envelope recipient given an ID',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZGetEnvelopeRecipientRequestSchema)
|
||||
.output(ZGetEnvelopeRecipientResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { teamId, user } = ctx;
|
||||
const { recipientId } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
const recipient = await prisma.recipient.findFirst({
|
||||
where: {
|
||||
id: recipientId,
|
||||
envelope: {
|
||||
team: buildTeamWhereQuery({ teamId, userId: user.id }),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
fields: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!recipient) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Recipient not found',
|
||||
});
|
||||
}
|
||||
|
||||
return recipient;
|
||||
});
|
||||
@ -0,0 +1,12 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeRecipientSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
export const ZGetEnvelopeRecipientRequestSchema = z.object({
|
||||
recipientId: z.number(),
|
||||
});
|
||||
|
||||
export const ZGetEnvelopeRecipientResponseSchema = ZEnvelopeRecipientSchema;
|
||||
|
||||
export type TGetEnvelopeRecipientRequest = z.infer<typeof ZGetEnvelopeRecipientRequestSchema>;
|
||||
export type TGetEnvelopeRecipientResponse = z.infer<typeof ZGetEnvelopeRecipientResponseSchema>;
|
||||
@ -0,0 +1,41 @@
|
||||
import { updateEnvelopeRecipients } from '@documenso/lib/server-only/recipient/update-envelope-recipients';
|
||||
|
||||
import { authenticatedProcedure } from '../../trpc';
|
||||
import {
|
||||
ZUpdateEnvelopeRecipientsRequestSchema,
|
||||
ZUpdateEnvelopeRecipientsResponseSchema,
|
||||
} from './update-envelope-recipients.types';
|
||||
|
||||
export const updateEnvelopeRecipientsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/recipient/update-many',
|
||||
summary: 'Update envelope recipients',
|
||||
description: 'Update multiple recipients for an envelope',
|
||||
tags: ['Envelope Recipient'],
|
||||
},
|
||||
})
|
||||
.input(ZUpdateEnvelopeRecipientsRequestSchema)
|
||||
.output(ZUpdateEnvelopeRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { user, teamId } = ctx;
|
||||
const { envelopeId, data: recipients } = input;
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
envelopeId,
|
||||
},
|
||||
});
|
||||
|
||||
return await updateEnvelopeRecipients({
|
||||
userId: user.id,
|
||||
teamId,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
id: envelopeId,
|
||||
},
|
||||
recipients,
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,21 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { ZRecipientLiteSchema } from '@documenso/lib/types/recipient';
|
||||
|
||||
import { ZUpdateRecipientSchema } from '../../recipient-router/schema';
|
||||
|
||||
export const ZUpdateEnvelopeRecipientsRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
data: ZUpdateRecipientSchema.array(),
|
||||
});
|
||||
|
||||
export const ZUpdateEnvelopeRecipientsResponseSchema = z.object({
|
||||
recipients: ZRecipientLiteSchema.array(),
|
||||
});
|
||||
|
||||
export type TUpdateEnvelopeRecipientsRequest = z.infer<
|
||||
typeof ZUpdateEnvelopeRecipientsRequestSchema
|
||||
>;
|
||||
export type TUpdateEnvelopeRecipientsResponse = z.infer<
|
||||
typeof ZUpdateEnvelopeRecipientsResponseSchema
|
||||
>;
|
||||
@ -4,7 +4,15 @@ import { authenticatedProcedure } from '../trpc';
|
||||
import { ZGetEnvelopeRequestSchema, ZGetEnvelopeResponseSchema } from './get-envelope.types';
|
||||
|
||||
export const getEnvelopeRoute = authenticatedProcedure
|
||||
// .meta(getEnvelopeMeta)
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/envelope/{envelopeId}',
|
||||
summary: 'Get envelope',
|
||||
description: 'Returns an envelope given an ID',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZGetEnvelopeRequestSchema)
|
||||
.output(ZGetEnvelopeResponseSchema)
|
||||
.query(async ({ input, ctx }) => {
|
||||
|
||||
@ -2,16 +2,6 @@ import { z } from 'zod';
|
||||
|
||||
import { ZEnvelopeSchema } from '@documenso/lib/types/envelope';
|
||||
|
||||
// export const getEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'GET',
|
||||
// path: '/envelope/{envelopeId}',
|
||||
// summary: 'Get envelope',
|
||||
// description: 'Returns a envelope given an ID',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZGetEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
});
|
||||
|
||||
@ -7,7 +7,16 @@ import {
|
||||
} from './redistribute-envelope.types';
|
||||
|
||||
export const redistributeEnvelopeRoute = authenticatedProcedure
|
||||
// .meta(redistributeEnvelopeMeta)
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/redistribute',
|
||||
summary: 'Redistribute envelope',
|
||||
description:
|
||||
'Redistribute the envelope to the provided recipients who have not actioned the envelope. Will use the distribution method set in the envelope',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZRedistributeEnvelopeRequestSchema)
|
||||
.output(ZRedistributeEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -1,16 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// export const redistributeEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/redistribute',
|
||||
// summary: 'Redistribute document',
|
||||
// description:
|
||||
// 'Redistribute the document to the provided recipients who have not actioned the document. Will use the distribution method set in the document',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZRedistributeEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
recipients: z
|
||||
|
||||
@ -9,6 +9,14 @@ import { deleteEnvelopeRoute } from './delete-envelope';
|
||||
import { deleteEnvelopeItemRoute } from './delete-envelope-item';
|
||||
import { distributeEnvelopeRoute } from './distribute-envelope';
|
||||
import { duplicateEnvelopeRoute } from './duplicate-envelope';
|
||||
import { createEnvelopeFieldsRoute } from './envelope-fields/create-envelope-fields';
|
||||
import { deleteEnvelopeFieldRoute } from './envelope-fields/delete-envelope-field';
|
||||
import { getEnvelopeFieldRoute } from './envelope-fields/get-envelope-field';
|
||||
import { updateEnvelopeFieldsRoute } from './envelope-fields/update-envelope-fields';
|
||||
import { createEnvelopeRecipientsRoute } from './envelope-recipients/create-envelope-recipients';
|
||||
import { deleteEnvelopeRecipientRoute } from './envelope-recipients/delete-envelope-recipient';
|
||||
import { getEnvelopeRecipientRoute } from './envelope-recipients/get-envelope-recipient';
|
||||
import { updateEnvelopeRecipientsRoute } from './envelope-recipients/update-envelope-recipients';
|
||||
import { getEnvelopeRoute } from './get-envelope';
|
||||
import { getEnvelopeItemsRoute } from './get-envelope-items';
|
||||
import { getEnvelopeItemsByTokenRoute } from './get-envelope-items-by-token';
|
||||
@ -27,8 +35,6 @@ export const envelopeRouter = router({
|
||||
duplicate: duplicateEnvelopeRoute,
|
||||
distribute: distributeEnvelopeRoute,
|
||||
redistribute: redistributeEnvelopeRoute,
|
||||
// share: shareEnvelopeRoute,
|
||||
|
||||
item: {
|
||||
getMany: getEnvelopeItemsRoute,
|
||||
getManyByToken: getEnvelopeItemsByTokenRoute,
|
||||
@ -37,9 +43,17 @@ export const envelopeRouter = router({
|
||||
delete: deleteEnvelopeItemRoute,
|
||||
},
|
||||
recipient: {
|
||||
get: getEnvelopeRecipientRoute,
|
||||
createMany: createEnvelopeRecipientsRoute,
|
||||
updateMany: updateEnvelopeRecipientsRoute,
|
||||
delete: deleteEnvelopeRecipientRoute,
|
||||
set: setEnvelopeRecipientsRoute,
|
||||
},
|
||||
field: {
|
||||
get: getEnvelopeFieldRoute,
|
||||
createMany: createEnvelopeFieldsRoute,
|
||||
updateMany: updateEnvelopeFieldsRoute,
|
||||
delete: deleteEnvelopeFieldRoute,
|
||||
set: setEnvelopeFieldsRoute,
|
||||
sign: signEnvelopeFieldRoute,
|
||||
},
|
||||
|
||||
@ -1,6 +1,12 @@
|
||||
import { EnvelopeType, FieldType } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
ZClampedFieldHeightSchema,
|
||||
ZClampedFieldPageXSchema,
|
||||
ZClampedFieldPageYSchema,
|
||||
ZClampedFieldWidthSchema,
|
||||
} from '@documenso/lib/types/field';
|
||||
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
|
||||
export const ZSetEnvelopeFieldsRequestSchema = z.object({
|
||||
@ -20,28 +26,11 @@ export const ZSetEnvelopeFieldsRequestSchema = z.object({
|
||||
.number()
|
||||
.min(1)
|
||||
.describe('The page number of the field on the envelope. Starts from 1.'),
|
||||
// Todo: Envelopes - Extract these 0-100 schemas with better descriptions.
|
||||
positionX: z
|
||||
.number()
|
||||
.min(0)
|
||||
.max(100)
|
||||
.describe('The percentage based X position of the field on the envelope.'),
|
||||
positionY: z
|
||||
.number()
|
||||
.min(0)
|
||||
.max(100)
|
||||
.describe('The percentage based Y position of the field on the envelope.'),
|
||||
width: z
|
||||
.number()
|
||||
.min(0)
|
||||
.max(100)
|
||||
.describe('The percentage based width of the field on the envelope.'),
|
||||
height: z
|
||||
.number()
|
||||
.min(0)
|
||||
.max(100)
|
||||
.describe('The percentage based height of the field on the envelope.'),
|
||||
fieldMeta: ZFieldMetaSchema, // Todo: Envelopes - Use a more strict form?
|
||||
positionX: ZClampedFieldPageXSchema,
|
||||
positionY: ZClampedFieldPageYSchema,
|
||||
width: ZClampedFieldWidthSchema,
|
||||
height: ZClampedFieldHeightSchema,
|
||||
fieldMeta: ZFieldMetaSchema,
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
@ -10,6 +10,15 @@ import {
|
||||
} from './update-envelope-items.types';
|
||||
|
||||
export const updateEnvelopeItemsRoute = authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/item/update-many',
|
||||
summary: 'Update envelope items',
|
||||
description: 'Update multiple envelope items for an envelope',
|
||||
tags: ['Envelope Item'],
|
||||
},
|
||||
})
|
||||
.input(ZUpdateEnvelopeItemsRequestSchema)
|
||||
.output(ZUpdateEnvelopeItemsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -7,7 +7,14 @@ import {
|
||||
} from './update-envelope.types';
|
||||
|
||||
export const updateEnvelopeRoute = authenticatedProcedure
|
||||
// .meta(updateEnvelopeTrpcMeta)
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/envelope/update',
|
||||
summary: 'Update envelope',
|
||||
tags: ['Envelope'],
|
||||
},
|
||||
})
|
||||
.input(ZUpdateEnvelopeRequestSchema)
|
||||
.output(ZUpdateEnvelopeResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@ -15,15 +15,6 @@ import {
|
||||
ZDocumentVisibilitySchema,
|
||||
} from '../document-router/schema';
|
||||
|
||||
// export const updateEnvelopeMeta: TrpcRouteMeta = {
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/envelope/update',
|
||||
// summary: 'Update envelope',
|
||||
// tags: ['Envelope'],
|
||||
// },
|
||||
// };
|
||||
|
||||
export const ZUpdateEnvelopeRequestSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
envelopeType: z.nativeEnum(EnvelopeType),
|
||||
|
||||
Reference in New Issue
Block a user