/** * Console roles of organization members (`organization_console_roles`, * migration 1511). Owners and admins are always full in Console and have no * row; a member's role is `none` (no row), `viewer` or `editor`. A row names a * member by their `user:` subject, or a pending invitation whose role becomes * the member's when they accept it. * * Authorization lives in the API (`apps/api/src/routes/console-roles.ts`): * only an organization owner or admin, signed in as themselves, writes these * rows, and the API resolves a reader's role before every Console read. Every * change is written to the Console audit log in the same transaction. */ import type { ConsoleMemberRole, ConsoleMemberRoleEntry } from "@opengeni/contracts"; import { type Database } from "./database.js"; export type ConsoleRoleTarget = { subjectId: string; } | { invitationId: string; }; /** * Serializes every Console role write for one person (or invitation) in an * organization: setting a role, clearing it after an organization role change * or offboarding, and applying an accepted invitation's role. A role write * that checks the person's membership does so after taking this lock, so a * concurrent offboarding that clears the role either finishes first (and the * check refuses) or clears it after. */ export declare function lockConsoleRoleTarget(tx: Database, accountId: string, target: ConsoleRoleTarget): Promise; /** The named invitation is not in this organization. */ export declare class ConsoleRoleTargetNotFoundError extends Error { constructor(); } /** A member's Console role in the organization; `none` without a row. */ export declare function getConsoleMemberRole(db: Database, accountId: string, subjectId: string): Promise; /** Every Console role set in the organization (members and pending invitations). */ export declare function listConsoleMemberRoles(db: Database, accountId: string): Promise; /** * Sets a member's or pending invitation's Console role and audits the change * (an unchanged role writes no audit row). The caller checked that the actor * administers the organization. `verifyTarget` runs in the same transaction, * after the target's lock: it checks the person is still a member (or the * invitation still pending), so a concurrent offboarding can't be overtaken. */ export declare function setConsoleMemberRole(db: Database, input: { accountId: string; target: ConsoleRoleTarget; role: ConsoleMemberRole; actorSubjectId: string; actorLabel: string | null; reason?: string; verifyTarget?: (tx: Database) => Promise; }): Promise<{ entry: ConsoleMemberRoleEntry; from: ConsoleMemberRole; changed: boolean; }>; /** * Clears a member's Console role (to `none`) when they had one, for example * when they leave the organization or their organization role changes. * Returns the role they had. */ export declare function clearConsoleMemberRole(db: Database, input: { accountId: string; subjectId: string; actorSubjectId: string; actorLabel: string | null; reason: string; }): Promise; /** * When a person accepts an invitation, their Console role becomes the one it * carried, or none when it carried none (so a role left from an earlier * membership never comes back). Once per invitation: the invitation's row is * marked applied (a row with role none is written for an invitation that had * none), and a replayed acceptance never overwrites a role an admin set * later. Runs in the acceptance's transaction. Returns the role applied, or * null when it was already applied. */ export declare function applyInvitationConsoleRole(db: Database, input: { accountId: string; invitationId: string; subjectId: string; }): Promise; /** * Who started a chat, as recorded at create (`sessions.created_by_*`), or * null when it does not exist. Console test chats are owned by the service * principal that started them (a service principal cannot own a chat as a * member), so this is how the test chat routes find a tester's own chats. */ export declare function getSessionCreator(db: Database, workspaceId: string, sessionId: string): Promise<{ kind: string; subjectId: string | null; } | null>;