@samimcodes/ai-shield 0.1.2 → 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.
@@ -204,6 +204,51 @@ interface AiShieldOptions {
204
204
  * Defaults to 'https://telemetry.ai-shield.dev/v1/events'.
205
205
  */
206
206
  dashboardUrl?: string | undefined;
207
+ /**
208
+ * When `true`, enables a self-contained live real-time security dashboard
209
+ * with live alerts and event stream directly in your Express app.
210
+ * Defaults to `false`.
211
+ */
212
+ enableDashboard?: boolean | undefined;
213
+ /**
214
+ * Route prefix where the live security dashboard will be mounted.
215
+ * Defaults to `'/admin/ai-shield'`.
216
+ */
217
+ dashboardPath?: string | undefined;
218
+ /**
219
+ * Optional authentication credentials to secure the dashboard.
220
+ */
221
+ dashboardAuth?: DashboardAuthConfig | undefined;
222
+ }
223
+ /** Optional authentication credentials for the built-in dashboard. */
224
+ interface DashboardAuthConfig {
225
+ username?: string | undefined;
226
+ password?: string | undefined;
227
+ token?: string | undefined;
228
+ }
229
+ /** Individual live security event displayed on the dashboard. */
230
+ interface DashboardSecurityEvent {
231
+ id: string;
232
+ timestamp: string;
233
+ botName: string;
234
+ category: BotCategory;
235
+ path: string;
236
+ score: number;
237
+ signals: DetectionSignal[];
238
+ ipHash: string;
239
+ userAgent: string;
240
+ action: 'POISON_HTML' | 'POISON_JSON' | 'POISON_SITEMAP' | 'HONEYPOT_TRAP' | 'SIMULATED_TEST';
241
+ }
242
+ /** Real-time statistics aggregated by the dashboard manager. */
243
+ interface DashboardStats {
244
+ totalRequests: number;
245
+ botsIntercepted: number;
246
+ goodBotsAllowed: number;
247
+ honeypotTriggers: number;
248
+ poisonPayloadsServed: number;
249
+ estimatedFakeTokens: number;
250
+ topBots: Record<string, number>;
251
+ topRoutes: Record<string, number>;
207
252
  }
208
253
  /** Telemetry event record emitted when bots/scrapers are trapped or poisoned. */
