Skip to content

Commit 8ec443f

Browse files
committed
merged changes from dev
2 parents 9248208 + ad411a1 commit 8ec443f

37 files changed

Lines changed: 4077 additions & 3880 deletions

File tree

package-lock.json

Lines changed: 2278 additions & 2317 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: 1 addition & 1 deletion
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.9.0 darwin-arm64 node-v22.13.1
22+
@contentstack/cli-audit/1.10.0 darwin-arm64 node-v22.13.1
2323
$ csdx --help [COMMAND]
2424
USAGE
2525
$ csdx COMMAND

packages/contentstack-audit/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-audit",
3-
"version": "1.9.0",
3+
"version": "1.10.0",
44
"description": "Contentstack audit plugin",
55
"author": "Contentstack CLI",
66
"homepage": "https://github.com/contentstack/cli",
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@contentstack/cli-command": "~1.4.0",
2222
"@oclif/plugin-help": "^6.2.25",
23-
"@contentstack/cli-utilities": "~1.9.0",
23+
"@contentstack/cli-utilities": "~1.10.0",
2424
"@oclif/plugin-plugins": "^5.4.24",
2525
"chalk": "^4.1.2",
2626
"fast-csv": "^4.3.6",
@@ -44,7 +44,7 @@
4444
"nyc": "^15.1.0",
4545
"oclif": "^4.17.30",
4646
"shx": "^0.3.4",
47-
"sinon": "^19.0.2",
47+
"sinon": "^19.0.5",
4848
"ts-node": "^10.9.2",
4949
"typescript": "^5.7.3"
5050
},

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ const config = {
4040
dirName: 'custom-roles',
4141
fileName: 'custom-roles.json',
4242
},
43-
'assets': {
43+
assets: {
4444
name: 'assets',
4545
dirName: 'assets',
4646
fileName: 'assets.json',
4747
},
48-
'environments': {
48+
environments: {
4949
name: 'environments',
5050
dirName: 'environments',
5151
fileName: 'environments.json',
52-
}
52+
},
5353
},
5454
entries: {
5555
systemKeys: [
@@ -93,16 +93,23 @@ 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',
100101
Entries_Mandatory_feild: 'Entries_Mandatory_feild',
101102
Entries_Title_feild: 'Entries_Title_feild',
102103
Entry_Missing_Locale_and_Env: 'Entry_Missing_Locale_and_Env',
103-
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details'
104+
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details',
104105
},
105-
feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details'],
106+
feild_level_modules: [
107+
'Entries_Title_feild',
108+
'Entries_Mandatory_feild',
109+
'Entries_Select_feild',
110+
'Entry_Missing_Locale_and_Env_in_Publish_Details',
111+
],
112+
fixSelectField: false,
106113
};
107114

