mirror of
https://github.com/documenso/documenso.git
synced 2026-07-14 14:57:12 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
import { API_V2_BETA_URL, API_V2_URL } from '@documenso/lib/constants/app';
|
|
import { AppError, genericErrorCodeToTrpcErrorCodeMap } from '@documenso/lib/errors/app-error';
|
|
import { createTrpcContext } from '@documenso/trpc/server/context';
|
|
import { appRouter } from '@documenso/trpc/server/router';
|
|
import { createOpenApiFetchHandler } from '@documenso/trpc/utils/openapi-fetch-handler';
|
|
import { handleTrpcRouterError } from '@documenso/trpc/utils/trpc-error-handler';
|
|
import type { Context } from 'hono';
|
|
|
|
type OpenApiTrpcServerHandlerOptions = {
|
|
isBeta: boolean;
|
|
};
|
|
|
|
export const openApiTrpcServerHandler = async (c: Context, { isBeta }: OpenApiTrpcServerHandlerOptions) => {
|
|
return createOpenApiFetchHandler<typeof appRouter>({
|
|
endpoint: isBeta ? API_V2_BETA_URL : API_V2_URL,
|
|
router: appRouter,
|
|
createContext: async () => createTrpcContext({ c, requestSource: 'apiV2' }),
|
|
req: c.req.raw,
|
|
onError: (opts) => handleTrpcRouterError(opts, 'apiV2'),
|
|
// Not sure why we need to do this since we handle it in errorFormatter which runs after this.
|
|
responseMeta: (opts) => {
|
|
if (opts.errors[0]?.cause instanceof AppError) {
|
|
const appError = AppError.parseError(opts.errors[0].cause);
|
|
|
|
const httpStatus = genericErrorCodeToTrpcErrorCodeMap[appError.code]?.status ?? 400;
|
|
|
|
return {
|
|
status: httpStatus,
|
|
};
|
|
}
|
|
|
|
return {};
|
|
},
|
|
});
|
|
};
|