@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.
@@ -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
+ }
322
+ }
323
+ else {
324
+ cli_utilities_1.log.debug('No marketplace_apps.json found', this.config.auditContext);
246
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,57 @@ 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':
418
+ cli_utilities_1.log.debug(`Validating global field: ${display_name}`, this.config.auditContext);
309
419
  this.validateGlobalField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
310
420
  break;
311
421
  case 'json':
312
422
  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
423
+ cli_utilities_1.log.debug(`Validating extension field: ${display_name}`, this.config.auditContext);
424
+ const extResults = this.validateExtensionAndAppField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry);
425
+ this.missingRefs[this.currentUid].push(...extResults);
426
+ cli_utilities_1.log.debug(`Found ${extResults.length} missing extension references in field: ${display_name}`, this.config.auditContext);
315
427
  }
316
428
  else if ('allow_json_rte' in child.field_metadata && child.field_metadata.allow_json_rte) {
317
429
  // NOTE JSON RTE field type
430
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${display_name}`, this.config.auditContext);
318
431
  this.validateJsonRTEFields([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
319
432
  }
320
433
  break;
321
434
  case 'blocks':
435
+ cli_utilities_1.log.debug(`Validating modular blocks field: ${display_name}`, this.config.auditContext);
322
436
  this.validateModularBlocksField([...tree, { uid: child.uid, name: child.display_name, field: uid }], child, entry[uid]);
323
437
  break;
324
438
  case 'group':
439
+ cli_utilities_1.log.debug(`Validating group field: ${display_name}`, this.config.auditContext);
325
440
  this.validateGroupField([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry[uid]);
326
441
  break;
327
442
  case 'text':
328
443
  case 'number':
329
444
  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]));
445
+ cli_utilities_1.log.debug(`Validating select field: ${display_name}`, this.config.auditContext);
446
+ const selectResults = this.validateSelectField([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry[uid]);
447
+ this.missingSelectFeild[this.currentUid].push(...selectResults);
448
+ cli_utilities_1.log.debug(`Found ${selectResults.length} missing select field values in field: ${display_name}`, this.config.auditContext);
331
449
  }
332
450
  break;
333
451
  }
334
452
  }
453
+ cli_utilities_1.log.debug(`Field reference validation completed: ${field.uid || field.title || 'unknown'}`, this.config.auditContext);
335
454
  }
336
455
  /**
337
456
  * The function `validateReferenceField` validates the reference values of a given field in a tree
@@ -347,12 +466,16 @@ class Entries {
347
466
  * `tree`, `fieldStructure`, and `field`.
348
467
  */
349
468
  validateReferenceField(tree, fieldStructure, field) {
469
+ cli_utilities_1.log.debug(`Validating reference field: ${fieldStructure.display_name}`, this.config.auditContext);
350
470
  if (typeof field === 'string') {
471
+ cli_utilities_1.log.debug(`Converting string reference to JSON: ${field}`, this.config.auditContext);
351
472
  let stringReference = field;
352
473
  stringReference = stringReference.replace(/'/g, '"');
353
474
  field = JSON.parse(stringReference);
354
475
  }
355
- return this.validateReferenceValues(tree, fieldStructure, field);
476
+ const result = this.validateReferenceValues(tree, fieldStructure, field);
477
+ 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);
478
+ return result;
356
479
  }
357
480
  /**
358
481
  * The function `validateExtensionAndAppField` checks if a given field has a valid extension
@@ -368,17 +491,29 @@ class Entries {
368
491
  * references, an empty array is returned.
369
492
  */
370
493
  validateExtensionAndAppField(tree, fieldStructure, field) {
371
- if (this.fix)
494
+ cli_utilities_1.log.debug(`Validating extension/app field: ${fieldStructure.display_name}`, this.config.auditContext);
495
+ if (this.fix) {
496
+ cli_utilities_1.log.debug('Fix mode enabled, skipping extension/app validation', this.config.auditContext);
372
497
  return [];
498
+ }
373
499
  const missingRefs = [];
374
500
  let { uid, display_name, data_type } = fieldStructure || {};
501
+ cli_utilities_1.log.debug(`Checking extension/app field: ${uid}`, this.config.auditContext);
375
502
  if (field[uid]) {
376
503
  let { metadata: { extension_uid } = { extension_uid: '' } } = field[uid] || {};
504
+ cli_utilities_1.log.debug(`Found extension UID: ${extension_uid}`, this.config.auditContext);
377
505
  if (extension_uid && !this.extensions.includes(extension_uid)) {
506
+ cli_utilities_1.log.debug(`Missing extension: ${extension_uid}`, this.config.auditContext);
378
507
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
379
508
  }
509
+ else {
510
+ cli_utilities_1.log.debug(`Extension ${extension_uid} is valid`, this.config.auditContext);
511
+ }
512
+ }
513
+ else {
514
+ cli_utilities_1.log.debug(`No extension/app data found for field: ${uid}`, this.config.auditContext);
380
515
  }
381
- return missingRefs.length
516
+ const result = missingRefs.length
382
517
  ? [
383
518
  {
384
519
  tree,
@@ -394,6 +529,8 @@ class Entries {
394
529
  },
395
530
  ]
396
531
  : [];
532
+ cli_utilities_1.log.debug(`Extension/app field validation completed: ${result.length} missing references found`, this.config.auditContext);
533
+ return result;
397
534
  }
398
535
  /**
399
536
  * The function "validateGlobalField" is an asynchronous function that takes in a tree,
@@ -408,8 +545,11 @@ class Entries {
408
545
  * `EntryGlobalFieldDataType`. It represents a single global field entry.
409
546
  */
410
547
  validateGlobalField(tree, fieldStructure, field) {
548
+ cli_utilities_1.log.debug(`Validating global field: ${fieldStructure.display_name}`, this.config.auditContext);
549
+ cli_utilities_1.log.debug(`Global field UID: ${fieldStructure.uid}`, this.config.auditContext);
411
550
  // NOTE Any GlobalField related logic can be added here
412
551
  this.lookForReference(tree, fieldStructure, field);
552
+ cli_utilities_1.log.debug(`Global field validation completed for: ${fieldStructure.display_name}`, this.config.auditContext);
413
553
  }
414
554
  /**
415
555
  * The function `validateJsonRTEFields` is used to validate the JSON RTE fields by checking if the
@@ -424,18 +564,25 @@ class Entries {
424
564
  * such as `uid`, `attrs`, and `children`.
425
565
  */
426
566
  validateJsonRTEFields(tree, fieldStructure, field) {
427
- var _a;
567
+ var _a, _b;
568
+ cli_utilities_1.log.debug(`Validating JSON RTE field: ${fieldStructure.display_name}`, this.config.auditContext);
569
+ cli_utilities_1.log.debug(`JSON RTE field UID: ${fieldStructure.uid}`, this.config.auditContext);
570
+ 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
571
  // 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 : []) {
572
+ for (const index in (_b = field === null || field === void 0 ? void 0 : field.children) !== null && _b !== void 0 ? _b : []) {
430
573
  const child = field.children[index];
431
574
  const { children } = child;
575
+ cli_utilities_1.log.debug(`Processing JSON RTE child ${index}`, this.config.auditContext);
432
576
  if (!this.fix) {
577
+ cli_utilities_1.log.debug(`Checking JSON RTE references for child ${index}`, this.config.auditContext);
433
578
  this.jsonRefCheck(tree, fieldStructure, child);
434
579
  }
435
580
  if (!(0, isEmpty_1.default)(children)) {
581
+ cli_utilities_1.log.debug(`Recursively validating JSON RTE children for child ${index}`, this.config.auditContext);
436
582
  this.validateJsonRTEFields(tree, fieldStructure, field.children[index]);
437
583
  }
438
584
  }
585
+ cli_utilities_1.log.debug(`JSON RTE field validation completed for: ${fieldStructure.display_name}`, this.config.auditContext);
439
586
  }
440
587
  /**
441
588
  * The function validates the modular blocks field by traversing each module and looking for
@@ -451,19 +598,28 @@ class Entries {
451
598
  * `EntryModularBlocksDataType`.
452
599
  */
453
600
  validateModularBlocksField(tree, fieldStructure, field) {
601
+ cli_utilities_1.log.debug(`Validating modular blocks field: ${fieldStructure.display_name}`, this.config.auditContext);
602
+ cli_utilities_1.log.debug(`Modular blocks field UID: ${fieldStructure.uid}`, this.config.auditContext);
603
+ cli_utilities_1.log.debug(`Found ${field.length} modular blocks`, this.config.auditContext);
604
+ cli_utilities_1.log.debug(`Available blocks: ${fieldStructure.blocks.map(b => b.title).join(', ')}`);
454
605
  if (!this.fix) {
606
+ cli_utilities_1.log.debug('Checking modular block references (non-fix mode)');
455
607
  for (const index in field) {
608
+ cli_utilities_1.log.debug(`Checking references for modular block ${index}`);
456
609
  this.modularBlockRefCheck(tree, fieldStructure.blocks, field[index], +index);
457
610
  }
458
611
  }
459
612
  for (const block of fieldStructure.blocks) {
460
613
  const { uid, title } = block;
614
+ cli_utilities_1.log.debug(`Processing block: ${title} (${uid})`);
461
615
  for (const eBlock of field) {
462
616
  if (eBlock[uid]) {
617
+ cli_utilities_1.log.debug(`Found entry block data for: ${title}`);
463
618
  this.lookForReference([...tree, { uid, name: title }], block, eBlock[uid]);
464
619
  }
465
620
  }
466
621
  }
622
+ cli_utilities_1.log.debug(`Modular blocks field validation completed for: ${fieldStructure.display_name}`);
467
623
  }
468
624
  /**
469
625
  * The function validates a group field by looking for a reference in a tree structure.
@@ -475,15 +631,22 @@ class Entries {
475
631
  * `EntryGroupFieldDataType` and represents a single group field entry.
476
632
  */
477
633
  validateGroupField(tree, fieldStructure, field) {
634
+ cli_utilities_1.log.debug(`Validating group field: ${fieldStructure.display_name}`);
635
+ cli_utilities_1.log.debug(`Group field UID: ${fieldStructure.uid}`);
636
+ cli_utilities_1.log.debug(`Group field type: ${Array.isArray(field) ? 'array' : 'single'}`);
478
637
  // NOTE Any Group Field related logic can be added here (Ex data serialization or picking any metadata for report etc.,)
479
638
  if (Array.isArray(field)) {
480
- field.forEach((eGroup) => {
639
+ cli_utilities_1.log.debug(`Processing ${field.length} group field entries`);
640
+ field.forEach((eGroup, index) => {
641
+ cli_utilities_1.log.debug(`Processing group field entry ${index}`);
481
642
  this.lookForReference([...tree, { uid: fieldStructure.uid, display_name: fieldStructure.display_name }], fieldStructure, eGroup);
482
643
  });
483
644
  }
484
645
  else {
646
+ cli_utilities_1.log.debug('Processing single group field entry');
485
647
  this.lookForReference(tree, fieldStructure, field);
486
648
  }
649
+ cli_utilities_1.log.debug(`Group field validation completed for: ${fieldStructure.display_name}`);
487
650
  }
488
651
  /**
489
652
  * The function `validateReferenceValues` checks if the references in a given field exist in the
@@ -501,16 +664,25 @@ class Entries {
501
664
  * objects.
502
665
  */
503
666
  validateReferenceValues(tree, fieldStructure, field) {
504
- if (this.fix)
667
+ cli_utilities_1.log.debug(`Validating reference values for field: ${fieldStructure.display_name}`);
668
+ if (this.fix) {
669
+ cli_utilities_1.log.debug('Fix mode enabled, skipping reference validation');
505
670
  return [];
671
+ }
506
672
  const missingRefs = [];
507
673
  const { uid: data_type, display_name, reference_to } = fieldStructure;
674
+ cli_utilities_1.log.debug(`Reference field UID: ${data_type}`);
675
+ cli_utilities_1.log.debug(`Reference to: ${(reference_to === null || reference_to === void 0 ? void 0 : reference_to.join(', ')) || 'none'}`);
676
+ cli_utilities_1.log.debug(`Found ${(field === null || field === void 0 ? void 0 : field.length) || 0} references to validate`);
508
677
  for (const index in field !== null && field !== void 0 ? field : []) {
509
678
  const reference = field[index];
510
679
  const { uid } = reference;
680
+ cli_utilities_1.log.debug(`Processing reference ${index}: ${uid || reference}`);
511
681
  if (!uid && reference.startsWith('blt')) {
682
+ cli_utilities_1.log.debug(`Checking reference: ${reference}`);
512
683
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
513
684
  if (!refExist) {
685
+ cli_utilities_1.log.debug(`Missing reference: ${reference}`);
514
686
  if (Array.isArray(reference_to) && reference_to.length === 1) {
515
687
  missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
516
688
  }
@@ -518,17 +690,25 @@ class Entries {
518
690
  missingRefs.push(reference);
519
691
  }
520
692
  }
693
+ else {
694
+ cli_utilities_1.log.debug(`Reference ${reference} is valid`);
695
+ }
521
696
  }
522
697
  // NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
523
698
  // if (this.config.skipRefs.includes(reference)) continue;
524
699
  else {
700
+ cli_utilities_1.log.debug(`Checking standard reference: ${uid}`);
525
701
  const refExist = (0, find_1.default)(this.entryMetaData, { uid });
526
702
  if (!refExist) {
703
+ cli_utilities_1.log.debug(`Missing reference: ${uid}`);
527
704
  missingRefs.push(reference);
528
705
  }
706
+ else {
707
+ cli_utilities_1.log.debug(`Reference ${uid} is valid`);
708
+ }
529
709
  }
530
710
  }
531
- return missingRefs.length
711
+ const result = missingRefs.length
532
712
  ? [
533
713
  {
534
714
  tree,
@@ -544,17 +724,24 @@ class Entries {
544
724
  },
545
725
  ]
546
726
  : [];
727
+ cli_utilities_1.log.debug(`Reference values validation completed: ${result.length} missing references found`);
728
+ return result;
547
729
  }
548
730
  removeMissingKeysOnEntry(schema, entry) {
731
+ cli_utilities_1.log.debug(`Removing missing keys from entry: ${this.currentUid}`);
549
732
  // NOTE remove invalid entry keys
550
733
  const ctFields = (0, map_1.default)(schema, 'uid');
551
734
  const entryFields = Object.keys(entry !== null && entry !== void 0 ? entry : {});
735
+ cli_utilities_1.log.debug(`Content type fields: ${ctFields.length}, Entry fields: ${entryFields.length}`);
736
+ cli_utilities_1.log.debug(`System keys: ${this.config.entries.systemKeys.join(', ')}`);
552
737
  entryFields.forEach((eKey) => {
553
738
  // NOTE Key should not be system key and not exist in schema means it's invalid entry key
554
739
  if (!this.config.entries.systemKeys.includes(eKey) && !ctFields.includes(eKey)) {
740
+ cli_utilities_1.log.debug(`Removing invalid field: ${eKey}`);
555
741
  delete entry[eKey];
556
742
  }
557
743
  });
744
+ cli_utilities_1.log.debug(`Missing keys removal completed for entry: ${this.currentUid}`);
558
745
  }
559
746
  /**
560
747
  * The function `runFixOnSchema` takes in a tree, schema, and entry, and applies fixes to the entry
@@ -571,15 +758,20 @@ class Entries {
571
758
  * `schema`.
572
759
  */
573
760
  runFixOnSchema(tree, schema, entry) {
761
+ cli_utilities_1.log.debug(`Running fix on schema for entry: ${this.currentUid}`);
762
+ cli_utilities_1.log.debug(`Schema fields: ${schema.length}, Entry fields: ${Object.keys(entry).length}`);
574
763
  // NOTE Global field Fix
575
764
  schema.forEach((field) => {
576
765
  var _a;
577
766
  var _b, _c;
578
767
  const { uid, data_type, multiple } = field;
768
+ cli_utilities_1.log.debug(`Processing field: ${uid} (${data_type})`);
579
769
  if (!Object(entry).hasOwnProperty(uid)) {
770
+ cli_utilities_1.log.debug(`Field ${uid} not found in entry, skipping`);
580
771
  return;
581
772
  }
582
773
  if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
774
+ cli_utilities_1.log.debug(`Fixing multiple field: ${uid} - converting to array`);
583
775
  (_a = (_b = this.missingMultipleField)[_c = this.currentUid]) !== null && _a !== void 0 ? _a : (_b[_c] = []);
584
776
  this.missingMultipleField[this.currentUid].push({
585
777
  uid: this.currentUid,
@@ -598,41 +790,51 @@ class Entries {
598
790
  }
599
791
  switch (data_type) {
600
792
  case 'global_field':
793
+ cli_utilities_1.log.debug(`Fixing global field: ${uid}`);
601
794
  entry[uid] = this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
602
795
  break;
603
796
  case 'json':
604
797
  case 'reference':
798
+ cli_utilities_1.log.debug(`Fixing ${data_type} field: ${uid}`);
605
799
  if (data_type === 'json') {
606
800
  if ('extension' in field.field_metadata && field.field_metadata.extension) {
607
801
  // NOTE Custom field type
802
+ cli_utilities_1.log.debug(`Fixing extension/app field: ${uid}`);
608
803
  this.fixMissingExtensionOrApp([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry);
609
804
  break;
610
805
  }
611
806
  else if ('allow_json_rte' in field.field_metadata && field.field_metadata.allow_json_rte) {
807
+ cli_utilities_1.log.debug(`Fixing JSON RTE field: ${uid}`);
612
808
  this.fixJsonRteMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
613
809
  break;
614
810
  }
615
811
  }
616
812
  // NOTE Reference field
813
+ cli_utilities_1.log.debug(`Fixing reference field: ${uid}`);
617
814
  entry[uid] = this.fixMissingReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
618
815
  if (!entry[uid]) {
816
+ cli_utilities_1.log.debug(`Deleting empty reference field: ${uid}`);
619
817
  delete entry[uid];
620
818
  }
621
819
  break;
622
820
  case 'blocks':
821
+ cli_utilities_1.log.debug(`Fixing modular blocks field: ${uid}`);
623
822
  entry[uid] = this.fixModularBlocksReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field.blocks, entry[uid]);
624
823
  break;
625
824
  case 'group':
825
+ cli_utilities_1.log.debug(`Fixing group field: ${uid}`);
626
826
  entry[uid] = this.fixGroupField([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
627
827
  break;
628
828
  case 'text':
629
829
  case 'number':
630
830
  if (field.hasOwnProperty('display_type')) {
831
+ cli_utilities_1.log.debug(`Fixing select field: ${uid}`);
631
832
  entry[uid] = this.fixSelectField([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
632
833
  }
633
834
  break;
634
835
  }
635
836
  });
837
+ cli_utilities_1.log.debug(`Schema fix completed for entry: ${this.currentUid}`);
636
838
  return entry;
637
839
  }
638
840
  /**
@@ -648,11 +850,16 @@ class Entries {
648
850
  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
851
  }
650
852
  validateSelectField(tree, fieldStructure, field) {
853
+ cli_utilities_1.log.debug(`Validating select field: ${fieldStructure.display_name}`);
854
+ cli_utilities_1.log.debug(`Select field UID: ${fieldStructure.uid}`);
855
+ cli_utilities_1.log.debug(`Field value: ${JSON.stringify(field)}`);
856
+ cli_utilities_1.log.debug(`Multiple: ${fieldStructure.multiple}, Display type: ${fieldStructure.display_type}`);
651
857
  const { display_name, enum: selectOptions, multiple, min_instance, display_type, data_type } = fieldStructure;
652
858
  if (field === null ||
653
859
  field === '' ||
654
860
  (Array.isArray(field) && field.length === 0) ||
655
861
  (!field && data_type !== 'number')) {
862
+ cli_utilities_1.log.debug(`Select field is empty or null: ${display_name}`);
656
863
  let missingCTSelectFieldValues = 'Not Selected';
657
864
  return [
658
865
  {
@@ -672,18 +879,32 @@ class Entries {
672
879
  }
673
880
  let missingCTSelectFieldValues;
674
881
  if (multiple) {
882
+ cli_utilities_1.log.debug(`Validating multiple select field: ${display_name}`);
675
883
  if (Array.isArray(field)) {
884
+ cli_utilities_1.log.debug(`Field is array with ${field.length} values`);
676
885
  let obj = this.findNotPresentSelectField(field, selectOptions);
677
886
  let { notPresent } = obj;
678
887
  if (notPresent.length) {
888
+ cli_utilities_1.log.debug(`Found ${notPresent.length} missing select values: ${notPresent.join(', ')}`);
679
889
  missingCTSelectFieldValues = notPresent;
680
890
  }
891
+ else {
892
+ cli_utilities_1.log.debug(`All select values are valid`);
893
+ }
681
894
  }
682
895
  }
683
- else if (!selectOptions.choices.some((choice) => choice.value === field)) {
684
- missingCTSelectFieldValues = field;
896
+ else {
897
+ cli_utilities_1.log.debug(`Validating single select field: ${display_name}`);
898
+ if (!selectOptions.choices.some((choice) => choice.value === field)) {
899
+ cli_utilities_1.log.debug(`Invalid select value: ${field}`);
900
+ missingCTSelectFieldValues = field;
901
+ }
902
+ else {
903
+ cli_utilities_1.log.debug(`Select value is valid: ${field}`);
904
+ }
685
905
  }
686
906
  if (display_type && missingCTSelectFieldValues) {
907
+ cli_utilities_1.log.debug(`Select field validation found issues: ${JSON.stringify(missingCTSelectFieldValues)}`);
687
908
  return [
688
909
  {
689
910
  uid: this.currentUid,
@@ -701,6 +922,7 @@ class Entries {
701
922
  ];
702
923
  }
703
924
  else {
925
+ cli_utilities_1.log.debug(`Select field validation completed successfully: ${display_name}`);
704
926
  return [];
705
927
  }
706
928
  }
@@ -715,56 +937,74 @@ class Entries {
715
937
  * @returns
716
938
  */
717
939
  fixSelectField(tree, field, entry) {
940
+ cli_utilities_1.log.debug(`Fixing select field: ${field.display_name}`);
941
+ cli_utilities_1.log.debug(`Select field UID: ${field.uid}`);
942
+ cli_utilities_1.log.debug(`Current entry value: ${JSON.stringify(entry)}`);
718
943
  if (!this.config.fixSelectField) {
944
+ cli_utilities_1.log.debug('Select field fixing is disabled in config');
719
945
  return entry;
720
946
  }
721
947
  const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
948
+ cli_utilities_1.log.debug(`Select options: ${selectOptions.choices.length} choices, Multiple: ${multiple}, Min instance: ${min_instance}`);
722
949
  let missingCTSelectFieldValues;
723
950
  let isMissingValuePresent = false;
724
951
  let selectedValue = '';
725
952
  if (multiple) {
953
+ cli_utilities_1.log.debug('Processing multiple select field', this.config.auditContext);
726
954
  let obj = this.findNotPresentSelectField(entry, selectOptions);
727
955
  let { notPresent, filteredFeild } = obj;
956
+ cli_utilities_1.log.debug(`Found ${notPresent.length} invalid values, filtered to ${filteredFeild.length} values`, this.config.auditContext);
728
957
  entry = filteredFeild;
729
958
  missingCTSelectFieldValues = notPresent;
730
959
  if (missingCTSelectFieldValues.length) {
731
960
  isMissingValuePresent = true;
961
+ cli_utilities_1.log.debug(`Missing values found: ${missingCTSelectFieldValues.join(', ')}`, this.config.auditContext);
732
962
  }
733
963
  if (min_instance && Array.isArray(entry)) {
734
964
  const missingInstances = min_instance - entry.length;
965
+ cli_utilities_1.log.debug(`Checking min instance requirement: ${min_instance}, current: ${entry.length}, missing: ${missingInstances}`, this.config.auditContext);
735
966
  if (missingInstances > 0) {
736
967
  isMissingValuePresent = true;
737
968
  const newValues = selectOptions.choices
738
969
  .filter((choice) => !entry.includes(choice.value))
739
970
  .slice(0, missingInstances)
740
971
  .map((choice) => choice.value);
972
+ cli_utilities_1.log.debug(`Adding ${newValues.length} values to meet min instance requirement: ${newValues.join(', ')}`, this.config.auditContext);
741
973
  entry.push(...newValues);
742
974
  selectedValue = newValues;
743
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), 'error');
975
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), this.config.auditContext);
744
976
  }
745
977
  }
746
978
  else {
747
979
  if (entry.length === 0) {
748
980
  isMissingValuePresent = true;
749
981
  const defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
982
+ cli_utilities_1.log.debug(`Empty multiple select field, adding default value: ${defaultValue}`, this.config.auditContext);
750
983
  entry.push(defaultValue);
751
984
  selectedValue = defaultValue;
752
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
985
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), this.config.auditContext);
753
986
  }
754
987
  }
755
988
  }
756
989
  else {
990
+ cli_utilities_1.log.debug('Processing single select field', this.config.auditContext);
757
991
  const isPresent = selectOptions.choices.some((choice) => choice.value === entry);
758
992
  if (!isPresent) {
993
+ cli_utilities_1.log.debug(`Invalid single select value: ${entry}`, this.config.auditContext);
759
994
  missingCTSelectFieldValues = entry;
760
995
  isMissingValuePresent = true;
761
996
  let defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
997
+ cli_utilities_1.log.debug(`Replacing with default value: ${defaultValue}`, this.config.auditContext);
762
998
  entry = defaultValue;
763
999
  selectedValue = defaultValue;
764
- this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
1000
+ cli_utilities_1.log.error((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), this.config.auditContext);
1001
+ }
1002
+ else {
1003
+ cli_utilities_1.log.debug(`Single select value is valid: ${entry}`, this.config.auditContext);
765
1004
  }
766
1005
  }
767
1006
  if (display_type && isMissingValuePresent) {
1007
+ cli_utilities_1.log.debug(`Recording select field fix for entry: ${this.currentUid}`, this.config.auditContext);
768
1008
  this.missingSelectFeild[this.currentUid].push({
769
1009
  uid: this.currentUid,
770
1010
  name: this.currentTitle,
@@ -781,15 +1021,19 @@ class Entries {
781
1021
  fixStatus: 'Fixed',
782
1022
  });
783
1023
  }
1024
+ cli_utilities_1.log.debug(`Select field fix completed for: ${field.display_name}`);
784
1025
  return entry;
785
1026
  }
786
1027
  validateMandatoryFields(tree, fieldStructure, entry) {
1028
+ cli_utilities_1.log.debug(`Validating mandatory field: ${fieldStructure.display_name}`);
1029
+ cli_utilities_1.log.debug(`Field UID: ${fieldStructure.uid}, Mandatory: ${fieldStructure.mandatory}`);
787
1030
  const { display_name, multiple, data_type, mandatory, field_metadata, uid } = fieldStructure;
788
1031
  const isJsonRteEmpty = () => {
789
1032
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
790
1033
  const jsonNode = multiple
791
1034
  ? (_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
1035
  : (_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;
1036
+ cli_utilities_1.log.debug(`JSON RTE empty check: ${jsonNode === ''}`);
793
1037
  return jsonNode === '';
794
1038
  };
795
1039
  const isEntryEmpty = () => {
@@ -804,10 +1048,13 @@ class Entries {
804
1048
  if (Array.isArray(entry[uid]) && data_type === 'reference') {
805
1049
  fieldValue = ((_b = entry[uid]) === null || _b === void 0 ? void 0 : _b.length) ? true : false;
806
1050
  }
1051
+ cli_utilities_1.log.debug(`Entry empty check: ${fieldValue === '' || !fieldValue}`);
807
1052
  return fieldValue === '' || !fieldValue;
808
1053
  };
809
1054
  if (mandatory) {
1055
+ cli_utilities_1.log.debug(`Field is mandatory, checking if empty`);
810
1056
  if ((data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) || isEntryEmpty()) {
1057
+ cli_utilities_1.log.debug(`Mandatory field is empty: ${display_name}`);
811
1058
  return [
812
1059
  {
813
1060
  uid: this.currentUid,
@@ -822,7 +1069,14 @@ class Entries {
822
1069
  },
823
1070
  ];
824
1071
  }
1072
+ else {
1073
+ cli_utilities_1.log.debug(`Mandatory field has value: ${display_name}`);
1074
+ }
1075
+ }
1076
+ else {
1077
+ cli_utilities_1.log.debug(`Field is not mandatory: ${display_name}`);
825
1078
  }
1079
+ cli_utilities_1.log.debug(`Mandatory field validation completed: ${display_name}`);
826
1080
  return [];
827
1081
  }
828
1082
  /**
@@ -832,21 +1086,30 @@ class Entries {
832
1086
  * @returns An Array of entry containing only the values that were present in CT, An array of not present entries
833
1087
  */
834
1088
  findNotPresentSelectField(field, selectOptions) {
1089
+ cli_utilities_1.log.debug(`Finding not present select field values`);
1090
+ cli_utilities_1.log.debug(`Field values: ${JSON.stringify(field)}`);
1091
+ cli_utilities_1.log.debug(`Available choices: ${selectOptions.choices.length}`);
835
1092
  if (!field) {
1093
+ cli_utilities_1.log.debug('Field is null/undefined, initializing as empty array');
836
1094
  field = [];
837
1095
  }
838
1096
  let present = [];
839
1097
  let notPresent = [];
840
1098
  const choicesMap = new Map(selectOptions.choices.map((choice) => [choice.value, choice]));
1099
+ cli_utilities_1.log.debug(`Created choices map with ${choicesMap.size} entries`);
841
1100
  for (const value of field) {
842
1101
  const choice = choicesMap.get(value);
1102
+ cli_utilities_1.log.debug(`Checking value: ${value}`);
843
1103
  if (choice) {
1104
+ cli_utilities_1.log.debug(`Value ${value} is present in choices`);
844
1105
  present.push(choice.value);
845
1106
  }
846
1107
  else {
1108
+ cli_utilities_1.log.debug(`Value ${value} is not present in choices`);
847
1109
  notPresent.push(value);
848
1110
  }
849
1111
  }
1112
+ cli_utilities_1.log.debug(`Result: ${present.length} present, ${notPresent.length} not present`);
850
1113
  return { filteredFeild: present, notPresent };
851
1114
  }
852
1115
  /**
@@ -861,7 +1124,13 @@ class Entries {
861
1124
  * `field.schema`, and `entry` as arguments.
862
1125
  */
863
1126
  fixGlobalFieldReferences(tree, field, entry) {
864
- return this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
1127
+ var _a;
1128
+ cli_utilities_1.log.debug(`Fixing global field references: ${field.display_name}`);
1129
+ cli_utilities_1.log.debug(`Global field UID: ${field.uid}`);
1130
+ cli_utilities_1.log.debug(`Schema fields: ${((_a = field.schema) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
1131
+ const result = this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
1132
+ cli_utilities_1.log.debug(`Global field references fix completed: ${field.display_name}`);
1133
+ return result;
865
1134
  }
866
1135
  /**
867
1136
  * The function `fixModularBlocksReferences` takes in a tree, a list of blocks, and an entry, and
@@ -876,17 +1145,33 @@ class Entries {
876
1145
  * @returns the updated `entry` array after performing some modifications.
877
1146
  */
878
1147
  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));
