@contentstack/cli-audit 1.14.2 → 1.15.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.
@@ -11,12 +11,11 @@ const messages_1 = require("../messages");
11
11
  /* The `ContentType` class is responsible for scanning content types, looking for references, and
12
12
  generating a report in JSON and CSV formats. */
13
13
  class ContentType {
14
- constructor({ log, fix, config, moduleName, ctSchema, gfSchema }) {
14
+ constructor({ fix, config, moduleName, ctSchema, gfSchema }) {
15
15
  this.extensions = [];
16
16
  this.inMemoryFix = false;
17
17
  this.schema = [];
18
18
  this.missingRefs = {};
19
- this.log = log;
20
19
  this.config = config;
21
20
  this.fix = fix !== null && fix !== void 0 ? fix : false;
22
21
  this.ctSchema = ctSchema;
@@ -24,11 +23,16 @@ class ContentType {
24
23
  this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
25
24
  this.fileName = config.moduleConfig[this.moduleName].fileName;
26
25
  this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig[this.moduleName].dirName));
26
+ cli_utilities_1.log.debug(`Starting ${this.moduleName} audit process`, this.config.auditContext);
27
27
  }
28
28
  validateModules(moduleName, moduleConfig) {
29
+ cli_utilities_1.log.debug(`Validating module: ${moduleName}`, this.config.auditContext);
30
+ cli_utilities_1.log.debug(`Available modules in config: ${Object.keys(moduleConfig).join(', ')}`, this.config.auditContext);
29
31
  if (Object.keys(moduleConfig).includes(moduleName)) {
32
+ cli_utilities_1.log.debug(`Module ${moduleName} found in config, returning: ${moduleName}`, this.config.auditContext);
30
33
  return moduleName;
31
34
  }
35
+ cli_utilities_1.log.debug(`Module ${moduleName} not found in config, defaulting to: content-types`, this.config.auditContext);
32
36
  return 'content-types';
33
37
  }
34
38
  /**
@@ -37,34 +41,45 @@ class ContentType {
37
41
  * @returns the `missingRefs` object.
38
42
  */
39
43
  async run(returnFixSchema = false) {
40
- var _a;
44
+ var _a, _b, _c;
41
45
  this.inMemoryFix = returnFixSchema;
42
46
  if (!(0, fs_1.existsSync)(this.folderPath)) {
43
- this.log(`Skipping ${this.moduleName} audit`, 'warn');
44
- this.log((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
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' });
45
49
  return returnFixSchema ? [] : {};
46
50
  }
47
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);
48
53
  await this.prerequisiteData();
49
- for (const schema of (_a = this.schema) !== null && _a !== void 0 ? _a : []) {
54
+ for (const schema of (_b = this.schema) !== null && _b !== void 0 ? _b : []) {
50
55
  this.currentUid = schema.uid;
51
56
  this.currentTitle = schema.title;
52
57
  this.missingRefs[this.currentUid] = [];
53
58
  const { uid, title } = schema;
59
+ cli_utilities_1.log.debug(`Auditing ${this.moduleName}: ${title} (${uid})`, this.config.auditContext);
54
60
  await this.lookForReference([{ uid, name: title }], schema);
55
- this.log((0, messages_1.$t)(messages_1.auditMsg.SCAN_CT_SUCCESS_MSG, { title, module: this.config.moduleConfig[this.moduleName].name }), 'info');
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);
56
62
  }
57
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);
58
65
  return this.schema;
59
66
  }
60
67
  if (this.fix) {
68
+ cli_utilities_1.log.debug('Writing fix content to files', this.config.auditContext);
61
69
  await this.writeFixContent();
62
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);
63
73
  for (let propName in this.missingRefs) {
64
- if (!this.missingRefs[propName].length) {
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);
65
78
  delete this.missingRefs[propName];
66
79
  }
67
80
  }
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);
68
83
  return this.missingRefs;
69
84
  }
70
85
  /**
@@ -73,40 +88,72 @@ class ContentType {
73
88
  * app data, and stores them in the `extensions` array.
74
89
  */
75
90
  async prerequisiteData() {
76
- var _a;
91
+ var _a, _b;
92
+ cli_utilities_1.log.debug('Loading prerequisite data (extensions and marketplace apps)', this.config.auditContext);
77
93
  const extensionPath = (0, path_1.resolve)(this.config.basePath, 'extensions', 'extensions.json');
78
94
  const marketplacePath = (0, path_1.resolve)(this.config.basePath, 'marketplace_apps', 'marketplace_apps.json');
79
95
  if ((0, fs_1.existsSync)(extensionPath)) {
96
+ cli_utilities_1.log.debug(`Loading extensions from: ${extensionPath}`, this.config.auditContext);
80
97
  try {
81
98
  this.extensions = Object.keys(JSON.parse((0, fs_1.readFileSync)(extensionPath, 'utf8')));
99
+ cli_utilities_1.log.debug(`Loaded ${this.extensions.length} extensions`, this.config.auditContext);
100
+ }
101
+ catch (error) {
102
+ cli_utilities_1.log.debug(`Failed to load extensions: ${error}`, this.config.auditContext);
82
103
  }
83
- catch (error) { }
104
+ }
105
+ else {
106
+ cli_utilities_1.log.debug('No extensions.json found', this.config.auditContext);
84
107
  }
85
108
  if ((0, fs_1.existsSync)(marketplacePath)) {
109
+ cli_utilities_1.log.debug(`Loading marketplace apps from: ${marketplacePath}`, this.config.auditContext);
86
110
  try {
87
111
  const marketplaceApps = JSON.parse((0, fs_1.readFileSync)(marketplacePath, 'utf8'));
112
+ cli_utilities_1.log.debug(`Found ${marketplaceApps.length} marketplace apps`, this.config.auditContext);
88
113
  for (const app of marketplaceApps) {
89
114
  const metaData = (0, map_1.default)((0, map_1.default)((_a = app === null || app === void 0 ? void 0 : app.ui_location) === null || _a === void 0 ? void 0 : _a.locations, 'meta').flat(), 'extension_uid').filter((val) => val);
90
115
  this.extensions.push(...metaData);
116
+ cli_utilities_1.log.debug(`Added ${metaData.length} extension UIDs from app: ${((_b = app.manifest) === null || _b === void 0 ? void 0 : _b.name) || app.uid}`, this.config.auditContext);
91
117
  }
92
118
  }
93
- catch (error) { }
119
+ catch (error) {
120
+ cli_utilities_1.log.debug(`Failed to load marketplace apps: ${error}`, this.config.auditContext);
121
+ }
122
+ }
123
+ else {
124
+ cli_utilities_1.log.debug('No marketplace_apps.json found', this.config.auditContext);
94
125
  }
126
+ cli_utilities_1.log.debug(`Total extensions loaded: ${this.extensions.length}`, this.config.auditContext);
95
127
  }
