@syntropysoft/syntropyfront 0.1.0-alpha.1 โ†’ 0.2.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/README.md CHANGED
@@ -1,322 +1,402 @@
1
- <p align="center">
2
- <img src="./assets/syntropysoft-logo.png" alt="SyntropyLog Logo" width="170"/>
3
- </p>
4
-
5
- <h1 align="center">SyntropyFront</h1>
6
-
7
- <p align="center">
8
- <strong>From Chaos to Clarity</strong>
9
- <br />
10
- The Observability Framework for High-Performance Teams
11
- </p>
12
- <p align="center">
13
- Advanced frontend tracing and error monitoring with reactive object tracking, worker architecture, and circular reference handling
14
- <br />
15
- </p>
16
-
17
- ## ๐Ÿš€ Features
18
-
19
- - **๐Ÿ”„ Reactive Object Tracking** - Real-time object state tracking using JavaScript Proxies
20
- - **โšก Worker Architecture** - Non-blocking data collection and processing
21
- - **๐Ÿ›ก๏ธ Circular Reference Handling** - Robust serialization for complex objects
22
- - **๐ŸŽฏ Configuration Presets** - Pre-configured setups for different use cases
23
- - **๐Ÿ“ฆ Lazy Loading** - Dynamic module loading for optimal bundle size
24
- - **๐Ÿ”— Framework Agnostic** - Works with any JavaScript framework
25
- - **๐Ÿ“Š Breadcrumb System** - Comprehensive user action tracking
26
- - **๐Ÿ”„ Automatic Retry** - Exponential backoff with persistent buffer
27
- - **๐Ÿ”’ Privacy First** - Granular context collection with opt-in sensitive data
1
+ # SyntropyFront
28
2
 
29
- ## ๐Ÿ“ฆ Installation
3
+ ๐Ÿš€ **Observability library with automatic capture - Just 1 line of code!**
30
4
 
31
- ```bash
32
- npm install syntropyfront
33
- ```
5
+ SyntropyFront automatically captures user interactions, errors, HTTP calls, and console logs, providing comprehensive observability for your web applications with minimal setup.
34
6
 
35
- ## ๐ŸŽฏ Quick Start
7
+ ## โœจ Features
36
8
 
37
- ```javascript
38
- import { SyntropyFront } from 'syntropyfront';
9
+ - ๐ŸŽฏ **Automatic click capture** - Tracks all user interactions
10
+ - ๐Ÿšจ **Error detection** - Catches uncaught exceptions and promise rejections
11
+ - ๐ŸŒ **HTTP monitoring** - Intercepts fetch calls automatically
12
+ - ๐Ÿ“ **Console logging** - Records console.log, console.error, console.warn
13
+ - ๐Ÿ’พ **Smart storage** - Keeps the last N events (configurable)
14
+ - ๐Ÿ“ค **Flexible posting** - Posts errors to your endpoint or logs to console
15
+ - โšก **Zero configuration** - Works out of the box with just an import
39
16
 
40
- // Initialize with balanced preset
41
- await SyntropyFront.init({
42
- preset: 'balanced',
43
- agent: {
44
- endpoint: 'https://your-api.com/errors'
45
- }
46
- });
17
+ ## ๐Ÿš€ Quick Start
47
18
 
48
- // Add reactive object tracking
49
- const userProfile = SyntropyFront.addProxyObject('userProfile', {
50
- name: 'John Doe',
51
- preferences: { theme: 'dark' }
52
- });
19
+ ### Basic Usage (1 line of code!)
53
20
 
54
- // Track user actions automatically
55
- // Error handling is automatic
21
+ ```javascript
22
+ import syntropyFront from 'syntropyfront';
23
+ // That's it! Auto-initializes and captures everything automatically
56
24
  ```
57
25
 
58
- ## โš™๏ธ Configuration Presets
26
+ ### With Custom Configuration
59
27
 
60
- ### Safe Preset
61
28
  ```javascript
