@ninetailed/experience.js-plugin-preview 7.17.4 → 7.17.5

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.
Files changed (3) hide show
  1. package/index.cjs.js +37 -23
  2. package/index.esm.js +48 -27
  3. package/package.json +5 -5
package/index.cjs.js CHANGED
@@ -230,21 +230,20 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
230
230
  // Handle entry replacements as before
231
231
  const entryReplacementComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
232
232
  const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
233
- // Get the selected variant index
234
233
  const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
235
- // Handle variable components for this experience (NEW CODE)
236
- if (variantIndex !== undefined) {
237
- // Process all variable components for this experience
234
+ // Natural evaluation should not create overwrites, letting the core SDK handle variable evaluation
235
+ if (variantIndex !== undefined && this.experienceVariantIndexOverwrites[experience.id] !== undefined) {
236
+ // Only set variable overwrites when there's an explicit preview override for this experience
238
237
  const variableComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.InlineVariable);
239
238
  // Set variable values based on the selected variant index
240
239
  variableComponents.forEach(component => {
241
240
  const key = component.key;
242
241
  let value;
243
242
  if (variantIndex === 0) {
244
- value = component.baseline;
243
+ value = component.baseline.value;
245
244
  } else {
246
245
  const variant = component.variants[variantIndex - 1];
247
- value = variant && 'value' in variant ? variant.value : component.baseline;
246
+ value = variant && 'value' in variant ? variant.value : component.baseline.value;
248
247
  }
249
248
  // Set the variable in our changes system
250
249
  this.setVariableValue({
@@ -398,29 +397,28 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
398
397
  experience_jsShared.logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
399
398
  return;
400
399
  }
401
- this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
402
- return !this.experiences.filter(experience => {
403
- var _b;
404
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
405
- }).map(experience => experience.id).includes(key);
406
- }).reduce((acc, [key, value]) => {
407
- return Object.assign(Object.assign({}, acc), {
408
- [key]: value
409
- });
410
- }, {});
411
- this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
412
- [id]: false
413
- });
414
- this.onChange();
415
- this.experiences.filter(experience => {
400
+ // Identify all experiences that belong to this audience
401
+ const experiencesToReset = this.experiences.filter(experience => {
416
402
  var _b;
417
403
  return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
418
- }).forEach(experience => {
404
+ });
405
+ // 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
406
+ experiencesToReset.forEach(experience => {
419
407
  this.setExperienceVariant({
420
408
  experienceId: experience.id,
421
409
  variantIndex: 0
422
410
  });
423
411
  });
412
+ // 2. Remove experience variant index overwrites for these experiences
413
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
414
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
415
+ // 3. Remove any variable overwrites that were set for these experiences (prevents being stuck on a variant value)
416
+ if (experienceIdsToReset.length > 0) {
417
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
418
+ var _b;
419
+ return !(((_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId) && experienceIdsToReset.includes(change.meta.experienceId));
420
+ }));
421
+ }
424
422
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
425
423
  [id]: false
426
424
  });
@@ -434,6 +432,22 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
434
432
  experience_jsShared.logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
435
433
  return;
436
434
  }
435
+ // Identify all experiences that belong to this audience
436
+ const experiencesToReset = this.experiences.filter(experience => {
437
+ var _b;
438
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
439
+ });
440
+ if (experiencesToReset.length > 0) {
441
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
442
+ // 1. Clear any variable overwrites that were set for these experiences (allows natural evaluation)
443
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
444
+ var _b;
445
+ return !(((_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId) && experienceIdsToReset.includes(change.meta.experienceId));
446
+ }));
447
+ // 2. Clear experience variant index overwrites for these experiences (allows natural variant selection)
448
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
449
+ }
450
+ // 3. Remove audience override (allows natural audience evaluation)
437
451
  const _b = this.audienceOverwrites,
438
452
  _c = id;
439
453
  _b[_c];
