Skip to content

Commit 766141b

Browse files
authored
Merge pull request #1812 from contentstack/fix/DX-2324
DX - 2324 - Feat: Added Support for audit fix to fix select field based on config and added fixedStatus and selected value
2 parents 0ede720 + 162b3d0 commit 766141b

File tree

10 files changed

+756
-385
lines changed

10 files changed

+756
-385
lines changed

package-lock.json

Lines changed: 336 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-audit/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
1919
$ csdx COMMAND
2020
running command...
2121
$ csdx (--version|-v)
22-
@contentstack/cli-audit/1.8.0 darwin-arm64 node-v23.6.0
22+
@contentstack/cli-audit/1.9.0 darwin-arm64 node-v23.6.0
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND
@@ -269,7 +269,7 @@ EXAMPLES
269269
$ csdx plugins
270270
```
271271

272-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/index.ts)_
272+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
273273

274274
## `csdx plugins:add PLUGIN`
275275

@@ -343,7 +343,7 @@ EXAMPLES
343343
$ csdx plugins:inspect myplugin
344344
```
345345

346-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/inspect.ts)_
346+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
347347

348348
## `csdx plugins:install PLUGIN`
349349

@@ -392,7 +392,7 @@ EXAMPLES
392392
$ csdx plugins:install someuser/someplugin
393393
```
394394

395-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/install.ts)_
395+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
396396

397397
## `csdx plugins:link PATH`
398398

@@ -423,7 +423,7 @@ EXAMPLES
423423
$ csdx plugins:link myplugin
424424
```
425425

426-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/link.ts)_
426+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
427427

428428
## `csdx plugins:remove [PLUGIN]`
429429

@@ -464,7 +464,7 @@ FLAGS
464464
--reinstall Reinstall all plugins after uninstalling.
465465
```
466466

467-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/reset.ts)_
467+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
468468

469469
## `csdx plugins:uninstall [PLUGIN]`
470470

@@ -492,7 +492,7 @@ EXAMPLES
492492
$ csdx plugins:uninstall myplugin
493493
```
494494

495-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/uninstall.ts)_
495+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
496496

497497
## `csdx plugins:unlink [PLUGIN]`
498498

