@contentstack/cli-variants 2.0.0-beta.5 → 2.0.0-beta.7
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/import/audiences.js
CHANGED
|
@@ -39,7 +39,7 @@ class Audiences extends utils_1.PersonalizationAdapter {
|
|
|
39
39
|
*/
|
|
40
40
|
import() {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
var _a, _b;
|
|
42
|
+
var _a, _b, _c;
|
|
43
43
|
try {
|
|
44
44
|
cli_utilities_1.log.debug('Starting audiences import...', this.config.context);
|
|
45
45
|
const [canImport, audiencesCount] = yield this.analyzeAudiences();
|
|
@@ -73,9 +73,15 @@ class Audiences extends utils_1.PersonalizationAdapter {
|
|
|
73
73
|
progress.updateStatus(constants_1.IMPORT_PROCESS_STATUS[constants_1.PROCESS_NAMES.AUDIENCES].CREATING);
|
|
74
74
|
}
|
|
75
75
|
cli_utilities_1.log.debug(`Processing audience: ${name} (${uid})`, this.config.context);
|
|
76
|
+
// Skip Lytics audiences - they cannot be created via API (synced from Lytics)
|
|
77
|
+
if (((_a = audience.source) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === 'LYTICS') {
|
|
78
|
+
cli_utilities_1.log.debug(`Skipping Lytics audience: ${name} (${uid})`, this.config.context);
|
|
79
|
+
this.updateProgress(true, `audience: ${name} (skipped - Lytics)`, undefined, constants_1.PROCESS_NAMES.AUDIENCES);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
76
82
|
try {
|
|
77
83
|
//check whether reference attributes exists or not
|
|
78
|
-
if ((
|
|
84
|
+
if ((_b = definition === null || definition === void 0 ? void 0 : definition.rules) === null || _b === void 0 ? void 0 : _b.length) {
|
|
79
85
|
cli_utilities_1.log.debug(`Processing ${definition.rules.length} definition rules for audience: ${name}`, this.config.context);
|
|
80
86
|
definition.rules = (0, utils_1.lookUpAttributes)(definition.rules, attributesUid);
|
|
81
87
|
cli_utilities_1.log.debug(`Processed definition rules, remaining rules: ${definition.rules.length}`, this.config.context);
|
|
@@ -87,7 +93,7 @@ class Audiences extends utils_1.PersonalizationAdapter {
|
|
|
87
93
|
const audienceRes = yield this.createAudience({ definition, name, description });
|
|
88
94
|
//map old audience uid to new audience uid
|
|
89
95
|
//mapper file is used to check whether audience created or not before creating experience
|
|
90
|
-
this.audiencesUidMapper[uid] = (
|
|
96
|
+
this.audiencesUidMapper[uid] = (_c = audienceRes === null || audienceRes === void 0 ? void 0 : audienceRes.uid) !== null && _c !== void 0 ? _c : '';
|
|
91
97
|
this.updateProgress(true, `audience: ${name}`, undefined, constants_1.PROCESS_NAMES.AUDIENCES);
|
|
92
98
|
cli_utilities_1.log.debug(`Created audience: ${uid} -> ${audienceRes === null || audienceRes === void 0 ? void 0 : audienceRes.uid}`, this.config.context);
|
|
93
99
|
}
|
|
@@ -210,12 +210,16 @@ class Experiences extends utils_1.PersonalizationAdapter {
|
|
|
210
210
|
};
|
|
211
211
|
// Process each version and map them by status
|
|
212
212
|
versions.forEach((version) => {
|
|
213
|
+
var _a, _b, _c, _d;
|
|
213
214
|
let versionReqObj = (0, utils_1.lookUpAudiences)(version, this.audiencesUid);
|
|
214
215
|
versionReqObj = (0, utils_1.lookUpEvents)(version, this.eventsUid);
|
|
215
|
-
if (versionReqObj && versionReqObj.status) {
|
|
216
|
+
if (versionReqObj && versionReqObj.status && ((_b = (_a = versionReqObj.variants) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
216
217
|
versionMap[versionReqObj.status] = versionReqObj;
|
|
217
218
|
cli_utilities_1.log.debug(`Mapped version with status: ${versionReqObj.status}`, this.config.context);
|
|
218
219
|
}
|
|
220
|
+
else if ((versionReqObj === null || versionReqObj === void 0 ? void 0 : versionReqObj.status) && !((_d = (_c = versionReqObj.variants) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0)) {
|
|
221
|
+
cli_utilities_1.log.warn(`Skipping version ${versionReqObj.status}: no valid variants (all had unmapped Lytics audiences)`, this.config.context);
|
|
222
|
+
}
|
|
219
223
|
});
|
|
220
224
|
// Prioritize updating or creating versions based on the order: ACTIVE -> DRAFT -> PAUSE
|
|
221
225
|
return yield this.handleVersionUpdateOrCreate(experience, versionMap);
|
|
@@ -30,7 +30,7 @@ function updateAudiences(audiences, audiencesUid) {
|
|
|
30
30
|
* @returns
|
|
31
31
|
*/
|
|
32
32
|
const lookUpAudiences = (experience, audiencesUid) => {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
34
34
|
cli_utilities_1.log.debug('Starting audience lookup for experience');
|
|
35
35
|
cli_utilities_1.log.debug(`Available audience mappings: ${(_a = Object.keys(audiencesUid)) === null || _a === void 0 ? void 0 : _a.length}`);
|
|
36
36
|
// Update experience variations
|
|
@@ -57,10 +57,13 @@ const lookUpAudiences = (experience, audiencesUid) => {
|
|
|
57
57
|
for (let index = experience.variants.length - 1; index >= 0; index--) {
|
|
58
58
|
const expVariations = experience.variants[index];
|
|
59
59
|
cli_utilities_1.log.debug(`Processing variant ${index + 1}/${experience.variants.length} of type: ${expVariations['__type']}`);
|
|
60
|
-
if (expVariations['__type'] === 'SegmentedVariant' && ((_d = expVariations === null || expVariations === void 0 ? void 0 : expVariations.audiences) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
61
|
-
cli_utilities_1.log.debug(`Found ${expVariations.audiences.length} audiences in SegmentedVariant`);
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
if (expVariations['__type'] === 'SegmentedVariant' && (((_d = expVariations === null || expVariations === void 0 ? void 0 : expVariations.audiences) === null || _d === void 0 ? void 0 : _d.length) || ((_e = expVariations === null || expVariations === void 0 ? void 0 : expVariations.lyticsAudiences) === null || _e === void 0 ? void 0 : _e.length))) {
|
|
61
|
+
cli_utilities_1.log.debug(`Found ${(_g = (_f = expVariations.audiences) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0} audiences in SegmentedVariant`);
|
|
62
|
+
if ((_h = expVariations === null || expVariations === void 0 ? void 0 : expVariations.audiences) === null || _h === void 0 ? void 0 : _h.length)
|
|
63
|
+
updateAudiences(expVariations.audiences, audiencesUid);
|
|
64
|
+
if ((_j = expVariations === null || expVariations === void 0 ? void 0 : expVariations.lyticsAudiences) === null || _j === void 0 ? void 0 : _j.length)
|
|
65
|
+
updateAudiences(expVariations.lyticsAudiences, audiencesUid);
|
|
66
|
+
if (!(((_k = expVariations.audiences) === null || _k === void 0 ? void 0 : _k.length) || ((_l = expVariations === null || expVariations === void 0 ? void 0 : expVariations.lyticsAudiences) === null || _l === void 0 ? void 0 : _l.length))) {
|
|
64
67
|
cli_utilities_1.log.warn('No audiences remaining after mapping. Removing variant.');
|
|
65
68
|
experience.variants.splice(index, 1);
|
|
66
69
|
}
|
|
@@ -73,7 +76,7 @@ const lookUpAudiences = (experience, audiencesUid) => {
|
|
|
73
76
|
else {
|
|
74
77
|
cli_utilities_1.log.debug('No variations or variants found in experience');
|
|
75
78
|
}
|
|
76
|
-
if (((
|
|
79
|
+
if (((_m = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _m === void 0 ? void 0 : _m.hasOwnProperty('audience')) && ((_q = (_p = (_o = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _o === void 0 ? void 0 : _o.audience) === null || _p === void 0 ? void 0 : _p.audiences) === null || _q === void 0 ? void 0 : _q.length)) {
|
|
77
80
|
cli_utilities_1.log.debug(`Processing ${experience.targeting.audience.audiences.length} targeting audiences`);
|
|
78
81
|
// Update targeting audiences
|
|
79
82
|
updateAudiences(experience.targeting.audience.audiences, audiencesUid);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-variants",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.7",
|
|
4
4
|
"description": "Variants plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"typescript": "^5.8.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@contentstack/cli-utilities": "~2.0.0-beta",
|
|
30
|
+
"@contentstack/cli-utilities": "~2.0.0-beta.1",
|
|
31
31
|
"@oclif/core": "^4.3.0",
|
|
32
32
|
"@oclif/plugin-help": "^6.2.28",
|
|
33
33
|
"lodash": "^4.17.23",
|
package/src/import/audiences.ts
CHANGED
|
@@ -89,9 +89,16 @@ export default class Audiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
89
89
|
}
|
|
90
90
|
log.debug(`Processing audience: ${name} (${uid})`, this.config.context);
|
|
91
91
|
|
|
92
|
+
// Skip Lytics audiences - they cannot be created via API (synced from Lytics)
|
|
93
|
+
if ((audience as any).source?.toUpperCase() === 'LYTICS') {
|
|
94
|
+
log.debug(`Skipping Lytics audience: ${name} (${uid})`, this.config.context);
|
|
95
|
+
this.updateProgress(true, `audience: ${name} (skipped - Lytics)`, undefined, PROCESS_NAMES.AUDIENCES);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
92
99
|
try {
|
|
93
100
|
//check whether reference attributes exists or not
|
|
94
|
-
if (definition
|
|
101
|
+
if (definition?.rules?.length) {
|
|
95
102
|
log.debug(
|
|
96
103
|
`Processing ${definition.rules.length} definition rules for audience: ${name}`,
|
|
97
104
|
this.config.context,
|
|
@@ -272,9 +272,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
|
|
|
272
272
|
let versionReqObj = lookUpAudiences(version, this.audiencesUid) as CreateExperienceVersionInput;
|
|
273
273
|
versionReqObj = lookUpEvents(version, this.eventsUid) as CreateExperienceVersionInput;
|
|
274
274
|
|
|
275
|
-
if (versionReqObj && versionReqObj.status) {
|
|
275
|
+
if (versionReqObj && versionReqObj.status && (versionReqObj.variants?.length ?? 0) > 0) {
|
|
276
276
|
versionMap[versionReqObj.status] = versionReqObj;
|
|
277
277
|
log.debug(`Mapped version with status: ${versionReqObj.status}`, this.config.context);
|
|
278
|
+
} else if (versionReqObj?.status && !(versionReqObj.variants?.length ?? 0)) {
|
|
279
|
+
log.warn(`Skipping version ${versionReqObj.status}: no valid variants (all had unmapped Lytics audiences)`, this.config.context);
|
|
278
280
|
}
|
|
279
281
|
});
|
|
280
282
|
|
|
@@ -65,11 +65,11 @@ export const lookUpAudiences = (
|
|
|
65
65
|
const expVariations = experience.variants[index];
|
|
66
66
|
log.debug(`Processing variant ${index + 1}/${experience.variants.length} of type: ${expVariations['__type']}`);
|
|
67
67
|
|
|
68
|
-
if (expVariations['__type'] === 'SegmentedVariant' && expVariations?.audiences?.length) {
|
|
69
|
-
log.debug(`Found ${expVariations.audiences
|
|
70
|
-
updateAudiences(expVariations.audiences, audiencesUid);
|
|
71
|
-
|
|
72
|
-
if (!expVariations.audiences
|
|
68
|
+
if (expVariations['__type'] === 'SegmentedVariant' && (expVariations?.audiences?.length || expVariations?.lyticsAudiences?.length)) {
|
|
69
|
+
log.debug(`Found ${expVariations.audiences?.length ?? 0} audiences in SegmentedVariant`);
|
|
70
|
+
if (expVariations?.audiences?.length) updateAudiences(expVariations.audiences, audiencesUid);
|
|
71
|
+
if (expVariations?.lyticsAudiences?.length) updateAudiences(expVariations.lyticsAudiences, audiencesUid);
|
|
72
|
+
if (!(expVariations.audiences?.length || expVariations?.lyticsAudiences?.length)) {
|
|
73
73
|
log.warn('No audiences remaining after mapping. Removing variant.');
|
|
74
74
|
experience.variants.splice(index, 1);
|
|
75
75
|
}
|