mirror of
https://github.com/documenso/documenso.git
synced 2026-07-26 18:04:55 +10:00
fix: bump trpc and openapi packages (#1591)
This commit is contained in:
@@ -106,14 +106,6 @@ export const adminRouter = router({
|
||||
deleteUser: adminProcedure.input(ZAdminDeleteUserMutationSchema).mutation(async ({ input }) => {
|
||||
const { id } = input;
|
||||
|
||||
const user = await getUserById({ id }).catch(() => null);
|
||||
|
||||
if (!user) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'User not found',
|
||||
});
|
||||
}
|
||||
|
||||
return await deleteUser({ id });
|
||||
}),
|
||||
|
||||
|
||||
@@ -10,7 +10,11 @@ type CreateTrpcContext = CreateNextContextOptions & {
|
||||
requestSource: 'apiV1' | 'apiV2' | 'app';
|
||||
};
|
||||
|
||||
export const createTrpcContext = async ({ req, res, requestSource }: CreateTrpcContext) => {
|
||||
export const createTrpcContext = async ({
|
||||
req,
|
||||
res,
|
||||
requestSource,
|
||||
}: Omit<CreateTrpcContext, 'info'>) => {
|
||||
const { session, user } = await getServerSession({ req, res });
|
||||
|
||||
const metadata: ApiRequestMetadata = {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { z } from 'zod';
|
||||
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
import { DOCUMENSO_ENCRYPTION_KEY } from '@documenso/lib/constants/crypto';
|
||||
import { AppError } from '@documenso/lib/errors/app-error';
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import { encryptSecondaryData } from '@documenso/lib/server-only/crypto/encrypt';
|
||||
import { createDocumentData } from '@documenso/lib/server-only/document-data/create-document-data';
|
||||
import { upsertDocumentMeta } from '@documenso/lib/server-only/document-meta/upsert-document-meta';
|
||||
@@ -186,9 +186,9 @@ export const documentRouter = router({
|
||||
const { remaining } = await getServerLimits({ email: ctx.user.email, teamId });
|
||||
|
||||
if (remaining.documents <= 0) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
throw new AppError(AppErrorCode.LIMIT_EXCEEDED, {
|
||||
message: 'You have reached your document limit for this month. Please upgrade your plan.',
|
||||
statusCode: 400,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -246,9 +246,9 @@ export const documentRouter = router({
|
||||
const { remaining } = await getServerLimits({ email: ctx.user.email, teamId });
|
||||
|
||||
if (remaining.documents <= 0) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
throw new AppError(AppErrorCode.LIMIT_EXCEEDED, {
|
||||
message: 'You have reached your document limit for this month. Please upgrade your plan.',
|
||||
statusCode: 400,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -219,14 +219,6 @@ export const fieldRouter = router({
|
||||
* Todo: Refactor to setFieldsForDocument function.
|
||||
*/
|
||||
addFields: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/document/{documentId}/field',
|
||||
// summary: 'Set document fields',
|
||||
// tags: ['Document Fields'],
|
||||
// },
|
||||
// })
|
||||
.input(ZSetDocumentFieldsRequestSchema)
|
||||
.output(ZSetDocumentFieldsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
@@ -395,14 +387,6 @@ export const fieldRouter = router({
|
||||
* Todo: Refactor to setFieldsForTemplate.
|
||||
*/
|
||||
addTemplateFields: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/template/{templateId}/field',
|
||||
// summary: 'Set template fields',
|
||||
// tags: ['Template Fields'],
|
||||
// },
|
||||
// })
|
||||
.input(ZSetFieldsForTemplateRequestSchema)
|
||||
.output(ZSetFieldsForTemplateResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { generateOpenApiDocument } from 'trpc-openapi';
|
||||
import { generateOpenApiDocument } from 'trpc-to-openapi';
|
||||
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
|
||||
|
||||
@@ -217,16 +217,6 @@ export const recipientRouter = router({
|
||||
* @private
|
||||
*/
|
||||
setDocumentRecipients: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/document/recipient/set',
|
||||
// summary: 'Set document recipients',
|
||||
// description:
|
||||
// 'This will replace all recipients attached to the document. If the array contains existing recipients, they will be updated and the original fields will be retained.',
|
||||
// tags: ['Document Recipients'],
|
||||
// },
|
||||
// })
|
||||
.input(ZSetDocumentRecipientsRequestSchema)
|
||||
.output(ZSetDocumentRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
@@ -390,16 +380,6 @@ export const recipientRouter = router({
|
||||
* @private
|
||||
*/
|
||||
setTemplateRecipients: authenticatedProcedure
|
||||
// .meta({
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/template/recipient/set',
|
||||
// summary: 'Set template recipients',
|
||||
// description:
|
||||
// 'This will replace all recipients attached to the template. If the array contains existing recipients, they will be updated and the original fields will be retained.',
|
||||
// tags: ['Template Recipients'],
|
||||
// },
|
||||
// })
|
||||
.input(ZSetTemplateRecipientsRequestSchema)
|
||||
.output(ZSetTemplateRecipientsResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
|
||||
@@ -91,7 +91,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamsQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeams({
|
||||
userId: ctx.user.id,
|
||||
@@ -110,7 +109,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamById({ teamId: input.teamId, userId: ctx.user.id });
|
||||
}),
|
||||
@@ -126,7 +124,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeam({
|
||||
userId: ctx.user.id,
|
||||
@@ -145,7 +142,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeam({
|
||||
userId: ctx.user.id,
|
||||
@@ -164,7 +160,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeam({
|
||||
userId: ctx.user.id,
|
||||
@@ -184,7 +179,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZLeaveTeamMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await leaveTeam({
|
||||
userId: ctx.user.id,
|
||||
@@ -204,7 +198,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMemberInvitesQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
@@ -224,7 +217,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZCreateTeamMemberInvitesMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await createTeamMemberInvites({
|
||||
userId: ctx.user.id,
|
||||
@@ -245,7 +237,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZResendTeamMemberInvitationMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
await resendTeamMemberInvitation({
|
||||
userId: ctx.user.id,
|
||||
@@ -266,7 +257,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMemberInvitationsMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMemberInvitations({
|
||||
userId: ctx.user.id,
|
||||
@@ -285,7 +275,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZGetTeamMembersQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await getTeamMembers({ teamId: input.teamId, userId: ctx.user.id });
|
||||
}),
|
||||
@@ -302,7 +291,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZFindTeamMembersQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
return await findTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
@@ -321,7 +309,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamMemberMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await updateTeamMember({
|
||||
userId: ctx.user.id,
|
||||
@@ -341,7 +328,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZDeleteTeamMembersMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
return await deleteTeamMembers({
|
||||
userId: ctx.user.id,
|
||||
@@ -400,7 +386,6 @@ export const teamRouter = router({
|
||||
// },
|
||||
// })
|
||||
.input(ZUpdateTeamPublicProfileMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
try {
|
||||
const { teamId, bio, enabled } = input;
|
||||
|
||||
@@ -369,7 +369,7 @@ export const templateRouter = router({
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/template/{templateId}/direct/toggle',
|
||||
path: '/template/direct/toggle',
|
||||
summary: 'Toggle direct link',
|
||||
description: 'Enable or disable a direct link for a template',
|
||||
tags: ['Template'],
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { TRPCError, initTRPC } from '@trpc/server';
|
||||
import SuperJSON from 'superjson';
|
||||
import type { OpenApiMeta } from 'trpc-openapi';
|
||||
import type { AnyZodObject } from 'zod';
|
||||
|
||||
import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error';
|
||||
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
|
||||
@@ -10,6 +10,26 @@ import { extractNextApiRequestMetadata } from '@documenso/lib/universal/extract-
|
||||
|
||||
import type { TrpcContext } from './context';
|
||||
|
||||
// Can't import type from trpc-to-openapi because it breaks nextjs build, not sure why.
|
||||
type OpenApiMeta = {
|
||||
openapi?: {
|
||||
enabled?: boolean;
|
||||
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
|
||||
path: `/${string}`;
|
||||
summary?: string;
|
||||
description?: string;
|
||||
protect?: boolean;
|
||||
tags?: string[];
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
contentTypes?: ('application/json' | 'application/x-www-form-urlencoded' | (string & {}))[];
|
||||
deprecated?: boolean;
|
||||
requestHeaders?: AnyZodObject;
|
||||
responseHeaders?: AnyZodObject;
|
||||
successDescription?: string;
|
||||
errorResponses?: number[] | Record<number, string>;
|
||||
};
|
||||
} & Record<string, unknown>;
|
||||
|
||||
const t = initTRPC
|
||||
.meta<OpenApiMeta>()
|
||||
.context<TrpcContext>()
|
||||
|
||||
Reference in New Issue
Block a user