Skip to content

chore: code-quality pass — extract dashboard, agent loop, rate-limit login#86

Open
victalejo wants to merge 1 commit into
David-patrick-chuks:mainfrom
victalejo:main
Open

chore: code-quality pass — extract dashboard, agent loop, rate-limit login#86
victalejo wants to merge 1 commit into
David-patrick-chuks:mainfrom
victalejo:main

Conversation

@victalejo
Copy link
Copy Markdown

Summary

  • Structure: extract dashboard HTML (~300 lines) from app.ts into src/views/dashboard.ts; move the Instagram agent loop out of app.ts (it was a module-load side-effect) into src/agentLoop.ts, started explicitly from index.ts. app.ts shrinks from 422 → 64 lines and is now safely importable in tests.
  • Security: add a zero-dependency in-memory rate limiter (src/utils/rateLimit.ts) and apply it to POST /api/login (10 attempts / 15 min per IP). Returns 429 + Retry-After when exceeded.
  • Tests: +6 integration tests over the real Express app (src/routes/api.test.ts) covering /api/status, /api/health, /api/me, /api/login validation + rate limit, and /dashboard. +4 unit tests for the rate limiter. Total suite: 11 suites / 33 tests passing.
  • Tooling:
    • Migrate ESLint v10 to flat config (eslint.config.js); drop deprecated .eslintrc.cjs and .eslintignore.
    • Fix pre-existing @typescript-eslint/no-unsafe-function-type error in requireAuth (FunctionNextFunction).
    • package.json scripts: split build/serve/clean/dev; start now just runs build && serve; add test:coverage.
    • jest.config.cjs: configure collectCoverageFrom, exclude views/, app.ts, index.ts, and the recaptcha subproject.
  • Cleanup: delete empty/orphan files src/server.ts, src/client/Twitter.ts, src/client/Github.ts, src/twitterAgent.js, riona-tweet.js.

Why

  • app.ts was acting as entrypoint + dashboard view + agent runtime, which made it untestable and hard to read.
  • /api/login had no protection against brute-force.
  • ESLint was broken on this branch (v10 needs flat config), so npm run lint failed before any change could be vetted.

…es and implement rate limiting for login requests

- Deleted unused files: riona-tweet.js, Twitter.ts, Github.ts, server.ts, twitterAgent.js
- Added agentLoop.ts to manage Instagram agent iterations with error handling and re-login logic
- Introduced rate limiting for login endpoint in api.ts to prevent abuse
- Created a new dashboard view in dashboard.ts for better status monitoring
- Added tests for API routes in api.test.ts and rate limiting functionality in rateLimit.test.ts
- Updated app.ts to serve the new dashboard and integrate agent functionality
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.

1 participant