import { SmrtObject, SmrtObjectOptions } from '@happyvertical/smrt-core'; import { Tenant as TenantContract } from '@happyvertical/smrt-types'; import { TenantStatus } from '../types/index.js'; /** * Constructor options for {@link Tenant}. */ export interface TenantOptions extends SmrtObjectOptions { name?: string; status?: TenantStatus; description?: string; parentTenantId?: string | null; hierarchyLevel?: number; hierarchyPath?: string; cascadePermissions?: boolean; inheritPermissions?: boolean; } /** * Maximum allowed depth for tenant hierarchy. * Prevents excessively deep trees that could cause performance issues. */ export declare const MAX_TENANT_HIERARCHY_DEPTH = 10; /** * Tenant represents an organizational boundary in the multi-tenant system. * * Supports hierarchical organization with parent-child relationships. * Users can belong to multiple tenants through Memberships. * Each tenant can have custom roles in addition to system defaults. * * ## Hierarchical Tenants * * Tenants can be organized in a tree structure where child tenants * can optionally inherit permissions from their parent tenants. * * ### Cascade Control * * Two flags control permission inheritance: * - `cascadePermissions`: If true, this tenant pushes its permissions to children * - `inheritPermissions`: If true, this tenant accepts permissions from parent * * Both must be true for inheritance to flow from parent to child. * * @example * ```typescript * // Create root tenant * const corp = await tenants.create({ * name: 'Acme Corporation', * slug: 'acme-corp', * cascadePermissions: true, // Push permissions to children * }); * await corp.save(); * * // Create child tenant that inherits * const division = await tenants.create({ * name: 'Acme West Division', * slug: 'acme-west', * parentTenantId: corp.id, * inheritPermissions: true, // Accept parent permissions * }); * await division.save(); * * // Create independent child (breaks inheritance chain) * const independent = await tenants.create({ * name: 'Acme Labs', * slug: 'acme-labs', * parentTenantId: corp.id, * inheritPermissions: false, // Does NOT inherit from parent * }); * await independent.save(); * ``` */ export declare class Tenant extends SmrtObject implements TenantContract { /** * Display name for the tenant */ name: string; /** * Tenant status */ status: TenantStatus; /** * Optional description */ description: string; /** * Parent tenant ID for hierarchical organization. * Null for root-level tenants. */ parentTenantId?: string | null; /** * Depth in the hierarchy tree (0 = root, 1 = first level child, etc.) * Automatically managed by TenantCollection methods. */ hierarchyLevel: number; /** * Materialized path for efficient tree traversal. * Format: "ancestor-id/parent-id" (path to parent; does not include this tenant's id) * Empty string for root tenants. * Automatically managed by TenantCollection methods. */ hierarchyPath: string; /** * If true, this tenant's permissions cascade DOWN to child tenants. * Children can still opt-out by setting inheritPermissions: false. * Default: true */ cascadePermissions: boolean; /** * If true, this tenant ACCEPTS permissions from its parent tenant. * Parent must also have cascadePermissions: true for inheritance to work. * Default: true */ inheritPermissions: boolean; constructor(options?: TenantOptions); /** * Check if tenant is active */ isActive(): boolean; /** * Check if tenant is suspended */ isSuspended(): boolean; /** * Check if this is a root-level tenant (no parent) */ isRoot(): boolean; /** * Check if this tenant is configured to cascade permissions to children. * * Note: This does NOT indicate whether any child tenants actually exist. * Use TenantCollection.findChildren() for accurate child lookup. */ canCascadeToChildren(): boolean; /** * Check if permission inheritance is active for this tenant. * Inheritance is active if: * - This tenant has a parent AND * - This tenant has inheritPermissions: true * * Note: The parent must also have cascadePermissions: true * for actual inheritance to occur. Use PermissionResolver * for accurate permission calculation. */ acceptsInheritance(): boolean; /** * Get ancestor IDs from the hierarchy path. * Returns an array of tenant IDs from root to immediate parent. * Empty array for root tenants. */ getAncestorIds(): string[]; } //# sourceMappingURL=Tenant.d.ts.map