209
254
  interface TelemetryEvent {
@@ -287,6 +332,62 @@ declare class TelemetryEmitter {
287
332
  destroy(): Promise<void>;
288
333
  }
289
334
 
335
+ /**
336
+ * @file src/core/dashboard.ts
337
+ * @description Built-in live real-time security dashboard and SSE event broadcaster.
338
+ *
339
+ * Provides developers with an out-of-the-box, zero-dependency, ultra-sleek
340
+ * admin monitoring interface to watch AI bots being intercepted, poisoned,
341
+ * and trapped in real-time right on their own server.
342
+ */
343
+
344
+ interface DashboardManagerOptions {
345
+ basePath?: string | undefined;
346
+ auth?: DashboardAuthConfig | undefined;
347
+ maxStoredEvents?: number | undefined;
348
+ debug?: boolean | undefined;
349
+ }
350
+ declare class DashboardManager {
351
+ private readonly basePath;
352
+ private readonly auth;
353
+ private readonly maxStoredEvents;
354
+ private readonly debug;
355
+ private events;
356
+ private sseClients;
357
+ private heartbeatTimer;
358
+ private stats;
359
+ constructor(options?: DashboardManagerOptions);
360
+ /**
361
+ * Stop background timers and disconnect SSE clients (useful during teardown).
362
+ */
363
+ close(): void;
364
+ /** Record a normal or bot request to update total counters. */
365
+ recordRequest(): void;
366
+ /** Record a legitimate search engine pass-through (Googlebot, Bingbot, etc). */
367
+ recordGoodBot(botName: string, path: string): void;
368
+ /**
369
+ * Record an intercepted AI crawler or scraper, update stats,
370
+ * prepend to event log, and push to all active SSE browser tabs.
371
+ */
372
+ recordEvent(event: Omit<DashboardSecurityEvent, 'id' | 'timestamp'> & {
373
+ timestamp?: string;
374
+ }): DashboardSecurityEvent;
375
+ /** Retrieve snapshot of current metrics. */
376
+ getStats(): DashboardStats;
377
+ /** Retrieve recent security events. */
378
+ getEvents(): DashboardSecurityEvent[];
379
+ /** Broadcast SSE event to all connected dashboard tabs. */
380
+ private broadcastEvent;
381
+ /** Broadcast periodic ping to keep SSE connections open through proxies. */
382
+ private broadcastPing;
383
+ /** Authenticate request if dashboardAuth is configured. */
384
+ private checkAuth;
385
+ /** Mount and return Express router serving the live dashboard and API. */
386
+ buildRouter(): Router;
387
+ /** Render self-contained, responsive, dark-mode single-page HTML dashboard. */
388
+ renderHtml(): string;
389
+ }
390
+
290
391
  /**
291
392
  * @file src/core/detector.ts
292
393
  * @description Multi-signal bot fingerprinting engine.
@@ -638,10 +739,11 @@ declare global {
638
739
  }
639
740
  }
640
741
  /**
641
- * Extended RequestHandler with attached telemetry subsystem.
742
+ * Extended RequestHandler with attached telemetry and dashboard subsystems.
642
743
  */
643
744
  interface AiShieldHandler extends RequestHandler {
644
745
  telemetry?: TelemetryEmitter | undefined;
746
+ dashboard?: DashboardManager | undefined;
645
747
  }
646
748
  /**
647
749
  * Create the ai-shield middleware stack.
@@ -654,4 +756,4 @@ interface AiShieldHandler extends RequestHandler {
654
756
  declare function createAiShield(options?: AiShieldOptions): AiShieldHandler;
655
757
  declare const aiShieldMiddleware: typeof createAiShield;
656
758
 
657
- export { type AiShieldOptions as A, BotCategory as B, CANONICAL_TRAP as C, DEFAULT_SIGNAL_WEIGHTS as D, type HoneypotRoute as H, IpTrapCache as I, type PoisonContentType as P, type ShieldOptions as S, TelemetryEmitter as T, type AiShieldRequestMeta as a, BotDetector as b, type BotFingerprint as c, Confidence as d, type DetectionResult as e, type DetectionSignal as f, HoneypotManager as g, PoisonEngine as h, type PoisonPayload as i, type SignalWeights as j, type TelemetryEvent as k, type TrapCacheEntry as l, aiShieldMiddleware as m, createAiShield as n, hashClientIp as o, type AiShieldHandler as p, syntheticTokenPublic as s };
759
+ export { type AiShieldOptions as A, BotCategory as B, CANONICAL_TRAP as C, DEFAULT_SIGNAL_WEIGHTS as D, type HoneypotRoute as H, IpTrapCache as I, type PoisonContentType as P, type ShieldOptions as S, TelemetryEmitter as T, type AiShieldRequestMeta as a, BotDetector as b, type BotFingerprint as c, Confidence as d, type DashboardAuthConfig as e, DashboardManager as f, type DashboardSecurityEvent as g, type DashboardStats as h, type DetectionResult as i, type DetectionSignal as j, HoneypotManager as k, PoisonEngine as l, type PoisonPayload as m, type SignalWeights as n, type TelemetryEvent as o, type TrapCacheEntry as p, aiShieldMiddleware as q, createAiShield as r, hashClientIp as s, syntheticTokenPublic as t, type AiShieldHandler as u };
@@ -204,6 +204,51 @@ interface AiShieldOptions {
204
204
  * Defaults to 'https://telemetry.ai-shield.dev/v1/events'.
205
205
  */
206
206
  dashboardUrl?: string | undefined;
207
+ /**
208
+ * When `true`, enables a self-contained live real-time security dashboard
209
+ * with live alerts and event stream directly in your Express app.
210
+ * Defaults to `false`.
211
+ */
212
+ enableDashboard?: boolean | undefined;
213
+ /**
214
+ * Route prefix where the live security dashboard will be mounted.
215
+ * Defaults to `'/admin/ai-shield'`.
216
+ */
217
+ dashboardPath?: string | undefined;
218
+ /**
219
+ * Optional authentication credentials to secure the dashboard.
220
+ */
221
+ dashboardAuth?: DashboardAuthConfig | undefined;
222
+ }
223
+ /** Optional authentication credentials for the built-in dashboard. */
224
+ interface DashboardAuthConfig {
225
+ username?: string | undefined;
226
+ password?: string | undefined;
227
+ token?: string | undefined;
228
+ }
229
+ /** Individual live security event displayed on the dashboard. */
230
+ interface DashboardSecurityEvent {
231
+ id: string;
232
+ timestamp: string;
233
+ botName: string;
234
+ category: BotCategory;
235
+ path: string;
236
+ score: number;
237
+ signals: DetectionSignal[];
238
+ ipHash: string;
239
+ userAgent: string;
240
+ action: 'POISON_HTML' | 'POISON_JSON' | 'POISON_SITEMAP' | 'HONEYPOT_TRAP' | 'SIMULATED_TEST';
241
+ }
242
+ /** Real-time statistics aggregated by the dashboard manager. */
243
+ interface DashboardStats {
244
+ totalRequests: number;
245
+ botsIntercepted: number;
246
+ goodBotsAllowed: number;
247
+ honeypotTriggers: number;
248
+ poisonPayloadsServed: number;
249
+ estimatedFakeTokens: number;
250
+ topBots: Record<string, number>;
251
+ topRoutes: Record<string, number>;
207
252
  }
208
253
  /** Telemetry event record emitted when bots/scrapers are trapped or poisoned. */
