From 0a2a10679811cc295f6daf2a9ddf5cc6e017e3eb Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 16 Feb 2024 16:22:09 +0530 Subject: [PATCH 1/7] added update the extension after the creation of content types and version bump --- package-lock.json | 8 ++-- packages/contentstack-clone/package.json | 2 +- packages/contentstack-import/package.json | 2 +- .../src/import/modules/base-class.ts | 6 +++ .../src/import/modules/content-types.ts | 45 ++++++++++++++++++- .../src/import/modules/extensions.ts | 39 +++++++++++++++- packages/contentstack-seed/package.json | 2 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 6 +-- 9 files changed, 99 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf5efad16a..71402adc69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23551,7 +23551,7 @@ "@contentstack/cli-cm-clone": "~1.10.0", "@contentstack/cli-cm-export": "~1.10.5", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.1", "@contentstack/cli-command": "~1.2.17", @@ -24093,7 +24093,7 @@ "dependencies": { "@colors/colors": "^1.5.0", "@contentstack/cli-cm-export": "~1.10.5", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "async": "^3.2.4", @@ -24993,7 +24993,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.13.4", + "version": "1.13.5", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.4.0", @@ -25472,7 +25472,7 @@ "version": "1.7.1", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "inquirer": "8.2.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 43aa7a03b6..de8ff337a2 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@contentstack/cli-cm-export": "~1.10.5", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "@colors/colors": "^1.5.0", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 7c612fd273..4f72bd8b52 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.13.4", + "version": "1.13.5", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index d4a69296c9..9b4c92f619 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -283,6 +283,12 @@ export default abstract class BaseClass { .create({ extension: omit(apiData, ['uid']) as ExtensionData }) .then(onSuccess) .catch(onReject); + case 'update-extensions': + console.log(apiData.scope) + return this.stack.extension(apiData.uid).fetch().then((extension) => { + extension.scope = apiData.scope + return extension.update() + }).then(onSuccess).catch(onReject); case 'create-locale': return this.stack .locale() diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index 0ca255da31..ead0c74a48 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -51,6 +51,7 @@ export default class ContentTypesImport extends BaseClass { }; private taxonomiesPath: string; public taxonomies: Record; + private extPendingPath: string; constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -78,6 +79,7 @@ export default class ContentTypesImport extends BaseClass { this.createdGFs = []; this.pendingGFs = []; this.taxonomiesPath = path.join(importConfig.data, 'mapper/taxonomies', 'success.json'); + this.extPendingPath = path.join(importConfig.data,'mapper','extensions','pending_extensions.js'); } async start(): Promise { @@ -106,6 +108,7 @@ export default class ContentTypesImport extends BaseClass { if (this.fieldRules.length > 0) { await fsUtil.writeFile(path.join(this.cTsFolderPath, 'field_rules_uid.json'), this.fieldRules); } + await this.createPendingExtensions(); await this.updatePendingGFs().catch((error) => { log(this.importConfig, `Error while updating pending global field ${formatError(error)}`, 'error'); }); @@ -250,4 +253,44 @@ export default class ContentTypesImport extends BaseClass { apiOptions.apiData = globalFieldPayload; return apiOptions; } -} + + async createPendingExtensions(): Promise{ + let ext = fsUtil.readFile(this.extPendingPath) as Record[]; + console.log(ext) + let apiContent = ext + + console.log(apiContent) + const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }: any) => { + log(this.importConfig, `Extension '${response.title}' imported successfully`, 'success'); + }; + + const onReject = ({ error, apiData }: any) => { + const { uid } = apiData; + if (error?.errors?.title) { + if (!this.importConfig.skipExisting) { + log(this.importConfig, `Extension '${uid}' already exists`, 'info'); + } + } else { + // this.extFailed.push(apiData); + log(this.importConfig, `Extension '${uid}' failed to be import ${formatError(error)}`, 'error'); + log(this.importConfig, error, 'error'); + } + }; + + return await this.makeConcurrentCall( + { + apiContent, + processName: 'update extensions', + apiParams: { + reject: onReject.bind(this), + resolve: onSuccess.bind(this), + entity: 'update-extensions', + includeParamOnCompletion: true, + }, + concurrencyLimit: this.importConfig.concurrency || this.importConfig.fetchConcurrency || 1, + }, + undefined, + false, + ); + } +} \ No newline at end of file diff --git a/packages/contentstack-import/src/import/modules/extensions.ts b/packages/contentstack-import/src/import/modules/extensions.ts index 22ce73dbb9..e9b1abeb45 100644 --- a/packages/contentstack-import/src/import/modules/extensions.ts +++ b/packages/contentstack-import/src/import/modules/extensions.ts @@ -19,6 +19,8 @@ export default class ImportExtensions extends BaseClass { private extSuccess: Record[]; private extFailed: Record[]; private existingExtensions: Record[]; + private extPendingPath: string; + private extensionObject:Record[]; constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -28,10 +30,12 @@ export default class ImportExtensions extends BaseClass { this.extUidMapperPath = join(this.mapperDirPath, 'uid-mapping.json'); this.extSuccessPath = join(this.mapperDirPath, 'success.json'); this.extFailsPath = join(this.mapperDirPath, 'fails.json'); + this.extPendingPath = join(this.mapperDirPath,'pending_extensions.js'); this.extFailed = []; this.extSuccess = []; this.existingExtensions = []; this.extUidMapper = {}; + this.extensionObject = []; } /** @@ -45,7 +49,7 @@ export default class ImportExtensions extends BaseClass { if (fileHelper.fileExistsSync(this.extensionsFolderPath)) { this.extensions = fsUtil.readFile(join(this.extensionsFolderPath, 'extensions.json'), true) as Record< string, - unknown + Record >; } else { log(this.importConfig, `No such file or directory - '${this.extensionsFolderPath}'`, 'error'); @@ -57,8 +61,11 @@ export default class ImportExtensions extends BaseClass { ? (fsUtil.readFile(join(this.extUidMapperPath), true) as Record) : {}; + await this.getContentTypesInScope(); + await this.importExtensions(); + await this.updateUidExtension(); // Note: if any extensions present, then update it if (this.importConfig.replaceExisting && this.existingExtensions.length > 0) { await this.replaceExtensions().catch((error: Error) => { @@ -209,4 +216,34 @@ export default class ImportExtensions extends BaseClass { } }); } + + async getContentTypesInScope(){ + const extension= values(this.extensions); + + type extType = { + uid: string, + scope: Record + } + extension.forEach((ext:extType)=>{ + let ct:any = ext?.scope?.content_types || []; + if(ct.length===1 && (ct[0]!=='$all')){ + const {uid, scope} = ext; + this.extensionObject.push({uid,scope}); + delete ext.scope; + this.extensions[ext.uid] = ext; + } else if(ct?.length>1) { + const {uid, scope} = ext; + this.extensionObject.push({uid,scope}) ; + delete ext.scope; + this.extensions[ext.uid] = ext; + } + }); + } + + async updateUidExtension() { + for(let i in this.extensionObject) { + this.extensionObject[i].uid = this.extUidMapper[this.extensionObject[i].uid as string]; + } + fsUtil.writeFile(this.extPendingPath, this.extensionObject); + } } diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 22a7c5808e..85f4037877 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -5,7 +5,7 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.12", "inquirer": "8.2.4", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 62b7ba57d8..570b6bf858 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -30,7 +30,7 @@ "@contentstack/cli-cm-export": "~1.10.5", "@contentstack/cli-cm-clone": "~1.10.0", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.13.4", + "@contentstack/cli-cm-import": "~1.13.5", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.1", "@contentstack/cli-command": "~1.2.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2be68a439..45799cea17 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: '@contentstack/cli-cm-clone': ~1.10.0 '@contentstack/cli-cm-export': ~1.10.5 '@contentstack/cli-cm-export-to-csv': ~1.6.2 - '@contentstack/cli-cm-import': ~1.13.4 + '@contentstack/cli-cm-import': ~1.13.5 '@contentstack/cli-cm-migrate-rte': ~1.4.15 '@contentstack/cli-cm-seed': ~1.7.1 '@contentstack/cli-command': ~1.2.17 @@ -424,7 +424,7 @@ importers: specifiers: '@colors/colors': ^1.5.0 '@contentstack/cli-cm-export': ~1.10.5 - '@contentstack/cli-cm-import': ~1.13.4 + '@contentstack/cli-cm-import': ~1.13.5 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.12 '@oclif/test': ^2.5.6 @@ -990,7 +990,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.13.4 + '@contentstack/cli-cm-import': ~1.13.5 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.12 '@oclif/plugin-help': ^5.1.19 From d90d37e9395e0c3a33cb62fa4c40d655a588163d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 16 Feb 2024 17:27:29 +0530 Subject: [PATCH 2/7] optimized the code combining if and else if, and added logs --- .../src/import/modules/base-class.ts | 1 - .../src/import/modules/content-types.ts | 15 +++++----- .../src/import/modules/extensions.ts | 30 ++++++++----------- .../contentstack-import/src/types/index.ts | 8 ++++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index 9b4c92f619..90c72984f1 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -284,7 +284,6 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'update-extensions': - console.log(apiData.scope) return this.stack.extension(apiData.uid).fetch().then((extension) => { extension.scope = apiData.scope return extension.update() diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index ead0c74a48..87dec7c7a5 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -108,6 +108,7 @@ export default class ContentTypesImport extends BaseClass { if (this.fieldRules.length > 0) { await fsUtil.writeFile(path.join(this.cTsFolderPath, 'field_rules_uid.json'), this.fieldRules); } + log(this.importConfig, 'Updating the Extensions', 'success'); await this.createPendingExtensions(); await this.updatePendingGFs().catch((error) => { log(this.importConfig, `Error while updating pending global field ${formatError(error)}`, 'error'); @@ -255,13 +256,14 @@ export default class ContentTypesImport extends BaseClass { } async createPendingExtensions(): Promise{ - let ext = fsUtil.readFile(this.extPendingPath) as Record[]; - console.log(ext) - let apiContent = ext + let apiContent = fsUtil.readFile(this.extPendingPath) as Record[]; + if(apiContent.length===0) { + log(this.importConfig, `No Extension are present to be updated`, 'success'); + return; + } - console.log(apiContent) const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }: any) => { - log(this.importConfig, `Extension '${response.title}' imported successfully`, 'success'); + log(this.importConfig, `Extension '${response.title}' updated successfully`, 'success'); }; const onReject = ({ error, apiData }: any) => { @@ -271,8 +273,7 @@ export default class ContentTypesImport extends BaseClass { log(this.importConfig, `Extension '${uid}' already exists`, 'info'); } } else { - // this.extFailed.push(apiData); - log(this.importConfig, `Extension '${uid}' failed to be import ${formatError(error)}`, 'error'); + log(this.importConfig, `Extension '${uid}' failed to be updated ${formatError(error)}`, 'error'); log(this.importConfig, error, 'error'); } }; diff --git a/packages/contentstack-import/src/import/modules/extensions.ts b/packages/contentstack-import/src/import/modules/extensions.ts index e9b1abeb45..04340aeba0 100644 --- a/packages/contentstack-import/src/import/modules/extensions.ts +++ b/packages/contentstack-import/src/import/modules/extensions.ts @@ -5,7 +5,7 @@ import { join } from 'node:path'; import { log, formatError, fsUtil, fileHelper } from '../../utils'; import BaseClass, { ApiOptions } from './base-class'; -import { ModuleClassParams, Extensions } from '../../types'; +import { ModuleClassParams, Extensions, extensionType } from '../../types'; export default class ImportExtensions extends BaseClass { private mapperDirPath: string; @@ -61,11 +61,14 @@ export default class ImportExtensions extends BaseClass { ? (fsUtil.readFile(join(this.extUidMapperPath), true) as Record) : {}; - await this.getContentTypesInScope(); + // Check whether the scope of an extension contains content-types in scope + // Remove the scope and store the scope with uid in pending extensions + this.getContentTypesInScope(); await this.importExtensions(); - await this.updateUidExtension(); + // Update the uid of the extension + this.updateUidExtension(); // Note: if any extensions present, then update it if (this.importConfig.replaceExisting && this.existingExtensions.length > 0) { await this.replaceExtensions().catch((error: Error) => { @@ -217,30 +220,21 @@ export default class ImportExtensions extends BaseClass { }); } - async getContentTypesInScope(){ - const extension= values(this.extensions); - - type extType = { - uid: string, - scope: Record - } - extension.forEach((ext:extType)=>{ + getContentTypesInScope(){ + const extension = values(this.extensions); + extension.forEach((ext:extensionType)=>{ let ct:any = ext?.scope?.content_types || []; - if(ct.length===1 && (ct[0]!=='$all')){ + if((ct.length===1 && (ct[0]!=='$all')) || (ct?.length>1)){ + log(this.importConfig, `Removing the Content-types ${ct.join(',')} from Extension ${ext.title}`, 'success'); const {uid, scope} = ext; this.extensionObject.push({uid,scope}); delete ext.scope; this.extensions[ext.uid] = ext; - } else if(ct?.length>1) { - const {uid, scope} = ext; - this.extensionObject.push({uid,scope}) ; - delete ext.scope; - this.extensions[ext.uid] = ext; } }); } - async updateUidExtension() { + updateUidExtension() { for(let i in this.extensionObject) { this.extensionObject[i].uid = this.extUidMapper[this.extensionObject[i].uid as string]; } diff --git a/packages/contentstack-import/src/types/index.ts b/packages/contentstack-import/src/types/index.ts index 5a570afac3..a780516919 100644 --- a/packages/contentstack-import/src/types/index.ts +++ b/packages/contentstack-import/src/types/index.ts @@ -106,4 +106,10 @@ export { default as DefaultConfig } from './default-config'; export { default as ImportConfig } from './import-config'; export * from './entries' -export * from './marketplace-app' \ No newline at end of file +export * from './marketplace-app' + +export type extensionType = { + uid: string, + scope: Record, + title: string +} \ No newline at end of file From a791c8247230fbd73d44110e544e9609bb338844 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 16 Feb 2024 17:34:05 +0530 Subject: [PATCH 3/7] updated logs --- packages/contentstack-import/src/import/modules/base-class.ts | 1 + packages/contentstack-import/src/import/modules/content-types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index 90c72984f1..fd804c5b78 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -284,6 +284,7 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'update-extensions': + if(!apiData.uid) return Promise.resolve();; return this.stack.extension(apiData.uid).fetch().then((extension) => { extension.scope = apiData.scope return extension.update() diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index 87dec7c7a5..85dab431a1 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -110,6 +110,7 @@ export default class ContentTypesImport extends BaseClass { } log(this.importConfig, 'Updating the Extensions', 'success'); await this.createPendingExtensions(); + log(this.importConfig, 'Extensions Updated', 'success'); await this.updatePendingGFs().catch((error) => { log(this.importConfig, `Error while updating pending global field ${formatError(error)}`, 'error'); }); From e9ef48ceec01f78163a54c298f0d1c15f096a78c Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 16 Feb 2024 18:45:50 +0530 Subject: [PATCH 4/7] fromatting and audit fix --- package-lock.json | 50 ++++++++++++------- .../src/import/modules/base-class.ts | 15 ++++-- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 71402adc69..70586503af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10036,10 +10036,23 @@ "node": ">=8" } }, - "node_modules/ip": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", - "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==", + "node_modules/ip-address": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", + "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "dev": true, + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/ip-address/node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", "dev": true }, "node_modules/ipaddr.js": { @@ -11684,6 +11697,12 @@ "xmlcreate": "^2.0.4" } }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "dev": true + }, "node_modules/jsdoc": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-4.0.2.tgz", @@ -11734,14 +11753,13 @@ } }, "node_modules/jsdoc-parse": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/jsdoc-parse/-/jsdoc-parse-6.2.0.tgz", - "integrity": "sha512-Afu1fQBEb7QHt6QWX/6eUWvYHJofB90Fjx7FuJYF7mnG9z5BkAIpms1wsnvYLytfmqpEENHs/fax9p8gvMj7dw==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/jsdoc-parse/-/jsdoc-parse-6.2.1.tgz", + "integrity": "sha512-9viGRUUtWOk/G4V0+nQ6rfLucz5plxh5I74WbNSNm9h9NWugCDVX4jbG8hZP9QqKGpdTPDE+qJXzaYNos3wqTA==", "dev": true, "dependencies": { "array-back": "^6.2.2", "lodash.omit": "^4.5.0", - "lodash.pick": "^4.4.0", "reduce-extract": "^1.0.0", "sort-array": "^4.1.5", "test-value": "^3.0.0" @@ -12474,12 +12492,6 @@ "integrity": "sha512-sOQs2aqGpbl27tmCS1QNZA09Uqp01ZzWfDUoD+xzTii0E7dSQfRKcRetFwa+uXaxaqL+TKm7CgD2JdKP7aZBSw==", "dev": true }, - "node_modules/lodash.pick": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz", - "integrity": "sha512-hXt6Ul/5yWjfklSGvLQl8vM//l3FtyHZeuelpzK6mm99pNvN9yTDruNZPEJZD1oWrqo+izBmB7oUfWgcCX7s4Q==", - "dev": true - }, "node_modules/lodash.template": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz", @@ -20106,16 +20118,16 @@ } }, "node_modules/socks": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", - "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.3.tgz", + "integrity": "sha512-vfuYK48HXCTFD03G/1/zkIls3Ebr2YNa4qU9gHDZdblHLiqhJrJGkY3+0Nx0JpN9qBhJbVObc1CNciT1bIZJxw==", "dev": true, "dependencies": { - "ip": "^2.0.0", + "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" }, "engines": { - "node": ">= 10.13.0", + "node": ">= 10.0.0", "npm": ">= 3.0.0" } }, diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index fd804c5b78..5018a7ab1b 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -284,11 +284,16 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'update-extensions': - if(!apiData.uid) return Promise.resolve();; - return this.stack.extension(apiData.uid).fetch().then((extension) => { - extension.scope = apiData.scope - return extension.update() - }).then(onSuccess).catch(onReject); + if (!apiData.uid) return Promise.resolve(); + return this.stack + .extension(apiData.uid) + .fetch() + .then((extension) => { + extension.scope = apiData.scope; + return extension.update(); + }) + .then(onSuccess) + .catch(onReject); case 'create-locale': return this.stack .locale() From e48ad6ed83d2914badec8abe58bcc990c241cb25 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 16 Feb 2024 18:49:38 +0530 Subject: [PATCH 5/7] re-formatted --- .../src/import/modules/content-types.ts | 12 +++++------ .../src/import/modules/extensions.ts | 20 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index 85dab431a1..fd65ba5acd 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -79,7 +79,7 @@ export default class ContentTypesImport extends BaseClass { this.createdGFs = []; this.pendingGFs = []; this.taxonomiesPath = path.join(importConfig.data, 'mapper/taxonomies', 'success.json'); - this.extPendingPath = path.join(importConfig.data,'mapper','extensions','pending_extensions.js'); + this.extPendingPath = path.join(importConfig.data, 'mapper', 'extensions', 'pending_extensions.js'); } async start(): Promise { @@ -109,7 +109,7 @@ export default class ContentTypesImport extends BaseClass { await fsUtil.writeFile(path.join(this.cTsFolderPath, 'field_rules_uid.json'), this.fieldRules); } log(this.importConfig, 'Updating the Extensions', 'success'); - await this.createPendingExtensions(); + await this.updatePendingExtensions(); log(this.importConfig, 'Extensions Updated', 'success'); await this.updatePendingGFs().catch((error) => { log(this.importConfig, `Error while updating pending global field ${formatError(error)}`, 'error'); @@ -256,13 +256,13 @@ export default class ContentTypesImport extends BaseClass { return apiOptions; } - async createPendingExtensions(): Promise{ + async updatePendingExtensions(): Promise { let apiContent = fsUtil.readFile(this.extPendingPath) as Record[]; - if(apiContent.length===0) { + if (apiContent.length === 0) { log(this.importConfig, `No Extension are present to be updated`, 'success'); return; } - + const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }: any) => { log(this.importConfig, `Extension '${response.title}' updated successfully`, 'success'); }; @@ -295,4 +295,4 @@ export default class ContentTypesImport extends BaseClass { false, ); } -} \ No newline at end of file +} diff --git a/packages/contentstack-import/src/import/modules/extensions.ts b/packages/contentstack-import/src/import/modules/extensions.ts index 04340aeba0..c8228aa85c 100644 --- a/packages/contentstack-import/src/import/modules/extensions.ts +++ b/packages/contentstack-import/src/import/modules/extensions.ts @@ -20,7 +20,7 @@ export default class ImportExtensions extends BaseClass { private extFailed: Record[]; private existingExtensions: Record[]; private extPendingPath: string; - private extensionObject:Record[]; + private extensionObject: Record[]; constructor({ importConfig, stackAPIClient }: ModuleClassParams) { super({ importConfig, stackAPIClient }); @@ -30,7 +30,7 @@ export default class ImportExtensions extends BaseClass { this.extUidMapperPath = join(this.mapperDirPath, 'uid-mapping.json'); this.extSuccessPath = join(this.mapperDirPath, 'success.json'); this.extFailsPath = join(this.mapperDirPath, 'fails.json'); - this.extPendingPath = join(this.mapperDirPath,'pending_extensions.js'); + this.extPendingPath = join(this.mapperDirPath, 'pending_extensions.js'); this.extFailed = []; this.extSuccess = []; this.existingExtensions = []; @@ -49,7 +49,7 @@ export default class ImportExtensions extends BaseClass { if (fileHelper.fileExistsSync(this.extensionsFolderPath)) { this.extensions = fsUtil.readFile(join(this.extensionsFolderPath, 'extensions.json'), true) as Record< string, - Record + Record >; } else { log(this.importConfig, `No such file or directory - '${this.extensionsFolderPath}'`, 'error'); @@ -220,14 +220,14 @@ export default class ImportExtensions extends BaseClass { }); } - getContentTypesInScope(){ + getContentTypesInScope() { const extension = values(this.extensions); - extension.forEach((ext:extensionType)=>{ - let ct:any = ext?.scope?.content_types || []; - if((ct.length===1 && (ct[0]!=='$all')) || (ct?.length>1)){ + extension.forEach((ext: extensionType) => { + let ct: any = ext?.scope?.content_types || []; + if ((ct.length === 1 && ct[0] !== '$all') || ct?.length > 1) { log(this.importConfig, `Removing the Content-types ${ct.join(',')} from Extension ${ext.title}`, 'success'); - const {uid, scope} = ext; - this.extensionObject.push({uid,scope}); + const { uid, scope } = ext; + this.extensionObject.push({ uid, scope }); delete ext.scope; this.extensions[ext.uid] = ext; } @@ -235,7 +235,7 @@ export default class ImportExtensions extends BaseClass { } updateUidExtension() { - for(let i in this.extensionObject) { + for (let i in this.extensionObject) { this.extensionObject[i].uid = this.extUidMapper[this.extensionObject[i].uid as string]; } fsUtil.writeFile(this.extPendingPath, this.extensionObject); From cea0d1087910935e3e00cdd9d3adb322c941c150 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 19 Feb 2024 13:20:34 +0530 Subject: [PATCH 6/7] pr fixes --- .../src/import/modules/base-class.ts | 23 ++++++------------- .../src/import/modules/extensions.ts | 6 ++--- .../contentstack-import/src/types/index.ts | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/packages/contentstack-import/src/import/modules/base-class.ts b/packages/contentstack-import/src/import/modules/base-class.ts index 5018a7ab1b..72b2374897 100644 --- a/packages/contentstack-import/src/import/modules/base-class.ts +++ b/packages/contentstack-import/src/import/modules/base-class.ts @@ -251,6 +251,13 @@ export default abstract class BaseClass { apiData: includeParamOnCompletion ? apiData : undefined, }); + if ( + !apiData || + (entity === 'publish-entries' && !apiData.entryUid) || + (entity === 'update-extensions' && !apiData.uid) + ) { + return Promise.resolve(); + } switch (entity) { case 'create-assets-folder': return this.stack @@ -284,7 +291,6 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'update-extensions': - if (!apiData.uid) return Promise.resolve(); return this.stack .extension(apiData.uid) .fetch() @@ -309,14 +315,8 @@ export default abstract class BaseClass { case 'create-cts': return this.stack.contentType().create(apiData).then(onSuccess).catch(onReject); case 'update-cts': - if (!apiData) { - return Promise.resolve(); - } return apiData.update().then(onSuccess).catch(onReject); case 'update-gfs': - if (!apiData) { - return Promise.resolve(); - } return apiData.update().then(onSuccess).catch(onReject); case 'create-environments': return this.stack @@ -358,9 +358,6 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'create-entries': - if (!apiData) { - return Promise.resolve(); - } if (additionalInfo[apiData?.uid]?.isLocalized) { return apiData.update({ locale: additionalInfo.locale }).then(onSuccess).catch(onReject); } @@ -371,14 +368,8 @@ export default abstract class BaseClass { .then(onSuccess) .catch(onReject); case 'update-entries': - if (!apiData) { - return Promise.resolve(); - } return apiData.update({ locale: additionalInfo.locale }).then(onSuccess).catch(onReject); case 'publish-entries': - if (!apiData || !apiData.entryUid) { - return Promise.resolve(); - } return this.stack .contentType(additionalInfo.cTUid) .entry(apiData.entryUid) diff --git a/packages/contentstack-import/src/import/modules/extensions.ts b/packages/contentstack-import/src/import/modules/extensions.ts index c8228aa85c..9d467b9e90 100644 --- a/packages/contentstack-import/src/import/modules/extensions.ts +++ b/packages/contentstack-import/src/import/modules/extensions.ts @@ -5,7 +5,7 @@ import { join } from 'node:path'; import { log, formatError, fsUtil, fileHelper } from '../../utils'; import BaseClass, { ApiOptions } from './base-class'; -import { ModuleClassParams, Extensions, extensionType } from '../../types'; +import { ModuleClassParams, Extensions, ExtensionType } from '../../types'; export default class ImportExtensions extends BaseClass { private mapperDirPath: string; @@ -222,10 +222,10 @@ export default class ImportExtensions extends BaseClass { getContentTypesInScope() { const extension = values(this.extensions); - extension.forEach((ext: extensionType) => { + extension.forEach((ext: ExtensionType) => { let ct: any = ext?.scope?.content_types || []; if ((ct.length === 1 && ct[0] !== '$all') || ct?.length > 1) { - log(this.importConfig, `Removing the Content-types ${ct.join(',')} from Extension ${ext.title}`, 'success'); + log(this.importConfig, `Removing the Content-types ${ct.join(',')} from Extension ${ext.title}`, 'info'); const { uid, scope } = ext; this.extensionObject.push({ uid, scope }); delete ext.scope; diff --git a/packages/contentstack-import/src/types/index.ts b/packages/contentstack-import/src/types/index.ts index a780516919..16b6785a88 100644 --- a/packages/contentstack-import/src/types/index.ts +++ b/packages/contentstack-import/src/types/index.ts @@ -108,7 +108,7 @@ export { default as ImportConfig } from './import-config'; export * from './entries' export * from './marketplace-app' -export type extensionType = { +export type ExtensionType = { uid: string, scope: Record, title: string From 788df4847bef12a709b4348d4e09f4ae7be93149 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 20 Feb 2024 17:46:39 +0530 Subject: [PATCH 7/7] ui text update --- .../src/import/modules/content-types.ts | 12 ++++++------ .../src/import/modules/extensions.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/contentstack-import/src/import/modules/content-types.ts b/packages/contentstack-import/src/import/modules/content-types.ts index fd65ba5acd..9fd9f4e5c3 100644 --- a/packages/contentstack-import/src/import/modules/content-types.ts +++ b/packages/contentstack-import/src/import/modules/content-types.ts @@ -108,9 +108,9 @@ export default class ContentTypesImport extends BaseClass { if (this.fieldRules.length > 0) { await fsUtil.writeFile(path.join(this.cTsFolderPath, 'field_rules_uid.json'), this.fieldRules); } - log(this.importConfig, 'Updating the Extensions', 'success'); + log(this.importConfig, 'Updating the extensions...', 'success'); await this.updatePendingExtensions(); - log(this.importConfig, 'Extensions Updated', 'success'); + log(this.importConfig, 'Successfully updated the extensions.', 'success'); await this.updatePendingGFs().catch((error) => { log(this.importConfig, `Error while updating pending global field ${formatError(error)}`, 'error'); }); @@ -259,22 +259,22 @@ export default class ContentTypesImport extends BaseClass { async updatePendingExtensions(): Promise { let apiContent = fsUtil.readFile(this.extPendingPath) as Record[]; if (apiContent.length === 0) { - log(this.importConfig, `No Extension are present to be updated`, 'success'); + log(this.importConfig, `No extensions found to be updated.`, 'success'); return; } const onSuccess = ({ response, apiData: { uid, title } = { uid: null, title: '' } }: any) => { - log(this.importConfig, `Extension '${response.title}' updated successfully`, 'success'); + log(this.importConfig, `Successfully updated the '${response.title}' extension.`, 'success'); }; const onReject = ({ error, apiData }: any) => { const { uid } = apiData; if (error?.errors?.title) { if (!this.importConfig.skipExisting) { - log(this.importConfig, `Extension '${uid}' already exists`, 'info'); + log(this.importConfig, `Extension '${uid}' already exists.`, 'info'); } } else { - log(this.importConfig, `Extension '${uid}' failed to be updated ${formatError(error)}`, 'error'); + log(this.importConfig, `Failed to update '${uid}' extension due to ${formatError(error)}.`, 'error'); log(this.importConfig, error, 'error'); } }; diff --git a/packages/contentstack-import/src/import/modules/extensions.ts b/packages/contentstack-import/src/import/modules/extensions.ts index 9d467b9e90..ce92433ca9 100644 --- a/packages/contentstack-import/src/import/modules/extensions.ts +++ b/packages/contentstack-import/src/import/modules/extensions.ts @@ -225,7 +225,7 @@ export default class ImportExtensions extends BaseClass { extension.forEach((ext: ExtensionType) => { let ct: any = ext?.scope?.content_types || []; if ((ct.length === 1 && ct[0] !== '$all') || ct?.length > 1) { - log(this.importConfig, `Removing the Content-types ${ct.join(',')} from Extension ${ext.title}`, 'info'); + log(this.importConfig, `Removing the content-types ${ct.join(',')} from the extension ${ext.title} ...`, 'info'); const { uid, scope } = ext; this.extensionObject.push({ uid, scope }); delete ext.scope;