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

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/index.cjs.js CHANGED
@@ -191,7 +191,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
191
191
  * Returns a middleware function that applies variable overwrites to changes
192
192
  */
193
193
  this.getChangesModificationMiddleware = () => {
194
- if (!this.isActiveInstance || Object.keys(this.variableOverwrites).length === 0) {
194
+ if (!this.isActiveInstance || Object.keys(this.variableOverwrites).length === 0 && Object.keys(this.audienceOverwrites).length === 0) {
195
195
  return undefined;
196
196
  }
197
197
  return ({
@@ -202,9 +202,16 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
202
202
  changes: inputChanges
203
203
  };
204
204
  }
205
- // Calculate and return overridden changes on demand instead of storing them
205
+ const filteredChanges = inputChanges.filter(change => {
206
+ var _b, _c;
207
+ const experienceId = (_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId;
208
+ if (!experienceId) return true;
209
+ const experience = this.experiences.find(e => e.id === experienceId);
210
+ if (!((_c = experience === null || experience === void 0 ? void 0 : experience.audience) === null || _c === void 0 ? void 0 : _c.id)) return true;
211
+ return this.audienceOverwrites[experience.audience.id] !== false;
212
+ });
206
213
  return {
207
- changes: this.getEffectiveChanges(inputChanges)
214
+ changes: this.getEffectiveChanges(filteredChanges)
208
215
  };
209
216
  };
210
217
  };
@@ -230,31 +237,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
230
237
  // Handle entry replacements as before
231
238
  const entryReplacementComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
232
239
  const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
233
- // Get the selected variant index
234
240
  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
238
- const variableComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.InlineVariable);
239
- // Set variable values based on the selected variant index
240
- variableComponents.forEach(component => {
241
- const key = component.key;
242
- let value;
243
- if (variantIndex === 0) {
244
- value = component.baseline;
245
- } else {
246
- const variant = component.variants[variantIndex - 1];
247
- value = variant && 'value' in variant ? variant.value : component.baseline;
248
- }
249
- // Set the variable in our changes system
250
- this.setVariableValue({
251
- experienceId: experience.id,
252
- key,
253
- value,
254
- variantIndex
255
- });
256
- });
257
- }
258
241
  // Continue with entry replacement handling
259
242
  if (!baselineComponent) {
260
243
  return {
@@ -398,29 +381,6 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
398
381
  experience_jsShared.logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
399
382
  return;
400
383
  }
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 => {
416
- var _b;
417
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
418
- }).forEach(experience => {
419
- this.setExperienceVariant({
420
- experienceId: experience.id,
421
- variantIndex: 0
422
- });
423
- });
424
384
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
425
385
  [id]: false
426
386
  });
@@ -434,6 +394,22 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
434
394
  experience_jsShared.logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
435
395
  return;
436
396
  }
397
+ // Identify all experiences that belong to this audience
398
+ const experiencesToReset = this.experiences.filter(experience => {
399
+ var _b;
400
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
401
+ });
402
+ if (experiencesToReset.length > 0) {
403
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
404
+ // 1. Clear any variable overwrites that were set for these experiences (allows natural evaluation)
405
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
406
+ var _b;
407
+ return !(((_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId) && experienceIdsToReset.includes(change.meta.experienceId));
408
+ }));
409
+ // 2. Clear experience variant index overwrites for these experiences (allows natural variant selection)
410
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
411
+ }
412
+ // 3. Remove audience override (allows natural audience evaluation)
437
413
  const _b = this.audienceOverwrites,
438
414
  _c = id;
439
415
  _b[_c];
