@qaecy/cue-sdk 0.0.31 → 0.0.33

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/lib/project.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import { FirebaseApp } from 'firebase/app';
2
- import { CueAuth } from './auth';
3
- import { CreateProjectOptions, CueEndpoints, ProjectData } from './models';
4
- type ProjectRole = 'admin' | 'syncer' | 'member';
5
- export declare class CueProjects {
6
- private readonly _auth;
7
- private readonly _db;
8
- private readonly _functions;
9
- private readonly _gatewayUrl;
10
- constructor(_auth: CueAuth, app: FirebaseApp, useEmulator?: boolean, endpoints?: CueEndpoints);
11
- private _requireUser;
12
- /**
13
- * Create a new project. The authenticated user is automatically set as admin, syncer, and member.
14
- * Throws if a project with the given ID already exists.
15
- */
16
- createProject(options: CreateProjectOptions): Promise<ProjectData>;
17
- /**
18
- * List all projects where the authenticated user appears in the members array.
19
- * Access is gated by Firestore rules which check membership.
20
- */
21
- listProjects(): Promise<ProjectData[]>;
22
- /** Fetch a single project by ID. Returns null if not found. */
23
- getProject(projectId: string): Promise<ProjectData | null>;
24
- /**
25
- * Atomically increments `unitsConsumed` on the top-level `clientSync/{projectId}`
26
- * document, creating it if it doesn't exist. Intended for pre-flight checks.
27
- */
28
- incrementUnitsConsumed(projectId: string, units: number, userId: string): Promise<void>;
29
- /**
30
- * Invite a user to a project by email. Returns the invited user's uid and display name.
31
- */
32
- inviteUserToProject(email: string, projectId: string, role: ProjectRole): Promise<{
33
- uid: string;
34
- name?: string;
35
- }>;
36
- /** Change an existing member's role on a project. */
37
- changeUserRoleOnProject(uid: string, projectId: string, role: ProjectRole): Promise<void>;
38
- /** Remove a member from a project. */
39
- removeUserFromProject(uid: string, projectId: string): Promise<void>;
40
- /**
41
- * Delete a project by ID. Requires superadmin privileges on the server.
42
- */
43
- deleteProject(projectId: string): Promise<void>;
44
- }
45
- export {};
package/lib/schema.d.ts DELETED
@@ -1,85 +0,0 @@
1
- import { CueApi } from './api';
2
- import { ReadonlySignal } from './signal';
3
- import { CategoryDef, QueryCache, RelationshipDef } from './models';
4
- /**
5
- * Holds the schema for a single project: available content categories,
6
- * entity categories, and entity relationship types.
7
- *
8
- * The full schema is fetched **once** (a single SPARQL query covering all three
9
- * collections) and cached. Labels and definitions are retained for every
10
- * available language as {@link LangMap}s; switching language is therefore a
11
- * cheap, client-side re-projection with no extra network round-trip.
12
- *
13
- * ### Reactive paradigm
14
- * All three collections are exposed as `ReadonlySignal<T>`. Framework adapters
15
- * (e.g. Angular) should bridge these to their own reactive primitives using
16
- * `subscribe()`.
17
- *
18
- * ### Lifecycle
19
- * One `CueProjectSchema` instance should be created per project. It is owned
20
- * by the higher-level `CueProjectView` and shares the same `CueApi` instance.
21
- *
22
- * @example
23
- * ```ts
24
- * const schema = new CueProjectSchema(cue.api, projectId, 'en');
25
- * schema.availableContentCategories.get(); // CategoryDef[]
26
- * schema.setLanguage('da'); // re-projects cached data instantly
27
- * await schema.refresh(); // force re-fetch
28
- * ```
29
- */
30
- export declare class CueProjectSchema {
31
- private readonly _api;
32
- private readonly _projectId;
33
- private readonly _queryCache?;
34
- private readonly _graphType?;
35
- private _snapshot?;
36
- private _inflight?;
37
- private _currentLang;
38
- private readonly _verbose;
39
- private readonly _contentCategories;
40
- private readonly _entityCategories;
41
- private readonly _relationships;
42
- /** Currently active content categories for the selected language. */
43
- readonly availableContentCategories: ReadonlySignal<CategoryDef[]>;
44
- /** Currently active entity categories for the selected language. */
45
- readonly availableEntityCategories: ReadonlySignal<CategoryDef[]>;
46
- /** Currently active entity relationship types for the selected language. */
47
- readonly availableEntityRelationships: ReadonlySignal<RelationshipDef[]>;
48
- /**
49
- * Resolves when the initial schema load for the constructor language has
50
- * completed (or failed). Await this before reading signal values imperatively.
51
- */
52
- readonly ready: Promise<void>;
53
- constructor(_api: CueApi, _projectId: string, language: string, _queryCache?: QueryCache | undefined, _graphType?: string | undefined, verbose?: boolean);
54
- /** Returns the currently active language. */
55
- get language(): string;
56
- /**
57
- * Switch the active language. Re-projects the already-fetched schema for the
58
- * new language without re-querying; only triggers a fetch if nothing has been
59
- * loaded yet.
60
- */
61
- setLanguage(lang: string): void;
62
- /**
63
- * Force a re-fetch of the schema, bypassing the cache.
64
- * Useful when the triplestore data has changed.
65
- */
66
- refresh(): Promise<void>;
67
- private _load;
68
- /**
69
- * Fetches the schema once. On QLever the pre-computed `schemas` materialized
70
- * view is tried first; if it yields no rows we warn and fall back to the live
71
- * schema query.
72
- */
73
- private _fetchSnapshot;
74
- private _apply;
75
- /** Projects a language-independent {@link SchemaNode} into a {@link CategoryDef}. */
76
- private _toDef;
77
- /**
78
- * Single query covering content categories, entity categories and entity
79
- * relationship types. Labels/definitions are returned untouched (with their
80
- * language tags) so they can be grouped into {@link LangMap}s client-side.
81
- */
82
- private _buildSchemaQuery;
83
- /** Runs a schema query and groups the flat rows into a {@link SchemaSnapshot}. */
84
- private _runSchemaQuery;
85
- }
package/lib/signal.d.ts DELETED
@@ -1,54 +0,0 @@
1
- import { QueryCache } from './models';
2
- /** A reactive value that can be read and subscribed to. */
3
- export interface ReadonlySignal<T> {
4
- /** Returns the current value. */
5
- get(): T;
6
- /**
7
- * Register a listener that is called whenever the value changes.
8
- * Returns an unsubscribe function.
9
- */
10
- subscribe(listener: () => void): () => void;
11
- }
12
- /** A writable reactive state container. */
13
- export declare class CueSignal<T> implements ReadonlySignal<T> {
14
- private _value;
15
- private _listeners;
16
- constructor(initial: T);
17
- get(): T;
18
- set(value: T): void;
19
- subscribe(listener: () => void): () => void;
20
- /** Returns a read-only view of this signal. */
21
- asReadonly(): ReadonlySignal<T>;
22
- }
23
- /**
24
- * Creates a derived read-only signal from one or more source signals.
25
- * The compute function is evaluated lazily and cached until a dependency changes.
26
- *
27
- * @param deps Source signals to watch.
28
- * @param compute Function that computes the derived value; must be pure.
29
- * @returns A `ReadonlySignal` with a `destroy()` method to stop tracking deps.
30
- */
31
- export declare function cueComputed<T>(deps: ReadonlySignal<unknown>[], compute: () => T): ReadonlySignal<T> & {
32
- destroy(): void;
33
- };
34
- /**
35
- * Stale-while-revalidate helper for SPARQL queries.
36
- *
37
- * 1. If `cache` is provided and has a stored result for `cacheKey`, calls
38
- * `onData(staleData, true)` immediately (synchronously relative to the await).
39
- * 2. Fires `fetchFresh()` to get current data from the triplestore.
40
- * 3. Calls `onData(freshData, false)`.
41
- * 4. Writes the fresh result to `cache` only if it differs from the stale
42
- * result (content-addressed via `contextBasedGuid`).
43
- * 5. Returns the fresh data.
44
- *
45
- * If no `cache` is provided the function simply fetches and calls `onData`
46
- * once, transparently.
47
- *
48
- * @param query The SPARQL query string — also used as cache key input.
49
- * @param fetchFresh Function that executes the query and returns the result.
50
- * @param onData Called once with stale data (if available) and once with
51
- * fresh data.
52
- * @param cache Optional {@link QueryCache} implementation.
53
- */
54
- export declare function staleWhileRevalidate<T>(query: string, fetchFresh: () => Promise<T>, onData: (data: T, isStale: boolean) => void, cache?: QueryCache): Promise<T>;
package/lib/storage.d.ts DELETED
@@ -1,52 +0,0 @@
1
- import { CueAuth } from './auth';
2
- export type StorageBucket = 'raw' | 'processed';
3
- /**
4
- * Provides document download URL resolution proxied through the Cue gateway.
5
- *
6
- * The returned URLs require an `Authorization: Bearer {token}` header — use
7
- * `cue.api.getAuthHeaders()` or `cue.auth.authenticatedFetch()` to fetch them.
8
- * For use in `<img src>` / `<video src>`, convert to a blob URL first:
9
- * ```ts
10
- * const response = await cue.auth.authenticatedFetch(url);
11
- * const objectUrl = URL.createObjectURL(await response.blob());
12
- * ```
13
- *
14
- * @example
15
- * ```ts
16
- * const url = cue.storage.getDownloadUrl('my-project', 'abc123', '.pdf');
17
- * const res = await cue.auth.authenticatedFetch(url);
18
- * ```
19
- */
20
- export declare class CueStorage {
21
- private readonly _auth;
22
- private readonly _gatewayUrl;
23
- constructor(_auth: CueAuth, _gatewayUrl: string);
24
- /**
25
- * Returns a gateway download URL for a document stored in Cue.
26
- *
27
- * The storage path is `{projectId}/{uuid}{suffix}`, e.g. `my-project/abc-123.pdf`.
28
- * The returned URL must be fetched with an Authorization header.
29
- *
30
- * @param projectId - The Cue project (space) ID.
31
- * @param uuid - The document UUID.
32
- * @param suffix - File suffix including the leading dot, e.g. `'.pdf'`, `'.ifc'`.
33
- * @param bucket - `'raw'` (default, original uploads) or `'processed'` (derived artefacts).
34
- */
35
- getDownloadUrl(projectId: string, uuid: string, suffix: string, bucket?: StorageBucket): string;
36
- /**
37
- * Returns a gateway download URL for an alternative representation using its
38
- * full `qcy:remoteRelativePath` stored in the processed bucket.
39
- *
40
- * Use this instead of `getDownloadUrl` when the document info was obtained via
41
- * `fetchAlternativeRepresentations` and carries a `remoteRelativePath`.
42
- *
43
- * @param remoteRelativePath - The full path in the processed bucket,
44
- * e.g. `{projectId}/fragments/{uuid}.fragments`.
45
- */
46
- getAltRepDownloadUrl(remoteRelativePath: string): string;
47
- /**
48
- * Fetch a file through the gateway and return it as a Blob.
49
- * Convenience wrapper around `getDownloadUrl` + `authenticatedFetch`.
50
- */
51
- downloadBlob(projectId: string, uuid: string, suffix: string, bucket?: StorageBucket): Promise<Blob>;
52
- }
package/lib/sync.d.ts DELETED
@@ -1,125 +0,0 @@
1
- import { CueBlobStorage } from 'js-databases';
2
- import { LocalFile } from 'js-sync-tools';
3
- import { CueAuth } from './auth';
4
- import { CueApi } from './api';
5
- import { CueProjects } from './project';
6
- import { ScanOutputRecord, SyncOptions, SyncPreview, SyncResult } from './models';
7
- /**
8
- * Configure the URL from which the WASM scanner assets are loaded in browser environments.
9
- * Call this once during app initialisation (e.g. Angular APP_INITIALIZER) before any credit
10
- * calculations are requested.
11
- *
12
- * @param baseUrl - URL prefix for `dir_scanner_wasm_bg.wasm` and `dir_scanner_wasm.mjs`,
13
- * e.g. `'/assets/wasm'` or `'https://cdn.example.com/wasm'`.
14
- */
15
- export declare function configureScanWasm(baseUrl: string): void;
16
- export declare class CueSyncApi {
17
- private readonly _auth;
18
- private readonly _projects;
19
- private readonly _blob;
20
- private readonly _gatewayUrl;
21
- private readonly _graphMap;
22
- private _api?;
23
- private _pendingItems;
24
- private _pendingSpaceId;
25
- private _flushTimer;
26
- private _legacy;
27
- constructor(_auth: CueAuth, _projects: CueProjects, _blob: CueBlobStorage, _gatewayUrl: string);
28
- /** @internal Injected by CueApi after construction to avoid circular dependency. */
29
- _bindApi(api: CueApi): void;
30
- /**
31
- * Initialises browser-mode sync for a project space.
32
- * - Flushes any metadata items that were queued but not sent in a previous session
33
- * (persisted in `localStorage`).
34
- * - Starts the 60-second periodic flush timer.
35
- *
36
- * Call this once when the file manager component is created (or when the active
37
- * project changes) so that interrupted uploads are recovered immediately.
38
- */
39
- initBrowserSync(spaceId: string): Promise<void>;
40
- /**
41
- * Pushes filesystem-structure metadata for all provided files directly to the
42
- * commands API, without checking what is already on the remote or accounting for
43
- * credits. Use this when you want to force-write metadata for every file in a
44
- * local path (e.g. to repair missing graph data after a migration).
45
- */
46
- pushAllMetadata(localFiles: LocalFile[], options: Pick<SyncOptions, 'spaceId' | 'providerId' | 'verbose' | 'legacy'>): Promise<void>;
47
- /**
48
- * Flushes any pending file-location metadata from a previously interrupted sync.
49
- * Safe to call even when there are no new files to upload (e.g. when the process
50
- * died after uploading to blob storage but before the commands-API batch POST).
51
- */
52
- flushPendingMetadata(spaceId: string, verbose?: boolean, legacy?: boolean): Promise<void>;
53
- /**
54
- * Returns a preview of what would be synced: cost breakdown for new files only,
55
- * units required, and units still available. Use this before calling {@link sync}
56
- * to show the user an accurate cost estimate.
57
- */
58
- previewSync(localFiles: LocalFile[], options: SyncOptions): Promise<SyncPreview>;
59
- sync(localFiles: LocalFile[], options: SyncOptions): Promise<SyncResult>;
60
- private _getOrCreateGraph;
61
- private _listRemoteFiles;
62
- private _getGraphFiles;
63
- private _initPendingBatch;
64
- private _queueFileLocation;
65
- /**
66
- * Flush all queued file-location items to the commands API in a single batch.
67
- * Call this once after a group of `syncBrowserFile` calls completes so that
68
- * all items are sent together rather than one POST per file.
69
- */
70
- drainPending(): Promise<void>;
71
- private _drainPending;
72
- private _flushBatch;
73
- private _postFssBatch;
74
- private _stopFlushTimer;
75
- /**
76
- * Scans `localFiles` and returns a per-extension cost breakdown.
77
- *
78
- * Each {@link ScanOutputRecord} contains `units` — the billable metric for
79
- * that extension (e.g. pages for PDFs, rows for spreadsheets) — which can be
80
- * shown to the user before or after calling {@link sync}.
81
- */
82
- scanCost(localFiles: LocalFile[]): Promise<ScanOutputRecord[]>;
83
- /**
84
- * Compute the credit cost for a set of local files without uploading anything.
85
- * Intended for browser use where the full {@link previewSync} (which requires a
86
- * remote file listing) would be too heavy for a quick estimate.
87
- *
88
- * @param localFiles - Files to analyse. Each entry must carry `data` when
89
- * called from a browser context.
90
- * @param spaceId - Project/space identifier used to fetch the tier settings.
91
- * @returns Per-extension cost breakdown and the number of credits currently
92
- * available in the project.
93
- */
94
- computeCredits(localFiles: LocalFile[], spaceId: string): Promise<{
95
- costRecords: ScanOutputRecord[];
96
- creditsToConsume: number;
97
- creditsAvailable: number;
98
- }>;
99
- /**
100
- * Upload a single browser-supplied file and write its metadata to the knowledge graph.
101
- *
102
- * Unlike {@link sync} (which performs a full remote comparison), this method is
103
- * designed for the web file-manager flow where the user has already confirmed the
104
- * upload via the credit modal. The file's binary data must be provided in
105
- * `file.data`; the `file.fullPath` field is ignored.
106
- *
107
- * Cancellation is supported via `options.signal`. Aborting the signal cancels
108
- * the Firebase Storage upload; metadata is never written for a cancelled upload.
109
- *
110
- * @param file - `LocalFile` with `data` populated (e.g. from `File.arrayBuffer()`).
111
- * @param options - Upload options including project/provider/user context and an
112
- * optional `AbortSignal` for cancellation and `onProgress` for tracking.
113
- */
114
- syncBrowserFile(file: LocalFile, options: {
115
- spaceId: string;
116
- providerId: string;
117
- userId: string;
118
- signal?: AbortSignal;
119
- onProgress?: (percent: number) => void;
120
- }): Promise<void>;
121
- getTierNames(): Promise<Record<string, string>>;
122
- private _fetchTierNames;
123
- private _fetchUnitCreditMap;
124
- private _logProgress;
125
- }
package/lib/tables.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { CueAuth } from './auth';
2
- export interface ProjectTable {
3
- id: string;
4
- title: string;
5
- columnDefs: Record<string, unknown>[];
6
- rowDef: string;
7
- }
8
- export declare class CueTables {
9
- private readonly _auth;
10
- private readonly _gatewayUrl;
11
- constructor(_auth: CueAuth, _gatewayUrl: string);
12
- listTables(projectId: string): Promise<ProjectTable[]>;
13
- saveTables(tables: ProjectTable[] | unknown[], projectId: string): Promise<void>;
14
- }
package/variables.d.ts DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Default Firebase configuration for the QAECY SDK demo app ("sdk-default").
3
- * These are safe to use for evaluation and development purposes.
4
- * For production use, obtain your own configuration from QAECY.
5
- */
6
- export declare const DEFAULT_SDK_CONFIG: {
7
- readonly apiKey: "AIzaSyAiW42QBx9HS4Khu88pCW7MV66IhBAQul0";
8
- readonly appId: "1:151132927589:web:d2ffdb377dfadfd23ab88c";
9
- readonly measurementId: "G-YT4PK6HGZD";
10
- };
11
- export declare const FIREBASE_PROJECT_ID = "qaecy-mvp-406413";
12
- export declare const FIREBASE_SENDER_ID = "734737865998";
13
- export declare const GCP_REGION = "europe-west6";
14
- export declare const COLLECTION_API_KEYS = "apiKeys";
15
- export declare const COLLECTION_ORGANIZATIONS = "organizations";
16
- export declare const COLLECTION_PROJECTS = "projects";
17
- export declare const BUCKET_SESSIONS = "sessions_eu_west6";
18
- export declare const BUCKET_CHAT_SESSIONS = "spaces_chats_eu_west6";
19
- export declare const BUCKET_RAW = "spaces_raw_eu_west6";
20
- export declare const BUCKET_PROCESSED = "spaces_processed_eu_west6";
21
- export declare const BUCKET_LOGS = "spaces_logs_eu_west6";
22
- export declare const BUCKET_PUBLIC = "cue_public_eu_west6";
23
- export declare const BUCKET_PERSISTENCE = "db_persistence_eu_west6";
24
- export declare const ENDPOINT_CONSUMPTION = "/data-views/admin/consumption";
25
- export declare const ENDPOINT_PROFILE_ORGANIZATIONS = "/data-views/admin/profile/organizations";
26
- export declare const ENDPOINT_PROFILE_API_KEYS = "/data-views/admin/profile/api-keys";
27
- export declare const ENDPOINT_COMMANDS_PROFILE_API_KEYS = "/commands/admin/profile/api-keys";
28
- export declare const ENDPOINT_COMMANDS_PROFILE_TERMS = "/commands/admin/profile/terms";
29
- export declare const ENDPOINT_ORG_MEMBERS: (orgId: string) => string;
30
- export declare const ENDPOINT_CREATE_PROJECT = "/commands/admin/project";
31
- export declare const ENDPOINT_DELETE_PROJECT: (projectId: string) => string;
32
- export declare const ENDPOINT_SEARCH = "/assistant/search";
33
- export declare const ENDPOINT_FUSEKI_QUERY = "/triplestore/query";
34
- export declare const ENDPOINT_FUSEKI_UPDATE = "/triplestore/update";
35
- export declare const ENDPOINT_FUSEKI_SHACL = "/triplestore/shacl";
36
- export declare const ENDPOINT_QLEVER_QUERY = "/qlever-server/qlever/query";
37
- export declare const ENDPOINT_QLEVER_UPDATE = "/qlever-server/qlever/update";
38
- export declare const ENDPOINT_QLEVER_SHACL = "/qlever-server/qlever/shacl";
39
- export declare const ENDPOINT_FSS_BATCH = "/commands/file-system-structure/batch";
40
- export declare const ENDPOINT_STORAGE_SESSIONS = "/storage/sessions";
41
- export declare const ENDPOINT_STORAGE_RAW = "/storage/raw";
42
- export declare const ENDPOINT_STORAGE_PROCESSED = "/storage/processed";
43
- export declare const MICROSOFT_PROVIDER_ID = "microsoft.com";
44
- export declare const SUPERADMIN_ROLE = "superadmin";
45
- /**
46
- * Base URL for all RDF resource IRIs: `https://cue.qaecy.com/r/{projectId}/{entityUUID}`.
47
- * Entity IRIs are constructed as `${RESOURCE_BASE}${projectId}/${uuid}`.
48
- */
49
- export declare const RESOURCE_BASE = "https://cue.qaecy.com/r/";