Skip to content

Commit 6c8b984

Browse files
committed
docs: update ODS documentation for friendly sandbox ID format
Add documentation for the realm-instance friendly ID format (e.g., zzzv-123) to the ODS skill and CLI reference. Also refactor OdsCommand to inline the lookup logic with user-facing log messages.
1 parent a314204 commit 6c8b984

3 files changed

Lines changed: 113 additions & 24 deletions

File tree

docs/cli/ods.md

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ description: Commands for creating, managing, starting, stopping, and deleting O
66

77
Commands for managing On-Demand Sandboxes (ODS).
88

9+
## Sandbox ID Formats
10+
11+
Commands that operate on a specific sandbox (`get`, `start`, `stop`, `restart`, `delete`) accept two ID formats:
12+
13+
| Format | Example | Description |
14+
|--------|---------|-------------|
15+
| UUID | `abc12345-1234-1234-1234-abc123456789` | Full sandbox UUID |
16+
| Friendly ID | `zzzv-123` or `zzzv_123` | Realm-instance format |
17+
18+
The friendly ID format uses the 4-character realm code followed by a dash (`-`) or underscore (`_`) and the instance identifier. When using a friendly ID, the CLI automatically looks up the corresponding sandbox UUID.
19+
20+
```bash
21+
# These are equivalent (assuming zzzv-123 resolves to the UUID)
22+
b2c ods get abc12345-1234-1234-1234-abc123456789
23+
b2c ods get zzzv-123
24+
```
25+
926
## Global ODS Flags
1027

1128
These flags are available on all ODS commands:
@@ -176,16 +193,19 @@ b2c ods get <SANDBOXID>
176193

177194
| Argument | Description | Required |
178195
|----------|-------------|----------|
179-
| `SANDBOXID` | Sandbox ID (UUID) | Yes |
196+
| `SANDBOXID` | Sandbox ID (UUID or realm-instance, e.g., `zzzv-123`) | Yes |
180197

181198
### Examples
182199

183200
```bash
184-
# Get sandbox details
201+
# Get sandbox details using UUID
185202
b2c ods get abc12345-1234-1234-1234-abc123456789
186203

204+
# Get sandbox details using friendly ID
205+
b2c ods get zzzv-123
206+
187207
# Output as JSON
188-
b2c ods get abc12345-1234-1234-1234-abc123456789 --json
208+
b2c ods get zzzv_123 --json
189209
```
190210

191211
### Output
@@ -244,16 +264,19 @@ b2c ods start <SANDBOXID>
244264

245265
| Argument | Description | Required |
246266
|----------|-------------|----------|
247-
| `SANDBOXID` | Sandbox ID (UUID) | Yes |
267+
| `SANDBOXID` | Sandbox ID (UUID or realm-instance, e.g., `zzzv-123`) | Yes |
248268

249269
### Examples
250270

251271
```bash
252-
# Start a sandbox
272+
# Start a sandbox using UUID
253273
b2c ods start abc12345-1234-1234-1234-abc123456789
254274

275+
# Start a sandbox using friendly ID
276+
b2c ods start zzzv-123
277+
255278
# Output as JSON
256-
b2c ods start abc12345-1234-1234-1234-abc123456789 --json
279+
b2c ods start zzzv_123 --json
257280
```
258281

259282
---
@@ -272,16 +295,19 @@ b2c ods stop <SANDBOXID>
272295

273296
| Argument | Description | Required |
274297
|----------|-------------|----------|
275-
| `SANDBOXID` | Sandbox ID (UUID) | Yes |
298+
| `SANDBOXID` | Sandbox ID (UUID or realm-instance, e.g., `zzzv-123`) | Yes |
276299

277300
### Examples
278301

279302
```bash
280-
# Stop a sandbox
303+
# Stop a sandbox using UUID
281304
b2c ods stop abc12345-1234-1234-1234-abc123456789
282305

306+
# Stop a sandbox using friendly ID
307+
b2c ods stop zzzv-123
308+
283309
# Output as JSON
284-
b2c ods stop abc12345-1234-1234-1234-abc123456789 --json
310+
b2c ods stop zzzv_123 --json
285311
```
286312

287313
---
@@ -300,16 +326,19 @@ b2c ods restart <SANDBOXID>
300326

301327
| Argument | Description | Required |
302328
|----------|-------------|----------|
303-
| `SANDBOXID` | Sandbox ID (UUID) | Yes |
329+
| `SANDBOXID` | Sandbox ID (UUID or realm-instance, e.g., `zzzv-123`) | Yes |
304330

305331
### Examples
306332

307333
```bash
308-
# Restart a sandbox
334+
# Restart a sandbox using UUID
309335
b2c ods restart abc12345-1234-1234-1234-abc123456789
310336

337+
# Restart a sandbox using friendly ID
338+
b2c ods restart zzzv-123
339+
311340
# Output as JSON
312-
b2c ods restart abc12345-1234-1234-1234-abc123456789 --json
341+
b2c ods restart zzzv_123 --json
313342
```
314343

315344
---
@@ -328,7 +357,7 @@ b2c ods delete <SANDBOXID>
328357

329358
| Argument | Description | Required |
330359
|----------|-------------|----------|
331-
| `SANDBOXID` | Sandbox ID (UUID) | Yes |
360+
| `SANDBOXID` | Sandbox ID (UUID or realm-instance, e.g., `zzzv-123`) | Yes |
332361

333362
### Flags
334363

@@ -339,11 +368,14 @@ b2c ods delete <SANDBOXID>
339368
### Examples
340369

