refactor(sharing): read and judge grants from a leaf module

lib/sharing/grants.ts held both the grant transitions and the predicates
every reader asks (state, level, scope, the live grant for a pair). The
transitions reach into the managed-profile lifecycle and the OAuth connect
target, and both of those read a live grant, so grants, lifecycle and
connect-target formed an import cycle.

The predicates, findActiveGrant and touchGrantUsage move verbatim to
lib/sharing/grant-access.ts, which imports only the database client and
the scope vocabulary. Importers and the mocks that replaced those
functions point at the new module. Runtime import cycles fall from 7 to 6.
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 11:02:10 +02:00
1 parent e84b80ee3c
commit 78ac2c5aeb
27 files changed
+315 -296

No files matched your search

@@ -9,7 +9,7 @@ const { findUnique, update, findActiveGrant, auditLog } = vi.hoisted(() => ({
vi.mock("@/lib/db", () => ({ prisma: { user: { findUnique, update } } }));
vi.mock("@/lib/auth/audit", () => ({ auditLog }));
vi.mock("@/lib/sharing/grants", () => ({
vi.mock("@/lib/sharing/grant-access", () => ({
findActiveGrant,
grantAllows: (
grant: { access: string; revokedAt: Date | null },
@@ -19,7 +19,7 @@
import { prisma } from "@/lib/db";
import { Prisma } from "@/generated/prisma/client";
import { auditLog } from "@/lib/auth/audit";
import { findActiveGrant, grantAllows } from "@/lib/sharing/grants";
import { findActiveGrant, grantAllows } from "@/lib/sharing/grant-access";
import type { OAuthKitProvider } from "./token";
export type CallbackActorVerdict =