@contentstack/cli-variants 0.0.1-alpha → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/export/attributes.d.ts +2 -2
- package/lib/export/attributes.js +5 -4
- package/lib/export/audiences.d.ts +2 -2
- package/lib/export/audiences.js +5 -4
- package/lib/export/events.d.ts +2 -2
- package/lib/export/events.js +5 -4
- package/lib/export/experiences.d.ts +2 -2
- package/lib/export/experiences.js +20 -5
- package/lib/export/projects.d.ts +2 -2
- package/lib/export/projects.js +9 -6
- package/lib/export/variant-entries.js +1 -1
- package/lib/import/attribute.d.ts +1 -1
- package/lib/import/attribute.js +21 -10
- package/lib/import/audiences.d.ts +2 -2
- package/lib/import/audiences.js +21 -14
- package/lib/import/events.d.ts +1 -1
- package/lib/import/events.js +15 -8
- package/lib/import/experiences.d.ts +12 -5
- package/lib/import/experiences.js +86 -21
- package/lib/import/project.js +12 -11
- package/lib/import/variant-entries.d.ts +1 -1
- package/lib/import/variant-entries.js +28 -22
- package/lib/messages/index.d.ts +1 -1
- package/lib/messages/index.js +3 -2
- package/lib/types/export-config.d.ts +3 -3
- package/lib/types/import-config.d.ts +1 -1
- package/lib/types/personalization-api-adapter.d.ts +14 -1
- package/lib/types/variant-api-adapter.d.ts +3 -2
- package/lib/types/variant-entry.d.ts +2 -3
- package/lib/utils/attributes-helper.js +2 -2
- package/lib/utils/audiences-helper.js +14 -3
- package/lib/utils/error-helper.js +6 -6
- package/lib/utils/logger.js +5 -4
- package/lib/utils/personalization-api-adapter.d.ts +6 -2
- package/lib/utils/personalization-api-adapter.js +90 -23
- package/lib/utils/variant-api-adapter.d.ts +5 -4
- package/lib/utils/variant-api-adapter.js +29 -10
- package/package.json +2 -2
- package/src/export/attributes.ts +11 -7
- package/src/export/audiences.ts +7 -6
- package/src/export/events.ts +7 -6
- package/src/export/experiences.ts +24 -7
- package/src/export/projects.ts +11 -8
- package/src/export/variant-entries.ts +1 -2
- package/src/import/attribute.ts +31 -13
- package/src/import/audiences.ts +37 -19
- package/src/import/events.ts +25 -11
- package/src/import/experiences.ts +120 -30
- package/src/import/project.ts +13 -13
- package/src/import/variant-entries.ts +70 -37
- package/src/messages/index.ts +3 -2
- package/src/types/export-config.ts +3 -3
- package/src/types/import-config.ts +1 -1
- package/src/types/personalization-api-adapter.ts +14 -1
- package/src/types/variant-api-adapter.ts +3 -1
- package/src/types/variant-entry.ts +2 -3
- package/src/utils/attributes-helper.ts +2 -2
- package/src/utils/audiences-helper.ts +12 -2
- package/src/utils/error-helper.ts +6 -6
- package/src/utils/logger.ts +5 -4
- package/src/utils/personalization-api-adapter.ts +71 -18
- package/src/utils/variant-api-adapter.ts +21 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PersonalizationAdapter } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
3
3
|
export default class ExportAttributes extends PersonalizationAdapter<ExportConfig> {
|
|
4
4
|
readonly exportConfig: ExportConfig;
|
|
5
5
|
private attributesConfig;
|
|
6
6
|
private attributesFolderPath;
|
|
7
7
|
private attributes;
|
|
8
|
-
|
|
8
|
+
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
|
11
11
|
/**
|
package/lib/export/attributes.js
CHANGED
|
@@ -20,13 +20,13 @@ class ExportAttributes extends utils_1.PersonalizationAdapter {
|
|
|
20
20
|
constructor(exportConfig) {
|
|
21
21
|
super({
|
|
22
22
|
config: exportConfig,
|
|
23
|
-
baseURL: exportConfig.modules.
|
|
24
|
-
headers: {
|
|
23
|
+
baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
|
|
24
|
+
headers: { 'X-Project-Uid': exportConfig.project_id },
|
|
25
25
|
});
|
|
26
26
|
this.exportConfig = exportConfig;
|
|
27
|
-
this.
|
|
27
|
+
this.personalizeConfig = exportConfig.modules.personalize;
|
|
28
28
|
this.attributesConfig = exportConfig.modules.attributes;
|
|
29
|
-
this.attributesFolderPath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.
|
|
29
|
+
this.attributesFolderPath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(this.attributesConfig.dirName));
|
|
30
30
|
this.attributes = [];
|
|
31
31
|
}
|
|
32
32
|
start() {
|
|
@@ -34,6 +34,7 @@ class ExportAttributes extends utils_1.PersonalizationAdapter {
|
|
|
34
34
|
var _a;
|
|
35
35
|
try {
|
|
36
36
|
(0, utils_1.log)(this.exportConfig, 'Starting attributes export', 'info');
|
|
37
|
+
yield this.init();
|
|
37
38
|
yield utils_1.fsUtil.makeDirectory(this.attributesFolderPath);
|
|
38
39
|
this.attributes = (yield this.getAttributes());
|
|
39
40
|
if (!((_a = this.attributes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PersonalizationAdapter } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
3
3
|
export default class ExportAudiences extends PersonalizationAdapter<ExportConfig> {
|
|
4
4
|
readonly exportConfig: ExportConfig;
|
|
5
5
|
private audiencesConfig;
|
|
6
6
|
private audiencesFolderPath;
|
|
7
7
|
private audiences;
|
|
8
|
-
|
|
8
|
+
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
|
11
11
|
/**
|
package/lib/export/audiences.js
CHANGED
|
@@ -19,13 +19,13 @@ class ExportAudiences extends utils_1.PersonalizationAdapter {
|
|
|
19
19
|
constructor(exportConfig) {
|
|
20
20
|
super({
|
|
21
21
|
config: exportConfig,
|
|
22
|
-
baseURL: exportConfig.modules.
|
|
23
|
-
headers: {
|
|
22
|
+
baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
|
|
23
|
+
headers: { 'X-Project-Uid': exportConfig.project_id },
|
|
24
24
|
});
|
|
25
25
|
this.exportConfig = exportConfig;
|
|
26
|
-
this.
|
|
26
|
+
this.personalizeConfig = exportConfig.modules.personalize;
|
|
27
27
|
this.audiencesConfig = exportConfig.modules.audiences;
|
|
28
|
-
this.audiencesFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.
|
|
28
|
+
this.audiencesFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.personalizeConfig.dirName, this.audiencesConfig.dirName);
|
|
29
29
|
this.audiences = [];
|
|
30
30
|
}
|
|
31
31
|
start() {
|
|
@@ -33,6 +33,7 @@ class ExportAudiences extends utils_1.PersonalizationAdapter {
|
|
|
33
33
|
var _a;
|
|
34
34
|
try {
|
|
35
35
|
(0, utils_1.log)(this.exportConfig, 'Starting audiences export', 'info');
|
|
36
|
+
yield this.init();
|
|
36
37
|
yield utils_1.fsUtil.makeDirectory(this.audiencesFolderPath);
|
|
37
38
|
this.audiences = (yield this.getAudiences());
|
|
38
39
|
if (!((_a = this.audiences) === null || _a === void 0 ? void 0 : _a.length)) {
|
package/lib/export/events.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PersonalizationAdapter } from '../utils';
|
|
2
|
-
import {
|
|
2
|
+
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
3
3
|
export default class ExportEvents extends PersonalizationAdapter<ExportConfig> {
|
|
4
4
|
readonly exportConfig: ExportConfig;
|
|
5
5
|
private eventsConfig;
|
|
6
6
|
private eventsFolderPath;
|
|
7
7
|
private events;
|
|
8
|
-
|
|
8
|
+
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
|
11
11
|
/**
|
package/lib/export/events.js
CHANGED
|
@@ -19,13 +19,13 @@ class ExportEvents extends utils_1.PersonalizationAdapter {
|
|
|
19
19
|
constructor(exportConfig) {
|
|
20
20
|
super({
|
|
21
21
|
config: exportConfig,
|
|
22
|
-
baseURL: exportConfig.modules.
|
|
23
|
-
headers: {
|
|
22
|
+
baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
|
|
23
|
+
headers: { 'X-Project-Uid': exportConfig.project_id },
|
|
24
24
|
});
|
|
25
25
|
this.exportConfig = exportConfig;
|
|
26
|
-
this.
|
|
26
|
+
this.personalizeConfig = exportConfig.modules.personalize;
|
|
27
27
|
this.eventsConfig = exportConfig.modules.events;
|
|
28
|
-
this.eventsFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.
|
|
28
|
+
this.eventsFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.personalizeConfig.dirName, this.eventsConfig.dirName);
|
|
29
29
|
this.events = [];
|
|
30
30
|
}
|
|
31
31
|
start() {
|
|
@@ -33,6 +33,7 @@ class ExportEvents extends utils_1.PersonalizationAdapter {
|
|
|
33
33
|
var _a;
|
|
34
34
|
try {
|
|
35
35
|
(0, utils_1.log)(this.exportConfig, 'Starting events export', 'info');
|
|
36
|
+
yield this.init();
|
|
36
37
|
yield utils_1.fsUtil.makeDirectory(this.eventsFolderPath);
|
|
37
38
|
this.events = (yield this.getEvents());
|
|
38
39
|
if (!((_a = this.events) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
2
2
|
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportExperiences extends PersonalizationAdapter<ExportConfig> {
|
|
4
4
|
private experiencesFolderPath;
|
|
5
5
|
exportConfig: ExportConfig;
|
|
6
|
-
|
|
6
|
+
personalizeConfig: PersonalizeConfig;
|
|
7
7
|
constructor(exportConfig: ExportConfig);
|
|
8
8
|
start(): Promise<void>;
|
|
9
9
|
}
|
|
@@ -39,16 +39,16 @@ class ExportExperiences extends utils_1.PersonalizationAdapter {
|
|
|
39
39
|
constructor(exportConfig) {
|
|
40
40
|
super({
|
|
41
41
|
config: exportConfig,
|
|
42
|
-
baseURL: exportConfig.modules.
|
|
43
|
-
headers: {
|
|
42
|
+
baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
|
|
43
|
+
headers: { 'X-Project-Uid': exportConfig.project_id },
|
|
44
44
|
cmaConfig: {
|
|
45
45
|
baseURL: exportConfig.region.cma + `/v3`,
|
|
46
|
-
headers: {
|
|
46
|
+
headers: { api_key: exportConfig.apiKey },
|
|
47
47
|
},
|
|
48
48
|
});
|
|
49
49
|
this.exportConfig = exportConfig;
|
|
50
|
-
this.
|
|
51
|
-
this.experiencesFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.
|
|
50
|
+
this.personalizeConfig = exportConfig.modules.personalize;
|
|
51
|
+
this.experiencesFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), 'experiences');
|
|
52
52
|
}
|
|
53
53
|
start() {
|
|
54
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -58,7 +58,9 @@ class ExportExperiences extends utils_1.PersonalizationAdapter {
|
|
|
58
58
|
// loop through experiences and get content types attached to it
|
|
59
59
|
// write experiences in to a file
|
|
60
60
|
(0, utils_1.log)(this.exportConfig, 'Starting experiences export', 'info');
|
|
61
|
+
yield this.init();
|
|
61
62
|
yield utils_1.fsUtil.makeDirectory(this.experiencesFolderPath);
|
|
63
|
+
yield utils_1.fsUtil.makeDirectory(path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'versions'));
|
|
62
64
|
const experiences = (yield this.getExperiences()) || [];
|
|
63
65
|
if (!experiences || (experiences === null || experiences === void 0 ? void 0 : experiences.length) < 1) {
|
|
64
66
|
(0, utils_1.log)(this.exportConfig, 'No Experiences found with the give project', 'info');
|
|
@@ -74,6 +76,19 @@ class ExportExperiences extends utils_1.PersonalizationAdapter {
|
|
|
74
76
|
const experienceToVariantsStr = `${experience.uid}-${variantShortId}-${variants[variantShortId]}`;
|
|
75
77
|
experienceToVariantsStrList.push(experienceToVariantsStr);
|
|
76
78
|
});
|
|
79
|
+
try {
|
|
80
|
+
// fetch versions of experience
|
|
81
|
+
const experienceVersions = (yield this.getExperienceVersions(experience.uid)) || [];
|
|
82
|
+
if (experienceVersions.length > 0) {
|
|
83
|
+
utils_1.fsUtil.writeFile(path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'versions', `${experience.uid}.json`), experienceVersions);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
(0, utils_1.log)(this.exportConfig, `No versions found for experience ${experience.name}`, 'info');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
(0, utils_1.log)(this.exportConfig, `Failed to fetch versions of experience ${experience.name}`, 'error');
|
|
91
|
+
}
|
|
77
92
|
try {
|
|
78
93
|
// fetch content of experience
|
|
79
94
|
const { variant_groups: [variantGroup] = [] } = (yield this.getVariantGroup({ experienceUid: experience.uid })) || {};
|
package/lib/export/projects.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ExportConfig,
|
|
1
|
+
import { ExportConfig, PersonalizeConfig } from '../types';
|
|
2
2
|
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportProjects extends PersonalizationAdapter<ExportConfig> {
|
|
4
4
|
private projectFolderPath;
|
|
5
5
|
exportConfig: ExportConfig;
|
|
6
|
-
|
|
6
|
+
personalizeConfig: PersonalizeConfig;
|
|
7
7
|
constructor(exportConfig: ExportConfig);
|
|
8
8
|
start(): Promise<void>;
|
|
9
9
|
}
|
package/lib/export/projects.js
CHANGED
|
@@ -39,22 +39,23 @@ class ExportProjects extends utils_1.PersonalizationAdapter {
|
|
|
39
39
|
constructor(exportConfig) {
|
|
40
40
|
super({
|
|
41
41
|
config: exportConfig,
|
|
42
|
-
baseURL: exportConfig.modules.
|
|
43
|
-
headers: {
|
|
42
|
+
baseURL: exportConfig.modules.personalize.baseURL[exportConfig.region.name],
|
|
43
|
+
headers: { organization_uid: exportConfig.org_uid },
|
|
44
44
|
});
|
|
45
45
|
this.exportConfig = exportConfig;
|
|
46
|
-
this.
|
|
47
|
-
this.projectFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.
|
|
46
|
+
this.personalizeConfig = exportConfig.modules.personalize;
|
|
47
|
+
this.projectFolderPath = path.resolve((0, cli_utilities_1.sanitizePath)(exportConfig.data), (0, cli_utilities_1.sanitizePath)(exportConfig.branchName || ''), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), 'projects');
|
|
48
48
|
}
|
|
49
49
|
start() {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
var _a;
|
|
52
52
|
try {
|
|
53
53
|
(0, utils_1.log)(this.exportConfig, 'Starting projects export', 'info');
|
|
54
|
+
yield this.init();
|
|
54
55
|
yield utils_1.fsUtil.makeDirectory(this.projectFolderPath);
|
|
55
56
|
const project = yield this.projects({ connectedStackApiKey: this.exportConfig.apiKey });
|
|
56
57
|
if (!project || (project === null || project === void 0 ? void 0 : project.length) < 1) {
|
|
57
|
-
(0, utils_1.log)(this.exportConfig, 'No
|
|
58
|
+
(0, utils_1.log)(this.exportConfig, 'No Personalize Project connected with the given stack', 'info');
|
|
58
59
|
this.exportConfig.personalizationEnabled = false;
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
@@ -64,7 +65,9 @@ class ExportProjects extends utils_1.PersonalizationAdapter {
|
|
|
64
65
|
(0, utils_1.log)(this.exportConfig, 'Project exported successfully!', 'success');
|
|
65
66
|
}
|
|
66
67
|
catch (error) {
|
|
67
|
-
|
|
68
|
+
if (error !== 'Forbidden') {
|
|
69
|
+
(0, utils_1.log)(this.exportConfig, `Failed to export projects!`, 'error');
|
|
70
|
+
}
|
|
68
71
|
throw error;
|
|
69
72
|
}
|
|
70
73
|
});
|
|
@@ -47,7 +47,6 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
47
47
|
headers: {
|
|
48
48
|
api_key: config.apiKey,
|
|
49
49
|
branch: config.branchName,
|
|
50
|
-
authtoken: config.auth_token,
|
|
51
50
|
organization_uid: config.org_uid,
|
|
52
51
|
'X-Project-Uid': config.project_id,
|
|
53
52
|
},
|
|
@@ -65,6 +64,7 @@ class VariantEntries extends variant_api_adapter_1.default {
|
|
|
65
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
65
|
const variantEntry = this.config.modules.variantEntry;
|
|
67
66
|
const { entries, locale, contentTypeUid: content_type_uid } = options;
|
|
67
|
+
yield this.variantInstance.init();
|
|
68
68
|
for (let index = 0; index < entries.length; index++) {
|
|
69
69
|
const entry = entries[index];
|
|
70
70
|
const variantEntryBasePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.entriesDirPath), (0, cli_utilities_1.sanitizePath)(content_type_uid), (0, cli_utilities_1.sanitizePath)(locale), (0, cli_utilities_1.sanitizePath)(variantEntry.dirName), (0, cli_utilities_1.sanitizePath)(entry.uid));
|
|
@@ -7,7 +7,7 @@ export default class Attribute extends PersonalizationAdapter<ImportConfig> {
|
|
|
7
7
|
private attrMapperDirPath;
|
|
8
8
|
private attributesUidMapperPath;
|
|
9
9
|
private attributesUidMapper;
|
|
10
|
-
private
|
|
10
|
+
private personalizeConfig;
|
|
11
11
|
private attributeConfig;
|
|
12
12
|
constructor(config: ImportConfig, log?: LogType);
|
|
13
13
|
/**
|
package/lib/import/attribute.js
CHANGED
|
@@ -17,15 +17,15 @@ class Attribute extends utils_1.PersonalizationAdapter {
|
|
|
17
17
|
constructor(config, log = console.log) {
|
|
18
18
|
const conf = {
|
|
19
19
|
config,
|
|
20
|
-
baseURL: config.modules.
|
|
21
|
-
headers: { 'X-Project-Uid': config.modules.
|
|
20
|
+
baseURL: config.modules.personalize.baseURL[config.region.name],
|
|
21
|
+
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
|
|
22
22
|
};
|
|
23
23
|
super(Object.assign(config, conf));
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.log = log;
|
|
26
|
-
this.
|
|
27
|
-
this.attributeConfig = this.
|
|
28
|
-
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.
|
|
26
|
+
this.personalizeConfig = this.config.modules.personalize;
|
|
27
|
+
this.attributeConfig = this.personalizeConfig.attributes;
|
|
28
|
+
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName));
|
|
29
29
|
this.attrMapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.mapperDirPath), (0, cli_utilities_1.sanitizePath)(this.attributeConfig.dirName));
|
|
30
30
|
this.attributesUidMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.attrMapperDirPath), 'uid-mapping.json');
|
|
31
31
|
this.attributesUidMapper = {};
|
|
@@ -37,18 +37,29 @@ class Attribute extends utils_1.PersonalizationAdapter {
|
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
var _a;
|
|
39
39
|
this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Attributes' }), 'info');
|
|
40
|
+
yield this.init();
|
|
40
41
|
yield utils_1.fsUtil.makeDirectory(this.attrMapperDirPath);
|
|
41
42
|
const { dirName, fileName } = this.attributeConfig;
|
|
42
|
-
const attributesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.
|
|
43
|
+
const attributesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(dirName), (0, cli_utilities_1.sanitizePath)(fileName));
|
|
43
44
|
if ((0, fs_1.existsSync)(attributesPath)) {
|
|
44
45
|
try {
|
|
45
46
|
const attributes = utils_1.fsUtil.readFile(attributesPath, true);
|
|
46
47
|
for (const attribute of attributes) {
|
|
47
48
|
const { key, name, description, uid } = attribute;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// skip creating preset attributes, as they are already present in the system
|
|
50
|
+
if (attribute.__type === 'PRESET') {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const attributeRes = yield this.createAttribute({ key, name, description });
|
|
55
|
+
//map old attribute uid to new attribute uid
|
|
56
|
+
//mapper file is used to check whether attribute created or not before creating audience
|
|
57
|
+
this.attributesUidMapper[uid] = (_a = attributeRes === null || attributeRes === void 0 ? void 0 : attributeRes.uid) !== null && _a !== void 0 ? _a : '';
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.log(this.config, `Failed to create attribute ${name}!`, 'error');
|
|
61
|
+
this.log(this.config, error, 'error');
|
|
62
|
+
}
|
|
52
63
|
}
|
|
53
64
|
utils_1.fsUtil.writeFile(this.attributesUidMapperPath, this.attributesUidMapper);
|
|
54
65
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Attributes' }), 'info');
|
|
@@ -8,9 +8,9 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
8
8
|
private attributesMapperPath;
|
|
9
9
|
private audiencesUidMapperPath;
|
|
10
10
|
private audiencesUidMapper;
|
|
11
|
-
private
|
|
11
|
+
private personalizeConfig;
|
|
12
12
|
private audienceConfig;
|
|
13
|
-
attributeConfig: ImportConfig['modules']['
|
|
13
|
+
attributeConfig: ImportConfig['modules']['personalize']['attributes'];
|
|
14
14
|
constructor(config: ImportConfig, log?: LogType);
|
|
15
15
|
/**
|
|
16
16
|
* The function asynchronously imports audiences from a JSON file and creates them in the system.
|
package/lib/import/audiences.js
CHANGED
|
@@ -17,16 +17,16 @@ class Audiences extends utils_1.PersonalizationAdapter {
|
|
|
17
17
|
constructor(config, log = console.log) {
|
|
18
18
|
const conf = {
|
|
19
19
|
config,
|
|
20
|
-
baseURL: config.modules.
|
|
21
|
-
headers: { 'X-Project-Uid': config.modules.
|
|
20
|
+
baseURL: config.modules.personalize.baseURL[config.region.name],
|
|
21
|
+
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
|
|
22
22
|
};
|
|
23
23
|
super(Object.assign(config, conf));
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.log = log;
|
|
26
|
-
this.
|
|
27
|
-
this.audienceConfig = this.
|
|
28
|
-
this.attributeConfig = this.
|
|
29
|
-
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.
|
|
26
|
+
this.personalizeConfig = this.config.modules.personalize;
|
|
27
|
+
this.audienceConfig = this.personalizeConfig.audiences;
|
|
28
|
+
this.attributeConfig = this.personalizeConfig.attributes;
|
|
29
|
+
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName));
|
|
30
30
|
this.audienceMapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.mapperDirPath), (0, cli_utilities_1.sanitizePath)(this.audienceConfig.dirName));
|
|
31
31
|
this.audiencesUidMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.audienceMapperDirPath), 'uid-mapping.json');
|
|
32
32
|
this.attributesMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.mapperDirPath), (0, cli_utilities_1.sanitizePath)(this.attributeConfig.dirName), 'uid-mapping.json');
|
|
@@ -39,23 +39,30 @@ class Audiences extends utils_1.PersonalizationAdapter {
|
|
|
39
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
40
|
var _a, _b;
|
|
41
41
|
this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Audiences' }), 'info');
|
|
42
|
+
yield this.init();
|
|
42
43
|
yield utils_1.fsUtil.makeDirectory(this.audienceMapperDirPath);
|
|
43
44
|
const { dirName, fileName } = this.audienceConfig;
|
|
44
|
-
const audiencesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.
|
|
45
|
+
const audiencesPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(dirName), (0, cli_utilities_1.sanitizePath)(fileName));
|
|
45
46
|
if ((0, fs_1.existsSync)(audiencesPath)) {
|
|
46
47
|
try {
|
|
47
48
|
const audiences = utils_1.fsUtil.readFile(audiencesPath, true);
|
|
48
49
|
const attributesUid = utils_1.fsUtil.readFile(this.attributesMapperPath, true) || {};
|
|
49
50
|
for (const audience of audiences) {
|
|
50
51
|
let { name, definition, description, uid } = audience;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
definition.rules
|
|
52
|
+
try {
|
|
53
|
+
//check whether reference attributes exists or not
|
|
54
|
+
if ((_a = definition.rules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
55
|
+
definition.rules = (0, utils_1.lookUpAttributes)(definition.rules, attributesUid);
|
|
56
|
+
}
|
|
57
|
+
const audienceRes = yield this.createAudience({ definition, name, description });
|
|
58
|
+
//map old audience uid to new audience uid
|
|
59
|
+
//mapper file is used to check whether audience created or not before creating experience
|
|
60
|
+
this.audiencesUidMapper[uid] = (_b = audienceRes === null || audienceRes === void 0 ? void 0 : audienceRes.uid) !== null && _b !== void 0 ? _b : '';
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.log(this.config, `Failed to create audience uid: ${uid}, name: ${name}`, 'error');
|
|
64
|
+
this.log(this.config, error, 'error');
|
|
54
65
|
}
|
|
55
|
-
const audienceRes = yield this.createAudience({ definition, name, description });
|
|
56
|
-
//map old audience uid to new audience uid
|
|
57
|
-
//mapper file is used to check whether audience created or not before creating experience
|
|
58
|
-
this.audiencesUidMapper[uid] = (_b = audienceRes === null || audienceRes === void 0 ? void 0 : audienceRes.uid) !== null && _b !== void 0 ? _b : '';
|
|
59
66
|
}
|
|
60
67
|
utils_1.fsUtil.writeFile(this.audiencesUidMapperPath, this.audiencesUidMapper);
|
|
61
68
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Audiences' }), 'info');
|
package/lib/import/events.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export default class Events extends PersonalizationAdapter<ImportConfig> {
|
|
|
7
7
|
private eventMapperDirPath;
|
|
8
8
|
private eventsUidMapperPath;
|
|
9
9
|
private eventsUidMapper;
|
|
10
|
-
private
|
|
10
|
+
private personalizeConfig;
|
|
11
11
|
private eventsConfig;
|
|
12
12
|
constructor(config: ImportConfig, log?: LogType);
|
|
13
13
|
/**
|
package/lib/import/events.js
CHANGED
|
@@ -17,15 +17,15 @@ class Events extends utils_1.PersonalizationAdapter {
|
|
|
17
17
|
constructor(config, log = console.log) {
|
|
18
18
|
const conf = {
|
|
19
19
|
config,
|
|
20
|
-
baseURL: config.modules.
|
|
21
|
-
headers: { 'X-Project-Uid': config.modules.
|
|
20
|
+
baseURL: config.modules.personalize.baseURL[config.region.name],
|
|
21
|
+
headers: { 'X-Project-Uid': config.modules.personalize.project_id },
|
|
22
22
|
};
|
|
23
23
|
super(Object.assign(config, conf));
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.log = log;
|
|
26
|
-
this.
|
|
27
|
-
this.eventsConfig = this.
|
|
28
|
-
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.
|
|
26
|
+
this.personalizeConfig = this.config.modules.personalize;
|
|
27
|
+
this.eventsConfig = this.personalizeConfig.events;
|
|
28
|
+
this.mapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName));
|
|
29
29
|
this.eventMapperDirPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.mapperDirPath), (0, cli_utilities_1.sanitizePath)(this.eventsConfig.dirName));
|
|
30
30
|
this.eventsUidMapperPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.eventMapperDirPath), 'uid-mapping.json');
|
|
31
31
|
this.eventsUidMapper = {};
|
|
@@ -37,16 +37,23 @@ class Events extends utils_1.PersonalizationAdapter {
|
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
38
|
var _a;
|
|
39
39
|
this.log(this.config, this.$t(this.messages.IMPORT_MSG, { module: 'Events' }), 'info');
|
|
40
|
+
yield this.init();
|
|
40
41
|
yield utils_1.fsUtil.makeDirectory(this.eventMapperDirPath);
|
|
41
42
|
const { dirName, fileName } = this.eventsConfig;
|
|
42
|
-
const eventsPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.
|
|
43
|
+
const eventsPath = (0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.config.data), (0, cli_utilities_1.sanitizePath)(this.personalizeConfig.dirName), (0, cli_utilities_1.sanitizePath)(dirName), (0, cli_utilities_1.sanitizePath)(fileName));
|
|
43
44
|
if ((0, fs_1.existsSync)(eventsPath)) {
|
|
44
45
|
try {
|
|
45
46
|
const events = utils_1.fsUtil.readFile(eventsPath, true);
|
|
46
47
|
for (const event of events) {
|
|
47
48
|
const { key, description, uid } = event;
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
try {
|
|
50
|
+
const eventsResponse = yield this.createEvents({ key, description });
|
|
51
|
+
this.eventsUidMapper[uid] = (_a = eventsResponse === null || eventsResponse === void 0 ? void 0 : eventsResponse.uid) !== null && _a !== void 0 ? _a : '';
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.log(this.config, `failed to create event uid: ${uid}`, 'error');
|
|
55
|
+
this.log(this.config, error, 'error');
|
|
56
|
+
}
|
|
50
57
|
}
|
|
51
58
|
utils_1.fsUtil.writeFile(this.eventsUidMapperPath, this.eventsUidMapper);
|
|
52
59
|
this.log(this.config, this.$t(this.messages.CREATE_SUCCESS, { module: 'Events' }), 'info');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PersonalizationAdapter } from '../utils';
|
|
2
|
-
import { ImportConfig, LogType } from '../types';
|
|
2
|
+
import { ImportConfig, ExperienceStruct, LogType } from '../types';
|
|
3
3
|
export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
4
4
|
readonly config: ImportConfig;
|
|
5
5
|
private readonly log;
|
|
@@ -25,7 +25,9 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
25
25
|
private cmsVariantGroups;
|
|
26
26
|
private experiencesUidMapper;
|
|
27
27
|
private pendingVariantAndVariantGrpForExperience;
|
|
28
|
-
private
|
|
28
|
+
private audiencesUid;
|
|
29
|
+
private eventsUid;
|
|
30
|
+
private personalizeConfig;
|
|
29
31
|
private audienceConfig;
|
|
30
32
|
private experienceConfig;
|
|
31
33
|
constructor(config: ImportConfig, log?: LogType);
|
|
@@ -34,9 +36,14 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
34
36
|
*/
|
|
35
37
|
import(): Promise<void>;
|
|
36
38
|
/**
|
|
37
|
-
* function
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
* function import experience versions from a JSON file and creates them in the project.
|
|
40
|
+
*/
|
|
41
|
+
importExperienceVersions(experience: ExperienceStruct, oldExperienceUid: string): Promise<void>;
|
|
42
|
+
private handleVersionUpdateOrCreate;
|
|
43
|
+
/**
|
|
44
|
+
* function to validate if all variant groups and variants have been created using personalize background job
|
|
45
|
+
* store the variant groups data in mapper/personalize/experiences/cms-variant-groups.json and the variants data
|
|
46
|
+
* in mapper/personalize/experiences/cms-variants.json. If not, invoke validateVariantGroupAndVariantsCreated after some delay.
|
|
40
47
|
* @param retryCount Counter to track the number of times the function has been called
|
|
41
48
|
* @returns
|
|
42
49
|
*/
|