1148
+ cli_utilities_1.log.debug(`Fixing modular blocks references`);
1149
+ cli_utilities_1.log.debug(`Available blocks: ${blocks.length}, Entry blocks: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0}`);
1150
+ entry = entry === null || entry === void 0 ? void 0 : entry.map((block, index) => {
1151
+ cli_utilities_1.log.debug(`Checking modular block ${index}`);
1152
+ return this.modularBlockRefCheck(tree, blocks, block, index);
1153
+ }).filter((val) => {
1154
+ const isEmpty = !val || Object.keys(val).length === 0;
1155
+ cli_utilities_1.log.debug(`Block ${val ? 'kept' : 'filtered out'} (empty: ${isEmpty})`);
1156
+ return !isEmpty;
1157
+ });
880
1158
  blocks.forEach((block) => {
1159
+ cli_utilities_1.log.debug(`Processing block: ${block.title} (${block.uid})`);
881
1160
  entry = entry === null || entry === void 0 ? void 0 : entry.map((eBlock) => {
882
1161
  if (!(0, isEmpty_1.default)(block.schema)) {
883
1162
  if (eBlock[block.uid]) {
1163
+ cli_utilities_1.log.debug(`Fixing schema for block: ${block.title}`);
884
1164
  eBlock[block.uid] = this.runFixOnSchema([...tree, { uid: block.uid, display_name: block.title }], block.schema, eBlock[block.uid]);
885
1165
  }
886
1166
  }
887
1167
  return eBlock;
888
- }).filter((val) => !(0, isEmpty_1.default)(val));
1168
+ }).filter((val) => {
1169
+ const isEmpty = !val || Object.keys(val).length === 0;
1170
+ cli_utilities_1.log.debug(`Entry block ${val ? 'kept' : 'filtered out'} (empty: ${isEmpty})`);
1171
+ return !isEmpty;
1172
+ });
889
1173
  });
