Skip to content

Commit 307910f

Browse files
committed
fix hostname defaults and overrides
1 parent e350147 commit 307910f

6 files changed

Lines changed: 48 additions & 9 deletions

File tree

packages/b2c-tooling/src/auth/oauth-implicit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {URL} from 'node:url';
44
import type {AuthStrategy, AccessTokenResponse, DecodedJWT} from './types.js';
55
import {getLogger} from '../logging/logger.js';
66
import {decodeJWT} from './oauth.js';
7+
import {DEFAULT_ACCOUNT_MANAGER_HOST} from '../defaults.js';
78

8-
const DEFAULT_ACCOUNT_MANAGER_HOST = 'account.demandware.com';
99
const DEFAULT_LOCAL_PORT = 8080;
1010

1111
// Module-level token cache to support multiple instances with same clientId

packages/b2c-tooling/src/auth/oauth.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {AuthStrategy, AccessTokenResponse, DecodedJWT} from './types.js';
22
import {getLogger} from '../logging/logger.js';
3-
4-
const DEFAULT_ACCOUNT_MANAGER_HOST = 'account.demandware.com';
3+
import {DEFAULT_ACCOUNT_MANAGER_HOST} from '../defaults.js';
54

65
// Module-level token cache to support multiple instances with same clientId
76
const ACCESS_TOKEN_CACHE: Map<string, AccessTokenResponse> = new Map();

packages/b2c-tooling/src/cli/oauth-command.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {ResolvedConfig, LoadConfigOptions, AuthMethod} from './config.js';
55
import {OAuthStrategy} from '../auth/oauth.js';
66
import {ImplicitOAuthStrategy} from '../auth/oauth-implicit.js';
77
import {t} from '../i18n/index.js';
8+
import {DEFAULT_ACCOUNT_MANAGER_HOST} from '../defaults.js';
89

910
/**
1011
* Base command for operations requiring OAuth authentication.
@@ -47,6 +48,12 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
4748
options: ALL_AUTH_METHODS,
4849
helpGroup: 'AUTH',
4950
}),
51+
'account-manager-host': Flags.string({
52+
description: 'Account Manager hostname for OAuth',
53+
env: 'SFCC_ACCOUNT_MANAGER_HOST',
54+
default: DEFAULT_ACCOUNT_MANAGER_HOST,
55+
helpGroup: 'AUTH',
56+
}),
5057
};
5158

5259
/**
@@ -96,6 +103,13 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
96103
return config;
97104
}
98105

106+
/**
107+
* Gets the configured Account Manager host.
108+
*/
109+
protected get accountManagerHost(): string {
110+
return this.flags['account-manager-host'] ?? DEFAULT_ACCOUNT_MANAGER_HOST;
111+
}
112+
99113
/**
100114
* Gets an OAuth auth strategy based on allowed auth methods and available credentials.
101115
*
@@ -106,6 +120,7 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
106120
*/
107121
protected getOAuthStrategy(): OAuthStrategy | ImplicitOAuthStrategy {
108122
const config = this.resolvedConfig;
123+
const accountManagerHost = this.accountManagerHost;
109124
// Default to client-credentials and implicit if no methods specified
110125
const allowedMethods = config.authMethods || (['client-credentials', 'implicit'] as AuthMethod[]);
111126

@@ -117,6 +132,7 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
117132
clientId: config.clientId,
118133
clientSecret: config.clientSecret,
119134
scopes: config.scopes,
135+
accountManagerHost,
120136
});
121137
}
122138
break;
@@ -126,6 +142,7 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
126142
return new ImplicitOAuthStrategy({
127143
clientId: config.clientId,
128144
scopes: config.scopes,
145+
accountManagerHost,
129146
});
130147
}
131148
break;

packages/b2c-tooling/src/cli/ods-command.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import {Command, Flags} from '@oclif/core';
22
import {OAuthCommand} from './oauth-command.js';
33
import {createOdsClient, type OdsClient} from '../clients/ods.js';
4-
5-
/**
6-
* Default ODS API host.
7-
*/
8-
const DEFAULT_ODS_HOST = 'admin.dx.commercecloud.salesforce.com';
4+
import {DEFAULT_ODS_HOST} from '../defaults.js';
95

106
/**
117
* Base command for ODS (On-Demand Sandbox) operations.
@@ -79,6 +75,6 @@ export abstract class OdsCommand<T extends typeof Command> extends OAuthCommand<
7975
* Gets the configured ODS API host.
8076
*/
8177
protected get odsHost(): string {
82-
return this.flags.host ?? DEFAULT_ODS_HOST;
78+
return this.flags['sandbox-api-host'] ?? DEFAULT_ODS_HOST;
8379
}
8480
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Centralized default values for B2C Commerce APIs.
3+
*
4+
* These defaults are used across auth strategies, clients, and CLI commands.
5+
* Override via environment variables or CLI flags.
6+
*
7+
* @module defaults
8+
*/
9+
10+
/**
11+
* Default Account Manager host for OAuth authentication.
12+
* Used for client credentials and implicit OAuth flows.
13+
*
14+
* Environment variable: SFCC_ACCOUNT_MANAGER_HOST
15+
*/
16+
export const DEFAULT_ACCOUNT_MANAGER_HOST = 'account.demandware.com';
17+
18+
/**
19+
* Default ODS (On-Demand Sandbox) API host.
20+
* Used for sandbox management operations.
21+
*
22+
* Environment variable: SFCC_SANDBOX_API_HOST
23+
*/
24+
export const DEFAULT_ODS_HOST = 'admin.dx.commercecloud.salesforce.com';

packages/b2c-tooling/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,6 @@ export type {JobExecutionResult} from './operations/jobs/index.js';
112112
// Operations - Sites
113113
export {listSites, getSite} from './operations/sites/index.js';
114114
export type {Site} from './operations/sites/index.js';
115+
116+
// Defaults
117+
export {DEFAULT_ACCOUNT_MANAGER_HOST, DEFAULT_ODS_HOST} from './defaults.js';

0 commit comments

Comments
 (0)