@@ -536,5 +536,5 @@ DESCRIPTION
536536
Update installed plugins.
537537
```
538538

539-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/update.ts)_
539+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
540540
<!-- commandsstop -->

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.8.0",
3+
"version": "1.9.0",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",

packages/contentstack-audit/src/config/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ const config = {
9393
'entry_uid',
9494
'publish_locale',
9595
'publish_environment',
96-
'asset_uid'
96+
'asset_uid',
97+
'selectedValue'
9798
],
9899
ReportTitleForEntries: {
99100
Entries_Select_feild: 'Entries_Select_feild',
@@ -103,6 +104,7 @@ const config = {
103104
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details'
104105
},
105106
feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details'],
107+
fixSelectField: false
106108
};
107109

108110
export default config;

packages/contentstack-audit/src/modules/entries.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ export default class Entries {
332332
field: ContentTypeStruct | GlobalFieldDataType | ModularBlockType | GroupFieldDataType,
333333
entry: EntryFieldType,
334334
) {
335+
335336
if (this.fix) {
336337
entry = this.runFixOnSchema(tree, field.schema as ContentTypeSchemaType[], entry);
337338
}
@@ -846,11 +847,14 @@ export default class Entries {
846847
* @returns
847848
*/
848849
fixSelectField(tree: Record<string, unknown>[], field: SelectFeildStruct, entry: any) {
850+
if(!this.config.fixSelectField) {
851+
return entry;
852+
}
849853
const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
850854

851855
let missingCTSelectFieldValues;
852856
let isMissingValuePresent = false;
853-
857+
let selectedValue: unknown = '';
854858
if (multiple) {
855859
let obj = this.findNotPresentSelectField(entry, selectOptions);
856860
let { notPresent, filteredFeild } = obj;
@@ -868,13 +872,15 @@ export default class Entries {
868872
.slice(0, missingInstances)
869873
.map((choice) => choice.value);
870874
entry.push(...newValues);
875+
selectedValue = newValues;
871876
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), 'error');
872877
}
873878
} else {
874879
if (entry.length === 0) {
875880
isMissingValuePresent = true;
876881
const defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
877882
entry.push(defaultValue);
883+
selectedValue = defaultValue;
878884
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue as string, uid }), 'error');
879885
}
880886
}
@@ -885,6 +891,7 @@ export default class Entries {
885891
isMissingValuePresent = true;
886892
let defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
887893
entry = defaultValue;
894+
selectedValue = defaultValue;
888895
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue as string, uid }), 'error');
889896
}
890897
}
@@ -895,6 +902,7 @@ export default class Entries {
895902
display_name,
896903
display_type,
897904
missingCTSelectFieldValues,
905+
selectedValue,
898906
min_instance: min_instance ?? 'NA',
899907
tree,
900908
treeStr: tree
@@ -909,7 +917,7 @@ export default class Entries {
909917

910918
validateMandatoryFields(tree: Record<string, unknown>[], fieldStructure: any, entry: any) {
911919
const { display_name, multiple, data_type, mandatory, field_metadata, uid } = fieldStructure;
912-
920+
913921
const isJsonRteEmpty = () => {
914922
const jsonNode = multiple
915923
? entry[uid]?.[0]?.children?.[0]?.children?.[0]?.text
@@ -922,6 +930,9 @@ export default class Entries {
922930
if (data_type === 'number' && !multiple) {
923931
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
924932
}
933+
if (data_type === 'text' && !multiple) {
934+
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
935+
}
925936
if (Array.isArray(entry[uid]) && data_type === 'reference') {
926937
fieldValue = entry[uid]?.length ? true : false;
927938
}

packages/contentstack-audit/src/types/content-types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ enum OutputColumn {
158158
'entry_uid' = 'entry_uid',
159159
'publish_locale' = 'publish_locale',
160160
'publish_environment' = 'publish_environment',
161-
'asset_uid' = 'asset_uid'
161+
'asset_uid' = 'asset_uid',
162+
'selectedValue' = 'selectedValue',
163+
'fixStatus' = 'fixStatus'
162164
}
163165

164166
export {

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-audit": "~1.8.0",
8+
"@contentstack/cli-audit": "~1.9.0",
99
"@contentstack/cli-command": "~1.3.3",
1010
"@contentstack/cli-utilities": "~1.8.4",
1111
"@contentstack/management": "~1.18.4",

packages/contentstack/README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli
1818
$ csdx COMMAND
1919
running command...
2020
$ csdx (--version|-v)
21-
@contentstack/cli/1.36.0 darwin-x64 node-v22.14.0
21+
@contentstack/cli/1.36.0 darwin-arm64 node-v23.6.0
2222
$ csdx --help [COMMAND]
2323
USAGE
2424
$ csdx COMMAND
@@ -129,12 +129,12 @@ Perform audits and find possible errors in the exported Contentstack data
129129
```
130130
USAGE
131131
$ csdx audit [--report-path <value>] [--modules
132-
content-types|global-fields|entries|extensions|workflows|custom-roles...] [--columns <value> | ] [--sort <value>]
133-
[--filter <value>] [--csv | --no-truncate]
132+
content-types|global-fields|entries|extensions|workflows|custom-roles|assets...] [--columns <value> | ] [--sort
133+
<value>] [--filter <value>] [--csv | --no-truncate]
134134
135135
FLAGS
136136
--modules=<option>... Provide the list of modules to be audited
137-
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
137+
<options: content-types|global-fields|entries|extensions|workflows|custom-roles|assets>
138138
--report-path=<value> Path to store the audit reports
139139
140140
TABLE FLAGS
@@ -170,7 +170,7 @@ Perform audits and fix possible errors in the exported Contentstack data.
170170
```
171171
USAGE
172172
$ csdx audit:fix [--report-path <value>] [--modules
173-
content-types|global-fields|entries|extensions|workflows|custom-roles...] [--copy-path <value> --copy-dir]
173+
content-types|global-fields|entries|extensions|workflows|custom-roles|assets...] [--copy-path <value> --copy-dir]
174174
[--fix-only reference|global_field|json:rte|json:extension|blocks|group|content_types...] [--columns <value> | ]
175175
[--sort <value>] [--filter <value>] [--csv | --no-truncate]
176176
@@ -180,7 +180,7 @@ FLAGS
180180
--fix-only=<option>... Provide the list of fix options
181181
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
182182
--modules=<option>... Provide the list of modules to be audited
183-
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
183+
<options: content-types|global-fields|entries|extensions|workflows|custom-roles|assets>
184184
--report-path=<value> Path to store the audit reports
185185
186186
TABLE FLAGS
@@ -2346,7 +2346,9 @@ FLAGS
23462346
--personalize-project-name=<value> (optional) Provide a unique name for the Personalize project.
23472347
--replace-existing Replaces the existing module in the target stack.
23482348
--skip-app-recreation (optional) Skips the recreation of private apps if they already exist.
2349+
--skip-assets-publish Skips asset publishing during the import process.
23492350
--skip-audit Skips the audit fix that occurs during an import operation.
2351+
--skip-entries-publish Skips entry publishing during the import process
23502352
--skip-existing Skips the module exists warning messages.
23512353
23522354
DESCRIPTION
@@ -2608,12 +2610,12 @@ Perform audits and find possible errors in the exported Contentstack data
26082610
```
26092611
USAGE
26102612
$ csdx cm:stacks:audit [--report-path <value>] [--modules
2611-
content-types|global-fields|entries|extensions|workflows|custom-roles...] [--columns <value> | ] [--sort <value>]
2612-
[--filter <value>] [--csv | --no-truncate]
2613+
content-types|global-fields|entries|extensions|workflows|custom-roles|assets...] [--columns <value> | ] [--sort
2614+
<value>] [--filter <value>] [--csv | --no-truncate]
26132615
26142616
FLAGS
26152617
--modules=<option>... Provide the list of modules to be audited
2616-
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
2618+
<options: content-types|global-fields|entries|extensions|workflows|custom-roles|assets>
26172619
--report-path=<value> Path to store the audit reports
26182620
26192621
TABLE FLAGS
@@ -2651,7 +2653,7 @@ Perform audits and fix possible errors in the exported Contentstack data.
26512653
```
26522654
USAGE
26532655
$ csdx cm:stacks:audit:fix [--report-path <value>] [--modules
2654-
content-types|global-fields|entries|extensions|workflows|custom-roles...] [--copy-path <value> --copy-dir]
2656+
content-types|global-fields|entries|extensions|workflows|custom-roles|assets...] [--copy-path <value> --copy-dir]
26552657
[--fix-only reference|global_field|json:rte|json:extension|blocks|group|content_types...] [--columns <value> | ]
26562658
[--sort <value>] [--filter <value>] [--csv | --no-truncate]
26572659
@@ -2661,7 +2663,7 @@ FLAGS
26612663
--fix-only=<option>... Provide the list of fix options
26622664
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
26632665
--modules=<option>... Provide the list of modules to be audited
2664-
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
2666+
<options: content-types|global-fields|entries|extensions|workflows|custom-roles|assets>
26652667
--report-path=<value> Path to store the audit reports
26662668
26672669
TABLE FLAGS
@@ -2837,7 +2839,9 @@ FLAGS
28372839
--personalize-project-name=<value> (optional) Provide a unique name for the Personalize project.
28382840
--replace-existing Replaces the existing module in the target stack.
28392841
--skip-app-recreation (optional) Skips the recreation of private apps if they already exist.
2842+
--skip-assets-publish Skips asset publishing during the import process.
28402843
--skip-audit Skips the audit fix that occurs during an import operation.
2844+
--skip-entries-publish Skips entry publishing during the import process
28412845
--skip-existing Skips the module exists warning messages.
28422846
28432847
DESCRIPTION
@@ -3899,7 +3903,7 @@ EXAMPLES
38993903
$ csdx plugins
39003904
```
39013905

