mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
fix: remove redundant endpoint (#2170)
Remove duplicate redundant endpoint
This commit is contained in:
@ -1,136 +0,0 @@
|
|||||||
import { EnvelopeType } from '@prisma/client';
|
|
||||||
|
|
||||||
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
|
||||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
||||||
import { createEnvelope } from '@documenso/lib/server-only/envelope/create-envelope';
|
|
||||||
import { putPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
|
||||||
import { mapSecondaryIdToDocumentId } from '@documenso/lib/utils/envelope';
|
|
||||||
import { prisma } from '@documenso/prisma';
|
|
||||||
|
|
||||||
import { authenticatedProcedure } from '../trpc';
|
|
||||||
import {
|
|
||||||
ZCreateDocumentFormDataRequestSchema,
|
|
||||||
ZCreateDocumentFormDataResponseSchema,
|
|
||||||
createDocumentFormDataMeta,
|
|
||||||
} from './create-document-formdata.types';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Temporary endpoint for V2 Beta until we allow passthrough documents on create.
|
|
||||||
*
|
|
||||||
* @public
|
|
||||||
*/
|
|
||||||
export const createDocumentFormDataRoute = authenticatedProcedure
|
|
||||||
.meta(createDocumentFormDataMeta)
|
|
||||||
.input(ZCreateDocumentFormDataRequestSchema)
|
|
||||||
.output(ZCreateDocumentFormDataResponseSchema)
|
|
||||||
.mutation(async ({ input, ctx }) => {
|
|
||||||
const { teamId, user } = ctx;
|
|
||||||
|
|
||||||
const { payload, file } = input;
|
|
||||||
|
|
||||||
const {
|
|
||||||
title,
|
|
||||||
externalId,
|
|
||||||
visibility,
|
|
||||||
globalAccessAuth,
|
|
||||||
globalActionAuth,
|
|
||||||
recipients,
|
|
||||||
meta,
|
|
||||||
folderId,
|
|
||||||
attachments,
|
|
||||||
} = payload;
|
|
||||||
|
|
||||||
const { remaining } = await getServerLimits({ userId: user.id, teamId });
|
|
||||||
|
|
||||||
if (remaining.documents <= 0) {
|
|
||||||
throw new AppError(AppErrorCode.LIMIT_EXCEEDED, {
|
|
||||||
message: 'You have reached your document limit for this month. Please upgrade your plan.',
|
|
||||||
statusCode: 400,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const documentData = await putPdfFileServerSide(file);
|
|
||||||
|
|
||||||
const createdEnvelope = await createEnvelope({
|
|
||||||
userId: ctx.user.id,
|
|
||||||
teamId,
|
|
||||||
normalizePdf: false, // Not normalizing because of presigned URL.
|
|
||||||
internalVersion: 1,
|
|
||||||
data: {
|
|
||||||
type: EnvelopeType.DOCUMENT,
|
|
||||||
title,
|
|
||||||
externalId,
|
|
||||||
visibility,
|
|
||||||
globalAccessAuth,
|
|
||||||
globalActionAuth,
|
|
||||||
recipients: (recipients || []).map((recipient) => ({
|
|
||||||
...recipient,
|
|
||||||
fields: (recipient.fields || []).map((field) => ({
|
|
||||||
...field,
|
|
||||||
page: field.pageNumber,
|
|
||||||
positionX: field.pageX,
|
|
||||||
positionY: field.pageY,
|
|
||||||
documentDataId: documentData.id,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
folderId,
|
|
||||||
envelopeItems: [
|
|
||||||
{
|
|
||||||
// If you ever allow more than 1 in this endpoint, make sure to use `maximumEnvelopeItemCount` to limit it.
|
|
||||||
documentDataId: documentData.id,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
attachments,
|
|
||||||
meta: {
|
|
||||||
...meta,
|
|
||||||
emailSettings: meta?.emailSettings ?? undefined,
|
|
||||||
},
|
|
||||||
requestMetadata: ctx.metadata,
|
|
||||||
});
|
|
||||||
|
|
||||||
const envelopeItems = await prisma.envelopeItem.findMany({
|
|
||||||
where: {
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
documentData: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const legacyDocumentId = mapSecondaryIdToDocumentId(createdEnvelope.secondaryId);
|
|
||||||
|
|
||||||
const firstDocumentData = envelopeItems[0].documentData;
|
|
||||||
|
|
||||||
if (!firstDocumentData) {
|
|
||||||
throw new Error('Document data not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
document: {
|
|
||||||
...createdEnvelope,
|
|
||||||
envelopeId: createdEnvelope.id,
|
|
||||||
documentDataId: firstDocumentData.id,
|
|
||||||
documentData: {
|
|
||||||
...firstDocumentData,
|
|
||||||
envelopeItemId: envelopeItems[0].id,
|
|
||||||
},
|
|
||||||
documentMeta: {
|
|
||||||
...createdEnvelope.documentMeta,
|
|
||||||
documentId: legacyDocumentId,
|
|
||||||
},
|
|
||||||
id: legacyDocumentId,
|
|
||||||
fields: createdEnvelope.fields.map((field) => ({
|
|
||||||
...field,
|
|
||||||
documentId: legacyDocumentId,
|
|
||||||
templateId: null,
|
|
||||||
})),
|
|
||||||
recipients: createdEnvelope.recipients.map((recipient) => ({
|
|
||||||
...recipient,
|
|
||||||
documentId: legacyDocumentId,
|
|
||||||
templateId: null,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
folder: createdEnvelope.folder, // Todo: Remove this prior to api-v2 release.
|
|
||||||
};
|
|
||||||
});
|
|
||||||
@ -1,97 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
import { zfd } from 'zod-form-data';
|
|
||||||
|
|
||||||
import { ZDocumentSchema } from '@documenso/lib/types/document';
|
|
||||||
import {
|
|
||||||
ZDocumentAccessAuthTypesSchema,
|
|
||||||
ZDocumentActionAuthTypesSchema,
|
|
||||||
} from '@documenso/lib/types/document-auth';
|
|
||||||
import { ZDocumentFormValuesSchema } from '@documenso/lib/types/document-form-values';
|
|
||||||
import { ZDocumentMetaCreateSchema } from '@documenso/lib/types/document-meta';
|
|
||||||
import { ZEnvelopeAttachmentTypeSchema } from '@documenso/lib/types/envelope-attachment';
|
|
||||||
import {
|
|
||||||
ZFieldHeightSchema,
|
|
||||||
ZFieldPageNumberSchema,
|
|
||||||
ZFieldPageXSchema,
|
|
||||||
ZFieldPageYSchema,
|
|
||||||
ZFieldWidthSchema,
|
|
||||||
} from '@documenso/lib/types/field';
|
|
||||||
import { ZFieldAndMetaSchema } from '@documenso/lib/types/field-meta';
|
|
||||||
|
|
||||||
import { zodFormData } from '../../utils/zod-form-data';
|
|
||||||
import { ZCreateRecipientSchema } from '../recipient-router/schema';
|
|
||||||
import type { TrpcRouteMeta } from '../trpc';
|
|
||||||
import {
|
|
||||||
ZDocumentExternalIdSchema,
|
|
||||||
ZDocumentTitleSchema,
|
|
||||||
ZDocumentVisibilitySchema,
|
|
||||||
} from './schema';
|
|
||||||
|
|
||||||
export const createDocumentFormDataMeta: TrpcRouteMeta = {
|
|
||||||
openapi: {
|
|
||||||
method: 'POST',
|
|
||||||
path: '/document/create/formdata',
|
|
||||||
contentTypes: ['multipart/form-data'],
|
|
||||||
summary: 'Create document',
|
|
||||||
description: 'Create a document using form data.',
|
|
||||||
tags: ['Document'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const ZCreateDocumentFormDataPayloadRequestSchema = z.object({
|
|
||||||
title: ZDocumentTitleSchema,
|
|
||||||
externalId: ZDocumentExternalIdSchema.optional(),
|
|
||||||
visibility: ZDocumentVisibilitySchema.optional(),
|
|
||||||
globalAccessAuth: z.array(ZDocumentAccessAuthTypesSchema).optional(),
|
|
||||||
globalActionAuth: z.array(ZDocumentActionAuthTypesSchema).optional(),
|
|
||||||
formValues: ZDocumentFormValuesSchema.optional(),
|
|
||||||
folderId: z
|
|
||||||
.string()
|
|
||||||
.describe(
|
|
||||||
'The ID of the folder to create the document in. If not provided, the document will be created in the root folder.',
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
recipients: z
|
|
||||||
.array(
|
|
||||||
ZCreateRecipientSchema.extend({
|
|
||||||
fields: ZFieldAndMetaSchema.and(
|
|
||||||
z.object({
|
|
||||||
pageNumber: ZFieldPageNumberSchema,
|
|
||||||
pageX: ZFieldPageXSchema,
|
|
||||||
pageY: ZFieldPageYSchema,
|
|
||||||
width: ZFieldWidthSchema,
|
|
||||||
height: ZFieldHeightSchema,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.array()
|
|
||||||
.optional(),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
.optional(),
|
|
||||||
attachments: z
|
|
||||||
.array(
|
|
||||||
z.object({
|
|
||||||
label: z.string().min(1, 'Label is required'),
|
|
||||||
data: z.string().url('Must be a valid URL'),
|
|
||||||
type: ZEnvelopeAttachmentTypeSchema.optional().default('link'),
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.optional(),
|
|
||||||
meta: ZDocumentMetaCreateSchema.optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// !: Can't use zfd.formData() here because it receives `undefined`
|
|
||||||
// !: somewhere in the pipeline of our openapi schema generation and throws
|
|
||||||
// !: an error.
|
|
||||||
export const ZCreateDocumentFormDataRequestSchema = zodFormData({
|
|
||||||
payload: zfd.json(ZCreateDocumentFormDataPayloadRequestSchema),
|
|
||||||
file: zfd.file(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const ZCreateDocumentFormDataResponseSchema = z.object({
|
|
||||||
document: ZDocumentSchema,
|
|
||||||
});
|
|
||||||
|
|
||||||
export type TCreateDocumentFormDataRequest = z.infer<typeof ZCreateDocumentFormDataRequestSchema>;
|
|
||||||
export type TCreateDocumentFormDataResponse = z.infer<typeof ZCreateDocumentFormDataResponseSchema>;
|
|
||||||
@ -5,7 +5,6 @@ import { deleteAttachmentRoute } from './attachment/delete-attachment';
|
|||||||
import { findAttachmentsRoute } from './attachment/find-attachments';
|
import { findAttachmentsRoute } from './attachment/find-attachments';
|
||||||
import { updateAttachmentRoute } from './attachment/update-attachment';
|
import { updateAttachmentRoute } from './attachment/update-attachment';
|
||||||
import { createDocumentRoute } from './create-document';
|
import { createDocumentRoute } from './create-document';
|
||||||
import { createDocumentFormDataRoute } from './create-document-formdata';
|
|
||||||
import { createDocumentTemporaryRoute } from './create-document-temporary';
|
import { createDocumentTemporaryRoute } from './create-document-temporary';
|
||||||
import { deleteDocumentRoute } from './delete-document';
|
import { deleteDocumentRoute } from './delete-document';
|
||||||
import { distributeDocumentRoute } from './distribute-document';
|
import { distributeDocumentRoute } from './distribute-document';
|
||||||
@ -39,11 +38,11 @@ export const documentRouter = router({
|
|||||||
search: searchDocumentRoute,
|
search: searchDocumentRoute,
|
||||||
share: shareDocumentRoute,
|
share: shareDocumentRoute,
|
||||||
|
|
||||||
// Temporary v2 beta routes to be removed once V2 is fully released.
|
|
||||||
downloadBeta: downloadDocumentBetaRoute,
|
|
||||||
download: downloadDocumentRoute,
|
download: downloadDocumentRoute,
|
||||||
|
|
||||||
|
// Deprecated endpoints which need to be removed in the future.
|
||||||
|
downloadBeta: downloadDocumentBetaRoute,
|
||||||
createDocumentTemporary: createDocumentTemporaryRoute,
|
createDocumentTemporary: createDocumentTemporaryRoute,
|
||||||
createDocumentFormData: createDocumentFormDataRoute,
|
|
||||||
|
|
||||||
// Internal document routes for custom frontend requests.
|
// Internal document routes for custom frontend requests.
|
||||||
getDocumentByToken: getDocumentByTokenRoute,
|
getDocumentByToken: getDocumentByTokenRoute,
|
||||||
|
|||||||
Reference in New Issue
Block a user