@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/assets/wasm/dir_scanner_wasm.mjs +461 -0
- package/assets/wasm/dir_scanner_wasm_bg.wasm +0 -0
- package/document-filter-Dr_-QbaZ.js +10187 -0
- package/index.d.ts +14 -3
- package/index.js +33 -24
- package/lib/api.d.ts +79 -0
- package/lib/app-data.d.ts +21 -0
- package/lib/apps.d.ts +24 -0
- package/lib/auth.d.ts +77 -0
- package/lib/cache.d.ts +26 -0
- package/lib/contexts.d.ts +17 -0
- package/lib/cue-node.d.ts +19 -0
- package/lib/cue.d.ts +129 -0
- package/lib/currency.d.ts +34 -0
- package/lib/document-filter.d.ts +76 -0
- package/lib/documents.d.ts +223 -0
- package/lib/entities.d.ts +211 -0
- package/lib/extraction.d.ts +48 -0
- package/lib/gis.d.ts +89 -0
- package/lib/index-api.d.ts +39 -0
- package/lib/mcp.d.ts +61 -0
- package/lib/models.d.ts +662 -0
- package/lib/privileges.d.ts +76 -0
- package/lib/processing.d.ts +25 -0
- package/lib/profile.d.ts +128 -0
- package/lib/project-view.d.ts +112 -0
- package/lib/project.d.ts +56 -0
- package/lib/schema.d.ts +84 -0
- package/lib/signal.d.ts +38 -0
- package/lib/signup.d.ts +73 -0
- package/lib/storage.d.ts +52 -0
- package/lib/sync.d.ts +153 -0
- package/lib/tables.d.ts +14 -0
- package/lib/user-settings.d.ts +22 -0
- package/node.js +33 -24
- package/package.json +5 -6
- package/variables.d.ts +71 -0
- package/browser.js +0 -37970
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ReadonlySignal } from './signal';
|
|
2
|
+
/** Roles ordered from highest to lowest privilege. */
|
|
3
|
+
declare const ROLE_HIERARCHY: readonly ["superadmin", "admin", "syncer", "member"];
|
|
4
|
+
export type UserProjectRole = (typeof ROLE_HIERARCHY)[number];
|
|
5
|
+
/** Role a user can have within an organization. */
|
|
6
|
+
export type UserOrgRole = 'admin' | 'member';
|
|
7
|
+
export interface Privileges {
|
|
8
|
+
changeContentCategories: boolean;
|
|
9
|
+
createEntities: boolean;
|
|
10
|
+
createProject: boolean;
|
|
11
|
+
createProvider: boolean;
|
|
12
|
+
deleteDocuments: boolean;
|
|
13
|
+
deleteProject: boolean;
|
|
14
|
+
deleteUserFromProject: boolean;
|
|
15
|
+
downloadDocuments: boolean;
|
|
16
|
+
editContentCategories: boolean;
|
|
17
|
+
editPublicReposAvailableToAgent: boolean;
|
|
18
|
+
editTier: boolean;
|
|
19
|
+
inviteUserToProject: boolean;
|
|
20
|
+
rebuildIndex: boolean;
|
|
21
|
+
refreshStats: boolean;
|
|
22
|
+
renameDocuments: boolean;
|
|
23
|
+
uploadDocuments: boolean;
|
|
24
|
+
viewAdvancedStats: boolean;
|
|
25
|
+
viewCredits: boolean;
|
|
26
|
+
viewEntities: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Minimum project role required for each privilege.
|
|
30
|
+
* Note: `createProject` is intentionally absent — it is gated by the
|
|
31
|
+
* user's organisation role, not their project role.
|
|
32
|
+
*/
|
|
33
|
+
export declare const REQUIRED_ROLES: Record<Exclude<keyof Privileges, 'createProject'>, UserProjectRole>;
|
|
34
|
+
/**
|
|
35
|
+
* Manages role-based access control for the current user + selected project.
|
|
36
|
+
*
|
|
37
|
+
* - Call `setProjectRoles()` whenever the selected project changes.
|
|
38
|
+
* - Call `setOrgRole()` whenever the selected project's organisation changes.
|
|
39
|
+
* - Read `privileges` (a `ReadonlySignal<Privileges>`) for reactive access.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* cue.privileges.setProjectRoles(['admin']);
|
|
43
|
+
* cue.privileges.setOrgRole('admin');
|
|
44
|
+
* const canUpload = cue.privileges.privileges.get().uploadDocuments; // true
|
|
45
|
+
* const canCreate = cue.privileges.privileges.get().createProject; // true
|
|
46
|
+
*/
|
|
47
|
+
export declare class CuePrivileges {
|
|
48
|
+
private readonly _isSuperAdmin;
|
|
49
|
+
private readonly _projectRoles;
|
|
50
|
+
private readonly _orgRole;
|
|
51
|
+
/**
|
|
52
|
+
* Reactive signal — current user's privileges for the selected project.
|
|
53
|
+
* Recomputes automatically when `setProjectRoles()` is called or when
|
|
54
|
+
* the `isSuperAdmin` signal changes.
|
|
55
|
+
*/
|
|
56
|
+
readonly privileges: ReadonlySignal<Privileges>;
|
|
57
|
+
constructor(_isSuperAdmin: ReadonlySignal<boolean>);
|
|
58
|
+
/**
|
|
59
|
+
* Set the user's role within the organisation that owns the selected project.
|
|
60
|
+
* Pass `null` to clear the organisation role (e.g. when deselecting a project).
|
|
61
|
+
*
|
|
62
|
+
* Only organisation admins (and superadmins) may create projects.
|
|
63
|
+
*/
|
|
64
|
+
setOrgRole(role: UserOrgRole | null): void;
|
|
65
|
+
/**
|
|
66
|
+
* Set the user's roles for the currently selected project.
|
|
67
|
+
*
|
|
68
|
+
* Roles are expanded along the hierarchy: `admin` automatically includes
|
|
69
|
+
* `syncer` and `member`; `syncer` includes `member`. Pass an empty array
|
|
70
|
+
* to reset to the lowest privilege level.
|
|
71
|
+
*/
|
|
72
|
+
setProjectRoles(roles: UserProjectRole[]): void;
|
|
73
|
+
private _expand;
|
|
74
|
+
private _compute;
|
|
75
|
+
}
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CueAuth } from './auth';
|
|
2
|
+
import { ReadonlySignal } from './signal';
|
|
3
|
+
import { ProcessingStatus } from './models';
|
|
4
|
+
export interface ProcessingStatusWatcher {
|
|
5
|
+
/** Live pipeline status for the watched project; `undefined` until the first message arrives. */
|
|
6
|
+
status: ReadonlySignal<ProcessingStatus | undefined>;
|
|
7
|
+
/** Stops the subscription and closes the underlying WebSocket. */
|
|
8
|
+
close(): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Live pipeline-progress status, pushed by the `accessors-data-views`
|
|
12
|
+
* processing-status WebSocket. Backs the upload modal and project-settings
|
|
13
|
+
* "processing" indicators in the portal.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CueProcessingApi {
|
|
16
|
+
private readonly _auth;
|
|
17
|
+
private readonly _gatewayUrl;
|
|
18
|
+
constructor(_auth: CueAuth, _gatewayUrl: string);
|
|
19
|
+
/**
|
|
20
|
+
* Opens a live subscription to a project's pipeline status. Reconnects
|
|
21
|
+
* automatically (with a fixed delay) if the connection drops, until `close()`
|
|
22
|
+
* is called.
|
|
23
|
+
*/
|
|
24
|
+
watchStatus(projectId: string): ProcessingStatusWatcher;
|
|
25
|
+
}
|
package/lib/profile.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { UserInfo } from 'firebase/auth';
|
|
2
|
+
import { FirebaseApp } from 'firebase/app';
|
|
3
|
+
import { APIKeyDoc, APIKeyInfo, OrgConsumptionReportDto, OrgCreditsDto, OrgMember, OrganizationData, ProfileSSOAccount } from './models';
|
|
4
|
+
import { CueAuth } from './auth';
|
|
5
|
+
import { ReadonlySignal } from './signal';
|
|
6
|
+
export declare class CueProfile {
|
|
7
|
+
private readonly _auth;
|
|
8
|
+
private readonly _gatewayUrl;
|
|
9
|
+
private readonly _functions;
|
|
10
|
+
private readonly _orgCredits;
|
|
11
|
+
/**
|
|
12
|
+
* Reactive view of the last-fetched org credit pool. Updated automatically
|
|
13
|
+
* by `getOrgCredits()` and by the sync layer after every `previewSync`/
|
|
14
|
+
* `sync`/`computeCredits` call, so consumers that bind to this signal see
|
|
15
|
+
* balance changes (e.g. after an upload) without polling or manually
|
|
16
|
+
* re-fetching. Angular consumers bridge via
|
|
17
|
+
* `effect(() => sig.set(cue.profile.orgCredits.get()))` + `.subscribe(...)`.
|
|
18
|
+
*/
|
|
19
|
+
readonly orgCredits: ReadonlySignal<OrgCreditsDto | undefined>;
|
|
20
|
+
constructor(_auth: CueAuth, app: FirebaseApp, useEmulator: boolean, _gatewayUrl: string);
|
|
21
|
+
private _url;
|
|
22
|
+
private _fetch;
|
|
23
|
+
/** Whether the current user has an active API key. */
|
|
24
|
+
hasAPIKey(): Promise<boolean>;
|
|
25
|
+
/** Returns the sign-in methods registered for the current user's email. */
|
|
26
|
+
getSignInMethods(): Promise<string[]>;
|
|
27
|
+
/** Builds a human-readable label from a Firebase UserInfo provider entry. */
|
|
28
|
+
buildProviderLabel(userInfo: UserInfo): string;
|
|
29
|
+
/** Returns SSO accounts linked to the current user (excludes password). */
|
|
30
|
+
getSSOAccounts(): ProfileSSOAccount[];
|
|
31
|
+
/** Links a Google or Microsoft provider to the current account via popup. Returns the new provider label. */
|
|
32
|
+
linkProvider(ssoProvider: string): Promise<string>;
|
|
33
|
+
/** Unlinks a provider from the current account. */
|
|
34
|
+
unlinkProvider(providerId: string): Promise<void>;
|
|
35
|
+
/** Changes the password. Reauthenticates first. */
|
|
36
|
+
updatePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
37
|
+
/** Adds (sets) a password for an account that currently only uses SSO. */
|
|
38
|
+
addPassword(password: string): Promise<void>;
|
|
39
|
+
/** Requests an e-mail change. Sends a verification e-mail to the new address. */
|
|
40
|
+
updateEmail(newEmail: string, password: string): Promise<void>;
|
|
41
|
+
/** Creates a new API key for the current user. */
|
|
42
|
+
createAPIKey(expiration: string): Promise<APIKeyDoc>;
|
|
43
|
+
/** Revokes the current user's API key. */
|
|
44
|
+
revokeAPIKey(): Promise<void>;
|
|
45
|
+
/** Fetches the current user's existing API key. */
|
|
46
|
+
requestAPIKey(): Promise<APIKeyInfo>;
|
|
47
|
+
/** Returns organizations the current user is a member of. */
|
|
48
|
+
listOrganizations(): Promise<(Pick<OrganizationData, 'id' | 'name'> & {
|
|
49
|
+
isAdmin: boolean;
|
|
50
|
+
})[]>;
|
|
51
|
+
/** Returns all members of the given organisation. Caller must be an org admin or superadmin. */
|
|
52
|
+
getOrgMembers(orgId: string): Promise<OrgMember[]>;
|
|
53
|
+
/** Adds a new member to the organisation. Caller must be an org admin or superadmin. */
|
|
54
|
+
addOrgMember(orgId: string, member: {
|
|
55
|
+
name: string;
|
|
56
|
+
email: string;
|
|
57
|
+
role: 'admin' | 'member';
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/** Changes an existing member's role within the organisation. Caller must be an org admin or superadmin. */
|
|
60
|
+
setOrgUserRole(orgId: string, userId: string, role: 'admin' | 'member'): Promise<void>;
|
|
61
|
+
/** Removes a member from the organisation, optionally also removing them from every project they belong to. Caller must be an org admin or superadmin. */
|
|
62
|
+
removeOrgMember(orgId: string, userId: string, removeFromProjects: boolean): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the organisation's shared credit pool: `purchased`, `consumed`
|
|
65
|
+
* (summed across every project the org owns), and `available`. Caller must
|
|
66
|
+
* be an org admin or superadmin.
|
|
67
|
+
*/
|
|
68
|
+
getOrgCredits(orgId: string): Promise<OrgCreditsDto>;
|
|
69
|
+
/**
|
|
70
|
+
* Per-project, per-month consumption breakdown for the org — for reporting/export, not
|
|
71
|
+
* the balance itself (use {@link getOrgCredits} for that). Caller must be an org admin
|
|
72
|
+
* or superadmin.
|
|
73
|
+
*/
|
|
74
|
+
getOrgConsumptionReport(orgId: string): Promise<OrgConsumptionReportDto>;
|
|
75
|
+
/** Manual/support credit grant to an organisation's shared pool. Superadmins only — org admins self-serve via `startOrgCheckout`. */
|
|
76
|
+
topUpOrgCredits(orgId: string, amount: number): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Starts a self-serve Stripe checkout for a one-time credit top-up.
|
|
79
|
+
* Returns the hosted checkout URL to redirect the user to; credits are
|
|
80
|
+
* granted by the backend webhook once payment completes.
|
|
81
|
+
*/
|
|
82
|
+
startOrgCheckout(orgId: string, credits: number): Promise<{
|
|
83
|
+
url: string;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Opens the Stripe Billing Portal for the organisation (update card, view
|
|
87
|
+
* invoices, cancel the plan). Returns the hosted portal URL. Caller must be
|
|
88
|
+
* an org admin; requires the org to have a Stripe customer.
|
|
89
|
+
*/
|
|
90
|
+
startOrgBillingPortal(orgId: string): Promise<{
|
|
91
|
+
url: string;
|
|
92
|
+
}>;
|
|
93
|
+
/**
|
|
94
|
+
* Change an organisation's plan — freemium → custom (first paid plan), or
|
|
95
|
+
* re-quote a plan that's still `pendingPayment`. Prices with the same
|
|
96
|
+
* canonical formula used at signup. Returns a checkout URL for the card
|
|
97
|
+
* flow (redirect the user there); omitted for the invoice flow or a
|
|
98
|
+
* freemium change, which apply immediately.
|
|
99
|
+
*
|
|
100
|
+
* Orgs with an *active* paid subscription must use
|
|
101
|
+
* {@link startOrgBillingPortal} instead — this throws if called on one.
|
|
102
|
+
*/
|
|
103
|
+
changeOrgPlan(orgId: string, plan: {
|
|
104
|
+
type: 'freemium' | 'custom';
|
|
105
|
+
monthlySpendChf?: number;
|
|
106
|
+
paymentMethod?: 'card' | 'invoice';
|
|
107
|
+
}): Promise<{
|
|
108
|
+
checkoutUrl?: string;
|
|
109
|
+
}>;
|
|
110
|
+
private _requireUser;
|
|
111
|
+
/**
|
|
112
|
+
* Fetch display name and email for a list of user UIDs.
|
|
113
|
+
* Uses the `getUserInfo` Firebase callable function.
|
|
114
|
+
*/
|
|
115
|
+
getUserInfo(uids: string[]): Promise<Record<string, {
|
|
116
|
+
name: string;
|
|
117
|
+
email: string;
|
|
118
|
+
}>>;
|
|
119
|
+
/** Record that the current user has accepted the terms of service. Sets a `terms` custom claim on the token. */
|
|
120
|
+
acceptTerms(version: string): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the terms version the current user has accepted (e.g. `"v1"`),
|
|
123
|
+
* or `null` if they have not accepted any version yet.
|
|
124
|
+
* Reads from the cached ID token — call after `acceptTerms()` with a
|
|
125
|
+
* force-refreshed token to see the updated value.
|
|
126
|
+
*/
|
|
127
|
+
latestTermsAccepted(): Promise<string | null>;
|
|
128
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { CueApi } from './api';
|
|
2
|
+
import { CueProjectSchema } from './schema';
|
|
3
|
+
import { CueProjectEntities } from './entities';
|
|
4
|
+
import { CueProjectDocuments } from './documents';
|
|
5
|
+
import { ReadonlySignal } from './signal';
|
|
6
|
+
import { SearchOptions, SearchResponse, CategoryDef, RelationshipDef, EntityDetailedData, EntityRelationships, ProjectEntitiesData, DocumentInfo, ProjectDocumentsData } from './models';
|
|
7
|
+
export interface CueProjectViewOptions {
|
|
8
|
+
language: string;
|
|
9
|
+
/** Override the RDF resource base URL. Defaults to `https://cue.qaecy.com/r/`. */
|
|
10
|
+
rdfBase?: string;
|
|
11
|
+
/** Graph engine type from projectSettings.graph.type (e.g. 'qlever' or 'fuseki'). */
|
|
12
|
+
graphType?: string;
|
|
13
|
+
/** Enable verbose debug logging for entity and document fetch stats. */
|
|
14
|
+
verbose?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Framework-agnostic facade over `CueProjectSchema`, `CueProjectEntities`, and
|
|
18
|
+
* `CueProjectDocuments`. Exposes a flat, ergonomic API for all knowledge-graph
|
|
19
|
+
* view state needed by the portal.
|
|
20
|
+
*
|
|
21
|
+
* Create via `cue.createProjectView()` rather than constructing directly.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const view = cue.createProjectView('my-project', { language: 'en' });
|
|
26
|
+
* view.entityInfoMap.subscribe(map => render(map));
|
|
27
|
+
* view.requestEntityData(['uuid1', 'uuid2']);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class CueProjectView {
|
|
31
|
+
private readonly _api;
|
|
32
|
+
private readonly _projectId;
|
|
33
|
+
/** Direct access to the schema data class (available categories / relationships). */
|
|
34
|
+
readonly schema: CueProjectSchema;
|
|
35
|
+
/** Direct access to the entity data class. */
|
|
36
|
+
readonly entities: CueProjectEntities;
|
|
37
|
+
/** Direct access to the document data class. */
|
|
38
|
+
readonly documents: CueProjectDocuments;
|
|
39
|
+
/** Available content category definitions for this project. Auto-fetched on init. */
|
|
40
|
+
readonly availableContentCategories: ReadonlySignal<CategoryDef[]>;
|
|
41
|
+
/** Available entity category definitions for this project. Auto-fetched on init. */
|
|
42
|
+
readonly availableEntityCategories: ReadonlySignal<CategoryDef[]>;
|
|
43
|
+
/** Available entity relationship types. Auto-fetched on init. */
|
|
44
|
+
readonly availableEntityRelationships: ReadonlySignal<RelationshipDef[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Resolves when the initial schema load has completed. Await before reading
|
|
47
|
+
* schema signal values imperatively.
|
|
48
|
+
*/
|
|
49
|
+
readonly schemaReady: Promise<void>;
|
|
50
|
+
/** Merged per-entity detail map. Populated lazily via `requestEntityData()` etc. */
|
|
51
|
+
readonly entityInfoMap: ReadonlySignal<Record<string, EntityDetailedData>>;
|
|
52
|
+
/** Project-level entity co-occurrence graph. Fetched once on init. */
|
|
53
|
+
readonly entityGraph: ReadonlySignal<ProjectEntitiesData | undefined>;
|
|
54
|
+
/** Per-document info map. Populated lazily via `requestDocumentData()`. */
|
|
55
|
+
readonly documentInfoMap: ReadonlySignal<Record<string, DocumentInfo>>;
|
|
56
|
+
/** Project document overview (counts by suffix and category). Fetched on init. */
|
|
57
|
+
readonly projectDocumentsData: ReadonlySignal<ProjectDocumentsData | undefined>;
|
|
58
|
+
private readonly _searchResults;
|
|
59
|
+
/** The result of the most recent `search()` call. `undefined` before first search. */
|
|
60
|
+
readonly searchResults: ReadonlySignal<SearchResponse | undefined>;
|
|
61
|
+
private _destroyed;
|
|
62
|
+
constructor(_api: CueApi, _projectId: string, { language, rdfBase, graphType, verbose }: CueProjectViewOptions);
|
|
63
|
+
/**
|
|
64
|
+
* Lazily batch-fetch core data (label + categories) for the given entity UUIDs.
|
|
65
|
+
* Already-fetched UUIDs are skipped. Populates `entityInfoMap`.
|
|
66
|
+
*/
|
|
67
|
+
requestEntityData(uuids: string[], includeMentionCount?: boolean): void;
|
|
68
|
+
/**
|
|
69
|
+
* Lazily fetch OSM location data for the given entity UUIDs.
|
|
70
|
+
* Already-fetched UUIDs are skipped. Populates `entityInfoMap` geometry fields.
|
|
71
|
+
*/
|
|
72
|
+
requestEntityLocations(uuids: string[]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Fetch incoming and outgoing relationships for a single entity IRI.
|
|
75
|
+
* Result is stored in `entityInfoMap[uuid].relationshipData`.
|
|
76
|
+
*/
|
|
77
|
+
fetchEntityRelationships(iri: string): Promise<EntityRelationships>;
|
|
78
|
+
/**
|
|
79
|
+
* Fetch UUIDs of documents that reference the given entity IRI.
|
|
80
|
+
* Result is stored in `entityInfoMap[uuid].documentRefs`.
|
|
81
|
+
*/
|
|
82
|
+
fetchEntityDocuments(iri: string): Promise<string[]>;
|
|
83
|
+
/** Constructs the full RDF IRI for an entity UUID. */
|
|
84
|
+
entityIri(uuid: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Lazily batch-fetch document info for the given UUIDs.
|
|
87
|
+
* Already-fetched UUIDs are skipped. Populates `documentInfoMap`.
|
|
88
|
+
*/
|
|
89
|
+
requestDocumentData(uuids: string[]): void;
|
|
90
|
+
/**
|
|
91
|
+
* Run a natural-language search against the project.
|
|
92
|
+
* The result is stored in `searchResults` and replaces any previous result.
|
|
93
|
+
*/
|
|
94
|
+
search(term: string, options?: SearchOptions): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Switch the active language for schema labels and document text fields.
|
|
97
|
+
* Schema responses are cached per language (instant if previously loaded).
|
|
98
|
+
* The document info map is cleared and lazily re-populated on next access.
|
|
99
|
+
*/
|
|
100
|
+
setLanguage(lang: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Reset all entity and document state and re-fetch the project overview.
|
|
103
|
+
* Prefer creating a fresh `CueProjectView` when switching projects.
|
|
104
|
+
* Use `reset()` only when the same project's data needs to be invalidated.
|
|
105
|
+
*/
|
|
106
|
+
reset(): void;
|
|
107
|
+
/**
|
|
108
|
+
* Tear down this view instance. Clears all reactive state and blocks further
|
|
109
|
+
* updates. Call from the Angular adapter's `ngOnDestroy` or equivalent.
|
|
110
|
+
*/
|
|
111
|
+
destroy(): void;
|
|
112
|
+
}
|
package/lib/project.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { FirebaseApp } from 'firebase/app';
|
|
2
|
+
import { CueAuth } from './auth';
|
|
3
|
+
import { CreateProjectOptions, CueEndpoints, ProjectData } from './models';
|
|
4
|
+
import { ReadonlySignal } from './signal';
|
|
5
|
+
type ProjectRole = 'admin' | 'syncer' | 'member';
|
|
6
|
+
export declare class CueProjects {
|
|
7
|
+
private readonly _auth;
|
|
8
|
+
private readonly _db;
|
|
9
|
+
private readonly _functions;
|
|
10
|
+
private readonly _gatewayUrl;
|
|
11
|
+
private readonly _projects;
|
|
12
|
+
/**
|
|
13
|
+
* Live cache of the current user's projects, refreshed on every `listProjects()`
|
|
14
|
+
* call and patched in place by `getProject()` — lets consumers reflect changes
|
|
15
|
+
* without every caller having to remember to re-fetch the whole list.
|
|
16
|
+
*/
|
|
17
|
+
readonly projects: ReadonlySignal<ProjectData[] | undefined>;
|
|
18
|
+
constructor(_auth: CueAuth, app: FirebaseApp, useEmulator?: boolean, endpoints?: CueEndpoints);
|
|
19
|
+
/**
|
|
20
|
+
* Create a new project. The authenticated user is automatically set as admin, syncer, and member.
|
|
21
|
+
* Throws if a project with the given ID already exists.
|
|
22
|
+
*/
|
|
23
|
+
createProject(options: CreateProjectOptions): Promise<ProjectData>;
|
|
24
|
+
/** List all projects where the authenticated user appears in the members array. */
|
|
25
|
+
listProjects(): Promise<ProjectData[]>;
|
|
26
|
+
/** Fetch a single project by ID. Returns null if not found or user lacks access. */
|
|
27
|
+
getProject(projectId: string): Promise<ProjectData | null>;
|
|
28
|
+
/**
|
|
29
|
+
* Merges a freshly-fetched project into the live `projects` signal, replacing
|
|
30
|
+
* the entry with matching `id`. Skipped if the signal hasn't been populated by
|
|
31
|
+
* `listProjects()` yet — patching into an unknown/partial list would make a
|
|
32
|
+
* single project look like the user's entire project set.
|
|
33
|
+
*/
|
|
34
|
+
private _patchProject;
|
|
35
|
+
/**
|
|
36
|
+
* Atomically increments `unitsConsumed` on the top-level `clientSync/{projectId}`
|
|
37
|
+
* document, creating it if it doesn't exist. Intended for pre-flight checks.
|
|
38
|
+
*/
|
|
39
|
+
incrementUnitsConsumed(projectId: string, units: number, userId: string): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Invite a user to a project by email. Returns the invited user's uid and display name.
|
|
42
|
+
*/
|
|
43
|
+
inviteUserToProject(email: string, projectId: string, role: ProjectRole): Promise<{
|
|
44
|
+
uid: string;
|
|
45
|
+
name?: string;
|
|
46
|
+
}>;
|
|
47
|
+
/** Change an existing member's role on a project. */
|
|
48
|
+
changeUserRoleOnProject(uid: string, projectId: string, role: ProjectRole): Promise<void>;
|
|
49
|
+
/** Remove a member from a project. */
|
|
50
|
+
removeUserFromProject(uid: string, projectId: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Delete a project by ID. Requires superadmin privileges on the server.
|
|
53
|
+
*/
|
|
54
|
+
deleteProject(projectId: string): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
package/lib/schema.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CueApi } from './api';
|
|
2
|
+
import { ReadonlySignal } from './signal';
|
|
3
|
+
import { CategoryDef, 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 _graphType?;
|
|
34
|
+
private _snapshot?;
|
|
35
|
+
private _inflight?;
|
|
36
|
+
private _currentLang;
|
|
37
|
+
private readonly _verbose;
|
|
38
|
+
private readonly _contentCategories;
|
|
39
|
+
private readonly _entityCategories;
|
|
40
|
+
private readonly _relationships;
|
|
41
|
+
/** Currently active content categories for the selected language. */
|
|
42
|
+
readonly availableContentCategories: ReadonlySignal<CategoryDef[]>;
|
|
43
|
+
/** Currently active entity categories for the selected language. */
|
|
44
|
+
readonly availableEntityCategories: ReadonlySignal<CategoryDef[]>;
|
|
45
|
+
/** Currently active entity relationship types for the selected language. */
|
|
46
|
+
readonly availableEntityRelationships: ReadonlySignal<RelationshipDef[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves when the initial schema load for the constructor language has
|
|
49
|
+
* completed (or failed). Await this before reading signal values imperatively.
|
|
50
|
+
*/
|
|
51
|
+
readonly ready: Promise<void>;
|
|
52
|
+
constructor(_api: CueApi, _projectId: string, language: string, _graphType?: string | undefined, verbose?: boolean);
|
|
53
|
+
/** Returns the currently active language. */
|
|
54
|
+
get language(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Switch the active language. Re-projects the already-fetched schema for the
|
|
57
|
+
* new language without re-querying; only triggers a fetch if nothing has been
|
|
58
|
+
* loaded yet.
|
|
59
|
+
*/
|
|
60
|
+
setLanguage(lang: string): void;
|
|
61
|
+
/**
|
|
62
|
+
* Force a re-fetch of the schema, bypassing the cache.
|
|
63
|
+
* Useful when the triplestore data has changed.
|
|
64
|
+
*/
|
|
65
|
+
refresh(): Promise<void>;
|
|
66
|
+
private _load;
|
|
67
|
+
/**
|
|
68
|
+
* Fetches the schema once. On QLever the pre-computed `schemas` materialized
|
|
69
|
+
* view is tried first; if it yields no rows we warn and fall back to the live
|
|
70
|
+
* schema query.
|
|
71
|
+
*/
|
|
72
|
+
private _fetchSnapshot;
|
|
73
|
+
private _apply;
|
|
74
|
+
/** Projects a language-independent {@link SchemaNode} into a {@link CategoryDef}. */
|
|
75
|
+
private _toDef;
|
|
76
|
+
/**
|
|
77
|
+
* Single query covering content categories, entity categories and entity
|
|
78
|
+
* relationship types. Labels/definitions are returned untouched (with their
|
|
79
|
+
* language tags) so they can be grouped into {@link LangMap}s client-side.
|
|
80
|
+
*/
|
|
81
|
+
private _buildSchemaQuery;
|
|
82
|
+
/** Runs a schema query and groups the flat rows into a {@link SchemaSnapshot}. */
|
|
83
|
+
private _runSchemaQuery;
|
|
84
|
+
}
|
package/lib/signal.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal framework-agnostic reactive primitives for the Cue SDK.
|
|
3
|
+
*
|
|
4
|
+
* No external dependencies. Angular consumers bridge to Angular signals via
|
|
5
|
+
* `effect(() => { angularSig.set(sdkSig.get()); sdkSig.subscribe(...) })`.
|
|
6
|
+
*/
|
|
7
|
+
/** A reactive value that can be read and subscribed to. */
|
|
8
|
+
export interface ReadonlySignal<T> {
|
|
9
|
+
/** Returns the current value. */
|
|
10
|
+
get(): T;
|
|
11
|
+
/**
|
|
12
|
+
* Register a listener that is called whenever the value changes.
|
|
13
|
+
* Returns an unsubscribe function.
|
|
14
|
+
*/
|
|
15
|
+
subscribe(listener: () => void): () => void;
|
|
16
|
+
}
|
|
17
|
+
/** A writable reactive state container. */
|
|
18
|
+
export declare class CueSignal<T> implements ReadonlySignal<T> {
|
|
19
|
+
private _value;
|
|
20
|
+
private _listeners;
|
|
21
|
+
constructor(initial: T);
|
|
22
|
+
get(): T;
|
|
23
|
+
set(value: T): void;
|
|
24
|
+
subscribe(listener: () => void): () => void;
|
|
25
|
+
/** Returns a read-only view of this signal. */
|
|
26
|
+
asReadonly(): ReadonlySignal<T>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates a derived read-only signal from one or more source signals.
|
|
30
|
+
* The compute function is evaluated lazily and cached until a dependency changes.
|
|
31
|
+
*
|
|
32
|
+
* @param deps Source signals to watch.
|
|
33
|
+
* @param compute Function that computes the derived value; must be pure.
|
|
34
|
+
* @returns A `ReadonlySignal` with a `destroy()` method to stop tracking deps.
|
|
35
|
+
*/
|
|
36
|
+
export declare function cueComputed<T>(deps: ReadonlySignal<unknown>[], compute: () => T): ReadonlySignal<T> & {
|
|
37
|
+
destroy(): void;
|
|
38
|
+
};
|
package/lib/signup.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown by unauthenticated sign-up requests. Carries the HTTP status
|
|
3
|
+
* and, when the backend provides one, a machine-readable `code`
|
|
4
|
+
* (e.g. 'emailExists' | 'domainClaimed' | 'domainBlocked').
|
|
5
|
+
*/
|
|
6
|
+
export declare class CueRequestError extends Error {
|
|
7
|
+
readonly status: number;
|
|
8
|
+
readonly code?: string | undefined;
|
|
9
|
+
constructor(message: string, status: number, code?: string | undefined);
|
|
10
|
+
}
|
|
11
|
+
export type OrgSignUpPlan = {
|
|
12
|
+
type: 'freemium';
|
|
13
|
+
} | {
|
|
14
|
+
type: 'custom';
|
|
15
|
+
monthlySpendChf: number;
|
|
16
|
+
paymentMethod?: 'card' | 'invoice';
|
|
17
|
+
};
|
|
18
|
+
export interface OrgSignUpPayload {
|
|
19
|
+
/** Display name of the new admin user. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** The organization domain is extracted from this address server-side. */
|
|
22
|
+
email: string;
|
|
23
|
+
orgName: string;
|
|
24
|
+
/** When provided, the account is created with this password and no
|
|
25
|
+
* password-reset email is sent — the admin can sign in immediately. */
|
|
26
|
+
password?: string;
|
|
27
|
+
/** Version of the terms accepted client-side — recorded immediately so the
|
|
28
|
+
* admin isn't asked again on their next sign-in. */
|
|
29
|
+
termsVersion?: string;
|
|
30
|
+
plan: OrgSignUpPlan;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Unauthenticated account-creation calls — create a Firebase user (and,
|
|
34
|
+
* for `signUpWithOrganization`, a new organisation) before any session
|
|
35
|
+
* exists. Kept separate from `CueAuth`, which manages an *existing* session
|
|
36
|
+
* (sign in/out, tokens, superadmin checks).
|
|
37
|
+
*/
|
|
38
|
+
export declare class CueSignUp {
|
|
39
|
+
private readonly _gatewayUrl;
|
|
40
|
+
constructor(_gatewayUrl: string);
|
|
41
|
+
/**
|
|
42
|
+
* Register a new user by name and email.
|
|
43
|
+
* The backend validates that the email domain belongs to an existing organisation,
|
|
44
|
+
* creates the Firebase Auth account, assigns org membership, and — when no
|
|
45
|
+
* `password` is given — dispatches a "set your password" email to the
|
|
46
|
+
* address provided. `termsVersion`, when given, is recorded as accepted
|
|
47
|
+
* immediately so the user isn't asked again on their next sign-in.
|
|
48
|
+
* Returns the new user's UID and the organisation name on success.
|
|
49
|
+
*/
|
|
50
|
+
signUp(name: string, email: string, password?: string, termsVersion?: string): Promise<{
|
|
51
|
+
uid: string;
|
|
52
|
+
orgName: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Self-service sign-up that creates a new organisation together with its
|
|
56
|
+
* first (admin) user — for users whose email domain matches no existing
|
|
57
|
+
* organisation. The backend records the selected plan, seeds the freemium
|
|
58
|
+
* credit grant, and dispatches verification + "set your password" emails.
|
|
59
|
+
* Throws `CueRequestError` with `code` 'emailExists' | 'domainClaimed' |
|
|
60
|
+
* 'domainBlocked' for the mappable failure modes.
|
|
61
|
+
*/
|
|
62
|
+
signUpWithOrganization(payload: OrgSignUpPayload): Promise<{
|
|
63
|
+
uid: string;
|
|
64
|
+
orgId: string;
|
|
65
|
+
orgName: string;
|
|
66
|
+
checkoutUrl?: string;
|
|
67
|
+
}>;
|
|
68
|
+
/** Re-send the verification + set-password emails after a sign-up. */
|
|
69
|
+
resendSignUpEmails(email: string): Promise<{
|
|
70
|
+
sent: boolean;
|
|
71
|
+
}>;
|
|
72
|
+
private _publicPost;
|
|
73
|
+
}
|
package/lib/storage.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
}
|