import { type Permission } from "@opengeni/contracts"; import { ExternalIdentity, type AddExternalWorkspaceMemberRequest, type CancelExternalWorkspaceMemberGrantRequest, type UpdateExternalWorkspaceMemberRequest, type ExternalIdentityReference } from "@opengeni/contracts/external-identities"; import { type Database } from "./database.js"; type ServiceScope = { organizationId: string; actorSubjectId: string; }; export declare function lookupExternalIdentity(db: Database, scope: ServiceScope, identity: ExternalIdentityReference): Promise<{ found: false; } | { found: true; subjectId: string; organizationMembershipId: string; identityStatus: "active" | "disabled" | "revoked"; identityAuthorizationRevision: number; membershipStatus: "active" | "provisioning" | "revoked" | "suspended"; membershipAuthorizationRevision: number; }>; /** One keyed grant. An operation replay never restores a removed/reduced row. */ export declare function addExternalWorkspaceMemberOperation(db: Database, scope: ServiceScope & { workspaceId: string; }, request: AddExternalWorkspaceMemberRequest & { operationId: string; }): Promise<{ id: string; accountId: string; source: string; externalId: string; subjectId: string; organizationMembershipId: string; personalWorkspaceId: string; status: "active" | "disabled" | "revoked"; authorizationRevision: number; }>; /** SDK-provisioned per-user workspaces stay single-user: never auto-admitted. */ export declare const USER_ISOLATION_WORKSPACE_SOURCE_PREFIX = "opengeni-sdk:user-isolation:"; /** * First-use membership for an organization key acting as an external user * (`asUser`). This is the explicit keyed onboarding effect, not new authority: * the same organization lifecycle fence, the same live key check * (`members:manage`, or a legacy `workspace:admin` key, holding every requested * permission, with the workspace in the key's scope), the same in-database * identity re-check (`ensure_external_identity` locks the identity and its * organization membership and requires both active), and the same receipt and * lifecycle event attributed to the key. It only inserts a missing row (insert * ... on conflict do nothing): an existing membership is returned unchanged. * A removal stamped after `revocationWatermark` (read under the same fence * when the request authenticated) wins exactly as for a stated membership: * the request is `superseded` and creates nothing. A request that * authenticates after the removal creates the member again, because the host * owns its users. Personal and SDK per-user (`opengeni-sdk:user-isolation:*`) * workspaces are refused. Concurrent first requests serialize on the * organization fence. */ export declare function ensureExternalWorkspaceMemberOnFirstUse(db: Database, scope: ServiceScope & { workspaceId: string; }, input: { subjectId: string; identity: { source: string; externalId: string; }; permissions: readonly Permission[]; revocationWatermark: string; }): Promise<"created" | "existing" | "superseded">; /** The native removal owns all teardown; this wrapper adds an immutable causal * fence even when an earlier grant has not reached the database yet. */ export declare function cancelExternalWorkspaceMemberGrant(db: Database, scope: ServiceScope & { workspaceId: string; membershipId: string; }, request: CancelExternalWorkspaceMemberGrantRequest): Promise<{ removed: boolean; replay: boolean; fencedGrantOperationId: string; }>; /** One keyed permission update of an existing external member's workspace * access. The database applies the effect under the organization fence and * advances the member's authorization revision when the set narrows, so live * authority snapshots re-check; nothing is cancelled or torn down. A replay * returns the original receipt even after later changes. */ export declare function updateExternalWorkspaceMemberOperation(db: Database, scope: ServiceScope & { workspaceId: string; membershipId: string; }, request: UpdateExternalWorkspaceMemberRequest): Promise<{ subjectId: string; organizationMembershipId: string; permissions: ("account:admin" | "account:read" | "agents:manage" | "agents:read" | "api_keys:manage" | "artifacts:publish" | "artifacts:read" | "billing:manage" | "billing:read" | "capabilities:manage" | "codemode:call" | "connections:personal" | "connections:read" | "connections:write" | "documents:manage" | "documents:search" | "enrollments:manage" | "enrollments:read" | "environments:manage" | "environments:use" | "files:read" | "files:upload" | "files:write" | "github:manage" | "github:use" | "goals:manage" | "mcp_servers:attach" | "members:manage" | "rigs:manage" | "rigs:use" | "scheduled_tasks:manage" | "scheduled_tasks:run" | "secrets:list" | "secrets:read" | "secrets:use" | "secrets:write" | "sessions:control" | "sessions:create" | "sessions:read" | "stream:acknowledge" | "stream:control" | "stream:view" | "terminal:attach" | "tool_credentials:write" | "usage_allowances:manage" | "variable-sets:attach" | "variable-sets:list" | "variable-sets:manage" | "variable-sets:read" | "variable-sets:use" | "variable-sets:write" | "workspace:admin" | "workspace:create" | "workspace:read")[]; narrowed: boolean; replay: boolean; }>; /** Revocation markers order an app's revoke against requests that state a * membership. Both run under the organization membership fence, so the last * value read there when a request authenticates is a strict watermark: every * revoke committed before it is at or below it, every later revoke above. */ export declare function readExternalWorkspaceRevocationWatermark(tx: Database): Promise; /** The audit reason recorded on receipts written for a stated membership. */ export declare const STATED_EXTERNAL_MEMBERSHIP_REASON = "membership stated by request"; /** A stated narrowing would leave the workspace without an administering member. */ export declare class StatedExternalMembershipLastAdminError extends Error { constructor(); } export type StatedExternalWorkspaceMembershipOutcome = /** The stored grant already equals the stated one; nothing was written. */ "unchanged" | "created" | "updated" /** The app revoked this member after the request authenticated, so the * request's older statement writes nothing and the stored state stands. */ | "superseded"; /** * Make an external member's grant in one shared workspace exactly the * permissions its app stated on this request. The same authority as the * keyed external-members grant and update: the organization lifecycle fence, * the live key check (`members:manage`, or a legacy `workspace:admin` key, * covering every stated permission under its policy, with the workspace in * scope), the database's own grant ceiling (literal `secrets:read`, no * permission outside a non-admin key), the identity's active status, and the * same receipts and lifecycle events attributed to the key, with * {@link STATED_EXTERNAL_MEMBERSHIP_REASON} as the reason. Narrowing advances * the member's authorization revision exactly like the keyed update. * * Writes only when the stored grant differs, after re-reading it under the * fence, so concurrent equal statements write once. A revoke stamped after * `revocationWatermark` (read when the request authenticated) wins: the * statement is `superseded` and nothing is created or changed. Never narrows * the workspace's last administering member. Personal and SDK per-user * workspaces are refused (42501). */ export declare function applyStatedExternalWorkspaceMembership(db: Database, scope: ServiceScope & { workspaceId: string; }, input: { identity: ExternalIdentity; permissions: readonly Permission[]; revocationWatermark: string; }): Promise; export {};