import { OrganizationIntegrationPolicy, UpdateOrganizationIntegrationPolicyRequest } from "@opengeni/contracts"; import { type Database } from "./database.js"; export type OrganizationIntegrationPolicyScope = { accountId: string; }; export type OrganizationIntegrationAcquisitionScope = { accountId: string; workspaceId: string; }; /** Trusted application adapter MUST verify canonical human/local organization-admin * provenance or accountScopedApiKeyWorkspaceAuthority (exact account + workspace:admin). * This callback is a server dependency, never deserialized request data. The returned * subject alone is NOT authentication. DB checks below are live authority fences only. */ export type AuthorizeOrganizationIntegrationPolicyAdministration = () => Promise<{ accountId: string; subjectId: string; }>; /** * The organization's current integration policy for a serving-time filter * (what an acquisition in this organization would be allowed to add). A plain * read under the organization's own RLS scope: it takes no policy fence and is * NOT an acquisition guard. Acquisitions keep using * `withOrganizationIntegrationPolicyFence`. */ export declare function readOrganizationIntegrationPolicyForServing(db: Database, inputScope: OrganizationIntegrationPolicyScope): Promise; export declare function getOrganizationIntegrationPolicy(db: Database, inputScope: OrganizationIntegrationPolicyScope, authorize: AuthorizeOrganizationIntegrationPolicyAdministration): Promise; /** Call before acquiring membership/workspace/credential locks in any enclosing * transaction. The SQL operation owns policy-exclusive -> membership -> admin * row order; it never locks a workspace and rejects acquisition-lock upgrades. */ export declare function updateOrganizationIntegrationPolicy(db: Database, inputScope: OrganizationIntegrationPolicyScope, input: UpdateOrganizationIntegrationPolicyRequest, authorize: AuthorizeOrganizationIntegrationPolicyAdministration): Promise; /** Internal serialization primitive, NOT acquisition authorization. Authenticate * the caller normally. A callback may first return an exact completed receipt; * before any new claim, uncommitted progress, or commit it MUST assert the trusted * integration classification against the supplied runtime-frozen policy snapshot. * Do not put network operations or retries inside this transaction. * * Requires read committed isolation. The shared policy fence precedes EVERY * organization-membership, workspace/tenancy, and credential lock. In particular, * persistProviderOAuthConnection may take the membership fence inside acquire. * Policy writers take exclusive policy -> membership -> live administrator rows, * and never workspace rows. Ordinary connection lifecycle writers do not take * the policy fence. A caller passing an existing transaction must honor this * prefix. Never administer policy inside or after an acquisition in that transaction: * the SQL writer rejects shared-to-exclusive upgrades rather than risking deadlock. * All final persistence must use tx, never a separate connection. No automatic * retries: external effects cannot be rolled back. For slow external preparation, * preflight separately and use this guard for final persistence. Existing execution, * refresh, credential lifecycle, and cleanup do not belong behind this guard. */ export declare function withOrganizationIntegrationPolicyFence(db: Database, inputScope: OrganizationIntegrationAcquisitionScope, run: (tx: Database, policy: OrganizationIntegrationPolicy) => Promise): Promise; /** New acquisitions always assert before effects and before returning to commit. * The immutable snapshot stays authoritative through commit: the shared fence * excludes policy writers and the SQL writer rejects same-transaction upgrades. * Receipt-aware callers instead use withOrganizationIntegrationPolicyFence and * assert only after distinguishing completed replay from new workflow progress. */ export declare function withOrganizationIntegrationAcquisition(db: Database, inputScope: OrganizationIntegrationAcquisitionScope, integrationKeys: readonly (string | null)[], acquire: (tx: Database) => Promise): Promise;