fix: redirect v2 beta url

This commit is contained in:
David Nguyen
2025-11-04 11:55:07 +11:00
parent bbf1dd3c6b
commit c89ca83f44
17 changed files with 31 additions and 23 deletions

View File

@ -8,7 +8,7 @@ import type { Logger } from 'pino';
import { tsRestHonoApp } from '@documenso/api/hono'; import { tsRestHonoApp } from '@documenso/api/hono';
import { auth } from '@documenso/auth/server'; import { auth } from '@documenso/auth/server';
import { API_V2_BETA_URL } from '@documenso/lib/constants/app'; import { API_V2_BETA_URL, API_V2_URL } from '@documenso/lib/constants/app';
import { jobsClient } from '@documenso/lib/jobs/client'; import { jobsClient } from '@documenso/lib/jobs/client';
import { getIpAddress } from '@documenso/lib/universal/get-ip-address'; import { getIpAddress } from '@documenso/lib/universal/get-ip-address';
import { logger } from '@documenso/lib/utils/logger'; import { logger } from '@documenso/lib/utils/logger';
@ -90,8 +90,14 @@ app.use('/api/jobs/*', jobsClient.getApiHandler());
app.use('/api/trpc/*', reactRouterTrpcServer); app.use('/api/trpc/*', reactRouterTrpcServer);
// Unstable API server routes. Order matters for these two. // Unstable API server routes. Order matters for these two.
app.get(`${API_V2_BETA_URL}/openapi.json`, (c) => c.json(openApiDocument)); app.get(`${API_V2_URL}/openapi.json`, (c) => c.json(openApiDocument));
app.use(`${API_V2_BETA_URL}/*`, cors()); app.use(`${API_V2_URL}/*`, cors());
app.use(`${API_V2_BETA_URL}/*`, async (c) => openApiTrpcServerHandler(c)); app.use(`${API_V2_URL}/*`, async (c) => openApiTrpcServerHandler(c));
// Redirect /api/v2-beta to /api/v2.
app.all('/api/v2-beta/*', (c) => {
const newPath = c.req.path.replace(API_V2_BETA_URL, API_V2_URL);
return c.redirect(newPath, 301);
});
export default app; export default app;

View File

@ -1,6 +1,6 @@
import type { Context } from 'hono'; import type { Context } from 'hono';
import { API_V2_BETA_URL } from '@documenso/lib/constants/app'; import { API_V2_URL } from '@documenso/lib/constants/app';
import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error'; import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error';
import { createTrpcContext } from '@documenso/trpc/server/context'; import { createTrpcContext } from '@documenso/trpc/server/context';
import { appRouter } from '@documenso/trpc/server/router'; import { appRouter } from '@documenso/trpc/server/router';
@ -9,7 +9,7 @@ import { handleTrpcRouterError } from '@documenso/trpc/utils/trpc-error-handler'
export const openApiTrpcServerHandler = async (c: Context) => { export const openApiTrpcServerHandler = async (c: Context) => {
return createOpenApiFetchHandler<typeof appRouter>({ return createOpenApiFetchHandler<typeof appRouter>({
endpoint: API_V2_BETA_URL, endpoint: API_V2_URL,
router: appRouter, router: appRouter,
createContext: async () => createTrpcContext({ c, requestSource: 'apiV2' }), createContext: async () => createTrpcContext({ c, requestSource: 'apiV2' }),
req: c.req.raw, req: c.req.raw,

View File

@ -12,6 +12,7 @@ export const NEXT_PRIVATE_INTERNAL_WEBAPP_URL =
export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED') === 'true'; export const IS_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED') === 'true';
export const API_V2_BETA_URL = '/api/v2-beta'; export const API_V2_BETA_URL = '/api/v2-beta';
export const API_V2_URL = '/api/v2';
export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com'; export const SUPPORT_EMAIL = env('NEXT_PUBLIC_SUPPORT_EMAIL') ?? 'support@documenso.com';

View File

@ -13,7 +13,7 @@ export const createAttachmentRoute = authenticatedProcedure
path: '/envelope/attachment/create', path: '/envelope/attachment/create',
summary: 'Create attachment', summary: 'Create attachment',
description: 'Create a new attachment for an envelope', description: 'Create a new attachment for an envelope',
tags: ['Envelope Attachment'], tags: ['Envelope Attachments'],
}, },
}) })
.input(ZCreateAttachmentRequestSchema) .input(ZCreateAttachmentRequestSchema)

