Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import { join, resolve } from 'path';
import cloneDeep from 'lodash/cloneDeep';
import { cliux, sanitizePath, TableFlags, TableHeader } from '@contentstack/cli-utilities';
import { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'fs';

import config from './config';
import { print } from './util/log';
import { auditMsg } from './messages';
import { BaseCommand } from './base-command';
import { Entries, GlobalField, ContentType, Extensions, Workflows, Assets } from './modules';
import { Entries, GlobalField, ContentType, Extensions, Workflows, Assets, FieldRule } from './modules';
import {
CommandNames,
ContentTypeStruct,
Expand Down Expand Up @@ -61,6 +60,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingRefInCustomRoles,
missingEnvLocalesInAssets,
missingEnvLocalesInEntries,
missingFieldRules,
missingMultipleFields
} = await this.scanAndFix();

Expand All @@ -71,6 +71,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Extensions', missingRefs: missingCtRefsInExtensions }]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Workflows', missingRefs: missingCtRefsInWorkflow }]);

this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Select Field', missingRefs: missingSelectFeild }]);
this.showOutputOnScreenWorkflowsAndExtension([
{ module: 'Entries Mandatory Field', missingRefs: missingMandatoryFields },
Expand All @@ -79,6 +80,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Custom Roles', missingRefs: missingRefInCustomRoles }]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Assets', missingRefs: missingEnvLocalesInAssets }]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Missing Locale and Environments', missingRefs: missingEnvLocalesInEntries }])
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Field Rules', missingRefs: missingFieldRules }])

this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Entries Changed Multiple Fields', missingRefs: missingMultipleFields }])
if (
!isEmpty(missingCtRefs) ||
Expand All @@ -90,7 +93,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingTitleFields) ||
!isEmpty(missingRefInCustomRoles) ||
!isEmpty(missingEnvLocalesInAssets) ||
!isEmpty(missingEnvLocalesInEntries) ||
!isEmpty(missingEnvLocalesInEntries) ||
!isEmpty(missingFieldRules) ||
!isEmpty(missingMultipleFields)
) {
if (this.currentCommand === 'cm:stacks:audit') {
Expand Down Expand Up @@ -121,7 +125,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingSelectFeild) ||
!isEmpty(missingRefInCustomRoles) ||
!isEmpty(missingEnvLocalesInAssets) ||
!isEmpty(missingEnvLocalesInEntries)
!isEmpty(missingEnvLocalesInEntries) ||
!isEmpty(missingFieldRules)
);
}

Expand All @@ -145,6 +150,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingRefInCustomRoles,
missingEnvLocalesInAssets,
missingEnvLocalesInEntries,
missingFieldRules,
missingMultipleFields;

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
Expand Down Expand Up @@ -216,6 +222,10 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingRefInCustomRoles = await new CustomRoles(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingRefInCustomRoles);
break;
case 'field-rules':
missingFieldRules = await new FieldRule(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingFieldRules);
break;
}

