@qaecy/cue-sdk 0.0.5 → 0.0.8

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/index.d.ts CHANGED
@@ -1,7 +1,19 @@
1
1
  export { Cue } from './lib/cue';
2
2
  export { CueAuth } from './lib/auth';
3
3
  export { CueApi } from './lib/api';
4
+ export { CueSyncApi, configureScanWasm } from './lib/sync';
5
+ export { CueProjectSchema } from './lib/schema';
6
+ export { CueProjectEntities } from './lib/entities';
7
+ export { CueProjectDocuments } from './lib/documents';
8
+ export { CueProjectView } from './lib/project-view';
9
+ export type { CueProjectViewOptions } from './lib/project-view';
4
10
  export { CueProjects } from './lib/project';
5
11
  export { CueProfile } from './lib/profile';
6
- export type { CueSdkConfig, SsoProvider, PasswordCredentials, SearchRequest, SearchResponse, SearchSource, ProjectData, ProjectSettings, CreateProjectOptions, SyncOptions, SyncResult, SyncPreview, ScanOutputRecord, UnitsConsumedDto, ProfileSSOAccount, APIKeyInfo, APIKeyDoc, } from './lib/models';
12
+ export { CuePrivileges, REQUIRED_ROLES } from './lib/privileges';
13
+ export type { UserProjectRole, Privileges } from './lib/privileges';
14
+ export { CueSignal, cueComputed, staleWhileRevalidate } from './lib/signal';
15
+ export type { ReadonlySignal } from './lib/signal';
16
+ export { CueCache } from './lib/cache';
17
+ export type { QueryCacheEntry } from './lib/cache';
18
+ export type { CueSdkConfig, SsoProvider, PasswordCredentials, SearchRequest, SearchResponse, SearchSource, SearchOptions, ProjectData, ProjectSettings, CreateProjectOptions, SyncOptions, SyncResult, SyncPreview, ScanOutputRecord, UnitsConsumedDto, OrganizationData, OrgMember, ProfileSSOAccount, APIKeyInfo, APIKeyDoc, ProjectDoc, OrganizationDoc, UserDoc, RDFWritingDoc, ViewDefinition, QueryCache, CategoryDef, RelationshipDef, EntityCoreData, EntityRelationship, EntityRelationships, MapGeometry, EntityDetailedData, ProjectEntitiesData, DocumentInfo, DocumentSummary, ProjectDocumentsData, } from './lib/models';
7
19
  export type { AuthStateListener, Unsubscribe } from './lib/auth';
package/index.js CHANGED
@@ -1,8 +1,20 @@
1
- import { C as s, a as u, b as C, c as o, d as r } from "./cue-y-t8nSnt.js";
1
+ import { C as s, a as u, b as C, c, d as i, e as t, f as o, g as r, h as l, i as n, j as P, k as j, l as m, R as h, m as R, n as S, s as f } from "./cue-BIvMahsX.js";
2
2
  export {
3
3
  s as Cue,
4
4
  u as CueApi,
5
5
  C as CueAuth,
6
- o as CueProfile,
7
- r as CueProjects
6
+ c as CueCache,
7
+ i as CuePrivileges,
8
+ t as CueProfile,
9
+ o as CueProjectDocuments,
10
+ r as CueProjectEntities,
11
+ l as CueProjectSchema,
12
+ n as CueProjectView,
13
+ P as CueProjects,
14
+ j as CueSignal,
15
+ m as CueSyncApi,
16
+ h as REQUIRED_ROLES,
17
+ R as configureScanWasm,
18
+ S as cueComputed,
19
+ f as staleWhileRevalidate
8
20
  };
package/lib/api.d.ts CHANGED
@@ -8,7 +8,6 @@ export declare class CueApi {
8
8
  readonly projects: CueProjects;
9
9
  readonly sync?: CueSyncApi | undefined;
10
10
  constructor(_auth: CueAuth, _gatewayUrl: string, projects: CueProjects, sync?: CueSyncApi | undefined);
11
- private _authHeaders;
12
11
  /**
13
12
  * Returns standard authentication headers for the current user.
14
13
  * Useful when calling Cue-backed services directly (e.g. the GIS proxy).
@@ -23,6 +22,6 @@ export declare class CueApi {
23
22
  * Execute a SPARQL query against the project's triplestore.
24
23
  * The user must be authenticated before calling this.
25
24
  */
26
- sparql(query: string, projectId: string): Promise<unknown>;
25
+ sparql(query: string, projectId: string, graphType?: string): Promise<unknown>;
27
26
  getConsumption(projectId: string): Promise<UnitsConsumedDto>;
28
27
  }
