@contentstack/cli-audit 1.17.1 → 1.19.0-beta.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.17.1 linux-x64 node-v22.22.0
22
+ @contentstack/cli-audit/1.19.0-beta.0 linux-x64 node-v22.22.0
23
23
  $ csdx --help [COMMAND]
24
24
  USAGE
25
25
  $ csdx COMMAND
@@ -309,7 +309,7 @@ EXAMPLES
309
309
  $ csdx plugins
310
310
  ```
311
311
 
312
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/index.ts)_
312
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/index.ts)_
313
313
 
314
314
  ## `csdx plugins:add PLUGIN`
315
315
 
@@ -383,7 +383,7 @@ EXAMPLES
383
383
  $ csdx plugins:inspect myplugin
384
384
  ```
385
385
 
386
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/inspect.ts)_
386
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/inspect.ts)_
387
387
 
388
388
  ## `csdx plugins:install PLUGIN`
389
389
 
@@ -432,7 +432,7 @@ EXAMPLES
432
432
  $ csdx plugins:install someuser/someplugin
433
433
  ```
434
434
 
435
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/install.ts)_
435
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/install.ts)_
436
436
 
437
437
  ## `csdx plugins:link PATH`
438
438
 
@@ -463,7 +463,7 @@ EXAMPLES
463
463
  $ csdx plugins:link myplugin
464
464
  ```
465
465
 
466
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/link.ts)_
466
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/link.ts)_
467
467
 
468
468
  ## `csdx plugins:remove [PLUGIN]`
469
469
 
@@ -504,7 +504,7 @@ FLAGS
504
504
  --reinstall Reinstall all plugins after uninstalling.
505
505
  ```
506
506
 
507
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/reset.ts)_
507
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/reset.ts)_
508
508
 
509
509
  ## `csdx plugins:uninstall [PLUGIN]`
510
510
 
@@ -532,7 +532,7 @@ EXAMPLES
532
532
  $ csdx plugins:uninstall myplugin
533
533
  ```
534
534
 
535
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/uninstall.ts)_
535
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/uninstall.ts)_
536
536
 
537
537
  ## `csdx plugins:unlink [PLUGIN]`
538
538
 
@@ -576,5 +576,5 @@ DESCRIPTION
576
576
  Update installed plugins.
