Skip to content

[CLI] Add --as-token option for CLI#2397

Merged
nezaj merged 4 commits intomainfrom
cli-as-token
Mar 21, 2026
Merged

[CLI] Add --as-token option for CLI#2397
nezaj merged 4 commits intomainfrom
cli-as-token

Conversation

@nezaj
Copy link
Contributor

@nezaj nezaj commented Mar 20, 2026

What it says on the tin!

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 716184c8-dcdb-4d6f-a085-40fca7729b4a

📥 Commits

Reviewing files that changed from the base of the PR and between e83b148 and 07b6088.

📒 Files selected for processing (4)
  • client/packages/cli/__tests__/e2e/cli.e2e.test.ts
  • client/packages/cli/src/index.js
  • client/packages/version/src/version.ts
  • client/www/pages/docs/cli.md

📝 Walkthrough

Walkthrough

This PR adds support for a new --as-token CLI option to the query command, enabling users to run queries as a user identified by their refresh token. The implementation includes CLI flag handling, request header construction, end-to-end test coverage, documentation updates, and a version bump.

Changes

Cohort / File(s) Summary
CLI Implementation
client/packages/cli/src/index.js
Added --as-token <refresh-token> flag to query command with mutually-exclusive context validation and as-token request header construction for /admin/query endpoint.
E2E Tests
client/packages/cli/__tests__/e2e/cli.e2e.test.ts
Added new test case for --as-token flag that verifies restricted view permissions are enforced when querying as a user identified by their refresh token.
Documentation
client/www/pages/docs/cli.md
Documented the new --as-token <refresh-token> flag in the CLI query command reference.
Version Bump
client/packages/version/src/version.ts
Updated version constant from v0.22.168 to v0.22.169.

Sequence Diagram

sequenceDiagram
    participant User as User/CLI
    participant CLI as handleQuery()
    participant Headers as Request Headers
    participant Server as /admin/query Server

    User->>CLI: query --as-token <refreshToken>
    CLI->>CLI: Validate context (--as-token, --admin, --as-email, --as-guest mutually exclusive)
    CLI->>Headers: Set headers['as-token'] = refreshToken
    Headers->>Server: POST /admin/query with as-token header
    Server->>Server: Authenticate user from refresh token
    Server->>Server: Apply user-specific view permissions
    Server->>User: Return filtered query results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • stopachka
  • dwwoelfel
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description 'What it says on the tin!' is vague and uses non-descriptive language that doesn't convey meaningful information about the changeset. Provide a more descriptive summary of what the --as-token option does and why it was added, even if brief.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a --as-token option to the CLI, which is the primary focus of the changeset.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli-as-token

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

@stopachka stopachka left a comment

Choose a reason for hiding this comment

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

Niice!

@github-actions
Copy link
Contributor

View Vercel preview at instant-www-js-cli-as-token-jsv.vercel.app.

@nezaj nezaj merged commit 0978a2d into main Mar 21, 2026
28 checks passed
@nezaj nezaj deleted the cli-as-token branch March 21, 2026 00:01
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