Skip to content

Commit c4a2159

Browse files
committed
Merge main into feature/scaffolding-framework
Resolve conflicts by keeping both: - Scaffolding guide/commands from this branch - IDE Support guide and Account Manager commands from main
2 parents d8fb941 + 1a3117c commit c4a2159

81 files changed

Lines changed: 16714 additions & 73 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@salesforce/b2c-cli': patch
3+
'@salesforce/b2c-tooling-sdk': patch
4+
---
5+
6+
Account Manager (AM) topic with `users`, `roles`, and `orgs` subtopics. Use `b2c am users`, `b2c am roles`, and `b2c am orgs` for user, role, and organization management.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Update Script API Documentation
2+
3+
Download the latest B2C Commerce Script API documentation from the configured sandbox and update the bundled docs in the SDK.
4+
5+
## Steps
6+
7+
1. Download Script API docs from the configured sandbox using `./cli docs download`
8+
2. Replace the markdown files in `packages/b2c-tooling-sdk/data/script-api/`
9+
3. Regenerate the search index with `pnpm --filter @salesforce/b2c-tooling-sdk run generate:docs-index`
10+
4. Show the version extracted from `index.md` header
11+
5. Show git status/diff summary of what changed
12+
13+
## Commands to Run
14+
15+
```bash
16+
# Download to temp directory
17+
./cli docs download /tmp/script-api-docs-update
18+
19+
# Check version
20+
head -1 /tmp/script-api-docs-update/index.md
21+
22+
# Replace existing files
23+
rm -f packages/b2c-tooling-sdk/data/script-api/*.md
24+
cp /tmp/script-api-docs-update/*.md packages/b2c-tooling-sdk/data/script-api/
25+
26+
# Regenerate index
27+
pnpm --filter @salesforce/b2c-tooling-sdk run generate:docs-index
28+
29+
# Show changes
30+
git status packages/b2c-tooling-sdk/data/script-api/ --short
31+
git diff packages/b2c-tooling-sdk/data/script-api/*.md --stat
32+
33+
# Cleanup
34+
rm -rf /tmp/script-api-docs-update
35+
```
36+
37+
After running, summarize:
38+
- The Script API version (from index.md header like "# B2C Commerce Script API 26.2")
39+
- Number of files updated
40+
- Key changes (new classes, deprecated methods, etc.)

docs/.vitepress/config.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const guideSidebar = [
1616
items: [
1717
{ text: 'Authentication Setup', link: '/guide/authentication' },
1818
{ text: 'Scaffolding', link: '/guide/scaffolding' },
19+
{ text: 'IDE Support', link: '/guide/ide-support' },
1920
{ text: 'Security', link: '/guide/security' },
2021
],
2122
},

