B2H BaaS

SDK Overview

The B2H BaaS SDK provides a simple, Firebase-like API for your applications.

Installation

npm install @baas/js-sdk

Initialization

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

ModuleMethodDescription
Authclient.auth()Authentication methods
Dataclient.data()Data operations
Collectionclient.collection('name')Collection reference
Storageclient.storage()File storage
Firestoreclient.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