/** * What a shared subscription connection serves, for any provider on the * shared core: its models and, at organization scope, its reach (the whole * organization, chosen workspaces with the Personal-workspace switch, or * chosen people). Design 5.4 and the 0702 access editor. * * Every shared connection has one owner (D-50, SUB-OWN-04): the * organization, or one shared workspace whose own connection reaches only * that workspace. The organization route reads all of them; it changes a * workspace's own connection only by giving it more reach, which makes it the * organization's. The workspace route reads and edits only the models of the * workspace's own connection. The organization route also lets an exact * personal owner who is an organization administrator explicitly share that * named connection. It never inventories personal connections. * * Every query runs under the caller's own row-level-security context, so the * core tables' policies and the scope guard decide authority. Personal * sharing additionally uses an owner-fenced, versioned database capability. */ import { type SQL } from "drizzle-orm"; import type { Database } from "../database.js"; import { type SubscriptionCoreProvider } from "./provider.js"; export type SubscriptionCoreAccessPolicy = { allowedModels: string[] | null; /** The shared workspaces it reaches; null for every shared workspace, including new ones. */ allowedWorkspaces: string[] | null; allowPersonalWorkspaces: boolean; /** The chosen people (organization membership ids), or null when not limited to people. */ allowedPeople?: string[] | null | undefined; sharePersonal?: true | undefined; /** * Organization route: an explicit move of a workspace's own connection to the * organization (D-52). Required before it can serve every shared workspace, * Personal workspaces or chosen people; the workspace's administrators then * stop managing it. */ moveToOrganization?: true | undefined; version: number; }; export type SubscriptionCoreAccessTarget = { accountId: string; /** null: the organization route. */ workspaceId: string | null; subjectId: string; connectionId: string; }; export type SubscriptionCoreAccess = { policy: SubscriptionCoreAccessPolicy & { allowedPeople: string[] | null; }; /** The workspace whose own connection this is, as a list (organization route only). */ localWorkspaceIds: string[]; /** The workspace whose own connection this is, if any (organization route only). */ managedByWorkspaceId: string | null; /** * Whether the connection may be limited to chosen people (organization * route, an organization connection). */ peopleSupported: boolean; personalSharingSupported?: boolean; }; /** A requested access policy names a workspace outside the organization's shared workspaces. */ export declare class SubscriptionCoreAccessWorkspaceNotInOrganizationError extends Error { constructor(); } /** A requested access policy names someone who is not an active person of the organization. */ export declare class SubscriptionCoreAccessPersonNotInOrganizationError extends Error { constructor(); } /** People can't be added: the organization has more members than can be listed. */ export declare class SubscriptionCoreAccessPeopleUnlistableError extends Error { constructor(); } /** The requested combination cannot be saved (for example people together with workspaces). */ export declare class SubscriptionCoreAccessInvalidError extends Error { constructor(message: string); } /** The viewer can read a connection's access but may not change it. */ export declare class SubscriptionCoreAccessForbiddenError extends Error { constructor(); } /** * A workspace's own connection was asked to serve every shared workspace, * Personal workspaces or chosen people without moving it to the organization. */ export declare class SubscriptionCoreAccessMoveRequiredError extends Error { constructor(); } /** A workspace route tried to add a workspace its person doesn't administer. */ export declare class SubscriptionCoreAccessWorkspaceNotAdministeredError extends Error { constructor(); } /** * Runs an access route's reads and writes: under the subject's workspace RLS * for a workspace's connection, otherwise in the organization scope once the * subject's organization administration overview is readable, or the request * proved account administration for this organization. */ export declare function withSubscriptionCoreAccessScope(db: Database, target: SubscriptionCoreAccessTarget, use: (tx: Database) => Promise): Promise; /** * A shared connection the organization administers: one no workspace manages, * or one a shared workspace manages (its delegated manager, design 5.4). A * shared connection managed by a Personal workspace cannot be produced by any * writer; if one existed it is not an organization account (fail closed). * Organization context only (the shared-workspace inventory refuses a * workspace context). `alias` names the `subscription_connections` row, or * none for unqualified columns. */ export declare function organizationAdministeredConnection(alias?: string): SQL; /** * The workspaces the person in `target` administers in its organization, as * the share policy sees them from that workspace: the ones a workspace's own * connection can be given to from its route (D-52). Personal workspaces have * no memberships, so they are never among them. */ export declare function listSubscriptionCoreAdministeredWorkspaceIds(db: Database, target: { accountId: string; workspaceId: string; subjectId: string; }): Promise; /** * Removes another workspace's own connection from the workspace in `target` * (D-52): that workspace's administrators can stop using it but can't change * it. True when it was removed; null when no such connection serves this * workspace. A person who can see it but isn't an administrator here is * refused. */ export declare function removeSubscriptionCoreConnectionFromWorkspace(db: Database, provider: SubscriptionCoreProvider, target: SubscriptionCoreAccessTarget & { workspaceId: string; }): Promise; /** * A shared connection's access. The organization route reads any shared * connection of the provider, the workspace route one that workspace manages. */ export declare function readSubscriptionCoreConnectionAccess(db: Database, provider: SubscriptionCoreProvider, target: SubscriptionCoreAccessTarget): Promise; /** * Save what a shared connection serves. Null when the connection is gone or * its access changed since `policy.version` was read (or a form that cannot * show the current people choice saved over it). * * At organization scope the connection's scope, its workspace and people * assignments and the reach for workspaces created later change together, in * one transaction: * - chosen people: `people` scope over them, with no reach for later * workspaces; * - every shared and Personal workspace: `organization` scope; * - otherwise `workspaces` scope over the chosen shared workspaces (all of * today's when the choice is "all, including new ones") plus every Personal * workspace when they are allowed, with the reach kept for later ones. * A workspace's own connection stays its own whatever chosen shared workspaces * it serves (D-52); serving every shared workspace, Personal workspaces or * chosen people needs `moveToOrganization`, which makes it the organization's. * In a workspace, the models of the workspace's own connection change, and a * non-null `allowedWorkspaces` sets the other workspaces it serves: its * administrators remove any of them and add ones they also administer. */ export declare function updateSubscriptionCoreConnectionAccess(db: Database, provider: SubscriptionCoreProvider, target: SubscriptionCoreAccessTarget, policy: SubscriptionCoreAccessPolicy): Promise;