docs/api-readme.md

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,219 @@ const { data, error } = await instance.ocapi.PATCH('/code_versions/{code_version
241241
});
242242
```
243243

244+
## Account Manager Operations
245+
246+
The SDK provides a unified client for managing users, roles, and organizations through the Account Manager API.
247+
248+
### Authentication
249+
250+
Account Manager operations use **OAuth implicit flow** by default, which opens a browser for interactive authentication. This is ideal for development and manual operations where you want to use roles assigned to your user account.
251+
252+
For CI/CD and automation, you can also use **OAuth client credentials flow** (requires both client ID and secret).
253+
254+
### Unified Client (Recommended)
255+
256+
The recommended approach is to use the unified `createAccountManagerClient` which provides access to all Account Manager APIs (users, roles, and organizations):
257+
258+
```typescript
259+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
260+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
261+
262+
// Create Account Manager client with implicit OAuth (opens browser for login)
263+
const auth = new ImplicitOAuthStrategy({
264+
clientId: 'your-client-id',
265+
// No clientSecret needed for implicit flow
266+
});
267+
268+
const client = createAccountManagerClient(
269+
{ accountManagerHost: 'account.demandware.com' },
270+
auth,
271+
);
272+
273+
// Users API
274+
const users = await client.listUsers({ size: 25, page: 0 });
275+
const user = await client.getUser('user-id');
276+
const userByLogin = await client.findUserByLogin('user@example.com');
277+
await client.createUser({
278+
mail: 'newuser@example.com',
279+
firstName: 'John',
280+
lastName: 'Doe',
281+
organizations: ['org-id'],
282+
primaryOrganization: 'org-id',
283+
});
284+
await client.updateUser('user-id', { firstName: 'Jane' });
285+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2');
286+
await client.revokeRole('user-id', 'bm-admin', 'tenant1');
287+
await client.resetUser('user-id');
288+
await client.deleteUser('user-id');
289+
290+
// Roles API
291+
const roles = await client.listRoles({ size: 20, page: 0 });
292+
const role = await client.getRole('bm-admin');
293+
294+
// Organizations API
295+
const orgs = await client.listOrgs({ size: 25, page: 0 });
296+
const org = await client.getOrg('org-id');
297+
const orgByName = await client.getOrgByName('My Organization');
298+
const auditLogs = await client.getOrgAuditLogs('org-id');
299+
```
300+
301+
### Client Credentials Flow (Alternative)
302+
303+
For automation and CI/CD, you can use client credentials flow:
304+
305+
```typescript
306+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
307+
import { OAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
308+
309+
// Create Account Manager client with client credentials OAuth
310+
const auth = new OAuthStrategy({
311+
clientId: 'your-client-id',
312+
clientSecret: 'your-client-secret',
313+
});
314+
315+
const client = createAccountManagerClient(
316+
{ accountManagerHost: 'account.demandware.com' },
317+
auth,
318+
);
319+
320+
// Use the unified client as shown above
321+
```
322+
323+
### Individual Clients
324+
325+
If you only need access to a specific API, you can create individual clients:
326+
327+
```typescript
328+
import {
329+
createAccountManagerUsersClient,
330+
createAccountManagerRolesClient,
331+
createAccountManagerOrgsClient,
332+
} from '@salesforce/b2c-tooling-sdk/clients';
333+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
334+
335+
const auth = new ImplicitOAuthStrategy({
336+
clientId: 'your-client-id',
337+
});
338+
339+
// Users client
340+
const usersClient = createAccountManagerUsersClient(
341+
{ accountManagerHost: 'account.demandware.com' },
342+
auth,
343+
);
344+
345+
// Roles client
346+
const rolesClient = createAccountManagerRolesClient(
347+
{ accountManagerHost: 'account.demandware.com' },
348+
auth,
349+
);
350+
351+
// Organizations client
352+
const orgsClient = createAccountManagerOrgsClient(
353+
{ accountManagerHost: 'account.demandware.com' },
354+
auth,
355+
);
356+
```
357+
358+
### User Operations
359+
360+
```typescript
361+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
362+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
363+
364+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
365+
const client = createAccountManagerClient({}, auth);
366+
367+
// List users with pagination
368+
const users = await client.listUsers({ size: 25, page: 0 });
369+
370+
// Get user by email/login
371+
const user = await client.findUserByLogin('user@example.com');
372+
373+
// Get user with expanded organizations and roles
374+
const userExpanded = await client.getUser('user-id', ['organizations', 'roles']);
375+
376+
// Create a new user
377+
const newUser = await client.createUser({
378+
mail: 'newuser@example.com',
379+
firstName: 'John',
380+
lastName: 'Doe',
381+
organizations: ['org-id'],
382+
primaryOrganization: 'org-id',
383+
});
384+
385+
// Update a user
386+
await client.updateUser('user-id', { firstName: 'Jane' });
387+
388+
// Grant a role to a user
389+
await client.grantRole('user-id', 'bm-admin', 'tenant1,tenant2'); // Optional tenant filter
390+
391+
// Revoke a role from a user
392+
await client.revokeRole('user-id', 'bm-admin', 'tenant1'); // Optional: remove specific scope
393+
394+
// Reset user to INITIAL state
395+
await client.resetUser('user-id');
396+
397+
// Delete (disable) a user
398+
await client.deleteUser('user-id');
399+
```
400+
401+
### Role Operations
402+
403+
```typescript
404+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
405+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
406+
407+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
408+
const client = createAccountManagerClient({}, auth);
409+
410+
// Get role details by ID
411+
const role = await client.getRole('bm-admin');
412+
413+
// List all roles with pagination
414+
const roles = await client.listRoles({ size: 25, page: 0 });
415+
416+
// List roles filtered by target type
417+
const userRoles = await client.listRoles({
418+
size: 25,
419+
page: 0,
420+
roleTargetType: 'User',
421+
});
422+
```
423+
424+
### Organization Operations
425+
426+
```typescript
427+
import { createAccountManagerClient } from '@salesforce/b2c-tooling-sdk/clients';
428+
import { ImplicitOAuthStrategy } from '@salesforce/b2c-tooling-sdk/auth';
429+
430+
const auth = new ImplicitOAuthStrategy({ clientId: 'your-client-id' });
431+
const client = createAccountManagerClient({}, auth);
432+
433+
// Get organization by ID
434+
const org = await client.getOrg('org-123');
435+
436+
// Get organization by name
437+
const orgByName = await client.getOrgByName('My Organization');
438+
439+
// List organizations with pagination
440+
const orgs = await client.listOrgs({ size: 25, page: 0 });
441+
442+
// List all organizations (uses max page size of 5000)
443+
const allOrgs = await client.listOrgs({ all: true });
444+
445+
// Get audit logs for an organization
446+
const auditLogs = await client.getOrgAuditLogs('org-123');
447+
```
448+
449+
### Required Permissions
450+
451+
Account Manager operations require:
452+
- OAuth client with `sfcc.accountmanager.user.manage` scope
453+
- Account Manager hostname configuration
454+
- For implicit flow: roles configured on your **user account**
455+
- For client credentials flow: roles configured on the **API client**
456+
244457
## Logging
245458

246459
Configure logging for debugging HTTP requests:

0 commit comments

Comments
 (0)