/** * StorageService - Main Storage Service Class * * Provides a unified interface for cloud storage operations including * upload, download, delete, list, and signed URL generation. * * Supported providers: AWS S3, Google Cloud Storage, Azure Blob Storage * Supports Redis caching for download operations */ import { IStorageServiceConfig, IUploadOptions, IDownloadOptions, IDeleteOptions, IListFilesOptions, ISignedUrlOptions, IStorageStatsOptions, IStorageResult, IDownloadResult, IDeleteResult, IListFilesResult, ISignedUrlResult, IStorageStatsResult, IStorageDispatchOptions, IStorageDispatchResult } from './types'; /** * Error class for storage operations */ export declare class StorageError extends Error { code: string; details?: unknown; constructor(message: string, code: string, details?: unknown); } /** * StorageService * * Unified API for all cloud storage operations. * * @example * ```ts * import { StorageService } from '@ductape/sdk'; * * const storage = new StorageService({ * workspace_id: 'your-workspace-id', * public_key: 'your-public-key', * user_id: 'your-user-id', * token: 'your-token', * env_type: 'prd', * }); * * // Upload a file * const result = await storage.upload({ * product: 'my-product', * env: 'production', * storage: 'main-storage', * fileName: 'documents/report.pdf', * buffer: fileBuffer, * mimeType: 'application/pdf', * }); * * // Download a file * const downloadResult = await storage.download({ * product: 'my-product', * env: 'production', * storage: 'main-storage', * fileName: 'documents/report.pdf', * }); * * // Delete a file * await storage.delete({ * product: 'my-product', * env: 'production', * storage: 'main-storage', * fileName: 'documents/report.pdf', * }); * * // List files * const files = await storage.list({ * product: 'my-product', * env: 'production', * storage: 'main-storage', * prefix: 'documents/', * }); * * // Get signed URL * const signedUrl = await storage.getSignedUrl({ * product: 'my-product', * env: 'production', * storage: 'main-storage', * fileName: 'documents/report.pdf', * expiresIn: 3600, // 1 hour * }); * ``` */ export declare class StorageService { private config; private productBuilderService; private logService; private productId; private productTag; private cacheManager; private privateKey; private _privateKey; private cacheConfigCache; private privateKeys; private readonly productEnv; constructor(config: IStorageServiceConfig & { private_key: string; }); private resolvePE; /** * Initialize product and get storage configuration */ private initializeStorage; /** * Initialize logging service */ private initializeLogService; /** * Validate cache tag exists in product and return cache configuration * Uses local in-memory cache to avoid repeated API calls (5 minute TTL) */ private validateCache; /** * Upload a file to cloud storage */ upload(options: IUploadOptions): Promise; /** * Download a file from cloud storage * Supports caching when cache option is provided */ download(options: IDownloadOptions): Promise; /** * Delete a file from cloud storage */ delete(options: IDeleteOptions): Promise; /** * List files in cloud storage */ list(options: IListFilesOptions): Promise; /** * Get a signed URL for temporary file access */ getSignedUrl(options: ISignedUrlOptions): Promise; /** * Dispatch a storage operation as a background job */ dispatch(options: IStorageDispatchOptions): Promise; /** * Test connection to a storage provider * * Validates storage configuration and attempts to list objects (with limit 1) * to verify connectivity and credentials. * * @example * ```ts * const result = await storage.testConnection({ * product: 'my-product', * env: 'prd', * storage: 'main-bucket', * }); * console.log(result.connected); // true or false * ``` */ testConnection(options: { product: string; env: string; storage: string; }): Promise<{ connected: boolean; latency?: number; error?: string; }>; /** * Get storage statistics (file counts and sizes by type) * * Efficiently counts all files in the storage without downloading content. * Uses provider-native pagination to iterate through all objects and * categorizes files by type based on file extension. * * @example * ```ts * const stats = await storage.stats({ * product: 'my-product', * env: 'prd', * storage: 'main-bucket', * }); * console.log(stats.totalFiles); // 1234 * console.log(stats.byType.image.count); // 567 * ``` */ stats(options: IStorageStatsOptions): Promise; } export default StorageService;