@@ -557,7 +533,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
557
533
  get pluginApi() {
558
534
  var _b;
559
535
  return {
560
- version: "7.17.4" ,
536
+ version: "7.17.6" ,
561
537
  open: this.open.bind(this),
562
538
  close: this.close.bind(this),
563
539
  toggle: this.toggle.bind(this),
@@ -649,7 +625,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
649
625
  return `${experienceId}:${key}`;
650
626
  }
651
627
  /**
652
- * Get effective changes by applying overrides - compute on demand
628
+ * Get effective changes by applying overwrites - compute on demand
653
629
  */
654
630
  getEffectiveChanges(inputChanges = this.changes) {
655
631
  if (!inputChanges || Object.keys(this.variableOverwrites).length === 0) {
package/index.esm.js CHANGED
@@ -162,7 +162,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
162
162
  * Returns a middleware function that applies variable overwrites to changes
163
163
  */
164
164
  this.getChangesModificationMiddleware = () => {
165
- if (!this.isActiveInstance || Object.keys(this.variableOverwrites).length === 0) {
165
+ if (!this.isActiveInstance || Object.keys(this.variableOverwrites).length === 0 && Object.keys(this.audienceOverwrites).length === 0) {
166
166
  return undefined;
167
167
  }
168
168
  return ({
@@ -173,10 +173,16 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
173
173
  changes: inputChanges
174
174
  };
175
175
  }
176
-
177
- // Calculate and return overridden changes on demand instead of storing them
176
+ const filteredChanges = inputChanges.filter(change => {
177
+ var _change$meta, _experience$audience;
178
+ const experienceId = (_change$meta = change.meta) == null ? void 0 : _change$meta.experienceId;
179
+ if (!experienceId) return true;
180
+ const experience = this.experiences.find(e => e.id === experienceId);
181
+ if (!(experience != null && (_experience$audience = experience.audience) != null && _experience$audience.id)) return true;
182
+ return this.audienceOverwrites[experience.audience.id] !== false;
183
+ });
178
184
  return {
179
- changes: this.getEffectiveChanges(inputChanges)
185
+ changes: this.getEffectiveChanges(filteredChanges)
180
186
  };
181
187
  };
182
188
  };
@@ -203,36 +209,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
203
209
  // Handle entry replacements as before
204
210
  const entryReplacementComponents = experience.components.filter(component => component.type === ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
205
211
  const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
206
-
207
- // Get the selected variant index
208
212
  const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
209
213
 
210
- // Handle variable components for this experience (NEW CODE)
211
- if (variantIndex !== undefined) {
212
- // Process all variable components for this experience
213
- const variableComponents = experience.components.filter(component => component.type === ComponentTypeEnum.InlineVariable);
214
-
215
- // Set variable values based on the selected variant index
216
- variableComponents.forEach(component => {
217
- const key = component.key;
218
- let value;
219
- if (variantIndex === 0) {
220
- value = component.baseline;
221
- } else {
222
- const variant = component.variants[variantIndex - 1];
223
- value = variant && 'value' in variant ? variant.value : component.baseline;
224
- }
225
-
226
- // Set the variable in our changes system
227
- this.setVariableValue({
228
- experienceId: experience.id,
229
- key,
230
- value,
231
- variantIndex
232
- });
233
- });
234
- }
235
-
236
214
  // Continue with entry replacement handling
237
215
  if (!baselineComponent) {
238
216
  return {
@@ -363,8 +341,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
363
341
  [id]: true
364
342
  });
365
343
  this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
366
- var _experience$audience;
367
- return ((_experience$audience = experience.audience) == null ? void 0 : _experience$audience.id) === id;
344
+ var _experience$audience2;
345
+ return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
368
346
  }).map(experience => experience.id).reduce((acc, curr) => {
369
347
  return Object.assign({}, acc, {
370
348
  [curr]: this.experienceVariantIndexes[curr] || 0
@@ -380,29 +358,6 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
380
358
  logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
381
359
  return;
382
360
  }
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
395
- });
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 => {
401
- this.setExperienceVariant({
402
- experienceId: experience.id,
403
- variantIndex: 0
404
- });
405
- });
406
361
  this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
407
362
  [id]: false
408
363
  });
@@ -416,6 +371,26 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
416
371
  logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
417
372
  return;
418
373
  }
374
+
375
+ // Identify all experiences that belong to this audience
376
+ const experiencesToReset = this.experiences.filter(experience => {
377
+ var _experience$audience3;
378
+ return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
379
+ });
380
+ if (experiencesToReset.length > 0) {
381
+ const experienceIdsToReset = experiencesToReset.map(e => e.id);
382
+
383
+ // 1. Clear any variable overwrites that were set for these experiences (allows natural evaluation)
384
+ this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
385
+ var _change$meta2;
386
+ return !((_change$meta2 = change.meta) != null && _change$meta2.experienceId && experienceIdsToReset.includes(change.meta.experienceId));
387
+ }));
388
+
389
+ // 2. Clear experience variant index overwrites for these experiences (allows natural variant selection)
390
+ this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
391
+ }
392
+
393
+ // 3. Remove audience override (allows natural audience evaluation)
419
394
  const _this$audienceOverwri = this.audienceOverwrites,
420
395
  audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
421
396
  this.audienceOverwrites = audienceOverwrites;
@@ -543,7 +518,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
543
518
  get pluginApi() {
544
519
  var _this$profile;
545
520
  return {
546
- version: "7.17.4" ,
521
+ version: "7.17.6" ,
547
522
  open: this.open.bind(this),
548
523
  close: this.close.bind(this),
549
524
  toggle: this.toggle.bind(this),
@@ -637,7 +612,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
637
612
  }
638
613
 
639
614
  /**
640
- * Get effective changes by applying overrides - compute on demand
615
+ * Get effective changes by applying overwrites - compute on demand
641
616
  */
642
617
  getEffectiveChanges(inputChanges = this.changes) {
643
618
  if (!inputChanges || Object.keys(this.variableOverwrites).length === 0) {
@@ -646,9 +621,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
646
621
 
647
622
  // Filter out changes that we're overriding
648
623
  const filteredChanges = inputChanges.filter(change => {
649
- var _change$meta;
624
+ var _change$meta3;
650
625
  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;
626
+ const changeKey = (_change$meta3 = change.meta) != null && _change$meta3.experienceId ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
652
627
  return !this.variableOverwrites[changeKey];
653
628
  });
654
629
  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.6",
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.6",
19
+ "@ninetailed/experience.js": "7.17.6",
20
+ "@ninetailed/experience.js-preview-bridge": "7.17.6",
21
+ "@ninetailed/experience.js-plugin-analytics": "7.17.6",
22
22
  "radash": "10.9.0"
23
23
  },
24
24
  "module": "./index.esm.js",
@@ -85,7 +85,7 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
85
85
  */
86
86
  private getOverrideKey;
87
87
  /**
88
- * Get effective changes by applying overrides - compute on demand
88
+ * Get effective changes by applying overwrites - compute on demand
89
89
  */
90
90
  private getEffectiveChanges;
91
91
  private onChange;