Skip to content

Commit 2892685

Browse files
committed
tenant-id at wrong level/config
1 parent 97f4b68 commit 2892685

File tree

15 files changed

+139
-48
lines changed

15 files changed

+139
-48
lines changed

packages/b2c-cli/src/commands/setup/config.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ export default class SetupConfig extends BaseCommand<typeof SetupConfig> {
191191
);
192192

193193
// SCAPI section
194-
this.renderSection(ui, 'SCAPI', [['shortCode', config.shortCode]], fieldSources, unmask);
194+
this.renderSection(
195+
ui,
196+
'SCAPI',
197+
[
198+
['shortCode', config.shortCode],
199+
['tenantId', config.tenantId],
200+
],
201+
fieldSources,
202+
unmask,
203+
);
195204

196205
// MRT section
197206
this.renderSection(

packages/b2c-cli/src/commands/slas/client/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export default class SlasClientCreate extends SlasClientCommand<typeof SlasClien
109109
this.requireOAuthCredentials();
110110

111111
const {
112-
'tenant-id': tenantId,
113112
name,
114113
channels,
115114
scopes,
@@ -120,6 +119,7 @@ export default class SlasClientCreate extends SlasClientCommand<typeof SlasClien
120119
public: isPublic,
121120
'create-tenant': createTenant,
122121
} = this.flags;
122+
const tenantId = this.requireTenantId();
123123

124124
// Validate that either --scopes or --default-scopes is provided
125125
if (!scopes && !useDefaultScopes) {

packages/b2c-cli/src/commands/slas/client/delete.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default class SlasClientDelete extends SlasClientCommand<typeof SlasClien
3636
async run(): Promise<DeleteOutput> {
3737
this.requireOAuthCredentials();
3838

39-
const {'tenant-id': tenantId} = this.flags;
39+
const tenantId = this.requireTenantId();
4040
const {clientId} = this.args;
4141

4242
if (!this.jsonEnabled()) {

packages/b2c-cli/src/commands/slas/client/get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class SlasClientGet extends SlasClientCommand<typeof SlasClientGe
3838
async run(): Promise<ClientOutput> {
3939
this.requireOAuthCredentials();
4040

41-
const {'tenant-id': tenantId} = this.flags;
41+
const tenantId = this.requireTenantId();
4242
const {clientId} = this.args;
4343

4444
if (!this.jsonEnabled()) {

packages/b2c-cli/src/commands/slas/client/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default class SlasClientList extends SlasClientCommand<typeof SlasClientL
5151
async run(): Promise<ClientListOutput> {
5252
this.requireOAuthCredentials();
5353

54-
const {'tenant-id': tenantId} = this.flags;
54+
const tenantId = this.requireTenantId();
5555

5656
if (!this.jsonEnabled()) {
5757
this.log(t('commands.slas.client.list.fetching', 'Fetching SLAS clients for tenant {{tenantId}}...', {tenantId}));

packages/b2c-cli/src/commands/slas/client/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export default class SlasClientUpdate extends SlasClientCommand<typeof SlasClien
7777
this.requireOAuthCredentials();
7878

7979
const {
80-
'tenant-id': tenantId,
8180
name,
8281
secret,
8382
channels,
@@ -87,6 +86,7 @@ export default class SlasClientUpdate extends SlasClientCommand<typeof SlasClien
8786
replace,
8887
} = this.flags;
8988
const {clientId} = this.args;
89+
const tenantId = this.requireTenantId();
9090

9191
if (!this.jsonEnabled()) {
9292
this.log(t('commands.slas.client.update.fetching', 'Fetching SLAS client {{clientId}}...', {clientId}));

packages/b2c-cli/src/utils/ecdn/base-command.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
6-
import {Command, Flags} from '@oclif/core';
6+
import {Command} from '@oclif/core';
77
import {OAuthCommand} from '@salesforce/b2c-tooling-sdk/cli';
88
import {createCdnZonesClient, toOrganizationId, type CdnZonesClient} from '@salesforce/b2c-tooling-sdk/clients';
99
import {t} from '../../i18n/index.js';
@@ -17,18 +17,9 @@ export function formatApiError(error: unknown): string {
1717

1818
/**
1919
* Base command for eCDN operations.
20-
* Provides tenant-id flag and lazy-loaded CDN Zones client.
20+
* Provides lazy-loaded CDN Zones client.
2121
*/
2222
export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand<T> {
23-
static baseFlags = {
24-
...OAuthCommand.baseFlags,
25-
'tenant-id': Flags.string({
26-
description: t('flags.tenantId.description', 'Organization/tenant ID'),
27-
env: 'SFCC_TENANT_ID',
28-
required: true,
29-
}),
30-
};
31-
3223
private _cdnZonesClient?: CdnZonesClient;
3324
private _cdnZonesRwClient?: CdnZonesClient;
3425

@@ -37,8 +28,7 @@ export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand
3728
*/
3829
protected getCdnZonesClient(): CdnZonesClient {
3930
if (!this._cdnZonesClient) {
40-
const {shortCode} = this.resolvedConfig.values;
41-
const tenantId = (this.flags as Record<string, string>)['tenant-id'];
31+
const {shortCode, tenantId} = this.resolvedConfig.values;
4232

4333
if (!shortCode) {
4434
this.error(
@@ -48,6 +38,14 @@ export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand
4838
),
4939
);
5040
}
41+
if (!tenantId) {
42+
this.error(
43+
t(
44+
'error.tenantIdRequired',
45+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
46+
),
47+
);
48+
}
5149

5250
const oauthStrategy = this.getOAuthStrategy();
5351
this._cdnZonesClient = createCdnZonesClient({shortCode, tenantId}, oauthStrategy);
@@ -60,8 +58,7 @@ export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand
6058
*/
6159
protected getCdnZonesRwClient(): CdnZonesClient {
6260
if (!this._cdnZonesRwClient) {
63-
const {shortCode} = this.resolvedConfig.values;
64-
const tenantId = (this.flags as Record<string, string>)['tenant-id'];
61+
const {shortCode, tenantId} = this.resolvedConfig.values;
6562

6663
if (!shortCode) {
6764
this.error(
@@ -71,6 +68,14 @@ export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand
7168
),
7269
);
7370
}
71+
if (!tenantId) {
72+
this.error(
73+
t(
74+
'error.tenantIdRequired',
75+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
76+
),
77+
);
78+
}
7479

7580
const oauthStrategy = this.getOAuthStrategy();
7681
this._cdnZonesRwClient = createCdnZonesClient({shortCode, tenantId}, oauthStrategy, {readWrite: true});
@@ -79,10 +84,19 @@ export abstract class EcdnCommand<T extends typeof Command> extends OAuthCommand
7984
}
8085

8186
/**
82-
* Get the organization ID from the tenant-id flag.
87+
* Get the organization ID from resolved config.
88+
* @throws Error if tenant ID is not provided through any source
8389
*/
8490
protected getOrganizationId(): string {
85-
const tenantId = (this.flags as Record<string, string>)['tenant-id'];
91+
const {tenantId} = this.resolvedConfig.values;
92+
if (!tenantId) {
93+
this.error(
94+
t(
95+
'error.tenantIdRequired',
96+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
97+
),
98+
);
99+
}
86100
return toOrganizationId(tenantId);
87101
}
88102
}

packages/b2c-cli/src/utils/scapi/schemas.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
6-
import {Command, Flags} from '@oclif/core';
6+
import {Command} from '@oclif/core';
77
import {OAuthCommand} from '@salesforce/b2c-tooling-sdk/cli';
88
import {
99
createScapiSchemasClient,
@@ -25,29 +25,28 @@ export function formatApiError(error: unknown, response: Response): string {
2525
* Provides common flags and helper methods for interacting with the SCAPI Schemas API.
2626
*/
2727
export abstract class ScapiSchemasCommand<T extends typeof Command> extends OAuthCommand<T> {
28-
static baseFlags = {
29-
...OAuthCommand.baseFlags,
30-
'tenant-id': Flags.string({
31-
description: t('flags.tenantId.description', 'Organization/tenant ID'),
32-
env: 'SFCC_TENANT_ID',
33-
required: true,
34-
}),
35-
};
36-
3728
/**
38-
* Get the organization ID from the tenant-id flag.
29+
* Get the organization ID from resolved config.
30+
* @throws Error if tenant ID is not provided through any source
3931
*/
4032
protected getOrganizationId(): string {
41-
const tenantId = (this.flags as Record<string, string>)['tenant-id'];
33+
const {tenantId} = this.resolvedConfig.values;
34+
if (!tenantId) {
35+
this.error(
36+
t(
37+
'error.tenantIdRequired',
38+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
39+
),
40+
);
41+
}
4242
return toOrganizationId(tenantId);
4343
}
4444

4545
/**
46-
* Get the SCAPI Schemas client, ensuring short code is configured.
46+
* Get the SCAPI Schemas client, ensuring short code and tenant ID are configured.
4747
*/
4848
protected getSchemasClient(): ScapiSchemasClient {
49-
const {shortCode} = this.resolvedConfig.values;
50-
const tenantId = (this.flags as Record<string, string>)['tenant-id'];
49+
const {shortCode, tenantId} = this.resolvedConfig.values;
5150

5251
if (!shortCode) {
5352
this.error(
@@ -57,6 +56,14 @@ export abstract class ScapiSchemasCommand<T extends typeof Command> extends OAut
5756
),
5857
);
5958
}
59+
if (!tenantId) {
60+
this.error(
61+
t(
62+
'error.tenantIdRequired',
63+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
64+
),
65+
);
66+
}
6067

6168
const oauthStrategy = this.getOAuthStrategy();
6269
return createScapiSchemasClient({shortCode, tenantId}, oauthStrategy);

packages/b2c-cli/src/utils/slas/client.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2
44
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
55
*/
6-
import {Command, Flags, ux} from '@oclif/core';
6+
import {Command, ux} from '@oclif/core';
77
import cliui from 'cliui';
88
import {OAuthCommand} from '@salesforce/b2c-tooling-sdk/cli';
99
import {createSlasClient, getApiErrorMessage, type SlasClient, type SlasComponents} from '@salesforce/b2c-tooling-sdk';
@@ -100,15 +100,6 @@ export function formatApiError(error: unknown, response: Response): string {
100100
* Provides common flags and helper methods.
101101
*/
102102
export abstract class SlasClientCommand<T extends typeof Command> extends OAuthCommand<T> {
103-
static baseFlags = {
104-
...OAuthCommand.baseFlags,
105-
'tenant-id': Flags.string({
106-
description: 'SLAS tenant ID (organization ID)',
107-
env: 'SFCC_TENANT_ID',
108-
required: true,
109-
}),
110-
};
111-
112103
/**
113104
* Ensure tenant exists, creating it if necessary.
114105
* This is required before creating SLAS clients.
@@ -193,4 +184,22 @@ export abstract class SlasClientCommand<T extends typeof Command> extends OAuthC
193184
const oauthStrategy = this.getOAuthStrategy();
194185
return createSlasClient({shortCode}, oauthStrategy);
195186
}
187+
188+
/**
189+
* Get the tenant ID from resolved config, throwing if not available.
190+
* @throws Error if tenant ID is not provided through any source
191+
*/
192+
protected requireTenantId(): string {
193+
const tenantId = this.resolvedConfig.values.tenantId;
194+
195+
if (!tenantId) {
196+
this.error(
197+
t(
198+
'error.tenantIdRequired',
199+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
200+
),
201+
);
202+
}
203+
return tenantId;
204+
}
196205
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
4949
env: 'SFCC_SHORTCODE',
5050
helpGroup: 'AUTH',
5151
}),
52+
'tenant-id': Flags.string({
53+
description: 'Organization/tenant ID',
54+
env: 'SFCC_TENANT_ID',
55+
helpGroup: 'AUTH',
56+
}),
5257
'auth-methods': Flags.string({
5358
description: 'Allowed auth methods in priority order (comma-separated)',
5459
env: 'SFCC_AUTH_METHODS',
@@ -93,6 +98,7 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
9398
clientId: this.flags['client-id'],
9499
clientSecret: this.flags['client-secret'],
95100
shortCode: this.flags['short-code'],
101+
tenantId: this.flags['tenant-id'],
96102
authMethods: this.parseAuthMethods(),
97103
accountManagerHost: this.flags['account-manager-host'],
98104
// Merge scopes from flags (if provided)

0 commit comments

Comments
 (0)