1174
+ cli_utilities_1.log.debug(`Modular blocks references fix completed: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0} blocks remaining`);
890
1175
  return entry;
891
1176
  }
892
1177
  /**
@@ -903,15 +1188,26 @@ class Entries {
903
1188
  * @returns the `field` parameter.
904
1189
  */
905
1190
  fixMissingExtensionOrApp(tree, field, entry) {
1191
+ cli_utilities_1.log.debug(`Fixing missing extension/app: ${field.display_name}`);
1192
+ cli_utilities_1.log.debug(`Extension/app field UID: ${field.uid}`);
906
1193
  const missingRefs = [];
907
1194
  let { uid, display_name, data_type } = field || {};
908
1195
  if (entry[uid]) {
909
1196
  let { metadata: { extension_uid } = { extension_uid: '' } } = entry[uid] || {};
1197
+ cli_utilities_1.log.debug(`Found extension UID: ${extension_uid}`);
910
1198
  if (extension_uid && !this.extensions.includes(extension_uid)) {
1199
+ cli_utilities_1.log.debug(`Missing extension: ${extension_uid}`, this.config.auditContext);
911
1200
  missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' });
912
1201
  }
1202
+ else {
1203
+ cli_utilities_1.log.debug(`Extension ${extension_uid} is valid`, this.config.auditContext);
1204
+ }
1205
+ }
1206
+ else {
1207
+ cli_utilities_1.log.debug(`No extension/app data found for field: ${uid}`, this.config.auditContext);
913
1208
  }
914
1209
  if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
1210
+ cli_utilities_1.log.debug(`Recording extension/app fix for entry: ${this.currentUid}`);
915
1211
  this.missingRefs[this.currentUid].push({
916
1212
  tree,
917
1213
  data_type,
@@ -922,8 +1218,10 @@ class Entries {
922
1218
  name: this.currentTitle,
923
1219
  treeStr: tree.map(({ name }) => name).join(' ➜ '),
924
1220
  });
1221
+ cli_utilities_1.log.debug(`Deleting invalid extension/app field: ${uid}`);
925
1222
  delete entry[uid];
926
1223
  }
1224
+ cli_utilities_1.log.debug(`Extension/app fix completed for: ${field.display_name}`);
927
1225
  return field;
928
1226
  }
