@salesforce/b2c-cli 0.9.0 → 0.10.0

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.
@@ -0,0 +1,39 @@
1
+ import { BaseCommand } from '@salesforce/b2c-tooling-sdk/cli';
2
+ import { validateMetaDefinitionFile, type MetaDefinitionValidationResult } from '@salesforce/b2c-tooling-sdk/operations/content';
3
+ interface ContentValidateResponse {
4
+ results: MetaDefinitionValidationResult[];
5
+ totalErrors: number;
6
+ totalFiles: number;
7
+ validFiles: number;
8
+ }
9
+ export default class ContentValidate extends BaseCommand<typeof ContentValidate> {
10
+ static args: {
11
+ files: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
12
+ };
13
+ static description: string;
14
+ static enableJsonFlag: boolean;
15
+ static examples: string[];
16
+ static flags: {
17
+ type: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
18
+ 'log-level': import("@oclif/core/interfaces").OptionFlag<"trace" | "debug" | "info" | "warn" | "error" | "silent" | undefined, import("@oclif/core/interfaces").CustomOptions>;
19
+ debug: import("@oclif/core/interfaces").BooleanFlag<boolean>;
20
+ json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
21
+ jsonl: import("@oclif/core/interfaces").BooleanFlag<boolean>;
22
+ lang: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
23
+ config: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
24
+ instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
25
+ 'project-directory': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
26
+ 'extra-query': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
27
+ 'extra-body': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
28
+ 'extra-headers': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
29
+ };
30
+ static strict: boolean;
31
+ protected operations: {
32
+ glob: (pattern: string, options?: {
33
+ nodir?: boolean;
34
+ }) => Promise<string[]>;
35
+ validateMetaDefinitionFile: typeof validateMetaDefinitionFile;
36
+ };
37
+ run(): Promise<ContentValidateResponse>;
38
+ }
39
+ export {};
@@ -0,0 +1,110 @@
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 fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { Args, Flags, ux } from '@oclif/core';
9
+ import { glob } from 'glob';
10
+ import { BaseCommand } from '@salesforce/b2c-tooling-sdk/cli';
11
+ import { CONTENT_SCHEMA_TYPES, MetaDefinitionDetectionError, validateMetaDefinitionFile, } from '@salesforce/b2c-tooling-sdk/operations/content';
12
+ export default class ContentValidate extends BaseCommand {
13
+ static args = {
14
+ files: Args.string({
15
+ description: 'File(s), directory, or glob pattern(s) for JSON metadefinition files to validate',
16
+ required: true,
17
+ }),
18
+ };
19
+ static description = 'Validate Page Designer metadefinition JSON files against schemas';
20
+ static enableJsonFlag = true;
21
+ static examples = [
22
+ '<%= config.bin %> <%= command.id %> cartridge/experience/pages/storePage.json',
23
+ '<%= config.bin %> <%= command.id %> --type componenttype mycomponent.json',
24
+ "<%= config.bin %> <%= command.id %> 'cartridge/experience/**/*.json'",
25
+ '<%= config.bin %> <%= command.id %> cartridge/experience/',
26
+ '<%= config.bin %> <%= command.id %> storePage.json --json',
27
+ ];
28
+ static flags = {
29
+ ...BaseCommand.baseFlags,
30
+ type: Flags.string({
31
+ char: 't',
32
+ description: 'Schema type (auto-detected if not specified)',
33
+ options: [...CONTENT_SCHEMA_TYPES],
34
+ }),
35
+ };
36
+ // Allow multiple file arguments
37
+ static strict = false;
38
+ operations = {
39
+ glob,
40
+ validateMetaDefinitionFile,
41
+ };
42
+ async run() {
43
+ const { argv, flags } = await this.parse(ContentValidate);
44
+ const patterns = argv;
45
+ if (patterns.length === 0) {
46
+ this.error('At least one file path, directory, or glob pattern is required.');
47
+ }
48
+ // Expand directories to recursive JSON globs, then resolve all patterns in parallel
49
+ const resolvedPatterns = patterns.map((pattern) => fs.existsSync(pattern) && fs.statSync(pattern).isDirectory() ? path.join(pattern, '**/*.json') : pattern);
50
+ const allMatches = await Promise.all(resolvedPatterns.map((resolved) => this.operations.glob(resolved, { nodir: true })));
51
+ const filePaths = [];
52
+ for (const [i, matches] of allMatches.entries()) {
53
+ if (matches.length === 0) {
54
+ this.warn(`No files matched: ${patterns[i]}`);
55
+ }
56
+ filePaths.push(...matches);
57
+ }
58
+ if (filePaths.length === 0) {
59
+ this.error('No files found matching the provided patterns.');
60
+ }
61
+ const results = [];
62
+ for (const filePath of filePaths) {
63
+ try {
64
+ const result = this.operations.validateMetaDefinitionFile(filePath, {
65
+ type: flags.type,
66
+ });
67
+ results.push(result);
68
+ }
69
+ catch (error) {
70
+ if (error instanceof MetaDefinitionDetectionError) {
71
+ const relativePath = path.relative(process.cwd(), path.resolve(filePath));
72
+ this.error(`${relativePath}: ${error.message}`);
73
+ }
74
+ throw error;
75
+ }
76
+ }
77
+ const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
78
+ const validFiles = results.filter((r) => r.valid).length;
79
+ const response = {
80
+ results,
81
+ totalErrors,
82
+ totalFiles: results.length,
83
+ validFiles,
84
+ };
85
+ if (this.jsonEnabled()) {
86
+ return response;
87
+ }
88
+ for (const result of results) {
89
+ const relativePath = path.relative(process.cwd(), result.filePath ?? '');
90
+ const typeInfo = result.schemaType ? ` (${result.schemaType})` : '';
91
+ if (result.valid) {
92
+ ux.stdout(`${ux.colorize('green', 'PASS')}: ${relativePath}${typeInfo}`);
93
+ }
94
+ else {
95
+ ux.stdout(`${ux.colorize('red', 'FAIL')}: ${relativePath}${typeInfo}`);
96
+ for (const error of result.errors) {
97
+ const location = error.path && error.path !== '/' ? ` at ${error.path}` : '';
98
+ ux.stdout(` ${ux.colorize('red', 'ERROR')}${location}: ${error.message}`);
99
+ }
100
+ }
101
+ }
102
+ ux.stdout('');
103
+ ux.stdout(`${validFiles}/${results.length} file(s) valid, ${totalErrors} error(s)`);
104
+ if (totalErrors > 0) {
105
+ this.error('Validation failed', { exit: 1 });
106
+ }
107
+ return response;
108
+ }
109
+ }
110
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../src/commands/content/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC5B,0BAA0B,GAG3B,MAAM,gDAAgD,CAAC;AASxD,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,WAAmC;IAC9E,MAAM,CAAC,IAAI,GAAG;QACZ,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;YACjB,WAAW,EAAE,kFAAkF;YAC/F,QAAQ,EAAE,IAAI;SACf,CAAC;KACH,CAAC;IAEF,MAAM,CAAC,WAAW,GAAG,kEAAkE,CAAC;IAExF,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IAE7B,MAAM,CAAC,QAAQ,GAAG;QAChB,+EAA+E;QAC/E,2EAA2E;QAC3E,sEAAsE;QACtE,2DAA2D;QAC3D,2DAA2D;KAC5D,CAAC;IAEF,MAAM,CAAC,KAAK,GAAG;QACb,GAAG,WAAW,CA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