@contentstack/cli-audit 1.17.0 → 2.0.0-beta.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 (42) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +10 -431
  3. package/lib/audit-base-command.d.ts +4 -1
  4. package/lib/audit-base-command.js +85 -54
  5. package/lib/commands/cm/stacks/audit/fix.d.ts +0 -1
  6. package/lib/commands/cm/stacks/audit/fix.js +0 -1
  7. package/lib/commands/cm/stacks/audit/index.d.ts +0 -1
  8. package/lib/commands/cm/stacks/audit/index.js +0 -1
  9. package/lib/config/index.d.ts +0 -5
  10. package/lib/config/index.js +9 -16
  11. package/lib/messages/index.d.ts +0 -1
  12. package/lib/messages/index.js +1 -2
  13. package/lib/modules/assets.d.ts +6 -4
  14. package/lib/modules/assets.js +51 -30
  15. package/lib/modules/base-class.d.ts +24 -0
  16. package/lib/modules/base-class.js +54 -0
  17. package/lib/modules/content-types.d.ts +6 -4
  18. package/lib/modules/content-types.js +62 -40
  19. package/lib/modules/custom-roles.d.ts +4 -4
  20. package/lib/modules/custom-roles.js +82 -61
  21. package/lib/modules/entries.d.ts +5 -4
  22. package/lib/modules/entries.js +190 -168
  23. package/lib/modules/extensions.d.ts +4 -4
  24. package/lib/modules/extensions.js +78 -58
  25. package/lib/modules/field_rules.d.ts +4 -4
  26. package/lib/modules/field_rules.js +69 -52
  27. package/lib/modules/global-fields.d.ts +3 -1
  28. package/lib/modules/global-fields.js +4 -2
  29. package/lib/modules/index.d.ts +2 -2
  30. package/lib/modules/index.js +3 -3
  31. package/lib/modules/modulesData.js +8 -17
  32. package/lib/modules/workflows.d.ts +4 -4
  33. package/lib/modules/workflows.js +85 -68
  34. package/lib/types/content-types.d.ts +1 -2
  35. package/lib/types/content-types.js +0 -1
  36. package/lib/types/context.d.ts +5 -0
  37. package/oclif.manifest.json +5 -13
  38. package/package.json +4 -6
  39. package/lib/modules/composable-studio.d.ts +0 -40
  40. package/lib/modules/composable-studio.js +0 -307
  41. package/lib/types/composable-studio.d.ts +0 -25
  42. package/lib/types/composable-studio.js +0 -2
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
4
+ class BaseClass {
5
+ constructor({ config }) {
6
+ this.progressManager = null;
7
+ this.currentModuleName = '';
8
+ this.config = config;
9
+ }
10
+ /**
11
+ * Create simple progress manager
12
+ */
13
+ createSimpleProgress(moduleName, total) {
14
+ var _a;
15
+ this.currentModuleName = moduleName;
16
+ const logConfig = cli_utilities_1.configHandler.get('log') || {};
17
+ const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
18
+ this.progressManager = cli_utilities_1.CLIProgressManager.createSimple(moduleName, total, showConsoleLogs);
19
+ return this.progressManager;
20
+ }
21
+ /**
22
+ * Create nested progress manager
23
+ */
24
+ createNestedProgress(moduleName) {
25
+ var _a;
26
+ this.currentModuleName = moduleName;
27
+ const logConfig = cli_utilities_1.configHandler.get('log') || {};
28
+ const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
29
+ this.progressManager = cli_utilities_1.CLIProgressManager.createNested(moduleName, showConsoleLogs);
30
+ return this.progressManager;
31
+ }
32
+ /**
33
+ * Complete progress manager
34
+ */
35
+ completeProgress(success = true, error) {
36
+ var _a;
37
+ (_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.complete(success, error);
38
+ this.progressManager = null;
39
+ }
40
+ /**
41
+ * Execute action with loading spinner (if console logs are disabled)
42
+ */
43
+ async withLoadingSpinner(message, action) {
44
+ var _a;
45
+ const logConfig = cli_utilities_1.configHandler.get('log') || {};
46
+ const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
47
+ if (showConsoleLogs) {
48
+ // If console logs are enabled, don't show spinner, just execute the action
49
+ return await action();
50
+ }
51
+ return await cli_utilities_1.CLIProgressManager.withLoadingSpinner(message, action);
52
+ }
53
+ }
54
+ exports.default = BaseClass;
@@ -1,9 +1,9 @@
1
- import { ConfigType, ModularBlockType, ContentTypeStruct, GroupFieldDataType, RefErrorReturnType, CtConstructorParam, GlobalFieldDataType, JsonRTEFieldDataType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, ContentTypeSchemaType, ExtensionOrAppFieldDataType } from '../types';
1
+ import { ModularBlockType, ContentTypeStruct, GroupFieldDataType, RefErrorReturnType, CtConstructorParam, GlobalFieldDataType, JsonRTEFieldDataType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, ContentTypeSchemaType, ExtensionOrAppFieldDataType } from '../types';
2
2
  import auditConfig from '../config';
3
- export default class ContentType {
3
+ import BaseClass from './base-class';
4
+ export default class ContentType extends BaseClass {
4
5
  protected fix: boolean;
5
6
  fileName: string;
6
- config: ConfigType;
7
7
  folderPath: string;
8
8
  currentUid: string;
9
9
  currentTitle: string;
@@ -19,9 +19,11 @@ export default class ContentType {
19
19
  /**
20
20
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
21
21
  * iterates over the schema and looks for references, and returns a list of missing references.
22
+ * @param returnFixSchema - If true, returns the fixed schema instead of missing references
23
+ * @param totalCount - Total number of items to process (for progress tracking)
22
24
  * @returns the `missingRefs` object.
23
25
  */
24
- run(returnFixSchema?: boolean): Promise<Record<string, any> | ContentTypeStruct[]>;
26
+ run(returnFixSchema?: boolean, totalCount?: number): Promise<Record<string, any> | ContentTypeStruct[]>;
25
27
  /**
26
28
  * @method prerequisiteData
27
29
  * The `prerequisiteData` function reads and parses JSON files to retrieve extension and marketplace
@@ -8,15 +8,16 @@ const path_1 = require("path");
8
8
  const fs_1 = require("fs");
9
9
  const cli_utilities_1 = require("@contentstack/cli-utilities");
10
10
  const messages_1 = require("../messages");
11
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
11
12
  /* The `ContentType` class is responsible for scanning content types, looking for references, and
12
13
  generating a report in JSON and CSV formats. */
13
- class ContentType {
14
+ class ContentType extends base_class_1.default {
14
15
  constructor({ fix, config, moduleName, ctSchema, gfSchema }) {
16
+ super({ config });
15
17
  this.extensions = [];
16
18
  this.inMemoryFix = false;
17
19
  this.schema = [];
18
20
  this.missingRefs = {};
19
- this.config = config;
20
21
  this.fix = fix !== null && fix !== void 0 ? fix : false;
21
22
  this.ctSchema = ctSchema;
22
23
  this.gfSchema = gfSchema;
@@ -38,49 +39,70 @@ class ContentType {
38
39
  /**
39
40
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
40
41
  * iterates over the schema and looks for references, and returns a list of missing references.
42
+ * @param returnFixSchema - If true, returns the fixed schema instead of missing references
43
+ * @param totalCount - Total number of items to process (for progress tracking)
41
44
  * @returns the `missingRefs` object.
42
45
  */
43
- async run(returnFixSchema = false) {
46
+ async run(returnFixSchema = false, totalCount) {
44
47
  var _a, _b, _c;
45
- this.inMemoryFix = returnFixSchema;
46
- if (!(0, fs_1.existsSync)(this.folderPath)) {
47
- cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
48
- cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
49
- return returnFixSchema ? [] : {};
50
- }
51
- this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;
52
- cli_utilities_1.log.debug(`Found ${((_a = this.schema) === null || _a === void 0 ? void 0 : _a.length) || 0} ${this.moduleName} schemas to audit`, this.config.auditContext);
53
- await this.prerequisiteData();
54
- for (const schema of (_b = this.schema) !== null && _b !== void 0 ? _b : []) {
55
- this.currentUid = schema.uid;
56
- this.currentTitle = schema.title;
57
- this.missingRefs[this.currentUid] = [];
58
- const { uid, title } = schema;
59
- cli_utilities_1.log.debug(`Auditing ${this.moduleName}: ${title} (${uid})`, this.config.auditContext);
60
- await this.lookForReference([{ uid, name: title }], schema);
61
- cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.SCAN_CT_SUCCESS_MSG, { title, module: this.config.moduleConfig[this.moduleName].name }), this.config.auditContext);
62
- }
63
- if (returnFixSchema) {
64
- cli_utilities_1.log.debug(`Returning fixed schema with ${((_c = this.schema) === null || _c === void 0 ? void 0 : _c.length) || 0} items`, this.config.auditContext);
65
- return this.schema;
66
- }
67
- if (this.fix) {
68
- cli_utilities_1.log.debug('Writing fix content to files', this.config.auditContext);
69
- await this.writeFixContent();
70
- }
71
- cli_utilities_1.log.debug('Cleaning up empty missing references', this.config.auditContext);
72
- cli_utilities_1.log.debug(`Total missing reference properties: ${Object.keys(this.missingRefs).length}`, this.config.auditContext);
73
- for (let propName in this.missingRefs) {
74
- const refCount = this.missingRefs[propName].length;
75
- cli_utilities_1.log.debug(`Property ${propName}: ${refCount} missing references`, this.config.auditContext);
76
- if (!refCount) {
77
- cli_utilities_1.log.debug(`Removing empty property: ${propName}`, this.config.auditContext);
78
- delete this.missingRefs[propName];
48
+ try {
49
+ this.inMemoryFix = returnFixSchema;
50
+ if (!(0, fs_1.existsSync)(this.folderPath)) {
51
+ cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
52
+ cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
53
+ return returnFixSchema ? [] : {};
54
+ }
55
+ this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;
56
+ cli_utilities_1.log.debug(`Found ${((_a = this.schema) === null || _a === void 0 ? void 0 : _a.length) || 0} ${this.moduleName} schemas to audit`, this.config.auditContext);
57
+ // Load prerequisite data with loading spinner
58
+ await this.withLoadingSpinner(`${this.moduleName.toUpperCase()}: Loading prerequisite data...`, async () => {
59
+ await this.prerequisiteData();
60
+ });
61
+ // Create progress manager if we have a total count
62
+ if (totalCount && totalCount > 0) {
63
+ const progress = this.createSimpleProgress(this.moduleName, totalCount);
64
+ progress.updateStatus('Validating references...');
65
+ }
66
+ for (const schema of (_b = this.schema) !== null && _b !== void 0 ? _b : []) {
67
+ this.currentUid = schema.uid;
68
+ this.currentTitle = schema.title;
69
+ this.missingRefs[this.currentUid] = [];
70
+ const { uid, title } = schema;
71
+ cli_utilities_1.log.debug(`Auditing ${this.moduleName}: ${title} (${uid})`, this.config.auditContext);
72
+ await this.lookForReference([{ uid, name: title }], schema);
73
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.SCAN_CT_SUCCESS_MSG, { title, module: this.config.moduleConfig[this.moduleName].name }), this.config.auditContext);
74
+ // Track progress for each schema processed
75
+ if (this.progressManager) {
76
+ this.progressManager.tick(true, `${this.moduleName}: ${title}`, null);
77
+ }
79
78
  }
79
+ if (returnFixSchema) {
80
+ cli_utilities_1.log.debug(`Returning fixed schema with ${((_c = this.schema) === null || _c === void 0 ? void 0 : _c.length) || 0} items`, this.config.auditContext);
81
+ return this.schema;
82
+ }
83
+ if (this.fix) {
84
+ cli_utilities_1.log.debug('Writing fix content to files', this.config.auditContext);
85
+ await this.writeFixContent();
86
+ }
87
+ cli_utilities_1.log.debug('Cleaning up empty missing references', this.config.auditContext);
88
+ cli_utilities_1.log.debug(`Total missing reference properties: ${Object.keys(this.missingRefs).length}`, this.config.auditContext);
89
+ for (let propName in this.missingRefs) {
90
+ const refCount = this.missingRefs[propName].length;
91
+ cli_utilities_1.log.debug(`Property ${propName}: ${refCount} missing references`, this.config.auditContext);
92
+ if (!refCount) {
93
+ cli_utilities_1.log.debug(`Removing empty property: ${propName}`, this.config.auditContext);
94
+ delete this.missingRefs[propName];
95
+ }
96
+ }
97
+ const totalIssues = Object.keys(this.missingRefs).length;
98
+ cli_utilities_1.log.debug(`${this.moduleName} audit completed. Found ${totalIssues} schemas with issues`, this.config.auditContext);
99
+ this.completeProgress(true);
100
+ return this.missingRefs;
101
+ }
102
+ catch (error) {
103
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || `${this.moduleName} audit failed`);
104
+ throw error;
80
105
  }
81
- const totalIssues = Object.keys(this.missingRefs).length;
82
- cli_utilities_1.log.debug(`${this.moduleName} audit completed. Found ${totalIssues} schemas with issues`, this.config.auditContext);
83
- return this.missingRefs;
84
106
  }
85
107
  /**
86
108
  * @method prerequisiteData
@@ -1,9 +1,9 @@
1
- import { ConfigType, CtConstructorParam, ModuleConstructorParam, CustomRole } from '../types';
1
+ import { CtConstructorParam, ModuleConstructorParam, CustomRole } from '../types';
2
2
  import auditConfig from '../config';
3
- export default class CustomRoles {
3
+ import BaseClass from './base-class';
4
+ export default class CustomRoles extends BaseClass {
4
5
  protected fix: boolean;
5
6
  fileName: any;
6
- config: ConfigType;
7
7
  folderPath: string;
8
8
  customRoleSchema: CustomRole[];
9
9
  moduleName: keyof typeof auditConfig.moduleConfig;
@@ -18,7 +18,7 @@ export default class CustomRoles {
18
18
  * From the ctSchema add all the content type UID into ctUidSet to check whether the content-type is present or not
19
19
  * @returns Array of object containing the custom role name, uid and content_types that are missing
20
20
  */
21
- run(): Promise<{}>;
21
+ run(totalCount?: number): Promise<{}>;
22
22
  fixCustomRoleSchema(): Promise<void>;
23
23
  writeFixContent(newCustomRoleSchema: Record<string, CustomRole>): Promise<void>;
24
24
  }
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
3
4
  const path_1 = require("path");
4
5
  const fs_1 = require("fs");
5
6
  const lodash_1 = require("lodash");
6
7
  const cli_utilities_1 = require("@contentstack/cli-utilities");
7
8
  const messages_1 = require("../messages");
8
9
  const lodash_2 = require("lodash");
9
- class CustomRoles {
10
+ const base_class_1 = tslib_1.__importDefault(require("./base-class"));
11
+ class CustomRoles extends base_class_1.default {
10
12
  constructor({ fix, config, moduleName }) {
11
13
  var _a;
12
- this.config = config;
14
+ super({ config });
13
15
  cli_utilities_1.log.debug(`Initializing Custom Roles module`, this.config.auditContext);
14
16
  this.fix = fix !== null && fix !== void 0 ? fix : false;
15
17
  this.customRoleSchema = [];
@@ -40,77 +42,96 @@ class CustomRoles {
40
42
  * From the ctSchema add all the content type UID into ctUidSet to check whether the content-type is present or not
41
43
  * @returns Array of object containing the custom role name, uid and content_types that are missing
42
44
  */
43
- async run() {
45
+ async run(totalCount) {
44
46
  var _a, _b, _c, _d;
45
- if (!(0, fs_1.existsSync)(this.folderPath)) {
46
- cli_utilities_1.log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
47
- cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
48
- cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
49
- return {};
50
- }
51
- this.customRolePath = (0, path_1.join)(this.folderPath, this.fileName);
52
- cli_utilities_1.log.debug(`Custom roles file path: ${this.customRolePath}`, this.config.auditContext);
53
- this.customRoleSchema = (0, fs_1.existsSync)(this.customRolePath)
54
- ? (0, lodash_2.values)(JSON.parse((0, fs_1.readFileSync)(this.customRolePath, 'utf8')))
55
- : [];
56
- cli_utilities_1.log.debug(`Found ${this.customRoleSchema.length} custom roles to audit`, this.config.auditContext);
57
- for (let index = 0; index < ((_a = this.customRoleSchema) === null || _a === void 0 ? void 0 : _a.length); index++) {
58
- const customRole = this.customRoleSchema[index];
59
- cli_utilities_1.log.debug(`Processing custom role: ${customRole.name} (${customRole.uid})`, this.config.auditContext);
60
- let branchesToBeRemoved = [];
61
- if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.branch) {
62
- cli_utilities_1.log.debug(`Config branch : ${this.config.branch}`, this.config.auditContext);
63
- cli_utilities_1.log.debug(`Checking branch rules for custom role: ${customRole.name}`, this.config.auditContext);
64
- (_c = customRole === null || customRole === void 0 ? void 0 : customRole.rules) === null || _c === void 0 ? void 0 : _c.filter((rule) => {
65
- var _a, _b;
66
- if (rule.module === 'branch') {
67
- cli_utilities_1.log.debug(`Found branch rule with branches: ${((_a = rule === null || rule === void 0 ? void 0 : rule.branches) === null || _a === void 0 ? void 0 : _a.join(', ')) || 'none'}`, this.config.auditContext);
68
- branchesToBeRemoved = ((_b = rule === null || rule === void 0 ? void 0 : rule.branches) === null || _b === void 0 ? void 0 : _b.filter((branch) => { var _a; return branch !== ((_a = this.config) === null || _a === void 0 ? void 0 : _a.branch); })) || [];
69
- cli_utilities_1.log.debug(`Branches to be removed: ${branchesToBeRemoved.join(', ') || 'none'}`, this.config.auditContext);
70
- }
71
- });
47
+ try {
48
+ if (!(0, fs_1.existsSync)(this.folderPath)) {
49
+ cli_utilities_1.log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
50
+ cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
51
+ cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
52
+ return {};
72
53
  }
73
- else {
74
- cli_utilities_1.log.debug(`No branch filter configured, skipping branch validation`, this.config.auditContext);
54
+ this.customRolePath = (0, path_1.join)(this.folderPath, this.fileName);
55
+ cli_utilities_1.log.debug(`Custom roles file path: ${this.customRolePath}`, this.config.auditContext);
56
+ // Load custom roles schema with loading spinner
57
+ await this.withLoadingSpinner('CUSTOM-ROLES: Loading custom roles schema...', async () => {
58
+ this.customRoleSchema = (0, fs_1.existsSync)(this.customRolePath)
59
+ ? (0, lodash_2.values)(JSON.parse((0, fs_1.readFileSync)(this.customRolePath, 'utf8')))
60
+ : [];
61
+ });
62
+ cli_utilities_1.log.debug(`Found ${this.customRoleSchema.length} custom roles to audit`, this.config.auditContext);
63
+ // Create progress manager if we have a total count
64
+ if (totalCount && totalCount > 0) {
65
+ const progress = this.createSimpleProgress(this.moduleName, totalCount);
66
+ progress.updateStatus('Validating custom roles...');
75
67
  }
76
- if (branchesToBeRemoved === null || branchesToBeRemoved === void 0 ? void 0 : branchesToBeRemoved.length) {
77
- cli_utilities_1.log.debug(`Custom role ${customRole.name} has branches to be removed: ${branchesToBeRemoved.join(', ')}`, this.config.auditContext);
78
- this.isBranchFixDone = true;
79
- const tempCR = (0, lodash_1.cloneDeep)(customRole);
80
- if ((customRole === null || customRole === void 0 ? void 0 : customRole.rules) && ((_d = this.config) === null || _d === void 0 ? void 0 : _d.branch)) {
81
- cli_utilities_1.log.debug(`Applying branch fix to custom role: ${customRole.name}`, this.config.auditContext);
82
- tempCR.rules.forEach((rule) => {
83
- var _a;
68
+ for (let index = 0; index < ((_a = this.customRoleSchema) === null || _a === void 0 ? void 0 : _a.length); index++) {
69
+ const customRole = this.customRoleSchema[index];
70
+ cli_utilities_1.log.debug(`Processing custom role: ${customRole.name} (${customRole.uid})`, this.config.auditContext);
71
+ let branchesToBeRemoved = [];
72
+ if ((_b = this.config) === null || _b === void 0 ? void 0 : _b.branch) {
73
+ cli_utilities_1.log.debug(`Config branch : ${this.config.branch}`, this.config.auditContext);
74
+ cli_utilities_1.log.debug(`Checking branch rules for custom role: ${customRole.name}`, this.config.auditContext);
75
+ (_c = customRole === null || customRole === void 0 ? void 0 : customRole.rules) === null || _c === void 0 ? void 0 : _c.filter((rule) => {
76
+ var _a, _b;
84
77
  if (rule.module === 'branch') {
85
- cli_utilities_1.log.debug(`Updating branch rule branches from ${(_a = rule.branches) === null || _a === void 0 ? void 0 : _a.join(', ')} to ${branchesToBeRemoved.join(', ')}`, this.config.auditContext);
86
- rule.branches = branchesToBeRemoved;
78
+ cli_utilities_1.log.debug(`Found branch rule with branches: ${((_a = rule === null || rule === void 0 ? void 0 : rule.branches) === null || _a === void 0 ? void 0 : _a.join(', ')) || 'none'}`, this.config.auditContext);
79
+ branchesToBeRemoved = ((_b = rule === null || rule === void 0 ? void 0 : rule.branches) === null || _b === void 0 ? void 0 : _b.filter((branch) => { var _a; return branch !== ((_a = this.config) === null || _a === void 0 ? void 0 : _a.branch); })) || [];
80
+ cli_utilities_1.log.debug(`Branches to be removed: ${branchesToBeRemoved.join(', ') || 'none'}`, this.config.auditContext);
87
81
  }
88
82
  });
89
83
  }
90
- this.missingFieldsInCustomRoles.push(tempCR);
91
- cli_utilities_1.log.debug(`Added custom role ${customRole.name} to missing fields list`, this.config.auditContext);
84
+ else {
85
+ cli_utilities_1.log.debug(`No branch filter configured, skipping branch validation`, this.config.auditContext);
86
+ }
87
+ if (branchesToBeRemoved === null || branchesToBeRemoved === void 0 ? void 0 : branchesToBeRemoved.length) {
88
+ cli_utilities_1.log.debug(`Custom role ${customRole.name} has branches to be removed: ${branchesToBeRemoved.join(', ')}`, this.config.auditContext);
89
+ this.isBranchFixDone = true;
90
+ const tempCR = (0, lodash_1.cloneDeep)(customRole);
91
+ if ((customRole === null || customRole === void 0 ? void 0 : customRole.rules) && ((_d = this.config) === null || _d === void 0 ? void 0 : _d.branch)) {
92
+ cli_utilities_1.log.debug(`Applying branch fix to custom role: ${customRole.name}`, this.config.auditContext);
93
+ tempCR.rules.forEach((rule) => {
94
+ var _a;
95
+ if (rule.module === 'branch') {
96
+ cli_utilities_1.log.debug(`Updating branch rule branches from ${(_a = rule.branches) === null || _a === void 0 ? void 0 : _a.join(', ')} to ${branchesToBeRemoved.join(', ')}`, this.config.auditContext);
97
+ rule.branches = branchesToBeRemoved;
98
+ }
99
+ });
100
+ }
101
+ this.missingFieldsInCustomRoles.push(tempCR);
102
+ cli_utilities_1.log.debug(`Added custom role ${customRole.name} to missing fields list`, this.config.auditContext);
103
+ }
104
+ else {
105
+ cli_utilities_1.log.debug(`Custom role ${customRole.name} has no branch issues`, this.config.auditContext);
106
+ }
107
+ cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditMsg.SCAN_CR_SUCCESS_MSG, {
108
+ name: customRole.name,
109
+ uid: customRole.uid,
110
+ }), this.config.auditContext);
111
+ // Track progress for each custom role processed
112
+ if (this.progressManager) {
113
+ this.progressManager.tick(true, `custom-role: ${customRole.name}`, null);
114
+ }
115
+ }
116
+ cli_utilities_1.log.debug(`Found ${this.missingFieldsInCustomRoles.length} custom roles with issues`, this.config.auditContext);
117
+ cli_utilities_1.log.debug(`Branch fix done: ${this.isBranchFixDone}`, this.config.auditContext);
118
+ if (this.fix && (this.missingFieldsInCustomRoles.length || this.isBranchFixDone)) {
119
+ cli_utilities_1.log.debug('Fix mode enabled and issues found, applying fixes', this.config.auditContext);
120
+ await this.fixCustomRoleSchema();
121
+ this.missingFieldsInCustomRoles.forEach((cr) => (cr.fixStatus = 'Fixed'));
122
+ cli_utilities_1.log.debug(`Applied fixes to ${this.missingFieldsInCustomRoles.length} custom roles`, this.config.auditContext);
92
123
  }
93
124
  else {
94
- cli_utilities_1.log.debug(`Custom role ${customRole.name} has no branch issues`, this.config.auditContext);
125
+ cli_utilities_1.log.debug('No fixes needed or fix mode disabled', this.config.auditContext);
95
126
  }
96
- cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditMsg.SCAN_CR_SUCCESS_MSG, {
97
- name: customRole.name,
98
- uid: customRole.uid,
99
- }), this.config.auditContext);
100
- }
101
- cli_utilities_1.log.debug(`Found ${this.missingFieldsInCustomRoles.length} custom roles with issues`, this.config.auditContext);
102
- cli_utilities_1.log.debug(`Branch fix done: ${this.isBranchFixDone}`, this.config.auditContext);
103
- if (this.fix && (this.missingFieldsInCustomRoles.length || this.isBranchFixDone)) {
104
- cli_utilities_1.log.debug('Fix mode enabled and issues found, applying fixes', this.config.auditContext);
105
- await this.fixCustomRoleSchema();
106
- this.missingFieldsInCustomRoles.forEach((cr) => (cr.fixStatus = 'Fixed'));
107
- cli_utilities_1.log.debug(`Applied fixes to ${this.missingFieldsInCustomRoles.length} custom roles`, this.config.auditContext);
127
+ cli_utilities_1.log.debug(`${this.moduleName} audit completed. Found ${this.missingFieldsInCustomRoles.length} custom roles with issues`, this.config.auditContext);
128
+ this.completeProgress(true);
129
+ return this.missingFieldsInCustomRoles;
108
130
  }
109
- else {
110
- cli_utilities_1.log.debug('No fixes needed or fix mode disabled', this.config.auditContext);
131
+ catch (error) {
132
+ this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Custom roles audit failed');
133
+ throw error;
111
134
  }
112
- cli_utilities_1.log.debug(`${this.moduleName} audit completed. Found ${this.missingFieldsInCustomRoles.length} custom roles with issues`, this.config.auditContext);
113
- return this.missingFieldsInCustomRoles;
114
135
  }
115
136
  async fixCustomRoleSchema() {
116
137
  var _a;
@@ -1,10 +1,10 @@
1
1
  import auditConfig from '../config';
2
- import { Locale, ConfigType, EntryStruct, EntryFieldType, ModularBlockType, ContentTypeStruct, CtConstructorParam, GroupFieldDataType, GlobalFieldDataType, JsonRTEFieldDataType, ContentTypeSchemaType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, EntryRefErrorReturnType, EntryGroupFieldDataType, EntryGlobalFieldDataType, EntryJsonRTEFieldDataType, EntryModularBlocksDataType, EntryReferenceFieldDataType, ExtensionOrAppFieldDataType, EntryExtensionOrAppFieldDataType, SelectFeildStruct } from '../types';
3
- export default class Entries {
2
+ import BaseClass from './base-class';
3
+ import { Locale, EntryStruct, EntryFieldType, ModularBlockType, ContentTypeStruct, CtConstructorParam, GroupFieldDataType, GlobalFieldDataType, JsonRTEFieldDataType, ContentTypeSchemaType, ModularBlocksDataType, ModuleConstructorParam, ReferenceFieldDataType, EntryRefErrorReturnType, EntryGroupFieldDataType, EntryGlobalFieldDataType, EntryJsonRTEFieldDataType, EntryModularBlocksDataType, EntryReferenceFieldDataType, ExtensionOrAppFieldDataType, EntryExtensionOrAppFieldDataType, SelectFeildStruct } from '../types';
4
+ export default class Entries extends BaseClass {
4
5
  protected fix: boolean;
5
6
  fileName: string;
6
7
  locales: Locale[];
7
- config: ConfigType;
8
8
  folderPath: string;
9
9
  currentUid: string;
10
10
  currentTitle: string;
@@ -26,9 +26,10 @@ export default class Entries {
26
26
  /**
27
27
  * The `run` function checks if a folder path exists, sets the schema based on the module name,
28
28
  * iterates over the schema and looks for references, and returns a list of missing references.
29
+ * @param totalCount - Total number of entries to process (for progress tracking)
29
30
  * @returns the `missingRefs` object.
30
31
  */
31
- run(): Promise<{}>;
32
+ run(totalCount?: number): Promise<{}>;
32
33
  /**
33
34
  * The function removes any properties from the `missingRefs` object that have an empty array value.
34
35
  */