/** * Organization subscription settings with lockable workspace overrides and * the organization overview (design docs/design/subscription-core-2026-10-07.md * 3.3, contract SUB-SET-01..05). * * Values are read through `subscription_effective_settings`, the SQL * resolver the core enforces with; nothing here resolves a setting itself. * Authority is the database's: organization rows are written only by * organization administrators (the settings manager policy), workspace rows * by workspace or organization administrators, and a Personal workspace's row * by its verified owner (1233); a locked setting cannot be widened by anyone * (the 0724 guard). The checks below only turn those * refusals into typed errors before anything is written. */ import { type SubscriptionSettingKey, type SubscriptionSettingsView, type SubscriptionSettingValues } from "@opengeni/subscriptions"; import { type Database } from "./database.js"; import { type PersonalWorkspaceOwnerSettingsInput } from "./personal-workspace-owner-settings.js"; export { SubscriptionSettingsBusyError, SubscriptionSettingsLockedError, subscriptionSettingLockRefusal, } from "./subscription-settings-lock.js"; export type SubscriptionRotationMode = "spread" | "primary_first"; /** The caller may not read or write these settings. */ export declare class SubscriptionSettingsForbiddenError extends Error { constructor(message?: string); } /** The caller's expected version is not the stored one. */ export declare class SubscriptionSettingsVersionConflictError extends Error { readonly currentVersion: number; constructor(currentVersion: number); } /** * A Personal workspace whose owner isn't changing it as themselves (or one * without an owner row, like a local one) follows the organization. */ export declare class SubscriptionSettingsPersonalWorkspaceError extends Error { constructor(); } /** The patch is not a valid settings change. */ export declare class SubscriptionSettingsInvalidError extends Error { constructor(message: string); } export type OrganizationSubscriptionSettingsState = { organizationId: string; /** Every value set: the organization row, with the resolver's defaults for absent values. */ values: SubscriptionSettingValues; locked: SubscriptionSettingKey[]; /** 0 while the organization has no settings row. */ version: number; updatedAt: string | null; }; export type OrganizationSubscriptionSettingsPatch = { crossProviderFailover?: boolean | undefined; /** Replaces the organization's fallback order. */ fallbackOrder?: Record | undefined; personalConnectionsAllowed?: boolean | undefined; personalFallbackAllowed?: boolean | undefined; /** Per provider on the shared core; the provider's primary connection is unchanged. */ rotation?: Record | undefined; /** Replaces the set of locked settings. */ locked?: SubscriptionSettingKey[] | undefined; }; /** A workspace row as stored: null inherits the organization value. */ export type WorkspaceSubscriptionSettingOverrides = { rotation: Record | null; providers: Record | null; crossProviderFailover: boolean | null; fallbackOrder: Record | null; personalConnectionsAllowed: boolean | null; personalFallbackAllowed: boolean | null; }; export type WorkspaceSubscriptionSettingsState = SubscriptionSettingsView & { workspaceId: string; locked: SubscriptionSettingKey[]; overrides: WorkspaceSubscriptionSettingOverrides; /** 0 while the workspace has no settings row. */ version: number; updatedAt: string | null; /** Whether the caller administers this workspace's settings (the database decides writes). */ canEdit: boolean; }; /** * A workspace change: `null` resets a setting to the organization value. A * map-valued setting changes entry by entry (D-25); a `null` entry resets * that entry. */ export type WorkspaceSubscriptionSettingsPatch = { crossProviderFailover?: boolean | null | undefined; personalConnectionsAllowed?: boolean | null | undefined; personalFallbackAllowed?: boolean | null | undefined; fallbackOrder?: Record | null | undefined; rotation?: Record | null | undefined; }; export type SubscriptionSettingsOverviewWorkspace = SubscriptionSettingsView & { workspaceId: string; name: string; }; export type SubscriptionSettingsOverviewState = { organization: OrganizationSubscriptionSettingsState; workspaces: SubscriptionSettingsOverviewWorkspace[]; /** The cursor for the next page, or null after the last workspace. */ nextCursor: string | null; }; /** Who a settings write should wake (capacity waiters recheck their placement). */ export type SubscriptionSettingsWake = { accountId: string; reason: typeof SUBSCRIPTION_SETTINGS_WAKE_REASON; workspaceIds?: string[]; }; export declare const SUBSCRIPTION_SETTINGS_WAKE_REASON = "core_settings_changed"; export declare function readOrganizationSubscriptionSettings(db: Database, input: { organizationId: string; actorSubjectId: string; }): Promise; /** * Update organization settings and locks in one transaction. Locking a * setting clears its workspace overrides (the 0724 trigger). A lock change * first queues for the organization's exclusive settings lock and never * waits for a workspace row while holding it; a row held elsewhere makes it * retry, and then answer busy. */ export declare function updateOrganizationSubscriptionSettings(db: Database, input: { organizationId: string; actorSubjectId: string; patch: OrganizationSubscriptionSettingsPatch; expectedVersion?: number; }): Promise<{ settings: OrganizationSubscriptionSettingsState; wake: SubscriptionSettingsWake | null; }>; type WorkspaceSubjectInput = { accountId: string; workspaceId: string; subjectId: string; } & PersonalWorkspaceOwnerSettingsInput; /** A workspace's effective settings, sources, locks and stored overrides. */ export declare function readWorkspaceSubscriptionSettings(db: Database, input: WorkspaceSubjectInput): Promise; /** * Change a workspace's overrides. Refuses (before writing) a change that * would widen a locked setting; the database guard refuses it again if a lock * lands concurrently. Resetting an override is always allowed. */ export declare function updateWorkspaceSubscriptionSettings(db: Database, input: WorkspaceSubjectInput & { patch: WorkspaceSubscriptionSettingsPatch; expectedVersion?: number; }): Promise<{ settings: WorkspaceSubscriptionSettingsState; wake: SubscriptionSettingsWake | null; }>; /** * Every shared workspace's effective settings with one source per setting * (SUB-SET-05), read through the same SQL resolver the core enforces with. * Organization administrators only. Personal workspaces are not listed, as * in the organization administration overview. Ordered by workspace id and * paged by `after` (the previous page's `nextCursor`). */ export declare function readSubscriptionSettingsOverview(db: Database, input: { organizationId: string; actorSubjectId: string; after?: string | null; limit?: number; }): Promise;