Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/b2c-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@salesforce/b2c-tooling-sdk": "workspace:*",
"cliui": "^9.0.1",
"marked": "^15.0.0",
"marked-terminal": "^7.3.0"
"marked-terminal": "^7.3.0",
"open": "^11.0.0"
},
"bundleDependencies": [
"@oclif/core",
Expand Down
71 changes: 71 additions & 0 deletions packages/b2c-cli/src/commands/slas/client/open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2025, Salesforce, Inc.
* SPDX-License-Identifier: Apache-2
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
*/
import {Args, Flags} from '@oclif/core';
import {BaseCommand} from '@salesforce/b2c-tooling-sdk/cli';
import {t} from '../../../i18n/index.js';

async function openBrowser(url: string): Promise<void> {
try {
const open = await import('open');
await open.default(url);
} catch {
// If open fails, the URL will still be printed to console
}
}

export default class SlasClientOpen extends BaseCommand<typeof SlasClientOpen> {
static args = {
clientId: Args.string({
description: 'SLAS client ID to open in the admin UI',
required: true,
}),
};

static description = t('commands.slas.client.open.description', 'Open the SLAS Admin UI for a client');

static examples = [
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123',
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123 --short-code kv7kzm78',
];

static flags = {
...BaseCommand.baseFlags,
'tenant-id': Flags.string({
description: 'SLAS tenant ID (organization ID)',
env: 'SFCC_TENANT_ID',
required: true,
}),
'short-code': Flags.string({
description: 'SCAPI short code',
env: 'SFCC_SHORTCODE',
}),
};

async run(): Promise<{url: string}> {
const {'tenant-id': tenantId, 'short-code': shortCodeFlag} = this.flags;
const {clientId} = this.args;

const shortCode = shortCodeFlag ?? this.resolvedConfig.shortCode;

if (!shortCode) {
this.error(
t(
'error.shortCodeRequired',
'SCAPI short code required. Provide --short-code, set SFCC_SHORTCODE, or configure short-code in dw.json.',
),
);
}

const url = `https://${shortCode}.api.commercecloud.salesforce.com/shopper/auth-admin/v1/ui/client?clientId=${encodeURIComponent(clientId)}&tenantId=${encodeURIComponent(tenantId)}`;

this.log(t('commands.slas.client.open.opening', 'Opening SLAS Admin UI...'));
this.log(url);

await openBrowser(url);

return {url};
}
}
6 changes: 3 additions & 3 deletions packages/b2c-cli/src/commands/slas/client/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}),
};

async run(): Promise<ClientOutput> {

Check warning on line 76 in packages/b2c-cli/src/commands/slas/client/update.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

Async method 'run' has a complexity of 31. Maximum allowed is 20

Check warning on line 76 in packages/b2c-cli/src/commands/slas/client/update.ts

View workflow job for this annotation

GitHub Actions / test (24.x)

Async method 'run' has a complexity of 31. Maximum allowed is 20
this.requireOAuthCredentials();

const {
Expand Down Expand Up @@ -119,11 +119,11 @@
? existing.scopes
: [];

// Normalize existing redirectUri (ensure array) - API returns string or array
// Normalize existing redirectUri (ensure array) - API returns pipe-delimited string
const existingRedirectUri = Array.isArray(existing.redirectUri)
? existing.redirectUri
? existing.redirectUri.flatMap((uri) => (typeof uri === 'string' ? uri.split('|').map((s) => s.trim()) : []))
: typeof existing.redirectUri === 'string'
? [existing.redirectUri]
? existing.redirectUri.split('|').map((s) => s.trim())
: [];

// oclif handles comma-separation via delimiter option
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading