Skip to content

Commit bdab85b

Browse files
committed
nit fix: scapi custom should read config for tenant
1 parent 46b0328 commit bdab85b

4 files changed

Lines changed: 24 additions & 32 deletions

File tree

packages/b2c-cli/src/commands/scapi/custom/status.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,7 @@ const tableRenderer = new TableRenderer(COLUMNS);
168168
/**
169169
* Base command for SCAPI Custom API operations.
170170
*/
171-
abstract class ScapiCustomCommand<T extends typeof Command> extends OAuthCommand<T> {
172-
static baseFlags = {
173-
...OAuthCommand.baseFlags,
174-
'tenant-id': Flags.string({
175-
description: 'Organization/tenant ID',
176-
env: 'SFCC_TENANT_ID',
177-
required: true,
178-
}),
179-
};
180-
}
171+
abstract class ScapiCustomCommand<T extends typeof Command> extends OAuthCommand<T> {}
181172

182173
/**
183174
* Command to get the status of Custom API endpoints.
@@ -226,7 +217,8 @@ export default class ScapiCustomStatus extends ScapiCustomCommand<typeof ScapiCu
226217
async run(): Promise<CustomApiStatusResponse> {
227218
this.requireOAuthCredentials();
228219

229-
const {'tenant-id': tenantId, status, 'group-by': groupBy} = this.flags;
220+
const {status, 'group-by': groupBy} = this.flags;
221+
const tenantId = this.requireTenantId();
230222
const {shortCode} = this.resolvedConfig.values;
231223

232224
if (!shortCode) {

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,4 @@ export abstract class SlasClientCommand<T extends typeof Command> extends OAuthC
184184
const oauthStrategy = this.getOAuthStrategy();
185185
return createSlasClient({shortCode}, oauthStrategy);
186186
}
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-
}
205187
}

packages/b2c-cli/test/commands/scapi/custom/status.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('scapi custom status', () => {
5151

5252
sinon.stub(command, 'requireOAuthCredentials').returns(void 0);
5353
sinon.stub(command, 'jsonEnabled').returns(true);
54-
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78'}}));
54+
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78', tenantId: 'zzxy_prd'}}));
5555

5656
sinon.stub(command, 'getOAuthStrategy').returns({
5757
getAuthorizationHeader: async () => 'Bearer test',
@@ -95,7 +95,7 @@ describe('scapi custom status', () => {
9595

9696
sinon.stub(command, 'requireOAuthCredentials').returns(void 0);
9797
sinon.stub(command, 'jsonEnabled').returns(true);
98-
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78'}}));
98+
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78', tenantId: 'zzxy_prd'}}));
9999

100100
sinon.stub(command, 'getOAuthStrategy').returns({
101101
getAuthorizationHeader: async () => 'Bearer test',
@@ -123,7 +123,7 @@ describe('scapi custom status', () => {
123123
sinon.stub(command, 'requireOAuthCredentials').returns(void 0);
124124
sinon.stub(command, 'jsonEnabled').returns(false);
125125
sinon.stub(command, 'log').returns(void 0);
126-
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78'}}));
126+
sinon.stub(command, 'resolvedConfig').get(() => ({values: {shortCode: 'kv7kzm78', tenantId: 'zzxy_prd'}}));
127127

128128
sinon.stub(command, 'renderEndpoints').returns(void 0);
129129

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,22 @@ export abstract class OAuthCommand<T extends typeof Command> extends BaseCommand
166166
);
167167
}
168168
}
169+
170+
/**
171+
* Get the tenant ID from resolved config, throwing if not available.
172+
* @throws Error if tenant ID is not provided through any source
173+
*/
174+
protected requireTenantId(): string {
175+
const tenantId = this.resolvedConfig.values.tenantId;
176+
177+
if (!tenantId) {
178+
this.error(
179+
t(
180+
'error.tenantIdRequired',
181+
'tenant-id is required. Provide via --tenant-id flag, SFCC_TENANT_ID env var, or tenant-id in dw.json.',
182+
),
183+
);
184+
}
185+
return tenantId;
186+
}
169187
}

0 commit comments

Comments
 (0)