@qaecy/cue-sdk 0.0.33 → 0.0.35

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/sync.d.ts ADDED
@@ -0,0 +1,153 @@
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 { CueProfile } from './profile';
6
+ import { CueProjects } from './project';
7
+ import { ScanOutputRecord, SyncOptions, SyncPreview, SyncResult } from './models';
8
+ /**
9
+ * Configure the URL from which the WASM scanner assets are loaded in browser environments.
10
+ * Call this once during app initialisation (e.g. Angular APP_INITIALIZER) before any credit
11
+ * calculations are requested.
12
+ *
13
+ * @param baseUrl - URL prefix for `dir_scanner_wasm_bg.wasm` and `dir_scanner_wasm.mjs`,
14
+ * e.g. `'/assets/wasm'` or `'https://cdn.example.com/wasm'`.
15
+ */
16
+ export declare function configureScanWasm(baseUrl: string): void;
17
+ export declare class CueSyncApi {
18
+ private readonly _auth;
19
+ private readonly _projects;
20
+ private readonly _blob;
21
+ private readonly _gatewayUrl;
22
+ private readonly _graphMap;
23
+ private _api?;
24
+ private _profile?;
25
+ private _pendingItems;
26
+ private _pendingSpaceId;
27
+ private _flushTimer;
28
+ private _legacy;
29
+ constructor(_auth: CueAuth, _projects: CueProjects, _blob: CueBlobStorage, _gatewayUrl: string);
30
+ /** @internal Injected by CueApi after construction to avoid circular dependency. */
31
+ _bindApi(api: CueApi): void;
32
+ /** @internal Injected by Cue after construction so sync can read/refresh org-level credits. */
33
+ _bindProfile(profile: CueProfile): void;
34
+ /**
35
+ * Credits are tracked per-organization (a shared pool across every project
36
+ * the org owns), not per-project — resolve the project's org and read from
37
+ * there instead of the legacy per-project `getConsumption` endpoint.
38
+ * `unitsAvailable` is set to the same org-level `available` figure, mirroring
39
+ * how the legacy per-project formula already treated the two as the same pool.
40
+ *
41
+ * Goes through `CueProfile.getOrgCredits()` rather than fetching directly so
42
+ * its `orgCredits` signal also refreshes as a side effect — consumers bound
43
+ * to that signal see balance changes after every preview/sync automatically.
44
+ */
45
+ private _getAvailableCredits;
46
+ /**
47
+ * Initialises browser-mode sync for a project space.
48
+ * - Flushes any metadata items that were queued but not sent in a previous session
49
+ * (persisted in `localStorage`).
50
+ * - Starts the 60-second periodic flush timer.
51
+ *
52
+ * Call this once when the file manager component is created (or when the active
53
+ * project changes) so that interrupted uploads are recovered immediately.
54
+ */
55
+ initBrowserSync(spaceId: string): Promise<void>;
56
+ /**
57
+ * Pushes filesystem-structure metadata for all provided files directly to the
58
+ * commands API, without checking what is already on the remote or accounting for
59
+ * credits. Use this when you want to force-write metadata for every file in a
60
+ * local path (e.g. to repair missing graph data after a migration).
61
+ */
62
+ pushAllMetadata(localFiles: LocalFile[], options: Pick<SyncOptions, 'spaceId' | 'providerId' | 'verbose' | 'legacy'>): Promise<void>;
63
+ /**
64
+ * Flushes any pending file-location metadata from a previously interrupted sync.
65
+ * Safe to call even when there are no new files to upload (e.g. when the process
66
+ * died after uploading to blob storage but before the commands-API batch POST).
67
+ */
68
+ flushPendingMetadata(spaceId: string, verbose?: boolean, legacy?: boolean): Promise<void>;
69
+ /**
70
+ * Returns a preview of what would be synced: cost breakdown for new files only,
71
+ * units required, and units still available. Use this before calling {@link sync}
72
+ * to show the user an accurate cost estimate.
73
+ */
74
+ previewSync(localFiles: LocalFile[], options: SyncOptions): Promise<SyncPreview>;
75
+ sync(localFiles: LocalFile[], options: SyncOptions): Promise<SyncResult>;
76
+ private _getOrCreateGraph;
77
+ private _listRemoteFiles;
78
+ private _getGraphFiles;
79
+ private _initPendingBatch;
80
+ private _queueFileLocation;
81
+ /**
82
+ * Flush all queued file-location items to the commands API in a single batch.
83
+ * Call this once after a group of `syncBrowserFile` calls completes so that
84
+ * all items are sent together rather than one POST per file.
85
+ *
86
+ * Also refreshes the org's credit pool (best-effort) once the batch is
87
+ * flushed, so `CueProfile.orgCredits` reflects the just-uploaded files
88
+ * without the caller having to remember to ask for it — `syncBrowserFile`
89
+ * itself never touches credits, unlike the CLI's `sync()`.
90
+ */
91
+ drainPending(): Promise<void>;
92
+ private _drainPending;
93
+ private _flushBatch;
94
+ private _postFssBatch;
95
+ private _stopFlushTimer;
96
+ /**
97
+ * Scans `localFiles` and returns a per-extension cost breakdown.
98
+ *
99
+ * Each {@link ScanOutputRecord} contains `units` — the billable metric for
100
+ * that extension (e.g. pages for PDFs, rows for spreadsheets) — which can be
101
+ * shown to the user before or after calling {@link sync}.
102
+ */
103
+ scanCost(localFiles: LocalFile[]): Promise<ScanOutputRecord[]>;
104
+ /**
105
+ * Compute the credit cost for a set of local files without uploading anything.
106
+ * Intended for browser use where the full {@link previewSync} (which requires a
107
+ * remote file listing) would be too heavy for a quick estimate.
108
+ *
109
+ * @param localFiles - Files to analyse. Each entry must carry `data` when
110
+ * called from a browser context.
111
+ * @param spaceId - Project/space identifier used to fetch tier settings and resolve the owning org.
112
+ * @returns Per-extension cost breakdown and the number of credits currently
113
+ * available in the project's organization (shared pool).
114
+ */
115
+ computeCredits(localFiles: LocalFile[], spaceId: string): Promise<{
116
+ costRecords: ScanOutputRecord[];
117
+ creditsToConsume: number;
118
+ creditsAvailable: number;
119
+ }>;
120
+ /**
121
+ * Upload a single browser-supplied file and write its metadata to the knowledge graph.
122
+ *
123
+ * Unlike {@link sync} (which performs a full remote comparison), this method is
124
+ * designed for the web file-manager flow where the user has already confirmed the
125
+ * upload via the credit modal. The file's binary data must be provided in
126
+ * `file.data`; the `file.fullPath` field is ignored.
127
+ *
128
+ * Cancellation is supported via `options.signal`. Aborting the signal cancels
129
+ * the Firebase Storage upload; metadata is never written for a cancelled upload.
130
+ *
131
+ * @param file - `LocalFile` with `data` populated (e.g. from `File.arrayBuffer()`).
132
+ * @param options - Upload options including project/provider/user context and an
133
+ * optional `AbortSignal` for cancellation and `onProgress` for tracking.
134
+ */
135
+ syncBrowserFile(file: LocalFile, options: {
136
+ spaceId: string;
137
+ providerId: string;
138
+ userId: string;
139
+ signal?: AbortSignal;
140
+ onProgress?: (percent: number) => void;
141
+ }): Promise<void>;
142
+ getTierNames(): Promise<Record<string, string>>;
143
+ /**
144
+ * Per-extension credit rates for `tier` (e.g. `{ pdf: 4, ifc: 2, dwg: 2 }`),
145
+ * read from the public `unit-credit.json` rate table. Used by host apps to
146
+ * show usage estimates (e.g. the sign-up plan-selection step) without
147
+ * running a full {@link computeCredits} scan.
148
+ */
149
+ getUnitCredits(tier: 's' | 'm' | 'l'): Promise<Record<string, number>>;
150
+ private _fetchTierNames;
151
+ private _fetchUnitCreditMap;
152
+ private _logProgress;
153
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,22 @@
1
+ import { CueAuth } from './auth';
2
+ /**
3
+ * Global, per-user app settings — a single small JSON blob (capped at 100KB
4
+ * server-side), scoped to the current user only. Unlike {@link CueAppData}
5
+ * (which namespaces data per studio-app UUID), this is one blob shared across
6
+ * the whole portal, e.g. `{ language: 'da' }`.
7
+ */
8
+ export declare class CueUserSettings {
9
+ private readonly _auth;
10
+ private readonly _gatewayUrl;
11
+ constructor(_auth: CueAuth, _gatewayUrl: string);
12
+ /**
13
+ * Fetch the current user's settings.
14
+ * Returns `null` if nothing has been saved yet.
15
+ */
16
+ get<T = unknown>(): Promise<T | null>;
17
+ /**
18
+ * Save the current user's settings. Overwrites any previous value.
19
+ * The server rejects payloads larger than 100KB.
20
+ */
21
+ set(data: unknown): Promise<void>;
22
+ }
package/node.js CHANGED
@@ -1,34 +1,43 @@
1
- import { C as s } from "./document-filter-Cmavbe75.js";
2
- import { a as r, b as c, c as i, d as n, e as l, f as m, g as p, h as P, i as d, j, k as x, l as S, m as f, n as g, o as h, p as E, q as R, r as A, s as v, R as D, t as b, u as I, v as W } from "./document-filter-Cmavbe75.js";
3
- class t extends s {
1
+ import { C as s } from "./document-filter-Dr_-QbaZ.js";
2
+ import { B as o, f as c, A as i, D as n, c as p, v as E, z as S, w as P, m as R, y as m, a as A, g, h as l, s as x, k as j, r as D, o as U, n as d, l as f, p as h, q as y, e as I, d as N, t as _, b, i as q, x as v, E as w, R as B, S as O, j as T, u as k } from "./document-filter-Dr_-QbaZ.js";
3
+ class C extends s {
4
4
  constructor(e) {
5
5
  super(e);
6
6
  }
7
7
  }
8
8
  export {
9
+ o as BASE_CURRENCY,
9
10
  s as Cue,
10
- r as CueApi,
11
- c as CueAuth,
12
- i as CueCache,
13
- n as CueContexts,
14
- l as CueDocumentFilter,
11
+ c as CueApi,
12
+ i as CueAppData,
13
+ n as CueApps,
14
+ p as CueAuth,
15
+ E as CueCache,
16
+ S as CueContexts,
17
+ P as CueCurrency,
18
+ R as CueDocumentFilter,
15
19
  m as CueExtraction,
16
- p as CueGis,
17
- P as CueIndexApi,
18
- t as CueNode,
19
- d as CuePrivileges,
20
- j as CueProfile,
21
- x as CueProjectDocuments,
22
- S as CueProjectEntities,
20
+ A as CueGis,
21
+ g as CueIndexApi,
22
+ l as CueMcp,
23
+ C as CueNode,
24
+ x as CuePrivileges,
25
+ j as CueProcessingApi,
26
+ D as CueProfile,
27
+ U as CueProjectDocuments,
28
+ d as CueProjectEntities,
23
29
  f as CueProjectSchema,
24
- g as CueProjectView,
25
- h as CueProjects,
26
- E as CueSignal,
27
- R as CueStorage,
28
- A as CueSyncApi,
30
+ h as CueProjectView,
31
+ y as CueProjects,
32
+ I as CueRequestError,
33
+ N as CueSignUp,
34
+ _ as CueSignal,
35
+ b as CueStorage,
36
+ q as CueSyncApi,
29
37
  v as CueTables,
30
- D as REQUIRED_ROLES,
31
- b as configureScanWasm,
32
- I as cueComputed,
33
- W as staleWhileRevalidate
38
+ w as CueUserSettings,
39
+ B as REQUIRED_ROLES,
40
+ O as SUPPORTED_CURRENCIES,
41
+ T as configureScanWasm,
42
+ k as cueComputed
34
43
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qaecy/cue-sdk",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -18,11 +18,10 @@
18
18
  }
19
19
  },
20
20
  "files": [
21
- "index.js",
22
- "index.d.ts",
23
- "node.js",
24
- "node.d.ts",
25
- "browser.js"
21
+ "*.js",
22
+ "*.d.ts",
23
+ "lib",
24
+ "assets"
26
25
  ],
27
26
  "peerDependencies": {
28
27
  "firebase": ">=10.0.0"
package/variables.d.ts ADDED
@@ -0,0 +1,71 @@
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_ORG_CREDITS: (orgId: string) => string;
31
+ export declare const ENDPOINT_ORG_CREDITS_REPORT: (orgId: string) => string;
32
+ export declare const ENDPOINT_COMMANDS_USER_SIGNUP = "/commands/admin/user/signup";
33
+ export declare const ENDPOINT_COMMANDS_USER_SIGNUP_RESEND = "/commands/admin/user/signup/resend";
34
+ export declare const ENDPOINT_COMMANDS_USER_SETTINGS = "/commands/admin/user/settings";
35
+ export declare const ENDPOINT_DATA_VIEWS_USER_SETTINGS = "/data-views/admin/users/settings";
36
+ export declare const ENDPOINT_COMMANDS_ORG_SIGNUP = "/commands/admin/organization/signup";
37
+ export declare const ENDPOINT_COMMANDS_ORG_CREDITS: (orgId: string) => string;
38
+ export declare const ENDPOINT_COMMANDS_ORG_PLAN: (orgId: string) => string;
39
+ export declare const ENDPOINT_COMMANDS_ORG_CHECKOUT: (orgId: string) => string;
40
+ export declare const ENDPOINT_COMMANDS_ORG_BILLING_PORTAL: (orgId: string) => string;
41
+ export declare const ENDPOINT_COMMANDS_ORG_MEMBERS: (orgId: string) => string;
42
+ export declare const ENDPOINT_COMMANDS_ORG_MEMBER_ROLE: (orgId: string, userId: string) => string;
43
+ export declare const ENDPOINT_COMMANDS_ORG_MEMBER: (orgId: string, userId: string) => string;
44
+ export declare const ENDPOINT_PROJECTS = "/data-views/admin/projects";
45
+ export declare const ENDPOINT_CREATE_PROJECT = "/commands/admin/project";
46
+ export declare const ENDPOINT_DELETE_PROJECT: (projectId: string) => string;
47
+ export declare const ENDPOINT_SEARCH = "/assistant/search";
48
+ export declare const ENDPOINT_MCP = "/mcp";
49
+ export declare const ENDPOINT_INDEX_SEARCH = "/index/search";
50
+ export declare const ENDPOINT_INDEX_LOOKUP = "/index/lookup";
51
+ export declare const ENDPOINT_INDEX_AVAILABLE_FILTERS = "/index/available-filters";
52
+ export declare const ENDPOINT_FUSEKI_QUERY = "/triplestore/query";
53
+ export declare const ENDPOINT_FUSEKI_UPDATE = "/triplestore/update";
54
+ export declare const ENDPOINT_FUSEKI_SHACL = "/triplestore/shacl";
55
+ export declare const ENDPOINT_QLEVER_QUERY = "/qlever-server/qlever/query";
56
+ export declare const ENDPOINT_QLEVER_UPDATE = "/qlever-server/qlever/update";
57
+ export declare const ENDPOINT_QLEVER_SHACL = "/qlever-server/qlever/shacl";
58
+ export declare const ENDPOINT_QLEVER_ADMIN_REBUILD = "/qlever-server/qlever/admin/rebuild";
59
+ export declare const ENDPOINT_QLEVER_ADMIN_STATS_REFRESH = "/qlever-server/admin/stats/refresh";
60
+ export declare const ENDPOINT_FSS_BATCH = "/commands/file-system-structure/batch";
61
+ export declare const ENDPOINT_STORAGE_SESSIONS = "/storage/sessions";
62
+ export declare const ENDPOINT_STORAGE_RAW = "/storage/raw";
63
+ export declare const ENDPOINT_STORAGE_PROCESSED = "/storage/processed";
64
+ export declare const ENDPOINT_PROCESSING_STATUS_WS = "/data-views/processing-status";
65
+ export declare const MICROSOFT_PROVIDER_ID = "microsoft.com";
66
+ export declare const SUPERADMIN_ROLE = "superadmin";
67
+ /**
68
+ * Base URL for all RDF resource IRIs: `https://cue.qaecy.com/r/{projectId}/{entityUUID}`.
69
+ * Entity IRIs are constructed as `${RESOURCE_BASE}${projectId}/${uuid}`.
70
+ */
71
+ export declare const RESOURCE_BASE = "https://cue.qaecy.com/r/";