@bentolabs/sdk
v2.0.2
Published
BentoLabs SDK for user session recording and analytics
Maintainers
Readme
BentoLabs SDK
A TypeScript SDK for user session recording and analytics using rrweb.
Installation
npm install @bentolabs/sdkCI/CD Pipeline
This project includes a streamlined CI/CD pipeline with:
- ✅ Release-Triggered Builds - Only runs when you create a GitHub release
- ✅ Automated Testing on Node.js 18.x
- ✅ Code Quality Checks (ESLint, Prettier, TypeScript)
- ✅ Automated Build and validation
- ✅ Automated NPM Publishing on releases
- ✅ Dependency Management with Dependabot
Quick Setup
- Set NPM Token: Add
NPM_TOKENto GitHub repository secrets - Create Release: Tag and release on GitHub to automatically build, test, and publish to npm
See DEPLOYMENT.md for detailed setup instructions.
Quick Start
import { BentoLabsSDK } from '@bentolabs/sdk';
// Create SDK instance
const sdk = new BentoLabsSDK();
// Initialize with your API key
sdk.init('your-api-key', {
endpoint: 'https://api.bentolabs.ai',
debug: true,
});
// Check status
console.log('Session ID:', sdk.getSessionId());
console.log('Recording:', sdk.isRecordingActive());API Reference
Initialization
init(apiKey: string, options?: SDKOptions)
Initialize the SDK with your API key and optional configuration.
Parameters:
apiKey(string): Your BentoLabs API keyoptions(SDKOptions, optional): Configuration options
Options:
interface SDKOptions {
endpoint?: string; // API endpoint URL (default: 'https://api.bentolabs.ai')
debug?: boolean; // Enable debug logging (default: false)
}Example:
sdk.init('your-api-key', {
endpoint: 'https://custom-endpoint.com',
debug: true,
});Methods
getSessionId(): string
Returns the current session ID.
const sessionId = sdk.getSessionId();
console.log('Current session:', sessionId); // sess_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxisRecordingActive(): boolean
Check if recording is currently active.
if (sdk.isRecordingActive()) {
console.log('Recording user interactions...');
}getConfig(): Omit<SDKConfig, 'apiKey'> & { apiKey: string }
Get current configuration with masked API key for security.
const config = sdk.getConfig();
console.log(config);
// {
// apiKey: 'your-api...',
// endpoint: 'https://api.bentolabs.ai',
// debug: false
// }Examples
React Integration
import React, { useEffect, useState } from 'react';
import { BentoLabsSDK } from '@bentolabs/sdk';
function App() {
const [sdk] = useState(() => new BentoLabsSDK());
const [sessionId, setSessionId] = useState('');
useEffect(() => {
sdk.init('your-api-key', { debug: true });
setSessionId(sdk.getSessionId());
}, [sdk]);
return (
<div>
<h1>My App</h1>
<p>Session: {sessionId}</p>
<p>Recording: {sdk.isRecordingActive() ? 'Active' : 'Inactive'}</p>
</div>
);
}Vanilla JavaScript
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/@bentolabs/sdk@latest/dist/index.js"></script>
</head>
<body>
<script>
const sdk = new BentoLabsSDK();
sdk.init('your-api-key', { debug: true });
console.log('Session ID:', sdk.getSessionId());
console.log('Recording:', sdk.isRecordingActive());
</script>
</body>
</html>Examples Directory
Check out the examples directory for complete working examples:
- React Example: Comprehensive React application with interactive demo
- Vanilla JS Example: Simple HTML/JavaScript integration
Development
Setup
# Clone the repository
git clone https://github.com/bentolabs/bentolabs-sdk.git
cd bentolabs-sdk
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Start development mode
npm run devScripts
npm run build- Build the TypeScript projectnpm run dev- Start TypeScript compiler in watch modenpm test- Run all testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage reportnpm run lint- Run ESLintnpm run format- Format code with Prettier
Project Structure
bentolabs-sdk/
├── src/ # Source code
│ └── index.ts # Main SDK implementation
├── tests/ # Test files
│ ├── BentoLabsSDK.test.ts
│ └── integration.test.ts
├── examples/ # Example applications
│ └── react-example/ # React example
├── dist/ # Built files (generated)
├── coverage/ # Test coverage (generated)
└── .github/ # GitHub Actions workflowsContributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes and add tests
- Run tests:
npm test - Run linting:
npm run lint - Commit your changes:
git commit -am 'Add my feature' - Push to the branch:
git push origin feature/my-feature - Submit a pull request
Publishing
Stable Release
- Create a GitHub release with a version tag (e.g.,
v1.0.0) - GitHub Actions will automatically publish to npm
Beta Release
- Push changes to the
developbranch - GitHub Actions will automatically publish a beta version
License
MIT License - see LICENSE file for details.
