Skip to content

Commit 782e21a

Browse files
committed
clarity in docs and jsdocc
1 parent 7fa1ad4 commit 782e21a

File tree

3 files changed

+133
-9
lines changed

3 files changed

+133
-9
lines changed

docs/guide/configuration.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,78 @@ You can configure authentication using environment variables:
8686

8787
## Configuration File
8888

89-
You can create a configuration file to store instance settings. See the [CLI Reference](/cli/) for more details on configuration file options.
89+
You can create a `dw.json` file to store instance settings. The CLI searches for this file starting from the current directory and walking up the directory tree.
90+
91+
### Single Instance
92+
93+
```json
94+
{
95+
"hostname": "your-instance.demandware.net",
96+
"code-version": "version1",
97+
"client-id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
98+
"client-secret": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
99+
}
100+
```
101+
102+
### Multiple Instances
103+
104+
For projects that work with multiple instances, use the `configs` array:
105+
106+
```json
107+
{
108+
"configs": [
109+
{
110+
"name": "dev",
111+
"active": true,
112+
"hostname": "dev-instance.demandware.net",
113+
"code-version": "version1",
114+
"client-id": "dev-client-id"
115+
},
116+
{
117+
"name": "staging",
118+
"hostname": "staging-instance.demandware.net",
119+
"code-version": "version1",
120+
"client-id": "staging-client-id"
121+
}
122+
]
123+
}
124+
```
125+
126+
Use the `--instance` flag to select a specific configuration:
127+
128+
```bash
129+
b2c code deploy --instance staging
130+
```
131+
132+
If no instance is specified, the config with `"active": true` is used.
133+
134+
### Supported Fields
135+
136+
| Field | Description |
137+
|-------|-------------|
138+
| `hostname` | B2C instance hostname |
139+
| `webdav-hostname` | Separate hostname for WebDAV (if different) |
140+
| `code-version` | Code version for deployments |
141+
| `client-id` | OAuth client ID |
142+
| `client-secret` | OAuth client secret |
143+
| `username` | Basic auth username |
144+
| `password` | Basic auth password/access-key |
145+
| `scopes` | OAuth scopes (array or comma-separated string) |
146+
| `auth-methods` | Authentication methods in priority order |
147+
| `account-manager-host` | Custom Account Manager hostname |
148+
| `shortCode` | SCAPI short code |
149+
150+
### Resolution Priority
151+
152+
Configuration is resolved with the following precedence (highest to lowest):
153+
154+
1. **CLI flags and environment variables** - Explicit values always take priority
155+
2. **dw.json** - Project configuration file
156+
3. **~/.mobify** - Home directory file (for MRT API key only)
157+
158+
::: warning Hostname Mismatch Protection
159+
When you explicitly specify a hostname that differs from the `dw.json` hostname, the CLI ignores all other values from `dw.json` and only uses your explicit overrides. This prevents accidentally using credentials from one instance with a different server.
160+
:::
90161

91162
## Next Steps
92163

packages/b2c-tooling-sdk/src/config/index.ts

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,34 @@
2727
* const instance = resolver.createInstance({ hostname: '...' });
2828
* ```
2929
*
30-
* ## Lower-Level APIs
30+
* ## Resolution Priority
3131
*
32-
* For advanced use cases, you can use the lower-level dw.json loading functions:
32+
* Configuration is resolved with the following precedence (highest to lowest):
3333
*
34-
* ```typescript
35-
* import { loadDwJson, findDwJson } from '@salesforce/b2c-tooling-sdk/config';
34+
* 1. **Explicit overrides** - Values passed to `resolve()`, `createInstance()`, etc.
35+
* 2. **Configuration sources** - dw.json, ~/.mobify (in order)
3636
*
37-
* const dwJsonPath = findDwJson();
38-
* const config = loadDwJson({ path: dwJsonPath, instance: 'staging' });
39-
* ```
37+
* Later sources only fill in missing values—they do not override values from
38+
* higher-priority sources.
39+
*
40+
* ## Hostname Mismatch Protection
41+
*
42+
* The configuration system includes safety protection against accidentally using
43+
* credentials from one instance with a different hostname. When you explicitly
44+
* specify a hostname that differs from the dw.json hostname:
45+
*
46+
* - The entire base configuration from dw.json is ignored
47+
* - Only your explicit overrides are used
48+
* - A warning is included in the resolution result
49+
*
50+
* This prevents credential leakage between different B2C instances.
51+
*
52+
* ## Default Configuration Sources
53+
*
54+
* The default sources loaded by {@link createConfigResolver} are:
55+
*
56+
* - **dw.json** - Project configuration file, searched upward from cwd
57+
* - **~/.mobify** - Home directory file for MRT API key
4058
*
4159
* ## Custom Configuration Sources
4260
*
@@ -53,6 +71,17 @@
5371
* const resolver = new ConfigResolver([new MySource()]);
5472
* ```
5573
*
74+
* ## Lower-Level APIs
75+
*
76+
* For advanced use cases, you can use the lower-level dw.json loading functions:
77+
*
78+
* ```typescript
79+
* import { loadDwJson, findDwJson } from '@salesforce/b2c-tooling-sdk/config';
80+
*
81+
* const dwJsonPath = findDwJson();
82+
* const config = loadDwJson({ path: dwJsonPath, instance: 'staging' });
83+
* ```
84+
*
5685
* @module config
5786
*/
5887

packages/b2c-tooling-sdk/src/config/mapping.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,19 @@ export function mergeConfigsWithProtection(
164164

165165
/**
166166
* Gets the list of fields that have values in a config.
167-
* Used for tracking which sources contributed which fields.
167+
*
168+
* Used for tracking which sources contributed which fields during
169+
* configuration resolution.
170+
*
171+
* @param config - The configuration to inspect
172+
* @returns Array of field names that have non-empty values
173+
*
174+
* @example
175+
* ```typescript
176+
* const config = { hostname: 'example.com', clientId: 'abc' };
177+
* const fields = getPopulatedFields(config);
178+
* // ['hostname', 'clientId']
179+
* ```
168180
*/
169181
export function getPopulatedFields(config: NormalizedConfig): (keyof NormalizedConfig)[] {
170182
const fields: (keyof NormalizedConfig)[] = [];
@@ -184,6 +196,18 @@ export function getPopulatedFields(config: NormalizedConfig): (keyof NormalizedC
184196
*
185197
* @param config - The normalized configuration
186198
* @returns AuthConfig for B2CInstance
199+
*
200+
* @example
201+
* ```typescript
202+
* const config = {
203+
* clientId: 'my-client-id',
204+
* clientSecret: 'my-secret',
205+
* username: 'admin',
206+
* password: 'pass',
207+
* };
208+
* const authConfig = buildAuthConfigFromNormalized(config);
209+
* // { oauth: { clientId: '...', clientSecret: '...' }, basic: { username: '...', password: '...' } }
210+
* ```
187211
*/
188212
export function buildAuthConfigFromNormalized(config: NormalizedConfig): AuthConfig {
189213
const authConfig: AuthConfig = {

0 commit comments

Comments
 (0)