From a9145183ae47bb6f7a40b2d3d8370b37e8606d97 Mon Sep 17 00:00:00 2001 From: Harshitha D Date: Wed, 28 Aug 2024 17:41:38 +0530 Subject: [PATCH 01/19] replaced personalize-url with getter methodcd --- packages/contentstack-variants/src/export/attributes.ts | 5 +++-- packages/contentstack-variants/src/export/audiences.ts | 5 +++-- packages/contentstack-variants/src/export/events.ts | 5 +++-- packages/contentstack-variants/src/export/experiences.ts | 5 +++-- packages/contentstack-variants/src/export/projects.ts | 5 +++-- packages/contentstack-variants/src/import/attribute.ts | 5 +++-- packages/contentstack-variants/src/import/audiences.ts | 5 +++-- packages/contentstack-variants/src/import/events.ts | 5 +++-- packages/contentstack-variants/src/import/experiences.ts | 5 +++-- packages/contentstack-variants/src/import/project.ts | 5 +++-- .../contentstack-variants/src/types/variant-api-adapter.ts | 2 +- 11 files changed, 31 insertions(+), 21 deletions(-) diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 1c1192413b..5df1f0eb6d 100644 --- a/packages/contentstack-variants/src/export/attributes.ts +++ b/packages/contentstack-variants/src/export/attributes.ts @@ -3,6 +3,7 @@ import { resolve as pResolve } from 'node:path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; import { PersonalizationConfig, ExportConfig, AttributesConfig, AttributeStruct } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class ExportAttributes extends PersonalizationAdapter { private attributesConfig: AttributesConfig; @@ -10,10 +11,10 @@ export default class ExportAttributes extends PersonalizationAdapter[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig) { + constructor(readonly exportConfig: ExportConfig, readonly command: Command) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; diff --git a/packages/contentstack-variants/src/export/audiences.ts b/packages/contentstack-variants/src/export/audiences.ts index f63bf1c981..a73e71a061 100644 --- a/packages/contentstack-variants/src/export/audiences.ts +++ b/packages/contentstack-variants/src/export/audiences.ts @@ -3,6 +3,7 @@ import { resolve as pResolve } from 'node:path'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; import { PersonalizationConfig, ExportConfig, AudienceStruct, AudiencesConfig } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class ExportAudiences extends PersonalizationAdapter { private audiencesConfig: AudiencesConfig; @@ -10,10 +11,10 @@ export default class ExportAudiences extends PersonalizationAdapter[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig) { + constructor(readonly exportConfig: ExportConfig, readonly command: Command) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; diff --git a/packages/contentstack-variants/src/export/events.ts b/packages/contentstack-variants/src/export/events.ts index f125b0e41f..11ce2c217c 100644 --- a/packages/contentstack-variants/src/export/events.ts +++ b/packages/contentstack-variants/src/export/events.ts @@ -3,6 +3,7 @@ import { resolve as pResolve } from 'node:path'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; import { PersonalizationConfig, ExportConfig, EventStruct, EventsConfig } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class ExportEvents extends PersonalizationAdapter { private eventsConfig: EventsConfig; @@ -10,10 +11,10 @@ export default class ExportEvents extends PersonalizationAdapter { private events: Record[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig) { + constructor(readonly exportConfig: ExportConfig, readonly command: Command) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index 0b65ef3076..72fc96f49e 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -2,15 +2,16 @@ import * as path from 'path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationConfig, ExportConfig, ExperienceStruct } from '../types'; import { formatError, fsUtil, log, PersonalizationAdapter } from '../utils'; +import { Command } from '@contentstack/cli-command'; export default class ExportExperiences extends PersonalizationAdapter { private experiencesFolderPath: string; public exportConfig: ExportConfig; public personalizationConfig: PersonalizationConfig; - constructor(exportConfig: ExportConfig) { + constructor(exportConfig: ExportConfig, readonly command: Command) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, cmaConfig: { baseURL: exportConfig.region.cma + `/v3`, diff --git a/packages/contentstack-variants/src/export/projects.ts b/packages/contentstack-variants/src/export/projects.ts index 993d610dd8..281490e5ef 100644 --- a/packages/contentstack-variants/src/export/projects.ts +++ b/packages/contentstack-variants/src/export/projects.ts @@ -2,15 +2,16 @@ import * as path from 'path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { ExportConfig, PersonalizationConfig } from '../types'; import { PersonalizationAdapter, log, fsUtil, formatError } from '../utils'; +import { Command } from '@contentstack/cli-command'; export default class ExportProjects extends PersonalizationAdapter { private projectFolderPath: string; public exportConfig: ExportConfig; public personalizationConfig: PersonalizationConfig; - constructor(exportConfig: ExportConfig) { + constructor(exportConfig: ExportConfig, readonly command: Command) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, headers: { authtoken: exportConfig.auth_token, organization_uid: exportConfig.org_uid }, }); this.exportConfig = exportConfig; diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index 3d1e513bff..b79b8f6c7d 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -3,6 +3,7 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil } from '../utils'; import { APIConfig, AttributeStruct, ImportConfig, LogType } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class Attribute extends PersonalizationAdapter { private mapperDirPath: string; @@ -12,10 +13,10 @@ export default class Attribute extends PersonalizationAdapter { private personalizationConfig: ImportConfig['modules']['personalization']; private attributeConfig: ImportConfig['modules']['personalization']['attributes']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/audiences.ts b/packages/contentstack-variants/src/import/audiences.ts index 5812ad853a..a648698ace 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -3,6 +3,7 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { APIConfig, AudienceStruct, ImportConfig, LogType } from '../types'; import { PersonalizationAdapter, fsUtil, lookUpAttributes } from '../utils'; +import { Command } from '@contentstack/cli-command'; export default class Audiences extends PersonalizationAdapter { private mapperDirPath: string; @@ -14,10 +15,10 @@ export default class Audiences extends PersonalizationAdapter { private audienceConfig: ImportConfig['modules']['personalization']['audiences']; public attributeConfig: ImportConfig['modules']['personalization']['attributes']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/events.ts b/packages/contentstack-variants/src/import/events.ts index d87d3b93fd..bdf5c909bb 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -3,6 +3,7 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil } from '../utils'; import { APIConfig, EventStruct, ImportConfig, LogType } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class Events extends PersonalizationAdapter { private mapperDirPath: string; @@ -12,10 +13,10 @@ export default class Events extends PersonalizationAdapter { private personalizationConfig: ImportConfig['modules']['personalization']; private eventsConfig: ImportConfig['modules']['personalization']['events']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index 2db2580e5b..39633d90db 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil, lookUpAudiences, lookUpEvents } from '../utils'; import { APIConfig, ImportConfig, ExperienceStruct, CreateExperienceInput, LogType } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class Experiences extends PersonalizationAdapter { private createdCTs: string[]; @@ -33,10 +34,10 @@ export default class Experiences extends PersonalizationAdapter { private audienceConfig: ImportConfig['modules']['personalization']['audiences']; private experienceConfig: ImportConfig['modules']['personalization']['experiences']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, cmaConfig: { baseURL: config.region.cma + `/v3`, diff --git a/packages/contentstack-variants/src/import/project.ts b/packages/contentstack-variants/src/import/project.ts index 5de48e851f..9b2d797278 100644 --- a/packages/contentstack-variants/src/import/project.ts +++ b/packages/contentstack-variants/src/import/project.ts @@ -3,13 +3,14 @@ import { existsSync, readFileSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, askProjectName, fsUtil } from '../utils'; import { APIConfig, CreateProjectInput, ImportConfig, LogType, ProjectStruct } from '../types'; +import { Command } from '@contentstack/cli-command'; export default class Project extends PersonalizationAdapter { private projectMapperFolderPath: string; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, headers: { organization_uid: config.org_uid, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/types/variant-api-adapter.ts b/packages/contentstack-variants/src/types/variant-api-adapter.ts index bb1ea3ba28..f8e1d9220e 100644 --- a/packages/contentstack-variants/src/types/variant-api-adapter.ts +++ b/packages/contentstack-variants/src/types/variant-api-adapter.ts @@ -9,7 +9,7 @@ import { CreateVariantEntryDto, CreateVariantEntryOptions, VariantEntryStruct } export type APIConfig = HttpRequestConfig & { httpClient?: boolean; sharedConfig?: ExportConfig | Record | undefined; - personalizationURL?: string; + personalizeUrl?: string; config: ExportConfig | Record | undefined; baseURL?: string; cmaConfig?: HttpRequestConfig; From 223f80e6d5b2dc51dd9d0727c0ded84fd2664d2e Mon Sep 17 00:00:00 2001 From: Harshitha D Date: Thu, 29 Aug 2024 10:59:18 +0530 Subject: [PATCH 02/19] updated for personalize url in attributes --- .../contentstack-export/src/commands/cm/stacks/export.ts | 1 + packages/contentstack-variants/src/export/attributes.ts | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 68c3ac9963..bdcc4ddb4c 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -107,6 +107,7 @@ export default class ExportCommand extends Command { exportConfig.host = this.cmaHost; exportConfig.region = this.region; exportConfig.developerHubBaseUrl = this.developerHubUrl; + exportConfig.modules.personalization.baseURL = { 'baseURL': this.personalizeUrl }; exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 5df1f0eb6d..45a8583ffe 100644 --- a/packages/contentstack-variants/src/export/attributes.ts +++ b/packages/contentstack-variants/src/export/attributes.ts @@ -3,7 +3,6 @@ import { resolve as pResolve } from 'node:path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; import { PersonalizationConfig, ExportConfig, AttributesConfig, AttributeStruct } from '../types'; -import { Command } from '@contentstack/cli-command'; export default class ExportAttributes extends PersonalizationAdapter { private attributesConfig: AttributesConfig; @@ -11,10 +10,10 @@ export default class ExportAttributes extends PersonalizationAdapter[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig, readonly command: Command) { + constructor(readonly exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, + baseURL: exportConfig.modules.personalization.baseURL as unknown as string || exportConfig.modules.personalization.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; From 01f2738af8b2fb1a19b15c5f4fed2ac58cef0b7e Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Thu, 19 Sep 2024 18:25:41 +0530 Subject: [PATCH 03/19] updated personalizeUrl im import, export and variants --- .../contentstack-export/src/commands/cm/stacks/export.ts | 2 +- .../contentstack-import/src/commands/cm/stacks/import.ts | 1 + packages/contentstack-variants/src/export/attributes.ts | 2 +- packages/contentstack-variants/src/export/audiences.ts | 5 ++--- packages/contentstack-variants/src/export/events.ts | 5 ++--- packages/contentstack-variants/src/export/experiences.ts | 5 ++--- packages/contentstack-variants/src/export/projects.ts | 5 ++--- packages/contentstack-variants/src/import/attribute.ts | 5 ++--- packages/contentstack-variants/src/import/audiences.ts | 5 ++--- packages/contentstack-variants/src/import/events.ts | 5 ++--- packages/contentstack-variants/src/import/experiences.ts | 6 ++---- packages/contentstack-variants/src/import/project.ts | 5 ++--- 12 files changed, 21 insertions(+), 30 deletions(-) diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index bdcc4ddb4c..3f03203b27 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -107,7 +107,7 @@ export default class ExportCommand extends Command { exportConfig.host = this.cmaHost; exportConfig.region = this.region; exportConfig.developerHubBaseUrl = this.developerHubUrl; - exportConfig.modules.personalization.baseURL = { 'baseURL': this.personalizeUrl }; + exportConfig.modules.personalization.baseURL[exportConfig.region.name] = this.personalizeUrl; exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 8d42f024a7..64897f4509 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -136,6 +136,7 @@ export default class ImportCommand extends Command { importConfig.host = this.cmaHost; importConfig.region = this.region; importConfig.developerHubBaseUrl = this.developerHubUrl; + importConfig.modules.personalization.baseURL[importConfig.region.name] = this.personalizeUrl; backupDir = importConfig.cliLogsPath || importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 45a8583ffe..1c1192413b 100644 --- a/packages/contentstack-variants/src/export/attributes.ts +++ b/packages/contentstack-variants/src/export/attributes.ts @@ -13,7 +13,7 @@ export default class ExportAttributes extends PersonalizationAdapter { private audiencesConfig: AudiencesConfig; @@ -11,10 +10,10 @@ export default class ExportAudiences extends PersonalizationAdapter[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig, readonly command: Command) { + constructor(readonly exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; diff --git a/packages/contentstack-variants/src/export/events.ts b/packages/contentstack-variants/src/export/events.ts index 11ce2c217c..f125b0e41f 100644 --- a/packages/contentstack-variants/src/export/events.ts +++ b/packages/contentstack-variants/src/export/events.ts @@ -3,7 +3,6 @@ import { resolve as pResolve } from 'node:path'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; import { PersonalizationConfig, ExportConfig, EventStruct, EventsConfig } from '../types'; -import { Command } from '@contentstack/cli-command'; export default class ExportEvents extends PersonalizationAdapter { private eventsConfig: EventsConfig; @@ -11,10 +10,10 @@ export default class ExportEvents extends PersonalizationAdapter { private events: Record[]; public personalizationConfig: PersonalizationConfig; - constructor(readonly exportConfig: ExportConfig, readonly command: Command) { + constructor(readonly exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); this.personalizationConfig = exportConfig.modules.personalization; diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index 72fc96f49e..0b65ef3076 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -2,16 +2,15 @@ import * as path from 'path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationConfig, ExportConfig, ExperienceStruct } from '../types'; import { formatError, fsUtil, log, PersonalizationAdapter } from '../utils'; -import { Command } from '@contentstack/cli-command'; export default class ExportExperiences extends PersonalizationAdapter { private experiencesFolderPath: string; public exportConfig: ExportConfig; public personalizationConfig: PersonalizationConfig; - constructor(exportConfig: ExportConfig, readonly command: Command) { + constructor(exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, cmaConfig: { baseURL: exportConfig.region.cma + `/v3`, diff --git a/packages/contentstack-variants/src/export/projects.ts b/packages/contentstack-variants/src/export/projects.ts index 281490e5ef..993d610dd8 100644 --- a/packages/contentstack-variants/src/export/projects.ts +++ b/packages/contentstack-variants/src/export/projects.ts @@ -2,16 +2,15 @@ import * as path from 'path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { ExportConfig, PersonalizationConfig } from '../types'; import { PersonalizationAdapter, log, fsUtil, formatError } from '../utils'; -import { Command } from '@contentstack/cli-command'; export default class ExportProjects extends PersonalizationAdapter { private projectFolderPath: string; public exportConfig: ExportConfig; public personalizationConfig: PersonalizationConfig; - constructor(exportConfig: ExportConfig, readonly command: Command) { + constructor(exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name] || command.personalizeUrl, + baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, organization_uid: exportConfig.org_uid }, }); this.exportConfig = exportConfig; diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index b79b8f6c7d..3d1e513bff 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -3,7 +3,6 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil } from '../utils'; import { APIConfig, AttributeStruct, ImportConfig, LogType } from '../types'; -import { Command } from '@contentstack/cli-command'; export default class Attribute extends PersonalizationAdapter { private mapperDirPath: string; @@ -13,10 +12,10 @@ export default class Attribute extends PersonalizationAdapter { private personalizationConfig: ImportConfig['modules']['personalization']; private attributeConfig: ImportConfig['modules']['personalization']['attributes']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/audiences.ts b/packages/contentstack-variants/src/import/audiences.ts index a648698ace..5812ad853a 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -3,7 +3,6 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { APIConfig, AudienceStruct, ImportConfig, LogType } from '../types'; import { PersonalizationAdapter, fsUtil, lookUpAttributes } from '../utils'; -import { Command } from '@contentstack/cli-command'; export default class Audiences extends PersonalizationAdapter { private mapperDirPath: string; @@ -15,10 +14,10 @@ export default class Audiences extends PersonalizationAdapter { private audienceConfig: ImportConfig['modules']['personalization']['audiences']; public attributeConfig: ImportConfig['modules']['personalization']['attributes']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/events.ts b/packages/contentstack-variants/src/import/events.ts index bdf5c909bb..d87d3b93fd 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -3,7 +3,6 @@ import { existsSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil } from '../utils'; import { APIConfig, EventStruct, ImportConfig, LogType } from '../types'; -import { Command } from '@contentstack/cli-command'; export default class Events extends PersonalizationAdapter { private mapperDirPath: string; @@ -13,10 +12,10 @@ export default class Events extends PersonalizationAdapter { private personalizationConfig: ImportConfig['modules']['personalization']; private eventsConfig: ImportConfig['modules']['personalization']['events']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index 39633d90db..ea4a1c27e6 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -5,8 +5,6 @@ import cloneDeep from 'lodash/cloneDeep'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, fsUtil, lookUpAudiences, lookUpEvents } from '../utils'; import { APIConfig, ImportConfig, ExperienceStruct, CreateExperienceInput, LogType } from '../types'; -import { Command } from '@contentstack/cli-command'; - export default class Experiences extends PersonalizationAdapter { private createdCTs: string[]; private mapperDirPath: string; @@ -34,10 +32,10 @@ export default class Experiences extends PersonalizationAdapter { private audienceConfig: ImportConfig['modules']['personalization']['audiences']; private experienceConfig: ImportConfig['modules']['personalization']['experiences']; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, cmaConfig: { baseURL: config.region.cma + `/v3`, diff --git a/packages/contentstack-variants/src/import/project.ts b/packages/contentstack-variants/src/import/project.ts index 9b2d797278..5de48e851f 100644 --- a/packages/contentstack-variants/src/import/project.ts +++ b/packages/contentstack-variants/src/import/project.ts @@ -3,14 +3,13 @@ import { existsSync, readFileSync } from 'fs'; import { sanitizePath } from '@contentstack/cli-utilities'; import { PersonalizationAdapter, askProjectName, fsUtil } from '../utils'; import { APIConfig, CreateProjectInput, ImportConfig, LogType, ProjectStruct } from '../types'; -import { Command } from '@contentstack/cli-command'; export default class Project extends PersonalizationAdapter { private projectMapperFolderPath: string; - constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log, readonly command: Command) { + constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name] || command.personalizeUrl, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { organization_uid: config.org_uid, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); From e5b21384e552cb8c01bdc005dd47ef6fd02b4454 Mon Sep 17 00:00:00 2001 From: "harshitha.d" Date: Thu, 19 Sep 2024 19:11:25 +0530 Subject: [PATCH 04/19] reverting --- packages/contentstack-variants/src/types/variant-api-adapter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-variants/src/types/variant-api-adapter.ts b/packages/contentstack-variants/src/types/variant-api-adapter.ts index f8e1d9220e..bb1ea3ba28 100644 --- a/packages/contentstack-variants/src/types/variant-api-adapter.ts +++ b/packages/contentstack-variants/src/types/variant-api-adapter.ts @@ -9,7 +9,7 @@ import { CreateVariantEntryDto, CreateVariantEntryOptions, VariantEntryStruct } export type APIConfig = HttpRequestConfig & { httpClient?: boolean; sharedConfig?: ExportConfig | Record | undefined; - personalizeUrl?: string; + personalizationURL?: string; config: ExportConfig | Record | undefined; baseURL?: string; cmaConfig?: HttpRequestConfig; From 63722f3d928990b82e5efe2e904cdc0e07d4a36b Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 20 Sep 2024 11:31:57 +0530 Subject: [PATCH 05/19] refactor: entry variant api response & replaced personalization with personalize --- .../src/commands/cm/stacks/export.ts | 2 +- .../contentstack-export/src/config/index.ts | 8 +++---- .../{personalization.ts => personalize.ts} | 6 ++--- .../src/types/default-config.ts | 2 +- .../contentstack-export/src/types/index.ts | 2 +- .../src/commands/cm/stacks/import.ts | 2 +- .../contentstack-import/src/config/index.ts | 6 ++--- .../{personalization.ts => personalize.ts} | 10 ++++---- .../src/import/modules/variant-entries.ts | 10 ++++---- .../src/types/default-config.ts | 2 +- .../contentstack-import/src/types/index.ts | 2 +- .../src/export/attributes.ts | 4 ++-- .../src/export/audiences.ts | 4 ++-- .../src/export/events.ts | 4 ++-- .../src/export/experiences.ts | 4 ++-- .../src/export/projects.ts | 4 ++-- .../src/import/attribute.ts | 10 ++++---- .../src/import/audiences.ts | 12 +++++----- .../src/import/events.ts | 10 ++++---- .../src/import/experiences.ts | 20 ++++++++-------- .../src/import/project.ts | 20 ++++++++-------- .../src/import/variant-entries.ts | 24 +++++++++---------- .../src/messages/index.ts | 2 +- .../src/types/export-config.ts | 4 ++-- .../src/types/import-config.ts | 2 +- .../src/types/variant-entry.ts | 4 ++-- .../src/utils/error-helper.ts | 2 +- .../src/utils/personalization-api-adapter.ts | 4 ++-- .../tsconfig.tsbuildinfo | 1 + packages/contentstack/README.md | 2 +- 30 files changed, 95 insertions(+), 94 deletions(-) rename packages/contentstack-export/src/export/modules/{personalization.ts => personalize.ts} (93%) rename packages/contentstack-import/src/import/modules/{personalization.ts => personalize.ts} (85%) create mode 100644 packages/contentstack-variants/tsconfig.tsbuildinfo diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 3f03203b27..622238cb33 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -107,7 +107,7 @@ export default class ExportCommand extends Command { exportConfig.host = this.cmaHost; exportConfig.region = this.region; exportConfig.developerHubBaseUrl = this.developerHubUrl; - exportConfig.modules.personalization.baseURL[exportConfig.region.name] = this.personalizeUrl; + exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl; exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); diff --git a/packages/contentstack-export/src/config/index.ts b/packages/contentstack-export/src/config/index.ts index ad51bf8437..e83d09215f 100644 --- a/packages/contentstack-export/src/config/index.ts +++ b/packages/contentstack-export/src/config/index.ts @@ -33,7 +33,7 @@ const config: DefaultConfig = { 'content-types', 'custom-roles', 'workflows', - 'personalization', + 'personalize', 'entries', 'labels', 'marketplace-apps', @@ -144,11 +144,11 @@ const config: DefaultConfig = { dependencies: ['locales', 'content-types'], exportVersions: false, }, - personalization: { + personalize: { baseURL: { - NA: 'https://personalization-api.contentstack.com', + NA: 'https://personalize-api.contentstack.com', }, - dirName: 'personalization', + dirName: 'personalize', exportOrder: ['attributes', 'audiences', 'events', 'experiences'], projects: { dirName: 'projects', diff --git a/packages/contentstack-export/src/export/modules/personalization.ts b/packages/contentstack-export/src/export/modules/personalize.ts similarity index 93% rename from packages/contentstack-export/src/export/modules/personalization.ts rename to packages/contentstack-export/src/export/modules/personalize.ts index 6d0673ffb1..1e3bc2856a 100644 --- a/packages/contentstack-export/src/export/modules/personalization.ts +++ b/packages/contentstack-export/src/export/modules/personalize.ts @@ -10,12 +10,12 @@ import { import { log, formatError } from '../../utils'; import { ModuleClassParams, ExportConfig } from '../../types'; -export default class ExportPersonalization { +export default class ExportPersonalize { public exportConfig: ExportConfig; public personalizeConfig: { dirName: string; baseURL: Record } & AnyProperty; constructor({ exportConfig }: ModuleClassParams) { this.exportConfig = exportConfig; - this.personalizeConfig = exportConfig.modules.personalization; + this.personalizeConfig = exportConfig.modules.personalize; } async start(): Promise { @@ -39,7 +39,7 @@ export default class ExportPersonalization { experiences: new ExportExperiences(this.exportConfig), }; - const order: (keyof typeof moduleMapper)[] = this.exportConfig.modules.personalization + const order: (keyof typeof moduleMapper)[] = this.exportConfig.modules.personalize .exportOrder as (keyof typeof moduleMapper)[]; for (const module of order) { diff --git a/packages/contentstack-export/src/types/default-config.ts b/packages/contentstack-export/src/types/default-config.ts index edded90644..eb6c5c0474 100644 --- a/packages/contentstack-export/src/types/default-config.ts +++ b/packages/contentstack-export/src/types/default-config.ts @@ -122,7 +122,7 @@ export default interface DefaultConfig { dependencies?: Modules[]; exportVersions: boolean; }; - personalization: { + personalize: { dirName: string; baseURL: Record; } & AnyProperty; diff --git a/packages/contentstack-export/src/types/index.ts b/packages/contentstack-export/src/types/index.ts index 0616dbe545..0b922c0969 100644 --- a/packages/contentstack-export/src/types/index.ts +++ b/packages/contentstack-export/src/types/index.ts @@ -49,7 +49,7 @@ export type Modules = | 'labels' | 'marketplace-apps' | 'taxonomies' - | 'personalization'; + | 'personalize'; export type ModuleClassParams = { stackAPIClient: ReturnType; diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 64897f4509..992586245c 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -136,7 +136,7 @@ export default class ImportCommand extends Command { importConfig.host = this.cmaHost; importConfig.region = this.region; importConfig.developerHubBaseUrl = this.developerHubUrl; - importConfig.modules.personalization.baseURL[importConfig.region.name] = this.personalizeUrl; + importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl; backupDir = importConfig.cliLogsPath || importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); diff --git a/packages/contentstack-import/src/config/index.ts b/packages/contentstack-import/src/config/index.ts index 1b1e9965ae..1e81b84428 100644 --- a/packages/contentstack-import/src/config/index.ts +++ b/packages/contentstack-import/src/config/index.ts @@ -33,7 +33,7 @@ const config: DefaultConfig = { 'marketplace-apps', 'global-fields', 'content-types', - 'personalization', + 'personalize', 'custom-roles', 'workflows', 'entries', @@ -151,12 +151,12 @@ const config: DefaultConfig = { dirName: 'taxonomies', fileName: 'taxonomies.json', }, - personalization: { + personalize: { baseURL: { NA: 'https://personalization-api.contentstack.com', }, importData: true, - dirName: 'personalization', + dirName: 'personalize', importOrder: ['attributes', 'audiences', 'events', 'experiences'], project_id: '', projects: { diff --git a/packages/contentstack-import/src/import/modules/personalization.ts b/packages/contentstack-import/src/import/modules/personalize.ts similarity index 85% rename from packages/contentstack-import/src/import/modules/personalization.ts rename to packages/contentstack-import/src/import/modules/personalize.ts index 71f9f29dbe..f8bf81ab51 100644 --- a/packages/contentstack-import/src/import/modules/personalization.ts +++ b/packages/contentstack-import/src/import/modules/personalize.ts @@ -2,13 +2,13 @@ import { Import, LogType } from '@contentstack/cli-variants'; import { log } from '../../utils'; import { ImportConfig, ModuleClassParams } from '../../types'; -export default class ImportPersonalization { +export default class ImportPersonalize { private config: ImportConfig; - public personalizeConfig: ImportConfig['modules']['personalization']; + public personalizeConfig: ImportConfig['modules']['personalize']; constructor({ importConfig }: ModuleClassParams) { this.config = importConfig; - this.personalizeConfig = importConfig.modules.personalization; + this.personalizeConfig = importConfig.modules.personalize; } /** @@ -45,10 +45,10 @@ export default class ImportPersonalization { } } } catch (error) { - this.personalizeConfig.importData = false; // Stop personalization import if project creation fails + this.personalizeConfig.importData = false; // Stop personalize import if project creation fails log(this.config, error, 'error'); if (!this.personalizeConfig.importData) { - log(this.config, 'Skipping personalization migration...', 'warn'); + log(this.config, 'Skipping personalize migration...', 'warn'); } } } diff --git a/packages/contentstack-import/src/import/modules/variant-entries.ts b/packages/contentstack-import/src/import/modules/variant-entries.ts index 2dd4f99390..c699035e4b 100644 --- a/packages/contentstack-import/src/import/modules/variant-entries.ts +++ b/packages/contentstack-import/src/import/modules/variant-entries.ts @@ -14,16 +14,16 @@ import { export default class ImportVarientEntries { private config: ImportConfig; - public personalization: ImportConfig['modules']['personalization']; + public personalize: ImportConfig['modules']['personalize']; private projectMapperFilePath: string; constructor({ importConfig }: ModuleClassParams) { this.config = importConfig; - this.personalization = importConfig.modules.personalization; + this.personalize = importConfig.modules.personalize; this.projectMapperFilePath = path.resolve( sanitizePath(this.config.data), 'mapper', - sanitizePath(this.personalization.dirName), + sanitizePath(this.personalize.dirName), 'projects', 'projects.json', ); @@ -36,8 +36,8 @@ export default class ImportVarientEntries { async start(): Promise { try { const project = fsUtil.readFile(this.projectMapperFilePath) as ProjectStruct; - if (project && project.uid && this.personalization.importData) { - this.config.modules.personalization.project_id = project.uid; + if (project && project.uid) { + this.config.modules.personalize.project_id = project.uid; const helpers: ImportHelperMethodsConfig = { lookUpTerms, lookupAssets, diff --git a/packages/contentstack-import/src/types/default-config.ts b/packages/contentstack-import/src/types/default-config.ts index 8b5390be37..4a39aff817 100644 --- a/packages/contentstack-import/src/types/default-config.ts +++ b/packages/contentstack-import/src/types/default-config.ts @@ -122,7 +122,7 @@ export default interface DefaultConfig { fileName: string; dependencies?: Modules[]; }; - personalization: { + personalize: { baseURL: Record; dirName: string; importData: boolean; diff --git a/packages/contentstack-import/src/types/index.ts b/packages/contentstack-import/src/types/index.ts index e0a82835f7..dab9d5beda 100644 --- a/packages/contentstack-import/src/types/index.ts +++ b/packages/contentstack-import/src/types/index.ts @@ -49,7 +49,7 @@ export type Modules = | 'labels' | 'marketplace-apps' | 'taxonomies' - | 'personalization' + | 'personalize' | 'variant-entries'; export type ModuleClassParams = { diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 1c1192413b..34310de4eb 100644 --- a/packages/contentstack-variants/src/export/attributes.ts +++ b/packages/contentstack-variants/src/export/attributes.ts @@ -13,10 +13,10 @@ export default class ExportAttributes extends PersonalizationAdapter { constructor(readonly exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); - this.personalizationConfig = exportConfig.modules.personalization; + this.personalizationConfig = exportConfig.modules.personalize; this.eventsConfig = exportConfig.modules.events; this.eventsFolderPath = pResolve( exportConfig.data, diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index 0b65ef3076..1a1960a803 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -10,7 +10,7 @@ export default class ExportExperiences extends PersonalizationAdapter constructor(exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL[exportConfig.region.name], + baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, organization_uid: exportConfig.org_uid }, }); this.exportConfig = exportConfig; - this.personalizationConfig = exportConfig.modules.personalization; + this.personalizationConfig = exportConfig.modules.personalize; this.projectFolderPath = path.resolve( sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index 3d1e513bff..c3a3f2eb03 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -9,17 +9,17 @@ export default class Attribute extends PersonalizationAdapter { private attrMapperDirPath: string; private attributesUidMapperPath: string; private attributesUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalization']; - private attributeConfig: ImportConfig['modules']['personalization']['attributes']; + private personalizationConfig: ImportConfig['modules']['personalize']; + private attributeConfig: ImportConfig['modules']['personalize']['attributes']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], - headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, + baseURL: config.modules.personalize.baseURL[config.region.name], + headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalization; + this.personalizationConfig = this.config.modules.personalize; this.attributeConfig = this.personalizationConfig.attributes; this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); this.attrMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName)); diff --git a/packages/contentstack-variants/src/import/audiences.ts b/packages/contentstack-variants/src/import/audiences.ts index 5812ad853a..867da17f1e 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -10,18 +10,18 @@ export default class Audiences extends PersonalizationAdapter { private attributesMapperPath: string; private audiencesUidMapperPath: string; private audiencesUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalization']; - private audienceConfig: ImportConfig['modules']['personalization']['audiences']; - public attributeConfig: ImportConfig['modules']['personalization']['attributes']; + private personalizationConfig: ImportConfig['modules']['personalize']; + private audienceConfig: ImportConfig['modules']['personalize']['audiences']; + public attributeConfig: ImportConfig['modules']['personalize']['attributes']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], - headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, + baseURL: config.modules.personalize.baseURL[config.region.name], + headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalization; + this.personalizationConfig = this.config.modules.personalize; this.audienceConfig = this.personalizationConfig.audiences; this.attributeConfig = this.personalizationConfig.attributes; this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); diff --git a/packages/contentstack-variants/src/import/events.ts b/packages/contentstack-variants/src/import/events.ts index d87d3b93fd..84bff37239 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -9,17 +9,17 @@ export default class Events extends PersonalizationAdapter { private eventMapperDirPath: string; private eventsUidMapperPath: string; private eventsUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalization']; - private eventsConfig: ImportConfig['modules']['personalization']['events']; + private personalizationConfig: ImportConfig['modules']['personalize']; + private eventsConfig: ImportConfig['modules']['personalize']['events']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], - headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, + baseURL: config.modules.personalize.baseURL[config.region.name], + headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalization; + this.personalizationConfig = this.config.modules.personalize; this.eventsConfig = this.personalizationConfig.events; this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); this.eventMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.eventsConfig.dirName)); diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index ea4a1c27e6..20348afcda 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -28,22 +28,22 @@ export default class Experiences extends PersonalizationAdapter { private cmsVariantGroups: Record; private experiencesUidMapper: Record; private pendingVariantAndVariantGrpForExperience: string[]; - private personalizationConfig: ImportConfig['modules']['personalization']; - private audienceConfig: ImportConfig['modules']['personalization']['audiences']; - private experienceConfig: ImportConfig['modules']['personalization']['experiences']; + private personalizationConfig: ImportConfig['modules']['personalize']; + private audienceConfig: ImportConfig['modules']['personalize']['audiences']; + private experienceConfig: ImportConfig['modules']['personalize']['experiences']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], - headers: { 'X-Project-Uid': config.modules.personalization.project_id, authtoken: config.auth_token }, + baseURL: config.modules.personalize.baseURL[config.region.name], + headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, cmaConfig: { baseURL: config.region.cma + `/v3`, headers: { authtoken: config.auth_token, api_key: config.apiKey }, }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalization; + this.personalizationConfig = this.config.modules.personalize; this.experiencesDirPath = resolve( sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), @@ -130,9 +130,9 @@ export default class Experiences extends PersonalizationAdapter { } /** - * function to validate if all variant groups and variants have been created using personalization background job - * store the variant groups data in mapper/personalization/experiences/cms-variant-groups.json and the variants data - * in mapper/personalization/experiences/cms-variants.json. If not, invoke validateVariantGroupAndVariantsCreated after some delay. + * function to validate if all variant groups and variants have been created using personalize background job + * store the variant groups data in mapper/personalize/experiences/cms-variant-groups.json and the variants data + * in mapper/personalize/experiences/cms-variants.json. If not, invoke validateVariantGroupAndVariantsCreated after some delay. * @param retryCount Counter to track the number of times the function has been called * @returns */ @@ -159,7 +159,7 @@ export default class Experiences extends PersonalizationAdapter { ); return this.validateVariantGroupAndVariantsCreated(retryCount); } else { - this.log(this.config, this.messages.PERSONALIZATION_JOB_FAILURE, 'error'); + this.log(this.config, this.messages.PERSONALIZE_JOB_FAILURE, 'error'); fsUtil.writeFile(this.failedCmsExpPath, this.pendingVariantAndVariantGrpForExperience); return false; } diff --git a/packages/contentstack-variants/src/import/project.ts b/packages/contentstack-variants/src/import/project.ts index 5de48e851f..0741785e49 100644 --- a/packages/contentstack-variants/src/import/project.ts +++ b/packages/contentstack-variants/src/import/project.ts @@ -9,14 +9,14 @@ export default class Project extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.modules.personalization.baseURL[config.region.name], + baseURL: config.modules.personalize.baseURL[config.region.name], headers: { organization_uid: config.org_uid, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); this.projectMapperFolderPath = pResolve( sanitizePath(this.config.backupDir), 'mapper', - sanitizePath(this.config.modules.personalization.dirName), + sanitizePath(this.config.modules.personalize.dirName), 'projects', ); } @@ -26,15 +26,15 @@ export default class Project extends PersonalizationAdapter { * data. */ async import() { - const personalization = this.config.modules.personalization; - const { dirName, fileName } = personalization.projects; - const projectPath = join(sanitizePath(this.config.data), sanitizePath(personalization.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const personalize = this.config.modules.personalize; + const { dirName, fileName } = personalize.projects; + const projectPath = join(sanitizePath(this.config.data), sanitizePath(personalize.dirName), sanitizePath(dirName), sanitizePath(fileName)); if (existsSync(projectPath)) { const projects = JSON.parse(readFileSync(projectPath, 'utf8')) as CreateProjectInput[]; if (!projects || projects.length < 1) { - this.config.modules.personalization.importData = false; // Stop personalization import if stack not connected to any project + this.config.modules.personalize.importData = false; // Stop personalize import if stack not connected to any project this.log(this.config, 'No project found!', 'info'); return; } @@ -46,7 +46,7 @@ export default class Project extends PersonalizationAdapter { description: project.description, connectedStackApiKey: this.config.apiKey, }).catch(async (error) => { - if (error === 'personalization.PROJECTS.DUPLICATE_NAME') { + if (error === 'personalization.PROJECTS.DUPLICATE_NAME' || error === 'personalize.PROJECTS.DUPLICATE_NAME') { const projectName = await askProjectName('Copy Of ' + (newName || project.name)); return await createProject(projectName); } @@ -56,15 +56,15 @@ export default class Project extends PersonalizationAdapter { }; const projectRes = await createProject(this.config.personalizeProjectName); - this.config.modules.personalization.project_id = projectRes.uid; - this.config.modules.personalization.importData = true; + this.config.modules.personalize.project_id = projectRes.uid; + this.config.modules.personalize.importData = true; await fsUtil.makeDirectory(this.projectMapperFolderPath); fsUtil.writeFile(pResolve(sanitizePath(this.projectMapperFolderPath), 'projects.json'), projectRes); this.log(this.config, `Project Created Successfully: ${projectRes.uid}`, 'info'); } } else { - this.config.modules.personalization.importData = false; // Stop personalization import if stack not connected to any project + this.config.modules.personalize.importData = false; // Stop personalize import if stack not connected to any project this.log(this.config, 'No project found!', 'info'); } } diff --git a/packages/contentstack-variants/src/import/variant-entries.ts b/packages/contentstack-variants/src/import/variant-entries.ts index 50e899c4bd..3f81bf1bae 100644 --- a/packages/contentstack-variants/src/import/variant-entries.ts +++ b/packages/contentstack-variants/src/import/variant-entries.ts @@ -29,7 +29,7 @@ export default class VariantEntries extends VariantAdapter; - public personalizationConfig: ImportConfig['modules']['personalization']; + public personalizationConfig: ImportConfig['modules']['personalize']; public taxonomies!: Record; public assetUrlMapper!: Record; @@ -51,12 +51,12 @@ export default class VariantEntries extends VariantAdapter; } & AnyProperty; diff --git a/packages/contentstack-variants/src/types/import-config.ts b/packages/contentstack-variants/src/types/import-config.ts index c534796acc..d46f32f098 100644 --- a/packages/contentstack-variants/src/types/import-config.ts +++ b/packages/contentstack-variants/src/types/import-config.ts @@ -12,7 +12,7 @@ export interface ImportDefaultConfig extends AnyProperty { dirName: string; fileName: string; }; - personalization: { + personalize: { baseURL: Record; dirName: string; importData: boolean; diff --git a/packages/contentstack-variants/src/types/variant-entry.ts b/packages/contentstack-variants/src/types/variant-entry.ts index adf10be0bb..5608cb21e2 100644 --- a/packages/contentstack-variants/src/types/variant-entry.ts +++ b/packages/contentstack-variants/src/types/variant-entry.ts @@ -3,11 +3,11 @@ import { AnyProperty } from './utils'; export type VariantEntryStruct = { uid: string; title: string; - variant_id: string; locale: string; _version: number; _variant: { - uid: string; + _uid: string; + _instance_uid: string; _change_set: string[]; _base_entry_version: number; }; diff --git a/packages/contentstack-variants/src/utils/error-helper.ts b/packages/contentstack-variants/src/utils/error-helper.ts index 36ceeb08de..58c087fbbc 100644 --- a/packages/contentstack-variants/src/utils/error-helper.ts +++ b/packages/contentstack-variants/src/utils/error-helper.ts @@ -22,5 +22,5 @@ function formatError(error: any): string { if (typeof error === 'object') { return Object.values(error).join(' '); } - return String(error); + return error; } diff --git a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts index 531b22d698..71b01c4f8c 100644 --- a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts +++ b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts @@ -178,10 +178,10 @@ export class PersonalizationAdapter extends AdapterHelper impl if (status >= 200 && status < 300) { return data; } - + const errorMsg = data?.errors ? formatErrors(data.errors) - : data?.error_message || data?.message || 'Something went wrong while processing variant entries request!'; + : data?.error || data?.error_message || data?.message || 'Something went wrong while processing variant entries request!'; throw errorMsg; } diff --git a/packages/contentstack-variants/tsconfig.tsbuildinfo b/packages/contentstack-variants/tsconfig.tsbuildinfo new file mode 100644 index 0000000000..d2b5f2c97d --- /dev/null +++ b/packages/contentstack-variants/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./src/index.ts"],"version":"5.6.2"} \ No newline at end of file diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 18ec0a5b68..ed98442025 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.25.1 darwin-arm64 node-v22.8.0 +@contentstack/cli/1.25.1 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND From bd740631d66e78bef710a652edd0aac2b75c8b83 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 20 Sep 2024 11:40:29 +0530 Subject: [PATCH 06/19] added build info in gitignore file --- packages/contentstack-variants/.gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-variants/.gitignore b/packages/contentstack-variants/.gitignore index a9c2ebe564..e0f971471f 100644 --- a/packages/contentstack-variants/.gitignore +++ b/packages/contentstack-variants/.gitignore @@ -7,4 +7,5 @@ /yarn.lock node_modules .DS_Store -coverage \ No newline at end of file +coverage +/tsconfig.tsbuildinfo \ No newline at end of file From 57a885c10ef7733eb81987bdd238fc367538c517 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 20 Sep 2024 14:27:10 +0530 Subject: [PATCH 07/19] refactor: replaced personalizationConfig with personalizeConfig --- .../src/export/attributes.ts | 8 ++++---- .../src/export/audiences.ts | 8 ++++---- .../src/export/events.ts | 8 ++++---- .../src/export/experiences.ts | 8 ++++---- .../src/export/projects.ts | 8 ++++---- .../src/import/attribute.ts | 10 +++++----- .../src/import/audiences.ts | 12 +++++------ .../src/import/events.ts | 10 +++++----- .../src/import/experiences.ts | 20 +++++++++---------- .../src/import/variant-entries.ts | 8 ++++---- .../src/types/export-config.ts | 2 +- 11 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 34310de4eb..9fa7643a74 100644 --- a/packages/contentstack-variants/src/export/attributes.ts +++ b/packages/contentstack-variants/src/export/attributes.ts @@ -2,13 +2,13 @@ import omit from 'lodash/omit'; import { resolve as pResolve } from 'node:path'; import { sanitizePath } from '@contentstack/cli-utilities'; import { formatError, fsUtil, PersonalizationAdapter, log } from '../utils'; -import { PersonalizationConfig, ExportConfig, AttributesConfig, AttributeStruct } from '../types'; +import { PersonalizeConfig, ExportConfig, AttributesConfig, AttributeStruct } from '../types'; export default class ExportAttributes extends PersonalizationAdapter { private attributesConfig: AttributesConfig; private attributesFolderPath: string; private attributes: Record[]; - public personalizationConfig: PersonalizationConfig; + public personalizeConfig: PersonalizeConfig; constructor(readonly exportConfig: ExportConfig) { super({ @@ -16,12 +16,12 @@ export default class ExportAttributes extends PersonalizationAdapter { private audiencesConfig: AudiencesConfig; private audiencesFolderPath: string; private audiences: Record[]; - public personalizationConfig: PersonalizationConfig; + public personalizeConfig: PersonalizeConfig; constructor(readonly exportConfig: ExportConfig) { super({ @@ -16,12 +16,12 @@ export default class ExportAudiences extends PersonalizationAdapter { private eventsConfig: EventsConfig; private eventsFolderPath: string; private events: Record[]; - public personalizationConfig: PersonalizationConfig; + public personalizeConfig: PersonalizeConfig; constructor(readonly exportConfig: ExportConfig) { super({ @@ -16,12 +16,12 @@ export default class ExportEvents extends PersonalizationAdapter { baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name], headers: { authtoken: exportConfig.auth_token, 'X-Project-Uid': exportConfig.project_id }, }); - this.personalizationConfig = exportConfig.modules.personalize; + this.personalizeConfig = exportConfig.modules.personalize; this.eventsConfig = exportConfig.modules.events; this.eventsFolderPath = pResolve( exportConfig.data, exportConfig.branchName || '', - this.personalizationConfig.dirName, + this.personalizeConfig.dirName, this.eventsConfig.dirName, ); this.events = []; diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index 1a1960a803..2148aaad93 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -1,12 +1,12 @@ import * as path from 'path'; import { sanitizePath } from '@contentstack/cli-utilities'; -import { PersonalizationConfig, ExportConfig, ExperienceStruct } from '../types'; +import { PersonalizeConfig, ExportConfig, ExperienceStruct } from '../types'; import { formatError, fsUtil, log, PersonalizationAdapter } from '../utils'; export default class ExportExperiences extends PersonalizationAdapter { private experiencesFolderPath: string; public exportConfig: ExportConfig; - public personalizationConfig: PersonalizationConfig; + public personalizeConfig: PersonalizeConfig; constructor(exportConfig: ExportConfig) { super({ config: exportConfig, @@ -18,11 +18,11 @@ export default class ExportExperiences extends PersonalizationAdapter { private projectFolderPath: string; public exportConfig: ExportConfig; - public personalizationConfig: PersonalizationConfig; + public personalizeConfig: PersonalizeConfig; constructor(exportConfig: ExportConfig) { super({ config: exportConfig, @@ -14,11 +14,11 @@ export default class ExportProjects extends PersonalizationAdapter headers: { authtoken: exportConfig.auth_token, organization_uid: exportConfig.org_uid }, }); this.exportConfig = exportConfig; - this.personalizationConfig = exportConfig.modules.personalize; + this.personalizeConfig = exportConfig.modules.personalize; this.projectFolderPath = path.resolve( sanitizePath(exportConfig.data), sanitizePath(exportConfig.branchName || ''), - sanitizePath(this.personalizationConfig.dirName), + sanitizePath(this.personalizeConfig.dirName), 'projects', ); } diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index c3a3f2eb03..b7da7c5d71 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -9,7 +9,7 @@ export default class Attribute extends PersonalizationAdapter { private attrMapperDirPath: string; private attributesUidMapperPath: string; private attributesUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalize']; + private personalizeConfig: ImportConfig['modules']['personalize']; private attributeConfig: ImportConfig['modules']['personalize']['attributes']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { @@ -19,9 +19,9 @@ export default class Attribute extends PersonalizationAdapter { headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalize; - this.attributeConfig = this.personalizationConfig.attributes; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); + this.personalizeConfig = this.config.modules.personalize; + this.attributeConfig = this.personalizeConfig.attributes; + this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); this.attrMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName)); this.attributesUidMapperPath = resolve(sanitizePath(this.attrMapperDirPath), 'uid-mapping.json'); this.attributesUidMapper = {}; @@ -35,7 +35,7 @@ export default class Attribute extends PersonalizationAdapter { await fsUtil.makeDirectory(this.attrMapperDirPath); const { dirName, fileName } = this.attributeConfig; - const attributesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const attributesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); if (existsSync(attributesPath)) { try { diff --git a/packages/contentstack-variants/src/import/audiences.ts b/packages/contentstack-variants/src/import/audiences.ts index 867da17f1e..9925101699 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -10,7 +10,7 @@ export default class Audiences extends PersonalizationAdapter { private attributesMapperPath: string; private audiencesUidMapperPath: string; private audiencesUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalize']; + private personalizeConfig: ImportConfig['modules']['personalize']; private audienceConfig: ImportConfig['modules']['personalize']['audiences']; public attributeConfig: ImportConfig['modules']['personalize']['attributes']; @@ -21,10 +21,10 @@ export default class Audiences extends PersonalizationAdapter { headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalize; - this.audienceConfig = this.personalizationConfig.audiences; - this.attributeConfig = this.personalizationConfig.attributes; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); + this.personalizeConfig = this.config.modules.personalize; + this.audienceConfig = this.personalizeConfig.audiences; + this.attributeConfig = this.personalizeConfig.attributes; + this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); this.audienceMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.audienceConfig.dirName)); this.audiencesUidMapperPath = resolve(sanitizePath(this.audienceMapperDirPath), 'uid-mapping.json'); this.attributesMapperPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName), 'uid-mapping.json'); @@ -39,7 +39,7 @@ export default class Audiences extends PersonalizationAdapter { await fsUtil.makeDirectory(this.audienceMapperDirPath); const { dirName, fileName } = this.audienceConfig; - const audiencesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const audiencesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); if (existsSync(audiencesPath)) { try { diff --git a/packages/contentstack-variants/src/import/events.ts b/packages/contentstack-variants/src/import/events.ts index 84bff37239..954a797278 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -9,7 +9,7 @@ export default class Events extends PersonalizationAdapter { private eventMapperDirPath: string; private eventsUidMapperPath: string; private eventsUidMapper: Record; - private personalizationConfig: ImportConfig['modules']['personalize']; + private personalizeConfig: ImportConfig['modules']['personalize']; private eventsConfig: ImportConfig['modules']['personalize']['events']; constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { @@ -19,9 +19,9 @@ export default class Events extends PersonalizationAdapter { headers: { 'X-Project-Uid': config.modules.personalize.project_id, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalize; - this.eventsConfig = this.personalizationConfig.events; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); + this.personalizeConfig = this.config.modules.personalize; + this.eventsConfig = this.personalizeConfig.events; + this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); this.eventMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.eventsConfig.dirName)); this.eventsUidMapperPath = resolve(sanitizePath(this.eventMapperDirPath), 'uid-mapping.json'); this.eventsUidMapper = {}; @@ -35,7 +35,7 @@ export default class Events extends PersonalizationAdapter { await fsUtil.makeDirectory(this.eventMapperDirPath); const { dirName, fileName } = this.eventsConfig; - const eventsPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizationConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const eventsPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); if (existsSync(eventsPath)) { try { diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index 20348afcda..5bf7a72fd7 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -28,7 +28,7 @@ export default class Experiences extends PersonalizationAdapter { private cmsVariantGroups: Record; private experiencesUidMapper: Record; private pendingVariantAndVariantGrpForExperience: string[]; - private personalizationConfig: ImportConfig['modules']['personalize']; + private personalizeConfig: ImportConfig['modules']['personalize']; private audienceConfig: ImportConfig['modules']['personalize']['audiences']; private experienceConfig: ImportConfig['modules']['personalize']['experiences']; @@ -43,16 +43,16 @@ export default class Experiences extends PersonalizationAdapter { }, }; super(Object.assign(config, conf)); - this.personalizationConfig = this.config.modules.personalize; + this.personalizeConfig = this.config.modules.personalize; this.experiencesDirPath = resolve( sanitizePath(this.config.data), - sanitizePath(this.personalizationConfig.dirName), - sanitizePath(this.personalizationConfig.experiences.dirName), + sanitizePath(this.personalizeConfig.dirName), + sanitizePath(this.personalizeConfig.experiences.dirName), ); - this.experiencesPath = join(sanitizePath(this.experiencesDirPath), sanitizePath(this.personalizationConfig.experiences.fileName)); - this.experienceConfig = this.personalizationConfig.experiences; - this.audienceConfig = this.personalizationConfig.audiences; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); + this.experiencesPath = join(sanitizePath(this.experiencesDirPath), sanitizePath(this.personalizeConfig.experiences.fileName)); + this.experienceConfig = this.personalizeConfig.experiences; + this.audienceConfig = this.personalizeConfig.audiences; + this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); this.expMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.experienceConfig.dirName)); this.experiencesUidMapperPath = resolve(sanitizePath(this.expMapperDirPath), 'uid-mapping.json'); this.cmsVariantGroupPath = resolve(sanitizePath(this.expMapperDirPath), 'cms-variant-groups.json'); @@ -64,7 +64,7 @@ export default class Experiences extends PersonalizationAdapter { this.experienceCTsPath = resolve(sanitizePath(this.experiencesDirPath), 'experiences-content-types.json'); this.experienceVariantsIdsPath = resolve( sanitizePath(this.config.data), - sanitizePath(this.personalizationConfig.dirName), + sanitizePath(this.personalizeConfig.dirName), sanitizePath(this.experienceConfig.dirName), 'experiences-variants-ids.json', ); @@ -116,7 +116,7 @@ export default class Experiences extends PersonalizationAdapter { if (jobRes) this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Variant & Variant groups' }), 'info'); - if (this.personalizationConfig.importData) { + if (this.personalizeConfig.importData) { this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info'); await this.attachCTsInExperience(); } diff --git a/packages/contentstack-variants/src/import/variant-entries.ts b/packages/contentstack-variants/src/import/variant-entries.ts index 3f81bf1bae..0ff2b6a06b 100644 --- a/packages/contentstack-variants/src/import/variant-entries.ts +++ b/packages/contentstack-variants/src/import/variant-entries.ts @@ -29,7 +29,7 @@ export default class VariantEntries extends VariantAdapter; - public personalizationConfig: ImportConfig['modules']['personalize']; + public personalizeConfig: ImportConfig['modules']['personalize']; public taxonomies!: Record; public assetUrlMapper!: Record; @@ -56,7 +56,7 @@ export default class VariantEntries extends VariantAdapter; } From 557d4bd768e39d192229a9f30dc5fcec10a7ba94 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Mon, 23 Sep 2024 12:13:37 +0530 Subject: [PATCH 08/19] Added support for experience versioning --- .../src/export/experiences.ts | 22 +++- .../src/import/experiences.ts | 109 ++++++++++++++++-- .../src/types/personalization-api-adapter.ts | 13 +++ .../src/utils/audiences-helper.ts | 14 ++- .../src/utils/personalization-api-adapter.ts | 30 +++++ packages/contentstack/README.md | 2 +- 6 files changed, 175 insertions(+), 15 deletions(-) diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index 0b65ef3076..dccda7efa0 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -34,12 +34,13 @@ export default class ExportExperiences extends PersonalizationAdapter = (await this.getExperiences()) || []; if (!experiences || experiences?.length < 1) { log(this.exportConfig, 'No Experiences found with the give project', 'info'); return; } - fsUtil.writeFile(path.resolve(sanitizePath(this.experiencesFolderPath), 'experiences.json'), experiences); + fsUtil.writeFile(path.resolve(this.experiencesFolderPath, 'experiences.json'), experiences); const experienceToVariantsStrList: Array = []; const experienceToContentTypesMap: Record = {}; @@ -51,6 +52,21 @@ export default class ExportExperiences extends PersonalizationAdapter 0) { + fsUtil.writeFile( + path.resolve(this.experiencesFolderPath, 'versions', `${experience.uid}.json`), + experienceVersions, + ); + } else { + log(this.exportConfig, `No versions found for experience ${experience.name}`, 'info'); + } + } catch (error) { + log(this.exportConfig, `Failed to fetch versions of experience ${experience.name}`, 'error'); + } + try { // fetch content of experience const { variant_groups: [variantGroup] = [] } = @@ -63,12 +79,12 @@ export default class ExportExperiences extends PersonalizationAdapter { private createdCTs: string[]; @@ -29,6 +37,8 @@ export default class Experiences extends PersonalizationAdapter { private cmsVariantGroups: Record; private experiencesUidMapper: Record; private pendingVariantAndVariantGrpForExperience: string[]; + private audiencesUid: Record; + private eventsUid: Record; private personalizationConfig: ImportConfig['modules']['personalization']; private audienceConfig: ImportConfig['modules']['personalization']['audiences']; private experienceConfig: ImportConfig['modules']['personalization']['experiences']; @@ -50,15 +60,26 @@ export default class Experiences extends PersonalizationAdapter { sanitizePath(this.personalizationConfig.dirName), sanitizePath(this.personalizationConfig.experiences.dirName), ); - this.experiencesPath = join(sanitizePath(this.experiencesDirPath), sanitizePath(this.personalizationConfig.experiences.fileName)); + this.experiencesPath = join( + sanitizePath(this.experiencesDirPath), + sanitizePath(this.personalizationConfig.experiences.fileName), + ); this.experienceConfig = this.personalizationConfig.experiences; this.audienceConfig = this.personalizationConfig.audiences; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizationConfig.dirName)); + this.mapperDirPath = resolve( + sanitizePath(this.config.backupDir), + 'mapper', + sanitizePath(this.personalizationConfig.dirName), + ); this.expMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.experienceConfig.dirName)); this.experiencesUidMapperPath = resolve(sanitizePath(this.expMapperDirPath), 'uid-mapping.json'); this.cmsVariantGroupPath = resolve(sanitizePath(this.expMapperDirPath), 'cms-variant-groups.json'); this.cmsVariantPath = resolve(sanitizePath(this.expMapperDirPath), 'cms-variants.json'); - this.audiencesMapperPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.audienceConfig.dirName), 'uid-mapping.json'); + this.audiencesMapperPath = resolve( + sanitizePath(this.mapperDirPath), + sanitizePath(this.audienceConfig.dirName), + 'uid-mapping.json', + ); this.eventsMapperPath = resolve(sanitizePath(this.mapperDirPath), 'events', 'uid-mapping.json'); this.failedCmsExpPath = resolve(sanitizePath(this.expMapperDirPath), 'failed-cms-experience.json'); this.failedCmsExpPath = resolve(sanitizePath(this.expMapperDirPath), 'failed-cms-experience.json'); @@ -79,6 +100,8 @@ export default class Experiences extends PersonalizationAdapter { this.pendingVariantAndVariantGrpForExperience = []; this.cTsSuccessPath = resolve(sanitizePath(this.config.backupDir), 'mapper', 'content_types', 'success.json'); this.createdCTs = []; + this.audiencesUid = (fsUtil.readFile(this.audiencesMapperPath, true) as Record) || {}; + this.eventsUid = (fsUtil.readFile(this.eventsMapperPath, true) as Record) || {}; } /** @@ -92,19 +115,25 @@ export default class Experiences extends PersonalizationAdapter { if (existsSync(this.experiencesPath)) { try { const experiences = fsUtil.readFile(this.experiencesPath, true) as ExperienceStruct[]; - const audiencesUid = (fsUtil.readFile(this.audiencesMapperPath, true) as Record) || {}; - const eventsUid = (fsUtil.readFile(this.eventsMapperPath, true) as Record) || {}; for (const experience of experiences) { const { uid, ...restExperienceData } = experience; //check whether reference audience exists or not that referenced in variations having __type equal to AudienceBasedVariation & targeting - let experienceReqObj: CreateExperienceInput = lookUpAudiences(restExperienceData, audiencesUid); + let experienceReqObj: CreateExperienceInput = lookUpAudiences(restExperienceData, this.audiencesUid); //check whether events exists or not that referenced in metrics - experienceReqObj = lookUpEvents(experienceReqObj, eventsUid); + experienceReqObj = lookUpEvents(experienceReqObj, this.eventsUid); - const expRes = await this.createExperience(experienceReqObj); + const expRes = (await this.createExperience(experienceReqObj)) as ExperienceStruct; //map old experience uid to new experience uid this.experiencesUidMapper[uid] = expRes?.uid ?? ''; + + try { + // import versions of experience + await this.importExperienceVersions(expRes, uid); + } catch (error) { + this.log(this.config, `Error while importing experience versions of ${expRes.uid}`, 'error'); + this.log(this.config, error, 'error'); + } } fsUtil.writeFile(this.experiencesUidMapperPath, this.experiencesUidMapper); this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Experiences' }), 'info'); @@ -130,6 +159,68 @@ export default class Experiences extends PersonalizationAdapter { } } + /** + * function import experience versions from a JSON file and creates them in the project. + */ + async importExperienceVersions(experience: ExperienceStruct, oldExperienceUid: string) { + const versionsPath = resolve(sanitizePath(this.experiencesDirPath), 'versions', `${oldExperienceUid}.json`); + + if (!existsSync(versionsPath)) { + return; + } + + const versions = fsUtil.readFile(versionsPath, true) as ExperienceStruct[]; + const versionMap: Record = { + ACTIVE: undefined, + DRAFT: undefined, + PAUSE: undefined, + }; + + // Process each version and map them by status + versions.forEach((version) => { + let versionReqObj = lookUpAudiences(version, this.audiencesUid) as CreateExperienceVersionInput; + versionReqObj = lookUpEvents(version, this.eventsUid) as CreateExperienceVersionInput; + + if (versionReqObj && versionReqObj.status) { + versionMap[versionReqObj.status] = versionReqObj; + } + }); + + // Prioritize updating or creating versions based on the order: ACTIVE -> DRAFT -> PAUSE + return await this.handleVersionUpdateOrCreate(experience, versionMap); + } + + // Helper method to handle version update or creation logic + private async handleVersionUpdateOrCreate( + experience: ExperienceStruct, + versionMap: Record, + ) { + const { ACTIVE, DRAFT, PAUSE } = versionMap; + let latestVersionUsed = false; + + if (ACTIVE) { + await this.updateExperienceVersion(experience.uid, experience.latestVersion, ACTIVE); + latestVersionUsed = true; + } + + if (DRAFT) { + if (latestVersionUsed) { + await this.createExperienceVersion(experience.uid, DRAFT); + } else { + await this.updateExperienceVersion(experience.uid, experience.latestVersion, DRAFT); + latestVersionUsed = true; + } + } + + if (PAUSE) { + if (latestVersionUsed) { + await this.createExperienceVersion(experience.uid, PAUSE); + } else { + await this.updateExperienceVersion(experience.uid, experience.latestVersion, PAUSE); + } + } + } + /** * function to validate if all variant groups and variants have been created using personalization background job * store the variant groups data in mapper/personalization/experiences/cms-variant-groups.json and the variants data diff --git a/packages/contentstack-variants/src/types/personalization-api-adapter.ts b/packages/contentstack-variants/src/types/personalization-api-adapter.ts index 2036511706..baec467586 100644 --- a/packages/contentstack-variants/src/types/personalization-api-adapter.ts +++ b/packages/contentstack-variants/src/types/personalization-api-adapter.ts @@ -130,6 +130,18 @@ export type ExperienceStruct = { content_types?: string[]; } & AnyProperty; +export interface CreateExperienceVersionInput { + name: string; + __type: string; + description: string; + targeting?: ExpTargeting; + variations: ExpVariations[]; + variationSplit?: string; + metrics?: ExpMetric[]; + status: string; + metadata?: object; + variants: Array; +} export interface CreateExperienceInput { name: string; __type: string; @@ -140,6 +152,7 @@ export interface CreateExperienceInput { metrics?: ExpMetric[]; status: string; metadata?: object; + variants?: Array; } export interface UpdateExperienceInput { diff --git a/packages/contentstack-variants/src/utils/audiences-helper.ts b/packages/contentstack-variants/src/utils/audiences-helper.ts index 285025413e..2b6a7d4881 100644 --- a/packages/contentstack-variants/src/utils/audiences-helper.ts +++ b/packages/contentstack-variants/src/utils/audiences-helper.ts @@ -1,4 +1,4 @@ -import { CreateExperienceInput } from '../types'; +import { CreateExperienceInput, CreateExperienceVersionInput } from '../types'; /** * function for substituting an old audience UID with a new one or deleting the audience information if it does not exist @@ -37,10 +37,20 @@ export const lookUpAudiences = ( } } } + } else if (experience.variants) { + for (let index = experience.variants.length - 1; index >= 0; index--) { + const expVariations = experience.variants[index]; + if (expVariations['__type'] === 'AudienceBasedVariation' && expVariations?.audiences?.length) { + updateAudiences(expVariations.audiences, audiencesUid); + if (!expVariations.audiences.length) { + experience.variants.splice(index, 1); + } + } + } } - // Update targeting audiences if (experience?.targeting?.hasOwnProperty('audience') && experience?.targeting?.audience?.audiences?.length) { + // Update targeting audiences updateAudiences(experience.targeting.audience.audiences, audiencesUid); if (!experience.targeting.audience.audiences.length) { experience.targeting = {}; diff --git a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts index 531b22d698..40a24ac73f 100644 --- a/packages/contentstack-variants/src/utils/personalization-api-adapter.ts +++ b/packages/contentstack-variants/src/utils/personalization-api-adapter.ts @@ -22,6 +22,7 @@ import { APIResponse, VariantGroupStruct, VariantGroup, + CreateExperienceVersionInput, } from '../types'; import { formatErrors } from './error-helper'; @@ -77,6 +78,35 @@ export class PersonalizationAdapter extends AdapterHelper impl return this.handleVariantAPIRes(data) as ExperienceStruct; } + async getExperienceVersions(experienceUid: string): Promise { + const getExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`; + const data = await this.apiClient.get(getExperiencesVersionsEndPoint); + return this.handleVariantAPIRes(data) as ExperienceStruct; + } + + async createExperienceVersion( + experienceUid: string, + input: CreateExperienceVersionInput, + ): Promise { + const createExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions`; + const data = await this.apiClient.post(createExperiencesVersionsEndPoint, input); + return this.handleVariantAPIRes(data) as ExperienceStruct; + } + + async updateExperienceVersion( + experienceUid: string, + versionId: string, + input: CreateExperienceVersionInput, + ): Promise { + // loop through input and remove shortId from variant + if (input?.variants) { + input.variants = input.variants.map(({ shortUid, ...rest }) => rest); + } + const updateExperiencesVersionsEndPoint = `/experiences/${experienceUid}/versions/${versionId}`; + const data = await this.apiClient.put(updateExperiencesVersionsEndPoint, input); + return this.handleVariantAPIRes(data) as ExperienceStruct; + } + async getVariantGroup(input: GetVariantGroupInput): Promise { if (this.cmaAPIClient) { const getVariantGroupEndPoint = `/variant_groups`; diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index 18ec0a5b68..ed98442025 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.25.1 darwin-arm64 node-v22.8.0 +@contentstack/cli/1.25.1 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND From f06afc1ae6062f4dbac9b3eed40c620134826ce8 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Mon, 23 Sep 2024 13:05:04 +0530 Subject: [PATCH 09/19] sanitized path --- .../contentstack-variants/src/export/experiences.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/contentstack-variants/src/export/experiences.ts b/packages/contentstack-variants/src/export/experiences.ts index dccda7efa0..fee1d5ef3c 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -34,13 +34,13 @@ export default class ExportExperiences extends PersonalizationAdapter = (await this.getExperiences()) || []; if (!experiences || experiences?.length < 1) { log(this.exportConfig, 'No Experiences found with the give project', 'info'); return; } - fsUtil.writeFile(path.resolve(this.experiencesFolderPath, 'experiences.json'), experiences); + fsUtil.writeFile(path.resolve(sanitizePath(this.experiencesFolderPath), 'experiences.json'), experiences); const experienceToVariantsStrList: Array = []; const experienceToContentTypesMap: Record = {}; @@ -57,7 +57,7 @@ export default class ExportExperiences extends PersonalizationAdapter 0) { fsUtil.writeFile( - path.resolve(this.experiencesFolderPath, 'versions', `${experience.uid}.json`), + path.resolve(sanitizePath(this.experiencesFolderPath), 'versions', `${experience.uid}.json`), experienceVersions, ); } else { @@ -79,12 +79,12 @@ export default class ExportExperiences extends PersonalizationAdapter Date: Mon, 23 Sep 2024 14:57:48 +0530 Subject: [PATCH 10/19] refactor: experience & variant-entries code --- .../src/import/experiences.ts | 7 +-- .../src/import/variant-entries.ts | 49 ++++++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index f2a5036c52..a3a82f6b40 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -147,6 +147,7 @@ export default class Experiences extends PersonalizationAdapter { if (this.personalizeConfig.importData) { this.log(this.config, this.messages.UPDATING_CT_IN_EXP, 'info'); await this.attachCTsInExperience(); + this.log(this.config, this.messages.UPDATED_CT_IN_EXP, 'info'); } await this.createVariantIdMapper(); @@ -220,9 +221,9 @@ export default class Experiences extends PersonalizationAdapter { } /** - * function to validate if all variant groups and variants have been created using personalization background job - * store the variant groups data in mapper/personalization/experiences/cms-variant-groups.json and the variants data - * in mapper/personalization/experiences/cms-variants.json. If not, invoke validateVariantGroupAndVariantsCreated after some delay. + * function to validate if all variant groups and variants have been created using personalize background job + * store the variant groups data in mapper/personalize/experiences/cms-variant-groups.json and the variants data + * in mapper/personalize/experiences/cms-variants.json. If not, invoke validateVariantGroupAndVariantsCreated after some delay. * @param retryCount Counter to track the number of times the function has been called * @returns */ diff --git a/packages/contentstack-variants/src/import/variant-entries.ts b/packages/contentstack-variants/src/import/variant-entries.ts index 0ff2b6a06b..ce53af4661 100644 --- a/packages/contentstack-variants/src/import/variant-entries.ts +++ b/packages/contentstack-variants/src/import/variant-entries.ts @@ -53,11 +53,20 @@ export default class VariantEntries extends VariantAdapter; @@ -141,9 +155,22 @@ export default class VariantEntries extends VariantAdapter Date: Mon, 23 Sep 2024 16:49:31 +0530 Subject: [PATCH 11/19] refactor: error handling in attribute, audiences &events --- .../src/import/attribute.ts | 26 ++++++++++--- .../src/import/audiences.ts | 38 ++++++++++++++----- .../src/import/events.ts | 22 +++++++++-- 3 files changed, 66 insertions(+), 20 deletions(-) diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index b7da7c5d71..f5714632cf 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -21,7 +21,11 @@ export default class Attribute extends PersonalizationAdapter { super(Object.assign(config, conf)); this.personalizeConfig = this.config.modules.personalize; this.attributeConfig = this.personalizeConfig.attributes; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); + this.mapperDirPath = resolve( + sanitizePath(this.config.backupDir), + 'mapper', + sanitizePath(this.personalizeConfig.dirName), + ); this.attrMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName)); this.attributesUidMapperPath = resolve(sanitizePath(this.attrMapperDirPath), 'uid-mapping.json'); this.attributesUidMapper = {}; @@ -35,7 +39,12 @@ export default class Attribute extends PersonalizationAdapter { await fsUtil.makeDirectory(this.attrMapperDirPath); const { dirName, fileName } = this.attributeConfig; - const attributesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const attributesPath = resolve( + sanitizePath(this.config.data), + sanitizePath(this.personalizeConfig.dirName), + sanitizePath(dirName), + sanitizePath(fileName), + ); if (existsSync(attributesPath)) { try { @@ -43,10 +52,15 @@ export default class Attribute extends PersonalizationAdapter { for (const attribute of attributes) { const { key, name, description, uid } = attribute; - const attributeRes = await this.createAttribute({ key, name, description }); - //map old attribute uid to new attribute uid - //mapper file is used to check whether attribute created or not before creating audience - this.attributesUidMapper[uid] = attributeRes?.uid ?? ''; + try { + const attributeRes = await this.createAttribute({ key, name, description }); + //map old attribute uid to new attribute uid + //mapper file is used to check whether attribute created or not before creating audience + this.attributesUidMapper[uid] = attributeRes?.uid ?? ''; + } catch (error) { + this.log(this.config, `Failed to create attribute ${name}!`, 'error'); + this.log(this.config, error, 'error'); + } } fsUtil.writeFile(this.attributesUidMapperPath, this.attributesUidMapper); diff --git a/packages/contentstack-variants/src/import/audiences.ts b/packages/contentstack-variants/src/import/audiences.ts index 9925101699..be414a8c25 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -24,10 +24,18 @@ export default class Audiences extends PersonalizationAdapter { this.personalizeConfig = this.config.modules.personalize; this.audienceConfig = this.personalizeConfig.audiences; this.attributeConfig = this.personalizeConfig.attributes; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); + this.mapperDirPath = resolve( + sanitizePath(this.config.backupDir), + 'mapper', + sanitizePath(this.personalizeConfig.dirName), + ); this.audienceMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.audienceConfig.dirName)); this.audiencesUidMapperPath = resolve(sanitizePath(this.audienceMapperDirPath), 'uid-mapping.json'); - this.attributesMapperPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.attributeConfig.dirName), 'uid-mapping.json'); + this.attributesMapperPath = resolve( + sanitizePath(this.mapperDirPath), + sanitizePath(this.attributeConfig.dirName), + 'uid-mapping.json', + ); this.audiencesUidMapper = {}; } @@ -39,7 +47,12 @@ export default class Audiences extends PersonalizationAdapter { await fsUtil.makeDirectory(this.audienceMapperDirPath); const { dirName, fileName } = this.audienceConfig; - const audiencesPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const audiencesPath = resolve( + sanitizePath(this.config.data), + sanitizePath(this.personalizeConfig.dirName), + sanitizePath(dirName), + sanitizePath(fileName), + ); if (existsSync(audiencesPath)) { try { @@ -48,14 +61,19 @@ export default class Audiences extends PersonalizationAdapter { for (const audience of audiences) { let { name, definition, description, uid } = audience; - //check whether reference attributes exists or not - if (definition.rules?.length) { - definition.rules = lookUpAttributes(definition.rules, attributesUid); + try { + //check whether reference attributes exists or not + if (definition.rules?.length) { + definition.rules = lookUpAttributes(definition.rules, attributesUid); + } + const audienceRes = await this.createAudience({ definition, name, description }); + //map old audience uid to new audience uid + //mapper file is used to check whether audience created or not before creating experience + this.audiencesUidMapper[uid] = audienceRes?.uid ?? ''; + } catch (error) { + this.log(this.config, `Failed to create audience uid: ${uid}, name: ${name}`, 'error'); + this.log(this.config, error, 'error'); } - const audienceRes = await this.createAudience({ definition, name, description }); - //map old audience uid to new audience uid - //mapper file is used to check whether audience created or not before creating experience - this.audiencesUidMapper[uid] = audienceRes?.uid ?? ''; } fsUtil.writeFile(this.audiencesUidMapperPath, this.audiencesUidMapper); diff --git a/packages/contentstack-variants/src/import/events.ts b/packages/contentstack-variants/src/import/events.ts index 954a797278..25d7de178f 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -21,7 +21,11 @@ export default class Events extends PersonalizationAdapter { super(Object.assign(config, conf)); this.personalizeConfig = this.config.modules.personalize; this.eventsConfig = this.personalizeConfig.events; - this.mapperDirPath = resolve(sanitizePath(this.config.backupDir), 'mapper', sanitizePath(this.personalizeConfig.dirName)); + this.mapperDirPath = resolve( + sanitizePath(this.config.backupDir), + 'mapper', + sanitizePath(this.personalizeConfig.dirName), + ); this.eventMapperDirPath = resolve(sanitizePath(this.mapperDirPath), sanitizePath(this.eventsConfig.dirName)); this.eventsUidMapperPath = resolve(sanitizePath(this.eventMapperDirPath), 'uid-mapping.json'); this.eventsUidMapper = {}; @@ -35,7 +39,12 @@ export default class Events extends PersonalizationAdapter { await fsUtil.makeDirectory(this.eventMapperDirPath); const { dirName, fileName } = this.eventsConfig; - const eventsPath = resolve(sanitizePath(this.config.data), sanitizePath(this.personalizeConfig.dirName), sanitizePath(dirName), sanitizePath(fileName)); + const eventsPath = resolve( + sanitizePath(this.config.data), + sanitizePath(this.personalizeConfig.dirName), + sanitizePath(dirName), + sanitizePath(fileName), + ); if (existsSync(eventsPath)) { try { @@ -43,8 +52,13 @@ export default class Events extends PersonalizationAdapter { for (const event of events) { const { key, description, uid } = event; - const eventsResponse = await this.createEvents({ key, description }); - this.eventsUidMapper[uid] = eventsResponse?.uid ?? ''; + try { + const eventsResponse = await this.createEvents({ key, description }); + this.eventsUidMapper[uid] = eventsResponse?.uid ?? ''; + } catch (error) { + this.log(this.config, `failed to create event uid: ${uid}`, 'error'); + this.log(this.config, error, 'error'); + } } fsUtil.writeFile(this.eventsUidMapperPath, this.eventsUidMapper); From 56d2e2a57279a43cb6817f82c6162ac386702304 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Tue, 24 Sep 2024 11:41:59 +0530 Subject: [PATCH 12/19] fixed --- packages/contentstack-export/src/commands/cm/stacks/export.ts | 2 +- packages/contentstack-import/src/commands/cm/stacks/import.ts | 2 +- packages/contentstack-variants/src/import/attribute.ts | 4 ++++ packages/contentstack-variants/src/import/experiences.ts | 4 ++-- packages/contentstack-variants/src/import/variant-entries.ts | 2 +- packages/contentstack-variants/src/utils/audiences-helper.ts | 2 +- .../contentstack-variants/src/utils/variant-api-adapter.ts | 4 ++-- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 622238cb33..56fd80a12e 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -107,7 +107,7 @@ export default class ExportCommand extends Command { exportConfig.host = this.cmaHost; exportConfig.region = this.region; exportConfig.developerHubBaseUrl = this.developerHubUrl; - exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl; + // exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl; exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 992586245c..5147fa4572 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -136,7 +136,7 @@ export default class ImportCommand extends Command { importConfig.host = this.cmaHost; importConfig.region = this.region; importConfig.developerHubBaseUrl = this.developerHubUrl; - importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl; + // importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl; backupDir = importConfig.cliLogsPath || importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); diff --git a/packages/contentstack-variants/src/import/attribute.ts b/packages/contentstack-variants/src/import/attribute.ts index f5714632cf..fd21548232 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -52,6 +52,10 @@ export default class Attribute extends PersonalizationAdapter { for (const attribute of attributes) { const { key, name, description, uid } = attribute; + // skip creating preset attributes, as they are already present in the system + if (attribute.__type === 'PRESET') { + continue; + } try { const attributeRes = await this.createAttribute({ key, name, description }); //map old attribute uid to new attribute uid diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index a3a82f6b40..2021f5179b 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -275,8 +275,8 @@ export default class Experiences extends PersonalizationAdapter { Object.entries(this.experiencesUidMapper).map(async ([oldExpUid, newExpUid]) => { if (experienceCTsMap[oldExpUid]?.length) { // Filter content types that were created - const updatedContentTypes = experienceCTsMap[oldExpUid].filter((ct: any) => - this.createdCTs.includes(ct?.uid), + const updatedContentTypes = experienceCTsMap[oldExpUid].filter( + (ct: any) => this.createdCTs.includes(ct?.uid) && ct.status === 'linked', ); if (updatedContentTypes?.length) { const { variant_groups: [variantGroup] = [] } = diff --git a/packages/contentstack-variants/src/import/variant-entries.ts b/packages/contentstack-variants/src/import/variant-entries.ts index ce53af4661..c4f4c75176 100644 --- a/packages/contentstack-variants/src/import/variant-entries.ts +++ b/packages/contentstack-variants/src/import/variant-entries.ts @@ -463,7 +463,7 @@ export default class VariantEntries extends VariantAdapter= 0; index--) { const expVariations = experience.variants[index]; - if (expVariations['__type'] === 'AudienceBasedVariation' && expVariations?.audiences?.length) { + if (expVariations['__type'] === 'SegmentedVariant' && expVariations?.audiences?.length) { updateAudiences(expVariations.audiences, audiencesUid); if (!expVariations.audiences.length) { experience.variants.splice(index, 1); diff --git a/packages/contentstack-variants/src/utils/variant-api-adapter.ts b/packages/contentstack-variants/src/utils/variant-api-adapter.ts index 89d46c5c7f..9e25299576 100644 --- a/packages/contentstack-variants/src/utils/variant-api-adapter.ts +++ b/packages/contentstack-variants/src/utils/variant-api-adapter.ts @@ -184,6 +184,7 @@ export class VariantHttpClient extends AdapterHelper implement }); try { + this.apiClient.headers({ api_version: undefined }); const res = await this.apiClient.put(endpoint, { entry: input }); const data = this.handleVariantAPIRes(res); @@ -214,8 +215,7 @@ export class VariantHttpClient extends AdapterHelper implement const { entry_uid, content_type_uid } = options; let endpoint = `content_types/${content_type_uid}/entries/${entry_uid}/publish`; - const onSuccess = (response: any) => - resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log }); + const onSuccess = (response: any) => resolve({ response, apiData: { entryUid: entry_uid, variantUid }, log }); const onReject = (error: any) => reject({ error, From 6778c3d482e465f5ad6df38e94190931efbd7459 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 24 Sep 2024 12:35:39 +0530 Subject: [PATCH 13/19] refactor: added personalize url --- .../contentstack-config/src/utils/region-handler.ts | 10 +++++----- .../src/commands/cm/stacks/export.ts | 2 +- .../src/commands/cm/stacks/import.ts | 2 +- packages/contentstack-import/src/config/index.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/contentstack-config/src/utils/region-handler.ts b/packages/contentstack-config/src/utils/region-handler.ts index c0fae7d353..4b63978112 100644 --- a/packages/contentstack-config/src/utils/region-handler.ts +++ b/packages/contentstack-config/src/utils/region-handler.ts @@ -24,7 +24,7 @@ const regions = { name: 'NA', 'developerHubUrl': 'https://developerhub-api.contentstack.com', 'launchHubUrl': 'https://launch-api.contentstack.com', - 'personalizeUrl': 'https://personalization-api.contentstack.com', + 'personalizeUrl': 'https://personalize-api.contentstack.com', }, EU: { cma: 'https://eu-api.contentstack.com', @@ -33,7 +33,7 @@ const regions = { name: 'EU', 'developerHubUrl': 'https://eu-developerhub-api.contentstack.com', 'launchHubUrl': 'https://eu-launch-api.contentstack.com', - 'personalizeUrl': 'Not available', + 'personalizeUrl': 'https://eu-personalize-api.contentstack.com', }, 'AZURE-NA': { cma: 'https://azure-na-api.contentstack.com', @@ -42,7 +42,7 @@ const regions = { name: 'AZURE-NA', 'developerHubUrl': 'https://azure-na-developerhub-api.contentstack.com', 'launchHubUrl': 'https://azure-na-launch-api.contentstack.com', - 'personalizeUrl': 'Not available', + 'personalizeUrl': 'https://azure-na-personalize-api.contentstack.com', }, 'AZURE-EU': { cma: 'https://azure-eu-api.contentstack.com', @@ -51,7 +51,7 @@ const regions = { name: 'AZURE-EU', 'developerHubUrl': 'https://azure-eu-developerhub-api.contentstack.com', 'launchHubUrl': 'https://azure-eu-launch-api.contentstack.com', - 'personalizeUrl': 'Not available', + 'personalizeUrl': 'https://azure-eu-personalize-api.contentstack.com', }, 'GCP-NA': { cma: 'https://gcp-na-api.contentstack.com', @@ -60,7 +60,7 @@ const regions = { name: 'GCP-NA', 'developerHubUrl': 'https://gcp-na-developerhub-api.contentstack.com', 'launchHubUrl': 'Not available', - 'personalizeUrl': 'Not available', + 'personalizeUrl': 'https://gcp-na-personalize-api.contentstack.com', }, }; diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 56fd80a12e..79568c00bf 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -107,7 +107,7 @@ export default class ExportCommand extends Command { exportConfig.host = this.cmaHost; exportConfig.region = this.region; exportConfig.developerHubBaseUrl = this.developerHubUrl; - // exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl; + if (this.personalizeUrl) exportConfig.modules.personalize.baseURL[exportConfig.region.name] = this.personalizeUrl; exportDir = exportConfig.cliLogsPath || exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 5147fa4572..19b20877f8 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -136,7 +136,7 @@ export default class ImportCommand extends Command { importConfig.host = this.cmaHost; importConfig.region = this.region; importConfig.developerHubBaseUrl = this.developerHubUrl; - // importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl; + if (this.personalizeUrl) importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl; backupDir = importConfig.cliLogsPath || importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); diff --git a/packages/contentstack-import/src/config/index.ts b/packages/contentstack-import/src/config/index.ts index 1e81b84428..10082f2d39 100644 --- a/packages/contentstack-import/src/config/index.ts +++ b/packages/contentstack-import/src/config/index.ts @@ -153,7 +153,7 @@ const config: DefaultConfig = { }, personalize: { baseURL: { - NA: 'https://personalization-api.contentstack.com', + NA: 'https://personalize-api.contentstack.com', }, importData: true, dirName: 'personalize', From 33ef991d5ce9b49d48f7ccfc0dc5761b789f7374 Mon Sep 17 00:00:00 2001 From: shafeeqd959 Date: Tue, 24 Sep 2024 12:48:16 +0530 Subject: [PATCH 14/19] version bumped --- packages/contentstack-bootstrap/package.json | 4 ++-- packages/contentstack-clone/package.json | 6 +++--- packages/contentstack-export/package.json | 4 ++-- packages/contentstack-import/package.json | 4 ++-- packages/contentstack-seed/package.json | 4 ++-- packages/contentstack-variants/package.json | 2 +- packages/contentstack/package.json | 12 ++++++------ 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/contentstack-bootstrap/package.json b/packages/contentstack-bootstrap/package.json index 3f4c973c34..5afeb6b48a 100644 --- a/packages/contentstack-bootstrap/package.json +++ b/packages/contentstack-bootstrap/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-bootstrap", "description": "Bootstrap contentstack apps", - "version": "1.11.0", + "version": "1.12.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "scripts": { @@ -17,7 +17,7 @@ "test:report": "nyc --reporter=lcov mocha \"test/**/*.test.js\"" }, "dependencies": { - "@contentstack/cli-cm-seed": "~1.8.0", + "@contentstack/cli-cm-seed": "~1.9.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "inquirer": "8.2.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 3e0c1b30ab..d8d5e7823e 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,13 +1,13 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.11.1", + "version": "1.12.0", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.12.0", - "@contentstack/cli-cm-import": "~1.17.0", + "@contentstack/cli-cm-export": "~1.13.0", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "async": "^3.2.4", diff --git a/packages/contentstack-export/package.json b/packages/contentstack-export/package.json index 7a604f498b..1e76451286 100644 --- a/packages/contentstack-export/package.json +++ b/packages/contentstack-export/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-export", "description": "Contentstack CLI plugin to export content from stack", - "version": "1.12.1", + "version": "1.13.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { "@contentstack/cli-command": "~1.3.0", - "@contentstack/cli-variants": "~0.0.1-alpha", + "@contentstack/cli-variants": "~1.0.0", "@contentstack/cli-utilities": "~1.7.2", "@oclif/core": "^3.26.5", "async": "^3.2.4", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 97447361a4..f1ec8916f9 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.17.1", + "version": "1.18.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { @@ -9,7 +9,7 @@ "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "@contentstack/management": "~1.17.0", - "@contentstack/cli-variants": "0.0.1-alpha", + "@contentstack/cli-variants": "~1.0.0", "@oclif/core": "^3.26.5", "big-json": "^3.2.0", "bluebird": "^3.7.2", diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 87f90193b7..e15ecdf73a 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -1,11 +1,11 @@ { "name": "@contentstack/cli-cm-seed", "description": "create a Stack from existing content types, entries, assets, etc.", - "version": "1.8.0", + "version": "1.9.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.17.0", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "inquirer": "8.2.4", diff --git a/packages/contentstack-variants/package.json b/packages/contentstack-variants/package.json index 39f22e2b17..5a723f8085 100644 --- a/packages/contentstack-variants/package.json +++ b/packages/contentstack-variants/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-variants", - "version": "0.0.1-alpha", + "version": "1.0.0", "description": "Variants plugin", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 650c0c1053..07583ae265 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli", "description": "Command-line tool (CLI) to interact with Contentstack", - "version": "1.25.1", + "version": "1.26.0", "author": "Contentstack", "bin": { "csdx": "./bin/run.js" @@ -24,15 +24,15 @@ "dependencies": { "@contentstack/cli-audit": "~1.7.1", "@contentstack/cli-auth": "~1.3.21", - "@contentstack/cli-cm-bootstrap": "~1.11.0", + "@contentstack/cli-cm-bootstrap": "~1.12.0", "@contentstack/cli-cm-branches": "~1.1.3", "@contentstack/cli-cm-bulk-publish": "~1.4.8", - "@contentstack/cli-cm-export": "~1.12.1", - "@contentstack/cli-cm-clone": "~1.11.1", + "@contentstack/cli-cm-export": "~1.13.0", + "@contentstack/cli-cm-clone": "~1.12.0", "@contentstack/cli-cm-export-to-csv": "~1.7.2", - "@contentstack/cli-cm-import": "~1.17.1", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-cm-migrate-rte": "~1.4.19", - "@contentstack/cli-cm-seed": "~1.8.0", + "@contentstack/cli-cm-seed": "~1.9.0", "@contentstack/cli-command": "~1.3.1", "@contentstack/cli-config": "~1.7.1", "@contentstack/cli-launch": "~1.2.2", From c9c4fff5c86ab6e551b57d7857cb60522f8560c3 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 24 Sep 2024 16:25:21 +0530 Subject: [PATCH 15/19] refactor: error formatting --- .../contentstack-variants/src/utils/error-helper.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/contentstack-variants/src/utils/error-helper.ts b/packages/contentstack-variants/src/utils/error-helper.ts index 58c087fbbc..746b8b0d3d 100644 --- a/packages/contentstack-variants/src/utils/error-helper.ts +++ b/packages/contentstack-variants/src/utils/error-helper.ts @@ -9,18 +9,18 @@ export function formatErrors(errors: any): string { for (const errorKey in errors) { const errorValue = errors[errorKey]; if (Array.isArray(errorValue)) { - errorMessages.push(...errorValue.map((error: any) => formatError(error))); + errorMessages.push(...errorValue.map((error: any) => formatError(errorKey, error))); } else { - errorMessages.push(formatError(errorValue)); + errorMessages.push(formatError(errorKey, errorValue)); } } return errorMessages.join(' '); } -function formatError(error: any): string { +function formatError(errorKey: string, error: any): string { if (typeof error === 'object') { - return Object.values(error).join(' '); + return `${errorKey}: ${Object.values(error).join(' ')}`; } - return error; + return `${errorKey}: ${error}`; } From 0b8e5ea21d60dd11611680716a15f7695567b4db Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Tue, 24 Sep 2024 17:55:30 +0530 Subject: [PATCH 16/19] fix: handle forbidden error --- .../contentstack-export/src/export/modules/personalize.ts | 6 +++++- packages/contentstack-variants/src/export/projects.ts | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-export/src/export/modules/personalize.ts b/packages/contentstack-export/src/export/modules/personalize.ts index 1e3bc2856a..45cff20807 100644 --- a/packages/contentstack-export/src/export/modules/personalize.ts +++ b/packages/contentstack-export/src/export/modules/personalize.ts @@ -51,8 +51,12 @@ export default class ExportPersonalize { } } } catch (error) { + if (error === 'Forbidden') { + log(this.exportConfig, "Personalize is not enabled in the given organization!", 'info'); + } else { + log(this.exportConfig, error, 'error'); + } this.exportConfig.personalizationEnabled = false; - log(this.exportConfig, error, 'error'); } } } diff --git a/packages/contentstack-variants/src/export/projects.ts b/packages/contentstack-variants/src/export/projects.ts index f5114dfc82..4404c51738 100644 --- a/packages/contentstack-variants/src/export/projects.ts +++ b/packages/contentstack-variants/src/export/projects.ts @@ -29,7 +29,7 @@ export default class ExportProjects extends PersonalizationAdapter await fsUtil.makeDirectory(this.projectFolderPath); const project = await this.projects({ connectedStackApiKey: this.exportConfig.apiKey }); if (!project || project?.length < 1) { - log(this.exportConfig, 'No Personalization Project connected with the given stack', 'info'); + log(this.exportConfig, 'No Personalize Project connected with the given stack', 'info'); this.exportConfig.personalizationEnabled = false; return; } @@ -38,7 +38,9 @@ export default class ExportProjects extends PersonalizationAdapter fsUtil.writeFile(path.resolve(sanitizePath(this.projectFolderPath), 'projects.json'), project); log(this.exportConfig, 'Project exported successfully!', 'success'); } catch (error) { - log(this.exportConfig, `Failed to export projects!`, 'error'); + if (error !== 'Forbidden') { + log(this.exportConfig, `Failed to export projects!`, 'error'); + } throw error; } } From eae602d69d826268bb41d6b05574a7441392b7a0 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 25 Sep 2024 10:29:06 +0530 Subject: [PATCH 17/19] update lock & yaml file --- package-lock.json | 36 +++++++++++------------ packages/contentstack-audit/README.md | 14 ++++----- packages/contentstack-bootstrap/README.md | 2 +- packages/contentstack-clone/README.md | 2 +- packages/contentstack-export/README.md | 2 +- packages/contentstack-import/README.md | 2 +- packages/contentstack/README.md | 16 +++++----- pnpm-lock.yaml | 22 +++++++------- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/package-lock.json b/package-lock.json index f0b761ee33..34af07d919 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26300,20 +26300,20 @@ }, "packages/contentstack": { "name": "@contentstack/cli", - "version": "1.25.1", + "version": "1.26.0", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.7.1", "@contentstack/cli-auth": "~1.3.21", - "@contentstack/cli-cm-bootstrap": "~1.11.0", + "@contentstack/cli-cm-bootstrap": "~1.12.0", "@contentstack/cli-cm-branches": "~1.1.3", "@contentstack/cli-cm-bulk-publish": "~1.4.8", - "@contentstack/cli-cm-clone": "~1.11.1", - "@contentstack/cli-cm-export": "~1.12.1", + "@contentstack/cli-cm-clone": "~1.12.0", + "@contentstack/cli-cm-export": "~1.13.0", "@contentstack/cli-cm-export-to-csv": "~1.7.2", - "@contentstack/cli-cm-import": "~1.17.1", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-cm-migrate-rte": "~1.4.19", - "@contentstack/cli-cm-seed": "~1.8.0", + "@contentstack/cli-cm-seed": "~1.9.0", "@contentstack/cli-command": "~1.3.1", "@contentstack/cli-config": "~1.7.1", "@contentstack/cli-launch": "~1.2.2", @@ -26670,10 +26670,10 @@ }, "packages/contentstack-bootstrap": { "name": "@contentstack/cli-cm-bootstrap", - "version": "1.11.0", + "version": "1.12.0", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-seed": "~1.8.0", + "@contentstack/cli-cm-seed": "~1.9.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "inquirer": "8.2.4", @@ -26839,12 +26839,12 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.11.1", + "version": "1.12.0", "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", - "@contentstack/cli-cm-export": "~1.12.0", - "@contentstack/cli-cm-import": "~1.17.0", + "@contentstack/cli-cm-export": "~1.13.0", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "async": "^3.2.4", @@ -27432,12 +27432,12 @@ }, "packages/contentstack-export": { "name": "@contentstack/cli-cm-export", - "version": "1.12.1", + "version": "1.13.0", "license": "MIT", "dependencies": { "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", - "@contentstack/cli-variants": "~0.0.1-alpha", + "@contentstack/cli-variants": "~1.0.0", "@oclif/core": "^3.26.5", "async": "^3.2.4", "big-json": "^3.2.0", @@ -28012,13 +28012,13 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.17.1", + "version": "1.18.0", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "~1.7.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", - "@contentstack/cli-variants": "0.0.1-alpha", + "@contentstack/cli-variants": "~1.0.0", "@contentstack/management": "~1.17.0", "@oclif/core": "^3.26.5", "big-json": "^3.2.0", @@ -28456,10 +28456,10 @@ }, "packages/contentstack-seed": { "name": "@contentstack/cli-cm-seed", - "version": "1.8.0", + "version": "1.9.0", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.17.0", + "@contentstack/cli-cm-import": "~1.18.0", "@contentstack/cli-command": "~1.3.0", "@contentstack/cli-utilities": "~1.7.2", "inquirer": "8.2.4", @@ -28626,7 +28626,7 @@ }, "packages/contentstack-variants": { "name": "@contentstack/cli-variants", - "version": "0.0.1-alpha", + "version": "1.0.0", "license": "MIT", "dependencies": { "@contentstack/cli-utilities": "^1.5.12", diff --git a/packages/contentstack-audit/README.md b/packages/contentstack-audit/README.md index f6df6f8124..e08014afd3 100644 --- a/packages/contentstack-audit/README.md +++ b/packages/contentstack-audit/README.md @@ -269,7 +269,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -343,7 +343,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -392,7 +392,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -422,7 +422,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -463,7 +463,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -491,7 +491,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -535,5 +535,5 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/update.ts)_ diff --git a/packages/contentstack-bootstrap/README.md b/packages/contentstack-bootstrap/README.md index 4fcc88c103..1b75d997d7 100644 --- a/packages/contentstack-bootstrap/README.md +++ b/packages/contentstack-bootstrap/README.md @@ -15,7 +15,7 @@ $ npm install -g @contentstack/cli-cm-bootstrap $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-bootstrap/1.11.0 darwin-arm64 node-v22.2.0 +@contentstack/cli-cm-bootstrap/1.12.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-clone/README.md b/packages/contentstack-clone/README.md index 2f281f3a14..63e5b864cc 100644 --- a/packages/contentstack-clone/README.md +++ b/packages/contentstack-clone/README.md @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-clone/1.11.1 darwin-arm64 node-v22.2.0 +@contentstack/cli-cm-clone/1.12.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-export/README.md b/packages/contentstack-export/README.md index d43abd7847..977f6c8cce 100755 --- a/packages/contentstack-export/README.md +++ b/packages/contentstack-export/README.md @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-export/1.12.1 darwin-arm64 node-v22.2.0 +@contentstack/cli-cm-export/1.13.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index 4a928d0210..7f298bfa34 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.17.1 darwin-arm64 node-v22.2.0 +@contentstack/cli-cm-import/1.18.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND diff --git a/packages/contentstack/README.md b/packages/contentstack/README.md index ed98442025..1fcebd327f 100644 --- a/packages/contentstack/README.md +++ b/packages/contentstack/README.md @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli $ csdx COMMAND running command... $ csdx (--version|-v) -@contentstack/cli/1.25.1 darwin-arm64 node-v22.2.0 +@contentstack/cli/1.26.0 darwin-arm64 node-v22.2.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND @@ -3525,7 +3525,7 @@ EXAMPLES $ csdx plugins ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/index.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/index.ts)_ ## `csdx plugins:add PLUGIN` @@ -3599,7 +3599,7 @@ EXAMPLES $ csdx plugins:inspect myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/inspect.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/inspect.ts)_ ## `csdx plugins:install PLUGIN` @@ -3648,7 +3648,7 @@ EXAMPLES $ csdx plugins:install someuser/someplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/install.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/install.ts)_ ## `csdx plugins:link PATH` @@ -3678,7 +3678,7 @@ EXAMPLES $ csdx plugins:link myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/link.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/link.ts)_ ## `csdx plugins:remove [PLUGIN]` @@ -3719,7 +3719,7 @@ FLAGS --reinstall Reinstall all plugins after uninstalling. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/reset.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/reset.ts)_ ## `csdx plugins:uninstall [PLUGIN]` @@ -3747,7 +3747,7 @@ EXAMPLES $ csdx plugins:uninstall myplugin ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/uninstall.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/uninstall.ts)_ ## `csdx plugins:unlink [PLUGIN]` @@ -3791,7 +3791,7 @@ DESCRIPTION Update installed plugins. ``` -_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.8/src/commands/plugins/update.ts)_ +_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/v5.4.9/src/commands/plugins/update.ts)_ ## `csdx tokens` diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 80fd9740c2..798c165aae 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,15 +12,15 @@ importers: specifiers: '@contentstack/cli-audit': ~1.7.1 '@contentstack/cli-auth': ~1.3.21 - '@contentstack/cli-cm-bootstrap': ~1.11.0 + '@contentstack/cli-cm-bootstrap': ~1.12.0 '@contentstack/cli-cm-branches': ~1.1.3 '@contentstack/cli-cm-bulk-publish': ~1.4.8 - '@contentstack/cli-cm-clone': ~1.11.1 - '@contentstack/cli-cm-export': ~1.12.1 + '@contentstack/cli-cm-clone': ~1.12.0 + '@contentstack/cli-cm-export': ~1.13.0 '@contentstack/cli-cm-export-to-csv': ~1.7.2 - '@contentstack/cli-cm-import': ~1.17.1 + '@contentstack/cli-cm-import': ~1.18.0 '@contentstack/cli-cm-migrate-rte': ~1.4.19 - '@contentstack/cli-cm-seed': ~1.8.0 + '@contentstack/cli-cm-seed': ~1.9.0 '@contentstack/cli-command': ~1.3.1 '@contentstack/cli-config': ~1.7.1 '@contentstack/cli-launch': ~1.2.2 @@ -249,7 +249,7 @@ importers: packages/contentstack-bootstrap: specifiers: - '@contentstack/cli-cm-seed': ~1.8.0 + '@contentstack/cli-cm-seed': ~1.9.0 '@contentstack/cli-command': ~1.3.0 '@contentstack/cli-utilities': ~1.7.2 '@oclif/test': ^2.5.6 @@ -423,8 +423,8 @@ importers: packages/contentstack-clone: specifiers: '@colors/colors': ^1.5.0 - '@contentstack/cli-cm-export': ~1.12.0 - '@contentstack/cli-cm-import': ~1.17.0 + '@contentstack/cli-cm-export': ~1.13.0 + '@contentstack/cli-cm-import': ~1.18.0 '@contentstack/cli-command': ~1.3.0 '@contentstack/cli-utilities': ~1.7.2 '@oclif/test': ^2.5.6 @@ -611,7 +611,7 @@ importers: '@contentstack/cli-config': ~1.7.0 '@contentstack/cli-dev-dependencies': ~1.2.4 '@contentstack/cli-utilities': ~1.7.2 - '@contentstack/cli-variants': ~0.0.1-alpha + '@contentstack/cli-variants': ~1.0.0 '@oclif/core': ^3.26.5 '@oclif/plugin-help': ^5.1.19 '@oclif/test': ^2.5.6 @@ -735,7 +735,7 @@ importers: '@contentstack/cli-audit': ~1.7.0 '@contentstack/cli-command': ~1.3.0 '@contentstack/cli-utilities': ~1.7.2 - '@contentstack/cli-variants': 0.0.1-alpha + '@contentstack/cli-variants': ~1.0.0 '@contentstack/management': ~1.17.0 '@oclif/core': ^3.26.5 '@oclif/test': ^2.5.6 @@ -994,7 +994,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.17.0 + '@contentstack/cli-cm-import': ~1.18.0 '@contentstack/cli-command': ~1.3.0 '@contentstack/cli-utilities': ~1.7.2 '@oclif/plugin-help': ^5.1.19 From ad3f969577eecf621148ec7f4bb260a1306b2e27 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 25 Sep 2024 16:18:27 +0530 Subject: [PATCH 18/19] fix: snyk issues --- packages/contentstack-variants/src/import/experiences.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-variants/src/import/experiences.ts b/packages/contentstack-variants/src/import/experiences.ts index 2021f5179b..763c0f929d 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -162,7 +162,7 @@ export default class Experiences extends PersonalizationAdapter { * function import experience versions from a JSON file and creates them in the project. */ async importExperienceVersions(experience: ExperienceStruct, oldExperienceUid: string) { - const versionsPath = resolve(sanitizePath(this.experiencesDirPath), 'versions', `${oldExperienceUid}.json`); + const versionsPath = resolve(sanitizePath(this.experiencesDirPath), 'versions', `${sanitizePath(oldExperienceUid)}.json`); if (!existsSync(versionsPath)) { return; From 8a76cbe248cab1219f858f8f6799009686f6bbbe Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Wed, 25 Sep 2024 18:24:15 +0530 Subject: [PATCH 19/19] fix: duplicate project error issue --- .../contentstack-variants/src/utils/error-helper.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/contentstack-variants/src/utils/error-helper.ts b/packages/contentstack-variants/src/utils/error-helper.ts index 746b8b0d3d..58c087fbbc 100644 --- a/packages/contentstack-variants/src/utils/error-helper.ts +++ b/packages/contentstack-variants/src/utils/error-helper.ts @@ -9,18 +9,18 @@ export function formatErrors(errors: any): string { for (const errorKey in errors) { const errorValue = errors[errorKey]; if (Array.isArray(errorValue)) { - errorMessages.push(...errorValue.map((error: any) => formatError(errorKey, error))); + errorMessages.push(...errorValue.map((error: any) => formatError(error))); } else { - errorMessages.push(formatError(errorKey, errorValue)); + errorMessages.push(formatError(errorValue)); } } return errorMessages.join(' '); } -function formatError(errorKey: string, error: any): string { +function formatError(error: any): string { if (typeof error === 'object') { - return `${errorKey}: ${Object.values(error).join(' ')}`; + return Object.values(error).join(' '); } - return `${errorKey}: ${error}`; + return error; }