Add bm users/whoami/access-key commands + CLI table flag consistency#408
Merged
Conversation
Adds full Business Manager Data API user administration to the CLI:
- bm users list/get/search/update/delete (OCAPI /users, /user_search)
- bm whoami (OCAPI /users/this — defaults to user-auth)
- bm access-key get/create/set/delete (OCAPI /users/{login}/access_key/{scope};
optional [LOGIN] defaults to whoami; --scope is an enum with
WEBDAV_AND_STUDIO as the default)
A new SDK module @salesforce/b2c-tooling-sdk/operations/bm-users wraps
the underlying endpoints. Endpoints whose OCAPI documentation states
"a valid user is required" (whoami + access-key) extend a shared
BmUserAuthCommand base which defaults the auth-method priority to
['implicit'] so a fresh shell triggers browser login rather than
failing the API call with UserNotAvailableException.
Also reworks tabular output across the CLI for consistency:
- New SDK helpers columnFlagsFor() / selectColumns() replace 22 copies
of an identical getSelectedColumns() helper. printFieldsBlock() does
the same for *Get-style label/value detail blocks (5 commands).
- Adds --columns / --extended to ~30 list and search commands that
previously had no column-customization (bm roles list, webdav ls,
cap list, code list, content list, docs search, job search, logs list,
sites list, slas client list, every mrt/* list command, plus several
setup and scaffold commands). webdav ls --extended now exposes the
previously-hidden modified and contentType columns.
- Renames --confirm to --force on the new bm/users delete commands to
match the dominant codebase convention.
Skills + docs: new b2c-cli:b2c-bm-users-roles skill and a rewritten
docs/cli/bm.md page cover the four bm command groups and the user-auth
defaulting. The b2c-am skill now defers to the new BM skill.
Switches bm/users/delete and bm/access-key/delete from @inquirer/prompts to the SDK's @salesforce/b2c-tooling-sdk/ux confirm() introduced in main. Drops the @inquirer/prompts dependency from these two files.
Acts on findings from a post-merge audit covering both this branch and recently-merged main work: SDK: - Export ACCESS_KEY_SCOPES + AccessKeyScope from operations/bm-users so the 4 access-key CLI commands no longer redeclare the same tuple. - Refresh stale doc comment on getBmUserAccessKey (referenced removed example values 'WEBDAV', 'OCAPI', 'SCAPI'). - printFieldsBlock now accepts null in addition to undefined and skips both, matching the common shape of optional OpenAPI fields. New DetailValue type alias exported. CLI — apply our helpers to MRT commands main introduced in PR #407: - mrt/org/cert/list and mrt/org/member/list now use TableRenderer + columnFlagsFor + selectColumns instead of inline createTable. - mrt/org/cert/get and mrt/org/member/get now use printFieldsBlock instead of inline cliui label/value rendering. CLI — finish the @inquirer/prompts -> SDK ux migration begun in main: - setup, setup/instance/remove, sandbox/reset, sandbox/alias/delete, and mrt/env/var/push now use confirm() from @salesforce/b2c-tooling-sdk/ux. The two remaining @inquirer/prompts importers (setup/skills, setup/instance/create) need more than just confirm so they stay as-is for now.
10 new test files following the bm/roles test patterns. Each covers:
JSON-mode return shape, non-JSON output (where applicable),
flag/arg behavior, and OCAPI error paths via the expectError helper.
- whoami.test.ts (3 cases)
- users/{list,get,delete}.test.ts (3 cases each)
- users/search.test.ts (5 cases — covers convenience flags, raw --query
passthrough, and invalid JSON rejection)
- users/update.test.ts (4 cases — covers the field→snake_case mapping
and "no fields" guard)
- access-key/{get,delete}.test.ts cover both the explicit-login and
whoami-fallback branches via two-call OCAPI stubs
- access-key/{create,set}.test.ts cover scope flag and PATCH body shape
CLI tests now: 1218 passing (was 1184). SDK tests unchanged at 1722.
bm.md: - Lead the Authentication section with the two flows (client-credentials vs user-auth) and explicit setup before the "defaults" table. - Document --user-auth, --auth-methods, and SFCC_AUTH_METHODS overrides with concrete examples. - Annotate the OCAPI permissions table with which command uses each resource so readers know what to grant. - Add a dedicated subsection on the Manage_Users_Access_Keys BM functional permission required for access-key writes. - Add Configuration Examples block. authentication.md: - Add "BM administration" entry under "Minimal Configuration by Feature" with the importable JSON snippet covering /roles, /users, /users/this, /users/*/access_key/*, and /user_search. - Add a tip box explaining the user-identity requirement on whoami / access-key endpoints and cross-link back to /cli/bm#authentication. Both pages now properly cross-link to each other.
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
Two related changes bundled together since the second was discovered while implementing the first:
1. New
b2c bmData API user administrationAdds full Business Manager user-side administration to the CLI:
bm users list/get/search/update/delete— OCAPI/users,/user_searchbm whoami—/users/this(defaults to user-auth)bm access-key get/create/set/delete—/users/{login}/access_key/{scope}.[LOGIN]is optional (defaults to whoami),--scopeis an enum (WEBDAV_AND_STUDIO/AGENT_USER_AND_OCAPI/STOREFRONT) defaulting toWEBDAV_AND_STUDIOso common usage isb2c bm access-key createto rotate your own WebDAV password.A new SDK module
@salesforce/b2c-tooling-sdk/operations/bm-userswraps the endpoints. Endpoints whose OCAPI documentation states "a valid user is required" (whoami + access-key) extend aBmUserAuthCommandbase that defaultsauthMethodsto['implicit']— a fresh shell triggers browser login rather than failing withUserNotAvailableException. Explicit--auth-methods/--client-secretoverrides still win.2. CLI table flag consistency refactor
While auditing the new commands I found 22 list commands with copy-pasted
getSelectedColumns()helpers and 30 commands with no column-customization at all. This fixes both:columnFlagsFor()/selectColumns()replace the 22 duplicates.printFieldsBlock()does the same for*Get-style label/value detail blocks (5 commands).--columns/--extended(-c/-x) added to ~30 commands that lacked them —bm roles list,webdav ls,cap list,code list,content list,docs search,job search,logs list,sites list,slas client list, everymrt/*list command, plus severalsetupandscaffoldcommands.webdav ls --extendednow exposes the previously-hiddenmodifiedandcontentTypecolumns.--confirmto--forceon the newbm users deleteandbm access-key deletecommands to match the dominant codebase convention (13 other commands use--force; only 3 use--yes).Docs + skills
b2c-cli:b2c-bm-users-rolesskill covers all fourbmcommand groupsb2c-amskill is trimmed back to AM-only and defers to the new BM skilldocs/cli/bm.mdreplacesdocs/cli/bm-roles.mdwith comprehensive coverage of all four command groups, including the user-auth defaulting table and access-key scope enumTest plan
pnpm run typecheck:agentpassespnpm run lint:agentpassespnpm run test:agentpasses (1705 passing, 6 pending)b2c bm --help,b2c bm users --help,b2c bm access-key --helprender the new topic treeb2c bm whoamitriggers browser auth (verified by hitting the login page)b2c bm access-key createcalls PUT with no body (fixed empty-body issue at the SDK level)b2c bm roles list --help,b2c webdav ls --help, etc. show the new-c/-xflagsb2c bm whoami,bm access-key create,bm access-key getagainst a real instanceb2c bm users list(which keeps client-credentials default) works against a service-client setupmrt/*list commands render correctly