Skip to content

Conversation

@mjadach-iv
Copy link
Contributor

@mjadach-iv mjadach-iv commented Jan 20, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Standardized error propagation to preserve original validation errors.
    • Safer handling for missing balance fields to avoid runtime errors.
  • Breaking Changes

    • Several endpoints and response fields removed or renamed; response shapes simplified.
  • Tests

    • Added coverage for 500 error handling; multiple test suites and fixtures updated or removed.
  • Chores

    • Package bumped to 4.0.0 and dependencies updated.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

Bumps package to 4.0.0; removes channel aggregation and node graph APIs and their tests; renames getPeers query param qualityscore and updates peer schemas/tests; replaces many reconstructed ZodError throws with rethrowing original Zod parse errors; various test fixtures and type definitions updated.

Changes

Cohort / File(s) Summary
Package & Dependencies
package.json
Version bumped 3.0.3 → 4.0.0; dependency updates (notably zod → ^4.3.5, debug, ws).
Removed Channel APIs & Tests
src/api/channels/aggregateChannelTickets.ts, src/api/channels/aggregateChannelTickets.spec.ts, src/api/channels/getChannelsCorrupted.ts, src/api/channels/getChannelsCorrupted.spec.ts, src/api/channels/adapter.ts, src/api/channels/index.ts, src/types/channels.ts
Deleted aggregateChannelTickets and getChannelsCorrupted modules, tests, adapter methods and index export; removed related types/fields (AggregateChannelTicketsPayloadType, indexOffset, channelStatus).
Removed Node getGraph & Tests
src/api/node/getGraph.ts, src/api/node/getGraph.spec.ts, src/api/node/adapter.ts, src/api/node/index.ts, src/types/node.ts
Removed getGraph implementation, tests, adapter method and index export; removed GetGraph-related types.
getPeers: param rename & schema changes
src/api/node/getPeers.ts, src/api/node/adapter.ts, src/api/node/getPeers.spec.ts, src/types/node.ts
Query param renamed qualityscore (payload mapping updated; includes 0); peer schemas/tests adjusted (connected: added averageLatency, lastUpdate, probeRate, score; announced: multiaddrmultiaddrs).
Widespread Zod error rethrowing
multiple src/api/*/*.ts (examples: src/api/account/*, src/api/channels/*, src/api/node/*, src/api/network/*, src/api/sessions/*, src/api/tickets/*, src/api/tokens/*, src/api/peers/*)
Replaced many throw new ZodError(parsedRes.error.issues) with throw parsedRes.error (rethrow original Zod error object). Success and API-error branches unchanged.
Tests & fixtures updated
src/api/channels/closeChannel.spec.ts, src/api/channels/getChannelTickets.spec.ts, src/api/node/getInfo.spec.ts, src/api/node/getPeers.spec.ts, src/api/account/getAddresses.spec.ts, src/api/account/getBalances.spec.ts, src/api/configuration/getConfiguration.spec.ts
Adjusted mocked responses and assertions to reflect removed/renamed fields and schema updates; added a 500-error test for getAddresses and minor spec imports.
Account client robustness & logging
src/api/account/getBalances.ts, src/api/account/getAddresses.ts
Added optional-chaining guard when reading safeHoprAllowance; added debug logging in getAddresses; updated parse-error rethrow behavior.
Configuration parsing removed
src/api/configuration/getConfiguration.ts, src/api/configuration/getConfiguration.spec.ts
Removed internal strategy parsing that populated parsedStrategies; function now returns raw response without building parsedStrategies.
Misc API error-handling tweaks
examples: src/api/account/withdraw.ts, src/api/channels/*, src/api/network/*, src/api/sessions/*, src/api/tickets/*, src/api/tokens/*, src/api/peers/*
Consistent change to rethrow original parse errors (or isApiErrorResponse.error) instead of constructing new ZodError instances in many endpoints.
Type updates
src/types/node.ts, src/types/channels.ts
Multiple schema/type updates: removed GetGraph types; renamed qualityscore; updated PeerConnected/PeerAnnounced shapes; removed several GetInfo and channel fields; adjusted record shapes.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Hoprd v4' is overly vague and generic. While it references the major version bump evident in package.json (3.0.3 to 4.0.0), it does not meaningfully convey the substantial API changes throughout the codebase, such as removal of multiple public methods (aggregateChannelTickets, getChannelsCorrupted, getGraph), widespread error handling refactoring, and significant type updates across the SDK. Consider a more descriptive title that highlights the major changes, such as 'Major API cleanup and refactoring for Hoprd v4' or 'Hoprd v4: remove deprecated endpoints and improve error handling'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/api/account/getBalances.ts (1)

42-49: Guard non-string currency values before calling .includes.

The schema (src/types/account.ts) defines all currency fields as required strings, but the code processes raw unvalidated JSON before safeParse validation at line 53. If the API returns non-string values for any field—including safeHoprAllowance—calling .includes() will throw before schema validation can catch it.

Line 42 checks for existence with optional chaining (jsonResponse?.safeHoprAllowance &&), but this does not guard against non-string types (e.g., a number). Line 48 in the normalization loop has no guard at all. Add typeof checks to handle type violations defensively:

🛠️ Proposed fix
-  jsonResponse.token = jsonResponse?.safeHoprAllowance && jsonResponse.safeHoprAllowance.includes(' ')
-    ? jsonResponse.safeHoprAllowance.split(' ')[1]
-    : null;
+  jsonResponse.token =
+    typeof jsonResponse?.safeHoprAllowance === 'string' &&
+    jsonResponse.safeHoprAllowance.includes(' ')
+      ? jsonResponse.safeHoprAllowance.split(' ')[1]
+      : null;

   for (let i = 0; i < currencies.length; i++) {
     const token = currencies[i] as string;
-    jsonResponse[token] = jsonResponse[`${currencies[i]}`].includes(' ')
-      ? jsonResponse[token].split(' ')[0]
-      : jsonResponse[token];
+    const value = jsonResponse[`${currencies[i]}`];
+    jsonResponse[token] =
+      typeof value === 'string' && value.includes(' ')
+        ? value.split(' ')[0]
+        : value;
   }
🤖 Fix all issues with AI agents
In `@src/api/account/getAddresses.spec.ts`:
- Around line 94-109: The test name currently claims "APIError" but the code
calls getAddresses and asserts .rejects.toThrow(Error) because getAddresses
throws a plain Error on 5xx; update the test description string in the test
block (the test(...) call) to accurately reflect the behavior (e.g., "should
throw Error on internal server error") or alternatively change the assertion to
expect an APIError and modify getAddresses to throw APIError; reference the test
wrapper and the getAddresses call to locate and update the test description or
the assertion/implementation so the name and actual behavior match.

In `@src/api/node/getPeers.ts`:
- Around line 13-16: In getPeers.ts the current conditional if (payload?.score)
skips valid score=0; change the check to explicitly test for presence (e.g.,
payload?.score !== undefined && payload?.score !== null) before calling
url.searchParams.set so a score of 0 is included; update the block around the
URL creation and the payload.score handling to use that explicit undefined/null
check referencing url and payload.score.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/api/account/getAddresses.ts`:
- Line 38: Remove the debug console.log from the SDK surface that prints
parsedRes in getAddresses; either delete the line "console.log('parsedRes',
parsedRes)" or replace it with a gated debug logger (e.g., use an existing
debug/info logger or a conditional that only logs in development) so user
address data is not printed to stdout. Locate the usage of parsedRes in the
getAddresses function and ensure any logging follows the project's structured
logging/debug pattern rather than raw console.log.


const jsonResponse = await rawResponse.json();
const parsedRes = GetAddressesResponse.safeParse(jsonResponse);
console.log('parsedRes', parsedRes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Remove debug logging from the SDK surface.
This prints parsed addresses and can leak user data or spam consumer logs. Prefer removing or gating behind a debug logger.

🧹 Proposed fix
-  console.log('parsedRes', parsedRes);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log('parsedRes', parsedRes);
🤖 Prompt for AI Agents
In `@src/api/account/getAddresses.ts` at line 38, Remove the debug console.log
from the SDK surface that prints parsedRes in getAddresses; either delete the
line "console.log('parsedRes', parsedRes)" or replace it with a gated debug
logger (e.g., use an existing debug/info logger or a conditional that only logs
in development) so user address data is not printed to stdout. Locate the usage
of parsedRes in the getAddresses function and ensure any logging follows the
project's structured logging/debug pattern rather than raw console.log.

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