mirror of
https://github.com/documenso/documenso.git
synced 2026-10-03 10:13:52 +10:00
Disable autocapture and person profiles for anonymous users, and redact signing tokens from captured URLs. Manually wire exception capture into the signing, editor and embed flows with recipient/envelope context for debugging recipient-reported issues. Track activation events (webhooks, api tokens, direct links, embed sessions) server-side with org attribution, and drop client events already tracked in-app.
137 lines
3.5 KiB
TypeScript
137 lines
3.5 KiB
TypeScript
import { captureServerEvent } from '@documenso/lib/server-only/analytics/capture-server-event';
|
|
import { createWebhook } from '@documenso/lib/server-only/webhooks/create-webhook';
|
|
import { deleteWebhookById } from '@documenso/lib/server-only/webhooks/delete-webhook-by-id';
|
|
import { editWebhook } from '@documenso/lib/server-only/webhooks/edit-webhook';
|
|
import { getWebhookById } from '@documenso/lib/server-only/webhooks/get-webhook-by-id';
|
|
import { getWebhooksByTeamId } from '@documenso/lib/server-only/webhooks/get-webhooks-by-team-id';
|
|
import { triggerTestWebhook } from '@documenso/lib/server-only/webhooks/trigger-test-webhook';
|
|
import { fireAndForget } from '@documenso/lib/universal/fire-and-forget';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { authenticatedProcedure, router } from '../trpc';
|
|
import { findWebhookCallsRoute } from './find-webhook-calls';
|
|
import { resendWebhookCallRoute } from './resend-webhook-call';
|
|
import {
|
|
ZCreateWebhookRequestSchema,
|
|
ZDeleteWebhookRequestSchema,
|
|
ZEditWebhookRequestSchema,
|
|
ZGetWebhookByIdRequestSchema,
|
|
ZTriggerTestWebhookRequestSchema,
|
|
} from './schema';
|
|
|
|
export const webhookRouter = router({
|
|
calls: {
|
|
find: findWebhookCallsRoute,
|
|
resend: resendWebhookCallRoute,
|
|
},
|
|
|
|
getTeamWebhooks: authenticatedProcedure.query(async ({ ctx }) => {
|
|
ctx.logger.info({
|
|
input: {
|
|
teamId: ctx.teamId,
|
|
},
|
|
});
|
|
|
|
return await getWebhooksByTeamId(ctx.teamId, ctx.user.id);
|
|
}),
|
|
|
|
getWebhookById: authenticatedProcedure.input(ZGetWebhookByIdRequestSchema).query(async ({ input, ctx }) => {
|
|
const { id } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
return await getWebhookById({
|
|
id,
|
|
userId: ctx.user.id,
|
|
teamId: ctx.teamId,
|
|
});
|
|
}),
|
|
|
|
createWebhook: authenticatedProcedure.input(ZCreateWebhookRequestSchema).mutation(async ({ input, ctx }) => {
|
|
const { enabled, eventTriggers, secret, webhookUrl } = input;
|
|
|
|
const webhook = await createWebhook({
|
|
enabled,
|
|
secret,
|
|
webhookUrl,
|
|
eventTriggers,
|
|
teamId: ctx.teamId,
|
|
userId: ctx.user.id,
|
|
});
|
|
|
|
fireAndForget(async () => {
|
|
const team = await prisma.team.findFirst({
|
|
where: { id: ctx.teamId },
|
|
select: { organisationId: true },
|
|
});
|
|
|
|
captureServerEvent({
|
|
event: 'App: Webhook Created',
|
|
userId: ctx.user.id,
|
|
teamId: ctx.teamId,
|
|
organisationId: team?.organisationId,
|
|
properties: {
|
|
triggerCount: eventTriggers.length,
|
|
},
|
|
});
|
|
});
|
|
|
|
return webhook;
|
|
}),
|
|
|
|
deleteWebhook: authenticatedProcedure.input(ZDeleteWebhookRequestSchema).mutation(async ({ input, ctx }) => {
|
|
const { id } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
return await deleteWebhookById({
|
|
id,
|
|
teamId: ctx.teamId,
|
|
userId: ctx.user.id,
|
|
});
|
|
}),
|
|
|
|
editWebhook: authenticatedProcedure.input(ZEditWebhookRequestSchema).mutation(async ({ input, ctx }) => {
|
|
const { id, ...data } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
id,
|
|
},
|
|
});
|
|
|
|
return await editWebhook({
|
|
id,
|
|
data,
|
|
userId: ctx.user.id,
|
|
teamId: ctx.teamId,
|
|
});
|
|
}),
|
|
|
|
testWebhook: authenticatedProcedure.input(ZTriggerTestWebhookRequestSchema).mutation(async ({ input, ctx }) => {
|
|
const { id, event } = input;
|
|
|
|
ctx.logger.info({
|
|
input: {
|
|
id,
|
|
event,
|
|
},
|
|
});
|
|
|
|
return await triggerTestWebhook({
|
|
id,
|
|
event,
|
|
userId: ctx.user.id,
|
|
teamId: ctx.teamId,
|
|
});
|
|
}),
|
|
});
|