Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staging | 24-03-2025 #1821

Merged
merged 26 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
64f356e
test: added test cases for custom roles
Mar 5, 2025
05eae46
fix: resolved conflicts
Mar 5, 2025
e7b26ef
Merge pull request #1806 from contentstack/test1/DX-1303
vkalta Mar 5, 2025
84f89be
Merge branch 'staging' into development
cs-raj Mar 12, 2025
e848bad
Merge pull request #1811 from contentstack/fix/development
cs-raj Mar 12, 2025
2527907
fix: Added Option which has been selected and fixStatus for the selec…
cs-raj Mar 14, 2025
3ac6119
Feat: Added support to fix Select field on on config
cs-raj Mar 15, 2025
a340c54
Added Check in mandatory Feilds
cs-raj Mar 15, 2025
b441cd6
Fixed comments
cs-raj Mar 17, 2025
d36c5b4
Version bump
cs-raj Mar 17, 2025
cb37e1c
Merge pull request #1812 from contentstack/fix/DX-2324
cs-raj Mar 17, 2025
a7252d3
Added Array check for reference feilds
cs-raj Mar 18, 2025
87a8593
Merge pull request #1817 from contentstack/fix/dev2
cs-raj Mar 18, 2025
d40553d
Added log for audit and audit fix
cs-raj Mar 18, 2025
5c198a0
Added to content_type_uid and uid field to references that are in the…
cs-raj Mar 18, 2025
a6abc60
Handled the case of reference not in correct format
cs-raj Mar 19, 2025
2695c2f
Merge pull request #1819 from contentstack/fix/DX-2339
cs-raj Mar 19, 2025
977c992
Fix Meta data
cs-raj Mar 19, 2025
3515f79
Fix
cs-raj Mar 19, 2025
04dd92e
Version bump
cs-raj Mar 20, 2025
e0f5662
Fix Version bump
cs-raj Mar 20, 2025
d3ba728
Merge pull request #1822 from contentstack/fix/VersionBump
harshithad0703 Mar 20, 2025
903e61b
package.json file update
cs-raj Mar 20, 2025
faccd87
Merge pull request #1823 from contentstack/fix/dev3
harshithad0703 Mar 20, 2025
cb1de29
Merge branch 'development' into fix/auditRefMetaData
cs-raj Mar 20, 2025
3615ace
Merge pull request #1824 from contentstack/fix/auditRefMetaData
cs-raj Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
915 changes: 419 additions & 496 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.8.0 darwin-arm64 node-v23.6.0
@contentstack/cli-audit/1.9.0 darwin-arm64 node-v23.6.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -269,7 +269,7 @@ EXAMPLES
$ csdx plugins
```

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

## `csdx plugins:add PLUGIN`

Expand Down Expand Up @@ -343,7 +343,7 @@ EXAMPLES
$ csdx plugins:inspect myplugin
```

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

## `csdx plugins:install PLUGIN`

Expand Down Expand Up @@ -392,7 +392,7 @@ EXAMPLES
$ csdx plugins:install someuser/someplugin
```

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

## `csdx plugins:link PATH`

Expand Down Expand Up @@ -423,7 +423,7 @@ EXAMPLES
$ csdx plugins:link myplugin
```

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

## `csdx plugins:remove [PLUGIN]`

Expand Down Expand Up @@ -464,7 +464,7 @@ FLAGS
--reinstall Reinstall all plugins after uninstalling.
```

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

## `csdx plugins:uninstall [PLUGIN]`

Expand Down Expand Up @@ -492,7 +492,7 @@ EXAMPLES
$ csdx plugins:uninstall myplugin
```

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

## `csdx plugins:unlink [PLUGIN]`

