Files
triggerdotdev--trigger.dev/apps/webapp/app/models/admin.server.ts
Eric Allam 5ba8557a51 chore(webapp,core): remove the end-of-life v3 (engine V1) execution stack (#4236)
## Summary

v3 (the engine that ran the SDK v3 era, internally
`RunEngineVersion.V1`) is end-of-life. Following the removal of the v3
execution apps
([#4194](https://github.com/triggerdotdev/trigger.dev/pull/4194)) and
the legacy dev websocket
([#4198](https://github.com/triggerdotdev/trigger.dev/pull/4198)), this
removes the remaining v3 execution stack from the server.

Clients still on v3 (an old SDK or CLI that has not upgraded) keep
getting a clear "upgrade to v4" response. Triggers, batch triggers,
reschedules, and deploys that resolve to v3 are rejected with a graceful
4xx pointing at the migration guide, never a 5xx, so a stale client
cannot affect server health. Self-hosted instances still running v3
should stay on the 4.5.x release line until they migrate.

## What is removed

- The MarQS queue and its shared/dev queue consumers.
- The v3 socket.io namespaces (coordinator, provider, shared-queue) and
the v3 run lifecycle services (attempt, checkpoint, and batch-resume).
- The graphile-worker background job system; all live jobs already run
on `@trigger.dev/redis-worker`.
- The `DEPRECATE_V3_ENABLED` flag: v3 is now rejected unconditionally,
so the flag is gone.
- Unused v3 exports from `@trigger.dev/core` (the `v3/zodNamespace`
subpath and the legacy socket message catalogs) and the now-dead MarQS
environment variables.

## What stays

The v4 engine is untouched. The graceful v3 rejection boundary stays,
`determineEngineVersion` still detects a v3 project so it can reject it,
and the batch service plus batch-completion worker stay for current
clients. Live queue concurrency limits and metrics now read from the v4
run engine instead of MarQS, and a brand-new dev environment now
defaults to v4.



## Dependency cleanup

Removes webapp dependencies left unused by this change: `seedrandom` and
`semver` (only the removed v3 code used them) plus a set that was
already dead, their orphaned `@types` packages, and two dead files. Adds
a `knip:deps` script and a `knip.json` config so unused dependencies can
be found the same way going forward.
2026-07-13 11:32:06 +01:00

284 lines
6.2 KiB
TypeScript

import { redirect } from "@remix-run/server-runtime";
import { prisma } from "~/db.server";
import { logger } from "~/services/logger.server";
import type { SearchParams } from "~/routes/admin._index";
import {
clearImpersonationId,
commitImpersonationSession,
getImpersonationId,
setImpersonationId,
} from "~/services/impersonation.server";
import { authenticator } from "~/services/auth.server";
import { requireUser } from "~/services/session.server";
import { extractClientIp } from "~/utils/extractClientIp.server";
const pageSize = 20;
export async function adminGetUsers(userId: string, { page, search }: SearchParams) {
page = page || 1;
search = search ? decodeURIComponent(search) : undefined;
const user = await prisma.user.findUnique({
where: {
id: userId,
},
});
if (user?.admin !== true) {
throw new Error("Unauthorized");
}
const users = await prisma.user.findMany({
select: {
id: true,
name: true,
email: true,
admin: true,
createdAt: true,
displayName: true,
orgMemberships: {
select: {
organization: {
select: {
title: true,
slug: true,
deletedAt: true,
},
},
},
},
},
where: search
? {
OR: [
{
name: {
contains: search,
mode: "insensitive",
},
},
{
email: {
contains: search,
mode: "insensitive",
},
},
{
orgMemberships: {
some: {
organization: {
title: {
contains: search,
mode: "insensitive",
},
},
},
},
},
{
orgMemberships: {
some: {
organization: {
slug: {
contains: search,
mode: "insensitive",
},
},
},
},
},
],
}
: undefined,
orderBy: {
createdAt: "desc",
},
take: pageSize,
skip: (page - 1) * pageSize,
});
const totalUsers = await prisma.user.count();
return {
users,
page,
pageCount: Math.ceil(totalUsers / pageSize),
filters: {
search,
},
};
}
export async function adminGetOrganizations(userId: string, { page, search }: SearchParams) {
page = page || 1;
search = search ? decodeURIComponent(search) : undefined;
const user = await prisma.user.findUnique({
where: {
id: userId,
},
});
if (user?.admin !== true) {
throw new Error("Unauthorized");
}
const organizations = await prisma.organization.findMany({
select: {
id: true,
slug: true,
title: true,
isActivated: true,
deletedAt: true,
members: {
select: {
user: {
select: {
email: true,
},
},
},
},
},
where: search
? {
OR: [
{
members: {
some: {
user: {
name: {
contains: search,
mode: "insensitive",
},
},
},
},
},
{
members: {
some: {
user: {
email: {
contains: search,
mode: "insensitive",
},
},
},
},
},
{
slug: {
contains: search,
mode: "insensitive",
},
},
{
title: {
contains: search,
mode: "insensitive",
},
},
{
id: {
contains: search,
mode: "insensitive",
},
},
],
}
: undefined,
orderBy: {
createdAt: "desc",
},
take: pageSize,
skip: (page - 1) * pageSize,
});
const totalOrgs = await prisma.organization.count();
return {
organizations,
page,
pageCount: Math.ceil(totalOrgs / pageSize),
filters: {
search,
},
};
}
export async function redirectWithImpersonation(
request: Request,
userId: string,
path: string,
currentUser?: { id: string; admin: boolean }
) {
const user = currentUser ?? (await requireUser(request));
if (!user.admin) {
throw new Error("Unauthorized");
}
const xff = request.headers.get("x-forwarded-for");
const ipAddress = extractClientIp(xff);
try {
await prisma.impersonationAuditLog.create({
data: {
action: "START",
adminId: user.id,
targetId: userId,
ipAddress,
},
});
} catch (error) {
logger.error("Failed to create impersonation audit log", {
error,
adminId: user.id,
targetId: userId,
});
}
const session = await setImpersonationId(userId, request);
return redirect(path, {
headers: { "Set-Cookie": await commitImpersonationSession(session) },
});
}
export async function clearImpersonation(request: Request, path: string) {
const authUser = await authenticator.isAuthenticated(request);
const targetId = await getImpersonationId(request);
if (targetId && authUser?.userId) {
const xff = request.headers.get("x-forwarded-for");
const ipAddress = extractClientIp(xff);
try {
await prisma.impersonationAuditLog.create({
data: {
action: "STOP",
adminId: authUser.userId,
targetId,
ipAddress,
},
});
} catch (error) {
logger.error("Failed to create impersonation audit log", {
error,
adminId: authUser.userId,
targetId,
});
}
}
const session = await clearImpersonationId(request);
return redirect(path, {
headers: {
"Set-Cookie": await commitImpersonationSession(session),
},
});
}