Skip to content

Commit 7e31076

Browse files
committed
topic realignment
1 parent 755a043 commit 7e31076

39 files changed

Lines changed: 6047 additions & 272 deletions

packages/b2c-cli/package.json

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,40 @@
100100
"description": "WebDAV file operations (ls, get, put, rm, zip, unzip)"
101101
},
102102
"mrt": {
103-
"description": "Manage Managed Runtime projects and deployments",
104-
"subtopics": {
105-
"env-var": {
106-
"description": "Manage environment variables on MRT projects"
107-
}
108-
}
103+
"description": "Manage Managed Runtime projects and deployments"
104+
},
105+
"mrt:env": {
106+
"description": "Manage MRT environments"
107+
},
108+
"mrt:env:var": {
109+
"description": "Manage environment variables"
110+
},
111+
"mrt:env:redirect": {
112+
"description": "Manage URL redirects"
113+
},
114+
"mrt:org": {
115+
"description": "Manage MRT organizations"
116+
},
117+
"mrt:project": {
118+
"description": "Manage MRT projects"
119+
},
120+
"mrt:project:member": {
121+
"description": "Manage project members"
122+
},
123+
"mrt:project:notification": {
124+
"description": "Manage deployment notifications"
125+
},
126+
"mrt:env:access-control": {
127+
"description": "Manage access control headers"
128+
},
129+
"mrt:bundle": {
130+
"description": "Manage and deploy bundles"
131+
},
132+
"mrt:user": {
133+
"description": "Manage user profile and settings"
134+
},
135+
"mrt:b2c": {
136+
"description": "Manage B2C Commerce integrations"
109137
},
110138
"ods": {
111139
"description": "Manage On-Demand Sandboxes"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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} from '@oclif/core';
7+
import {MrtCommand, createTable, type ColumnDef} from '@salesforce/b2c-tooling-sdk/cli';
8+
import {getB2COrgInfo, type B2COrgInfo} from '@salesforce/b2c-tooling-sdk/operations/mrt';
9+
import {t} from '../../../i18n/index.js';
10+
11+
type InfoEntry = {field: string; value: string};
12+
13+
const COLUMNS: Record<string, ColumnDef<InfoEntry>> = {
14+
field: {
15+
header: 'Field',
16+
get: (e) => e.field,
17+
},
18+
value: {
19+
header: 'Value',
20+
get: (e) => e.value,
21+
},
22+
};
23+
24+
const DEFAULT_COLUMNS = ['field', 'value'];
25+
26+
/**
27+
* Get B2C Commerce info for an organization.
28+
*/
29+
export default class MrtB2COrgInfo extends MrtCommand<typeof MrtB2COrgInfo> {
30+
static args = {
31+
organization: Args.string({
32+
description: 'Organization slug',
33+
required: true,
34+
}),
35+
};
36+
37+
static description = t(
38+
'commands.mrt.b2c.org-info.description',
39+
'Get B2C Commerce instances connected to an organization',
40+
);
41+
42+
static enableJsonFlag = true;
43+
44+
static examples = ['<%= config.bin %> <%= command.id %> my-org', '<%= config.bin %> <%= command.id %> my-org --json'];
45+
46+
static flags = {
47+
...MrtCommand.baseFlags,
48+
};
49+
50+
async run(): Promise<B2COrgInfo> {
51+
this.requireMrtCredentials();
52+
53+
const {organization} = this.args;
54+
55+
this.log(
56+
t('commands.mrt.b2c.org-info.fetching', 'Fetching B2C info for organization {{org}}...', {org: organization}),
57+
);
58+
59+
const info = await getB2COrgInfo(
60+
{
61+
organizationSlug: organization,
62+
origin: this.resolvedConfig.values.mrtOrigin,
63+
},
64+
this.getMrtAuth(),
65+
);
66+
67+
if (!this.jsonEnabled()) {
68+
const entries: InfoEntry[] = [
69+
{field: 'B2C Customer', value: info.is_b2c_customer ? 'Yes' : 'No'},
70+
{field: 'Instances', value: info.instances.length > 0 ? info.instances.join(', ') : 'None'},
71+
];
72+
createTable(COLUMNS).render(entries, DEFAULT_COLUMNS);
73+
}
74+
75+
return info;
76+
}
77+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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 {Flags} from '@oclif/core';
7+
import {MrtCommand, createTable, type ColumnDef} from '@salesforce/b2c-tooling-sdk/cli';
8+
import {
9+
getB2CTargetInfo,
10+
setB2CTargetInfo,
11+
updateB2CTargetInfo,
12+
type B2CTargetInfo,
13+
} from '@salesforce/b2c-tooling-sdk/operations/mrt';
14+
import {t} from '../../../i18n/index.js';
15+
16+
type InfoEntry = {field: string; value: string};
17+
18+
const COLUMNS: Record<string, ColumnDef<InfoEntry>> = {
19+
field: {
20+
header: 'Field',
21+
get: (e) => e.field,
22+
},
23+
value: {
24+
header: 'Value',
25+
get: (e) => e.value,
26+
},
27+
};
28+
29+
const DEFAULT_COLUMNS = ['field', 'value'];
30+
31+
/**
32+
* Get or update B2C Commerce info for a target/environment.
33+
*/
34+
export default class MrtB2CTargetInfo extends MrtCommand<typeof MrtB2CTargetInfo> {
35+
static description = t(
36+
'commands.mrt.b2c.target-info.description',
37+
'Get or update B2C Commerce connection for a target/environment',
38+
);
39+
40+
static enableJsonFlag = true;
41+
42+
static examples = [
43+
'<%= config.bin %> <%= command.id %> -p my-storefront -e production',
44+
'<%= config.bin %> <%= command.id %> -p my-storefront -e production --instance-id aaaa_prd',
45+
'<%= config.bin %> <%= command.id %> -p my-storefront -e production --instance-id aaaa_prd --sites RefArch,SiteGenesis',
46+
'<%= config.bin %> <%= command.id %> -p my-storefront -e production --json',
47+
];
48+
49+
static flags = {
50+
...MrtCommand.baseFlags,
51+
'instance-id': Flags.string({
52+
description: 'B2C Commerce instance ID to connect',
53+
}),
54+
sites: Flags.string({
55+
description: 'Comma-separated list of site IDs to connect',
56+
}),
57+
'clear-sites': Flags.boolean({
58+
description: 'Clear the sites list',
59+
default: false,
60+
}),
61+
};
62+
63+
async run(): Promise<B2CTargetInfo> {
64+
this.requireMrtCredentials();
65+
66+
const {mrtProject: project, mrtEnvironment: environment} = this.resolvedConfig.values;
67+
68+
if (!project) {
69+
this.error(
70+
'MRT project is required. Provide --project flag, set SFCC_MRT_PROJECT, or set mrtProject in dw.json.',
71+
);
72+
}
73+
if (!environment) {
74+
this.error(
75+
'MRT environment is required. Provide --environment flag, set SFCC_MRT_ENVIRONMENT, or set mrtEnvironment in dw.json.',
76+
);
77+
}
78+
79+
const instanceId = this.flags['instance-id'];
80+
const sitesStr = this.flags.sites;
81+
const clearSites = this.flags['clear-sites'];
82+
83+
// If instance-id is provided, set or update the target info
84+
if (instanceId) {
85+
this.log(
86+
t('commands.mrt.b2c.target-info.setting', 'Setting B2C info for {{project}}/{{environment}}...', {
87+
project,
88+
environment,
89+
}),
90+
);
91+
92+
const sites = clearSites ? null : sitesStr ? sitesStr.split(',').map((s) => s.trim()) : undefined;
93+
94+
const info = await setB2CTargetInfo(
95+
{
96+
projectSlug: project,
97+
targetSlug: environment,
98+
instanceId,
99+
sites,
100+
origin: this.resolvedConfig.values.mrtOrigin,
101+
},
102+
this.getMrtAuth(),
103+
);
104+
105+
if (!this.jsonEnabled()) {
106+
this.log(t('commands.mrt.b2c.target-info.updated', 'B2C target info updated successfully.'));
107+
this.displayInfo(info);
108+
}
109+
110+
return info;
111+
}
112+
113+
// If only sites or clear-sites is provided, update
114+
if (sitesStr !== undefined || clearSites) {
115+
this.log(
116+
t('commands.mrt.b2c.target-info.updating', 'Updating B2C info for {{project}}/{{environment}}...', {
117+
project,
118+
environment,
119+
}),
120+
);
121+
122+
const sites = clearSites ? null : sitesStr ? sitesStr.split(',').map((s) => s.trim()) : undefined;
123+
124+
const info = await updateB2CTargetInfo(
125+
{
126+
projectSlug: project,
127+
targetSlug: environment,
128+
sites,
129+
origin: this.resolvedConfig.values.mrtOrigin,
130+
},
131+
this.getMrtAuth(),
132+
);
133+
134+
if (!this.jsonEnabled()) {
135+
this.log(t('commands.mrt.b2c.target-info.updated', 'B2C target info updated successfully.'));
136+
this.displayInfo(info);
137+
}
138+
139+
return info;
140+
}
141+
142+
// Otherwise, get the current info
143+
this.log(
144+
t('commands.mrt.b2c.target-info.fetching', 'Fetching B2C info for {{project}}/{{environment}}...', {
145+
project,
146+
environment,
147+
}),
148+
);
149+
150+
const info = await getB2CTargetInfo(
151+
{
152+
projectSlug: project,
153+
targetSlug: environment,
154+
origin: this.resolvedConfig.values.mrtOrigin,
155+
},
156+
this.getMrtAuth(),
157+
);
158+
159+
if (!this.jsonEnabled()) {
160+
this.displayInfo(info);
161+
}
162+
163+
return info;
164+
}
165+
166+
private displayInfo(info: B2CTargetInfo): void {
167+
const entries: InfoEntry[] = [
168+
{field: 'Instance ID', value: info.instance_id ?? '-'},
169+
{field: 'Sites', value: info.sites && info.sites.length > 0 ? info.sites.join(', ') : 'None'},
170+
];
171+
createTable(COLUMNS).render(entries, DEFAULT_COLUMNS);
172+
}
173+
}

0 commit comments

Comments
 (0)