hazo_files 1.4.2 → 1.4.4
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/README.md +103 -9
- package/dist/index.d.mts +288 -8
- package/dist/index.d.ts +288 -8
- package/dist/index.js +842 -16
- package/dist/index.mjs +835 -16
- package/dist/server/index.d.mts +298 -11
- package/dist/server/index.d.ts +298 -11
- package/dist/server/index.js +849 -19
- package/dist/server/index.mjs +842 -19
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A powerful, modular file management package for Node.js and React applications w
|
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
|
-
- **Multiple Storage Providers**: Local filesystem
|
|
10
|
+
- **Multiple Storage Providers**: Local filesystem, Google Drive, and Dropbox support out of the box
|
|
11
11
|
- **Modular Architecture**: Easily add custom storage providers
|
|
12
12
|
- **Unified API**: Single consistent interface across all storage providers
|
|
13
13
|
- **React UI Components**: Drop-in FileBrowser component with folder tree, file list, and preview
|
|
@@ -18,9 +18,11 @@ A powerful, modular file management package for Node.js and React applications w
|
|
|
18
18
|
- **Upload + Extract Workflow**: Combined service for uploading files with automatic LLM extraction and naming
|
|
19
19
|
- **File Reference Tracking**: Multi-entity file references with orphan detection, soft delete, and lifecycle management
|
|
20
20
|
- **File Change Detection**: xxHash-based content hashing for efficient change detection
|
|
21
|
-
- **
|
|
21
|
+
- **Content Tagging**: Optional LLM-based content classification at upload time or on-demand via `content_tag` field
|
|
22
|
+
- **Schema Migrations**: Built-in V2/V3 migration utilities for adding reference tracking and content tagging to existing databases
|
|
22
23
|
- **TypeScript**: Full type safety and IntelliSense support
|
|
23
|
-
- **OAuth Integration**: Built-in Google Drive OAuth authentication
|
|
24
|
+
- **OAuth Integration**: Built-in Google Drive and Dropbox OAuth authentication
|
|
25
|
+
- **Prompt Cache Invalidation**: Passthrough for hazo_llm_api prompt cache management via server instance
|
|
24
26
|
- **Progress Tracking**: Upload/download progress callbacks
|
|
25
27
|
- **File Validation**: Extension filtering and file size limits
|
|
26
28
|
- **Error Handling**: Comprehensive error types and handling
|
|
@@ -1108,11 +1110,17 @@ const extractionService = new LLMExtractionService((provider, options) => {
|
|
|
1108
1110
|
return createLLM({ provider, ...options });
|
|
1109
1111
|
}, 'gemini');
|
|
1110
1112
|
|
|
1111
|
-
// Create upload + extract service
|
|
1113
|
+
// Create upload + extract service (with optional content tag config)
|
|
1112
1114
|
const uploadExtract = new UploadExtractService(
|
|
1113
1115
|
trackedFileManager,
|
|
1114
1116
|
namingService,
|
|
1115
|
-
extractionService
|
|
1117
|
+
extractionService,
|
|
1118
|
+
{
|
|
1119
|
+
content_tag_set_by_llm: true,
|
|
1120
|
+
content_tag_prompt_area: 'classification',
|
|
1121
|
+
content_tag_prompt_key: 'classify_document',
|
|
1122
|
+
content_tag_prompt_return_fieldname: 'document_type',
|
|
1123
|
+
}
|
|
1116
1124
|
);
|
|
1117
1125
|
|
|
1118
1126
|
// Upload with extraction and naming convention
|
|
@@ -1140,6 +1148,8 @@ if (result.success) {
|
|
|
1140
1148
|
console.log('Uploaded to:', result.generatedPath);
|
|
1141
1149
|
// e.g., '/documents/2024/ACME/ACME_Q4_2024-12-09_001.pdf'
|
|
1142
1150
|
console.log('Extracted data:', result.extraction?.data);
|
|
1151
|
+
console.log('Content tag:', result.contentTag);
|
|
1152
|
+
// e.g., 'invoice', 'report', 'contract'
|
|
1143
1153
|
}
|
|
1144
1154
|
|
|
1145
1155
|
// Generate path preview without uploading
|
|
@@ -1164,7 +1174,10 @@ const folderResult = await uploadExtract.createFolderFromConvention(
|
|
|
1164
1174
|
```typescript
|
|
1165
1175
|
import { LLMExtractionService } from 'hazo_files';
|
|
1166
1176
|
|
|
1167
|
-
const extractionService = new LLMExtractionService(
|
|
1177
|
+
const extractionService = new LLMExtractionService({
|
|
1178
|
+
create: llmFactory,
|
|
1179
|
+
invalidateCache: (area, key) => invalidate_prompt_cache(area, key), // optional
|
|
1180
|
+
}, 'gemini');
|
|
1168
1181
|
|
|
1169
1182
|
// Extract from document
|
|
1170
1183
|
const result = await extractionService.extractFromDocument(
|
|
@@ -1194,6 +1207,74 @@ const autoResult = await extractionService.extract(
|
|
|
1194
1207
|
);
|
|
1195
1208
|
```
|
|
1196
1209
|
|
|
1210
|
+
## Content Tagging
|
|
1211
|
+
|
|
1212
|
+
Automatically classify uploaded files using LLM-based content analysis. The `content_tag` field stores a classification string (e.g., "invoice", "report", "contract") determined by an LLM prompt.
|
|
1213
|
+
|
|
1214
|
+
### Configuration
|
|
1215
|
+
|
|
1216
|
+
```typescript
|
|
1217
|
+
import type { ContentTagConfig } from 'hazo_files';
|
|
1218
|
+
|
|
1219
|
+
const contentTagConfig: ContentTagConfig = {
|
|
1220
|
+
content_tag_set_by_llm: true,
|
|
1221
|
+
content_tag_prompt_area: 'classification',
|
|
1222
|
+
content_tag_prompt_key: 'classify_document',
|
|
1223
|
+
content_tag_prompt_return_fieldname: 'document_type',
|
|
1224
|
+
content_tag_prompt_variables: { language: 'en' }, // optional
|
|
1225
|
+
};
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
### Automatic Tagging at Upload
|
|
1229
|
+
|
|
1230
|
+
Pass `contentTagConfig` to `UploadExtractService` constructor (default for all uploads) or per-upload via options:
|
|
1231
|
+
|
|
1232
|
+
```typescript
|
|
1233
|
+
// Per-upload override
|
|
1234
|
+
const result = await uploadExtract.uploadWithExtract(buffer, 'file.pdf', {
|
|
1235
|
+
basePath: '/docs',
|
|
1236
|
+
contentTagConfig: {
|
|
1237
|
+
content_tag_set_by_llm: true,
|
|
1238
|
+
content_tag_prompt_area: 'classification',
|
|
1239
|
+
content_tag_prompt_key: 'classify_document',
|
|
1240
|
+
content_tag_prompt_return_fieldname: 'document_type',
|
|
1241
|
+
},
|
|
1242
|
+
});
|
|
1243
|
+
console.log(result.contentTag); // e.g., 'invoice'
|
|
1244
|
+
```
|
|
1245
|
+
|
|
1246
|
+
### Manual Tagging
|
|
1247
|
+
|
|
1248
|
+
Tag existing files by their database record ID:
|
|
1249
|
+
|
|
1250
|
+
```typescript
|
|
1251
|
+
const tagResult = await uploadExtract.tagFileContent('file-record-id');
|
|
1252
|
+
if (tagResult.success) {
|
|
1253
|
+
console.log('Tagged as:', tagResult.data);
|
|
1254
|
+
}
|
|
1255
|
+
```
|
|
1256
|
+
|
|
1257
|
+
### V3 Database Migration
|
|
1258
|
+
|
|
1259
|
+
If you have an existing `hazo_files` table, run the V3 migration to add the `content_tag` column:
|
|
1260
|
+
|
|
1261
|
+
```typescript
|
|
1262
|
+
import { migrateToV3, HAZO_FILES_MIGRATION_V3 } from 'hazo_files';
|
|
1263
|
+
|
|
1264
|
+
// Using the migration helper
|
|
1265
|
+
await migrateToV3(
|
|
1266
|
+
{ run: (sql) => db.run(sql) },
|
|
1267
|
+
'sqlite'
|
|
1268
|
+
);
|
|
1269
|
+
|
|
1270
|
+
// Or run statements manually
|
|
1271
|
+
for (const stmt of HAZO_FILES_MIGRATION_V3.sqlite.alterStatements) {
|
|
1272
|
+
try { await db.run(stmt); } catch { /* column exists */ }
|
|
1273
|
+
}
|
|
1274
|
+
```
|
|
1275
|
+
|
|
1276
|
+
New tables created with `HAZO_FILES_TABLE_SCHEMA` already include the `content_tag` column.
|
|
1277
|
+
|
|
1197
1278
|
## File Reference Tracking
|
|
1198
1279
|
|
|
1199
1280
|
Track which entities (form fields, chat messages, etc.) reference each file. Multiple entities can reference the same file, enabling shared files without duplication.
|
|
@@ -1274,7 +1355,7 @@ for (const idx of HAZO_FILES_MIGRATION_V2.sqlite.indexes) {
|
|
|
1274
1355
|
}
|
|
1275
1356
|
```
|
|
1276
1357
|
|
|
1277
|
-
New tables created with `HAZO_FILES_TABLE_SCHEMA` already include V2 columns.
|
|
1358
|
+
New tables created with `HAZO_FILES_TABLE_SCHEMA` already include V2 columns. For V3 content tagging migration, see [Content Tagging](#content-tagging) above.
|
|
1278
1359
|
|
|
1279
1360
|
### Reference Tracking Types
|
|
1280
1361
|
|
|
@@ -1332,11 +1413,24 @@ const hazoFiles = await createHazoFilesServer({
|
|
|
1332
1413
|
local: { basePath: './storage' },
|
|
1333
1414
|
},
|
|
1334
1415
|
enableTracking: true,
|
|
1335
|
-
llmFactory:
|
|
1416
|
+
llmFactory: {
|
|
1417
|
+
create: (provider) => createLLM({ provider }),
|
|
1418
|
+
invalidateCache: (area, key) => invalidate_prompt_cache(area, key), // optional
|
|
1419
|
+
},
|
|
1420
|
+
// Optional: enable automatic content tagging for all uploads
|
|
1421
|
+
defaultContentTagConfig: {
|
|
1422
|
+
content_tag_set_by_llm: true,
|
|
1423
|
+
content_tag_prompt_area: 'classification',
|
|
1424
|
+
content_tag_prompt_key: 'classify_document',
|
|
1425
|
+
content_tag_prompt_return_fieldname: 'document_type',
|
|
1426
|
+
},
|
|
1336
1427
|
});
|
|
1337
1428
|
|
|
1338
1429
|
// Access all services
|
|
1339
|
-
const { fileManager, metadataService, namingService, extractionService, uploadExtractService } = hazoFiles;
|
|
1430
|
+
const { fileManager, metadataService, namingService, extractionService, uploadExtractService, invalidatePromptCache } = hazoFiles;
|
|
1431
|
+
|
|
1432
|
+
// Invalidate prompt cache without importing hazo_llm_api directly
|
|
1433
|
+
invalidatePromptCache?.('classification', 'classify_document');
|
|
1340
1434
|
```
|
|
1341
1435
|
|
|
1342
1436
|
## API Reference
|
package/dist/index.d.mts
CHANGED
|
@@ -185,6 +185,8 @@ interface FileMetadataInput {
|
|
|
185
185
|
uploaded_by?: string;
|
|
186
186
|
/** Original filename at upload time (V2) */
|
|
187
187
|
original_filename?: string;
|
|
188
|
+
/** Content tag classifying the document type (V3) */
|
|
189
|
+
content_tag?: string;
|
|
188
190
|
}
|
|
189
191
|
/**
|
|
190
192
|
* Input for updating an existing metadata record
|
|
@@ -258,6 +260,23 @@ interface RemoveExtractionOptions {
|
|
|
258
260
|
/** Merge strategy to use when recalculating (default: 'shallow') */
|
|
259
261
|
mergeStrategy?: 'shallow' | 'deep';
|
|
260
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* Configuration for LLM-based content tagging.
|
|
265
|
+
* When enabled, calls the LLM with a specific prompt and writes
|
|
266
|
+
* the extracted field value to the content_tag column.
|
|
267
|
+
*/
|
|
268
|
+
interface ContentTagConfig {
|
|
269
|
+
/** Whether to enable LLM-based content tagging */
|
|
270
|
+
content_tag_set_by_llm: boolean;
|
|
271
|
+
/** Prompt area for hazo_llm_api lookup */
|
|
272
|
+
content_tag_prompt_area: string;
|
|
273
|
+
/** Prompt key within the area */
|
|
274
|
+
content_tag_prompt_key: string;
|
|
275
|
+
/** Optional variables to substitute in the prompt template */
|
|
276
|
+
content_tag_prompt_variables?: Record<string, string>;
|
|
277
|
+
/** Field name to extract from the LLM response as the content tag */
|
|
278
|
+
content_tag_prompt_return_fieldname: string;
|
|
279
|
+
}
|
|
261
280
|
|
|
262
281
|
/**
|
|
263
282
|
* Naming convention types for hazo_files
|
|
@@ -412,6 +431,8 @@ interface FileMetadataRecordV2 extends FileMetadataRecord {
|
|
|
412
431
|
storage_verified_at?: string | null;
|
|
413
432
|
/** ISO timestamp when file was soft-deleted */
|
|
414
433
|
deleted_at?: string | null;
|
|
434
|
+
/** Content tag classifying the document type (V3) */
|
|
435
|
+
content_tag?: string | null;
|
|
415
436
|
}
|
|
416
437
|
/**
|
|
417
438
|
* Options for adding a reference to a file
|
|
@@ -493,7 +514,7 @@ interface UploadWithRefOptions {
|
|
|
493
514
|
* Core types for the hazo_files package
|
|
494
515
|
*/
|
|
495
516
|
/** Supported storage provider types */
|
|
496
|
-
type StorageProvider = 'local' | 'google_drive';
|
|
517
|
+
type StorageProvider = 'local' | 'google_drive' | 'dropbox';
|
|
497
518
|
/** File item representing a file in storage */
|
|
498
519
|
interface FileItem {
|
|
499
520
|
id: string;
|
|
@@ -521,11 +542,21 @@ interface FolderItem {
|
|
|
521
542
|
}
|
|
522
543
|
/** Union type for file system items */
|
|
523
544
|
type FileSystemItem = FileItem | FolderItem;
|
|
545
|
+
/** Dropbox specific configuration */
|
|
546
|
+
interface DropboxConfig {
|
|
547
|
+
clientId: string;
|
|
548
|
+
clientSecret: string;
|
|
549
|
+
redirectUri: string;
|
|
550
|
+
refreshToken?: string;
|
|
551
|
+
accessToken?: string;
|
|
552
|
+
rootPath?: string;
|
|
553
|
+
}
|
|
524
554
|
/** Configuration for the file manager */
|
|
525
555
|
interface HazoFilesConfig {
|
|
526
556
|
provider: StorageProvider;
|
|
527
557
|
local?: LocalStorageConfig;
|
|
528
558
|
google_drive?: GoogleDriveConfig;
|
|
559
|
+
dropbox?: DropboxConfig;
|
|
529
560
|
}
|
|
530
561
|
/** Local storage specific configuration */
|
|
531
562
|
interface LocalStorageConfig {
|
|
@@ -1004,7 +1035,7 @@ declare class FileMetadataService {
|
|
|
1004
1035
|
/**
|
|
1005
1036
|
* Update specific V2 fields on a record
|
|
1006
1037
|
*/
|
|
1007
|
-
updateFields(fileId: string, fields: Partial<Pick<FileMetadataRecordV2, 'scope_id' | 'uploaded_by' | 'original_filename' | 'storage_verified_at' | 'status'>>): Promise<boolean>;
|
|
1038
|
+
updateFields(fileId: string, fields: Partial<Pick<FileMetadataRecordV2, 'scope_id' | 'uploaded_by' | 'original_filename' | 'storage_verified_at' | 'status' | 'content_tag'>>): Promise<boolean>;
|
|
1008
1039
|
/**
|
|
1009
1040
|
* Find orphaned files (zero references)
|
|
1010
1041
|
*/
|
|
@@ -1408,6 +1439,13 @@ interface HazoLLMInstance {
|
|
|
1408
1439
|
* Factory function type for creating LLM instances
|
|
1409
1440
|
*/
|
|
1410
1441
|
type LLMFactory = (provider: LLMProvider, options?: Record<string, unknown>) => HazoLLMInstance | Promise<HazoLLMInstance>;
|
|
1442
|
+
/**
|
|
1443
|
+
* Extended LLM factory configuration with optional cache management
|
|
1444
|
+
*/
|
|
1445
|
+
interface LLMFactoryConfig {
|
|
1446
|
+
create: LLMFactory;
|
|
1447
|
+
invalidateCache?: (area?: string, key?: string) => void;
|
|
1448
|
+
}
|
|
1411
1449
|
/**
|
|
1412
1450
|
* LLM Extraction Service
|
|
1413
1451
|
*
|
|
@@ -1449,7 +1487,13 @@ type LLMFactory = (provider: LLMProvider, options?: Record<string, unknown>) =>
|
|
|
1449
1487
|
declare class LLMExtractionService {
|
|
1450
1488
|
private llmFactory;
|
|
1451
1489
|
private defaultProvider;
|
|
1452
|
-
|
|
1490
|
+
private cacheInvalidator?;
|
|
1491
|
+
constructor(factoryConfig: LLMFactoryConfig, defaultProvider?: LLMProvider);
|
|
1492
|
+
/**
|
|
1493
|
+
* Invalidate the LLM prompt cache
|
|
1494
|
+
* Passthrough to hazo_llm_api's invalidate_prompt_cache when configured
|
|
1495
|
+
*/
|
|
1496
|
+
invalidatePromptCache(area?: string, key?: string): void;
|
|
1453
1497
|
/**
|
|
1454
1498
|
* Extract data from a document
|
|
1455
1499
|
*
|
|
@@ -1481,10 +1525,10 @@ declare class LLMExtractionService {
|
|
|
1481
1525
|
/**
|
|
1482
1526
|
* Create an LLMExtractionService instance
|
|
1483
1527
|
*
|
|
1484
|
-
* @param
|
|
1528
|
+
* @param factoryConfig - LLM factory configuration with create function and optional cache invalidation
|
|
1485
1529
|
* @param defaultProvider - Default LLM provider (default: 'gemini')
|
|
1486
1530
|
*/
|
|
1487
|
-
declare function createLLMExtractionService(
|
|
1531
|
+
declare function createLLMExtractionService(factoryConfig: LLMFactoryConfig, defaultProvider?: LLMProvider): LLMExtractionService;
|
|
1488
1532
|
|
|
1489
1533
|
/**
|
|
1490
1534
|
* Upload + Extract Service
|
|
@@ -1532,6 +1576,11 @@ interface UploadExtractOptions extends TrackedUploadOptions {
|
|
|
1532
1576
|
* Whether to create the folder path if it doesn't exist
|
|
1533
1577
|
*/
|
|
1534
1578
|
createFolders?: boolean;
|
|
1579
|
+
/**
|
|
1580
|
+
* Content tag configuration for this upload.
|
|
1581
|
+
* Overrides the default config set on the service.
|
|
1582
|
+
*/
|
|
1583
|
+
contentTagConfig?: ContentTagConfig;
|
|
1535
1584
|
}
|
|
1536
1585
|
/**
|
|
1537
1586
|
* Result of upload with extraction
|
|
@@ -1551,6 +1600,8 @@ interface UploadExtractResult {
|
|
|
1551
1600
|
generatedFolderPath?: string;
|
|
1552
1601
|
/** Original file name before renaming */
|
|
1553
1602
|
originalFileName?: string;
|
|
1603
|
+
/** Content tag assigned by LLM (if content tagging was performed) */
|
|
1604
|
+
contentTag?: string;
|
|
1554
1605
|
}
|
|
1555
1606
|
/**
|
|
1556
1607
|
* Options for creating folders from naming convention
|
|
@@ -1608,7 +1659,8 @@ declare class UploadExtractService {
|
|
|
1608
1659
|
private fileManager;
|
|
1609
1660
|
private namingService?;
|
|
1610
1661
|
private extractionService?;
|
|
1611
|
-
|
|
1662
|
+
private defaultContentTagConfig?;
|
|
1663
|
+
constructor(fileManager: TrackedFileManager, namingService?: NamingConventionService, extractionService?: LLMExtractionService, defaultContentTagConfig?: ContentTagConfig);
|
|
1612
1664
|
/**
|
|
1613
1665
|
* Upload a file with optional extraction and naming convention
|
|
1614
1666
|
*/
|
|
@@ -1633,6 +1685,21 @@ declare class UploadExtractService {
|
|
|
1633
1685
|
fullPath?: string;
|
|
1634
1686
|
folderPath?: string;
|
|
1635
1687
|
}>;
|
|
1688
|
+
/**
|
|
1689
|
+
* Perform content tagging via LLM extraction.
|
|
1690
|
+
* Calls the LLM with the configured prompt, extracts the specified field,
|
|
1691
|
+
* and writes it to the content_tag column.
|
|
1692
|
+
*/
|
|
1693
|
+
private performContentTagging;
|
|
1694
|
+
/**
|
|
1695
|
+
* Manually tag a file's content via LLM.
|
|
1696
|
+
* Works with existing DB records, resolving the file path internally.
|
|
1697
|
+
*
|
|
1698
|
+
* @param fileId - Database record ID of the file
|
|
1699
|
+
* @param config - Content tag config (falls back to default if not provided)
|
|
1700
|
+
* @returns OperationResult with the tag value
|
|
1701
|
+
*/
|
|
1702
|
+
tagFileContent(fileId: string, config?: ContentTagConfig): Promise<OperationResult<string>>;
|
|
1636
1703
|
/**
|
|
1637
1704
|
* Get the file manager
|
|
1638
1705
|
*/
|
|
@@ -1649,7 +1716,7 @@ declare class UploadExtractService {
|
|
|
1649
1716
|
/**
|
|
1650
1717
|
* Create an UploadExtractService instance
|
|
1651
1718
|
*/
|
|
1652
|
-
declare function createUploadExtractService(fileManager: TrackedFileManager, namingService?: NamingConventionService, extractionService?: LLMExtractionService): UploadExtractService;
|
|
1719
|
+
declare function createUploadExtractService(fileManager: TrackedFileManager, namingService?: NamingConventionService, extractionService?: LLMExtractionService, defaultContentTagConfig?: ContentTagConfig): UploadExtractService;
|
|
1653
1720
|
|
|
1654
1721
|
/**
|
|
1655
1722
|
* Configuration loader for hazo_files
|
|
@@ -1743,6 +1810,8 @@ interface HazoFilesColumnDefinitions {
|
|
|
1743
1810
|
deleted_at: 'TEXT' | 'TIMESTAMP';
|
|
1744
1811
|
/** Original filename at upload time (V2) */
|
|
1745
1812
|
original_filename: 'TEXT';
|
|
1813
|
+
/** Content tag classifying the document type (V3) */
|
|
1814
|
+
content_tag: 'TEXT';
|
|
1746
1815
|
}
|
|
1747
1816
|
/**
|
|
1748
1817
|
* Schema definition for a specific database type
|
|
@@ -1925,6 +1994,46 @@ declare const HAZO_FILES_NAMING_TABLE_SCHEMA: HazoFilesNamingTableSchema;
|
|
|
1925
1994
|
* Get DDL for a custom naming table name
|
|
1926
1995
|
*/
|
|
1927
1996
|
declare function getNamingSchemaForTable(tableName: string, dbType: 'sqlite' | 'postgres'): DatabaseSchemaDefinition;
|
|
1997
|
+
/**
|
|
1998
|
+
* Migration schema for adding V3 content tagging column to existing tables.
|
|
1999
|
+
* Idempotent — safe to run multiple times.
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* ```typescript
|
|
2003
|
+
* import { HAZO_FILES_MIGRATION_V3 } from 'hazo_files';
|
|
2004
|
+
*
|
|
2005
|
+
* // SQLite
|
|
2006
|
+
* for (const stmt of HAZO_FILES_MIGRATION_V3.sqlite.alterStatements) {
|
|
2007
|
+
* try { await db.run(stmt); } catch { /* column already exists *\/ }
|
|
2008
|
+
* }
|
|
2009
|
+
* for (const idx of HAZO_FILES_MIGRATION_V3.sqlite.indexes) {
|
|
2010
|
+
* await db.run(idx);
|
|
2011
|
+
* }
|
|
2012
|
+
*
|
|
2013
|
+
* // PostgreSQL
|
|
2014
|
+
* for (const stmt of HAZO_FILES_MIGRATION_V3.postgres.alterStatements) {
|
|
2015
|
+
* await client.query(stmt);
|
|
2016
|
+
* }
|
|
2017
|
+
* for (const idx of HAZO_FILES_MIGRATION_V3.postgres.indexes) {
|
|
2018
|
+
* await client.query(idx);
|
|
2019
|
+
* }
|
|
2020
|
+
* ```
|
|
2021
|
+
*/
|
|
2022
|
+
interface HazoFilesMigrationV3 {
|
|
2023
|
+
/** Default table name */
|
|
2024
|
+
tableName: string;
|
|
2025
|
+
/** SQLite migration statements */
|
|
2026
|
+
sqlite: MigrationSchemaDefinition;
|
|
2027
|
+
/** PostgreSQL migration statements */
|
|
2028
|
+
postgres: MigrationSchemaDefinition;
|
|
2029
|
+
/** New column names added in V3 */
|
|
2030
|
+
newColumns: readonly string[];
|
|
2031
|
+
}
|
|
2032
|
+
declare const HAZO_FILES_MIGRATION_V3: HazoFilesMigrationV3;
|
|
2033
|
+
/**
|
|
2034
|
+
* Get V3 migration statements for a custom table name
|
|
2035
|
+
*/
|
|
2036
|
+
declare function getMigrationV3ForTable(tableName: string, dbType: 'sqlite' | 'postgres'): MigrationSchemaDefinition;
|
|
1928
2037
|
|
|
1929
2038
|
/**
|
|
1930
2039
|
* Migration: Add Reference Tracking (V2)
|
|
@@ -1967,6 +2076,33 @@ declare function migrateToV2(executor: MigrationExecutor, dbType: 'sqlite' | 'po
|
|
|
1967
2076
|
*/
|
|
1968
2077
|
declare function backfillV2Defaults(executor: MigrationExecutor, dbType: 'sqlite' | 'postgres', tableName?: string): Promise<void>;
|
|
1969
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* Migration: Add Content Tag (V3)
|
|
2081
|
+
*
|
|
2082
|
+
* Adds content_tag column to an existing hazo_files table.
|
|
2083
|
+
* Idempotent — safe to run multiple times.
|
|
2084
|
+
*/
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* Run the V3 migration: add content_tag column and index.
|
|
2088
|
+
*
|
|
2089
|
+
* @param executor - Object with a `run(sql)` method
|
|
2090
|
+
* @param dbType - Database type ('sqlite' | 'postgres')
|
|
2091
|
+
* @param tableName - Custom table name (defaults to 'hazo_files')
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```typescript
|
|
2095
|
+
* import { migrateToV3 } from 'hazo_files';
|
|
2096
|
+
*
|
|
2097
|
+
* // SQLite with better-sqlite3
|
|
2098
|
+
* await migrateToV3({ run: (sql) => db.exec(sql) }, 'sqlite');
|
|
2099
|
+
*
|
|
2100
|
+
* // PostgreSQL with pg
|
|
2101
|
+
* await migrateToV3({ run: (sql) => client.query(sql) }, 'postgres');
|
|
2102
|
+
* ```
|
|
2103
|
+
*/
|
|
2104
|
+
declare function migrateToV3(executor: MigrationExecutor, dbType: 'sqlite' | 'postgres', tableName?: string): Promise<void>;
|
|
2105
|
+
|
|
1970
2106
|
/**
|
|
1971
2107
|
* Common utility functions
|
|
1972
2108
|
*/
|
|
@@ -2336,6 +2472,150 @@ declare class GoogleDriveModule extends BaseStorageModule {
|
|
|
2336
2472
|
*/
|
|
2337
2473
|
declare function createGoogleDriveModule(): GoogleDriveModule;
|
|
2338
2474
|
|
|
2475
|
+
/**
|
|
2476
|
+
* Dropbox OAuth Authentication Handler
|
|
2477
|
+
* Manages OAuth flow, token storage, and token refresh
|
|
2478
|
+
*/
|
|
2479
|
+
interface DropboxAuthConfig {
|
|
2480
|
+
clientId: string;
|
|
2481
|
+
clientSecret: string;
|
|
2482
|
+
redirectUri: string;
|
|
2483
|
+
}
|
|
2484
|
+
interface DropboxTokenData {
|
|
2485
|
+
accessToken: string;
|
|
2486
|
+
refreshToken: string;
|
|
2487
|
+
expiryDate?: number;
|
|
2488
|
+
}
|
|
2489
|
+
interface DropboxAuthCallbacks {
|
|
2490
|
+
onTokensUpdated?: (tokens: DropboxTokenData) => Promise<void>;
|
|
2491
|
+
getStoredTokens?: () => Promise<DropboxTokenData | null>;
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* Dropbox Authentication Manager
|
|
2495
|
+
*/
|
|
2496
|
+
declare class DropboxAuth {
|
|
2497
|
+
private config;
|
|
2498
|
+
private callbacks;
|
|
2499
|
+
private tokens;
|
|
2500
|
+
constructor(config: DropboxAuthConfig, callbacks?: DropboxAuthCallbacks);
|
|
2501
|
+
/**
|
|
2502
|
+
* Generate the authorization URL for OAuth consent
|
|
2503
|
+
*/
|
|
2504
|
+
getAuthUrl(state?: string): string;
|
|
2505
|
+
/**
|
|
2506
|
+
* Exchange authorization code for tokens
|
|
2507
|
+
*/
|
|
2508
|
+
exchangeCodeForTokens(code: string): Promise<DropboxTokenData>;
|
|
2509
|
+
/**
|
|
2510
|
+
* Set tokens directly (e.g., from stored tokens)
|
|
2511
|
+
*/
|
|
2512
|
+
setTokens(tokens: DropboxTokenData): Promise<void>;
|
|
2513
|
+
/**
|
|
2514
|
+
* Load tokens from storage using callback
|
|
2515
|
+
*/
|
|
2516
|
+
loadStoredTokens(): Promise<boolean>;
|
|
2517
|
+
/**
|
|
2518
|
+
* Check if authenticated
|
|
2519
|
+
*/
|
|
2520
|
+
isAuthenticated(): boolean;
|
|
2521
|
+
/**
|
|
2522
|
+
* Get current tokens
|
|
2523
|
+
*/
|
|
2524
|
+
getTokens(): DropboxTokenData | null;
|
|
2525
|
+
/**
|
|
2526
|
+
* Get current access token
|
|
2527
|
+
*/
|
|
2528
|
+
getAccessToken(): string | null;
|
|
2529
|
+
/**
|
|
2530
|
+
* Refresh the access token
|
|
2531
|
+
*/
|
|
2532
|
+
refreshAccessToken(): Promise<DropboxTokenData>;
|
|
2533
|
+
/**
|
|
2534
|
+
* Revoke access (disconnect)
|
|
2535
|
+
*/
|
|
2536
|
+
revokeAccess(): Promise<void>;
|
|
2537
|
+
/**
|
|
2538
|
+
* Check if token is expired or will expire soon
|
|
2539
|
+
*/
|
|
2540
|
+
isTokenExpired(bufferSeconds?: number): boolean;
|
|
2541
|
+
/**
|
|
2542
|
+
* Ensure valid access token (refresh if needed)
|
|
2543
|
+
*/
|
|
2544
|
+
ensureValidToken(): Promise<void>;
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Create a new DropboxAuth instance
|
|
2548
|
+
*/
|
|
2549
|
+
declare function createDropboxAuth(config: DropboxAuthConfig, callbacks?: DropboxAuthCallbacks): DropboxAuth;
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* Dropbox Storage Module
|
|
2553
|
+
* Implements file operations using Dropbox API via the official SDK
|
|
2554
|
+
*/
|
|
2555
|
+
|
|
2556
|
+
declare class DropboxModule extends BaseStorageModule {
|
|
2557
|
+
readonly provider: StorageProvider;
|
|
2558
|
+
private auth;
|
|
2559
|
+
private dbx;
|
|
2560
|
+
private rootPath;
|
|
2561
|
+
private authCallbacks;
|
|
2562
|
+
/**
|
|
2563
|
+
* Set authentication callbacks for token persistence
|
|
2564
|
+
*/
|
|
2565
|
+
setAuthCallbacks(callbacks: DropboxAuthCallbacks): void;
|
|
2566
|
+
initialize(config: HazoFilesConfig): Promise<void>;
|
|
2567
|
+
/**
|
|
2568
|
+
* Create/recreate the Dropbox SDK client with the current access token
|
|
2569
|
+
*/
|
|
2570
|
+
private createDropboxClient;
|
|
2571
|
+
/**
|
|
2572
|
+
* Get the auth instance for OAuth flow
|
|
2573
|
+
*/
|
|
2574
|
+
getAuth(): DropboxAuth;
|
|
2575
|
+
/**
|
|
2576
|
+
* Check if user is authenticated
|
|
2577
|
+
*/
|
|
2578
|
+
isAuthenticated(): boolean;
|
|
2579
|
+
/**
|
|
2580
|
+
* Authenticate with provided tokens
|
|
2581
|
+
*/
|
|
2582
|
+
authenticate(tokens: DropboxTokenData): Promise<void>;
|
|
2583
|
+
/**
|
|
2584
|
+
* Ensure authenticated before operations
|
|
2585
|
+
*/
|
|
2586
|
+
private ensureAuthenticated;
|
|
2587
|
+
/**
|
|
2588
|
+
* Convert virtual path to Dropbox path
|
|
2589
|
+
* Virtual: /folder/file.txt -> Dropbox: /folder/file.txt (or /rootPath/folder/file.txt)
|
|
2590
|
+
* Dropbox root is empty string "", not "/"
|
|
2591
|
+
*/
|
|
2592
|
+
private toDropboxPath;
|
|
2593
|
+
/**
|
|
2594
|
+
* Convert Dropbox metadata to FileSystemItem
|
|
2595
|
+
*/
|
|
2596
|
+
private metadataToItem;
|
|
2597
|
+
/**
|
|
2598
|
+
* Convert a Dropbox path_display to virtual path
|
|
2599
|
+
*/
|
|
2600
|
+
private toVirtualPath;
|
|
2601
|
+
createDirectory(virtualPath: string): Promise<OperationResult<FolderItem>>;
|
|
2602
|
+
removeDirectory(virtualPath: string, recursive?: boolean): Promise<OperationResult>;
|
|
2603
|
+
uploadFile(source: string | Buffer | ReadableStream, remotePath: string, options?: UploadOptions): Promise<OperationResult<FileItem>>;
|
|
2604
|
+
downloadFile(remotePath: string, localPath?: string, options?: DownloadOptions): Promise<OperationResult<Buffer | string>>;
|
|
2605
|
+
moveItem(sourcePath: string, destinationPath: string, _options?: MoveOptions): Promise<OperationResult<FileSystemItem>>;
|
|
2606
|
+
deleteFile(virtualPath: string): Promise<OperationResult>;
|
|
2607
|
+
renameFile(virtualPath: string, newName: string, _options?: RenameOptions): Promise<OperationResult<FileItem>>;
|
|
2608
|
+
renameFolder(virtualPath: string, newName: string, _options?: RenameOptions): Promise<OperationResult<FolderItem>>;
|
|
2609
|
+
listDirectory(virtualPath: string, options?: ListOptions): Promise<OperationResult<FileSystemItem[]>>;
|
|
2610
|
+
getItem(virtualPath: string): Promise<OperationResult<FileSystemItem>>;
|
|
2611
|
+
exists(virtualPath: string): Promise<boolean>;
|
|
2612
|
+
getFolderTree(path?: string, depth?: number): Promise<OperationResult<TreeNode[]>>;
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* Factory function to create a DropboxModule instance
|
|
2616
|
+
*/
|
|
2617
|
+
declare function createDropboxModule(): DropboxModule;
|
|
2618
|
+
|
|
2339
2619
|
/**
|
|
2340
2620
|
* Module Registry
|
|
2341
2621
|
* Central registry for all storage modules
|
|
@@ -2782,4 +3062,4 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
|
|
|
2782
3062
|
*/
|
|
2783
3063
|
declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
|
|
2784
3064
|
|
|
2785
|
-
export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type ExtractionData, type ExtractionOptions, type ExtractionResult, type FileBrowserState, type FileDataStructure, FileExistsError, type FileInfo, type FileItem, FileManager, type FileManagerOptions, type FileMetadataInput, type FileMetadataRecord, type FileMetadataRecordV2, FileMetadataService, type FileMetadataServiceOptions, type FileMetadataUpdate, FileNotFoundError, type FileRef, type FileRefVisibility, type FileStatus, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_MIGRATION_V2, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, type HazoFilesColumnDefinitions, type HazoFilesConfig, HazoFilesError, type HazoFilesMigrationV2, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesTableSchema, type HazoLLMInstance, InvalidExtensionError, InvalidPathError, LLMExtractionService, type LLMFactory, type LLMProvider, type ListNamingConventionsOptions, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MetadataLogger, type MigrationExecutor, type MigrationSchemaDefinition, type MoveOptions, type NameGenerationOptions, type NamingConventionInput, type NamingConventionRecord, NamingConventionService, type NamingConventionServiceOptions, type NamingConventionType, type NamingConventionUpdate, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type ParsedNamingConvention, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, TrackedFileManager, type TrackedFileManagerFullOptions, type TrackedFileManagerOptions, type TrackedUploadOptions, type TreeNode, type UploadExtractOptions, type UploadExtractResult, UploadExtractService, type UploadOptions, type UploadWithRefOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, addExtractionToFileData, backfillV2Defaults, buildFileWithStatus, clearExtractions, clonePattern, computeFileHash, computeFileHashFromStream, computeFileHashSync, computeFileInfo, createAndInitializeModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createTrackedFileManager, createUploadExtractService, createVariableSegment, deepMerge, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateExtractionId, generateId, generatePreviewName, generateRefId, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getExtractionById, getExtractionCount, getExtractions, getFileCategory, getFileMetadataValues, getMergedData, getMigrationForTable, getMimeType, getNameWithoutExtension, getNamingSchemaForTable, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSchemaForTable, getSystemVariablePreviewValues, hasExtension, hasExtractionStructure, hasFileContentChanged, hashesEqual, 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, migrateToV2, normalizePath, parseConfig, parseFileData, parseFileRefs, parsePatternString, patternToString, recalculateMergedData, registerModule, removeExtractionById, removeExtractionByIndex, removeRefFromArray, removeRefsByCriteriaFromArray, sanitizeFilename, saveConfig, sortItems, stringifyFileData, stringifyFileRefs, successResult, toV2Record, updateExtractionById, validateExtractionData, validateFileDataStructure, validateNamingRuleSchema, validatePath };
|
|
3065
|
+
export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type ContentTagConfig, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, DropboxAuth, type DropboxAuthCallbacks, type DropboxAuthConfig, type DropboxConfig, DropboxModule, type DropboxTokenData, type ExtractionData, type ExtractionOptions, type ExtractionResult, type FileBrowserState, type FileDataStructure, FileExistsError, type FileInfo, type FileItem, FileManager, type FileManagerOptions, type FileMetadataInput, type FileMetadataRecord, type FileMetadataRecordV2, FileMetadataService, type FileMetadataServiceOptions, type FileMetadataUpdate, FileNotFoundError, type FileRef, type FileRefVisibility, type FileStatus, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_MIGRATION_V2, HAZO_FILES_MIGRATION_V3, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, type HazoFilesColumnDefinitions, type HazoFilesConfig, HazoFilesError, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesTableSchema, type HazoLLMInstance, InvalidExtensionError, InvalidPathError, LLMExtractionService, type LLMFactory, type LLMFactoryConfig, type LLMProvider, type ListNamingConventionsOptions, type ListOptions, type LocalStorageConfig, LocalStorageModule, type MetadataLogger, type MigrationExecutor, type MigrationSchemaDefinition, type MoveOptions, type NameGenerationOptions, type NamingConventionInput, type NamingConventionRecord, NamingConventionService, type NamingConventionServiceOptions, type NamingConventionType, type NamingConventionUpdate, type NamingRuleConfiguratorProps, type NamingRuleHistoryEntry, type NamingRuleSchema, type NamingVariable, OperationError, type OperationResult, type ParsedNamingConvention, type PatternSegment, PermissionDeniedError, type ProgressCallback, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type StorageModule, type StorageProvider, type TokenData, TrackedFileManager, type TrackedFileManagerFullOptions, type TrackedFileManagerOptions, type TrackedUploadOptions, type TreeNode, type UploadExtractOptions, type UploadExtractResult, UploadExtractService, type UploadOptions, type UploadWithRefOptions, type UseNamingRuleActions, type UseNamingRuleReturn, type UseNamingRuleState, type VariableCategory, addExtractionToFileData, backfillV2Defaults, buildFileWithStatus, clearExtractions, clonePattern, computeFileHash, computeFileHashFromStream, computeFileHashSync, computeFileInfo, createAndInitializeModule, createDropboxAuth, createDropboxModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createTrackedFileManager, createUploadExtractService, createVariableSegment, deepMerge, errorResult, filterItems, formatBytes, formatCounter, formatDateToken, generateExtractionId, generateId, generatePreviewName, generateRefId, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getExtractionById, getExtractionCount, getExtractions, getFileCategory, getFileMetadataValues, getMergedData, getMigrationForTable, getMigrationV3ForTable, getMimeType, getNameWithoutExtension, getNamingSchemaForTable, getParentPath, getPathSegments, getRegisteredProviders, getRelativePath, getSchemaForTable, getSystemVariablePreviewValues, hasExtension, hasExtractionStructure, hasFileContentChanged, hashesEqual, 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, migrateToV2, migrateToV3, normalizePath, parseConfig, parseFileData, parseFileRefs, parsePatternString, patternToString, recalculateMergedData, registerModule, removeExtractionById, removeExtractionByIndex, removeRefFromArray, removeRefsByCriteriaFromArray, sanitizeFilename, saveConfig, sortItems, stringifyFileData, stringifyFileRefs, successResult, toV2Record, updateExtractionById, validateExtractionData, validateFileDataStructure, validateNamingRuleSchema, validatePath };
|