@pixora-dev-ai/dev-sentinel
Version:
๐ก๏ธ Enterprise-grade observability SDK for React applications. Real-time diagnostics with 14+ specialized packs: Network Intelligence, Security Guards, Privacy Protection, Code Quality Analysis, Device Monitoring, and more.
385 lines (288 loc) โข 10.2 kB
Markdown
# ๐ก๏ธ Dev-Sentinel
[](https://www.npmjs.com/package/@prepilot/dev-sentinel)
[](https://opensource.org/licenses/MIT)
[](https://www.typescriptlang.org/)
> **Enterprise-grade observability SDK for React applications**
> Real-time diagnostics, intelligent monitoring, and advanced debugging tools for modern web applications.
## ๐ Why Dev-Sentinel?
Dev-Sentinel is not just another logging library. It's a **comprehensive observability platform** that gives you:
โ
**14+ Specialized Monitoring Packs** - Network, Security, Privacy, Performance, Testing, and more
โ
**Zero Runtime Overhead in Production** - Only runs in development mode
โ
**Smart AI-Assisted Analysis** - Detect code smells, patterns, and anti-patterns automatically
โ
**Visual Dev Panel** - Beautiful UI to inspect all diagnostics in real-time
โ
**Export & Share** - Download logs as JSON for debugging with your team
โ
**Framework Agnostic Core** - Works with React, Vite, and modern build tools
โ
**Privacy-First** - Built-in PII redaction and sensitive data protection
## ๐ฆ Installation
```bash
# npm
npm install @prepilot/dev-sentinel
# yarn
yarn add @prepilot/dev-sentinel
# pnpm
pnpm add @prepilot/dev-sentinel
```
## โก Quick Start
### 1. Basic Setup
```typescript
import { devSentinel } from '@prepilot/dev-sentinel';
// Log an event
devSentinel.log('network_request', {
url: '/api/users',
method: 'GET',
status: 200,
duration: 234
});
// Subscribe to events
const unsubscribe = devSentinel.subscribe((event) => {
console.log('New event:', event);
});
```
### 2. With React Components
```tsx
import { useEffect } from 'react';
import { devSentinel } from '@prepilot/dev-sentinel';
function App() {
useEffect(() => {
// Hydrate logs from IndexedDB
devSentinel.hydrateFromDb();
// Subscribe to runtime events
const unsubscribe = devSentinel.subscribe((event) => {
console.log('Event logged:', event);
});
return () => unsubscribe();
}, []);
return <YourApp />;
}
```
### 3. Enable Privacy Protection
```typescript
import {
devSentinel,
configureDevSentinelRedaction,
defaultDevSentinelRedactor
} from '@prepilot/dev-sentinel';
// Use default redactor (removes emails, tokens, passwords, etc.)
configureDevSentinelRedaction(defaultDevSentinelRedactor);
// Or create custom redactor
import { createRedactor } from '@prepilot/dev-sentinel';
const customRedactor = createRedactor({
piiPatterns: [
/\b\d{3}-\d{2}-\d{4}\b/g, // SSN
/\b\d{16}\b/g // Credit cards
],
tokenPatterns: [
/Bearer\s+[\w-]+/gi,
/api[_-]?key[\s:=]+[\w-]+/gi
]
});
configureDevSentinelRedaction(customRedactor);
```
## ๐ Available Packs
Dev-Sentinel organizes monitoring capabilities into specialized **Packs**:
| Pack | Description | Key Features |
|------|-------------|--------------|
| ๐ **Network Pack** | API monitoring & diagnostics | Endpoint health, waterfall analysis, retry tracking |
| ๐งช **Testing Pack** | Runtime test intelligence | Flaky tests, race conditions, coverage gaps |
| ๐จ **Design Pack** | UI/UX quality monitoring | Layout shifts, responsive issues, contrast errors |
| ๐ **Secure-UI Pack** | Fraud & abuse detection | Click injection, autofill abuse, brute-force detection |
| ๐ **Privacy Guard Pack** | PII protection | Console leaks, storage issues, analytics protection |
| ๐ฑ **Device Pack** | Hardware diagnostics | CPU throttling, memory pressure, battery saver |
| ๐ **Environment Pack** | Runtime environment tracking | OS detection, browser info, WebView detection |
| ๐ง **Code Smell Pack** | AI-powered code analysis | Duplicate logic, props explosion, anti-patterns |
| ๐ **Regression Pack** | Issue tracking & history | Novel issues, fingerprints, frequency spikes |
| ๐ **Auth & Session Pack** | Authentication flow monitoring | Token issues, logout problems, multi-tab sync |
| ๐ค **AI Agent Pack** | LLM interaction monitoring | Prompt tracking, hallucination detection, context overhead |
| ๐ **SaaS Metrics Pack** | Product analytics | Funnel analysis, friction detection, time-to-value |
| โฟ **A11y Interaction Pack** | Accessibility UX tracking | Rage clicks, dead taps, small tap targets |
| ๐ฉ **Feature Flag Pack** | Flag management monitoring | Misconfigurations, conflicts, flag drift |
## ๐ฏ Core API
### Logging Events
```typescript
// Basic logging
await devSentinel.log('network_request', payload);
// Network-specific
await devSentinel.log('endpoint_health_update', {
endpoint: '/api/users',
health: 'degraded'
});
// Security events
await devSentinel.log('secure_ui_brute_force_indicator', {
attempts: 5,
ip: '192.168.1.1'
});
// Privacy events
await devSentinel.log('privacy_console_pii_leak', {
message: 'User email detected in console'
});
```
### Retrieving Logs
```typescript
// Get all logs
const allLogs = await devSentinel.get();
// Get specific event type
const networkLogs = await devSentinel.getNetwork('network_request');
const securityLogs = await devSentinel.getSecureUi('secure_ui_click_injection_pattern');
const privacyLogs = await devSentinel.getPrivacy('privacy_storage_pii_issue');
const deviceLogs = await devSentinel.getDevice('device_issue');
```
### Subscribing to Events
```typescript
// Subscribe to all events
const unsubAll = devSentinel.subscribe((event) => {
console.log('Event:', event);
});
// Subscribe to network events only
const unsubNetwork = devSentinel.subscribeNetwork((event) => {
console.log('Network event:', event);
});
// Subscribe to security events
const unsubSecurity = devSentinel.subscribeSecureUi((event) => {
console.log('Security event:', event);
});
// Subscribe to privacy events
const unsubPrivacy = devSentinel.subscribePrivacy((event) => {
console.log('Privacy event:', event);
});
// Clean up
unsubAll();
unsubNetwork();
```
### Clearing Logs
```typescript
// Clear all design logs
await devSentinel.clear();
// Clear specific event type
await devSentinel.clearNetwork('network_request');
await devSentinel.clearSecureUi('secure_ui_brute_force_indicator');
await devSentinel.clearPrivacy('privacy_console_pii_leak');
```
## ๐จ Dev Panel Integration
Dev-Sentinel includes a beautiful **Dev Panel** component for visualizing diagnostics:
```tsx
import { DevPanel } from '@prepilot/dev-sentinel/ui';
function App() {
return (
<>
<YourApp />
{import.meta.env.DEV && <DevPanel />}
</>
);
}
```
**Features:**
- ๐ Real-time event streaming
- ๐ Advanced filtering by pack and event type
- ๐ฅ Export logs as JSON
- ๐ฏ Click to inspect detailed payloads
- ๐จ Beautiful UI with syntax highlighting
- ๐ Dark mode support
## ๐ง Advanced Usage
### Custom Event Types
```typescript
import type { StoredLog } from '@prepilot/dev-sentinel';
interface CustomPayload {
userId: string;
action: string;
metadata: Record<string, unknown>;
}
await devSentinel.log('custom_event_type' as any, {
userId: 'user-123',
action: 'clicked_button',
metadata: { page: 'dashboard' }
} as CustomPayload);
```
### Hydration from IndexedDB
```typescript
// Hydrate all stores on app init
await Promise.all([
devSentinel.hydrateFromDb(),
devSentinel.hydrateCodeSmellFromDb(),
devSentinel.hydrateSecureUiFromDb(),
devSentinel.hydratePrivacyFromDb(),
devSentinel.hydrateDeviceFromDb(),
devSentinel.hydrateEnvFromDb()
]);
```
### TypeScript Support
Full TypeScript support with comprehensive type definitions:
```typescript
import type {
NetworkEventType,
TestingEventType,
CodeSmellEventType,
SecureUiEventType,
PrivacyEventType,
DeviceEventType,
EnvironmentEventType,
StoredLog
} from '@prepilot/dev-sentinel';
```
## ๐๏ธ Architecture
Dev-Sentinel uses a **modular store architecture**:
```
devSentinel (main)
โโโ SentinelStore (design events)
โโโ NetworkEventStore (network events)
โโโ CodeSmellStore (code quality events)
โโโ SecureUiStore (security events)
โโโ PrivacyStore (privacy events)
โโโ DeviceEventStore (device events)
โโโ EnvironmentEventStore (environment events)
```
Each store:
- โ
Persists to **IndexedDB** automatically
- โ
Provides **reactive subscriptions**
- โ
Supports **filtering and clearing**
- โ
Implements **hydration** from storage
## ๐ Privacy & Security
Dev-Sentinel takes privacy seriously:
- ๐ซ **Never runs in production** (checks `import.meta.env.DEV`)
- ๐ **Built-in PII redaction** for emails, tokens, passwords
- ๐ก๏ธ **Customizable redaction rules**
- ๐ **Local-only storage** (IndexedDB, no external calls)
- ๐ **Privacy Guard Pack** detects accidental PII leaks
## ๐ Documentation
Comprehensive documentation for each pack:
- [Network Pack Guide](./docs/Network_Pack_Overview.md)
- [Testing Pack Guide](./docs/Testing_Pack_Overview.md)
- [Secure-UI Pack Guide](./docs/SecureUI_Pack_Overview.md)
- [Privacy Guard Guide](./docs/Privacy_Guard_Overview.md)
- [Code Smell Pack Guide](./docs/CodeSmell_Pack_Overview.md)
- [Device & Environment Pack Guide](./docs/Device_Environment_Pack.md)
- [Regression Pack Guide](./docs/Regression_Pack_Overview.md)
- [Integration Guide](./docs/INTEGRATION_GUIDE.md)
## ๐ค Contributing
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
## ๐ License
MIT ยฉ PrePilot Team
## ๐ Acknowledgments
Built with:
- React Error Boundary
- IndexedDB
- TypeScript
- Zod (for schema validation)
## ๐ง Support
- ๐ [Report Issues](https://github.com/prepilot/dev-sentinel/issues)
- ๐ฌ [Discussions](https://github.com/prepilot/dev-sentinel/discussions)
- ๐ [Documentation](https://github.com/prepilot/dev-sentinel/wiki)
<div align="center">
<strong>Made with โค๏ธ by the PrePilot Team</strong>
<br />
<sub>Elevating developer experience, one diagnostic at a time.</sub>
</div>