import { CompatiblePropertyDecorator } from '@happyvertical/smrt-core'; import { TenantIdFieldOptions } from './fields.js'; /** * Options accepted by the `@TenantScoped()` class decorator. * * All fields are optional; defaults match the most restrictive safe behaviour * (required mode, auto-filter and auto-populate enabled, no super-admin bypass). * * @see TenantScoped * @see TenantScopedConfig */ export interface TenantScopedOptions { /** * Tenancy mode for this class * - 'required': Must have tenant context for all operations (default) * - 'optional': Works with or without tenant context */ mode?: 'required' | 'optional'; /** * Field name containing tenant ID * @default 'tenantId' */ field?: string; /** * Auto-filter all queries by tenant * @default true */ autoFilter?: boolean; /** * Auto-populate tenant ID from context on create * @default true */ autoPopulate?: boolean; /** * Allow super admin bypass for this class * @default false - must be explicitly enabled */ allowSuperAdminBypass?: boolean; } /** * Mark a class as tenant-scoped * * This decorator registers the class with the tenancy system so that: * - list()/get() queries are automatically filtered by tenant * - save() validates tenant ID matches current context * - delete() validates tenant ownership * - Raw SQL queries trigger policy enforcement * * @param options - Configuration options * * @example Basic usage (required tenancy) * ```typescript * @smrt() * @TenantScoped() * class Document extends SmrtObject { * @tenantId() * tenantId: string = ''; * * title: string = ''; * } * ``` * * @example With super admin bypass enabled * ```typescript * @smrt() * @TenantScoped({ allowSuperAdminBypass: true }) * class AuditLog extends SmrtObject { * @tenantId() * tenantId: string = ''; * * action: string = ''; * } * ``` * * @example Optional tenancy (works with or without context) * ```typescript * @smrt() * @TenantScoped({ mode: 'optional' }) * class GlobalConfig extends SmrtObject { * @tenantId({ nullable: true }) * tenantId: string | null = null; // null = global, string = tenant-specific * * key: string = ''; * value: string = ''; * } * ``` */ export declare function TenantScoped(options?: TenantScopedOptions): (target: T, decoratorContext?: ClassDecoratorContext) => T; /** * Tenant ID property decorator * * Marks a property as the tenant identifier field. This decorator registers * the field metadata with ObjectRegistry, keeping the property value clean * (no descriptor objects that could be accidentally saved to the database). * * @param options - Field options (nullable, autoFilter, autoPopulate, etc.) * @returns Property decorator * * @example Basic usage (required tenancy) * ```typescript * @smrt() * @TenantScoped() * class Document extends SmrtObject { * @tenantId() * tenantId: string = ''; * * title: string = ''; * } * ``` * * @example Nullable tenant ID (for global resources) * ```typescript * @smrt() * @TenantScoped({ mode: 'optional' }) * class GlobalConfig extends SmrtObject { * @tenantId({ nullable: true }) * tenantId: string | null = null; // null = global, string = tenant-specific * * key: string = ''; * } * ``` * * @see https://github.com/happyvertical/smrt/issues/829 - Why decorators over field helpers */ export declare function tenantId(options?: TenantIdFieldOptions): CompatiblePropertyDecorator; //# sourceMappingURL=decorators.d.ts.map