@ninetailed/experience.js-plugin-preview 7.17.2 → 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.
- package/index.cjs.js +39 -24
- package/index.esm.js +50 -28
- package/package.json +6 -5
package/index.cjs.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var experience_jsShared = require('@ninetailed/experience.js-shared');
|
|
6
6
|
var experience_js = require('@ninetailed/experience.js');
|
|
7
7
|
var experience_jsPluginAnalytics = require('@ninetailed/experience.js-plugin-analytics');
|
|
8
|
+
var radash = require('radash');
|
|
8
9
|
|
|
9
10
|
function _interopNamespace(e) {
|
|
10
11
|
if (e && e.__esModule) return e;
|
|
@@ -229,21 +230,20 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
229
230
|
// Handle entry replacements as before
|
|
230
231
|
const entryReplacementComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
|
|
231
232
|
const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
|
|
232
|
-
// Get the selected variant index
|
|
233
233
|
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
234
|
-
//
|
|
235
|
-
if (variantIndex !== undefined) {
|
|
236
|
-
//
|
|
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
|
|
237
237
|
const variableComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.InlineVariable);
|
|
238
238
|
// Set variable values based on the selected variant index
|
|
239
239
|
variableComponents.forEach(component => {
|
|
240
240
|
const key = component.key;
|
|
241
241
|
let value;
|
|
242
242
|
if (variantIndex === 0) {
|
|
243
|
-
value = component.baseline;
|
|
243
|
+
value = component.baseline.value;
|
|
244
244
|
} else {
|
|
245
245
|
const variant = component.variants[variantIndex - 1];
|
|
246
|
-
value = variant && 'value' in variant ? variant.value : component.baseline;
|
|
246
|
+
value = variant && 'value' in variant ? variant.value : component.baseline.value;
|
|
247
247
|
}
|
|
248
248
|
// Set the variable in our changes system
|
|
249
249
|
this.setVariableValue({
|
|
@@ -397,29 +397,28 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
397
397
|
experience_jsShared.logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
398
398
|
return;
|
|
399
399
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var _b;
|
|
403
|
-
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
404
|
-
}).map(experience => experience.id).includes(key);
|
|
405
|
-
}).reduce((acc, [key, value]) => {
|
|
406
|
-
return Object.assign(Object.assign({}, acc), {
|
|
407
|
-
[key]: value
|
|
408
|
-
});
|
|
409
|
-
}, {});
|
|
410
|
-
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
411
|
-
[id]: false
|
|
412
|
-
});
|
|
413
|
-
this.onChange();
|
|
414
|
-
this.experiences.filter(experience => {
|
|
400
|
+
// Identify all experiences that belong to this audience
|
|
401
|
+
const experiencesToReset = this.experiences.filter(experience => {
|
|
415
402
|
var _b;
|
|
416
403
|
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
417
|
-
})
|
|
404
|
+
});
|
|
405
|
+
// 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
|
|
406
|
+
experiencesToReset.forEach(experience => {
|
|
418
407
|
this.setExperienceVariant({
|
|
419
408
|
experienceId: experience.id,
|
|
420
409
|
variantIndex: 0
|
|
421
410
|
});
|
|
422
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
|
+
}
|
|
423
422
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
424
423
|
[id]: false
|
|
425
424
|
});
|
|
@@ -433,6 +432,22 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
433
432
|
experience_jsShared.logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
434
433
|
return;
|
|
435
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)
|
|
436
451
|
const _b = this.audienceOverwrites,
|
|
437
452
|
_c = id;
|
|
438
453
|
_b[_c];
|
|
@@ -519,7 +534,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
519
534
|
}
|
|
520
535
|
const overrideKey = `${experienceId}:${key}`;
|
|
521
536
|
// Only create new object if actually changing
|
|
522
|
-
if (((_b = this.variableOverwrites[overrideKey]) === null || _b === void 0 ? void 0 : _b.value
|
|
537
|
+
if (radash.isEqual((_b = this.variableOverwrites[overrideKey]) === null || _b === void 0 ? void 0 : _b.value, value)) {
|
|
523
538
|
return; // No change needed
|
|
524
539
|
}
|
|
525
540
|
|
|
@@ -556,7 +571,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
556
571
|
get pluginApi() {
|
|
557
572
|
var _b;
|
|
558
573
|
return {
|
|
559
|
-
version: "7.17.
|
|
574
|
+
version: "7.17.5" ,
|
|
560
575
|
open: this.open.bind(this),
|
|
561
576
|
close: this.close.bind(this),
|
|
562
577
|
toggle: this.toggle.bind(this),
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { logger, ComponentTypeEnum, ChangeTypes, unionBy } from '@ninetailed/experience.js-shared';
|
|
2
2
|
import { OnChangeEmitter, PROFILE_CHANGE, isExperienceMatch, selectDistribution } from '@ninetailed/experience.js';
|
|
3
3
|
import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
|
+
import { isEqual } from 'radash';
|
|
4
5
|
|
|
5
6
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
6
7
|
if (source == null) return {};
|
|
@@ -202,13 +203,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
202
203
|
// Handle entry replacements as before
|
|
203
204
|
const entryReplacementComponents = experience.components.filter(component => component.type === ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
|
|
204
205
|
const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
|
|
205
|
-
|
|
206
|
-
// Get the selected variant index
|
|
207
206
|
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
208
207
|
|
|
209
|
-
//
|
|
210
|
-
if (variantIndex !== undefined) {
|
|
211
|
-
//
|
|
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
|
|
212
211
|
const variableComponents = experience.components.filter(component => component.type === ComponentTypeEnum.InlineVariable);
|
|
213
212
|
|
|
214
213
|
// Set variable values based on the selected variant index
|
|
@@ -216,10 +215,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
216
215
|
const key = component.key;
|
|
217
216
|
let value;
|
|
218
217
|
if (variantIndex === 0) {
|
|
219
|
-
value = component.baseline;
|
|
218
|
+
value = component.baseline.value;
|
|
220
219
|
} else {
|
|
221
220
|
const variant = component.variants[variantIndex - 1];
|
|
222
|
-
value = variant && 'value' in variant ? variant.value : component.baseline;
|
|
221
|
+
value = variant && 'value' in variant ? variant.value : component.baseline.value;
|
|
223
222
|
}
|
|
224
223
|
|
|
225
224
|
// Set the variable in our changes system
|
|
@@ -379,29 +378,32 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
379
378
|
logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
380
379
|
return;
|
|
381
380
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}).reduce((acc, [key, value]) => {
|
|
388
|
-
return Object.assign({}, acc, {
|
|
389
|
-
[key]: value
|
|
390
|
-
});
|
|
391
|
-
}, {});
|
|
392
|
-
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
393
|
-
[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;
|
|
394
386
|
});
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
|
|
399
|
-
}).forEach(experience => {
|
|
387
|
+
|
|
388
|
+
// 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
|
|
389
|
+
experiencesToReset.forEach(experience => {
|
|
400
390
|
this.setExperienceVariant({
|
|
401
391
|
experienceId: experience.id,
|
|
402
392
|
variantIndex: 0
|
|
403
393
|
});
|
|
404
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
|
+
}
|
|
405
407
|
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
406
408
|
[id]: false
|
|
407
409
|
});
|
|
@@ -415,6 +417,26 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
415
417
|
logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
416
418
|
return;
|
|
417
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)
|
|
418
440
|
const _this$audienceOverwri = this.audienceOverwrites,
|
|
419
441
|
audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
|
|
420
442
|
this.audienceOverwrites = audienceOverwrites;
|
|
@@ -502,7 +524,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
502
524
|
const overrideKey = `${experienceId}:${key}`;
|
|
503
525
|
|
|
504
526
|
// Only create new object if actually changing
|
|
505
|
-
if (((_this$variableOverwri = this.variableOverwrites[overrideKey]) == null ? void 0 : _this$variableOverwri.value
|
|
527
|
+
if (isEqual((_this$variableOverwri = this.variableOverwrites[overrideKey]) == null ? void 0 : _this$variableOverwri.value, value)) {
|
|
506
528
|
return; // No change needed
|
|
507
529
|
}
|
|
508
530
|
|
|
@@ -542,7 +564,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
542
564
|
get pluginApi() {
|
|
543
565
|
var _this$profile;
|
|
544
566
|
return {
|
|
545
|
-
version: "7.17.
|
|
567
|
+
version: "7.17.5" ,
|
|
546
568
|
open: this.open.bind(this),
|
|
547
569
|
close: this.close.bind(this),
|
|
548
570
|
toggle: this.toggle.bind(this),
|
|
@@ -645,9 +667,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
645
667
|
|
|
646
668
|
// Filter out changes that we're overriding
|
|
647
669
|
const filteredChanges = inputChanges.filter(change => {
|
|
648
|
-
var _change$
|
|
670
|
+
var _change$meta3;
|
|
649
671
|
if (change.type !== ChangeTypes.Variable) return true;
|
|
650
|
-
const changeKey = (_change$
|
|
672
|
+
const changeKey = (_change$meta3 = change.meta) != null && _change$meta3.experienceId ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
|
|
651
673
|
return !this.variableOverwrites[changeKey];
|
|
652
674
|
});
|
|
653
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.
|
|
3
|
+
"version": "7.17.5",
|
|
4
4
|
"description": "Ninetailed SDK plugin for preview",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,10 +15,11 @@
|
|
|
15
15
|
"a/b testing"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@ninetailed/experience.js-shared": "7.17.
|
|
19
|
-
"@ninetailed/experience.js": "7.17.
|
|
20
|
-
"@ninetailed/experience.js-preview-bridge": "7.17.
|
|
21
|
-
"@ninetailed/experience.js-plugin-analytics": "7.17.
|
|
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
|
+
"radash": "10.9.0"
|
|
22
23
|
},
|
|
23
24
|
"module": "./index.esm.js",
|
|
24
25
|
"main": "./index.cjs.js"
|