929
1227
  /**
@@ -941,16 +1239,29 @@ class Entries {
941
1239
  * Otherwise, it will return the `entry` as is.
942
1240
  */
943
1241
  fixGroupField(tree, field, entry) {
1242
+ var _a;
1243
+ cli_utilities_1.log.debug(`Fixing group field: ${field.display_name}`);
1244
+ cli_utilities_1.log.debug(`Group field UID: ${field.uid}`);
1245
+ cli_utilities_1.log.debug(`Schema fields: ${((_a = field.schema) === null || _a === void 0 ? void 0 : _a.length) || 0}`);
1246
+ cli_utilities_1.log.debug(`Entry type: ${Array.isArray(entry) ? 'array' : 'single'}`);
944
1247
  if (!(0, isEmpty_1.default)(field.schema)) {
1248
+ cli_utilities_1.log.debug(`Group field has schema, applying fixes`);
945
1249
  if (Array.isArray(entry)) {
946
- entry = entry.map((eGroup) => {
1250
+ cli_utilities_1.log.debug(`Processing ${entry.length} group field entries`);
1251
+ entry = entry.map((eGroup, index) => {
1252
+ cli_utilities_1.log.debug(`Fixing group field entry ${index}`);
947
1253
  return this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, eGroup);
948
1254
  });
949
1255
  }
950
1256
  else {
1257
+ cli_utilities_1.log.debug(`Processing single group field entry`);
951
1258
  entry = this.runFixOnSchema([...tree, { uid: field.uid, display_name: field.display_name }], field.schema, entry);
952
1259
  }
953
1260
  }
1261
+ else {
1262
+ cli_utilities_1.log.debug(`Group field has no schema, skipping fixes`);
1263
+ }
1264
+ cli_utilities_1.log.debug(`Group field fix completed for: ${field.display_name}`);
954
1265
  return entry;
955
1266
  }
956
1267
  /**
@@ -964,26 +1275,45 @@ class Entries {
964
1275
  * @returns the updated `entry` object with fixed missing references in the `children` property.
965
1276
  */
966
1277
  fixJsonRteMissingReferences(tree, field, entry) {
1278
+ cli_utilities_1.log.debug(`Fixing JSON RTE missing references`);
1279
+ cli_utilities_1.log.debug(`Field UID: ${field.uid}`);
1280
+ cli_utilities_1.log.debug(`Entry type: ${Array.isArray(entry) ? 'array' : 'single'}`);
967
1281
  if (Array.isArray(entry)) {
1282
+ cli_utilities_1.log.debug(`Processing ${entry.length} JSON RTE entries`);
968
1283
  entry = entry.map((child, index) => {
1284
+ cli_utilities_1.log.debug(`Fixing JSON RTE entry ${index}: ${(child === null || child === void 0 ? void 0 : child.type) || 'unknown type'}`);
969
1285
  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
1286
  });
971
1287
  }
972
1288
  else {
973
1289
  if (entry === null || entry === void 0 ? void 0 : entry.children) {
1290
+ cli_utilities_1.log.debug(`Processing ${entry.children.length} JSON RTE children`);
974
1291
  entry.children = entry.children
975
- .map((child) => {
1292
+ .map((child, index) => {
1293
+ cli_utilities_1.log.debug(`Checking JSON RTE child ${index}: ${child.type || 'unknown type'}`);
976
1294
  const refExist = this.jsonRefCheck(tree, field, child);
977
- if (!refExist)
1295
+ if (!refExist) {
1296
+ cli_utilities_1.log.debug(`JSON RTE child ${index} has invalid reference, removing`);
978
1297
  return null;
1298
+ }
979
1299
  if (!(0, isEmpty_1.default)(child.children)) {
1300
+ cli_utilities_1.log.debug(`JSON RTE child ${index} has children, recursively fixing`);
980
1301
  child = this.fixJsonRteMissingReferences(tree, field, child);
981
1302
  }
1303
+ cli_utilities_1.log.debug(`JSON RTE child ${index} reference is valid`);
982
1304
  return child;
983
1305
  })
984
- .filter((val) => val);
1306
+ .filter((val) => {
1307
+ const isValid = val !== null;
1308
+ cli_utilities_1.log.debug(`JSON RTE child ${val ? 'kept' : 'filtered out'}`);
1309
+ return isValid;
1310
+ });
1311
+ }
1312
+ else {
1313
+ cli_utilities_1.log.debug(`JSON RTE entry has no children`);
985
1314
  }
986
1315
  }
1316
+ cli_utilities_1.log.debug(`JSON RTE missing references fix completed`);
987
1317
  return entry;
988
1318
  }
989
1319
  /**
@@ -998,18 +1328,28 @@ class Entries {
998
1328
  * @returns the `entry` variable.
999
1329
  */
1000
1330
  fixMissingReferences(tree, field, entry) {
1331
+ var _a;
1332
+ cli_utilities_1.log.debug(`Fixing missing references`);
1333
+ cli_utilities_1.log.debug(`Field UID: ${field.uid}`);
1334
+ cli_utilities_1.log.debug(`Reference to: ${((_a = field.reference_to) === null || _a === void 0 ? void 0 : _a.join(', ')) || 'none'}`);
1335
+ cli_utilities_1.log.debug(`Entry type: ${typeof entry}, length: ${Array.isArray(entry) ? entry.length : 'N/A'}`);
1001
1336
  const missingRefs = [];
1002
1337
  if (typeof entry === 'string') {
1338
+ cli_utilities_1.log.debug(`Entry is string, parsing JSON`);
1003
1339
  let stringReference = entry;
1004
1340
  stringReference = stringReference.replace(/'/g, '"');
1005
1341
  entry = JSON.parse(stringReference);
1342
+ cli_utilities_1.log.debug(`Parsed entry: ${Array.isArray(entry) ? entry.length : 'N/A'} references`);
1006
1343
  }
1007
- entry = entry === null || entry === void 0 ? void 0 : entry.map((reference) => {
1344
+ entry = entry === null || entry === void 0 ? void 0 : entry.map((reference, index) => {
1008
1345
  const { uid } = reference;
1009
1346
  const { reference_to } = field;
1347
+ cli_utilities_1.log.debug(`Processing reference ${index}: ${uid || reference}`);
1010
1348
  if (!uid && reference.startsWith('blt')) {
1349
+ cli_utilities_1.log.debug(`Checking blt reference: ${reference}`);
1011
1350
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
1012
1351
  if (!refExist) {
1352
+ cli_utilities_1.log.debug(`Missing blt reference: ${reference}`);
1013
1353
  if (Array.isArray(reference_to) && reference_to.length === 1) {
1014
1354
  missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
1015
1355
  }
@@ -1018,21 +1358,30 @@ class Entries {
1018
1358
  }
1019
1359
  }
1020
1360
  else {
1361
+ cli_utilities_1.log.debug(`Blt reference ${reference} is valid`);
1021
1362
  return { uid: reference, _content_type_uid: refExist.ctUid };
1022
1363
  }
1023
1364
  }
1024
1365
  else {
1366
+ cli_utilities_1.log.debug(`Checking standard reference: ${uid}`);
1025
1367
  const refExist = (0, find_1.default)(this.entryMetaData, { uid });
1026
1368
  if (!refExist) {
1369
+ cli_utilities_1.log.debug(`Missing reference: ${uid}`);
1027
1370
  missingRefs.push(reference);
1028
1371
  return null;
1029
1372
  }
1030
1373
  else {
1374
+ cli_utilities_1.log.debug(`Reference ${uid} is valid`);
1031
1375
  return reference;
1032
1376
  }
1033
1377
  }
1034
- }).filter((val) => val);
1378
+ }).filter((val) => {
1379
+ const isValid = val !== null;
1380
+ cli_utilities_1.log.debug(`Reference ${val ? 'kept' : 'filtered out'}`);
1381
+ return isValid;
1382
+ });
1035
1383
  if (!(0, isEmpty_1.default)(missingRefs)) {
1384
+ cli_utilities_1.log.debug(`Recording ${missingRefs.length} missing references for entry: ${this.currentUid}`);
1036
1385
  this.missingRefs[this.currentUid].push({
1037
1386
  tree,
1038
1387
  fixStatus: 'Fixed',
@@ -1047,6 +1396,10 @@ class Entries {
1047
1396
  missingRefs,
1048
1397
  });
1049
1398
  }
1399
+ else {
1400
+ cli_utilities_1.log.debug(`No missing references found`);
1401
+ }
1402
+ cli_utilities_1.log.debug(`Missing references fix completed: ${(entry === null || entry === void 0 ? void 0 : entry.length) || 0} references remaining`);
1050
1403
  return entry;
1051
1404
  }
1052
1405
  /**
@@ -1064,12 +1417,18 @@ class Entries {
1064
1417
  * @returns the `entryBlock` object.
1065
1418
  */
1066
1419
  modularBlockRefCheck(tree, blocks, entryBlock, index) {
1420
+ cli_utilities_1.log.debug(`Checking modular block references for block ${index}`);
1421
+ cli_utilities_1.log.debug(`Available block UIDs: ${blocks.map(b => b.uid).join(', ')}`);
1422
+ cli_utilities_1.log.debug(`Entry block keys: ${Object.keys(entryBlock).join(', ')}`);
1067
1423
  const validBlockUid = blocks.map((block) => block.uid);
1068
1424
  const invalidKeys = Object.keys(entryBlock).filter((key) => !validBlockUid.includes(key));
1425
+ cli_utilities_1.log.debug(`Found ${invalidKeys.length} invalid keys: ${invalidKeys.join(', ')}`);
1069
1426
  invalidKeys.forEach((key) => {
1070
1427
  if (this.fix) {
1428
+ cli_utilities_1.log.debug(`Deleting invalid key: ${key}`);
1071
1429
  delete entryBlock[key];
1072
1430
  }
1431
+ cli_utilities_1.log.debug(`Recording invalid modular block key: ${key}`);
1073
1432
  this.missingRefs[this.currentUid].push({
1074
1433
  uid: this.currentUid,
1075
1434
  name: this.currentTitle,
@@ -1084,6 +1443,7 @@ class Entries {
1084
1443
  missingRefs: [key],
1085
1444
  });
1086
1445
  });
1446
+ cli_utilities_1.log.debug(`Modular block reference check completed for block ${index}`);
1087
1447
  return entryBlock;
1088
1448
  }
1089
1449
  /**
@@ -1098,11 +1458,16 @@ class Entries {
1098
1458
  * @returns The function `jsonRefCheck` returns either `null` or `true`.
1099
1459
  */
1100
1460
  jsonRefCheck(tree, schema, child) {
1461
+ cli_utilities_1.log.debug(`Checking JSON reference for child: ${child.type || 'unknown type'}`);
1462
+ cli_utilities_1.log.debug(`Child UID: ${child.uid}`);
1101
1463
  const { uid: childrenUid } = child;
1102
1464
  const { 'entry-uid': entryUid, 'content-type-uid': contentTypeUid } = child.attrs || {};
1465
+ cli_utilities_1.log.debug(`Entry UID: ${entryUid}, Content type UID: ${contentTypeUid}`);
1103
1466
  if (entryUid) {
1467
+ cli_utilities_1.log.debug(`Checking entry reference: ${entryUid}`);
1104
1468
  const refExist = (0, find_1.default)(this.entryMetaData, { uid: entryUid });
1105
1469
  if (!refExist) {
1470
+ cli_utilities_1.log.debug(`Missing entry reference: ${entryUid}`);
1106
1471
  tree.push({ field: 'children' }, { field: childrenUid, uid: schema.uid });
1107
1472
  this.missingRefs[this.currentUid].push({
1108
1473
  tree,
@@ -1117,9 +1482,17 @@ class Entries {
1117
1482
  .join(' ➜ '),
1118
1483
  missingRefs: [{ uid: entryUid, 'content-type-uid': contentTypeUid }],
1119
1484
  });
1485
+ cli_utilities_1.log.debug(`JSON reference check failed for entry: ${entryUid}`);
1120
1486
  return null;
1121
1487
  }
1488
+ else {
1489
+ cli_utilities_1.log.debug(`Entry reference ${entryUid} is valid`);
1490
+ }
1122
1491
  }
1492
+ else {
1493
+ cli_utilities_1.log.debug(`No entry UID found in JSON child`);
1494
+ }
1495
+ cli_utilities_1.log.debug(`JSON reference check passed`);
1123
1496
  return true;
1124
1497
  }
1125
1498
  /**
@@ -1127,41 +1500,63 @@ class Entries {
1127
1500
  * schemas.
1128
1501
  */
1129
1502
  async prepareEntryMetaData() {
1130
- this.log(messages_1.auditMsg.PREPARING_ENTRY_METADATA, 'info');
1503
+ cli_utilities_1.log.debug('Starting entry metadata preparation');
1504
+ cli_utilities_1.log.info(messages_1.auditMsg.PREPARING_ENTRY_METADATA);
1131
1505
  const localesFolderPath = (0, path_1.resolve)(this.config.basePath, this.config.moduleConfig.locales.dirName);
1132
1506
  const localesPath = (0, path_1.join)(localesFolderPath, this.config.moduleConfig.locales.fileName);
1133
1507
  const masterLocalesPath = (0, path_1.join)(localesFolderPath, 'master-locale.json');
1508
+ cli_utilities_1.log.debug(`Loading locales from: ${masterLocalesPath}`);
1134
1509
  this.locales = (0, fs_1.existsSync)(masterLocalesPath) ? (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(masterLocalesPath, 'utf8'))) : [];
1510
+ cli_utilities_1.log.debug(`Loaded ${this.locales.length} master locales`);
1511
+ cli_utilities_1.log.debug(`Loading additional locales from: ${localesPath}`);
1135
1512
  if ((0, fs_1.existsSync)(localesPath)) {
1136
- this.locales.push(...(0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8'))));
1513
+ const additionalLocales = (0, values_1.default)(JSON.parse((0, fs_1.readFileSync)(localesPath, 'utf8')));
1514
+ this.locales.push(...additionalLocales);
1515
+ cli_utilities_1.log.debug(`Added ${additionalLocales.length} additional locales`);
1516
+ }
1517
+ else {
1518
+ cli_utilities_1.log.debug('No additional locales file found');
1137
1519
  }
1138
1520
  const environmentPath = (0, path_1.resolve)(this.config.basePath, this.config.moduleConfig.environments.dirName, this.config.moduleConfig.environments.fileName);
1521
+ cli_utilities_1.log.debug(`Loading environments from: ${environmentPath}`);
1139
1522
  this.environments = (0, fs_1.existsSync)(environmentPath) ? (0, lodash_1.keys)(JSON.parse((0, fs_1.readFileSync)(environmentPath, 'utf8'))) : [];
1523
+ cli_utilities_1.log.debug(`Loaded ${this.environments.length} environments: ${this.environments.join(', ')}`, this.config.auditContext);
1524
+ cli_utilities_1.log.debug(`Processing ${this.locales.length} locales and ${this.ctSchema.length} content types for entry metadata`, this.config.auditContext);
1140
1525
  for (const { code } of this.locales) {
1526
+ cli_utilities_1.log.debug(`Processing locale: ${code}`, this.config.auditContext);
1141
1527
  for (const { uid } of this.ctSchema) {
1528
+ cli_utilities_1.log.debug(`Processing content type: ${uid} in locale ${code}`, this.config.auditContext);
1142
1529
  let basePath = (0, path_1.join)(this.folderPath, uid, code);
1530
+ cli_utilities_1.log.debug(`Entry base path: ${basePath}`, this.config.auditContext);
1143
1531
  let fsUtility = new cli_utilities_1.FsUtility({ basePath, indexFileName: 'index.json' });
1144
1532
  let indexer = fsUtility.indexFileContent;
1533
+ cli_utilities_1.log.debug(`Found ${Object.keys(indexer).length} entry files for ${uid}/${code}`, this.config.auditContext);
1145
1534
  for (const _ in indexer) {
1146
1535
  const entries = (await fsUtility.readChunkFiles.next());
1536
+ cli_utilities_1.log.debug(`Processing ${Object.keys(entries).length} entries from file`, this.config.auditContext);
1147
1537
  for (const entryUid in entries) {
1148
1538
  let { title } = entries[entryUid];
1539
+ cli_utilities_1.log.debug(`Processing entry metadata: ${entryUid} (${title || 'no title'})`, this.config.auditContext);
1149
1540
  if (entries[entryUid].hasOwnProperty('title') && !title) {
1541
+ cli_utilities_1.log.debug(`Entry ${entryUid} has empty title field`, this.config.auditContext);
1150
1542
  this.missingTitleFields[entryUid] = {
1151
1543
  'Entry UID': entryUid,
1152
1544
  'Content Type UID': uid,
1153
1545
  Locale: code,
1154
1546
  };
1155
- this.log(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`);
1547
+ 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
1548
  }
1157
1549
  else if (!title) {
1158
- this.log(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`);
1550
+ cli_utilities_1.log.debug(`Entry ${entryUid} has no title field`, this.config.auditContext);
1551
+ 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
1552
  }
1160
1553
  this.entryMetaData.push({ uid: entryUid, title, ctUid: uid });
1161
1554
  }
1162
1555
  }
1163
1556
  }
1164
1557
  }
1558
+ cli_utilities_1.log.debug(`Entry metadata preparation completed: ${this.entryMetaData.length} entries processed`, this.config.auditContext);
1559
+ cli_utilities_1.log.debug(`Missing title fields found: ${Object.keys(this.missingTitleFields).length}`, this.config.auditContext);
1165
1560
  }
1166
1561
  }
1167
1562
  exports.default = Entries;