@contentstack/cli-audit 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
19
19
  $ csdx COMMAND
20
20
  running command...
21
21
  $ csdx (--version|-v)
22
- @contentstack/cli-audit/1.9.0 linux-x64 node-v22.14.0
22
+ @contentstack/cli-audit/1.10.0 linux-x64 node-v22.14.0
23
23
  $ csdx --help [COMMAND]
24
24
  USAGE
25
25
  $ csdx COMMAND
@@ -35,6 +35,7 @@ export declare abstract class AuditBaseCommand extends BaseCommand<typeof AuditB
35
35
  missingRefInCustomRoles: {} | undefined;
36
36
  missingEnvLocalesInAssets: Record<string, any> | undefined;
37
37
  missingEnvLocalesInEntries: Record<string, any> | undefined;
38
+ missingMultipleFields: Record<string, any> | undefined;
38
39
  }>;
39
40
  /**
40
41
  * The `promptQueue` function prompts the user to enter a data directory path if the `data-dir` flag
@@ -41,7 +41,7 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
41
41
  await this.promptQueue();
42
42
  await this.createBackUp();
43
43
  this.sharedConfig.reportPath = (0, path_1.resolve)(this.flags['report-path'] || process.cwd(), 'audit-report');
44
- const { missingCtRefs, missingGfRefs, missingEntryRefs, missingCtRefsInExtensions, missingCtRefsInWorkflow, missingSelectFeild, missingMandatoryFields, missingTitleFields, missingRefInCustomRoles, missingEnvLocalesInAssets, missingEnvLocalesInEntries } = await this.scanAndFix();
44
+ const { missingCtRefs, missingGfRefs, missingEntryRefs, missingCtRefsInExtensions, missingCtRefsInWorkflow, missingSelectFeild, missingMandatoryFields, missingTitleFields, missingRefInCustomRoles, missingEnvLocalesInAssets, missingEnvLocalesInEntries, missingMultipleFields } = await this.scanAndFix();
45
45
  this.showOutputOnScreen([
46
46
  { module: 'Content types', missingRefs: missingCtRefs },
47
47
  { module: 'Global Fields', missingRefs: missingGfRefs },
@@ -59,6 +59,7 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
59
59
  this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Custom Roles', missingRefs: missingRefInCustomRoles }]);
60
60
  this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Assets', missingRefs: missingEnvLocalesInAssets }]);
61
61
  this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Missing Locale and Environments', missingRefs: missingEnvLocalesInEntries }]);
62
+ this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Changed Multiple Fields', missingRefs: missingMultipleFields }]);
62
63
  if (!(0, isEmpty_1.default)(missingCtRefs) ||
63
64
  !(0, isEmpty_1.default)(missingGfRefs) ||
64
65
  !(0, isEmpty_1.default)(missingEntryRefs) ||
@@ -68,7 +69,8 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
68
69
  !(0, isEmpty_1.default)(missingTitleFields) ||
69
70
  !(0, isEmpty_1.default)(missingRefInCustomRoles) ||
70
71
  !(0, isEmpty_1.default)(missingEnvLocalesInAssets) ||
71
- !(0, isEmpty_1.default)(missingEnvLocalesInEntries)) {
72
+ !(0, isEmpty_1.default)(missingEnvLocalesInEntries) ||
73
+ !(0, isEmpty_1.default)(missingMultipleFields)) {
72
74
  if (this.currentCommand === 'cm:stacks:audit') {
73
75
  this.log(this.$t(messages_1.auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), 'warn');
74
76
  }
@@ -103,9 +105,9 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
103
105
  * and `missingEntryRefs`.
104
106
  */
