@syntropysoft/syntropyfront 0.4.3 → 0.4.5

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
@@ -5,7 +5,7 @@
5
5
  <h1 align="center">SyntropyFront</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>From Chaos to Clarity</strong>
8
+ <strong>From Uncertainty to Clarity</strong>
9
9
  <br />
10
10
  The Observability Library for High-Performance Teams
11
11
  </p>
@@ -14,554 +14,265 @@
14
14
  <a href="https://www.npmjs.com/package/@syntropysoft/syntropyfront"><img src="https://img.shields.io/npm/v/@syntropysoft/syntropyfront.svg" alt="NPM Version"></a>
15
15
  <a href="https://github.com/Syntropysoft/syntropyfront/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@syntropysoft/syntropyfront.svg" alt="License"></a>
16
16
  <a href="#"><img src="https://img.shields.io/badge/status-ready%20for%20production-brightgreen.svg" alt="Ready for Production"></a>
17
- <a href="#"><img src="https://github.com/Syntropysoft/syntropyfront/workflows/CodeQL/badge.svg" alt="CodeQL"></a>
18
- <a href="#"><img src="https://img.shields.io/badge/dependabot-enabled-brightgreen.svg" alt="Dependabot"></a>
19
- <a href="#"><img src="https://img.shields.io/badge/mutation%20score-71.03%25-brightgreen.svg" alt="Mutation Score"></a>
20
- <a href="#"><img src="https://img.shields.io/badge/test%20coverage-89.47%25-brightgreen.svg" alt="Test Coverage"></a>
17
+ <a href="#"><img src="https://img.shields.io/badge/test%20coverage-87%25-brightgreen.svg" alt="Test Coverage"></a>
21
18
  <a href="#"><img src="https://img.shields.io/badge/bundle%20size-34%20KB-brightgreen.svg" alt="Bundle Size"></a>
22
19
  <a href="https://socket.dev/npm/package/@syntropysoft/syntropyfront"><img src="https://socket.dev/api/badge/npm/package/@syntropysoft/syntropyfront" alt="Socket Badge"></a>
23
20
  </p>
24
21
 
25
22
  ---
26
23
 
27
- 🚀 **Observability library with automatic capture - Just 1 line of code! No dependencies!**
24
+ 🚀 **Automatic observability capture - Just 1 line of code! Zero external dependencies.**
28
25
 
29
- SyntropyFront automatically captures user interactions, errors, HTTP calls, and console logs, providing comprehensive observability for your web applications with minimal setup.
26
+ SyntropyFront automatically captures user interactions, errors, HTTP calls, and console logs, providing a 360° view of the user experience with minimal performance impact.
30
27
 
31
- ## Features
28
+ ## 🧠 Our Philosophy: Observability with Purpose
32
29
 
33
- - 🎯 **Automatic click capture** - Tracks all user interactions
34
- - 🚨 **Error detection** - Catches uncaught exceptions and promise rejections
35
- - 🌐 **HTTP monitoring** - Intercepts fetch calls automatically
36
- - 📝 **Console logging** - Records console.log, console.error, console.warn
37
- - 💾 **Smart storage** - Keeps the last N events (configurable)
38
- - 📤 **Flexible posting** - Posts errors to your endpoint or logs to console
39
- - ⚡ **Zero configuration** - Works out of the box with just an import
40
- - 📦 **Zero Dependencies** - 100% standalone, no runtime dependencies
41
- - 🛡️ **Highly Resilient** - Automatic retry and persistent queuing
30
+ SyntropyFront is not just a log collector; it is a piece of engineering designed under three fundamental pillars:
42
31
 
43
- ## 🚀 Quick Start
44
-
45
- ### Basic Usage (1 line of code!)
32
+ 1. **SOLID Principles**: Each component has a single responsibility. From `QueueManager` to `RetryManager`, the system is extensible and predictable.
33
+ 2. **Functional Programming**: We use declarative patterns to transform data, ensuring that error processing and PII obfuscation are pure and without unexpected side effects.
34
+ 3. **Privacy by Design (Privacy-by-Default)**: Security is not optional. The system includes a sensitive data masking engine (PII) that acts before any information leaves the client.
46
35
 
