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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { HazoAuthError, HazoConfigError, HazoConflictError, HazoNotFoundError, HazoValidationError, HazoExternalError } from 'hazo_core';
2
+ export { HazoError as HazoFilesError } from 'hazo_core';
1
3
  import { Readable } from 'node:stream';
2
4
  import { OAuth2Client } from 'google-auth-library';
3
5
 
@@ -2871,46 +2873,43 @@ declare function registerModule(provider: StorageProvider, factory: ModuleFactor
2871
2873
 
2872
2874
  /**
2873
2875
  * Custom error classes for hazo_files
2876
+ * All errors extend the appropriate hazo_core subclass.
2874
2877
  */
2875
- declare class HazoFilesError extends Error {
2876
- code: string;
2877
- details?: Record<string, unknown> | undefined;
2878
- constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
2879
- }
2880
- declare class FileNotFoundError extends HazoFilesError {
2878
+
2879
+ declare class FileNotFoundError extends HazoNotFoundError {
2881
2880
  constructor(path: string);
2882
2881
  }
2883
- declare class DirectoryNotFoundError extends HazoFilesError {
2882
+ declare class DirectoryNotFoundError extends HazoNotFoundError {
2884
2883
  constructor(path: string);
2885
2884
  }
2886
- declare class FileExistsError extends HazoFilesError {
2885
+ declare class FileExistsError extends HazoConflictError {
2887
2886
  constructor(path: string);
2888
2887
  }
2889
- declare class DirectoryExistsError extends HazoFilesError {
2888
+ declare class DirectoryExistsError extends HazoConflictError {
2890
2889
  constructor(path: string);
2891
2890
  }
2892
- declare class DirectoryNotEmptyError extends HazoFilesError {
2891
+ declare class DirectoryNotEmptyError extends HazoConflictError {
2893
2892
  constructor(path: string);
2894
2893
  }
2895
- declare class PermissionDeniedError extends HazoFilesError {
2894
+ declare class PermissionDeniedError extends HazoAuthError {
2896
2895
  constructor(path: string, operation: string);
2897
2896
  }
2898
- declare class InvalidPathError extends HazoFilesError {
2897
+ declare class InvalidPathError extends HazoValidationError {
2899
2898
  constructor(path: string, reason: string);
2900
2899
  }
2901
- declare class FileTooLargeError extends HazoFilesError {
2900
+ declare class FileTooLargeError extends HazoValidationError {
2902
2901
  constructor(path: string, size: number, maxSize: number);
2903
2902
  }
2904
- declare class InvalidExtensionError extends HazoFilesError {
2903
+ declare class InvalidExtensionError extends HazoValidationError {
2905
2904
  constructor(path: string, extension: string, allowedExtensions: string[]);
2906
2905
  }
2907
- declare class AuthenticationError extends HazoFilesError {
2906
+ declare class AuthenticationError extends HazoAuthError {
2908
2907
  constructor(provider: string, message: string);
2909
2908
  }
2910
- declare class ConfigurationError extends HazoFilesError {
2909
+ declare class ConfigurationError extends HazoConfigError {
2911
2910
  constructor(message: string);
2912
2911
  }
2913
- declare class OperationError extends HazoFilesError {
2912
+ declare class OperationError extends HazoExternalError {
2914
2913
  constructor(operation: string, message: string, details?: Record<string, unknown>);
2915
2914
  }
2916
2915
 
@@ -3319,6 +3318,22 @@ interface ProbeResult {
3319
3318
  /** Free-form detail for logging. */
3320
3319
  message?: string;
3321
3320
  }
3321
+ /**
3322
+ * A single entry returned by `FileStorageProvider.list()`.
3323
+ *
3324
+ * `path` is the same logical namespace used by `put`/`get` — callers can pass
3325
+ * it directly back to those methods without any transformation.
3326
+ */
3327
+ interface FileEntry {
3328
+ /** Logical path within the provider (same namespace as put/get). */
3329
+ path: StoragePath;
3330
+ /** Bare filename or directory name (the last segment of `path`). */
3331
+ name: string;
3332
+ /** Size in bytes. 0 for directories. */
3333
+ size: number;
3334
+ /** True when this entry represents a directory. */
3335
+ isDirectory: boolean;
3336
+ }
3322
3337
  /**
3323
3338
  * Storage provider abstraction. Every method MUST be idempotent at the
3324
3339
  * data-content level — re-invoking put with identical body is allowed.
@@ -3333,6 +3348,36 @@ interface FileStorageProvider {
3333
3348
  getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
3334
3349
  /** Used by validation cron + onboarding step 2. */
3335
3350
  probe(): Promise<ProbeResult>;
3351
+ /**
3352
+ * List all entries (files and sub-directories) under a logical path prefix.
3353
+ * Results are recursive — all descendants are included.
3354
+ * Returns an empty array when the prefix does not exist.
3355
+ */
3356
+ list(prefix: StoragePath): Promise<FileEntry[]>;
3357
+ /**
3358
+ * Move bytes from `from` to `to`, creating any intermediate directories.
3359
+ * The source is removed on success.
3360
+ * Throws with a message containing "Not found" when `from` does not exist.
3361
+ */
3362
+ move(from: StoragePath, to: StoragePath): Promise<void>;
3363
+ /**
3364
+ * Rename a file or directory. `to` is the full new logical path.
3365
+ * Implementations may delegate to `move`.
3366
+ * Throws with a message containing "Not found" when `from` does not exist.
3367
+ */
3368
+ rename(from: StoragePath, to: StoragePath): Promise<void>;
3369
+ }
3370
+ declare class StorageCollisionExhausted extends Error {
3371
+ attempts: number;
3372
+ lastPath: StoragePath;
3373
+ constructor(attempts: number, lastPath: StoragePath);
3374
+ }
3375
+ declare class StorageNotConfigured extends Error {
3376
+ constructor();
3377
+ }
3378
+ declare class StorageUnavailable extends Error {
3379
+ reason: ProbeResult["error"];
3380
+ constructor(reason: ProbeResult["error"], message: string);
3336
3381
  }
3337
3382
 
3338
3383
  interface WriteWithCollisionOpts {
@@ -3371,4 +3416,82 @@ declare function addRef<T extends FileWithRefs>(file: T, ref: FileRef): T;
3371
3416
  declare function removeRef<T extends FileWithRefs>(file: T, ref_id: string, removed_at: string): T;
3372
3417
  declare function countRefs(file: Pick<FileWithRefs, "file_refs">): number;
3373
3418
 
3374
- 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$1 as FileRef, type FileRefVisibility, type FileStatus, type FileSystemItem, FileTooLargeError, type FileWithRefs, 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, NamingTemplate, 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, type WriteWithCollisionOpts, addExtractionToFileData, addRef, backfillV2Defaults, buildFileWithStatus, clearExtractions, clonePattern, computeFileHash, computeFileHashFromStream, computeFileHashSync, computeFileInfo, countRefs, 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, removeRef, removeRefFromArray, removeRefsByCriteriaFromArray, sanitizeFilename, saveConfig, sortItems, stringifyFileData, stringifyFileRefs, successResult, toV2Record, updateExtractionById, validateExtractionData, validateFileDataStructure, validateNamingRuleSchema, validatePath, writeWithCollisionRetry };
3419
+ interface AppFileServerOpts {
3420
+ /** Filesystem root. All paths are resolved relative to this. */
3421
+ root: string;
3422
+ /** HMAC secret used to sign download URLs. */
3423
+ hmac_secret: string;
3424
+ /** Default signed-URL TTL in seconds. */
3425
+ default_ttl_seconds?: number;
3426
+ }
3427
+ declare class AppFileServerProvider implements FileStorageProvider {
3428
+ readonly provider_tag: "app_file_server";
3429
+ private readonly root;
3430
+ private readonly secret;
3431
+ private readonly default_ttl;
3432
+ constructor(opts: AppFileServerOpts);
3433
+ private resolve;
3434
+ put(path: string, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
3435
+ get(path: string): Promise<Buffer>;
3436
+ delete(path: string): Promise<void>;
3437
+ exists(path: string): Promise<boolean>;
3438
+ getSignedUrl(path: string, opts?: SignedUrlOpts): Promise<string>;
3439
+ /** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
3440
+ verifySignedUrl(token: string, path: string): boolean;
3441
+ probe(): Promise<ProbeResult>;
3442
+ list(prefix: string): Promise<FileEntry[]>;
3443
+ private walkDir;
3444
+ move(from: string, to: string): Promise<void>;
3445
+ rename(from: string, to: string): Promise<void>;
3446
+ }
3447
+
3448
+ declare class InMemoryProvider implements FileStorageProvider {
3449
+ readonly provider_tag: "in_memory";
3450
+ private readonly store;
3451
+ put(path: string, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
3452
+ get(path: string): Promise<Buffer>;
3453
+ delete(path: string): Promise<void>;
3454
+ exists(path: string): Promise<boolean>;
3455
+ getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
3456
+ probe(): Promise<ProbeResult>;
3457
+ list(prefix: string): Promise<FileEntry[]>;
3458
+ move(from: string, to: string): Promise<void>;
3459
+ rename(from: string, to: string): Promise<void>;
3460
+ /** Test-only escape hatch — exposes the internal store for assertions. */
3461
+ snapshot(): Map<string, Buffer>;
3462
+ }
3463
+
3464
+ interface DrivePathCache {
3465
+ lookup(key: string): Promise<string | null>;
3466
+ write(key: string, folder_id: string): Promise<void>;
3467
+ invalidate(key: string): Promise<void>;
3468
+ }
3469
+ interface GoogleDriveOpts {
3470
+ /** Raw JSON keyfile contents (decoded from GOOGLE_SERVICE_ACCOUNT_JSON env var). */
3471
+ service_account_json: string;
3472
+ /** Target Shared Drive ID. */
3473
+ shared_drive_id: string;
3474
+ /** Lazy folder-ID cache, scoped per Hazodocs org. */
3475
+ path_cache: DrivePathCache;
3476
+ }
3477
+ declare class GoogleDriveProvider implements FileStorageProvider {
3478
+ readonly provider_tag: "gdrive";
3479
+ private readonly drive;
3480
+ private readonly driveId;
3481
+ private readonly cache;
3482
+ constructor(opts: GoogleDriveOpts);
3483
+ probe(): Promise<ProbeResult>;
3484
+ put(path: string, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
3485
+ get(path: string): Promise<Buffer>;
3486
+ delete(path: string): Promise<void>;
3487
+ exists(path: string): Promise<boolean>;
3488
+ getSignedUrl(path: string, _opts?: SignedUrlOpts): Promise<string>;
3489
+ list(prefix: string): Promise<FileEntry[]>;
3490
+ move(from: string, to: string): Promise<void>;
3491
+ rename(from: string, to: string): Promise<void>;
3492
+ private resolvePath;
3493
+ private findChild;
3494
+ private lookupFileId;
3495
+ }
3496
+
3497
+ 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, type FileEntry, FileExistsError, type FileInfo, type FileItem, FileManager, type FileManagerOptions, type FileMetadataInput, type FileMetadataRecord, type FileMetadataRecordV2, FileMetadataService, type FileMetadataServiceOptions, type FileMetadataUpdate, FileNotFoundError, type FileRef$1 as FileRef, type FileRefVisibility, type FileStatus, type FileStorageProvider, type FileSystemItem, FileTooLargeError, type FileWithRefs, type FileWithStatus, type FindOrphanedOptions, type FolderItem, type GeneratedNameResult, type GoogleAuthConfig, GoogleDriveAuth, type GoogleDriveConfig, GoogleDriveModule, type GoogleDriveOpts, GoogleDriveProvider, 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, type HazoFilesMigrationV2, type HazoFilesMigrationV3, type HazoFilesNamingColumnDefinitions, type HazoFilesNamingTableSchema, type HazoFilesTableSchema, type HazoLLMInstance, 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, NamingTemplate, type NamingVariable, OperationError, type OperationResult, type ParsedNamingConvention, type PatternSegment, PermissionDeniedError, type ProbeResult, type ProgressCallback, type PutOpts, type PutResult, type RemoveExtractionOptions, type RemoveRefsCriteria, type RenameOptions, 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, type WriteWithCollisionOpts, addExtractionToFileData, addRef, backfillV2Defaults, buildFileWithStatus, clearExtractions, clonePattern, computeFileHash, computeFileHashFromStream, computeFileHashSync, computeFileInfo, countRefs, 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, removeRef, removeRefFromArray, removeRefsByCriteriaFromArray, sanitizeFilename, saveConfig, sortItems, stringifyFileData, stringifyFileRefs, successResult, toV2Record, updateExtractionById, validateExtractionData, validateFileDataStructure, validateNamingRuleSchema, validatePath, writeWithCollisionRetry };