96
128
  /**
97
129
  * The function checks if it can write the fix content to a file and if so, it writes the content as
98
130
  * JSON to the specified file path.
99
131
  */
100
132
  async writeFixContent() {
101
- var _a, _b;
133
+ var _a, _b, _c;
134
+ cli_utilities_1.log.debug('Starting writeFixContent process', this.config.auditContext);
102
135
  let canWrite = true;
103
136
  if (!this.inMemoryFix && this.fix) {
137
+ cli_utilities_1.log.debug('Fix mode enabled, checking write permissions', this.config.auditContext);
104
138
  if (!this.config.flags['copy-dir'] && !((_a = this.config.flags['external-config']) === null || _a === void 0 ? void 0 : _a.skipConfirm)) {
139
+ cli_utilities_1.log.debug('Asking user for confirmation to write fix content', this.config.auditContext);
105
140
  canWrite = (_b = this.config.flags.yes) !== null && _b !== void 0 ? _b : (await cli_utilities_1.cliux.confirm(messages_1.commonMsg.FIX_CONFIRMATION));
106
141
  }
142
+ else {
143
+ cli_utilities_1.log.debug('Skipping confirmation due to copy-dir or external-config flags', this.config.auditContext);
144
+ }
107
145
  if (canWrite) {
108
- (0, fs_1.writeFileSync)((0, path_1.join)(this.folderPath, this.config.moduleConfig[this.moduleName].fileName), JSON.stringify(this.schema));
146
+ const filePath = (0, path_1.join)(this.folderPath, this.config.moduleConfig[this.moduleName].fileName);
147
+ cli_utilities_1.log.debug(`Writing fixed schema to: ${filePath}`, this.config.auditContext);
148
+ (0, fs_1.writeFileSync)(filePath, JSON.stringify(this.schema));
149
+ cli_utilities_1.log.debug(`Successfully wrote ${((_c = this.schema) === null || _c === void 0 ? void 0 : _c.length) || 0} schemas to file`, this.config.auditContext);
109
150
  }
151
+ else {
152
+ cli_utilities_1.log.debug('User declined to write fix content', this.config.auditContext);
153
+ }
154
+ }
155
+ else {
156
+ cli_utilities_1.log.debug('Skipping writeFixContent - not in fix mode or in-memory fix', this.config.auditContext);
110
157
  }
111
158
  }
112
159
  /**
@@ -122,38 +169,62 @@ class ContentType {
122
169
  */
123
170
  async lookForReference(tree, field) {
124
171
  var _a, _b;
172
+ cli_utilities_1.log.debug(`Looking for references in field: ${field.uid}`, this.config.auditContext);
125
173
  const fixTypes = (_a = this.config.flags['fix-only']) !== null && _a !== void 0 ? _a : this.config['fix-fields'];
174
+ cli_utilities_1.log.debug(`Fix types filter: ${fixTypes.join(', ')}`, this.config.auditContext);
126
175
  if (this.fix) {
176
+ cli_utilities_1.log.debug('Running fix on schema', this.config.auditContext);
127
177
  field.schema = this.runFixOnSchema(tree, field.schema);
128
178
  }
129
- for (let child of (_b = field.schema) !== null && _b !== void 0 ? _b : []) {
130
- if (!fixTypes.includes(child.data_type) && child.data_type !== 'json')
179
+ const schemaFields = (_b = field.schema) !== null && _b !== void 0 ? _b : [];
180
+ cli_utilities_1.log.debug(`Processing ${schemaFields.length} fields in schema`, this.config.auditContext);
181
+ for (let child of schemaFields) {
182
+ if (!fixTypes.includes(child.data_type) && child.data_type !== 'json') {
183
+ cli_utilities_1.log.debug(`Skipping field ${child.display_name} (${child.data_type}) - not in fix types`, this.config.auditContext);
131
184
  continue;
185
+ }
186
+ cli_utilities_1.log.debug(`Processing field: ${child.display_name} (${child.data_type})`, this.config.auditContext);
132
187
  switch (child.data_type) {
133
188
  case 'reference':
134
- this.missingRefs[this.currentUid].push(...this.validateReferenceField([...tree, { uid: field.uid, name: child.display_name }], child));
189
+ cli_utilities_1.log.debug(`Validating reference field: ${child.display_name}`, this.config.auditContext);
190
+ const refResults = this.validateReferenceField([...tree, { uid: field.uid, name: child.display_name }], child);
191
+ this.missingRefs[this.currentUid].push(...refResults);
192
+ cli_utilities_1.log.debug(`Found ${refResults.length} missing references in field: ${child.display_name}`, this.config.auditContext);
135
193
  break;
136
194
  case 'global_field':
195
+ cli_utilities_1.log.debug(`Validating global field: ${child.display_name}`, this.config.auditContext);
137
196
  await this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name }], child);
138
197
  break;
139
198
  case 'json':
140
199
  if ('extension' in child.field_metadata && child.field_metadata.extension) {
141
- if (!fixTypes.includes('json:extension'))
200
+ if (!fixTypes.includes('json:extension')) {
201
+ cli_utilities_1.log.debug(`Skipping extension field ${child.display_name} - not in fix types`, this.config.auditContext);
142
202
  continue;
203
+ }
204
+ cli_utilities_1.log.debug(`Validating extension field: ${child.display_name}`, this.config.auditContext);
143
205
  // NOTE Custom field type
144
- this.missingRefs[this.currentUid].push(...this.validateExtensionAndAppField([...tree, { uid: child.uid, name: child.display_name }], child));
206
+ const extResults = this.validateExtensionAndAppField([...tree, { uid: child.uid, name: child.display_name }], child);
207
+ this.missingRefs[this.currentUid].push(...extResults);
208
+ cli_utilities_1.log.debug(`Found ${extResults.length} missing extension references in field: ${child.display_name}`, this.config.auditContext);
145
209
  }
146
210
  else if ('allow_json_rte' in child.field_metadata && child.field_metadata.allow_json_rte) {
147
- if (!fixTypes.includes('json:rte'))
211
+ if (!fixTypes.includes('json:rte')) {
212
+ cli_utilities_1.log.debug(`Skipping JSON RTE field ${child.display_name} - not in fix types`, this.config.auditContext);
148
213
  continue;
214
+ }
215
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${child.display_name}`, this.config.auditContext);
149
216
  // NOTE JSON RTE field type
150
- this.missingRefs[this.currentUid].push(...this.validateJsonRTEFields([...tree, { uid: child.uid, name: child.display_name }], child));
217
+ const rteResults = this.validateJsonRTEFields([...tree, { uid: child.uid, name: child.display_name }], child);
218
+ this.missingRefs[this.currentUid].push(...rteResults);
219
+ cli_utilities_1.log.debug(`Found ${rteResults.length} missing RTE references in field: ${child.display_name}`, this.config.auditContext);
151
220
  }
152
221
  break;
153
222
  case 'blocks':
223
+ cli_utilities_1.log.debug(`Validating modular blocks field: ${child.display_name}`, this.config.auditContext);
154
224
  await this.validateModularBlocksField([...tree, { uid: child.uid, name: child.display_name }], child);
155
225
  break;
156
226
  case 'group':
227
+ cli_utilities_1.log.debug(`Validating group field: ${child.display_name}`, this.config.auditContext);
157
228
  await this.validateGroupField([...tree, { uid: child.uid, name: child.display_name }], child);
158
229
  break;
159
230
  }
@@ -168,7 +239,10 @@ class ContentType {
168
239
  * @returns an array of RefErrorReturnType.
169
240
  */
170
241
  validateReferenceField(tree, field) {
171
- return this.validateReferenceToValues(tree, field);
242
+ cli_utilities_1.log.debug(`Validating reference field: ${field.display_name} (${field.uid})`, this.config.auditContext);
243
+ const results = this.validateReferenceToValues(tree, field);
244
+ cli_utilities_1.log.debug(`Reference field validation completed. Found ${results.length} missing references`, this.config.auditContext);
245
+ return results;
172
246
  }
173
247
  /**
174
248
  * The function `validateExtensionAndAppsField` checks if a given field has a valid extension or app
@@ -179,14 +253,22 @@ class ContentType {
179
253
  * objects.
180
254
  */
181
255
  validateExtensionAndAppField(tree, field) {
182
- if (this.fix)
256
+ cli_utilities_1.log.debug(`Validating extension/app field: ${field.display_name} (${field.uid})`, this.config.auditContext);
257
+ if (this.fix) {
258
+ cli_utilities_1.log.debug('Skipping extension validation in fix mode', this.config.auditContext);
183
259
  return [];
260
+ }
184
261
  const missingRefs = [];
185
262
  let { uid, extension_uid, display_name, data_type } = field;
263
+ cli_utilities_1.log.debug(`Checking if extension ${extension_uid} exists in loaded extensions`, this.config.auditContext);
186
264
  if (!this.extensions.includes(extension_uid)) {
265
+ cli_utilities_1.log.debug(`Extension ${extension_uid} not found in loaded extensions`, this.config.auditContext);
187
266
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
188
267
  }
189
- return missingRefs.length
268
+ else {
269
+ cli_utilities_1.log.debug(`Extension ${extension_uid} found in loaded extensions`, this.config.auditContext);
270
+ }
271
+ const result = missingRefs.length
190
272
  ? [
191
273
  {
192
274
  tree,
@@ -202,6 +284,8 @@ class ContentType {
202
284
  },
203
285
  ]
204
286
  : [];
287
+ cli_utilities_1.log.debug(`Extension/app field validation completed. Found ${result.length} issues`, this.config.auditContext);
288
+ return result;
205
289
  }
206
290
  /**
207
291
  * The function "validateGlobalField" asynchronously validates a global field by looking for a
@@ -213,11 +297,14 @@ class ContentType {
213
297
  * represents the field that needs to be validated.
214
298
  */
215
299
  async validateGlobalField(tree, field) {
300
+ cli_utilities_1.log.debug(`Validating global field: ${field.display_name} (${field.uid})`, this.config.auditContext);
216
301
  // NOTE Any GlobalField related logic can be added here
217
302
  if (this.moduleName === 'global-fields') {
218
303
  let { reference_to } = field;
304
+ cli_utilities_1.log.debug(`Checking if global field ${reference_to} exists in schema`, this.config.auditContext);
219
305
  const refExist = (0, find_1.default)(this.schema, { uid: reference_to });
220
306
  if (!refExist) {
307
+ cli_utilities_1.log.debug(`Global field ${reference_to} not found in schema`, this.config.auditContext);
221
308
  this.missingRefs[this.currentUid].push({
222
309
  tree,
223
310
  ct: this.currentUid,
@@ -229,9 +316,14 @@ class ContentType {
229
316
  });
230
317
  return void 0;
231
318
  }
319
+ else {
320
+ cli_utilities_1.log.debug(`Global field ${reference_to} found in schema`, this.config.auditContext);
321
+ }
232
322
  }
233
323
  else if (this.moduleName === 'content-types') {
324
+ cli_utilities_1.log.debug('Processing global field in content-types module', this.config.auditContext);
234
325
  if (!field.schema && !this.fix) {
326
+ cli_utilities_1.log.debug(`Global field ${field.display_name} has no schema and not in fix mode`, this.config.auditContext);
235
327
  this.missingRefs[this.currentUid].push({
236
328
  tree,
237
329
  ct_uid: this.currentUid,
@@ -243,8 +335,13 @@ class ContentType {
243
335
  });
244
336
  return void 0;
245
337
  }
338
+ else {
339
+ cli_utilities_1.log.debug(`Global field ${field.display_name} has schema, proceeding with validation`, this.config.auditContext);
340
+ }
246
341
  }
342
+ cli_utilities_1.log.debug(`Calling lookForReference for global field: ${field.display_name}`, this.config.auditContext);
247
343
  await this.lookForReference(tree, field);
344
+ cli_utilities_1.log.debug(`Global field validation completed: ${field.display_name}`, this.config.auditContext);
248
345
  }
249
346
  /**
250
347
  * The function validates the reference to values in a JSON RTE field.
@@ -256,8 +353,11 @@ class ContentType {
256
353
  * objects.
257
354
  */
258
355
  validateJsonRTEFields(tree, field) {
356
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${field.display_name} (${field.uid})`, this.config.auditContext);
259
357
  // NOTE Other possible reference logic will be added related to JSON RTE (Ex missing assets, extensions etc.,)
260
- return this.validateReferenceToValues(tree, field);
358
+ const results = this.validateReferenceToValues(tree, field);
359
+ cli_utilities_1.log.debug(`JSON RTE field validation completed. Found ${results.length} missing references`, this.config.auditContext);
360
+ return results;
261
361
  }
262
362
  /**
263
363
  * The function validates the modular blocks field by traversing each module and looking for
@@ -270,12 +370,16 @@ class ContentType {
270
370
  * like `uid` and `title`.
271
371
  */
272
372
  async validateModularBlocksField(tree, field) {
373
+ cli_utilities_1.log.debug(`[CONTENT-TYPES] Validating modular blocks field: ${field.display_name} (${field.uid})`, this.config.auditContext);
273
374
  const { blocks } = field;
375
+ cli_utilities_1.log.debug(`Found ${blocks.length} blocks in modular blocks field`, this.config.auditContext);
274
376
  this.fixModularBlocksReferences(tree, blocks);
275
377
  for (const block of blocks) {
276
378
  const { uid, title } = block;
379
+ cli_utilities_1.log.debug(`Processing block: ${title} (${uid})`, this.config.auditContext);
277
380
  await this.lookForReference([...tree, { uid, name: title }], block);
278
381
  }
382
+ cli_utilities_1.log.debug(`Modular blocks field validation completed: ${field.display_name}`, this.config.auditContext);
279
383
  }
280
384
  /**
281
385
  * The function `validateGroupField` is an asynchronous function that validates a group field by
@@ -288,8 +392,10 @@ class ContentType {
288
392
  * represents the group field that needs to be validated.
289
393
  */
290
394
  async validateGroupField(tree, field) {
395
+ cli_utilities_1.log.debug(`[CONTENT-TYPES] Validating group field: ${field.display_name} (${field.uid})`, this.config.auditContext);
291
396
  // NOTE Any Group Field related logic can be added here (Ex data serialization or picking any metadata for report etc.,)
292
397
  await this.lookForReference(tree, field);
398
+ cli_utilities_1.log.debug(`[CONTENT-TYPES] Group field validation completed: ${field.display_name}`, this.config.auditContext);
293
399
  }
294
400
  /**
295
401
  * The function `validateReferenceToValues` checks if all the references specified in a field exist
@@ -302,33 +408,53 @@ class ContentType {
302
408
  * objects.
303
409
  */
304
410
  validateReferenceToValues(tree, field) {
305
- if (this.fix)
411
+ cli_utilities_1.log.debug(`Validating reference to values for field: ${field.display_name} (${field.uid})`, this.config.auditContext);
412
+ if (this.fix) {
413
+ cli_utilities_1.log.debug('Skipping reference validation in fix mode', this.config.auditContext);
306
414
  return [];
415
+ }
307
416
  const missingRefs = [];
308
417
  let { reference_to, display_name, data_type } = field;
418
+ cli_utilities_1.log.debug(`Reference_to type: ${Array.isArray(reference_to) ? 'array' : 'single'}, value: ${JSON.stringify(reference_to)}`, this.config.auditContext);
309
419
  if (!Array.isArray(reference_to)) {
310
- this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), 'error');
311
- this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
420
+ cli_utilities_1.log.debug(`Processing single reference: ${reference_to}`, this.config.auditContext);
421
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), this.config.auditContext);
422
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), this.config.auditContext);
312
423
  if (!this.config.skipRefs.includes(reference_to)) {
424
+ cli_utilities_1.log.debug(`Checking if reference ${reference_to} exists in content type schema`, this.config.auditContext);
313
425
  const refExist = (0, find_1.default)(this.ctSchema, { uid: reference_to });
314
426
  if (!refExist) {
427
+ cli_utilities_1.log.debug(`Reference ${reference_to} not found in schema`, this.config.auditContext);
315
428
  missingRefs.push(reference_to);
316
429
  }
430
+ else {
431
+ cli_utilities_1.log.debug(`Reference ${reference_to} found in schema`, this.config.auditContext);
432
+ }
433
+ }
434
+ else {
435
+ cli_utilities_1.log.debug(`Skipping reference ${reference_to} - in skip list`, this.config.auditContext);
317
436
  }
318
437
  }
319
438
  else {
439
+ cli_utilities_1.log.debug(`Processing ${(reference_to === null || reference_to === void 0 ? void 0 : reference_to.length) || 0} references in array`, this.config.auditContext);
320
440
  for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
321
441
  // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
322
442
  if (this.config.skipRefs.includes(reference)) {
443
+ cli_utilities_1.log.debug(`Skipping reference ${reference} - in skip list`, this.config.auditContext);
323
444
  continue;
324
445
  }
446
+ cli_utilities_1.log.debug(`Checking if reference ${reference} exists in content type schema`, this.config.auditContext);
325
447
  const refExist = (0, find_1.default)(this.ctSchema, { uid: reference });
326
448
  if (!refExist) {
449
+ cli_utilities_1.log.debug(`Reference ${reference} not found in schema`, this.config.auditContext);
327
450
  missingRefs.push(reference);
328
451
  }
452
+ else {
453
+ cli_utilities_1.log.debug(`Reference ${reference} found in schema`, this.config.auditContext);
454
+ }
329
455
  }
330
456
  }
331
- return missingRefs.length
457
+ const result = missingRefs.length
332
458
  ? [
333
459
  {
334
460
  tree,
@@ -344,6 +470,8 @@ class ContentType {
344
470
  },
345
471
  ]
346
472
  : [];
473
+ cli_utilities_1.log.debug(`Reference validation completed. Found ${missingRefs.length} missing references: ${missingRefs.join(', ')}`, this.config.auditContext);
474
+ return result;
347
475
  }
348
476
  /**
349
477
  * The function `runFixOnSchema` takes in a tree and a schema, and performs various fixes on the
@@ -356,55 +484,79 @@ class ContentType {
356
484
  * @returns an array of ContentTypeSchemaType objects.
357
485
  */
358
486
  runFixOnSchema(tree, schema) {
487
+ cli_utilities_1.log.debug(`Running fix on schema with ${(schema === null || schema === void 0 ? void 0 : schema.length) || 0} fields`, this.config.auditContext);
359
488
  // NOTE Global field Fix
360
- return schema === null || schema === void 0 ? void 0 : schema.map((field) => {
489
+ const result = schema === null || schema === void 0 ? void 0 : schema.map((field) => {
361
490
  var _a;
362
- const { data_type } = field;
491
+ const { data_type, display_name, uid } = field;
363
492
  const fixTypes = (_a = this.config.flags['fix-only']) !== null && _a !== void 0 ? _a : this.config['fix-fields'];
364
- if (!fixTypes.includes(data_type) && data_type !== 'json')
493
+ cli_utilities_1.log.debug(`Processing field for fix: ${display_name} (${uid}) - ${data_type}`, this.config.auditContext);
494
+ if (!fixTypes.includes(data_type) && data_type !== 'json') {
495
+ cli_utilities_1.log.debug(`Skipping field ${display_name} - not in fix types`, this.config.auditContext);
365
496
  return field;
497
+ }
366
498
  switch (data_type) {
367
499
  case 'global_field':
500
+ cli_utilities_1.log.debug(`Fixing global field references for: ${display_name}`, this.config.auditContext);
368
501
  return this.fixGlobalFieldReferences(tree, field);
369
502
  case 'json':
370
503
  case 'reference':
371
504
  if (data_type === 'json') {
372
505
  if ('extension' in field.field_metadata && field.field_metadata.extension) {
373
506
  // NOTE Custom field type
374
- if (!fixTypes.includes('json:extension'))
507
+ if (!fixTypes.includes('json:extension')) {
508
+ cli_utilities_1.log.debug(`Skipping extension field ${display_name} - not in fix types`, this.config.auditContext);
375
509
  return field;
510
+ }
511
+ cli_utilities_1.log.debug(`Fixing extension/app field: ${display_name}`, this.config.auditContext);
376
512
  // NOTE Fix logic
377
513
  return this.fixMissingExtensionOrApp(tree, field);
378
514
  }
379
515
  else if ('allow_json_rte' in field.field_metadata && field.field_metadata.allow_json_rte) {
380
- if (!fixTypes.includes('json:rte'))
516
+ if (!fixTypes.includes('json:rte')) {
517
+ cli_utilities_1.log.debug(`Skipping JSON RTE field ${display_name} - not in fix types`, this.config.auditContext);
381
518
  return field;
519
+ }
520
+ cli_utilities_1.log.debug(`Fixing JSON RTE field: ${display_name}`, this.config.auditContext);
382
521
  return this.fixMissingReferences(tree, field);
383
522
  }
384
523
  }
524
+ cli_utilities_1.log.debug(`Fixing reference field: ${display_name}`, this.config.auditContext);
385
525
  return this.fixMissingReferences(tree, field);
386
526
  case 'blocks':
527
+ cli_utilities_1.log.debug(`Fixing modular blocks field: ${display_name}`, this.config.auditContext);
387
528
  field.blocks = this.fixModularBlocksReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field.blocks);
388
529
  if ((0, isEmpty_1.default)(field.blocks)) {
530
+ cli_utilities_1.log.debug(`Modular blocks field ${display_name} became empty after fix`, this.config.auditContext);
389
531
  return null;
390
532
  }
391
533
  return field;
392
534
  case 'group':
535
+ cli_utilities_1.log.debug(`Fixing group field: ${display_name}`, this.config.auditContext);
393
536
  return this.fixGroupField(tree, field);
394
537
  default:
538
+ cli_utilities_1.log.debug(`No fix needed for field type ${data_type}: ${display_name}`, this.config.auditContext);
395
539
  return field;
396
540
  }
397
541
  }).filter((val) => {
398
- if (this.config.skipFieldTypes.includes(val === null || val === void 0 ? void 0 : val.data_type))
542
+ if (this.config.skipFieldTypes.includes(val === null || val === void 0 ? void 0 : val.data_type)) {
543
+ cli_utilities_1.log.debug(`Keeping field ${val === null || val === void 0 ? void 0 : val.display_name} - in skip field types`, this.config.auditContext);
399
544
  return true;
545
+ }
400
546
  if ((val === null || val === void 0 ? void 0 : val.schema) &&
401
547
  (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)))
548
+ (!(val === null || val === void 0 ? void 0 : val.data_type) || this.config['schema-fields-data-type'].includes(val.data_type))) {
549
+ cli_utilities_1.log.debug(`Filtering out field ${val === null || val === void 0 ? void 0 : val.display_name} - empty schema`, this.config.auditContext);
403
550
  return false;
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')
551
+ }
552
+ 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') {
553
+ cli_utilities_1.log.debug(`Filtering out field ${val === null || val === void 0 ? void 0 : val.display_name} - empty reference_to`, this.config.auditContext);
405
554
  return false;
555
+ }
406
556
  return !!val;
407
557
  });
558
+ cli_utilities_1.log.debug(`Schema fix completed. ${(result === null || result === void 0 ? void 0 : result.length) || 0} fields remain after filtering`, this.config.auditContext);
559
+ return result;
408
560
  }
409
561
  /**
410
562
  * The function fixes global field references in a tree structure by adding missing references and
@@ -417,11 +569,14 @@ class ContentType {
417
569
  */
418
570
  fixGlobalFieldReferences(tree, field) {
419
571
  var _a, _b;
572
+ cli_utilities_1.log.debug(`Fixing global field references for: ${field.display_name} (${field.uid})`, this.config.auditContext);
420
573
  const { reference_to, display_name, data_type } = field;
421
574
  if (reference_to && data_type === 'global_field') {
575
+ cli_utilities_1.log.debug(`Processing global field reference: ${reference_to}`, this.config.auditContext);
422
576
  tree = [...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }];
423
577
  const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
424
578
  if (!refExist) {
579
+ cli_utilities_1.log.debug(`Global field reference ${reference_to} not found, marking as fixed`, this.config.auditContext);
425
580
  this.missingRefs[this.currentUid].push({
426
581
  tree,
427
582
  data_type,
@@ -434,11 +589,14 @@ class ContentType {
434
589
  });
435
590
  }
436
591
  else if (!field.schema && this.moduleName === 'content-types') {
592
+ cli_utilities_1.log.debug(`Global field ${reference_to} found, copying schema to field`, this.config.auditContext);
437
593
  const gfSchema = (_a = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _a === void 0 ? void 0 : _a.schema;
438
594
  if (gfSchema) {
595
+ cli_utilities_1.log.debug(`Successfully copied schema from global field ${reference_to}`, this.config.auditContext);
439
596
  field.schema = gfSchema;
440
597
  }
441
598
  else {
599
+ cli_utilities_1.log.debug(`Global field ${reference_to} has no schema, marking as fixed`, this.config.auditContext);
442
600
  this.missingRefs[this.currentUid].push({
443
601
  tree,
444
602
  data_type,
@@ -452,11 +610,14 @@ class ContentType {
452
610
  }
453
611
  }
454
612
  else if (!field.schema && this.moduleName === 'global-fields') {
613
+ cli_utilities_1.log.debug(`Processing global field in global-fields module: ${reference_to}`, this.config.auditContext);
455
614
  const gfSchema = (_b = (0, find_1.default)(this.gfSchema, { uid: field.reference_to })) === null || _b === void 0 ? void 0 : _b.schema;
456
615
  if (gfSchema) {
616
+ cli_utilities_1.log.debug(`Successfully copied schema from global field ${reference_to}`, this.config.auditContext);
457
617
  field.schema = gfSchema;
458
618
  }
459
619
  else {
620
+ cli_utilities_1.log.debug(`Global field ${reference_to} has no schema, marking as fixed`, this.config.auditContext);
460
621
  this.missingRefs[this.currentUid].push({
461
622
  tree,
462
623
  data_type,
@@ -470,10 +631,14 @@ class ContentType {
470
631
  }
471
632
  }
472
633
  if (field.schema && !(0, isEmpty_1.default)(field.schema)) {
634
+ cli_utilities_1.log.debug(`Running recursive fix on global field schema: ${display_name}`, this.config.auditContext);
473
635
  field.schema = this.runFixOnSchema(tree, field.schema);
474
636
  }
475
- return refExist ? field : null;
637
+ const result = refExist ? field : null;
638
+ cli_utilities_1.log.debug(`Global field fix completed for ${display_name}. Result: ${result ? 'kept' : 'removed'}`, this.config.auditContext);
639
+ return result;
476
640
  }
641
+ cli_utilities_1.log.debug(`Skipping global field fix for ${display_name} - not a global field or no reference_to`, this.config.auditContext);
477
642
  return field;
478
643
  }
479
644
  /**
@@ -485,8 +650,10 @@ class ContentType {
485
650
  * @returns an array of `ModularBlockType` objects.
486
651
  */
487
652
  fixModularBlocksReferences(tree, blocks) {
488
- return blocks === null || blocks === void 0 ? void 0 : blocks.map((block) => {
489
- const { reference_to, schema, title: display_name } = block;
653
+ cli_utilities_1.log.debug(`Fixing modular blocks references for ${(blocks === null || blocks === void 0 ? void 0 : blocks.length) || 0} blocks`, this.config.auditContext);
654
+ const result = blocks === null || blocks === void 0 ? void 0 : blocks.map((block) => {
655
+ const { reference_to, schema, title: display_name, uid } = block;
656
+ cli_utilities_1.log.debug(`Processing modular block: ${display_name} (${uid})`, this.config.auditContext);
490
657
  tree = [...tree, { uid: block.uid, name: block.title }];
491
658
  const refErrorObj = {
492
659
  tree,
@@ -498,13 +665,16 @@ class ContentType {
498
665
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
499
666
  };
500
667
  if (!schema && this.moduleName === 'content-types') {
668
+ cli_utilities_1.log.debug(`Modular block ${display_name} has no schema, marking as fixed`, this.config.auditContext);
501
669
  this.missingRefs[this.currentUid].push(refErrorObj);
502
670
  return false;
503
671
  }
504
672
  // NOTE Global field section
505
673
  if (reference_to) {
674
+ cli_utilities_1.log.debug(`Checking global field reference ${reference_to} for block ${display_name}`, this.config.auditContext);
506
675
  const refExist = (0, find_1.default)(this.gfSchema, { uid: reference_to });
507
676
  if (!refExist) {
677
+ cli_utilities_1.log.debug(`Global field reference ${reference_to} not found for block ${display_name}`, this.config.auditContext);
508
678
  this.missingRefs[this.currentUid].push(refErrorObj);
509
679
  return false;
510
680
  }
@@ -513,14 +683,19 @@ class ContentType {
513
683
  return block;
514
684
  }
515
685
  }
686
+ cli_utilities_1.log.debug(`Running fix on block schema for: ${display_name}`, this.config.auditContext);
516
687
  block.schema = this.runFixOnSchema(tree, block.schema);
517
688
  if ((0, isEmpty_1.default)(block.schema) && this.moduleName === 'content-types') {
689
+ cli_utilities_1.log.debug(`Block ${display_name} became empty after fix`, this.config.auditContext);
518
690
  this.missingRefs[this.currentUid].push(Object.assign(Object.assign({}, refErrorObj), { missingRefs: 'Empty schema found', treeStr: tree.map(({ name }) => name).join(' ➜ ') }));
519
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
691
+ cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }));
520
692
  return null;
521
693
  }
694
+ cli_utilities_1.log.debug(`Block ${display_name} fix completed successfully`, this.config.auditContext);
522
695
  return block;
523
696
  }).filter((val) => val);
697
+ cli_utilities_1.log.debug(`Modular blocks fix completed. ${(result === null || result === void 0 ? void 0 : result.length) || 0} blocks remain`, this.config.auditContext);
698
+ return result;
524
699
  }
525
700
  /**
526
701
  * The function checks for missing extension or app references in a given tree and fixes them if the
@@ -532,12 +707,19 @@ class ContentType {
532
707
  * then `null` is returned. Otherwise, the `field` parameter is returned.
533
708
  */
534
709
  fixMissingExtensionOrApp(tree, field) {
710
+ cli_utilities_1.log.debug(`Fixing missing extension/app for field: ${field.display_name} (${field.uid})`, this.config.auditContext);
535
711
  const missingRefs = [];
536
712
  const { uid, extension_uid, data_type, display_name } = field;
713
+ cli_utilities_1.log.debug(`Checking if extension ${extension_uid} exists in loaded extensions`, this.config.auditContext);
537
714
  if (!this.extensions.includes(extension_uid)) {
715
+ cli_utilities_1.log.debug(`Extension ${extension_uid} not found, adding to missing refs`, this.config.auditContext);
538
716
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
539
717
  }
718
+ else {
719
+ cli_utilities_1.log.debug(`Extension ${extension_uid} found in loaded extensions`, this.config.auditContext);
720
+ }
540
721
  if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
722
+ cli_utilities_1.log.debug(`Fix mode enabled and missing refs found, marking as fixed`, this.config.auditContext);
541
723
  this.missingRefs[this.currentUid].push({
542
724
  tree,
543
725
  data_type,
@@ -550,6 +732,7 @@ class ContentType {
550
732
  });
551
733
  return null;
552
734
  }
735
+ cli_utilities_1.log.debug(`Extension/app fix completed for ${display_name}. Result: ${missingRefs.length > 0 ? 'issues found' : 'no issues'}`, this.config.auditContext);
553
736
  return field;
554
737
  }
555
738
  /**
@@ -562,40 +745,63 @@ class ContentType {
562
745
  * @returns the `field` object.
563
746
  */
564
747
  fixMissingReferences(tree, field) {
748
+ cli_utilities_1.log.debug(`Fixing missing references for field: ${field.display_name} (${field.uid})`, this.config.auditContext);
565
749
  let fixStatus;
566
750
  const missingRefs = [];
567
751
  const { reference_to, data_type, display_name } = field;
752
+ cli_utilities_1.log.debug(`Reference_to type: ${Array.isArray(reference_to) ? 'array' : 'single'}, value: ${JSON.stringify(reference_to)}`, this.config.auditContext);
568
753
  if (!Array.isArray(reference_to)) {
569
- this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'error');
570
- this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
754
+ cli_utilities_1.log.debug(`Processing single reference: ${reference_to}`, this.config.auditContext);
755
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), this.config.auditContext);
756
+ cli_utilities_1.log.info((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), this.config.auditContext);
571
757
  if (!this.config.skipRefs.includes(reference_to)) {
758
+ cli_utilities_1.log.debug(`Checking if reference ${reference_to} exists in content type schema`, this.config.auditContext);
572
759
  const refExist = (0, find_1.default)(this.ctSchema, { uid: reference_to });
573
760
  if (!refExist) {
761
+ cli_utilities_1.log.debug(`Reference ${reference_to} not found, adding to missing refs`, this.config.auditContext);
574
762
  missingRefs.push(reference_to);
575
763
  }
764
+ else {
765
+ cli_utilities_1.log.debug(`Reference ${reference_to} found in schema`, this.config.auditContext);
766
+ }
767
+ }
768
+ else {
769
+ cli_utilities_1.log.debug(`Skipping reference ${reference_to} - in skip list`, this.config.auditContext);
576
770
  }
771
+ cli_utilities_1.log.debug(`Converting single reference to array format`, this.config.auditContext);
577
772
  field.reference_to = [reference_to];
578
773
  field.field_metadata = Object.assign(Object.assign({}, field.field_metadata), { ref_multiple_content_types: true });
579
774
  }
580
775
  else {
776
+ cli_utilities_1.log.debug(`Processing ${(reference_to === null || reference_to === void 0 ? void 0 : reference_to.length) || 0} references in array`, this.config.auditContext);
581
777
  for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
582
778
  // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
583
779
  if (this.config.skipRefs.includes(reference)) {
780
+ cli_utilities_1.log.debug(`Skipping reference ${reference} - in skip list`, this.config.auditContext);
584
781
  continue;
585
782
  }
783
+ cli_utilities_1.log.debug(`Checking if reference ${reference} exists in content type schema`, this.config.auditContext);
586
784
  const refExist = (0, find_1.default)(this.ctSchema, { uid: reference });
587
785
  if (!refExist) {
786
+ cli_utilities_1.log.debug(`Reference ${reference} not found, adding to missing refs`, this.config.auditContext);
588
787
  missingRefs.push(reference);
589
788
  }
789
+ else {
790
+ cli_utilities_1.log.debug(`Reference ${reference} found in schema`, this.config.auditContext);
791
+ }
590
792
  }
591
793
  }
794
+ cli_utilities_1.log.debug(`Found ${missingRefs.length} missing references: ${missingRefs.join(', ')}`, this.config.auditContext);
592
795
  if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
796
+ cli_utilities_1.log.debug(`Fix mode enabled, removing missing references from field`, this.config.auditContext);
593
797
  try {
594
798
  field.reference_to = field.reference_to.filter((ref) => !missingRefs.includes(ref));
595
799
  fixStatus = 'Fixed';
800
+ cli_utilities_1.log.debug(`Successfully removed missing references. New reference_to: ${JSON.stringify(field.reference_to)}`, this.config.auditContext);
596
801
  }
597
802
  catch (error) {
598
803
  fixStatus = `Not Fixed (${JSON.stringify(error)})`;
804
+ cli_utilities_1.log.debug(`Failed to remove missing references: ${error}`, this.config.auditContext);
599
805
  }
600
806
  this.missingRefs[this.currentUid].push({
601
807
  tree,
@@ -608,6 +814,7 @@ class ContentType {
608
814
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
609
815
  });
610
816
  }
817
+ cli_utilities_1.log.debug(`Missing references fix completed for ${display_name}. Status: ${fixStatus || 'no fix needed'}`, this.config.auditContext);
611
818
  return field;
612
819
  }
613
820
  /**
@@ -619,9 +826,12 @@ class ContentType {
619
826
  * @returns The function `fixGroupField` returns either `null` or the `field` object.
620
827
  */
621
828
  fixGroupField(tree, field) {
829
+ cli_utilities_1.log.debug(`Fixing group field: ${field.display_name} (${field.uid})`, this.config.auditContext);
622
830
  const { data_type, display_name } = field;
831
+ cli_utilities_1.log.debug(`Running fix on group field schema for: ${display_name}`, this.config.auditContext);
623
832
  field.schema = this.runFixOnSchema(tree, field.schema);
624
833
  if ((0, isEmpty_1.default)(field.schema)) {
834
+ cli_utilities_1.log.debug(`Group field ${display_name} became empty after fix`, this.config.auditContext);
625
835
  this.missingRefs[this.currentUid].push({
626
836
  tree,
627
837
  data_type,
@@ -632,9 +842,10 @@ class ContentType {
632
842
  missingRefs: 'Empty schema found',
633
843
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
634
844
  });
635
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }), 'info');
845
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditFixMsg.EMPTY_FIX_MSG, { path: tree.map(({ name }) => name).join(' ➜ ') }));
636
846
  return null;
637
847
  }
848
+ cli_utilities_1.log.debug(`Group field fix completed successfully for: ${display_name}`, this.config.auditContext);
638
849
  return field;
639
850
  }
640
851
  }