Skip to content

Commit

Permalink
Merge pull request #1162 from contentstack/main
Browse files Browse the repository at this point in the history
Main -> stag
  • Loading branch information
antonyagustine authored Nov 20, 2023
2 parents 5bc7977 + 3517e77 commit 9351bc7
Show file tree
Hide file tree
Showing 59 changed files with 1,904 additions and 580 deletions.
612 changes: 383 additions & 229 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.2.0 darwin-arm64 node-v20.8.0
@contentstack/cli-audit/1.2.1 darwin-arm64 node-v21.1.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 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.2.0",
"version": "1.2.1",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand All @@ -18,8 +18,8 @@
"/oclif.manifest.json"
],
"dependencies": {
"@contentstack/cli-command": "~1.2.14",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"@oclif/plugin-help": "^5",
"@oclif/plugin-plugins": "^3.8.4",
"chalk": "^4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
}
}

let gfSchema = existsSync(gfPath) ? (JSON.parse(readFileSync(gfPath, 'utf-8')) as ContentTypeStruct[]) : [];
let ctSchema = existsSync(ctPath) ? (JSON.parse(readFileSync(ctPath, 'utf-8')) as ContentTypeStruct[]) : [];
const gfSchema = existsSync(gfPath) ? (JSON.parse(readFileSync(gfPath, 'utf8')) as ContentTypeStruct[]) : [];
const ctSchema = existsSync(ctPath) ? (JSON.parse(readFileSync(ctPath, 'utf8')) as ContentTypeStruct[]) : [];

return { ctSchema, gfSchema };
}
Expand Down
75 changes: 43 additions & 32 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,7 @@ export default class Entries {
}

await this.prepareEntryMetaData();

this.ctSchema = (await new ContentType({
fix: true,
log: () => {},
config: this.config,
moduleName: 'content-types',
ctSchema: this.ctSchema,
gfSchema: this.gfSchema,
}).run(true)) as ContentTypeStruct[];
this.gfSchema = (await new ContentType({
fix: true,
log: () => {},
config: this.config,
moduleName: 'entries',
ctSchema: this.ctSchema,
gfSchema: this.gfSchema,
}).run(true)) as ContentTypeStruct[];
await this.fixPrerequisiteData();

