Files
zeekay 9dff9e667e rip: enterprise dirs + paywalls — full AGPL, no commercial-license code
Drop the dual-licensed `ee/` tree entirely. All features previously
locked behind the Hanzo Dataroom Commercial License are now part of the
AGPL-3.0 core and freely available — custom domains, branded viewing,
advanced analytics, watermarks, access controls, Q&A, AI vector stores,
workflows, SAML SSO, dataroom invitations, conversations, templates.

Layout changes:
* `ee/features/{ai,conversations,workflows,permissions,storage,templates,
  dataroom-invitations,access-notifications,security,conversions}/` →
  `features/<name>/` (AGPL).
* `ee/limits/` → `lib/billing/limits/` with every plan resolving to an
  unlimited profile (no users/links/documents/domains/datarooms cap,
  conversations and watermarks always on).
* `ee/stripe/` → `lib/billing/legacy/` (already a compat shim over
  `@hanzoai/commerce`; renewal-reminder webhook is now a no-op).
* `ee/features/billing/cancellation/` deleted. Pause/unpause/cancel/
  retention routes now compile against `lib/billing/cancellation.ts`
  stubs that return 410 Gone; `isTeamPaused`/`isTeamPausedById` in
  `lib/billing/paused.ts` always report active. `CancellationModal` is
  a no-op shim in `components/billing/`.
* `app/(ee)/api/*` route group folded into `app/api/*` (SAML auth,
  SCIM, AI chat, workflows, FAQ, link-upload).

Build: `npm run build` green.
2026-06-07 11:46:48 -07:00

117 lines
3.4 KiB
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import { isTeamPaused } from "@/lib/billing/paused";
import getSubscriptionItem, {
SubscriptionDiscount,
} from "@/lib/billing/legacy/functions/get-subscription-item";
import { isOldAccount } from "@/lib/billing/legacy/utils";
import { getServerSession } from "next-auth/next";
import { errorhandler } from "@/lib/errorHandler";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
import { authOptions } from "../../../auth/[...nextauth]";
export default async function handle(
req: NextApiRequest,
res: NextApiResponse,
) {
if (req.method === "GET") {
// GET /api/teams/:teamId/billing/plan
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
}
const { teamId } = req.query as { teamId: string };
const userId = (session.user as CustomUser).id;
const withDiscount = req.query.withDiscount === "true";
try {
const team = await prisma.team.findUnique({
where: {
id: teamId,
users: {
some: {
userId: userId,
},
},
},
select: {
plan: true,
stripeId: true,
subscriptionId: true,
startsAt: true,
endsAt: true,
pausedAt: true,
pauseStartsAt: true,
pauseEndsAt: true,
cancelledAt: true,
},
});
if (!team) {
return res.status(404).json({ error: "Team not found" });
}
const isCustomer = !!team.stripeId;
// calculate the plan cycle either yearly or monthly based on the startsAt and endsAt dates
let subscriptionCycle = "monthly";
if (team?.startsAt && team?.endsAt) {
const durationInDays = Math.round(
(team.endsAt.getTime() - team.startsAt.getTime()) /
(1000 * 60 * 60 * 24),
);
// If duration is more than 31 days, consider it yearly
subscriptionCycle = durationInDays > 31 ? "yearly" : "monthly";
}
// Fetch discount information if team has an active subscription
let discount: SubscriptionDiscount | null = null;
if (
withDiscount &&
team?.subscriptionId &&
team.plan &&
team.plan !== "free" &&
team.pauseStartsAt === null
) {
try {
const subscriptionData = await getSubscriptionItem(
team.subscriptionId,
isOldAccount(team.plan),
);
discount = subscriptionData.discount;
} catch (error) {
// If we can't fetch discount info, just log and continue without it
console.error("Failed to fetch discount information:", error);
}
}
// Calculate if team is currently paused
const isPaused = isTeamPaused(team);
return res.status(200).json({
plan: team.plan,
startsAt: team.startsAt,
endsAt: team.endsAt,
isCustomer,
subscriptionCycle,
pausedAt: team.pausedAt,
pauseStartsAt: team.pauseStartsAt,
pauseEndsAt: team.pauseEndsAt,
isPaused,
cancelledAt: team.cancelledAt,
discount,
});
} catch (error) {
errorhandler(error, res);
}
} else {
// We only allow GET and POST requests
res.setHeader("Allow", ["GET"]);
return res.status(405).end(`Method ${req.method} Not Allowed`);
}
}