@arbidocs/core
v0.3.9
Published
Shared operations layer for ARBI — auth, config, SSE, WebSocket, and API operations
Maintainers
Readme
@arbidocs/core
High-level TypeScript SDK for the ARBI platform. Wraps authentication, workspace encryption, and all API operations into a single Arbi class.
Install
npm install @arbidocs/coreFor Node.js, also install the IndexedDB polyfill:
npm install fake-indexeddbQuick Start
import 'fake-indexeddb/auto' // Node.js only
import { Arbi } from '@arbidocs/core'
const arbi = new Arbi({ url: 'https://arbi.mycompany.com' })
// Login
await arbi.login('[email protected]', 'password')
// Pick a workspace
const workspaces = await arbi.workspaces.list()
await arbi.selectWorkspace(workspaces[0].external_id)
// Use it
const docs = await arbi.documents.list()
const tags = await arbi.tags.list()
const conversations = await arbi.conversations.list()Streaming AI Queries
const result = await arbi.assistant.query('What does section 3 say?', {
docIds: [docs[0].external_id],
onToken: (token) => process.stdout.write(token),
onStreamStart: ({ assistant_message_ext_id }) => {
console.log('Stream started:', assistant_message_ext_id)
},
onComplete: () => console.log('\nDone'),
})Session Recovery
After login, the SDK automatically persists your signing key (encrypted) in IndexedDB. You can also recover a session using the raw private key:
// Save the key after first login (e.g. the recovery key download)
const signingKeyBase64 = '...'
// Later, recover without password:
await arbi.loginWithKey('[email protected]', signingKeyBase64)API Reference
Constructor
const arbi = new Arbi({
url: 'https://arbi.mycompany.com', // Required: backend URL
deploymentDomain: 'arbi.mycompany.com', // Optional: defaults to URL hostname
credentials: 'omit', // Optional: 'omit' | 'include' | 'same-origin'
})Lifecycle
| Method | Description |
|--------|-------------|
| login(email, password) | Authenticate with email and password |
| loginWithKey(email, signingKeyBase64) | Authenticate with a stored signing key |
| selectWorkspace(workspaceId) | Select a workspace (decrypts workspace key) |
| logout() | Log out and securely clear key material |
Properties
| Property | Type | Description |
|----------|------|-------------|
| isLoggedIn | boolean | Whether the user is authenticated |
| hasWorkspace | boolean | Whether a workspace is selected |
Operations
All operations are namespaced and require a workspace to be selected (except workspaces and health).
| Namespace | Methods |
|-----------|---------|
| arbi.workspaces | list(), create(), update(), delete(), listUsers(), addUsers(), removeUsers(), setUserRole() |
| arbi.documents | list(), get(), upload(), update(), delete() |
| arbi.conversations | list(), getThreads(), updateTitle(), share(), delete() |
| arbi.assistant | query(question, options), retrieve(messageExtId) |
| arbi.tags | list(), create(), update(), delete() |
| arbi.doctags | assign(), remove() |
| arbi.contacts | list(), search() |
| arbi.health | check() |
Browser Entry Point
For browser environments (no Node.js APIs like fs), import from the browser entry:
import { Arbi } from '@arbidocs/core/browser'Security
- Zero-knowledge auth: Passwords never leave the client. Ed25519 keys are derived locally via Argon2id.
- E2E workspace encryption: Each workspace has a symmetric key, wrapped with your public key.
- Encrypted key storage: Private keys in IndexedDB are encrypted with a non-extractable Web Crypto AES-GCM key.
- Key zeroing on logout: Signing and session keys are scrubbed from memory on logout.
Examples
- Node.js Hello World — Login, list docs, ask a streaming question (~40 lines)
- React Chat App — Login form, workspace selector, document picker, streaming chat
Requirements
- Browser: Any modern browser with Web Crypto API
- Node.js: v18+ (needs
fetch,FormData,Blobglobals). Installfake-indexeddb. - TypeScript: 5.0+ (optional)