577
577
  ```
578
578
 
579
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.55/src/commands/plugins/update.ts)_
579
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.56/src/commands/plugins/update.ts)_
580
580
  <!-- commandsstop -->
@@ -23,6 +23,21 @@ export default class Entries {
23
23
  moduleName: keyof typeof auditConfig.moduleConfig;
24
24
  constructor({ fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam);
25
25
  validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig;
26
+ /**
27
+ * Returns whether a referenced entry's content type is allowed by the schema's reference_to.
28
+ * @param refCtUid - Content type UID of the referenced entry (e.g. from _content_type_uid)
29
+ * @param referenceTo - Schema's reference_to (string or string[])
30
+ * @param configOverride - Optional config with skipRefs; falls back to this.config
31
+ * @returns true if allowed or check cannot be performed; false if refCtUid is not in reference_to
32
+ */
33
+ protected isRefContentTypeAllowed(refCtUid: string | undefined, referenceTo: string | string[] | undefined, configOverride?: {
34
+ skipRefs?: string[];
35
+ }): boolean;
36
+ /**
37
+ * If ref CT is not allowed, pushes to missingRefs.
38
+ * @returns true if invalid (pushed), false if valid
39
+ */
40
+ private addInvalidRefIfNeeded;
26
41
  /**
27
42
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
28
43
  * iterates over the schema and looks for references, and returns a list of missing references.
@@ -46,6 +46,39 @@ class Entries {
46
46
  cli_utilities_1.log.debug(`Module ${moduleName} not found in config, defaulting to: entries`, this.config.auditContext);
47
47
  return 'entries';
48
48
  }
49
+ /**
50
+ * Returns whether a referenced entry's content type is allowed by the schema's reference_to.
51
+ * @param refCtUid - Content type UID of the referenced entry (e.g. from _content_type_uid)
52
+ * @param referenceTo - Schema's reference_to (string or string[])
53
+ * @param configOverride - Optional config with skipRefs; falls back to this.config
54
+ * @returns true if allowed or check cannot be performed; false if refCtUid is not in reference_to
55
+ */
56
+ isRefContentTypeAllowed(refCtUid, referenceTo, configOverride) {
57
+ var _a, _b;
58
+ if (refCtUid === undefined)
59
+ return true;
60
+ const skipRefs = (_b = (_a = configOverride === null || configOverride === void 0 ? void 0 : configOverride.skipRefs) !== null && _a !== void 0 ? _a : this.config.skipRefs) !== null && _b !== void 0 ? _b : [];
61
+ if (Array.isArray(skipRefs) && skipRefs.includes(refCtUid))
62
+ return true;
63
+ if (referenceTo === undefined || referenceTo === null)
64
+ return true;
65
+ const refToList = Array.isArray(referenceTo) ? referenceTo : [referenceTo];
66
+ if (refToList.length === 0)
67
+ return false;
68
+ return refToList.includes(refCtUid);
69
+ }
70
+ /**
71
+ * If ref CT is not allowed, pushes to missingRefs.
72
+ * @returns true if invalid (pushed), false if valid
73
+ */
74
+ addInvalidRefIfNeeded(missingRefs, uidValue, refCtUid, referenceTo, fullRef, logLabel) {
75
+ if (this.isRefContentTypeAllowed(refCtUid, referenceTo))
76
+ return false;
77
+ cli_utilities_1.log.debug(`${logLabel} has wrong content type: ${refCtUid} not in reference_to`);
78
+ const refList = Array.isArray(referenceTo) ? referenceTo : referenceTo != null ? [referenceTo] : [];
79
+ missingRefs.push(refList.length === 1 ? { uid: uidValue, _content_type_uid: refCtUid } : fullRef);
80
+ return true;
81
+ }
49
82
  /**
50
83
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
51
84
  * iterates over the schema and looks for references, and returns a list of missing references.
@@ -674,6 +707,7 @@ class Entries {
674
707
  * objects.
675
708
  */
676
709
  validateReferenceValues(tree, fieldStructure, field) {
710
+ var _a;
677
711
  cli_utilities_1.log.debug(`Validating reference values for field: ${fieldStructure.display_name}`);
678
712
  if (this.fix) {
679
713
  cli_utilities_1.log.debug('Fix mode enabled, skipping reference validation');
@@ -681,8 +715,9 @@ class Entries {
681
715
  }
682
716
  const missingRefs = [];
683
717
  const { uid: data_type, display_name, reference_to } = fieldStructure;
718
+ const refToList = Array.isArray(reference_to) ? reference_to : reference_to != null ? [reference_to] : [];
684
719
  cli_utilities_1.log.debug(`Reference field UID: ${data_type}`);
685
- cli_utilities_1.log.debug(`Reference to: ${(reference_to === null || reference_to === void 0 ? void 0 : reference_to.join(', ')) || 'none'}`);
720
+ cli_utilities_1.log.debug(`Reference to: ${refToList.join(', ') || 'none'}`);
686
721
  cli_utilities_1.log.debug(`Found ${(field === null || field === void 0 ? void 0 : field.length) || 0} references to validate`);
687
722
  for (const index in field !== null && field !== void 0 ? field : []) {
688
723
  const reference = field[index];
@@ -701,7 +736,10 @@ class Entries {
701
736
  }
702
737
  }
703
738
  else {
704
- cli_utilities_1.log.debug(`Reference ${reference} is valid`);
739
+ const refCtUid = refExist.ctUid;
740
+ if (!this.addInvalidRefIfNeeded(missingRefs, reference, refCtUid, reference_to, reference, `Reference ${reference}`)) {
741
+ cli_utilities_1.log.debug(`Reference ${reference} is valid`);
742
+ }
705
743
  }
706
744
  }
707
745
  // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
@@ -714,7 +752,10 @@ class Entries {
714
752
  missingRefs.push(reference);
715
753
  }
716
754
  else {
717
- cli_utilities_1.log.debug(`Reference ${uid} is valid`);
755
+ const refCtUid = (_a = reference._content_type_uid) !== null && _a !== void 0 ? _a : refExist.ctUid;
756
+ if (!this.addInvalidRefIfNeeded(missingRefs, uid, refCtUid, reference_to, reference, `Reference ${uid}`)) {
757
+ cli_utilities_1.log.debug(`Reference ${uid} is valid`);
758
+ }
718
759
  }
719
760
  }
720
761
  }
@@ -1362,6 +1403,7 @@ class Entries {
1362
1403
  cli_utilities_1.log.debug(`Parsed entry: ${Array.isArray(entry) ? entry.length : 'N/A'} references`);
1363
1404
  }
1364
1405
  entry = entry === null || entry === void 0 ? void 0 : entry.map((reference, index) => {
1406
+ var _a, _b;
1365
1407
  const { uid } = reference;
1366
1408
  const { reference_to } = field;
1367
1409
  cli_utilities_1.log.debug(`Processing reference ${index}: ${uid || reference}`);
@@ -1378,6 +1420,10 @@ class Entries {
1378
1420
  }
1379
1421
  }
1380
1422
  else {
1423
+ const refCtUid = (_a = reference._content_type_uid) !== null && _a !== void 0 ? _a : refExist.ctUid;
1424
+ if (this.addInvalidRefIfNeeded(missingRefs, reference, refCtUid, reference_to, reference, `Blt reference ${reference}`)) {
1425
+ return null;
1426
+ }
1381
1427
  cli_utilities_1.log.debug(`Blt reference ${reference} is valid`);
1382
1428
  return { uid: reference, _content_type_uid: refExist.ctUid };
1383
1429
  }
@@ -1391,6 +1437,10 @@ class Entries {
1391
1437
  return null;
1392
1438
  }
1393
1439
  else {
1440
+ const refCtUid = (_b = reference._content_type_uid) !== null && _b !== void 0 ? _b : refExist.ctUid;
1441
+ if (this.addInvalidRefIfNeeded(missingRefs, uid, refCtUid, reference_to, reference, `Reference ${uid}`)) {
1442
+ return null;
1443
+ }
1394
1444
  cli_utilities_1.log.debug(`Reference ${uid} is valid`);
1395
1445
  return reference;
1396
1446
  }
@@ -1506,6 +1556,25 @@ class Entries {
1506
1556
  return null;
1507
1557
  }
1508
1558
  else {
1559
+ const refCtUid = contentTypeUid !== null && contentTypeUid !== void 0 ? contentTypeUid : refExist.ctUid;
1560
+ const referenceTo = schema.reference_to;
1561
+ if (!this.isRefContentTypeAllowed(refCtUid, referenceTo)) {
1562
+ cli_utilities_1.log.debug(`JSON RTE embed ${entryUid} has wrong content type: ${refCtUid} not in reference_to`);
1563
+ this.missingRefs[this.currentUid].push({
1564
+ tree,
1565
+ uid: this.currentUid,
1566
+ name: this.currentTitle,
1567
+ data_type: schema.data_type,
1568
+ display_name: schema.display_name,
1569
+ fixStatus: this.fix ? 'Fixed' : undefined,
1570
+ treeStr: tree
1571
+ .map(({ name }) => name)
1572
+ .filter((val) => val)
1573
+ .join(' ➜ '),
1574
+ missingRefs: [{ uid: entryUid, 'content-type-uid': refCtUid }],
1575
+ });
1576
+ return this.fix ? null : true;
1577
+ }
1509
1578
  cli_utilities_1.log.debug(`Entry reference ${entryUid} is valid`);
1510
1579
  }
1511
1580
  }
@@ -346,5 +346,5 @@
346
346
  ]
347
347
  }
348
348
  },
349
- "version": "1.17.1"
349
+ "version": "1.19.0-beta.0"
350
350
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-audit",
3
- "version": "1.17.1",
3
+ "version": "1.19.0-beta.0",
4
4
  "description": "Contentstack audit plugin",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/cli",
@@ -18,15 +18,15 @@
18
18
  "/oclif.manifest.json"
19
19
  ],
20
20
  "dependencies": {
21
- "@contentstack/cli-command": "~1.7.2",
22
- "@contentstack/cli-utilities": "~1.17.0",
21
+ "@contentstack/cli-command": "~1.8.0-beta.0",
22
+ "@contentstack/cli-utilities": "~1.18.0-beta.0",
23
23
  "@oclif/core": "^4.3.0",
24
24
  "@oclif/plugin-help": "^6.2.28",
25
25
  "@oclif/plugin-plugins": "^5.4.54",
26
26
  "chalk": "^4.1.2",
27
27
  "fast-csv": "^4.3.6",
28
28
  "fs-extra": "^11.3.0",
29
- "lodash": "^4.17.21",
29
+ "lodash": "^4.17.23",
30
30
  "uuid": "^9.0.1",
31
31
  "winston": "^3.17.0"
32
32
  },
@@ -66,15 +66,15 @@
66
66
  "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-audit/<%- commandPath %>"
67
67
  },
68
68
  "scripts": {
69
- "build": "npm run clean && shx rm -rf lib && tsc -b",
69
+ "build": "pnpm compile && oclif manifest && oclif readme",
70
70
  "lint": "eslint . --ext .ts --config .eslintrc",
71
71
  "postpack": "shx rm -f oclif.manifest.json",
72
72
  "posttest": "npm run lint",
73
- "compile": "shx rm -rf lib tsconfig.tsbuildinfo && tsc -b",
73
+ "compile": "tsc -b tsconfig.json",
74
74
  "prepack": "pnpm compile && oclif manifest && oclif readme",
75
75
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
76
76
  "version": "oclif readme && git add README.md",
77
- "clean": "rm -rf ./lib ./node_modules .tsbuildinfo oclif.manifest.json",
77
+ "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo",
78
78
  "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
79
79
  "test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\""
80
80
  },