SDK Overview
The B2H BaaS SDK provides a simple, Firebase-like API for your applications.
Installation
npm install @baas/js-sdkInitialization
import BaasClient from '@baas/js-sdk';
const client = new BaasClient({
apiBase: 'https://api.b2h.app',
projectId: 'your-project-id',
transport: 'auto' // 'auto', 'rest', or 'websocket'
});Modules
| Module | Method | Description |
|---|---|---|
| Auth | client.auth() | Authentication methods |
| Data | client.data() | Data operations |
| Collection | client.collection('name') | Collection reference |
| Storage | client.storage() | File storage |
| Firestore | client.firestore() | Firebase-compatible API |
Firebase Compatibility
B2H BaaS provides a Firebase Firestore-compatible API:
// Firebase-style usage
const firestore = client.firestore();
// Get a document
const doc = await firestore.doc('users/abc').get();
console.log(doc.data());
// Query with where/orderBy
const snapshot = await firestore
.collection('posts')
.where('published', '==', true)
.orderBy('createdAt', 'desc')
.limit(10)
.get();
snapshot.forEach(doc => console.log(doc.id, doc.data()));
// Real-time listener
firestore.collection('messages').onSnapshot(snapshot => {
snapshot.forEach(doc => console.log(doc.data()));
});Transport Modes
- auto (default) - Uses WebSocket, falls back to REST polling
- websocket - Forces WebSocket only
- rest - Uses REST API with polling for real-time