@abraca/dabra 0.1.2 → 0.1.3
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/dist/index.d.ts
CHANGED
|
@@ -132,8 +132,129 @@ declare class EventEmitter {
|
|
|
132
132
|
removeAllListeners(): void;
|
|
133
133
|
}
|
|
134
134
|
//#endregion
|
|
135
|
+
//#region packages/provider/src/AbracadabraClient.d.ts
|
|
136
|
+
interface AbracadabraClientConfig {
|
|
137
|
+
/** Server base URL (http or https). WebSocket URL is derived automatically. */
|
|
138
|
+
url: string;
|
|
139
|
+
/** Initial JWT token. If omitted and persistAuth is true, loads from storage. */
|
|
140
|
+
token?: string;
|
|
141
|
+
/** Persist JWT to localStorage for stay-logged-in. Default: true in browser. */
|
|
142
|
+
persistAuth?: boolean;
|
|
143
|
+
/** localStorage key for token persistence. Default: "abracadabra:auth". */
|
|
144
|
+
storageKey?: string;
|
|
145
|
+
/** Custom fetch implementation (useful for Node.js or testing). */
|
|
146
|
+
fetch?: typeof globalThis.fetch;
|
|
147
|
+
}
|
|
148
|
+
declare class AbracadabraClient {
|
|
149
|
+
private _token;
|
|
150
|
+
private readonly baseUrl;
|
|
151
|
+
private readonly persistAuth;
|
|
152
|
+
private readonly storageKey;
|
|
153
|
+
private readonly _fetch;
|
|
154
|
+
constructor(config: AbracadabraClientConfig);
|
|
155
|
+
get token(): string | null;
|
|
156
|
+
set token(value: string | null);
|
|
157
|
+
get isAuthenticated(): boolean;
|
|
158
|
+
/** Derives ws:// or wss:// URL from the http(s) base URL. */
|
|
159
|
+
get wsUrl(): string;
|
|
160
|
+
/** Register a new user with password. */
|
|
161
|
+
register(opts: {
|
|
162
|
+
username: string;
|
|
163
|
+
password: string;
|
|
164
|
+
email?: string;
|
|
165
|
+
displayName?: string;
|
|
166
|
+
}): Promise<UserProfile>;
|
|
167
|
+
/**
|
|
168
|
+
* Register a new user with an Ed25519 public key (crypto auth).
|
|
169
|
+
* Username is optional — if omitted, a short identifier is derived from the key.
|
|
170
|
+
*/
|
|
171
|
+
registerWithKey(opts: {
|
|
172
|
+
publicKey: string;
|
|
173
|
+
username?: string;
|
|
174
|
+
deviceName?: string;
|
|
175
|
+
displayName?: string;
|
|
176
|
+
email?: string;
|
|
177
|
+
}): Promise<UserProfile>;
|
|
178
|
+
/** Login with username + password. Auto-persists returned token. */
|
|
179
|
+
login(opts: {
|
|
180
|
+
username: string;
|
|
181
|
+
password: string;
|
|
182
|
+
}): Promise<string>;
|
|
183
|
+
/** Request an Ed25519 crypto auth challenge for the given public key. */
|
|
184
|
+
challenge(publicKey: string): Promise<{
|
|
185
|
+
challenge: string;
|
|
186
|
+
expiresAt: number;
|
|
187
|
+
}>;
|
|
188
|
+
/** Verify an Ed25519 signature to complete crypto auth. Auto-persists token. */
|
|
189
|
+
verify(opts: {
|
|
190
|
+
publicKey: string;
|
|
191
|
+
signature: string;
|
|
192
|
+
challenge: string;
|
|
193
|
+
}): Promise<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Full crypto auth flow: challenge → sign → verify.
|
|
196
|
+
* Convenience method combining challenge() + external signing + verify().
|
|
197
|
+
*/
|
|
198
|
+
loginWithKey(publicKey: string, signChallenge: (challenge: string) => Promise<string>): Promise<string>;
|
|
199
|
+
/** Add a new Ed25519 public key to the current user (multi-device). */
|
|
200
|
+
addKey(opts: {
|
|
201
|
+
publicKey: string;
|
|
202
|
+
deviceName?: string;
|
|
203
|
+
}): Promise<void>;
|
|
204
|
+
/** List all registered public keys for the current user. */
|
|
205
|
+
listKeys(): Promise<PublicKeyInfo[]>;
|
|
206
|
+
/** Revoke a public key by its ID. */
|
|
207
|
+
revokeKey(keyId: string): Promise<void>;
|
|
208
|
+
/** Clear token from memory and storage. */
|
|
209
|
+
logout(): void;
|
|
210
|
+
/** Get the current user's profile. */
|
|
211
|
+
getMe(): Promise<UserProfile>;
|
|
212
|
+
/** Update the current user's display name. */
|
|
213
|
+
updateMe(opts: {
|
|
214
|
+
displayName?: string;
|
|
215
|
+
}): Promise<void>;
|
|
216
|
+
/** Create a new root document. Returns its metadata. */
|
|
217
|
+
createDoc(opts?: {
|
|
218
|
+
id?: string;
|
|
219
|
+
}): Promise<DocumentMeta>;
|
|
220
|
+
/** Get document metadata. */
|
|
221
|
+
getDoc(docId: string): Promise<DocumentMeta>;
|
|
222
|
+
/** Delete a document (requires Owner role). Cascades to children and uploads. */
|
|
223
|
+
deleteDoc(docId: string): Promise<void>;
|
|
224
|
+
/** List immediate child documents. */
|
|
225
|
+
listChildren(docId: string): Promise<string[]>;
|
|
226
|
+
/** Create a child document under a parent (requires write permission). */
|
|
227
|
+
createChild(docId: string, opts?: {
|
|
228
|
+
child_id?: string;
|
|
229
|
+
}): Promise<DocumentMeta>;
|
|
230
|
+
/** Grant or change a user's role on a document (requires Owner). */
|
|
231
|
+
setPermission(docId: string, opts: {
|
|
232
|
+
user_id: string;
|
|
233
|
+
role: "owner" | "editor" | "viewer" | "observer";
|
|
234
|
+
}): Promise<void>;
|
|
235
|
+
/** Revoke a user's permission on a document (requires Owner). */
|
|
236
|
+
removePermission(docId: string, opts: {
|
|
237
|
+
user_id: string;
|
|
238
|
+
}): Promise<void>;
|
|
239
|
+
/** Upload a file to a document (requires write permission). */
|
|
240
|
+
upload(docId: string, file: File | Blob, filename?: string): Promise<UploadMeta>;
|
|
241
|
+
/** List all uploads for a document. */
|
|
242
|
+
listUploads(docId: string): Promise<UploadInfo[]>;
|
|
243
|
+
/** Download an upload as a Blob. */
|
|
244
|
+
getUpload(docId: string, uploadId: string): Promise<Blob>;
|
|
245
|
+
/** Delete an upload (requires uploader or document Owner). */
|
|
246
|
+
deleteUpload(docId: string, uploadId: string): Promise<void>;
|
|
247
|
+
/** Health check — no auth required. */
|
|
248
|
+
health(): Promise<HealthStatus>;
|
|
249
|
+
private request;
|
|
250
|
+
private toError;
|
|
251
|
+
private loadPersistedToken;
|
|
252
|
+
private persistToken;
|
|
253
|
+
private clearPersistedToken;
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
135
256
|
//#region packages/provider/src/AbracadabraProvider.d.ts
|
|
136
|
-
interface AbracadabraProviderConfiguration extends HocuspocusProviderConfiguration {
|
|
257
|
+
interface AbracadabraProviderConfiguration extends Omit<HocuspocusProviderConfiguration, "url" | "websocketProvider"> {
|
|
137
258
|
/**
|
|
138
259
|
* Subdocument loading strategy.
|
|
139
260
|
* - "lazy" (default) – child providers are created only when explicitly requested.
|
|
@@ -159,6 +280,16 @@ interface AbracadabraProviderConfiguration extends HocuspocusProviderConfigurati
|
|
|
159
280
|
* Required when cryptoIdentity is set.
|
|
160
281
|
*/
|
|
161
282
|
signChallenge?: (challenge: string) => Promise<string>;
|
|
283
|
+
/**
|
|
284
|
+
* AbracadabraClient instance for REST API access.
|
|
285
|
+
* When provided, the provider automatically derives the WebSocket URL
|
|
286
|
+
* and token from the client (unless explicitly overridden).
|
|
287
|
+
*/
|
|
288
|
+
client?: AbracadabraClient;
|
|
289
|
+
/** WebSocket URL. Derived from client.wsUrl if client is provided. */
|
|
290
|
+
url?: string;
|
|
291
|
+
/** Shared WebSocket connection (use when multiplexing multiple root documents). */
|
|
292
|
+
websocketProvider?: HocuspocusProviderWebsocket;
|
|
162
293
|
}
|
|
163
294
|
/**
|
|
164
295
|
* AbracadabraProvider extends HocuspocusProvider with:
|
|
@@ -177,6 +308,7 @@ interface AbracadabraProviderConfiguration extends HocuspocusProviderConfigurati
|
|
|
177
308
|
*/
|
|
178
309
|
declare class AbracadabraProvider extends HocuspocusProvider {
|
|
179
310
|
effectiveRole: EffectiveRole;
|
|
311
|
+
private _client;
|
|
180
312
|
private offlineStore;
|
|
181
313
|
private childProviders;
|
|
182
314
|
private subdocLoading;
|
|
@@ -185,14 +317,20 @@ declare class AbracadabraProvider extends HocuspocusProvider {
|
|
|
185
317
|
constructor(configuration: AbracadabraProviderConfiguration);
|
|
186
318
|
authenticatedHandler(scope: string): void;
|
|
187
319
|
/**
|
|
188
|
-
* Override sendToken to send
|
|
189
|
-
* when cryptoIdentity is configured.
|
|
320
|
+
* Override sendToken to send a pubkey-only identity declaration instead of a
|
|
321
|
+
* JWT when cryptoIdentity is configured.
|
|
322
|
+
*
|
|
323
|
+
* The public key is the sole identifier in the crypto auth handshake.
|
|
324
|
+
* Username is decoupled from auth; it lives on the server as an immutable
|
|
325
|
+
* internal field and is never sent in the challenge-response frames.
|
|
190
326
|
*/
|
|
191
327
|
sendToken(): Promise<void>;
|
|
192
328
|
/** Handle an auth_challenge message from the server. */
|
|
193
329
|
private handleAuthChallenge;
|
|
194
330
|
private restorePermissionSnapshot;
|
|
195
331
|
get canWrite(): boolean;
|
|
332
|
+
/** The AbracadabraClient instance for REST API access, if configured. */
|
|
333
|
+
get client(): AbracadabraClient | null;
|
|
196
334
|
/**
|
|
197
335
|
* Called when a MSG_STATELESS frame arrives from the server.
|
|
198
336
|
* Abracadabra uses stateless frames to deliver subdoc confirmations
|
|
@@ -418,10 +556,15 @@ type StatesArray = {
|
|
|
418
556
|
[key: string | number]: any;
|
|
419
557
|
}[];
|
|
420
558
|
type EffectiveRole = "owner" | "editor" | "viewer" | null;
|
|
421
|
-
/**
|
|
559
|
+
/**
|
|
560
|
+
* Ed25519 identity for passwordless crypto auth.
|
|
561
|
+
*
|
|
562
|
+
* The public key is the sole identifier sent to the server during the
|
|
563
|
+
* challenge-response handshake. Username is decoupled from auth and is
|
|
564
|
+
* managed separately as a mutable display name (see PATCH /users/me).
|
|
565
|
+
*/
|
|
422
566
|
interface CryptoIdentity {
|
|
423
|
-
|
|
424
|
-
/** base64url-encoded Ed25519 public key (32 bytes) */
|
|
567
|
+
/** base64url-encoded Ed25519 public key (32 bytes). Primary auth identifier. */
|
|
425
568
|
publicKey: string;
|
|
426
569
|
}
|
|
427
570
|
interface SubdocRegisteredEvent {
|
|
@@ -436,6 +579,38 @@ type onSubdocLoadedParameters = {
|
|
|
436
579
|
interface AbracadabraOutgoingMessageArguments extends OutgoingMessageArguments {
|
|
437
580
|
childDocumentName: string;
|
|
438
581
|
}
|
|
582
|
+
interface UserProfile {
|
|
583
|
+
id: string;
|
|
584
|
+
username: string;
|
|
585
|
+
email: string | null;
|
|
586
|
+
displayName: string | null;
|
|
587
|
+
}
|
|
588
|
+
interface DocumentMeta {
|
|
589
|
+
id: string;
|
|
590
|
+
parent_id: string | null;
|
|
591
|
+
}
|
|
592
|
+
interface UploadMeta {
|
|
593
|
+
id: string;
|
|
594
|
+
doc_id: string;
|
|
595
|
+
filename: string;
|
|
596
|
+
}
|
|
597
|
+
interface UploadInfo {
|
|
598
|
+
id: string;
|
|
599
|
+
filename: string;
|
|
600
|
+
mime_type: string;
|
|
601
|
+
size: number;
|
|
602
|
+
}
|
|
603
|
+
interface PublicKeyInfo {
|
|
604
|
+
id: string;
|
|
605
|
+
publicKey: string;
|
|
606
|
+
deviceName: string | null;
|
|
607
|
+
revoked: boolean;
|
|
608
|
+
}
|
|
609
|
+
interface HealthStatus {
|
|
610
|
+
status: string;
|
|
611
|
+
version: string;
|
|
612
|
+
active_documents: number;
|
|
613
|
+
}
|
|
439
614
|
//#endregion
|
|
440
615
|
//#region packages/provider/src/HocuspocusProviderWebsocket.d.ts
|
|
441
616
|
type HocuspocusWebSocket = WebSocket & {
|
|
@@ -768,7 +943,13 @@ declare class CryptoIdentityKeystore {
|
|
|
768
943
|
sign(challengeB64: string): Promise<string>;
|
|
769
944
|
/** Returns the stored base64url public key, or null if no identity exists. */
|
|
770
945
|
getPublicKey(): Promise<string | null>;
|
|
771
|
-
/**
|
|
946
|
+
/**
|
|
947
|
+
* Returns the locally-stored internal username label, or null if no identity exists.
|
|
948
|
+
*
|
|
949
|
+
* This is NOT the auth identifier (the public key is). It can be used as a
|
|
950
|
+
* hint when calling POST /auth/register, or displayed before the user sets
|
|
951
|
+
* a real display name via PATCH /users/me.
|
|
952
|
+
*/
|
|
772
953
|
getUsername(): Promise<string | null>;
|
|
773
954
|
/** Returns true if an identity is stored in IndexedDB. */
|
|
774
955
|
hasIdentity(): Promise<boolean>;
|
|
@@ -776,4 +957,4 @@ declare class CryptoIdentityKeystore {
|
|
|
776
957
|
clear(): Promise<void>;
|
|
777
958
|
}
|
|
778
959
|
//#endregion
|
|
779
|
-
export { AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AuthorizedScope, AwarenessError, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, Constructable, ConstructableOutgoingMessage, CryptoIdentity, CryptoIdentityKeystore, EffectiveRole, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, MessageType, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PendingSubdoc, StatesArray, SubdocMessage, SubdocRegisteredEvent, WebSocketStatus, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters };
|
|
960
|
+
export { AbracadabraClient, AbracadabraClientConfig, AbracadabraOutgoingMessageArguments, AbracadabraProvider, AbracadabraProviderConfiguration, AuthorizedScope, AwarenessError, CompleteHocuspocusProviderConfiguration, CompleteHocuspocusProviderWebsocketConfiguration, Constructable, ConstructableOutgoingMessage, CryptoIdentity, CryptoIdentityKeystore, DocumentMeta, EffectiveRole, HealthStatus, HocusPocusWebSocket, HocuspocusProvider, HocuspocusProviderConfiguration, HocuspocusProviderWebsocket, HocuspocusProviderWebsocketConfiguration, HocuspocusWebSocket, MessageType, OfflineStore, OutgoingMessageArguments, OutgoingMessageInterface, PendingSubdoc, PublicKeyInfo, StatesArray, SubdocMessage, SubdocRegisteredEvent, UploadInfo, UploadMeta, UserProfile, WebSocketStatus, onAuthenticatedParameters, onAuthenticationFailedParameters, onAwarenessChangeParameters, onAwarenessUpdateParameters, onCloseParameters, onDisconnectParameters, onMessageParameters, onOpenParameters, onOutgoingMessageParameters, onStatelessParameters, onStatusParameters, onSubdocLoadedParameters, onSubdocRegisteredParameters, onSyncedParameters, onUnsyncedChangesParameters };
|