diff --git a/packages/contentstack-export/src/commands/cm/stacks/export.ts b/packages/contentstack-export/src/commands/cm/stacks/export.ts index 4e90b7e2ca..b370f0eec2 100644 --- a/packages/contentstack-export/src/commands/cm/stacks/export.ts +++ b/packages/contentstack-export/src/commands/cm/stacks/export.ts @@ -8,7 +8,7 @@ import { flags, ContentstackClient, FlagInput, - pathValidator + pathValidator, } from '@contentstack/cli-utilities'; import { ModuleExporter } from '../../../export'; import { setupExportConfig, log, formatError, writeExportMetaFile } from '../../../utils'; @@ -105,6 +105,7 @@ export default class ExportCommand extends Command { let exportConfig = await setupExportConfig(flags); // Note setting host to create cma client exportConfig.host = this.cmaHost; + exportConfig.region = this.region; exportDir = exportConfig.data || exportConfig.exportDir; const managementAPIClient: ContentstackClient = await managementSDKClient(exportConfig); const moduleExporter = new ModuleExporter(managementAPIClient, exportConfig); @@ -113,7 +114,11 @@ export default class ExportCommand extends Command { writeExportMetaFile(exportConfig); } log(exportConfig, `The content of the stack ${exportConfig.apiKey} has been exported successfully!`, 'success'); - log(exportConfig, `The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`, 'success'); + log( + exportConfig, + `The log has been stored at '${pathValidator(path.join(exportDir, 'logs', 'export'))}'`, + 'success', + ); } catch (error) { log({ data: exportDir } as ExportConfig, `Failed to export stack content - ${formatError(error)}`, 'error'); log({ data: exportDir } as ExportConfig, `The log has been stored at ${exportDir}`, 'info'); diff --git a/packages/contentstack-export/src/config/index.ts b/packages/contentstack-export/src/config/index.ts index 1b7e9fcc14..c941dd061c 100644 --- a/packages/contentstack-export/src/config/index.ts +++ b/packages/contentstack-export/src/config/index.ts @@ -145,7 +145,9 @@ const config: DefaultConfig = { exportVersions: false, }, personalization: { - baseURL: 'https://personalization-api.contentstack.com', + baseURL: { + NA: 'https://personalization-api.contentstack.com', + }, dirName: 'personalization', exportOrder: ['attributes', 'audiences', 'events', 'experiences'], projects: { @@ -471,7 +473,7 @@ const config: DefaultConfig = { stacks: '/stacks/', }, preserveStackVersion: false, - personalizationEnabled: false, + personalizationEnabled: true, fetchConcurrency: 5, writeConcurrency: 5, developerHubBaseUrl: '', diff --git a/packages/contentstack-export/src/types/default-config.ts b/packages/contentstack-export/src/types/default-config.ts index c9f1e1e70d..4b4d1b52b6 100644 --- a/packages/contentstack-export/src/types/default-config.ts +++ b/packages/contentstack-export/src/types/default-config.ts @@ -123,8 +123,8 @@ export default interface DefaultConfig { exportVersions: boolean; }; personalization: { - dirName: string, - baseURL: string, + dirName: string; + baseURL: Record; } & AnyProperty; variantEntry: { dirName: string; diff --git a/packages/contentstack-export/src/types/export-config.ts b/packages/contentstack-export/src/types/export-config.ts index c34b919ec4..123421ebf2 100644 --- a/packages/contentstack-export/src/types/export-config.ts +++ b/packages/contentstack-export/src/types/export-config.ts @@ -1,4 +1,4 @@ -import { Modules } from '.'; +import { Modules, Region } from '.'; import DefaultConfig from './default-config'; export default interface ExportConfig extends DefaultConfig { @@ -22,12 +22,13 @@ export default interface ExportConfig extends DefaultConfig { access_token?: string; authtoken?: string; 'X-User-Agent': string; - organization_uid?: string + organization_uid?: string; }; access_token?: string; org_uid?: string; source_stack?: string; - sourceStackName?:string; + sourceStackName?: string; + region: Region; } type branch = { diff --git a/packages/contentstack-export/src/types/index.ts b/packages/contentstack-export/src/types/index.ts index 7549353ff5..0616dbe545 100644 --- a/packages/contentstack-export/src/types/index.ts +++ b/packages/contentstack-export/src/types/index.ts @@ -27,6 +27,13 @@ export interface User { authtoken: string; } +export interface Region { + name: string; + cma: string; + cda: string; + uiHost: string; +} + export type Modules = | 'stack' | 'assets' diff --git a/packages/contentstack-export/src/utils/export-config-handler.ts b/packages/contentstack-export/src/utils/export-config-handler.ts index 876adf7473..27f16b7e54 100644 --- a/packages/contentstack-export/src/utils/export-config-handler.ts +++ b/packages/contentstack-export/src/utils/export-config-handler.ts @@ -19,12 +19,9 @@ const setupConfig = async (exportCmdFlags: any): Promise => { const pattern = /[*$%#<>{}!&?]/g; if (pattern.test(config.exportDir)) { - cliux.print( - `\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, - { - color: 'yellow', - }, - ); + cliux.print(`\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, { + color: 'yellow', + }); config.exportDir = await askExportDir(); } config.exportDir = config.exportDir.replace(/['"]/g, ''); @@ -84,7 +81,6 @@ const setupConfig = async (exportCmdFlags: any): Promise => { if (Array.isArray(config.filteredModules) && config.filteredModules.length > 0) { config.modules.types = filter(defaultConfig.modules.types, (module) => includes(config.filteredModules, module)); } - return config; }; diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 5b7bf38e18..abfb3ae45d 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -7,7 +7,7 @@ import { flags, FlagInput, ContentstackClient, - pathValidator + pathValidator, } from '@contentstack/cli-utilities'; import { ImportConfig } from '../../../types'; @@ -126,6 +126,7 @@ export default class ImportCommand extends Command { let importConfig = await setupImportConfig(flags); // Note setting host to create cma client importConfig.host = this.cmaHost; + importConfig.region = this.region; backupDir = importConfig.backupDir; const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); @@ -156,7 +157,9 @@ export default class ImportCommand extends Command { log( { data: backupDir } as ImportConfig, `The log has been stored at ${ - { data: backupDir } ? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) : pathValidator(path.join(__dirname, 'logs')) + { data: backupDir } + ? pathValidator(path.join(backupDir || __dirname, 'logs', 'import')) + : pathValidator(path.join(__dirname, 'logs')) }`, 'info', ); diff --git a/packages/contentstack-import/src/config/index.ts b/packages/contentstack-import/src/config/index.ts index c3145358ee..6169d52067 100644 --- a/packages/contentstack-import/src/config/index.ts +++ b/packages/contentstack-import/src/config/index.ts @@ -15,7 +15,6 @@ const config: DefaultConfig = { // locales: ['fr-fr'], host: 'https://api.contentstack.io/v3', extensionHost: 'https://app.contentstack.com', - personalizationHost: 'https://personalization-api.contentstack.com', developerHubUrls: { 'https://api.contentstack.io': 'https://developerhub-api.contentstack.com', 'https://eu-api.contentstack.com': 'https://eu-developerhub-api.contentstack.com', @@ -28,7 +27,6 @@ const config: DefaultConfig = { types: [ 'locales', 'environments', - 'assets', 'taxonomies', 'extensions', 'marketplace-apps', @@ -38,9 +36,9 @@ const config: DefaultConfig = { 'custom-roles', 'workflows', 'entries', + 'variant-entries', 'labels', 'webhooks', - 'variant-entries', ], locales: { dirName: 'locales', @@ -153,6 +151,9 @@ const config: DefaultConfig = { fileName: 'taxonomies.json', }, personalization: { + baseURL: { + NA: 'https://personalization-api.contentstack.com', + }, importData: true, dirName: 'personalization', importOrder: ['projects', 'attributes', 'audiences', 'events', 'experiences'], diff --git a/packages/contentstack-import/src/types/default-config.ts b/packages/contentstack-import/src/types/default-config.ts index 3805639f98..69fe3d38fd 100644 --- a/packages/contentstack-import/src/types/default-config.ts +++ b/packages/contentstack-import/src/types/default-config.ts @@ -8,7 +8,6 @@ export default interface DefaultConfig { versioning: boolean; host: string; extensionHost: string; - personalizationHost: string; developerHubUrls: Record; modules: { apiConcurrency: number; @@ -124,6 +123,7 @@ export default interface DefaultConfig { dependencies?: Modules[]; }; personalization: { + baseURL: Record; dirName: string; importData: boolean; importOrder: string[]; diff --git a/packages/contentstack-import/src/types/import-config.ts b/packages/contentstack-import/src/types/import-config.ts index 667a53b53f..0de52bf673 100644 --- a/packages/contentstack-import/src/types/import-config.ts +++ b/packages/contentstack-import/src/types/import-config.ts @@ -1,4 +1,4 @@ -import { Modules } from '.'; +import { Modules, Region } from '.'; import DefaultConfig from './default-config'; export interface ExternalConfig { @@ -49,6 +49,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig { skipExisting?: boolean; skipAudit?: boolean; stackName?: string; + region: Region; } type branch = { diff --git a/packages/contentstack-import/src/types/index.ts b/packages/contentstack-import/src/types/index.ts index 8924268629..e0a82835f7 100644 --- a/packages/contentstack-import/src/types/index.ts +++ b/packages/contentstack-import/src/types/index.ts @@ -14,6 +14,13 @@ export interface PrintOptions { color?: string; } +export interface Region { + name: string; + cma: string; + cda: string; + uiHost: string; +} + export interface InquirePayload { type: string; name: string; @@ -92,7 +99,7 @@ export interface CustomRoleConfig { customRolesLocalesFileName: string; } -export interface TaxonomiesConfig{ +export interface TaxonomiesConfig { dirName: string; fileName: string; dependencies?: Modules[]; @@ -101,11 +108,11 @@ export interface TaxonomiesConfig{ export { default as DefaultConfig } from './default-config'; export { default as ImportConfig } from './import-config'; -export * from './entries' -export * from './marketplace-app' +export * from './entries'; +export * from './marketplace-app'; -export type ExtensionType = { - uid: string, - scope: Record, - title: string -} \ No newline at end of file +export type ExtensionType = { + uid: string; + scope: Record; + title: string; +}; diff --git a/packages/contentstack-variants/src/export/attributes.ts b/packages/contentstack-variants/src/export/attributes.ts index 1f2a875398..7fc32cb0d4 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 { constructor(readonly exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL, + 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 ab7861b3fa..8b35cfbe9a 100644 --- a/packages/contentstack-variants/src/export/experiences.ts +++ b/packages/contentstack-variants/src/export/experiences.ts @@ -9,7 +9,7 @@ export default class ExportExperiences extends PersonalizationAdapter = await this.getExperiences() || []; + const experiences: Array = (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); - const experienceToVarianceStrList: Array = []; + const experienceToVariantsStrList: Array = []; for (let experience of experiences) { - let variants = experience?._cms?.variants ?? {}; // Add nullish coalescing operator - if (variants) { - Object.keys(variants).forEach((variantShortId: string) => { - const experienceToVarianceStr = `${experience.uid}-${variantShortId}-${variants[variantShortId]}`; - experienceToVarianceStrList.push(experienceToVarianceStr); - }); - } + let variants = experience?._cms?.variants ?? {}; + Object.keys(variants).forEach((variantShortId: string) => { + const experienceToVariantsStr = `${experience.uid}-${variantShortId}-${variants[variantShortId]}`; + experienceToVariantsStrList.push(experienceToVariantsStr); + }); } fsUtil.writeFile( path.resolve(this.experiencesFolderPath, 'experiences-variants-ids.json'), - experienceToVarianceStrList, + experienceToVariantsStrList, ); log(this.exportConfig, 'All the experiences have been exported successfully!', 'success'); } catch (error) { diff --git a/packages/contentstack-variants/src/export/projects.ts b/packages/contentstack-variants/src/export/projects.ts index 668b401132..aea1b1c913 100644 --- a/packages/contentstack-variants/src/export/projects.ts +++ b/packages/contentstack-variants/src/export/projects.ts @@ -10,7 +10,7 @@ export default class ExportProjects extends PersonalizationAdapter constructor(exportConfig: ExportConfig) { super({ config: exportConfig, - baseURL: exportConfig.modules.personalization.baseURL, + 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 e507c8edb6..ee3ae6266d 100644 --- a/packages/contentstack-variants/src/import/attribute.ts +++ b/packages/contentstack-variants/src/import/attribute.ts @@ -15,7 +15,7 @@ export default class Attribute extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.personalizationHost, + 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 3349bbcbca..b3351e513c 100644 --- a/packages/contentstack-variants/src/import/audiences.ts +++ b/packages/contentstack-variants/src/import/audiences.ts @@ -17,7 +17,7 @@ export default class Audiences extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.personalizationHost, + 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 0529df22d7..864a730b5a 100644 --- a/packages/contentstack-variants/src/import/events.ts +++ b/packages/contentstack-variants/src/import/events.ts @@ -15,7 +15,7 @@ export default class Events extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.personalizationHost, + 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 83736d0176..9fe2ccc4b6 100644 --- a/packages/contentstack-variants/src/import/experiences.ts +++ b/packages/contentstack-variants/src/import/experiences.ts @@ -33,7 +33,7 @@ export default class Experiences extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.personalizationHost, + 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)); @@ -204,6 +204,3 @@ export default class Experiences extends PersonalizationAdapter { } } } - - - diff --git a/packages/contentstack-variants/src/import/project.ts b/packages/contentstack-variants/src/import/project.ts index e3741e4680..0327b0976c 100644 --- a/packages/contentstack-variants/src/import/project.ts +++ b/packages/contentstack-variants/src/import/project.ts @@ -8,7 +8,7 @@ export default class Project extends PersonalizationAdapter { constructor(public readonly config: ImportConfig, private readonly log: LogType = console.log) { const conf: APIConfig = { config, - baseURL: config.personalizationHost, + baseURL: config.modules.personalization.baseURL[config.region.name], headers: { organization_uid: config.org_uid, authtoken: config.auth_token }, }; super(Object.assign(config, conf)); diff --git a/packages/contentstack-variants/src/types/export-config.ts b/packages/contentstack-variants/src/types/export-config.ts index d78cd8510e..7e2e1af690 100644 --- a/packages/contentstack-variants/src/types/export-config.ts +++ b/packages/contentstack-variants/src/types/export-config.ts @@ -156,7 +156,7 @@ export interface DefaultConfig { } & AnyProperty; personalization: { dirName: string; - baseURL: string; + baseURL: Record; } & AnyProperty; extensions: { dirName: string; @@ -265,18 +265,13 @@ export interface ExportConfig extends DefaultConfig { sourceStackName?: string; personalizationEnabled: boolean; personalizationHost?: string; + region: any; } export interface PersonalizationConfig { dirName: string; - baseURL: string; + baseURL: Record; } - -export interface PersonalizationConfig { - dirName: string; - baseURL: string; -} - export interface EventsConfig { dirName: string; fileName: string; diff --git a/packages/contentstack-variants/src/types/import-config.ts b/packages/contentstack-variants/src/types/import-config.ts index 06b3ea93c5..c534796acc 100644 --- a/packages/contentstack-variants/src/types/import-config.ts +++ b/packages/contentstack-variants/src/types/import-config.ts @@ -1,7 +1,6 @@ import { AnyProperty } from './utils'; export interface ImportDefaultConfig extends AnyProperty { - personalizationHost: string; modules: { 'content-types': { dirName: string; @@ -14,6 +13,7 @@ export interface ImportDefaultConfig extends AnyProperty { fileName: string; }; personalization: { + baseURL: Record; dirName: string; importData: boolean; importOrder: string[];