Files
documenso/packages/trpc/server/webhook-router/resend-webhook-call.ts
T
Lucas Smith 960217c78d build: migrate from npm to pnpm with workspace catalogs
- Switch package manager to pnpm 10 via corepack
- Add pnpm-workspace.yaml with 54+ shared dependency catalogs
- Convert all workspace packages to catalog: and workspace:* protocols
- Upgrade Turborepo from 1.x to 2.8.12 (pipeline -> tasks)
- Upgrade apps/openpage-api from Next 15 to Next 16
- Update Docker, CI workflows, and GitHub Actions for pnpm
- Convert patch file to pnpm native format
- Replace deprecated next lint with standalone eslint
- Update all documentation references from npm to pnpm
- Fix stale dependabot config and documentation paths
2026-03-06 14:28:12 +11:00

80 lines
2.2 KiB
TypeScript

import { Prisma, WebhookCallStatus } from '@prisma/client';
import { TEAM_MEMBER_ROLE_PERMISSIONS_MAP } from '@documenso/lib/constants/teams';
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 {
ZResendWebhookCallRequestSchema,
ZResendWebhookCallResponseSchema,
} from './resend-webhook-call.types';
export const resendWebhookCallRoute = authenticatedProcedure
.input(ZResendWebhookCallRequestSchema)
.output(ZResendWebhookCallResponseSchema)
.mutation(async ({ input, ctx }) => {
const { teamId, user } = ctx;
const { webhookId, webhookCallId } = input;
ctx.logger.info({
input: { webhookId, webhookCallId },
});
const webhookCall = await prisma.webhookCall.findFirst({
where: {
id: webhookCallId,
webhook: {
id: webhookId,
team: buildTeamWhereQuery({
teamId,
userId: user.id,
roles: TEAM_MEMBER_ROLE_PERMISSIONS_MAP.MANAGE_TEAM,
}),
},
},
include: {
webhook: true,
},
});
if (!webhookCall) {
throw new AppError(AppErrorCode.NOT_FOUND);
}
const { webhook } = webhookCall;
// Note: This is duplicated in `execute-webhook.handler.ts`.
const response = await fetch(webhookCall.url, {
method: 'POST',
body: JSON.stringify(webhookCall.requestBody),
headers: {
'Content-Type': 'application/json',
'X-Documenso-Secret': webhook.secret ?? '',
},
});
const body = await response.text();
let responseBody: Prisma.InputJsonValue | Prisma.JsonNullValueInput = Prisma.JsonNull;
try {
responseBody = JSON.parse(body);
} catch (err) {
responseBody = body;
}
return await prisma.webhookCall.update({
where: {
id: webhookCall.id,
},
data: {
status: response.ok ? WebhookCallStatus.SUCCESS : WebhookCallStatus.FAILED,
responseCode: response.status,
responseBody,
responseHeaders: Object.fromEntries(response.headers.entries()),
},
});
});