108115
export default config;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const auditMsg = {
4040
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
4141
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
4242
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`,
43-
CT_REFERENCE_FIELD: `The mentioned Reference Field is not Array field name 'reference_to' having display name 'display_name'`,
43+
CT_REFERENCE_FIELD: `The mentioned Reference field is not Array field reference is '{reference_to}' having display name '{display_name}''`,
4444
ASSET_NOT_EXIST: `The publish_details either does not exist or is not an array for asset uid '{uid}'`,
4545
ENTRY_PUBLISH_DETAILS_NOT_EXIST: `The publish_details either does not exist or is not an array for entry uid '{uid}'`,
4646
};

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { join, resolve } from 'path';
22
import { existsSync, readFileSync, writeFileSync } from 'fs';
3-
43
import { FsUtility, sanitizePath, cliux } from '@contentstack/cli-utilities';
5-
64
import {
75
LogFn,
86
ConfigType,

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

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -389,16 +389,28 @@ export default class ContentType {
389389
const missingRefs: string[] = [];
390390
let { reference_to, display_name, data_type } = field;
391391

392-
for (const reference of reference_to ?? []) {
393-
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
394-
if (this.config.skipRefs.includes(reference)) {
395-
continue;
392+
if (!Array.isArray(reference_to)) {
393+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), 'error');
394+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
395+
if (!this.config.skipRefs.includes(reference_to)) {
396+
const refExist = find(this.ctSchema, { uid: reference_to });
397+
398+
if (!refExist) {
399+
missingRefs.push(reference_to);
400+
}
396401
}
402+
} else {
403+
for (const reference of reference_to ?? []) {
404+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
405+
if (this.config.skipRefs.includes(reference)) {
406+
continue;
407+
}
397408

398-
const refExist = find(this.ctSchema, { uid: reference });
409+
const refExist = find(this.ctSchema, { uid: reference });
399410

400-
if (!refExist) {
401-
missingRefs.push(reference);
411+
if (!refExist) {
412+
missingRefs.push(reference);
413+
}
402414
}
403415
}
404416

@@ -641,19 +653,34 @@ export default class ContentType {
641653
let fixStatus;
642654
const missingRefs: string[] = [];
643655
const { reference_to, data_type, display_name } = field;
644-
if(!Array.isArray(reference_to)) {
645-
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), { color: 'green' });
646-
}
647-
for (const reference of reference_to ?? []) {
648-
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
649-
if (this.config.skipRefs.includes(reference)) {
650-
continue;
656+
if (!Array.isArray(reference_to)) {
657+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'error');
658+
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
659+
if (!this.config.skipRefs.includes(reference_to)) {
660+
const refExist = find(this.ctSchema, { uid: reference_to });
661+
662+
if (!refExist) {
663+
missingRefs.push(reference_to);
664+
}
651665
}
652666

653-
const refExist = find(this.ctSchema, { uid: reference });
667+
field.reference_to = [reference_to];
668+
field.field_metadata = {
669+
...field.field_metadata,
670+
ref_multiple_content_types: true,
671+
};
672+
} else {
673+
for (const reference of reference_to ?? []) {
674+
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
675+
if (this.config.skipRefs.includes(reference)) {
676+
continue;
677+
}
654678

655-
if (!refExist) {
656-
missingRefs.push(reference);
679+
const refExist = find(this.ctSchema, { uid: reference });
680+
681+
if (!refExist) {
682+
missingRefs.push(reference);
683+
}
657684
}
658685
}
659686

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

Lines changed: 68 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class Entries {
175175

176176
const localKey = this.locales.map((locale: any) => locale.code);
177177

178-
if(this.entries[entryUid]?.publish_details && !Array.isArray(this.entries[entryUid].publish_details)) {
178+
if (this.entries[entryUid]?.publish_details && !Array.isArray(this.entries[entryUid].publish_details)) {
179179
this.log($t(auditMsg.ENTRY_PUBLISH_DETAILS_NOT_EXIST, { uid: entryUid }), { color: 'red' });
180180
}
181181

@@ -194,11 +194,23 @@ export default class Entries {
194194
{ color: 'red' },
195195
);
196196
if (!Object.keys(this.missingEnvLocale).includes(entryUid)) {
197-
this.missingEnvLocale[entryUid] = [{ entry_uid: entryUid, publish_locale: pd.locale, publish_environment: pd.environment, ctUid: ctSchema.uid, ctLocale: code }];
197+
this.missingEnvLocale[entryUid] = [
198+
{
199+
entry_uid: entryUid,
200+
publish_locale: pd.locale,
201+
publish_environment: pd.environment,
202+
ctUid: ctSchema.uid,
203+
ctLocale: code,
204+
},
205+
];
198206
} else {
199-
this.missingEnvLocale[entryUid].push(
200-
{ entry_uid: entryUid, publish_locale: pd.locale, publish_environment: pd.environment, ctUid: ctSchema.uid, ctLocale: code },
201-
);
207+
this.missingEnvLocale[entryUid].push({
208+
entry_uid: entryUid,
209+
publish_locale: pd.locale,
210+
publish_environment: pd.environment,
211+
ctUid: ctSchema.uid,
212+
ctLocale: code,
213+
});
202214
}
203215
return false;
204216
}
@@ -630,18 +642,29 @@ export default class Entries {
630642
if (this.fix) return [];
631643

632644
const missingRefs: Record<string, any>[] = [];
633-
const { uid: data_type, display_name } = fieldStructure;
645+
const { uid: data_type, display_name, reference_to } = fieldStructure;
634646

635647
for (const index in field ?? []) {
636-
const reference = field[index];
648+
const reference: any = field[index];
637649
const { uid } = reference;
650+
if (!uid && reference.startsWith('blt')) {
651+
const refExist = find(this.entryMetaData, { uid: reference });
652+
if (!refExist) {
653+
if (Array.isArray(reference_to) && reference_to.length === 1) {
654+
missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
655+
} else {
656+
missingRefs.push(reference);
657+
}
658+
}
659+
}
638660
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
639661
// if (this.config.skipRefs.includes(reference)) continue;
662+
else {
663+
const refExist = find(this.entryMetaData, { uid });
640664

641-
const refExist = find(this.entryMetaData, { uid });
642-
643-
if (!refExist) {
644-
missingRefs.push(reference);
665+
if (!refExist) {
666+
missingRefs.push(reference);
667+
}
645668
}
646669
}
647670

@@ -846,11 +869,14 @@ export default class Entries {
846869
* @returns
847870
*/
848871
fixSelectField(tree: Record<string, unknown>[], field: SelectFeildStruct, entry: any) {
872+
if (!this.config.fixSelectField) {
873+
return entry;
874+
}
849875
const { enum: selectOptions, multiple, min_instance, display_type, display_name, uid } = field;
850876

851877
let missingCTSelectFieldValues;
852878
let isMissingValuePresent = false;
853-
879+
let selectedValue: unknown = '';
854880
if (multiple) {
855881
let obj = this.findNotPresentSelectField(entry, selectOptions);
856882
let { notPresent, filteredFeild } = obj;
@@ -868,13 +894,15 @@ export default class Entries {
868894
.slice(0, missingInstances)
869895
.map((choice) => choice.value);
870896
entry.push(...newValues);
897+
selectedValue = newValues;
871898
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: newValues.join(' '), uid }), 'error');
872899
}
873900
} else {
874901
if (entry.length === 0) {
875902
isMissingValuePresent = true;
876903
const defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
877904
entry.push(defaultValue);
905+
selectedValue = defaultValue;
878906
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue as string, uid }), 'error');
879907
}
880908
}
@@ -885,6 +913,7 @@ export default class Entries {
885913
isMissingValuePresent = true;
886914
let defaultValue = selectOptions.choices.length > 0 ? selectOptions.choices[0].value : null;
887915
entry = defaultValue;
916+
selectedValue = defaultValue;
888917
this.log($t(auditFixMsg.ENTRY_SELECT_FIELD_FIX, { value: defaultValue as string, uid }), 'error');
889918
}
890919
}
@@ -895,6 +924,7 @@ export default class Entries {
895924
display_name,
896925
display_type,
897926
missingCTSelectFieldValues,
927+
selectedValue,
898928
min_instance: min_instance ?? 'NA',
899929
tree,
900930
treeStr: tree
@@ -909,7 +939,7 @@ export default class Entries {
909939

910940
validateMandatoryFields(tree: Record<string, unknown>[], fieldStructure: any, entry: any) {
911941
const { display_name, multiple, data_type, mandatory, field_metadata, uid } = fieldStructure;
912-
942+
913943
const isJsonRteEmpty = () => {
914944
const jsonNode = multiple
915945
? entry[uid]?.[0]?.children?.[0]?.children?.[0]?.text
@@ -922,6 +952,9 @@ export default class Entries {
922952
if (data_type === 'number' && !multiple) {
923953
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
924954
}
955+
if (data_type === 'text' && !multiple) {
956+
fieldValue = entry[uid] || entry[uid] === 0 ? true : false;
957+
}
925958
if (Array.isArray(entry[uid]) && data_type === 'reference') {
926959
fieldValue = entry[uid]?.length ? true : false;
927960
}
@@ -1186,16 +1219,29 @@ export default class Entries {
11861219
entry = JSON.parse(stringReference);
11871220
}
11881221
entry = entry
1189-
?.map((reference) => {
1222+
?.map((reference: any) => {
11901223
const { uid } = reference;
1191-
const refExist = find(this.entryMetaData, { uid });
1192-
1193-
if (!refExist) {
1194-
missingRefs.push(reference);
1195-
return null;
1224+
const { reference_to } = field;
1225+
if (!uid && reference.startsWith('blt')) {
1226+
const refExist = find(this.entryMetaData, { uid: reference });
1227+
if (!refExist) {
1228+
if (Array.isArray(reference_to) && reference_to.length === 1) {
1229+
missingRefs.push({ uid: reference, _content_type_uid: reference_to[0] });
1230+
} else {
1231+
missingRefs.push(reference);
1232+
}
1233+
} else {
1234+
return { uid: reference, _content_type_uid: refExist.ctUid };
1235+
}
1236+
} else {
1237+
const refExist = find(this.entryMetaData, { uid });
1238+
if (!refExist) {
1239+
missingRefs.push(reference);
1240+
return null;
1241+
} else {
1242+
return reference;
1243+
}
11961244
}
1197-
1198-
return reference;
11991245
})
12001246
.filter((val) => val) as EntryReferenceFieldDataType[];
12011247

@@ -1353,7 +1399,7 @@ export default class Entries {
13531399
`error`,
13541400
);
13551401
}
1356-
this.entryMetaData.push({ uid: entryUid, title });
1402+
this.entryMetaData.push({ uid: entryUid, title, ctUid: uid });
13571403
}
13581404
}
13591405
}

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-auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"dependencies": {
2525
"@contentstack/cli-command": "~1.4.0",
26-
"@contentstack/cli-utilities": "~1.9.0"
26+
"@contentstack/cli-utilities": "~1.10.0"
2727
},
2828
"devDependencies": {
2929
"@fancy-test/nock": "^0.1.1",

0 commit comments

Comments
 (0)