47
- ```javascript
48
- import syntropyFront from '@syntropysoft/syntropyfront';
49
- // That's it! Auto-initializes and captures everything automatically
50
- ```
36
+ ## ✨ Key Features
51
37
 
52
- ### With Custom Configuration
38
+ - 🎯 **Smart Click Capture**: Tracks interactions on interactive elements with built-in throttling logic.
39
+ - 🚨 **Global Error Management**: Captures uncaught exceptions (`window.onerror`) and promise rejections.
40
+ - 🌐 **Network Monitoring**: Intercepts `fetch` calls for full API visibility.
41
+ - 🛡️ **PII Masking & ANSI Cleaning**: Automatically protects sensitive data (emails, cards, tokens).
42
+ - 🎲 **Probabilistic Sampling**: Controls the volume of data sent to optimize costs and traffic.
43
+ - 💾 **Offline Resilience**: Retry queue with *Exponential Backoff* and persistent storage via IndexedDB.
44
+ - 📦 **Native Tree Shaking**: Modular architecture that allows you to include only the interceptors you truly need.
53
45
 
54
- ```javascript
55
- import syntropyFront from '@syntropysoft/syntropyfront';
56
-
57
- // Option 1: Console only (default)
58
- syntropyFront.configure({
59
- maxEvents: 50
60
- });
61
-
62
- // Option 2: With endpoint (automatic fetch)
63
- syntropyFront.configure({
64
- maxEvents: 50,
65
- fetch: {
66
- url: 'https://your-api.com/errors',
67
- options: {
68
- headers: {
69
- 'Authorization': 'Bearer your-token',
70
- 'Content-Type': 'application/json'
71
- },
72
- mode: 'cors'
73
- }
74
- }
75
- });
76
-
77
- // Option 3: With custom error handler (maximum flexibility)
78
- syntropyFront.configure({
79
- maxEvents: 50,
80
- onError: (errorPayload) => {
81
- // You can do anything with the error:
82
- // - Send to your API
83
- // - Save to localStorage
84
- // - Send to a repository
85
- // - Upload to cloud
86
- // - Whatever you want!
87
- console.log('Error captured:', errorPayload);
88
-
89
- // Example: send to multiple places
90
- fetch('https://api1.com/errors', {
91
- method: 'POST',
92
- body: JSON.stringify(errorPayload)
93
- });
94
-
95
- // Also save locally
96
- localStorage.setItem('lastError', JSON.stringify(errorPayload));
97
- }
98
- });
99
- ```
46
+ ## 🚀 Quick Start
100
47
 
101
- ## 📦 Installation
48
+ ### Installation
102
49
 
103
50
  ```bash
104
51
  pnpm add @syntropysoft/syntropyfront
105
52
  ```
106
53
 
