-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1473 from contentstack/next-feature-update
Variants changes
- Loading branch information
Showing
95 changed files
with
4,967 additions
and
2,505 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/contentstack-export/src/export/modules/personalization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { | ||
ExportProjects, | ||
ExportExperiences, | ||
ExportEvents, | ||
ExportAttributes, | ||
ExportAudiences, | ||
AnyProperty, | ||
} from '@contentstack/cli-variants'; | ||
|
||
import { log, formatError } from '../../utils'; | ||
import { ModuleClassParams, ExportConfig } from '../../types'; | ||
|
||
export default class ExportPersonalization { | ||
public exportConfig: ExportConfig; | ||
public personalizeConfig: { dirName: string; baseURL: Record<string, string> } & AnyProperty; | ||
constructor({ exportConfig }: ModuleClassParams) { | ||
this.exportConfig = exportConfig; | ||
this.personalizeConfig = exportConfig.modules.personalization; | ||
} | ||
|
||
async start(): Promise<void> { | ||
try { | ||
if (!this.personalizeConfig.baseURL[this.exportConfig.region.name]) { | ||
log(this.exportConfig, 'Skipping Personalize project export, personalize url is not set', 'info'); | ||
this.exportConfig.personalizationEnabled = false; | ||
return; | ||
} | ||
if (this.exportConfig.management_token) { | ||
log(this.exportConfig, 'Skipping Personalize project export when using management token', 'info'); | ||
this.exportConfig.personalizationEnabled = false; | ||
return; | ||
} | ||
await new ExportProjects(this.exportConfig).start(); | ||
if (this.exportConfig.personalizationEnabled) { | ||
const moduleMapper = { | ||
events: new ExportEvents(this.exportConfig), | ||
attributes: new ExportAttributes(this.exportConfig), | ||
audiences: new ExportAudiences(this.exportConfig), | ||
experiences: new ExportExperiences(this.exportConfig), | ||
}; | ||
|
||
const order: (keyof typeof moduleMapper)[] = this.exportConfig.modules.personalization | ||
.exportOrder as (keyof typeof moduleMapper)[]; | ||
|
||
for (const module of order) { | ||
if (moduleMapper[module]) { | ||
await moduleMapper[module].start(); | ||
} else { | ||
log(this.exportConfig, `No implementation found for the module ${module}`, 'info'); | ||
} | ||
} | ||
} | ||
} catch (error) { | ||
this.exportConfig.personalizationEnabled = false; | ||
log(this.exportConfig, error, 'error'); | ||
} | ||
} | ||
} |
Oops, something went wrong.