@ninetailed/experience.js-plugin-preview 7.17.5 → 7.18.0
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 +12 -50
- package/index.esm.js +14 -60
- package/package.json +19 -8
- package/src/lib/plugin/NinetailedPreviewPlugin.d.ts +1 -1
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
|
-
|
|
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(
|
|
214
|
+
changes: this.getEffectiveChanges(filteredChanges)
|
|
208
215
|
};
|
|
209
216
|
};
|
|
210
217
|
};
|
|
@@ -231,29 +238,6 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
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
240
|
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
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
|
-
const variableComponents = experience.components.filter(component => component.type === experience_jsShared.ComponentTypeEnum.InlineVariable);
|
|
238
|
-
// Set variable values based on the selected variant index
|
|
239
|
-
variableComponents.forEach(component => {
|
|
240
|
-
const key = component.key;
|
|
241
|
-
let value;
|
|
242
|
-
if (variantIndex === 0) {
|
|
243
|
-
value = component.baseline.value;
|
|
244
|
-
} else {
|
|
245
|
-
const variant = component.variants[variantIndex - 1];
|
|
246
|
-
value = variant && 'value' in variant ? variant.value : component.baseline.value;
|
|
247
|
-
}
|
|
248
|
-
// Set the variable in our changes system
|
|
249
|
-
this.setVariableValue({
|
|
250
|
-
experienceId: experience.id,
|
|
251
|
-
key,
|
|
252
|
-
value,
|
|
253
|
-
variantIndex
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
241
|
// Continue with entry replacement handling
|
|
258
242
|
if (!baselineComponent) {
|
|
259
243
|
return {
|
|
@@ -397,28 +381,6 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
397
381
|
experience_jsShared.logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
398
382
|
return;
|
|
399
383
|
}
|
|
400
|
-
// Identify all experiences that belong to this audience
|
|
401
|
-
const experiencesToReset = this.experiences.filter(experience => {
|
|
402
|
-
var _b;
|
|
403
|
-
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
|
|
404
|
-
});
|
|
405
|
-
// 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
|
|
406
|
-
experiencesToReset.forEach(experience => {
|
|
407
|
-
this.setExperienceVariant({
|
|
408
|
-
experienceId: experience.id,
|
|
409
|
-
variantIndex: 0
|
|
410
|
-
});
|
|
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
|
-
}
|
|
422
384
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
423
385
|
[id]: false
|
|
424
386
|
});
|
|
@@ -571,7 +533,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
571
533
|
get pluginApi() {
|
|
572
534
|
var _b;
|
|
573
535
|
return {
|
|
574
|
-
version: "7.
|
|
536
|
+
version: "7.18.0" ,
|
|
575
537
|
open: this.open.bind(this),
|
|
576
538
|
close: this.close.bind(this),
|
|
577
539
|
toggle: this.toggle.bind(this),
|
|
@@ -663,7 +625,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
|
|
|
663
625
|
return `${experienceId}:${key}`;
|
|
664
626
|
}
|
|
665
627
|
/**
|
|
666
|
-
* Get effective changes by applying
|
|
628
|
+
* Get effective changes by applying overwrites - compute on demand
|
|
667
629
|
*/
|
|
668
630
|
getEffectiveChanges(inputChanges = this.changes) {
|
|
669
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
|
-
|
|
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(
|
|
185
|
+
changes: this.getEffectiveChanges(filteredChanges)
|
|
180
186
|
};
|
|
181
187
|
};
|
|
182
188
|
};
|
|
@@ -205,32 +211,6 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
205
211
|
const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
|
|
206
212
|
const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
|
|
207
213
|
|
|
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
|
|
211
|
-
const variableComponents = experience.components.filter(component => component.type === ComponentTypeEnum.InlineVariable);
|
|
212
|
-
|
|
213
|
-
// Set variable values based on the selected variant index
|
|
214
|
-
variableComponents.forEach(component => {
|
|
215
|
-
const key = component.key;
|
|
216
|
-
let value;
|
|
217
|
-
if (variantIndex === 0) {
|
|
218
|
-
value = component.baseline.value;
|
|
219
|
-
} else {
|
|
220
|
-
const variant = component.variants[variantIndex - 1];
|
|
221
|
-
value = variant && 'value' in variant ? variant.value : component.baseline.value;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Set the variable in our changes system
|
|
225
|
-
this.setVariableValue({
|
|
226
|
-
experienceId: experience.id,
|
|
227
|
-
key,
|
|
228
|
-
value,
|
|
229
|
-
variantIndex
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
214
|
// Continue with entry replacement handling
|
|
235
215
|
if (!baselineComponent) {
|
|
236
216
|
return {
|
|
@@ -361,8 +341,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
361
341
|
[id]: true
|
|
362
342
|
});
|
|
363
343
|
this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
|
|
364
|
-
var _experience$
|
|
365
|
-
return ((_experience$
|
|
344
|
+
var _experience$audience2;
|
|
345
|
+
return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
|
|
366
346
|
}).map(experience => experience.id).reduce((acc, curr) => {
|
|
367
347
|
return Object.assign({}, acc, {
|
|
368
348
|
[curr]: this.experienceVariantIndexes[curr] || 0
|
|
@@ -378,32 +358,6 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
378
358
|
logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
379
359
|
return;
|
|
380
360
|
}
|
|
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;
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// 1. Reset each experience to baseline BEFORE removing the audience so the guard in setExperienceVariant passes
|
|
389
|
-
experiencesToReset.forEach(experience => {
|
|
390
|
-
this.setExperienceVariant({
|
|
391
|
-
experienceId: experience.id,
|
|
392
|
-
variantIndex: 0
|
|
393
|
-
});
|
|
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
|
-
}
|
|
407
361
|
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
408
362
|
[id]: false
|
|
409
363
|
});
|
|
@@ -564,7 +518,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
564
518
|
get pluginApi() {
|
|
565
519
|
var _this$profile;
|
|
566
520
|
return {
|
|
567
|
-
version: "7.
|
|
521
|
+
version: "7.18.0" ,
|
|
568
522
|
open: this.open.bind(this),
|
|
569
523
|
close: this.close.bind(this),
|
|
570
524
|
toggle: this.toggle.bind(this),
|
|
@@ -658,7 +612,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
658
612
|
}
|
|
659
613
|
|
|
660
614
|
/**
|
|
661
|
-
* Get effective changes by applying
|
|
615
|
+
* Get effective changes by applying overwrites - compute on demand
|
|
662
616
|
*/
|
|
663
617
|
getEffectiveChanges(inputChanges = this.changes) {
|
|
664
618
|
if (!inputChanges || Object.keys(this.variableOverwrites).length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-plugin-preview",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.18.0",
|
|
4
4
|
"description": "Ninetailed SDK plugin for preview",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -14,13 +14,24 @@
|
|
|
14
14
|
"personalization",
|
|
15
15
|
"a/b testing"
|
|
16
16
|
],
|
|
17
|
+
"main": "./index.cjs.js",
|
|
18
|
+
"module": "./index.esm.js",
|
|
19
|
+
"types": "./index.cjs.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./index.cjs.d.ts",
|
|
23
|
+
"import": "./index.esm.js",
|
|
24
|
+
"require": "./index.cjs.js",
|
|
25
|
+
"default": "./index.esm.js"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
17
30
|
"dependencies": {
|
|
18
|
-
"@ninetailed/experience.js-shared": "7.
|
|
19
|
-
"@ninetailed/experience.js": "7.
|
|
20
|
-
"@ninetailed/experience.js-preview-bridge": "7.
|
|
21
|
-
"@ninetailed/experience.js-plugin-analytics": "7.
|
|
31
|
+
"@ninetailed/experience.js-shared": "7.18.0",
|
|
32
|
+
"@ninetailed/experience.js": "7.18.0",
|
|
33
|
+
"@ninetailed/experience.js-preview-bridge": "7.18.0",
|
|
34
|
+
"@ninetailed/experience.js-plugin-analytics": "7.18.0",
|
|
22
35
|
"radash": "10.9.0"
|
|
23
|
-
}
|
|
24
|
-
"module": "./index.esm.js",
|
|
25
|
-
"main": "./index.cjs.js"
|
|
36
|
+
}
|
|
26
37
|
}
|
|
@@ -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
|
|
88
|
+
* Get effective changes by applying overwrites - compute on demand
|
|
89
89
|
*/
|
|
90
90
|
private getEffectiveChanges;
|
|
91
91
|
private onChange;
|