341370
```bash
342-
# Delete a sandbox (with confirmation prompt)
371+
# Delete a sandbox using UUID (with confirmation prompt)
343372
b2c ods delete abc12345-1234-1234-1234-abc123456789
344373

374+
# Delete a sandbox using friendly ID
375+
b2c ods delete zzzv-123
376+
345377
# Delete without confirmation
346-
b2c ods delete abc12345-1234-1234-1234-abc123456789 --force
378+
b2c ods delete zzzv_123 --force
347379
```
348380

349381
### Notes

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Command, Flags} from '@oclif/core';
77
import {OAuthCommand} from './oauth-command.js';
88
import {createOdsClient, type OdsClient} from '../clients/ods.js';
99
import {DEFAULT_ODS_HOST} from '../defaults.js';
10-
import {resolveSandboxId, SandboxNotFoundError} from '../operations/ods/sandbox-lookup.js';
10+
import {isUuid, parseFriendlySandboxId, SandboxNotFoundError} from '../operations/ods/sandbox-lookup.js';
1111

1212
/**
1313
* Base command for ODS (On-Demand Sandbox) operations.
@@ -89,7 +89,7 @@ export abstract class OdsCommand<T extends typeof Command> extends OAuthCommand<
8989
*
9090
* Supports both UUID format and friendly format (realm-instance, e.g., "abcd-123" or "abcd_123").
9191
* If given a UUID, returns it directly. If given a friendly format, queries the API to find
92-
* the matching sandbox.
92+
* the matching sandbox and logs the resolution.
9393
*
9494
* @param identifier - Sandbox identifier (UUID or friendly format)
9595
* @returns The sandbox UUID
@@ -102,13 +102,43 @@ export abstract class OdsCommand<T extends typeof Command> extends OAuthCommand<
102102
* ```
103103
*/
104104
protected async resolveSandboxId(identifier: string): Promise<string> {
105-
try {
106-
return await resolveSandboxId(this.odsClient, identifier);
107-
} catch (error) {
108-
if (error instanceof SandboxNotFoundError) {
109-
this.error(error.message);
110-
}
111-
throw error;
105+
// If already a UUID, return directly
106+
if (isUuid(identifier)) {
107+
return identifier;
112108
}
109+
110+
// Try to parse as friendly ID
111+
const parsed = parseFriendlySandboxId(identifier);
112+
if (!parsed) {
113+
// Not a UUID and not a friendly ID - pass through as-is
114+
// (let the API return an appropriate error)
115+
return identifier;
116+
}
117+
118+
// Log that we're looking up the sandbox
119+
this.log(`Looking up sandbox ${identifier}...`);
120+
121+
// Query sandboxes filtered by realm
122+
const {data, error} = await this.odsClient.GET('/sandboxes', {
123+
params: {
124+
query: {
125+
filter_params: `realm=${parsed.realm}`,
126+
},
127+
},
128+
});
129+
130+
if (error || !data?.data) {
131+
this.error(new SandboxNotFoundError(identifier, parsed.realm, parsed.instance).message);
132+
}
133+
134+
// Find sandbox with matching instance
135+
const sandbox = data.data.find((s) => s.instance?.toLowerCase() === parsed.instance);
136+
137+
if (!sandbox?.id) {
138+
this.error(new SandboxNotFoundError(identifier, parsed.realm, parsed.instance).message);
139+
}
140+
141+
this.log(`Resolved ${identifier} to sandbox ${sandbox.id}`);
142+
return sandbox.id;
113143
}
114144
}

plugins/b2c-cli/skills/b2c-ods/SKILL.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ description: Create and manage on-demand sandboxes (ODS). Use when provisioning
77

88
Use the `b2c` CLI plugin to manage Salesforce B2C Commerce On-demand sandboxes (ODS). Only create or delete a sandbox if explicitly asked as this may be a billable or destructible action.
99

10+
## Sandbox ID Formats
11+
12+
Commands that operate on a specific sandbox accept two ID formats:
13+
14+
- **UUID**: The full sandbox UUID (e.g., `abc12345-1234-1234-1234-abc123456789`)
15+
- **Friendly ID**: The realm-instance format (e.g., `zzzv-123` or `zzzv_123`)
16+
17+
The friendly ID format uses the 4-character realm code followed by a dash or underscore and the instance number. When using a friendly ID, the CLI will automatically look up the corresponding UUID.
18+
1019
## Examples
1120

1221
### List ODS Sandboxes
@@ -36,6 +45,24 @@ b2c ods create --realm zzpq --profile large
3645
b2c ods create --realm zzpq --log-level trace
3746
```
3847

48+
### Get/Start/Stop/Restart/Delete Sandbox
49+
50+
Commands that operate on a specific sandbox support both UUID and friendly ID formats:
51+
52+
```bash
53+
# Using UUID
54+
b2c ods get abc12345-1234-1234-1234-abc123456789
55+
b2c ods start abc12345-1234-1234-1234-abc123456789
56+
b2c ods stop abc12345-1234-1234-1234-abc123456789
57+
58+
# Using friendly ID (realm-instance)
59+
b2c ods get zzzv-123
60+
b2c ods start zzzv_123
61+
b2c ods stop zzzv-123
62+
b2c ods restart zzzv-123
63+
b2c ods delete zzzv-123 --force
64+
```
65+
3966
### More Commands
4067

4168
See `b2c ods --help` for a full list of available commands and options in the `ods` topic.

0 commit comments

Comments
 (0)