@contentstack/cli-audit 1.6.1 → 1.6.2

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.
package/README.md CHANGED
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
19
19
  $ csdx COMMAND
20
20
  running command...
21
21
  $ csdx (--version|-v)
22
- @contentstack/cli-audit/1.6.1 linux-x64 node-v18.20.2
22
+ @contentstack/cli-audit/1.6.2 linux-x64 node-v18.20.3
23
23
  $ csdx --help [COMMAND]
24
24
  USAGE
25
25
  $ csdx COMMAND
@@ -267,7 +267,7 @@ EXAMPLES
267
267
  $ csdx plugins
268
268
  ```
269
269
 
270
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/index.ts)_
270
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/index.ts)_
271
271
 
272
272
  ## `csdx plugins:add PLUGIN`
273
273
 
@@ -341,7 +341,7 @@ EXAMPLES
341
341
  $ csdx plugins:inspect myplugin
342
342
  ```
343
343
 
344
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/inspect.ts)_
344
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/inspect.ts)_
345
345
 
346
346
  ## `csdx plugins:install PLUGIN`
347
347
 
@@ -390,7 +390,7 @@ EXAMPLES
390
390
  $ csdx plugins:install someuser/someplugin
391
391
  ```
392
392
 
393
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/install.ts)_
393
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/install.ts)_
394
394
 
395
395
  ## `csdx plugins:link PATH`
396
396
 
@@ -420,7 +420,7 @@ EXAMPLES
420
420
  $ csdx plugins:link myplugin
421
421
  ```
422
422
 
423
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/link.ts)_
423
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/link.ts)_
424
424
 
425
425
  ## `csdx plugins:remove [PLUGIN]`
426
426
 
@@ -461,7 +461,7 @@ FLAGS
461
461
  --reinstall Reinstall all plugins after uninstalling.
462
462
  ```
463
463
 
464
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/reset.ts)_
464
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/reset.ts)_
465
465
 
466
466
  ## `csdx plugins:uninstall [PLUGIN]`
467
467
 
@@ -489,7 +489,7 @@ EXAMPLES
489
489
  $ csdx plugins:uninstall myplugin
490
490
  ```
491
491
 
492
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/uninstall.ts)_
492
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/uninstall.ts)_
493
493
 
494
494
  ## `csdx plugins:unlink [PLUGIN]`
495
495
 
@@ -533,5 +533,5 @@ DESCRIPTION
533
533
  Update installed plugins.
