arbase-js
v0.1.0
Published
Official JavaScript/TypeScript client for ARBase
Maintainers
Readme
arbase-js
Official JavaScript/TypeScript client for ARBase.
npm install arbase-jsLocal development (this monorepo):
cd packages/arbase-js
npm install
npm run build
npm test
npm run smoke # requires php artisan serve + demo keysQuick start
import { createClient } from 'arbase-js'
const arbase = createClient('http://127.0.0.1:8000/p/demo', process.env.ARBASE_ANON_KEY!, {
timeoutMs: 30_000,
global: { headers: { 'X-Client-Info': 'my-app/1.0' } },
})
const { data, error } = await arbase
.from('orders')
.select('id,title,status')
.eq('status', 'open')
.limit(20)
await arbase.auth.signUp({ email: '[email protected]', password: 'password123' })
await arbase.auth.signInWithPassword({ email: '[email protected]', password: 'password123' })
await arbase.auth.refreshSession()
arbase.auth.onAuthStateChange((event, session) => {
console.log(event, session?.user.email)
})
await arbase.storage.from('avatars').upload('me.png', file)
await arbase.rpc('report_sales', { p_from: '2026-01-01', p_to: '2026-07-01' })
await arbase.functions.invoke('hello-world', { body: { name: 'Rabin' } })
arbase.channel('orders').on('INSERT', (e) => console.log(e)).subscribe()Abort a request
Low-level module methods that go through the shared HTTP layer accept a standard
AbortSignal when calling fetch options indirectly via client timeout. Set
timeoutMs: 0 to disable the default timeout, or pass a custom fetch that
forwards your own signals.
const arbase = createClient(url, key, { timeoutMs: 10_000 })Notes
- Project URL is
https://host/p/{slug}plus an anon/serviceapikey. - Auth sessions persist to
localStoragein browsers (memory fallback in Node). - Access tokens refresh automatically using
grant_type=refresh_token. - Realtime uses HTTP polling (not WebSockets). Default interval: 800ms.
- Query filters currently supported:
eq,like. migrations.*and function deploy/list/remove require a service-role key.- Browser clients need CORS: Laravel
config/cors.phpincludesp/*.
Scripts
| Command | Purpose |
|---------|---------|
| npm run build | Emit ESM + CJS + .d.ts |
| npm run typecheck | tsc --noEmit |
| npm test | Unit tests (vitest) |
| npm run smoke | Live Node integration smoke |
| npm run pack:check | npm pack --dry-run after build |
Browser smoke: build the package, then serve it and open
examples/browser.html (e.g. npx serve . from packages/arbase-js).
