Skip to content

Commit

Permalink
Merge pull request #1370 from contentstack/development
Browse files Browse the repository at this point in the history
Sprint 55 Development to Staging
  • Loading branch information
cs-raj authored Apr 12, 2024
2 parents b858b70 + 0a34d78 commit 61a9067
Show file tree
Hide file tree
Showing 20 changed files with 14,856 additions and 2,647 deletions.
17,151 changes: 14,587 additions & 2,564 deletions package-lock.json

Large diffs are not rendered by default.

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.5.2",
"version": "1.5.3",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
35 changes: 20 additions & 15 deletions packages/contentstack-audit/src/modules/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,20 @@ export default class Workflows {

for (const workflow of this.workflowSchema) {
const ctNotPresent = workflow.content_types.filter((ct) => !this.ctUidSet.has(ct));
const branch = workflow?.branches?.filter((branch) => branch !== this.config?.branch);
let branchesToBeRemoved: string[] = [];
if (this.config?.branch) {
branchesToBeRemoved = workflow?.branches?.filter((branch) => branch !== this.config?.branch) || [];
}

if (ctNotPresent.length || branch?.length) {
if (ctNotPresent.length || branchesToBeRemoved?.length) {
const tempwf = cloneDeep(workflow);
tempwf.content_types = ctNotPresent || [];

if (workflow?.branches) {
tempwf.branches = branch;
if (workflow?.branches && this.config?.branch) {
tempwf.branches = branchesToBeRemoved;
}

if (branch?.length) {
if (branchesToBeRemoved?.length) {
this.isBranchFixDone = true;
}

Expand Down Expand Up @@ -111,17 +114,19 @@ export default class Workflows {
const fixedCts = workflow.content_types.filter((ct) => !this.missingCts.has(ct));
const fixedBranches: string[] = [];

workflow?.branches?.forEach((branch) => {
if (branch !== this.config?.branch) {
const { uid, name } = workflow;
this.log($t(commonMsg.WF_BRANCH_REMOVAL, { uid, name, branch }), { color: 'yellow' });
} else {
fixedBranches.push(branch);
if (this.config.branch) {
workflow?.branches?.forEach((branch) => {
if (branch !== this.config?.branch) {
const { uid, name } = workflow;
this.log($t(commonMsg.WF_BRANCH_REMOVAL, { uid, name, branch }), { color: 'yellow' });
} else {
fixedBranches.push(branch);
}
});

if (fixedBranches.length > 0) {
newWorkflowSchema[workflow.uid].branches = fixedBranches;
}
});

if (fixedBranches.length > 0) {
newWorkflowSchema[workflow.uid].branches = fixedBranches;
}

if (fixedCts.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-bulk-publish",
"description": "Contentstack CLI plugin for bulk publish actions",
"version": "1.4.3",
"version": "1.4.4",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ async function getSyncEntries(

const entriesResponse = await Stack.sync(syncData);

if (filter?.content_type_uid?.length) {
entriesResponse.items = entriesResponse.items.filter((entry) =>
filter?.content_type_uid.includes(entry.content_type_uid),
);
}

if (entriesResponse.items.length > 0) {
await bulkAction(stack, entriesResponse.items, bulkPublish, filter, destEnv, apiVersion);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.11.1",
"@contentstack/cli-cm-import": "~1.15.0",
"@contentstack/cli-cm-import": "~1.15.1",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"async": "^3.2.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function createNodeCryptoInstance(config: ExportConfig): Promise<No

return true;
},
message: 'Enter marketplace app configurations encryption key',
message: 'Enter Marketplace app configurations encryption key',
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.15.0",
"version": "1.15.1",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~1.5.2",
"@contentstack/cli-audit": "~1.5.3",
"@contentstack/cli-command": "~1.2.16",
"@contentstack/cli-utilities": "~1.6.0",
"@contentstack/management": "~1.15.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = class ImportMarketplaceApps {

return true;
},
message: 'Enter marketplace app configurations encryption key',
message: 'Enter Marketplace app configurations encryption key',
});

try {
Expand Down
14 changes: 8 additions & 6 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ export default class EntriesImport extends BaseClass {

async replaceEntriesHandler({
apiParams,
element: entry
element: entry,
}: {
apiParams: ApiOptions;
element: Record<string, string>;
Expand Down Expand Up @@ -876,19 +876,21 @@ export default class EntriesImport extends BaseClass {
}
// log(this.importConfig, `Starting publish entries for ${cTUid} in locale ${locale}`, 'info');

const onSuccess = ({ response, apiData: { environments, entryUid }, additionalInfo }: any) => {
const onSuccess = ({ response, apiData: { environments, entryUid, locales }, additionalInfo }: any) => {
log(
this.importConfig,
`Published entry: '${entryUid}' of content type ${cTUid} and locale ${locale} in ${environments?.join(
`Published the entry: '${entryUid}' of Content Type '${cTUid}' and Locale '${locale}' in Environments '${environments?.join(
',',
)} environments`,
)}' and Locales '${locales?.join(',')}'`,
'info',
);
};
const onReject = ({ error, apiData, additionalInfo }: any) => {
const onReject = ({ error, apiData: { environments, entryUid, locales }, additionalInfo }: any) => {
log(
this.importConfig,
`${apiData.entryUid} entry of content type ${cTUid} in locale ${locale} failed to publish`,
`Failed to publish: '${entryUid}' entry of Content Type '${cTUid}' and Locale '${locale}' in Environments '${environments?.join(
',',
)}' and Locales '${locales?.join(',')}'`,
'error',
);
log(this.importConfig, formatError(error), 'error');
Expand Down
61 changes: 34 additions & 27 deletions packages/contentstack-import/src/import/modules/marketplace-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,35 +231,38 @@ export default class ImportMarketplaceApps {
return Promise.resolve();
}

await getConfirmationToCreateApps(privateApps, this.importConfig);

log(this.importConfig, 'Starting developer hub private apps re-creation', 'success');
let canCreatePrivateApp = await getConfirmationToCreateApps(privateApps, this.importConfig);
this.importConfig.canCreatePrivateApp = canCreatePrivateApp;
if (canCreatePrivateApp) {
log(this.importConfig, 'Starting developer hub private apps re-creation', 'success');
for (let app of privateApps) {
if (this.importConfig.skipPrivateAppRecreationIfExist && (await this.isPrivateAppExistInDeveloperHub(app))) {
// NOTE Found app already exist in the same org
this.appUidMapping[app.uid] = app.uid;
cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
continue;
}

for (let app of privateApps) {
if (this.importConfig.skipPrivateAppRecreationIfExist && (await this.isPrivateAppExistInDeveloperHub(app))) {
// NOTE Found app already exist in the same org
this.appUidMapping[app.uid] = app.uid;
cliux.print(`App '${app.manifest.name}' already exist. skipping app recreation.!`, { color: 'yellow' });
continue;
// NOTE keys can be passed to install new app in the developer hub
const validKeys = [
'uid',
'name',
'icon',
'oauth',
'webhook',
'visibility',
'target_type',
'description',
'ui_location',
'framework_version',
];
const manifest = pick(app.manifest, validKeys) as Manifest;
this.appOriginalName = manifest.name;

await this.createPrivateApp(manifest);
}

// NOTE keys can be passed to install new app in the developer hub
const validKeys = [
'uid',
'name',
'icon',
'oauth',
'webhook',
'visibility',
'target_type',
'description',
'ui_location',
'framework_version',
];
const manifest = pick(app.manifest, validKeys) as Manifest;
this.appOriginalName = manifest.name;

await this.createPrivateApp(manifest);
} else {
log(this.importConfig, 'Skipping private apps creation on Developer Hub...', 'success');
}

this.appOriginalName = undefined;
Expand Down Expand Up @@ -422,6 +425,10 @@ export default class ImportMarketplaceApps {

if (!currentStackApp) {
// NOTE install new app
if (app.manifest.visibility === 'private' && !this.importConfig.canCreatePrivateApp) {
log(this.importConfig, `Skipping the installation of the private app ${app.manifest.name}...`, 'info');
return Promise.resolve();
}
const installation = await this.installApp(
this.importConfig,
// NOTE if it's private app it should get uid from mapper else will use manifest uid
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/types/import-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface ExternalConfig {
}

export default interface ImportConfig extends DefaultConfig, ExternalConfig {
canCreatePrivateApp: boolean;
contentDir: string;
data: string;
management_token?: string;
Expand Down
8 changes: 5 additions & 3 deletions packages/contentstack-import/src/utils/asset-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ export const lookupAssets = function (
assetUrls.forEach(function (assetUrl: any) {
let mappedAssetUrl = mappedAssetUrls[assetUrl];
if (typeof mappedAssetUrl !== 'undefined') {
const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&');
const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&');
entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
//NOTE - This code was added to resolve the SRE issue but once the code was merged Assets URLs in JSON RTE started breaking
// const sanitizedUrl = escapeRegExp(assetUrl).replace(/\.\./g, '\\$&');
// const escapedMappedUrl = escapeRegExp(mappedAssetUrl).replace(/\.\./g, '\\$&');
// entry = entry.replace(new RegExp(sanitizedUrl, 'img'), escapedMappedUrl);
entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl);
matchedUrls.push(mappedAssetUrl);
} else {
unmatchedUrls.push(assetUrl);
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/src/utils/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const askEncryptionKey = async(defaultValue: unknown): Promise<string> =>

return true;
},
message: 'Enter marketplace app configurations encryption key',
message: 'Enter Marketplace app configurations encryption key',
});
}

Expand Down
22 changes: 12 additions & 10 deletions packages/contentstack-import/src/utils/marketplace-app-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
configHandler,
managementSDKClient,
marketplaceSDKClient,
createDeveloperHubUrl
createDeveloperHubUrl,
} from '@contentstack/cli-utilities';

import { log } from './logger';
Expand Down Expand Up @@ -90,15 +90,17 @@ export const getConfirmationToCreateApps = async (privateApps: any, config: Impo
),
)
) {
return Promise.resolve(true);
}

if (
!(await cliux.confirm(
chalk.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)'),
))
) {
process.exit();
return Promise.resolve(false);
} else {
if (
await cliux.confirm(
chalk.yellow('\nWould you like to re-create the private app and then proceed with the installation? (y/n)'),
)
) {
return Promise.resolve(true);
} else {
return Promise.resolve(false);
}
}
}
}
Expand Down
Loading

0 comments on commit 61a9067

Please sign in to comment.