@bahterabase/sdk-js
v0.1.0
Published
Official BahteraBase Client SDK for JavaScript and TypeScript (PostgreSQL, Auth, Storage, Realtime, Edge Functions, AI & Vectors)
Downloads
87
Maintainers
Readme
🚢 @bahterabase/sdk-js
Official JavaScript & TypeScript client library for BahteraBase — The Open-Source-Friendly Backend-as-a-Service (PostgreSQL, Auth, Storage, Realtime, Edge Functions, AI & Vectors).
📦 Installation
Install via npm:
npm install @bahterabase/sdk-jsOr using yarn / pnpm / bun:
# Yarn
yarn add @bahterabase/sdk-js
# pnpm
pnpm add @bahterabase/sdk-js
# Bun
bun add @bahterabase/sdk-jsInstall directly from GitHub:
npm install github:kangpcode/bahterabase#workspace=@bahterabase/sdk-js⚡ Quick Start
import { createClient } from '@bahterabase/sdk-js';
// 1. Initialize the client
const bahtera = createClient(
'https://your-project.bahterabase.io',
'bb_anon_your_public_anon_key'
);
// 2. Database Query with Filter & Pagination
const { data: users, error } = await bahtera
.from('profiles')
.select('id, full_name, email, role')
.eq('role', 'admin')
.order('created_at', { ascending: false })
.limit(10);
if (error) {
console.error('Error fetching users:', error);
} else {
console.log('Users:', users);
}🧩 Features & Modules
1. 🔐 Authentication (bahtera.auth)
// Sign Up with Email & Password
const { data, error } = await bahtera.auth.signUp({
email: '[email protected]',
password: 'super-secure-password',
});
// Sign In
const { session, user } = await bahtera.auth.signInWithPassword({
email: '[email protected]',
password: 'super-secure-password',
});
// Get current user / session
const currentUser = bahtera.auth.getUser();
// Sign Out
await bahtera.auth.signOut();2. 🗄️ Database CRUD (bahtera.from(tableName))
// Insert
const { data: inserted } = await bahtera.from('posts').insert({
title: 'Hello BahteraBase',
content: 'Building modern fullstack apps with ease',
published: true,
});
// Update
const { data: updated } = await bahtera.from('posts')
.update({ published: false })
.eq('id', 'post_123');
// Delete
const { data: deleted } = await bahtera.from('posts')
.delete()
.eq('id', 'post_123');
// Call Postgres Stored Procedures (RPC)
const { data: report } = await bahtera.rpc('calculate_monthly_revenue', {
year: 2026,
month: 9,
});3. 📦 Object Storage (bahtera.storage)
// Upload a file to bucket
const { data: file, error } = await bahtera.storage
.from('avatars')
.upload('users/user_1.png', imageFile, {
contentType: 'image/png',
});
// Get public URL
const publicUrl = bahtera.storage.from('avatars').getPublicUrl('users/user_1.png');
// Download file
const { blob } = await bahtera.storage.from('avatars').download('users/user_1.png');4. ⚡ Realtime Subscriptions (bahtera.channel)
const room = bahtera.channel('room:general');
// Listen to custom broadcast events
room.on('broadcast', { event: 'message' }, (payload) => {
console.log('New message:', payload);
});
// Listen to Postgres Database Changes (CDC)
room.on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'messages' }, (payload) => {
console.log('New message in DB:', payload.new);
});
// Subscribe to channel
room.subscribe((status) => {
if (status === 'SUBSCRIBED') {
// Send a broadcast message
room.send({
type: 'broadcast',
event: 'message',
payload: { text: 'Hello from BahteraBase SDK!' },
});
}
});5. 🚀 Edge Functions (bahtera.functions)
// Invoke Serverless Edge Function
const { data, error } = await bahtera.functions.invoke('send-welcome-email', {
body: { email: '[email protected]', name: 'Budi' },
});6. ✨ AI & Vector Search (bahtera.ai)
// Generate text embeddings (1536-dim pgvector compatible)
const { embedding } = await bahtera.ai.generateEmbedding('Semantic search query');
// Perform Cosine Similarity Vector Search
const { data: similarArticles } = await bahtera.ai.vectorSearch({
table: 'articles',
vectorColumn: 'embedding',
queryVector: embedding,
similarityThreshold: 0.75,
limit: 5,
});📄 License
Apache-2.0 © kangpcode
