-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathregionAccess.server.ts
More file actions
50 lines (45 loc) · 1.47 KB
/
regionAccess.server.ts
File metadata and controls
50 lines (45 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { type Prisma, type WorkloadType } from "@trigger.dev/database";
import { type PrismaClientOrTransaction } from "~/db.server";
import { FEATURE_FLAG } from "./featureFlags";
import { makeFlag } from "./featureFlags.server";
/**
* Resolves whether an org has compute access based on feature flags.
*/
export async function resolveComputeAccess(
prisma: PrismaClientOrTransaction,
orgFeatureFlags: unknown
): Promise<boolean> {
const flag = makeFlag(prisma);
return flag({
key: FEATURE_FLAG.hasComputeAccess,
defaultValue: false,
overrides: (orgFeatureFlags as Record<string, unknown>) ?? {},
});
}
/**
* Builds a visibility filter for non-admin, non-allowlisted users.
* Without compute access, MICROVM regions are excluded entirely.
* With compute access, hidden flag works normally (existing behavior).
*/
export function defaultVisibilityFilter(
hasComputeAccess: boolean
): Prisma.WorkerInstanceGroupWhereInput {
if (hasComputeAccess) {
return { hidden: false };
}
return { hidden: false, workloadType: { not: "MICROVM" } };
}
/**
* Whether a region is accessible given compute access.
* MICROVM regions require compute access; all other types pass through.
*/
export function isComputeRegionAccessible(
region: { workloadType: WorkloadType },
hasComputeAccess: boolean
): boolean {
if (region.workloadType !== "MICROVM") {
return true;
}
// Allow access to any MICROVM region if the org has compute access
return hasComputeAccess;
}