How wispayr/protect-night-watch works
protect-night-watch is a scheduled or one-shot overnight UniFi Protect reporting tool. Its main workflow is to define a timezone-aware night window, fetch and filter smart-detection events, cluster them into incidents, render a PDF with optional stills, save it, and email it. The graph includes the CLI/check paths and offline demo capability. Edges reflect shown calls or documented behavior; unsampled details, including precise persistence and scheduling internals, are not inferred.
Main entry points: run.ts Run coordinator · index.ts CLI and scheduler · mailer.ts Email delivery · client.ts Protect client
Components 15
Entry and configuration
- CLI and scheduler
src/index.ts - Configuration
src/config.ts - Logging
src/logger.ts - Run coordinator
src/run.ts
Protect data
- Protect client
src/protect/client.ts - UniFi Protect
- Detection and incident models
src/protect/types.ts - Synthetic report data
src/demo.ts
Report generation
- Night window
src/report/window.ts - Filter and aggregate
src/report/aggregate.ts - PDF renderer
src/report/pdf.ts
Delivery
- PDF output and retention
src/run.ts - Email delivery
src/mail/mailer.ts - SMTP service
Other components
- Operator
Connections 20
- Operator → CLI and scheduler: invokes
README.md - CLI and scheduler → Configuration: loads
src/index.ts - CLI and scheduler → Run coordinator: runs
src/index.ts - CLI and scheduler → Protect client: checks
src/index.ts - CLI and scheduler → Email delivery: verifies
src/index.ts - CLI and scheduler → Night window: checks window
src/index.ts - CLI and scheduler → Logging: sets level
src/index.ts - Run coordinator → Night window: builds window
src/run.ts - Run coordinator → Protect client: fetches events
src/run.ts - Protect client → UniFi Protect: queries API
src/protect/client.ts - Run coordinator → Filter and aggregate: filters and clusters
src/run.ts - Run coordinator → PDF renderer: renders report
src/run.ts - Run coordinator → Protect client: fetches stills
src/run.ts - Run coordinator → Synthetic report data: uses synthetic data
src/run.ts - Run coordinator → PDF output and retention: writes and prunes
src/run.ts - Run coordinator → Email delivery: sends report
src/run.ts - Email delivery → SMTP service: sends email
src/mail/mailer.ts - PDF renderer → Night window: formats times
src/report/pdf.ts - Email delivery → Night window: formats times
src/mail/mailer.ts - CLI and scheduler → Logging: logs status
src/index.ts