Skip to content

Commit 470a3ba

Browse files
committed
docs: add package.json config source and priority system documentation
- Add "Project Configuration (package.json)" section to configuration.md - Document allowed fields: shortCode, clientId, mrtProject, mrtOrigin, accountManagerHost - Explain security rationale for excluding sensitive fields - Update resolution priority list to include package.json as lowest priority - Document numeric priority system in extending.md - Add priority table showing ranges (< 0, 0, 1-999, 1000) - Add example showing how to set priority on custom ConfigSource
1 parent 17d5c30 commit 470a3ba

2 files changed

Lines changed: 76 additions & 9 deletions

File tree

docs/guide/configuration.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,56 @@ For multi-instance configurations, each config object also supports:
148148
| `name` | Instance name for selection with `-i`/`--instance` |
149149
| `active` | Set to `true` to use this config by default |
150150

151+
## Project Configuration (package.json)
152+
153+
You can store project-level defaults in your `package.json` file under the `b2c` key. This is useful for settings that are shared across your entire project and safe to commit to version control.
154+
155+
```json
156+
{
157+
"name": "my-storefront",
158+
"version": "1.0.0",
159+
"b2c": {
160+
"shortCode": "abc123",
161+
"clientId": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
162+
"mrtProject": "my-project",
163+
"accountManagerHost": "account.demandware.com"
164+
}
165+
}
166+
```
167+
168+
### Allowed Fields
169+
170+
Only non-sensitive, project-level fields can be configured in `package.json`:
171+
172+
| Field | Description |
173+
|-------|-------------|
174+
| `shortCode` | SCAPI short code |
175+
| `clientId` | OAuth client ID (for implicit login discovery) |
176+
| `mrtProject` | MRT project slug |
177+
| `mrtOrigin` | MRT API origin URL override |
178+
| `accountManagerHost` | Account Manager hostname for OAuth |
179+
180+
::: warning Security Note
181+
Sensitive fields like `hostname`, `password`, `clientSecret`, `username`, and `mrtApiKey` are intentionally **not** supported in `package.json`. These should be configured via `dw.json` (which should be in `.gitignore`), environment variables, or secure credential stores.
182+
:::
183+
184+
::: tip Lowest Priority
185+
`package.json` has the lowest priority of all configuration sources. Values from `dw.json`, environment variables, or CLI flags will always override `package.json` settings. This makes it ideal for project defaults that can be overridden per-environment.
186+
:::
187+
151188
### Resolution Priority
152189

153190
Configuration is resolved with the following precedence (highest to lowest):
154191

155192
1. **CLI flags and environment variables** - Explicit values always take priority
156-
2. **Plugin sources (high priority)** - Custom sources with `priority: 'before'`
157-
3. **dw.json** - Project configuration file
158-
4. **~/.mobify** - Home directory file (for MRT API key only)
159-
5. **Plugin sources (low priority)** - Custom sources with `priority: 'after'`
193+
2. **Plugin sources (high priority)** - Custom sources with `priority: 'before'` (or priority < 0)
194+
3. **dw.json** - Project configuration file (priority 0)
195+
4. **~/.mobify** - Home directory file for MRT API key (priority 0)
196+
5. **Plugin sources (low priority)** - Custom sources with `priority: 'after'` (or priority 1-999)
197+
6. **package.json** - Project-level defaults (priority 1000, lowest)
160198

161199
::: tip Extending Configuration
162-
Plugins can add custom configuration sources like secret managers or environment-specific files. See [Extending the CLI](./extending) for details.
200+
Plugins can add custom configuration sources like secret managers or environment-specific files. Plugins can use numeric priorities for fine-grained control over ordering. See [Extending the CLI](./extending) for details.
163201
:::
164202

165203
### Credential Grouping

docs/guide/extending.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,48 @@ This hook is called during command initialization, after CLI flags are parsed bu
5858
| Property | Type | Description |
5959
|----------|------|-------------|
6060
| `sources` | `ConfigSource[]` | Config sources to add to resolution |
61-
| `priority` | `'before' \| 'after'` | Where to insert relative to defaults (default: `'after'`) |
61+
| `priority` | `'before' \| 'after' \| number` | Priority for sources (see below). Default: `'after'` |
62+
63+
::: tip Numeric Priorities
64+
String values map to numeric priorities: `'before'` → -1, `'after'` → 10. You can also use any numeric value directly for fine-grained control. Lower numbers = higher priority.
65+
:::
6266

6367
### Priority Ordering
6468

69+
Configuration sources use a numeric priority system where **lower numbers = higher priority**:
70+
71+
| Priority | Description | Example |
72+
|----------|-------------|---------|
73+
| < 0 | Override built-in sources | `'before'` maps to -1 |
74+
| 0 | Built-in sources | `dw.json`, `~/.mobify` |
75+
| 1-999 | After built-in sources | `'after'` maps to 10 |
76+
| 1000 | Lowest priority | `package.json` |
77+
6578
Configuration is resolved with the following precedence:
6679

6780
1. **CLI flags and environment variables** - Always highest priority
68-
2. **Plugin sources with `priority: 'before'`** - Override dw.json defaults
69-
3. **Default sources** - `dw.json` and `~/.mobify`
70-
4. **Plugin sources with `priority: 'after'`** - Fill gaps left by defaults
81+
2. **Plugin sources with `priority: 'before'` (or < 0)** - Override dw.json defaults
82+
3. **Default sources** - `dw.json` and `~/.mobify` (priority 0)
83+
4. **Plugin sources with `priority: 'after'` (or 1-999)** - Fill gaps left by defaults
84+
5. **package.json** - Project-level defaults (priority 1000)
7185

7286
Each source fills in missing values - it doesn't override values from higher-priority sources.
7387

88+
::: tip Custom ConfigSource Priority
89+
When implementing a custom `ConfigSource`, you can set the `priority` property directly on your class:
90+
91+
```typescript
92+
export class MyCustomSource implements ConfigSource {
93+
readonly name = 'my-custom-source';
94+
readonly priority = 5; // Between 'before' (-1) and 'after' (10)
95+
96+
load(options: ResolveConfigOptions): ConfigLoadResult | undefined {
97+
// ...
98+
}
99+
}
100+
```
101+
:::
102+
74103
::: warning Credential Grouping
75104
OAuth credentials (`clientId`/`clientSecret`) and Basic auth credentials (`username`/`password`) are treated as atomic groups. If any field in a group is already set by a higher-priority source, all fields in that group from your source will be ignored. Ensure your source provides complete credential pairs, or that higher-priority sources don't partially define the same credentials.
76105
:::

0 commit comments

Comments
 (0)