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

Sprint 52 release #1313

Merged
merged 86 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
5e583c1
added the developerhub urls and version bump
cs-raj Feb 5, 2024
3f01adc
fixed type
cs-raj Feb 5, 2024
c7a1f8b
feat: replaced taxonomy all terms with export api
aman19K Feb 6, 2024
b771a26
version bump
aman19K Feb 6, 2024
8968752
management sdk version bump
aman19K Feb 6, 2024
f07aa37
updated lock file
aman19K Feb 6, 2024
c408880
moved the developerhuburl to utilites
cs-raj Feb 6, 2024
5fe6eac
handled why logs where not created in mentioned path
cs-raj Feb 6, 2024
c6f44fc
Merge pull request #1287 from contentstack/feat/CS-43753
aman19K Feb 7, 2024
e174dff
changed the logs location to present working directory
cs-raj Feb 7, 2024
845dad9
indentation
cs-raj Feb 7, 2024
2a63a60
utilites version bump
cs-raj Feb 7, 2024
cd164c0
Merge branch 'development' into fix/CS-43661
cs-raj Feb 7, 2024
23036ff
Merge branch 'development' into feat/taxonomy-export-import-api
aman19K Feb 8, 2024
f3063c5
feat: replaced taxonomy & terms create api with taxonomy import
aman19K Feb 8, 2024
6bfabc9
Feat: Audit and check if extensions/marketplace apps are missing used…
antonyagustine Feb 8, 2024
55da7c0
Entry, missing extension logic fix
antonyagustine Feb 8, 2024
b5bf3db
fixed indentation
aman19K Feb 8, 2024
aeae249
Merge pull request #1292 from contentstack/feat/CS-43754
aman19K Feb 8, 2024
7eec0fb
fixed for NA region developerhub
cs-raj Feb 9, 2024
b14b39e
Audit command 'fixed' status correction
antonyagustine Feb 9, 2024
d0a0e53
Merge pull request #1291 from contentstack/feat/CS-43888
antonyagustine Feb 9, 2024
3fc7c0d
Merge branch 'development' into bugfix/CS-43741
cs-raj Feb 12, 2024
f333aba
Merge branch 'development' into fix/CS-43661
cs-raj Feb 12, 2024
b2b6b5b
Merge pull request #1282 from contentstack/fix/CS-43661
cs-raj Feb 12, 2024
cf4ba71
Merge branch 'development' into bugfix/CS-43741
cs-raj Feb 12, 2024
3940e6e
Merge pull request #1289 from contentstack/bugfix/CS-43741
cs-raj Feb 12, 2024
adb579d
Merge pull request #1294 from contentstack/main
aman19K Feb 12, 2024
3159d4d
Merge branch 'staging' into stage-to-development
aman19K Feb 12, 2024
dd7ec39
Merge pull request #1296 from contentstack/stage-to-development
aman19K Feb 12, 2024
427b2a8
Merge branch 'development' into feat/taxonomy-export-import-api
aman19K Feb 13, 2024
7c9e008
feat: replace taxonomy all terms api with export api(CSV format)
aman19K Feb 13, 2024
dfec61e
lock file updated
aman19K Feb 13, 2024
1e6cb17
refactor: export csv code
aman19K Feb 13, 2024
a8dc20e
Merge pull request #1297 from contentstack/feat/CS-43756
aman19K Feb 13, 2024
afb3890
feat:replaced taxonomy & terms create api with import api in migratio…
aman19K Feb 14, 2024
4865e7b
refactor: taxonomy error handling
aman19K Feb 14, 2024
643047d
refactor: migration utility error handling
aman19K Feb 14, 2024
806aa15
Merge pull request #1298 from contentstack/feat/CS-43758
aman19K Feb 14, 2024
74fbc22
nuxt3 added, deperaction warning for nuxt, env file creation for angu…
cs-raj Feb 15, 2024
b6c06b9
added update the extension after the creation of content types and ve…
cs-raj Feb 16, 2024
8dd6ad5
optimized the code combining if and else if, and added logs
cs-raj Feb 16, 2024
ae5d111
updated logs
cs-raj Feb 16, 2024
9f12882
fromatting and audit fix
cs-raj Feb 16, 2024
dae2441
re-formatted
cs-raj Feb 16, 2024
1c99ea8
pr fixes
cs-raj Feb 19, 2024
68efea2
replaced pseudoRandomBytes with randomBytes and version bump
cs-raj Feb 19, 2024
8d0fcd7
removed stray console log
cs-raj Feb 19, 2024
c2c03b6
refactor: updated management sdk version
aman19K Feb 19, 2024
d698341
Merge pull request #1303 from contentstack/refactor/management-sdk-ve…
aman19K Feb 19, 2024
532861b
fix: import taxonomy issue
aman19K Feb 19, 2024
b601d63
Merge pull request #1302 from contentstack/fix/CS-42790
cs-raj Feb 20, 2024
6f31a2b
added stack name to the config
cs-raj Feb 20, 2024
180f948
changed the name following the convention
cs-raj Feb 20, 2024
8734295
Merge branch 'development' into fix/CS-43755
cs-raj Feb 20, 2024
de42174
Merge pull request #1299 from contentstack/fix/CS-43755
cs-raj Feb 20, 2024
c86512f
ui text update
cs-raj Feb 20, 2024
a18cd1b
fromatting updated
cs-raj Feb 20, 2024
86174f0
Merge branch 'development' into fix/CS-43987
cs-raj Feb 20, 2024
78235ed
ui text update
cs-raj Feb 20, 2024
638adb6
Merge branch 'development' into fix/CS-43639
cs-raj Feb 20, 2024
f3cc680
Merge pull request #1300 from contentstack/fix/CS-43639
cs-raj Feb 20, 2024
19e8331
Merge branch 'development' into feat/taxonomy-export-import-api
aman19K Feb 21, 2024
bdd1e81
Merge branch 'development' into fix/CS-43987
cs-raj Feb 21, 2024
dec07e8
added two messages depending whether management token is used or not
cs-raj Feb 21, 2024
1a63fe3
made stackName optional
cs-raj Feb 21, 2024
8cc2bd4
Merge pull request #1304 from contentstack/fix/CS-43987
cs-raj Feb 21, 2024
f553b39
Merge branch 'development' into feat/taxonomy-export-import-api
aman19K Feb 21, 2024
f482822
removed unnecessary try catch block
aman19K Feb 21, 2024
d1060e2
Merge pull request #1305 from contentstack/feat/taxonomy-export-impor…
aman19K Feb 21, 2024
92ff5a2
fix: updated rimraf version from 3.0.2 to 5.0.5
aman19K Feb 23, 2024
1320755
Merge pull request #1308 from contentstack/fix/CS-43934
aman19K Feb 23, 2024
94574ae
fixed bulk publish fix
shafeeqd959 Feb 23, 2024
f127f2e
merged latest changes
shafeeqd959 Feb 23, 2024
8456d17
Merge pull request #1310 from contentstack/devfix/CS-43960
aman19K Feb 26, 2024
137b372
sprint52 version bump
aman19K Feb 26, 2024
9a148c1
Merge pull request #1311 from contentstack/refactor/sprint52-version-…
aman19K Feb 26, 2024
e2f041e
Merge pull request #1312 from contentstack/development
aman19K Feb 26, 2024
3a510f2
fix: handle module not found error in migration error helper
aman19K Feb 27, 2024
cbab27b
Merge pull request #1314 from contentstack/fix/migration-error-helper
aman19K Feb 27, 2024
a9c22a3
Merge branch 'main' into main-to-stage
aman19K Feb 27, 2024
a7ea138
Merge pull request #1317 from contentstack/main-to-stage
aman19K Feb 27, 2024
705a333
fixed referenced entries publish
shafeeqd959 Feb 28, 2024
6d746cb
bumped tmp package
shafeeqd959 Feb 29, 2024
cfb7448
Update jira.yml
aravindbuilt Feb 29, 2024
752be70
Merge pull request #1319 from contentstack/hotfix/CS-43955
shafeeqd959 Feb 29, 2024
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
855 changes: 686 additions & 169 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 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.3.5 darwin-arm64 node-v20.8.0
@contentstack/cli-audit/1.4.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -99,14 +99,14 @@ Perform audits and fix possible errors in the exported Contentstack data.
USAGE
$ csdx audit:fix [-c <value>] [-d <value>] [--report-path <value>] [--modules
content-types|global-fields|entries] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:custom-field|blocks|group] [--columns <value> | ] [--sort <value>] [--filter
reference|global_field|json:rte|json:extension|blocks|group] [--columns <value> | ] [--sort <value>] [--filter
<value>] [--csv | --no-truncate]

