@abraca/dabra 2.90.0 → 2.91.0

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.
Files changed (71) hide show
  1. package/package.json +5 -11
  2. package/src/AbracadabraBaseProvider.ts +0 -963
  3. package/src/AbracadabraClient.ts +0 -1960
  4. package/src/AbracadabraProvider.ts +0 -915
  5. package/src/AbracadabraWS.ts +0 -695
  6. package/src/BackgroundSyncManager.ts +0 -856
  7. package/src/BackgroundSyncPersistence.ts +0 -140
  8. package/src/ChatClient.ts +0 -314
  9. package/src/CloseEvents.ts +0 -49
  10. package/src/ContentManager.ts +0 -246
  11. package/src/CoverReconcile.ts +0 -168
  12. package/src/CryptoIdentityKeystore.ts +0 -754
  13. package/src/DeviceRegistrationService.ts +0 -257
  14. package/src/DocConverters.ts +0 -1859
  15. package/src/DocKeyManager.ts +0 -163
  16. package/src/DocTypes.ts +0 -628
  17. package/src/DocUtils.ts +0 -251
  18. package/src/DocumentCache.ts +0 -210
  19. package/src/DocumentManager.ts +0 -410
  20. package/src/E2EAbracadabraProvider.ts +0 -426
  21. package/src/E2EOfflineStore.ts +0 -55
  22. package/src/EncryptedChatClient.ts +0 -173
  23. package/src/EncryptedY.ts +0 -145
  24. package/src/EventEmitter.ts +0 -59
  25. package/src/FileBlobStore.ts +0 -569
  26. package/src/IdentityDoc.ts +0 -711
  27. package/src/IncomingMessage.ts +0 -63
  28. package/src/MessageReceiver.ts +0 -151
  29. package/src/MessageSender.ts +0 -22
  30. package/src/MetaManager.ts +0 -194
  31. package/src/MnemonicKeyDerivation.ts +0 -171
  32. package/src/NodeConnect.ts +0 -63
  33. package/src/NodeIdentity.ts +0 -378
  34. package/src/NotificationsClient.ts +0 -207
  35. package/src/OfflineStore.ts +0 -294
  36. package/src/OutgoingMessage.ts +0 -25
  37. package/src/OutgoingMessages/AuthenticationMessage.ts +0 -23
  38. package/src/OutgoingMessages/AwarenessMessage.ts +0 -41
  39. package/src/OutgoingMessages/CloseMessage.ts +0 -17
  40. package/src/OutgoingMessages/QueryAwarenessMessage.ts +0 -17
  41. package/src/OutgoingMessages/StatelessMessage.ts +0 -18
  42. package/src/OutgoingMessages/SubdocMessage.ts +0 -35
  43. package/src/OutgoingMessages/SyncStepOneMessage.ts +0 -25
  44. package/src/OutgoingMessages/SyncStepTwoMessage.ts +0 -25
  45. package/src/OutgoingMessages/UpdateMessage.ts +0 -20
  46. package/src/QueryClient.ts +0 -209
  47. package/src/RpcClient.ts +0 -659
  48. package/src/SchemaTypes.ts +0 -179
  49. package/src/SearchIndex.ts +0 -250
  50. package/src/ServerRegistry.ts +0 -220
  51. package/src/ServerReset.ts +0 -222
  52. package/src/TokenManager.ts +0 -337
  53. package/src/TreeManager.ts +0 -894
  54. package/src/TreeTimestamps.ts +0 -101
  55. package/src/auth.ts +0 -62
  56. package/src/awarenessStatesToArray.ts +0 -10
  57. package/src/index.ts +0 -219
  58. package/src/messageRecord.ts +0 -121
  59. package/src/sync/BroadcastChannelSync.ts +0 -235
  60. package/src/types.ts +0 -790
  61. package/src/webrtc/AbracadabraWebRTC.ts +0 -683
  62. package/src/webrtc/DataChannelRouter.ts +0 -179
  63. package/src/webrtc/DevicePairingChannel.ts +0 -496
  64. package/src/webrtc/E2EEChannel.ts +0 -195
  65. package/src/webrtc/FileTransferChannel.ts +0 -367
  66. package/src/webrtc/ManualSignaling.ts +0 -204
  67. package/src/webrtc/PeerConnection.ts +0 -133
  68. package/src/webrtc/SignalingSocket.ts +0 -378
  69. package/src/webrtc/YjsDataChannel.ts +0 -203
  70. package/src/webrtc/index.ts +0 -26
  71. package/src/webrtc/types.ts +0 -177
