@salesforce/b2c-dx-mcp 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +15 -62
  2. package/dist/commands/mcp.d.ts +1 -0
  3. package/dist/commands/mcp.js +41 -9
  4. package/dist/registry.d.ts +3 -4
  5. package/dist/registry.js +7 -14
  6. package/dist/server.d.ts +1 -1
  7. package/dist/server.js +3 -1
  8. package/dist/services.d.ts +21 -1
  9. package/dist/services.js +39 -6
  10. package/dist/tools/adapter.d.ts +18 -2
  11. package/dist/tools/adapter.js +49 -10
  12. package/dist/tools/cartridges/index.js +16 -22
  13. package/dist/tools/diagnostics/config-inspect.js +4 -8
  14. package/dist/tools/diagnostics/debug-capture-at-breakpoint.js +3 -9
  15. package/dist/tools/diagnostics/debug-list-sessions.js +1 -0
  16. package/dist/tools/diagnostics/debug-start-session.js +16 -9
  17. package/dist/tools/diagnostics/debug-wait-for-stop.js +1 -3
  18. package/dist/tools/diagnostics/log-watch-registry.d.ts +3 -0
  19. package/dist/tools/diagnostics/log-watch-registry.js +1 -0
  20. package/dist/tools/diagnostics/logs-get-recent.js +2 -5
  21. package/dist/tools/diagnostics/logs-list-files.js +1 -1
  22. package/dist/tools/diagnostics/logs-watch-list.js +1 -0
  23. package/dist/tools/diagnostics/logs-watch-start.js +10 -10
  24. package/dist/tools/diagnostics/mrt-log-watch-registry.d.ts +3 -0
  25. package/dist/tools/diagnostics/mrt-log-watch-registry.js +0 -0
  26. package/dist/tools/diagnostics/mrt-logs-watch-list.js +1 -0
  27. package/dist/tools/diagnostics/mrt-logs-watch-poll.js +2 -5
  28. package/dist/tools/diagnostics/mrt-logs-watch-start.js +9 -8
  29. package/dist/tools/diagnostics/session-registry.d.ts +3 -0
  30. package/dist/tools/diagnostics/session-registry.js +2 -1
  31. package/dist/tools/docs/docs-list.js +4 -6
  32. package/dist/tools/docs/docs-read.js +2 -9
  33. package/dist/tools/docs/docs-schema-list.js +1 -1
  34. package/dist/tools/docs/docs-schema-read.js +2 -3
  35. package/dist/tools/docs/docs-schema-search.js +2 -2
  36. package/dist/tools/docs/docs-search.js +3 -9
  37. package/dist/tools/docs/storefront.js +3 -3
  38. package/dist/tools/docs/topics.js +3 -1
  39. package/dist/tools/index.d.ts +0 -1
  40. package/dist/tools/index.js +0 -1
  41. package/dist/tools/mrt/index.js +6 -2
  42. package/dist/tools/project-context.d.ts +38 -11
  43. package/dist/tools/project-context.js +32 -15
  44. package/dist/tools/pwav3/pwa-kit-development-guidelines.js +3 -43
  45. package/dist/tools/scapi/metrics-get.js +5 -23
  46. package/dist/tools/scapi/scapi-custom-api-generate-scaffold.d.ts +4 -0
  47. package/dist/tools/scapi/scapi-custom-api-generate-scaffold.js +29 -14
  48. package/dist/tools/scapi/scapi-custom-apis-get-status.js +3 -14
  49. package/dist/tools/scapi/scapi-schemas-list.js +11 -11
  50. package/dist/utils/constants.d.ts +2 -13
  51. package/dist/utils/constants.js +1 -20
  52. package/oclif.manifest.json +2 -2
  53. package/package.json +5 -5
  54. package/content/sfnext/auth.md +0 -62
  55. package/content/sfnext/components.md +0 -123
  56. package/content/sfnext/config.md +0 -180
  57. package/content/sfnext/data-fetching.md +0 -323
  58. package/content/sfnext/extensions.md +0 -80
  59. package/content/sfnext/i18n.md +0 -121
  60. package/content/sfnext/page-designer.md +0 -78
  61. package/content/sfnext/performance.md +0 -80
  62. package/content/sfnext/pitfalls.md +0 -141
  63. package/content/sfnext/quick-reference.md +0 -226
  64. package/content/sfnext/state-management.md +0 -75
  65. package/content/sfnext/styling.md +0 -51
  66. package/content/sfnext/testing.md +0 -232
  67. package/dist/tools/storefrontnext/figma/figma-to-component/figma-url-parser.d.ts +0 -24
  68. package/dist/tools/storefrontnext/figma/figma-to-component/figma-url-parser.js +0 -53
  69. package/dist/tools/storefrontnext/figma/figma-to-component/index.d.ts +0 -45
  70. package/dist/tools/storefrontnext/figma/figma-to-component/index.js +0 -332
  71. package/dist/tools/storefrontnext/figma/generate-component/decision.d.ts +0 -40
  72. package/dist/tools/storefrontnext/figma/generate-component/decision.js +0 -312
  73. package/dist/tools/storefrontnext/figma/generate-component/formatter.d.ts +0 -9
  74. package/dist/tools/storefrontnext/figma/generate-component/formatter.js +0 -92
  75. package/dist/tools/storefrontnext/figma/generate-component/index.d.ts +0 -117
  76. package/dist/tools/storefrontnext/figma/generate-component/index.js +0 -102
  77. package/dist/tools/storefrontnext/figma/map-tokens/css-parser.d.ts +0 -71
  78. package/dist/tools/storefrontnext/figma/map-tokens/css-parser.js +0 -260
  79. package/dist/tools/storefrontnext/figma/map-tokens/index.d.ts +0 -64
  80. package/dist/tools/storefrontnext/figma/map-tokens/index.js +0 -242
  81. package/dist/tools/storefrontnext/figma/map-tokens/token-matcher.d.ts +0 -65
  82. package/dist/tools/storefrontnext/figma/map-tokens/token-matcher.js +0 -268
  83. package/dist/tools/storefrontnext/index.d.ts +0 -30
  84. package/dist/tools/storefrontnext/index.js +0 -28
  85. package/dist/tools/storefrontnext/page-designer-decorator/analyzer.d.ts +0 -169
  86. package/dist/tools/storefrontnext/page-designer-decorator/analyzer.js +0 -567
  87. package/dist/tools/storefrontnext/page-designer-decorator/index.d.ts +0 -259
  88. package/dist/tools/storefrontnext/page-designer-decorator/index.js +0 -622
  89. package/dist/tools/storefrontnext/page-designer-decorator/rules/1-mode-selection.d.ts +0 -8
  90. package/dist/tools/storefrontnext/page-designer-decorator/rules/1-mode-selection.js +0 -65
  91. package/dist/tools/storefrontnext/page-designer-decorator/rules/2a-auto-mode.d.ts +0 -13
  92. package/dist/tools/storefrontnext/page-designer-decorator/rules/2a-auto-mode.js +0 -87
  93. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-0-interactive-overview.d.ts +0 -4
  94. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-0-interactive-overview.js +0 -55
  95. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-1-interactive-analyze.d.ts +0 -22
  96. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-1-interactive-analyze.js +0 -109
  97. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-2-interactive-select-props.d.ts +0 -21
  98. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-2-interactive-select-props.js +0 -60
  99. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-3-interactive-configure-attrs.d.ts +0 -27
  100. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-3-interactive-configure-attrs.js +0 -68
  101. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-4-interactive-configure-regions.d.ts +0 -4
  102. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-4-interactive-configure-regions.js +0 -65
  103. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-5-interactive-confirm-generation.d.ts +0 -11
  104. package/dist/tools/storefrontnext/page-designer-decorator/rules/2b-5-interactive-confirm-generation.js +0 -92
  105. package/dist/tools/storefrontnext/page-designer-decorator/rules.d.ts +0 -51
  106. package/dist/tools/storefrontnext/page-designer-decorator/rules.js +0 -70
  107. package/dist/tools/storefrontnext/page-designer-decorator/templates/decorator-generator.d.ts +0 -116
  108. package/dist/tools/storefrontnext/page-designer-decorator/templates/decorator-generator.js +0 -350
  109. package/dist/tools/storefrontnext/sfnext-development-guidelines.d.ts +0 -9
  110. package/dist/tools/storefrontnext/sfnext-development-guidelines.js +0 -141
  111. package/dist/tools/storefrontnext/site-theming/color-contrast.d.ts +0 -92
  112. package/dist/tools/storefrontnext/site-theming/color-contrast.js +0 -186
  113. package/dist/tools/storefrontnext/site-theming/color-mapping.d.ts +0 -16
  114. package/dist/tools/storefrontnext/site-theming/color-mapping.js +0 -131
  115. package/dist/tools/storefrontnext/site-theming/guidance-merger.d.ts +0 -11
  116. package/dist/tools/storefrontnext/site-theming/guidance-merger.js +0 -78
  117. package/dist/tools/storefrontnext/site-theming/index.d.ts +0 -14
  118. package/dist/tools/storefrontnext/site-theming/index.js +0 -128
  119. package/dist/tools/storefrontnext/site-theming/response-builder.d.ts +0 -16
  120. package/dist/tools/storefrontnext/site-theming/response-builder.js +0 -316
  121. package/dist/tools/storefrontnext/site-theming/theming-store.d.ts +0 -64
  122. package/dist/tools/storefrontnext/site-theming/theming-store.js +0 -417
  123. package/dist/tools/storefrontnext/site-theming/types.d.ts +0 -36
  124. package/dist/tools/storefrontnext/site-theming/types.js +0 -7
