Skip to content

Harden Redis/Stellar/config handling (#220, #221, #222, #225) - #360

Merged
meshackyaro merged 11 commits into
trustflow-protocol:mainfrom
thefadah:config-hardening-220-221-222-225
Aug 31, 2026
Merged

Harden Redis/Stellar/config handling (#220, #221, #222, #225)#360
meshackyaro merged 11 commits into
trustflow-protocol:mainfrom
thefadah:config-hardening-220-221-222-225

Conversation

@thefadah

Copy link
Copy Markdown
Contributor

This PR hardens the backend's configuration and connection handling, and covers a few endpoints/knobs that existed in the code but were undocumented or unreachable.

#220 — Redis client resilience

  • createRedisClient() is now an exported factory (independently testable); the module provider delegates to it.
  • Returns null with a warning when REDIS_URL is unset instead of throwing at construction.
  • Attaches error / connect / reconnecting listeners so a transient failure is logged, not an unhandled event.
  • Kicks off an initial connect() whose rejection is logged; the client keeps retrying per retryStrategy.

#221 — Stellar lookups exposed

  • New StellarAccountNotFoundError so getBalance() distinguishes "account does not exist" (Horizon 404) from a transport failure; withFailover() treats it as terminal.
  • New StellarController: GET /stellar/ledger and GET /stellar/balance/:address, with strkey validation (400) and not-found mapping (404). Registered on StellarModule.

#222.env.example coverage

  • Adds NODE_ENV, API_URL, ADMIN_ADDRESSES, SENTRY_DSN, RATE_LIMIT_ABUSE_WINDOW_SECONDS, RATE_LIMIT_ABUSE_THRESHOLD, RATE_LIMIT_LOCKOUT_SECONDS, IDEMPOTENCY_KEY_TTL_SECONDS, ESCROW_RECONCILIATION_SWEEP_INTERVAL_MS, each with a short comment.
  • Adds env-example-coverage.spec.ts which fails if any process.env.X referenced under backend/src is missing from .env.example.

#225 — pre-commit hook

  • husky + lint-staged dev deps, a prepare script, and a lint-staged config (eslint --fix + prettier --write on staged *.ts).
  • backend/.husky/pre-commit runs lint-staged against the backend package (the repo keeps the Node project in backend/ while .git is at the root).
  • SETUP_INSTRUCTIONS.md documents the hook.

Closes #220
Closes #221
Closes #222
Closes #225

Split into 10 commits. Not built or run in this environment.

REDIS_URL being unset used to throw at construction; a bad URL or an
unreachable server produced an unhandled 'error' event that could crash
the process. Extract createRedisClient() as an exported factory, return
null (with a warning) when REDIS_URL is absent, attach error/connect/
reconnecting listeners, and kick off a connect() whose rejection is
logged rather than thrown.

Closes trustflow-protocol#220
getBalance() surfaced raw Horizon SDK errors, so a caller could not tell
'account does not exist' (a 404 that should map to a client error) from
a transport failure. Translate Horizon's not-found into a dedicated
error class and make withFailover() treat it as terminal instead of
retrying it.

Refs trustflow-protocol#221
StellarService was wired into the DI graph but unreachable. Add
GET /stellar/ledger and GET /stellar/balance/:address, with strkey
validation (400) and not-found mapping (404), and register the
controller on StellarModule.

Closes trustflow-protocol#221
Adds NODE_ENV, API_URL, ADMIN_ADDRESSES, SENTRY_DSN, the
RATE_LIMIT_ABUSE_* / RATE_LIMIT_LOCKOUT_SECONDS abuse-detection knobs,
IDEMPOTENCY_KEY_TTL_SECONDS and ESCROW_RECONCILIATION_SWEEP_INTERVAL_MS
to .env.example, each with a short comment.

Closes trustflow-protocol#222
Declares the dev dependencies, a prepare script that installs the git
hook, and the lint-staged config (eslint --fix + prettier --write on
staged *.ts).

Refs trustflow-protocol#225
Runs lint-staged against the backend package (the repo keeps the Node
project in backend/ while .git is at the root).

Refs trustflow-protocol#225
@thefadah
thefadah requested a review from meshackyaro as a code owner August 31, 2026 02:06
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@thefadah Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@meshackyaro
meshackyaro merged commit 6ecb9d4 into trustflow-protocol:main Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants