hazo_files 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example ADDED
@@ -0,0 +1,23 @@
1
+ # Google Drive OAuth Configuration
2
+ # Get these credentials from Google Cloud Console
3
+ # https://console.cloud.google.com
4
+
5
+ # Google Drive Client ID (required for Google Drive OAuth)
6
+ HAZO_GOOGLE_DRIVE_CLIENT_ID=your-client-id.apps.googleusercontent.com
7
+
8
+ # Google Drive Client Secret (required for Google Drive OAuth)
9
+ HAZO_GOOGLE_DRIVE_CLIENT_SECRET=your-client-secret
10
+
11
+ # OAuth Redirect URI (must match Google Cloud Console settings)
12
+ HAZO_GOOGLE_DRIVE_REDIRECT_URI=http://localhost:3000/api/auth/callback/google
13
+
14
+ # Google Drive Refresh Token (obtained after OAuth flow)
15
+ # Leave empty initially, will be set after first authentication
16
+ HAZO_GOOGLE_DRIVE_REFRESH_TOKEN=
17
+
18
+ # Google Drive Access Token (optional, auto-refreshed)
19
+ HAZO_GOOGLE_DRIVE_ACCESS_TOKEN=
20
+
21
+ # Google Drive Root Folder ID (optional, use specific folder as root)
22
+ # Leave empty to use the root of Google Drive
23
+ HAZO_GOOGLE_DRIVE_ROOT_FOLDER_ID=
package/README.md CHANGED
@@ -480,7 +480,7 @@ The `FileBrowser` is a complete, drop-in file management UI with:
480
480
  - File preview (images, text, PDFs)
481
481
  - Context menus and actions
482
482
  - Upload, download, rename, delete operations
483
- - Drag-and-drop support (if implemented in API)
483
+ - Drag-and-drop file moving between folders
484
484
 
485
485
  ```typescript
486
486
  import { FileBrowser } from 'hazo_files/ui';
@@ -499,6 +499,38 @@ import { FileBrowser } from 'hazo_files/ui';
499
499
  />
500
500
  ```
501
501
 
502
+ #### Drag-and-Drop File Moving
503
+
504
+ The FileBrowser includes built-in drag-and-drop functionality for moving files and folders:
505
+
506
+ **Features**:
507
+ - Drag files/folders from the file list
508
+ - Drop onto folders in the sidebar tree or main file list
509
+ - Visual feedback with opacity and colored borders during drag
510
+ - Prevents invalid operations (dropping on self, into current parent, folder into descendant)
511
+ - Shows dragged item preview during drag operation
512
+
513
+ **How to use**:
514
+ 1. Click and hold on any file or folder in the file list
515
+ 2. Drag it over a folder in either the tree sidebar or file list
516
+ 3. Valid drop targets show a green ring/background
517
+ 4. Release to move the item to the new location
518
+
519
+ **Technical requirements**:
520
+ - Requires `@dnd-kit/core` peer dependency (already included for NamingRuleConfigurator)
521
+ - API must implement `moveItem(sourcePath, destinationPath)` method
522
+ - Automatically validates drop targets to prevent invalid moves
523
+
524
+ **Visual feedback**:
525
+ - **Dragging**: Item becomes semi-transparent (opacity-50)
526
+ - **Valid drop target**: Green ring (`ring-2 ring-green-500`) and background (`bg-green-50`)
527
+ - **Drag preview**: Shows file/folder icon and name following cursor
528
+
529
+ **ID patterns used**:
530
+ - File items: `file-item-{path}` (draggable)
531
+ - Folder tree drops: `folder-drop-tree-{path}` (droppable)
532
+ - Folder list drops: `folder-drop-list-{path}` (droppable)
533
+
502
534
  ### Individual Components
503
535
 
504
536
  You can also use individual components:
