feat: support SAMPLEX_API_KEY for CI/CD authentication#4
Merged
Conversation
When SAMPLE_API_KEY is set, the CLI uses x-api-key header instead of OAuth Bearer tokens. This enables authentication in CI/CD environments where interactive OAuth flows aren't possible. - API key takes precedence over OAuth credentials when both exist - No token refresh needed for API key auth - Updated error messages to mention SAMPLE_API_KEY as an alternative - Added 25 tests covering API key auth for rpc() and rpcUpload()
- Remove dead-code getAuthHeaders() helper, inline into requireAuth() - Add SAMPLEX_API_KEY assertion to rpcUpload 401 test for consistency - Add non-401 error tests (500) for both rpc and rpcUpload with API key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SAMPLE_API_KEYenvironment variable support for CI/CD authenticationx-api-keyheader instead of OAuth Bearer tokens — no interactive login neededsamplex loginChanges
src/lib/env.ts— AddedSAMPLE_API_KEYenv varsrc/lib/api.ts—requireAuth()checks API key first, falls back to OAuth. Separate error messages for API key vs OAuth 401s. No token refresh when using API key.src/lib/__tests__/api.test.ts— 25 new tests covering API key auth path (97 total, up from 72)Usage
Test plan
bun run test)bun run check-types)SAMPLEX_API_KEY=user_... samplex listusesx-api-keyheaderSAMPLEX_API_KEY=user_bad samplex listshows "API key is invalid or expired"samplex loginandSAMPLEX_API_KEY