1.0.2 • Published 9 months ago
bfloat v1.0.2
bfloat.ai SDK
A powerful and intuitive TypeScript/JavaScript SDK for interacting with the bfloat.ai API. Manage browser automation sessions with ease.
Features
- 🚀 Full TypeScript support with comprehensive type definitions
- 💪 Promise-based API for all operations
- 🛡️ Robust error handling
- 🔄 Complete session lifecycle management
- ⚙️ Flexible browser configuration
- 📘 Extensive documentation and examples
Installation
# Using npm
npm install bfloat
# Using yarn
yarn add bfloat
# Using pnpm
pnpm add bfloat
Quick Start
import { BfloatSDK, defaultBrowserConfig } from 'bfloat';
// Initialize the SDK
const bfloat = new BfloatSDK('your-api-key');
// Create and manage a session
async function example() {
try {
// Create a new session
const session = await bfloat.createSession({
browser: defaultBrowserConfig,
lifetime: 3600,
keep_alive: true
});
console.log('Session created:', session.id);
console.log('Debug URL:', session.debug_info.ws_debugger_url);
// Stop the session when done
await bfloat.stopSession(session.id);
} catch (error) {
console.error('Error:', error);
}
}
API Reference
Initialization
const bfloat = new BfloatSDK(apiKey: string, baseUrl?: string);
Methods
List Sessions
const sessions = await bfloat.listSessions();
Get Session Details
const session = await bfloat.getSession(sessionId: string);
Create Session
const session = await bfloat.createSession(config: SessionConfig);
Stop Session
const result = await bfloat.stopSession(sessionId: string);
Configuration
Browser Configuration
interface BrowserConfig {
type: string;
settings?: {
os?: string[];
devices?: string[];
screen?: {
max_width?: number;
max_height?: number;
min_width?: number;
min_height?: number;
};
locales?: string[];
};
block_ads?: boolean;
proxy?: boolean;
}
Session Configuration
interface SessionConfig {
browser: BrowserConfig;
lifetime?: number;
keep_alive?: boolean;
}
Error Handling
The SDK provides a custom BFloatError
class for error handling:
try {
const session = await bfloat.createSession({...});
} catch (error) {
if (error instanceof BFloatError) {
console.error('Status:', error.status);
console.error('Message:', error.message);
console.error('Response:', error.response);
}
}
Complete Example
import { BfloatSDK, BFloatError, defaultBrowserConfig } from 'bfloat';
async function runBrowserSession() {
const bfloat = new BfloatSDK('your-api-key');
try {
// List existing sessions
const sessions = await bfloat.listSessions();
console.log('Active sessions:', sessions.length);
// Create a new session
const session = await bfloat.createSession({
browser: {
...defaultBrowserConfig,
settings: {
...defaultBrowserConfig.settings,
locales: ['en-US']
}
},
lifetime: 3600
});
console.log('New session:', session.id);
console.log('Debug URL:', session.debug_info.ws_debugger_url);
// Get session details
const details = await bfloat.getSession(session.id);
console.log('Session status:', details.status);
// Stop session
await bfloat.stopSession(session.id);
console.log('Session stopped successfully');
} catch (error) {
if (error instanceof BFloatError) {
console.error('BFloat API error:', error.message);
console.error('Status:', error.status);
} else {
console.error('Unexpected error:', error);
}
}
}
Development
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Generate documentation
npm run docs
Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Documentation: https://docs.bfloat.ai
- Issues: GitHub Issues
- Email: support@bfloat.ai
Security
If you discover a security vulnerability, please send an email to security@bfloat.ai. All security vulnerabilities will be promptly addressed.