for (const { code } of this.locales) {
for (const ctSchema of this.ctSchema) {
Expand Down Expand Up @@ -125,13 +109,43 @@ export default class Entries {
}
this.log('', 'info'); // Adding empty line

this.removeEmptyVal();

return this.missingRefs;
}

/**
* The function removes any properties from the `missingRefs` object that have an empty array value.
*/
removeEmptyVal() {
for (let propName in this.missingRefs) {
if (!this.missingRefs[propName].length) {
delete this.missingRefs[propName];
}
}
}

return this.missingRefs;
/**
* The function `fixPrerequisiteData` fixes the prerequisite data by updating the `ctSchema` and
* `gfSchema` properties using the `ContentType` class.
*/
async fixPrerequisiteData() {
this.ctSchema = (await new ContentType({
fix: true,
log: () => {},
config: this.config,
moduleName: 'content-types',
ctSchema: this.ctSchema,
gfSchema: this.gfSchema,
}).run(true)) as ContentTypeStruct[];
this.gfSchema = (await new ContentType({
fix: true,
log: () => {},
config: this.config,
moduleName: 'entries',
ctSchema: this.ctSchema,
gfSchema: this.gfSchema,
}).run(true)) as ContentTypeStruct[];
}

/**
Expand Down Expand Up @@ -449,13 +463,14 @@ export default class Entries {
if (data_type === 'json') {
if (field.field_metadata.extension) {
// NOTE Custom field type
return field;
break;
} else if (field.field_metadata.allow_json_rte) {
return this.fixJsonRteMissingReferences(
this.fixJsonRteMissingReferences(
[...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }],
field as JsonRTEFieldDataType,
entry[uid] as EntryJsonRTEFieldDataType,
);
break;
}
}

Expand All @@ -464,7 +479,7 @@ export default class Entries {
[...tree, { uid: field.uid, name: field.display_name, data_type: field.data_type }],
field as ReferenceFieldDataType,
entry[uid] as EntryReferenceFieldDataType[],
) as EntryReferenceFieldDataType[];
);
break;
case 'blocks':
entry[uid] = this.fixModularBlocksReferences(
Expand Down Expand Up @@ -541,7 +556,7 @@ export default class Entries {

return eBlock;
})
.filter((val) => !isEmpty(val)) as EntryModularBlocksDataType[];
.filter((val) => !isEmpty(val));
});

return entry;
Expand Down Expand Up @@ -604,11 +619,7 @@ export default class Entries {
) {
if (Array.isArray(entry)) {
entry = entry.map((child: any, index) => {
return this.fixJsonRteMissingReferences(
[...tree, { index, type: (child as any)?.type, uid: child?.uid }],
field,
child,
);
return this.fixJsonRteMissingReferences([...tree, { index, type: child?.type, uid: child?.uid }], field, child);
}) as EntryJsonRTEFieldDataType[];
} else {
entry.children = entry.children
Expand Down Expand Up @@ -669,7 +680,7 @@ export default class Entries {
data_type: field.data_type,
display_name: field.display_name,
treeStr: tree
.map(({ name, index }) => (index || index === 0 ? `[${index}].${name}` : name))
.map(({ name, index }) => (index || index === 0 ? `[${+index}].${name}` : name))
.filter((val) => val)
.join(' ➜ '),
missingRefs,
Expand Down Expand Up @@ -697,7 +708,7 @@ export default class Entries {
tree: Record<string, unknown>[],
blocks: ModularBlockType[],
entryBlock: EntryModularBlocksDataType,
index: Number,
index: number,
) {
const validBlockUid = blocks.map((block) => block.uid);
const invalidKeys = Object.keys(entryBlock).filter((key) => !validBlockUid.includes(key));
Expand All @@ -715,7 +726,7 @@ export default class Entries {
fixStatus: this.fix ? 'Fixed' : undefined,
tree: [...tree, { index, uid: key, name: key }],
treeStr: [...tree, { index, uid: key, name: key }]
.map(({ name, index }) => (index || index === 0 ? `[${index}].${name}` : name))
.map(({ name, index }) => (index || index === 0 ? `[${+index}].${name}` : name))
.filter((val) => val)
.join(' ➜ '),
missingRefs: [key],
Expand Down Expand Up @@ -775,8 +786,8 @@ export default class Entries {
const localesFolderPath = resolve(this.config.basePath, this.config.moduleConfig.locales.dirName);
const localesPath = join(localesFolderPath, this.config.moduleConfig.locales.fileName);
const masterLocalesPath = join(localesFolderPath, 'master-locale.json');
this.locales = values(JSON.parse(readFileSync(masterLocalesPath, 'utf-8')));
this.locales.push(...values(JSON.parse(readFileSync(localesPath, 'utf-8'))));
this.locales = values(JSON.parse(readFileSync(masterLocalesPath, 'utf8')));
this.locales.push(...values(JSON.parse(readFileSync(localesPath, 'utf8'))));

for (const { code } of this.locales) {
for (const { uid } of this.ctSchema) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-auth
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-auth/1.3.15 darwin-arm64 node-v20.8.0
@contentstack/cli-auth/1.3.16 darwin-arm64 node-v21.1.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-auth",
"description": "Contentstack CLI plugin for authentication activities",
"version": "1.3.15",
"version": "1.3.16",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -22,8 +22,8 @@
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
},
"dependencies": {
"@contentstack/cli-command": "~1.2.13",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bootstrap/1.6.1 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-bootstrap/1.6.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
8 changes: 4 additions & 4 deletions packages/contentstack-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bootstrap",
"description": "Bootstrap contentstack apps",
"version": "1.6.1",
"version": "1.6.2",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"scripts": {
Expand All @@ -17,9 +17,9 @@
"test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\""
},
"dependencies": {
"@contentstack/cli-cm-seed": "~1.6.1",
"@contentstack/cli-command": "~1.2.14",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-cm-seed": "~1.6.2",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"inquirer": "8.2.4",
"mkdirp": "^1.0.4",
"tar": "^6.1.13"
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.15 darwin-arm64 node-v20.3.1
@contentstack/cli-cm-branches/1.0.16 darwin-arm64 node-v21.1.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
10 changes: 5 additions & 5 deletions packages/contentstack-branches/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-branches",
"description": "Contentstack CLI plugin to do branches operations",
"version": "1.0.15",
"version": "1.0.16",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.13",
"@contentstack/cli-utilities": "~1.5.3",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"@oclif/core": "^2.9.3",
"async": "^3.2.4",
"big-json": "^3.2.0",
Expand All @@ -25,8 +25,8 @@
"winston": "^3.7.2"
},
"devDependencies": {
"@contentstack/cli-auth": "~1.3.14",
"@contentstack/cli-config": "~1.4.11",
"@contentstack/cli-auth": "~1.3.16",
"@contentstack/cli-config": "~1.4.14",
"@contentstack/cli-dev-dependencies": "~1.2.3",
"@oclif/plugin-help": "^5.1.19",
"@oclif/test": "^1.2.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.3.13 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-bulk-publish/1.3.14 darwin-arm64 node-v21.1.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@contentstack/cli-cm-bulk-publish",
"description": "Contentstack CLI plugin for bulk publish actions",
"version": "1.3.13",
"version": "1.3.14",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-command": "~1.2.14",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"bluebird": "^3.7.2",
"chalk": "^4.1.2",
"dotenv": "^16.1.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dependencies": {
"@contentstack/cli-cm-export": "~1.10.0",
"@contentstack/cli-cm-import": "~1.11.0",
"@contentstack/cli-command": "~1.2.14",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"@colors/colors": "^1.5.0",
"async": "^3.2.4",
"chalk": "^4.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-command/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-command",
"description": "Contentstack CLI plugin for configuration",
"version": "1.2.14",
"version": "1.2.15",
"author": "Contentstack",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -17,7 +17,7 @@
"format": "eslint src/**/*.ts --fix"
},
"dependencies": {
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-utilities": "~1.5.5",
"contentstack": "^3.10.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-config/1.4.13 darwin-arm64 node-v20.8.0
@contentstack/cli-config/1.4.14 darwin-arm64 node-v21.1.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
6 changes: 3 additions & 3 deletions packages/contentstack-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-config",
"description": "Contentstack CLI plugin for configuration",
"version": "1.4.13",
"version": "1.4.14",
"author": "Contentstack",
"scripts": {
"build": "npm run clean && npm run compile",
Expand All @@ -21,8 +21,8 @@
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\""
},
"dependencies": {
"@contentstack/cli-command": "~1.2.14",
"@contentstack/cli-utilities": "~1.5.4",
"@contentstack/cli-command": "~1.2.15",
"@contentstack/cli-utilities": "~1.5.5",
"chalk": "^4.0.0",
"debug": "^4.1.1",
"mkdirp": "^1.0.4",
Expand Down
16 changes: 9 additions & 7 deletions packages/contentstack-config/src/utils/region-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { configHandler } from '@contentstack/cli-utilities';

function validURL(str) {
const pattern = new RegExp(
'^(https:\\/\\/)?' + // protocol
'((([a-z0-9A-Z]*)[\\. |-]([a-z0-9A-Z]*))[\\.|-]([a-z0-9]{2,})+(\\.[a-z]{2,}\\.([a-z]{2,})|\\.([a-z]{2,}))|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'^(https?:\\/\\/)?' + // protocol (http or https)
'([a-zA-Z0-9.-]+|' + // domain name
'((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))' + // IP address
'(:\\d+)?' + // port
'(/[-a-zA-Z0-9_.~+-]*)*' + // path
'(\\?[;&a-zA-Z0-9_.~+=-]*)?' + // query string
'(\\#[-a-zA-Z0-9_]*)?$', // fragment
'i',
);
return Boolean(pattern.test(str));

return pattern.test(str);
}

// Available region list
Expand Down
Loading

0 comments on commit 9351bc7

Please sign in to comment.