@contentstack/cli-audit 1.12.0 → 1.13.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.
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.12.0 linux-x64 node-v22.14.0
22
+ @contentstack/cli-audit/1.13.0 linux-x64 node-v22.15.0
23
23
  $ csdx --help [COMMAND]
24
24
  USAGE
25
25
  $ csdx COMMAND
@@ -282,7 +282,7 @@ DESCRIPTION
282
282
  Display help for csdx.
283
283
  ```
284
284
 
285
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.27/src/commands/help.ts)_
285
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v6.2.28/src/commands/help.ts)_
286
286
 
287
287
  ## `csdx plugins`
288
288
 
@@ -305,7 +305,7 @@ EXAMPLES
305
305
  $ csdx plugins
306
306
  ```
307
307
 
308
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
308
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/index.ts)_
309
309
 
310
310
  ## `csdx plugins:add PLUGIN`
311
311
 
@@ -379,7 +379,7 @@ EXAMPLES
379
379
  $ csdx plugins:inspect myplugin
380
380
  ```
381
381
 
382
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
382
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/inspect.ts)_
383
383
 
384
384
  ## `csdx plugins:install PLUGIN`
385
385
 
@@ -428,7 +428,7 @@ EXAMPLES
428
428
  $ csdx plugins:install someuser/someplugin
429
429
  ```
430
430
 
431
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
431
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/install.ts)_
432
432
 
433
433
  ## `csdx plugins:link PATH`
434
434
 
@@ -459,7 +459,7 @@ EXAMPLES
459
459
  $ csdx plugins:link myplugin
460
460
  ```
461
461
 
462
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
462
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/link.ts)_
463
463
 
464
464
  ## `csdx plugins:remove [PLUGIN]`
465
465
 
@@ -500,7 +500,7 @@ FLAGS
500
500
  --reinstall Reinstall all plugins after uninstalling.
501
501
  ```
502
502
 
503
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
503
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/reset.ts)_
504
504
 
505
505
  ## `csdx plugins:uninstall [PLUGIN]`
506
506
 
@@ -528,7 +528,7 @@ EXAMPLES
528
528
  $ csdx plugins:uninstall myplugin
529
529
  ```
530
530
 
531
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
531
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/uninstall.ts)_
532
532
 
533
533
  ## `csdx plugins:unlink [PLUGIN]`
534
534
 
@@ -572,5 +572,5 @@ DESCRIPTION
572
572
  Update installed plugins.
573
573
  ```
574
574
 
575
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
575
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.39/src/commands/plugins/update.ts)_
576
576
  <!-- commandsstop -->
@@ -194,6 +194,10 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
194
194
  this.getAffectedData('custom-roles', dataModuleWise['custom-roles'], missingRefInCustomRoles);
195
195
  break;
196
196
  case 'field-rules':
197
+ // NOTE: We are using the fixed content-type for validation of field rules
198
+ const data = this.getCtAndGfSchema();
199
+ constructorParam.ctSchema = data.ctSchema;
200
+ constructorParam.gfSchema = data.gfSchema;
197
201
  missingFieldRules = await new modules_1.FieldRule((0, cloneDeep_1.default)(constructorParam)).run();
198
202
  await this.prepareReport(module, missingFieldRules);
199
203
  this.getAffectedData('field-rules', dataModuleWise['content-types'], missingFieldRules);
