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' ;
77import { OAuthCommand } from '@salesforce/b2c-tooling-sdk/cli' ;
88import { createCdnZonesClient , toOrganizationId , type CdnZonesClient } from '@salesforce/b2c-tooling-sdk/clients' ;
99import { 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 */
2222export 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}
0 commit comments