From 4c0b772fc9698b3099ba4e16d7e594c39f2d4fb6 Mon Sep 17 00:00:00 2001 From: Mythie Date: Wed, 22 May 2024 21:58:30 +1000 Subject: [PATCH 1/5] fix: rewrite form flattening handler Previously we used the form flattening method from PDF-Lib but unfortunately when it encountered orphaned form items or other PDF oddities it would throw an error. Because of this certain documents would fail to seal and be stuck in a pending state with no recourse available. This change rewrites the form flattening handler to be more lenient when coming across the unknown opting to skip items it can't handle rather than abort. --- .../admin/documents/[id]/admin-actions.tsx | 10 +- .../(dashboard)/admin/documents/[id]/page.tsx | 2 +- .../lib/server-only/document/seal-document.ts | 6 +- packages/lib/server-only/pdf/flatten-form.ts | 112 ++++++++++++++++++ packages/trpc/server/admin-router/router.ts | 8 +- 5 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 packages/lib/server-only/pdf/flatten-form.ts diff --git a/apps/web/src/app/(dashboard)/admin/documents/[id]/admin-actions.tsx b/apps/web/src/app/(dashboard)/admin/documents/[id]/admin-actions.tsx index 5d6cae4af..f084b5db5 100644 --- a/apps/web/src/app/(dashboard)/admin/documents/[id]/admin-actions.tsx +++ b/apps/web/src/app/(dashboard)/admin/documents/[id]/admin-actions.tsx @@ -2,7 +2,8 @@ import Link from 'next/link'; -import { type Document, DocumentStatus } from '@documenso/prisma/client'; +import type { Recipient } from '@documenso/prisma/client'; +import { type Document, SigningStatus } from '@documenso/prisma/client'; import { trpc } from '@documenso/trpc/react'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; @@ -17,9 +18,10 @@ import { useToast } from '@documenso/ui/primitives/use-toast'; export type AdminActionsProps = { className?: string; document: Document; + recipients: Recipient[]; }; -export const AdminActions = ({ className, document }: AdminActionsProps) => { +export const AdminActions = ({ className, document, recipients }: AdminActionsProps) => { const { toast } = useToast(); const { mutate: resealDocument, isLoading: isResealDocumentLoading } = @@ -47,7 +49,9 @@ export const AdminActions = ({ className, document }: AdminActionsProps) => {