Skip to content

refactor: move /v1/nodes and /v1/version to a module#1458

Merged
stalniy merged 1 commit intoakash-network:mainfrom
jzsfkzm:refactor/1271-nodes-and-versions
Jun 19, 2025
Merged

refactor: move /v1/nodes and /v1/version to a module#1458
stalniy merged 1 commit intoakash-network:mainfrom
jzsfkzm:refactor/1271-nodes-and-versions

Conversation

@jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Jun 9, 2025

closes #1271
closes #1276

Summary by CodeRabbit

  • New Features

    • Introduced a consolidated network API with endpoints to fetch node lists and version info for mainnet, testnet, and sandbox.
    • Added schema validation and OpenAPI documentation for network-related routes.
    • Implemented a new HTTP service with automatic retry logic for improved network data fetching reliability.
  • Improvements

    • Enhanced caching mechanism for network data with memoization to reduce redundant calls.
    • Simplified API routing by removing legacy individual node and version routes.
  • Refactor

    • Reorganized network-related code into a unified module with dependency injection and streamlined route handling.
  • Bug Fixes

    • Updated API test request paths to include leading slashes for accurate endpoint testing.

@jzsfkzm jzsfkzm requested a review from a team as a code owner June 9, 2025 21:25
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

"""

Walkthrough

This change refactors the handling of network nodes and version routes by removing legacy route files and introducing a new modular structure. It adds new service, controller, schema, and router layers for network-related endpoints, updates dependency injection and constants, and consolidates the HTTP SDK node logic with improved type safety and retry handling.

Changes

File(s) Change Summary
apps/api/src/app.ts Registers new networkRouter for network-related API routes.
apps/api/src/core/providers/http-sdk.provider.ts, apps/api/src/utils/constants.ts Adds NodeHttpService to DI with new base path constant.
apps/api/src/network/controllers/network/network.controller.ts Introduces NetworkController with methods for nodes and version.
apps/api/src/network/http-schemas/network.schema.ts Adds Zod/OpenAPI schemas and types for network endpoints.
apps/api/src/network/index.ts, apps/api/src/network/routes/index.ts Re-exports network router modules for modular access.
apps/api/src/network/routes/network/network.router.ts Adds networkRouter with OpenAPI routes for /v1/nodes/{network} and /v1/version/{network}.
apps/api/src/network/services/network/network.service.ts Adds NetworkService with memoized methods for nodes and version retrieval.
apps/api/src/routes/v1/index.ts Removes legacy nodes and version route imports/exports.
apps/api/src/routes/v1/nodes/mainnet.ts, .../sandbox.ts, .../testnet.ts Deletes old node route files for each network.
apps/api/src/routes/v1/nodes/nodeClient.ts Deletes legacy NodeClient class for node/version fetching.
apps/api/src/routes/v1/version/mainnet.ts, .../sandbox.ts, .../testnet.ts Deletes old version route files for each network.
apps/api/test/functional/nodes-v1.spec.ts Updates test URLs to include leading slashes and adds invalid network tests.
apps/api/test/seeders/node.seeder.ts Updates types and faker usage for node seeding.
apps/api/tsconfig.strict.json Adds src/network/**/*.ts to strict type checking.
packages/http-sdk/src/index.ts, packages/http-sdk/src/node/index.ts Adds and re-exports new node module in HTTP SDK.
packages/http-sdk/src/node/node-http.service.ts Introduces NodeHttpService with retry logic and network methods.
packages/http-sdk/src/node/types.ts Adds NetworkNode type definition.
apps/api/src/caching/helpers.ts Removes legacy cache keys related to nodes and versions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API (networkRouter)
    participant NetworkController
    participant NetworkService
    participant NodeHttpService

    Client->>API (networkRouter): GET /v1/nodes/{network}
    API (networkRouter)->>NetworkController: getNodes(network)
    NetworkController->>NetworkService: getNodes(network)
    NetworkService->>NodeHttpService: getNodes(network)
    NodeHttpService-->>NetworkService: [nodes]
    NetworkService-->>NetworkController: [nodes]
    NetworkController-->>API (networkRouter): [nodes]
    API (networkRouter)-->>Client: JSON response

    Client->>API (networkRouter): GET /v1/version/{network}
    API (networkRouter)->>NetworkController: getVersion(network)
    NetworkController->>NetworkService: getVersion(network)
    NetworkService->>NodeHttpService: getVersion(network)
    NodeHttpService-->>NetworkService: "version"
    NetworkService-->>NetworkController: "version"
    NetworkController-->>API (networkRouter): "version"
    API (networkRouter)-->>Client: text response
Loading

Assessment against linked issues

Objective Addressed Explanation
Refactor nodes routes to use new modular service/controller/router (1271)
Remove legacy node route files and logic (1271)
Refactor version routes to use new modular service/controller/router (1276)
Remove legacy version route files and logic (1276)

Suggested reviewers

  • baktun14

Poem

A rabbit hopped through fields of code,
Refactoring routes, lightening the load.
Old files retired, new modules appear,
With schemas and services, the path is clear!
Now nodes and versions, neat and spry,
Respond to requests as quick as a sigh.
🐇✨ Hooray for clean code—let’s multiply!
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-19T03_49_42_317Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac384ac and 3b971b7.

📒 Files selected for processing (25)
  • apps/api/src/app.ts (2 hunks)
  • apps/api/src/caching/helpers.ts (0 hunks)
  • apps/api/src/core/providers/http-sdk.provider.ts (2 hunks)
  • apps/api/src/network/controllers/network/network.controller.ts (1 hunks)
  • apps/api/src/network/http-schemas/network.schema.ts (1 hunks)
  • apps/api/src/network/index.ts (1 hunks)
  • apps/api/src/network/routes/index.ts (1 hunks)
  • apps/api/src/network/routes/network/network.router.ts (1 hunks)
  • apps/api/src/network/services/network/network.service.ts (1 hunks)
  • apps/api/src/routes/v1/index.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/mainnet.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/nodeClient.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/sandbox.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/testnet.ts (0 hunks)
  • apps/api/src/routes/v1/version/mainnet.ts (0 hunks)
  • apps/api/src/routes/v1/version/sandbox.ts (0 hunks)
  • apps/api/src/routes/v1/version/testnet.ts (0 hunks)
  • apps/api/src/utils/constants.ts (1 hunks)
  • apps/api/test/functional/nodes-v1.spec.ts (2 hunks)
  • apps/api/test/seeders/node.seeder.ts (1 hunks)
  • apps/api/tsconfig.strict.json (1 hunks)
  • packages/http-sdk/src/index.ts (1 hunks)
  • packages/http-sdk/src/node/index.ts (1 hunks)
  • packages/http-sdk/src/node/node-http.service.ts (1 hunks)
  • packages/http-sdk/src/node/types.ts (1 hunks)
💤 Files with no reviewable changes (9)
  • apps/api/src/routes/v1/version/testnet.ts
  • apps/api/src/routes/v1/nodes/mainnet.ts
  • apps/api/src/routes/v1/version/mainnet.ts
  • apps/api/src/routes/v1/nodes/sandbox.ts
  • apps/api/src/routes/v1/nodes/testnet.ts
  • apps/api/src/routes/v1/version/sandbox.ts
  • apps/api/src/routes/v1/nodes/nodeClient.ts
  • apps/api/src/caching/helpers.ts
  • apps/api/src/routes/v1/index.ts
🚧 Files skipped from review as they are similar to previous changes (16)
  • apps/api/src/network/index.ts
  • apps/api/src/utils/constants.ts
  • apps/api/test/functional/nodes-v1.spec.ts
  • packages/http-sdk/src/index.ts
  • apps/api/src/app.ts
  • packages/http-sdk/src/node/index.ts
  • apps/api/src/network/routes/index.ts
  • apps/api/tsconfig.strict.json
  • apps/api/src/core/providers/http-sdk.provider.ts
  • packages/http-sdk/src/node/types.ts
  • apps/api/src/network/routes/network/network.router.ts
  • apps/api/test/seeders/node.seeder.ts
  • apps/api/src/network/services/network/network.service.ts
  • apps/api/src/network/controllers/network/network.controller.ts
  • packages/http-sdk/src/node/node-http.service.ts
  • apps/api/src/network/http-schemas/network.schema.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: validate-deploy-web
  • GitHub Check: test-deploy-web-build
  • GitHub Check: validate-notifications
  • GitHub Check: test-api-build
  • GitHub Check: validate-api
  • GitHub Check: Validate local packages
✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jzsfkzm jzsfkzm force-pushed the refactor/1271-nodes-and-versions branch from 586d295 to bf01292 Compare June 9, 2025 21:26
@codecov
Copy link

codecov bot commented Jun 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.32%. Comparing base (87994d4) to head (3b971b7).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1458      +/-   ##
==========================================
- Coverage   40.34%   40.32%   -0.02%     
==========================================
  Files         875      872       -3     
  Lines       21107    21097      -10     
  Branches     3846     3844       -2     
==========================================
- Hits         8515     8508       -7     
+ Misses      12420    11860     -560     
- Partials      172      729     +557     
Flag Coverage Δ *Carryforward flag
api 71.35% <100.00%> (+<0.01%) ⬆️
deploy-web 18.37% <ø> (ø)
notifications 89.21% <ø> (ø)
provider-proxy 82.10% <ø> (ø) Carriedforward from 87994d4

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
apps/api/src/app.ts 89.13% <100.00%> (+0.15%) ⬆️
apps/api/src/caching/helpers.ts 97.50% <ø> (ø)
apps/api/src/core/providers/http-sdk.provider.ts 100.00% <100.00%> (ø)
.../network/controllers/network/network.controller.ts 100.00% <100.00%> (ø)
...pps/api/src/network/http-schemas/network.schema.ts 100.00% <100.00%> (ø)
...s/api/src/network/routes/network/network.router.ts 100.00% <100.00%> (ø)
...pi/src/network/services/network/network.service.ts 100.00% <100.00%> (ø)
apps/api/src/utils/constants.ts 100.00% <100.00%> (ø)

... and 184 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 4

🧹 Nitpick comments (4)
apps/api/src/utils/constants.ts (1)

22-22: Suggest renaming constant to nodeApiBasePath for clarity.

The current name nNodeApiBasePath has an extra leading “n”; aligning with other constants (e.g., apiNodeUrl) improves readability and reduces confusion.

apps/api/test/seeders/node.seeder.ts (1)

6-9: Simplify faker usage pattern.

The current usage faker.faker.string.alphanumeric() is redundant. Modern faker API allows direct usage of methods.

-    id = faker.faker.string.alphanumeric(),
-    api = faker.faker.string.alphanumeric(),
-    rpc = faker.faker.string.alphanumeric()
+    id = faker.string.alphanumeric(),
+    api = faker.string.alphanumeric(),
+    rpc = faker.string.alphanumeric()
apps/api/src/network/controllers/network/network.controller.ts (1)

6-17: LGTM! Clean controller implementation with proper dependency injection.

The controller follows good patterns with dependency injection and proper type safety. Consider adding error handling to transform service-level exceptions into appropriate HTTP responses.

Consider adding error handling:

  async getNodes(network: GetNodesParams["network"]): Promise<GetNodesResponse> {
+   try {
      return await this.networkService.getNodes(network);
+   } catch (error) {
+     // Transform service errors to appropriate HTTP responses
+     throw error;
+   }
  }

  async getVersion(network: GetNodesParams["network"]): Promise<string> {
+   try {
      return await this.networkService.getVersion(network);
+   } catch (error) {
+     // Transform service errors to appropriate HTTP responses
+     throw error;
+   }
  }
packages/http-sdk/src/node/node-http.service.ts (1)

21-43: Consider making endpoint paths configurable.

The hardcoded endpoint paths work but could be made more maintainable by extracting them to configuration constants. This would make it easier to update paths or support different environments.

Consider extracting endpoint paths to constants:

+const ENDPOINTS = {
+  mainnet: {
+    nodes: "console/main/config/mainnet-nodes.json",
+    version: "net/master/mainnet/version.txt"
+  },
+  sandbox: {
+    nodes: "console/main/config/sandbox-nodes.json", 
+    version: "net/master/sandbox/version.txt"
+  },
+  testnet: {
+    nodes: "console/main/config/testnet-nodes.json",
+    version: "net/master/testnet-02/version.txt"
+  }
+} as const;

  async getMainnetNodes() {
-   return this.extractData(await this.get<NetworkNode[]>("console/main/config/mainnet-nodes.json"));
+   return this.extractData(await this.get<NetworkNode[]>(ENDPOINTS.mainnet.nodes));
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8898710 and bf01292.

📒 Files selected for processing (24)
  • apps/api/src/app.ts (2 hunks)
  • apps/api/src/core/providers/http-sdk.provider.ts (2 hunks)
  • apps/api/src/network/controllers/network/network.controller.ts (1 hunks)
  • apps/api/src/network/http-schemas/network.schema.ts (1 hunks)
  • apps/api/src/network/index.ts (1 hunks)
  • apps/api/src/network/routes/index.ts (1 hunks)
  • apps/api/src/network/routes/network/network.router.ts (1 hunks)
  • apps/api/src/network/services/network/network.service.ts (1 hunks)
  • apps/api/src/routes/v1/index.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/mainnet.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/nodeClient.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/sandbox.ts (0 hunks)
  • apps/api/src/routes/v1/nodes/testnet.ts (0 hunks)
  • apps/api/src/routes/v1/version/mainnet.ts (0 hunks)
  • apps/api/src/routes/v1/version/sandbox.ts (0 hunks)
  • apps/api/src/routes/v1/version/testnet.ts (0 hunks)
  • apps/api/src/utils/constants.ts (1 hunks)
  • apps/api/test/functional/nodes-v1.spec.ts (1 hunks)
  • apps/api/test/seeders/node.seeder.ts (1 hunks)
  • apps/api/tsconfig.strict.json (1 hunks)
  • packages/http-sdk/src/index.ts (1 hunks)
  • packages/http-sdk/src/node/index.ts (1 hunks)
  • packages/http-sdk/src/node/node-http.service.ts (1 hunks)
  • packages/http-sdk/src/node/types.ts (1 hunks)
💤 Files with no reviewable changes (8)
  • apps/api/src/routes/v1/version/mainnet.ts
  • apps/api/src/routes/v1/version/testnet.ts
  • apps/api/src/routes/v1/nodes/mainnet.ts
  • apps/api/src/routes/v1/version/sandbox.ts
  • apps/api/src/routes/v1/nodes/testnet.ts
  • apps/api/src/routes/v1/nodes/sandbox.ts
  • apps/api/src/routes/v1/nodes/nodeClient.ts
  • apps/api/src/routes/v1/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (8)
apps/api/src/app.ts (1)
apps/api/src/network/routes/network/network.router.ts (1)
  • networkRouter (45-45)
apps/api/src/core/providers/http-sdk.provider.ts (2)
packages/http-sdk/src/node/node-http.service.ts (1)
  • NodeHttpService (10-44)
apps/api/src/utils/constants.ts (1)
  • nNodeApiBasePath (22-22)
packages/http-sdk/src/node/types.ts (1)
apps/api/src/network/http-schemas/network.schema.ts (1)
  • NetworkNode (16-16)
apps/api/src/network/controllers/network/network.controller.ts (2)
apps/api/src/network/services/network/network.service.ts (1)
  • singleton (8-35)
apps/api/src/network/http-schemas/network.schema.ts (2)
  • GetNodesParams (15-15)
  • GetNodesResponse (17-17)
apps/api/src/network/services/network/network.service.ts (4)
apps/api/src/network/controllers/network/network.controller.ts (1)
  • singleton (6-17)
packages/http-sdk/src/node/node-http.service.ts (1)
  • NodeHttpService (10-44)
apps/api/src/caching/helpers.ts (1)
  • Memoize (22-38)
apps/api/src/network/http-schemas/network.schema.ts (2)
  • GetNodesParams (15-15)
  • GetNodesResponse (17-17)
apps/api/src/network/http-schemas/network.schema.ts (1)
packages/http-sdk/src/node/types.ts (1)
  • NetworkNode (1-5)
apps/api/test/seeders/node.seeder.ts (2)
packages/http-sdk/src/node/types.ts (1)
  • NetworkNode (1-5)
apps/api/src/network/http-schemas/network.schema.ts (1)
  • NetworkNode (16-16)
packages/http-sdk/src/node/node-http.service.ts (3)
packages/http-sdk/src/http/http.service.ts (1)
  • HttpService (3-15)
packages/http-sdk/src/node/types.ts (1)
  • NetworkNode (1-5)
apps/api/src/network/http-schemas/network.schema.ts (1)
  • NetworkNode (16-16)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-api-build
  • GitHub Check: validate-api
  • GitHub Check: validate-notifications
  • GitHub Check: test-deploy-web-build
🔇 Additional comments (23)
apps/api/src/utils/constants.ts (1)

22-22: Ensure NODE_API_BASE_PATH is defined or provide a fallback.

If env.NODE_API_BASE_PATH is undefined, the DI registration of NodeHttpService will receive undefined as its baseURL. Consider validating this value at startup (and throwing early) or supplying a sensible default to avoid runtime errors.

apps/api/src/network/index.ts (1)

1-1: Approve central re-export of the network routes.

Re-exporting all exports from ./routes correctly exposes the network routing module interface.

apps/api/src/app.ts (2)

48-48: Approve import of networkRouter.

The new network routes are correctly brought in via the module index and follow the project’s routing pattern.


133-133: Verify route ordering and overlaps.

Mounting networkRouter at root ("/") is consistent, but double-check that its /v1/... paths don’t conflict with neighbouring routers (pricingRouter, notificationsApiProxy, etc.) and that middleware ordering remains correct.

packages/http-sdk/src/index.ts (1)

22-22: Approve exposing node API in HTTP SDK public API.

Re-exporting the new ./node submodule ensures NodeHttpService and its types are available to consumers.

apps/api/src/network/routes/index.ts (1)

1-1: LGTM! Clean barrel export pattern.

The export statement follows standard patterns for centralizing module exports and integrates well with the network module refactoring.

packages/http-sdk/src/node/index.ts (1)

1-2: LGTM! Proper module exports for HTTP SDK node functionality.

The exports provide clean access to both the NodeHttpService and related types, following standard barrel export patterns.

apps/api/tsconfig.strict.json (1)

29-29: LGTM! Appropriate addition to strict type checking.

Adding the network module to strict TypeScript configuration ensures type safety for the new network-related code.

apps/api/src/core/providers/http-sdk.provider.ts (3)

11-11: LGTM! Proper import of NodeHttpService.

The import follows the established pattern and integrates the new HTTP service into the dependency injection system.


16-16: LGTM! Appropriate import of the node API base path constant.

The import of nNodeApiBasePath provides the necessary configuration for the NodeHttpService registration.


33-33: LGTM! Correct service registration pattern.

The NodeHttpService registration follows the same pattern as other services with custom base URLs (GitHubHttpService, CoinGeckoHttpService). The separation from the SERVICES array is appropriate since it uses a different base URL than the other services.

packages/http-sdk/src/node/types.ts (1)

1-5:

Details

✅ Verification successful

Type definition looks good, but verify consistency with Zod schema.

The NetworkNode type is well-defined with clear property names and types. However, there's also a NetworkNode type defined via Zod schema in apps/api/src/network/http-schemas/network.schema.ts. Ensure both types are structurally identical to avoid type inconsistencies.


🏁 Script executed:

#!/bin/bash
# Verify that both NetworkNode type definitions are structurally identical
echo "=== HTTP SDK NetworkNode type ==="
cat packages/http-sdk/src/node/types.ts

echo -e "\n=== API Schema NetworkNode definition ==="
ast-grep --pattern 'export const NodeSchema = $_'

Length of output: 712


NetworkNode type definitions are consistent across modules

The NetworkNode type in packages/http-sdk/src/node/types.ts and the Zod NodeSchema in apps/api/src/network/http-schemas/network.schema.ts both define id, api, and rpc as strings, so no further changes are needed.

apps/api/test/seeders/node.seeder.ts (1)

1-2: Import changes look good.

The migration to use NetworkNode from the HTTP SDK package and the namespace import for faker are both appropriate changes that align with the refactoring objectives.

apps/api/src/network/routes/network/network.router.ts (4)

8-26: Well-structured route definition.

The nodes route is properly configured with OpenAPI metadata, parameter validation, and clear response schema. The implementation follows Hono and OpenAPI best practices.


28-43: Good version route implementation.

The version route is well-documented with helpful description linking to the actual version files. The OpenAPI configuration is appropriate for a text response.


47-52: Clean handler implementation for nodes.

The route handler properly extracts validated parameters, resolves the controller via dependency injection, and returns the response in the correct JSON format.


54-59: Appropriate text response for version.

The version handler correctly returns the response as plain text, which is suitable for version information.

apps/api/src/network/services/network/network.service.ts (2)

8-11: Well-structured service with proper dependency injection.

The singleton pattern and constructor injection are correctly implemented, following good dependency injection practices.


12-12: Excellent use of memoization for performance.

The 5-minute cache TTL is appropriate for network configuration data that doesn't change frequently. This will significantly reduce external API calls and improve response times.

Also applies to: 24-24

packages/http-sdk/src/node/node-http.service.ts (1)

7-8: Good constants definition for retry configuration.

The retry constants are appropriately defined and will make the retry behavior predictable.

apps/api/src/network/http-schemas/network.schema.ts (3)

3-5: Good network parameter validation.

The enum correctly restricts network values to the supported networks, matching the implementation in NodeHttpService.


15-17: Excellent type definitions with proper inference.

The type exports provide good TypeScript integration and will ensure type safety across the network module.


7-11:

Details

✅ Verification successful

Verify schema consistency with http-sdk NetworkNode type.

The NodeSchema matches the structure of NetworkNode from packages/http-sdk/src/node/types.ts. Consider adding URL validation for the api and rpc fields since they represent endpoints.

Let me verify the type consistency between the schema and the http-sdk NetworkNode type:

Consider adding URL validation for endpoint fields:

export const NodeSchema = z.object({
  id: z.string(),
- api: z.string(),
- rpc: z.string()
+ api: z.string().url("API endpoint must be a valid URL"),
+ rpc: z.string().url("RPC endpoint must be a valid URL")
});

🏁 Script executed:

#!/bin/bash
# Check if the NetworkNode type in http-sdk matches our schema
cat packages/http-sdk/src/node/types.ts

# Also check if there are any other NetworkNode type definitions that might conflict
rg -A 5 "type NetworkNode" --type ts

Length of output: 642


Schema matches NetworkNode; consider URL validation

  • Verified that NodeSchema properties (id, api, rpc) exactly align with the NetworkNode type in packages/http-sdk/src/node/types.ts.
  • No conflicting definitions of NetworkNode were found in the codebase.

To enforce that api and rpc are valid URLs, you can update the schema as follows:

-export const NodeSchema = z.object({
-  id: z.string(),
-  api: z.string(),
-  rpc: z.string()
-});
+export const NodeSchema = z.object({
+  id: z.string(),
+  api: z.string().url("API endpoint must be a valid URL"),
+  rpc: z.string().url("RPC endpoint must be a valid URL")
+});

@jzsfkzm jzsfkzm force-pushed the refactor/1271-nodes-and-versions branch 2 times, most recently from 511bde9 to 9982207 Compare June 9, 2025 22:52
baktun14
baktun14 previously approved these changes Jun 10, 2025
@jzsfkzm jzsfkzm force-pushed the refactor/1271-nodes-and-versions branch 2 times, most recently from 04edeed to 27dd512 Compare June 11, 2025 20:31
stalniy
stalniy previously approved these changes Jun 16, 2025
@stalniy stalniy enabled auto-merge (squash) June 18, 2025 04:25
auto-merge was automatically disabled June 18, 2025 20:29

Head branch was pushed to by a user without write access

@jzsfkzm jzsfkzm force-pushed the refactor/1271-nodes-and-versions branch from 6e817e1 to ac384ac Compare June 18, 2025 20:29
@stalniy stalniy force-pushed the refactor/1271-nodes-and-versions branch from ac384ac to 3b971b7 Compare June 19, 2025 03:48
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.

Refactor versions routes Refactor nodes routes

3 participants

Comments