Update prettier styling

This commit is contained in:
Ephraim Atta-Duncan
2023-04-04 22:10:30 +00:00
parent 84b57d715c
commit 964e749039
34 changed files with 258 additions and 93 deletions

View File

@ -27,7 +27,9 @@ export const uploadDocument = async (event: any) => {
)
.then((response: Response) => {
response.json().then((createdDocumentIdFromBody) => {
router.push(`${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}/recipients`);
router.push(
`${NEXT_PUBLIC_WEBAPP_URL}/documents/${createdDocumentIdFromBody}/recipients`
);
});
});
}

View File

@ -62,7 +62,9 @@ export function isPasswordValid(password: string, breakdown?: boolean, strict?:
return errors;
}
type CtxOrReq = { req: NextApiRequest; ctx?: never } | { ctx: { req: NextApiRequest }; req?: never };
type CtxOrReq =
| { req: NextApiRequest; ctx?: never }
| { ctx: { req: NextApiRequest }; req?: never };
export const ensureSession = async (ctxOrReq: CtxOrReq) => {
const session = await getSession(ctxOrReq);

View File

@ -12,7 +12,11 @@ export const getSafeRedirectUrl = (url = "") => {
const urlParsed = new URL(url);
// Avoid open redirection security vulnerability
if (!["CONSOLE_URL", "WEBAPP_URL", "WEBSITE_URL"].some((u) => new URL(u).origin === urlParsed.origin)) {
if (
!["CONSOLE_URL", "WEBAPP_URL", "WEBSITE_URL"].some(
(u) => new URL(u).origin === urlParsed.origin
)
) {
url = `${"WEBAPP_URL"}/`;
}

View File

@ -2,7 +2,11 @@ import { getUserFromToken } from "@documenso/lib/server";
import prisma from "@documenso/prisma";
import { Document as PrismaDocument } from "@prisma/client";
export const getDocument = async (documentId: number, req: any, res: any): Promise<PrismaDocument> => {
export const getDocument = async (
documentId: number,
req: any,
res: any
): Promise<PrismaDocument> => {
const user = await getUserFromToken(req, res);
if (!user) return Promise.reject("Invalid user or token.");
if (!documentId) Promise.reject("No documentId");

View File

@ -1,24 +1,27 @@
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
type Handlers = {
[method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{ default: NextApiHandler }>;
[method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{
default: NextApiHandler;
}>;
};
/** Allows us to split big API handlers by method */
export const defaultHandler = (handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => {
const handler = (await handlers[req.method as keyof typeof handlers])?.default;
// auto catch unsupported methods.
if (!handler) {
return res
.status(405)
.json({ message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})` });
}
export const defaultHandler =
(handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => {
const handler = (await handlers[req.method as keyof typeof handlers])?.default;
// auto catch unsupported methods.
if (!handler) {
return res.status(405).json({
message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})`,
});
}
try {
await handler(req, res);
return;
} catch (error) {
console.error(error);
return res.status(500).json({ message: "Something went wrong" });
}
};
try {
await handler(req, res);
return;
} catch (error) {
console.error(error);
return res.status(500).json({ message: "Something went wrong" });
}
};

View File

@ -5,7 +5,13 @@ export class HttpError<TCode extends number = number> extends Error {
public readonly url: string | undefined;
public readonly method: string | undefined;
constructor(opts: { url?: string; method?: string; message?: string; statusCode: TCode; cause?: Error }) {
constructor(opts: {
url?: string;
method?: string;
message?: string;
statusCode: TCode;
cause?: Error;
}) {
super(opts.message ?? `HTTP Error ${opts.statusCode} `);
Object.setPrototypeOf(this, HttpError.prototype);

View File

@ -15,7 +15,9 @@ async function createUser(userData: { email: string; password: string }) {
return user;
} catch (error) {
console.info(`WARN: Could not create user "${userData.email}". Maybe the email is already taken?`);
console.info(
`WARN: Could not create user "${userData.email}". Maybe the email is already taken?`
);
}
}

View File

@ -40,7 +40,10 @@ const extractSignature = (pdf, signatureCount = 1) => {
const byteRangePos = getSubstringIndex(pdf, "/ByteRange [", signatureCount);
if (byteRangePos === -1) {
throw new _SignPdfError.default("Failed to locate ByteRange.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to locate ByteRange.",
_SignPdfError.default.TYPE_PARSE
);
}
const byteRangeEnd = pdf.indexOf("]", byteRangePos);
@ -56,7 +59,10 @@ const extractSignature = (pdf, signatureCount = 1) => {
const matches = /\/ByteRange \[(\d+) +(\d+) +(\d+) +(\d+) *\]/.exec(byteRange);
if (matches === null) {
throw new _SignPdfError.default("Failed to parse the ByteRange.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to parse the ByteRange.",
_SignPdfError.default.TYPE_PARSE
);
}
const ByteRange = matches.slice(1).map(Number);

View File

@ -87,7 +87,10 @@ class PDFObject {
let string = `D:${pad(object.getUTCFullYear(), 4)}${pad(object.getUTCMonth() + 1, 2)}${pad(
object.getUTCDate(),
2
)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(object.getUTCSeconds(), 2)}Z`; // Encrypt the string when necessary
)}${pad(object.getUTCHours(), 2)}${pad(object.getUTCMinutes(), 2)}${pad(
object.getUTCSeconds(),
2
)}Z`; // Encrypt the string when necessary
if (encryptFn) {
string = encryptFn(Buffer.from(string, "ascii")).toString("binary"); // Escape characters as required by the spec

View File

@ -21,7 +21,10 @@ const getIndexFromRef = (refTable, ref) => {
index = parseInt(index);
if (!refTable.offsets.has(index)) {
throw new _SignPdfError.default(`Failed to locate object "${ref}".`, _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
`Failed to locate object "${ref}".`,
_SignPdfError.default.TYPE_PARSE
);
}
return index;

View File

@ -21,9 +21,13 @@ var _readPdf = _interopRequireDefault(require("./readPdf"));
var _getPageRef = _interopRequireDefault(require("./getPageRef"));
var _createBufferRootWithAcroform = _interopRequireDefault(require("./createBufferRootWithAcroform"));
var _createBufferRootWithAcroform = _interopRequireDefault(
require("./createBufferRootWithAcroform")
);
var _createBufferPageWithAnnotation = _interopRequireDefault(require("./createBufferPageWithAnnotation"));
var _createBufferPageWithAnnotation = _interopRequireDefault(
require("./createBufferPageWithAnnotation")
);
var _createBufferTrailer = _interopRequireDefault(require("./createBufferTrailer"));

View File

@ -3,7 +3,11 @@
Object.defineProperty(exports, "__esModule", {
value: true,
});
exports.getXref = exports.getLastTrailerPosition = exports.getFullXrefTable = exports.default = void 0;
exports.getXref =
exports.getLastTrailerPosition =
exports.getFullXrefTable =
exports.default =
void 0;
var _SignPdfError = _interopRequireDefault(require("../../SignPdfError"));
@ -16,7 +20,9 @@ function _interopRequireDefault(obj) {
const getLastTrailerPosition = (pdf) => {
const trailerStart = pdf.lastIndexOf(Buffer.from("trailer", "utf8"));
const trailer = pdf.slice(trailerStart, pdf.length - 6);
const xRefPosition = trailer.slice(trailer.lastIndexOf(Buffer.from("startxref", "utf8")) + 10).toString();
const xRefPosition = trailer
.slice(trailer.lastIndexOf(Buffer.from("startxref", "utf8")) + 10)
.toString();
return parseInt(xRefPosition);
};
@ -63,13 +69,19 @@ const getXref = (pdf, position) => {
let size = refTable.toString().split("/Size")[1];
if (!size) {
throw new _SignPdfError.default("Size not found in xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Size not found in xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
size = /^\s*(\d+)/.exec(size);
if (size === null) {
throw new _SignPdfError.default("Failed to parse size of xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Failed to parse size of xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
size = parseInt(size[1]);

View File

@ -26,7 +26,10 @@ const xrefToRefMap = (xrefString) => {
}
if (expectedLines <= 0) {
throw new _SignPdfError.default("Too many lines in xref table.", _SignPdfError.default.TYPE_PARSE);
throw new _SignPdfError.default(
"Too many lines in xref table.",
_SignPdfError.default.TYPE_PARSE
);
}
expectedLines -= 1;

View File

@ -102,9 +102,16 @@ class SignPdf {
let actualByteRange = `/ByteRange [${byteRange.join(" ")}]`;
actualByteRange += " ".repeat(byteRangePlaceholder.length - actualByteRange.length); // Replace the /ByteRange placeholder with the actual ByteRange
pdf = Buffer.concat([pdf.slice(0, byteRangePos), Buffer.from(actualByteRange), pdf.slice(byteRangeEnd)]); // Remove the placeholder signature
pdf = Buffer.concat([
pdf.slice(0, byteRangePos),
Buffer.from(actualByteRange),
pdf.slice(byteRangeEnd),
]); // Remove the placeholder signature
pdf = Buffer.concat([pdf.slice(0, byteRange[1]), pdf.slice(byteRange[2], byteRange[2] + byteRange[3])]); // Convert Buffer P12 to a forge implementation.
pdf = Buffer.concat([
pdf.slice(0, byteRange[1]),
pdf.slice(byteRange[2], byteRange[2] + byteRange[3]),
]); // Convert Buffer P12 to a forge implementation.
const forgeCert = _nodeForge.default.util.createBuffer(p12Buffer.toString("binary"));
@ -190,11 +197,15 @@ class SignPdf {
this.lastSignature = signature; // Pad the signature with zeroes so the it is the same length as the placeholder
signature += Buffer.from(String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)).toString(
"hex"
); // Place it in the document.
signature += Buffer.from(
String.fromCharCode(0).repeat(placeholderLength / 2 - raw.length)
).toString("hex"); // Place it in the document.
pdf = Buffer.concat([pdf.slice(0, byteRange[1]), Buffer.from(`<${signature}>`), pdf.slice(byteRange[1])]); // Magic. Done.
pdf = Buffer.concat([
pdf.slice(0, byteRange[1]),
Buffer.from(`<${signature}>`),
pdf.slice(byteRange[1]),
]); // Magic. Done.
return pdf;
}

View File

@ -7,9 +7,14 @@ export function Breadcrumb(props: any) {
<>
<nav className="sm:hidden" aria-label="Back">
<Link
href={props.items.length > 1 ? props.items[props.items.length - 2].href : props.items[0].href}
href={
props.items.length > 1 ? props.items[props.items.length - 2].href : props.items[0].href
}
className="flex items-center text-sm font-medium text-gray-500 hover:text-gray-700">
<ChevronLeftIcon className="-ml-1 mr-1 h-5 w-5 flex-shrink-0 text-gray-400" aria-hidden="true" />
<ChevronLeftIcon
className="-ml-1 mr-1 h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true"
/>
Back
</Link>
</nav>
@ -18,13 +23,18 @@ export function Breadcrumb(props: any) {
{props?.items.map((item: any, index: number) => (
<React.Fragment key={item.href}>
{index > 0 ? (
<ChevronRightIcon className="h-5 w-5 flex-shrink-0 text-gray-400" aria-hidden="true" />
<ChevronRightIcon
className="h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true"
/>
) : (
""
)}
<li>
<div className="flex">
<Link href={item.href} className="text-sm font-medium text-gray-500 hover:text-gray-700">
<Link
href={item.href}
className="text-sm font-medium text-gray-500 hover:text-gray-700">
{item.title}
</Link>
</div>

View File

@ -21,8 +21,18 @@ type DialogProps = {
icon: React.ReactNode;
};
export function Dialog({ title, open, setOpen, document, formValues, setLoading, icon }: DialogProps) {
const unsentEmailsLength = formValues.filter((s: any) => s.email && s.sendStatus != "SENT").length;
export function Dialog({
title,
open,
setOpen,
document,
formValues,
setLoading,
icon,
}: DialogProps) {
const unsentEmailsLength = formValues.filter(
(s: any) => s.email && s.sendStatus != "SENT"
).length;
return (
<Transition.Root show={open} as={Fragment}>
@ -54,7 +64,9 @@ export function Dialog({ title, open, setOpen, document, formValues, setLoading,
{icon}
</div>
<div className="mt-3 text-center sm:mt-5">
<DialogComponent.Title as="h3" className="text-lg font-medium leading-6 text-gray-900">
<DialogComponent.Title
as="h3"
className="text-lg font-medium leading-6 text-gray-900">
{title}
</DialogComponent.Title>
<div className="mt-2">

View File

@ -13,7 +13,9 @@ export function SelectBox(props: any) {
}}>
{({ open }) => (
<>
<Listbox.Label className="block text-sm font-medium text-gray-700">{props.label}</Listbox.Label>
<Listbox.Label className="block text-sm font-medium text-gray-700">
{props.label}
</Listbox.Label>
<div className="relative mt-1">
<Listbox.Button className="focus:border-neon focus:ring-neon relative w-full cursor-default rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 text-left shadow-sm focus:outline-none focus:ring-1 sm:text-sm">
<span className="block truncate">{props?.value?.label}</span>