import { type Database } from "./database.js"; /** * THE canonical live-workspace-authority resolver for one exact subject, run on * a handle that is ALREADY inside the caller's transaction with that subject's * RLS context applied. * * `getWorkspaceGrant` is a bare `workspace_memberships` join and is therefore * NOT a complete authority answer: a managed human's personal workspace * deliberately has no row in that table (migration 0219 raises on one), so its * owner's access is the `organization_memberships.personal_workspace_id` * pointer instead. Any seam that re-derives "does this subject still hold * workspace authority here" from that bare join denies the one human who always * belongs. This module exists so that rule has exactly one implementation. * * Seams that must serialize the answer with their own writes — session listing, * session pins, the composer draft — call this variant so the read and the write * share one transaction snapshot and one advisory fence. Seams that need to ask * about a subject that is NOT the caller call * {@link namedSubjectHasLiveWorkspaceAuthority} (`@opengeni/db`), which is a thin * scope wrapper over exactly this body. * * True when the subject currently holds workspace authority the same way the * route-time access builder derives it: a `workspace_memberships` row whose * owning organization membership (when one exists) is active, or an active * organization membership whose personal-workspace pointer is exactly this * workspace. Never infers authority any other way; a deleted membership row and * a suspended/revoked organization membership are both false. Only the * membership's own `personal_workspace_id` counts as stated authority — nothing * is read from `created_by`, a default workspace, a resource name, or current * access. * * # This function is NOT an authorization. Read this before relying on it. * * It answers "does subject X hold authority over workspace W". It does NOT * establish that the caller is X. Nothing here authenticates anybody. * * The scope assertion below is a **consistency check, not an authorization**. * It prevents one thing: a caller naming a third-party subject while its * transaction is scoped to someone else. It cannot detect a caller that scoped * the transaction to an attacker-chosen subject in the first place, because * `withWorkspaceSubjectRls(db, workspaceId, subjectId, ...)` takes that subject * from its argument too. At today's three call sites both sides come from the * same variable, so the check is a tautology there and fires only if a future * refactor makes them diverge. Treat it as a tripwire against that refactor — * never as evidence that the subject was authenticated. * * **The actual authorization for the personal-workspace exception lives in the * API layer**: `AccessGrantAuthorization.canonicalManagedHumanSession` * (`@opengeni/core`), stamped only where a Better Auth cookie was verified. A * caller that has not proven that must not enable the exception. If you are * adding a caller, that stamp is the part you have to get right; this function * will happily answer `true` for any subject you scope a transaction to. * * Persisted `external_user:` subjects also have an organization membership and * an exact Personal pointer. They use the same consistency check only after the * API's dedicated verified external proof, never a native-cookie stamp. Other * service/configured/local subjects retain the plain membership answer. */ export declare function subjectHasLiveWorkspaceAuthorityInScope(scopedDb: Database, input: { accountId: string; workspaceId: string; subjectId: string; }): Promise; /** * The applied subject GUC, or `""` when none is set. `""` is the canonical * "unset" for this GUC: `current_subject_id()` is * `nullif(current_setting('opengeni.subject_id', true), '')` (0239 precedent), so * a caller restoring `""` genuinely clears it rather than pinning an empty * subject. Never throws, so it is safe for capturing a prior value that may * legitimately be absent. */ export declare function rlsSubjectIdOrEmpty(scopedDb: Database): Promise; /** * The tenant account of the caller's ALREADY-applied RLS scope. `withRlsContext` * sets and read-back-verifies this GUC on the pinned backend before running the * scoped body, so it is exact rather than a re-derivation — which lets a seam * that only received a workspace id consult * {@link subjectHasLiveWorkspaceAuthorityInScope} without a second round trip to * resolve the account. */ export declare function accountIdInRlsScope(scopedDb: Database): Promise;