package/src/types.ts DELETED
@@ -1,790 +0,0 @@
1
- import type { Encoder } from "lib0/encoding";
2
- import type { Event, MessageEvent } from "ws";
3
- import type { Awareness } from "y-protocols/awareness";
4
- import type * as Y from "yjs";
5
- import type { CloseEvent } from "./CloseEvents.ts";
6
- import type { IncomingMessage } from "./IncomingMessage.ts";
7
- import type { OutgoingMessage } from "./OutgoingMessage.ts";
8
- import type { AuthenticationMessage } from "./OutgoingMessages/AuthenticationMessage.ts";
9
- import type { AwarenessMessage } from "./OutgoingMessages/AwarenessMessage.ts";
10
- import type { QueryAwarenessMessage } from "./OutgoingMessages/QueryAwarenessMessage.ts";
11
- import type { SyncStepOneMessage } from "./OutgoingMessages/SyncStepOneMessage.ts";
12
- import type { SyncStepTwoMessage } from "./OutgoingMessages/SyncStepTwoMessage.ts";
13
- import type { UpdateMessage } from "./OutgoingMessages/UpdateMessage.ts";
14
-
15
- /**
16
- * State of the WebSocket connection.
17
- * https://developer.mozilla.org/de/docs/Web/API/WebSocket/readyState
18
- */
19
- export enum WsReadyStates {
20
- Connecting = 0,
21
- Open = 1,
22
- Closing = 2,
23
- Closed = 3,
24
- }
25
-
26
- export enum MessageType {
27
- Sync = 0,
28
- Awareness = 1,
29
- Auth = 2,
30
- QueryAwareness = 3,
31
- Subdoc = 4,
32
- Stateless = 5,
33
- CLOSE = 7,
34
- SyncStatus = 8,
35
- }
36
-
37
- export enum WebSocketStatus {
38
- Connecting = "connecting",
39
- Connected = "connected",
40
- Disconnected = "disconnected",
41
- }
42
-
43
- export type AuthorizedScope = "service" | "admin" | "owner" | "editor" | "viewer" | "observer" | "read-write" | "readonly";
44
-
45
- export interface OutgoingMessageInterface {
46
- encoder: Encoder;
47
- type?: MessageType;
48
- }
49
-
50
- export interface OutgoingMessageArguments {
51
- documentName: string;
52
- token: string;
53
- document: Y.Doc;
54
- awareness: Awareness;
55
- clients: number[];
56
- states: Map<number, { [key: string]: any }>;
57
- update: any;
58
- payload: string;
59
- encoder: Encoder;
60
- }
61
-
62
- export interface Constructable<T> {
63
- new (...args: any): T;
64
- }
65
-
66
- export type ConstructableOutgoingMessage =
67
- | Constructable<AuthenticationMessage>
68
- | Constructable<AwarenessMessage>
69
- | Constructable<QueryAwarenessMessage>
70
- | Constructable<SyncStepOneMessage>
71
- | Constructable<SyncStepTwoMessage>
72
- | Constructable<UpdateMessage>;
73
-
74
- export type onAuthenticationFailedParameters = {
75
- reason: string;
76
- };
77
-
78
- /**
79
- * Why the server refused a local change.
80
- *
81
- * - `permission` — the resolved role on that document cannot write. The read
82
- * subscription stays alive; only the update was dropped.
83
- * - `validation` — the update was structurally accepted but rejected by a
84
- * server-side gate (schema validation, size/pattern guards). Deliberately
85
- * NOT an auth failure: the server sends `SyncStatus(applied=0)` rather than
86
- * a permission-denied frame so a transient data error can't bounce a legit
87
- * editor off sync.
88
- */
89
- export type WriteRejectionKind = "permission" | "validation";
90
-
91
- /**
92
- * Fired when the server tells us a local change was NOT applied.
93
- *
94
- * This event exists because the refusal was previously unobservable from
95
- * application code. The server has always nacked — `AUTH_PERMISSION_DENIED`
96
- * for a role that cannot write, `SyncStatus(applied=0)` for a rejected
97
- * update — but the SDK folded the first into a generic
98
- * `authenticationFailed` (which apps do not listen to, since on a shared
99
- * socket it usually is not one) and dropped the second on the floor entirely.
100
- * The write stayed in the unsynced buffer and the UI showed an edit that had
101
- * already been refused, so "it saved, then it wasn't there after reload"
102
- * became the standard bug report for viewer-role clients.
103
- *
104
- * The change is NOT lost when this fires: `unsyncedChanges` deliberately does
105
- * not decrement, so the update remains queued for retry after whatever caused
106
- * the rejection is fixed. Treat this as "surface it", not "discard it".
107
- */
108
- export type onWriteRejectedParameters = {
109
- /** Document name (id) whose update was refused. */
110
- documentName: string;
111
- /** Server-supplied reason where one exists, else a fixed description. */
112
- reason: string;
113
- kind: WriteRejectionKind;
114
- };
115
-
116
- export type onAuthenticatedParameters = {
117
- scope: AuthorizedScope;
118
- };
119
-
120
- export type onOpenParameters = {
121
- event: Event;
122
- };
123
-
124
- /**
125
- * Fired when a socket re-establishes after having previously been open at
126
- * least once on this provider — i.e. an actual reconnect, not the first
127
- * connect. Consumers use this to re-run a reconciliation pass (e.g. re-scan a
128
- * watched column) after a drop. The provider's Y.Doc is never replaced, so any
129
- * `observe`/`observeDeep` listeners are still attached and fire on their own as
130
- * the post-reconnect sync delivers updates — this event is a belt-and-braces
131
- * "we're live again" signal, not a requirement for observers to keep working.
132
- */
133
- export type onReconnectedParameters = {
134
- event: Event;
135
- };
136
-
137
- export type onMessageParameters = {
138
- event: MessageEvent;
139
- message: IncomingMessage;
140
- };
141
-
142
- export type onOutgoingMessageParameters = {
143
- message: OutgoingMessage;
144
- };
145
-
146
- export type onStatusParameters = {
147
- status: WebSocketStatus;
148
- };
149
-
150
- export type onSyncedParameters = {
151
- state: boolean;
152
- };
153
-
154
- export type onUnsyncedChangesParameters = {
155
- number: number;
156
- };
157
-
158
- export type onDisconnectParameters = {
159
- event: CloseEvent;
160
- };
161
-
162
- export type onCloseParameters = {
163
- event: CloseEvent;
164
- };
165
-
166
- export type onAwarenessUpdateParameters = {
167
- states: StatesArray;
168
- };
169
-
170
- export type onAwarenessChangeParameters = {
171
- states: StatesArray;
172
- };
173
-
174
- export type onStatelessParameters = {
175
- payload: string;
176
- };
177
-
178
- /** Fired by E2EAbracadabraProvider when the server acknowledges an E2E
179
- * client-side compaction (via the `snapshot:compacted` stateless broadcast). */
180
- export type onCompactedParameters = {
181
- docId: string;
182
- /** User id that performed the compaction; undefined if payload was malformed. */
183
- by: string | undefined;
184
- };
185
-
186
- export type onServerErrorParameters = {
187
- source: string;
188
- code: string;
189
- message: string;
190
- meta?: Record<string, unknown>;
191
- };
192
-
193
- export type StatesArray = { clientId: number; [key: string | number]: any }[];
194
-
195
- // ── Abracadabra extensions ────────────────────────────────────────────────────
196
-
197
- export type EffectiveRole = "service" | "admin" | "owner" | "editor" | "viewer" | "observer" | null;
198
-
199
- /**
200
- * Ed25519 identity for passwordless crypto auth.
201
- *
202
- * The public key is the sole identifier sent to the server during the
203
- * challenge-response handshake. Username is decoupled from auth and is
204
- * managed separately as a mutable display name (see PATCH /users/me).
205
- */
206
- export interface CryptoIdentity {
207
- /** base64url-encoded Ed25519 public key (32 bytes). Primary auth identifier. */
208
- publicKey: string;
209
- }
210
-
211
- export interface SubdocRegisteredEvent {
212
- childId: string;
213
- parentId: string;
214
- }
215
-
216
- export type onSubdocRegisteredParameters = SubdocRegisteredEvent;
217
-
218
- export type onSubdocLoadedParameters = {
219
- childId: string;
220
- provider: import("./AbracadabraProvider.ts").AbracadabraProvider;
221
- };
222
-
223
- export interface AbracadabraOutgoingMessageArguments extends OutgoingMessageArguments {
224
- childDocumentName: string;
225
- }
226
-
227
- // ── REST API response types ──────────────────────────────────────────────────
228
-
229
- export interface UserProfile {
230
- id: string;
231
- username: string;
232
- email: string | null;
233
- displayName: string | null;
234
- role: string;
235
- /** Account-level Ed25519 public key (base64url). Canonical user identity. */
236
- publicKey: string | null;
237
- /**
238
- * Whether the user has a password set. `false` for key-based soft
239
- * identities until they opt in via {@link AbracadabraClient.setPassword}.
240
- * Drives the UI's "Set password" vs "Change password" branching.
241
- */
242
- hasPassword?: boolean;
243
- }
244
-
245
- export interface DocumentMeta {
246
- id: string;
247
- parent_id: string | null;
248
- /**
249
- * Renderer hint — `"kanban"`, `"checklist"`, `"outline"`, `"graph"`,
250
- * `"sheet"`, `"mindmap"`, `"doc"`, etc. Drives the dashboard's choice of
251
- * Vue component for this doc. Orthogonal to {@link kind}.
252
- */
253
- doc_type?: string | null;
254
- label?: string | null;
255
- description?: string | null;
256
- public_access?: string | null;
257
- owner_id?: string | null;
258
- /**
259
- * Structural role hint — `"server"` for the reserved server-root doc,
260
- * `"space"` for top-level workspace containers, `null`/absent otherwise.
261
- * Distinct from {@link doc_type}: a Space (`kind: "space"`) can contain
262
- * many Kanban boards (each `doc_type: "kanban"`).
263
- */
264
- kind?: string | null;
265
- updated_at?: number | null;
266
- }
267
-
268
- /**
269
- * Well-known structural roles for the {@link DocumentMeta.kind} field. These
270
- * are conventions only — the server treats `kind` as an opaque string. Use
271
- * these constants instead of string literals to avoid typos.
272
- */
273
- export const Kind = {
274
- /** The reserved server root document. There is exactly one per server. */
275
- Server: "server",
276
- /** A top-level workspace container — what the dashboard calls a "Space". */
277
- Space: "space",
278
- /** A regular content page rendered by the editor. */
279
- Page: "page",
280
- /** A group chat container under a Space. */
281
- Channel: "channel",
282
- /** A direct-message container at the server root with two-member permissions. */
283
- Dm: "dm",
284
- /** A child of channel/dm holding the messages Y.Array. */
285
- ChannelPeriod: "channel-period",
286
- /** A per-user inbox doc holding inbox entries; child of server root. */
287
- Inbox: "inbox",
288
- } as const;
289
- export type Kind = typeof Kind[keyof typeof Kind];
290
-
291
- /**
292
- * Hardcoded UUID of the reserved server root document. Every doc in the tree
293
- * chains up to this row, so a permission grant on this doc cascades into
294
- * every descendant. Mirrors the constant in the Rust crate
295
- * (`crate::types::SERVER_ROOT_ID_STR`).
296
- */
297
- export const SERVER_ROOT_ID = "00000000-0000-0000-0000-000000000000";
298
-
299
- export interface UploadMeta {
300
- id: string;
301
- doc_id: string;
302
- filename: string;
303
- }
304
-
305
- export interface UploadInfo {
306
- id: string;
307
- filename: string;
308
- mime_type: string;
309
- size: number;
310
- /** Intrinsic pixel width of the image (captured server-side at upload).
311
- * Absent for non-images and older servers. */
312
- width?: number;
313
- /** Intrinsic pixel height of the image. */
314
- height?: number;
315
- /** True when the server can synthesise a thumbnail for this upload (a
316
- * supported raster image and the feature is enabled). Absent on older
317
- * servers — treat as `false`. */
318
- thumbnail?: boolean;
319
- }
320
-
321
- /** Query options for the on-demand thumbnail endpoint. `w`/`h` are the
322
- * bounding box (at least one required, each on the server's allowed_sizes);
323
- * `fit` defaults to `contain`, `format` to `auto`. */
324
- export interface ThumbnailOptions {
325
- w?: number;
326
- h?: number;
327
- fit?: "cover" | "contain" | "inside";
328
- format?: "auto" | "jpeg" | "png";
329
- /** JPEG quality 1–100. */
330
- q?: number;
331
- }
332
-
333
- /** Response of `POST /docs/:docId/uploads/:uploadId/stream-token` — a
334
- * short-lived grant that reads exactly one upload and travels in the query
335
- * string, so a `<video src>` can Range-seek it without an Authorization
336
- * header. `url` is server-relative. */
337
- export interface StreamTokenInfo {
338
- token: string;
339
- /** Lifetime in seconds, from the moment the server minted it. */
340
- expires_in: number;
341
- /** `/docs/<docId>/uploads/<uploadId>?token=…` */
342
- url: string;
343
- }
344
-
345
- export interface PublicKeyInfo {
346
- id: string;
347
- publicKey: string;
348
- deviceName: string | null;
349
- revoked: boolean;
350
- createdAt?: number | null;
351
- pairedBy?: string | null;
352
- pairedVia?: string | null;
353
- }
354
-
355
- export interface PermissionEntry {
356
- user_id: string;
357
- role: "service" | "admin" | "owner" | "editor" | "viewer" | "observer";
358
- username: string;
359
- display_name: string | null;
360
- }
361
-
362
- export interface EffectivePermissionEntry {
363
- user_id: string;
364
- role: "service" | "admin" | "owner" | "editor" | "viewer" | "observer";
365
- username: string;
366
- display_name: string | null;
367
- source: "direct" | "inherited";
368
- inherited_from_doc_id?: string;
369
- }
370
-
371
- export interface EffectivePermissionsResponse {
372
- permissions: EffectivePermissionEntry[];
373
- default_role: string;
374
- }
375
-
376
- // ── Snapshots ────────────────────────────────────────────────────────────────
377
-
378
- export interface SnapshotMeta {
379
- version: number;
380
- size_bytes: number;
381
- trigger: string;
382
- label?: string | null;
383
- created_by?: string | null;
384
- created_at: number;
385
- /** Number of uploads referenced by this snapshot's CRDT state.
386
- * Always 0 on servers older than the `snapshot_files` migration, or for
387
- * snapshots created before that migration ran (until the operator runs
388
- * `POST /admin/snapshots/backfill-refs`). */
389
- file_count?: number;
390
- /** Signed byte delta vs. the previous-version snapshot for this doc.
391
- * `null` for the first snapshot of a doc (or when the previous version
392
- * has been pruned). Lets the UI render `+12 KB` / `−3 KB`. */
393
- delta_bytes?: number | null;
394
- }
395
-
396
- export interface SnapshotFileEntry {
397
- id: string;
398
- doc_id: string;
399
- filename: string;
400
- mime_type?: string | null;
401
- size?: number | null;
402
- }
403
-
404
- export interface SnapshotData extends SnapshotMeta {
405
- data: string;
406
- /** Populated only when fetched with `?include=files`. Each entry is an
407
- * upload referenced by this snapshot's CRDT state. */
408
- files?: SnapshotFileEntry[];
409
- }
410
-
411
- export interface SnapshotCreateResult {
412
- version: number;
413
- size_bytes: number;
414
- label?: string | null;
415
- }
416
-
417
- export interface SnapshotRestoreResult {
418
- restored_from: number;
419
- diff_bytes: number;
420
- }
421
-
422
- export interface SnapshotForkResult {
423
- doc_id: string;
424
- forked_from: { doc_id: string; version: number };
425
- }
426
-
427
- export interface HealthStatus {
428
- status: string;
429
- version: string;
430
- active_documents: number;
431
- }
432
-
433
- export interface ServerInfo {
434
- /** Human-readable server name set by the operator. */
435
- name?: string;
436
- /**
437
- * Identity of this server's DATABASE, persisted beside it.
438
- *
439
- * Stable across restarts and upgrades; it changes only when the database is
440
- * replaced — a wipe, or a restore from backup. That makes it the one signal a
441
- * client can use to know its cached CRDT state belongs to a peer that no
442
- * longer exists, which a CRDT cannot work out for itself. See
443
- * {@link dropCachesIfServerReplaced}.
444
- */
445
- server_id?: string;
446
- /** Server version string. */
447
- version?: string;
448
- /** Hocuspocus wire protocol version (currently 2). */
449
- protocol_version?: number;
450
- /**
451
- * The reserved server root document id. Every doc in the tree chains up
452
- * to this row; granting Admin here cascades to every doc. Hardcoded by
453
- * the server — clients can also use {@link SERVER_ROOT_ID} directly.
454
- */
455
- root_doc_id?: string;
456
- /**
457
- * Server-wide access policy. Drives client-side decisions like "show the
458
- * sign-up CTA?" (anonymous mode) or "warn before publishing?" (anonymous
459
- * grants).
460
- */
461
- access?: {
462
- /** `"none"` rejects unauthenticated requests; `"observer"` allows public read. */
463
- anonymous?: "none" | "observer";
464
- /** Server-wide floor for authed users with no explicit grant. */
465
- authenticated?: "none" | "observer" | "viewer" | "editor";
466
- };
467
- /** Enabled auth methods (e.g. ["crypto", "jwt"]). */
468
- auth_methods?: string[];
469
- /** Whether open registration is enabled. */
470
- registration_allowed?: boolean;
471
- /** Whether an invite code is required to register. */
472
- invite_only?: boolean;
473
- /** Server encryption configuration. */
474
- encryption?: { default_mode?: string; minimum_mode?: string };
475
- /**
476
- * Ed25519 public key (base64url, no padding) the server uses to sign every
477
- * accepted `messages:*` record (`server_sig`). Clients can verify message
478
- * placement / ordering by checking each record's `server_sig` against this
479
- * key over the canonical `{ msg_id, period_id, ts, client_sig }` payload.
480
- */
481
- messages_signer_pubkey?: string;
482
- }
483
-
484
- // ── Search ───────────────────────────────────────────────────────────────────
485
-
486
- export interface SearchResult {
487
- docId: string;
488
- /** Number of matching trigrams — higher is better. */
489
- score: number;
490
- }
491
-
492
- /**
493
- * A single hit returned by the server's full-text search endpoint
494
- * (`GET /docs/search`). Distinct from {@link SearchResult}, which is the
495
- * client-side trigram index in `SearchIndex.ts`.
496
- *
497
- * `snippet` is server-rendered HTML with `<mark>` wrappers around the
498
- * matched tokens — safe to inject after standard sanitization. `rank` is
499
- * a backend-specific score (SQLite bm25 vs Postgres ts_rank); the only
500
- * guarantee is that hits arrive in best-first order.
501
- */
502
- /**
503
- * One inbound link, as returned by `GET /docs/:id/backlinks`.
504
- *
505
- * Deliberately thin: identity plus enough to render a row. Anything richer
506
- * (icon, breadcrumb, the sentence the link sits in) lives in the client's own
507
- * tree/index — the server index only knows the edge.
508
- */
509
- export interface DocBacklink {
510
- doc_id: string;
511
- label: string | null;
512
- /** Structural role tag (`space`/`page`/`channel`/…), when the doc has one. */
513
- kind: string | null;
514
- }
515
-
516
- export interface DocSearchHit {
517
- doc_id: string;
518
- parent_id: string | null;
519
- /**
520
- * Structural role tag (`space`/`page`/`channel`/…) — what the doc *is*,
521
- * not how it renders. See {@link doc_type} for the renderer/page type.
522
- */
523
- kind: string | null;
524
- label: string | null;
525
- /**
526
- * Renderer / page type (`kanban`/`graph`/`calendar`/…), surfaced by the
527
- * server from `documents.doc_type` or the CRDT-derived
528
- * `doc_meta_index.kind`. Use this as the renderer hint when opening a hit.
529
- * Absent from older servers and for plain docs.
530
- */
531
- doc_type?: string | null;
532
- /**
533
- * The top-level space (`kind: "space"`) that contains this hit, resolved
534
- * server-side by walking the CRDT tree. Lets a client jump straight to the
535
- * space without a client-side parent walk. Absent from older servers or
536
- * when no `kind="space"` ancestor was found.
537
- */
538
- space_id?: string | null;
539
- /** HTML-safe snippet with `<mark>` markers around the matched tokens. */
540
- snippet: string;
541
- rank: number;
542
- }
543
-
544
- // ── Audit log (admin) ────────────────────────────────────────────────────────
545
-
546
- /**
547
- * A single row from `GET /admin/audit`. Mirrors the server's audit log
548
- * row format (see `audit::AuditLogRow`). `metadata` is the parsed JSON
549
- * object the server stored, or `null` if the row had no metadata. Each
550
- * row carries an internal `prev_hash` / `row_hash` chain that admins
551
- * verify with {@link AuditVerifyResult}.
552
- */
553
- export interface AuditLogEntry {
554
- id: string;
555
- ts: number;
556
- event_type: string;
557
- actor_user_id: string | null;
558
- actor_ip: string | null;
559
- request_id: string | null;
560
- target_type: string | null;
561
- target_id: string | null;
562
- metadata: Record<string, unknown> | null;
563
- outcome: string;
564
- }
565
-
566
- /** Filters for `GET /admin/audit`. All optional and AND-combined. */
567
- export interface AuditQueryOpts {
568
- event_type?: string;
569
- actor_user_id?: string;
570
- target_type?: string;
571
- target_id?: string;
572
- since_ts?: number;
573
- until_ts?: number;
574
- limit?: number;
575
- offset?: number;
576
- }
577
-
578
- /** Response of `GET /admin/audit/verify`. `status: "broken"` carries `break`. */
579
- export interface AuditVerifyResult {
580
- status: "ok" | "broken";
581
- message?: string;
582
- break?: { rows_checked: number; row_id: string; reason: string };
583
- }
584
-
585
- // ── Admin: runtime config store ───────────────────────────────────────────────
586
-
587
- /**
588
- * Where the current value of a config field came from.
589
- *
590
- * * `default` — compiled-in default; nobody touched it.
591
- * * `env` — set at startup by an `ABRA_*` env var.
592
- * * `global_override` — admin runtime override via `/admin/config`.
593
- * * `route_override` — per-route override (Phase 3).
594
- */
595
- export type AdminConfigOriginKind =
596
- | "default"
597
- | "env"
598
- | "global_override"
599
- | "route_override";
600
-
601
- /** One entry returned by `GET /admin/config` and `GET /admin/config/fields/:path`. */
602
- export interface AdminConfigField {
603
- path: string;
604
- section: string;
605
- description: string;
606
- env_var: string;
607
- runtime_mutable: boolean;
608
- value: unknown;
609
- origin_kind: AdminConfigOriginKind;
610
- /** Provenance — present only when origin_kind is a `*_override`. */
611
- set_at?: number;
612
- set_by?: string;
613
- route?: string;
614
- }
615
-
616
- /**
617
- * One row from `GET /admin/config/env-snapshot.items[]`. Reports whether
618
- * each registry-known `ABRA_*` env var was set in the running process at
619
- * boot, with secrets reported as `value: null` and `redacted: true`.
620
- */
621
- export interface EnvSnapshotItem {
622
- env_var: string;
623
- path: string;
624
- section: string;
625
- present: boolean;
626
- /** Verbatim env value, or `null` for redacted (secrets) or unset. */
627
- value: string | null;
628
- redacted: boolean;
629
- }
630
-
631
- /**
632
- * One row from `GET /admin/config/env-snapshot.extensions[]`. Extension
633
- * overrides (`ABRA_EXT_<name>_<field>`) sit outside the registry and are
634
- * reported by name with values inline.
635
- */
636
- export interface EnvSnapshotExtension {
637
- env_var: string;
638
- value: string;
639
- }
640
-
641
- /**
642
- * `GET /admin/config/env-snapshot` response.
643
- *
644
- * `unknown` lists `ABRA_*` env vars present in the process that don't map
645
- * to any registered field — i.e. typos. Operators that see their tweak
646
- * land here instead of in `items` know they misspelled the var.
647
- */
648
- export interface EnvSnapshotResponse {
649
- items: EnvSnapshotItem[];
650
- extensions: EnvSnapshotExtension[];
651
- unknown: string[];
652
- }
653
-
654
- // ── Readiness ────────────────────────────────────────────────────────────────
655
-
656
- /** Response of `GET /readyz`. HTTP 200 when ready, 503 when not. */
657
- export interface ReadyzStatus {
658
- status: "ready" | "unready";
659
- version: string;
660
- checks: { database: "ok" | "error" };
661
- }
662
-
663
- // ── Spaces ───────────────────────────────────────────────────────────────────
664
- //
665
- // Spaces are documents whose `parent_id` is the server root and whose `kind`
666
- // is `"space"`. Listing them is `client.listSpaces()`; they come back as
667
- // regular `DocumentMeta` objects. Visibility is encoded in `public_access`:
668
- // `null` (or `"none"`) = private, `"observer"` = public read-only.
669
-
670
- // ── Invites ──────────────────────────────────────────────────────────────────
671
-
672
- export interface InviteRow {
673
- code: string;
674
- createdBy: string | null;
675
- role: string;
676
- maxUses: number;
677
- useCount: number;
678
- expiresAt: number | null;
679
- revoked: boolean;
680
- createdAt: number;
681
- }
682
-
683
- // ── Upload queue ─────────────────────────────────────────────────────────────
684
-
685
- export type UploadQueueStatus = "pending" | "uploading" | "done" | "error";
686
-
687
- export interface UploadQueueEntry {
688
- /** Client-generated UUID. */
689
- id: string;
690
- docId: string;
691
- /** File or Blob to upload. File extends Blob and survives IDB as Blob. */
692
- file: Blob;
693
- /** Eagerly captured filename (from File.name or explicit arg). */
694
- filename: string;
695
- status: UploadQueueStatus;
696
- createdAt: number;
697
- error?: string;
698
- }
699
-
700
- export interface DocEncryptionInfo {
701
- mode: "none" | "cse" | "e2e";
702
- effective_mode: "none" | "cse" | "e2e";
703
- inherited_from?: string;
704
- }
705
-
706
- // ── Chat (stateless channel) ─────────────────────────────────────────────────
707
-
708
- export interface ChatMessage {
709
- id: string;
710
- channel: string;
711
- sender_id: string;
712
- sender_name?: string | null;
713
- content: string;
714
- created_at: number;
715
- }
716
-
717
- export interface ChatChannel {
718
- channel: string;
719
- label?: string | null;
720
- last_message: ChatMessage;
721
- unread_count: number;
722
- }
723
-
724
- export interface ChatTypingEvent {
725
- channel: string;
726
- sender_id: string;
727
- sender_name?: string | null;
728
- }
729
-
730
- export interface ChatReadReceipt {
731
- channel: string;
732
- user_id: string;
733
- last_read_at: number;
734
- }
735
-
736
- export interface ChatReadCursor {
737
- user_id: string;
738
- last_read_at: number;
739
- }
740
-
741
- export interface SendChatMessageInput {
742
- channel: string;
743
- content: string;
744
- sender_name?: string;
745
- }
746
-
747
- export interface GetChatHistoryInput {
748
- channel: string;
749
- before?: number;
750
- limit?: number;
751
- }
752
-
753
- // ── Notifications (stateless channel) ────────────────────────────────────────
754
-
755
- export interface NotificationRecord {
756
- id: string;
757
- recipient_id: string;
758
- notification_type: string;
759
- title: string;
760
- body: string;
761
- icon?: string | null;
762
- link?: string | null;
763
- source_id?: string | null;
764
- read: boolean;
765
- created_at: number;
766
- }
767
-
768
- export interface NotificationReadUpdate {
769
- /** Present when a specific set of notifications was marked read. */
770
- ids?: string[];
771
- /** Present when mark_all_read was called. */
772
- all?: boolean;
773
- recipient_id: string;
774
- }
775
-
776
- export interface CreateNotificationInput {
777
- recipient_id: string;
778
- notification_type?: string;
779
- title: string;
780
- body?: string;
781
- icon?: string;
782
- link?: string;
783
- source_id?: string;
784
- }
785
-
786
- export interface FetchNotificationsInput {
787
- before?: number;
788
- limit?: number;
789
- unread_only?: boolean;
790
- }