209
254
  interface TelemetryEvent {
@@ -287,6 +332,62 @@ declare class TelemetryEmitter {
287
332
  destroy(): Promise<void>;
288
333
  }
289
334
 
335
+ /**
336
+ * @file src/core/dashboard.ts
337
+ * @description Built-in live real-time security dashboard and SSE event broadcaster.
338
+ *
339
+ * Provides developers with an out-of-the-box, zero-dependency, ultra-sleek
340
+ * admin monitoring interface to watch AI bots being intercepted, poisoned,
341
+ * and trapped in real-time right on their own server.
342
+ */
343
+
344
+ interface DashboardManagerOptions {
345
+ basePath?: string | undefined;
346
+ auth?: DashboardAuthConfig | undefined;
347
+ maxStoredEvents?: number | undefined;
348
+ debug?: boolean | undefined;
349
+ }
350
+ declare class DashboardManager {
351
+ private readonly basePath;
352
+ private readonly auth;
353
+ private readonly maxStoredEvents;
354
+ private readonly debug;
355
+ private events;
356
+ private sseClients;
357
+ private heartbeatTimer;
358
+ private stats;
359
+ constructor(options?: DashboardManagerOptions);
360
+ /**
361
+ * Stop background timers and disconnect SSE clients (useful during teardown).
362
+ */
363
+ close(): void;
364
+ /** Record a normal or bot request to update total counters. */
365
+ recordRequest(): void;
366
+ /** Record a legitimate search engine pass-through (Googlebot, Bingbot, etc). */
367
+ recordGoodBot(botName: string, path: string): void;
368
+ /**
369
+ * Record an intercepted AI crawler or scraper, update stats,
370
+ * prepend to event log, and push to all active SSE browser tabs.
371
+ */
372
+ recordEvent(event: Omit<DashboardSecurityEvent, 'id' | 'timestamp'> & {
373
+ timestamp?: string;
374
+ }): DashboardSecurityEvent;
375
+ /** Retrieve snapshot of current metrics. */
376
+ getStats(): DashboardStats;
377
+ /** Retrieve recent security events. */
378
+ getEvents(): DashboardSecurityEvent[];
379
+ /** Broadcast SSE event to all connected dashboard tabs. */
380
+ private broadcastEvent;
381
+ /** Broadcast periodic ping to keep SSE connections open through proxies. */
382
+ private broadcastPing;
383
+ /** Authenticate request if dashboardAuth is configured. */
384
+ private checkAuth;
385
+ /** Mount and return Express router serving the live dashboard and API. */
386
+ buildRouter(): Router;
387
+ /** Render self-contained, responsive, dark-mode single-page HTML dashboard. */
388
+ renderHtml(): string;
389
+ }
390
+
290
391
  /**
291
392
  * @file src/core/detector.ts
292
393
  * @description Multi-signal bot fingerprinting engine.
@@ -638,10 +739,11 @@ declare global {
638
739
  }
639
740
  }
640
741
  /**
641
- * Extended RequestHandler with attached telemetry subsystem.
742
+ * Extended RequestHandler with attached telemetry and dashboard subsystems.
642
743
  */
643
744
  interface AiShieldHandler extends RequestHandler {
644
745
  telemetry?: TelemetryEmitter | undefined;
746
+ dashboard?: DashboardManager | undefined;
645
747
  }
646
748
  /**
647
749
  * Create the ai-shield middleware stack.
@@ -654,4 +756,4 @@ interface AiShieldHandler extends RequestHandler {
654
756
  declare function createAiShield(options?: AiShieldOptions): AiShieldHandler;
655
757
  declare const aiShieldMiddleware: typeof createAiShield;
656
758
 
657
- export { type AiShieldOptions as A, BotCategory as B, CANONICAL_TRAP as C, DEFAULT_SIGNAL_WEIGHTS as D, type HoneypotRoute as H, IpTrapCache as I, type PoisonContentType as P, type ShieldOptions as S, TelemetryEmitter as T, type AiShieldRequestMeta as a, BotDetector as b, type BotFingerprint as c, Confidence as d, type DetectionResult as e, type DetectionSignal as f, HoneypotManager as g, PoisonEngine as h, type PoisonPayload as i, type SignalWeights as j, type TelemetryEvent as k, type TrapCacheEntry as l, aiShieldMiddleware as m, createAiShield as n, hashClientIp as o, type AiShieldHandler as p, syntheticTokenPublic as s };
759
+ export { type AiShieldOptions as A, BotCategory as B, CANONICAL_TRAP as C, DEFAULT_SIGNAL_WEIGHTS as D, type HoneypotRoute as H, IpTrapCache as I, type PoisonContentType as P, type ShieldOptions as S, TelemetryEmitter as T, type AiShieldRequestMeta as a, BotDetector as b, type BotFingerprint as c, Confidence as d, type DashboardAuthConfig as e, DashboardManager as f, type DashboardSecurityEvent as g, type DashboardStats as h, type DetectionResult as i, type DetectionSignal as j, HoneypotManager as k, PoisonEngine as l, type PoisonPayload as m, type SignalWeights as n, type TelemetryEvent as o, type TrapCacheEntry as p, aiShieldMiddleware as q, createAiShield as r, hashClientIp as s, syntheticTokenPublic as t, type AiShieldHandler as u };