@@ -1,51 +0,0 @@
1
- import { type ModeSelectionContext } from './rules/1-mode-selection.js';
2
- import { type AnalyzeStepContext } from './rules/2b-1-interactive-analyze.js';
3
- import { type SelectPropsContext } from './rules/2b-2-interactive-select-props.js';
4
- import { type ConfigureAttrsContext } from './rules/2b-3-interactive-configure-attrs.js';
5
- import { type ConfigureRegionsContext } from './rules/2b-4-interactive-configure-regions.js';
6
- import { type ConfirmGenerationContext } from './rules/2b-5-interactive-confirm-generation.js';
7
- import { type AutoModeContext } from './rules/2a-auto-mode.js';
8
- /**
9
- * Page Designer decorator rules - type-safe, zero dependencies
10
- */
11
- export declare const pageDesignerDecoratorRules: {
12
- /**
13
- * Renders the mode selection prompt
14
- */
15
- getModeSelectionInstructions(context: ModeSelectionContext): string;
16
- /**
17
- * Renders the interactive mode workflow overview
18
- */
19
- getInteractiveOverview(): string;
20
- /**
21
- * Renders Interactive Analyze step instructions
22
- */
23
- getAnalyzeInstructions(context: AnalyzeStepContext): string;
24
- /**
25
- * Renders Interactive Select Props step confirmation
26
- */
27
- getSelectPropsConfirmation(context: SelectPropsContext): string;
28
- /**
29
- * Renders Interactive Configure Attributes step instructions
30
- */
31
- getConfigureAttrsInstructions(context: ConfigureAttrsContext): string;
32
- /**
33
- * Renders Interactive Configure Regions step instructions
34
- */
35
- getConfigureRegionsInstructions(context: ConfigureRegionsContext): string;
36
- /**
37
- * Renders Interactive Confirm Generation step (final code presentation)
38
- */
39
- getConfirmGenerationInstructions(context: ConfirmGenerationContext): string;
40
- /**
41
- * Renders Auto Mode instructions
42
- */
43
- getAutoModeInstructions(context: AutoModeContext): string;
44
- };
45
- export type { ModeSelectionContext } from './rules/1-mode-selection.js';
46
- export type { AutoModeContext } from './rules/2a-auto-mode.js';
47
- export type { AnalyzeStepContext } from './rules/2b-1-interactive-analyze.js';
48
- export type { SelectPropsContext } from './rules/2b-2-interactive-select-props.js';
49
- export type { ConfigureAttrsContext } from './rules/2b-3-interactive-configure-attrs.js';
50
- export type { ConfigureRegionsContext } from './rules/2b-4-interactive-configure-regions.js';
51
- export type { ConfirmGenerationContext } from './rules/2b-5-interactive-confirm-generation.js';
@@ -1,70 +0,0 @@
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 all rule renderers
7
- import { renderModeSelection } from './rules/1-mode-selection.js';
8
- import { renderInteractiveOverview } from './rules/2b-0-interactive-overview.js';
9
- import { renderAnalyzeStep } from './rules/2b-1-interactive-analyze.js';
10
- import { renderSelectPropsConfirmation } from './rules/2b-2-interactive-select-props.js';
11
- import { renderConfigureAttrs } from './rules/2b-3-interactive-configure-attrs.js';
12
- import { renderConfigureRegions } from './rules/2b-4-interactive-configure-regions.js';
13
- import { renderConfirmGeneration } from './rules/2b-5-interactive-confirm-generation.js';
14
- import { renderAutoMode } from './rules/2a-auto-mode.js';
15
- /**
16
- * Page Designer decorator rules - type-safe, zero dependencies
17
- */
18
- export const pageDesignerDecoratorRules = {
19
- /**
20
- * Renders the mode selection prompt
21
- */
22
- getModeSelectionInstructions(context) {
23
- return renderModeSelection(context);
24
- },
25
- /**
26
- * Renders the interactive mode workflow overview
27
- */
28
- getInteractiveOverview() {
29
- return renderInteractiveOverview();
30
- },
31
- /**
32
- * Renders Interactive Analyze step instructions
33
- */
34
- getAnalyzeInstructions(context) {
35
- const workflow = this.getInteractiveOverview();
36
- const stepContent = renderAnalyzeStep(context);
37
- return `${workflow}\n\n${stepContent}`;
38
- },
39
- /**
40
- * Renders Interactive Select Props step confirmation
41
- */
42
- getSelectPropsConfirmation(context) {
43
- return renderSelectPropsConfirmation(context);
44
- },
45
- /**
46
- * Renders Interactive Configure Attributes step instructions
47
- */
48
- getConfigureAttrsInstructions(context) {
49
- return renderConfigureAttrs(context);
50
- },
51
- /**
52
- * Renders Interactive Configure Regions step instructions
53
- */
54
- getConfigureRegionsInstructions(context) {
55
- return renderConfigureRegions(context);
56
- },
57
- /**
58
- * Renders Interactive Confirm Generation step (final code presentation)
59
- */
60
- getConfirmGenerationInstructions(context) {
61
- return renderConfirmGeneration(context);
62
- },
63
- /**
64
- * Renders Auto Mode instructions
65
- */
66
- getAutoModeInstructions(context) {
67
- return renderAutoMode(context);
68
- },
69
- };
70
- //# sourceMappingURL=rules.js.map
@@ -1,116 +0,0 @@
1
- export interface AttributeContext {
2
- name: string;
3
- tsType: string;
4
- optional: boolean;
5
- hasConfig: boolean;
6
- config?: {
7
- id?: string;
8
- type?: string;
9
- name?: string;
10
- description?: string;
11
- defaultValue?: unknown;
12
- required?: boolean;
13
- values?: string[];
14
- };
15
- }
16
- export interface RegionContext {
17
- id: string;
18
- name: string;
19
- description?: string;
20
- maxComponents?: number;
21
- componentTypeInclusions?: string[];
22
- componentTypeExclusions?: string[];
23
- }
24
- export interface MetadataContext {
25
- needsImports: boolean;
26
- componentId: string;
27
- componentName: string;
28
- componentDescription: string;
29
- componentGroup?: string;
30
- metadataClassName: string;
31
- hasAttributes: boolean;
32
- hasRegions: boolean;
33
- hasLoader: boolean;
34
- regions: RegionContext[];
35
- attributes: AttributeContext[];
36
- }
37
- /**
38
- * Generate complete Page Designer decorator code for a React component
39
- *
40
- * **This is the main code generation function.**
41
- *
42
- * Produces a TypeScript class with decorators that:
43
- * 1. Registers the component in Page Designer
44
- * 2. Defines editable attributes (props)
45
- * 3. Optionally defines nested content regions
46
- *
47
- * **Output structure:**
48
- * ```typescript
49
- * import { Component } from '...';
50
- * import { AttributeDefinition } from '...';
51
- *
52
- * @Component('component-id', {
53
- * name: 'Component Name',
54
- * description: '...',
55
- * group: 'category'
56
- * })
57
- * @RegionDefinition([...]) // Optional
58
- * export class ComponentMetadata {
59
- * @AttributeDefinition({ ... })
60
- * prop1!: string;
61
- *
62
- * @AttributeDefinition()
63
- * prop2?: number;
64
- * }
65
- * ```
66
- *
67
- * **Generated code must be:**
68
- * - Added to the component file (after imports, before component)
69
- * - Compiled with TypeScript
70
- * - Used by the staticRegistry Vite plugin to generate the component registry
71
- *
72
- * @param context - Complete metadata context
73
- * @returns TypeScript code string ready to paste into component file
74
- *
75
- * @example
76
- * // Simple component with attributes:
77
- * generateDecoratorCode({
78
- * needsImports: true,
79
- * componentId: 'hero-banner',
80
- * componentName: 'Hero Banner',
81
- * componentDescription: 'Large hero section with image and CTA',
82
- * componentGroup: 'content',
83
- * metadataClassName: 'HeroBannerMetadata',
84
- * hasAttributes: true,
85
- * hasRegions: false,
86
- * hasLoader: false,
87
- * regions: [],
88
- * attributes: [
89
- * { name: 'title', tsType: 'string', optional: false, hasConfig: false },
90
- * { name: 'imageUrl', tsType: 'string', optional: false, hasConfig: true,
91
- * config: { type: 'image', name: 'Background Image' } }
92
- * ]
93
- * })
94
- *
95
- * @example
96
- * // Layout component with regions:
97
- * generateDecoratorCode({
98
- * needsImports: true,
99
- * componentId: 'two-column',
100
- * componentName: 'Two Column Layout',
101
- * componentDescription: 'Side-by-side content layout',
102
- * componentGroup: 'layout',
103
- * metadataClassName: 'TwoColumnMetadata',
104
- * hasAttributes: false,
105
- * hasRegions: true,
106
- * hasLoader: false,
107
- * regions: [
108
- * { id: 'left', name: 'Left Column' },
109
- * { id: 'right', name: 'Right Column' }
110
- * ],
111
- * attributes: []
112
- * })
113
- *
114
- * @public
115
- */
116
- export declare function generateDecoratorCode(context: MetadataContext): string;
@@ -1,350 +0,0 @@
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
- /**
7
- * Generate a simple attribute decorator with auto-inferred type
8
- *
9
- * **Simple attributes** use default Page Designer behavior:
10
- * - Type is inferred from TypeScript type
11
- * - No custom configuration needed
12
- * - Minimal decorator syntax
13
- *
14
- * **When to use:**
15
- * - Basic string, number, or boolean props
16
- * - No special validation or defaults needed
17
- * - Standard field naming is acceptable
18
- *
19
- * @param attr - Attribute context
20
- * @returns TypeScript code string for the attribute
21
- *
22
- * @example
23
- * // Input:
24
- * { name: 'title', tsType: 'string', optional: false, hasConfig: false }
25
- *
26
- * // Output:
27
- * `@AttributeDefinition()
28
- * title!: string;`
29
- *
30
- * @internal
31
- */
32
- function generateSimpleAttribute(attr) {
33
- return ` @AttributeDefinition()
34
- ${attr.name}${attr.optional ? '?' : '!'}: ${attr.tsType};`;
35
- }
36
- /**
37
- * Generate a configured attribute decorator with explicit settings
38
- *
39
- * **Configured attributes** specify custom Page Designer behavior:
40
- * - Explicit `type` (url, image, enum, etc.)
41
- * - Custom `name` for display in Page Designer UI
42
- * - `description` for merchant guidance
43
- * - `defaultValue` for new instances
44
- * - `required` flag for validation
45
- * - `values` array for enum types
46
- *
47
- * **When to use:**
48
- * - URL, image, or rich text fields (need specific editors)
49
- * - Enum fields with predefined options
50
- * - Fields with default values
51
- * - Fields with merchant-friendly names
52
- *
53
- * @param attr - Attribute context with configuration
54
- * @returns TypeScript code string for the configured attribute
55
- *
56
- * @example
57
- * // Input (URL field):
58
- * {
59
- * name: 'ctaUrl',
60
- * tsType: 'string',
61
- * optional: false,
62
- * hasConfig: true,
63
- * config: {
64
- * type: 'url',
65
- * name: 'CTA Button URL',
66
- * description: 'Destination URL for the call-to-action button'
67
- * }
68
- * }
69
- *
70
- * // Output:
71
- * `@AttributeDefinition({
72
- * type: 'url',
73
- * name: 'CTA Button URL',
74
- * description: 'Destination URL for the call-to-action button',
75
- * })
76
- * ctaUrl!: string;`
77
- *
78
- * @example
79
- * // Input (Enum field):
80
- * {
81
- * name: 'variant',
82
- * tsType: 'string',
83
- * optional: false,
84
- * hasConfig: true,
85
- * config: {
86
- * type: 'enum',
87
- * name: 'Button Variant',
88
- * values: ['primary', 'secondary', 'outline'],
89
- * defaultValue: 'primary'
90
- * }
91
- * }
92
- *
93
- * // Output:
94
- * `@AttributeDefinition({
95
- * type: 'enum',
96
- * name: 'Button Variant',
97
- * defaultValue: 'primary',
98
- * values: ['primary', 'secondary', 'outline'],
99
- * })
100
- * variant!: string;`
101
- *
102
- * @internal
103
- */
104
- function generateConfiguredAttribute(attr) {
105
- if (!attr.config) {
106
- return generateSimpleAttribute(attr);
107
- }
108
- const config = attr.config;
109
- const configLines = [];
110
- if (config.id) {
111
- configLines.push(` id: '${config.id}',`);
112
- }
113
- if (config.name) {
114
- configLines.push(` name: '${config.name}',`);
115
- }
116
- if (config.type) {
117
- configLines.push(` type: '${config.type}',`);
118
- }
119
- if (config.description) {
120
- configLines.push(` description: '${config.description}',`);
121
- }
122
- if (config.defaultValue !== undefined) {
123
- const valueStr = typeof config.defaultValue === 'string' ? `'${config.defaultValue}'` : JSON.stringify(config.defaultValue);
124
- configLines.push(` defaultValue: ${valueStr},`);
125
- }
126
- if (config.required !== undefined) {
127
- configLines.push(` required: ${config.required},`);
128
- }
129
- if (config.values && config.values.length > 0) {
130
- configLines.push(` values: [${config.values.map((v) => `'${v}'`).join(', ')}],`);
131
- }
132
- return ` @AttributeDefinition({
133
- ${configLines.join('\n')}
134
- })
135
- ${attr.name}${attr.optional ? '?' : '!'}: ${attr.tsType};`;
136
- }
137
- /**
138
- * Generate import statements for Page Designer decorators
139
- *
140
- * **Decision logic:**
141
- * - Always imports `Component` (required for all decorated components)
142
- * - Conditionally imports `AttributeDefinition` (if component has editable props)
143
- * - Conditionally imports `RegionDefinition` (if component has nested content areas)
144
- *
145
- * **Why conditional:**
146
- * Avoids unused imports that would trigger linting warnings.
147
- *
148
- * @param context - Metadata context indicating what's needed
149
- * @returns TypeScript import statements with trailing newlines
150
- *
151
- * @example
152
- * // Component with attributes only:
153
- * generateImports({ needsImports: true, hasAttributes: true, hasRegions: false })
154
- * // => `import { Component } from '@/lib/decorators/component';
155
- * // import { AttributeDefinition } from '@/lib/decorators/attribute-definition';\n\n`
156
- *
157
- * @example
158
- * // Component with regions:
159
- * generateImports({ needsImports: true, hasAttributes: true, hasRegions: true })
160
- * // => All three decorators imported
161
- *
162
- * @internal
163
- */
164
- function generateImports(context) {
165
- if (!context.needsImports) {
166
- return '';
167
- }
168
- const imports = [`import { Component } from '@/lib/decorators/component';`];
169
- if (context.hasAttributes) {
170
- imports.push(`import { AttributeDefinition } from '@/lib/decorators/attribute-definition';`);
171
- }
172
- if (context.hasRegions) {
173
- imports.push(`import { RegionDefinition } from '@/lib/decorators';`);
174
- }
175
- return `${imports.join('\n')}\n\n`;
176
- }
177
- /**
178
- * Generate @RegionDefinition decorator for nested content areas
179
- *
180
- * **Regions** define areas where merchants can add nested components in Page Designer.
181
- * Common use cases:
182
- * - Layout containers (grid cells, columns)
183
- * - Content sections (header, body, footer)
184
- * - Tab panels, accordion items
185
- *
186
- * **Configuration options:**
187
- * - `id`: Unique identifier for the region
188
- * - `name`: Display name in Page Designer
189
- * - `description`: Merchant guidance
190
- * - `maxComponents`: Limit number of nested components
191
- * - `componentTypeInclusions`: Whitelist of allowed component types
192
- * - `componentTypeExclusions`: Blacklist of disallowed component types
193
- *
194
- * @param context - Metadata context with region definitions
195
- * @returns TypeScript code for @RegionDefinition decorator or empty string
196
- *
197
- * @example
198
- * // Simple region:
199
- * {
200
- * hasRegions: true,
201
- * regions: [{
202
- * id: 'main',
203
- * name: 'Main Content Area',
204
- * description: 'Add content components here'
205
- * }]
206
- * }
207
- * // => `@RegionDefinition([
208
- * // {
209
- * // id: 'main',
210
- * // name: 'Main Content Area',
211
- * // description: 'Add content components here',
212
- * // }
213
- * // ])\n`
214
- *
215
- * @example
216
- * // Constrained region:
217
- * {
218
- * hasRegions: true,
219
- * regions: [{
220
- * id: 'grid',
221
- * name: 'Product Grid',
222
- * maxComponents: 12,
223
- * componentTypeInclusions: ['product-tile', 'product-card']
224
- * }]
225
- * }
226
- *
227
- * @internal
228
- */
229
- function generateRegionDefinition(context) {
230
- if (!context.hasRegions || context.regions.length === 0) {
231
- return '';
232
- }
233
- const regionsDef = context.regions
234
- .map((region) => {
235
- const lines = [` {`, ` id: '${region.id}',`, ` name: '${region.name}',`];
236
- if (region.description) {
237
- lines.push(` description: '${region.description}',`);
238
- }
239
- if (region.maxComponents !== undefined) {
240
- lines.push(` maxComponents: ${region.maxComponents},`);
241
- }
242
- if (region.componentTypeInclusions && region.componentTypeInclusions.length > 0) {
243
- lines.push(` componentTypeInclusions: [${region.componentTypeInclusions.map((t) => `'${t}'`).join(', ')}],`);
244
- }
245
- if (region.componentTypeExclusions && region.componentTypeExclusions.length > 0) {
246
- lines.push(` componentTypeExclusions: [${region.componentTypeExclusions.map((t) => `'${t}'`).join(', ')}],`);
247
- }
248
- lines.push(` }`);
249
- return lines.join('\n');
250
- })
251
- .join(',\n');
252
- return `@RegionDefinition([\n${regionsDef}\n])\n`;
253
- }
254
- /**
255
- * Generate complete Page Designer decorator code for a React component
256
- *
257
- * **This is the main code generation function.**
258
- *
259
- * Produces a TypeScript class with decorators that:
260
- * 1. Registers the component in Page Designer
261
- * 2. Defines editable attributes (props)
262
- * 3. Optionally defines nested content regions
263
- *
264
- * **Output structure:**
265
- * ```typescript
266
- * import { Component } from '...';
267
- * import { AttributeDefinition } from '...';
268
- *
269
- * @Component('component-id', {
270
- * name: 'Component Name',
271
- * description: '...',
272
- * group: 'category'
273
- * })
274
- * @RegionDefinition([...]) // Optional
275
- * export class ComponentMetadata {
276
- * @AttributeDefinition({ ... })
277
- * prop1!: string;
278
- *
279
- * @AttributeDefinition()
280
- * prop2?: number;
281
- * }
282
- * ```
283
- *
284
- * **Generated code must be:**
285
- * - Added to the component file (after imports, before component)
286
- * - Compiled with TypeScript
287
- * - Used by the staticRegistry Vite plugin to generate the component registry
288
- *
289
- * @param context - Complete metadata context
290
- * @returns TypeScript code string ready to paste into component file
291
- *
292
- * @example
293
- * // Simple component with attributes:
294
- * generateDecoratorCode({
295
- * needsImports: true,
296
- * componentId: 'hero-banner',
297
- * componentName: 'Hero Banner',
298
- * componentDescription: 'Large hero section with image and CTA',
299
- * componentGroup: 'content',
300
- * metadataClassName: 'HeroBannerMetadata',
301
- * hasAttributes: true,
302
- * hasRegions: false,
303
- * hasLoader: false,
304
- * regions: [],
305
- * attributes: [
306
- * { name: 'title', tsType: 'string', optional: false, hasConfig: false },
307
- * { name: 'imageUrl', tsType: 'string', optional: false, hasConfig: true,
308
- * config: { type: 'image', name: 'Background Image' } }
309
- * ]
310
- * })
311
- *
312
- * @example
313
- * // Layout component with regions:
314
- * generateDecoratorCode({
315
- * needsImports: true,
316
- * componentId: 'two-column',
317
- * componentName: 'Two Column Layout',
318
- * componentDescription: 'Side-by-side content layout',
319
- * componentGroup: 'layout',
320
- * metadataClassName: 'TwoColumnMetadata',
321
- * hasAttributes: false,
322
- * hasRegions: true,
323
- * hasLoader: false,
324
- * regions: [
325
- * { id: 'left', name: 'Left Column' },
326
- * { id: 'right', name: 'Right Column' }
327
- * ],
328
- * attributes: []
329
- * })
330
- *
331
- * @public
332
- */
333
- export function generateDecoratorCode(context) {
334
- const imports = generateImports(context);
335
- const componentDecorator = `@Component('${context.componentId}', {
336
- name: '${context.componentName}',
337
- description: '${context.componentDescription}',${context.componentGroup ? `\n group: '${context.componentGroup}',` : ''}
338
- })`;
339
- const regionDefinition = generateRegionDefinition(context);
340
- const attributes = context.attributes
341
- .map((attr) => {
342
- return attr.hasConfig ? generateConfiguredAttribute(attr) : generateSimpleAttribute(attr);
343
- })
344
- .join('\n\n');
345
- return `${imports}${componentDecorator}
346
- ${regionDefinition}export class ${context.metadataClassName} {
347
- ${attributes}
348
- }`;
349
- }
350
- //# sourceMappingURL=decorator-generator.js.map
@@ -1,9 +0,0 @@
1
- import type { McpTool } from '../../utils/index.js';
2
- import type { Services } from '../../services.js';
3
- /**
4
- * Creates the developer guidelines tool for Storefront Next.
5
- *
6
- * @param loadServices - Function that loads configuration and returns Services instance
7
- * @returns The configured MCP tool
8
- */
9
- export declare function createDeveloperGuidelinesTool(loadServices: () => Promise<Services> | Services): McpTool;