Skip to content

Commit db01c8a

Browse files
committed
fix(personalize): filter lytics audiences in experience variants during import
1 parent 2d1ad10 commit db01c8a

File tree

12 files changed

+1351
-1413
lines changed

12 files changed

+1351
-1413
lines changed

.talismanrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 1b011574c5a640f7132f2dcabfced269cb497ddd3270524ec32abe3cb4a95cb5
3+
checksum: c91b9e5fba1c84c0b6de15ad2f8cce698a5c781c9db31bebb7a3ad63ee88d9e1
44
- filename: pnpm-lock.yaml
5-
checksum: 91ffcd3364bcbef7dad0d25547849a572dc9ebd004999c3ede85c7730959a2e5
5+
checksum: 8405d813bbcc584a7540542acfdbc27f5b8768da60354b7eff9f6cd93c3d832d
66
- filename: packages/contentstack-bootstrap/src/bootstrap/utils.ts
77
checksum: 6e6fb00bb11b03141e5ad27eeaa4af9718dc30520c3e73970bc208cc0ba2a7d2
88
version: '1.0'

package-lock.json

Lines changed: 575 additions & 674 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-export/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@contentstack/cli-command": "~1.7.2",
99
"@oclif/core": "^4.3.3",
10-
"@contentstack/cli-variants": "~1.3.7",
10+
"@contentstack/cli-variants": "~1.3.8",
1111
"@contentstack/cli-utilities": "~1.17.4",
1212
"async": "^3.2.6",
1313
"big-json": "^3.2.0",

packages/contentstack-import/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@contentstack/cli-audit": "~1.18.0",
99
"@contentstack/cli-command": "~1.7.2",
1010
"@contentstack/cli-utilities": "~1.17.4",
11-
"@contentstack/cli-variants": "~1.3.7",
11+
"@contentstack/cli-variants": "~1.3.8",
1212
"@oclif/core": "^4.3.0",
1313
"big-json": "^3.2.0",
1414
"bluebird": "^3.7.2",

packages/contentstack-variants/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-variants",
3-
"version": "1.3.7",
3+
"version": "1.3.8",
44
"description": "Variants plugin",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

packages/contentstack-variants/src/import/experiences.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ export default class Experiences extends PersonalizationAdapter<ImportConfig> {
203203
let versionReqObj = lookUpAudiences(version, this.audiencesUid) as CreateExperienceVersionInput;
204204
versionReqObj = lookUpEvents(version, this.eventsUid) as CreateExperienceVersionInput;
205205

206-
if (versionReqObj && versionReqObj.status) {
206+
if (versionReqObj && versionReqObj.status && (versionReqObj.variants?.length ?? 0) > 0) {
207207
versionMap[versionReqObj.status] = versionReqObj;
208208
log.debug(`Mapped version with status: ${versionReqObj.status}`, this.config.context);
209+
} else if (versionReqObj?.status && !(versionReqObj.variants?.length ?? 0)) {
210+
log.warn(`Skipping version ${versionReqObj.status}: no valid variants (all had unmapped Lytics audiences)`, this.config.context);
209211
}
210212
});
211213

packages/contentstack-variants/src/utils/audiences-helper.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export const lookUpAudiences = (
6565
const expVariations = experience.variants[index];
6666
log.debug(`Processing variant ${index + 1}/${experience.variants.length} of type: ${expVariations['__type']}`);
6767

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)) {
7373
log.warn('No audiences remaining after mapping. Removing variant.');
7474
experience.variants.splice(index, 1);
7575
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"contentstack-audience-001":"new-contentstack-uid","no-source-audience-001":"new-contentstack-uid"}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"uid": "contentstack-audience-001",
4+
"name": "Contentstack Test Audience",
5+
"description": "Audience with rules",
6+
"definition": {
7+
"__type": "RuleCombination",
8+
"combinationType": "AND",
9+
"rules": [
10+
{
11+
"__type": "Rule",
12+
"attribute": { "__type": "PresetAttributeReference", "ref": "DEVICE_TYPE" },
13+
"attributeMatchOptions": { "__type": "StringMatchOptions", "value": "MOBILE" },
14+
"attributeMatchCondition": "STRING_EQUALS",
15+
"invertCondition": false
16+
}
17+
]
18+
}
19+
},
20+
{
21+
"uid": "lytics-audience-001",
22+
"name": "Lytics Audience",
23+
"description": "From Lytics",
24+
"slug": "lytics_audience",
25+
"source": "LYTICS"
26+
},
27+
{
28+
"uid": "lytics-lowercase-001",
29+
"name": "Lytics Lowercase",
30+
"description": "source is lowercase",
31+
"slug": "lytics_lowercase",
32+
"source": "lytics"
33+
},
34+
{
35+
"uid": "no-source-audience-001",
36+
"name": "No Source Audience",
37+
"description": "Audience without source field",
38+
"definition": {
39+
"__type": "RuleCombination",
40+
"combinationType": "AND",
41+
"rules": []
42+
}
43+
}
44+
]

0 commit comments

Comments
 (0)