hazo_files 1.6.0 → 2.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/server/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JobHandler } from 'hazo_jobs';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
2
3
|
import { OAuth2Client } from 'google-auth-library';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -2581,6 +2582,89 @@ declare const HAZO_FILE_QUOTAS_TABLE_SCHEMA: {
|
|
|
2581
2582
|
columns: readonly ["scope_id", "byte_limit", "byte_used", "updated_at"];
|
|
2582
2583
|
};
|
|
2583
2584
|
|
|
2585
|
+
type StoragePath = string;
|
|
2586
|
+
interface PutOpts {
|
|
2587
|
+
/** Reject if the target path already exists (atomic). */
|
|
2588
|
+
ifNotExists?: boolean;
|
|
2589
|
+
/** Hint for content-type; provider may sniff if absent. */
|
|
2590
|
+
contentType?: string;
|
|
2591
|
+
/** Free-form key/value metadata persisted with the file when supported. */
|
|
2592
|
+
metadata?: Record<string, string>;
|
|
2593
|
+
}
|
|
2594
|
+
interface PutResult {
|
|
2595
|
+
/** Provider tag — `"app_file_server"`, `"gdrive"`, `"in_memory"`. */
|
|
2596
|
+
provider: string;
|
|
2597
|
+
/** Provider-native identifier (path for app-server; file ID for GDrive). */
|
|
2598
|
+
native_id: string;
|
|
2599
|
+
/** Size in bytes of the persisted body. */
|
|
2600
|
+
size: number;
|
|
2601
|
+
}
|
|
2602
|
+
interface SignedUrlOpts {
|
|
2603
|
+
/** Seconds the URL is valid for. */
|
|
2604
|
+
ttl_seconds?: number;
|
|
2605
|
+
/** Suggested download filename (Content-Disposition). */
|
|
2606
|
+
filename_hint?: string;
|
|
2607
|
+
}
|
|
2608
|
+
interface ProbeResult {
|
|
2609
|
+
ok: boolean;
|
|
2610
|
+
/** Machine-readable error tag when ok=false. */
|
|
2611
|
+
error?: "drive_not_shared" | "write_denied" | "invalid_id" | "transient" | "config_missing";
|
|
2612
|
+
/** Free-form detail for logging. */
|
|
2613
|
+
message?: string;
|
|
2614
|
+
}
|
|
2615
|
+
/**
|
|
2616
|
+
* Storage provider abstraction. Every method MUST be idempotent at the
|
|
2617
|
+
* data-content level — re-invoking put with identical body is allowed.
|
|
2618
|
+
*
|
|
2619
|
+
* Paths are logical; providers translate to native identifiers internally.
|
|
2620
|
+
*/
|
|
2621
|
+
interface FileStorageProvider {
|
|
2622
|
+
put(path: StoragePath, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
|
|
2623
|
+
get(path: StoragePath): Promise<Buffer | Readable>;
|
|
2624
|
+
delete(path: StoragePath): Promise<void>;
|
|
2625
|
+
exists(path: StoragePath): Promise<boolean>;
|
|
2626
|
+
getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
|
|
2627
|
+
/** Used by validation cron + onboarding step 2. */
|
|
2628
|
+
probe(): Promise<ProbeResult>;
|
|
2629
|
+
}
|
|
2630
|
+
declare class StorageCollisionExhausted extends Error {
|
|
2631
|
+
attempts: number;
|
|
2632
|
+
lastPath: StoragePath;
|
|
2633
|
+
constructor(attempts: number, lastPath: StoragePath);
|
|
2634
|
+
}
|
|
2635
|
+
declare class StorageNotConfigured extends Error {
|
|
2636
|
+
constructor();
|
|
2637
|
+
}
|
|
2638
|
+
declare class StorageUnavailable extends Error {
|
|
2639
|
+
reason: ProbeResult["error"];
|
|
2640
|
+
constructor(reason: ProbeResult["error"], message: string);
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
interface AppFileServerOpts {
|
|
2644
|
+
/** Filesystem root. All paths are resolved relative to this. */
|
|
2645
|
+
root: string;
|
|
2646
|
+
/** HMAC secret used to sign download URLs. */
|
|
2647
|
+
hmac_secret: string;
|
|
2648
|
+
/** Default signed-URL TTL in seconds. */
|
|
2649
|
+
default_ttl_seconds?: number;
|
|
2650
|
+
}
|
|
2651
|
+
declare class AppFileServerProvider implements FileStorageProvider {
|
|
2652
|
+
readonly provider_tag: "app_file_server";
|
|
2653
|
+
private readonly root;
|
|
2654
|
+
private readonly secret;
|
|
2655
|
+
private readonly default_ttl;
|
|
2656
|
+
constructor(opts: AppFileServerOpts);
|
|
2657
|
+
private resolve;
|
|
2658
|
+
put(path: string, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
|
|
2659
|
+
get(path: string): Promise<Buffer>;
|
|
2660
|
+
delete(path: string): Promise<void>;
|
|
2661
|
+
exists(path: string): Promise<boolean>;
|
|
2662
|
+
getSignedUrl(path: string, opts?: SignedUrlOpts): Promise<string>;
|
|
2663
|
+
/** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
|
|
2664
|
+
verifySignedUrl(token: string, path: string): boolean;
|
|
2665
|
+
probe(): Promise<ProbeResult>;
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2584
2668
|
/**
|
|
2585
2669
|
* Migration: Add Reference Tracking (V2)
|
|
2586
2670
|
*
|
|
@@ -3644,4 +3728,4 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
|
|
|
3644
3728
|
*/
|
|
3645
3729
|
declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
|
|
3646
3730
|
|
|
3647
|
-
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_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, 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 PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, 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 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, 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 };
|
|
3731
|
+
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, 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, 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, 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 };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { JobHandler } from 'hazo_jobs';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
2
3
|
import { OAuth2Client } from 'google-auth-library';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -2581,6 +2582,89 @@ declare const HAZO_FILE_QUOTAS_TABLE_SCHEMA: {
|
|
|
2581
2582
|
columns: readonly ["scope_id", "byte_limit", "byte_used", "updated_at"];
|
|
2582
2583
|
};
|
|
2583
2584
|
|
|
2585
|
+
type StoragePath = string;
|
|
2586
|
+
interface PutOpts {
|
|
2587
|
+
/** Reject if the target path already exists (atomic). */
|
|
2588
|
+
ifNotExists?: boolean;
|
|
2589
|
+
/** Hint for content-type; provider may sniff if absent. */
|
|
2590
|
+
contentType?: string;
|
|
2591
|
+
/** Free-form key/value metadata persisted with the file when supported. */
|
|
2592
|
+
metadata?: Record<string, string>;
|
|
2593
|
+
}
|
|
2594
|
+
interface PutResult {
|
|
2595
|
+
/** Provider tag — `"app_file_server"`, `"gdrive"`, `"in_memory"`. */
|
|
2596
|
+
provider: string;
|
|
2597
|
+
/** Provider-native identifier (path for app-server; file ID for GDrive). */
|
|
2598
|
+
native_id: string;
|
|
2599
|
+
/** Size in bytes of the persisted body. */
|
|
2600
|
+
size: number;
|
|
2601
|
+
}
|
|
2602
|
+
interface SignedUrlOpts {
|
|
2603
|
+
/** Seconds the URL is valid for. */
|
|
2604
|
+
ttl_seconds?: number;
|
|
2605
|
+
/** Suggested download filename (Content-Disposition). */
|
|
2606
|
+
filename_hint?: string;
|
|
2607
|
+
}
|
|
2608
|
+
interface ProbeResult {
|
|
2609
|
+
ok: boolean;
|
|
2610
|
+
/** Machine-readable error tag when ok=false. */
|
|
2611
|
+
error?: "drive_not_shared" | "write_denied" | "invalid_id" | "transient" | "config_missing";
|
|
2612
|
+
/** Free-form detail for logging. */
|
|
2613
|
+
message?: string;
|
|
2614
|
+
}
|
|
2615
|
+
/**
|
|
2616
|
+
* Storage provider abstraction. Every method MUST be idempotent at the
|
|
2617
|
+
* data-content level — re-invoking put with identical body is allowed.
|
|
2618
|
+
*
|
|
2619
|
+
* Paths are logical; providers translate to native identifiers internally.
|
|
2620
|
+
*/
|
|
2621
|
+
interface FileStorageProvider {
|
|
2622
|
+
put(path: StoragePath, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
|
|
2623
|
+
get(path: StoragePath): Promise<Buffer | Readable>;
|
|
2624
|
+
delete(path: StoragePath): Promise<void>;
|
|
2625
|
+
exists(path: StoragePath): Promise<boolean>;
|
|
2626
|
+
getSignedUrl(path: StoragePath, opts?: SignedUrlOpts): Promise<string>;
|
|
2627
|
+
/** Used by validation cron + onboarding step 2. */
|
|
2628
|
+
probe(): Promise<ProbeResult>;
|
|
2629
|
+
}
|
|
2630
|
+
declare class StorageCollisionExhausted extends Error {
|
|
2631
|
+
attempts: number;
|
|
2632
|
+
lastPath: StoragePath;
|
|
2633
|
+
constructor(attempts: number, lastPath: StoragePath);
|
|
2634
|
+
}
|
|
2635
|
+
declare class StorageNotConfigured extends Error {
|
|
2636
|
+
constructor();
|
|
2637
|
+
}
|
|
2638
|
+
declare class StorageUnavailable extends Error {
|
|
2639
|
+
reason: ProbeResult["error"];
|
|
2640
|
+
constructor(reason: ProbeResult["error"], message: string);
|
|
2641
|
+
}
|
|
2642
|
+
|
|
2643
|
+
interface AppFileServerOpts {
|
|
2644
|
+
/** Filesystem root. All paths are resolved relative to this. */
|
|
2645
|
+
root: string;
|
|
2646
|
+
/** HMAC secret used to sign download URLs. */
|
|
2647
|
+
hmac_secret: string;
|
|
2648
|
+
/** Default signed-URL TTL in seconds. */
|
|
2649
|
+
default_ttl_seconds?: number;
|
|
2650
|
+
}
|
|
2651
|
+
declare class AppFileServerProvider implements FileStorageProvider {
|
|
2652
|
+
readonly provider_tag: "app_file_server";
|
|
2653
|
+
private readonly root;
|
|
2654
|
+
private readonly secret;
|
|
2655
|
+
private readonly default_ttl;
|
|
2656
|
+
constructor(opts: AppFileServerOpts);
|
|
2657
|
+
private resolve;
|
|
2658
|
+
put(path: string, body: Buffer | Readable, opts?: PutOpts): Promise<PutResult>;
|
|
2659
|
+
get(path: string): Promise<Buffer>;
|
|
2660
|
+
delete(path: string): Promise<void>;
|
|
2661
|
+
exists(path: string): Promise<boolean>;
|
|
2662
|
+
getSignedUrl(path: string, opts?: SignedUrlOpts): Promise<string>;
|
|
2663
|
+
/** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
|
|
2664
|
+
verifySignedUrl(token: string, path: string): boolean;
|
|
2665
|
+
probe(): Promise<ProbeResult>;
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2584
2668
|
/**
|
|
2585
2669
|
* Migration: Add Reference Tracking (V2)
|
|
2586
2670
|
*
|
|
@@ -3644,4 +3728,4 @@ declare function toV2Record(record: FileMetadataRecord): FileMetadataRecordV2;
|
|
|
3644
3728
|
*/
|
|
3645
3729
|
declare function buildFileWithStatus(record: FileMetadataRecord): FileWithStatus;
|
|
3646
3730
|
|
|
3647
|
-
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_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, 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 PurgeJobHandlerOptions, type PurgeOnePayload, type PurgePlanPayload, type PurgePlanResult, 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 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, 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 };
|
|
3731
|
+
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, 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, 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, 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 };
|
package/dist/server/index.js
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
ALL_SYSTEM_VARIABLES: () => ALL_SYSTEM_VARIABLES,
|
|
34
|
+
AppFileServerProvider: () => AppFileServerProvider,
|
|
34
35
|
AuthenticationError: () => AuthenticationError,
|
|
35
36
|
ConfigurationError: () => ConfigurationError,
|
|
36
37
|
DEFAULT_DATE_FORMATS: () => DEFAULT_DATE_FORMATS,
|
|
@@ -71,6 +72,9 @@ __export(index_exports, {
|
|
|
71
72
|
SYSTEM_COUNTER_VARIABLES: () => SYSTEM_COUNTER_VARIABLES,
|
|
72
73
|
SYSTEM_DATE_VARIABLES: () => SYSTEM_DATE_VARIABLES,
|
|
73
74
|
SYSTEM_FILE_VARIABLES: () => SYSTEM_FILE_VARIABLES,
|
|
75
|
+
StorageCollisionExhausted: () => StorageCollisionExhausted,
|
|
76
|
+
StorageNotConfigured: () => StorageNotConfigured,
|
|
77
|
+
StorageUnavailable: () => StorageUnavailable,
|
|
74
78
|
TrackedFileManager: () => TrackedFileManager,
|
|
75
79
|
UploadExtractService: () => UploadExtractService,
|
|
76
80
|
addExtractionToFileData: () => addExtractionToFileData,
|
|
@@ -6477,6 +6481,102 @@ var HAZO_FILE_QUOTAS_TABLE_SCHEMA = {
|
|
|
6477
6481
|
columns: ["scope_id", "byte_limit", "byte_used", "updated_at"]
|
|
6478
6482
|
};
|
|
6479
6483
|
|
|
6484
|
+
// src/providers/app-file-server.ts
|
|
6485
|
+
var import_node_crypto = require("crypto");
|
|
6486
|
+
var import_node_fs = require("fs");
|
|
6487
|
+
var import_node_path = require("path");
|
|
6488
|
+
var AppFileServerProvider = class {
|
|
6489
|
+
constructor(opts) {
|
|
6490
|
+
this.provider_tag = "app_file_server";
|
|
6491
|
+
this.root = (0, import_node_path.normalize)(opts.root);
|
|
6492
|
+
this.secret = opts.hmac_secret;
|
|
6493
|
+
this.default_ttl = opts.default_ttl_seconds ?? 300;
|
|
6494
|
+
}
|
|
6495
|
+
resolve(path4) {
|
|
6496
|
+
const safe = (0, import_node_path.normalize)(path4).replace(/^([./\\])+/, "");
|
|
6497
|
+
if (safe.includes(`..${import_node_path.sep}`) || safe.startsWith("..")) {
|
|
6498
|
+
throw new Error(`Path escapes root: ${path4}`);
|
|
6499
|
+
}
|
|
6500
|
+
return (0, import_node_path.join)(this.root, safe);
|
|
6501
|
+
}
|
|
6502
|
+
async put(path4, body, opts) {
|
|
6503
|
+
const abs = this.resolve(path4);
|
|
6504
|
+
if (opts?.ifNotExists && (0, import_node_fs.existsSync)(abs)) {
|
|
6505
|
+
throw new Error(`File exists: ${path4}`);
|
|
6506
|
+
}
|
|
6507
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path.dirname)(abs), { recursive: true });
|
|
6508
|
+
const buf = Buffer.isBuffer(body) ? body : await streamToBuffer(body);
|
|
6509
|
+
(0, import_node_fs.writeFileSync)(abs, buf);
|
|
6510
|
+
return { provider: this.provider_tag, native_id: path4, size: buf.length };
|
|
6511
|
+
}
|
|
6512
|
+
async get(path4) {
|
|
6513
|
+
return (0, import_node_fs.readFileSync)(this.resolve(path4));
|
|
6514
|
+
}
|
|
6515
|
+
async delete(path4) {
|
|
6516
|
+
const abs = this.resolve(path4);
|
|
6517
|
+
if ((0, import_node_fs.existsSync)(abs)) (0, import_node_fs.rmSync)(abs, { force: true });
|
|
6518
|
+
}
|
|
6519
|
+
async exists(path4) {
|
|
6520
|
+
return (0, import_node_fs.existsSync)(this.resolve(path4));
|
|
6521
|
+
}
|
|
6522
|
+
async getSignedUrl(path4, opts) {
|
|
6523
|
+
const ttl = opts?.ttl_seconds ?? this.default_ttl;
|
|
6524
|
+
const exp = Math.floor(Date.now() / 1e3) + ttl;
|
|
6525
|
+
const payload = `${path4}:${exp}`;
|
|
6526
|
+
const sig = (0, import_node_crypto.createHmac)("sha256", this.secret).update(payload).digest("base64url");
|
|
6527
|
+
const token = `${exp}.${sig}`;
|
|
6528
|
+
return `/api/files/serve/${token}/${path4}`;
|
|
6529
|
+
}
|
|
6530
|
+
/** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
|
|
6531
|
+
verifySignedUrl(token, path4) {
|
|
6532
|
+
const [expStr, sig] = token.split(".");
|
|
6533
|
+
const exp = Number(expStr);
|
|
6534
|
+
if (!Number.isFinite(exp) || exp * 1e3 < Date.now()) return false;
|
|
6535
|
+
const expected = (0, import_node_crypto.createHmac)("sha256", this.secret).update(`${path4}:${exp}`).digest("base64url");
|
|
6536
|
+
return sig === expected;
|
|
6537
|
+
}
|
|
6538
|
+
async probe() {
|
|
6539
|
+
try {
|
|
6540
|
+
const test = (0, import_node_path.join)(this.root, ".hazo_probe");
|
|
6541
|
+
(0, import_node_fs.mkdirSync)(this.root, { recursive: true });
|
|
6542
|
+
(0, import_node_fs.writeFileSync)(test, "probe");
|
|
6543
|
+
(0, import_node_fs.statSync)(test);
|
|
6544
|
+
(0, import_node_fs.rmSync)(test, { force: true });
|
|
6545
|
+
return { ok: true };
|
|
6546
|
+
} catch (err) {
|
|
6547
|
+
return { ok: false, error: "write_denied", message: String(err) };
|
|
6548
|
+
}
|
|
6549
|
+
}
|
|
6550
|
+
};
|
|
6551
|
+
async function streamToBuffer(s) {
|
|
6552
|
+
const chunks = [];
|
|
6553
|
+
for await (const c of s) chunks.push(Buffer.isBuffer(c) ? c : Buffer.from(c));
|
|
6554
|
+
return Buffer.concat(chunks);
|
|
6555
|
+
}
|
|
6556
|
+
|
|
6557
|
+
// src/providers/types.ts
|
|
6558
|
+
var StorageCollisionExhausted = class extends Error {
|
|
6559
|
+
constructor(attempts, lastPath) {
|
|
6560
|
+
super(`Storage collision could not be resolved after ${attempts} attempts at "${lastPath}"`);
|
|
6561
|
+
this.attempts = attempts;
|
|
6562
|
+
this.lastPath = lastPath;
|
|
6563
|
+
this.name = "StorageCollisionExhausted";
|
|
6564
|
+
}
|
|
6565
|
+
};
|
|
6566
|
+
var StorageNotConfigured = class extends Error {
|
|
6567
|
+
constructor() {
|
|
6568
|
+
super("Storage provider is not configured for this scope");
|
|
6569
|
+
this.name = "StorageNotConfigured";
|
|
6570
|
+
}
|
|
6571
|
+
};
|
|
6572
|
+
var StorageUnavailable = class extends Error {
|
|
6573
|
+
constructor(reason, message) {
|
|
6574
|
+
super(message);
|
|
6575
|
+
this.reason = reason;
|
|
6576
|
+
this.name = "StorageUnavailable";
|
|
6577
|
+
}
|
|
6578
|
+
};
|
|
6579
|
+
|
|
6480
6580
|
// src/migrations/add-reference-tracking.ts
|
|
6481
6581
|
async function migrateToV2(executor, dbType, tableName) {
|
|
6482
6582
|
const migration = tableName ? getMigrationForTable(tableName, dbType) : HAZO_FILES_MIGRATION_V2[dbType];
|
|
@@ -6520,6 +6620,7 @@ try {
|
|
|
6520
6620
|
// Annotate the CommonJS export names for ESM import in node:
|
|
6521
6621
|
0 && (module.exports = {
|
|
6522
6622
|
ALL_SYSTEM_VARIABLES,
|
|
6623
|
+
AppFileServerProvider,
|
|
6523
6624
|
AuthenticationError,
|
|
6524
6625
|
ConfigurationError,
|
|
6525
6626
|
DEFAULT_DATE_FORMATS,
|
|
@@ -6560,6 +6661,9 @@ try {
|
|
|
6560
6661
|
SYSTEM_COUNTER_VARIABLES,
|
|
6561
6662
|
SYSTEM_DATE_VARIABLES,
|
|
6562
6663
|
SYSTEM_FILE_VARIABLES,
|
|
6664
|
+
StorageCollisionExhausted,
|
|
6665
|
+
StorageNotConfigured,
|
|
6666
|
+
StorageUnavailable,
|
|
6563
6667
|
TrackedFileManager,
|
|
6564
6668
|
UploadExtractService,
|
|
6565
6669
|
addExtractionToFileData,
|
package/dist/server/index.mjs
CHANGED
|
@@ -6288,6 +6288,109 @@ var HAZO_FILE_QUOTAS_TABLE_SCHEMA = {
|
|
|
6288
6288
|
columns: ["scope_id", "byte_limit", "byte_used", "updated_at"]
|
|
6289
6289
|
};
|
|
6290
6290
|
|
|
6291
|
+
// src/providers/app-file-server.ts
|
|
6292
|
+
import { createHmac } from "crypto";
|
|
6293
|
+
import {
|
|
6294
|
+
existsSync as existsSync2,
|
|
6295
|
+
mkdirSync,
|
|
6296
|
+
readFileSync as readFileSync2,
|
|
6297
|
+
rmSync,
|
|
6298
|
+
statSync,
|
|
6299
|
+
writeFileSync
|
|
6300
|
+
} from "fs";
|
|
6301
|
+
import { dirname as dirname2, join as join4, normalize, sep } from "path";
|
|
6302
|
+
var AppFileServerProvider = class {
|
|
6303
|
+
constructor(opts) {
|
|
6304
|
+
this.provider_tag = "app_file_server";
|
|
6305
|
+
this.root = normalize(opts.root);
|
|
6306
|
+
this.secret = opts.hmac_secret;
|
|
6307
|
+
this.default_ttl = opts.default_ttl_seconds ?? 300;
|
|
6308
|
+
}
|
|
6309
|
+
resolve(path4) {
|
|
6310
|
+
const safe = normalize(path4).replace(/^([./\\])+/, "");
|
|
6311
|
+
if (safe.includes(`..${sep}`) || safe.startsWith("..")) {
|
|
6312
|
+
throw new Error(`Path escapes root: ${path4}`);
|
|
6313
|
+
}
|
|
6314
|
+
return join4(this.root, safe);
|
|
6315
|
+
}
|
|
6316
|
+
async put(path4, body, opts) {
|
|
6317
|
+
const abs = this.resolve(path4);
|
|
6318
|
+
if (opts?.ifNotExists && existsSync2(abs)) {
|
|
6319
|
+
throw new Error(`File exists: ${path4}`);
|
|
6320
|
+
}
|
|
6321
|
+
mkdirSync(dirname2(abs), { recursive: true });
|
|
6322
|
+
const buf = Buffer.isBuffer(body) ? body : await streamToBuffer(body);
|
|
6323
|
+
writeFileSync(abs, buf);
|
|
6324
|
+
return { provider: this.provider_tag, native_id: path4, size: buf.length };
|
|
6325
|
+
}
|
|
6326
|
+
async get(path4) {
|
|
6327
|
+
return readFileSync2(this.resolve(path4));
|
|
6328
|
+
}
|
|
6329
|
+
async delete(path4) {
|
|
6330
|
+
const abs = this.resolve(path4);
|
|
6331
|
+
if (existsSync2(abs)) rmSync(abs, { force: true });
|
|
6332
|
+
}
|
|
6333
|
+
async exists(path4) {
|
|
6334
|
+
return existsSync2(this.resolve(path4));
|
|
6335
|
+
}
|
|
6336
|
+
async getSignedUrl(path4, opts) {
|
|
6337
|
+
const ttl = opts?.ttl_seconds ?? this.default_ttl;
|
|
6338
|
+
const exp = Math.floor(Date.now() / 1e3) + ttl;
|
|
6339
|
+
const payload = `${path4}:${exp}`;
|
|
6340
|
+
const sig = createHmac("sha256", this.secret).update(payload).digest("base64url");
|
|
6341
|
+
const token = `${exp}.${sig}`;
|
|
6342
|
+
return `/api/files/serve/${token}/${path4}`;
|
|
6343
|
+
}
|
|
6344
|
+
/** Verify a token produced by `getSignedUrl`. Used by the `/api/files/serve` route. */
|
|
6345
|
+
verifySignedUrl(token, path4) {
|
|
6346
|
+
const [expStr, sig] = token.split(".");
|
|
6347
|
+
const exp = Number(expStr);
|
|
6348
|
+
if (!Number.isFinite(exp) || exp * 1e3 < Date.now()) return false;
|
|
6349
|
+
const expected = createHmac("sha256", this.secret).update(`${path4}:${exp}`).digest("base64url");
|
|
6350
|
+
return sig === expected;
|
|
6351
|
+
}
|
|
6352
|
+
async probe() {
|
|
6353
|
+
try {
|
|
6354
|
+
const test = join4(this.root, ".hazo_probe");
|
|
6355
|
+
mkdirSync(this.root, { recursive: true });
|
|
6356
|
+
writeFileSync(test, "probe");
|
|
6357
|
+
statSync(test);
|
|
6358
|
+
rmSync(test, { force: true });
|
|
6359
|
+
return { ok: true };
|
|
6360
|
+
} catch (err) {
|
|
6361
|
+
return { ok: false, error: "write_denied", message: String(err) };
|
|
6362
|
+
}
|
|
6363
|
+
}
|
|
6364
|
+
};
|
|
6365
|
+
async function streamToBuffer(s) {
|
|
6366
|
+
const chunks = [];
|
|
6367
|
+
for await (const c of s) chunks.push(Buffer.isBuffer(c) ? c : Buffer.from(c));
|
|
6368
|
+
return Buffer.concat(chunks);
|
|
6369
|
+
}
|
|
6370
|
+
|
|
6371
|
+
// src/providers/types.ts
|
|
6372
|
+
var StorageCollisionExhausted = class extends Error {
|
|
6373
|
+
constructor(attempts, lastPath) {
|
|
6374
|
+
super(`Storage collision could not be resolved after ${attempts} attempts at "${lastPath}"`);
|
|
6375
|
+
this.attempts = attempts;
|
|
6376
|
+
this.lastPath = lastPath;
|
|
6377
|
+
this.name = "StorageCollisionExhausted";
|
|
6378
|
+
}
|
|
6379
|
+
};
|
|
6380
|
+
var StorageNotConfigured = class extends Error {
|
|
6381
|
+
constructor() {
|
|
6382
|
+
super("Storage provider is not configured for this scope");
|
|
6383
|
+
this.name = "StorageNotConfigured";
|
|
6384
|
+
}
|
|
6385
|
+
};
|
|
6386
|
+
var StorageUnavailable = class extends Error {
|
|
6387
|
+
constructor(reason, message) {
|
|
6388
|
+
super(message);
|
|
6389
|
+
this.reason = reason;
|
|
6390
|
+
this.name = "StorageUnavailable";
|
|
6391
|
+
}
|
|
6392
|
+
};
|
|
6393
|
+
|
|
6291
6394
|
// src/migrations/add-reference-tracking.ts
|
|
6292
6395
|
async function migrateToV2(executor, dbType, tableName) {
|
|
6293
6396
|
const migration = tableName ? getMigrationForTable(tableName, dbType) : HAZO_FILES_MIGRATION_V2[dbType];
|
|
@@ -6330,6 +6433,7 @@ try {
|
|
|
6330
6433
|
}
|
|
6331
6434
|
export {
|
|
6332
6435
|
ALL_SYSTEM_VARIABLES,
|
|
6436
|
+
AppFileServerProvider,
|
|
6333
6437
|
AuthenticationError,
|
|
6334
6438
|
ConfigurationError,
|
|
6335
6439
|
DEFAULT_DATE_FORMATS,
|
|
@@ -6370,6 +6474,9 @@ export {
|
|
|
6370
6474
|
SYSTEM_COUNTER_VARIABLES,
|
|
6371
6475
|
SYSTEM_DATE_VARIABLES,
|
|
6372
6476
|
SYSTEM_FILE_VARIABLES,
|
|
6477
|
+
StorageCollisionExhausted,
|
|
6478
|
+
StorageNotConfigured,
|
|
6479
|
+
StorageUnavailable,
|
|
6373
6480
|
TrackedFileManager,
|
|
6374
6481
|
UploadExtractService,
|
|
6375
6482
|
addExtractionToFileData,
|