Skip to content

Commit 8388394

Browse files
committed
scaffold docs: add service scaffold and SDK programmatic API
- Add service scaffold to built-in scaffolds tables - Document SDK programmatic API for non-CLI usage (MCP, IDE integrations) - Add scaffold module to typedoc entry points for API reference generation
1 parent c3d7f2e commit 8388394

4 files changed

Lines changed: 137 additions & 6 deletions

File tree

docs/api-readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The SDK is organized into focused submodules that can be imported individually:
2929
├── /operations/mrt # Managed Runtime bundle operations
3030
├── /operations/ods # On-demand sandbox utilities
3131
32+
├── /scaffold # Scaffold discovery, generation, and validation
3233
├── /docs # B2C Script API documentation search
3334
└── /schemas # OpenAPI schema utilities
3435
```

docs/cli/scaffold.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ b2c scaffold validate ./my-scaffold --strict
260260
| `cartridge` | cartridge | B2C cartridge with standard directory structure |
261261
| `controller` | cartridge | SFRA controller with route handlers and middleware |
262262
| `hook` | cartridge | Hook implementation with hooks.json registration |
263-
| `custom-api` | custom-api | Custom SCAPI endpoint with OAS 3.0 schema |
264-
| `job-step` | job | Custom job step with steptypes.json registration |
265-
| `page-designer-component` | page-designer | Page Designer component with meta/script/template |
263+
| `service` | cartridge | B2C web service using LocalServiceRegistry |
264+
| `custom-api` | cartridge | Custom SCAPI endpoint with OAS 3.0 schema |
265+
| `job-step` | cartridge | Custom job step with steptypes.json registration |
266+
| `page-designer-component` | cartridge | Page Designer component with meta/script/template |
266267

267268
Use `b2c scaffold info <id>` to see the parameters for each scaffold.

docs/guide/scaffolding.md

Lines changed: 131 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ The CLI includes scaffolds for common B2C development tasks:
2828
| `cartridge` | cartridge | Complete B2C cartridge with standard directory structure |
2929
| `controller` | cartridge | SFRA controller with route handlers and middleware |
3030
| `hook` | cartridge | Hook implementation with hooks.json registration |
31-
| `custom-api` | custom-api | Custom SCAPI endpoint with OAS 3.0 schema |
32-
| `job-step` | job | Custom job step with steptypes.json registration |
33-
| `page-designer-component` | page-designer | Page Designer component with meta/script/template |
31+
| `service` | cartridge | B2C web service using LocalServiceRegistry |
32+
| `custom-api` | cartridge | Custom SCAPI endpoint with OAS 3.0 schema |
33+
| `job-step` | cartridge | Custom job step with steptypes.json registration |
34+
| `page-designer-component` | cartridge | Page Designer component with meta/script/template |
3435

3536
## Using Scaffolds
3637

@@ -146,6 +147,26 @@ b2c scaffold hook \
146147
--option cartridgeName=app_custom
147148
```
148149

150+
### service
151+
152+
Creates a B2C Commerce web service using LocalServiceRegistry.
153+
154+
**Parameters:**
155+
- `serviceName` (required) - Service name in PascalCase (e.g., `PaymentGateway`)
156+
- `cartridgeName` (required) - Target cartridge (auto-discovered from project)
157+
- `serviceType` (required) - Service type: HTTP, SOAP, SFTP (default: HTTP)
158+
- `authType` - Authentication method: NONE, BASIC, BEARER, API_KEY (default: NONE, HTTP only)
159+
- `includeErrorHandling` - Include robust error handling (default: true)
160+
- `includeMocking` - Include mock callback for testing (default: false)
161+
162+
```bash
163+
b2c scaffold service \
164+
--option serviceName=PaymentGateway \
165+
--option cartridgeName=app_custom \
166+
--option serviceType=HTTP \
167+
--option authType=BASIC
168+
```
169+
149170
### custom-api
150171

151172
Creates a Custom SCAPI endpoint with OAS 3.0 schema.
@@ -469,3 +490,110 @@ When multiple scaffolds have the same ID, later sources take precedence:
469490
4. Project scaffolds (`.b2c/scaffolds/`) (highest priority)
470491

