import { PersonalResourceAttachmentSummary, type PersonalResourceAttachmentIntent, USER_RESOURCE_ACTION_BY_KIND, type UserResourceDelegation, type UserResourceKind } from "@opengeni/contracts"; import { type Database } from "./database.js"; import { ClassifiedDatabaseRefusal } from "./persistence-errors.js"; export type UserResourceAuthorityGrant = { grantId: string; targetWorkspaceId: string; targetSessionId: string | null; action: (typeof USER_RESOURCE_ACTION_BY_KIND)[UserResourceKind]; mode: "once" | "session" | "always"; context: "user_private" | "workspace_shared"; authorityEpoch: number | null; generation: number; status: "active" | "consumed" | "revoked" | "expired"; expiresAt: string | null; delegation: UserResourceDelegation; }; export type UserResourceAuthoritySummary = { authorityId: string; resourceKind: UserResourceKind; resourceId: string; originWorkspaceId: string | null; generation: number; status: "active" | "retained" | "revoked"; grants: UserResourceAuthorityGrant[]; }; export type AcceptedTurnPersonalResourceAttachment = { summary: PersonalResourceAttachmentSummary; replay: boolean; }; export declare class PersonalResourceAttachmentAcceptanceError extends ClassifiedDatabaseRefusal { readonly kind: "invalid" | "forbidden" | "conflict" | "stale"; /** Which invalid request: one that selects nothing personal says so. */ readonly invalidReason: "nothing_to_attach" | null; readonly name = "PersonalResourceAttachmentAcceptanceError"; constructor(kind: "invalid" | "forbidden" | "conflict" | "stale", options?: ErrorOptions, /** Which invalid request: one that selects nothing personal says so. */ invalidReason?: "nothing_to_attach" | null); } /** * Issue and freeze the locked session's personal Variable Set/Rig/Connected * Machine closure on * one already-inserted logical turn. The caller owns the surrounding accepted- * work transaction; this helper must never be called as a standalone grant * mutation. */ export declare function acceptTurnPersonalResourceAttachmentInTransaction(db: Database, input: { accountId: string; workspaceId: string; sessionId: string; turnId: string; subjectId: string; intent: PersonalResourceAttachmentIntent & { expectedAuthorityEpoch: number; }; }): Promise; export declare function listSelfUserResourceAuthorities(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; resourceKind: UserResourceKind; cursor?: string | undefined; limit: number; }): Promise<{ authorities: UserResourceAuthoritySummary[]; nextCursor: string | null; }>; /** * Where a person turned their own logins on (D-54): for each of their personal * connections that is turned on in `workspaceId`, the standing grant that does * it. A turned-on login has an active `always` `connection.use` grant for this * workspace. Their Personal workspace needs none; callers decide that. */ export declare function listOwnLoginsTurnedOn(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; }): Promise>; /** * `listOwnLoginsTurnedOn` on a handle already in the owner's scope (its * account, workspace and subject): the same pages and the same answer, * without a scope per page. */ export declare function listOwnLoginsTurnedOnInOwnerScope(scopedDb: Database, input: { accountId: string; workspaceId: string; }): Promise>; export declare function issueSelfUserResourceGrant(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; authorityId: string; resourceKind: UserResourceKind; mode: "session" | "always"; context: "user_private" | "workspace_shared"; sessionId?: string | null; expectedAuthorityEpoch?: number | null; workspaceSharedAcknowledged: boolean; }): Promise; export declare function revokeSelfUserResourceGrant(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; grantId: string; }): Promise<{ grantId: string; generation: number; status: "revoked"; revokedAt: string; }>; export declare function resolveSessionAttemptPersonalResources(db: Database, input: { accountId: string; workspaceId: string; subjectId: string | null; attemptId: string; }): Promise; export type PersonalDocumentAuthority = { authorityId: string; ownerOrganizationMembershipId: string; authorityGeneration: number; }; /** * Create the common organization-user authority before inserting a personal * Document. Returns null for a configured/local or rolling-legacy subject that * has no eligible active organization membership, preserving the existing * workspace-anchored personal lane. Call this inside the same database * transaction as the Document insert so a failed write cannot leave an orphan * authority. */ export declare function createPersonalDocumentAuthority(db: Database, input: { accountId: string; workspaceId: string; subjectId: string; documentId: string; }): Promise;