@bentolabs/sdk
Version:
BentoLabs SDK for user session recording and analytics
255 lines (184 loc) • 6.26 kB
Markdown
for user session recording and analytics using rrweb.
[](https://github.com/bentolabs/bentolabs-sdk/actions)
[](https://github.com/bentolabs/bentolabs-sdk/actions)
[](https://badge.fury.io/js/%40bentolabs%2Fsdk)
```bash
npm install @bentolabs/sdk
```
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
1. **Set NPM Token**: Add `NPM_TOKEN` to GitHub repository secrets
2. **Create Release**: Tag and release on GitHub to automatically build, test, and publish to npm
See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed setup instructions.
```typescript
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());
```
Initialize the SDK with your API key and optional configuration.
**Parameters:**
- `apiKey` (string): Your BentoLabs API key
- `options` (SDKOptions, optional): Configuration options
**Options:**
```typescript
interface SDKOptions {
endpoint?: string; // API endpoint URL (default: 'https://api.bentolabs.ai')
debug?: boolean; // Enable debug logging (default: false)
}
```
**Example:**
```typescript
sdk.init('your-api-key', {
endpoint: 'https://custom-endpoint.com',
debug: true,
});
```
Returns the current session ID.
```typescript
const sessionId = sdk.getSessionId();
console.log('Current session:', sessionId); // sess_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
```
Check if recording is currently active.
```typescript
if (sdk.isRecordingActive()) {
console.log('Recording user interactions...');
}
```
Get current configuration with masked API key for security.
```typescript
const config = sdk.getConfig();
console.log(config);
// {
// apiKey: 'your-api...',
// endpoint: 'https://api.bentolabs.ai',
// debug: false
// }
```
```typescript
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>
);
}
```
```html
<!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>
```
Check out the [examples](./examples/) directory for complete working examples:
- **[React Example](./examples/react-example/)**: Comprehensive React application with interactive demo
- **[Vanilla JS Example](./examples/vanilla-js/)**: Simple HTML/JavaScript integration
```bash
git clone https://github.com/bentolabs/bentolabs-sdk.git
cd bentolabs-sdk
npm install
npm run build
npm test
npm run test:coverage
npm run dev
```
- `npm run build` - Build the TypeScript project
- `npm run dev` - Start TypeScript compiler in watch mode
- `npm test` - Run all tests
- `npm run test:watch` - Run tests in watch mode
- `npm run test:coverage` - Run tests with coverage report
- `npm run lint` - Run ESLint
- `npm run format` - Format code with Prettier
```
bentolabs-sdk/
├── src/
│ └── index.ts
├── tests/
│ ├── BentoLabsSDK.test.ts
│ └── integration.test.ts
├── examples/
│ └── react-example/
├── dist/
├── coverage/
└── .github/
```
1. Fork the repository
2. Create a feature branch: `git checkout -b feature/my-feature`
3. Make your changes and add tests
4. Run tests: `npm test`
5. Run linting: `npm run lint`
6. Commit your changes: `git commit -am 'Add my feature'`
7. Push to the branch: `git push origin feature/my-feature`
8. Submit a pull request
1. Create a GitHub release with a version tag (e.g., `v1.0.0`)
2. GitHub Actions will automatically publish to npm
### Beta Release
1. Push changes to the `develop` branch
2. GitHub Actions will automatically publish a beta version
## License
MIT License - see [LICENSE](LICENSE) file for details.
## Support
- 📖 [Documentation](https://github.com/bentolabs/bentolabs-sdk)
- 🐛 [Issue Tracker](https://github.com/bentolabs/bentolabs-sdk/issues)
- 💬 [Discussions](https://github.com/bentolabs/bentolabs-sdk/discussions)
A TypeScript SDK