FLAGS
--copy-dir Create backup from the original data.
--copy-path=<value> Provide the path to backup the copied data
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:custom-field|blocks|group>
<options: reference|global_field|json:rte|json:extension|blocks|group>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries>
--report-path=<value> Path to store the audit reports
Expand Down Expand Up @@ -198,14 +198,14 @@ Perform audits and fix possible errors in the exported Contentstack data.
USAGE
$ csdx cm:stacks:audit:fix [-c <value>] [-d <value>] [--report-path <value>] [--modules
content-types|global-fields|entries] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:custom-field|blocks|group] [--columns <value> | ] [--sort <value>] [--filter
reference|global_field|json:rte|json:extension|blocks|group] [--columns <value> | ] [--sort <value>] [--filter
<value>] [--csv | --no-truncate]

FLAGS
--copy-dir Create backup from the original data.
--copy-path=<value> Provide the path to backup the copied data
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:custom-field|blocks|group>
<options: reference|global_field|json:rte|json:extension|blocks|group>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries>
--report-path=<value> Path to store the audit reports
Expand Down
4 changes: 2 additions & 2 deletions 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.3.5",
"version": "1.4.0",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -19,7 +19,7 @@
],
"dependencies": {
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.5.11",
"@contentstack/cli-utilities": "~1.5.12",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^4.1.9",
"chalk": "^4.1.2",
Expand Down
20 changes: 19 additions & 1 deletion packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = {
skipRefs: ['sys_assets'],
skipFieldTypes: ['taxonomy'],
modules: ['content-types', 'global-fields', 'entries'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:custom-field', 'blocks', 'group'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group'],
moduleConfig: {
'content-types': {
name: 'content type',
Expand All @@ -26,6 +26,24 @@ const config = {
fileName: 'locales.json',
},
},
entries: {
systemKeys: [
'uid',
'ACL',
'tags',
'locale',
'_version',
'_metadata',
'published',
'created_at',
'updated_at',
'created_by',
'updated_by',
'_in_progress',
'_restore_status',
'publish_details',
],
},
};

export default config;
146 changes: 133 additions & 13 deletions packages/contentstack-audit/src/modules/content-types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import map from 'lodash/map';
import find from 'lodash/find';
import isEmpty from 'lodash/isEmpty';
import { join, resolve } from 'path';
import { existsSync, writeFileSync } from 'fs';
import { existsSync, readFileSync, writeFileSync } from 'fs';

import { ux } from '@contentstack/cli-utilities';

import {
Expand All @@ -19,9 +21,11 @@ import {
ReferenceFieldDataType,
ContentTypeSchemaType,
GlobalFieldSchemaTypes,
ExtensionOrAppFieldDataType,
} from '../types';
import auditConfig from '../config';
import { $t, auditFixMsg, auditMsg, commonMsg } from '../messages';
import { MarketplaceAppsInstallationData } from '../types/extension';

/* The `ContentType` class is responsible for scanning content types, looking for references, and
generating a report in JSON and CSV formats. */
Expand All @@ -33,6 +37,7 @@ export default class ContentType {
public folderPath: string;
public currentUid!: string;
public currentTitle!: string;
public extensions: string[] = [];
public inMemoryFix: boolean = false;
public gfSchema: ContentTypeStruct[];
public ctSchema: ContentTypeStruct[];
Expand Down Expand Up @@ -67,6 +72,8 @@ export default class ContentType {

this.schema = this.moduleName === 'content-types' ? this.ctSchema : this.gfSchema;

await this.prerequisiteData();

for (const schema of this.schema ?? []) {
this.currentUid = schema.uid;
this.currentTitle = schema.title;
Expand Down Expand Up @@ -96,6 +103,35 @@ export default class ContentType {
return this.missingRefs;
}

/**
* @method prerequisiteData
* The `prerequisiteData` function reads and parses JSON files to retrieve extension and marketplace
* app data, and stores them in the `extensions` array.
*/
async prerequisiteData() {
const extensionPath = resolve(this.config.basePath, 'extensions', 'extensions.json');
const marketplacePath = resolve(this.config.basePath, 'marketplace_apps', 'marketplace_apps.json');

if (existsSync(extensionPath)) {
try {
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
} catch (error) {}
}

if (existsSync(marketplacePath)) {
try {
const marketplaceApps: MarketplaceAppsInstallationData[] = JSON.parse(readFileSync(marketplacePath, 'utf8'));

for (const app of marketplaceApps) {
const metaData = map(map(app?.ui_location?.locations, 'meta').flat(), 'extension_uid').filter(
(val) => val,
) as string[];
this.extensions.push(...metaData);
}
} catch (error) {}
}
}

/**
* The function checks if it can write the fix content to a file and if so, it writes the content as
* JSON to the specified file path.
Expand Down Expand Up @@ -157,10 +193,16 @@ export default class ContentType {
);
break;
case 'json':
if (child.field_metadata.extension) {
if (!fixTypes.includes('json:custom-field')) continue;
if ('extension' in child.field_metadata && child.field_metadata.extension) {
if (!fixTypes.includes('json:extension')) continue;
// NOTE Custom field type
} else if (child.field_metadata.allow_json_rte) {
this.missingRefs[this.currentUid].push(
...this.validateExtensionAndAppField(
[...tree, { uid: child.uid, name: child.display_name }],
child as ExtensionOrAppFieldDataType,
),
);
} else if ('allow_json_rte' in child.field_metadata && child.field_metadata.allow_json_rte) {
if (!fixTypes.includes('json:rte')) continue;
// NOTE JSON RTE field type
this.missingRefs[this.currentUid].push(
Expand Down Expand Up @@ -199,6 +241,45 @@ export default class ContentType {
return this.validateReferenceToValues(tree, field);
}

/**
* The function `validateExtensionAndAppsField` checks if a given field has a valid extension or app
* reference and returns any missing references.
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure.
* @param {ExtensionOrAppFieldDataType} field - The `field` parameter is of type `ExtensionOrAppFieldDataType`.
* @returns The function `validateExtensionAndAppsField` returns an array of `RefErrorReturnType`
* objects.
*/
validateExtensionAndAppField(
tree: Record<string, unknown>[],
field: ExtensionOrAppFieldDataType,
): RefErrorReturnType[] {
if (this.fix) return [];

const missingRefs = [];
let { uid, extension_uid, display_name, data_type } = field;

if (!this.extensions.includes(extension_uid)) {
missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' } as any);
}

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(' ➜ '),
},
]
: [];
}

/**
* The function "validateGlobalField" asynchronously validates a global field by looking for a
* reference in a tree data structure.
Expand Down Expand Up @@ -298,7 +379,9 @@ export default class ContentType {

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 (this.config.skipRefs.includes(reference)) {
continue;
}

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

Expand Down Expand Up @@ -350,14 +433,13 @@ export default class ContentType {
case 'json':
case 'reference':
if (data_type === 'json') {
if (field.field_metadata.extension) {
if ('extension' in field.field_metadata && field.field_metadata.extension) {
// NOTE Custom field type
if (!fixTypes.includes('json:custom-field')) return field;
if (!fixTypes.includes('json:extension')) return field;

// NOTE Fix logic

return field;
} else if (field.field_metadata.allow_json_rte) {
return this.fixMissingExtensionOrApp(tree, field as ExtensionOrAppFieldDataType);
} else if ('allow_json_rte' in field.field_metadata && field.field_metadata.allow_json_rte) {
if (!fixTypes.includes('json:rte')) return field;

return this.fixMissingReferences(tree, field as JsonRTEFieldDataType);
Expand Down Expand Up @@ -456,10 +538,10 @@ export default class ContentType {
const refErrorObj = {
tree,
display_name,
fixStatus: 'Fixed',
missingRefs: [reference_to],
ct_uid: this.currentUid,
name: this.currentTitle,
missingRefs: [reference_to],
fixStatus: this.fix ? 'Fixed' : undefined,
treeStr: tree.map(({ name }) => name).join(' ➜ '),
};

Expand Down Expand Up @@ -499,6 +581,41 @@ export default class ContentType {
.filter((val) => val) as ModularBlockType[];
}

/**
* The function checks for missing extension or app references in a given tree and fixes them if the
* fix flag is enabled.
* @param {Record<string, unknown>[]} tree - An array of objects representing a tree structure.
* @param {ExtensionOrAppFieldDataType} field - The `field` parameter is of type
* `ExtensionOrAppFieldDataType`.
* @returns If the `fix` flag is true and there are missing references (`missingRefs` is not empty),
* then `null` is returned. Otherwise, the `field` parameter is returned.
*/
fixMissingExtensionOrApp(tree: Record<string, unknown>[], field: ExtensionOrAppFieldDataType) {
const missingRefs: string[] = [];
const { uid, extension_uid, data_type, display_name } = field;

if (!this.extensions.includes(extension_uid)) {
missingRefs.push({ uid, extension_uid, type: 'Extension or Apps' } as any);
}

if (this.fix && !isEmpty(missingRefs)) {
this.missingRefs[this.currentUid].push({
tree,
data_type,
missingRefs,
display_name,
fixStatus: 'Fixed',
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree.map(({ name }) => name).join(' ➜ '),
});

return null
}

return field;
}

/**
* The function `fixMissingReferences` checks for missing references in a given tree and field, and
* attempts to fix them by removing the missing references from the field's `reference_to` array.
Expand All @@ -515,7 +632,9 @@ export default class ContentType {

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 (this.config.skipRefs.includes(reference)) {
continue;
}

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

Expand Down Expand Up @@ -557,6 +676,7 @@ export default class ContentType {
*/
fixGroupField(tree: Record<string, unknown>[], field: GroupFieldDataType) {
const { data_type, display_name } = field;

field.schema = this.runFixOnSchema(tree, field.schema as ContentTypeSchemaType[]);

if (isEmpty(field.schema)) {
Expand Down
Loading
Loading