@@ -4,6 +4,7 @@ declare const config: {
4
4
  skipFieldTypes: string[];
5
5
  modules: string[];
6
6
  'fix-fields': string[];
7
+ 'schema-fields-data-type': string[];
7
8
  moduleConfig: {
8
9
  'content-types': {
9
10
  name: string;
@@ -15,6 +15,7 @@ const config = {
15
15
  'field-rules',
16
16
  ],
17
17
  'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group', 'content_types'],
18
+ 'schema-fields-data-type': ['blocks', 'group', 'global_field'],
18
19
  moduleConfig: {
19
20
  'content-types': {
20
21
  name: 'content type',
@@ -214,17 +214,35 @@ class ContentType {
214
214
  */
215
215
  async validateGlobalField(tree, field) {
216
216
  // NOTE Any GlobalField related logic can be added here
217
- if (!field.schema && !this.fix) {
218
- this.missingRefs[this.currentUid].push({
219
- tree,
220
- ct_uid: this.currentUid,
221
- name: this.currentTitle,
222
- data_type: field.data_type,
223
- display_name: field.display_name,
224
- missingRefs: 'Empty schema found',
225
- treeStr: tree.map(({ name }) => name).join(' ➜ '),
226
- });
227
- return void 0;
217
+ if (this.moduleName === 'global-fields') {
218
+ let { reference_to } = field;
219
+ const refExist = (0, find_1.default)(this.schema, { uid: reference_to });
220
+ if (!refExist) {
221
+ this.missingRefs[this.currentUid].push({
222
+ tree,
223
+ ct: this.currentUid,
224
+ name: this.currentTitle,
225
+ data_type: field.data_type,
226
+ display_name: field.display_name,
227
+ missingRefs: 'Referred Global Field Does not Exist',
228
+ treeStr: tree.map(({ name }) => name).join(' ➜ '),
229
+ });
230
+ return void 0;
231
+ }
232
+ }
233
+ else if (this.moduleName === 'content-types') {
234
+ if (!field.schema && !this.fix) {
235
+ this.missingRefs[this.currentUid].push({
236
+ tree,
237
+ ct_uid: this.currentUid,
238
+ name: this.currentTitle,
239
+ data_type: field.data_type,
240
+ display_name: field.display_name,
241
+ missingRefs: 'Empty schema found',
242
+ treeStr: tree.map(({ name }) => name).join(' ➜ '),
243
+ });
244
+ return void 0;
245
+ }
228
246
  }
229
247
  await this.lookForReference(tree, field);
230
248
  }
@@ -339,8 +357,7 @@ class ContentType {
339
357
  */
340
358
  runFixOnSchema(tree, schema) {
341
359
  // NOTE Global field Fix
342
- return schema
343
- .map((field) => {
360
+ return schema === null || schema === void 0 ? void 0 : schema.map((field) => {
344
361
  var _a;
345
362
  const { data_type } = field;
346
363
  const fixTypes = (_a = this.config.flags['fix-only']) !== null && _a !== void 0 ? _a : this.config['fix-fields'];
@@ -377,13 +394,14 @@ class ContentType {
377
394
  default:
378
395
  return field;
379
396
  }
380
- })
381
- .filter((val) => {
397
+ }).filter((val) => {
382
398
  if (this.config.skipFieldTypes.includes(val === null || val === void 0 ? void 0 : val.data_type))
383
399
  return true;
384
- if ((val === null || val === void 0 ? void 0 : val.schema) && (0, isEmpty_1.default)(val === null || val === void 0 ? void 0 : val.schema))
400
+ if ((val === null || val === void 0 ? void 0 : val.schema) &&
401
+ (0, isEmpty_1.default)(val === null || val === void 0 ? void 0 : val.schema) &&
402
+ (!(val === null || val === void 0 ? void 0 : val.data_type) || this.config['schema-fields-data-type'].includes(val.data_type)))
385
403
  return false;
386
- if ((val === null || val === void 0 ? void 0 : val.reference_to) && (0, isEmpty_1.default)(val === null || val === void 0 ? void 0 : val.reference_to))
404
+ if ((val === null || val === void 0 ? void 0 : val.reference_to) && (0, isEmpty_1.default)(val === null || val === void 0 ? void 0 : val.reference_to) && val.data_type === 'reference')
387
405
  return false;
388
406
  return !!val;
389
407
  });
@@ -398,7 +416,7 @@ class ContentType {
398
416
  * doesn't.
399
417
  */
400
418
  fixGlobalFieldReferences(tree, field) {
401
- var _a;
419
+ var _a, _b;
402
420
  const { reference_to, display_name, data_type } = field;
403
421
  if (reference_to && data_type === 'global_field') {
404
422
  tree = [...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }];
@@ -415,10 +433,12 @@ class ContentType {
415
433
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
416
434
  });
417
435
  }
418
- else if (!field.schema) {
436
+ else if (!field.schema && this.moduleName === 'content-types') {
419
437
  const gfSchema = (_a = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _a === void 0 ? void 0 : _a.schema;
420
438
  if (gfSchema) {
421
439
  field.schema = gfSchema;
440
+ }
441
+ else {
422
442
  this.missingRefs[this.currentUid].push({
423
443
  tree,
424
444
  data_type,
@@ -431,6 +451,27 @@ class ContentType {
431
451
  });
432
452
  }
433
453
  }
454
+ else if (!field.schema && this.moduleName === 'global-fields') {
455
+ const gfSchema = (_b = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _b === void 0 ? void 0 : _b.schema;
456
+ if (gfSchema) {
457
+ field.schema = gfSchema;
458
+ }
459
+ else {
460
+ this.missingRefs[this.currentUid].push({
461
+ tree,
462
+ data_type,
463
+ display_name,
464
+ fixStatus: 'Fixed',
465
+ ct_uid: this.currentUid,
466
+ name: this.currentTitle,
467
+ missingRefs: 'Referred Global Field Does not exist',
468
+ treeStr: tree.map(({ name }) => name).join(' ➜ '),
469
+ });
470
+ }
471
+ }
472
+ if (field.schema && !(0, isEmpty_1.default)(field.schema)) {
473
+ field.schema = this.runFixOnSchema(tree, field.schema);
474
+ }
434
475
  return refExist ? field : null;
435
476
  }
436
477
  return field;
@@ -444,8 +485,7 @@ class ContentType {
444
485
  * @returns an array of `ModularBlockType` objects.
445
486
  */
446
487
  fixModularBlocksReferences(tree, blocks) {
447
- return blocks
448
- .map((block) => {
488
+ return blocks === null || blocks === void 0 ? void 0 : blocks.map((block) => {
449
489
  const { reference_to, schema, title: display_name } = block;
450
490
  tree = [...tree, { uid: block.uid, name: block.title }];
451
491
  const refErrorObj = {
@@ -457,27 +497,30 @@ class ContentType {
457
497
  fixStatus: this.fix ? 'Fixed' : undefined,
458
498
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
459
499
  };
460
- if (!schema) {
500
+ if (!schema && this.moduleName === 'content-types') {
461
501
  this.missingRefs[this.currentUid].push(refErrorObj);
462
502
  return false;
463
503
  }
464
504
  // NOTE Global field section
465
505
  if (reference_to) {
466
506
  const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
507
+ if (!refExist) {
508
+ this.missingRefs[this.currentUid].push(refErrorObj);
509
+ return false;
510
+ }
467
511
  if (!refExist) {
468
512
  this.missingRefs[this.currentUid].push(refErrorObj);
469
513
  return block;
470
514
  }
471
515
  }
472
516
  block.schema = this.runFixOnSchema(tree, block.schema);
473
- if ((0, isEmpty_1.default)(block.schema)) {
517
+ if ((0, isEmpty_1.default)(block.schema) && this.moduleName === 'content-types') {
474
518
  this.missingRefs[this.currentUid].push(Object.assign(Object.assign({}, refErrorObj), { missingRefs: 'Empty schema found', treeStr: tree.map(({ name }) => name).join(' ➜ ') }));
475
519
  this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
476
520
  return null;
477
521
  }
478
522
  return block;
479
- })
480
- .filter((val) => val);
523
+ }).filter((val) => val);
481
524
  }
482
525
  /**
483
526
  * The function checks for missing extension or app references in a given tree and fixes them if the
@@ -67,7 +67,9 @@ class Entries {
67
67
  const { uid, title } = entry;
68
68
  this.currentUid = uid;
69
69
  this.currentTitle = title;
70
- this.currentTitle = this.removeEmojiAndImages(this.currentTitle);
70
+ if (this.currentTitle) {
71
+ this.currentTitle = this.removeEmojiAndImages(this.currentTitle);
72
+ }
71
73
  if (!this.missingRefs[this.currentUid]) {
72
74
  this.missingRefs[this.currentUid] = [];
73
75
  }
@@ -80,7 +82,7 @@ class Entries {
80
82
  if (this.fix) {
81
83
  this.removeMissingKeysOnEntry(ctSchema.schema, this.entries[entryUid]);
82
84
  }
83
- this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(title) }], ctSchema, this.entries[entryUid]);
85
+ this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(this.currentTitle) }], ctSchema, this.entries[entryUid]);
84
86
  if ((_a = this.missingRefs[this.currentUid]) === null || _a === void 0 ? void 0 : _a.length) {
85
87
  this.missingRefs[this.currentUid].forEach((entry) => {
86
88
  entry.ct = ctSchema.uid;
@@ -179,7 +181,7 @@ class Entries {
179
181
  missingMandatoryFields: this.missingMandatoryFields,
180
182
  missingTitleFields: this.missingTitleFields,
181
183
  missingEnvLocale: this.missingEnvLocale,
182
- missingMultipleFields: this.missingMultipleField
184
+ missingMultipleFields: this.missingMultipleField,
183
185
  };
184
186
  }
185
187
  /**
@@ -590,7 +592,7 @@ class Entries {
590
592
  .map(({ name }) => name)
591
593
  .filter(Boolean)
592
594
  .join(' ➜ '),
593
- 'fixStatus': 'Fixed',
595
+ fixStatus: 'Fixed',
594
596
  });
595
597
  entry[uid] = [entry[uid]];
596
598
  }
@@ -643,7 +645,7 @@ class Entries {
643
645
  * Else empty array
644
646
  */
645
647
  removeEmojiAndImages(str) {
646
- return str.replace(/[\p{Emoji}\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Emoji_Modifier_Base}\p{Emoji_Component}]+/gu, '');
648
+ return str === null || str === void 0 ? void 0 : str.replace(/[\p{Emoji}\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Emoji_Modifier_Base}\p{Emoji_Component}]+/gu, '');
647
649
  }
648
650
  validateSelectField(tree, fieldStructure, field) {
649
651
  const { display_name, enum: selectOptions, multiple, min_instance, display_type, data_type } = fieldStructure;
@@ -344,5 +344,5 @@
344
344
  ]
345
345
  }
346
346
  },
347
- "version": "1.12.0"
347
+ "version": "1.13.0"
348
348
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-audit",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Contentstack audit plugin",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/cli",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@contentstack/cli-command": "~1.5.0",
22
- "@oclif/plugin-help": "^6.2.27",
23
- "@contentstack/cli-utilities": "~1.11.0",
22
+ "@oclif/plugin-help": "^6.2.28",
23
+ "@contentstack/cli-utilities": "~1.12.0",
24
24
  "@oclif/plugin-plugins": "^5.4.36",
25
25
  "chalk": "^4.1.2",
26
26
  "fast-csv": "^4.3.6",
@@ -30,19 +30,19 @@
30
30
  "winston": "^3.17.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@oclif/test": "^4.1.12",
33
+ "@oclif/test": "^4.1.13",
34
34
  "@types/chai": "^4.3.20",
35
35
  "@types/fs-extra": "^11.0.4",
36
36
  "@types/mocha": "^10.0.10",
37
- "@types/node": "^20.17.30",
37
+ "@types/node": "^20.17.50",
38
38
  "@types/uuid": "^9.0.8",
39
39
  "chai": "^4.5.0",
40
40
  "eslint": "^8.57.1",
41
- "eslint-config-oclif": "^6.0.42",
41
+ "eslint-config-oclif": "^6.0.62",
42
42
  "eslint-config-oclif-typescript": "^3.1.14",
43
43
  "mocha": "^10.8.2",
44
44
  "nyc": "^15.1.0",
45
- "oclif": "^4.17.43",
45
+ "oclif": "^4.17.46",
46
46
  "shx": "^0.4.0",
47
47
  "sinon": "^19.0.5",
48
48
  "ts-node": "^10.9.2",