62
- await SyntropyFront.init({
63
- preset: 'safe',
64
- agent: { endpoint: 'https://api.com/errors' }
29
+ import syntropyFront from 'syntropyfront';
30
+
31
+ // Option 1: Console only (default)
32
+ syntropyFront.configure({
33
+ maxEvents: 50
65
34
  });
66
- ```
67
- - **Use case**: Production environments with privacy concerns
68
- - **Features**: Errors only, minimal context, no tracking
69
- - **Bundle size**: ~25KB
70
35
 
71
- ### Balanced Preset (Default)
72
- ```javascript
73
- await SyntropyFront.init({
74
- preset: 'balanced',
75
- agent: { endpoint: 'https://api.com/errors' }
36
+ // Option 2: With endpoint (automatic fetch)
37
+ syntropyFront.configure({
38
+ maxEvents: 50,
39
+ fetch: {
40
+ url: 'https://your-api.com/errors',
41
+ options: {
42
+ headers: {
43
+ 'Authorization': 'Bearer your-token',
44
+ 'Content-Type': 'application/json'
45
+ },
46
+ mode: 'cors'
47
+ }
48
+ }
76
49
  });
77
- ```
78
- - **Use case**: General production use
79
- - **Features**: Periodic sending, curated context, moderate tracking
80
- - **Bundle size**: ~60KB
81
50
 
82
- ### Debug Preset
83
- ```javascript
84
- await SyntropyFront.init({
85
- preset: 'debug',
86
- agent: { endpoint: 'https://api.com/errors' }
51
+ // Option 3: With custom error handler (maximum flexibility)
52
+ syntropyFront.configure({
53
+ maxEvents: 50,
54
+ onError: (errorPayload) => {
55
+ // You can do anything with the error:
56
+ // - Send to your API
57
+ // - Save to localStorage
58
+ // - Send to a repository
59
+ // - Upload to cloud
60
+ // - Whatever you want!
61
+ console.log('Error captured:', errorPayload);
62
+
63
+ // Example: send to multiple places
64
+ fetch('https://api1.com/errors', {
65
+ method: 'POST',
66
+ body: JSON.stringify(errorPayload)
67
+ });
68
+
69
+ // Also save locally
70
+ localStorage.setItem('lastError', JSON.stringify(errorPayload));
71
+ }
87
72
  });
88
73
  ```
89
- - **Use case**: Development and debugging
90
- - **Features**: Frequent sending, full context, complete tracking
91
- - **Bundle size**: ~60KB
92
74
 
93
- ### Performance Preset
94
- ```javascript
95
- await SyntropyFront.init({
96
- preset: 'performance',
97
- agent: { endpoint: 'https://api.com/errors' }
98
- });
75
+ ## ๐Ÿ“ฆ Installation
76
+
77
+ ```bash
78
+ npm install syntropyfront
79
+ ## ๐ŸŽฏ How It Works
80
+
81
+ SyntropyFront automatically:
82
+
83
+ 1. **Captures clicks** - Records element info, coordinates, and timestamps
84
+ 2. **Detects errors** - Intercepts `window.onerror` and `window.onunhandledrejection`
85
+ 3. **Monitors HTTP** - Wraps `window.fetch` to track requests and responses
86
+ 4. **Logs console** - Intercepts console methods to capture debug info
87
+ 5. **Maintains context** - Keeps the last N events as breadcrumbs
88
+ 6. **Posts errors** - Sends error data with full context to your endpoint
89
+
90
+ ## ๐Ÿ“Š What Gets Captured
91
+
92
+ ### Error Payload Structure
93
+
94
+ ```json
95
+ {
96
+ "type": "uncaught_exception",
97
+ "error": {
98
+ "message": "Error message",
99
+ "source": "file.js",
100
+ "lineno": 42,
101
+ "colno": 15,
102
+ "stack": "Error stack trace..."
103
+ },
104
+ "breadcrumbs": [
105
+ {
106
+ "category": "user",
107
+ "message": "click",
108
+ "data": {
109
+ "element": "BUTTON",
110
+ "id": "submit-btn",
111
+ "className": "btn-primary",
112
+ "x": 100,
113
+ "y": 200
114
+ },
115
+ "timestamp": "2024-01-01T12:00:00.000Z"
116
+ }
117
+ ],
118
+ "timestamp": "2024-01-01T12:00:00.000Z"
119
+ }
99
120
  ```
100
- - **Use case**: High-performance applications
101
- - **Features**: Critical errors only, minimal overhead
102
- - **Bundle size**: ~25KB
103
121
 
104
- ## ๐Ÿ”„ Reactive Object Tracking
122
+ ### Breadcrumb Categories
123
+
124
+ - **`user`** - Click events, form submissions, etc.
125
+ - **`http`** - Fetch requests, responses, and errors
126
+ - **`console`** - Console.log, console.error, console.warn
127
+ - **`error`** - Manual error reports
128
+
129
+ ## โš™๏ธ Configuration Options
130
+
131
+ SyntropyFront uses a priority system for error handling:
105
132
 
106
- Track object changes in real-time using JavaScript Proxies:
133
+ 1. **Custom Error Handler** (`onError`) - Maximum flexibility
134
+ 2. **Endpoint** (`fetch`) - Automatic posting
135
+ 3. **Console** - Default fallback
136
+
137
+ ### Basic Configuration (Console Only)
107
138
 
108
139
  ```javascript
109
- // Add object for tracking
110
- const userProfile = SyntropyFront.addProxyObject('userProfile', {
111
- name: 'John Doe',
112
- preferences: { theme: 'dark' }
140
+ syntropyFront.configure({
141
+ maxEvents: 50 // Number of events to keep in memory
113
142
  });
143
+ ```
114
144
 
115
- // Changes are automatically tracked
116
- userProfile.name = 'Jane Doe';
117
- userProfile.preferences.theme = 'light';
145
+ ### With Endpoint (Automatic Fetch)
118
146
 
119
- // Get tracking history
120
- const history = SyntropyFront.getProxyObjectHistory('userProfile');
121
- const currentState = SyntropyFront.getProxyObjectState('userProfile');
147
+ ```javascript
148
+ syntropyFront.configure({
149
+ maxEvents: 50,
150
+ fetch: {
151
+ url: 'https://your-api.com/errors',
152
+ options: {
153
+ headers: {
154
+ 'Authorization': 'Bearer your-token',
155
+ 'X-API-Key': 'your-api-key',
156
+ 'Content-Type': 'application/json'
157
+ },
158
+ mode: 'cors',
159
+ credentials: 'include'
160
+ }
161
+ }
162
+ });
122
163
  ```
123
164
 
124
- ## โšก Worker Architecture
125
-
126
- Offload data processing to Web Workers for non-blocking operation:
165
+ ### With Custom Error Handler (Maximum Flexibility)
127
166
 
128
167
  ```javascript
129
- // Worker is automatically used when enabled
130
- await SyntropyFront.init({
131
- useWorker: true,
132
- // ... other config
168
+ syntropyFront.configure({
169
+ maxEvents: 50,
170
+ onError: (errorPayload) => {
171
+ // You have complete control over what to do with the error
172
+
173
+ // Send to your API
174
+ fetch('https://your-api.com/errors', {
175
+ method: 'POST',
176
+ body: JSON.stringify(errorPayload)
177
+ });
178
+
179
+ // Save to localStorage
180
+ localStorage.setItem('lastError', JSON.stringify(errorPayload));
181
+
182
+ // Send to multiple services
183
+ Promise.all([
184
+ fetch('https://service1.com/errors', { method: 'POST', body: JSON.stringify(errorPayload) }),
185
+ fetch('https://service2.com/errors', { method: 'POST', body: JSON.stringify(errorPayload) })
186
+ ]);
187
+
188
+ // Upload to cloud storage
189
+ // Send to repository
190
+ // Log to file
191
+ // Whatever you want!
192
+ }
133
193
  });
134
-
135
- // Check worker status
136
- const isAvailable = SyntropyFront.isWorkerAvailable();
137
- const status = SyntropyFront.getWorkerStatus();
138
194
  ```
139
195
 
140
- ## ๐Ÿ›ก๏ธ Circular Reference Handling
196
+ ## ๐Ÿ”ง API Reference
141
197
 
142
- Safely serialize complex objects with circular references:
198
+ ### Core Methods
143
199
 
144
200
  ```javascript
145
- // Create circular reference
146
- const obj = { name: 'test' };
147
- obj.self = obj;
201
+ // Add custom breadcrumb
202
+ syntropyFront.addBreadcrumb('user', 'Custom action', { data: 'value' });
203
+
204
+ // Send manual error
205
+ syntropyFront.sendError(new Error('Custom error'));
206
+
207
+ // Get current breadcrumbs
208
+ const breadcrumbs = syntropyFront.getBreadcrumbs();
148
209
 
149
- // SyntropyFront handles this automatically
150
- SyntropyFront.sendError(new Error('Test'), { context: obj });
210
+ // Clear breadcrumbs
211
+ syntropyFront.clearBreadcrumbs();
212
+
213
+ // Get statistics
214
+ const stats = syntropyFront.getStats();
215
+ // Returns: { breadcrumbs: 5, errors: 2, isActive: true, maxEvents: 50, endpoint: 'console' }
151
216
  ```
152
217
 
153
- ## ๐Ÿ“Š Breadcrumb System
218
+ ## ๐ŸŽฏ Extending SyntropyFront
219
+
220
+ SyntropyFront captures the essentials by default, but you can extend it to capture any DOM events you want:
154
221
 
155
- Track user actions and application events:
222
+ ### Adding Custom Event Capture
156
223
 
157
224
  ```javascript
158
- // Add custom breadcrumbs
159
- SyntropyFront.addBreadcrumb('user', 'User clicked button', {
160
- buttonId: 'submit',
161
- timestamp: Date.now()
225
+ import syntropyFront from 'syntropyfront';
226
+
227
+ // Add scroll tracking
228
+ window.addEventListener('scroll', () => {
229
+ syntropyFront.addBreadcrumb('user', 'scroll', {
230
+ scrollY: window.scrollY,
231
+ scrollX: window.scrollX
232
+ });
162
233
  });
163
234
 
164
- // Get breadcrumbs
165
- const breadcrumbs = SyntropyFront.getBreadcrumbs();
166
- ```
235
+ // Add form submissions
236
+ document.addEventListener('submit', (event) => {
237
+ syntropyFront.addBreadcrumb('user', 'form_submit', {
238
+ formId: event.target.id,
239
+ formAction: event.target.action
240
+ });
241
+ });
167
242
 
168
- ## ๐Ÿ”— Framework Integration
243
+ // Add window resize
244
+ window.addEventListener('resize', () => {
245
+ syntropyFront.addBreadcrumb('system', 'window_resize', {
246
+ width: window.innerWidth,
247
+ height: window.innerHeight
248
+ });
249
+ });
169
250
 
170
- ### React
171
- ```javascript
172
- // In your main App component
173
- useEffect(() => {
174
- SyntropyFront.init({
175
- preset: 'balanced',
176
- agent: { endpoint: 'https://api.com/errors' }
251
+ // Add custom business events
252
+ function trackPurchase(productId, amount) {
253
+ syntropyFront.addBreadcrumb('business', 'purchase', {
254
+ productId,
255
+ amount,
256
+ timestamp: new Date().toISOString()
177
257
  });
178
- }, []);
258
+ }
179
259
  ```
180
260
 
181
- ### Vue
182
- ```javascript
183
- // In your main.js
184
- import { createApp } from 'vue';
185
- import App from './App.vue';
261
+ ### Common Events You Can Track
186
262
 
187
- const app = createApp(App);
263
+ - **User interactions**: `click`, `scroll`, `keydown`, `focus`, `blur`
264
+ - **Form events**: `submit`, `input`, `change`, `reset`
265
+ - **System events**: `resize`, `online`, `offline`, `visibilitychange`
266
+ - **Custom events**: Any business logic or user actions
267
+ - **Performance**: `load`, `DOMContentLoaded`, timing events
188
268
 
189
- // Initialize SyntropyFront
190
- SyntropyFront.init({
191
- preset: 'balanced',
192
- agent: { endpoint: 'https://api.com/errors' }
193
- });
269
+ ## ๐ŸŒ CORS Configuration
270
+
271
+ To use with your API, ensure your server allows CORS:
194
272
 
195
- app.mount('#app');
273
+ ```javascript
274
+ // Express.js example
275
+ app.use(cors({
276
+ origin: 'http://localhost:3000',
277
+ credentials: true
278
+ }));
279
+
280
+ // Or in headers
281
+ res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
282
+ res.setHeader('Access-Control-Allow-Methods', 'POST');
283
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
196
284
  ```
197
285
 
198
- ### Angular
199
- ```typescript
200
- // In your main.ts
201
- import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
202
- import { AppModule } from './app/app.module';
286
+ ## ๐Ÿ“ฑ Framework Support
203
287
 
204
- // Initialize SyntropyFront
205
- SyntropyFront.init({
206
- preset: 'balanced',
207
- agent: { endpoint: 'https://api.com/errors' }
208
- });
288
+ SyntropyFront works with any JavaScript framework:
209
289
 
210
- platformBrowserDynamic().bootstrapModule(AppModule);
211
- ```
290
+ - โœ… **React** - Works out of the box
291
+ - โœ… **Vue** - Works out of the box
292
+ - โœ… **Angular** - Works out of the box
293
+ - โœ… **Svelte** - Works out of the box
294
+ - โœ… **Vanilla JS** - Works out of the box
212
295
 
213
- ## ๐Ÿ“š API Reference
296
+ ## ๐ŸŽฏ Examples
214
297
 
215
- ### Core Methods
216
-
217
- #### `SyntropyFront.init(config)`
218
- Initialize SyntropyFront with configuration.
298
+ ### React Example
219
299
 
220
- #### `SyntropyFront.addProxyObject(name, object, options)`
221
- Add an object for reactive tracking.
300
+ ```jsx
301
+ import React from 'react';
302
+ import syntropyFront from 'syntropyfront';
222
303
 
223
- #### `SyntropyFront.getProxyObjectHistory(name)`
224
- Get the change history of a tracked object.
304
+ function App() {
305
+ // SyntropyFront auto-initializes on import
306
+ return (
307
+ <div>
308
+ <button onClick={() => console.log('Button clicked')}>
309
+ Click me!
310
+ </button>
311
+ </div>
312
+ );
313
+ }
314
+ ```
225
315
 
226
- #### `SyntropyFront.addBreadcrumb(type, message, data)`
227
- Add a breadcrumb entry.
316
+ ### Vue Example
228
317
 
229
- #### `SyntropyFront.sendError(error, context)`
230
- Send an error with context to the backend.
318
+ ```vue
319
+ <template>
320
+ <button @click="handleClick">Click me!</button>
321
+ </template>
231
322
 
232
- ### Configuration Options
323
+ <script>
324
+ import syntropyFront from 'syntropyfront';
233
325
 
234
- ```javascript
235
- {
236
- preset: 'balanced', // 'safe' | 'balanced' | 'debug' | 'performance'
237
- agent: {
238
- endpoint: 'https://api.com/errors',
239
- batchTimeout: 10000,
240
- batchSize: 20,
241
- maxRetries: 3,
242
- usePersistentBuffer: true
243
- },
244
- proxyTracking: {
245
- enabled: true,
246
- maxStates: 10,
247
- trackNested: true,
248
- trackArrays: true
249
- },
250
- useWorker: true,
251
- maxBreadcrumbs: 50,
252
- context: {
253
- device: true,
254
- window: true,
255
- session: true,
256
- ui: true,
257
- network: true
326
+ export default {
327
+ methods: {
328
+ handleClick() {
329
+ console.log('Button clicked');
330
+ }
258
331
  }
259
332
  }
333
+ </script>
260
334
  ```
261
335
 
262
- ## ๐Ÿงช Testing
336
+ ### Manual Error Reporting
263
337
 
264
- ```bash
265
- # Run tests
266
- npm test
338
+ ```javascript
339
+ import syntropyFront from 'syntropyfront';
267
340
 
268
- # Run tests in watch mode
269
- npm run test:watch
341
+ try {
342
+ // Your code here
343
+ } catch (error) {
344
+ // SyntropyFront will automatically capture this
345
+ throw error;
346
+ }
270
347
 
271
- # Run tests with coverage
272
- npm run test:coverage
348
+ // Or manually report
349
+ syntropyFront.sendError(new Error('Something went wrong'));
273
350
  ```
274
351
 
275
- ## ๐Ÿ—๏ธ Development
352
+ ### Extending with Custom Events
276
353
 
277
- ```bash
278
- # Install dependencies
279
- npm install
280
-
281
- # Build the package
282
- npm run build
354
+ ```javascript
355
+ import syntropyFront from 'syntropyfront';
283
356
 
284
- # Build in watch mode
285
- npm run dev
357
+ // Add your custom event listeners
358
+ window.addEventListener('scroll', () => {
359
+ syntropyFront.addBreadcrumb('user', 'scroll', {
360
+ scrollY: window.scrollY,
361
+ scrollX: window.scrollX
362
+ });
363
+ });
286
364
 
287
- # Lint code
288
- npm run lint
365
+ // Track business events
366
+ function userCompletedCheckout(orderId, total) {
367
+ syntropyFront.addBreadcrumb('business', 'checkout_completed', {
368
+ orderId,
369
+ total,
370
+ timestamp: new Date().toISOString()
371
+ });
372
+ }
289
373
 
290
- # Fix linting issues
291
- npm run lint:fix
374
+ // Track performance
375
+ window.addEventListener('load', () => {
376
+ syntropyFront.addBreadcrumb('performance', 'page_loaded', {
377
+ loadTime: performance.now()
378
+ });
379
+ });
292
380
  ```
293
381
 
294
- ## ๐Ÿ“ฆ Build Outputs
295
-
296
- The build process generates multiple formats:
382
+ ## ๐Ÿ” Debugging
297
383
 
298
- - **ESM** (`dist/index.js`) - Modern ES modules
299
- - **CommonJS** (`dist/index.cjs`) - Node.js compatibility
300
- - **IIFE** (`dist/index.min.js`) - Browser-ready minified bundle
384
+ SyntropyFront logs helpful information to the console:
301
385
 
302
- ## ๐Ÿค Contributing
303
-
304
- 1. Fork the repository
305
- 2. Create a feature branch
306
- 3. Make your changes
307
- 4. Add tests
308
- 5. Submit a pull request
386
+ ```
387
+ ๐Ÿš€ SyntropyFront: Initialized with automatic capture
388
+ โœ… SyntropyFront: Configured - maxEvents: 50, endpoint: https://your-api.com/errors
389
+ โŒ Error: { type: "uncaught_exception", error: {...}, breadcrumbs: [...] }
390
+ ```
309
391
 
310
392
  ## ๐Ÿ“„ License
311
393
 
312
- Apache 2.0 - see [LICENSE](LICENSE) file for details.
394
+ Apache 2.0
313
395
 
314
- ## ๐Ÿ†˜ Support
396
+ ## ๐Ÿค Contributing
315
397
 
316
- - ๐Ÿ“– [Documentation](https://github.com/Syntropysoft/syntropyfront)
317
- - ๐Ÿ› [Issues](https://github.com/Syntropysoft/syntropyfront/issues)
318
- - ๐Ÿ’ฌ [Discussions](https://github.com/Syntropysoft/syntropyfront/discussions)
398
+ Contributions are welcome! Please feel free to submit a Pull Request.
319
399
 
320
400
  ---
321
401
 
322
- Made with โค๏ธ by the SyntropyLog Team
402
+ **Made with โค๏ธ for better web observability**