View File

@ -13,7 +13,7 @@ export const deleteAttachmentRoute = authenticatedProcedure
path: '/envelope/attachment/delete', path: '/envelope/attachment/delete',
summary: 'Delete attachment', summary: 'Delete attachment',
description: 'Delete an attachment from an envelope', description: 'Delete an attachment from an envelope',
tags: ['Envelope Attachment'], tags: ['Envelope Attachments'],
}, },
}) })
.input(ZDeleteAttachmentRequestSchema) .input(ZDeleteAttachmentRequestSchema)

View File

@ -15,7 +15,7 @@ export const findAttachmentsRoute = maybeAuthenticatedProcedure
path: '/envelope/attachment', path: '/envelope/attachment',
summary: 'Find attachments', summary: 'Find attachments',
description: 'Find all attachments for an envelope', description: 'Find all attachments for an envelope',
tags: ['Envelope Attachment'], tags: ['Envelope Attachments'],
}, },
}) })
.input(ZFindAttachmentsRequestSchema) .input(ZFindAttachmentsRequestSchema)

View File

@ -13,7 +13,7 @@ export const updateAttachmentRoute = authenticatedProcedure
path: '/envelope/attachment/update', path: '/envelope/attachment/update',
summary: 'Update attachment', summary: 'Update attachment',
description: 'Update an existing attachment', description: 'Update an existing attachment',
tags: ['Envelope Attachment'], tags: ['Envelope Attachments'],
}, },
}) })
.input(ZUpdateAttachmentRequestSchema) .input(ZUpdateAttachmentRequestSchema)

View File

@ -20,7 +20,7 @@ export const createEnvelopeItemsRoute = authenticatedProcedure
path: '/envelope/item/create-many', path: '/envelope/item/create-many',
summary: 'Create envelope items', summary: 'Create envelope items',
description: 'Create multiple envelope items for an envelope', description: 'Create multiple envelope items for an envelope',
tags: ['Envelope Item'], tags: ['Envelope Items'],
}, },
}) })
.input(ZCreateEnvelopeItemsRequestSchema) .input(ZCreateEnvelopeItemsRequestSchema)

View File

@ -18,7 +18,7 @@ export const deleteEnvelopeItemRoute = authenticatedProcedure
path: '/envelope/item/delete', path: '/envelope/item/delete',
summary: 'Delete envelope item', summary: 'Delete envelope item',
description: 'Delete an envelope item from an envelope', description: 'Delete an envelope item from an envelope',
tags: ['Envelope Item'], tags: ['Envelope Items'],
}, },
}) })
.input(ZDeleteEnvelopeItemRequestSchema) .input(ZDeleteEnvelopeItemRequestSchema)

View File

@ -20,7 +20,7 @@ export const deleteEnvelopeFieldRoute = authenticatedProcedure
path: '/envelope/field/delete', path: '/envelope/field/delete',
summary: 'Delete envelope field', summary: 'Delete envelope field',
description: 'Delete an envelope field', description: 'Delete an envelope field',
tags: ['Envelope Field'], tags: ['Envelope Fields'],
}, },
}) })
.input(ZDeleteEnvelopeFieldRequestSchema) .input(ZDeleteEnvelopeFieldRequestSchema)

View File

@ -13,7 +13,7 @@ export const getEnvelopeFieldRoute = authenticatedProcedure
path: '/envelope/field/{fieldId}', path: '/envelope/field/{fieldId}',
summary: 'Get envelope field', summary: 'Get envelope field',
description: 'Returns an envelope field given an ID', description: 'Returns an envelope field given an ID',
tags: ['Envelope Field'], tags: ['Envelope Fields'],
}, },
}) })
.input(ZGetEnvelopeFieldRequestSchema) .input(ZGetEnvelopeFieldRequestSchema)

