/** * ndm_client - Unified import & upload client for BuckyOS WebSDK. * * Provides `pickupAndImport` and companion session/upload APIs that hide * runtime differences (pure browser, NDM Cache, NDM Store) behind a single * provider-based abstraction, plus structured `/ndm/v1/store/*` helpers for * trusted runtimes. */ import type { FileMediaMeta } from './ndn_types'; export type ImportMode = 'single_file' | 'multi_file' | 'single_dir' | 'mixed'; export type MaterializationStatus = 'ok' | 'on_cache' | 'all_in_store'; export type UploadStatus = 'not_started' | 'uploading' | 'completed' | 'failed' | 'not_required' | 'cancelled'; export type ObjectStatus = 'pending' | 'finalizing' | 'ready' | 'failed' | 'cancelled'; export type MaterializationPhase = 'qcid_lookup' | 'materializing' | 'thumbnail'; /** * Progress information emitted during the materialization (hashing) phase * of `pickupAndImport`. Web developers can use this to drive progress bars * or status text while files are being processed. */ export interface MaterializationProgress { phase: MaterializationPhase; /** 0-based index of the file currently being processed. */ fileIndex: number; /** Total number of files selected by the user. */ fileCount: number; /** Name of the file currently being processed. */ fileName: string; /** Bytes hashed so far for the current file (materializing phase only). */ bytesProcessed?: number; /** Total bytes of the current file. */ fileTotalBytes?: number; } export type NdmErrorCode = 'USER_CANCELLED' | 'INVALID_IMPORT_PATH' | 'IMPORT_PATH_CONFLICT' | 'EMPTY_DIRECTORY_UNAVAILABLE' | 'OBJECT_NOT_READY' | 'MODE_NOT_SUPPORTED_IN_RUNTIME' | 'DIRECTORY_NOT_SUPPORTED' | 'INVALID_ACCEPT_FILTER' | 'SESSION_NOT_FOUND' | 'UPLOAD_FAILED' | 'THUMBNAIL_GENERATION_FAILED' | 'STORE_API_NOT_SUPPORTED_IN_RUNTIME' | 'STORE_API_ENDPOINT_REQUIRED'; export declare class NdmError extends Error { readonly code: NdmErrorCode; constructor(code: NdmErrorCode, message?: string); } export interface ThumbnailOptions { enabled?: boolean; forTypes?: string[]; maxWidth?: number; maxHeight?: number; eager?: boolean; } export interface ThumbnailResult { available: boolean; url?: string; width?: number; height?: number; mimeType?: string; errorCode?: string; } export interface BaseImportedObject { objectId: string; name: string; relativePath?: string; sourcePath?: string; locality?: 'local_only' | 'cache' | 'store'; } export interface ImportedFileObject extends BaseImportedObject { kind: 'file'; size: number; mimeType?: string; thumbnail?: ThumbnailResult; /** The browser File handle, kept for upload. */ _file?: File; /** The canonical NDN FileObject JSON used for parent DirObject hashing. */ _ndnFileObject?: Record; } export interface ImportedDirObject extends BaseImportedObject { kind: 'dir'; children?: Array; } export interface PickupAndImportOptions { mode: TMode; accept?: string[]; thumbnails?: ThumbnailOptions; autoStartUpload?: boolean; /** With `autoStartUpload`: bind the single imported root into a bucket at finalize. */ bind?: StartUploadOptions['bind']; endpoint?: string; sessionToken?: string | null; headers?: Record; fetcher?: NdmStoreRequestOptions['fetcher']; signal?: AbortSignal; /** Per-call provider; selected files should use importFiles instead. */ provider?: ImportProvider; /** * What the caller already knows of a file's common meta. With a `mime` it is * taken as the whole probe result and the file is not probed again; without * one it is merged over the probe result, which keeps fields a transcode lost. */ fileMeta?: (file: File) => FileMediaMeta | undefined; /** * Optional callback invoked during the materialization (hashing) phase. * Use this to drive a progress bar while large files are being processed. */ onProgress?: (progress: MaterializationProgress) => void; } export interface ImportSessionSummary { totalObjects: number; totalFiles: number; totalDirs: number; totalBytes: number; } export interface ImportSessionSnapshot { sessionId: string; selection: TSelection; items: Array; materializationStatus: MaterializationStatus; uploadStatus: UploadStatus; objectStatus: ObjectStatus; error?: string; warnings: string[]; summary: ImportSessionSummary; } export type PickupAndImportResult = TMode extends 'single_file' ? ImportSessionSnapshot : TMode extends 'multi_file' ? ImportSessionSnapshot : TMode extends 'single_dir' ? ImportSessionSnapshot : ImportSessionSnapshot>; export interface PerObjectProgress { objectId: string; uploadedBytes: number; totalBytes: number; state: 'pending' | 'uploading' | 'completed' | 'failed'; } /** Where `finalize` bound the single imported root (`StartUploadOptions.bind`). */ export interface UploadBinding { bucket_id: string; key: string; obj_id: string; version: number; etag: string; created: boolean; } export interface ImportSessionStatus { sessionId: string; binding?: UploadBinding; materializationStatus: MaterializationStatus; uploadStatus: UploadStatus; objectStatus: ObjectStatus; error?: string; warnings: string[]; summary: ImportSessionSummary; progress: { uploadedBytes: number; uploadedObjects: number; totalBytes: number; totalObjects: number; }; perObjectProgress?: Record; } export interface StartUploadOptions { concurrency?: number; signal?: AbortSignal; headers?: Record; fetcher?: NdmStoreRequestOptions['fetcher']; onProgress?: (progress: UploadProgress) => void; priority?: 'foreground' | 'background'; /** * Override the NDM service base URL for TUS uploads. When omitted the * SDK will try to derive it from the zone host; the final TUS endpoint * is `${endpoint}/ndm/v1/uploads`. */ endpoint?: string; /** * Session token sent as `Authorization: Bearer` with every TUS request. * Defaults to the active runtime's session (renewed per chunk); `null` * sends cookies only. */ sessionToken?: string | null; /** * Bind the imported root (exactly one) into an application object bucket * as part of finalize; success means the content is retained by the bucket. */ bind?: { bucketId: string; key: string; contentType?: string; metadata?: Record; tags?: Record; expiresAt?: number; origin?: { author: string; source: string; collected_at: number; proof?: string; }; ifNoneMatch?: string; ifMatch?: string; }; extra?: Record; } export interface UploadProgress { sessionId: string; uploadStatus: UploadStatus; objectStatus: ObjectStatus; error?: string; warnings: string[]; totalBytes: number; uploadedBytes: number; /** Actual chunk payload bytes sent; excludes deduplicated logical progress. */ transmittedBytes: number; totalObjects: number; uploadedObjects: number; speedBps?: number; elapsedMs?: number; estimatedRemainingMs?: number; perObjectProgress?: Record; } export interface RuntimeCapabilities { canRevealRealPath: boolean; canUseNDMCache: boolean; canUseNDMStore: boolean; canPickDirectory: boolean; canPickMixed: boolean; } export interface ImportProvider { getCapabilities(): RuntimeCapabilities; pickFiles(options: PickupAndImportOptions): Promise; } export interface NdmStoreRequestOptions { /** * Base origin for the zone gateway, for example `https://app.zone.example` * or `http://host.docker.internal:3180`. */ endpoint?: string; fetcher?: (input: RequestInfo | URL, init?: RequestInit) => Promise; headers?: Record; credentials?: RequestCredentials; sessionToken?: string | null; signal?: AbortSignal; } export interface NdmLookupRequestOptions extends NdmStoreRequestOptions { } export interface NdmStoreErrorBody { error?: string; message?: string; [key: string]: unknown; } export declare class NdmStoreApiError extends Error { readonly status: number; readonly errorCode?: string; readonly responseBody?: unknown; constructor(status: number, errorCode?: string, message?: string, responseBody?: unknown); } export interface GetObjectRequest { obj_id: string; } export interface GetObjectResponse { obj_id: string; obj_data: string; } export interface ObjIdWithInnerPathRequest { obj_id: string; inner_path?: string; } export interface OpenObjectResponse { obj_data: string; } export interface GetDirChildRequest { dir_obj_id: string; item_name: string; } export interface GetDirChildResponse { obj_id: string; } export interface IsObjectStoredResponse { stored: boolean; } export interface IsObjectExistResponse { exists: boolean; } export type QueryObjectByIdResponse = { state: 'not_exist'; } | { state: 'object'; obj_data: string; }; export interface PutObjectRequest { obj_id: string; obj_data: string; } export interface ChunkIdRequest { chunk_id: string; } export interface HaveChunkResponse { exists: boolean; } export interface ChunkStateLocalInfoRange { start: number; end: number; } export interface ChunkStateLocalInfo { qcid: string; last_modify_time: number; range?: ChunkStateLocalInfoRange; } export type QueryChunkStateResponse = { state: 'new'; chunk_size: number; } | { state: 'completed'; chunk_size: number; } | { state: 'disabled'; chunk_size: number; } | { state: 'not_exist'; chunk_size: number; } | { state: 'local_link'; chunk_size: number; local_info: ChunkStateLocalInfo; } | { state: 'same_as'; chunk_size: number; same_as: string; }; export interface AddChunkBySameAsRequest { big_chunk_id: string; chunk_list_id: string; big_chunk_size: number; } export type PinScope = 'recursive' | 'skeleton' | 'lease'; export interface EdgeMsg { op: 'add' | 'remove'; referee: string; referrer: string; target_epoch: number; } export interface PinRequest { obj_id: string; owner: string; scope: PinScope; ttl_secs?: number; } export interface UnpinRequest { obj_id: string; owner: string; } export interface OwnerRequest { owner: string; } export interface CountResponse { count: number; } export interface FsAnchorRequest { obj_id: string; inode_id: number; field_tag: number; } export interface InodeRequest { inode_id: number; } export type AnchorStateValue = 'Pending' | 'Materializing' | string; export interface AnchorStateResponse { state: AnchorStateValue; } export interface ForcedGcUntilRequest { target_bytes: number; } export interface ForcedGcUntilResponse { freed_bytes: number; } export type NdmLookupScope = 'app' | 'global'; export interface LookupObjectRequest { scope: NdmLookupScope; quick_hash: string; inner_path?: string; } export interface LookupObjectExistsResponse { reusable?: boolean; object_id: string; scope: NdmLookupScope; exists: boolean; } export type LookupObjectChunkStateResponse = ({ object_id: string; scope: NdmLookupScope; reusable?: boolean; } & { state: 'new'; chunk_size: number; }) | ({ object_id: string; scope: NdmLookupScope; reusable?: boolean; } & { state: 'completed'; chunk_size: number; }) | ({ object_id: string; scope: NdmLookupScope; reusable?: boolean; } & { state: 'disabled'; chunk_size: number; }) | ({ object_id: string; scope: NdmLookupScope; reusable?: boolean; } & { state: 'not_exist'; chunk_size: number; }) | ({ object_id: string; reusable?: boolean; scope: NdmLookupScope; state: 'local_link'; chunk_size: number; local_info: ChunkStateLocalInfo; }) | ({ object_id: string; reusable?: boolean; scope: NdmLookupScope; state: 'same_as'; chunk_size: number; same_as: string; }); export type LookupObjectResponse = LookupObjectExistsResponse | LookupObjectChunkStateResponse; export declare function setImportProvider(provider: ImportProvider): void; export declare function getImportProvider(): ImportProvider; export declare function lookupObject(request: LookupObjectRequest, options?: NdmLookupRequestOptions): Promise; export declare function getObject(request: GetObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function openObject(request: ObjIdWithInnerPathRequest, options?: NdmStoreRequestOptions): Promise; export declare function getDirChild(request: GetDirChildRequest, options?: NdmStoreRequestOptions): Promise; export declare function isObjectStored(request: ObjIdWithInnerPathRequest, options?: NdmStoreRequestOptions): Promise; export declare function isObjectExist(request: GetObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function queryObjectById(request: GetObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function putObject(request: PutObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function removeObject(request: GetObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function haveChunk(request: ChunkIdRequest, options?: NdmStoreRequestOptions): Promise; export declare function queryChunkState(request: ChunkIdRequest, options?: NdmStoreRequestOptions): Promise; export declare function removeChunk(request: ChunkIdRequest, options?: NdmStoreRequestOptions): Promise; export declare function addChunkBySameAs(request: AddChunkBySameAsRequest, options?: NdmStoreRequestOptions): Promise; export declare function applyEdge(request: EdgeMsg, options?: NdmStoreRequestOptions): Promise; export declare function pin(request: PinRequest, options?: NdmStoreRequestOptions): Promise; export declare function unpin(request: UnpinRequest, options?: NdmStoreRequestOptions): Promise; export declare function unpinOwner(request: OwnerRequest, options?: NdmStoreRequestOptions): Promise; export declare function fsAcquire(request: FsAnchorRequest, options?: NdmStoreRequestOptions): Promise; export declare function fsRelease(request: FsAnchorRequest, options?: NdmStoreRequestOptions): Promise; export declare function fsReleaseInode(request: InodeRequest, options?: NdmStoreRequestOptions): Promise; export declare function fsAnchorState(request: FsAnchorRequest, options?: NdmStoreRequestOptions): Promise; export declare function forcedGcUntil(request: ForcedGcUntilRequest, options?: NdmStoreRequestOptions): Promise; export declare function outboxCount(options?: NdmStoreRequestOptions): Promise; export declare function debugDumpExpandState(request: GetObjectRequest, options?: NdmStoreRequestOptions): Promise; export declare function anchorState(request: UnpinRequest, options?: NdmStoreRequestOptions): Promise; /** * Canonical ndn-lib QCID: hash the entire file below 12 KiB, otherwise hash * three 4096-byte samples at head, centered midpoint, and tail. */ export declare function calculateQcidFromFile(file: File): Promise; /** * Build directory tree from flat file list (for webkitdirectory results). */ export type ImportTreeEntry = { kind: 'file'; file: File; } | ImportDirectoryEntry; export interface ImportDirectoryEntry { kind: 'dir'; name: string; children: ImportTreeEntry[]; } /** * Initiate a user file/directory selection and materialize the chosen items * into NDN objects. Returns a session snapshot with objectIds ready to use. */ export declare function pickupAndImport(options: PickupAndImportOptions): Promise>; /** Import an already selected FileList without modifying the global picker. */ export declare function importFiles(selectedFiles: readonly File[], options: PickupAndImportOptions): Promise>; export declare function importDirectory(tree: ImportDirectoryEntry, options?: Omit, 'mode'>): Promise>; /** * Query the current status of an import session. */ export declare function getImportSessionStatus(sessionId: string): Promise; /** * Query upload progress for an import session (focused view for progress bars). */ export declare function getUploadProgress(sessionId: string): Promise; /** Begin or retry upload. Completion includes canonical metadata and readiness. */ export declare function startUpload(sessionId: string, options?: StartUploadOptions): Promise; export declare function ensureUploaded(sessionId: string, options?: StartUploadOptions): Promise; /** Cancels only this import; shared stored objects are never deleted. */ export declare function cancelImportSession(sessionId: string): void; /** Release local File handles after consuming the result. A refresh requires reselection. */ export declare function releaseImportSession(sessionId: string): void; //# sourceMappingURL=ndm_client.d.ts.map