Skip to content

Commit fd97748

Browse files
authored
Refactor ConfigSource API for better encapsulation (#54)
* better logging in config sources for debugging * Refactor ConfigSource API for better encapsulation - Change loadDwJson() to return {config, path} for proper path tracking - Make internal utilities internal (remove mapDwJsonToNormalizedConfig, mergeConfigsWithProtection, getPopulatedFields from exports) - Remove deprecated 'sources' option from ResolveConfigOptions - CLI commands now use ResolvedB2CConfig directly with .values.* access - SDK command classes use factory methods (createB2CInstance(), createMrtAuth(), etc.) instead of manual construction - Fix replaceDefaultSources option to work without sourcesAfter BREAKING CHANGE: loadConfig() now returns ResolvedB2CConfig instead of NormalizedConfig. Access config values via .values.* property. * debugging logging * Improve structured logging with proper fields and messages Add missing structured fields to log calls while preserving human-readable messages with interpolated values. This makes logs both machine-parseable and human-friendly. Changes: - Add jobId, executionId, path fields to job operations - Add cartridgeName, codeVersionId fields to code operations - Add method, url fields to client logging - Add headerName, keyPreview, username, port fields to auth - Change reserved 'hostname' field to 'server' in watch.ts * change interface of config sources for clarity * dw json should not return config on invalid instance name * update docs * config loading options for plugins * fix account-manager-host flag default overriding dw.json config The oclif flag had a default value that was always passed as an override to config resolution, preventing dw.json values from being used. Remove the default from the flag and rely on the existing fallback in the accountManagerHost getter.
1 parent d9b8ddf commit fd97748

Some content is hidden

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

56 files changed

+502
-742
lines changed

docs/guide/extending.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,28 @@ export default hook;
151151
// src/sources/my-custom-source.ts
152152
import type {
153153
ConfigSource,
154-
NormalizedConfig,
154+
ConfigLoadResult,
155155
ResolveConfigOptions
156156
} from '@salesforce/b2c-tooling-sdk/config';
157157

158158
export class MyCustomSource implements ConfigSource {
159159
readonly name = 'my-custom-source';
160160

161-
load(options: ResolveConfigOptions): NormalizedConfig | undefined {
161+
load(options: ResolveConfigOptions): ConfigLoadResult | undefined {
162162
// Load config from your custom source
163163
// Return undefined if source is not available
164164

165165
return {
166-
hostname: 'example.sandbox.us03.dx.commercecloud.salesforce.com',
167-
clientId: 'your-client-id',
168-
clientSecret: 'your-client-secret',
169-
codeVersion: 'version1',
166+
config: {
167+
hostname: 'example.sandbox.us03.dx.commercecloud.salesforce.com',
168+
clientId: 'your-client-id',
169+
clientSecret: 'your-client-secret',
170+
codeVersion: 'version1',
171+
},
172+
// Location is used for diagnostics - can be a file path, keychain entry, URL, etc.
173+
location: '/path/to/config/source',
170174
};
171175
}
172-
173-
// Optional: return path for diagnostics
174-
getPath(): string | undefined {
175-
return '/path/to/config/source';
176-
}
177176
}
178177
```
179178

packages/b2c-cli/src/commands/code/activate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ export default class CodeActivate extends InstanceCommand<typeof CodeActivate> {
3838
this.requireOAuthCredentials();
3939

4040
const codeVersionArg = this.args.codeVersion;
41-
const hostname = this.resolvedConfig.hostname!;
41+
const hostname = this.resolvedConfig.values.hostname!;
4242

4343
// Get code version from arg, flag, or config
44-
const codeVersion = codeVersionArg ?? this.resolvedConfig.codeVersion;
44+
const codeVersion = codeVersionArg ?? this.resolvedConfig.values.codeVersion;
4545

4646
if (this.flags.reload) {
4747
// Reload mode - re-activate the code version

packages/b2c-cli/src/commands/code/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class CodeDelete extends InstanceCommand<typeof CodeDelete> {
5555
this.requireOAuthCredentials();
5656

5757
const codeVersion = this.args.codeVersion;
58-
const hostname = this.resolvedConfig.hostname!;
58+
const hostname = this.resolvedConfig.values.hostname!;
5959

6060
// Confirm deletion unless --force is used
6161
if (!this.flags.force) {

packages/b2c-cli/src/commands/code/deploy.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
5151
this.requireWebDavCredentials();
5252
this.requireOAuthCredentials();
5353

54-
const hostname = this.resolvedConfig.hostname!;
55-
let version = this.resolvedConfig.codeVersion;
54+
const hostname = this.resolvedConfig.values.hostname!;
55+
let version = this.resolvedConfig.values.codeVersion;
5656

5757
// If no code version specified, discover the active one
5858
if (!version) {
@@ -102,7 +102,8 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
102102
this.error(t('commands.code.deploy.noCartridges', 'No cartridges found in {{path}}', {path: this.cartridgePath}));
103103
}
104104

105-
this.log(
105+
this.logger?.info(
106+
{path: this.cartridgePath, server: hostname, codeVersion: version},
106107
t('commands.code.deploy.deploying', 'Deploying {{path}} to {{hostname}} ({{version}})', {
107108
path: this.cartridgePath,
108109
hostname,
@@ -112,7 +113,7 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
112113

113114
// Log found cartridges
114115
for (const c of cartridges) {
115-
this.logger?.debug(` ${c.name} (${c.src})`);
116+
this.logger?.debug({cartridgeName: c.name, path: c.src}, ` ${c.name}`);
116117
}
117118

118119
try {
@@ -141,7 +142,8 @@ export default class CodeDeploy extends CartridgeCommand<typeof CodeDeploy> {
141142
reloaded,
142143
};
143144

144-
this.log(
145+
this.logger?.info(
146+
{codeVersion: result.codeVersion, cartridgeCount: result.cartridges.length},
145147
t('commands.code.deploy.summary', 'Deployed {{count}} cartridge(s) to {{codeVersion}}', {
146148
count: result.cartridges.length,
147149
codeVersion: result.codeVersion,

packages/b2c-cli/src/commands/code/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class CodeList extends InstanceCommand<typeof CodeList> {
4747
async run(): Promise<CodeVersionResult> {
4848
this.requireOAuthCredentials();
4949

50-
const hostname = this.resolvedConfig.hostname!;
50+
const hostname = this.resolvedConfig.values.hostname!;
5151

5252
this.log(t('commands.code.list.fetching', 'Fetching code versions from {{hostname}}...', {hostname}));
5353

packages/b2c-cli/src/commands/code/watch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ export default class CodeWatch extends CartridgeCommand<typeof CodeWatch> {
3131
this.requireWebDavCredentials();
3232
this.requireOAuthCredentials();
3333

34-
const hostname = this.resolvedConfig.hostname!;
35-
const version = this.resolvedConfig.codeVersion;
34+
const hostname = this.resolvedConfig.values.hostname!;
35+
const version = this.resolvedConfig.values.codeVersion;
3636

3737
this.log(t('commands.code.watch.starting', 'Starting watcher for {{path}}', {path: this.cartridgePath}));
3838
this.log(t('commands.code.watch.target', 'Target: {{hostname}}', {hostname}));

packages/b2c-cli/src/commands/docs/download.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default class DocsDownload extends InstanceCommand<typeof DocsDownload> {
4646

4747
this.log(
4848
t('commands.docs.download.downloading', 'Downloading documentation from {{hostname}}...', {
49-
hostname: this.resolvedConfig.hostname,
49+
hostname: this.resolvedConfig.values.hostname,
5050
}),
5151
);
5252

packages/b2c-cli/src/commands/job/export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export default class JobExport extends JobCommand<typeof JobExport> {
117117
'show-log': showLog,
118118
} = this.flags;
119119

120-
const hostname = this.resolvedConfig.hostname!;
120+
const hostname = this.resolvedConfig.values.hostname!;
121121

122122
// Build data units configuration
123123
const dataUnits = this.buildDataUnits({

packages/b2c-cli/src/commands/job/import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default class JobImport extends JobCommand<typeof JobImport> {
6363
const {target} = this.args;
6464
const {'keep-archive': keepArchive, remote, timeout, 'show-log': showLog} = this.flags;
6565

66-
const hostname = this.resolvedConfig.hostname!;
66+
const hostname = this.resolvedConfig.values.hostname!;
6767

6868
// Create lifecycle context
6969
const context = this.createContext('job:import', {

packages/b2c-cli/src/commands/job/run.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export default class JobRun extends JobCommand<typeof JobRun> {
8282
parameters: rawBody ? undefined : parameters,
8383
body: rawBody,
8484
wait,
85-
hostname: this.resolvedConfig.hostname,
85+
hostname: this.resolvedConfig.values.hostname,
8686
});
8787

8888
// Run beforeOperation hooks - check for skip
@@ -100,7 +100,7 @@ export default class JobRun extends JobCommand<typeof JobRun> {
100100
this.log(
101101
t('commands.job.run.executing', 'Executing job {{jobId}} on {{hostname}}...', {
102102
jobId,
103-
hostname: this.resolvedConfig.hostname!,
103+
hostname: this.resolvedConfig.values.hostname!,
104104
}),
105105
);
106106

0 commit comments

Comments
 (0)