Aurabase Logo
aurabasedocs
docsRéférenceSDK JavaScript

SDK JavaScript

@aurabase/client — client typé pour Node, Bun, Deno, Next.js, React, SvelteKit, Vue. Couvre Database, Auth, Realtime, Storage, Functions.

10 min de lecture·Niveau référence·Révisé le 15 avr. 2026
#
Installation

Un package, quatre managers

§ 01
terminalBASH
pnpm add @aurabase/client
Astuce
Packages compagnons : @aurabase/next (helpers server/action + middleware), @aurabase/react (hooks typés + SWR-style), @aurabase/sveltekit, @aurabase/expo.
#
Initialisation

Créer le client

§ 02
src/lib/aurabase.ts
TYPESCRIPT
import { createClient } from '@aurabase/client'
import type { Database } from './aurabase.types'
export const aura = createClient<Database>(
process.env.AURA_URL!,
process.env.AURA_ANON_KEY!,
{ auth: { persistSession: true, autoRefreshToken: true } }
)
#
Types

Codegen depuis votre schéma

§ 03

aura types gen génère un fichier aurabase.types.ts avec l'intégralité de votre schéma : tables, vues, fonctions, relations. À brancher dans createClient<Database>pour typer l'ensemble du SDK.

package.json
JSON
{
"scripts": {
"types:gen": "aura types gen > src/aurabase.types.ts",
"migrate": "aura db push && pnpm types:gen"
}
}
#
Méthodes

Par service

§ 04

Database

SignatureRetour
.from(table).select(cols?)SelectBuilder<T>
.from(table).insert(row)Promise<{ data, error }>
.from(table).update(patch)UpdateBuilder<T>
.from(table).delete()DeleteBuilder<T>
.rpc(fn, args)Promise<{ data, error }>

Auth

SignatureRetour
.auth.signUp({ email, password })Promise<AuthResponse>
.auth.signInWithPassword({ ... })Promise<AuthResponse>
.auth.signInWithOAuth({ provider })Promise<{ url }>
.auth.getSession()Promise<Session | null>
.auth.signOut()Promise<void>
.auth.mfa.enroll({ factor_type })Promise<Factor>

Realtime

SignatureRetour
.channel(name, config?)Channel
channel.on(event, filter, cb)Channel
channel.subscribe()Channel
channel.send({ type, event, payload })Promise<void>
channel.unsubscribe()Promise<void>

Storage

SignatureRetour
.storage.from(bucket).upload(path, file, opts?)Promise<{ data, error }>
.storage.from(bucket).download(path)Promise<Blob>
.storage.from(bucket).getPublicUrl(path, opts?){ publicUrl }
.storage.from(bucket).createSignedUrl(path, expiresIn)Promise<{ signedUrl }>
.storage.from(bucket).remove(paths[])Promise<{ data, error }>

Functions

SignatureRetour
.functions.invoke(name, { body?, headers? })Promise<{ data, error }>
#
Erreurs

Shape uniforme { data, error }

§ 05

Chaque méthode async retourne { data, error }. error est null en cas de succès, sinon un objet avec code, message, details.

errors.ts
TYPESCRIPT
const { data, error } = await aura.from('users').select(
'*').single()
if (error) {
if (error.code === 'PGRST116') notFound()
throw new AurabaseError(error)
}
Dernière mise à jour · 15 avr. 2026