hazo_files 1.0.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/.cursor/rules/db_schema.mdc +0 -0
- package/.cursor/rules/design.mdc +0 -0
- package/.cursor/rules/general.mdc +0 -0
- package/CHANGE_LOG.md +341 -0
- package/CLAUDE.md +926 -0
- package/README.md +929 -0
- package/SETUP_CHECKLIST.md +931 -0
- package/TECHDOC.md +325 -0
- package/dist/index.d.mts +1031 -0
- package/dist/index.d.ts +1031 -0
- package/dist/index.js +2457 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2333 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ui/index.js +4054 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/index.mjs +3982 -0
- package/dist/ui/index.mjs.map +1 -0
- package/docs/ADDING_MODULES.md +964 -0
- package/hazo_files_config.ini +31 -0
- package/package.json +83 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/CHANGE_LOG.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2025-12-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
#### Core Features
|
|
13
|
+
- Initial release of hazo_files package
|
|
14
|
+
- Unified FileManager service providing consistent API across storage providers
|
|
15
|
+
- Modular architecture for easy extension with custom storage providers
|
|
16
|
+
- Full TypeScript support with comprehensive type definitions
|
|
17
|
+
|
|
18
|
+
#### Storage Providers
|
|
19
|
+
- **LocalStorageModule**: Direct filesystem operations using Node.js `fs` module
|
|
20
|
+
- Extension filtering via `allowedExtensions` configuration
|
|
21
|
+
- File size limits via `maxFileSize` configuration
|
|
22
|
+
- Progress tracking for upload/download operations
|
|
23
|
+
- Recursive directory operations
|
|
24
|
+
- **GoogleDriveModule**: Google Drive integration with OAuth 2.0
|
|
25
|
+
- Full Google Drive API v3 implementation
|
|
26
|
+
- OAuth authentication with automatic token refresh
|
|
27
|
+
- Token persistence via callback system
|
|
28
|
+
- Configurable root folder support
|
|
29
|
+
|
|
30
|
+
#### File Operations
|
|
31
|
+
- Create and remove directories (with recursive option)
|
|
32
|
+
- Upload files from local path, Buffer, or ReadableStream
|
|
33
|
+
- Download files to local path or return as Buffer
|
|
34
|
+
- Move and rename files and folders
|
|
35
|
+
- Delete files
|
|
36
|
+
- List directory contents with filtering options
|
|
37
|
+
- Get file/folder metadata
|
|
38
|
+
- Check file/folder existence
|
|
39
|
+
- Generate folder tree structure
|
|
40
|
+
|
|
41
|
+
#### UI Components
|
|
42
|
+
- **FileBrowser**: Complete drop-in file browser component
|
|
43
|
+
- Folder tree navigation with lazy loading
|
|
44
|
+
- File list with grid and list view modes
|
|
45
|
+
- Breadcrumb navigation
|
|
46
|
+
- File preview for images, text, and PDFs
|
|
47
|
+
- Action toolbar with upload, download, create, rename, delete
|
|
48
|
+
- Drag-and-drop support (via API adapter)
|
|
49
|
+
- **Individual Components**: PathBreadcrumb, FolderTree, FileList, FilePreview, FileActions
|
|
50
|
+
- **Dialogs**: CreateFolderDialog, RenameDialog, DeleteConfirmDialog, UploadDialog
|
|
51
|
+
- **Hooks**: useFileBrowser, useFileOperations, useMultiFileOperations
|
|
52
|
+
|
|
53
|
+
#### Configuration System
|
|
54
|
+
- INI file configuration (`hazo_files_config.ini`)
|
|
55
|
+
- Environment variable support with automatic override
|
|
56
|
+
- Programmatic configuration via code
|
|
57
|
+
- Configuration validation and defaults
|
|
58
|
+
- Sample configuration generator
|
|
59
|
+
|
|
60
|
+
#### Common Utilities
|
|
61
|
+
- **Error Types**: 12 specific error classes for different failure scenarios
|
|
62
|
+
- FileNotFoundError, DirectoryNotFoundError
|
|
63
|
+
- FileExistsError, DirectoryExistsError
|
|
64
|
+
- DirectoryNotEmptyError, PermissionDeniedError
|
|
65
|
+
- InvalidPathError, FileTooLargeError
|
|
66
|
+
- InvalidExtensionError, AuthenticationError
|
|
67
|
+
- ConfigurationError, OperationError
|
|
68
|
+
- **Path Utilities**: Normalization, joining, validation, sanitization
|
|
69
|
+
- **MIME Type Detection**: 50+ file types with category classification
|
|
70
|
+
- **Helper Functions**: ID generation, byte formatting, item sorting/filtering
|
|
71
|
+
|
|
72
|
+
#### Developer Experience
|
|
73
|
+
- Comprehensive documentation
|
|
74
|
+
- README with quick start and usage examples
|
|
75
|
+
- Technical documentation (TECHDOC.md)
|
|
76
|
+
- AI-optimized reference guide (CLAUDE.md)
|
|
77
|
+
- Setup checklist (SETUP_CHECKLIST.md)
|
|
78
|
+
- Module creation guide (docs/ADDING_MODULES.md)
|
|
79
|
+
- Complete TypeScript definitions
|
|
80
|
+
- Example Next.js test application
|
|
81
|
+
- Progress callbacks for upload/download operations
|
|
82
|
+
- OperationResult pattern for consistent error handling
|
|
83
|
+
|
|
84
|
+
### Design Decisions
|
|
85
|
+
|
|
86
|
+
#### Virtual Path System
|
|
87
|
+
**Decision**: Use Unix-style virtual paths (`/folder/file.pdf`) across all storage providers.
|
|
88
|
+
|
|
89
|
+
**Rationale**:
|
|
90
|
+
- Provides consistent API regardless of storage backend
|
|
91
|
+
- Prevents Windows/Unix path separator conflicts
|
|
92
|
+
- Simplifies path manipulation and validation
|
|
93
|
+
- Easier to implement access control and path restrictions
|
|
94
|
+
|
|
95
|
+
#### OperationResult Pattern
|
|
96
|
+
**Decision**: Return `{ success: boolean, data?: T, error?: string }` instead of throwing exceptions.
|
|
97
|
+
|
|
98
|
+
**Rationale**:
|
|
99
|
+
- Expected failures (file not found, permission denied) shouldn't be exceptions
|
|
100
|
+
- Easier error handling in async code
|
|
101
|
+
- Consistent pattern across all operations
|
|
102
|
+
- Better for API responses (JSON-serializable)
|
|
103
|
+
- Allows partial success in batch operations
|
|
104
|
+
|
|
105
|
+
#### Module System
|
|
106
|
+
**Decision**: BaseStorageModule abstract class with StorageModule interface.
|
|
107
|
+
|
|
108
|
+
**Rationale**:
|
|
109
|
+
- Enforces consistent interface across providers
|
|
110
|
+
- Provides common utilities (path normalization, result helpers)
|
|
111
|
+
- Reduces code duplication
|
|
112
|
+
- Makes adding new providers straightforward
|
|
113
|
+
- Separates provider-specific logic from common functionality
|
|
114
|
+
|
|
115
|
+
#### Separate UI Package Export
|
|
116
|
+
**Decision**: Export UI components separately (`hazo_files/ui`)
|
|
117
|
+
|
|
118
|
+
**Rationale**:
|
|
119
|
+
- Core package has no React dependency
|
|
120
|
+
- Allows using file management without UI
|
|
121
|
+
- Reduces bundle size for server-only usage
|
|
122
|
+
- Clear separation of concerns
|
|
123
|
+
- Different peer dependencies (React only for UI)
|
|
124
|
+
|
|
125
|
+
#### Configuration Priority
|
|
126
|
+
**Decision**: Code > Environment Variables > INI File > Defaults
|
|
127
|
+
|
|
128
|
+
**Rationale**:
|
|
129
|
+
- Code config for programmatic control (tests, dynamic config)
|
|
130
|
+
- Environment variables for deployment (Docker, cloud platforms)
|
|
131
|
+
- INI file for local development and simple deployments
|
|
132
|
+
- Defaults prevent configuration errors from breaking initialization
|
|
133
|
+
|
|
134
|
+
### Security
|
|
135
|
+
|
|
136
|
+
- Path validation prevents directory traversal attacks
|
|
137
|
+
- Filename sanitization removes dangerous characters
|
|
138
|
+
- Extension whitelisting prevents unwanted file types
|
|
139
|
+
- File size limits prevent resource exhaustion
|
|
140
|
+
- OAuth 2.0 for Google Drive with automatic token refresh
|
|
141
|
+
- No client-side credential exposure
|
|
142
|
+
|
|
143
|
+
### Performance
|
|
144
|
+
|
|
145
|
+
- Local storage: Sub-10ms operations for most actions
|
|
146
|
+
- Google Drive: 200-1000ms operations (network-dependent)
|
|
147
|
+
- Stream-based transfers for memory efficiency
|
|
148
|
+
- Lazy loading for folder tree
|
|
149
|
+
- Progress tracking without blocking
|
|
150
|
+
|
|
151
|
+
### Dependencies
|
|
152
|
+
|
|
153
|
+
#### Runtime
|
|
154
|
+
- `googleapis` (^140.0.1): Google Drive API client
|
|
155
|
+
- `ini` (^4.1.3): INI file parsing
|
|
156
|
+
|
|
157
|
+
#### Development
|
|
158
|
+
- `typescript` (^5.3.3): TypeScript compiler
|
|
159
|
+
- `tsup` (^8.0.1): Build tool
|
|
160
|
+
- `vitest` (^1.1.0): Testing framework
|
|
161
|
+
|
|
162
|
+
#### Peer Dependencies
|
|
163
|
+
- `react` (^18.0.0): For UI components
|
|
164
|
+
- `react-dom` (^18.0.0): For UI components
|
|
165
|
+
|
|
166
|
+
### Known Limitations
|
|
167
|
+
|
|
168
|
+
- Google Drive path resolution requires multiple API calls (O(n) where n = path depth)
|
|
169
|
+
- No built-in caching for Google Drive path-to-ID mappings
|
|
170
|
+
- UI components do not implement virtual scrolling for large directories
|
|
171
|
+
- File preview loads entire file into memory
|
|
172
|
+
- No batch operation support for Google Drive
|
|
173
|
+
- Local storage requires shared filesystem for horizontal scaling
|
|
174
|
+
|
|
175
|
+
### Migration Notes
|
|
176
|
+
|
|
177
|
+
This is the initial release, no migration required.
|
|
178
|
+
|
|
179
|
+
### Contributors
|
|
180
|
+
|
|
181
|
+
- Pubs Abayasiri (Creator and maintainer)
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## [Unreleased]
|
|
186
|
+
|
|
187
|
+
### Added
|
|
188
|
+
|
|
189
|
+
#### Naming Rules Configuration System (2025-12-09)
|
|
190
|
+
|
|
191
|
+
**Feature**: Comprehensive naming rules system for generating consistent file and folder names.
|
|
192
|
+
|
|
193
|
+
**Core Types** (`src/types/naming.ts`):
|
|
194
|
+
- `NamingVariable` - Define custom and system variables with descriptions and examples
|
|
195
|
+
- `PatternSegment` - Building blocks for naming patterns (variable or literal)
|
|
196
|
+
- `NamingRuleSchema` - Complete schema with file and folder patterns, metadata
|
|
197
|
+
- `GeneratedNameResult` - Result object from name generation
|
|
198
|
+
- `NameGenerationOptions` - Options for controlling generation behavior
|
|
199
|
+
|
|
200
|
+
**Utility Functions** (`src/common/naming-utils.ts`):
|
|
201
|
+
- `hazo_files_generate_file_name()` - Generate file names from schemas
|
|
202
|
+
- `hazo_files_generate_folder_name()` - Generate folder paths from schemas
|
|
203
|
+
- `validateNamingRuleSchema()` - Validate schema structure
|
|
204
|
+
- `parsePatternString()` - Parse "{var}text" strings to segments
|
|
205
|
+
- `patternToString()` - Convert segments back to strings
|
|
206
|
+
- `formatDateToken()` - Format dates to various tokens (YYYY, MM, DD, etc.)
|
|
207
|
+
- `formatCounter()` - Format counter with zero padding
|
|
208
|
+
- `createVariableSegment()`, `createLiteralSegment()` - Segment builders
|
|
209
|
+
|
|
210
|
+
**System Variables**:
|
|
211
|
+
- **Date variables**: YYYY, YY, MM, M, DD, D, MMM, MMMM, YYYY-MM-DD, YYYY-MMM-DD, DD-MM-YYYY, MM-DD-YYYY
|
|
212
|
+
- **File metadata**: original_name, extension, ext
|
|
213
|
+
- **Counter**: counter (auto-incrementing with padding)
|
|
214
|
+
- Exported as constants: `SYSTEM_DATE_VARIABLES`, `SYSTEM_FILE_VARIABLES`, `SYSTEM_COUNTER_VARIABLES`, `ALL_SYSTEM_VARIABLES`
|
|
215
|
+
|
|
216
|
+
**UI Components** (`src/ui/components/naming/`):
|
|
217
|
+
- `NamingRuleConfigurator` - Main drop-in component for visual pattern building
|
|
218
|
+
- `VariableList` - Category tabs (User/Date/File/Counter) with draggable variables
|
|
219
|
+
- `PatternBuilder` - Drag-and-drop zones for file and folder patterns
|
|
220
|
+
- `PatternPreview` - Live preview of generated names with example values
|
|
221
|
+
- `PatternSegmentItem` - Individual segments in patterns (editable/removable)
|
|
222
|
+
- `DraggableVariable` - Draggable variable chips
|
|
223
|
+
- `SeparatorPicker` - Quick-add common separators (-, _, space, /)
|
|
224
|
+
|
|
225
|
+
**Hooks** (`src/ui/hooks/useNamingRule.ts`):
|
|
226
|
+
- `useNamingRule` - State management for naming patterns with:
|
|
227
|
+
- Undo/redo support (max 50 history entries)
|
|
228
|
+
- Keyboard shortcuts (Ctrl+Z, Ctrl+Y, Ctrl+Shift+Z)
|
|
229
|
+
- Pattern manipulation functions (add, remove, update, reorder, clear)
|
|
230
|
+
- Schema import/export
|
|
231
|
+
- isDirty tracking
|
|
232
|
+
|
|
233
|
+
**Configuration** (`hazo_files_config.ini`):
|
|
234
|
+
- New `[naming]` section
|
|
235
|
+
- `date_formats` setting for customizing available date format tokens
|
|
236
|
+
|
|
237
|
+
**Dependencies**:
|
|
238
|
+
- Added peer dependencies: `@dnd-kit/core`, `@dnd-kit/sortable`, `@dnd-kit/utilities` (for drag-and-drop UI)
|
|
239
|
+
|
|
240
|
+
**Design Decisions**:
|
|
241
|
+
|
|
242
|
+
**Variable-based Pattern System**:
|
|
243
|
+
- **Decision**: Use segment-based patterns instead of regex or string templates
|
|
244
|
+
- **Rationale**:
|
|
245
|
+
- Type-safe with full IDE support
|
|
246
|
+
- Easier to manipulate programmatically
|
|
247
|
+
- Works well with React drag-and-drop
|
|
248
|
+
- Clear separation between variables and literals
|
|
249
|
+
- Enables visual editing without string parsing complexity
|
|
250
|
+
|
|
251
|
+
**System vs User Variables**:
|
|
252
|
+
- **Decision**: Separate system variables (dates, file metadata) from user variables
|
|
253
|
+
- **Rationale**:
|
|
254
|
+
- System variables work automatically without configuration
|
|
255
|
+
- User variables are application-specific
|
|
256
|
+
- Category-based UI organization improves UX
|
|
257
|
+
- Clear distinction prevents naming conflicts
|
|
258
|
+
|
|
259
|
+
**Undo/Redo System**:
|
|
260
|
+
- **Decision**: Implement history with keyboard shortcuts in the hook
|
|
261
|
+
- **Rationale**:
|
|
262
|
+
- Essential for pattern building workflow
|
|
263
|
+
- Users expect standard shortcuts (Ctrl+Z)
|
|
264
|
+
- Separates history logic from UI components
|
|
265
|
+
- 50-entry limit prevents memory issues
|
|
266
|
+
|
|
267
|
+
**Prefix Convention**:
|
|
268
|
+
- **Decision**: Use `hazo_files_` prefix for main generation functions
|
|
269
|
+
- **Rationale**:
|
|
270
|
+
- Prevents naming conflicts with user code
|
|
271
|
+
- Makes functions easily discoverable
|
|
272
|
+
- Consistent with package naming
|
|
273
|
+
- Clear these are primary API functions
|
|
274
|
+
|
|
275
|
+
**Use Cases**:
|
|
276
|
+
- Document management systems requiring consistent naming
|
|
277
|
+
- Automated file organization workflows
|
|
278
|
+
- Multi-tenant applications with client-specific naming
|
|
279
|
+
- Date-based archival systems
|
|
280
|
+
- Sequential numbering for versioned documents
|
|
281
|
+
|
|
282
|
+
### Fixed
|
|
283
|
+
|
|
284
|
+
#### NamingRuleConfigurator Drag-and-Drop Issues (2025-12-10)
|
|
285
|
+
|
|
286
|
+
**Fixed drag-and-drop for variables into patterns**:
|
|
287
|
+
- **Problem**: Variables from VariableList could not be dragged into PatternBuilder drop zones
|
|
288
|
+
- **Root Cause**: PatternBuilder had a nested DndContext that blocked drag events from the parent NamingRuleConfigurator
|
|
289
|
+
- **Solution**: Removed nested DndContext from PatternBuilder. Now uses single parent DndContext in NamingRuleConfigurator with SortableContext and useDroppable only in PatternBuilder
|
|
290
|
+
- **Impact**: Variables can now be dragged from the variable list into file and folder pattern areas
|
|
291
|
+
- **Files Changed**: `src/ui/components/naming/PatternBuilder.tsx`, `src/ui/components/naming/NamingRuleConfigurator.tsx`
|
|
292
|
+
|
|
293
|
+
**Why Nested DndContext Fails**: @dnd-kit prevents nested DndContext to avoid event bubbling conflicts. Child contexts block drag events from reaching parent handlers. Always use a single top-level DndContext with droppable/sortable children.
|
|
294
|
+
|
|
295
|
+
**Fixed segment reordering within patterns**:
|
|
296
|
+
- **Problem**: Segments could not be reordered by dragging within the same pattern
|
|
297
|
+
- **Root Cause**: handleDragEnd in NamingRuleConfigurator didn't handle the reordering case, only handled new variable drops
|
|
298
|
+
- **Solution**: Added Case 2 logic to handleDragEnd that detects when dragging between segments in the same pattern and calls reorderFilePattern or reorderFolderPattern with the correct indices
|
|
299
|
+
- **Impact**: Users can now reorder segments by dragging them to new positions within file or folder patterns
|
|
300
|
+
- **Files Changed**: `src/ui/components/naming/NamingRuleConfigurator.tsx`
|
|
301
|
+
|
|
302
|
+
**Improved drag activation sensitivity**:
|
|
303
|
+
- **Change**: Added PointerSensor with 8px activation distance
|
|
304
|
+
- **Rationale**: Prevents accidental drags when clicking on variables or segments
|
|
305
|
+
- **Impact**: More intentional drag interactions, better UX
|
|
306
|
+
- **Files Changed**: `src/ui/components/naming/NamingRuleConfigurator.tsx`
|
|
307
|
+
|
|
308
|
+
**Added visual drag feedback**:
|
|
309
|
+
- **Change**: Implemented DragOverlay showing the dragged variable during drag operation
|
|
310
|
+
- **Rationale**: Provides clear visual feedback of what is being dragged
|
|
311
|
+
- **Impact**: Users can see the variable chip following their cursor during drag
|
|
312
|
+
- **Files Changed**: `src/ui/components/naming/NamingRuleConfigurator.tsx`
|
|
313
|
+
|
|
314
|
+
**Made NamingRuleConfigurator content scrollable**:
|
|
315
|
+
- **Problem**: With many variables or long patterns, content overflowed the container with no way to scroll
|
|
316
|
+
- **Solution**: Wrapped Available Variables, Pattern Builders, and Preview sections in a scrollable container with `flex-1 overflow-y-auto min-h-0`, keeping Action Bar fixed at bottom
|
|
317
|
+
- **Impact**: Component now works well in fixed-height containers, all content is accessible via scroll
|
|
318
|
+
- **Files Changed**: `src/ui/components/naming/NamingRuleConfigurator.tsx`
|
|
319
|
+
|
|
320
|
+
### Planned Features
|
|
321
|
+
|
|
322
|
+
- Amazon S3 storage module
|
|
323
|
+
- Dropbox storage module
|
|
324
|
+
- OneDrive storage module
|
|
325
|
+
- WebDAV support
|
|
326
|
+
- Path caching for Google Drive (performance optimization)
|
|
327
|
+
- Batch operations for Google Drive
|
|
328
|
+
- Virtual scrolling for large file lists
|
|
329
|
+
- File versioning support
|
|
330
|
+
- Sharing and permissions system
|
|
331
|
+
- Advanced search and filtering
|
|
332
|
+
- Thumbnail generation
|
|
333
|
+
- File compression/decompression
|
|
334
|
+
- Trash/recycle bin functionality
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
**Note**: This changelog follows the principles of [Keep a Changelog](https://keepachangelog.com). Each version should be documented with Added, Changed, Deprecated, Removed, Fixed, and Security sections as applicable.
|
|
339
|
+
|
|
340
|
+
[1.0.0]: https://github.com/pub12/hazo_files/releases/tag/v1.0.0
|
|
341
|
+
[Unreleased]: https://github.com/pub12/hazo_files/compare/v1.0.0...HEAD
|