534
534
  ```
535
535
 
536
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.0.21/src/commands/plugins/update.ts)_
536
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.1.2/src/commands/plugins/update.ts)_
537
537
  <!-- commandsstop -->
@@ -317,7 +317,7 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
317
317
  (0, fs_1.mkdirSync)(this.sharedConfig.reportPath, { recursive: true });
318
318
  }
319
319
  // NOTE write int json
320
- (0, fs_1.writeFileSync)((0, path_1.join)(this.sharedConfig.reportPath, `${moduleName}.json`), JSON.stringify(listOfMissingRefs));
320
+ (0, fs_1.writeFileSync)((0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.sharedConfig.reportPath), `${(0, cli_utilities_1.sanitizePath)(moduleName)}.json`), JSON.stringify(listOfMissingRefs));
321
321
  // NOTE write into CSV
322
322
  return this.prepareCSV(moduleName, listOfMissingRefs);
323
323
  }
@@ -332,44 +332,51 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
332
332
  * @returns The function `prepareCSV` returns a Promise that resolves to `void`.
333
333
  */
334
334
  prepareCSV(moduleName, listOfMissingRefs) {
335
- const csvPath = (0, path_1.join)(this.sharedConfig.reportPath, `${moduleName}.csv`);
336
- return new Promise((resolve, reject) => {
337
- // file deepcode ignore MissingClose: Will auto close once csv stream end
338
- const ws = (0, fs_1.createWriteStream)(csvPath).on('error', reject);
339
- const defaultColumns = Object.keys(types_1.OutputColumn);
340
- const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null;
341
- let missingRefs = Object.values(listOfMissingRefs).flat();
342
- const columns = userDefinedColumns
343
- ? [...userDefinedColumns, ...defaultColumns.filter((val) => !userDefinedColumns.includes(val))]
344
- : defaultColumns;
345
- if (this.sharedConfig.flags.filter) {
346
- const [column, value] = this.sharedConfig.flags.filter.split('=');
347
- // Filter the missingRefs array
348
- missingRefs = missingRefs.filter((row) => {
349
- if (types_1.OutputColumn[column] in row) {
350
- const rowKey = types_1.OutputColumn[column];
351
- return row[rowKey] === value;
335
+ if (Object.keys(config_1.default.moduleConfig).includes(moduleName)) {
336
+ const csvPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.sharedConfig.reportPath), `${(0, cli_utilities_1.sanitizePath)(moduleName)}.csv`);
337
+ return new Promise((resolve, reject) => {
338
+ // file deepcode ignore MissingClose: Will auto close once csv stream end
339
+ const ws = (0, fs_1.createWriteStream)(csvPath).on('error', reject);
340
+ const defaultColumns = Object.keys(types_1.OutputColumn);
341
+ const userDefinedColumns = this.sharedConfig.flags.columns ? this.sharedConfig.flags.columns.split(',') : null;
342
+ let missingRefs = Object.values(listOfMissingRefs).flat();
343
+ const columns = userDefinedColumns
344
+ ? [...userDefinedColumns, ...defaultColumns.filter((val) => !userDefinedColumns.includes(val))]
345
+ : defaultColumns;
346
+ if (this.sharedConfig.flags.filter) {
347
+ const [column, value] = this.sharedConfig.flags.filter.split('=');
348
+ // Filter the missingRefs array
349
+ missingRefs = missingRefs.filter((row) => {
350
+ if (types_1.OutputColumn[column] in row) {
351
+ const rowKey = types_1.OutputColumn[column];
352
+ return row[rowKey] === value;
353
+ }
354
+ return false;
355
+ });
356
+ }
357
+ const rowData = [];
358
+ for (const issue of missingRefs) {
359
+ let row = {};
360
+ for (const column of columns) {
361
+ if (Object.keys(issue).includes(types_1.OutputColumn[column])) {
362
+ const issueKey = types_1.OutputColumn[column];
363
+ row[column] = issue[issueKey];
364
+ row[column] = typeof row[column] === 'object' ? JSON.stringify(row[column]) : row[column];
365
+ }
352
366
  }
353
- return false;
354
- });
355
- }
356
- const rowData = [];
357
- for (const issue of missingRefs) {
358
- let row = {};
359
- for (const column of columns) {
360
- if (Object.keys(issue).includes(types_1.OutputColumn[column])) {
361
- const issueKey = types_1.OutputColumn[column];
362
- row[column] = issue[issueKey];
363
- row[column] = typeof row[column] === 'object' ? JSON.stringify(row[column]) : row[column];
367
+ if (this.currentCommand === 'cm:stacks:audit:fix') {
368
+ row['Fix status'] = row.fixStatus;
364
369
  }
370
+ rowData.push(row);
365
371
  }
366
- if (this.currentCommand === 'cm:stacks:audit:fix') {
367
- row['Fix status'] = row.fixStatus;
368
- }
369
- rowData.push(row);
370
- }
371
- csv.write(rowData, { headers: true }).pipe(ws).on('error', reject).on('finish', resolve);
372
- });
372
+ csv.write(rowData, { headers: true }).pipe(ws).on('error', reject).on('finish', resolve);
373
+ });
374
+ }
375
+ else {
376
+ return new Promise((reject) => {
377
+ return reject();
378
+ });
379
+ }
373
380
  }
374
381
  }
375
382
  exports.AuditBaseCommand = AuditBaseCommand;
@@ -69,7 +69,12 @@ function $t(msg, args) {
69
69
  return '';
70
70
  for (const key of Object.keys(args)) {
71
71
  const escapedKey = (0, cli_utilities_1.escapeRegExp)(key);
72
- msg = msg.replace(new RegExp(`{${escapedKey}}`, 'g'), (0, cli_utilities_1.escapeRegExp)(args[key]) || escapedKey);
72
+ const escapedKeyRegex = new RegExp(`{${escapedKey}}`, 'g');
73
+ let { status } = (0, cli_utilities_1.validateRegex)(escapedKeyRegex);
74
+ if (status === 'safe') {
75
+ const sanitizedValue = args[key] ? (0, cli_utilities_1.escapeRegExp)(args[key]) : '';
76
+ msg = msg.replace(escapedKeyRegex, sanitizedValue || escapedKey);
77
+ }
73
78
  }
74
79
  return msg;
75
80
  });
@@ -16,6 +16,7 @@ export default class ContentType {
16
16
  protected missingRefs: Record<string, any>;
17
17
  moduleName: keyof typeof auditConfig.moduleConfig;
18
18
  constructor({ log, fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam);
19
+ validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
19
20
  /**
20
21
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
21
22
  * iterates over the schema and looks for references, and returns a list of missing references.
@@ -21,9 +21,15 @@ class ContentType {
21
21
  this.fix = fix !== null && fix !== void 0 ? fix : false;
22
22
  this.ctSchema = ctSchema;
23
23
  this.gfSchema = gfSchema;
24
- this.moduleName = moduleName !== null && moduleName !== void 0 ? moduleName : 'content-types';
24
+ this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
25
25
  this.fileName = config.moduleConfig[this.moduleName].fileName;
26
- this.folderPath = (0, path_1.resolve)(config.basePath, config.moduleConfig[this.moduleName].dirName);
26
+ this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
27
+ }
28
+ validateModules(moduleName, moduleConfig) {
29
+ if (Object.keys(moduleConfig).includes(moduleName)) {
30
+ return moduleName;
31
+ }
32
+ return 'content-types';
27
33
  }
28
34
  /**
29
35
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
@@ -20,6 +20,7 @@ export default class Entries {
20
20
  moduleName: keyof typeof auditConfig.moduleConfig;
21
21
  isEntryWithoutTitleField: boolean;
22
22
  constructor({ log, fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam);
23
+ validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
23
24
  /**
24
25
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
25
26
  * iterates over the schema and looks for references, and returns a list of missing references.
@@ -26,9 +26,15 @@ class Entries {
26
26
  this.fix = fix !== null && fix !== void 0 ? fix : false;
27
27
  this.ctSchema = ctSchema;
28
28
  this.gfSchema = gfSchema;
29
- this.moduleName = moduleName !== null && moduleName !== void 0 ? moduleName : 'entries';
29
+ this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
30
30
  this.fileName = config.moduleConfig[this.moduleName].fileName;
31
- this.folderPath = (0, path_1.resolve)(config.basePath, config.moduleConfig.entries.dirName);
31
+ this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig.entries.dirName));
32
+ }
33
+ validateModules(moduleName, moduleConfig) {
34
+ if (Object.keys(moduleConfig).includes(moduleName)) {
35
+ return moduleName;
36
+ }
37
+ return 'entries';
32
38
  }
33
39
  /**
34
40
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
@@ -14,6 +14,7 @@ export default class Extensions {
14
14
  missingCts: Set<string>;
15
15
  extensionsPath: string;
16
16
  constructor({ log, fix, config, moduleName, ctSchema, }: ModuleConstructorParam & Pick<CtConstructorParam, 'ctSchema'>);
17
+ validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
17
18
  run(): Promise<{}>;
18
19
  fixExtensionsScope(missingCtInExtensions: Extension[]): Promise<void>;
19
20
  writeFixContent(fixedExtensions: Record<string, Extension>): Promise<void>;
@@ -14,14 +14,20 @@ class Extensions {
14
14
  this.fix = fix !== null && fix !== void 0 ? fix : false;
15
15
  this.ctSchema = ctSchema;
16
16
  this.extensionsSchema = [];
17
- this.moduleName = moduleName !== null && moduleName !== void 0 ? moduleName : 'extensions';
17
+ this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
18
18
  this.fileName = config.moduleConfig[this.moduleName].fileName;
19
- this.folderPath = (0, path_1.resolve)(config.basePath, config.moduleConfig[this.moduleName].dirName);
19
+ this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
20
20
  this.ctUidSet = new Set(['$all']);
21
21
  this.missingCtInExtensions = [];
22
22
  this.missingCts = new Set();
23
23
  this.extensionsPath = '';
24
24
  }
25
+ validateModules(moduleName, moduleConfig) {
26
+ if (Object.keys(moduleConfig).includes(moduleName)) {
27
+ return moduleName;
28
+ }
29
+ return 'extensions';
30
+ }
25
31
  async run() {
26
32
  if (!(0, fs_1.existsSync)(this.folderPath)) {
27
33
  this.log(`Skipping ${this.moduleName} audit`, 'warn');
@@ -15,6 +15,7 @@ export default class Workflows {
15
15
  workflowPath: string;
16
16
  isBranchFixDone: boolean;
17
17
  constructor({ log, fix, config, moduleName, ctSchema, }: ModuleConstructorParam & Pick<CtConstructorParam, 'ctSchema'>);
18
+ validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
18
19
  /**
19
20
  * Check whether the given path for the workflow exists or not
20
21
  * If path exist read
@@ -13,15 +13,21 @@ class Workflows {
13
13
  this.fix = fix !== null && fix !== void 0 ? fix : false;
14
14
  this.ctSchema = ctSchema;
15
15
  this.workflowSchema = [];
16
- this.moduleName = moduleName !== null && moduleName !== void 0 ? moduleName : 'workflows';
16
+ this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
17
17
  this.fileName = config.moduleConfig[this.moduleName].fileName;
18
- this.folderPath = (0, path_1.resolve)(config.basePath, config.moduleConfig[this.moduleName].dirName);
18
+ this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
19
19
  this.ctUidSet = new Set(['$all']);
20
20
  this.missingCtInWorkflows = [];
21
21
  this.missingCts = new Set();
22
22
  this.workflowPath = '';
23
23
  this.isBranchFixDone = false;
24
24
  }
25
+ validateModules(moduleName, moduleConfig) {
26
+ if (Object.keys(moduleConfig).includes(moduleName)) {
27
+ return moduleName;
28
+ }
29
+ return 'workflows';
30
+ }
25
31
  /**
26
32
  * Check whether the given path for the workflow exists or not
27
33
  * If path exist read
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.1",
2
+ "version": "1.6.2",
3
3
  "commands": {
4
4
  "cm:stacks:audit:fix": {
5
5
  "id": "cm:stacks:audit:fix",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-audit",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "Contentstack audit plugin",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/cli",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@contentstack/cli-command": "~1.2.18",
22
- "@contentstack/cli-utilities": "~1.6.1",
22
+ "@contentstack/cli-utilities": "~1.6.2",
23
23
  "@oclif/plugin-help": "^5",
24
24
  "@oclif/plugin-plugins": "^5.0.0",
25
25
  "chalk": "^4.1.2",