@@ -557,7 +571,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
557
571
  get pluginApi() {
558
572
  var _b;
559
573
  return {
560
- version: "7.17.4" ,
574
+ version: "7.17.5" ,
561
575
  open: this.open.bind(this),
562
576
  close: this.close.bind(this),
563
577
  toggle: this.toggle.bind(this),
package/index.esm.js CHANGED
@@ -203,13 +203,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
203
203
  // Handle entry replacements as before
204
204
  const entryReplacementComponents = experience.components.filter(component => component.type === ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
205
205
  const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
206
-
207
- // Get the selected variant index
208
206
  const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
209
207
 
210
- // Handle variable components for this experience (NEW CODE)
211
- if (variantIndex !== undefined) {
212
- // Process all variable components for this experience
208
+ // Natural evaluation should not create overwrites, letting the core SDK handle variable evaluation
209
+ if (variantIndex !== undefined && this.experienceVariantIndexOverwrites[experience.id] !== undefined) {
210
+ // Only set variable overwrites when there's an explicit preview override for this experience
213
211
  const variableComponents = experience.components.filter(component => component.type === ComponentTypeEnum.InlineVariable);
214
212
 
215
213
  // Set variable values based on the selected variant index
@@ -217,10 +215,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
217
215
  const key = component.key;
218
216
  let value;
219
217
  if (variantIndex === 0) {
220
- value = component.baseline;
218
+ value = component.baseline.value;
221
219
  } else {
222
220
  const variant = component.variants[variantIndex - 1];
223
- value = variant && 'value' in variant ? variant.value : component.baseline;
221
+ value = variant && 'value' in variant ? variant.value : component.baseline.value;
224
222
  }
225
223
 
226
224
  // Set the variable in our changes system
@@ -380,29 +378,32 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
380
378
  logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
381
379
  return;
382
380
  }
383
- this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
384
- return !this.experiences.filter(experience => {
385
- var _experience$audience2;
386
- return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
387
- }).map(experience => experience.id).includes(key);
388
- }).reduce((acc, [key, value]) => {
389
- return Object.assign({}, acc, {
390
- [key]: value
391
- });
392
- }, {});
393
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
394
- [id]: false
381
+
382
+ // Identify all experiences that belong to this audience
383
+ const experiencesToReset = this.experiences.filter(experience => {
384
+ var _experience$audience2;
385
+ return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
395
386
  });
396
- this.onChange();
397
- this.experiences.filter(experience => {
398
- var _experience$audience3;
399
- return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
400
- }).forEach(experience => {
387
+
388
+ // 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
389
+ experiencesToReset.forEach(experience => {
401
390
  this.setExperienceVariant({
402
391
  experienceId: experience.id,
403
392
  variantIndex: 0
404
393
  });
405
394
  });
395
+
396
+ // 2. Remove experience variant index overwrites for these experiences
397
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
398
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
399
+
400
+ // 3. Remove any variable overwrites that were set for these experiences (prevents being stuck on a variant value)
401
+ if (experienceIdsToReset.length > 0) {
402
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
403
+ var _change$meta;
404
+ return !((_change$meta = change.meta) != null && _change$meta.experienceId && experienceIdsToReset.includes(change.meta.experienceId));
405
+ }));
406
+ }
406
407
  this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
407
408
  [id]: false
408
409
  });
@@ -416,6 +417,26 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
416
417
  logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
417
418
  return;
418
419
  }
420
+
421
+ // Identify all experiences that belong to this audience
422
+ const experiencesToReset = this.experiences.filter(experience => {
423
+ var _experience$audience3;
424
+ return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
425
+ });
426
+ if (experiencesToReset.length > 0) {
427
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
428
+
429
+ // 1. Clear any variable overwrites that were set for these experiences (allows natural evaluation)
430
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
431
+ var _change$meta2;
432
+ return !((_change$meta2 = change.meta) != null && _change$meta2.experienceId && experienceIdsToReset.includes(change.meta.experienceId));
433
+ }));
434
+
435
+ // 2. Clear experience variant index overwrites for these experiences (allows natural variant selection)
436
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
437
+ }
438
+
439
+ // 3. Remove audience override (allows natural audience evaluation)
419
440
  const _this$audienceOverwri = this.audienceOverwrites,
420
441
  audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
421
442
  this.audienceOverwrites = audienceOverwrites;
@@ -543,7 +564,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
543
564
  get pluginApi() {
544
565
  var _this$profile;
545
566
  return {
546
- version: "7.17.4" ,
567
+ version: "7.17.5" ,
547
568
  open: this.open.bind(this),
548
569
  close: this.close.bind(this),
549
570
  toggle: this.toggle.bind(this),
@@ -646,9 +667,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
646
667
 
647
668
  // Filter out changes that we're overriding
648
669
  const filteredChanges = inputChanges.filter(change => {
649
- var _change$meta;
670
+ var _change$meta3;
650
671
  if (change.type !== ChangeTypes.Variable) return true;
651
- const changeKey = (_change$meta = change.meta) != null && _change$meta.experienceId ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
672
+ const changeKey = (_change$meta3 = change.meta) != null && _change$meta3.experienceId ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
652
673
  return !this.variableOverwrites[changeKey];
653
674
  });
654
675
  const effectiveChanges = [...filteredChanges, ...Object.values(this.variableOverwrites)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "7.17.4",
3
+ "version": "7.17.5",
4
4
  "description": "Ninetailed SDK plugin for preview",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -15,10 +15,10 @@
15
15
  "a/b testing"
16
16
  ],
17
17
  "dependencies": {
18
- "@ninetailed/experience.js-shared": "7.17.4",
19
- "@ninetailed/experience.js": "7.17.4",
20
- "@ninetailed/experience.js-preview-bridge": "7.17.4",
21
- "@ninetailed/experience.js-plugin-analytics": "7.17.4",
18
+ "@ninetailed/experience.js-shared": "7.17.5",
19
+ "@ninetailed/experience.js": "7.17.5",
20
+ "@ninetailed/experience.js-preview-bridge": "7.17.5",
21
+ "@ninetailed/experience.js-plugin-analytics": "7.17.5",
22
22
  "radash": "10.9.0"
23
23
  },
24
24
  "module": "./index.esm.js",