@contentstack/cli-variants 2.0.0-beta.5 → 2.0.0-beta.8

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.
@@ -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
- updateAudiences(expVariations.audiences, audiencesUid);
63
- if (!expVariations.audiences.length) {
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 (((_e = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _e === void 0 ? void 0 : _e.hasOwnProperty('audience')) && ((_h = (_g = (_f = experience === null || experience === void 0 ? void 0 : experience.targeting) === null || _f === void 0 ? void 0 : _f.audience) === null || _g === void 0 ? void 0 : _g.audiences) === null || _h === void 0 ? void 0 : _h.length)) {
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,14 +1,15 @@
1
1
  {
2
2
  "name": "@contentstack/cli-variants",
3
- "version": "2.0.0-beta.5",
3
+ "version": "2.0.0-beta.8",
4
4
  "description": "Variants plugin",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "scripts": {
8
+ "build": "pnpm compile",
8
9
  "prepack": "pnpm compile",
9
10
  "compile": "tsc -b tsconfig.json",
10
11
  "test": "mocha --require ts-node/register --forbid-only \"test/**/*.test.ts\"",
11
- "clean": "rm -rf ./lib ./node_modules tsconfig.build.tsbuildinfo",
12
+ "clean": "rm -rf ./lib ./node_modules tsconfig.tsbuildinfo",
12
13
  "test:unit:report": "nyc --extension .ts mocha --require ts-node/register --forbid-only \"test/unit/**/*.test.ts\""
13
14
  },
14
15
  "keywords": [
@@ -17,7 +18,7 @@
17
18
  "author": "antony.raj@contentstack.com",
18
19
  "license": "MIT",
19
20
  "devDependencies": {
20
- "@contentstack/cli-dev-dependencies": "^1.3.0",
21
+ "@contentstack/cli-dev-dependencies": "^2.0.0-beta.0",
21
22
  "@oclif/plugin-help": "^6.2.28",
22
23
  "@oclif/test": "^4.1.13",
23
24
  "@types/node": "^20.17.50",
@@ -27,11 +28,11 @@
27
28
  "typescript": "^5.8.3"
28
29
  },
29
30
  "dependencies": {
30
- "@contentstack/cli-utilities": "~2.0.0-beta",
31
+ "@contentstack/cli-utilities": "~2.0.0-beta.2",
31
32
  "@oclif/core": "^4.3.0",
32
33
  "@oclif/plugin-help": "^6.2.28",
33
34
  "lodash": "^4.17.23",
34
35
  "mkdirp": "^1.0.4",
35
36
  "winston": "^3.17.0"
36
37
  }
37
- }
38
+ }
@@ -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.length} audiences in SegmentedVariant`);
70
- updateAudiences(expVariations.audiences, audiencesUid);
71
-
72
- if (!expVariations.audiences.length) {
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
  }