package/lib/auth.d.ts CHANGED
@@ -1,18 +1,52 @@
1
1
  import { Auth, User } from 'firebase/auth';
2
2
  import { FirebaseApp } from 'firebase/app';
3
3
  import { CueEndpoints, PasswordCredentials, SsoProvider } from './models';
4
+ import { ReadonlySignal } from './signal';
4
5
  export type AuthStateListener = (user: User | null) => void;
5
6
  export type Unsubscribe = () => void;
6
7
  export declare class CueAuth {
7
8
  private readonly _auth;
8
9
  private readonly _endpoints;
10
+ private readonly _userSignal;
11
+ private readonly _tokenSignal;
12
+ private readonly _isSuperAdminSignal;
13
+ private readonly _userIdsSignal;
14
+ private readonly _stopTokenListener;
15
+ /** Reactive auth state — emits the signed-in `User`, or `null` when signed out. */
16
+ readonly user: ReadonlySignal<User | null>;
17
+ /** Reactive Firebase ID token — refreshes automatically; `null` when signed out. */
18
+ readonly token: ReadonlySignal<string | null>;
19
+ /** `true` when the current user has the `superadmin` custom claim. */
20
+ readonly isSuperAdmin: ReadonlySignal<boolean>;
21
+ /** All unique UIDs for the current user (Firebase UID + linked provider UIDs). */
22
+ readonly userIds: ReadonlySignal<string[]>;
9
23
  constructor(app: FirebaseApp, useEmulator: boolean | undefined, endpoints: CueEndpoints);
24
+ /** Stop all internal Firebase listeners. Call when the `Cue` instance is no longer needed. */
25
+ destroy(): void;
10
26
  /** Sign in with Google or Microsoft via browser popup */
11
27
  signIn(provider: SsoProvider): Promise<User>;
12
28
  /** Sign in with email and password */
13
29
  signIn(provider: 'password', credentials: PasswordCredentials): Promise<User>;
14
- /** Sign in with a Cue API key */
15
- signInWithApiKey(cueApiKey: string, projectId: string): Promise<User>;
30
+ /**
31
+ * Initiate a redirect-based sign-in (mobile / iframe contexts where popups
32
+ * are blocked). Call `checkRedirectResult()` on the next page load to
33
+ * retrieve the result.
34
+ */
35
+ signInWithRedirect(provider: SsoProvider): Promise<void>;
36
+ /**
37
+ * Retrieve the result of a redirect sign-in. Returns the signed-in `User`
38
+ * or `null` if there is no pending redirect result.
39
+ * Call this once on app startup before showing a sign-in UI.
40
+ */
41
+ checkRedirectResult(): Promise<User | null>;
42
+ /**
43
+ * One-shot async check — returns `true` if the current user has the
44
+ * `superadmin` custom claim. For reactive use, read `cue.auth.isSuperAdmin`
45
+ * (the signal) instead.
46
+ */
47
+ checkSuperAdmin(): Promise<boolean>;
48
+ /** Sign in with a Cue API key. `projectId` is optional — omit it when no project context is available (e.g. admin flows). */
49
+ signInWithApiKey(cueApiKey: string, projectId?: string): Promise<User>;
16
50
  /** Sign out the current user */
17
51
  signOut(): Promise<void>;
18
52
  /** Currently signed-in user, or null if not authenticated */
@@ -21,6 +55,11 @@ export declare class CueAuth {
21
55
  onAuthStateChanged(listener: AuthStateListener): Unsubscribe;
22
56
  /** Get the Firebase ID token for the current user, or null if not authenticated */
23
57
  getToken(forceRefresh?: boolean): Promise<string | null>;
58
+ /**
59
+ * Executes a fetch with a Bearer token. On a 401 response the token is
60
+ * force-refreshed and the request is retried once before throwing.
61
+ */
62
+ authenticatedFetch(url: string, init?: RequestInit): Promise<Response>;
24
63
  /** Raw Firebase Auth instance, for advanced use cases */
25
64
  get firebaseAuth(): Auth;
26
65
  }
package/lib/cache.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { FirebaseStorage } from 'firebase/storage';
2
+ /** Shape stored by the query cache. */
3
+ export interface QueryCacheEntry {
4
+ query: string;
5
+ results: unknown;
6
+ }
7
+ /**
8
+ * Gzip-compressed JSON cache backed by the `persistence` Cloud Storage bucket.
9
+ *
10
+ * Path conventions:
11
+ * - Query results: `portal/projects/{pid}/queries/{id}.json.gz`
12
+ * - Agent sessions: `portal/projects/{pid}/agent/{id}.json.gz`
13
+ * - User-project data: `portal/projects/{pid}/users/{uid}/{id}.json.gz`
14
+ */
15
+ export declare class CueCache {
16
+ private readonly _storage;
17
+ constructor(_storage: FirebaseStorage);
18
+ getQueryCache(projectId: string, id: string): Promise<QueryCacheEntry | undefined>;
19
+ setQueryCache(projectId: string, id: string, payload: QueryCacheEntry): Promise<void>;
20
+ getAgentSessionCache(projectId: string, id: string): Promise<object | undefined>;
21
+ setAgentSessionCache(projectId: string, id: string, payload: object): Promise<void>;
22
+ getUserProjectCache(projectId: string, userId: string, id: string): Promise<object | undefined>;
23
+ setUserProjectCache(projectId: string, userId: string, id: string, payload: object): Promise<void>;
24
+ private _get;
25
+ private _set;
26
+ }
package/lib/cue.d.ts CHANGED
@@ -3,7 +3,10 @@ import { CueAuth } from './auth';
3
3
  import { CueApi } from './api';
4
4
  import { CueProjects } from './project';
5
5
  import { CueProfile } from './profile';
6
- import { CueEndpoints, CueSdkConfig } from './models';
6
+ import { CuePrivileges } from './privileges';
7
+ import { CueCache } from './cache';
8
+ import { CueProjectView, CueProjectViewOptions } from './project-view';
9
+ import { CueEndpoints, CueSdkConfig, QueryCache } from './models';
7
10
  /**
8
11
  * Main entry point for the QAECY SDK (browser-safe).
9
12
  * For Node.js use with file-sync capabilities, use `CueNode` from `js-cue-sdk/node`.
@@ -16,13 +19,50 @@ import { CueEndpoints, CueSdkConfig } from './models';
16
19
  export declare class Cue {
17
20
  readonly auth: CueAuth;
18
21
  readonly api: CueApi;
22
+ readonly projects: CueProjects;
19
23
  readonly profile: CueProfile;
24
+ readonly privileges: CuePrivileges;
25
+ readonly cache: CueCache;
20
26
  protected readonly _app: FirebaseApp;
21
27
  protected readonly _endpoints: CueEndpoints;
22
28
  protected readonly _isEmulator: boolean;
23
- constructor(config: CueSdkConfig);
29
+ constructor(config?: CueSdkConfig);
30
+ /**
31
+ * Create a `Cue` instance from an already-initialized Firebase app.
32
+ *
33
+ * Use this when the host application (e.g. cue-portal via `CueFirebase`) has
34
+ * already called `initializeApp()`. Reusing the same `FirebaseApp` means the
35
+ * SDK shares the same auth state and Firestore instance — no second login is
36
+ * needed and `getToken()` returns the portal user's token directly.
37
+ *
38
+ * Emulator connections are skipped because the host app already set them up.
39
+ *
40
+ * @example
41
+ * // In an Angular service after CueFirebase is ready:
42
+ * const cue = Cue.fromApp(CueFirebase.getInstance().app!, {
43
+ * environment: 'emulator',
44
+ * });
45
+ */
46
+ static fromApp(app: FirebaseApp, config?: Omit<CueSdkConfig, 'apiKey' | 'appId' | 'measurementId'>): Cue;
24
47
  /** Override in subclasses to provide a custom CueApi (e.g. with sync). */
25
48
  protected _buildApi(projects: CueProjects): CueApi;
26
49
  /** Convenience: get the current user's Firebase ID token */
27
50
  getToken(forceRefresh?: boolean): Promise<string | null>;
51
+ /**
52
+ * Create a `CueProjectView` for the given project, wiring the SDK's query
53
+ * cache automatically.
54
+ *
55
+ * The view auto-fetches the document overview and entity graph on construction
56
+ * and exposes reactive signals for all project knowledge-graph state.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const view = cue.createProjectView('my-project', { language: 'en' });
61
+ * view.requestEntityData(['uuid1']);
62
+ * const info = view.entityInfoMap.get()['uuid1'];
63
+ * ```
64
+ */
65
+ createProjectView(projectId: string, opts: Omit<CueProjectViewOptions, 'queryCache'> & {
66
+ queryCache?: QueryCache;
67
+ }): CueProjectView;
28
68
  }
