import { type OrganizationConnectorLogin } from "@opengeni/contracts"; import { type Database } from "./database.js"; import * as schema from "./schema.js"; /** * Organization connectors (docs/design/ownership-and-reach.md, OR-11). An * organization owner or admin adds an MCP connector once and chooses which * workspaces it reaches; row security serves each workspace exactly the rows * that reach it (packages/db/drizzle/1175_organization_connectors.sql). * * Administration runs without a workspace, as the acting person, and the * database checks that person is a live organization owner or admin. Turning * one on (adding it, or saving it while active) holds the organization's * integration policy fence and must be allowed by that policy, as a * workspace's own MCP setup is. */ export type OrganizationConnectorRow = typeof schema.organizationConnectors.$inferSelect; export type { OrganizationApiIntegrationDefinition, OrganizationMcpServerDefinition, } from "./schema.js"; /** An API organization connector's reviewed definition; null for an MCP server. */ export declare function organizationApiIntegrationDefinition(row: Pick): schema.OrganizationApiIntegrationDefinition | null; /** A trusted server callback that has already authenticated the acting person. */ export type AuthorizeOrganizationConnectorAdministration = () => Promise<{ accountId: string; subjectId: string; }>; export declare class OrganizationConnectorWorkspaceNotInOrganizationError extends Error { constructor(); } /** * The integration policy key a connector is checked against, the same key a * workspace setup of it checks: every MCP server is `custom:mcp`; an API * integration is its curated definition id, or `custom:`. */ export declare function organizationConnectorIntegrationKey(row: Pick): string; /** How turns sign in, read from what the setup stores. */ export declare function organizationConnectorLogin(config: Record): OrganizationConnectorLogin; /** * The names an organization key is sent under (headers, or an API * integration's header, query or cookie names). The encrypted values never * leave the database layer through this. */ export declare function organizationConnectorHeaderNames(config: Record): string[]; declare function withAdministrator(db: Database, accountId: string, authorize: AuthorizeOrganizationConnectorAdministration, use: (tx: Database, subjectId: string) => Promise): Promise; /** * Runs `use` as a live organization owner or admin, with no workspace: the * context organization-level settings (connectors, auto-connect issuers) are * written in. */ export declare const withOrganizationAdministrator: typeof withAdministrator; /** * Checks the acting person is a live organization owner or admin, for work * that must not start otherwise (such as contacting a server before saving it). */ export declare function assertOrganizationConnectorAdministrator(db: Database, scope: { accountId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export declare function listOrganizationConnectors(db: Database, scope: { accountId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export declare function getOrganizationConnector(db: Database, scope: { accountId: string; connectorId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export type NewOrganizationConnector = { /** Defaults to "mcp". */ kind?: "mcp" | "api"; capabilityId: string; customDefinition: OrganizationConnectorRow["customDefinition"]; config: Record; metadata: Record; allowedWorkspaceIds: string[] | null; allowPersonalWorkspaces: boolean; }; /** Unique per organization and capability: a second add of the same connector is a 23505. */ export declare function insertOrganizationConnector(db: Database, scope: { accountId: string; }, input: NewOrganizationConnector, authorize: AuthorizeOrganizationConnectorAdministration): Promise; export type OrganizationConnectorChange = { expectedGeneration: number; allowedWorkspaceIds?: string[] | null; allowPersonalWorkspaces?: boolean; status?: "active" | "disabled"; /** The complete new config, built from the row read at `expectedGeneration`. */ config?: Record; metadata?: Record; }; /** Null when the connector is gone or changed since `expectedGeneration`. */ export declare function updateOrganizationConnector(db: Database, scope: { accountId: string; connectorId: string; }, change: OrganizationConnectorChange, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** False when the connector is already gone. Workspaces stop serving it at once. */ export declare function deleteOrganizationConnector(db: Database, scope: { accountId: string; connectorId: string; }, authorize: AuthorizeOrganizationConnectorAdministration): Promise; /** * The active organization connectors of one kind (MCP servers unless asked) * that reach `workspaceId`, whatever the workspace's own settings say * (callers apply "the workspace's own setup wins"). Row security decides * reach; this read only narrows to active rows of that kind. */ export declare function listOrganizationConnectorsReachingWorkspace(db: Database, workspaceId: string, kind?: "mcp" | "api"): Promise;