[HDX-4129] CLI: support multiple teams and kubectx-style team switching#2176
[HDX-4129] CLI: support multiple teams and kubectx-style team switching#2176
Conversation
Adds three new commands for users that belong to multiple teams (HyperDX Cloud / EE): - `hdx team list` — list every team the authenticated user belongs to, marking the active one - `hdx team current` — print the currently active team - `hdx team use <name-or-id>` — switch the active team (matched by team ID or case-insensitive name) The active team is persisted to ~/.config/hyperdx/cli/session.json so the choice survives across CLI invocations, and the CLI now sends an `x-hdx-team` header on every API and ClickHouse-proxy request so the server scopes data to the chosen team. `hdx auth status` also surfaces the active team. On single-team OSS deployments these commands are effectively no-ops (the OSS API ignores the team header). HDX-4129
🦋 Changeset detectedLatest commit: f45681c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
E2E Test Results✅ All tests passed • 160 passed • 3 skipped • 1144s
Tests ran across 4 shards in parallel. |
🟡 Tier 3 — StandardIntroduces new logic, modifies core functionality, or touches areas with non-trivial risk. Why this tier:
Review process: Full human review — logic, architecture, edge cases. Stats
|
MeResponse is used only inside client.ts — exporting it tripped knip's unused-exports check.
PR Review
|
Summary
Adds kubectx-style team switching to
@hyperdx/cliso users that belong tomultiple teams (HyperDX Cloud / EE) can scope CLI commands to any of their
teams without re-authenticating.
Three new commands under
hdx team:hdx team list— lists every team the authenticated user belongs to, withthe active team highlighted (
▸).hdx team current— prints just the active team (handy in scripts).hdx team use <name-or-id>— switches the active team. Matches by team IDfirst, then falls back to case-insensitive name lookup. Errors out with the
full list when no match is found.
Mechanics:
SessionConfiggains an optionalactiveTeamId. It's persisted to~/.config/hyperdx/cli/session.jsonalongside the cookies so the choicesurvives across CLI invocations.
ApiClientinjects anx-hdx-teamheader on every REST call when anactive team is set.
ProxyClickhouseClientdoes the same on the underlyingClickHouse-proxy request — both at construction time (initial header set)
and per-query (so a mid-session change is picked up).
getMe()now typesteams?: MeTeam[]. EE's/api/mereturns the array;OSS doesn't, so
getUserTeams()falls back to a single-element listcontaining
me.team.auth loginclears any previously persisted active team — theprior choice may not apply to a freshly authenticated user.
hdx auth statusnow surfaces the active team alongside the email/server.The header pattern matches the EE auth middleware
(
packages/api/src/middleware/auth.ts)and the existing browser app
(
packages/app/src/api.ts addTeamHook).On OSS the header is harmless — the OSS API has no multi-team support and
ignores it.
Screenshots or video
N/A — terminal CLI changes only.
How to test locally or on Vercel
Single-team (OSS) smoke test:
cd packages/cli && yarn build:common-utils && yarn dev auth login -a http://localhost:8080yarn dev team list— should show one team with▸and a hint thatteam useis a no-op here.yarn dev team current— should print the same team.yarn dev team use <that-team-id>— should print "Switched to …".yarn dev auth status— should now also show the team line.~/.config/hyperdx/cli/session.jsoncontains anactiveTeamIdfield.
yarn dev sources— should still return the team's sources.yarn dev auth login -a http://localhost:8080 -e ... -p ...— verify afresh login resets
activeTeamIdto undefined in the session file.Multi-team (EE) smoke test (requires hyperdx-ee deployment with a user
that has multiple team memberships):
yarn dev auth login -a https://your-ee-instanceand authenticate.yarn dev team list— both teams should be listed.yarn dev team use <other-team-name>— switch.yarn dev sources— should now return the other team's sources(the API receives
x-hdx-teamand scopes accordingly).References
/api/mereturns theteamsarray(
hyperdx-ee/packages/api/src/routers/api/me.ts); EE auth middlewarevalidates
x-hdx-teamagainst user membership(
hyperdx-ee/packages/api/src/middleware/auth.ts).