hazo_files 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { HazoAuthError, HazoConfigError, HazoConflictError, HazoNotFoundError, HazoValidationError, HazoExternalError } from 'hazo_core';
2
+ export { HazoError as HazoFilesError } from 'hazo_core';
3
+ import { Readable } from 'node:stream';
1
4
  import { OAuth2Client } from 'google-auth-library';
2
5
 
3
6
  /**
@@ -396,7 +399,7 @@ type FileRefVisibility = 'public' | 'private' | 'internal';
396
399
  * A reference from an entity to a file.
397
400
  * Multiple entities can reference the same file.
398
401
  */
399
- interface FileRef {
402
+ interface FileRef$1 {
400
403
  /** Unique ID for this reference */
401
404
  ref_id: string;
402
405
  /** Type of entity referencing the file (e.g., 'form_field', 'chat_message') */
@@ -480,7 +483,7 @@ interface FileWithStatus {
480
483
  /** Full metadata record (V2) */
481
484
  record: FileMetadataRecordV2;
482
485
  /** Parsed file references */
483
- refs: FileRef[];
486
+ refs: FileRef$1[];
484
487
  /** Whether the file has zero references */
485
488
  is_orphaned: boolean;
486
489
  }
@@ -878,7 +881,7 @@ declare class FileMetadataService {
878
881
  /**
879
882
  * Get all references for a file
880
883
  */
881
- getRefs(fileId: string): Promise<FileRef[] | null>;
884
+ getRefs(fileId: string): Promise<FileRef$1[] | null>;
882
885
  /**
883
886
  * Get a file with its status and parsed refs
884
887
  */
@@ -2870,46 +2873,43 @@ declare function registerModule(provider: StorageProvider, factory: ModuleFactor
2870
2873
 
2871
2874
  /**
2872
2875
  * Custom error classes for hazo_files
2876
+ * All errors extend the appropriate hazo_core subclass.
2873
2877
  */
2874
- declare class HazoFilesError extends Error {
2875
- code: string;
2876
- details?: Record<string, unknown> | undefined;
2877
- constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
2878
- }
2879
- declare class FileNotFoundError extends HazoFilesError {
2878
+
2879
+ declare class FileNotFoundError extends HazoNotFoundError {
2880
2880
  constructor(path: string);
2881
2881
  }
2882
- declare class DirectoryNotFoundError extends HazoFilesError {
2882
+ declare class DirectoryNotFoundError extends HazoNotFoundError {
2883
2883
  constructor(path: string);
2884
2884
  }
2885
- declare class FileExistsError extends HazoFilesError {
2885
+ declare class FileExistsError extends HazoConflictError {
2886
2886
  constructor(path: string);
2887
2887
  }
2888
- declare class DirectoryExistsError extends HazoFilesError {
2888
+ declare class DirectoryExistsError extends HazoConflictError {
2889
2889
  constructor(path: string);
2890
2890
  }
2891
- declare class DirectoryNotEmptyError extends HazoFilesError {
2891
+ declare class DirectoryNotEmptyError extends HazoConflictError {
2892
2892
  constructor(path: string);
2893
2893
  }
2894
- declare class PermissionDeniedError extends HazoFilesError {
2894
+ declare class PermissionDeniedError extends HazoAuthError {
2895
2895
  constructor(path: string, operation: string);
2896
2896
  }
2897
- declare class InvalidPathError extends HazoFilesError {
2897
+ declare class InvalidPathError extends HazoValidationError {
2898
2898
  constructor(path: string, reason: string);
2899
2899
  }
2900
- declare class FileTooLargeError extends HazoFilesError {
2900
+ declare class FileTooLargeError extends HazoValidationError {
2901
2901
  constructor(path: string, size: number, maxSize: number);
2902
2902
  }
2903
- declare class InvalidExtensionError extends HazoFilesError {
2903
+ declare class InvalidExtensionError extends HazoValidationError {
2904
2904
  constructor(path: string, extension: string, allowedExtensions: string[]);
2905
2905
  }
2906
- declare class AuthenticationError extends HazoFilesError {
2906
+ declare class AuthenticationError extends HazoAuthError {
2907
2907
  constructor(provider: string, message: string);
2908
2908
  }
2909
- declare class ConfigurationError extends HazoFilesError {
2909
+ declare class ConfigurationError extends HazoConfigError {
2910
2910
  constructor(message: string);
2911
2911
  }
2912
- declare class OperationError extends HazoFilesError {
2912
+ declare class OperationError extends HazoExternalError {
2913
2913
  constructor(operation: string, message: string, details?: Record<string, unknown>);
2914
2914
  }
2915
2915
 
@@ -3256,24 +3256,24 @@ declare function generateRefId(): string;
3256
3256
  * Parse a JSON string into FileRef array.
3257
3257
  * Returns empty array on invalid input.
3258
3258
  */
3259
- declare function parseFileRefs(json: string | null | undefined): FileRef[];
3259
+ declare function parseFileRefs(json: string | null | undefined): FileRef$1[];
3260
3260
  /**
3261
3261
  * Serialize FileRef array to JSON string
3262
3262
  */
3263
- declare function stringifyFileRefs(refs: FileRef[]): string;
3263
+ declare function stringifyFileRefs(refs: FileRef$1[]): string;
3264
3264
  /**
3265
3265
  * Create a FileRef from AddRefOptions
3266
3266
  */
3267
- declare function createFileRef(options: AddRefOptions): FileRef;
3267
+ declare function createFileRef(options: AddRefOptions): FileRef$1;
3268
3268
  /**
3269
3269
  * Remove a ref by ref_id (immutable)
3270
3270
  */
3271
- declare function removeRefFromArray(refs: FileRef[], refId: string): FileRef[];
3271
+ declare function removeRefFromArray(refs: FileRef$1[], refId: string): FileRef$1[];
3272
3272
  /**
3273
3273
  * Remove refs matching criteria from array (immutable).
3274
3274
  * All specified criteria fields must match (AND semantics).
3275
3275
  */
3276
- declare function removeRefsByCriteriaFromArray(refs: FileRef[], criteria: Omit<RemoveRefsCriteria, 'file_id' | 'scope_id'>): FileRef[];
3276
+ declare function removeRefsByCriteriaFromArray(refs: FileRef$1[], criteria: Omit<RemoveRefsCriteria, 'file_id' | 'scope_id'>): FileRef$1[];
3277
3277
  /**
3278
3278
  * Safely cast a FileMetadataRecord to FileMetadataRecordV2.
3279
3279
  * Missing V2 fields are defaulted.
@@ -3284,4 +3284,90 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
3284
3284
  */
3285
3285
  declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
3286
3286
 
3287
- 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 };
3287
+ declare class NamingTemplate {
3288
+ static render(template: string, vars: Record<string, unknown>): string;
3289
+ }
3290
+
3291
+ type StoragePath = string;
3292
+ interface PutOpts {
3293
+ /** Reject if the target path already exists (atomic). */
3294
+ ifNotExists?: boolean;
3295
+ /** Hint for content-type; provider may sniff if absent. */
3296
+ contentType?: string;
3297
+ /** Free-form key/value metadata persisted with the file when supported. */
3298
+ metadata?: Record<string, string>;
3299
+ }
3300
+ interface PutResult {
3301
+ /** Provider tag — `"app_file_server"`, `"gdrive"`, `"in_memory"`. */
3302
+ provider: string;
3303
+ /** Provider-native identifier (path for app-server; file ID for GDrive). */
3304
+ native_id: string;
3305
+ /** Size in bytes of the persisted body. */
3306
+ size: number;
3307
+ }
3308
+ interface SignedUrlOpts {
3309
+ /** Seconds the URL is valid for. */
3310
+ ttl_seconds?: number;
3311
+ /** Suggested download filename (Content-Disposition). */
3312
+ filename_hint?: string;
3313
+ }
3314
+ interface ProbeResult {
3315
+ ok: boolean;
3316
+ /** Machine-readable error tag when ok=false. */
3317
+ error?: "drive_not_shared" | "write_denied" | "invalid_id" | "transient" | "config_missing";
3318
+ /** Free-form detail for logging. */
3319
+ message?: string;
3320
+ }
3321
+ /**
3322
+ * Storage provider abstraction. Every method MUST be idempotent at the
3323
+ * data-content level — re-invoking put with identical body is allowed.
3324
+ *
3325
+ * Paths are logical; providers translate to native identifiers internally.
3326
+ */
3327
+ interface FileStorageProvider {
3328
+ put(path: StoragePath, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
3329
+ get(path: StoragePath): Promise<Buffer | Readable>;
3330
+ delete(path: StoragePath): Promise<void>;
3331
+ exists(path: StoragePath): Promise<boolean>;
3332
+ getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
3333
+ /** Used by validation cron + onboarding step 2. */
3334
+ probe(): Promise<ProbeResult>;
3335
+ }
3336
+
3337
+ interface WriteWithCollisionOpts {
3338
+ provider: FileStorageProvider;
3339
+ template: string;
3340
+ vars: Record<string, unknown>;
3341
+ body: Buffer;
3342
+ /** Prefix to mount the rendered filename under, e.g. `"folders/abc123"`. */
3343
+ path_prefix?: string;
3344
+ /** Max attempts. Default 999. */
3345
+ max_attempts?: number;
3346
+ /** Extra opts passed to provider.put (ifNotExists is always forced true). */
3347
+ put_opts?: Omit<PutOpts, "ifNotExists">;
3348
+ }
3349
+ declare function writeWithCollisionRetry(opts: WriteWithCollisionOpts): Promise<PutResult & {
3350
+ logical_path: string;
3351
+ }>;
3352
+
3353
+ interface FileRef {
3354
+ ref_id: string;
3355
+ ref_type: string;
3356
+ ref_source: string;
3357
+ form_id?: string;
3358
+ field_id?: string;
3359
+ message_id?: string;
3360
+ document_id?: string;
3361
+ created_at: string;
3362
+ removed_at?: string;
3363
+ }
3364
+ interface FileWithRefs {
3365
+ file_refs: FileRef[];
3366
+ ref_count: number;
3367
+ }
3368
+
3369
+ declare function addRef<T extends FileWithRefs>(file: T, ref: FileRef): T;
3370
+ declare function removeRef<T extends FileWithRefs>(file: T, ref_id: string, removed_at: string): T;
3371
+ declare function countRefs(file: Pick<FileWithRefs, "file_refs">): number;
3372
+
3373
+ 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, 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 };