package/dist/index.d.mts CHANGED
@@ -133,6 +133,74 @@ interface UseNamingRuleActions {
133
133
  interface UseNamingRuleReturn extends UseNamingRuleState, UseNamingRuleActions {
134
134
  }
135
135
 
136
+ /**
137
+ * Metadata tracking types for hazo_files
138
+ * Used for database tracking of file operations
139
+ */
140
+
141
+ /**
142
+ * Record stored in the hazo_files database table
143
+ * Extends Record<string, unknown> for compatibility with hazo_connect CrudService
144
+ */
145
+ interface FileMetadataRecord extends Record<string, unknown> {
146
+ /** Unique identifier (UUID) */
147
+ id: string;
148
+ /** File or folder name */
149
+ filename: string;
150
+ /** MIME type for files, 'folder' for directories */
151
+ file_type: string;
152
+ /** Custom metadata as JSON string */
153
+ file_data: string;
154
+ /** ISO timestamp when record was created */
155
+ created_at: string;
156
+ /** ISO timestamp of last access or modification */
157
+ changed_at: string;
158
+ /** Virtual path in storage */
159
+ file_path: string;
160
+ /** Storage provider type */
161
+ storage_type: StorageProvider;
162
+ }
163
+ /**
164
+ * Input for creating a new metadata record
165
+ */
166
+ interface FileMetadataInput {
167
+ filename: string;
168
+ file_type: string;
169
+ file_data?: Record<string, unknown>;
170
+ file_path: string;
171
+ storage_type: StorageProvider;
172
+ }
173
+ /**
174
+ * Input for updating an existing metadata record
175
+ */
176
+ interface FileMetadataUpdate {
177
+ filename?: string;
178
+ file_type?: string;
179
+ file_data?: Record<string, unknown>;
180
+ file_path?: string;
181
+ changed_at?: string;
182
+ }
183
+ /**
184
+ * Configuration for database tracking
185
+ */
186
+ interface DatabaseTrackingConfig {
187
+ /** Enable database tracking (default: false) */
188
+ enabled: boolean;
189
+ /** Table name for metadata (default: 'hazo_files') */
190
+ tableName?: string;
191
+ /** Track download operations as access (default: true) */
192
+ trackDownloads?: boolean;
193
+ /** Log database errors instead of failing silently (default: true) */
194
+ logErrors?: boolean;
195
+ }
196
+ /**
197
+ * Options for TrackedFileManager
198
+ */
199
+ interface TrackedFileManagerOptions {
200
+ /** Database tracking configuration */
201
+ tracking?: DatabaseTrackingConfig;
202
+ }
203
+
136
204
  /**
137
205
  * Core types for the hazo_files package
138
206
  */
@@ -416,6 +484,208 @@ declare function createFileManager(options?: FileManagerOptions): FileManager;
416
484
  */
417
485
  declare function createInitializedFileManager(options?: FileManagerOptions): Promise<FileManager>;
418
486
 
487
+ /**
488
+ * File Metadata Service
489
+ * Handles database operations for tracking file metadata
490
+ * Uses hazo_connect for database interactions
491
+ */
492
+
493
+ /**
494
+ * Logger interface compatible with hazo_connect
495
+ */
496
+ interface MetadataLogger {
497
+ debug?(message: string, data?: Record<string, unknown>): void;
498
+ info?(message: string, data?: Record<string, unknown>): void;
499
+ warn?(message: string, data?: Record<string, unknown>): void;
500
+ error?(message: string, data?: Record<string, unknown>): void;
501
+ }
502
+ /**
503
+ * Minimal CRUD service interface (compatible with hazo_connect CrudService)
504
+ */
505
+ interface CrudServiceLike<T> {
506
+ list(configure?: (qb: unknown) => unknown): Promise<T[]>;
507
+ findBy(criteria: Record<string, unknown>): Promise<T[]>;
508
+ findOneBy(criteria: Record<string, unknown>): Promise<T | null>;
509
+ insert(data: Partial<T> | Partial<T>[]): Promise<T[]>;
510
+ updateById(id: unknown, patch: Partial<T>): Promise<T[]>;
511
+ deleteById(id: unknown): Promise<void>;
512
+ }
513
+ /**
514
+ * Options for FileMetadataService
515
+ */
516
+ interface FileMetadataServiceOptions {
517
+ /** Table name (default: 'hazo_files') */
518
+ tableName?: string;
519
+ /** Logger for diagnostics */
520
+ logger?: MetadataLogger;
521
+ /** Log errors to console (default: true) */
522
+ logErrors?: boolean;
523
+ }
524
+ /**
525
+ * File Metadata Service
526
+ * Provides methods to track file operations in a database
527
+ */
528
+ declare class FileMetadataService {
529
+ private crud;
530
+ private logger?;
531
+ private logErrors;
532
+ constructor(crudService: CrudServiceLike<FileMetadataRecord>, options?: FileMetadataServiceOptions);
533
+ /**
534
+ * Generate ISO timestamp
535
+ */
536
+ private now;
537
+ /**
538
+ * Log an error if logging is enabled
539
+ */
540
+ private logError;
541
+ /**
542
+ * Record a file upload
543
+ */
544
+ recordUpload(input: FileMetadataInput): Promise<FileMetadataRecord | null>;
545
+ /**
546
+ * Record a directory creation
547
+ */
548
+ recordDirectoryCreation(path: string, storageType: StorageProvider, metadata?: Record<string, unknown>): Promise<FileMetadataRecord | null>;
549
+ /**
550
+ * Record a file access (download)
551
+ */
552
+ recordAccess(path: string, storageType: StorageProvider): Promise<boolean>;
553
+ /**
554
+ * Record a file deletion
555
+ */
556
+ recordDelete(path: string, storageType: StorageProvider): Promise<boolean>;
557
+ /**
558
+ * Record a directory deletion (recursive)
559
+ */
560
+ recordDirectoryDelete(path: string, storageType: StorageProvider, recursive: boolean): Promise<boolean>;
561
+ /**
562
+ * Record a file or folder move
563
+ */
564
+ recordMove(sourcePath: string, destinationPath: string, storageType: StorageProvider): Promise<boolean>;
565
+ /**
566
+ * Record a file or folder rename
567
+ */
568
+ recordRename(path: string, newName: string, storageType: StorageProvider): Promise<boolean>;
569
+ /**
570
+ * Find a record by path and storage type
571
+ */
572
+ findByPath(path: string, storageType: StorageProvider): Promise<FileMetadataRecord | null>;
573
+ /**
574
+ * Find all records for a storage type
575
+ */
576
+ findByStorageType(storageType: StorageProvider): Promise<FileMetadataRecord[]>;
577
+ /**
578
+ * Find all records in a directory
579
+ */
580
+ findInDirectory(directoryPath: string, storageType: StorageProvider): Promise<FileMetadataRecord[]>;
581
+ /**
582
+ * Update custom metadata for a file
583
+ */
584
+ updateMetadata(path: string, storageType: StorageProvider, metadata: Record<string, unknown>): Promise<boolean>;
585
+ }
586
+ /**
587
+ * Create a FileMetadataService instance
588
+ */
589
+ declare function createFileMetadataService(crudService: CrudServiceLike<FileMetadataRecord>, options?: FileMetadataServiceOptions): FileMetadataService;
590
+
591
+ /**
592
+ * Tracked File Manager
593
+ * Extends FileManager to add database tracking of file operations
594
+ */
595
+
596
+ /**
597
+ * Options for creating a TrackedFileManager
598
+ */
599
+ interface TrackedFileManagerFullOptions extends FileManagerOptions {
600
+ /** CRUD service for database operations (from hazo_connect) */
601
+ crudService?: CrudServiceLike<FileMetadataRecord>;
602
+ /** Database tracking configuration */
603
+ tracking?: DatabaseTrackingConfig;
604
+ }
605
+ /**
606
+ * TrackedFileManager - File manager with database tracking
607
+ *
608
+ * Extends FileManager to record file operations in a database table.
609
+ * Database operations are non-blocking and failures don't affect file operations.
610
+ */
611
+ declare class TrackedFileManager extends FileManager {
612
+ private metadataService;
613
+ private trackingConfig;
614
+ constructor(options?: TrackedFileManagerFullOptions);
615
+ /**
616
+ * Check if tracking is enabled and service is available
617
+ */
618
+ private isTrackingEnabled;
619
+ /**
620
+ * Get the current storage provider type
621
+ */
622
+ private getStorageType;
623
+ /**
624
+ * Create a directory and record it in the database
625
+ */
626
+ createDirectory(path: string): Promise<OperationResult<FolderItem>>;
627
+ /**
628
+ * Remove a directory and delete its record from the database
629
+ */
630
+ removeDirectory(path: string, recursive?: boolean): Promise<OperationResult>;
631
+ /**
632
+ * Upload a file and record it in the database
633
+ */
634
+ uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
635
+ /**
636
+ * Download a file and optionally track access
637
+ */
638
+ downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
639
+ /**
640
+ * Move a file or folder and update its path in the database
641
+ */
642
+ moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
643
+ /**
644
+ * Delete a file and remove its record from the database
645
+ */
646
+ deleteFile(path: string): Promise<OperationResult>;
647
+ /**
648
+ * Rename a file and update its record in the database
649
+ */
650
+ renameFile(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
651
+ /**
652
+ * Rename a folder and update its record in the database
653
+ */
654
+ renameFolder(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
655
+ /**
656
+ * Write a file with string content and track it
657
+ */
658
+ writeFile(path: string, content: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
659
+ /**
660
+ * Read a file and optionally track access
661
+ */
662
+ readFile(path: string): Promise<OperationResult<string>>;
663
+ /**
664
+ * Copy a file and track the new file
665
+ */
666
+ copyFile(sourcePath: string, destinationPath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
667
+ /**
668
+ * Get the metadata service for direct access
669
+ */
670
+ getMetadataService(): FileMetadataService | null;
671
+ /**
672
+ * Check if database tracking is enabled
673
+ */
674
+ isTrackingActive(): boolean;
675
+ /**
676
+ * Get tracking configuration
677
+ */
678
+ getTrackingConfig(): DatabaseTrackingConfig;
679
+ }
680
+ /**
681
+ * Create a new TrackedFileManager instance
682
+ */
683
+ declare function createTrackedFileManager(options?: TrackedFileManagerFullOptions): TrackedFileManager;
684
+ /**
685
+ * Create and initialize a TrackedFileManager instance
686
+ */
687
+ declare function createInitializedTrackedFileManager(options?: TrackedFileManagerFullOptions): Promise<TrackedFileManager>;
688
+
419
689
  /**
420
690
  * Configuration loader for hazo_files
421
691
  * Reads configuration from hazo_files_config.ini file
@@ -1028,4 +1298,4 @@ declare function generatePreviewName(pattern: PatternSegment[], userVariables: N
1028
1298
  originalFileName?: string;
1029
1299
  }): string;
1030
1300
 
1031
- export { ALL_SYSTEM_VARIABLES, type AuthCallbacks, AuthenticationError, ConfigurationError, DEFAULT_DATE_FORMATS, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type FileBrowserState, FileExistsError, type FileItem, FileManager, type FileManagerOptions, FileNotFoundError, type FileSystemItem, FileTooLargeError, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type HazoFilesConfig, HazoFilesError, InvalidExtensionError, InvalidPathError, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MoveOptions, type NameGenerationOptions, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, type TreeNode, type UploadOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, clonePattern, createAndInitializeModule, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createLiteralSegment, createLocalModule, createModule, createVariableSegment, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateId, generatePreviewName, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getFileCategory, getFileMetadataValues, getMimeType, getNameWithoutExtension, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSystemVariablePreviewValues, hasExtension, hazo_files_generate_file_name, hazo_files_generate_folder_name, isAudio, isChildPath, isCounterVariable, isDateVariable, isDocument, isFile, isFileMetadataVariable, isFolder, isImage, isPreviewable, isProviderRegistered, isText, isVideo, joinPath, loadConfig, loadConfigAsync, normalizePath, parseConfig, parsePatternString, patternToString, registerModule, sanitizeFilename, saveConfig, sortItems, successResult, validateNamingRuleSchema, validatePath };
1301
+ export { ALL_SYSTEM_VARIABLES, type AuthCallbacks, AuthenticationError, ConfigurationError, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type FileBrowserState, FileExistsError, type FileItem, FileManager, type FileManagerOptions, type FileMetadataInput, type FileMetadataRecord, FileMetadataService, type FileMetadataServiceOptions, type FileMetadataUpdate, FileNotFoundError, type FileSystemItem, FileTooLargeError, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type HazoFilesConfig, HazoFilesError, InvalidExtensionError, InvalidPathError, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MetadataLogger, type MoveOptions, type NameGenerationOptions, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, TrackedFileManager, type TrackedFileManagerFullOptions, type TrackedFileManagerOptions, type TreeNode, type UploadOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, clonePattern, createAndInitializeModule, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createInitializedTrackedFileManager, createLiteralSegment, createLocalModule, createModule, createTrackedFileManager, createVariableSegment, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateId, generatePreviewName, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getFileCategory, getFileMetadataValues, getMimeType, getNameWithoutExtension, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSystemVariablePreviewValues, hasExtension, hazo_files_generate_file_name, hazo_files_generate_folder_name, isAudio, isChildPath, isCounterVariable, isDateVariable, isDocument, isFile, isFileMetadataVariable, isFolder, isImage, isPreviewable, isProviderRegistered, isText, isVideo, joinPath, loadConfig, loadConfigAsync, normalizePath, parseConfig, parsePatternString, patternToString, registerModule, sanitizeFilename, saveConfig, sortItems, successResult, validateNamingRuleSchema, validatePath };
package/dist/index.d.ts CHANGED
@@ -133,6 +133,74 @@ interface UseNamingRuleActions {
133
133
  interface UseNamingRuleReturn extends UseNamingRuleState, UseNamingRuleActions {
134
134
  }
135
135
 
136
+ /**
137
+ * Metadata tracking types for hazo_files
138
+ * Used for database tracking of file operations
139
+ */
140
+
141
+ /**
142
+ * Record stored in the hazo_files database table
143
+ * Extends Record<string, unknown> for compatibility with hazo_connect CrudService
144
+ */
145
+ interface FileMetadataRecord extends Record<string, unknown> {
146
+ /** Unique identifier (UUID) */
147
+ id: string;
148
+ /** File or folder name */
149
+ filename: string;
150
+ /** MIME type for files, 'folder' for directories */
151
+ file_type: string;
152
+ /** Custom metadata as JSON string */
153
+ file_data: string;
154
+ /** ISO timestamp when record was created */
155
+ created_at: string;
156
+ /** ISO timestamp of last access or modification */
157
+ changed_at: string;
158
+ /** Virtual path in storage */
159
+ file_path: string;
160
+ /** Storage provider type */
161
+ storage_type: StorageProvider;
162
+ }
163
+ /**
164
+ * Input for creating a new metadata record
165
+ */
166
+ interface FileMetadataInput {
167
+ filename: string;
168
+ file_type: string;
169
+ file_data?: Record<string, unknown>;
170
+ file_path: string;
171
+ storage_type: StorageProvider;
172
+ }
173
+ /**
174
+ * Input for updating an existing metadata record
175
+ */
176
+ interface FileMetadataUpdate {
177
+ filename?: string;
178
+ file_type?: string;
179
+ file_data?: Record<string, unknown>;
180
+ file_path?: string;
181
+ changed_at?: string;
182
+ }
183
+ /**
184
+ * Configuration for database tracking
185
+ */
186
+ interface DatabaseTrackingConfig {
187
+ /** Enable database tracking (default: false) */
188
+ enabled: boolean;
189
+ /** Table name for metadata (default: 'hazo_files') */
190
+ tableName?: string;
191
+ /** Track download operations as access (default: true) */
192
+ trackDownloads?: boolean;
193
+ /** Log database errors instead of failing silently (default: true) */
194
+ logErrors?: boolean;
195
+ }
196
+ /**
197
+ * Options for TrackedFileManager
198
+ */
199
+ interface TrackedFileManagerOptions {
200
+ /** Database tracking configuration */
201
+ tracking?: DatabaseTrackingConfig;
202
+ }
203
+
136
204
  /**
137
205
  * Core types for the hazo_files package
138
206
  */
@@ -416,6 +484,208 @@ declare function createFileManager(options?: FileManagerOptions): FileManager;
416
484
  */
417
485
  declare function createInitializedFileManager(options?: FileManagerOptions): Promise<FileManager>;
418
486
 
487
+ /**
488
+ * File Metadata Service
489
+ * Handles database operations for tracking file metadata
490
+ * Uses hazo_connect for database interactions
491
+ */
492
+
493
+ /**
494
+ * Logger interface compatible with hazo_connect
495
+ */
496
+ interface MetadataLogger {
497
+ debug?(message: string, data?: Record<string, unknown>): void;
498
+ info?(message: string, data?: Record<string, unknown>): void;
499
+ warn?(message: string, data?: Record<string, unknown>): void;
500
+ error?(message: string, data?: Record<string, unknown>): void;
501
+ }
502
+ /**
503
+ * Minimal CRUD service interface (compatible with hazo_connect CrudService)
504
+ */
505
+ interface CrudServiceLike<T> {
506
+ list(configure?: (qb: unknown) => unknown): Promise<T[]>;
507
+ findBy(criteria: Record<string, unknown>): Promise<T[]>;
508
+ findOneBy(criteria: Record<string, unknown>): Promise<T | null>;
509
+ insert(data: Partial<T> | Partial<T>[]): Promise<T[]>;
510
+ updateById(id: unknown, patch: Partial<T>): Promise<T[]>;
511
+ deleteById(id: unknown): Promise<void>;
512
+ }
513
+ /**
514
+ * Options for FileMetadataService
515
+ */
516
+ interface FileMetadataServiceOptions {
517
+ /** Table name (default: 'hazo_files') */
518
+ tableName?: string;
519
+ /** Logger for diagnostics */
520
+ logger?: MetadataLogger;
521
+ /** Log errors to console (default: true) */
522
+ logErrors?: boolean;
523
+ }
524
+ /**
525
+ * File Metadata Service
526
+ * Provides methods to track file operations in a database
527
+ */
528
+ declare class FileMetadataService {
529
+ private crud;
530
+ private logger?;
531
+ private logErrors;
532
+ constructor(crudService: CrudServiceLike<FileMetadataRecord>, options?: FileMetadataServiceOptions);
533
+ /**
534
+ * Generate ISO timestamp
535
+ */
536
+ private now;
537
+ /**
538
+ * Log an error if logging is enabled
539
+ */
540
+ private logError;
541
+ /**
542
+ * Record a file upload
543
+ */
544
+ recordUpload(input: FileMetadataInput): Promise<FileMetadataRecord | null>;
545
+ /**
546
+ * Record a directory creation
547
+ */
548
+ recordDirectoryCreation(path: string, storageType: StorageProvider, metadata?: Record<string, unknown>): Promise<FileMetadataRecord | null>;
549
+ /**
550
+ * Record a file access (download)
551
+ */
552
+ recordAccess(path: string, storageType: StorageProvider): Promise<boolean>;
553
+ /**
554
+ * Record a file deletion
555
+ */
556
+ recordDelete(path: string, storageType: StorageProvider): Promise<boolean>;
557
+ /**
558
+ * Record a directory deletion (recursive)
559
+ */
560
+ recordDirectoryDelete(path: string, storageType: StorageProvider, recursive: boolean): Promise<boolean>;
561
+ /**
562
+ * Record a file or folder move
563
+ */
564
+ recordMove(sourcePath: string, destinationPath: string, storageType: StorageProvider): Promise<boolean>;
565
+ /**
566
+ * Record a file or folder rename
567
+ */
568
+ recordRename(path: string, newName: string, storageType: StorageProvider): Promise<boolean>;
569
+ /**
570
+ * Find a record by path and storage type
571
+ */
572
+ findByPath(path: string, storageType: StorageProvider): Promise<FileMetadataRecord | null>;
573
+ /**
574
+ * Find all records for a storage type
575
+ */
576
+ findByStorageType(storageType: StorageProvider): Promise<FileMetadataRecord[]>;
577
+ /**
578
+ * Find all records in a directory
579
+ */
580
+ findInDirectory(directoryPath: string, storageType: StorageProvider): Promise<FileMetadataRecord[]>;
581
+ /**
582
+ * Update custom metadata for a file
583
+ */
584
+ updateMetadata(path: string, storageType: StorageProvider, metadata: Record<string, unknown>): Promise<boolean>;
585
+ }
586
+ /**
587
+ * Create a FileMetadataService instance
588
+ */
589
+ declare function createFileMetadataService(crudService: CrudServiceLike<FileMetadataRecord>, options?: FileMetadataServiceOptions): FileMetadataService;
590
+
591
+ /**
592
+ * Tracked File Manager
593
+ * Extends FileManager to add database tracking of file operations
594
+ */
595
+
596
+ /**
597
+ * Options for creating a TrackedFileManager
598
+ */
599
+ interface TrackedFileManagerFullOptions extends FileManagerOptions {
600
+ /** CRUD service for database operations (from hazo_connect) */
601
+ crudService?: CrudServiceLike<FileMetadataRecord>;
602
+ /** Database tracking configuration */
603
+ tracking?: DatabaseTrackingConfig;
604
+ }
605
+ /**
606
+ * TrackedFileManager - File manager with database tracking
607
+ *
608
+ * Extends FileManager to record file operations in a database table.
609
+ * Database operations are non-blocking and failures don't affect file operations.
610
+ */
611
+ declare class TrackedFileManager extends FileManager {
612
+ private metadataService;
613
+ private trackingConfig;
614
+ constructor(options?: TrackedFileManagerFullOptions);
615
+ /**
616
+ * Check if tracking is enabled and service is available
617
+ */
618
+ private isTrackingEnabled;
619
+ /**
620
+ * Get the current storage provider type
621
+ */
622
+ private getStorageType;
623
+ /**
624
+ * Create a directory and record it in the database
625
+ */
626
+ createDirectory(path: string): Promise<OperationResult<FolderItem>>;
627
+ /**
628
+ * Remove a directory and delete its record from the database
629
+ */
630
+ removeDirectory(path: string, recursive?: boolean): Promise<OperationResult>;
631
+ /**
632
+ * Upload a file and record it in the database
633
+ */
634
+ uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
635
+ /**
636
+ * Download a file and optionally track access
637
+ */
638
+ downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
639
+ /**
640
+ * Move a file or folder and update its path in the database
641
+ */
642
+ moveItem(sourcePath: string, destinationPath: string, options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
643
+ /**
644
+ * Delete a file and remove its record from the database
645
+ */
646
+ deleteFile(path: string): Promise<OperationResult>;
647
+ /**
648
+ * Rename a file and update its record in the database
649
+ */
650
+ renameFile(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FileItem>>;
651
+ /**
652
+ * Rename a folder and update its record in the database
653
+ */
654
+ renameFolder(path: string, newName: string, options?: RenameOptions): Promise<OperationResult<FolderItem>>;
655
+ /**
656
+ * Write a file with string content and track it
657
+ */
658
+ writeFile(path: string, content: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
659
+ /**
660
+ * Read a file and optionally track access
661
+ */
662
+ readFile(path: string): Promise<OperationResult<string>>;
663
+ /**
664
+ * Copy a file and track the new file
665
+ */
666
+ copyFile(sourcePath: string, destinationPath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
667
+ /**
668
+ * Get the metadata service for direct access
669
+ */
670
+ getMetadataService(): FileMetadataService | null;
671
+ /**
672
+ * Check if database tracking is enabled
673
+ */
674
+ isTrackingActive(): boolean;
675
+ /**
676
+ * Get tracking configuration
677
+ */
678
+ getTrackingConfig(): DatabaseTrackingConfig;
679
+ }
680
+ /**
681
+ * Create a new TrackedFileManager instance
682
+ */
683
+ declare function createTrackedFileManager(options?: TrackedFileManagerFullOptions): TrackedFileManager;
684
+ /**
685
+ * Create and initialize a TrackedFileManager instance
686
+ */
687
+ declare function createInitializedTrackedFileManager(options?: TrackedFileManagerFullOptions): Promise<TrackedFileManager>;
688
+
419
689
  /**
420
690
  * Configuration loader for hazo_files
421
691
  * Reads configuration from hazo_files_config.ini file
@@ -1028,4 +1298,4 @@ declare function generatePreviewName(pattern: PatternSegment[], userVariables: N
1028
1298
  originalFileName?: string;
1029
1299
  }): string;
1030
1300
 
1031
- export { ALL_SYSTEM_VARIABLES, type AuthCallbacks, AuthenticationError, ConfigurationError, DEFAULT_DATE_FORMATS, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type FileBrowserState, FileExistsError, type FileItem, FileManager, type FileManagerOptions, FileNotFoundError, type FileSystemItem, FileTooLargeError, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type HazoFilesConfig, HazoFilesError, InvalidExtensionError, InvalidPathError, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MoveOptions, type NameGenerationOptions, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, type TreeNode, type UploadOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, clonePattern, createAndInitializeModule, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createLiteralSegment, createLocalModule, createModule, createVariableSegment, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateId, generatePreviewName, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getFileCategory, getFileMetadataValues, getMimeType, getNameWithoutExtension, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSystemVariablePreviewValues, hasExtension, hazo_files_generate_file_name, hazo_files_generate_folder_name, isAudio, isChildPath, isCounterVariable, isDateVariable, isDocument, isFile, isFileMetadataVariable, isFolder, isImage, isPreviewable, isProviderRegistered, isText, isVideo, joinPath, loadConfig, loadConfigAsync, normalizePath, parseConfig, parsePatternString, patternToString, registerModule, sanitizeFilename, saveConfig, sortItems, successResult, validateNamingRuleSchema, validatePath };
1301
+ export { ALL_SYSTEM_VARIABLES, type AuthCallbacks, AuthenticationError, ConfigurationError, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type FileBrowserState, FileExistsError, type FileItem, FileManager, type FileManagerOptions, type FileMetadataInput, type FileMetadataRecord, FileMetadataService, type FileMetadataServiceOptions, type FileMetadataUpdate, FileNotFoundError, type FileSystemItem, FileTooLargeError, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type HazoFilesConfig, HazoFilesError, InvalidExtensionError, InvalidPathError, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MetadataLogger, type MoveOptions, type NameGenerationOptions, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, TrackedFileManager, type TrackedFileManagerFullOptions, type TrackedFileManagerOptions, type TreeNode, type UploadOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, clonePattern, createAndInitializeModule, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createInitializedTrackedFileManager, createLiteralSegment, createLocalModule, createModule, createTrackedFileManager, createVariableSegment, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateId, generatePreviewName, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getFileCategory, getFileMetadataValues, getMimeType, getNameWithoutExtension, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSystemVariablePreviewValues, hasExtension, hazo_files_generate_file_name, hazo_files_generate_folder_name, isAudio, isChildPath, isCounterVariable, isDateVariable, isDocument, isFile, isFileMetadataVariable, isFolder, isImage, isPreviewable, isProviderRegistered, isText, isVideo, joinPath, loadConfig, loadConfigAsync, normalizePath, parseConfig, parsePatternString, patternToString, registerModule, sanitizeFilename, saveConfig, sortItems, successResult, validateNamingRuleSchema, validatePath };