UNPKG

@bentolabs/sdk

Version:

BentoLabs SDK for user session recording and analytics

255 lines (184 loc) 6.26 kB
# BentoLabs SDK A TypeScript SDK for user session recording and analytics using rrweb. [![CI/CD Pipeline](https://github.com/bentolabs/bentolabs-sdk/workflows/CI%2FCD%20Pipeline/badge.svg)](https://github.com/bentolabs/bentolabs-sdk/actions) [![Code Quality](https://github.com/bentolabs/bentolabs-sdk/workflows/Code%20Quality/badge.svg)](https://github.com/bentolabs/bentolabs-sdk/actions) [![npm version](https://badge.fury.io/js/%40bentolabs%2Fsdk.svg)](https://badge.fury.io/js/%40bentolabs%2Fsdk) ## Installation ```bash npm install @bentolabs/sdk ``` ## CI/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 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. ## Quick Start ```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()); ``` ## API Reference ### Initialization #### `init(apiKey: string, options?: SDKOptions)` 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, }); ``` ### Methods #### `getSessionId(): string` Returns the current session ID. ```typescript const sessionId = sdk.getSessionId(); console.log('Current session:', sessionId); // sess_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ``` #### `isRecordingActive(): boolean` Check if recording is currently active. ```typescript if (sdk.isRecordingActive()) { console.log('Recording user interactions...'); } ``` #### `getConfig(): Omit<SDKConfig, 'apiKey'> & { apiKey: string }` 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 // } ``` ## Examples ### React Integration ```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> ); } ``` ### Vanilla JavaScript ```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> ``` ## Examples Directory 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 ## Development ### Setup ```bash # 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 dev ``` ### Scripts - `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 ### 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 workflows ``` ## Contributing 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 ## Publishing ### Stable Release 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)