Skip to content

chore: add Node.js admin JSON-RPC client - #149

Merged
MicBun merged 2 commits into
mainfrom
adminnode
Apr 16, 2026
Merged

chore: add Node.js admin JSON-RPC client#149
MicBun merged 2 commits into
mainfrom
adminnode

Conversation

@MicBun

@MicBun MicBun commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

resolves: https://github.com/truflation/website/issues/3481

Summary by CodeRabbit

Release Notes

  • New Features

    • Added AdminClient for making JSON-RPC requests to admin endpoints with built-in support for authentication credentials, custom request timeout configuration, and optional detailed request/response logging.
  • Tests

    • Added comprehensive unit test suite for AdminClient covering constructor validation, JSON-RPC request/response handling, authentication, and various error scenarios.
  • Chores

    • Updated TypeScript build configuration and repository gitignore file.

@MicBun
MicBun requested a review from pr-time-tracker April 16, 2026 11:44
@MicBun MicBun self-assigned this Apr 16, 2026
@holdex

holdex Bot commented Apr 16, 2026

Copy link
Copy Markdown

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Apr 16, 2026, 12:10 PM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@MicBun has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 34 minutes and 35 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 34 minutes and 35 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 386ac730-921c-43e1-964e-58f99a1f157a

📥 Commits

Reviewing files that changed from the base of the PR and between 2265d30 and 4d610f8.

📒 Files selected for processing (2)
  • src/api_client/admin_client.ts
  • tests/unitTests/api_client/admin_client.test.ts
📝 Walkthrough

Walkthrough

A new AdminClient class for making authenticated JSON-RPC 2.0 requests to an admin endpoint was introduced, with configuration support for authentication, timeout, and logging. Accompanying exports, type definitions, comprehensive unit tests, and build configuration were updated to integrate the new client.

Changes

Cohort / File(s) Summary
AdminClient Implementation
src/api_client/admin_client.ts
Introduces AdminClient class with JSON-RPC 2.0 request handling, constructor validation, request/response interceptors for logging, error handling for HTTP/network failures and JSON-RPC errors, and support for authentication and custom Axios configuration.
Public Exports & Type Registration
src/index.ts
Exports AdminClient class and registers AdminClientConfig type in the Types namespace for public API access.
Build Configuration
tsconfig.json
Updated TypeScript compiler configuration to include the new src/api_client/admin_client.ts file in the compilation pipeline.
Unit Tests
tests/unitTests/api_client/admin_client.test.ts
Comprehensive test suite covering constructor validation, JSON-RPC request formatting, response handling, id incrementation, error scenarios (HTTP errors, JSON-RPC errors, network failures), authentication configuration, and null result handling.
Repository Configuration
.gitignore
Added CLAUDE.md to the ignore list.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant AdminClient
    participant Axios
    participant AdminRPC as Admin RPC<br/>Endpoint

    Caller->>AdminClient: new AdminClient(config)
    AdminClient->>AdminClient: Validate config &<br/>environment
    
    Caller->>AdminClient: callMethod('method', params)
    AdminClient->>AdminClient: Construct JSON-RPC 2.0<br/>request body
    AdminClient->>AdminClient: Apply authentication<br/>if configured
    AdminClient->>Axios: POST /rpc/v1<br/>(request config)
    Axios->>AdminRPC: Send JSON-RPC request
    AdminRPC-->>Axios: HTTP 200 + JSON-RPC<br/>response
    Axios-->>AdminClient: Response received
    AdminClient->>AdminClient: Parse & validate<br/>JSON-RPC response
    alt JSON-RPC error present
        AdminClient->>Caller: throw JSON-RPC error
    else result present
        AdminClient->>Caller: return result (T)
    else HTTP error or network failure
        AdminClient->>Caller: throw error with<br/>details
    end
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A client hops in, JSON-RPC in tow,
Admin requests now have a proper flow!
With auth, with logging, with errors so neat,
This implementation makes admin tasks complete! 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a Node.js admin JSON-RPC client implementation, which aligns with the substantial additions of AdminClient class, configuration, tests, and exports.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch adminnode

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unitTests/api_client/admin_client.test.ts (1)

26-30: Test name and assertion are misaligned.

Line 26 says it verifies the default timeout, but the body only asserts construction succeeds. Either assert timeout behavior explicitly or rename the test to reflect what it checks.

✏️ Minimal correction (rename to match behavior)
-    it('should use default timeout of 10000ms', () => {
+    it('should construct when timeout is omitted', () => {
       const client = new AdminClient({ adminProvider: 'http://localhost:8485' });
       // We can't easily inspect private fields, but the constructor should not throw
       expect(client).toBeInstanceOf(AdminClient);
     });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unitTests/api_client/admin_client.test.ts` around lines 26 - 30, The
test titled "should use default timeout of 10000ms" is incorrectly asserting
only that new AdminClient(...) constructs successfully; update the test to
either assert the actual timeout behavior on the AdminClient instance or rename
the test to match its current assertion. Specifically, either change the it(...)
description to something like "should construct AdminClient with default
options" to match the existing expect(client).toBeInstanceOf(AdminClient), or
add an assertion that inspects/observes timeout behavior (e.g., via a public
getter, exposed config, or a mock request using AdminClient) to verify the
default 10000ms timeout; use the AdminClient constructor symbol to locate and
update the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/api_client/admin_client.ts`:
- Around line 97-110: The constructor of AdminClient currently assumes config is
defined and accepts whitespace-only URLs; update the AdminClient constructor to
first validate that the incoming config parameter is provided (throw a clear
Error if undefined/null) and then validate config.adminProvider by trimming
whitespace and ensuring the resulting string is non-empty (throw the existing
error message if invalid). Keep existing environment check (typeof window) and
assign this.adminProvider to the trimmed URL and this.timeout to config.timeout
?? 10000 after validation; reference the constructor, AdminClientConfig,
this.adminProvider and timeout when making the changes.

---

Nitpick comments:
In `@tests/unitTests/api_client/admin_client.test.ts`:
- Around line 26-30: The test titled "should use default timeout of 10000ms" is
incorrectly asserting only that new AdminClient(...) constructs successfully;
update the test to either assert the actual timeout behavior on the AdminClient
instance or rename the test to match its current assertion. Specifically, either
change the it(...) description to something like "should construct AdminClient
with default options" to match the existing
expect(client).toBeInstanceOf(AdminClient), or add an assertion that
inspects/observes timeout behavior (e.g., via a public getter, exposed config,
or a mock request using AdminClient) to verify the default 10000ms timeout; use
the AdminClient constructor symbol to locate and update the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 941b6524-b661-40a5-8de6-b35bc8b3f821

📥 Commits

Reviewing files that changed from the base of the PR and between e09df83 and 2265d30.

📒 Files selected for processing (5)
  • .gitignore
  • src/api_client/admin_client.ts
  • src/index.ts
  • tests/unitTests/api_client/admin_client.test.ts
  • tsconfig.json

Comment thread src/api_client/admin_client.ts
@MicBun
MicBun merged commit ad04f38 into main Apr 16, 2026
3 of 4 checks passed
@MicBun
MicBun deleted the adminnode branch April 16, 2026 13:31
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