@contentstack/cli-audit 1.8.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 +8 -8
- package/lib/audit-base-command.d.ts +1 -0
- package/lib/audit-base-command.js +10 -5
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +6 -3
- package/lib/messages/index.js +1 -1
- package/lib/modules/content-types.js +39 -16
- package/lib/modules/entries.d.ts +3 -0
- package/lib/modules/entries.js +109 -14
- package/lib/modules/index.d.ts +2 -1
- package/lib/modules/index.js +3 -1
- package/lib/types/content-types.d.ts +7 -1
- package/lib/types/content-types.js +4 -0
- package/oclif.manifest.json +1 -1
- package/package.json +7 -6
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.
|
|
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
|
|
@@ -269,7 +269,7 @@ EXAMPLES
|
|
|
269
269
|
$ csdx plugins
|
|
270
270
|
```
|
|
271
271
|
|
|
272
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
272
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
|
|
273
273
|
|
|
274
274
|
## `csdx plugins:add PLUGIN`
|
|
275
275
|
|
|
@@ -343,7 +343,7 @@ EXAMPLES
|
|
|
343
343
|
$ csdx plugins:inspect myplugin
|
|
344
344
|
```
|
|
345
345
|
|
|
346
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
346
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
|
|
347
347
|
|
|
348
348
|
## `csdx plugins:install PLUGIN`
|
|
349
349
|
|
|
@@ -392,7 +392,7 @@ EXAMPLES
|
|
|
392
392
|
$ csdx plugins:install someuser/someplugin
|
|
393
393
|
```
|
|
394
394
|
|
|
395
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
395
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
|
|
396
396
|
|
|
397
397
|
## `csdx plugins:link PATH`
|
|
398
398
|
|
|
@@ -423,7 +423,7 @@ EXAMPLES
|
|
|
423
423
|
$ csdx plugins:link myplugin
|
|
424
424
|
```
|
|
425
425
|
|
|
426
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
426
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
|
|
427
427
|
|
|
428
428
|
## `csdx plugins:remove [PLUGIN]`
|
|
429
429
|
|
|
@@ -464,7 +464,7 @@ FLAGS
|
|
|
464
464
|
--reinstall Reinstall all plugins after uninstalling.
|
|
465
465
|
```
|
|
466
466
|
|
|
467
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
467
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
|
|
468
468
|
|
|
469
469
|
## `csdx plugins:uninstall [PLUGIN]`
|
|
470
470
|
|
|
@@ -492,7 +492,7 @@ EXAMPLES
|
|
|
492
492
|
$ csdx plugins:uninstall myplugin
|
|
493
493
|
```
|
|
494
494
|
|
|
495
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
495
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
|
|
496
496
|
|
|
497
497
|
## `csdx plugins:unlink [PLUGIN]`
|
|
498
498
|
|
|
@@ -536,5 +536,5 @@ DESCRIPTION
|
|
|
536
536
|
Update installed plugins.
|
|
537
537
|
```
|
|
538
538
|
|
|
539
|
-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.
|
|
539
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
|
|
540
540
|
<!-- commandsstop -->
|
|
@@ -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
|
/**
|
package/lib/config/index.d.ts
CHANGED
|
@@ -61,7 +61,9 @@ 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[];
|
|
67
|
+
fixSelectField: boolean;
|
|
66
68
|
};
|
|
67
69
|
export default config;
|
package/lib/config/index.js
CHANGED
|
@@ -95,15 +95,18 @@ const config = {
|
|
|
95
95
|
'entry_uid',
|
|
96
96
|
'publish_locale',
|
|
97
97
|
'publish_environment',
|
|
98
|
-
'asset_uid'
|
|
98
|
+
'asset_uid',
|
|
99
|
+
'selectedValue'
|
|
99
100
|
],
|
|
100
101
|
ReportTitleForEntries: {
|
|
101
102
|
Entries_Select_feild: 'Entries_Select_feild',
|
|
102
103
|
Entries_Mandatory_feild: 'Entries_Mandatory_feild',
|
|
103
104
|
Entries_Title_feild: 'Entries_Title_feild',
|
|
104
105
|
Entry_Missing_Locale_and_Env: 'Entry_Missing_Locale_and_Env',
|
|
105
|
-
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'
|
|
106
108
|
},
|
|
107
|
-
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'],
|
|
110
|
+
fixSelectField: false
|
|
108
111
|
};
|
|
109
112
|
exports.default = config;
|
package/lib/messages/index.js
CHANGED
|
@@ -43,7 +43,7 @@ const auditMsg = {
|
|
|
43
43
|
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
|
|
44
44
|
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
|
|
45
45
|
ENTRY_PUBLISH_DETAILS: `Removing the publish detials for entry '{uid}' of ct '{ctuid}' in locale '{locale}' as locale '{publocale}' or environment '{environment}' does not exist`,
|
|
46
|
-
CT_REFERENCE_FIELD: `The mentioned Reference
|
|
46
|
+
CT_REFERENCE_FIELD: `The mentioned Reference field is not Array field reference is '{reference_to}' having display name '{display_name}''`,
|
|
47
47
|
ASSET_NOT_EXIST: `The publish_details either does not exist or is not an array for asset uid '{uid}'`,
|
|
48
48
|
ENTRY_PUBLISH_DETAILS_NOT_EXIST: `The publish_details either does not exist or is not an array for entry uid '{uid}'`,
|
|
49
49
|
};
|
|
@@ -288,14 +288,26 @@ class ContentType {
|
|
|
288
288
|
return [];
|
|
289
289
|
const missingRefs = [];
|
|
290
290
|
let { reference_to, display_name, data_type } = field;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
291
|
+
if (!Array.isArray(reference_to)) {
|
|
292
|
+
this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), 'error');
|
|
293
|
+
this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
|
|
294
|
+
if (!this.config.skipRefs.includes(reference_to)) {
|
|
295
|
+
const refExist = (0, find_1.default)(this.ctSchema, { uid: reference_to });
|
|
296
|
+
if (!refExist) {
|
|
297
|
+
missingRefs.push(reference_to);
|
|
298
|
+
}
|
|
295
299
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
|
|
303
|
+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
|
|
304
|
+
if (this.config.skipRefs.includes(reference)) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const refExist = (0, find_1.default)(this.ctSchema, { uid: reference });
|
|
308
|
+
if (!refExist) {
|
|
309
|
+
missingRefs.push(reference);
|
|
310
|
+
}
|
|
299
311
|
}
|
|
300
312
|
}
|
|
301
313
|
return missingRefs.length
|
|
@@ -511,16 +523,27 @@ class ContentType {
|
|
|
511
523
|
const missingRefs = [];
|
|
512
524
|
const { reference_to, data_type, display_name } = field;
|
|
513
525
|
if (!Array.isArray(reference_to)) {
|
|
514
|
-
this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to,
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
526
|
+
this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'error');
|
|
527
|
+
this.log((0, messages_1.$t)(messages_1.auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
|
|
528
|
+
if (!this.config.skipRefs.includes(reference_to)) {
|
|
529
|
+
const refExist = (0, find_1.default)(this.ctSchema, { uid: reference_to });
|
|
530
|
+
if (!refExist) {
|
|
531
|
+
missingRefs.push(reference_to);
|
|
532
|
+
}
|
|
520
533
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
534
|
+
field.reference_to = [reference_to];
|
|
535
|
+
field.field_metadata = Object.assign(Object.assign({}, field.field_metadata), { ref_multiple_content_types: true });
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
for (const reference of reference_to !== null && reference_to !== void 0 ? reference_to : []) {
|
|
539
|
+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
|
|
540
|
+
if (this.config.skipRefs.includes(reference)) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const refExist = (0, find_1.default)(this.ctSchema, { uid: reference });
|
|
544
|
+
if (!refExist) {
|
|
545
|
+
missingRefs.push(reference);
|
|
546
|
+
}
|
|
524
547
|
}
|
|
525
548
|
}
|
|
526
549
|
if (this.fix && !(0, isEmpty_1.default)(missingRefs)) {
|
package/lib/modules/entries.d.ts
CHANGED
|
@@ -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.
|
package/lib/modules/entries.js
CHANGED
|
@@ -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';
|
|
@@ -133,10 +134,24 @@ class Entries {
|
|
|
133
134
|
environment: pd.environment,
|
|
134
135
|
}), { color: 'red' });
|
|
135
136
|
if (!Object.keys(this.missingEnvLocale).includes(entryUid)) {
|
|
136
|
-
this.missingEnvLocale[entryUid] = [
|
|
137
|
+
this.missingEnvLocale[entryUid] = [
|
|
138
|
+
{
|
|
139
|
+
entry_uid: entryUid,
|
|
140
|
+
publish_locale: pd.locale,
|
|
141
|
+
publish_environment: pd.environment,
|
|
142
|
+
ctUid: ctSchema.uid,
|
|
143
|
+
ctLocale: code,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
137
146
|
}
|
|
138
147
|
else {
|
|
139
|
-
this.missingEnvLocale[entryUid].push({
|
|
148
|
+
this.missingEnvLocale[entryUid].push({
|
|
149
|
+
entry_uid: entryUid,
|
|
150
|
+
publish_locale: pd.locale,
|
|
151
|
+
publish_environment: pd.environment,
|
|
152
|
+
ctUid: ctSchema.uid,
|
|
153
|
+
ctLocale: code,
|
|
154
|
+
});
|
|
140
155
|
}
|
|
141
156
|
return false;
|
|
142
157
|
}
|
|
@@ -163,6 +178,7 @@ class Entries {
|
|
|
163
178
|
missingMandatoryFields: this.missingMandatoryFields,
|
|
164
179
|
missingTitleFields: this.missingTitleFields,
|
|
165
180
|
missingEnvLocale: this.missingEnvLocale,
|
|
181
|
+
missingMultipleFields: this.missingMultipleField
|
|
166
182
|
};
|
|
167
183
|
}
|
|
168
184
|
/**
|
|
@@ -260,7 +276,24 @@ class Entries {
|
|
|
260
276
|
entry = this.runFixOnSchema(tree, field.schema, entry);
|
|
261
277
|
}
|
|
262
278
|
for (const child of (_a = field === null || field === void 0 ? void 0 : field.schema) !== null && _a !== void 0 ? _a : []) {
|
|
263
|
-
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
|
+
}
|
|
264
297
|
this.missingMandatoryFields[this.currentUid].push(...this.validateMandatoryFields([...tree, { uid: field.uid, name: child.display_name, field: uid }], child, entry));
|
|
265
298
|
if (!(entry === null || entry === void 0 ? void 0 : entry[uid]) && !child.hasOwnProperty('display_type')) {
|
|
266
299
|
continue;
|
|
@@ -468,15 +501,28 @@ class Entries {
|
|
|
468
501
|
if (this.fix)
|
|
469
502
|
return [];
|
|
470
503
|
const missingRefs = [];
|
|
471
|
-
const { uid: data_type, display_name } = fieldStructure;
|
|
504
|
+
const { uid: data_type, display_name, reference_to } = fieldStructure;
|
|
472
505
|
for (const index in field !== null && field !== void 0 ? field : []) {
|
|
473
506
|
const reference = field[index];
|
|
474
507
|
const { uid } = reference;
|
|
508
|
+
if (!uid && reference.startsWith('blt')) {
|
|
509
|
+
const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
|
|
510
|
+
if (!refExist) {
|
|
511
|
+
if (Array.isArray(reference_to) && reference_to.length === 1) {
|
|
512
|
+
missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
|
|
513
|
+
}
|
|
514
|
+
else {
|
|
515
|
+
missingRefs.push(reference);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
475
519
|
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
|
|
476
520
|
// if (this.config.skipRefs.includes(reference)) continue;
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
521
|
+
else {
|
|
522
|
+
const refExist = (0, find_1.default)(this.entryMetaData, { uid });
|
|
523
|
+
if (!refExist) {
|
|
524
|
+
missingRefs.push(reference);
|
|
525
|
+
}
|
|
480
526
|
}
|
|
481
527
|
}
|
|
482
528
|
return missingRefs.length
|
|
@@ -524,10 +570,29 @@ class Entries {
|
|
|
524
570
|
runFixOnSchema(tree, schema, entry) {
|
|
525
571
|
// NOTE Global field Fix
|
|
526
572
|
schema.forEach((field) => {
|
|
527
|
-
|
|
573
|
+
var _a;
|
|
574
|
+
var _b, _c;
|
|
575
|
+
const { uid, data_type, multiple } = field;
|
|
528
576
|
if (!Object(entry).hasOwnProperty(uid)) {
|
|
529
577
|
return;
|
|
530
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
|
+
}
|
|
531
596
|
switch (data_type) {
|
|
532
597
|
case 'global_field':
|
|
533
598
|
entry[uid] = this.fixGlobalFieldReferences([...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }], field, entry[uid]);
|
|
@@ -644,9 +709,13 @@ class Entries {
|
|
|
644
709
|
* @returns
|
|
645
710
|
*/
|
|
646
711
|
fixSelectField(tree, field, entry) {
|
|
712
|
+
if (!this.config.fixSelectField) {
|
|
713
|
+
return entry;
|
|
714
|
+
}
|
|
647
715
|
const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
|
|
648
716
|
let missingCTSelectFieldValues;
|
|
649
717
|
let isMissingValuePresent = false;
|
|
718
|
+
let selectedValue = '';
|
|
650
719
|
if (multiple) {
|
|
651
720
|
let obj = this.findNotPresentSelectField(entry, selectOptions);
|
|
652
721
|
let { notPresent, filteredFeild } = obj;
|
|
@@ -664,6 +733,7 @@ class Entries {
|
|
|
664
733
|
.slice(0, missingInstances)
|
|
665
734
|
.map((choice) => choice.value);
|
|
666
735
|
entry.push(...newValues);
|
|
736
|
+
selectedValue = newValues;
|
|
667
737
|
this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), 'error');
|
|
668
738
|
}
|
|
669
739
|
}
|
|
@@ -672,6 +742,7 @@ class Entries {
|
|
|
672
742
|
isMissingValuePresent = true;
|
|
673
743
|
const defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
|
|
674
744
|
entry.push(defaultValue);
|
|
745
|
+
selectedValue = defaultValue;
|
|
675
746
|
this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
|
|
676
747
|
}
|
|
677
748
|
}
|
|
@@ -683,6 +754,7 @@ class Entries {
|
|
|
683
754
|
isMissingValuePresent = true;
|
|
684
755
|
let defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
|
|
685
756
|
entry = defaultValue;
|
|
757
|
+
selectedValue = defaultValue;
|
|
686
758
|
this.log((0, messages_1.$t)(messages_1.auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue, uid }), 'error');
|
|
687
759
|
}
|
|
688
760
|
}
|
|
@@ -693,6 +765,7 @@ class Entries {
|
|
|
693
765
|
display_name,
|
|
694
766
|
display_type,
|
|
695
767
|
missingCTSelectFieldValues,
|
|
768
|
+
selectedValue,
|
|
696
769
|
min_instance: min_instance !== null && min_instance !== void 0 ? min_instance : 'NA',
|
|
697
770
|
tree,
|
|
698
771
|
treeStr: tree
|
|
@@ -719,6 +792,9 @@ class Entries {
|
|
|
719
792
|
if (data_type === 'number' && !multiple) {
|
|
720
793
|
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
|
|
721
794
|
}
|
|
795
|
+
if (data_type === 'text' && !multiple) {
|
|
796
|
+
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
|
|
797
|
+
}
|
|
722
798
|
if (Array.isArray(entry[uid]) && data_type === 'reference') {
|
|
723
799
|
fieldValue = ((_b = entry[uid]) === null || _b === void 0 ? void 0 : _b.length) ? true : false;
|
|
724
800
|
}
|
|
@@ -924,12 +1000,31 @@ class Entries {
|
|
|
924
1000
|
}
|
|
925
1001
|
entry = entry === null || entry === void 0 ? void 0 : entry.map((reference) => {
|
|
926
1002
|
const { uid } = reference;
|
|
927
|
-
const
|
|
928
|
-
if (!
|
|
929
|
-
|
|
930
|
-
|
|
1003
|
+
const { reference_to } = field;
|
|
1004
|
+
if (!uid && reference.startsWith('blt')) {
|
|
1005
|
+
const refExist = (0, find_1.default)(this.entryMetaData, { uid: reference });
|
|
1006
|
+
if (!refExist) {
|
|
1007
|
+
if (Array.isArray(reference_to) && reference_to.length === 1) {
|
|
1008
|
+
missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
missingRefs.push(reference);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
else {
|
|
1015
|
+
return { uid: reference, _content_type_uid: refExist.ctUid };
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
else {
|
|
1019
|
+
const refExist = (0, find_1.default)(this.entryMetaData, { uid });
|
|
1020
|
+
if (!refExist) {
|
|
1021
|
+
missingRefs.push(reference);
|
|
1022
|
+
return null;
|
|
1023
|
+
}
|
|
1024
|
+
else {
|
|
1025
|
+
return reference;
|
|
1026
|
+
}
|
|
931
1027
|
}
|
|
932
|
-
return reference;
|
|
933
1028
|
}).filter((val) => val);
|
|
934
1029
|
if (!(0, isEmpty_1.default)(missingRefs)) {
|
|
935
1030
|
this.missingRefs[this.currentUid].push({
|
|
@@ -1056,7 +1151,7 @@ class Entries {
|
|
|
1056
1151
|
else if (!title) {
|
|
1057
1152
|
this.log(`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`, `error`);
|
|
1058
1153
|
}
|
|
1059
|
-
this.entryMetaData.push({ uid: entryUid, title });
|
|
1154
|
+
this.entryMetaData.push({ uid: entryUid, title, ctUid: uid });
|
|
1060
1155
|
}
|
|
1061
1156
|
}
|
|
1062
1157
|
}
|
package/lib/modules/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import GlobalField from './global-fields';
|
|
|
3
3
|
import ContentType from './content-types';
|
|
4
4
|
import Workflows from './workflows';
|
|
5
5
|
import Extensions from './extensions';
|
|
6
|
+
import CustomRoles from './custom-roles';
|
|
6
7
|
import Assets from './assets';
|
|
7
|
-
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets };
|
|
8
|
+
export { Entries, GlobalField, ContentType, Workflows, Extensions, Assets, CustomRoles };
|
package/lib/modules/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Assets = exports.Extensions = exports.Workflows = exports.ContentType = exports.GlobalField = exports.Entries = void 0;
|
|
3
|
+
exports.CustomRoles = exports.Assets = exports.Extensions = exports.Workflows = exports.ContentType = exports.GlobalField = exports.Entries = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const entries_1 = tslib_1.__importDefault(require("./entries"));
|
|
6
6
|
exports.Entries = entries_1.default;
|
|
@@ -12,5 +12,7 @@ const workflows_1 = tslib_1.__importDefault(require("./workflows"));
|
|
|
12
12
|
exports.Workflows = workflows_1.default;
|
|
13
13
|
const extensions_1 = tslib_1.__importDefault(require("./extensions"));
|
|
14
14
|
exports.Extensions = extensions_1.default;
|
|
15
|
+
const custom_roles_1 = tslib_1.__importDefault(require("./custom-roles"));
|
|
16
|
+
exports.CustomRoles = custom_roles_1.default;
|
|
15
17
|
const assets_1 = tslib_1.__importDefault(require("./assets"));
|
|
16
18
|
exports.Assets = assets_1.default;
|
|
@@ -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;
|
|
@@ -112,6 +114,10 @@ declare enum OutputColumn {
|
|
|
112
114
|
'entry_uid' = "entry_uid",
|
|
113
115
|
'publish_locale' = "publish_locale",
|
|
114
116
|
'publish_environment' = "publish_environment",
|
|
115
|
-
'asset_uid' = "asset_uid"
|
|
117
|
+
'asset_uid' = "asset_uid",
|
|
118
|
+
'selectedValue' = "selectedValue",
|
|
119
|
+
'fixStatus' = "fixStatus",
|
|
120
|
+
'field_uid' = "field_uid",
|
|
121
|
+
'multiple' = "multiple"
|
|
116
122
|
}
|
|
117
123
|
export { CtConstructorParam, ContentTypeStruct, ModuleConstructorParam, ReferenceFieldDataType, GlobalFieldDataType, ExtensionOrAppFieldDataType, JsonRTEFieldDataType, GroupFieldDataType, ModularBlocksDataType, RefErrorReturnType, ModularBlocksSchemaTypes, ModularBlockType, OutputColumn, ContentTypeSchemaType, GlobalFieldSchemaTypes, WorkflowExtensionsRefErrorReturnType, SelectFeildStruct, };
|
|
@@ -29,5 +29,9 @@ var OutputColumn;
|
|
|
29
29
|
OutputColumn["publish_locale"] = "publish_locale";
|
|
30
30
|
OutputColumn["publish_environment"] = "publish_environment";
|
|
31
31
|
OutputColumn["asset_uid"] = "asset_uid";
|
|
32
|
+
OutputColumn["selectedValue"] = "selectedValue";
|
|
33
|
+
OutputColumn["fixStatus"] = "fixStatus";
|
|
34
|
+
OutputColumn["field_uid"] = "field_uid";
|
|
35
|
+
OutputColumn["multiple"] = "multiple";
|
|
32
36
|
})(OutputColumn || (OutputColumn = {}));
|
|
33
37
|
exports.OutputColumn = OutputColumn;
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-audit",
|
|
3
|
-
"version": "1.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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"
|