Files
zeekay caad90bc04 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

336 lines
8.4 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import {
UpdateWorkflowRequestSchema,
formatZodError,
} from "@/features/workflows/lib/validation";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { customAlphabet } from "nanoid";
import { getServerSession } from "next-auth";
import { z } from "zod";
import prisma from "@/lib/prisma";
import { CustomUser } from "@/lib/types";
// GET /app/(ee)/api/workflows/[workflowId]?teamId=xxx - Get single workflow with details
export async function GET(
req: NextRequest,
{ params }: { params: { workflowId: string } },
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { workflowId } = params;
const searchParams = req.nextUrl.searchParams;
const teamId = searchParams.get("teamId");
if (!teamId) {
return NextResponse.json(
{ error: "teamId parameter is required" },
{ status: 400 },
);
}
// Validate IDs format
const idsValidation = z
.object({
workflowId: z.string().cuid(),
teamId: z.string().cuid(),
})
.safeParse({ workflowId, teamId });
if (!idsValidation.success) {
return NextResponse.json({ error: "Invalid ID format" }, { status: 400 });
}
const userId = (session.user as CustomUser).id;
// Check user is part of the team using userTeam table
const teamAccess = await prisma.userTeam.findUnique({
where: {
userId_teamId: {
userId: userId,
teamId: teamId,
},
},
});
if (!teamAccess) {
return NextResponse.json(
{ error: "Unauthorized to access this team" },
{ status: 403 },
);
}
// Fetch workflow
const workflow = await prisma.workflow.findUnique({
where: {
id: workflowId,
teamId: teamId, // Ensure workflow belongs to the team
},
include: {
entryLink: {
select: {
id: true,
slug: true,
domainSlug: true,
},
},
steps: {
orderBy: { stepOrder: "asc" },
},
},
});
if (!workflow) {
return NextResponse.json(
{ error: "Workflow not found" },
{ status: 404 },
);
}
// Build entry URL
const entryUrl =
workflow.entryLink.domainSlug && workflow.entryLink.slug
? `https://${workflow.entryLink.domainSlug}/${workflow.entryLink.slug}`
: `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${workflow.entryLink.id}`;
return NextResponse.json({
...workflow,
entryUrl,
});
} catch (error) {
console.error("Error fetching workflow:", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 },
);
}
}
// PATCH /app/(ee)/api/workflows/[workflowId]?teamId=xxx - Update workflow
export async function PATCH(
req: NextRequest,
{ params }: { params: { workflowId: string } },
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { workflowId } = params;
const searchParams = req.nextUrl.searchParams;
const teamId = searchParams.get("teamId");
if (!teamId) {
return NextResponse.json(
{ error: "teamId parameter is required" },
{ status: 400 },
);
}
// Validate IDs format
const idsValidation = z
.object({
workflowId: z.string().cuid(),
teamId: z.string().cuid(),
})
.safeParse({ workflowId, teamId });
if (!idsValidation.success) {
return NextResponse.json({ error: "Invalid ID format" }, { status: 400 });
}
const userId = (session.user as CustomUser).id;
// Check user is part of the team using userTeam table
const teamAccess = await prisma.userTeam.findUnique({
where: {
userId_teamId: {
userId: userId,
teamId: teamId,
},
},
});
if (!teamAccess) {
return NextResponse.json(
{ error: "Unauthorized to access this team" },
{ status: 403 },
);
}
const body = await req.json();
// Validate request body
const validation = UpdateWorkflowRequestSchema.safeParse(body);
if (!validation.success) {
return NextResponse.json(
{
error: "Invalid request data",
details: formatZodError(validation.error),
},
{ status: 400 },
);
}
// Check workflow exists and belongs to team
const workflow = await prisma.workflow.findUnique({
where: {
id: workflowId,
teamId: teamId,
},
select: {
id: true,
},
});
if (!workflow) {
return NextResponse.json(
{ error: "Workflow not found" },
{ status: 404 },
);
}
// Update workflow
const updatedWorkflow = await prisma.workflow.update({
where: { id: workflowId },
data: validation.data,
include: {
entryLink: {
select: {
id: true,
slug: true,
domainSlug: true,
},
},
},
});
return NextResponse.json(updatedWorkflow);
} catch (error) {
console.error("Error updating workflow:", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 },
);
}
}
// DELETE /app/(ee)/api/workflows/[workflowId]?teamId=xxx - Delete workflow
export async function DELETE(
req: NextRequest,
{ params }: { params: { workflowId: string } },
) {
try {
const session = await getServerSession(authOptions);
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { workflowId } = params;
const searchParams = req.nextUrl.searchParams;
const teamId = searchParams.get("teamId");
if (!teamId) {
return NextResponse.json(
{ error: "teamId parameter is required" },
{ status: 400 },
);
}
// Validate IDs format
const idsValidation = z
.object({
workflowId: z.string().cuid(),
teamId: z.string().cuid(),
})
.safeParse({ workflowId, teamId });
if (!idsValidation.success) {
return NextResponse.json({ error: "Invalid ID format" }, { status: 400 });
}
const userId = (session.user as CustomUser).id;
// Check user is part of the team using userTeam table
const teamAccess = await prisma.userTeam.findUnique({
where: {
userId_teamId: {
userId: userId,
teamId: teamId,
},
},
});
if (!teamAccess) {
return NextResponse.json(
{ error: "Unauthorized to access this team" },
{ status: 403 },
);
}
// Fetch workflow to check existence and get entryLinkId
const workflow = await prisma.workflow.findUnique({
where: {
id: workflowId,
teamId: teamId,
},
select: {
id: true,
entryLinkId: true,
entryLink: {
select: {
slug: true,
},
},
},
});
if (!workflow) {
return NextResponse.json(
{ error: "Workflow not found" },
{ status: 404 },
);
}
// Generate a random suffix for the deleted slug to free up the original slug
const generateDeletedSuffix = customAlphabet(
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
6,
);
// Delete workflow and entry link in transaction
// Note: Steps and executions will cascade delete via Prisma relations
await prisma.$transaction([
// Delete workflow first (cascade deletes steps and executions)
prisma.workflow.delete({
where: { id: workflowId },
}),
// Soft delete entry link and rename slug so it can be reused
prisma.link.update({
where: { id: workflow.entryLinkId },
data: {
deletedAt: new Date(),
isArchived: true,
...(workflow.entryLink?.slug && {
slug: `${workflow.entryLink.slug}-DELETED-${generateDeletedSuffix()}`,
}),
},
}),
]);
return NextResponse.json({ success: true });
} catch (error) {
console.error("Error deleting workflow:", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 },
);
}
}