feat(token): support read-write-stage-only granular access tokens #9948

Open
Tayvon opened 3:17pm on September 3, 2026 wants to merge 37 Δ into npm/cli latest from
tayvon-stage-only-gat-parity

Pull Request Overview

  • Opened on September 3, 2026
  • Status Open
  • Commit count 2 with first commit September 3, 2026

Total Delta

37 Total Diff Delta

Open Days

Open 12 weekdays

Test Delta

28 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Fraction of total time Business days Phase
 
0.3 days Authoring 2 commits before pull request opened for review
 
0.0 days Awaiting first review
 
11.0 days Revising work with 0 commits in response to 1 review that left 1 comment

Total time for pull request still awaiting merge (longer than repo's target): 11.3 business days

Author avatar

feat(token): support read-write-stage-only granular access tokens

Summary

Adds a read-write-stage-only value to the packages-and-scopes-permission option for npm token create, letting the CLI create granular access tokens with a stage-only publish policy (parity with the web UI). Also adds a deprecation warning when creating a direct-publish-capable token, steering users toward the stage-only value.

Changes


  • Add read-write-stage-only to the packages-and-scopes-permission config enum and update its description. orgs-permission is intentionally left unchanged (the registry only accepts read-write-stage-only for packages/scopes).


  • token create already forwards packages_and_scopes_permission verbatim in the POST body, so the value flows straight to the registry create-token route, which normalizes it to publish_policy: stage_only — identical to the web UI.

  • Add a log.warn when creating a token with read-write package/scope permission (direct-publish-capable), pointing users to --packages-and-scopes-permission=read-write-stage-only. Stage-only, read-only, and no-access tokens do not warn; --bypass-2fa is orthogonal and does not by itself trigger the warning.

  • Tests: creating a stage-only token asserts the POST body carries the value and emits no warning; read-write (with and without --bypass-2fa) emits the warning; --bypass-2fa alone does not.

  • Regenerate affected tap snapshots (docs.js, workspaces/config type-description.js).

Comments Threads Pending Resolution

ljharb reviewed on September 3, 2026
ljharb left a comment

## Copilot review overview

### 🟢 Approval recommended

The implementation matches the stated behavior and includes focused coverage for each permission scenario.

**Review tier:** Balanced
**Findings:** None

What changed in this PR

Adds stage-only granular token support and warns users creating direct-publish-capable tokens.

**Changes:**
- Adds and documents the `read-write-stage-only` permission.
- Warns when creating `read-write` tokens.
- Adds coverage and updates generated snapshots.

| File | Description |
| ---- | ----------- |
| `workspaces/​config/​lib/​definitions/​definitions.js` | Defines and documents the new permission. |
| `lib/​commands/​token.js` | Adds the direct-publish warning. |
| `test/​lib/​commands/​token.js` | Tests forwarding and warning behavior. |
| `workspaces/​config/​tap-snapshots/​test/​type-description.js.test.cjs` | Updates configuration snapshots. |
| `tap-snapshots/​test/​lib/​docs.js.test.cjs` | Updates generated documentation snapshots. |

---

💡 Add a `code-review` agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Resolved Comment Threads

No resolved comments have been left on this PR.