107
- ## 🚀 **Quality & Performance (v0.4.3)**
108
-
109
- SyntropyFront has been optimized for maximum performance and minimal bundle size:
110
-
111
- ### **🎯 Testing Excellence**
112
- - **Mutation Score**: **71.03%** (Total) / **80.02%** (Covered) verified with Stryker
113
- - **Test Coverage**: **81.47% Branch Coverage** (90.07% Lines)
114
- - **430+ Comprehensive Tests**: Covering all edge cases and resilience scenarios
115
- - **Database Modules**: All modules now have 77-100% mutation score
116
- - **Core Components**: 92.70% average mutation score across agent modules
117
-
118
- ### **📦 Ultra-Lightweight Bundle**
119
- - **Zero Runtime Dependencies**: No more external requirements.
120
- - **Bundle Size**: **34 KB** minified (fully featured with offline support)
121
- - **ES Module**: 80 KB (unminified)
122
- - **Zero Runtime Dependencies**: Near-instant installation and minimal noise
123
-
124
- ### **🔧 Smart Dependency Management**
125
- - **Clean Architecture**: All testing tools properly categorized as devDependencies
126
- - **Dependabot Optimized**: Smart configuration prevents incompatible updates
127
- - **Stable CI/CD**: Eliminated dependency conflicts and CI failures
128
- - **Cross-Node Compatibility**: Full support for Node.js 18, 20, 22
129
-
130
- ### **⚡ Production Ready**
131
- - **Zero Breaking Changes**: All existing code continues to work
132
- - **Same API**: Identical usage patterns and configuration
133
- - **Better Performance**: Optimized for production environments
134
- - **Maintained Security**: All security benefits preserved
135
-
136
- ## 🎯 How It Works
137
-
138
- SyntropyFront automatically:
139
-
140
- 1. **Captures clicks** - Records element info, coordinates, and timestamps
141
- 2. **Detects errors** - Intercepts `window.onerror` and `window.onunhandledrejection`
142
- 3. **Monitors HTTP** - Wraps `window.fetch` to track requests and responses
143
- 4. **Logs console** - Intercepts console methods to capture debug info
144
- 5. **Maintains context** - Keeps the last N events as breadcrumbs
145
- 6. **Posts errors** - Sends error data with full context to your endpoint
146
-
147
- ## 📊 What Gets Captured
148
-
149
- ### Error Payload Structure
150
-
151
- ```json
152
- {
153
- "type": "uncaught_exception",
154
- "error": {
155
- "message": "Error message",
156
- "source": "file.js",
157
- "lineno": 42,
158
- "colno": 15,
159
- "stack": "Error stack trace..."
160
- },
161
- "breadcrumbs": [
162
- {
163
- "category": "user",
164
- "message": "click",
165
- "data": {
166
- "element": "BUTTON",
167
- "id": "submit-btn",
168
- "className": "btn-primary",
169
- "x": 100,
170
- "y": 200
171
- },
172
- "timestamp": "2024-01-01T12:00:00.000Z"
173
- }
174
- ],
175
- "timestamp": "2024-01-01T12:00:00.000Z"
176
- }
177
- ```
178
-
179
- ### Breadcrumb Categories
180
-
181
- - **`user`** - Click events, form submissions, etc.
182
- - **`http`** - Fetch requests, responses, and errors
183
- - **`console`** - Console.log, console.error, console.warn
184
- - **`error`** - Manual error reports
185
-
186
- ## ⚙️ Configuration Options
187
-
188
- SyntropyFront uses a priority system for error handling:
189
-
190
- 1. **Custom Error Handler** (`onError`) - Maximum flexibility
191
- 2. **Endpoint** (`fetch`) - Automatic posting
192
- 3. **Console** - Default fallback
193
-
194
- ### Basic Configuration (Console Only)
195
-
196
- ```javascript
197
- syntropyFront.configure({
198
- maxEvents: 50 // Number of events to keep in memory
199
- });
200
- ```
201
-
202
- ### With Endpoint (Automatic Fetch)
54
+ ### Basic Usage (Zero Config)
203
55
 
204
- ```javascript
205
- syntropyFront.configure({
206
- maxEvents: 50,
207
- fetch: {
208
- url: 'https://your-api.com/errors',
209
- options: {
210
- headers: {
211
- 'Authorization': 'Bearer your-token',
212
- 'X-API-Key': 'your-api-key',
213
- 'Content-Type': 'application/json'
214
- },
215
- mode: 'cors',
216
- credentials: 'include'
217
- }
218
- }
219
- });
220
- ```
221
-
222
- ### With Custom Error Handler (Maximum Flexibility)
56
+ Simply import the library in your application's entry point:
223
57
 
