Skip to content

Commit b2e8910

Browse files
authored
Unified Configuration System with Plugin Extensibility Hooks (#30)
* refactoring configuration loading * clarity in docs and jsdocc * wip config resolution * Add plugin hook system for custom config sources - Add b2c:config-sources hook for plugins to provide ConfigSource instances - Support priority ordering (before/after default sources) - Create example plugin demonstrating .env.b2c config loading - Add documentation for extending the CLI with custom plugins * Add credential grouping to prevent mixing creds from different sources OAuth (clientId/clientSecret) and Basic auth (username/password) credentials are now treated as atomic groups. If any field in a group is set by a higher-priority source, all fields in that group from lower-priority sources are skipped. This prevents accidentally mixing credentials that don't belong together. * more flexible options for config source plugins * adding info about 3rd party plugins * doc update * adding more hook support for extensions * refactoring instance lifecycle to the proper class
1 parent d8475be commit b2e8910

52 files changed

Lines changed: 5261 additions & 459 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/.vitepress/config.mts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const guideSidebar = [
1212
{ text: 'Agent Skills & Plugins', link: '/guide/agent-skills' },
1313
],
1414
},
15+
{
16+
text: 'Extending',
17+
items: [
18+
{ text: 'Custom Plugins', link: '/guide/extending' },
19+
{ text: '3rd Party Plugins', link: '/guide/third-party-plugins' },
20+
],
21+
},
1522
{
1623
text: 'CLI Reference',
1724
items: [

docs/guide/configuration.md

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,98 @@ 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. **Plugin sources (high priority)** - Custom sources with `priority: 'before'`
156+
3. **dw.json** - Project configuration file
157+
4. **~/.mobify** - Home directory file (for MRT API key only)
158+
5. **Plugin sources (low priority)** - Custom sources with `priority: 'after'`
159+
160+
::: tip Extending Configuration
161+
Plugins can add custom configuration sources like secret managers or environment-specific files. See [Extending the CLI](./extending) for details.
162+
:::
163+
164+
### Credential Grouping
165+
166+
To prevent mixing credentials from different sources, certain fields are treated as atomic groups:
167+
168+
- **OAuth**: `clientId` and `clientSecret`
169+
- **Basic Auth**: `username` and `password`
170+
171+
If any field in a group is set by a higher-priority source, all fields in that group from lower-priority sources are ignored. This ensures credential pairs always come from the same source.
172+
173+
**Example:**
174+
- dw.json provides `clientId` only
175+
- A plugin provides `clientSecret`
176+
- Result: Only `clientId` is used; the plugin's `clientSecret` is ignored to prevent mismatched credentials
177+
178+
::: warning Hostname Mismatch Protection
179+
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.
180+
:::
90181

91182
## Next Steps
92183

0 commit comments

Comments
 (0)