View File

@ -13,7 +13,7 @@ export const updateEnvelopeFieldsRoute = authenticatedProcedure
path: '/envelope/field/update-many', path: '/envelope/field/update-many',
summary: 'Update envelope fields', summary: 'Update envelope fields',
description: 'Update multiple envelope fields for an envelope', description: 'Update multiple envelope fields for an envelope',
tags: ['Envelope Field'], tags: ['Envelope Fields'],
}, },
}) })
.input(ZUpdateEnvelopeFieldsRequestSchema) .input(ZUpdateEnvelopeFieldsRequestSchema)

View File

@ -13,7 +13,7 @@ export const deleteEnvelopeRecipientRoute = authenticatedProcedure
path: '/envelope/recipient/delete', path: '/envelope/recipient/delete',
summary: 'Delete envelope recipient', summary: 'Delete envelope recipient',
description: 'Delete an envelope recipient', description: 'Delete an envelope recipient',
tags: ['Envelope Recipient'], tags: ['Envelope Recipients'],
}, },
}) })
.input(ZDeleteEnvelopeRecipientRequestSchema) .input(ZDeleteEnvelopeRecipientRequestSchema)

View File

@ -15,7 +15,7 @@ export const getEnvelopeRecipientRoute = authenticatedProcedure
path: '/envelope/recipient/{recipientId}', path: '/envelope/recipient/{recipientId}',
summary: 'Get envelope recipient', summary: 'Get envelope recipient',
description: 'Returns an envelope recipient given an ID', description: 'Returns an envelope recipient given an ID',
tags: ['Envelope Recipient'], tags: ['Envelope Recipients'],
}, },
}) })
.input(ZGetEnvelopeRecipientRequestSchema) .input(ZGetEnvelopeRecipientRequestSchema)

View File

@ -13,7 +13,7 @@ export const updateEnvelopeRecipientsRoute = authenticatedProcedure
path: '/envelope/recipient/update-many', path: '/envelope/recipient/update-many',
summary: 'Update envelope recipients', summary: 'Update envelope recipients',
description: 'Update multiple recipients for an envelope', description: 'Update multiple recipients for an envelope',
tags: ['Envelope Recipient'], tags: ['Envelope Recipients'],
}, },
}) })
.input(ZUpdateEnvelopeRecipientsRequestSchema) .input(ZUpdateEnvelopeRecipientsRequestSchema)

View File

@ -16,7 +16,7 @@ export const updateEnvelopeItemsRoute = authenticatedProcedure
path: '/envelope/item/update-many', path: '/envelope/item/update-many',
summary: 'Update envelope items', summary: 'Update envelope items',
description: 'Update multiple envelope items for an envelope', description: 'Update multiple envelope items for an envelope',
tags: ['Envelope Item'], tags: ['Envelope Items'],
}, },
}) })
.input(ZUpdateEnvelopeItemsRequestSchema) .input(ZUpdateEnvelopeItemsRequestSchema)

View File

@ -6,10 +6,11 @@ import { appRouter } from './router';
export const openApiDocument = { export const openApiDocument = {
...generateOpenApiDocument(appRouter, { ...generateOpenApiDocument(appRouter, {
title: 'Documenso v2 beta API', title: 'Documenso v2 API',
description: 'Subject to breaking changes until v2 is fully released.', description:
version: '0.0.0', 'Welcome to the Documenso v2 API.\n\nThis API provides access to our system, which you can use to integrate applications, automate workflows, or build custom tools.',
baseUrl: `${NEXT_PUBLIC_WEBAPP_URL()}/api/v2-beta`, version: '1.0.0',
baseUrl: `${NEXT_PUBLIC_WEBAPP_URL()}/api/v2`,
securitySchemes: { securitySchemes: {
apiKey: { apiKey: {
type: 'apiKey', type: 'apiKey',