@bentolabs/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BentoLabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # BentoLabs SDK
2
+
3
+ A TypeScript SDK for user session recording and analytics using rrweb.
4
+
5
+ [![CI/CD Pipeline](https://github.com/bentolabs/bentolabs-sdk/workflows/CI%2FCD%20Pipeline/badge.svg)](https://github.com/bentolabs/bentolabs-sdk/actions)
6
+ [![Code Quality](https://github.com/bentolabs/bentolabs-sdk/workflows/Code%20Quality/badge.svg)](https://github.com/bentolabs/bentolabs-sdk/actions)
7
+ [![npm version](https://badge.fury.io/js/%40bentolabs%2Fsdk.svg)](https://badge.fury.io/js/%40bentolabs%2Fsdk)
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @bentolabs/sdk
13
+ ```
14
+
15
+ ## CI/CD Pipeline
16
+
17
+ This project includes a streamlined CI/CD pipeline with:
18
+
19
+ - ✅ **Release-Triggered Builds** - Only runs when you create a GitHub release
20
+ - ✅ **Automated Testing** on Node.js 18.x
21
+ - ✅ **Code Quality Checks** (ESLint, Prettier, TypeScript)
22
+ - ✅ **Automated Build** and validation
23
+ - ✅ **Automated NPM Publishing** on releases
24
+ - ✅ **Dependency Management** with Dependabot
25
+
26
+ ### Quick Setup
27
+
28
+ 1. **Set NPM Token**: Add `NPM_TOKEN` to GitHub repository secrets
29
+ 2. **Create Release**: Tag and release on GitHub to automatically build, test, and publish to npm
30
+
31
+ See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed setup instructions.
32
+
33
+ ## Quick Start
34
+
35
+ ```typescript
36
+ import { BentoLabsSDK } from '@bentolabs/sdk';
37
+
38
+ // Create SDK instance
39
+ const sdk = new BentoLabsSDK();
40
+
41
+ // Initialize with your API key
42
+ sdk.init('your-api-key', {
43
+ endpoint: 'https://api.bentolabs.ai',
44
+ debug: true,
45
+ });
46
+
47
+ // Check status
48
+ console.log('Session ID:', sdk.getSessionId());
49
+ console.log('Recording:', sdk.isRecordingActive());
50
+ ```
51
+
52
+ ## API Reference
53
+
54
+ ### Initialization
55
+
56
+ #### `init(apiKey: string, options?: SDKOptions)`
57
+
58
+ Initialize the SDK with your API key and optional configuration.
59
+
60
+ **Parameters:**
61
+
62
+ - `apiKey` (string): Your BentoLabs API key
63
+ - `options` (SDKOptions, optional): Configuration options
64
+
65
+ **Options:**
66
+
67
+ ```typescript
68
+ interface SDKOptions {
69
+ endpoint?: string; // API endpoint URL (default: 'https://api.bentolabs.ai')
70
+ debug?: boolean; // Enable debug logging (default: false)
71
+ }
72
+ ```
73
+
74
+ **Example:**
75
+
76
+ ```typescript
77
+ sdk.init('your-api-key', {
78
+ endpoint: 'https://custom-endpoint.com',
79
+ debug: true,
80
+ });
81
+ ```
82
+
83
+ ### Methods
84
+
85
+ #### `getSessionId(): string`
86
+
87
+ Returns the current session ID.
88
+
89
+ ```typescript
90
+ const sessionId = sdk.getSessionId();
91
+ console.log('Current session:', sessionId); // sess_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
92
+ ```
93
+
94
+ #### `isRecordingActive(): boolean`
95
+
96
+ Check if recording is currently active.
97
+
98
+ ```typescript
99
+ if (sdk.isRecordingActive()) {
100
+ console.log('Recording user interactions...');
101
+ }
102
+ ```
103
+
104
+ #### `getConfig(): Omit<SDKConfig, 'apiKey'> & { apiKey: string }`
105
+
106
+ Get current configuration with masked API key for security.
107
+
108
+ ```typescript
109
+ const config = sdk.getConfig();
110
+ console.log(config);
111
+ // {
112
+ // apiKey: 'your-api...',
113
+ // endpoint: 'https://api.bentolabs.ai',
114
+ // debug: false
115
+ // }
116
+ ```
117
+
118
+ ## Examples
119
+
120
+ ### React Integration
121
+
122
+ ```typescript
123
+ import React, { useEffect, useState } from 'react';
124
+ import { BentoLabsSDK } from '@bentolabs/sdk';
125
+
126
+ function App() {
127
+ const [sdk] = useState(() => new BentoLabsSDK());
128
+ const [sessionId, setSessionId] = useState('');
129
+
130
+ useEffect(() => {
131
+ sdk.init('your-api-key', { debug: true });
132
+ setSessionId(sdk.getSessionId());
133
+ }, [sdk]);
134
+
135
+ return (
136
+ <div>
137
+ <h1>My App</h1>
138
+ <p>Session: {sessionId}</p>
139
+ <p>Recording: {sdk.isRecordingActive() ? 'Active' : 'Inactive'}</p>
140
+ </div>
141
+ );
142
+ }
143
+ ```
144
+
145
+ ### Vanilla JavaScript
146
+
147
+ ```html
148
+ <!DOCTYPE html>
149
+ <html>
150
+ <head>
151
+ <script src="https://unpkg.com/@bentolabs/sdk@latest/dist/index.js"></script>
152
+ </head>
153
+ <body>
154
+ <script>
155
+ const sdk = new BentoLabsSDK();
156
+ sdk.init('your-api-key', { debug: true });
157
+
158
+ console.log('Session ID:', sdk.getSessionId());
159
+ console.log('Recording:', sdk.isRecordingActive());
160
+ </script>
161
+ </body>
162
+ </html>
163
+ ```
164
+
165
+ ## Examples Directory
166
+
167
+ Check out the [examples](./examples/) directory for complete working examples:
168
+
169
+ - **[React Example](./examples/react-example/)**: Comprehensive React application with interactive demo
170
+ - **[Vanilla JS Example](./examples/vanilla-js/)**: Simple HTML/JavaScript integration
171
+
172
+ ## Development
173
+
174
+ ### Setup
175
+
176
+ ```bash
177
+ # Clone the repository
178
+ git clone https://github.com/bentolabs/bentolabs-sdk.git
179
+ cd bentolabs-sdk
180
+
181
+ # Install dependencies
182
+ npm install
183
+
184
+ # Build the project
185
+ npm run build
186
+
187
+ # Run tests
188
+ npm test
189
+
190
+ # Run tests with coverage
191
+ npm run test:coverage
192
+
193
+ # Start development mode
194
+ npm run dev
195
+ ```
196
+
197
+ ### Scripts
198
+
199
+ - `npm run build` - Build the TypeScript project
200
+ - `npm run dev` - Start TypeScript compiler in watch mode
201
+ - `npm test` - Run all tests
202
+ - `npm run test:watch` - Run tests in watch mode
203
+ - `npm run test:coverage` - Run tests with coverage report
204
+ - `npm run lint` - Run ESLint
205
+ - `npm run format` - Format code with Prettier
206
+
207
+ ### Project Structure
208
+
209
+ ```
210
+ bentolabs-sdk/
211
+ ├── src/ # Source code
212
+ │ └── index.ts # Main SDK implementation
213
+ ├── tests/ # Test files
214
+ │ ├── BentoLabsSDK.test.ts
215
+ │ └── integration.test.ts
216
+ ├── examples/ # Example applications
217
+ │ └── react-example/ # React example
218
+ ├── dist/ # Built files (generated)
219
+ ├── coverage/ # Test coverage (generated)
220
+ └── .github/ # GitHub Actions workflows
221
+ ```
222
+
223
+ ## Contributing
224
+
225
+ 1. Fork the repository
226
+ 2. Create a feature branch: `git checkout -b feature/my-feature`
227
+ 3. Make your changes and add tests
228
+ 4. Run tests: `npm test`
229
+ 5. Run linting: `npm run lint`
230
+ 6. Commit your changes: `git commit -am 'Add my feature'`
231
+ 7. Push to the branch: `git push origin feature/my-feature`
232
+ 8. Submit a pull request
233
+
234
+ ## Publishing
235
+
236
+ ### Stable Release
237
+
238
+ 1. Create a GitHub release with a version tag (e.g., `v1.0.0`)
239
+ 2. GitHub Actions will automatically publish to npm
240
+
241
+ ### Beta Release
242
+
243
+ 1. Push changes to the `develop` branch
244
+ 2. GitHub Actions will automatically publish a beta version
245
+
246
+ ## License
247
+
248
+ MIT License - see [LICENSE](LICENSE) file for details.
249
+
250
+ ## Support
251
+
252
+ - 📖 [Documentation](https://github.com/bentolabs/bentolabs-sdk)
253
+ - 🐛 [Issue Tracker](https://github.com/bentolabs/bentolabs-sdk/issues)
254
+ - 💬 [Discussions](https://github.com/bentolabs/bentolabs-sdk/discussions)
@@ -0,0 +1,54 @@
1
+ interface SDKConfig {
2
+ apiKey: string;
3
+ endpoint: string;
4
+ debug: boolean;
5
+ }
6
+ interface SDKOptions {
7
+ endpoint?: string;
8
+ debug?: boolean;
9
+ }
10
+ export declare class BentoLabsSDK {
11
+ private config;
12
+ private sessionId;
13
+ private events;
14
+ private isRecording;
15
+ constructor();
16
+ /**
17
+ * Initialize the BentoLabs SDK
18
+ * @param apiKey - Your API key for authentication
19
+ * @param options - Optional configuration options
20
+ */
21
+ init(apiKey: string, options?: SDKOptions): void;
22
+ /**
23
+ * Generate a unique session ID with 'sess_' prefix
24
+ */
25
+ private generateSessionId;
26
+ /**
27
+ * Generate a simple UUID v4
28
+ */
29
+ private generateUUID;
30
+ /**
31
+ * Start recording user interactions
32
+ */
33
+ private startRecording;
34
+ /**
35
+ * Start batching events for transmission
36
+ */
37
+ private startBatching;
38
+ /**
39
+ * Get current session ID
40
+ */
41
+ getSessionId(): string;
42
+ /**
43
+ * Check if recording is active
44
+ */
45
+ isRecordingActive(): boolean;
46
+ /**
47
+ * Get current configuration (without exposing sensitive data)
48
+ */
49
+ getConfig(): Omit<SDKConfig, 'apiKey'> & {
50
+ apiKey: string;
51
+ };
52
+ }
53
+ declare const _default: BentoLabsSDK;
54
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BentoLabsSDK = void 0;
4
+ class BentoLabsSDK {
5
+ constructor() {
6
+ this.config = {
7
+ apiKey: '',
8
+ endpoint: '',
9
+ debug: false,
10
+ };
11
+ this.sessionId = '';
12
+ this.events = [];
13
+ this.isRecording = false;
14
+ }
15
+ /**
16
+ * Initialize the BentoLabs SDK
17
+ * @param apiKey - Your API key for authentication
18
+ * @param options - Optional configuration options
19
+ */
20
+ init(apiKey, options) {
21
+ var _a;
22
+ // Merge options with defaults
23
+ const defaultOptions = {
24
+ endpoint: 'https://api.bentolabs.ai', // Replace with your actual API URL
25
+ debug: false,
26
+ };
27
+ const mergedOptions = Object.assign(Object.assign(Object.assign({}, defaultOptions), options), {
28
+ // Ensure debug is always a boolean
29
+ debug: (_a = options === null || options === void 0 ? void 0 : options.debug) !== null && _a !== void 0 ? _a : defaultOptions.debug });
30
+ // Set up configuration
31
+ this.config = {
32
+ apiKey,
33
+ endpoint: mergedOptions.endpoint,
34
+ debug: mergedOptions.debug,
35
+ };
36
+ // Generate session ID with 'sess_' prefix
37
+ this.sessionId = this.generateSessionId();
38
+ // Log initialization if debug mode is on
39
+ if (this.config.debug) {
40
+ console.log('[BentoLabsSDK] Initialized with config:', {
41
+ apiKey: apiKey.substring(0, 8) + '...',
42
+ endpoint: this.config.endpoint,
43
+ debug: this.config.debug,
44
+ sessionId: this.sessionId,
45
+ });
46
+ }
47
+ // Start recording and batching
48
+ this.startRecording();
49
+ this.startBatching();
50
+ }
51
+ /**
52
+ * Generate a unique session ID with 'sess_' prefix
53
+ */
54
+ generateSessionId() {
55
+ const uuid = this.generateUUID();
56
+ return `sess_${uuid}`;
57
+ }
58
+ /**
59
+ * Generate a simple UUID v4
60
+ */
61
+ generateUUID() {
62
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
63
+ const r = (Math.random() * 16) | 0;
64
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
65
+ return v.toString(16);
66
+ });
67
+ }
68
+ /**
69
+ * Start recording user interactions
70
+ */
71
+ startRecording() {
72
+ if (this.config.debug) {
73
+ console.log('[BentoLabsSDK] Starting recording for session:', this.sessionId);
74
+ }
75
+ this.isRecording = true;
76
+ // TODO: Implement rrweb recording logic
77
+ }
78
+ /**
79
+ * Start batching events for transmission
80
+ */
81
+ startBatching() {
82
+ if (this.config.debug) {
83
+ console.log('[BentoLabsSDK] Starting event batching');
84
+ }
85
+ // TODO: Implement event batching logic
86
+ }
87
+ /**
88
+ * Get current session ID
89
+ */
90
+ getSessionId() {
91
+ return this.sessionId;
92
+ }
93
+ /**
94
+ * Check if recording is active
95
+ */
96
+ isRecordingActive() {
97
+ return this.isRecording;
98
+ }
99
+ /**
100
+ * Get current configuration (without exposing sensitive data)
101
+ */
102
+ getConfig() {
103
+ return {
104
+ apiKey: this.config.apiKey
105
+ ? this.config.apiKey.substring(0, 8) + '...'
106
+ : '',
107
+ endpoint: this.config.endpoint,
108
+ debug: this.config.debug,
109
+ };
110
+ }
111
+ }
112
+ exports.BentoLabsSDK = BentoLabsSDK;
113
+ // Export a default instance for convenience
114
+ exports.default = new BentoLabsSDK();
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@bentolabs/sdk",
3
+ "version": "1.0.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "scripts": {
7
+ "build": "tsc",
8
+ "dev": "tsc --watch",
9
+ "test": "jest",
10
+ "test:watch": "jest --watch",
11
+ "test:coverage": "jest --coverage",
12
+ "test:ci": "jest --ci --coverage --watchAll=false",
13
+ "lint": "eslint src/**/*.ts --fix",
14
+ "lint:check": "eslint src/**/*.ts",
15
+ "format": "prettier --write \"src/**/*.{ts,js,json}\"",
16
+ "format:check": "prettier --check \"src/**/*.{ts,js,json}\"",
17
+ "prepublishOnly": "npm run build && npm test",
18
+ "preversion": "npm run lint:check && npm test"
19
+ },
20
+ "description": "BentoLabs SDK for user session recording and analytics",
21
+ "keywords": [
22
+ "analytics",
23
+ "session-recording",
24
+ "user-tracking",
25
+ "rrweb",
26
+ "typescript",
27
+ "sdk"
28
+ ],
29
+ "author": "kacppian",
30
+ "license": "MIT",
31
+ "homepage": "https://github.com/bentolabs/bentolabs-sdk#readme",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/bentolabs/bentolabs-sdk.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/bentolabs/bentolabs-sdk/issues"
38
+ },
39
+ "files": [
40
+ "dist/**/*",
41
+ "README.md",
42
+ "LICENSE"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "registry": "https://registry.npmjs.org/"
47
+ },
48
+ "engines": {
49
+ "node": ">=14.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/jest": "^30.0.0",
53
+ "@types/node": "^24.5.1",
54
+ "@typescript-eslint/eslint-plugin": "^7.2.0",
55
+ "@typescript-eslint/parser": "^7.2.0",
56
+ "eslint": "^8.57.1",
57
+ "eslint-config-prettier": "^10.1.8",
58
+ "eslint-plugin-prettier": "^5.5.4",
59
+ "jest": "^30.1.3",
60
+ "jest-environment-jsdom": "^30.1.2",
61
+ "prettier": "^3.6.2",
62
+ "ts-jest": "^29.4.2",
63
+ "typescript": "^5.9.2"
64
+ },
65
+ "dependencies": {
66
+ "rrweb": "^1.1.3"
67
+ }
68
+ }