@contentstack/cli-variants 1.3.3 → 2.0.0-beta.1
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 +51 -23
- package/lib/export/audiences.d.ts +2 -2
- package/lib/export/audiences.js +50 -24
- package/lib/export/events.d.ts +2 -2
- package/lib/export/events.js +52 -24
- package/lib/export/experiences.js +87 -54
- package/lib/export/projects.d.ts +3 -2
- package/lib/export/projects.js +55 -63
- package/lib/export/variant-entries.d.ts +19 -0
- package/lib/export/variant-entries.js +76 -1
- package/lib/import/attribute.d.ts +2 -0
- package/lib/import/attribute.js +83 -37
- package/lib/import/audiences.d.ts +2 -0
- package/lib/import/audiences.js +85 -41
- package/lib/import/events.d.ts +3 -1
- package/lib/import/events.js +86 -30
- package/lib/import/experiences.d.ts +2 -0
- package/lib/import/experiences.js +93 -39
- package/lib/import/project.d.ts +2 -0
- package/lib/import/project.js +81 -22
- package/lib/import/variant-entries.d.ts +10 -0
- package/lib/import/variant-entries.js +132 -47
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/types/export-config.d.ts +0 -2
- package/lib/types/import-config.d.ts +0 -1
- package/lib/types/utils.d.ts +1 -1
- package/lib/utils/constants.d.ts +91 -0
- package/lib/utils/constants.js +93 -0
- package/lib/utils/personalization-api-adapter.d.ts +34 -1
- package/lib/utils/personalization-api-adapter.js +171 -44
- package/lib/utils/variant-api-adapter.d.ts +28 -1
- package/lib/utils/variant-api-adapter.js +75 -0
- package/package.json +2 -2
- package/src/export/attributes.ts +84 -34
- package/src/export/audiences.ts +87 -41
- package/src/export/events.ts +84 -41
- package/src/export/experiences.ts +155 -83
- package/src/export/projects.ts +71 -39
- package/src/export/variant-entries.ts +136 -12
- package/src/import/attribute.ts +105 -49
- package/src/import/audiences.ts +110 -54
- package/src/import/events.ts +104 -41
- package/src/import/experiences.ts +140 -62
- package/src/import/project.ts +108 -38
- package/src/import/variant-entries.ts +179 -65
- package/src/index.ts +2 -1
- package/src/types/export-config.ts +0 -2
- package/src/types/import-config.ts +0 -1
- package/src/types/utils.ts +1 -1
- package/src/utils/constants.ts +98 -0
- package/src/utils/personalization-api-adapter.ts +202 -66
- package/src/utils/variant-api-adapter.ts +82 -1
- package/tsconfig.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PersonalizationAdapter } from '../utils';
|
|
2
1
|
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
2
|
+
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportAttributes extends PersonalizationAdapter<ExportConfig> {
|
|
4
|
-
readonly exportConfig: ExportConfig;
|
|
5
4
|
private attributesConfig;
|
|
6
5
|
private attributesFolderPath;
|
|
7
6
|
private attributes;
|
|
7
|
+
exportConfig: ExportConfig;
|
|
8
8
|
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
package/lib/export/attributes.js
CHANGED
|
@@ -16,6 +16,7 @@ const omit_1 = __importDefault(require("lodash/omit"));
|
|
|
16
16
|
const node_path_1 = require("node:path");
|
|
17
17
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
18
18
|
const utils_1 = require("../utils");
|
|
19
|
+
const constants_1 = require("../utils/constants");
|
|
19
20
|
class ExportAttributes extends utils_1.PersonalizationAdapter {
|
|
20
21
|
constructor(exportConfig) {
|
|
21
22
|
super({
|
|
@@ -24,44 +25,63 @@ class ExportAttributes extends utils_1.PersonalizationAdapter {
|
|
|
24
25
|
headers: { 'X-Project-Uid': exportConfig.project_id },
|
|
25
26
|
});
|
|
26
27
|
this.exportConfig = exportConfig;
|
|
27
|
-
this.exportConfig = exportConfig;
|
|
28
28
|
this.personalizeConfig = exportConfig.modules.personalize;
|
|
29
29
|
this.attributesConfig = exportConfig.modules.attributes;
|
|
30
30
|
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));
|
|
31
31
|
this.attributes = [];
|
|
32
|
-
this.exportConfig.context.module =
|
|
32
|
+
this.exportConfig.context.module = constants_1.MODULE_CONTEXTS.ATTRIBUTES;
|
|
33
33
|
}
|
|
34
34
|
start() {
|
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
var _a
|
|
36
|
+
var _a;
|
|
37
37
|
try {
|
|
38
38
|
cli_utilities_1.log.info('Starting attributes export', this.exportConfig.context);
|
|
39
|
-
|
|
40
|
-
yield this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
// Initial setup with loading spinner
|
|
40
|
+
yield this.withLoadingSpinner('ATTRIBUTES: Initializing export and fetching data...', () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a;
|
|
42
|
+
cli_utilities_1.log.debug('Initializing personalization adapter...', this.exportConfig.context);
|
|
43
|
+
yield this.init();
|
|
44
|
+
cli_utilities_1.log.debug('Personalization adapter initialized successfully', this.exportConfig.context);
|
|
45
|
+
cli_utilities_1.log.debug(`Creating attributes directory at: ${this.attributesFolderPath}`, this.exportConfig.context);
|
|
46
|
+
yield utils_1.fsUtil.makeDirectory(this.attributesFolderPath);
|
|
47
|
+
cli_utilities_1.log.debug('Attributes directory created successfully', this.exportConfig.context);
|
|
48
|
+
cli_utilities_1.log.debug('Fetching attributes from personalization API...', this.exportConfig.context);
|
|
49
|
+
this.attributes = (yield this.getAttributes());
|
|
50
|
+
cli_utilities_1.log.debug(`Fetched ${((_a = this.attributes) === null || _a === void 0 ? void 0 : _a.length) || 0} attributes`, this.exportConfig.context);
|
|
51
|
+
}));
|
|
52
|
+
if (!((_a = this.attributes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
49
53
|
cli_utilities_1.log.debug('No attributes found, completing export', this.exportConfig.context);
|
|
50
54
|
cli_utilities_1.log.info('No Attributes found with the given project!', this.exportConfig.context);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let progress;
|
|
58
|
+
if (this.parentProgressManager) {
|
|
59
|
+
// Use parent progress manager - we're part of the personalize modules process
|
|
60
|
+
progress = this.parentProgressManager;
|
|
61
|
+
this.progressManager = this.parentProgressManager;
|
|
62
|
+
progress.updateProcessTotal(constants_1.PROCESS_NAMES.ATTRIBUTES, this.attributes.length);
|
|
51
63
|
}
|
|
52
64
|
else {
|
|
53
|
-
|
|
54
|
-
this.sanitizeAttribs();
|
|
55
|
-
cli_utilities_1.log.debug('Attributes sanitization completed', this.exportConfig.context);
|
|
56
|
-
const attributesFilePath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.attributesFolderPath), (0, cli_utilities_1.sanitizePath)(this.attributesConfig.fileName));
|
|
57
|
-
cli_utilities_1.log.debug(`Writing attributes to: ${attributesFilePath}`, this.exportConfig.context);
|
|
58
|
-
utils_1.fsUtil.writeFile(attributesFilePath, this.attributes);
|
|
59
|
-
cli_utilities_1.log.debug('Attributes export completed successfully', this.exportConfig.context);
|
|
60
|
-
cli_utilities_1.log.success(`Attributes exported successfully! Total attributes: ${this.attributes.length}`, this.exportConfig.context);
|
|
65
|
+
progress = this.createSimpleProgress(constants_1.PROCESS_NAMES.ATTRIBUTES, this.attributes.length);
|
|
61
66
|
}
|
|
67
|
+
cli_utilities_1.log.debug(`Processing ${this.attributes.length} attributes`, this.exportConfig.context);
|
|
68
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.ATTRIBUTES].EXPORTING, constants_1.PROCESS_NAMES.ATTRIBUTES);
|
|
69
|
+
this.sanitizeAttribs();
|
|
70
|
+
cli_utilities_1.log.debug('Attributes sanitization completed', this.exportConfig.context);
|
|
71
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.ATTRIBUTES].EXPORTING, constants_1.PROCESS_NAMES.ATTRIBUTES);
|
|
72
|
+
const attributesFilePath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.attributesFolderPath), (0, cli_utilities_1.sanitizePath)(this.attributesConfig.fileName));
|
|
73
|
+
cli_utilities_1.log.debug(`Writing attributes to: ${attributesFilePath}`, this.exportConfig.context);
|
|
74
|
+
utils_1.fsUtil.writeFile(attributesFilePath, this.attributes);
|
|
75
|
+
// Complete progress only if we're managing our own progress
|
|
76
|
+
if (!this.parentProgressManager) {
|
|
77
|
+
this.completeProgress(true);
|
|
78
|
+
}
|
|
79
|
+
cli_utilities_1.log.debug('Attributes export completed successfully', this.exportConfig.context);
|
|
80
|
+
cli_utilities_1.log.success(`Attributes exported successfully! Total attributes: ${this.attributes.length}`, this.exportConfig.context);
|
|
62
81
|
}
|
|
63
82
|
catch (error) {
|
|
64
83
|
cli_utilities_1.log.debug(`Error occurred during attributes export: ${error}`, this.exportConfig.context);
|
|
84
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Attributes export failed');
|
|
65
85
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
66
86
|
}
|
|
67
87
|
});
|
|
@@ -72,8 +92,16 @@ class ExportAttributes extends utils_1.PersonalizationAdapter {
|
|
|
72
92
|
sanitizeAttribs() {
|
|
73
93
|
var _a, _b;
|
|
74
94
|
cli_utilities_1.log.debug(`Sanitizing ${((_a = this.attributes) === null || _a === void 0 ? void 0 : _a.length) || 0} attributes`, this.exportConfig.context);
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
this.attributes =
|
|
96
|
+
((_b = this.attributes) === null || _b === void 0 ? void 0 : _b.map((attribute, index) => {
|
|
97
|
+
const sanitizedAttribute = (0, omit_1.default)(attribute, this.attributesConfig.invalidKeys);
|
|
98
|
+
// Update progress for each processed attribute
|
|
99
|
+
if (this.progressManager) {
|
|
100
|
+
const processName = this.parentProgressManager ? constants_1.PROCESS_NAMES.ATTRIBUTES : undefined;
|
|
101
|
+
this.updateProgress(true, `attribute ${index + 1}/${this.attributes.length}: ${(attribute === null || attribute === void 0 ? void 0 : attribute.name) || (attribute === null || attribute === void 0 ? void 0 : attribute.uid) || 'unknown'}`, undefined, processName);
|
|
102
|
+
}
|
|
103
|
+
return sanitizedAttribute;
|
|
104
|
+
})) || [];
|
|
77
105
|
cli_utilities_1.log.debug(`Sanitization complete. Total attributes after sanitization: ${this.attributes.length}`, this.exportConfig.context);
|
|
78
106
|
}
|
|
79
107
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PersonalizationAdapter } from '../utils';
|
|
2
1
|
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
2
|
+
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportAudiences extends PersonalizationAdapter<ExportConfig> {
|
|
4
|
-
readonly exportConfig: ExportConfig;
|
|
5
4
|
private audiencesConfig;
|
|
6
5
|
private audiencesFolderPath;
|
|
7
6
|
private audiences;
|
|
7
|
+
exportConfig: ExportConfig;
|
|
8
8
|
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
package/lib/export/audiences.js
CHANGED
|
@@ -16,6 +16,7 @@ const omit_1 = __importDefault(require("lodash/omit"));
|
|
|
16
16
|
const node_path_1 = require("node:path");
|
|
17
17
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
18
18
|
const utils_1 = require("../utils");
|
|
19
|
+
const constants_1 = require("../utils/constants");
|
|
19
20
|
class ExportAudiences extends utils_1.PersonalizationAdapter {
|
|
20
21
|
constructor(exportConfig) {
|
|
21
22
|
super({
|
|
@@ -26,44 +27,61 @@ class ExportAudiences extends utils_1.PersonalizationAdapter {
|
|
|
26
27
|
this.exportConfig = exportConfig;
|
|
27
28
|
this.personalizeConfig = exportConfig.modules.personalize;
|
|
28
29
|
this.audiencesConfig = exportConfig.modules.audiences;
|
|
29
|
-
this.audiencesFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.personalizeConfig.dirName, this.audiencesConfig.dirName);
|
|
30
|
+
this.audiencesFolderPath = (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.audiencesConfig.dirName));
|
|
30
31
|
this.audiences = [];
|
|
31
|
-
this.exportConfig.context.module =
|
|
32
|
+
this.exportConfig.context.module = constants_1.MODULE_CONTEXTS.AUDIENCES;
|
|
32
33
|
}
|
|
33
34
|
start() {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
var _a
|
|
36
|
+
var _a;
|
|
36
37
|
try {
|
|
37
38
|
cli_utilities_1.log.debug('Starting audiences export process...', this.exportConfig.context);
|
|
38
39
|
cli_utilities_1.log.info('Starting audiences export', this.exportConfig.context);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
yield this.withLoadingSpinner('AUDIENCES: Initializing export and fetching data...', () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a;
|
|
42
|
+
cli_utilities_1.log.debug('Initializing personalization adapter...', this.exportConfig.context);
|
|
43
|
+
yield this.init();
|
|
44
|
+
cli_utilities_1.log.debug('Personalization adapter initialized successfully', this.exportConfig.context);
|
|
45
|
+
cli_utilities_1.log.debug(`Creating audiences directory at: ${this.audiencesFolderPath}`, this.exportConfig.context);
|
|
46
|
+
yield utils_1.fsUtil.makeDirectory(this.audiencesFolderPath);
|
|
47
|
+
cli_utilities_1.log.debug('Audiences directory created successfully', this.exportConfig.context);
|
|
48
|
+
cli_utilities_1.log.debug('Fetching audiences from personalization API...', this.exportConfig.context);
|
|
49
|
+
this.audiences = (yield this.getAudiences());
|
|
50
|
+
cli_utilities_1.log.debug(`Fetched ${((_a = this.audiences) === null || _a === void 0 ? void 0 : _a.length) || 0} audiences`, this.exportConfig.context);
|
|
51
|
+
}));
|
|
52
|
+
if (!((_a = this.audiences) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
49
53
|
cli_utilities_1.log.debug('No audiences found, completing export', this.exportConfig.context);
|
|
50
54
|
cli_utilities_1.log.info('No Audiences found with the given project!', this.exportConfig.context);
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
57
|
+
let progress;
|
|
58
|
+
if (this.parentProgressManager) {
|
|
59
|
+
progress = this.parentProgressManager;
|
|
60
|
+
this.progressManager = this.parentProgressManager;
|
|
61
|
+
progress.updateProcessTotal(constants_1.PROCESS_NAMES.AUDIENCES, this.audiences.length);
|
|
62
|
+
}
|
|
53
63
|
else {
|
|
54
|
-
|
|
55
|
-
this.sanitizeAttribs();
|
|
56
|
-
cli_utilities_1.log.debug('Audiences sanitization completed', this.exportConfig.context);
|
|
57
|
-
const audiencesFilePath = (0, node_path_1.resolve)(this.audiencesFolderPath, this.audiencesConfig.fileName);
|
|
58
|
-
cli_utilities_1.log.debug(`Writing audiences to: ${audiencesFilePath}`, this.exportConfig.context);
|
|
59
|
-
utils_1.fsUtil.writeFile(audiencesFilePath, this.audiences);
|
|
60
|
-
cli_utilities_1.log.debug('Audiences export completed successfully', this.exportConfig.context);
|
|
61
|
-
cli_utilities_1.log.success(`Audiences exported successfully! Total audiences: ${this.audiences.length}`, this.exportConfig.context);
|
|
62
|
-
return;
|
|
64
|
+
progress = this.createSimpleProgress(constants_1.PROCESS_NAMES.AUDIENCES, this.audiences.length);
|
|
63
65
|
}
|
|
66
|
+
cli_utilities_1.log.debug(`Processing ${this.audiences.length} audiences`, this.exportConfig.context);
|
|
67
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.AUDIENCES].EXPORTING, constants_1.PROCESS_NAMES.AUDIENCES);
|
|
68
|
+
this.sanitizeAttribs();
|
|
69
|
+
cli_utilities_1.log.debug('Audiences sanitization completed', this.exportConfig.context);
|
|
70
|
+
// Write audiences to file
|
|
71
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.AUDIENCES].EXPORTING, constants_1.PROCESS_NAMES.AUDIENCES);
|
|
72
|
+
const audiencesFilePath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.audiencesFolderPath), (0, cli_utilities_1.sanitizePath)(this.audiencesConfig.fileName));
|
|
73
|
+
cli_utilities_1.log.debug(`Writing audiences to: ${audiencesFilePath}`, this.exportConfig.context);
|
|
74
|
+
utils_1.fsUtil.writeFile(audiencesFilePath, this.audiences);
|
|
75
|
+
// Complete progress only if we're managing our own progress
|
|
76
|
+
if (!this.parentProgressManager) {
|
|
77
|
+
this.completeProgress(true);
|
|
78
|
+
}
|
|
79
|
+
cli_utilities_1.log.debug('Audiences export completed successfully', this.exportConfig.context);
|
|
80
|
+
cli_utilities_1.log.success(`Audiences exported successfully! Total audiences: ${this.audiences.length}`, this.exportConfig.context);
|
|
64
81
|
}
|
|
65
82
|
catch (error) {
|
|
66
83
|
cli_utilities_1.log.debug(`Error occurred during audiences export: ${error}`, this.exportConfig.context);
|
|
84
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Audiences export failed');
|
|
67
85
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
68
86
|
}
|
|
69
87
|
});
|
|
@@ -74,8 +92,16 @@ class ExportAudiences extends utils_1.PersonalizationAdapter {
|
|
|
74
92
|
sanitizeAttribs() {
|
|
75
93
|
var _a, _b;
|
|
76
94
|
cli_utilities_1.log.debug(`Sanitizing ${((_a = this.audiences) === null || _a === void 0 ? void 0 : _a.length) || 0} audiences`, this.exportConfig.context);
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
this.audiences =
|
|
96
|
+
((_b = this.audiences) === null || _b === void 0 ? void 0 : _b.map((audience, index) => {
|
|
97
|
+
const sanitizedAudience = (0, omit_1.default)(audience, this.audiencesConfig.invalidKeys);
|
|
98
|
+
// Update progress for each processed audience
|
|
99
|
+
if (this.progressManager) {
|
|
100
|
+
const processName = this.parentProgressManager ? constants_1.PROCESS_NAMES.AUDIENCES : undefined;
|
|
101
|
+
this.updateProgress(true, `audience ${index + 1}/${this.audiences.length}: ${audience.name || audience.uid || 'unknown'}`, undefined, processName);
|
|
102
|
+
}
|
|
103
|
+
return sanitizedAudience;
|
|
104
|
+
})) || [];
|
|
79
105
|
cli_utilities_1.log.debug(`Sanitization complete. Total audiences after sanitization: ${this.audiences.length}`, this.exportConfig.context);
|
|
80
106
|
}
|
|
81
107
|
}
|
package/lib/export/events.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { PersonalizationAdapter } from '../utils';
|
|
2
1
|
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
2
|
+
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportEvents extends PersonalizationAdapter<ExportConfig> {
|
|
4
|
-
readonly exportConfig: ExportConfig;
|
|
5
4
|
private eventsConfig;
|
|
6
5
|
private eventsFolderPath;
|
|
7
6
|
private events;
|
|
7
|
+
exportConfig: ExportConfig;
|
|
8
8
|
personalizeConfig: PersonalizeConfig;
|
|
9
9
|
constructor(exportConfig: ExportConfig);
|
|
10
10
|
start(): Promise<void>;
|
package/lib/export/events.js
CHANGED
|
@@ -16,6 +16,7 @@ const omit_1 = __importDefault(require("lodash/omit"));
|
|
|
16
16
|
const node_path_1 = require("node:path");
|
|
17
17
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
18
18
|
const utils_1 = require("../utils");
|
|
19
|
+
const constants_1 = require("../utils/constants");
|
|
19
20
|
class ExportEvents extends utils_1.PersonalizationAdapter {
|
|
20
21
|
constructor(exportConfig) {
|
|
21
22
|
super({
|
|
@@ -26,44 +27,64 @@ class ExportEvents extends utils_1.PersonalizationAdapter {
|
|
|
26
27
|
this.exportConfig = exportConfig;
|
|
27
28
|
this.personalizeConfig = exportConfig.modules.personalize;
|
|
28
29
|
this.eventsConfig = exportConfig.modules.events;
|
|
29
|
-
this.eventsFolderPath = (0, node_path_1.resolve)(exportConfig.data, exportConfig.branchName || '', this.personalizeConfig.dirName, this.eventsConfig.dirName);
|
|
30
|
+
this.eventsFolderPath = (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.eventsConfig.dirName));
|
|
30
31
|
this.events = [];
|
|
31
|
-
this.exportConfig.context.module =
|
|
32
|
+
this.exportConfig.context.module = constants_1.MODULE_CONTEXTS.EVENTS;
|
|
32
33
|
}
|
|
33
34
|
start() {
|
|
34
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
var _a
|
|
36
|
+
var _a;
|
|
36
37
|
try {
|
|
37
38
|
cli_utilities_1.log.debug('Starting events export process...', this.exportConfig.context);
|
|
38
39
|
cli_utilities_1.log.info('Starting events export', this.exportConfig.context);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
yield this.withLoadingSpinner('EVENTS: Initializing export and fetching data...', () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a;
|
|
42
|
+
cli_utilities_1.log.debug('Initializing personalization adapter...', this.exportConfig.context);
|
|
43
|
+
yield this.init();
|
|
44
|
+
cli_utilities_1.log.debug('Personalization adapter initialized successfully', this.exportConfig.context);
|
|
45
|
+
cli_utilities_1.log.debug(`Creating events directory at: ${this.eventsFolderPath}`, this.exportConfig.context);
|
|
46
|
+
yield utils_1.fsUtil.makeDirectory(this.eventsFolderPath);
|
|
47
|
+
cli_utilities_1.log.debug('Events directory created successfully', this.exportConfig.context);
|
|
48
|
+
cli_utilities_1.log.debug('Fetching events from personalization API...', this.exportConfig.context);
|
|
49
|
+
this.events = (yield this.getEvents());
|
|
50
|
+
cli_utilities_1.log.debug(`Fetched ${((_a = this.events) === null || _a === void 0 ? void 0 : _a.length) || 0} events`, this.exportConfig.context);
|
|
51
|
+
}));
|
|
52
|
+
if (!((_a = this.events) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
49
53
|
cli_utilities_1.log.debug('No events found, completing export', this.exportConfig.context);
|
|
50
54
|
cli_utilities_1.log.info('No Events found with the given project!', this.exportConfig.context);
|
|
51
55
|
return;
|
|
52
56
|
}
|
|
57
|
+
let progress;
|
|
58
|
+
if (this.parentProgressManager) {
|
|
59
|
+
progress = this.parentProgressManager;
|
|
60
|
+
this.progressManager = this.parentProgressManager;
|
|
61
|
+
progress.updateProcessTotal(constants_1.PROCESS_NAMES.EVENTS, this.events.length);
|
|
62
|
+
}
|
|
53
63
|
else {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
progress = this.createSimpleProgress(constants_1.PROCESS_NAMES.EVENTS, this.events.length);
|
|
65
|
+
}
|
|
66
|
+
cli_utilities_1.log.debug(`Processing ${this.events.length} events`, this.exportConfig.context);
|
|
67
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.EVENTS].EXPORTING, constants_1.PROCESS_NAMES.EVENTS);
|
|
68
|
+
this.sanitizeAttribs();
|
|
69
|
+
cli_utilities_1.log.debug('Events sanitization completed', this.exportConfig.context);
|
|
70
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.EVENTS].EXPORTING, constants_1.PROCESS_NAMES.EVENTS);
|
|
71
|
+
const eventsFilePath = (0, node_path_1.resolve)((0, cli_utilities_1.sanitizePath)(this.eventsFolderPath), (0, cli_utilities_1.sanitizePath)(this.eventsConfig.fileName));
|
|
72
|
+
cli_utilities_1.log.debug(`Writing events to: ${eventsFilePath}`, this.exportConfig.context);
|
|
73
|
+
utils_1.fsUtil.writeFile(eventsFilePath, this.events);
|
|
74
|
+
// Final progress update
|
|
75
|
+
if (this.progressManager) {
|
|
76
|
+
//this.updateProgress(true, `${this.events.length} events exported`, undefined, processName);
|
|
63
77
|
}
|
|
78
|
+
// Complete progress only if we're managing our own progress
|
|
79
|
+
if (!this.parentProgressManager) {
|
|
80
|
+
this.completeProgress(true);
|
|
81
|
+
}
|
|
82
|
+
cli_utilities_1.log.debug('Events export completed successfully', this.exportConfig.context);
|
|
83
|
+
cli_utilities_1.log.success(`Events exported successfully! Total events: ${this.events.length}`, this.exportConfig.context);
|
|
64
84
|
}
|
|
65
85
|
catch (error) {
|
|
66
86
|
cli_utilities_1.log.debug(`Error occurred during events export: ${error}`, this.exportConfig.context);
|
|
87
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Events export failed');
|
|
67
88
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
68
89
|
}
|
|
69
90
|
});
|
|
@@ -74,8 +95,15 @@ class ExportEvents extends utils_1.PersonalizationAdapter {
|
|
|
74
95
|
sanitizeAttribs() {
|
|
75
96
|
var _a, _b;
|
|
76
97
|
cli_utilities_1.log.debug(`Sanitizing ${((_a = this.events) === null || _a === void 0 ? void 0 : _a.length) || 0} events`, this.exportConfig.context);
|
|
77
|
-
|
|
78
|
-
|
|
98
|
+
this.events =
|
|
99
|
+
((_b = this.events) === null || _b === void 0 ? void 0 : _b.map((event, index) => {
|
|
100
|
+
const sanitizedEvent = (0, omit_1.default)(event, this.eventsConfig.invalidKeys);
|
|
101
|
+
if (this.progressManager) {
|
|
102
|
+
const processName = this.parentProgressManager ? constants_1.PROCESS_NAMES.EVENTS : undefined;
|
|
103
|
+
this.updateProgress(true, `event ${index + 1}/${this.events.length}: ${event.key || event.name || event.uid || 'unknown'}`, undefined, processName);
|
|
104
|
+
}
|
|
105
|
+
return sanitizedEvent;
|
|
106
|
+
})) || [];
|
|
79
107
|
cli_utilities_1.log.debug(`Sanitization complete. Total events after sanitization: ${this.events.length}`, this.exportConfig.context);
|
|
80
108
|
}
|
|
81
109
|
}
|
|
@@ -45,6 +45,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
47
47
|
const utils_1 = require("../utils");
|
|
48
|
+
const constants_1 = require("../utils/constants");
|
|
48
49
|
class ExportExperiences extends utils_1.PersonalizationAdapter {
|
|
49
50
|
constructor(exportConfig) {
|
|
50
51
|
super({
|
|
@@ -59,98 +60,130 @@ class ExportExperiences extends utils_1.PersonalizationAdapter {
|
|
|
59
60
|
this.exportConfig = exportConfig;
|
|
60
61
|
this.personalizeConfig = exportConfig.modules.personalize;
|
|
61
62
|
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');
|
|
62
|
-
this.exportConfig.context.module =
|
|
63
|
+
this.exportConfig.context.module = constants_1.MODULE_CONTEXTS.EXPERIENCES;
|
|
63
64
|
}
|
|
64
65
|
start() {
|
|
65
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
67
|
var _a, _b, _c;
|
|
67
68
|
try {
|
|
68
|
-
// get all experiences
|
|
69
|
-
// loop through experiences and get content types attached to it
|
|
70
|
-
// write experiences in to a file
|
|
71
69
|
cli_utilities_1.log.debug('Starting experiences export process...', this.exportConfig.context);
|
|
72
70
|
cli_utilities_1.log.info('Starting experiences export', this.exportConfig.context);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
71
|
+
const { experiences } = yield this.withLoadingSpinner('EXPERIENCES: Initializing export and fetching data...', () => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
cli_utilities_1.log.debug('Initializing personalization adapter...', this.exportConfig.context);
|
|
73
|
+
yield this.init();
|
|
74
|
+
cli_utilities_1.log.debug('Personalization adapter initialized successfully', this.exportConfig.context);
|
|
75
|
+
cli_utilities_1.log.debug(`Creating experiences directory at: ${this.experiencesFolderPath}`, this.exportConfig.context);
|
|
76
|
+
yield utils_1.fsUtil.makeDirectory(this.experiencesFolderPath);
|
|
77
|
+
cli_utilities_1.log.debug('Experiences directory created successfully', this.exportConfig.context);
|
|
78
|
+
const versionsDirPath = path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'versions');
|
|
79
|
+
cli_utilities_1.log.debug(`Creating versions directory at: ${versionsDirPath}`, this.exportConfig.context);
|
|
80
|
+
yield utils_1.fsUtil.makeDirectory(versionsDirPath);
|
|
81
|
+
cli_utilities_1.log.debug('Versions directory created successfully', this.exportConfig.context);
|
|
82
|
+
cli_utilities_1.log.debug('Fetching experiences from personalization API...', this.exportConfig.context);
|
|
83
|
+
const experiences = (yield this.getExperiences()) || [];
|
|
84
|
+
cli_utilities_1.log.debug(`Fetched ${(experiences === null || experiences === void 0 ? void 0 : experiences.length) || 0} experiences`, this.exportConfig.context);
|
|
85
|
+
return { experiences };
|
|
86
|
+
}));
|
|
86
87
|
if (!experiences || (experiences === null || experiences === void 0 ? void 0 : experiences.length) < 1) {
|
|
87
88
|
cli_utilities_1.log.debug('No experiences found, completing export', this.exportConfig.context);
|
|
88
89
|
cli_utilities_1.log.info('No Experiences found with the given project!', this.exportConfig.context);
|
|
89
90
|
return;
|
|
90
91
|
}
|
|
92
|
+
let progress;
|
|
93
|
+
const processName = constants_1.PROCESS_NAMES.EXPERIENCES;
|
|
94
|
+
if (this.parentProgressManager) {
|
|
95
|
+
progress = this.parentProgressManager;
|
|
96
|
+
this.progressManager = this.parentProgressManager;
|
|
97
|
+
progress.updateProcessTotal(processName, experiences.length);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// Create our own progress for standalone execution
|
|
101
|
+
progress = this.createSimpleProgress(constants_1.PROCESS_NAMES.EXPERIENCES, experiences.length);
|
|
102
|
+
}
|
|
103
|
+
cli_utilities_1.log.debug(`Processing ${experiences.length} experiences`, this.exportConfig.context);
|
|
104
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.EXPERIENCES].EXPORTING, processName);
|
|
91
105
|
const experiencesFilePath = path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'experiences.json');
|
|
92
106
|
cli_utilities_1.log.debug(`Writing experiences to: ${experiencesFilePath}`, this.exportConfig.context);
|
|
93
107
|
utils_1.fsUtil.writeFile(experiencesFilePath, experiences);
|
|
94
108
|
const experienceToVariantsStrList = [];
|
|
95
109
|
const experienceToContentTypesMap = {};
|
|
96
110
|
cli_utilities_1.log.debug(`Processing ${experiences.length} experiences for variants and content types`, this.exportConfig.context);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
let variants = (_b = (_a = experience === null || experience === void 0 ? void 0 : experience._cms) === null || _a === void 0 ? void 0 : _a.variants) !== null && _b !== void 0 ? _b : {};
|
|
101
|
-
cli_utilities_1.log.debug(`Found ${Object.keys(variants).length} variants for experience: ${experience.name}`, this.exportConfig.context);
|
|
102
|
-
Object.keys(variants).forEach((variantShortId) => {
|
|
103
|
-
const experienceToVariantsStr = `${experience.uid}-${variantShortId}-${variants[variantShortId]}`;
|
|
104
|
-
experienceToVariantsStrList.push(experienceToVariantsStr);
|
|
105
|
-
cli_utilities_1.log.debug(`Added variant mapping: ${experienceToVariantsStr}`, this.exportConfig.context);
|
|
106
|
-
});
|
|
111
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.EXPERIENCES].EXPORTING, processName);
|
|
112
|
+
for (let experienceIndex = 0; experienceIndex < experiences.length; experienceIndex++) {
|
|
113
|
+
const experience = experiences[experienceIndex];
|
|
107
114
|
try {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
cli_utilities_1.log.debug(`Processing experience: ${experience.name} (${experience.uid}) - ${experienceIndex + 1}/${experiences.length}`, this.exportConfig.context);
|
|
116
|
+
// create id mapper for experience to variants
|
|
117
|
+
let variants = (_b = (_a = experience === null || experience === void 0 ? void 0 : experience._cms) === null || _a === void 0 ? void 0 : _a.variants) !== null && _b !== void 0 ? _b : {};
|
|
118
|
+
// talisman-ignore-start
|
|
119
|
+
cli_utilities_1.log.debug(`Found ${Object.keys(variants).length} variants for experience: ${experience.name}`, this.exportConfig.context);
|
|
120
|
+
// talisman-ignore-end
|
|
121
|
+
// talisman-ignore-start
|
|
122
|
+
Object.keys(variants).forEach((variantShortId) => {
|
|
123
|
+
const experienceToVariantsStr = `${experience.uid}-${variantShortId}-${variants[variantShortId]}`;
|
|
124
|
+
experienceToVariantsStrList.push(experienceToVariantsStr);
|
|
125
|
+
cli_utilities_1.log.debug(`Added variant mapping: ${experienceToVariantsStr}`, this.exportConfig.context);
|
|
126
|
+
});
|
|
127
|
+
// talisman-ignore-end
|
|
128
|
+
// Fetch versions of experience
|
|
129
|
+
try {
|
|
130
|
+
cli_utilities_1.log.debug(`Fetching versions for experience: ${experience.name}`, this.exportConfig.context);
|
|
131
|
+
const experienceVersions = (yield this.getExperienceVersions(experience.uid)) || [];
|
|
132
|
+
cli_utilities_1.log.debug(`Fetched ${experienceVersions.length} versions for experience: ${experience.name}`, this.exportConfig.context);
|
|
133
|
+
if (experienceVersions.length > 0) {
|
|
134
|
+
const versionsFilePath = path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'versions', `${experience.uid}.json`);
|
|
135
|
+
cli_utilities_1.log.debug(`Writing experience versions to: ${versionsFilePath}`, this.exportConfig.context);
|
|
136
|
+
utils_1.fsUtil.writeFile(versionsFilePath, experienceVersions);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
cli_utilities_1.log.debug(`No versions found for experience: ${experience.name}`, this.exportConfig.context);
|
|
140
|
+
cli_utilities_1.log.info(`No versions found for experience '${experience.name}'`, this.exportConfig.context);
|
|
141
|
+
}
|
|
116
142
|
}
|
|
117
|
-
|
|
118
|
-
cli_utilities_1.log.debug(`
|
|
119
|
-
cli_utilities_1.
|
|
143
|
+
catch (error) {
|
|
144
|
+
cli_utilities_1.log.debug(`Error occurred while fetching versions for experience: ${experience.name}`, this.exportConfig.context);
|
|
145
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to fetch versions of experience ${experience.name}`);
|
|
120
146
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
experienceToContentTypesMap[experience.uid] = variantGroup.content_types;
|
|
147
|
+
// Fetch content types of experience
|
|
148
|
+
try {
|
|
149
|
+
cli_utilities_1.log.debug(`Fetching variant group for experience: ${experience.name}`, this.exportConfig.context);
|
|
150
|
+
const { variant_groups: [variantGroup] = [] } = (yield this.getVariantGroup({ experienceUid: experience.uid })) || {};
|
|
151
|
+
if ((_c = variantGroup === null || variantGroup === void 0 ? void 0 : variantGroup.content_types) === null || _c === void 0 ? void 0 : _c.length) {
|
|
152
|
+
cli_utilities_1.log.debug(`Found ${variantGroup.content_types.length} content types for experience: ${experience.name}`, this.exportConfig.context);
|
|
153
|
+
experienceToContentTypesMap[experience.uid] = variantGroup.content_types;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
cli_utilities_1.log.debug(`No content types found for experience: ${experience.name}`, this.exportConfig.context);
|
|
157
|
+
}
|
|
133
158
|
}
|
|
134
|
-
|
|
135
|
-
cli_utilities_1.log.debug(`
|
|
159
|
+
catch (error) {
|
|
160
|
+
cli_utilities_1.log.debug(`Error occurred while fetching content types for experience: ${experience.name}`, this.exportConfig.context);
|
|
161
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to fetch content types of experience ${experience.name}`);
|
|
136
162
|
}
|
|
137
163
|
}
|
|
138
164
|
catch (error) {
|
|
139
|
-
cli_utilities_1.log.debug(`Error occurred while
|
|
140
|
-
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to
|
|
165
|
+
cli_utilities_1.log.debug(`Error occurred while processing experience: ${experience.name}`, this.exportConfig.context);
|
|
166
|
+
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context), `Failed to process experience ${experience.name}`);
|
|
141
167
|
}
|
|
142
168
|
}
|
|
169
|
+
progress.updateStatus(constants_1.EXPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.EXPERIENCES].EXPORTING, processName);
|
|
170
|
+
// Write final mapping files
|
|
143
171
|
const variantsIdsFilePath = path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'experiences-variants-ids.json');
|
|
144
172
|
cli_utilities_1.log.debug(`Writing experience variants mapping to: ${variantsIdsFilePath}`, this.exportConfig.context);
|
|
145
173
|
utils_1.fsUtil.writeFile(variantsIdsFilePath, experienceToVariantsStrList);
|
|
146
174
|
const contentTypesFilePath = path.resolve((0, cli_utilities_1.sanitizePath)(this.experiencesFolderPath), 'experiences-content-types.json');
|
|
147
175
|
cli_utilities_1.log.debug(`Writing experience content types mapping to: ${contentTypesFilePath}`, this.exportConfig.context);
|
|
148
176
|
utils_1.fsUtil.writeFile(contentTypesFilePath, experienceToContentTypesMap);
|
|
177
|
+
// Complete progress only if we're managing our own progress
|
|
178
|
+
if (!this.parentProgressManager) {
|
|
179
|
+
this.completeProgress(true);
|
|
180
|
+
}
|
|
149
181
|
cli_utilities_1.log.debug('Experiences export completed successfully', this.exportConfig.context);
|
|
150
182
|
cli_utilities_1.log.success('Experiences exported successfully!', this.exportConfig.context);
|
|
151
183
|
}
|
|
152
184
|
catch (error) {
|
|
153
185
|
cli_utilities_1.log.debug(`Error occurred during experiences export: ${error}`, this.exportConfig.context);
|
|
186
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Experiences export failed');
|
|
154
187
|
(0, cli_utilities_1.handleAndLogError)(error, Object.assign({}, this.exportConfig.context));
|
|
155
188
|
}
|
|
156
189
|
});
|
package/lib/export/projects.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PersonalizeConfig, ExportConfig } from '../types';
|
|
2
2
|
import { PersonalizationAdapter } from '../utils';
|
|
3
3
|
export default class ExportProjects extends PersonalizationAdapter<ExportConfig> {
|
|
4
|
-
private
|
|
4
|
+
private projectsFolderPath;
|
|
5
|
+
private projectsData;
|
|
5
6
|
exportConfig: ExportConfig;
|
|
6
7
|
personalizeConfig: PersonalizeConfig;
|
|
7
8
|
constructor(exportConfig: ExportConfig);
|