hazo_files 2.1.1 → 3.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.
@@ -1,5 +1,7 @@
1
1
  import { JobHandler } from 'hazo_jobs';
2
2
  import { Readable } from 'node:stream';
3
+ import { HazoAuthError, HazoConfigError, HazoConflictError, HazoNotFoundError, HazoValidationError, HazoExternalError } from 'hazo_core';
4
+ export { HazoError as HazoFilesError } from 'hazo_core';
3
5
  import { OAuth2Client } from 'google-auth-library';
4
6
 
5
7
  /**
@@ -2612,6 +2614,22 @@ interface ProbeResult {
2612
2614
  /** Free-form detail for logging. */
2613
2615
  message?: string;
2614
2616
  }
2617
+ /**
2618
+ * A single entry returned by `FileStorageProvider.list()`.
2619
+ *
2620
+ * `path` is the same logical namespace used by `put`/`get` — callers can pass
2621
+ * it directly back to those methods without any transformation.
2622
+ */
2623
+ interface FileEntry {
2624
+ /** Logical path within the provider (same namespace as put/get). */
2625
+ path: StoragePath;
2626
+ /** Bare filename or directory name (the last segment of `path`). */
2627
+ name: string;
2628
+ /** Size in bytes. 0 for directories. */
2629
+ size: number;
2630
+ /** True when this entry represents a directory. */
2631
+ isDirectory: boolean;
2632
+ }
2615
2633
  /**
2616
2634
  * Storage provider abstraction. Every method MUST be idempotent at the
2617
2635
  * data-content level — re-invoking put with identical body is allowed.
@@ -2626,6 +2644,24 @@ interface FileStorageProvider {
2626
2644
  getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
2627
2645
  /** Used by validation cron + onboarding step 2. */
2628
2646
  probe(): Promise<ProbeResult>;
2647
+ /**
2648
+ * List all entries (files and sub-directories) under a logical path prefix.
2649
+ * Results are recursive — all descendants are included.
2650
+ * Returns an empty array when the prefix does not exist.
2651
+ */
2652
+ list(prefix: StoragePath): Promise<FileEntry[]>;
2653
+ /**
2654
+ * Move bytes from `from` to `to`, creating any intermediate directories.
2655
+ * The source is removed on success.
2656
+ * Throws with a message containing "Not found" when `from` does not exist.
2657
+ */
2658
+ move(from: StoragePath, to: StoragePath): Promise<void>;
2659
+ /**
2660
+ * Rename a file or directory. `to` is the full new logical path.
2661
+ * Implementations may delegate to `move`.
2662
+ * Throws with a message containing "Not found" when `from` does not exist.
2663
+ */
2664
+ rename(from: StoragePath, to: StoragePath): Promise<void>;
2629
2665
  }