471492
This allows you to override built-in scaffolds with project-specific versions.
493+
494+
## Programmatic Usage (SDK)
495+
496+
The scaffold functionality is also available as a programmatic API for IDE integrations, MCP servers, and custom tooling.
497+
498+
### Discovery and Generation
499+
500+
```typescript
501+
import {
502+
createScaffoldRegistry,
503+
generateFromScaffold,
504+
resolveScaffoldParameters,
505+
parseParameterOptions,
506+
resolveOutputDirectory,
507+
} from '@salesforce/b2c-tooling-sdk/scaffold';
508+
509+
// Create registry and discover scaffolds
510+
const registry = createScaffoldRegistry();
511+
const scaffolds = await registry.getScaffolds({ projectRoot: '/path/to/project' });
512+
const scaffold = await registry.getScaffold('service', { projectRoot: '/path/to/project' });
513+
514+
// Parse command-line style options
515+
const providedVariables = parseParameterOptions(
516+
['serviceName=PaymentGateway', 'serviceType=HTTP'],
517+
scaffold
518+
);
519+
520+
// Resolve parameters (validate, apply defaults, resolve sources)
521+
const resolved = await resolveScaffoldParameters(scaffold, {
522+
providedVariables,
523+
projectRoot: '/path/to/project',
524+
useDefaults: true, // Apply defaults for missing optional params
525+
});
526+
527+
// Check for errors or missing required parameters
528+
if (resolved.errors.length > 0) {
529+
console.error('Validation errors:', resolved.errors);
530+
}
531+
if (resolved.missingParameters.length > 0) {
532+
console.log('Missing parameters:', resolved.missingParameters.map(p => p.name));
533+
}
534+
535+
// Resolve output directory
536+
const outputDir = resolveOutputDirectory({
537+
outputDir: undefined, // Optional explicit override
538+
scaffold,
539+
projectRoot: '/path/to/project',
540+
});
541+
542+
// Generate files
543+
const result = await generateFromScaffold(scaffold, {
544+
outputDir,
545+
variables: resolved.variables,
546+
dryRun: false,
547+
force: false,
548+
});
549+
550+
console.log('Generated files:', result.files);
551+
console.log('Post instructions:', result.postInstructions);
552+
```
553+
554+
### Parameter Schema Discovery
555+
556+
For building dynamic UIs or input schemas:
557+
558+
```typescript
559+
import { getParameterSchemas } from '@salesforce/b2c-tooling-sdk/scaffold';
560+
561+
// Get parameter schemas with resolved choices
562+
const schemas = await getParameterSchemas(scaffold, {
563+
projectRoot: '/path/to/project',
564+
});
565+
566+
for (const schema of schemas) {
567+
console.log(`${schema.parameter.name}: ${schema.parameter.type}`);
568+
if (schema.resolvedChoices) {
569+
console.log(' Choices:', schema.resolvedChoices.map(c => c.value));
570+
}
571+
if (schema.warning) {
572+
console.log(' Warning:', schema.warning);
573+
}
574+
}
575+
```
576+
577+
### Validation
578+
579+
```typescript
580+
import {
581+
validateScaffoldDirectory,
582+
validateEjsSyntax,
583+
} from '@salesforce/b2c-tooling-sdk/scaffold';
584+
585+
// Validate a scaffold directory
586+
const result = await validateScaffoldDirectory('/path/to/scaffold', {
587+
strict: false, // Set true to treat warnings as errors
588+
});
589+
590+
console.log('Valid:', result.valid);
591+
console.log('Errors:', result.errors);
592+
console.log('Warnings:', result.warnings);
593+
for (const issue of result.issues) {
594+
console.log(`${issue.severity}: ${issue.message} (${issue.file})`);
595+
}
596+
597+
// Validate EJS template syntax directly
598+
const ejsIssues = validateEjsSyntax('<%= name %>', 'template.ejs');
599+
```

typedoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"./packages/b2c-tooling-sdk/src/operations/logs/index.ts",
1212
"./packages/b2c-tooling-sdk/src/operations/mrt/index.ts",
1313
"./packages/b2c-tooling-sdk/src/operations/ods/index.ts",
14+
"./packages/b2c-tooling-sdk/src/scaffold/index.ts",
1415
"./packages/b2c-tooling-sdk/src/docs/index.ts",
1516
"./packages/b2c-tooling-sdk/src/schemas/index.ts",
1617
"./packages/b2c-tooling-sdk/src/cli/index.ts",

0 commit comments

Comments
 (0)