SDK Overview

Complete reference for the haex-vault SDK APIs and framework integrations.

Overview

The haex-vault SDK provides a complete API for building extensions. It includes database access, storage, filesystem operations, web requests, and more.

Installation

Install the SDK using your preferred package manager:

npm install @haex-space/vault-sdk

Framework Setup

The SDK provides adapters for popular frameworks. Choose your framework below:

Setup

// main.ts
import { createApp } from 'vue'
import { createHaexPlugin } from '@haex-space/vault-sdk/vue'
import App from './App.vue'

const app = createApp(App)
app.use(createHaexPlugin())
app.mount('#app')

Usage

<script setup lang="ts">
import { useHaexClient } from '@haex-space/vault-sdk/vue'

const client = useHaexClient()

// Access context
const theme = computed(() => client.context.value?.theme)
const locale = computed(() => client.context.value?.locale)

// Database operations
async function loadData() {
  const users = await client.query('SELECT * FROM users')
  console.log(users)
}
</script>

Client API Overview

The client provides access to all SDK features:

const client = useHaexClient()

// Extension info
client.extensionInfo        // { publicKey, name, version }
client.getTableName('users') // Prefixed table name

// Database
await client.query(sql, params)
await client.execute(sql, params)
await client.insert(table, data)
await client.update(table, data, where, whereParams)
await client.delete(table, where, whereParams)

// Storage
await client.storage.get(key)
await client.storage.set(key, value)
await client.storage.remove(key)

// Filesystem
await client.filesystem.saveFileAsync(data, options)
await client.filesystem.openFileAsync(options)

// Web
await client.web.fetchAsync(url, options)
await client.web.openAsync(url)

// Permissions
await client.checkDatabaseAsync(table, operation)
await client.checkFilesystemAsync(path, operation)
await client.checkWebAsync(url)

Application Context

Access the current theme, locale, and platform. The context updates automatically when the user changes settings.

const client = useHaexClient()

// Access current context
const context = client.context.value

// Available properties
context.theme    // 'light' | 'dark' | 'system'
context.locale   // 'en' | 'de' | ...
context.platform // 'windows' | 'macos' | 'linux' | 'ios' | 'android'

// React to context changes (Vue)
watch(() => client.context.value?.theme, (theme) => {
  console.log('Theme changed:', theme)
})
theme

Current theme: light, dark, or system

locale

Current locale code (en, de, etc.)

platform

Operating system: windows, macos, linux, ios, android

Events

Listen for events from haex-vault:

const client = useHaexClient()

// Listen for context changes
client.on('haextension:context:changed', (event) => {
  const { theme, locale, platform } = event.data.context
  console.log('Context updated:', { theme, locale, platform })
})

// Listen for search requests (if extension supports search)
client.on('haextension:search:request', async (event) => {
  const { query, requestId } = event.data

  // Perform search
  const results = await performSearch(query)

  // Send results back
  await client.respondToSearch(requestId, results)
})