105
107
  async scanAndFix() {
106
- var _a, _b, _c, _d, _e;
108
+ var _a, _b, _c, _d, _e, _f;
107
109
  let { ctSchema, gfSchema } = this.getCtAndGfSchema();
108
- let missingCtRefs, missingGfRefs, missingEntryRefs, missingCtRefsInExtensions, missingCtRefsInWorkflow, missingSelectFeild, missingEntry, missingMandatoryFields, missingTitleFields, missingRefInCustomRoles, missingEnvLocalesInAssets, missingEnvLocalesInEntries;
110
+ let missingCtRefs, missingGfRefs, missingEntryRefs, missingCtRefsInExtensions, missingCtRefsInWorkflow, missingSelectFeild, missingEntry, missingMandatoryFields, missingTitleFields, missingRefInCustomRoles, missingEnvLocalesInAssets, missingEnvLocalesInEntries, missingMultipleFields;
109
111
  for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
110
112
  (0, log_1.print)([
111
113
  {
@@ -142,11 +144,13 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
142
144
  missingMandatoryFields = (_c = missingEntry.missingMandatoryFields) !== null && _c !== void 0 ? _c : {};
143
145
  missingTitleFields = (_d = missingEntry.missingTitleFields) !== null && _d !== void 0 ? _d : {};
144
146
  missingEnvLocalesInEntries = (_e = missingEntry.missingEnvLocale) !== null && _e !== void 0 ? _e : {};
147
+ missingMultipleFields = (_f = missingEntry.missingMultipleFields) !== null && _f !== void 0 ? _f : {};
145
148
  await this.prepareReport(module, missingEntryRefs);
146
149
  await this.prepareReport(`Entries_Select_feild`, missingSelectFeild);
147
150
  await this.prepareReport('Entries_Mandatory_feild', missingMandatoryFields);
148
151
  await this.prepareReport('Entries_Title_feild', missingTitleFields);
149
152
  await this.prepareReport('Entry_Missing_Locale_and_Env_in_Publish_Details', missingEnvLocalesInEntries);
153
+ await this.prepareReport('Entry_Multiple_Fields', missingMultipleFields);
150
154
  break;
151
155
  case 'workflows':
152
156
  missingCtRefsInWorkflow = await new modules_1.Workflows({
@@ -191,7 +195,8 @@ class AuditBaseCommand extends base_command_1.BaseCommand {
191
195
  missingTitleFields,
192
196
  missingRefInCustomRoles,
193
197
  missingEnvLocalesInAssets,
194
- missingEnvLocalesInEntries
198
+ missingEnvLocalesInEntries,
199
+ missingMultipleFields
195
200
  };
196
201
  }
197
202
  /**
@@ -61,6 +61,7 @@ declare const config: {
61
61
  Entries_Title_feild: string;
62
62
  Entry_Missing_Locale_and_Env: string;
63
63
  Entry_Missing_Locale_and_Env_in_Publish_Details: string;
64
+ Entry_Multiple_Fields: string;
64
65
  };
65
66
  feild_level_modules: string[];
66
67
  fixSelectField: boolean;
@@ -103,9 +103,10 @@ const config = {
103
103
  Entries_Mandatory_feild: 'Entries_Mandatory_feild',
104
104
  Entries_Title_feild: 'Entries_Title_feild',
105
105
  Entry_Missing_Locale_and_Env: 'Entry_Missing_Locale_and_Env',
106
- Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details'
106
+ Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details',
107
+ Entry_Multiple_Fields: 'Entry_Multiple_Fields'
107
108
  },
108
- feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details'],
109
+ feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details', 'Entry_Multiple_Fields'],
109
110
  fixSelectField: false
110
111
  };
111
112
  exports.default = config;
@@ -18,6 +18,7 @@ export default class Entries {
18
18
  protected missingMandatoryFields: Record<string, any>;
19
19
  protected missingTitleFields: Record<string, any>;
20
20
  protected missingEnvLocale: Record<string, any>;
21
+ protected missingMultipleField: Record<string, any>;
21
22
  environments: string[];
22
23
  entryMetaData: Record<string, any>[];
23
24
  moduleName: keyof typeof auditConfig.moduleConfig;
@@ -34,12 +35,14 @@ export default class Entries {
34
35
  missingMandatoryFields?: undefined;
35
36
  missingTitleFields?: undefined;
36
37
  missingEnvLocale?: undefined;
38
+ missingMultipleFields?: undefined;
37
39
  } | {
38
40
  missingEntryRefs: Record<string, any>;
39
41
  missingSelectFeild: Record<string, any>;
40
42
  missingMandatoryFields: Record<string, any>;
41
43
  missingTitleFields: Record<string, any>;
42
44
  missingEnvLocale: Record<string, any>;
45
+ missingMultipleFields: Record<string, any>;
43
46
  }>;
44
47
  /**
45
48
  * The function removes any properties from the `missingRefs` object that have an empty array value.
@@ -21,6 +21,7 @@ class Entries {
21
21
  this.missingMandatoryFields = {};
22
22
  this.missingTitleFields = {};
23
23
  this.missingEnvLocale = {};
24
+ this.missingMultipleField = {};
24
25
  this.environments = [];
25
26
  this.entryMetaData = [];
26
27
  this.moduleName = 'entries';
@@ -177,6 +178,7 @@ class Entries {
177
178
  missingMandatoryFields: this.missingMandatoryFields,
178
179
  missingTitleFields: this.missingTitleFields,
179
180
  missingEnvLocale: this.missingEnvLocale,
181
+ missingMultipleFields: this.missingMultipleField
180
182
  };
181
183
  }
182
184
  /**
@@ -274,7 +276,24 @@ class Entries {
274
276
  entry = this.runFixOnSchema(tree, field.schema, entry);
275
277
  }
276
278
  for (const child of (_a = field === null || field === void 0 ? void 0 : field.schema) !== null && _a !== void 0 ? _a : []) {
277
- const { uid } = child;
279
+ const { uid, multiple, data_type } = child;
280
+ if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
281
+ if (!this.missingMultipleField[this.currentUid]) {
282
+ this.missingMultipleField[this.currentUid] = [];
283
+ }
284
+ this.missingMultipleField[this.currentUid].push({
285
+ uid: this.currentUid,
286
+ name: this.currentTitle,
287
+ field_uid: uid,
288
+ data_type,
289
+ multiple,
290
+ tree,
291
+ treeStr: tree
292
+ .map(({ name }) => name)
293
+ .filter((val) => val)
294
+ .join(' ➜ '),
295
+ });
296
+ }
278
297
  this.missingMandatoryFields[this.currentUid].push(...this.validateMandatoryFields([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry));
279
298
  if (!(entry === null || entry === void 0 ? void 0 : entry[uid]) && !child.hasOwnProperty('display_type')) {
280
299
  continue;
@@ -551,10 +570,29 @@ class Entries {
551
570
  runFixOnSchema(tree, schema, entry) {
552
571
  // NOTE Global field Fix
553
572
  schema.forEach((field) => {
554
- const { uid, data_type } = field;
573
+ var _a;
574
+ var _b, _c;
575
+ const { uid, data_type, multiple } = field;
555
576
  if (!Object(entry).hasOwnProperty(uid)) {
556
577
  return;
557
578
  }
579
+ if (multiple && entry[uid] && !Array.isArray(entry[uid])) {
580
+ (_a = (_b = this.missingMultipleField)[_c = this.currentUid]) !== null && _a !== void 0 ? _a : (_b[_c] = []);
581
+ this.missingMultipleField[this.currentUid].push({
582
+ uid: this.currentUid,
583
+ name: this.currentTitle,
584
+ field_uid: uid,
585
+ data_type,
586
+ multiple,
587
+ tree,
588
+ treeStr: tree
589
+ .map(({ name }) => name)
590
+ .filter(Boolean)
591
+ .join(' ➜ '),
592
+ 'fixStatus': 'Fixed',
593
+ });
594
+ entry[uid] = [entry[uid]];
595
+ }
558
596
  switch (data_type) {
559
597
  case 'global_field':
560
598
  entry[uid] = this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
@@ -8,6 +8,7 @@ type ContentTypeStruct = {
8
8
  description: string;
9
9
  schema?: ContentTypeSchemaType[];
10
10
  mandatory: boolean;
11
+ multiple: boolean;
11
12
  };
12
13
  type ModuleConstructorParam = {
13
14
  log: LogFn;
@@ -28,6 +29,7 @@ type CommonDataTypeStruct = {
28
29
  allow_json_rte: boolean;
29
30
  } & AnyProperty;
30
31
  mandatory: boolean;
32
+ multiple: boolean;
31
33
  };
32
34
  type RefErrorReturnType = {
33
35
  name: string;
@@ -114,6 +116,8 @@ declare enum OutputColumn {
114
116
  'publish_environment' = "publish_environment",
115
117
  'asset_uid' = "asset_uid",
116
118
  'selectedValue' = "selectedValue",
117
- 'fixStatus' = "fixStatus"
119
+ 'fixStatus' = "fixStatus",
120
+ 'field_uid' = "field_uid",
121
+ 'multiple' = "multiple"
118
122
  }
119
123
  export { CtConstructorParam, ContentTypeStruct, ModuleConstructorParam, ReferenceFieldDataType, GlobalFieldDataType, ExtensionOrAppFieldDataType, JsonRTEFieldDataType, GroupFieldDataType, ModularBlocksDataType, RefErrorReturnType, ModularBlocksSchemaTypes, ModularBlockType, OutputColumn, ContentTypeSchemaType, GlobalFieldSchemaTypes, WorkflowExtensionsRefErrorReturnType, SelectFeildStruct, };
@@ -31,5 +31,7 @@ var OutputColumn;
31
31
  OutputColumn["asset_uid"] = "asset_uid";
32
32
  OutputColumn["selectedValue"] = "selectedValue";
33
33
  OutputColumn["fixStatus"] = "fixStatus";
34
+ OutputColumn["field_uid"] = "field_uid";
35
+ OutputColumn["multiple"] = "multiple";
34
36
  })(OutputColumn || (OutputColumn = {}));
35
37
  exports.OutputColumn = OutputColumn;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.0",
2
+ "version": "1.10.0",
3
3
  "commands": {
4
4
  "cm:stacks:audit:fix": {
5
5
  "id": "cm:stacks:audit:fix",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/cli-audit",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Contentstack audit plugin",
5
5
  "author": "Contentstack CLI",
6
6
  "homepage": "https://github.com/contentstack/cli",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@contentstack/cli-command": "~1.3.3",
22
- "@contentstack/cli-utilities": "~1.8.4",
22
+ "@contentstack/cli-utilities": "~1.9.0",
23
23
  "@oclif/plugin-help": "^5.2.20",
24
24
  "@oclif/plugin-plugins": "^5.4.34",
25
25
  "chalk": "^4.1.2",
@@ -30,11 +30,11 @@
30
30
  "winston": "^3.17.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@oclif/test": "^4.1.11",
33
+ "@oclif/test": "^4.1.12",
34
34
  "@types/chai": "^4.3.20",
35
35
  "@types/fs-extra": "^11.0.4",
36
36
  "@types/mocha": "^10.0.10",
37
- "@types/node": "^20.17.19",
37
+ "@types/node": "^20.17.28",
38
38
  "@types/uuid": "^9.0.8",
39
39
  "chai": "^4.5.0",
40
40
  "eslint": "^8.57.1",
@@ -44,7 +44,7 @@
44
44
  "nyc": "^15.1.0",
45
45
  "oclif": "^3.17.2",
46
46
  "shx": "^0.3.4",
47
- "sinon": "^19.0.2",
47
+ "sinon": "^19.0.5",
48
48
  "ts-node": "^10.9.2",
49
49
  "typescript": "^5.7.3"
50
50
  },
@@ -74,7 +74,8 @@
74
74
  "test": "mocha --forbid-only \"test/**/*.test.ts\"",
75
75
  "version": "oclif readme && git add README.md",
76
76
  "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo oclif.manifest.json",
77
- "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
77
+ "test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
78
+ "test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\""
78
79
  },
79
80
  "engines": {
80
81
  "node": ">=16"