Expand Down Expand Up @@ -536,5 +536,5 @@ DESCRIPTION
Update installed plugins.
```

_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.34/src/commands/plugins/update.ts)_
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.36/src/commands/plugins/update.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.8.0",
"version": "1.9.0",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const config = {
'entry_uid',
'publish_locale',
'publish_environment',
'asset_uid'
'asset_uid',
'selectedValue'
],
ReportTitleForEntries: {
Entries_Select_feild: 'Entries_Select_feild',
Expand All @@ -103,6 +104,7 @@ const config = {
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details'
},
feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details'],
fixSelectField: false
};

export default config;
2 changes: 1 addition & 1 deletion packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const auditMsg = {
SCAN_ASSET_SUCCESS_MSG: `Successfully completed the scanning of Asset with UID '{uid}'.`,
SCAN_ASSET_WARN_MSG: `The locale '{locale}' or environment '{environment}' are not present for asset with uid '{uid}'`,
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`,
CT_REFERENCE_FIELD: `The mentioned Reference Field is not Array field name 'reference_to' having display name 'display_name'`,
CT_REFERENCE_FIELD: `The mentioned Reference field is not Array field reference is '{reference_to}' having display name '{display_name}''`,
ASSET_NOT_EXIST: `The publish_details either does not exist or is not an array for asset uid '{uid}'`,
ENTRY_PUBLISH_DETAILS_NOT_EXIST: `The publish_details either does not exist or is not an array for entry uid '{uid}'`,
};
Expand Down
129 changes: 81 additions & 48 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ export default class ContentType {
this.gfSchema = gfSchema;
this.moduleName = this.validateModules(moduleName!, this.config.moduleConfig);
this.fileName = config.moduleConfig[this.moduleName].fileName;
this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig[this.moduleName].dirName));
this.folderPath = resolve(
sanitizePath(config.basePath),
sanitizePath(config.moduleConfig[this.moduleName].dirName),
);
}

validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig {
validateModules(
moduleName: keyof typeof auditConfig.moduleConfig,
moduleConfig: Record<string, unknown>,
): keyof typeof auditConfig.moduleConfig {
if (Object.keys(moduleConfig).includes(moduleName)) {
return moduleName;
}
return 'content-types'
return 'content-types';
}
/**
* The `run` function checks if a folder path exists, sets the schema based on the module name,
Expand Down Expand Up @@ -121,7 +127,7 @@ export default class ContentType {
if (existsSync(extensionPath)) {
try {
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
} catch (error) { }
} catch (error) {}
}

if (existsSync(marketplacePath)) {
Expand All @@ -134,7 +140,7 @@ export default class ContentType {
) as string[];
this.extensions.push(...metaData);
}
} catch (error) { }
} catch (error) {}
}
}

Expand Down Expand Up @@ -270,19 +276,19 @@ export default class ContentType {

return missingRefs.length
? [
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
: [];
}

Expand Down Expand Up @@ -383,34 +389,46 @@ export default class ContentType {
const missingRefs: string[] = [];
let { reference_to, display_name, data_type } = field;

for (const reference of reference_to ?? []) {
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
if (this.config.skipRefs.includes(reference)) {
continue;
if (!Array.isArray(reference_to)) {
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), 'error');
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
if (!this.config.skipRefs.includes(reference_to)) {
const refExist = find(this.ctSchema, { uid: reference_to });

if (!refExist) {
missingRefs.push(reference_to);
}
}
} else {
for (const reference of reference_to ?? []) {
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
if (this.config.skipRefs.includes(reference)) {
continue;
}

const refExist = find(this.ctSchema, { uid: reference });
const refExist = find(this.ctSchema, { uid: reference });

if (!refExist) {
missingRefs.push(reference);
if (!refExist) {
missingRefs.push(reference);
}
}
}

return missingRefs.length
? [
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
: [];
}

Expand Down Expand Up @@ -635,19 +653,34 @@ export default class ContentType {
let fixStatus;
const missingRefs: string[] = [];
const { reference_to, data_type, display_name } = field;
if(!Array.isArray(reference_to)) {
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, data_type, display_name }), { color: 'green' });
}
for (const reference of reference_to ?? []) {
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
if (this.config.skipRefs.includes(reference)) {
continue;
if (!Array.isArray(reference_to)) {
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'error');
this.log($t(auditMsg.CT_REFERENCE_FIELD, { reference_to, display_name }), 'info');
if (!this.config.skipRefs.includes(reference_to)) {
const refExist = find(this.ctSchema, { uid: reference_to });

if (!refExist) {
missingRefs.push(reference_to);
}
}

field.reference_to = [reference_to];
field.field_metadata = {
...field.field_metadata,
ref_multiple_content_types: true
}
} else {
for (const reference of reference_to ?? []) {
// NOTE Can skip specific references keys (Ex, system defined keys can be skipped)
if (this.config.skipRefs.includes(reference)) {
continue;
}

const refExist = find(this.ctSchema, { uid: reference });
const refExist = find(this.ctSchema, { uid: reference });

if (!refExist) {
missingRefs.push(reference);
if (!refExist) {
missingRefs.push(reference);
}
}
}

Expand Down
Loading
Loading