@@ -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
151172Creates a Custom SCAPI endpoint with OAS 3.0 schema.
@@ -469,3 +490,110 @@ When multiple scaffolds have the same ID, later sources take precedence:
4694904 . Project scaffolds (` .b2c/scaffolds/ ` ) (highest priority)
470491
471492This 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+ ```
0 commit comments