print([
Expand Down Expand Up @@ -244,6 +254,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingRefInCustomRoles,
missingEnvLocalesInAssets,
missingEnvLocalesInEntries,
missingFieldRules,
missingMultipleFields
};
}
Expand Down Expand Up @@ -404,7 +415,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
key === 'content_types' ||
key === 'branches' ||
key === 'missingCTSelectFieldValues' ||
key === 'missingFieldUid'
key === 'missingFieldUid' ||
key === 'action'
) {
return chalk.red(typeof cellValue === 'object' ? JSON.stringify(cellValue) : cellValue);
} else {
Expand All @@ -429,7 +441,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* @returns The function `prepareReport` returns a Promise that resolves to `void`.
*/
prepareReport(
moduleName: keyof typeof config.moduleConfig | keyof typeof config.ReportTitleForEntries,
moduleName: keyof typeof config.moduleConfig | keyof typeof config.ReportTitleForEntries | 'field-rules',
listOfMissingRefs: Record<string, any>,
): Promise<void> {
if (isEmpty(listOfMissingRefs)) return Promise.resolve(void 0);
Expand Down Expand Up @@ -459,7 +471,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
* @returns The function `prepareCSV` returns a Promise that resolves to `void`.
*/
prepareCSV(
moduleName: keyof typeof config.moduleConfig | keyof typeof config.ReportTitleForEntries,
moduleName: keyof typeof config.moduleConfig | keyof typeof config.ReportTitleForEntries | 'field-rules',
listOfMissingRefs: Record<string, any>,
): Promise<void> {
if (Object.keys(config.moduleConfig).includes(moduleName) || config.feild_level_modules.includes(moduleName)) {
Expand Down
26 changes: 22 additions & 4 deletions packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ const config = {
showTerminalOutput: true,
skipRefs: ['sys_assets'],
skipFieldTypes: ['taxonomy', 'group'],
modules: ['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles', 'assets'],
modules: [
'content-types',
'global-fields',
'entries',
'extensions',
'workflows',
'custom-roles',
'assets',
'field-rules',
],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group', 'content_types'],
moduleConfig: {
'content-types': {
Expand Down Expand Up @@ -95,17 +104,26 @@ const config = {
'publish_environment',
'asset_uid',
'selectedValue',
'ct_uid',
'action',
],
ReportTitleForEntries: {
Entries_Select_feild: 'Entries_Select_feild',
Entries_Mandatory_feild: 'Entries_Mandatory_feild',
Entries_Title_feild: 'Entries_Title_feild',
Entry_Missing_Locale_and_Env: 'Entry_Missing_Locale_and_Env',
Entry_Missing_Locale_and_Env_in_Publish_Details: 'Entry_Missing_Locale_and_Env_in_Publish_Details',
Entry_Multiple_Fields: 'Entry_Multiple_Fields'
Entry_Multiple_Fields:"Entry_Multiple_Fields"
},
feild_level_modules: ['Entries_Title_feild', 'Entries_Mandatory_feild', 'Entries_Select_feild', 'Entry_Missing_Locale_and_Env_in_Publish_Details', 'Entry_Multiple_Fields'],
fixSelectField: false
feild_level_modules: [
'Entries_Title_feild',
'Entries_Mandatory_feild',
'Entries_Select_feild',
'Entry_Missing_Locale_and_Env_in_Publish_Details',
'field-rules',
'Entry_Multiple_Fields'
],
fixSelectField: false,
};

export default config;
5 changes: 5 additions & 0 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const auditMsg = {
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}'`,
FIELD_RULE_CONDITION_ABSENT: `The operand field '{condition_field}' is not present in the schema of the content-type {ctUid}`,
FIELD_RULE_TARGET_ABSENT: `The target field '{target_field}' is not present in the schema of the content-type {ctUid}`,
FIELD_RULE_CONDITION_SCAN_MESSAGE: `Completed Scanning of Field Rule '{num}' condition of Content-type '{ctUid}'`,
FIELD_RULE_TARGET_SCAN_MESSAGE: `Completed Scanning of Field Rule '{num}' target of Content-type '{ctUid}'`
};

const auditFixMsg = {
Expand All @@ -56,6 +60,7 @@ const auditFixMsg = {
ENTRY_MANDATORY_FIELD_FIX: `Removing the publish details from the entry with UID '{uid}' in Locale '{locale}'...`,
ENTRY_SELECT_FIELD_FIX: `Adding the value '{value}' in the select field of entry UID '{uid}'...`,
ASSET_FIX: `Fixed publish detials for Asset with UID '{uid}'`,
FIELD_RULE_FIX_MESSAGE: `Fixed Field Rule '{num}' target of Content-type '{ctUid}`,
};

const messages: typeof errors &
Expand Down
3 changes: 1 addition & 2 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default class ContentType {
protected schema: ContentTypeStruct[] = [];
protected missingRefs: Record<string, any> = {};
public moduleName: keyof typeof auditConfig.moduleConfig;

constructor({ log, fix, config, moduleName, ctSchema, gfSchema }: ModuleConstructorParam & CtConstructorParam) {
this.log = log;
this.config = config;
Expand Down Expand Up @@ -185,8 +184,8 @@ export default class ContentType {
if (this.fix) {
field.schema = this.runFixOnSchema(tree, field.schema as ContentTypeSchemaType[]);
}

for (let child of field.schema ?? []) {

if (!fixTypes.includes(child.data_type) && child.data_type !== 'json') continue;

switch (child.data_type) {
Expand Down
10 changes: 9 additions & 1 deletion packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class Entries {
const { uid, title } = entry;
this.currentUid = uid;
this.currentTitle = title;
this.currentTitle = this.removeEmojiAndImages(this.currentTitle)

if (!this.missingRefs[this.currentUid]) {
this.missingRefs[this.currentUid] = [];
Expand All @@ -132,7 +133,7 @@ export default class Entries {
this.removeMissingKeysOnEntry(ctSchema.schema as ContentTypeSchemaType[], this.entries[entryUid]);
}

this.lookForReference([{ locale: code, uid, name: title }], ctSchema, this.entries[entryUid]);
this.lookForReference([{ locale: code, uid, name: this.removeEmojiAndImages(title) }], ctSchema, this.entries[entryUid]);

if (this.missingRefs[this.currentUid]?.length) {
this.missingRefs[this.currentUid].forEach((entry: any) => {
Expand Down Expand Up @@ -840,6 +841,13 @@ export default class Entries {
* @returns if there is missing field returns field and path
* Else empty array
*/
removeEmojiAndImages(str: string) {
return str.replace(
/[\p{Emoji}\p{Emoji_Presentation}\p{Emoji_Modifier}\p{Emoji_Modifier_Base}\p{Emoji_Component}]+/gu,
'',
);
}

validateSelectField(tree: Record<string, unknown>[], fieldStructure: SelectFeildStruct, field: any) {
const { display_name, enum: selectOptions, multiple, min_instance, display_type, data_type } = fieldStructure;
if (
Expand Down
Loading
Loading