3902-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/index.ts)_
3906+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/index.ts)_
39033907

39043908
## `csdx plugins:add PLUGIN`
39053909

@@ -3973,7 +3977,7 @@ EXAMPLES
39733977
$ csdx plugins:inspect myplugin
39743978
```
39753979

3976-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/inspect.ts)_
3980+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/inspect.ts)_
39773981

39783982
## `csdx plugins:install PLUGIN`
39793983

@@ -4022,7 +4026,7 @@ EXAMPLES
40224026
$ csdx plugins:install someuser/someplugin
40234027
```
40244028

4025-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/install.ts)_
4029+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/install.ts)_
40264030

40274031
## `csdx plugins:link PATH`
40284032

@@ -4053,7 +4057,7 @@ EXAMPLES
40534057
$ csdx plugins:link myplugin
40544058
```
40554059

4056-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/link.ts)_
4060+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/link.ts)_
40574061

40584062
## `csdx plugins:remove [PLUGIN]`
40594063

@@ -4094,7 +4098,7 @@ FLAGS
40944098
--reinstall Reinstall all plugins after uninstalling.
40954099
```
40964100

4097-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/reset.ts)_
4101+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/reset.ts)_
40984102

40994103
## `csdx plugins:uninstall [PLUGIN]`
41004104

@@ -4122,7 +4126,7 @@ EXAMPLES
41224126
$ csdx plugins:uninstall myplugin
41234127
```
41244128

4125-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/uninstall.ts)_
4129+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/uninstall.ts)_
41264130

41274131
## `csdx plugins:unlink [PLUGIN]`
41284132

@@ -4166,7 +4170,7 @@ DESCRIPTION
41664170
Update installed plugins.
41674171
```
41684172

4169-
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/update.ts)_
4173+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
41704174

41714175
## `csdx tokens`
41724176

packages/contentstack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prepack": "pnpm compile && oclif manifest && oclif readme"
2323
},
2424
"dependencies": {
25-
"@contentstack/cli-audit": "~1.8.0",
25+
"@contentstack/cli-audit": "~1.9.0",
2626
"@contentstack/cli-auth": "~1.3.24",
2727
"@contentstack/cli-cm-bootstrap": "~1.13.2",
2828
"@contentstack/cli-cm-branches": "~1.3.0",

0 commit comments

Comments
 (0)