feat: render signatures on pending envelopes (#2743)

This commit is contained in:
David Nguyen
2026-04-30 14:43:48 +10:00
committed by GitHub
parent ae497092d7
commit 5d92aaf20a
7 changed files with 197 additions and 43 deletions
@@ -0,0 +1,65 @@
import { FieldType } from '@prisma/client';
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import { getEnvelopeWhereInput } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
import { prisma } from '@documenso/prisma';
import { authenticatedProcedure } from '../../trpc';
import {
ZGetEnvelopeFieldSignaturesRequestSchema,
ZGetEnvelopeFieldSignaturesResponseSchema,
} from './get-envelope-field-signatures.types';
export const getEnvelopeFieldSignaturesRoute = authenticatedProcedure
.input(ZGetEnvelopeFieldSignaturesRequestSchema)
.output(ZGetEnvelopeFieldSignaturesResponseSchema)
.query(async ({ input, ctx }) => {
const { teamId, user } = ctx;
const { envelopeId } = input;
ctx.logger.info({
input: {
envelopeId,
},
});
// Validate the user has access to the envelope.
const { envelopeWhereInput } = await getEnvelopeWhereInput({
id: {
type: 'envelopeId',
id: envelopeId,
},
type: null,
userId: user.id,
teamId,
});
const envelope = await prisma.envelope.findFirst({
where: envelopeWhereInput,
include: {
fields: {
where: {
inserted: true,
type: FieldType.SIGNATURE,
},
include: {
signature: true,
},
},
},
});
if (!envelope) {
throw new AppError(AppErrorCode.NOT_FOUND, {
message: 'Envelope not found',
});
}
const signatures = envelope.fields.map((field) => ({
fieldId: field.id,
signatureImageAsBase64: field.signature?.signatureImageAsBase64 ?? null,
typedSignature: field.signature?.typedSignature ?? null,
}));
return signatures;
});
@@ -0,0 +1,20 @@
import { z } from 'zod';
export const ZGetEnvelopeFieldSignaturesRequestSchema = z.object({
envelopeId: z.string().min(1),
});
export const ZGetEnvelopeFieldSignaturesResponseSchema = z
.object({
fieldId: z.number(),
signatureImageAsBase64: z.string().nullable(),
typedSignature: z.string().nullable(),
})
.array();
export type TGetEnvelopeFieldSignaturesRequest = z.infer<
typeof ZGetEnvelopeFieldSignaturesRequestSchema
>;
export type TGetEnvelopeFieldSignaturesResponse = z.infer<
typeof ZGetEnvelopeFieldSignaturesResponseSchema
>;
@@ -15,6 +15,7 @@ import { duplicateEnvelopeRoute } from './duplicate-envelope';
import { createEnvelopeFieldsRoute } from './envelope-fields/create-envelope-fields';
import { deleteEnvelopeFieldRoute } from './envelope-fields/delete-envelope-field';
import { getEnvelopeFieldRoute } from './envelope-fields/get-envelope-field';
import { getEnvelopeFieldSignaturesRoute } from './envelope-fields/get-envelope-field-signatures';
import { updateEnvelopeFieldsRoute } from './envelope-fields/update-envelope-fields';
import { createEnvelopeRecipientsRoute } from './envelope-recipients/create-envelope-recipients';
import { deleteEnvelopeRecipientRoute } from './envelope-recipients/delete-envelope-recipient';
@@ -68,6 +69,7 @@ export const envelopeRouter = router({
},
field: {
get: getEnvelopeFieldRoute,
getSignatures: getEnvelopeFieldSignaturesRoute,
createMany: createEnvelopeFieldsRoute,
updateMany: updateEnvelopeFieldsRoute,
delete: deleteEnvelopeFieldRoute,