Skip to content

Commit 4bcd3c8

Browse files
committed
changes to inspect and configuration skills for clarity and progressive disclosure
1 parent 211cea5 commit 4bcd3c8

2 files changed

Lines changed: 87 additions & 28 deletions

File tree

packages/b2c-cli/src/commands/setup/inspect.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import {withDocs} from '../../i18n/index.js';
1313
/**
1414
* Sensitive fields that should be masked by default.
1515
*/
16-
const SENSITIVE_FIELDS = new Set<keyof NormalizedConfig>(['clientSecret', 'mrtApiKey', 'password', 'slasClientSecret']);
16+
const SENSITIVE_FIELDS = new Set<keyof NormalizedConfig>([
17+
'certificatePassphrase',
18+
'clientSecret',
19+
'mrtApiKey',
20+
'password',
21+
'slasClientSecret',
22+
]);
1723

1824
/**
1925
* JSON output structure for the inspect command.
@@ -169,7 +175,7 @@ export default class SetupInspect extends BaseCommand<typeof SetupInspect> {
169175
'Instance',
170176
[
171177
['hostname', config.hostname],
172-
['webdavHostname', config.webdavHostname],
178+
...(config.webdavHostname ? [['webdavHostname', config.webdavHostname] as [string, unknown]] : []),
173179
['codeVersion', config.codeVersion],
174180
],
175181
fieldSources,
@@ -197,13 +203,28 @@ export default class SetupInspect extends BaseCommand<typeof SetupInspect> {
197203
['clientSecret', config.clientSecret],
198204
['scopes', config.scopes],
199205
['authMethods', config.authMethods],
200-
['accountManagerHost', config.accountManagerHost],
201-
['sandboxApiHost', config.sandboxApiHost],
206+
...(config.accountManagerHost ? [['accountManagerHost', config.accountManagerHost] as [string, unknown]] : []),
207+
...(config.sandboxApiHost ? [['sandboxApiHost', config.sandboxApiHost] as [string, unknown]] : []),
202208
],
203209
fieldSources,
204210
unmask,
205211
);
206212

213+
// TLS/mTLS section (only shown when at least one TLS field is configured)
214+
if (config.certificate || config.certificatePassphrase || config.selfSigned) {
215+
this.renderSection(
216+
ui,
217+
'TLS/mTLS',
218+
[
219+
['certificate', config.certificate],
220+
['certificatePassphrase', config.certificatePassphrase],
221+
['selfSigned', config.selfSigned],
222+
],
223+
fieldSources,
224+
unmask,
225+
);
226+
}
227+
207228
// SCAPI section
208229
this.renderSection(
209230
ui,
@@ -224,7 +245,7 @@ export default class SetupInspect extends BaseCommand<typeof SetupInspect> {
224245
['mrtProject', config.mrtProject],
225246
['mrtEnvironment', config.mrtEnvironment],
226247
['mrtApiKey', config.mrtApiKey],
227-
['mrtOrigin', config.mrtOrigin],
248+
...(config.mrtOrigin ? [['mrtOrigin', config.mrtOrigin] as [string, unknown]] : []),
228249
],
229250
fieldSources,
230251
unmask,

skills/b2c-cli/skills/b2c-config/SKILL.md

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,54 @@ description: View and debug b2c CLI configuration and understand where credentia
55

66
# B2C Config Skill
77

8-
Use the `b2c setup inspect` command to view the resolved configuration and understand where each value comes from. Use the `b2c setup instance` commands to manage named instance configurations.
8+
The B2C CLI (`@salesforce/b2c-cli`) is a command-line tool for Salesforce B2C Commerce development. It provides commands organized by topic: `auth`, `code`, `webdav`, `sandbox`, `mrt`, `scapi`, `slas`, `ecdn`, `job`, `logs`, `sites`, `content`, `cip`, `setup`, and more. Use `b2c --help` or `b2c <topic> --help` for a full list.
99

10-
> **Tip:** `b2c setup config` still works as an alias. If `b2c` is not installed globally, use `npx @salesforce/b2c-cli` instead (e.g., `npx @salesforce/b2c-cli setup inspect`).
10+
> **Tip:** If `b2c` is not installed globally, use `npx @salesforce/b2c-cli` instead (e.g., `npx @salesforce/b2c-cli setup inspect`).
1111
12-
## When to Use
12+
## Authentication
13+
14+
Most commands that interact with a B2C Commerce instance require authentication. The CLI supports several methods:
15+
16+
- **Client credentials (API client):** Configure `clientId` and `clientSecret` in dw.json or environment variables. This is the default for automated/CI use.
17+
- **Browser-based (implicit OAuth):** Use `--user-auth` on any OAuth-enabled command to authenticate interactively via the browser. This opens Account Manager in your default browser for login.
18+
- **Basic auth:** Configure `username` and `password` for WebDAV operations.
19+
- **Stateful sessions:** Use `b2c auth login` for persistent browser-based login sessions.
20+
21+
### `--user-auth` Flag
22+
23+
Many commands support `--user-auth` to use browser-based implicit OAuth instead of client credentials. This is useful when:
24+
25+
- You don't have a `clientSecret` configured
26+
- You need user-level permissions (e.g., Account Manager admin roles)
27+
- You're working interactively
28+
29+
```bash
30+
# Interactive browser-based auth for any OAuth command
31+
b2c sandbox list --user-auth
32+
b2c scapi schemas list --user-auth
33+
b2c auth token --user-auth
34+
```
35+
36+
Coding agents can also use `--user-auth` — the browser flow works in any environment where a browser can be opened. The flag is exclusive with `--auth-methods`.
37+
38+
## Tenant ID and Organization ID
39+
40+
B2C Commerce uses two related identifiers:
41+
42+
- **Tenant ID** — the short form (e.g., `zzxy_prd` or `zzxy-prd`)
43+
- **Organization ID** — the SCAPI form with `f_ecom_` prefix (e.g., `f_ecom_zzxy_prd`)
44+
45+
The CLI automatically normalizes and translates between these formats. You can provide either form in configuration or flags — the CLI handles the conversion. It also extracts tenant IDs from hostnames (e.g., `zzxy-prd.dx.commercecloud.salesforce.com` resolves to `zzxy_prd`).
46+
47+
In dw.json or environment variables, use the `tenantId` config key. The CLI will add the `f_ecom_` prefix when making SCAPI calls.
48+
49+
## Inspecting Configuration
50+
51+
Use `b2c setup inspect` to view the resolved configuration and understand where each value comes from. Use `b2c setup instance` commands to manage named instance configurations.
52+
53+
> **Note:** `b2c setup config` works as an alias for `b2c setup inspect`.
54+
55+
### When to Use
1356

1457
Use `b2c setup inspect` when you need to:
1558

@@ -20,15 +63,6 @@ Use `b2c setup inspect` when you need to:
2063
- Identify hostname mismatch protection issues
2164
- Verify MRT API key is loaded from ~/.mobify
2265

23-
Use `b2c setup instance` commands when you need to:
24-
25-
- List all configured instances
26-
- Create a new instance configuration
27-
- Switch between instances (set active)
28-
- Remove an instance configuration
29-
30-
## Inspecting Configuration
31-
3266
### View Current Configuration
3367

3468
```bash
@@ -135,21 +169,22 @@ b2c setup instance remove staging --force
135169

136170
The `setup inspect` command displays configuration organized by category:
137171

138-
- **Instance**: hostname, webdavHostname, codeVersion
172+
- **Instance**: hostname, webdavHostname (if set), codeVersion
139173
- **Authentication (Basic)**: username, password (for WebDAV)
140-
- **Authentication (OAuth)**: clientId, clientSecret, scopes, authMethods
141-
- **TLS/mTLS**: certificate, certificatePassphrase, selfSigned (for two-factor auth)
142-
- **SCAPI**: shortCode
143-
- **Managed Runtime (MRT)**: mrtProject, mrtEnvironment, mrtApiKey
174+
- **Authentication (OAuth)**: clientId, clientSecret, scopes, authMethods, accountManagerHost (if set), sandboxApiHost (if set)
175+
- **TLS/mTLS**: certificate, certificatePassphrase, selfSigned (only shown when configured)
176+
- **SCAPI**: shortCode, tenantId
177+
- **Managed Runtime (MRT)**: mrtProject, mrtEnvironment, mrtApiKey, mrtOrigin (if set)
144178
- **Metadata**: instanceName (from multi-instance configs)
145179
- **Sources**: List of all configuration sources that were loaded
146180

147181
Each value shows its source in brackets:
148182

149-
- `[DwJsonSource]` - Value from dw.json file
150-
- `[MobifySource]` - Value from ~/.mobify file
151-
- `[SFCC_*]` - Value from environment variable
152-
- `[password-store]` - Value from a credential plugin
183+
- `[DwJsonSource]` — Value from dw.json file
184+
- `[EnvSource]` — Value from an SFCC_* environment variable
185+
- `[MobifySource]` — Value from ~/.mobify file
186+
- `[PackageJsonSource]` — Value from package.json `b2c` key
187+
- Plugin-provided source names (e.g., a credential plugin)
153188

154189
## Configuration Priority
155190

@@ -160,7 +195,7 @@ Values are resolved with this priority (highest to lowest):
160195
3. dw.json file
161196
4. ~/.mobify file (MRT API key only)
162197
5. Plugin sources (low priority)
163-
6. package.json b2c key
198+
6. package.json `b2c` key
164199

165200
When troubleshooting, check the source column to understand which configuration is taking precedence.
166201

@@ -194,6 +229,9 @@ Use `b2c auth token` to get an admin OAuth access token for Account Manager cred
194229
# Get access token (outputs raw token to stdout)
195230
b2c auth token
196231

232+
# Get token with browser-based auth
233+
b2c auth token --user-auth
234+
197235
# Get token with specific scopes
198236
b2c auth token --auth-scope sfcc.orders --auth-scope sfcc.products
199237

@@ -205,7 +243,7 @@ curl -H "Authorization: Bearer $(b2c auth token)" \
205243
"https://your-instance.dx.commercecloud.salesforce.com/s/-/dw/data/v24_1/sites"
206244
```
207245

208-
The token is obtained using the `clientId` and `clientSecret` from your configuration (dw.json or environment variables). If only `clientId` is configured, an implicit OAuth flow is used (browser-based).
246+
The token is obtained using the `clientId` and `clientSecret` from your configuration (dw.json or environment variables). If only `clientId` is configured, or `--user-auth` is used, an implicit OAuth flow is used (browser-based).
209247

210248
**Note:** This command returns **admin** tokens for OCAPI/Admin APIs. For **shopper** tokens (SLAS), see the [b2c-slas skill](../b2c-slas/SKILL.md).
211249

0 commit comments

Comments
 (0)