Skip to content

Feature/export endpoints - #39

Merged
KarenZita01 merged 7 commits into
EquipChain:mainfrom
JinadJay:feature/export-endpoints
Jul 29, 2026
Merged

Feature/export endpoints#39
KarenZita01 merged 7 commits into
EquipChain:mainfrom
JinadJay:feature/export-endpoints

Conversation

@JinadJay

Copy link
Copy Markdown
Contributor

No description provided.

JinadJay and others added 5 commits July 26, 2026 18:18
…structure

- Create src/config/index.js for centralized configuration
- Create src/routes/index.js for route aggregation
- Create src/services/index.js for service initialization
- Create src/app.js for Express app configuration
- Create src/server.js for HTTP server with graceful shutdown
- Update index.js to minimal entry point
- Update package.json scripts
- Update test imports to use src/app.js
- Add unit tests for app.js
- Add integration tests for server.js

This refactoring improves separation of concerns, testability, and maintainability.
The app can now be imported without starting the server, enabling faster tests.
Graceful shutdown handling for SIGTERM/SIGINT signals is implemented.

Resolves EquipChain#28
…on prevention

- Add MAX_BODY_SIZE env var (default 1MB) for request payload limits
- Create XSS sanitization utility (src/utils/sanitize.js) with escape-html
- Add Helmet middleware for security headers (XSS, CSP, etc.)
- Sanitize user data in error responses and logs to prevent XSS/log injection
- Configure Pino redact to mask sensitive fields in logs
- Add ESLint security plugin with SQL injection prevention rules
- Create comprehensive security integration tests
- Add Content-Type enforcement middleware for JSON responses
- Update .env.example with new security configuration

Resolves EquipChain#30
- Add in-memory job queue service (src/services/queue.js)
  - Support for job prioritization, concurrency control, and retry with exponential backoff
  - Job status tracking (queued, running, completed, failed, cancelled)
  - API: add(), schedule(), getStatus(), cancel(), getStats()

- Add scheduler service (src/services/scheduler.js)
  - Cron-like recurring job scheduling
  - Support for numeric intervals and simple cron expressions
  - API: schedule(), cancelSchedule(), getSchedule(), getAllSchedules()

- Create job handlers (src/jobs/)
  - billing.job.js - Aggregate readings and compute charges
  - reports.job.js - Generate daily/monthly usage reports
  - sync.job.js - Sync on-chain data with local state
  - webhookRetry.job.js - Retry failed webhook deliveries
  - cacheWarm.job.js - Warm cache for frequently accessed data

- Add webhook service (src/services/webhook.js)
  - Queue-based webhook delivery with automatic retries

- Integrate queue and scheduler in src/services/index.js
  - Register all job handlers
  - Configure recurring schedules (hourly billing, daily/monthly reports, periodic sync, cache warming)

- Update health endpoint to expose queue and scheduler statistics

- Add unit tests for queue and scheduler

Resolves EquipChain#18
Implement export endpoints for meter readings, analytics summaries, and system reports with support for CSV, JSON, and NDJSON formats. Features include:

- Streaming export service using Node.js streams and csv-stringify
- Column selection via ?fields parameter
- Date range and metadata filtering
- Proper Content-Type and Content-Disposition headers
- Transfer-Encoding: chunked for large dataset support
- Authentication and authorization middleware
- Comprehensive unit and integration tests
- Updated README with export documentation

Closes EquipChain#23
@KarenZita01

Copy link
Copy Markdown
Member

CI failed. FIx it

@KarenZita01
KarenZita01 merged commit d25a674 into EquipChain:main Jul 29, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants