@contentstack/cli-audit 1.14.2 → 1.16.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.
@@ -10,11 +10,10 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
10
10
  const fs_1 = require("fs");
11
11
  const content_types_1 = tslib_1.__importDefault(require("./content-types"));
12
12
  const messages_1 = require("../messages");
13
- const util_1 = require("../util");
14
13
  const global_fields_1 = tslib_1.__importDefault(require("./global-fields"));
15
14
  const lodash_1 = require("lodash");
16
15
  class Entries {
17
- constructor({ log, fix, config, moduleName, ctSchema, gfSchema }) {
16
+ constructor({ fix, config, moduleName, ctSchema, gfSchema }) {
18
17
  this.extensions = [];
19
18
  this.missingRefs = {};
20
19
  this.missingSelectFeild = {};
@@ -25,19 +24,26 @@ class Entries {
25
24
  this.environments = [];
26
25
  this.entryMetaData = [];
27
26
  this.moduleName = 'entries';
28
- this.log = log;
29
27
  this.config = config;
28
+ cli_utilities_1.log.debug(`Initializing Entries module`, this.config.auditContext);
30
29
  this.fix = fix !== null && fix !== void 0 ? fix : false;
31
30
  this.ctSchema = ctSchema;
32
31
  this.gfSchema = gfSchema;
33
32
  this.moduleName = this.validateModules(moduleName, this.config.moduleConfig);
34
33
  this.fileName = config.moduleConfig[this.moduleName].fileName;
35
34
  this.folderPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(config.basePath), (0, cli_utilities_1.sanitizePath)(config.moduleConfig.entries.dirName));
35
+ cli_utilities_1.log.debug(`Starting ${this.moduleName} audit process`, this.config.auditContext);
36
+ cli_utilities_1.log.debug(`Data directory: ${this.folderPath}`, this.config.auditContext);
37
+ cli_utilities_1.log.debug(`Fix mode: ${this.fix}`, this.config.auditContext);
36
38
  }
37
39
  validateModules(moduleName, moduleConfig) {
40
+ cli_utilities_1.log.debug(`Validating module: ${moduleName}`, this.config.auditContext);
41
+ cli_utilities_1.log.debug(`Available modules in config: ${Object.keys(moduleConfig).join(', ')}`, this.config.auditContext);
38
42
  if (Object.keys(moduleConfig).includes(moduleName)) {
43
+ cli_utilities_1.log.debug(`Module ${moduleName} found in config, returning: ${moduleName}`, this.config.auditContext);
39
44
  return moduleName;
40
45
  }
46
+ cli_utilities_1.log.debug(`Module ${moduleName} not found in config, defaulting to: entries`, this.config.auditContext);
41
47
  return 'entries';
42
48
  }
43
49
  /**
@@ -46,22 +52,36 @@ class Entries {
46
52
  * @returns the `missingRefs` object.
47
53
  */
48
54
  async run() {
49
- var _a, _b, _c, _d, _e, _f;
55
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
50
56
  if (!(0, fs_1.existsSync)(this.folderPath)) {
51
- this.log(`Skipping ${this.moduleName} audit`, 'warn');
52
- this.log((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
57
+ cli_utilities_1.log.debug(`Skipping ${this.moduleName} audit - path does not exist`, this.config.auditContext);
58
+ cli_utilities_1.log.warn(`Skipping ${this.moduleName} audit`, this.config.auditContext);
59
+ cli_utilities_1.cliux.print((0, messages_1.$t)(messages_1.auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' });
53
60
  return {};
54
61
  }
62
+ cli_utilities_1.log.debug(`Found ${((_a = this.ctSchema) === null || _a === void 0 ? void 0 : _a.length) || 0} content types to audit`, this.config.auditContext);
63
+ cli_utilities_1.log.debug(`Found ${((_b = this.locales) === null || _b === void 0 ? void 0 : _b.length) || 0} locales to process`, this.config.auditContext);
64
+ cli_utilities_1.log.debug('Preparing entry metadata', this.config.auditContext);
55
65
  await this.prepareEntryMetaData();
66
+ cli_utilities_1.log.debug(`Entry metadata prepared: ${this.entryMetaData.length} entries found`, this.config.auditContext);
67
+ cli_utilities_1.log.debug('Fixing prerequisite data', this.config.auditContext);
56
68
  await this.fixPrerequisiteData();
69
+ cli_utilities_1.log.debug('Prerequisite data fix completed', this.config.auditContext);
70
+ cli_utilities_1.log.debug(`Processing ${this.locales.length} locales and ${this.ctSchema.length} content types`, this.config.auditContext);
57
71
  for (const { code } of this.locales) {
72
+ cli_utilities_1.log.debug(`Processing locale: ${code}`, this.config.auditContext);
58
73
  for (const ctSchema of this.ctSchema) {
74
+ cli_utilities_1.log.debug(`Processing content type: ${ctSchema.uid} in locale ${code}`, this.config.auditContext);
59
75
  const basePath = (0, path_1.join)(this.folderPath, ctSchema.uid, code);
76
+ cli_utilities_1.log.debug(`Base path for entries: ${basePath}`, this.config.auditContext);
60
77
  const fsUtility = new cli_utilities_1.FsUtility({ basePath, indexFileName: 'index.json', createDirIfNotExist: false });
61
78
  const indexer = fsUtility.indexFileContent;
79
+ cli_utilities_1.log.debug(`Found ${Object.keys(indexer).length} entry files to process`, this.config.auditContext);
62
80
  for (const fileIndex in indexer) {
81
+ cli_utilities_1.log.debug(`Processing entry file: ${indexer[fileIndex]}`, this.config.auditContext);
63
82
  const entries = (await fsUtility.readChunkFiles.next());
64
83
  this.entries = entries;
84
+ cli_utilities_1.log.debug(`Loaded ${Object.keys(entries).length} entries from file`, this.config.auditContext);
65
85
  for (const entryUid in this.entries) {
66
86
  const entry = this.entries[entryUid];
67
87
  const { uid, title } = entry;
@@ -70,6 +90,7 @@ class Entries {
70
90
  if (this.currentTitle) {
71
91
  this.currentTitle = this.removeEmojiAndImages(this.currentTitle);
72
92
  }
93
+ cli_utilities_1.log.debug(`Processing entry - title:${this.currentTitle} with uid:(${uid})`, this.config.auditContext);
73
94
  if (!this.missingRefs[this.currentUid]) {
74
95
  this.missingRefs[this.currentUid] = [];
75
96
  }
@@ -80,39 +101,49 @@ class Entries {
80
101
  this.missingMandatoryFields[this.currentUid] = [];
81
102
  }
82
103
  if (this.fix) {
104
+ cli_utilities_1.log.debug(`Removing missing keys from entry ${uid}`, this.config.auditContext);
83
105
  this.removeMissingKeysOnEntry(ctSchema.schema, this.entries[entryUid]);
84
106
  }
107
+ cli_utilities_1.log.debug(`Looking for references in entry ${uid}`, this.config.auditContext);
85
108
  this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(this.currentTitle) }], ctSchema, this.entries[entryUid]);
86
- if ((_a = this.missingRefs[this.currentUid]) === null || _a === void 0 ? void 0 : _a.length) {
109
+ if ((_c = this.missingRefs[this.currentUid]) === null || _c === void 0 ? void 0 : _c.length) {
110
+ cli_utilities_1.log.debug(`Found ${this.missingRefs[this.currentUid].length} missing references for entry ${uid}`, this.config.auditContext);
87
111
  this.missingRefs[this.currentUid].forEach((entry) => {
88
112
  entry.ct = ctSchema.uid;
89
113
  entry.locale = code;
90
114
  });
91
115
  }
92
- if ((_b = this.missingSelectFeild[this.currentUid]) === null || _b === void 0 ? void 0 : _b.length) {
116
+ if ((_d = this.missingSelectFeild[this.currentUid]) === null || _d === void 0 ? void 0 : _d.length) {
117
+ cli_utilities_1.log.debug(`Found ${this.missingSelectFeild[this.currentUid].length} missing select fields for entry ${uid}`, this.config.auditContext);
93
118
  this.missingSelectFeild[this.currentUid].forEach((entry) => {
94
119
  entry.ct = ctSchema.uid;
95
120
  entry.locale = code;
96
121
  });
97
122
  }
98
- if ((_c = this.missingMandatoryFields[this.currentUid]) === null || _c === void 0 ? void 0 : _c.length) {
123
+ if ((_e = this.missingMandatoryFields[this.currentUid]) === null || _e === void 0 ? void 0 : _e.length) {
124
+ cli_utilities_1.log.debug(`Found ${this.missingMandatoryFields[this.currentUid].length} missing mandatory fields for entry ${uid}`, this.config.auditContext);
99
125
  this.missingMandatoryFields[this.currentUid].forEach((entry) => {
100
126
  entry.ct = ctSchema.uid;
101
127
  entry.locale = code;
102
128
  });
103
129
  }
104
130
  const fields = this.missingMandatoryFields[uid];
105
- const isPublished = ((_d = entry.publish_details) === null || _d === void 0 ? void 0 : _d.length) > 0;
131
+ const isPublished = ((_f = entry.publish_details) === null || _f === void 0 ? void 0 : _f.length) > 0;
132
+ cli_utilities_1.log.debug(`Entry ${uid} published status: ${isPublished}, missing mandatory fields: ${(fields === null || fields === void 0 ? void 0 : fields.length) || 0}`, this.config.auditContext);
106
133
  if ((this.fix && fields.length && isPublished) || (!this.fix && fields)) {
107
134
  const fixStatus = this.fix ? 'Fixed' : '';
108
- fields === null || fields === void 0 ? void 0 : fields.forEach((field) => {
135
+ cli_utilities_1.log.debug(`Applying fix status: ${fixStatus} to ${fields.length} fields`, this.config.auditContext);
136
+ fields === null || fields === void 0 ? void 0 : fields.forEach((field, index) => {
137
+ cli_utilities_1.log.debug(`Processing field ${index + 1}/${fields.length}`, this.config.auditContext);
109
138
  field.isPublished = isPublished;
110
139
  if (this.fix && isPublished) {
111
140
  field.fixStatus = fixStatus;
141
+ cli_utilities_1.log.debug(`Field ${index + 1} marked as published and fixed`, this.config.auditContext);
112
142
  }
113
143
  });
114
144
  if (this.fix && isPublished) {
115
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_MANDATORY_FIELD_FIX, { uid, locale: code }), 'error');
145
+ cli_utilities_1.log.debug(`Fixing mandatory field issue for entry ${uid}`, this.config.auditContext);
146
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_MANDATORY_FIELD_FIX, { uid, locale: code }), this.config.auditContext);
116
147
  entry.publish_details = [];
117
148
  }
118
149
  }
@@ -120,23 +151,30 @@ class Entries {
120
151
  delete this.missingMandatoryFields[uid];
121
152
  }
122
153
  const localKey = this.locales.map((locale) => locale.code);
123
- if (((_e = this.entries[entryUid]) === null || _e === void 0 ? void 0 : _e.publish_details) && !Array.isArray(this.entries[entryUid].publish_details)) {
124
- this.log((0, messages_1.$t)(messages_1.auditMsg.ENTRY_PUBLISH_DETAILS_NOT_EXIST, { uid: entryUid }), { color: 'red' });
154
+ cli_utilities_1.log.debug(`Available locales: ${localKey.join(', ')}, environments: ${this.environments.join(', ')}`, this.config.auditContext);
155
+ if (((_g = this.entries[entryUid]) === null || _g === void 0 ? void 0 : _g.publish_details) && !Array.isArray(this.entries[entryUid].publish_details)) {
156
+ cli_utilities_1.log.debug(`Entry ${entryUid} has invalid publish_details format`, this.config.auditContext);
157
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.ENTRY_PUBLISH_DETAILS_NOT_EXIST, { uid: entryUid }), this.config.auditContext);
125
158
  }
126
- this.entries[entryUid].publish_details = (_f = this.entries[entryUid]) === null || _f === void 0 ? void 0 : _f.publish_details.filter((pd) => {
159
+ const originalPublishDetails = ((_j = (_h = this.entries[entryUid]) === null || _h === void 0 ? void 0 : _h.publish_details) === null || _j === void 0 ? void 0 : _j.length) || 0;
160
+ this.entries[entryUid].publish_details = (_k = this.entries[entryUid]) === null || _k === void 0 ? void 0 : _k.publish_details.filter((pd) => {
127
161
  var _a;
162
+ cli_utilities_1.log.debug(`Checking publish detail: locale=${pd.locale}, environment=${pd.environment}`, this.config.auditContext);
128
163
  if ((localKey === null || localKey === void 0 ? void 0 : localKey.includes(pd.locale)) && ((_a = this.environments) === null || _a === void 0 ? void 0 : _a.includes(pd.environment))) {
164
+ cli_utilities_1.log.debug(`Publish detail valid for entry ${entryUid}: locale=${pd.locale}, environment=${pd.environment}`, this.config.auditContext);
129
165
  return true;
130
166
  }
131
167
  else {
132
- this.log((0, messages_1.$t)(messages_1.auditMsg.ENTRY_PUBLISH_DETAILS, {
168
+ cli_utilities_1.log.debug(`Publish detail invalid for entry ${entryUid}: locale=${pd.locale}, environment=${pd.environment}`, this.config.auditContext);
169
+ cli_utilities_1.log.debug((0, messages_1.$t)(messages_1.auditMsg.ENTRY_PUBLISH_DETAILS, {
133
170
  uid: entryUid,
134
171
  ctuid: ctSchema.uid,
135
172
  locale: code,
136
173
  publocale: pd.locale,
137
174
  environment: pd.environment,
138
- }), { color: 'red' });
175
+ }), this.config.auditContext);
139
176
  if (!Object.keys(this.missingEnvLocale).includes(entryUid)) {
177
+ cli_utilities_1.log.debug(`Creating new missing environment/locale entry for ${entryUid}`, this.config.auditContext);
140
178
  this.missingEnvLocale[entryUid] = [
141
179
  {
142
180
  entry_uid: entryUid,
@@ -148,6 +186,7 @@ class Entries {
148
186
  ];
149
187
  }
150
188
  else {
189
+ cli_utilities_1.log.debug(`Adding to existing missing environment/locale entry for ${entryUid}`, this.config.auditContext);
151
190
  this.missingEnvLocale[entryUid].push({
152
191
  entry_uid: entryUid,
153
192
  publish_locale: pd.locale,
@@ -159,23 +198,26 @@ class Entries {
159
198
  return false;
160
199
  }
161
200
  });
201
+ const remainingPublishDetails = ((_l = this.entries[entryUid].publish_details) === null || _l === void 0 ? void 0 : _l.length) || 0;
202
+ cli_utilities_1.log.debug(`Entry ${entryUid} publish details: ${originalPublishDetails} -> ${remainingPublishDetails}`, this.config.auditContext);
162
203
  const message = (0, messages_1.$t)(messages_1.auditMsg.SCAN_ENTRY_SUCCESS_MSG, {
163
204
  title,
164
205
  local: code,
165
206
  module: this.config.moduleConfig.entries.name,
166
207
  });
167
- this.log(message, 'hidden');
168
- (0, util_1.print)([{ message: `info: ${message}`, color: 'green' }]);
208
+ cli_utilities_1.log.debug(message, this.config.auditContext);
209
+ cli_utilities_1.log.info(message, this.config.auditContext);
169
210
  }
170
211
  if (this.fix) {
212
+ cli_utilities_1.log.debug(`Writing fix content for ${Object.keys(this.entries).length} entries`, this.config.auditContext);
171
213
  await this.writeFixContent(`${basePath}/${indexer[fileIndex]}`, this.entries);
172
214
  }
173
215
  }
174
216
  }
175
217
  }
176
- // this.log('', 'info'); // Adding empty line
218
+ cli_utilities_1.log.debug('Cleaning up empty missing references', this.config.auditContext);
177
219
  this.removeEmptyVal();
178
- return {
220
+ const result = {
179
221
  missingEntryRefs: this.missingRefs,
180
222
  missingSelectFeild: this.missingSelectFeild,
181
223
  missingMandatoryFields: this.missingMandatoryFields,
@@ -183,67 +225,106 @@ class Entries {
183
225
  missingEnvLocale: this.missingEnvLocale,
184
226
  missingMultipleFields: this.missingMultipleField,
185
227
  };
228
+ cli_utilities_1.log.debug(`Entries audit completed. Found issues:`, this.config.auditContext);
229
+ cli_utilities_1.log.debug(`- Missing references: ${Object.keys(this.missingRefs).length}`, this.config.auditContext);
230
+ cli_utilities_1.log.debug(`- Missing select fields: ${Object.keys(this.missingSelectFeild).length}`, this.config.auditContext);
231
+ cli_utilities_1.log.debug(`- Missing mandatory fields: ${Object.keys(this.missingMandatoryFields).length}`, this.config.auditContext);
232
+ cli_utilities_1.log.debug(`- Missing title fields: ${Object.keys(this.missingTitleFields).length}`, this.config.auditContext);
233
+ cli_utilities_1.log.debug(`- Missing environment/locale: ${Object.keys(this.missingEnvLocale).length}`, this.config.auditContext);
234
+ cli_utilities_1.log.debug(`- Missing multiple fields: ${Object.keys(this.missingMultipleField).length}`, this.config.auditContext);
235
+ return result;
186
236
  }
187
237
  /**
188
238
  * The function removes any properties from the `missingRefs` object that have an empty array value.
189
239
  */
190
240
  removeEmptyVal() {
241
+ cli_utilities_1.log.debug('Removing empty missing reference arrays', this.config.auditContext);
242
+ let removedRefs = 0;
191
243
  for (let propName in this.missingRefs) {
192
244
  if (!this.missingRefs[propName].length) {
245
+ cli_utilities_1.log.debug(`Removing empty missing references for entry: ${propName}`, this.config.auditContext);
193
246
  delete this.missingRefs[propName];
247
+ removedRefs++;
194
248
  }
195
249
  }
250
+ let removedSelectFields = 0;
196
251
  for (let propName in this.missingSelectFeild) {
197
252
  if (!this.missingSelectFeild[propName].length) {
253
+ cli_utilities_1.log.debug(`Removing empty missing select fields for entry: ${propName}`, this.config.auditContext);
198
254
  delete this.missingSelectFeild[propName];
255
+ removedSelectFields++;
199
256
  }
200
257
  }
258
+ let removedMandatoryFields = 0;
201
259
  for (let propName in this.missingMandatoryFields) {
202
260
  if (!this.missingMandatoryFields[propName].length) {
261
+ cli_utilities_1.log.debug(`Removing empty missing mandatory fields for entry: ${propName}`, this.config.auditContext);
203
262
  delete this.missingMandatoryFields[propName];
263
+ removedMandatoryFields++;
204
264
  }
205
265
  }
266
+ cli_utilities_1.log.debug(`Cleanup completed: removed ${removedRefs} empty refs, ${removedSelectFields} empty select fields, ${removedMandatoryFields} empty mandatory fields`, this.config.auditContext);
206
267
  }
207
268
  /**
208
269
  * The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
209
270
  * `gfSchema` properties using the `ContentType` class.
210
271
  */
211
272
  async fixPrerequisiteData() {
212
- var _a;
273
+ var _a, _b;
274
+ cli_utilities_1.log.debug('Starting prerequisite data fix process', this.config.auditContext);
275
+ cli_utilities_1.log.debug('Fixing content type schema', this.config.auditContext);
213
276
  this.ctSchema = (await new content_types_1.default({
214
277
  fix: true,
215
- log: () => { },
216
278
  config: this.config,
217
279
  moduleName: 'content-types',
218
280
  ctSchema: this.ctSchema,
219
281
  gfSchema: this.gfSchema,
220
282
  }).run(true));
283
+ cli_utilities_1.log.debug(`Content type schema fixed: ${this.ctSchema.length} schemas`, this.config.auditContext);
284
+ cli_utilities_1.log.debug('Fixing global field schema', this.config.auditContext);
221
285
  this.gfSchema = (await new global_fields_1.default({
222
286
  fix: true,
223
- log: () => { },
224
287
  config: this.config,
225
288
  moduleName: 'global-fields',
226
289
  ctSchema: this.ctSchema,
227
290
  gfSchema: this.gfSchema,
228
291
  }).run(true));
292
+ cli_utilities_1.log.debug(`Global field schema fixed: ${this.gfSchema.length} schemas`, this.config.auditContext);
229
293
  const extensionPath = (0, path_1.resolve)(this.config.basePath, 'extensions', 'extensions.json');
230
294
  const marketplacePath = (0, path_1.resolve)(this.config.basePath, 'marketplace_apps', 'marketplace_apps.json');
295
+ cli_utilities_1.log.debug(`Loading extensions from: ${extensionPath}`, this.config.auditContext);
231
296
  if ((0, fs_1.existsSync)(extensionPath)) {
232
297
  try {
233
298
  this.extensions = Object.keys(JSON.parse((0, fs_1.readFileSync)(extensionPath, 'utf8')));
299
+ cli_utilities_1.log.debug(`Loaded ${this.extensions.length} extensions`, this.config.auditContext);
300
+ }
301
+ catch (error) {
302
+ cli_utilities_1.log.debug(`Failed to load extensions: ${error}`, this.config.auditContext);
234
303
  }
235
- catch (error) { }
236
304
  }
305
+ else {
306
+ cli_utilities_1.log.debug('No extensions.json found', this.config.auditContext);
307
+ }
308
+ cli_utilities_1.log.debug(`Loading marketplace apps from: ${marketplacePath}`, this.config.auditContext);
237
309
  if ((0, fs_1.existsSync)(marketplacePath)) {
238
310
  try {
239
311
  const marketplaceApps = JSON.parse((0, fs_1.readFileSync)(marketplacePath, 'utf8'));
312
+ cli_utilities_1.log.debug(`Found ${marketplaceApps.length} marketplace apps`, this.config.auditContext);
240
313
  for (const app of marketplaceApps) {
241
314
  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);
242
315
  this.extensions.push(...metaData);
316
+ 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);
243
317
  }
244
318
  }
245
- catch (error) { }
319
+ catch (error) {
320
+ cli_utilities_1.log.debug(`Failed to load marketplace apps: ${error}`, this.config.auditContext);
321
+ }
246
322
  }
323
+ else {
324
+ cli_utilities_1.log.debug('No marketplace_apps.json found', this.config.auditContext);
325
+ }
326
+ cli_utilities_1.log.debug(`Total extensions loaded: ${this.extensions.length}`, this.config.auditContext);
327
+ cli_utilities_1.log.debug('Prerequisite data fix process completed', this.config.auditContext);
247
328
  }
248
329
  /**
249
330
  * The function checks if it can write the fix content to a file and if so, it writes the content as
@@ -251,15 +332,31 @@ class Entries {
251
332
  */
252
333
  async writeFixContent(filePath, schema) {
253
334
  var _a;
254
- let canWrite = true;
335
+ cli_utilities_1.log.debug(`Starting writeFixContent process for entries`, this.config.auditContext);
336
+ cli_utilities_1.log.debug(`Target file path: ${filePath}`, this.config.auditContext);
337
+ cli_utilities_1.log.debug(`Entries to write: ${Object.keys(schema).length}`, this.config.auditContext);
255
338
  if (this.fix) {
256
- if (!this.config.flags['copy-dir'] && !((_a = this.config.flags['external-config']) === null || _a === void 0 ? void 0 : _a.skipConfirm)) {
257
- canWrite = this.config.flags.yes || (await cli_utilities_1.cliux.confirm(messages_1.commonMsg.FIX_CONFIRMATION));
339
+ cli_utilities_1.log.debug('Fix mode enabled, checking write permissions', this.config.auditContext);
340
+ const skipConfirm = this.config.flags['copy-dir'] || ((_a = this.config.flags['external-config']) === null || _a === void 0 ? void 0 : _a.skipConfirm);
341
+ if (skipConfirm) {
342
+ cli_utilities_1.log.debug('Skipping confirmation due to copy-dir or external-config flags', this.config.auditContext);
343
+ }
344
+ else {
345
+ cli_utilities_1.log.debug('Asking user for confirmation to write fix content', this.config.auditContext);
258
346
  }
347
+ const canWrite = skipConfirm || this.config.flags.yes || (await cli_utilities_1.cliux.confirm(messages_1.commonMsg.FIX_CONFIRMATION));
259
348
  if (canWrite) {
349
+ cli_utilities_1.log.debug(`Writing fixed entries to: ${filePath}`, this.config.auditContext);
260
350
  (0, fs_1.writeFileSync)(filePath, JSON.stringify(schema));
351
+ cli_utilities_1.log.debug(`Successfully wrote ${Object.keys(schema).length} entries to file`, this.config.auditContext);
352
+ }
353
+ else {
354
+ cli_utilities_1.log.debug('User declined to write fix content', this.config.auditContext);
261
355
  }
262
356
  }
357
+ else {
358
+ cli_utilities_1.log.debug('Skipping writeFixContent - not in fix mode', this.config.auditContext);
359
+ }
263
360
  }
264
361
  /**
265
362
  * The function `lookForReference` iterates over a given schema and validates different field types
@@ -275,12 +372,18 @@ class Entries {
275
372
  */
276
373
  lookForReference(tree, field, entry) {
277
374
  var _a;
375
+ cli_utilities_1.log.debug(`Looking for references in field: ${field.uid || field.title || 'unknown'}`, this.config.auditContext);
376
+ const schemaFields = (_a = field === null || field === void 0 ? void 0 : field.schema) !== null && _a !== void 0 ? _a : [];
377
+ cli_utilities_1.log.debug(`Processing ${schemaFields.length} fields in schema`, this.config.auditContext);
278
378
  if (this.fix) {
379
+ cli_utilities_1.log.debug('Running fix on schema', this.config.auditContext);
279
380
  entry = this.runFixOnSchema(tree, field.schema, entry);
280
381
  }
281
- for (const child of (_a = field === null || field === void 0 ? void 0 : field.schema) !== null && _a !== void 0 ? _a : []) {
282
- const { uid, multiple, data_type } = child;
382
+ for (const child of schemaFields) {
383
+ const { uid, multiple, data_type, display_name } = child;
384
+ cli_utilities_1.log.debug(`Processing field: ${display_name} (${uid}) - ${data_type}`, this.config.auditContext);
283
385
  if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
386
+ cli_utilities_1.log.debug(`Field ${display_name} should be array but is not`, this.config.auditContext);
284
387
  if (!this.missingMultipleField[this.currentUid]) {
285
388
  this.missingMultipleField[this.currentUid] = [];
286
389
  }
@@ -297,41 +400,67 @@ class Entries {
297
400
  .join(' ➜ '),
298
401
  });
299
402
  }
403
+ cli_utilities_1.log.debug(`Validating mandatory fields for: ${display_name}`, this.config.auditContext);
300
404
  this.missingMandatoryFields[this.currentUid].push(...this.validateMandatoryFields([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry));
301
405
  if (!(entry === null || entry === void 0 ? void 0 : entry[uid]) && !child.hasOwnProperty('display_type')) {
406
+ cli_utilities_1.log.debug(`Skipping field ${display_name} - no entry value and no display_type`, this.config.auditContext);
302
407
  continue;
303
408
  }
409
+ cli_utilities_1.log.debug(`Validating field type: ${data_type} for ${display_name}`, this.config.auditContext);
304
410
  switch (child.data_type) {
305
411
  case 'reference':
306
- this.missingRefs[this.currentUid].push(...this.validateReferenceField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]));
412
+ cli_utilities_1.log.debug(`Validating reference field: ${display_name}`, this.config.auditContext);
413
+ const refResults = this.validateReferenceField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
414
+ this.missingRefs[this.currentUid].push(...refResults);
415
+ cli_utilities_1.log.debug(`Found ${refResults.length} missing references in field: ${display_name}`, this.config.auditContext);
307
416
  break;
308
417
  case 'global_field':
309
- this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
418
+ cli_utilities_1.log.debug(`Validating global field: ${display_name}`, this.config.auditContext);
419
+ if (child.multiple && Array.isArray(entry[uid])) {
420
+ cli_utilities_1.log.debug(`Processing ${entry[uid].length} multiple global field entries`, this.config.auditContext);
421
+ entry[uid].forEach((globalFieldEntry, index) => {
422
+ cli_utilities_1.log.debug(`Processing global field entry ${index}`, this.config.auditContext);
423
+ this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, globalFieldEntry);
424
+ });
425
+ }
426
+ else {
427
+ cli_utilities_1.log.debug(`Processing single global field entry`, this.config.auditContext);
428
+ this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
429
+ }
310
430
  break;
311
431
  case 'json':
312
432
  if ('extension' in child.field_metadata && child.field_metadata.extension) {
313
- this.missingRefs[this.currentUid].push(...this.validateExtensionAndAppField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry));
314
- // NOTE Custom field type
433
+ cli_utilities_1.log.debug(`Validating extension field: ${display_name}`, this.config.auditContext);
434
+ const extResults = this.validateExtensionAndAppField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry);
435
+ this.missingRefs[this.currentUid].push(...extResults);
436
+ cli_utilities_1.log.debug(`Found ${extResults.length} missing extension references in field: ${display_name}`, this.config.auditContext);
315
437
  }
316
438
  else if ('allow_json_rte' in child.field_metadata && child.field_metadata.allow_json_rte) {
317
439
  // NOTE JSON RTE field type
440
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${display_name}`, this.config.auditContext);
318
441
  this.validateJsonRTEFields([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
319
442
  }
320
443
  break;
321
444
  case 'blocks':
445
+ cli_utilities_1.log.debug(`Validating modular blocks field: ${display_name}`, this.config.auditContext);
322
446
  this.validateModularBlocksField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
323
447
  break;
324
448
  case 'group':
449
+ cli_utilities_1.log.debug(`Validating group field: ${display_name}`, this.config.auditContext);
325
450
  this.validateGroupField([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry[uid]);
326
451
  break;
327
452
  case 'text':
328
453
  case 'number':
329
454
  if (child.hasOwnProperty('display_type')) {
330
- this.missingSelectFeild[this.currentUid].push(...this.validateSelectField([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry[uid]));
455
+ cli_utilities_1.log.debug(`Validating select field: ${display_name}`, this.config.auditContext);
456
+ const selectResults = this.validateSelectField([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry[uid]);
457
+ this.missingSelectFeild[this.currentUid].push(...selectResults);
458
+ cli_utilities_1.log.debug(`Found ${selectResults.length} missing select field values in field: ${display_name}`, this.config.auditContext);
331
459
  }
332
460
  break;
333
461
  }
334
462
  }
463
+ cli_utilities_1.log.debug(`Field reference validation completed: ${field.uid || field.title || 'unknown'}`, this.config.auditContext);
335
464
  }
336
465
  /**
337
466
  * The function `validateReferenceField` validates the reference values of a given field in a tree
@@ -347,12 +476,16 @@ class Entries {
347
476
  * `tree`, `fieldStructure`, and `field`.
348
477
  */
349
478
  validateReferenceField(tree, fieldStructure, field) {
479
+ cli_utilities_1.log.debug(`Validating reference field: ${fieldStructure.display_name}`, this.config.auditContext);
350
480
  if (typeof field === 'string') {
481
+ cli_utilities_1.log.debug(`Converting string reference to JSON: ${field}`, this.config.auditContext);
351
482
  let stringReference = field;
352
483
  stringReference = stringReference.replace(/'/g, '"');
353
484
  field = JSON.parse(stringReference);
354
485
  }
355
- return this.validateReferenceValues(tree, fieldStructure, field);
486
+ const result = this.validateReferenceValues(tree, fieldStructure, field);
487
+ cli_utilities_1.log.debug(`Reference field validation completed: ${(result === null || result === void 0 ? void 0 : result.length) || 0} missing references found`, this.config.auditContext);
488
+ return result;
356
489
  }
357
490
  /**
358
491
  * The function `validateExtensionAndAppField` checks if a given field has a valid extension
@@ -368,17 +501,29 @@ class Entries {
368
501
  * references, an empty array is returned.
369
502
  */
370
503
  validateExtensionAndAppField(tree, fieldStructure, field) {
371
- if (this.fix)
504
+ cli_utilities_1.log.debug(`Validating extension/app field: ${fieldStructure.display_name}`, this.config.auditContext);
505
+ if (this.fix) {
506
+ cli_utilities_1.log.debug('Fix mode enabled, skipping extension/app validation', this.config.auditContext);
372
507
  return [];
508
+ }
373
509
  const missingRefs = [];
374
510
  let { uid, display_name, data_type } = fieldStructure || {};
511
+ cli_utilities_1.log.debug(`Checking extension/app field: ${uid}`, this.config.auditContext);
375
512
  if (field[uid]) {
376
513
  let { metadata: { extension_uid } = { extension_uid: '' } } = field[uid] || {};
514
+ cli_utilities_1.log.debug(`Found extension UID: ${extension_uid}`, this.config.auditContext);
377
515
  if (extension_uid && !this.extensions.includes(extension_uid)) {
516
+ cli_utilities_1.log.debug(`Missing extension: ${extension_uid}`, this.config.auditContext);
378
517
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
379
518
  }
519
+ else {
520
+ cli_utilities_1.log.debug(`Extension ${extension_uid} is valid`, this.config.auditContext);
521
+ }
522
+ }
523
+ else {
524
+ cli_utilities_1.log.debug(`No extension/app data found for field: ${uid}`, this.config.auditContext);
380
525
  }
381
- return missingRefs.length
526
+ const result = missingRefs.length
382
527
  ? [
383
528
  {
384
529
  tree,
@@ -394,6 +539,8 @@ class Entries {
394
539
  },
395
540
  ]
396
541
  : [];
542
+ cli_utilities_1.log.debug(`Extension/app field validation completed: ${result.length} missing references found`, this.config.auditContext);
543
+ return result;
397
544
  }
398
545
  /**
399
546
  * The function "validateGlobalField" is an asynchronous function that takes in a tree,
@@ -408,8 +555,11 @@ class Entries {
408
555
  * `EntryGlobalFieldDataType`. It represents a single global field entry.
409
556
  */
410
557
  validateGlobalField(tree, fieldStructure, field) {
558
+ cli_utilities_1.log.debug(`Validating global field: ${fieldStructure.display_name}`, this.config.auditContext);
559
+ cli_utilities_1.log.debug(`Global field UID: ${fieldStructure.uid}`, this.config.auditContext);
411
560
  // NOTE Any GlobalField related logic can be added here
412
561
  this.lookForReference(tree, fieldStructure, field);
562
+ cli_utilities_1.log.debug(`Global field validation completed for: ${fieldStructure.display_name}`, this.config.auditContext);
413
563
  }
414
564
  /**
415
565
  * The function `validateJsonRTEFields` is used to validate the JSON RTE fields by checking if the
@@ -424,18 +574,25 @@ class Entries {
424
574
  * such as `uid`, `attrs`, and `children`.
425
575
  */
426
576
  validateJsonRTEFields(tree, fieldStructure, field) {
427
- var _a;
577
+ var _a, _b;
578
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${fieldStructure.display_name}`, this.config.auditContext);
579
+ cli_utilities_1.log.debug(`JSON RTE field UID: ${fieldStructure.uid}`, this.config.auditContext);
580
+ cli_utilities_1.log.debug(`Found ${((_a = field === null || field === void 0 ? void 0 : field.children) === null || _a === void 0 ? void 0 : _a.length) || 0} children in JSON RTE field`, this.config.auditContext);
428
581
  // NOTE Other possible reference logic will be added related to JSON RTE (Ex missing assets, extensions etc.,)
429
- for (const index in (_a = field === null || field === void 0 ? void 0 : field.children) !== null && _a !== void 0 ? _a : []) {
582
+ for (const index in (_b = field === null || field === void 0 ? void 0 : field.children) !== null && _b !== void 0 ? _b : []) {
430
583
  const child = field.children[index];
431
584
  const { children } = child;
585
+ cli_utilities_1.log.debug(`Processing JSON RTE child ${index}`, this.config.auditContext);
432
586
  if (!this.fix) {
587
+ cli_utilities_1.log.debug(`Checking JSON RTE references for child ${index}`, this.config.auditContext);
433
588
  this.jsonRefCheck(tree, fieldStructure, child);
434
589
  }
435
590
  if (!(0, isEmpty_1.default)(children)) {
591
+ cli_utilities_1.log.debug(`Recursively validating JSON RTE children for child ${index}`, this.config.auditContext);
436
592
  this.validateJsonRTEFields(tree, fieldStructure, field.children[index]);
437
593
  }
438
594
  }
595
+ cli_utilities_1.log.debug(`JSON RTE field validation completed for: ${fieldStructure.display_name}`, this.config.auditContext);
439
596
  }
440
597
  /**
441
598
  * The function validates the modular blocks field by traversing each module and looking for
@@ -451,19 +608,28 @@ class Entries {
451
608
  * `EntryModularBlocksDataType`.
452
609
  */
453
610
  validateModularBlocksField(tree, fieldStructure, field) {
611
+ cli_utilities_1.log.debug(`Validating modular blocks field: ${fieldStructure.display_name}`, this.config.auditContext);
612
+ cli_utilities_1.log.debug(`Modular blocks field UID: ${fieldStructure.uid}`, this.config.auditContext);
613
+ cli_utilities_1.log.debug(`Found ${field.length} modular blocks`, this.config.auditContext);
614
+ cli_utilities_1.log.debug(`Available blocks: ${fieldStructure.blocks.map(b => b.title).join(', ')}`);
454
615
  if (!this.fix) {
616
+ cli_utilities_1.log.debug('Checking modular block references (non-fix mode)');
455
617
  for (const index in field) {
618
+ cli_utilities_1.log.debug(`Checking references for modular block ${index}`);
456
619
  this.modularBlockRefCheck(tree, fieldStructure.blocks, field[index], +index);
457
620
  }
458
621
  }
459
622
  for (const block of fieldStructure.blocks) {
460
623
  const { uid, title } = block;
624
+ cli_utilities_1.log.debug(`Processing block: ${title} (${uid})`);
461
625
  for (const eBlock of field) {
462
626
  if (eBlock[uid]) {
627
+ cli_utilities_1.log.debug(`Found entry block data for: ${title}`);
463
628
  this.lookForReference([...tree, { uid, name: title }], block, eBlock[uid]);
464
629
  }
465
630
  }
466
631
  }
632
+ cli_utilities_1.log.debug(`Modular blocks field validation completed for: ${fieldStructure.display_name}`);
467
633
  }
468
634
  /**
469
635
  * The function validates a group field by looking for a reference in a tree structure.
@@ -475,15 +641,22 @@ class Entries {
475
641
  * `EntryGroupFieldDataType` and represents a single group field entry.
476
642
  */
477
643
  validateGroupField(tree, fieldStructure, field) {
644
+ cli_utilities_1.log.debug(`Validating group field: ${fieldStructure.display_name}`);
645
+ cli_utilities_1.log.debug(`Group field UID: ${fieldStructure.uid}`);
646
+ cli_utilities_1.log.debug(`Group field type: ${Array.isArray(field) ? 'array' : 'single'}`);
478
647
  // NOTE Any Group Field related logic can be added here (Ex data serialization or picking any metadata for report etc.,)
479
648
  if (Array.isArray(field)) {
480
- field.forEach((eGroup) => {
649
+ cli_utilities_1.log.debug(`Processing ${field.length} group field entries`);
650
+ field.forEach((eGroup, index) => {
651
+ cli_utilities_1.log.debug(`Processing group field entry ${index}`);
481
652
  this.lookForReference([...tree, { uid: fieldStructure.uid, display_name: fieldStructure.display_name }], fieldStructure, eGroup);
482
653
  });
483
654
  }
484
655
  else {
656
+ cli_utilities_1.log.debug('Processing single group field entry');
485
657
  this.lookForReference(tree, fieldStructure, field);
486
658
  }
659
+ cli_utilities_1.log.debug(`Group field validation completed for: ${fieldStructure.display_name}`);
487
660
  }
488
661
  /**
489
662
  * The function `validateReferenceValues` checks if the references in a given field exist in the
@@ -501,16 +674,25 @@ class Entries {
501
674
  * objects.
502
675
  */
503
676
  validateReferenceValues(tree, fieldStructure, field) {
504
- if (this.fix)
677
+ cli_utilities_1.log.debug(`Validating reference values for field: ${fieldStructure.display_name}`);
678
+ if (this.fix) {
679
+ cli_utilities_1.log.debug('Fix mode enabled, skipping reference validation');
505
680
  return [];
681
+ }
506
682
  const missingRefs = [];
507
683
  const { uid: data_type, display_name, reference_to } = fieldStructure;
684
+ 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'}`);
686
+ cli_utilities_1.log.debug(`Found ${(field === null || field === void 0 ? void 0 : field.length) || 0} references to validate`);
508
687
  for (const index in field !== null && field !== void 0 ? field : []) {
509
688
  const reference = field[index];
510
689
  const { uid } = reference;
690
+ cli_utilities_1.log.debug(`Processing reference ${index}: ${uid || reference}`);
511
691
  if (!uid && reference.startsWith('blt')) {
692
+ cli_utilities_1.log.debug(`Checking reference: ${reference}`);
512
693
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
513
694
  if (!refExist) {
695
+ cli_utilities_1.log.debug(`Missing reference: ${reference}`);
514
696
  if (Array.isArray(reference_to) && reference_to.length === 1) {
515
697
  missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
516
698
  }
@@ -518,17 +700,25 @@ class Entries {
518
700
  missingRefs.push(reference);
519
701
  }
520
702
  }
703
+ else {
704
+ cli_utilities_1.log.debug(`Reference ${reference} is valid`);
705
+ }
521
706
  }
522
707
  // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
523
708
  // if (this.config.skipRefs.includes(reference)) continue;
524
709
  else {
710
+ cli_utilities_1.log.debug(`Checking standard reference: ${uid}`);
525
711
  const refExist = (0, find_1.default)(this.entryMetaData, { uid });
526
712
  if (!refExist) {
713
+ cli_utilities_1.log.debug(`Missing reference: ${uid}`);
527
714
  missingRefs.push(reference);
528
715
  }
716
+ else {
717
+ cli_utilities_1.log.debug(`Reference ${uid} is valid`);
718
+ }
529
719
  }
530
720
  }
531
- return missingRefs.length
721
+ const result = missingRefs.length
532
722
  ? [
533
723
  {
534
724
  tree,
@@ -544,17 +734,24 @@ class Entries {
544
734
  },
545
735
  ]
546
736
  : [];
737
+ cli_utilities_1.log.debug(`Reference values validation completed: ${result.length} missing references found`);
738
+ return result;
547
739
  }
548
740
  removeMissingKeysOnEntry(schema, entry) {
741
+ cli_utilities_1.log.debug(`Removing missing keys from entry: ${this.currentUid}`);
549
742
  // NOTE remove invalid entry keys
550
743
  const ctFields = (0, map_1.default)(schema, 'uid');
551
744
  const entryFields = Object.keys(entry !== null && entry !== void 0 ? entry : {});
745
+ cli_utilities_1.log.debug(`Content type fields: ${ctFields.length}, Entry fields: ${entryFields.length}`);
746
+ cli_utilities_1.log.debug(`System keys: ${this.config.entries.systemKeys.join(', ')}`);
552
747
  entryFields.forEach((eKey) => {
553
748
  // NOTE Key should not be system key and not exist in schema means it's invalid entry key
554
749
  if (!this.config.entries.systemKeys.includes(eKey) && !ctFields.includes(eKey)) {
750
+ cli_utilities_1.log.debug(`Removing invalid field: ${eKey}`);
555
751
  delete entry[eKey];
556
752
  }
557
753
  });
754
+ cli_utilities_1.log.debug(`Missing keys removal completed for entry: ${this.currentUid}`);
558
755
  }
559
756
  /**
560
757
  * The function `runFixOnSchema` takes in a tree, schema, and entry, and applies fixes to the entry
@@ -571,15 +768,20 @@ class Entries {
571
768
  * `schema`.
572
769
  */
573
770
  runFixOnSchema(tree, schema, entry) {
771
+ cli_utilities_1.log.debug(`Running fix on schema for entry: ${this.currentUid}`);
772
+ cli_utilities_1.log.debug(`Schema fields: ${schema.length}, Entry fields: ${Object.keys(entry).length}`);
574
773
  // NOTE Global field Fix
575
774
  schema.forEach((field) => {
576
775
  var _a;
577
776
  var _b, _c;
578
777
  const { uid, data_type, multiple } = field;
778
+ cli_utilities_1.log.debug(`Processing field: ${uid} (${data_type})`);
579
779
  if (!Object(entry).hasOwnProperty(uid)) {
780
+ cli_utilities_1.log.debug(`Field ${uid} not found in entry, skipping`);
580
781
  return;
581
782
  }
582
783
  if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
784
+ cli_utilities_1.log.debug(`Fixing multiple field: ${uid} - converting to array`);
583
785
  (_a = (_b = this.missingMultipleField)[_c = this.currentUid]) !== null && _a !== void 0 ? _a : (_b[_c] = []);
584
786
  this.missingMultipleField[this.currentUid].push({
585
787
  uid: this.currentUid,
@@ -598,41 +800,61 @@ class Entries {
598
800
  }
599
801
  switch (data_type) {
600
802
  case 'global_field':
601
- entry[uid] = this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
803
+ cli_utilities_1.log.debug(`Fixing global field: ${uid}`);
804
+ if (field.multiple && Array.isArray(entry[uid])) {
805
+ cli_utilities_1.log.debug(`Fixing ${entry[uid].length} multiple global field entries`, this.config.auditContext);
806
+ entry[uid] = entry[uid].map((globalFieldEntry, index) => {
807
+ cli_utilities_1.log.debug(`Fixing global field entry ${index}`, this.config.auditContext);
808
+ return this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, globalFieldEntry);
809
+ });
810
+ }
811
+ else {
812
+ cli_utilities_1.log.debug(`Fixing single global field entry`, this.config.auditContext);
813
+ entry[uid] = this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
814
+ }
602
815
  break;
603
816
  case 'json':
604
817
  case 'reference':
818
+ cli_utilities_1.log.debug(`Fixing ${data_type} field: ${uid}`);
605
819
  if (data_type === 'json') {
606
820
  if ('extension' in field.field_metadata && field.field_metadata.extension) {
607
821
  // NOTE Custom field type
822
+ cli_utilities_1.log.debug(`Fixing extension/app field: ${uid}`);
608
823
  this.fixMissingExtensionOrApp([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry);
609
824
  break;
610
825
  }
611
826
  else if ('allow_json_rte' in field.field_metadata && field.field_metadata.allow_json_rte) {
827
+ cli_utilities_1.log.debug(`Fixing JSON RTE field: ${uid}`);
612
828
  this.fixJsonRteMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
613
829
  break;
614
830
  }
615
831
  }
616
832
  // NOTE Reference field
833
+ cli_utilities_1.log.debug(`Fixing reference field: ${uid}`);
617
834
  entry[uid] = this.fixMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
618
835
  if (!entry[uid]) {
836
+ cli_utilities_1.log.debug(`Deleting empty reference field: ${uid}`);
619
837
  delete entry[uid];
620
838
  }
621
839
  break;
622
840
  case 'blocks':
841
+ cli_utilities_1.log.debug(`Fixing modular blocks field: ${uid}`);
623
842
  entry[uid] = this.fixModularBlocksReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field.blocks, entry[uid]);
624
843
  break;
625
844
  case 'group':
845
+ cli_utilities_1.log.debug(`Fixing group field: ${uid}`);
626
846
  entry[uid] = this.fixGroupField([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
627
847
  break;
628
848
  case 'text':
629
849
  case 'number':
630
850
  if (field.hasOwnProperty('display_type')) {
851
+ cli_utilities_1.log.debug(`Fixing select field: ${uid}`);
631
852
  entry[uid] = this.fixSelectField([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
632
853
  }
633
854
  break;
634
855
  }
635
856
  });
857
+ cli_utilities_1.log.debug(`Schema fix completed for entry: ${this.currentUid}`);
636
858
  return entry;
637
859
  }
638
860
  /**
@@ -648,11 +870,16 @@ class Entries {
648
870
  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, '');
649
871
  }
650
872
  validateSelectField(tree, fieldStructure, field) {
873
+ cli_utilities_1.log.debug(`Validating select field: ${fieldStructure.display_name}`);
874
+ cli_utilities_1.log.debug(`Select field UID: ${fieldStructure.uid}`);
875
+ cli_utilities_1.log.debug(`Field value: ${JSON.stringify(field)}`);
876
+ cli_utilities_1.log.debug(`Multiple: ${fieldStructure.multiple}, Display type: ${fieldStructure.display_type}`);
651
877
  const { display_name, enum: selectOptions, multiple, min_instance, display_type, data_type } = fieldStructure;
652
878
  if (field === null ||
653
879
  field === '' ||
654
880
  (Array.isArray(field) && field.length === 0) ||
655
881
  (!field && data_type !== 'number')) {
882
+ cli_utilities_1.log.debug(`Select field is empty or null: ${display_name}`);
656
883
  let missingCTSelectFieldValues = 'Not Selected';
657
884
  return [
658
885
  {
@@ -672,18 +899,32 @@ class Entries {
672
899
  }
673
900
  let missingCTSelectFieldValues;
674
901
  if (multiple) {
902
+ cli_utilities_1.log.debug(`Validating multiple select field: ${display_name}`);
675
903
  if (Array.isArray(field)) {
904
+ cli_utilities_1.log.debug(`Field is array with ${field.length} values`);
676
905
  let obj = this.findNotPresentSelectField(field, selectOptions);
677
906
  let { notPresent } = obj;
678
907
  if (notPresent.length) {
908
+ cli_utilities_1.log.debug(`Found ${notPresent.length} missing select values: ${notPresent.join(', ')}`);
679
909
  missingCTSelectFieldValues = notPresent;
680
910
  }
911
+ else {
912
+ cli_utilities_1.log.debug(`All select values are valid`);
913
+ }
681
914
  }
682
915
  }
683
- else if (!selectOptions.choices.some((choice) => choice.value === field)) {
684
- missingCTSelectFieldValues = field;
916
+ else {
917
+ cli_utilities_1.log.debug(`Validating single select field: ${display_name}`);
918
+ if (!selectOptions.choices.some((choice) => choice.value === field)) {
919
+ cli_utilities_1.log.debug(`Invalid select value: ${field}`);
920
+ missingCTSelectFieldValues = field;
921
+ }
922
+ else {
923
+ cli_utilities_1.log.debug(`Select value is valid: ${field}`);
924
+ }
685
925
  }
686
926
  if (display_type && missingCTSelectFieldValues) {
927
+ cli_utilities_1.log.debug(`Select field validation found issues: ${JSON.stringify(missingCTSelectFieldValues)}`);
687
928
  return [
688
929
  {
689
930
  uid: this.currentUid,
@@ -701,6 +942,7 @@ class Entries {
701
942
  ];
702
943
  }
703
944
  else {
945
+ cli_utilities_1.log.debug(`Select field validation completed successfully: ${display_name}`);
704
946
  return [];
705
947
  }
706
948
  }
@@ -715,56 +957,74 @@ class Entries {
715
957
  * @returns
716
958
  */
717
959
  fixSelectField(tree, field, entry) {
960
+ cli_utilities_1.log.debug(`Fixing select field: ${field.display_name}`);
961
+ cli_utilities_1.log.debug(`Select field UID: ${field.uid}`);
962
+ cli_utilities_1.log.debug(`Current entry value: ${JSON.stringify(entry)}`);
718
963
  if (!this.config.fixSelectField) {
964
+ cli_utilities_1.log.debug('Select field fixing is disabled in config');
719
965
  return entry;
720
966
  }
721
967
  const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
968
+ cli_utilities_1.log.debug(`Select options: ${selectOptions.choices.length} choices, Multiple: ${multiple}, Min instance: ${min_instance}`);
722
969
  let missingCTSelectFieldValues;
723
970
  let isMissingValuePresent = false;
724
971
  let selectedValue = '';
725
972
  if (multiple) {
973
+ cli_utilities_1.log.debug('Processing multiple select field', this.config.auditContext);
726
974
  let obj = this.findNotPresentSelectField(entry, selectOptions);
727
975
  let { notPresent, filteredFeild } = obj;
976
+ cli_utilities_1.log.debug(`Found ${notPresent.length} invalid values, filtered to ${filteredFeild.length} values`, this.config.auditContext);
728
977
  entry = filteredFeild;
729
978
  missingCTSelectFieldValues = notPresent;
730
979
  if (missingCTSelectFieldValues.length) {
731
980
  isMissingValuePresent = true;
981
+ cli_utilities_1.log.debug(`Missing values found: ${missingCTSelectFieldValues.join(', ')}`, this.config.auditContext);
732
982
  }
733
983
  if (min_instance && Array.isArray(entry)) {
734
984
  const missingInstances = min_instance - entry.length;
985
+ cli_utilities_1.log.debug(`Checking min instance requirement: ${min_instance}, current: ${entry.length}, missing: ${missingInstances}`, this.config.auditContext);
735
986
  if (missingInstances > 0) {
736
987
  isMissingValuePresent = true;
737
988
  const newValues = selectOptions.choices
738
989
  .filter((choice) => !entry.includes(choice.value))
739
990
  .slice(0, missingInstances)
740
991
  .map((choice) => choice.value);
992
+ cli_utilities_1.log.debug(`Adding ${newValues.length} values to meet min instance requirement: ${newValues.join(', ')}`, this.config.auditContext);
741
993
  entry.push(...newValues);
742
994
  selectedValue = newValues;
743
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), 'error');
995
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), this.config.auditContext);
744
996
  }
745
997
  }
746
998
  else {
747
999
  if (entry.length === 0) {
748
1000
  isMissingValuePresent = true;
749
1001
  const defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
1002
+ cli_utilities_1.log.debug(`Empty multiple select field, adding default value: ${defaultValue}`, this.config.auditContext);
750
1003
  entry.push(defaultValue);
751
1004
  selectedValue = defaultValue;
752
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
1005
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), this.config.auditContext);
753
1006
  }
754
1007
  }
755
1008
  }
756
1009
  else {
1010
+ cli_utilities_1.log.debug('Processing single select field', this.config.auditContext);
757
1011
  const isPresent = selectOptions.choices.some((choice) => choice.value === entry);
758
1012
  if (!isPresent) {
1013
+ cli_utilities_1.log.debug(`Invalid single select value: ${entry}`, this.config.auditContext);
759
1014
  missingCTSelectFieldValues = entry;
760
1015
  isMissingValuePresent = true;
761
1016
  let defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
1017
+ cli_utilities_1.log.debug(`Replacing with default value: ${defaultValue}`, this.config.auditContext);
762
1018
  entry = defaultValue;
763
1019
  selectedValue = defaultValue;
764
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
1020
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), this.config.auditContext);
1021
+ }
1022
+ else {
1023
+ cli_utilities_1.log.debug(`Single select value is valid: ${entry}`, this.config.auditContext);
765
1024
  }
766
1025
  }
767
1026
  if (display_type && isMissingValuePresent) {
1027
+ cli_utilities_1.log.debug(`Recording select field fix for entry: ${this.currentUid}`, this.config.auditContext);
768
1028
  this.missingSelectFeild[this.currentUid].push({
769
1029
  uid: this.currentUid,
770
1030
  name: this.currentTitle,
@@ -781,15 +1041,19 @@ class Entries {
781
1041
  fixStatus: 'Fixed',
782
1042
  });
783
1043
  }
1044
+ cli_utilities_1.log.debug(`Select field fix completed for: ${field.display_name}`);
784
1045
  return entry;
785
1046
  }
786
1047
  validateMandatoryFields(tree, fieldStructure, entry) {
1048
+ cli_utilities_1.log.debug(`Validating mandatory field: ${fieldStructure.display_name}`);
1049
+ cli_utilities_1.log.debug(`Field UID: ${fieldStructure.uid}, Mandatory: ${fieldStructure.mandatory}`);
787
1050
  const { display_name, multiple, data_type, mandatory, field_metadata, uid } = fieldStructure;
788
1051
  const isJsonRteEmpty = () => {
789
1052
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
790
1053
  const jsonNode = multiple
791
1054
  ? (_f = (_e = (_d = (_c = (_b = (_a = entry[uid]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.children) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.text
792
1055
  : (_l = (_k = (_j = (_h = (_g = entry[uid]) === null || _g === void 0 ? void 0 : _g.children) === null || _h === void 0 ? void 0 : _h[0]) === null || _j === void 0 ? void 0 : _j.children) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.text;
1056
+ cli_utilities_1.log.debug(`JSON RTE empty check: ${jsonNode === ''}`);
793
1057
  return jsonNode === '';
794
1058
  };
795
1059
  const isEntryEmpty = () => {
@@ -804,10 +1068,13 @@ class Entries {
804
1068
  if (Array.isArray(entry[uid]) && data_type === 'reference') {
805
1069
  fieldValue = ((_b = entry[uid]) === null || _b === void 0 ? void 0 : _b.length) ? true : false;
806
1070
  }
1071
+ cli_utilities_1.log.debug(`Entry empty check: ${fieldValue === '' || !fieldValue}`);
807
1072
  return fieldValue === '' || !fieldValue;
808
1073
  };
809
1074
  if (mandatory) {
1075
+ cli_utilities_1.log.debug(`Field is mandatory, checking if empty`);
810
1076
  if ((data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) || isEntryEmpty()) {
1077
+ cli_utilities_1.log.debug(`Mandatory field is empty: ${display_name}`);
811
1078
  return [
812
1079
  {
813
1080
  uid: this.currentUid,
@@ -822,7 +1089,14 @@ class Entries {
822
1089
  },
823
1090
  ];
824
1091
  }
1092
+ else {
1093
+ cli_utilities_1.log.debug(`Mandatory field has value: ${display_name}`);
1094
+ }
825
1095
  }
1096
+ else {
1097
+ cli_utilities_1.log.debug(`Field is not mandatory: ${display_name}`);
1098
+ }
1099
+ cli_utilities_1.log.debug(`Mandatory field validation completed: ${display_name}`);
826
1100
  return [];
827
1101
  }
828
1102
  /**
@@ -832,21 +1106,30 @@ class Entries {
832
1106
  * @returns An Array of entry containing only the values that were present in CT, An array of not present entries
833
1107
  */
834
1108
  findNotPresentSelectField(field, selectOptions) {
1109
+ cli_utilities_1.log.debug(`Finding not present select field values`);
1110
+ cli_utilities_1.log.debug(`Field values: ${JSON.stringify(field)}`);
1111
+ cli_utilities_1.log.debug(`Available choices: ${selectOptions.choices.length}`);
835
1112
  if (!field) {
1113
+ cli_utilities_1.log.debug('Field is null/undefined, initializing as empty array');
836
1114
  field = [];
837
1115
  }
838
1116
  let present = [];
839
1117
  let notPresent = [];
840
1118
  const choicesMap = new Map(selectOptions.choices.map((choice) => [choice.value, choice]));
1119
+ cli_utilities_1.log.debug(`Created choices map with ${choicesMap.size} entries`);
841
1120
  for (const value of field) {
842
1121
  const choice = choicesMap.get(value);
1122
+ cli_utilities_1.log.debug(`Checking value: ${value}`);
843
1123
  if (choice) {
1124
+ cli_utilities_1.log.debug(`Value ${value} is present in choices`);
844
1125
  present.push(choice.value);
845
1126
  }
846
1127
  else {
1128
+ cli_utilities_1.log.debug(`Value ${value} is not present in choices`);
847
1129
  notPresent.push(value);
848
1130
  }
849
1131
  }
1132
+ cli_utilities_1.log.debug(`Result: ${present.length} present, ${notPresent.length} not present`);
850
1133
  return { filteredFeild: present, notPresent };
851
1134
  }
852
1135
  /**
@@ -861,7 +1144,13 @@ class Entries {
861
1144
  * `field.schema`, and `entry` as arguments.
862
1145
  */
863
1146
  fixGlobalFieldReferences(tree, field, entry) {
864
- return this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
1147
+ var _a;
1148
+ cli_utilities_1.log.debug(`Fixing global field references: ${field.display_name}`);
1149
+ cli_utilities_1.log.debug(`Global field UID: ${field.uid}`);
1150
+ cli_utilities_1.log.debug(`Schema fields: ${((_a = field.schema) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
1151
+ const result = this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
1152
+ cli_utilities_1.log.debug(`Global field references fix completed: ${field.display_name}`);
1153
+ return result;
865
1154
  }
866
1155
  /**
867
1156
  * The function `fixModularBlocksReferences` takes in a tree, a list of blocks, and an entry, and
@@ -876,17 +1165,33 @@ class Entries {
876
1165
  * @returns the updated `entry` array after performing some modifications.
877
1166
  */
878
1167
  fixModularBlocksReferences(tree, blocks, entry) {
879
- entry = entry === null || entry === void 0 ? void 0 : entry.map((block, index) => this.modularBlockRefCheck(tree, blocks, block, index)).filter((val) => !(0, isEmpty_1.default)(val));
1168
+ cli_utilities_1.log.debug(`Fixing modular blocks references`);
1169
+ cli_utilities_1.log.debug(`Available blocks: ${blocks.length}, Entry blocks: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0}`);
1170
+ entry = entry === null || entry === void 0 ? void 0 : entry.map((block, index) => {
1171
+ cli_utilities_1.log.debug(`Checking modular block ${index}`);
1172
+ return this.modularBlockRefCheck(tree, blocks, block, index);
1173
+ }).filter((val) => {
1174
+ const isEmpty = !val || Object.keys(val).length === 0;
1175
+ cli_utilities_1.log.debug(`Block ${val ? 'kept' : 'filtered out'} (empty: ${isEmpty})`);
1176
+ return !isEmpty;
1177
+ });
880
1178
  blocks.forEach((block) => {
1179
+ cli_utilities_1.log.debug(`Processing block: ${block.title} (${block.uid})`);
881
1180
  entry = entry === null || entry === void 0 ? void 0 : entry.map((eBlock) => {
882
1181
  if (!(0, isEmpty_1.default)(block.schema)) {
883
1182
  if (eBlock[block.uid]) {
1183
+ cli_utilities_1.log.debug(`Fixing schema for block: ${block.title}`);
884
1184
  eBlock[block.uid] = this.runFixOnSchema([...tree, { uid: block.uid, display_name: block.title }], block.schema, eBlock[block.uid]);
885
1185
  }
886
1186
  }
887
1187
  return eBlock;
888
- }).filter((val) => !(0, isEmpty_1.default)(val));
1188
+ }).filter((val) => {
1189
+ const isEmpty = !val || Object.keys(val).length === 0;
1190
+ cli_utilities_1.log.debug(`Entry block ${val ? 'kept' : 'filtered out'} (empty: ${isEmpty})`);
1191
+ return !isEmpty;
1192
+ });
889
1193
  });
1194
+ cli_utilities_1.log.debug(`Modular blocks references fix completed: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0} blocks remaining`);
890
1195
  return entry;
891
1196
  }
892
1197
  /**
@@ -903,15 +1208,26 @@ class Entries {
903
1208
  * @returns the `field` parameter.
904
1209
  */
905
1210
  fixMissingExtensionOrApp(tree, field, entry) {
1211
+ cli_utilities_1.log.debug(`Fixing missing extension/app: ${field.display_name}`);
1212
+ cli_utilities_1.log.debug(`Extension/app field UID: ${field.uid}`);
906
1213
  const missingRefs = [];
907
1214
  let { uid, display_name, data_type } = field || {};
908
1215
  if (entry[uid]) {
909
1216
  let { metadata: { extension_uid } = { extension_uid: '' } } = entry[uid] || {};
1217
+ cli_utilities_1.log.debug(`Found extension UID: ${extension_uid}`);
910
1218
  if (extension_uid && !this.extensions.includes(extension_uid)) {
1219
+ cli_utilities_1.log.debug(`Missing extension: ${extension_uid}`, this.config.auditContext);
911
1220
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
912
1221
  }
1222
+ else {
1223
+ cli_utilities_1.log.debug(`Extension ${extension_uid} is valid`, this.config.auditContext);
1224
+ }
1225
+ }
1226
+ else {
1227
+ cli_utilities_1.log.debug(`No extension/app data found for field: ${uid}`, this.config.auditContext);
913
1228
  }
914
1229
  if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
1230
+ cli_utilities_1.log.debug(`Recording extension/app fix for entry: ${this.currentUid}`);
915
1231
  this.missingRefs[this.currentUid].push({
916
1232
  tree,
917
1233
  data_type,
@@ -922,8 +1238,10 @@ class Entries {
922
1238
  name: this.currentTitle,
923
1239
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
924
1240
  });
1241
+ cli_utilities_1.log.debug(`Deleting invalid extension/app field: ${uid}`);
925
1242
  delete entry[uid];
926
1243
  }
1244
+ cli_utilities_1.log.debug(`Extension/app fix completed for: ${field.display_name}`);
927
1245
  return field;
928
1246
  }
929
1247
  /**
@@ -941,16 +1259,29 @@ class Entries {
941
1259
  * Otherwise, it will return the `entry` as is.
942
1260
  */
943
1261
  fixGroupField(tree, field, entry) {
1262
+ var _a;
1263
+ cli_utilities_1.log.debug(`Fixing group field: ${field.display_name}`);
1264
+ cli_utilities_1.log.debug(`Group field UID: ${field.uid}`);
1265
+ cli_utilities_1.log.debug(`Schema fields: ${((_a = field.schema) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
1266
+ cli_utilities_1.log.debug(`Entry type: ${Array.isArray(entry) ? 'array' : 'single'}`);
944
1267
  if (!(0, isEmpty_1.default)(field.schema)) {
1268
+ cli_utilities_1.log.debug(`Group field has schema, applying fixes`);
945
1269
  if (Array.isArray(entry)) {
946
- entry = entry.map((eGroup) => {
1270
+ cli_utilities_1.log.debug(`Processing ${entry.length} group field entries`);
1271
+ entry = entry.map((eGroup, index) => {
1272
+ cli_utilities_1.log.debug(`Fixing group field entry ${index}`);
947
1273
  return this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, eGroup);
948
1274
  });
949
1275
  }
950
1276
  else {
1277
+ cli_utilities_1.log.debug(`Processing single group field entry`);
951
1278
  entry = this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
952
1279
  }
953
1280
  }
1281
+ else {
1282
+ cli_utilities_1.log.debug(`Group field has no schema, skipping fixes`);
1283
+ }
1284
+ cli_utilities_1.log.debug(`Group field fix completed for: ${field.display_name}`);
954
1285
  return entry;
955
1286
  }
956
1287
  /**
@@ -964,26 +1295,45 @@ class Entries {
964
1295
  * @returns the updated `entry` object with fixed missing references in the `children` property.
965
1296
  */
966
1297
  fixJsonRteMissingReferences(tree, field, entry) {
1298
+ cli_utilities_1.log.debug(`Fixing JSON RTE missing references`);
1299
+ cli_utilities_1.log.debug(`Field UID: ${field.uid}`);
1300
+ cli_utilities_1.log.debug(`Entry type: ${Array.isArray(entry) ? 'array' : 'single'}`);
967
1301
  if (Array.isArray(entry)) {
1302
+ cli_utilities_1.log.debug(`Processing ${entry.length} JSON RTE entries`);
968
1303
  entry = entry.map((child, index) => {
1304
+ cli_utilities_1.log.debug(`Fixing JSON RTE entry ${index}: ${(child === null || child === void 0 ? void 0 : child.type) || 'unknown type'}`);
969
1305
  return this.fixJsonRteMissingReferences([...tree, { index, type: child === null || child === void 0 ? void 0 : child.type, uid: child === null || child === void 0 ? void 0 : child.uid }], field, child);
970
1306
  });
971
1307
  }
972
1308
  else {
973
1309
  if (entry === null || entry === void 0 ? void 0 : entry.children) {
1310
+ cli_utilities_1.log.debug(`Processing ${entry.children.length} JSON RTE children`);
974
1311
  entry.children = entry.children
975
- .map((child) => {
1312
+ .map((child, index) => {
1313
+ cli_utilities_1.log.debug(`Checking JSON RTE child ${index}: ${child.type || 'unknown type'}`);
976
1314
  const refExist = this.jsonRefCheck(tree, field, child);
977
- if (!refExist)
1315
+ if (!refExist) {
1316
+ cli_utilities_1.log.debug(`JSON RTE child ${index} has invalid reference, removing`);
978
1317
  return null;
1318
+ }
979
1319
  if (!(0, isEmpty_1.default)(child.children)) {
1320
+ cli_utilities_1.log.debug(`JSON RTE child ${index} has children, recursively fixing`);
980
1321
  child = this.fixJsonRteMissingReferences(tree, field, child);
981
1322
  }
1323
+ cli_utilities_1.log.debug(`JSON RTE child ${index} reference is valid`);
982
1324
  return child;
983
1325
  })
984
- .filter((val) => val);
1326
+ .filter((val) => {
1327
+ const isValid = val !== null;
1328
+ cli_utilities_1.log.debug(`JSON RTE child ${val ? 'kept' : 'filtered out'}`);
1329
+ return isValid;
1330
+ });
1331
+ }
1332
+ else {
1333
+ cli_utilities_1.log.debug(`JSON RTE entry has no children`);
985
1334
  }
986
1335
  }
1336
+ cli_utilities_1.log.debug(`JSON RTE missing references fix completed`);
987
1337
  return entry;
988
1338
  }
989
1339
  /**
@@ -998,18 +1348,28 @@ class Entries {
998
1348
  * @returns the `entry` variable.
999
1349
  */
1000
1350
  fixMissingReferences(tree, field, entry) {
1351
+ var _a;
1352
+ cli_utilities_1.log.debug(`Fixing missing references`);
1353
+ cli_utilities_1.log.debug(`Field UID: ${field.uid}`);
1354
+ cli_utilities_1.log.debug(`Reference to: ${((_a = field.reference_to) === null || _a === void 0 ? void 0 : _a.join(', ')) || 'none'}`);
1355
+ cli_utilities_1.log.debug(`Entry type: ${typeof entry}, length: ${Array.isArray(entry) ? entry.length : 'N/A'}`);
1001
1356
  const missingRefs = [];
1002
1357
  if (typeof entry === 'string') {
1358
+ cli_utilities_1.log.debug(`Entry is string, parsing JSON`);
1003
1359
  let stringReference = entry;
1004
1360
  stringReference = stringReference.replace(/'/g, '"');
1005
1361
  entry = JSON.parse(stringReference);
1362
+ cli_utilities_1.log.debug(`Parsed entry: ${Array.isArray(entry) ? entry.length : 'N/A'} references`);
1006
1363
  }
1007
- entry = entry === null || entry === void 0 ? void 0 : entry.map((reference) => {
1364
+ entry = entry === null || entry === void 0 ? void 0 : entry.map((reference, index) => {
1008
1365
  const { uid } = reference;
1009
1366
  const { reference_to } = field;
1367
+ cli_utilities_1.log.debug(`Processing reference ${index}: ${uid || reference}`);
1010
1368
  if (!uid && reference.startsWith('blt')) {
1369
+ cli_utilities_1.log.debug(`Checking blt reference: ${reference}`);
1011
1370
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
1012
1371
  if (!refExist) {
1372
+ cli_utilities_1.log.debug(`Missing blt reference: ${reference}`);
1013
1373
  if (Array.isArray(reference_to) && reference_to.length === 1) {
1014
1374
  missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
1015
1375
  }
@@ -1018,21 +1378,30 @@ class Entries {
1018
1378
  }
1019
1379
  }
1020
1380
  else {
1381
+ cli_utilities_1.log.debug(`Blt reference ${reference} is valid`);
1021
1382
  return { uid: reference, _content_type_uid: refExist.ctUid };
1022
1383
  }
1023
1384
  }
1024
1385
  else {
1386
+ cli_utilities_1.log.debug(`Checking standard reference: ${uid}`);
1025
1387
  const refExist = (0, find_1.default)(this.entryMetaData, { uid });
1026
1388
  if (!refExist) {
1389
+ cli_utilities_1.log.debug(`Missing reference: ${uid}`);
1027
1390
  missingRefs.push(reference);
1028
1391
  return null;
1029
1392
  }
1030
1393
  else {
1394
+ cli_utilities_1.log.debug(`Reference ${uid} is valid`);
1031
1395
  return reference;
1032
1396
  }
1033
1397
  }
1034
- }).filter((val) => val);
1398
+ }).filter((val) => {
1399
+ const isValid = val !== null;
1400
+ cli_utilities_1.log.debug(`Reference ${val ? 'kept' : 'filtered out'}`);
1401
+ return isValid;
1402
+ });
1035
1403
  if (!(0, isEmpty_1.default)(missingRefs)) {
1404
+ cli_utilities_1.log.debug(`Recording ${missingRefs.length} missing references for entry: ${this.currentUid}`);
1036
1405
  this.missingRefs[this.currentUid].push({
1037
1406
  tree,
1038
1407
  fixStatus: 'Fixed',
@@ -1047,6 +1416,10 @@ class Entries {
1047
1416
  missingRefs,
1048
1417
  });
1049
1418
  }
1419
+ else {
1420
+ cli_utilities_1.log.debug(`No missing references found`);
1421
+ }
1422
+ cli_utilities_1.log.debug(`Missing references fix completed: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0} references remaining`);
1050
1423
  return entry;
1051
1424
  }
1052
1425
  /**
@@ -1064,12 +1437,18 @@ class Entries {
1064
1437
  * @returns the `entryBlock` object.
1065
1438
  */
1066
1439
  modularBlockRefCheck(tree, blocks, entryBlock, index) {
1440
+ cli_utilities_1.log.debug(`Checking modular block references for block ${index}`);
1441
+ cli_utilities_1.log.debug(`Available block UIDs: ${blocks.map(b => b.uid).join(', ')}`);
1442
+ cli_utilities_1.log.debug(`Entry block keys: ${Object.keys(entryBlock).join(', ')}`);
1067
1443
  const validBlockUid = blocks.map((block) => block.uid);
1068
1444
  const invalidKeys = Object.keys(entryBlock).filter((key) => !validBlockUid.includes(key));
1445
+ cli_utilities_1.log.debug(`Found ${invalidKeys.length} invalid keys: ${invalidKeys.join(', ')}`);
1069
1446
  invalidKeys.forEach((key) => {
1070
1447
  if (this.fix) {
1448
+ cli_utilities_1.log.debug(`Deleting invalid key: ${key}`);
1071
1449
  delete entryBlock[key];
1072
1450
  }
1451
+ cli_utilities_1.log.debug(`Recording invalid modular block key: ${key}`);
1073
1452
  this.missingRefs[this.currentUid].push({
1074
1453
  uid: this.currentUid,
1075
1454
  name: this.currentTitle,
@@ -1084,6 +1463,7 @@ class Entries {
1084
1463
  missingRefs: [key],
1085
1464
  });
1086
1465
  });
1466
+ cli_utilities_1.log.debug(`Modular block reference check completed for block ${index}`);
1087
1467
  return entryBlock;
1088
1468
  }
1089
1469
  /**
@@ -1098,11 +1478,16 @@ class Entries {
1098
1478
  * @returns The function `jsonRefCheck` returns either `null` or `true`.
1099
1479
  */
1100
1480
  jsonRefCheck(tree, schema, child) {
1481
+ cli_utilities_1.log.debug(`Checking JSON reference for child: ${child.type || 'unknown type'}`);
1482
+ cli_utilities_1.log.debug(`Child UID: ${child.uid}`);
1101
1483
  const { uid: childrenUid } = child;
1102
1484
  const { 'entry-uid': entryUid, 'content-type-uid': contentTypeUid } = child.attrs || {};
1485
+ cli_utilities_1.log.debug(`Entry UID: ${entryUid}, Content type UID: ${contentTypeUid}`);
1103
1486
  if (entryUid) {
1487
+ cli_utilities_1.log.debug(`Checking entry reference: ${entryUid}`);
1104
1488
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: entryUid });
1105
1489
  if (!refExist) {
1490
+ cli_utilities_1.log.debug(`Missing entry reference: ${entryUid}`);
1106
1491
  tree.push({ field: 'children' }, { field: childrenUid, uid: schema.uid });
1107
1492
  this.missingRefs[this.currentUid].push({
1108
1493
  tree,
@@ -1117,9 +1502,17 @@ class Entries {
1117
1502
  .join(' ➜ '),
1118
1503
  missingRefs: [{ uid: entryUid, 'content-type-uid': contentTypeUid }],
1119
1504
  });
1505
+ cli_utilities_1.log.debug(`JSON reference check failed for entry: ${entryUid}`);
1120
1506
  return null;
1121
1507
  }
1508
+ else {
1509
+ cli_utilities_1.log.debug(`Entry reference ${entryUid} is valid`);
1510
+ }
1122
1511
  }
1512
+ else {
1513
+ cli_utilities_1.log.debug(`No entry UID found in JSON child`);
1514
+ }
1515
+ cli_utilities_1.log.debug(`JSON reference check passed`);
1123
1516
  return true;
1124
1517
  }
1125
1518
  /**
@@ -1127,41 +1520,63 @@ class Entries {
1127
1520
  * schemas.
1128
1521
  */
1129
1522
  async prepareEntryMetaData() {
1130
- this.log(messages_1.auditMsg.PREPARING_ENTRY_METADATA, 'info');
1523
+ cli_utilities_1.log.debug('Starting entry metadata preparation');
1524
+ cli_utilities_1.log.info(messages_1.auditMsg.PREPARING_ENTRY_METADATA);
1131
1525
  const localesFolderPath = (0, path_1.resolve)(this.config.basePath, this.config.moduleConfig.locales.dirName);
1132
1526
  const localesPath = (0, path_1.join)(localesFolderPath, this.config.moduleConfig.locales.fileName);
1133
1527
  const masterLocalesPath = (0, path_1.join)(localesFolderPath, 'master-locale.json');
1528
+ cli_utilities_1.log.debug(`Loading locales from: ${masterLocalesPath}`);
1134
1529
  this.locales = (0, fs_1.existsSync)(masterLocalesPath) ? (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(masterLocalesPath, 'utf8'))) : [];
1530
+ cli_utilities_1.log.debug(`Loaded ${this.locales.length} master locales`);
1531
+ cli_utilities_1.log.debug(`Loading additional locales from: ${localesPath}`);
1135
1532
  if ((0, fs_1.existsSync)(localesPath)) {
1136
- this.locales.push(...(0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8'))));
1533
+ const additionalLocales = (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8')));
1534
+ this.locales.push(...additionalLocales);
1535
+ cli_utilities_1.log.debug(`Added ${additionalLocales.length} additional locales`);
1536
+ }
1537
+ else {
1538
+ cli_utilities_1.log.debug('No additional locales file found');
1137
1539
  }
1138
1540
  const environmentPath = (0, path_1.resolve)(this.config.basePath, this.config.moduleConfig.environments.dirName, this.config.moduleConfig.environments.fileName);
1541
+ cli_utilities_1.log.debug(`Loading environments from: ${environmentPath}`);
1139
1542
  this.environments = (0, fs_1.existsSync)(environmentPath) ? (0, lodash_1.keys)(JSON.parse((0, fs_1.readFileSync)(environmentPath, 'utf8'))) : [];
1543
+ cli_utilities_1.log.debug(`Loaded ${this.environments.length} environments: ${this.environments.join(', ')}`, this.config.auditContext);
1544
+ cli_utilities_1.log.debug(`Processing ${this.locales.length} locales and ${this.ctSchema.length} content types for entry metadata`, this.config.auditContext);
1140
1545
  for (const { code } of this.locales) {
1546
+ cli_utilities_1.log.debug(`Processing locale: ${code}`, this.config.auditContext);
1141
1547
  for (const { uid } of this.ctSchema) {
1548
+ cli_utilities_1.log.debug(`Processing content type: ${uid} in locale ${code}`, this.config.auditContext);
1142
1549
  let basePath = (0, path_1.join)(this.folderPath, uid, code);
1550
+ cli_utilities_1.log.debug(`Entry base path: ${basePath}`, this.config.auditContext);
1143
1551
  let fsUtility = new cli_utilities_1.FsUtility({ basePath, indexFileName: 'index.json' });
1144
1552
  let indexer = fsUtility.indexFileContent;
1553
+ cli_utilities_1.log.debug(`Found ${Object.keys(indexer).length} entry files for ${uid}/${code}`, this.config.auditContext);
1145
1554
  for (const _ in indexer) {
1146
1555
  const entries = (await fsUtility.readChunkFiles.next());
1556
+ cli_utilities_1.log.debug(`Processing ${Object.keys(entries).length} entries from file`, this.config.auditContext);
1147
1557
  for (const entryUid in entries) {
1148
1558
  let { title } = entries[entryUid];
1559
+ cli_utilities_1.log.debug(`Processing entry metadata: ${entryUid} (${title || 'no title'})`, this.config.auditContext);
1149
1560
  if (entries[entryUid].hasOwnProperty('title') && !title) {
1561
+ cli_utilities_1.log.debug(`Entry ${entryUid} has empty title field`, this.config.auditContext);
1150
1562
  this.missingTitleFields[entryUid] = {
1151
1563
  'Entry UID': entryUid,
1152
1564
  'Content Type UID': uid,
1153
1565
  Locale: code,
1154
1566
  };
1155
- this.log(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`);
1567
+ cli_utilities_1.log.info(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, this.config.auditContext);
1156
1568
  }
1157
1569
  else if (!title) {
1158
- this.log(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`);
1570
+ cli_utilities_1.log.debug(`Entry ${entryUid} has no title field`, this.config.auditContext);
1571
+ cli_utilities_1.log.debug(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, this.config.auditContext);
1159
1572
  }
1160
1573
  this.entryMetaData.push({ uid: entryUid, title, ctUid: uid });
1161
1574
  }
1162
1575
  }
1163
1576
  }
1164
1577
  }
1578
+ cli_utilities_1.log.debug(`Entry metadata preparation completed: ${this.entryMetaData.length} entries processed`, this.config.auditContext);
1579
+ cli_utilities_1.log.debug(`Missing title fields found: ${Object.keys(this.missingTitleFields).length}`, this.config.auditContext);
1165
1580
  }
1166
1581
  }
1167
1582
  exports.default = Entries;