Skip to content

Commit 69b7905

Browse files
authored
slas client update fix and open command (#43)
1 parent 9cbd448 commit 69b7905

4 files changed

Lines changed: 79 additions & 4 deletions

File tree

packages/b2c-cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"@salesforce/b2c-tooling-sdk": "workspace:*",
1818
"cliui": "^9.0.1",
1919
"marked": "^15.0.0",
20-
"marked-terminal": "^7.3.0"
20+
"marked-terminal": "^7.3.0",
21+
"open": "^11.0.0"
2122
},
2223
"bundleDependencies": [
2324
"@oclif/core",
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) 2025, Salesforce, Inc.
3+
* SPDX-License-Identifier: Apache-2
4+
* For full license text, see the license.txt file in the repo root or http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
import {Args, Flags} from '@oclif/core';
7+
import {BaseCommand} from '@salesforce/b2c-tooling-sdk/cli';
8+
import {t} from '../../../i18n/index.js';
9+
10+
async function openBrowser(url: string): Promise<void> {
11+
try {
12+
const open = await import('open');
13+
await open.default(url);
14+
} catch {
15+
// If open fails, the URL will still be printed to console
16+
}
17+
}
18+
19+
export default class SlasClientOpen extends BaseCommand<typeof SlasClientOpen> {
20+
static args = {
21+
clientId: Args.string({
22+
description: 'SLAS client ID to open in the admin UI',
23+
required: true,
24+
}),
25+
};
26+
27+
static description = t('commands.slas.client.open.description', 'Open the SLAS Admin UI for a client');
28+
29+
static examples = [
30+
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123',
31+
'<%= config.bin %> <%= command.id %> my-client-id --tenant-id abcd_123 --short-code kv7kzm78',
32+
];
33+
34+
static flags = {
35+
...BaseCommand.baseFlags,
36+
'tenant-id': Flags.string({
37+
description: 'SLAS tenant ID (organization ID)',
38+
env: 'SFCC_TENANT_ID',
39+
required: true,
40+
}),
41+
'short-code': Flags.string({
42+
description: 'SCAPI short code',
43+
env: 'SFCC_SHORTCODE',
44+
}),
45+
};
46+
47+
async run(): Promise<{url: string}> {
48+
const {'tenant-id': tenantId, 'short-code': shortCodeFlag} = this.flags;
49+
const {clientId} = this.args;
50+
51+
const shortCode = shortCodeFlag ?? this.resolvedConfig.shortCode;
52+
53+
if (!shortCode) {
54+
this.error(
55+
t(
56+
'error.shortCodeRequired',
57+
'SCAPI short code required. Provide --short-code, set SFCC_SHORTCODE, or configure short-code in dw.json.',
58+
),
59+
);
60+
}
61+
62+
const url = `https://${shortCode}.api.commercecloud.salesforce.com/shopper/auth-admin/v1/ui/client?clientId=${encodeURIComponent(clientId)}&tenantId=${encodeURIComponent(tenantId)}`;
63+
64+
this.log(t('commands.slas.client.open.opening', 'Opening SLAS Admin UI...'));
65+
this.log(url);
66+
67+
await openBrowser(url);
68+
69+
return {url};
70+
}
71+
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ export default class SlasClientUpdate extends SlasClientCommand<typeof SlasClien
119119
? existing.scopes
120120
: [];
121121

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

129129
// oclif handles comma-separation via delimiter option

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)