Files
documenso/packages/trpc/server/api-token-router/create-api-token.ts
T
Lucas Smith ae4b56dd88 feat: optimise posthog usage and add error tracking (#3301)
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.
2026-08-27 11:11:51 +10:00

44 lines
1.3 KiB
TypeScript

import { captureServerEvent } from '@documenso/lib/server-only/analytics/capture-server-event';
import { createApiToken } from '@documenso/lib/server-only/public-api/create-api-token';
import { fireAndForget } from '@documenso/lib/universal/fire-and-forget';
import { prisma } from '@documenso/prisma';
import { authenticatedProcedure } from '../trpc';
import { ZCreateApiTokenRequestSchema, ZCreateApiTokenResponseSchema } from './create-api-token.types';
export const createApiTokenRoute = authenticatedProcedure
.input(ZCreateApiTokenRequestSchema)
.output(ZCreateApiTokenResponseSchema)
.mutation(async ({ input, ctx }) => {
const { tokenName, teamId, expirationDate } = input;
ctx.logger.info({
input: {
teamId,
},
});
const createdToken = await createApiToken({
userId: ctx.user.id,
teamId,
tokenName,
expiresIn: expirationDate,
});
fireAndForget(async () => {
const team = await prisma.team.findFirst({
where: { id: teamId },
select: { organisationId: true },
});
captureServerEvent({
event: 'App: API Token Created',
userId: ctx.user.id,
teamId,
organisationId: team?.organisationId,
});
});
return createdToken;
});