224
58
  ```javascript
225
- syntropyFront.configure({
226
- maxEvents: 50,
227
- onError: (errorPayload) => {
228
- // You have complete control over what to do with the error
229
-
230
- // Send to your API
231
- fetch('https://your-api.com/errors', {
232
- method: 'POST',
233
- body: JSON.stringify(errorPayload)
234
- });
235
-
236
- // Save to localStorage
237
- localStorage.setItem('lastError', JSON.stringify(errorPayload));
238
-
239
- // Send to multiple services
240
- Promise.all([
241
- fetch('https://service1.com/errors', { method: 'POST', body: JSON.stringify(errorPayload) }),
242
- fetch('https://service2.com/errors', { method: 'POST', body: JSON.stringify(errorPayload) })
243
- ]);
244
-
245
- // Upload to cloud storage
246
- // Send to repository
247
- // Log to file
248
- // Whatever you want!
249
- }
250
- });
59
+ import syntropyFront from '@syntropysoft/syntropyfront';
60
+ // Done! SyntropyFront auto-initializes and starts capturing events.
251
61
  ```
252
62
 
253
- ## 🔧 API Reference
63
+ ## ⚙️ Advanced Configuration
254
64
 
255
- ### Core Methods
65
+ SyntropyFront is highly configurable to suit your production needs.
256
66
 
257
67
  ```javascript
258
- // Add custom breadcrumb
259
- syntropyFront.addBreadcrumb('user', 'Custom action', { data: 'value' });
260
-
261
- // Send manual error
262
- syntropyFront.sendError(new Error('Custom error'));
263
-
264
- // Get current breadcrumbs
265
- const breadcrumbs = syntropyFront.getBreadcrumbs();
266
-
267
- // Clear breadcrumbs
268
- syntropyFront.clearBreadcrumbs();
269
-
270
- // Get statistics
271
- const stats = syntropyFront.getStats();
272
- // Returns: { breadcrumbs: 5, errors: 2, isActive: true, maxEvents: 50, endpoint: 'console' }
273
- ```
274
-
275
- ## 🎯 Extending SyntropyFront
68
+ import syntropyFront from '@syntropysoft/syntropyfront';
276
69
 
