mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
Papermark dual-licenses: AGPL-3.0 for the tree, a separate commercial
licence for ee/. We hold the first and not the second, so none of the
second may live here.
ee/ was already absent from main, but it was never deleted. 98f0da7fa
("ci: amd64-only build") renamed 150 files out of ee/ byte-identical
into features/, lib/billing/legacy/ (ee/stripe), lib/billing/limits/
(ee/limits), and flattened app/(ee)/ into app/ — putting commercially
licensed code under our AGPL root LICENSE. A rename is not a deletion.
Every path that commit moved is now gone, edited-since or not.
Deleted, with their routes and UI entry points: features/ai and
app/api/ai, features/workflows and app/api/{workflows,workflow-entry},
features/conversations and the Q&A/FAQ surface, features/security/sso
with app/api/auth/saml + app/api/scim + lib/jackson.ts (we use Hanzo
IAM OIDC natively), features/dataroom-invitations, features/templates,
features/access-notifications, features/conversions, features/
permissions. Five of these were gated by lib/featureFlags, which reads
@vercel/edge-config and returns false for every flag when EDGE_CONFIG
is unset — every non-Vercel deployment we run. Those flags are gone too.
Deleted the commercial gating outright rather than reimplementing it:
lib/billing/legacy (ee/stripe) and lib/billing/limits (ee/limits), the
upgrade modals and banners, UpgradeButton, FeaturePreview, PlanBadge,
the trial and blocking modals, /settings/upgrade, /settings/billing and
the billing checkout/seat/pause/cancel API. usePlan() no longer returns
capability booleans — the plan tag describes provisioning, it is not a
permission — and useLimits() is gone with every quota check it fed.
Subscription pause went the same way. Also dropped the npm dependencies
that existed only for the removed features (@boxyhq/saml-jackson, the
@ai-sdk packages, openai, streamdown, use-stick-to-bottom,
@trigger.dev/python) and the Jackson-specific next.config webpack shims.
Rewritten as original Hanzo code where a capability was load-bearing:
- lib/utils/get-file-size-limits.ts — one UPLOAD_LIMITS set plus
getFileSizeLimit(contentType), env-overridable. Operational limits,
not commercial ones, so the tus and browser-upload paths still refuse
oversized files without consulting a plan matrix.
- components/links/link-sheet/permissions-sheet.tsx — a flat, depth
annotated item list with view/download switches over the same
/permission-groups API. Two states, not three. ItemPermission now has
a single definition in lib/types.ts.
- app/api/links/[id]/upload/route.ts — visitor uploads, built around one
authorize() helper shared by GET and POST, and a notification debounce
keyed per (link, viewer) instead of listing and cancelling runs.
There is now exactly one link sheet: the ee DataroomLinkSheet duplicated
the AGPL LinkSheet, which already handled DATAROOM_LINK. Replaced
upstream's Omit<LinkType, "WORKFLOW_LINK"> — Omit on a string union
yields an object type and never narrowed anything — with a real union.
Verified: the S3/tus upload+download harness passes 13/13 against MinIO
after the deletions, and tsc goes from 257 pre-existing errors on
origin/main to 192 with zero files worse than baseline.
Reasoning recorded in LLM.md. LICENSE untouched.
Co-authored-by: Hanzo Dev <[email protected]>
326 lines
8.9 KiB
TypeScript
326 lines
8.9 KiB
TypeScript
import { useRouter } from "next/router";
|
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
import { Brand } from "@prisma/client";
|
|
import Cookies from "js-cookie";
|
|
import { ExtendedRecordMap } from "notion-types";
|
|
import { toast } from "sonner";
|
|
|
|
import { useAnalytics } from "@/lib/analytics";
|
|
import { useDisablePrint } from "@/lib/hooks/use-disable-print";
|
|
import { LinkWithDocument, NotionTheme } from "@/lib/types";
|
|
|
|
import LoadingSpinner from "@/components/ui/loading-spinner";
|
|
import AccessForm, {
|
|
DEFAULT_ACCESS_FORM_DATA,
|
|
DEFAULT_ACCESS_FORM_TYPE,
|
|
} from "@/components/view/access-form";
|
|
|
|
import EmailVerificationMessage from "./access-form/email-verification-form";
|
|
import ViewData, { TViewDocumentData } from "./view-data";
|
|
|
|
type RowData = { [key: string]: any };
|
|
type SheetData = {
|
|
sheetName: string;
|
|
columnData: string[];
|
|
rowData: RowData[];
|
|
};
|
|
|
|
export type DEFAULT_DOCUMENT_VIEW_TYPE = {
|
|
viewId?: string;
|
|
file?: string | null;
|
|
pages?:
|
|
| {
|
|
file: string;
|
|
pageNumber: string;
|
|
embeddedLinks: string[];
|
|
pageLinks: {
|
|
href: string;
|
|
coords: string;
|
|
isInternal?: boolean;
|
|
targetPage?: number;
|
|
}[];
|
|
metadata: { width: number; height: number; scaleFactor: number };
|
|
}[]
|
|
| null;
|
|
sheetData?: SheetData[] | null;
|
|
fileType?: string;
|
|
isPreview?: boolean;
|
|
ipAddress?: string;
|
|
verificationToken?: string;
|
|
isTeamMember?: boolean;
|
|
viewerId?: string;
|
|
};
|
|
|
|
export default function DocumentView({
|
|
link,
|
|
userEmail,
|
|
userId,
|
|
isProtected,
|
|
notionData,
|
|
brand,
|
|
token,
|
|
verifiedEmail,
|
|
showPoweredByBanner,
|
|
showAccountCreationSlide,
|
|
useAdvancedExcelViewer,
|
|
previewToken,
|
|
disableEditEmail,
|
|
useCustomAccessForm,
|
|
logoOnAccessForm,
|
|
isEmbedded,
|
|
annotationsEnabled,
|
|
textSelectionEnabled,
|
|
}: {
|
|
link: LinkWithDocument;
|
|
userEmail: string | null | undefined;
|
|
userId: string | null | undefined;
|
|
isProtected: boolean;
|
|
notionData?: {
|
|
rootNotionPageId: string | null;
|
|
recordMap: ExtendedRecordMap | null;
|
|
theme: NotionTheme | null;
|
|
};
|
|
brand?: Partial<Brand> | null;
|
|
token?: string;
|
|
verifiedEmail?: string;
|
|
showPoweredByBanner?: boolean;
|
|
showAccountCreationSlide?: boolean;
|
|
useAdvancedExcelViewer?: boolean;
|
|
previewToken?: string;
|
|
disableEditEmail?: boolean;
|
|
useCustomAccessForm?: boolean;
|
|
isEmbedded?: boolean;
|
|
logoOnAccessForm?: boolean;
|
|
annotationsEnabled?: boolean;
|
|
textSelectionEnabled?: boolean;
|
|
}) {
|
|
useDisablePrint();
|
|
const {
|
|
document,
|
|
emailProtected,
|
|
password: linkPassword,
|
|
enableAgreement,
|
|
} = link;
|
|
|
|
const analytics = useAnalytics();
|
|
const router = useRouter();
|
|
|
|
const didMount = useRef<boolean>(false);
|
|
const [submitted, setSubmitted] = useState<boolean>(false);
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
const [viewData, setViewData] = useState<DEFAULT_DOCUMENT_VIEW_TYPE>({
|
|
viewId: "",
|
|
});
|
|
const [data, setData] = useState<DEFAULT_ACCESS_FORM_TYPE>(
|
|
DEFAULT_ACCESS_FORM_DATA,
|
|
);
|
|
const [verificationRequested, setVerificationRequested] =
|
|
useState<boolean>(false);
|
|
const [verificationToken, setVerificationToken] = useState<string | null>(
|
|
token ?? null,
|
|
);
|
|
const [code, setCode] = useState<string | null>(null);
|
|
const [isInvalidCode, setIsInvalidCode] = useState<boolean>(false);
|
|
|
|
const handleSubmission = async (): Promise<void> => {
|
|
setIsLoading(true);
|
|
const response = await fetch("/api/views", {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
...data,
|
|
email: data.email ?? verifiedEmail ?? userEmail ?? null,
|
|
linkId: link.id,
|
|
documentId: document.id,
|
|
documentName: document.name,
|
|
ownerId: document.ownerId,
|
|
userId: userId ?? null,
|
|
documentVersionId: document.versions[0].id,
|
|
hasPages: document.versions[0].hasPages,
|
|
useAdvancedExcelViewer,
|
|
previewToken,
|
|
code: code ?? undefined,
|
|
token: verificationToken ?? undefined,
|
|
verifiedEmail: verifiedEmail ?? undefined,
|
|
}),
|
|
});
|
|
|
|
if (response.ok) {
|
|
const fetchData = await response.json();
|
|
|
|
if (fetchData.type === "email-verification") {
|
|
setVerificationRequested(true);
|
|
setIsLoading(false);
|
|
} else {
|
|
const {
|
|
viewId,
|
|
file,
|
|
pages,
|
|
sheetData,
|
|
fileType,
|
|
isPreview,
|
|
ipAddress,
|
|
verificationToken,
|
|
isTeamMember,
|
|
viewerId,
|
|
} = fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;
|
|
|
|
analytics.identify(
|
|
userEmail ?? verifiedEmail ?? data.email ?? undefined,
|
|
);
|
|
analytics.capture("Link Viewed", {
|
|
linkId: link.id,
|
|
documentId: document.id,
|
|
linkType: "DOCUMENT_LINK",
|
|
viewerId: viewId,
|
|
viewerEmail: data.email ?? verifiedEmail ?? userEmail,
|
|
isEmbedded,
|
|
isTeamMember,
|
|
teamId: link.teamId,
|
|
});
|
|
|
|
// set the verification token to the cookie
|
|
if (verificationToken) {
|
|
Cookies.set("pm_vft", verificationToken, {
|
|
path: router.asPath.split("?")[0],
|
|
expires: 1,
|
|
sameSite: "strict",
|
|
secure: true,
|
|
});
|
|
setCode(null);
|
|
}
|
|
|
|
setViewData({
|
|
viewId,
|
|
file,
|
|
pages,
|
|
sheetData,
|
|
fileType,
|
|
isPreview,
|
|
ipAddress,
|
|
isTeamMember,
|
|
viewerId,
|
|
});
|
|
setSubmitted(true);
|
|
setVerificationRequested(false);
|
|
setIsLoading(false);
|
|
}
|
|
} else {
|
|
const data = await response.json();
|
|
toast.error(data.message);
|
|
|
|
if (data.resetVerification) {
|
|
const currentPath = router.asPath.split("?")[0];
|
|
|
|
Cookies.remove("pm_vft", { path: currentPath });
|
|
setVerificationToken(null);
|
|
setCode(null);
|
|
setIsInvalidCode(true);
|
|
}
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const handleSubmit: React.FormEventHandler<HTMLFormElement> = async (
|
|
event: React.FormEvent,
|
|
): Promise<void> => {
|
|
event.preventDefault();
|
|
await handleSubmission();
|
|
};
|
|
|
|
// If token is present, run handle submit which will verify token and get document
|
|
// If link is not submitted and does not have email / password protection, show the access form
|
|
useEffect(() => {
|
|
if (!didMount.current) {
|
|
if ((!submitted && !isProtected) || token || previewToken) {
|
|
handleSubmission();
|
|
}
|
|
didMount.current = true;
|
|
}
|
|
}, [submitted, isProtected, token, previewToken]);
|
|
|
|
// Components to render when email is submitted but verification is pending
|
|
if (verificationRequested) {
|
|
return (
|
|
<EmailVerificationMessage
|
|
onSubmitHandler={handleSubmit}
|
|
data={data}
|
|
isLoading={isLoading}
|
|
code={code}
|
|
setCode={setCode}
|
|
isInvalidCode={isInvalidCode}
|
|
setIsInvalidCode={setIsInvalidCode}
|
|
brand={brand}
|
|
/>
|
|
);
|
|
}
|
|
|
|
// If link is not submitted and does not have email / password protection, show the access form
|
|
if (!submitted && isProtected) {
|
|
return (
|
|
<AccessForm
|
|
data={data}
|
|
email={userEmail}
|
|
setData={setData}
|
|
onSubmitHandler={handleSubmit}
|
|
requireEmail={emailProtected}
|
|
requirePassword={!!linkPassword}
|
|
requireAgreement={enableAgreement!}
|
|
agreementName={link.agreement?.name}
|
|
agreementContent={link.agreement?.content}
|
|
agreementContentType={link.agreement?.contentType}
|
|
requireName={link.agreement?.requireName}
|
|
isLoading={isLoading}
|
|
brand={brand}
|
|
disableEditEmail={disableEditEmail}
|
|
useCustomAccessForm={useCustomAccessForm}
|
|
customFields={link.customFields}
|
|
logoOnAccessForm={logoOnAccessForm}
|
|
linkWelcomeMessage={link.welcomeMessage}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<div className="flex h-screen items-center justify-center">
|
|
<LoadingSpinner className="h-20 w-20" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className="bg-gray-950"
|
|
style={{
|
|
backgroundColor:
|
|
brand && brand.accentColor ? brand.accentColor : "rgb(3, 7, 18)",
|
|
}}
|
|
>
|
|
{submitted ? (
|
|
<ViewData
|
|
link={link}
|
|
viewData={viewData}
|
|
document={document as unknown as TViewDocumentData}
|
|
notionData={notionData}
|
|
brand={brand}
|
|
showPoweredByBanner={showPoweredByBanner}
|
|
showAccountCreationSlide={showAccountCreationSlide}
|
|
useAdvancedExcelViewer={useAdvancedExcelViewer}
|
|
viewerEmail={data.email ?? verifiedEmail ?? userEmail ?? undefined}
|
|
annotationsEnabled={annotationsEnabled}
|
|
textSelectionEnabled={textSelectionEnabled}
|
|
/>
|
|
) : (
|
|
<div className="flex h-screen items-center justify-center">
|
|
<LoadingSpinner className="h-20 w-20" />
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|