2630
2666
  declare class StorageCollisionExhausted extends Error {
2631
2667
  attempts: number;
@@ -2663,6 +2699,10 @@ declare class AppFileServerProvider implements FileStorageProvider {
2663
2699
  /** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
2664
2700
  verifySignedUrl(token: string, path: string): boolean;
2665
2701
  probe(): Promise<ProbeResult>;
2702
+ list(prefix: string): Promise<FileEntry[]>;
2703
+ private walkDir;
2704
+ move(from: string, to: string): Promise<void>;
2705
+ rename(from: string, to: string): Promise<void>;
2666
2706
  }
2667
2707
 
2668
2708
  declare class InMemoryProvider implements FileStorageProvider {
@@ -2674,6 +2714,9 @@ declare class InMemoryProvider implements FileStorageProvider {
2674
2714
  exists(path: string): Promise<boolean>;
2675
2715
  getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
2676
2716
  probe(): Promise<ProbeResult>;
2717
+ list(prefix: string): Promise<FileEntry[]>;
2718
+ move(from: string, to: string): Promise<void>;
2719
+ rename(from: string, to: string): Promise<void>;
2677
2720
  /** Test-only escape hatch — exposes the internal store for assertions. */
2678
2721
  snapshot(): Map<string, Buffer>;
2679
2722
  }
@@ -2703,6 +2746,9 @@ declare class GoogleDriveProvider implements FileStorageProvider {
2703
2746
  delete(path: string): Promise<void>;
2704
2747
  exists(path: string): Promise<boolean>;
2705
2748
  getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
2749
+ list(prefix: string): Promise<FileEntry[]>;
2750
+ move(from: string, to: string): Promise<void>;
2751
+ rename(from: string, to: string): Promise<void>;
2706
2752
  private resolvePath;
2707
2753
  private findChild;
2708
2754
  private lookupFileId;
@@ -3348,55 +3394,52 @@ declare function saveConfig(config: HazoFilesConfig, configPath?: string): Promi
3348
3394
 
3349
3395
  /**
3350
3396
  * Custom error classes for hazo_files
3397
+ * All errors extend the appropriate hazo_core subclass.
3351
3398
  */
3352
- declare class HazoFilesError extends Error {
3353
- code: string;
3354
- details?: Record<string, unknown> | undefined;
3355
- constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
3356
- }
3357
- declare class FileNotFoundError extends HazoFilesError {
3399
+
3400
+ declare class FileNotFoundError extends HazoNotFoundError {
3358
3401
  constructor(path: string);
3359
3402
  }
3360
- declare class DirectoryNotFoundError extends HazoFilesError {
3403
+ declare class DirectoryNotFoundError extends HazoNotFoundError {
3361
3404
  constructor(path: string);
3362
3405
  }
3363
- declare class FileExistsError extends HazoFilesError {
3406
+ declare class FileExistsError extends HazoConflictError {
3364
3407
  constructor(path: string);
3365
3408
  }
3366
- declare class DirectoryExistsError extends HazoFilesError {
3409
+ declare class DirectoryExistsError extends HazoConflictError {
3367
3410
  constructor(path: string);
3368
3411
  }
3369
- declare class DirectoryNotEmptyError extends HazoFilesError {
3412
+ declare class DirectoryNotEmptyError extends HazoConflictError {
3370
3413
  constructor(path: string);
3371
3414
  }
3372
- declare class PermissionDeniedError extends HazoFilesError {
3415
+ declare class PermissionDeniedError extends HazoAuthError {
3373
3416
  constructor(path: string, operation: string);
3374
3417
  }
3375
- declare class InvalidPathError extends HazoFilesError {
3418
+ declare class InvalidPathError extends HazoValidationError {
3376
3419
  constructor(path: string, reason: string);
3377
3420
  }
3378
- declare class FileTooLargeError extends HazoFilesError {
3421
+ declare class FileTooLargeError extends HazoValidationError {
3379
3422
  constructor(path: string, size: number, maxSize: number);
3380
3423
  }
3381
- declare class InvalidExtensionError extends HazoFilesError {
3424
+ declare class InvalidExtensionError extends HazoValidationError {
3382
3425
  constructor(path: string, extension: string, allowedExtensions: string[]);
3383
3426
  }
3384
- declare class AuthenticationError extends HazoFilesError {
3427
+ declare class AuthenticationError extends HazoAuthError {
3385
3428
  constructor(provider: string, message: string);
3386
3429
  }
3387
- declare class ConfigurationError extends HazoFilesError {
3430
+ declare class ConfigurationError extends HazoConfigError {
3388
3431
  constructor(message: string);
3389
3432
  }
3390
- declare class OperationError extends HazoFilesError {
3433
+ declare class OperationError extends HazoExternalError {
3391
3434
  constructor(operation: string, message: string, details?: Record<string, unknown>);
3392
3435
  }
3393
- declare class QuotaExceededError extends HazoFilesError {
3436
+ declare class QuotaExceededError extends HazoValidationError {
3394
3437
  constructor(scopeId: string, byteUsed: number, byteLimit: number, deltaBytes: number);
3395
3438
  }
3396
- declare class SSRFError extends HazoFilesError {
3439
+ declare class SSRFError extends HazoValidationError {
3397
3440
  constructor(url: string, reason: string);
3398
3441
  }
3399
- declare class ImportSizeCapError extends HazoFilesError {
3442
+ declare class ImportSizeCapError extends HazoValidationError {
3400
3443
  constructor(url: string, capBytes: number);
3401
3444
  }
3402
3445
 
@@ -3771,4 +3814,43 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
3771
3814
  */
3772
3815
  declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
3773
3816
 
3774
- export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AppFileServerOpts, AppFileServerProvider, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type ContentTagConfig, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type DrivePathCache, 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 FileStorageProvider, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type GoogleDriveOpts, GoogleDriveProvider, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_JOB_TYPES, HAZO_FILES_MIGRATION_V2, HAZO_FILES_MIGRATION_V3, HAZO_FILES_MIGRATION_V4, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, HAZO_FILE_QUOTAS_DEFAULT_TABLE_NAME, HAZO_FILE_QUOTAS_TABLE_SCHEMA, type HazoFileQuotasColumnDefinitions, type HazoFilesColumnDefinitions, type HazoFilesConfig, HazoFilesError, type HazoFilesJobType, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesMigrationV4, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesServerInstance, type HazoFilesServerOptions, type HazoFilesTableSchema, type HazoLLMInstance, type HazoLogger, ImportSizeCapError, InMemoryProvider, 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 ProbeResult, type ProgressCallback, type PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, type PutOpts, type PutResult, type QuotaCrudServiceLike, QuotaExceededError, QuotaService, type QuotaServiceOptions, type QuotaStatus, type QuotaThresholdEvent, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SSRFError, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type SignedUrlOpts, StorageCollisionExhausted, type StorageModule, StorageNotConfigured, type StoragePath, type StorageProvider, StorageUnavailable, 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, createBasicFileManager, createDropboxAuth, createDropboxModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createHazoFilesServer, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createPurgeJobHandlers, createQuotaService, 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, getMigrationV4ForTable, 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 };
3817
+ interface ExternalFileLinkOptions {
3818
+ serve_base?: string;
3819
+ serve_path?: string;
3820
+ metadata?: FileMetadataRecord;
3821
+ }
3822
+ interface ExternalFileLink {
3823
+ url: string;
3824
+ link_type: 'provider_managed' | 'app_gated';
3825
+ storage_type: StorageProvider | string;
3826
+ }
3827
+ interface ExternalFileLinkDeps {
3828
+ metadataService: Pick<FileMetadataService, 'findById'>;
3829
+ }
3830
+ declare function external_file_link(file_id: string, deps: ExternalFileLinkDeps, opts?: ExternalFileLinkOptions): Promise<ExternalFileLink>;
3831
+ type ExternalFileLinkResult = ExternalFileLink | {
3832
+ error: string;
3833
+ };
3834
+ declare function external_file_links(file_ids: string[], deps: ExternalFileLinkDeps, opts?: ExternalFileLinkOptions): Promise<Record<string, ExternalFileLinkResult>>;
3835
+
3836
+ interface FileServeAuthContext {
3837
+ request: Request;
3838
+ file_id: string;
3839
+ }
3840
+ interface FileServeUser {
3841
+ user_id?: string;
3842
+ [k: string]: unknown;
3843
+ }
3844
+ interface FileServeHandlerOptions {
3845
+ provider: Pick<FileStorageProvider, 'get'>;
3846
+ metadataService: Pick<FileMetadataService, 'findById'>;
3847
+ authenticate?: (ctx: FileServeAuthContext) => Promise<FileServeUser | null>;
3848
+ authorize?: (ctx: FileServeAuthContext & {
3849
+ user: FileServeUser;
3850
+ metadata: FileMetadataRecord;
3851
+ }) => Promise<boolean>;
3852
+ get_file_id?: (request: Request) => string | null;
3853
+ }
3854
+ declare function createFileServeHandler(opts: FileServeHandlerOptions): (request: Request) => Promise<Response>;
3855
+
3856
+ export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AppFileServerOpts, AppFileServerProvider, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type ContentTagConfig, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type DrivePathCache, DropboxAuth, type DropboxAuthCallbacks, type DropboxAuthConfig, type DropboxConfig, DropboxModule, type DropboxTokenData, type ExternalFileLink, type ExternalFileLinkDeps, type ExternalFileLinkOptions, type ExternalFileLinkResult, type ExtractionData, type ExtractionOptions, type ExtractionResult, type FileBrowserState, type FileDataStructure, type FileEntry, 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 FileServeAuthContext, type FileServeHandlerOptions, type FileServeUser, type FileStatus, type FileStorageProvider, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type GoogleDriveOpts, GoogleDriveProvider, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_JOB_TYPES, HAZO_FILES_MIGRATION_V2, HAZO_FILES_MIGRATION_V3, HAZO_FILES_MIGRATION_V4, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, HAZO_FILE_QUOTAS_DEFAULT_TABLE_NAME, HAZO_FILE_QUOTAS_TABLE_SCHEMA, type HazoFileQuotasColumnDefinitions, type HazoFilesColumnDefinitions, type HazoFilesConfig, type HazoFilesJobType, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesMigrationV4, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesServerInstance, type HazoFilesServerOptions, type HazoFilesTableSchema, type HazoLLMInstance, type HazoLogger, ImportSizeCapError, InMemoryProvider, 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 ProbeResult, type ProgressCallback, type PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, type PutOpts, type PutResult, type QuotaCrudServiceLike, QuotaExceededError, QuotaService, type QuotaServiceOptions, type QuotaStatus, type QuotaThresholdEvent, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SSRFError, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type SignedUrlOpts, StorageCollisionExhausted, type StorageModule, StorageNotConfigured, type StoragePath, type StorageProvider, StorageUnavailable, 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, createBasicFileManager, createDropboxAuth, createDropboxModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFileServeHandler, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createHazoFilesServer, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createPurgeJobHandlers, createQuotaService, createTrackedFileManager, createUploadExtractService, createVariableSegment, deepMerge, errorResult, external_file_link, external_file_links, filterItems, formatBytes, formatCounter, formatDateToken, generateExtractionId, generateId, generatePreviewName, generateRefId, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getExtractionById, getExtractionCount, getExtractions, getFileCategory, getFileMetadataValues, getMergedData, getMigrationForTable, getMigrationV3ForTable, getMigrationV4ForTable, 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 };
@@ -1,5 +1,7 @@
1
1
  import { JobHandler } from 'hazo_jobs';
2
2
  import { Readable } from 'node:stream';
3
+ import { HazoAuthError, HazoConfigError, HazoConflictError, HazoNotFoundError, HazoValidationError, HazoExternalError } from 'hazo_core';
4
+ export { HazoError as HazoFilesError } from 'hazo_core';
3
5
  import { OAuth2Client } from 'google-auth-library';
4
6
 
5
7
  /**
@@ -2612,6 +2614,22 @@ interface ProbeResult {
2612
2614
  /** Free-form detail for logging. */
2613
2615
  message?: string;
2614
2616
  }
2617
+ /**
2618
+ * A single entry returned by `FileStorageProvider.list()`.
2619
+ *
2620
+ * `path` is the same logical namespace used by `put`/`get` — callers can pass
2621
+ * it directly back to those methods without any transformation.
2622
+ */
2623
+ interface FileEntry {
2624
+ /** Logical path within the provider (same namespace as put/get). */
2625
+ path: StoragePath;
2626
+ /** Bare filename or directory name (the last segment of `path`). */
2627
+ name: string;
2628
+ /** Size in bytes. 0 for directories. */
2629
+ size: number;
2630
+ /** True when this entry represents a directory. */
2631
+ isDirectory: boolean;
2632
+ }
2615
2633
  /**
2616
2634
  * Storage provider abstraction. Every method MUST be idempotent at the
2617
2635
  * data-content level — re-invoking put with identical body is allowed.
@@ -2626,6 +2644,24 @@ interface FileStorageProvider {
2626
2644
  getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
2627
2645
  /** Used by validation cron + onboarding step 2. */
2628
2646
  probe(): Promise<ProbeResult>;
2647
+ /**
2648
+ * List all entries (files and sub-directories) under a logical path prefix.
2649
+ * Results are recursive — all descendants are included.
2650
+ * Returns an empty array when the prefix does not exist.
2651
+ */
2652
+ list(prefix: StoragePath): Promise<FileEntry[]>;
2653
+ /**
2654
+ * Move bytes from `from` to `to`, creating any intermediate directories.
2655
+ * The source is removed on success.
2656
+ * Throws with a message containing "Not found" when `from` does not exist.
2657
+ */
2658
+ move(from: StoragePath, to: StoragePath): Promise<void>;
2659
+ /**
2660
+ * Rename a file or directory. `to` is the full new logical path.
2661
+ * Implementations may delegate to `move`.
2662
+ * Throws with a message containing "Not found" when `from` does not exist.
2663
+ */
2664
+ rename(from: StoragePath, to: StoragePath): Promise<void>;
2629
2665
  }
2630
2666
  declare class StorageCollisionExhausted extends Error {
2631
2667
  attempts: number;
@@ -2663,6 +2699,10 @@ declare class AppFileServerProvider implements FileStorageProvider {
2663
2699
  /** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
2664
2700
  verifySignedUrl(token: string, path: string): boolean;
2665
2701
  probe(): Promise<ProbeResult>;
2702
+ list(prefix: string): Promise<FileEntry[]>;
2703
+ private walkDir;
2704
+ move(from: string, to: string): Promise<void>;
2705
+ rename(from: string, to: string): Promise<void>;
2666
2706
  }
2667
2707
 
2668
2708
  declare class InMemoryProvider implements FileStorageProvider {
@@ -2674,6 +2714,9 @@ declare class InMemoryProvider implements FileStorageProvider {
2674
2714
  exists(path: string): Promise<boolean>;
2675
2715
  getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
2676
2716
  probe(): Promise<ProbeResult>;
2717
+ list(prefix: string): Promise<FileEntry[]>;
2718
+ move(from: string, to: string): Promise<void>;
2719
+ rename(from: string, to: string): Promise<void>;
2677
2720
  /** Test-only escape hatch — exposes the internal store for assertions. */
2678
2721
  snapshot(): Map<string, Buffer>;
2679
2722
  }
@@ -2703,6 +2746,9 @@ declare class GoogleDriveProvider implements FileStorageProvider {
2703
2746
  delete(path: string): Promise<void>;
2704
2747
  exists(path: string): Promise<boolean>;
2705
2748
  getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
2749
+ list(prefix: string): Promise<FileEntry[]>;
2750
+ move(from: string, to: string): Promise<void>;
2751
+ rename(from: string, to: string): Promise<void>;
2706
2752
  private resolvePath;
2707
2753
  private findChild;
2708
2754
  private lookupFileId;
@@ -3348,55 +3394,52 @@ declare function saveConfig(config: HazoFilesConfig, configPath?: string): Promi
3348
3394
 
3349
3395
  /**
3350
3396
  * Custom error classes for hazo_files
3397
+ * All errors extend the appropriate hazo_core subclass.
3351
3398
  */
3352
- declare class HazoFilesError extends Error {
3353
- code: string;
3354
- details?: Record<string, unknown> | undefined;
3355
- constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
3356
- }
3357
- declare class FileNotFoundError extends HazoFilesError {
3399
+
3400
+ declare class FileNotFoundError extends HazoNotFoundError {
3358
3401
  constructor(path: string);
3359
3402
  }
3360
- declare class DirectoryNotFoundError extends HazoFilesError {
3403
+ declare class DirectoryNotFoundError extends HazoNotFoundError {
3361
3404
  constructor(path: string);
3362
3405
  }
3363
- declare class FileExistsError extends HazoFilesError {
3406
+ declare class FileExistsError extends HazoConflictError {
3364
3407
  constructor(path: string);
3365
3408
  }
3366
- declare class DirectoryExistsError extends HazoFilesError {
3409
+ declare class DirectoryExistsError extends HazoConflictError {
3367
3410
  constructor(path: string);
3368
3411
  }
3369
- declare class DirectoryNotEmptyError extends HazoFilesError {
3412
+ declare class DirectoryNotEmptyError extends HazoConflictError {
3370
3413
  constructor(path: string);
3371
3414
  }
3372
- declare class PermissionDeniedError extends HazoFilesError {
3415
+ declare class PermissionDeniedError extends HazoAuthError {
3373
3416
  constructor(path: string, operation: string);
3374
3417
  }
3375
- declare class InvalidPathError extends HazoFilesError {
3418
+ declare class InvalidPathError extends HazoValidationError {
3376
3419
  constructor(path: string, reason: string);
3377
3420
  }
3378
- declare class FileTooLargeError extends HazoFilesError {
3421
+ declare class FileTooLargeError extends HazoValidationError {
3379
3422
  constructor(path: string, size: number, maxSize: number);
3380
3423
  }
3381
- declare class InvalidExtensionError extends HazoFilesError {
3424
+ declare class InvalidExtensionError extends HazoValidationError {
3382
3425
  constructor(path: string, extension: string, allowedExtensions: string[]);
3383
3426
  }
3384
- declare class AuthenticationError extends HazoFilesError {
3427
+ declare class AuthenticationError extends HazoAuthError {
3385
3428
  constructor(provider: string, message: string);
3386
3429
  }
3387
- declare class ConfigurationError extends HazoFilesError {
3430
+ declare class ConfigurationError extends HazoConfigError {
3388
3431
  constructor(message: string);
3389
3432
  }
3390
- declare class OperationError extends HazoFilesError {
3433
+ declare class OperationError extends HazoExternalError {
3391
3434
  constructor(operation: string, message: string, details?: Record<string, unknown>);
3392
3435
  }
3393
- declare class QuotaExceededError extends HazoFilesError {
3436
+ declare class QuotaExceededError extends HazoValidationError {
3394
3437
  constructor(scopeId: string, byteUsed: number, byteLimit: number, deltaBytes: number);
3395
3438
  }
3396
- declare class SSRFError extends HazoFilesError {
3439
+ declare class SSRFError extends HazoValidationError {
3397
3440
  constructor(url: string, reason: string);
3398
3441
  }
3399
- declare class ImportSizeCapError extends HazoFilesError {
3442
+ declare class ImportSizeCapError extends HazoValidationError {
3400
3443
  constructor(url: string, capBytes: number);
3401
3444
  }
3402
3445
 
@@ -3771,4 +3814,43 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
3771
3814
  */
3772
3815
  declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
3773
3816
 
3774
- export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AppFileServerOpts, AppFileServerProvider, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type ContentTagConfig, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type DrivePathCache, 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 FileStorageProvider, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type GoogleDriveOpts, GoogleDriveProvider, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_JOB_TYPES, HAZO_FILES_MIGRATION_V2, HAZO_FILES_MIGRATION_V3, HAZO_FILES_MIGRATION_V4, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, HAZO_FILE_QUOTAS_DEFAULT_TABLE_NAME, HAZO_FILE_QUOTAS_TABLE_SCHEMA, type HazoFileQuotasColumnDefinitions, type HazoFilesColumnDefinitions, type HazoFilesConfig, HazoFilesError, type HazoFilesJobType, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesMigrationV4, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesServerInstance, type HazoFilesServerOptions, type HazoFilesTableSchema, type HazoLLMInstance, type HazoLogger, ImportSizeCapError, InMemoryProvider, 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 ProbeResult, type ProgressCallback, type PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, type PutOpts, type PutResult, type QuotaCrudServiceLike, QuotaExceededError, QuotaService, type QuotaServiceOptions, type QuotaStatus, type QuotaThresholdEvent, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SSRFError, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type SignedUrlOpts, StorageCollisionExhausted, type StorageModule, StorageNotConfigured, type StoragePath, type StorageProvider, StorageUnavailable, 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, createBasicFileManager, createDropboxAuth, createDropboxModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createHazoFilesServer, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createPurgeJobHandlers, createQuotaService, 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, getMigrationV4ForTable, 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 };
3817
+ interface ExternalFileLinkOptions {
3818
+ serve_base?: string;
3819
+ serve_path?: string;
3820
+ metadata?: FileMetadataRecord;
3821
+ }
3822
+ interface ExternalFileLink {
3823
+ url: string;
3824
+ link_type: 'provider_managed' | 'app_gated';
3825
+ storage_type: StorageProvider | string;
3826
+ }
3827
+ interface ExternalFileLinkDeps {
3828
+ metadataService: Pick<FileMetadataService, 'findById'>;
3829
+ }
3830
+ declare function external_file_link(file_id: string, deps: ExternalFileLinkDeps, opts?: ExternalFileLinkOptions): Promise<ExternalFileLink>;
3831
+ type ExternalFileLinkResult = ExternalFileLink | {
3832
+ error: string;
3833
+ };
3834
+ declare function external_file_links(file_ids: string[], deps: ExternalFileLinkDeps, opts?: ExternalFileLinkOptions): Promise<Record<string, ExternalFileLinkResult>>;
3835
+
3836
+ interface FileServeAuthContext {
3837
+ request: Request;
3838
+ file_id: string;
3839
+ }
3840
+ interface FileServeUser {
3841
+ user_id?: string;
3842
+ [k: string]: unknown;
3843
+ }
3844
+ interface FileServeHandlerOptions {
3845
+ provider: Pick<FileStorageProvider, 'get'>;
3846
+ metadataService: Pick<FileMetadataService, 'findById'>;
3847
+ authenticate?: (ctx: FileServeAuthContext) => Promise<FileServeUser | null>;
3848
+ authorize?: (ctx: FileServeAuthContext & {
3849
+ user: FileServeUser;
3850
+ metadata: FileMetadataRecord;
3851
+ }) => Promise<boolean>;
3852
+ get_file_id?: (request: Request) => string | null;
3853
+ }
3854
+ declare function createFileServeHandler(opts: FileServeHandlerOptions): (request: Request) => Promise<Response>;
3855
+
3856
+ export { ALL_SYSTEM_VARIABLES, type AddExtractionOptions, type AddRefOptions, type AppFileServerOpts, AppFileServerProvider, type AuthCallbacks, AuthenticationError, type CleanupOrphanedOptions, ConfigurationError, type ContentTagConfig, type CreateFolderOptions, type CrudServiceLike, DEFAULT_DATE_FORMATS, type DatabaseSchemaDefinition, type DatabaseTrackingConfig, DirectoryExistsError, DirectoryNotEmptyError, DirectoryNotFoundError, type DownloadOptions, type DrivePathCache, DropboxAuth, type DropboxAuthCallbacks, type DropboxAuthConfig, type DropboxConfig, DropboxModule, type DropboxTokenData, type ExternalFileLink, type ExternalFileLinkDeps, type ExternalFileLinkOptions, type ExternalFileLinkResult, type ExtractionData, type ExtractionOptions, type ExtractionResult, type FileBrowserState, type FileDataStructure, type FileEntry, 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 FileServeAuthContext, type FileServeHandlerOptions, type FileServeUser, type FileStatus, type FileStorageProvider, type FileSystemItem, FileTooLargeError, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type GoogleDriveOpts, GoogleDriveProvider, HAZO_FILES_DEFAULT_TABLE_NAME, HAZO_FILES_JOB_TYPES, HAZO_FILES_MIGRATION_V2, HAZO_FILES_MIGRATION_V3, HAZO_FILES_MIGRATION_V4, HAZO_FILES_NAMING_DEFAULT_TABLE_NAME, HAZO_FILES_NAMING_TABLE_SCHEMA, HAZO_FILES_TABLE_SCHEMA, HAZO_FILE_QUOTAS_DEFAULT_TABLE_NAME, HAZO_FILE_QUOTAS_TABLE_SCHEMA, type HazoFileQuotasColumnDefinitions, type HazoFilesColumnDefinitions, type HazoFilesConfig, type HazoFilesJobType, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesMigrationV4, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesServerInstance, type HazoFilesServerOptions, type HazoFilesTableSchema, type HazoLLMInstance, type HazoLogger, ImportSizeCapError, InMemoryProvider, 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 ProbeResult, type ProgressCallback, type PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, type PutOpts, type PutResult, type QuotaCrudServiceLike, QuotaExceededError, QuotaService, type QuotaServiceOptions, type QuotaStatus, type QuotaThresholdEvent, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, SSRFError, SYSTEM_COUNTER_VARIABLES, SYSTEM_DATE_VARIABLES, SYSTEM_FILE_VARIABLES, type SignedUrlOpts, StorageCollisionExhausted, type StorageModule, StorageNotConfigured, type StoragePath, type StorageProvider, StorageUnavailable, 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, createBasicFileManager, createDropboxAuth, createDropboxModule, createEmptyFileDataStructure, createEmptyNamingRuleSchema, createFileItem, createFileManager, createFileMetadataService, createFileRef, createFileServeHandler, createFolderItem, createGoogleDriveAuth, createGoogleDriveModule, createHazoFilesServer, createInitializedFileManager, createInitializedTrackedFileManager, createLLMExtractionService, createLiteralSegment, createLocalModule, createModule, createNamingConventionService, createPurgeJobHandlers, createQuotaService, createTrackedFileManager, createUploadExtractService, createVariableSegment, deepMerge, errorResult, external_file_link, external_file_links, filterItems, formatBytes, formatCounter, formatDateToken, generateExtractionId, generateId, generatePreviewName, generateRefId, generateSampleConfig, generateSegmentId, getBaseName, getBreadcrumbs, getDirName, getExtension, getExtensionFromMime, getExtractionById, getExtractionCount, getExtractions, getFileCategory, getFileMetadataValues, getMergedData, getMigrationForTable, getMigrationV3ForTable, getMigrationV4ForTable, 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 };