-
Notifications
You must be signed in to change notification settings - Fork 3
fix(rpc): send x-account-id as HTTP header in RPC requests #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical bug where the RPC client was not sending x-account-id as an HTTP header, causing 400 Bad Request errors from the StackOne API.
- Extracts
x-account-idfrom request headers and includes it as an HTTP header in the fetch request - Maintains backwards compatibility by keeping
x-account-idin the request body - Adds test coverage to verify the header is properly sent at the HTTP level
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/rpc-client.ts | Extracts x-account-id from request headers and adds it to HTTP headers using type-safe conditional spreading |
| src/rpc-client.test.ts | Adds test case to verify x-account-id is sent both as HTTP header and in request body |
| mocks/handlers.ts | Updates MSW mock handler to capture and verify the x-account-id HTTP header |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 3 files
2f19072 to
9d7a698
Compare
The RPC client was sending x-account-id only in the request body's headers field, but the StackOne API expects it as an actual HTTP header. This caused 400 "Missing x-account-id header" errors when executing tools via the RPC endpoint. Changes: - Create src/schemas/headers.ts with shared header types and constants - Define STACKONE_HEADER_KEYS array for known headers to forward - Use Zod schema (stackOneHeadersSchema) for type-safe header validation - Forward all StackOne-specific headers as HTTP headers in RPC requests - Export Headers type from types.ts for consistency The fix extracts known StackOne headers from the request and includes them as HTTP headers on the fetch request while preserving them in the body for backwards compatibility.
9d7a698 to
8666db4
Compare
Summary
x-account-idas an actual HTTP header, not just in the request bodyx-account-idas an HTTP header for authentication/authorisationdefulibrary for clean header mergingProblem
When executing tools via the RPC endpoint (
/actions/rpc), the API returned:The
x-account-idwas being sent in the request body'sheadersfield:{ "action": "...", "headers": { "x-account-id": "..." }, ... }But the API expects it as an actual HTTP header on the request.
Solution
Architecture Changes
Created
src/schemas/headers.ts:STACKONE_HEADER_KEYSconstant for known headers to forwardstackOneHeadersSchemawith Zod branding for type safetyStackOneHeadersbranded typeCreated
src/utils/headers.ts:normaliseHeaders()utility functionUpdated
src/toolsets/base.ts:defufor clean header mergingUpdated
src/rpc-client.ts:STACKONE_HEADER_KEYSconstantKey Features
STACKONE_HEADER_KEYSdefufor merging, extracted utility functionsTest plan
should send x-account-id as HTTP headerto verify the fixnormaliseHeaders()utility function