277
- SyntropyFront captures the essentials by default, but you can extend it to capture any DOM events you want:
70
+ syntropyFront.configure({
71
+ // Your observability backend URL (optional, defaults to console logging)
72
+ endpoint: 'https://your-api.com/v1/telemetry',
73
+
74
+ // Custom headers for transmission
75
+ headers: {
76
+ 'Authorization': 'Bearer your-app-token',
77
+ 'X-Environment': 'production'
78
+ },
278
79
 
279
- ### Adding Custom Event Capture
80
+ // 🎲 SAMPLING: Only sends 10% of errors to save resources
81
+ samplingRate: 0.1,
280
82
 
281
- ```javascript
282
- import syntropyFront from '@syntropysoft/syntropyfront';
83
+ // 📦 BATCHING: Batch size and timeout before sending
84
+ batchSize: 10,
85
+ batchTimeout: 5000,
283
86
 
284
- // Add scroll tracking
285
- window.addEventListener('scroll', () => {
286
- syntropyFront.addBreadcrumb('user', 'scroll', {
287
- scrollY: window.scrollY,
288
- scrollX: window.scrollX
289
- });
290
- });
87
+ // 🛡️ SECURITY: Basic payload encryption (base64/rot13)
88
+ encrypt: true,
291
89
 
292
- // Add form submissions
293
- document.addEventListener('submit', (event) => {
294
- syntropyFront.addBreadcrumb('user', 'form_submit', {
295
- formId: event.target.id,
296
- formAction: event.target.action
297
- });
298
- });
90
+ // 💾 PERSISTENCE: Enable disk storage if the user is offline
91
+ usePersistentBuffer: true,
299
92
 
300
- // Add window resize
301
- window.addEventListener('resize', () => {
302
- syntropyFront.addBreadcrumb('system', 'window_resize', {
303
- width: window.innerWidth,
304
- height: window.innerHeight
305
- });
93
+ // Custom callback to handle the error before it is sent
94
+ onError: (payload) => {
95
+ console.warn('Error captured:', payload.type);
96
+ return payload; // You can modify the payload here if necessary
97
+ }
306
98
  });
307
-
308
- // Add custom business events
309
- function trackPurchase(productId, amount) {
310
- syntropyFront.addBreadcrumb('business', 'purchase', {
311
- productId,
312
- amount,
313
- timestamp: new Date().toISOString()
314
- });
315
- }
316
99
  ```
317
100
 
318
- ### Common Events You Can Track
101
+ ## 🕹️ Event Capture & Custom Events
319
102
 
320
- - **User interactions**: `click`, `scroll`, `keydown`, `focus`, `blur`
321
- - **Form events**: `submit`, `input`, `change`, `reset`
322
- - **System events**: `resize`, `online`, `offline`, `visibilitychange`
323
- - **Custom events**: Any business logic or user actions
324
- - **Performance**: `load`, `DOMContentLoaded`, timing events
103
+ SyntropyFront provides both automatic tracking and manual tools to enrich your observability data.
325
104
 
326
- ## 🌐 CORS Configuration
105
+ ### 🤖 Automatic Capture
106
+ By default, the following interceptors are initialized:
107
+ - **UI Clicks**: Captures clicks on interactive elements (buttons, links, etc.) with smart selection logic.
108
+ - **Network**: Intercepts `fetch` calls, logging requests and responses (without sensitive headers).
109
+ - **Errors**: Catch-all for uncaught exceptions and unhandled promise rejections.
327
110
 
328
- To use with your API, ensure your server allows CORS:
111
+ ### 🛠️ Custom Breadcrumbs
112
+ Breadcrumbs are a timeline of events that help you understand what happened before an error occurred. You can add your own milestones:
329
113
 
330
114
  ```javascript
331
- // Express.js example
332
- app.use(cors({
333
- origin: 'http://localhost:3000',
334
- credentials: true
335
- }));
336
-
337
- // Or in headers
338
- res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
339
- res.setHeader('Access-Control-Allow-Methods', 'POST');
340
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
341
- ```
342
-
343
- ## 📱 Framework Support
344
-
345
- SyntropyFront works with any JavaScript framework:
346
-
347
- - ✅ **React** - Works out of the box
348
- - ✅ **Vue** - Works out of the box
349
- - ✅ **Angular** - Works out of the box
350
- - ✅ **Svelte** - Works out of the box
351
- - ✅ **Vanilla JS** - Works out of the box
352
-
353
- ## 🎯 Examples
354
-
355
- ### React Example
356
-
357
- ```jsx
358
- import React from 'react';
359
115
  import syntropyFront from '@syntropysoft/syntropyfront';
360
116
 
361
- function App() {
362
- // SyntropyFront auto-initializes on import
363
- return (
364
- <div>
365
- <button onClick={() => console.log('Button clicked')}>
366
- Click me!
367
- </button>
368
- </div>
369
- );
370
- }
371
- ```
372
-
373
- ### Vue Example
374
-
375
- ```vue
376
- <template>
377
- <button @click="handleClick">Click me!</button>
378
- </template>
379
-
380
- <script>
381
- import syntropyFront from '@syntropysoft/syntropyfront';
117
+ // Simple breadcrumb
118
+ syntropyFront.addBreadcrumb('auth', 'User logged in successfully');
382
119
 
383
- export default {
384
- methods: {
385
- handleClick() {
386
- console.log('Button clicked');
387
- }
388
- }
389
- }
390
- </script>
120
+ // Breadcrumb with data
121
+ syntropyFront.addBreadcrumb('commerce', 'Item added to cart', {
122
+ productId: 'abc-123',
123
+ price: 49.99,
124
+ currency: 'USD'
125
+ });
391
126
  ```
392
127
 
393
- ### Manual Error Reporting
128
+ ### 🚨 Manual Error Reporting
129
+ You can manually send errors that you catch in your own `try/catch` blocks:
394
130
 
395
131
  ```javascript
396
- import syntropyFront from '@syntropysoft/syntropyfront';
397
-
398
132
  try {
399
- // Your code here
133
+ performRiskyOperation();
400
134
  } catch (error) {
401
- // SyntropyFront will automatically capture this
402
- throw error;
135
+ syntropyFront.sendError(error, {
136
+ severity: 'critical',
137
+ userId: 'user_99'
138
+ });
403
139
  }
404
-
405
- // Or manually report
406
- syntropyFront.sendError(new Error('Something went wrong'));
407
140
  ```
408
141
 
409
- ### Extending with Custom Events
410
-
411
- ```javascript
412
- import syntropyFront from '@syntropysoft/syntropyfront';
142
+ ---
413
143
 
414
- // Add your custom event listeners
415
- window.addEventListener('scroll', () => {
416
- syntropyFront.addBreadcrumb('user', 'scroll', {
417
- scrollY: window.scrollY,
418
- scrollX: window.scrollX
419
- });
420
- });
144
+ ## 🛡️ Sensitive Data Protection (PII Masking)
421
145
 
422
- // Track business events
423
- function userCompletedCheckout(orderId, total) {
424
- syntropyFront.addBreadcrumb('business', 'checkout_completed', {
425
- orderId,
426
- total,
427
- timestamp: new Date().toISOString()
428
- });
429
- }
146
+ SyntropyFront automatically protects your users' privacy. The `DataMaskingManager` detects and obfuscates:
147
+ - Email addresses (`j***@example.com`)
148
+ - Authentication tokens and passwords
149
+ - Credit card numbers (keeps only the last 4 digits)
150
+ - SSN and phone numbers
430
151
 
431
- // Track performance
432
- window.addEventListener('load', () => {
433
- syntropyFront.addBreadcrumb('performance', 'page_loaded', {
434
- loadTime: performance.now()
435
- });
152
+ ### Custom Rules Configuration
153
+ ```javascript
154
+ syntropyFront.configure({
155
+ maskingRules: [
156
+ {
157
+ pattern: /custom_id_\d+/i,
158
+ mask: 'HIDDEN_ID'
159
+ }
160
+ ]
436
161
  });
437
162
  ```
438
163
 
439
- ## 🏗️ Architecture & Code Quality
440
-
441
- SyntropyFront follows SOLID principles and maintains high code quality through:
164
+ ## 🏗️ Modular Architecture and Tree Shaking
442
165
 
443
- ### Modular Architecture
166
+ In a future version (e.g. 0.5.0), interceptors may be exposed as independent modules. To minimize your bundle size, you would then import only what you need:
444
167
 
445
- The codebase is organized into focused modules with single responsibilities:
446
-
447
- ```
448
- src/core/
449
- ├── agent/ # Core Agent components
450
- │ ├── Agent.js # Main coordinator
451
- │ ├── ConfigurationManager.js # Configuration handling
452
- │ ├── QueueManager.js # Batching and queuing
453
- │ └── HttpTransport.js # HTTP communication
454
- ├── database/ # IndexedDB management
455
- │ ├── DatabaseManager.js # Database coordinator
456
- │ ├── DatabaseConfigManager.js # Configuration
457
- │ ├── DatabaseConnectionManager.js # Connection handling
458
- │ ├── DatabaseTransactionManager.js # Transaction management
459
- │ ├── StorageManager.js # CRUD operations
460
- │ └── SerializationManager.js # Data serialization
461
- ├── retry/ # Retry system
462
- │ ├── RetryManager.js # Retry coordination
463
- │ └── RetryLogicManager.js # Retry logic
464
- ├── persistent/ # Persistent buffer
465
- │ └── PersistentBufferManager.js # Buffer management
466
- ├── breadcrumbs/ # Event tracking
467
- │ ├── BreadcrumbManager.js # Breadcrumb coordination
468
- │ └── BreadcrumbStore.js # Breadcrumb storage
469
- ├── context/ # Context collection
470
- │ └── ContextCollector.js # Context gathering
471
- └── utils/ # Utilities
472
- ├── Logger.js # Logging utilities
473
- └── ErrorManager.js # Error handling
168
+ ```javascript
169
+ // Instead of global import, use specific interceptors directly
170
+ // (Coming soon in the granular export API)
474
171
  ```
475
172
 
476
- ### Design Principles
477
-
478
- - **Single Responsibility Principle (SRP)**: Each class has one clear purpose
479
- - **Dependency Injection**: Components receive dependencies through constructors
480
- - **Declarative Error Handling**: Structured error responses with fallbacks
481
- - **Comprehensive Testing**: 430+ tests with 71.03% mutation score
482
- - **Optimized Performance**: Timeouts optimized for faster execution
173
+ ### Core Structure
174
+ The system is divided into managers with unique responsibilities:
175
+ - **QueueManager**: Manages batching and output flow.
176
+ - **RetryManager**: Handles smart retries with incremental waits.
177
+ - **SerializationManager**: Ensures data is safe for transmission over the network.
178
+ - **ContextCollector**: Collects device information and user environment context.
483
179
 
484
- ## 🧪 Testing & Quality
180
+ ## 📊 Quality Metrics
485
181
 
486
- SyntropyFront maintains high code quality through comprehensive testing:
182
+ We take stability seriously. SyntropyFront maintains:
183
+ - **Test Coverage**: **87%** (All files).
184
+ - **Stryker Mutation Score**: **>71%** (Our tests truly verify logic, they don't just "pass through" it).
185
+ - **Zero Dependencies**: We don't add third-party vulnerabilities to your project.
487
186
 
488
- ### Test Coverage & Mutation Testing
187
+ ## 📖 API Reference
489
188
 
490
- - **Mutation Score**: 71.03% - Our tests effectively detect code changes
491
- - **Test Coverage**: 89.47% (Statements) / 81.47% (Branches)
492
- - **Key Components Performance**:
493
- - `Agent.js`: 87.23% mutation score
494
- - `ConfigurationManager.js`: 100% mutation score
495
- - `QueueManager.js`: 97.37% mutation score
496
- - `HttpTransport.js`: 86.96% mutation score
497
- - `BreadcrumbManager.js`: 100% mutation score
498
- - `BreadcrumbStore.js`: 95.00% mutation score
499
- - `SerializationManager.js`: 100% mutation score
500
- - `DatabaseTransactionManager.js`: 100% mutation score
501
- - `DatabaseConfigManager.js`: 86.89% mutation score
502
- - `DatabaseConnectionManager.js`: 85.96% mutation score
503
- - `PersistentBufferManager.js`: 77.63% mutation score
504
- - `RobustSerializer.js`: 73.36% mutation score
189
+ ### `syntropyFront.configure(config)`
190
+ Updates the global configuration of the agent.
505
191
 
506
- ### Testing Stack
192
+ ### `syntropyFront.addBreadcrumb(category, message, data)`
193
+ Adds a manual milestone to the timeline.
194
+ - `category`: String (e.g., 'auth', 'ui', 'action')
195
+ - `message`: Description of the event.
196
+ - `data`: (Optional) Object with additional metadata.
507
197
 
508
- - **Jest**: Unit testing framework
509
- - **Stryker**: Mutation testing for test quality validation
510
- - **IndexedDB Mocking**: Browser storage testing
511
- - **Fetch Mocking**: HTTP request testing
198
+ ### `syntropyFront.sendError(error, context)`
199
+ Manually reports an error.
200
+ - `error`: Error object or string.
201
+ - `context`: (Optional) Additional data to send with this specific error.
512
202
 
513
- ### Running Tests
203
+ ### `syntropyFront.flush()`
204
+ Forces the immediate sending of all pending events in the queue.
514
205
 
515
- ```bash
516
- # Run all tests
517
- npm test
206
+ ### `syntropyFront.getBreadcrumbs()`
207
+ Returns the list of current breadcrumbs in memory.
518
208
 
519
- # Run with coverage
520
- npm run test:coverage
209
+ ### `syntropyFront.clearBreadcrumbs()`
210
+ Clears the temporary breadcrumb history.
521
211
 
522
- # Run mutation testing
523
- npm run test:mutation
524
- ```
212
+ ### `syntropyFront.getStats()`
213
+ Returns an object with library performance statistics (queue length, retry status, etc.).
525
214
 
215
+ ### `syntropyFront.destroy()`
216
+ Deactivates all interceptors and stops the agent.
526
217
 
527
- ## 🛡️ Security & Privacy
528
-
529
- SyntropyFront is designed with security and transparency in mind:
530
-
531
- - **Network Access**: Telemetry is sent **only** to the endpoint you configure via `configure({ fetch: { url: '...' } })`. By default, it only logs to the browser console.
532
- - **No Third-Party Tracking**: We don't include any tracking or analytics scripts. Your data is yours.
533
- - **PII Protection**: Breadcrumbs focus on technical context. We recommend using a custom `onError` handler to scrub sensitive data if necessary.
534
- - **Zero Runtime Dependencies**: Minimizes the attack surface by not relying on external code at runtime.
218
+ ---
535
219
 
536
- ## 🔍 Debugging
220
+ ## 🔍 Advanced Context Collection
537
221
 
538
- SyntropyFront logs helpful information to the console:
222
+ You can precisely control what environment data is collected when an error occurs.
539
223
 
224
+ ```javascript
225
+ syntropyFront.configure({
226
+ context: {
227
+ // Collect all default fields for these types
228
+ device: true,
229
+ network: true,
230
+
231
+ // Collect ONLY specific fields
232
+ window: ['url', 'title', 'viewport'],
233
+ performance: ['memory'],
234
+
235
+ // Explicitly disable a type
236
+ storage: false
237
+ }
238
+ });
540
239
  ```
541
- 🚀 SyntropyFront: Initialized with automatic capture
542
- ✅ SyntropyFront: Configured - maxEvents: 50, endpoint: https://your-api.com/errors
543
- ❌ Error: { type: "uncaught_exception", error: {...}, breadcrumbs: [...] }
544
- ```
545
-
546
- ## 📄 License
547
240
 
548
- This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.
241
+ ### Available Context Fields
242
+ - **`device`**: `userAgent`, `language`, `screen`, `timezone`, `cookieEnabled`.
243
+ - **`window`**: `url`, `pathname`, `referrer`, `title`, `viewport`.
244
+ - **`storage`**: `localStorage`, `sessionStorage` (size and keys only, no values).
245
+ - **`network`**: `online`, `connection` (type, downlink).
246
+ - **`ui`**: `focused`, `visibility`, `activeElement`.
247
+ - **`performance`**: `memory` (heap usage), `timing`.
248
+ - **`session`**: `sessionId`, `startTime`, `pageLoadTime`.
249
+
250
+ ## 🛠️ Local Development
251
+
252
+ If you want to contribute or test the library locally:
253
+
254
+ 1. **Clone and Install**:
255
+ ```bash
256
+ git clone https://github.com/Syntropysoft/syntropyfront.git
257
+ cd syntropyfront
258
+ pnpm install
259
+ ```
260
+
261
+ 2. **Run Tests**:
262
+ ```bash
263
+ npm test # Run all tests
264
+ npm run test:watch # Watch mode
265
+ ```
266
+
267
+ 3. **Build**:
268
+ ```bash
269
+ npm run build
270
+ ```
549
271
 
550
- **Apache License 2.0** - A permissive license that allows for:
551
- - ✅ Commercial use
552
- - ✅ Modification
553
- - ✅ Distribution
554
- - ✅ Patent use
555
- - ✅ Private use
556
-
557
- The only requirement is that you include the original copyright notice and license text in any substantial portions of the software you distribute.
558
-
559
- For more information, visit: https://www.apache.org/licenses/LICENSE-2.0
560
-
561
- ## 🤝 Contributing
272
+ ## 📄 License
562
273
 
563
- Contributions are welcome! Please feel free to submit a Pull Request.
274
+ This project is licensed under the **Apache License 2.0**. You can freely use, modify, and distribute it in commercial projects.
564
275
 
565
276
  ---
566
277
 
567
- **Made with ❤️ for better web observability**
278
+ **Developed with ❤️ for a clearer and more stable web.**