import { CueBlobStorage } from 'js-databases'; import { LocalFile } from 'js-sync-tools'; import { CueAuth } from './auth'; import { CueApi } from './api'; import { CueProfile } from './profile'; import { CueProjects } from './project'; import { ScanOutputRecord, SyncOptions, SyncPreview, SyncResult } from './models'; /** * Configure the URL from which the WASM scanner assets are loaded in browser environments. * Call this once during app initialisation (e.g. Angular APP_INITIALIZER) before any credit * calculations are requested. * * @param baseUrl - URL prefix for `dir_scanner_wasm_bg.wasm` and `dir_scanner_wasm.mjs`, * e.g. `'/assets/wasm'` or `'https://cdn.example.com/wasm'`. */ export declare function configureScanWasm(baseUrl: string): void; export declare class CueSyncApi { private readonly _auth; private readonly _projects; private readonly _blob; private readonly _gatewayUrl; private readonly _graphMap; private _api?; private _profile?; private _pendingItems; private _pendingSpaceId; private _flushTimer; private _legacy; constructor(_auth: CueAuth, _projects: CueProjects, _blob: CueBlobStorage, _gatewayUrl: string); /** @internal Injected by CueApi after construction to avoid circular dependency. */ _bindApi(api: CueApi): void; /** @internal Injected by Cue after construction so sync can read/refresh org-level credits. */ _bindProfile(profile: CueProfile): void; /** * Credits are tracked per-organization (a shared pool across every project * the org owns), not per-project — resolve the project's org and read from * there instead of the legacy per-project `getConsumption` endpoint. * `unitsAvailable` is set to the same org-level `available` figure, mirroring * how the legacy per-project formula already treated the two as the same pool. * * Goes through `CueProfile.getOrgCredits()` rather than fetching directly so * its `orgCredits` signal also refreshes as a side effect — consumers bound * to that signal see balance changes after every preview/sync automatically. */ private _getAvailableCredits; /** * Initialises browser-mode sync for a project space. * - Flushes any metadata items that were queued but not sent in a previous session * (persisted in `localStorage`). * - Starts the 60-second periodic flush timer. * * Call this once when the file manager component is created (or when the active * project changes) so that interrupted uploads are recovered immediately. */ initBrowserSync(spaceId: string): Promise; /** * Pushes filesystem-structure metadata for all provided files directly to the * commands API, without checking what is already on the remote or accounting for * credits. Use this when you want to force-write metadata for every file in a * local path (e.g. to repair missing graph data after a migration). */ pushAllMetadata(localFiles: LocalFile[], options: Pick): Promise; /** * Flushes any pending file-location metadata from a previously interrupted sync. * Safe to call even when there are no new files to upload (e.g. when the process * died after uploading to blob storage but before the commands-API batch POST). */ flushPendingMetadata(spaceId: string, verbose?: boolean, legacy?: boolean): Promise; /** * Returns a preview of what would be synced: cost breakdown for new files only, * units required, and units still available. Use this before calling {@link sync} * to show the user an accurate cost estimate. */ previewSync(localFiles: LocalFile[], options: SyncOptions): Promise; sync(localFiles: LocalFile[], options: SyncOptions): Promise; private _getOrCreateGraph; private _listRemoteFiles; private _getGraphFiles; private _initPendingBatch; private _queueFileLocation; /** * Flush all queued file-location items to the commands API in a single batch. * Call this once after a group of `syncBrowserFile` calls completes so that * all items are sent together rather than one POST per file. * * Also refreshes the org's credit pool (best-effort) once the batch is * flushed, so `CueProfile.orgCredits` reflects the just-uploaded files * without the caller having to remember to ask for it — `syncBrowserFile` * itself never touches credits, unlike the CLI's `sync()`. */ drainPending(): Promise; private _drainPending; private _flushBatch; private _postFssBatch; private _stopFlushTimer; /** * Scans `localFiles` and returns a per-extension cost breakdown. * * Each {@link ScanOutputRecord} contains `units` — the billable metric for * that extension (e.g. pages for PDFs, rows for spreadsheets) — which can be * shown to the user before or after calling {@link sync}. */ scanCost(localFiles: LocalFile[]): Promise; /** * Compute the credit cost for a set of local files without uploading anything. * Intended for browser use where the full {@link previewSync} (which requires a * remote file listing) would be too heavy for a quick estimate. * * @param localFiles - Files to analyse. Each entry must carry `data` when * called from a browser context. * @param spaceId - Project/space identifier used to fetch tier settings and resolve the owning org. * @returns Per-extension cost breakdown and the number of credits currently * available in the project's organization (shared pool). */ computeCredits(localFiles: LocalFile[], spaceId: string): Promise<{ costRecords: ScanOutputRecord[]; creditsToConsume: number; creditsAvailable: number; }>; /** * Upload a single browser-supplied file and write its metadata to the knowledge graph. * * Unlike {@link sync} (which performs a full remote comparison), this method is * designed for the web file-manager flow where the user has already confirmed the * upload via the credit modal. The file's binary data must be provided in * `file.data`; the `file.fullPath` field is ignored. * * Cancellation is supported via `options.signal`. Aborting the signal cancels * the Firebase Storage upload; metadata is never written for a cancelled upload. * * @param file - `LocalFile` with `data` populated (e.g. from `File.arrayBuffer()`). * @param options - Upload options including project/provider/user context and an * optional `AbortSignal` for cancellation and `onProgress` for tracking. */ syncBrowserFile(file: LocalFile, options: { spaceId: string; providerId: string; userId: string; signal?: AbortSignal; onProgress?: (percent: number) => void; }): Promise; getTierNames(): Promise>; /** * Per-extension credit rates for `tier` (e.g. `{ pdf: 4, ifc: 2, dwg: 2 }`), * read from the public `unit-credit.json` rate table. Used by host apps to * show usage estimates (e.g. the sign-up plan-selection step) without * running a full {@link computeCredits} scan. */ getUnitCredits(tier: 's' | 'm' | 'l'): Promise>; private _fetchTierNames; private _fetchUnitCreditMap; private _logProgress; }