@@ -0,0 +1,84 @@
1
+ import { CueApi } from './api';
2
+ import { ReadonlySignal } from './signal';
3
+ import { DocumentInfo, ProjectDocumentsData, QueryCache } from './models';
4
+ /**
5
+ * Manages document data for a single project.
6
+ *
7
+ * ### Data model
8
+ * - **`documentInfoMap`** — lazily populated per-document detail signal.
9
+ * Call `requestDocumentData(uuids)` to load entries; already-cached UUIDs
10
+ * are skipped. Data is merged incrementally.
11
+ * - **`projectDocumentsData`** — project-level overview (documents grouped by
12
+ * suffix and content category, plus duplicate count). Auto-fetched on
13
+ * construction via three parallel SPARQL queries that resolve as a single
14
+ * atomic update.
15
+ *
16
+ * ### Language
17
+ * `subject` and `summary` fields on documents are language-tagged in the
18
+ * triplestore. Pass the active language to `requestDocumentData()` and call
19
+ * `setLanguage()` when it changes (which clears and re-fetches the info map
20
+ * so labels re-resolve in the new language).
21
+ *
22
+ * ### Lifecycle
23
+ * Call `reset()` when the project changes. The Angular adapter's project-change
24
+ * effect should call this, followed by `fetchOverview()` once the triplestore
25
+ * is ready.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const docs = new CueProjectDocuments(cue.api, projectId, 'en');
30
+ * await docs.fetchOverview();
31
+ * docs.requestDocumentData(['uuid1', 'uuid2']);
32
+ * const info = docs.documentInfoMap.get()['uuid1'];
33
+ * ```
34
+ */
35
+ export declare class CueProjectDocuments {
36
+ private readonly _api;
37
+ private readonly _projectId;
38
+ private readonly _queryCache?;
39
+ private readonly _graphType?;
40
+ /** Full RDF base URL for this project, e.g. `https://cue.qaecy.com/r/{pid}/` */
41
+ readonly baseURL: string;
42
+ private _language;
43
+ private readonly _documentInfoMap;
44
+ private readonly _projectDocumentsData;
45
+ /** Lazily populated per-document detail map. */
46
+ readonly documentInfoMap: ReadonlySignal<Record<string, DocumentInfo>>;
47
+ /** Project-level document overview (grouped counts + sizes). */
48
+ readonly projectDocumentsData: ReadonlySignal<ProjectDocumentsData>;
49
+ constructor(_api: CueApi, _projectId: string, language: string,
50
+ /** Override the RDF resource base URL. Defaults to `https://cue.qaecy.com/r/`. */
51
+ rdfBase?: string, _queryCache?: QueryCache | undefined, _graphType?: string | undefined);
52
+ /**
53
+ * Resets all document state. Call when the active project changes.
54
+ * Follow with `fetchOverview()` once the triplestore is ready.
55
+ */
56
+ reset(): void;
57
+ /**
58
+ * Updates the active language and clears the document info map so that
59
+ * language-sensitive fields (subject, summary) are re-fetched on the next
60
+ * `requestDocumentData()` call.
61
+ */
62
+ setLanguage(lang: string): void;
63
+ /**
64
+ * Fetches the three-part project overview (by suffix, by content category,
65
+ * duplicate count) in parallel and writes them as a single atomic update to
66
+ * `projectDocumentsData`. Safe to call again to refresh.
67
+ */
68
+ fetchOverview(): Promise<void>;
69
+ /**
70
+ * Lazily batch-fetches core metadata for the given document UUIDs.
71
+ * Already-cached UUIDs are skipped. Data is merged into `documentInfoMap`
72
+ * once the SPARQL response arrives.
73
+ */
74
+ requestDocumentData(uuids: string[]): void;
75
+ private _fetchDocumentsBySuffix;
76
+ private _buildDocumentsBySuffixQuery;
77
+ private _runDocumentsBySuffixQuery;
78
+ private _fetchDocumentsByContentCategory;
79
+ private _buildDocumentsByContentCategoryQuery;
80
+ private _runDocumentsByContentCategoryQuery;
81
+ private _fetchDuplicateCount;
82
+ private _buildDuplicateCountQuery;
83
+ private _runDuplicateCountQuery;
84
+ }
@@ -0,0 +1,107 @@
1
+ import { CueApi } from './api';
2
+ import { ReadonlySignal } from './signal';
3
+ import { EntityDetailedData, EntityRelationships, ProjectEntitiesData, QueryCache } from './models';
4
+ /**
5
+ * Manages entity data for a single project.
6
+ *
7
+ * ### Data model
8
+ * - **`entityInfoMap`** — merged per-entity signal. Recomputes reactively as
9
+ * any of the five underlying slices (core data, documents, relationships,
10
+ * OSM map, OSM WKT) change.
11
+ * - **`entityGraph`** — project-level category-to-category relationship graph,
12
+ * fetched once on construction.
13
+ *
14
+ * ### Lazy loading
15
+ * All public `request*` / `fetch*` methods are no-ops for UUIDs / IRIs already
16
+ * in the cache. Only the delta is fetched. Data is merged into the
17
+ * `entityInfoMap` signal incrementally — callers just react to the signal.
18
+ *
19
+ * ### Language
20
+ * Entity labels (`qcy:value`) are not language-tagged in the triplestore, so
21
+ * entity data itself is language-independent. The `language` parameter is
22
+ * carried here for future-proofing and forwards to the schema-level queries
23
+ * where language filtering does apply.
24
+ *
25
+ * ### Lifecycle
26
+ * Call `reset()` when the project changes. The Angular adapter calls this from
27
+ * the effect that watches `projectId`.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const entities = new CueProjectEntities(cue.api, projectId);
32
+ * entities.requestEntityData(['uuid1', 'uuid2']);
33
+ * const info = entities.entityInfoMap.get()['uuid1'];
34
+ * ```
35
+ */
36
+ export declare class CueProjectEntities {
37
+ private readonly _api;
38
+ private readonly _projectId;
39
+ private readonly _queryCache?;
40
+ private readonly _graphType?;
41
+ /** Full RDF base URL for this project, e.g. `https://cue.qaecy.com/r/{pid}/` */
42
+ readonly baseURL: string;
43
+ private readonly _entityDetails;
44
+ private readonly _entityDocuments;
45
+ private readonly _entityRelationships;
46
+ private readonly _entityOSMMap;
47
+ private readonly _osmWKTMap;
48
+ private readonly _fetchingOSMIds;
49
+ private readonly _entityGraph;
50
+ private readonly _entityInfoMapComputed;
51
+ /** Merged per-entity detail map. Updated reactively as data arrives. */
52
+ readonly entityInfoMap: ReadonlySignal<Record<string, EntityDetailedData>>;
53
+ /** Project-level category graph (fetched once per project). */
54
+ readonly entityGraph: ReadonlySignal<ProjectEntitiesData | undefined>;
55
+ constructor(_api: CueApi, _projectId: string,
56
+ /** Override the RDF resource base URL. Defaults to `https://cue.qaecy.com/r/`. */
57
+ rdfBase?: string, _queryCache?: QueryCache | undefined, _graphType?: string | undefined);
58
+ /**
59
+ * Constructs the full RDF IRI for the given entity UUID.
60
+ * Use this to bridge the UUID-based batch APIs and the IRI-based per-entity APIs.
61
+ */
62
+ entityIri(uuid: string): string;
63
+ /**
64
+ * Resets all entity state and re-fetches the entity graph.
65
+ * Call when the active project changes.
66
+ */
67
+ reset(): void;
68
+ /**
69
+ * Lazily batch-fetches core data (label + categories) for the given entity
70
+ * UUIDs. Already-fetched UUIDs are skipped.
71
+ *
72
+ * Data is merged into `entityInfoMap` once the SPARQL response arrives.
73
+ */
74
+ requestEntityData(uuids: string[], includeMentionCount?: boolean): void;
75
+ /**
76
+ * Lazily fetches OSM location data for the given entity UUIDs.
77
+ * Already-fetched UUIDs are skipped.
78
+ *
79
+ * OSM WKT geometry is fetched in a second pass via a federated SPARQL SERVICE
80
+ * query and merged into `entityInfoMap` reactively once it arrives.
81
+ */
82
+ requestEntityLocations(uuids: string[]): Promise<void>;
83
+ /**
84
+ * Fetches incoming and outgoing relationships for a single entity IRI.
85
+ * Neighbouring entity core data is opportunistically populated into
86
+ * `entityInfoMap` as a side-effect.
87
+ *
88
+ * The result is stored in `entityInfoMap[uuid].relationshipData` and also
89
+ * returned directly for callers that need an immediate value.
90
+ */
91
+ fetchEntityRelationships(iri: string): Promise<EntityRelationships>;
92
+ /**
93
+ * Fetches UUIDs of documents that reference the given entity IRI.
94
+ * Also triggers a core-data fetch for the entity itself if not yet loaded.
95
+ *
96
+ * Returns document UUIDs. Full document data will be populated by the
97
+ * document service (future `CueProjectDocuments`).
98
+ */
99
+ fetchEntityDocuments(iri: string): Promise<string[]>;
100
+ private _computeEntityInfoMap;
101
+ private _fetchOutgoingRelationships;
102
+ private _fetchIncomingRelationships;
103
+ private _fetchEntityGraph;
104
+ /** Detects new OSM IRIs in the OSM map that don't yet have WKT and fetches them. */
105
+ private _checkPendingOSMFetches;
106
+ private _fetchOSMLocations;
107
+ }