From 4d4dfd3c5fa4719baa36a693121ca5d6d208017c Mon Sep 17 00:00:00 2001
From: Mythie
Date: Wed, 10 Apr 2024 17:38:34 +0700
Subject: [PATCH] fix: implement review feedback, resolve build errors
---
apps/marketing/next.config.js | 2 +-
apps/web/next.config.js | 2 +-
.../[id]/logs/download-audit-log-button.tsx | 59 +++++----
.../[id]/logs/download-certificate-button.tsx | 59 +++++----
.../%5F%5Fhtmltopdf/certificate/page.tsx | 42 ++-----
package-lock.json | 117 ++++++++++--------
package.json | 3 +-
packages/lib/package.json | 3 +-
8 files changed, 155 insertions(+), 132 deletions(-)
diff --git a/apps/marketing/next.config.js b/apps/marketing/next.config.js
index 0f7b7ad5c..c8c89e45d 100644
--- a/apps/marketing/next.config.js
+++ b/apps/marketing/next.config.js
@@ -22,7 +22,7 @@ const FONT_CAVEAT_BYTES = fs.readFileSync(
const config = {
experimental: {
outputFileTracingRoot: path.join(__dirname, '../../'),
- serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign'],
+ serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign', 'playwright'],
serverActions: {
bodySizeLimit: '50mb',
},
diff --git a/apps/web/next.config.js b/apps/web/next.config.js
index af82847c0..85d3097ca 100644
--- a/apps/web/next.config.js
+++ b/apps/web/next.config.js
@@ -23,7 +23,7 @@ const config = {
output: process.env.DOCKER_OUTPUT ? 'standalone' : undefined,
experimental: {
outputFileTracingRoot: path.join(__dirname, '../../'),
- serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign'],
+ serverComponentsExternalPackages: ['@node-rs/bcrypt', '@documenso/pdf-sign', 'playwright'],
serverActions: {
bodySizeLimit: '50mb',
},
diff --git a/apps/web/src/app/(dashboard)/documents/[id]/logs/download-audit-log-button.tsx b/apps/web/src/app/(dashboard)/documents/[id]/logs/download-audit-log-button.tsx
index fce4d4855..0847d63fa 100644
--- a/apps/web/src/app/(dashboard)/documents/[id]/logs/download-audit-log-button.tsx
+++ b/apps/web/src/app/(dashboard)/documents/[id]/logs/download-audit-log-button.tsx
@@ -5,6 +5,7 @@ import { DownloadIcon } from 'lucide-react';
import { trpc } from '@documenso/trpc/react';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
+import { useToast } from '@documenso/ui/primitives/use-toast';
export type DownloadAuditLogButtonProps = {
className?: string;
@@ -12,40 +13,52 @@ export type DownloadAuditLogButtonProps = {
};
export const DownloadAuditLogButton = ({ className, documentId }: DownloadAuditLogButtonProps) => {
+ const { toast } = useToast();
+
const { mutateAsync: downloadAuditLogs, isLoading } =
trpc.document.downloadAuditLogs.useMutation();
const onDownloadAuditLogsClick = async () => {
- const { url } = await downloadAuditLogs({ documentId });
+ try {
+ const { url } = await downloadAuditLogs({ documentId });
- const iframe = Object.assign(document.createElement('iframe'), {
- src: url,
- });
+ const iframe = Object.assign(document.createElement('iframe'), {
+ src: url,
+ });
- Object.assign(iframe.style, {
- position: 'fixed',
- top: '0',
- left: '0',
- width: '0',
- height: '0',
- });
+ Object.assign(iframe.style, {
+ position: 'fixed',
+ top: '0',
+ left: '0',
+ width: '0',
+ height: '0',
+ });
- const onLoaded = () => {
- if (iframe.contentDocument?.readyState === 'complete') {
- iframe.contentWindow?.print();
+ const onLoaded = () => {
+ if (iframe.contentDocument?.readyState === 'complete') {
+ iframe.contentWindow?.print();
- iframe.contentWindow?.addEventListener('afterprint', () => {
- document.body.removeChild(iframe);
- });
- }
- };
+ iframe.contentWindow?.addEventListener('afterprint', () => {
+ document.body.removeChild(iframe);
+ });
+ }
+ };
- // When the iframe has loaded, print the iframe and remove it from the dom
- iframe.addEventListener('load', onLoaded);
+ // When the iframe has loaded, print the iframe and remove it from the dom
+ iframe.addEventListener('load', onLoaded);
- document.body.appendChild(iframe);
+ document.body.appendChild(iframe);
- onLoaded();
+ onLoaded();
+ } catch (error) {
+ console.error(error);
+
+ toast({
+ title: 'Something went wrong',
+ description: 'Sorry, we were unable to download the audit logs. Please try again later.',
+ variant: 'destructive',
+ });
+ }
};
return (
diff --git a/apps/web/src/app/(dashboard)/documents/[id]/logs/download-certificate-button.tsx b/apps/web/src/app/(dashboard)/documents/[id]/logs/download-certificate-button.tsx
index e0ae395b4..49a330b94 100644
--- a/apps/web/src/app/(dashboard)/documents/[id]/logs/download-certificate-button.tsx
+++ b/apps/web/src/app/(dashboard)/documents/[id]/logs/download-certificate-button.tsx
@@ -5,6 +5,7 @@ import { DownloadIcon } from 'lucide-react';
import { trpc } from '@documenso/trpc/react';
import { cn } from '@documenso/ui/lib/utils';
import { Button } from '@documenso/ui/primitives/button';
+import { useToast } from '@documenso/ui/primitives/use-toast';
export type DownloadCertificateButtonProps = {
className?: string;
@@ -15,40 +16,52 @@ export const DownloadCertificateButton = ({
className,
documentId,
}: DownloadCertificateButtonProps) => {
+ const { toast } = useToast();
+
const { mutateAsync: downloadCertificate, isLoading } =
trpc.document.downloadCertificate.useMutation();
const onDownloadCertificatesClick = async () => {
- const { url } = await downloadCertificate({ documentId });
+ try {
+ const { url } = await downloadCertificate({ documentId });
- const iframe = Object.assign(document.createElement('iframe'), {
- src: url,
- });
+ const iframe = Object.assign(document.createElement('iframe'), {
+ src: url,
+ });
- Object.assign(iframe.style, {
- position: 'fixed',
- top: '0',
- left: '0',
- width: '0',
- height: '0',
- });
+ Object.assign(iframe.style, {
+ position: 'fixed',
+ top: '0',
+ left: '0',
+ width: '0',
+ height: '0',
+ });
- const onLoaded = () => {
- if (iframe.contentDocument?.readyState === 'complete') {
- iframe.contentWindow?.print();
+ const onLoaded = () => {
+ if (iframe.contentDocument?.readyState === 'complete') {
+ iframe.contentWindow?.print();
- iframe.contentWindow?.addEventListener('afterprint', () => {
- document.body.removeChild(iframe);
- });
- }
- };
+ iframe.contentWindow?.addEventListener('afterprint', () => {
+ document.body.removeChild(iframe);
+ });
+ }
+ };
- // When the iframe has loaded, print the iframe and remove it from the dom
- iframe.addEventListener('load', onLoaded);
+ // When the iframe has loaded, print the iframe and remove it from the dom
+ iframe.addEventListener('load', onLoaded);
- document.body.appendChild(iframe);
+ document.body.appendChild(iframe);
- onLoaded();
+ onLoaded();
+ } catch (error) {
+ console.error(error);
+
+ toast({
+ title: 'Something went wrong',
+ description: 'Sorry, we were unable to download the certificate. Please try again later.',
+ variant: 'destructive',
+ });
+ }
};
return (
diff --git a/apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx b/apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx
index 690f0eb78..4924e832b 100644
--- a/apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx
+++ b/apps/web/src/app/(internal)/%5F%5Fhtmltopdf/certificate/page.tsx
@@ -12,10 +12,7 @@ import { getEntireDocument } from '@documenso/lib/server-only/admin/get-entire-d
import { decryptSecondaryData } from '@documenso/lib/server-only/crypto/decrypt';
import { getDocumentCertificateAuditLogs } from '@documenso/lib/server-only/document/get-document-certificate-audit-logs';
import { DOCUMENT_AUDIT_LOG_TYPE } from '@documenso/lib/types/document-audit-logs';
-import {
- ZDocumentAuthOptionsSchema,
- ZRecipientAuthOptionsSchema,
-} from '@documenso/lib/types/document-auth';
+import { extractDocumentAuthMethods } from '@documenso/lib/utils/document-auth';
import { FieldType } from '@documenso/prisma/client';
import { Card, CardContent } from '@documenso/ui/primitives/card';
import {
@@ -93,40 +90,30 @@ export default async function SigningCertificate({ searchParams }: SigningCertif
return 'Unknown';
}
- const documentAuthOptions = ZDocumentAuthOptionsSchema.parse(document.authOptions);
- const recipientAuthOptions = ZRecipientAuthOptionsSchema.parse(recipient.authOptions);
+ const extractedAuthMethods = extractDocumentAuthMethods({
+ documentAuth: document.authOptions,
+ recipientAuth: recipient.authOptions,
+ });
let authLevel = 'Email';
- if (
- documentAuthOptions.globalAccessAuth === 'ACCOUNT' ||
- recipientAuthOptions.accessAuth === 'ACCOUNT'
- ) {
+ if (extractedAuthMethods.derivedRecipientAccessAuth === 'ACCOUNT') {
authLevel = 'Account Authentication';
}
- if (
- documentAuthOptions.globalActionAuth === 'ACCOUNT' ||
- recipientAuthOptions.actionAuth === 'ACCOUNT'
- ) {
+ if (extractedAuthMethods.derivedRecipientActionAuth === 'ACCOUNT') {
authLevel = 'Account Re-Authentication';
}
- if (
- documentAuthOptions.globalActionAuth === 'TWO_FACTOR_AUTH' ||
- recipientAuthOptions.actionAuth === 'TWO_FACTOR_AUTH'
- ) {
- authLevel = 'Two Factor Re-Authentication';
+ if (extractedAuthMethods.derivedRecipientActionAuth === 'TWO_FACTOR_AUTH') {
+ authLevel = 'Two-Factor Re-Authentication';
}
- if (
- documentAuthOptions.globalActionAuth === 'PASSKEY' ||
- recipientAuthOptions.actionAuth === 'PASSKEY'
- ) {
+ if (extractedAuthMethods.derivedRecipientActionAuth === 'PASSKEY') {
authLevel = 'Passkey Re-Authentication';
}
- if (recipientAuthOptions.actionAuth === 'EXPLICIT_NONE') {
+ if (extractedAuthMethods.derivedRecipientActionAuth === 'EXPLICIT_NONE') {
authLevel = 'Email';
}
@@ -284,13 +271,6 @@ export default async function SigningCertificate({ searchParams }: SigningCertif
-
- {/*
-
- Authentication: {''}
-
- IP: {''}
- */}
);
})}
diff --git a/package-lock.json b/package-lock.json
index e305355ef..fb03b3a67 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -22,6 +22,7 @@
"eslint-config-custom": "*",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
+ "playwright": "^1.43.0",
"prettier": "^2.5.1",
"rimraf": "^5.0.1",
"turbo": "^1.9.3"
@@ -4701,6 +4702,19 @@
"node": ">=14"
}
},
+ "node_modules/@playwright/browser-chromium": {
+ "version": "1.43.0",
+ "resolved": "https://registry.npmjs.org/@playwright/browser-chromium/-/browser-chromium-1.43.0.tgz",
+ "integrity": "sha512-F0S4KIqSqQqm9EgsdtWjaJRpgP8cD2vWZHPSB41YI00PtXUobiv/3AnYISeL7wNuTanND7giaXQ4SIjkcIq3KQ==",
+ "dev": true,
+ "hasInstallScript": true,
+ "dependencies": {
+ "playwright-core": "1.43.0"
+ },
+ "engines": {
+ "node": ">=16"
+ }
+ },
"node_modules/@playwright/test": {
"version": "1.40.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.0.tgz",
@@ -4716,6 +4730,50 @@
"node": ">=16"
}
},
+ "node_modules/@playwright/test/node_modules/fsevents": {
+ "version": "2.3.2",
+ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
+ "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
+ "dev": true,
+ "hasInstallScript": true,
+ "optional": true,
+ "os": [
+ "darwin"
+ ],
+ "engines": {
+ "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
+ }
+ },
+ "node_modules/@playwright/test/node_modules/playwright": {
+ "version": "1.40.0",
+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.0.tgz",
+ "integrity": "sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==",
+ "dev": true,
+ "dependencies": {
+ "playwright-core": "1.40.0"
+ },
+ "bin": {
+ "playwright": "cli.js"
+ },
+ "engines": {
+ "node": ">=16"
+ },
+ "optionalDependencies": {
+ "fsevents": "2.3.2"
+ }
+ },
+ "node_modules/@playwright/test/node_modules/playwright-core": {
+ "version": "1.40.0",
+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.0.tgz",
+ "integrity": "sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==",
+ "dev": true,
+ "bin": {
+ "playwright-core": "cli.js"
+ },
+ "engines": {
+ "node": ">=16"
+ }
+ },
"node_modules/@prisma/client": {
"version": "5.4.2",
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.4.2.tgz",
@@ -17615,12 +17673,11 @@
}
},
"node_modules/playwright": {
- "version": "1.40.0",
- "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.0.tgz",
- "integrity": "sha512-gyHAgQjiDf1m34Xpwzaqb76KgfzYrhK7iih+2IzcOCoZWr/8ZqmdBw+t0RU85ZmfJMgtgAiNtBQ/KS2325INXw==",
- "dev": true,
+ "version": "1.43.0",
+ "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.43.0.tgz",
+ "integrity": "sha512-SiOKHbVjTSf6wHuGCbqrEyzlm6qvXcv7mENP+OZon1I07brfZLGdfWV0l/efAzVx7TF3Z45ov1gPEkku9q25YQ==",
"dependencies": {
- "playwright-core": "1.40.0"
+ "playwright-core": "1.43.0"
},
"bin": {
"playwright": "cli.js"
@@ -17633,10 +17690,9 @@
}
},
"node_modules/playwright-core": {
- "version": "1.40.0",
- "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.0.tgz",
- "integrity": "sha512-fvKewVJpGeca8t0ipM56jkVSU6Eo0RmFvQ/MaCQNDYm+sdvKkMBBWTE1FdeMqIdumRaXXjZChWHvIzCGM/tA/Q==",
- "dev": true,
+ "version": "1.43.0",
+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.43.0.tgz",
+ "integrity": "sha512-iWFjyBUH97+pUFiyTqSLd8cDMMOS0r2ZYz2qEsPjH8/bX++sbIJT35MSwKnp1r/OQBAqC5XO99xFbJ9XClhf4w==",
"bin": {
"playwright-core": "cli.js"
},
@@ -17648,7 +17704,6 @@
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
- "dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
@@ -24934,22 +24989,10 @@
"zod": "^3.22.4"
},
"devDependencies": {
+ "@playwright/browser-chromium": "^1.43.0",
"@types/luxon": "^3.3.1"
}
},
- "packages/lib/node_modules/fsevents": {
- "version": "2.3.2",
- "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
- "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
- "hasInstallScript": true,
- "optional": true,
- "os": [
- "darwin"
- ],
- "engines": {
- "node": "^8.16.0 || ^10.6.0 || >=11.0.0"
- }
- },
"packages/lib/node_modules/nanoid": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-4.0.2.tgz",
@@ -24967,34 +25010,6 @@
"node": "^14 || ^16 || >=18"
}
},
- "packages/lib/node_modules/playwright": {
- "version": "1.43.0",
- "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.43.0.tgz",
- "integrity": "sha512-SiOKHbVjTSf6wHuGCbqrEyzlm6qvXcv7mENP+OZon1I07brfZLGdfWV0l/efAzVx7TF3Z45ov1gPEkku9q25YQ==",
- "dependencies": {
- "playwright-core": "1.43.0"
- },
- "bin": {
- "playwright": "cli.js"
- },
- "engines": {
- "node": ">=16"
- },
- "optionalDependencies": {
- "fsevents": "2.3.2"
- }
- },
- "packages/lib/node_modules/playwright-core": {
- "version": "1.43.0",
- "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.43.0.tgz",
- "integrity": "sha512-iWFjyBUH97+pUFiyTqSLd8cDMMOS0r2ZYz2qEsPjH8/bX++sbIJT35MSwKnp1r/OQBAqC5XO99xFbJ9XClhf4w==",
- "bin": {
- "playwright-core": "cli.js"
- },
- "engines": {
- "node": ">=16"
- }
- },
"packages/prettier-config": {
"name": "@documenso/prettier-config",
"version": "0.0.0",
diff --git a/package.json b/package.json
index bafada07a..396b2ecfd 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
"eslint-config-custom": "*",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
+ "playwright": "^1.43.0",
"prettier": "^2.5.1",
"rimraf": "^5.0.1",
"turbo": "^1.9.3"
@@ -59,4 +60,4 @@
"next": "14.0.3"
}
}
-}
+}
\ No newline at end of file
diff --git a/packages/lib/package.json b/packages/lib/package.json
index 616e391d0..1aa7e431e 100644
--- a/packages/lib/package.json
+++ b/packages/lib/package.json
@@ -47,6 +47,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
- "@types/luxon": "^3.3.1"
+ "@types/luxon": "^3.3.1",
+ "@playwright/browser-chromium": "^1.43.0"
}
}
\ No newline at end of file