/** * StorageService - Singleton File Storage Manager * * @description Manages file storage operations for the entire application using a singleton pattern. * This service wraps @plyaz/storage and provides a centralized way to initialize and access * file storage across all domains (media uploads, compliance documents, user avatars, etc.). * * **Architecture:** * - Uses `StorageService` from @plyaz/storage which supports multi-provider setup * - Supports Cloudflare R2 (compliance documents) and Supabase Storage (assets/media) * - Automatic failover between providers based on health status * - Event-driven architecture with 40+ event types * - **Proxy-based method forwarding**: All methods from the underlying service are * automatically available with error handling - no manual wrapping needed * * **Provider Configuration:** * - **Cloudflare R2**: For compliance documents (tax, invoices, KYC) with zero egress fees * - **Supabase Storage**: For assets like images, user avatars, media files * * **Required Environment Variables (Cloudflare R2):** * - CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account ID * - R2_ACCESS_KEY_ID: R2 access key * - R2_SECRET_ACCESS_KEY: R2 secret key * - R2_BUCKET_NAME: Default bucket name * * **Required Environment Variables (Supabase Storage):** * - SUPABASE_URL: Your Supabase project URL * - SUPABASE_SERVICE_ROLE_KEY: Service role key for storage operations * * @example Using with Core.initialize() (Recommended) * ```typescript * import { Core } from '@plyaz/core'; * * await Core.initialize({ * storage: { * adapters: [r2Adapter, supabaseAdapter], * plugins: [virusScanPlugin, sharpImagePlugin], * }, * }); * * // Access via Core.storage - all methods automatically available * const result = await Core.storage.uploadFile({ * file: buffer, * filename: 'document.pdf', * category: FILE_CATEGORY.COMPLIANCE_DOCUMENT, * }); * ``` * * @module services */ import { StorageService as StorageServiceImpl } from '@plyaz/storage'; import type { CoreStorageConfig, CoreStorageServiceInstance } from '@plyaz/types/core'; export type { CoreStorageConfig } from '@plyaz/types/core'; /** * StorageService - Singleton File Storage Manager with Proxy-based method forwarding * * Provides centralized file storage management for all domains. * Uses @plyaz/storage under the hood with configurable providers and plugins. * * All methods from the underlying StorageServiceImpl are automatically available * via Proxy - when new methods are added to @plyaz/storage, they're instantly * accessible here with automatic error handling. */ export declare class StorageService implements CoreStorageServiceInstance { private storageService; private config; private initialized; private constructor(); /** * Emits a storage error event via CoreEventManager. * Called when storage operations fail to integrate with global error handling. */ private emitStorageError; /** * Gets the singleton instance of StorageService */ static getInstance(): StorageService; /** * Checks if the storage service has been initialized */ static isInitialized(): boolean; /** * Resets the storage service by clearing the singleton instance */ static reset(): Promise; /** * Creates merged event handlers that persist uploads to the media table * and emit progress events for real-time streaming. * Merges Core's internal handlers with user-provided handlers. * * @param userHandlers - User-provided event handlers from config * @returns Merged handlers with DB persistence + streaming + user handlers */ private static createMergedEventHandlers; /** * Initializes the storage service * * @param config - Storage service configuration * @returns The initialized StorageService instance */ static initialize(config: CoreStorageConfig): Promise; /** * Gets the raw underlying storage service instance without error handling wrapper. * Use this only if you need direct access to the underlying service. * * @returns The raw StorageService instance from @plyaz/storage * @throws {StoragePackageError} When storage is not initialized */ private getRawStorage; /** * Gets the storage service with automatic error handling. * All method calls are wrapped with try/catch and emit error events on failure. * Any method added to @plyaz/storage will be automatically available. * * @example * ```typescript * const storage = StorageService.getInstance().getStorage(); * await storage.uploadFile({ file, filename: 'doc.pdf' }); * await storage.deleteFile({ fileId: '123' }); * ``` * * @returns StorageServiceImpl with automatic error handling */ getStorage(): StorageServiceImpl; /** * Performs a health check on the storage service by checking all adapter health. * This method has special handling to transform the response format. */ healthCheck(): Promise<{ isHealthy: boolean; responseTime?: number; error?: string; }>; /** * Gets the current configuration */ getConfig(): CoreStorageConfig | null; /** * Closes the storage service and cleans up resources */ close(): Promise; /** * Creates a dedicated storage service instance (NOT the singleton) * * Use this when you need an isolated storage connection with its own configuration. * * @param config - Storage service configuration * @returns Promise that resolves to a new dedicated StorageService instance */ static createInstance(config: CoreStorageConfig): Promise; } /** Type alias for StorageService instance (use for type-only imports to avoid bundling) */ export type StorageServiceInstance = StorageService; //# sourceMappingURL=StorageService.d.ts.map