@ninetailed/experience.js-plugin-preview 7.5.3 → 7.6.0-beta.2
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.d.ts
ADDED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var experience_jsShared = require('@ninetailed/experience.js-shared');
|
|
6
6
|
var experience_js = require('@ninetailed/experience.js');
|
|
7
|
+
var experience_jsPluginAnalytics = require('@ninetailed/experience.js-plugin-analytics');
|
|
7
8
|
|
|
8
9
|
function _interopNamespace(e) {
|
|
9
10
|
if (e && e.__esModule) return e;
|
|
@@ -111,7 +112,7 @@ class WidgetContainer {
|
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
var _a;
|
|
114
|
-
class NinetailedPreviewPlugin extends
|
|
115
|
+
class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlugin {
|
|
115
116
|
constructor(options) {
|
|
116
117
|
super();
|
|
117
118
|
this.options = options;
|
|
@@ -165,11 +166,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
|
165
166
|
return () => {
|
|
166
167
|
const experienceIds = Object.keys(this.pluginApi.experienceVariantIndexes);
|
|
167
168
|
const experience = experiences.find(experience => {
|
|
168
|
-
|
|
169
|
-
var _b;
|
|
170
|
-
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === activeAudienceId;
|
|
171
|
-
});
|
|
172
|
-
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
169
|
+
return experienceIds.includes(experience.id);
|
|
173
170
|
});
|
|
174
171
|
if (!experience) {
|
|
175
172
|
return {
|
|
@@ -262,7 +259,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
|
262
259
|
}
|
|
263
260
|
activateAudience(id) {
|
|
264
261
|
if (!this.isKnownAudience(id)) {
|
|
265
|
-
|
|
262
|
+
experience_jsShared.logger.warn(`You cannot activate an unknown audience (id: ${id}).`);
|
|
266
263
|
return;
|
|
267
264
|
}
|
|
268
265
|
this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
|
|
@@ -280,7 +277,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
|
280
277
|
}
|
|
281
278
|
deactivateAudience(id) {
|
|
282
279
|
if (!this.isKnownAudience(id)) {
|
|
283
|
-
|
|
280
|
+
experience_jsShared.logger.warn(`You cannot deactivate an unkown audience (id: ${id}). How did you get it in the first place?`);
|
|
284
281
|
return;
|
|
285
282
|
}
|
|
286
283
|
this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
|
|
@@ -313,7 +310,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
|
313
310
|
}
|
|
314
311
|
resetAudience(id) {
|
|
315
312
|
if (!this.isKnownAudience(id)) {
|
|
316
|
-
|
|
313
|
+
experience_jsShared.logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
317
314
|
return;
|
|
318
315
|
}
|
|
319
316
|
const _b = this.audienceOverwrites,
|
|
@@ -329,19 +326,19 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
|
|
|
329
326
|
}) {
|
|
330
327
|
const experience = this.experiences.find(experience => experience.id === experienceId);
|
|
331
328
|
if (!experience) {
|
|
332
|
-
|
|
329
|
+
experience_jsShared.logger.warn(`You cannot active a variant for an unknown experience (id: ${experienceId})`);
|
|
333
330
|
return;
|
|
334
331
|
}
|
|
335
332
|
if (experience.audience && !this.activeAudiences.some(id => {
|
|
336
333
|
var _b;
|
|
337
334
|
return id === ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id);
|
|
338
335
|
})) {
|
|
339
|
-
|
|
336
|
+
experience_jsShared.logger.warn(`You cannot active a variant for an experience (id: ${experienceId}), which is not in the active audiences.`);
|
|
340
337
|
return;
|
|
341
338
|
}
|
|
342
339
|
const isValidIndex = experience.components.map(component => component.variants.length + 1).every(length => length > variantIndex);
|
|
343
340
|
if (!isValidIndex) {
|
|
344
|
-
|
|
341
|
+
experience_jsShared.logger.warn(`You activated a variant at index ${variantIndex} for the experience (id: ${experienceId}). Not all components have that many variants, you may see the baseline for some.`);
|
|
345
342
|
}
|
|
346
343
|
this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), {
|
|
347
344
|
[experienceId]: variantIndex
|
|
@@ -1,41 +1,32 @@
|
|
|
1
1
|
import { logger, unionBy } from '@ninetailed/experience.js-shared';
|
|
2
|
-
import {
|
|
2
|
+
import { OnChangeEmitter, PROFILE_CHANGE, isExperienceMatch, selectDistribution } from '@ninetailed/experience.js';
|
|
3
|
+
import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
32
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
-
});
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
6
|
+
if (source == null) return {};
|
|
7
|
+
var target = {};
|
|
8
|
+
var sourceKeys = Object.keys(source);
|
|
9
|
+
var key, i;
|
|
10
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
11
|
+
key = sourceKeys[i];
|
|
12
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
13
|
+
target[key] = source[key];
|
|
14
|
+
}
|
|
15
|
+
return target;
|
|
16
|
+
}
|
|
17
|
+
function _toPrimitive(input, hint) {
|
|
18
|
+
if (typeof input !== "object" || input === null) return input;
|
|
19
|
+
var prim = input[Symbol.toPrimitive];
|
|
20
|
+
if (prim !== undefined) {
|
|
21
|
+
var res = prim.call(input, hint || "default");
|
|
22
|
+
if (typeof res !== "object") return res;
|
|
23
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
24
|
+
}
|
|
25
|
+
return (hint === "string" ? String : Number)(input);
|
|
26
|
+
}
|
|
27
|
+
function _toPropertyKey(arg) {
|
|
28
|
+
var key = _toPrimitive(arg, "string");
|
|
29
|
+
return typeof key === "symbol" ? key : String(key);
|
|
39
30
|
}
|
|
40
31
|
|
|
41
32
|
const CONTAINER_WIDTH = 432;
|
|
@@ -47,7 +38,8 @@ const TRANSFORM_CLOSED_HIDE = `translate(${CONTAINER_WIDTH}px, 0px)`;
|
|
|
47
38
|
const TRANSFORM_OPEN = `translate(0px, 0px)`;
|
|
48
39
|
class WidgetContainer {
|
|
49
40
|
constructor(options) {
|
|
50
|
-
var
|
|
41
|
+
var _options$ui;
|
|
42
|
+
this.container = void 0;
|
|
51
43
|
this.options = options;
|
|
52
44
|
this.container = document.createElement('div');
|
|
53
45
|
this.container.style.position = 'fixed';
|
|
@@ -56,7 +48,7 @@ class WidgetContainer {
|
|
|
56
48
|
this.container.style.bottom = `${BUTTON_BOTTOM_POSITION}px`;
|
|
57
49
|
this.container.style.width = `${CONTAINER_WIDTH}px`;
|
|
58
50
|
this.container.style.height = `${BUTTON_HEIGHT}px`;
|
|
59
|
-
if ((
|
|
51
|
+
if ((_options$ui = options.ui) != null && (_options$ui = _options$ui.opener) != null && _options$ui.hide) {
|
|
60
52
|
this.container.style.transform = TRANSFORM_CLOSED_HIDE;
|
|
61
53
|
} else {
|
|
62
54
|
this.container.style.transform = TRANSFORM_CLOSED;
|
|
@@ -72,8 +64,8 @@ class WidgetContainer {
|
|
|
72
64
|
this.container.style.bottom = `0px`;
|
|
73
65
|
}
|
|
74
66
|
close() {
|
|
75
|
-
var
|
|
76
|
-
if ((
|
|
67
|
+
var _this$options$ui;
|
|
68
|
+
if ((_this$options$ui = this.options.ui) != null && (_this$options$ui = _this$options$ui.opener) != null && _this$options$ui.hide) {
|
|
77
69
|
this.container.style.transform = TRANSFORM_CLOSED_HIDE;
|
|
78
70
|
} else {
|
|
79
71
|
this.container.style.transform = TRANSFORM_CLOSED;
|
|
@@ -88,11 +80,11 @@ class WidgetContainer {
|
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
|
|
91
|
-
var _a;
|
|
92
83
|
class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
93
84
|
constructor(options) {
|
|
85
|
+
var _this;
|
|
94
86
|
super();
|
|
95
|
-
|
|
87
|
+
_this = this;
|
|
96
88
|
this.name = 'ninetailed:preview' + Math.random();
|
|
97
89
|
this.isOpen = false;
|
|
98
90
|
this.experiences = [];
|
|
@@ -103,36 +95,38 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
103
95
|
this.container = null;
|
|
104
96
|
this.bridge = null;
|
|
105
97
|
this.onChangeEmitter = new OnChangeEmitter();
|
|
98
|
+
this.onOpenExperienceEditor = void 0;
|
|
99
|
+
this.onOpenAudienceEditor = void 0;
|
|
106
100
|
this.clientId = null;
|
|
107
101
|
this.environment = null;
|
|
108
|
-
this.initialize =
|
|
109
|
-
var _b;
|
|
102
|
+
this.initialize = async function () {
|
|
110
103
|
if (typeof window !== 'undefined') {
|
|
104
|
+
var _window$ninetailed;
|
|
111
105
|
const {
|
|
112
106
|
PreviewBridge
|
|
113
|
-
} =
|
|
114
|
-
|
|
115
|
-
ui:
|
|
107
|
+
} = await import('@ninetailed/experience.js-preview-bridge');
|
|
108
|
+
_this.container = new WidgetContainer({
|
|
109
|
+
ui: _this.options.ui
|
|
116
110
|
});
|
|
117
|
-
|
|
118
|
-
url:
|
|
111
|
+
_this.bridge = PreviewBridge({
|
|
112
|
+
url: _this.options.url
|
|
119
113
|
});
|
|
120
|
-
|
|
114
|
+
_this.bridge.render(_this.container.element);
|
|
121
115
|
window.ninetailed = Object.assign({}, window.ninetailed, {
|
|
122
|
-
plugins: Object.assign(
|
|
123
|
-
preview:
|
|
116
|
+
plugins: Object.assign({}, (_window$ninetailed = window.ninetailed) == null ? void 0 : _window$ninetailed.plugins, {
|
|
117
|
+
preview: _this.windowApi
|
|
124
118
|
})
|
|
125
119
|
});
|
|
126
|
-
|
|
127
|
-
props:
|
|
120
|
+
_this.bridge.updateProps({
|
|
121
|
+
props: _this.pluginApi
|
|
128
122
|
});
|
|
129
123
|
}
|
|
130
|
-
}
|
|
124
|
+
};
|
|
131
125
|
this.loaded = () => true;
|
|
132
|
-
this[
|
|
126
|
+
this[PROFILE_CHANGE] = ({
|
|
133
127
|
payload
|
|
134
128
|
}) => {
|
|
135
|
-
if (payload
|
|
129
|
+
if (payload != null && payload.profile) {
|
|
136
130
|
this.onProfileChange(payload.profile);
|
|
137
131
|
}
|
|
138
132
|
};
|
|
@@ -143,11 +137,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
143
137
|
return () => {
|
|
144
138
|
const experienceIds = Object.keys(this.pluginApi.experienceVariantIndexes);
|
|
145
139
|
const experience = experiences.find(experience => {
|
|
146
|
-
|
|
147
|
-
var _b;
|
|
148
|
-
return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === activeAudienceId;
|
|
149
|
-
});
|
|
150
|
-
return hasActiveAudience && experienceIds.includes(experience.id);
|
|
140
|
+
return experienceIds.includes(experience.id);
|
|
151
141
|
});
|
|
152
142
|
if (!experience) {
|
|
153
143
|
return {
|
|
@@ -189,10 +179,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
189
179
|
};
|
|
190
180
|
};
|
|
191
181
|
this.onChange = () => {
|
|
192
|
-
var
|
|
182
|
+
var _window$ninetailed2;
|
|
193
183
|
logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
|
|
194
184
|
Object.assign({}, window.ninetailed, {
|
|
195
|
-
plugins: Object.assign(
|
|
185
|
+
plugins: Object.assign({}, (_window$ninetailed2 = window.ninetailed) == null ? void 0 : _window$ninetailed2.plugins, {
|
|
196
186
|
preview: this.windowApi
|
|
197
187
|
})
|
|
198
188
|
});
|
|
@@ -212,20 +202,21 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
212
202
|
this.clientId = clientId;
|
|
213
203
|
this.environment = environment;
|
|
214
204
|
};
|
|
205
|
+
this.options = options;
|
|
215
206
|
this.experiences = options.experiences || [];
|
|
216
207
|
this.audienceDefinitions = options.audiences || [];
|
|
217
208
|
this.onOpenExperienceEditor = options.onOpenExperienceEditor;
|
|
218
209
|
this.onOpenAudienceEditor = options.onOpenAudienceEditor;
|
|
219
210
|
}
|
|
220
211
|
open() {
|
|
221
|
-
var
|
|
222
|
-
(
|
|
212
|
+
var _this$container;
|
|
213
|
+
(_this$container = this.container) == null || _this$container.open();
|
|
223
214
|
this.isOpen = true;
|
|
224
215
|
this.onChange();
|
|
225
216
|
}
|
|
226
217
|
close() {
|
|
227
|
-
var
|
|
228
|
-
(
|
|
218
|
+
var _this$container2;
|
|
219
|
+
(_this$container2 = this.container) == null || _this$container2.close();
|
|
229
220
|
setTimeout(() => {
|
|
230
221
|
this.isOpen = false;
|
|
231
222
|
this.onChange();
|
|
@@ -240,17 +231,17 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
240
231
|
}
|
|
241
232
|
activateAudience(id) {
|
|
242
233
|
if (!this.isKnownAudience(id)) {
|
|
243
|
-
|
|
234
|
+
logger.warn(`You cannot activate an unknown audience (id: ${id}).`);
|
|
244
235
|
return;
|
|
245
236
|
}
|
|
246
|
-
this.audienceOverwrites = Object.assign(
|
|
237
|
+
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
247
238
|
[id]: true
|
|
248
239
|
});
|
|
249
|
-
this.experienceVariantIndexOverwrites = Object.assign(
|
|
250
|
-
var
|
|
251
|
-
return ((
|
|
240
|
+
this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
|
|
241
|
+
var _experience$audience;
|
|
242
|
+
return ((_experience$audience = experience.audience) == null ? void 0 : _experience$audience.id) === id;
|
|
252
243
|
}).map(experience => experience.id).reduce((acc, curr) => {
|
|
253
|
-
return Object.assign(
|
|
244
|
+
return Object.assign({}, acc, {
|
|
254
245
|
[curr]: this.experienceVariantIndexes[curr] || 0
|
|
255
246
|
});
|
|
256
247
|
}, {}));
|
|
@@ -258,46 +249,44 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
258
249
|
}
|
|
259
250
|
deactivateAudience(id) {
|
|
260
251
|
if (!this.isKnownAudience(id)) {
|
|
261
|
-
|
|
252
|
+
logger.warn(`You cannot deactivate an unkown audience (id: ${id}). How did you get it in the first place?`);
|
|
262
253
|
return;
|
|
263
254
|
}
|
|
264
255
|
this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
|
|
265
256
|
return !this.experiences.filter(experience => {
|
|
266
|
-
var
|
|
267
|
-
return ((
|
|
257
|
+
var _experience$audience2;
|
|
258
|
+
return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
|
|
268
259
|
}).map(experience => experience.id).includes(key);
|
|
269
260
|
}).reduce((acc, [key, value]) => {
|
|
270
|
-
return Object.assign(
|
|
261
|
+
return Object.assign({}, acc, {
|
|
271
262
|
[key]: value
|
|
272
263
|
});
|
|
273
264
|
}, {});
|
|
274
|
-
this.audienceOverwrites = Object.assign(
|
|
265
|
+
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
275
266
|
[id]: false
|
|
276
267
|
});
|
|
277
268
|
this.onChange();
|
|
278
269
|
this.experiences.filter(experience => {
|
|
279
|
-
var
|
|
280
|
-
return ((
|
|
270
|
+
var _experience$audience3;
|
|
271
|
+
return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
|
|
281
272
|
}).forEach(experience => {
|
|
282
273
|
this.setExperienceVariant({
|
|
283
274
|
experienceId: experience.id,
|
|
284
275
|
variantIndex: 0
|
|
285
276
|
});
|
|
286
277
|
});
|
|
287
|
-
this.audienceOverwrites = Object.assign(
|
|
278
|
+
this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
|
|
288
279
|
[id]: false
|
|
289
280
|
});
|
|
290
281
|
this.onChange();
|
|
291
282
|
}
|
|
292
283
|
resetAudience(id) {
|
|
293
284
|
if (!this.isKnownAudience(id)) {
|
|
294
|
-
|
|
285
|
+
logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
|
|
295
286
|
return;
|
|
296
287
|
}
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
_b[_c];
|
|
300
|
-
const audienceOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
288
|
+
const _this$audienceOverwri = this.audienceOverwrites,
|
|
289
|
+
audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
|
|
301
290
|
this.audienceOverwrites = audienceOverwrites;
|
|
302
291
|
this.onChange();
|
|
303
292
|
}
|
|
@@ -307,30 +296,28 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
307
296
|
}) {
|
|
308
297
|
const experience = this.experiences.find(experience => experience.id === experienceId);
|
|
309
298
|
if (!experience) {
|
|
310
|
-
|
|
299
|
+
logger.warn(`You cannot active a variant for an unknown experience (id: ${experienceId})`);
|
|
311
300
|
return;
|
|
312
301
|
}
|
|
313
302
|
if (experience.audience && !this.activeAudiences.some(id => {
|
|
314
|
-
var
|
|
315
|
-
return id === ((
|
|
303
|
+
var _experience$audience4;
|
|
304
|
+
return id === ((_experience$audience4 = experience.audience) == null ? void 0 : _experience$audience4.id);
|
|
316
305
|
})) {
|
|
317
|
-
|
|
306
|
+
logger.warn(`You cannot active a variant for an experience (id: ${experienceId}), which is not in the active audiences.`);
|
|
318
307
|
return;
|
|
319
308
|
}
|
|
320
309
|
const isValidIndex = experience.components.map(component => component.variants.length + 1).every(length => length > variantIndex);
|
|
321
310
|
if (!isValidIndex) {
|
|
322
|
-
|
|
311
|
+
logger.warn(`You activated a variant at index ${variantIndex} for the experience (id: ${experienceId}). Not all components have that many variants, you may see the baseline for some.`);
|
|
323
312
|
}
|
|
324
|
-
this.experienceVariantIndexOverwrites = Object.assign(
|
|
313
|
+
this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, {
|
|
325
314
|
[experienceId]: variantIndex
|
|
326
315
|
});
|
|
327
316
|
this.onChange();
|
|
328
317
|
}
|
|
329
318
|
resetExperience(experienceId) {
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
_b[_c];
|
|
333
|
-
const experienceVariantIndexOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
319
|
+
const _this$experienceVaria = this.experienceVariantIndexOverwrites,
|
|
320
|
+
experienceVariantIndexOverwrites = _objectWithoutPropertiesLoose(_this$experienceVaria, [experienceId].map(_toPropertyKey));
|
|
334
321
|
this.experienceVariantIndexOverwrites = experienceVariantIndexOverwrites;
|
|
335
322
|
this.onChange();
|
|
336
323
|
}
|
|
@@ -349,7 +336,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
349
336
|
if (this.onOpenAudienceEditor && typeof this.onOpenAudienceEditor === 'function') return this.onOpenAudienceEditor(audience);
|
|
350
337
|
}
|
|
351
338
|
get pluginApi() {
|
|
352
|
-
var
|
|
339
|
+
var _this$profile;
|
|
353
340
|
return {
|
|
354
341
|
version: '2.0.0',
|
|
355
342
|
open: this.open.bind(this),
|
|
@@ -359,14 +346,14 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
359
346
|
activateAudience: this.activateAudience.bind(this),
|
|
360
347
|
deactivateAudience: this.deactivateAudience.bind(this),
|
|
361
348
|
resetAudience: this.resetAudience.bind(this),
|
|
362
|
-
apiAudiences: ((
|
|
349
|
+
apiAudiences: ((_this$profile = this.profile) == null ? void 0 : _this$profile.audiences) || [],
|
|
363
350
|
audienceOverwrites: this.audienceOverwrites,
|
|
364
351
|
activeAudiences: this.activeAudiences,
|
|
365
352
|
audienceDefinitions: this.audienceDefinitions,
|
|
366
353
|
setExperienceVariant: this.setExperienceVariant.bind(this),
|
|
367
354
|
resetExperience: this.resetExperience.bind(this),
|
|
368
355
|
apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
|
|
369
|
-
experienceVariantIndexes: Object.assign(
|
|
356
|
+
experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites),
|
|
370
357
|
experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
|
|
371
358
|
reset: this.reset.bind(this),
|
|
372
359
|
experiences: this.experiences,
|
|
@@ -387,7 +374,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
387
374
|
activeAudiences: this.activeAudiences,
|
|
388
375
|
setExperienceVariant: this.setExperienceVariant.bind(this),
|
|
389
376
|
resetExperience: this.resetExperience.bind(this),
|
|
390
|
-
experienceVariantIndexes: Object.assign(
|
|
377
|
+
experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites)
|
|
391
378
|
};
|
|
392
379
|
}
|
|
393
380
|
isKnownAudience(id) {
|
|
@@ -398,10 +385,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
398
385
|
return unionBy(this.audienceDefinitions, audiencesFromExperiences, 'id');
|
|
399
386
|
}
|
|
400
387
|
get activeAudiences() {
|
|
401
|
-
var
|
|
388
|
+
var _this$profile2;
|
|
402
389
|
const deactivatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => !active).map(([id]) => id);
|
|
403
390
|
const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
|
|
404
|
-
return [...(((
|
|
391
|
+
return [...(((_this$profile2 = this.profile) == null ? void 0 : _this$profile2.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
|
|
405
392
|
}
|
|
406
393
|
calculateExperienceVariantIndexes(profile) {
|
|
407
394
|
const matchedExperiences = this.experiences.filter(experience => isExperienceMatch({
|
|
@@ -413,7 +400,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
413
400
|
experience,
|
|
414
401
|
profile
|
|
415
402
|
});
|
|
416
|
-
return Object.assign(
|
|
403
|
+
return Object.assign({}, acc, {
|
|
417
404
|
[experience.id]: distribution.index
|
|
418
405
|
});
|
|
419
406
|
}, {});
|
|
@@ -430,12 +417,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
|
|
|
430
417
|
if (!profile) {
|
|
431
418
|
return {};
|
|
432
419
|
}
|
|
433
|
-
return this.calculateExperienceVariantIndexes(Object.assign(
|
|
420
|
+
return this.calculateExperienceVariantIndexes(Object.assign({}, profile, {
|
|
434
421
|
audiences: this.activeAudiences
|
|
435
422
|
}));
|
|
436
423
|
}
|
|
437
424
|
}
|
|
438
|
-
_a = PROFILE_CHANGE;
|
|
439
425
|
|
|
440
426
|
if (typeof window === 'object' && !('process' in window)) {
|
|
441
427
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-plugin-preview",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.0-beta.2",
|
|
4
4
|
"description": "Ninetailed SDK plugin for preview",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -8,14 +8,18 @@
|
|
|
8
8
|
"url": "https://github.com/ninetailed-inc/experience.js.git",
|
|
9
9
|
"directory": "packages/plugins/preview"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
"keywords": [
|
|
12
|
+
"preview",
|
|
13
|
+
"ninetailed",
|
|
14
|
+
"personalization",
|
|
15
|
+
"a/b testing"
|
|
16
|
+
],
|
|
15
17
|
"dependencies": {
|
|
16
|
-
"@ninetailed/experience.js": "
|
|
17
|
-
"@ninetailed/experience.js
|
|
18
|
-
"@ninetailed/experience.js-
|
|
18
|
+
"@ninetailed/experience.js-shared": "*",
|
|
19
|
+
"@ninetailed/experience.js": "*",
|
|
20
|
+
"@ninetailed/experience.js-preview-bridge": "*",
|
|
21
|
+
"@ninetailed/experience.js-plugin-analytics": "*"
|
|
19
22
|
},
|
|
20
|
-
"
|
|
23
|
+
"module": "./index.esm.js",
|
|
24
|
+
"main": "./index.cjs.js"
|
|
21
25
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Reference } from '@ninetailed/experience.js-shared';
|
|
2
|
-
import { ExperienceConfiguration, PROFILE_CHANGE, HasExperienceSelectionMiddleware,
|
|
2
|
+
import { ExperienceConfiguration, PROFILE_CHANGE, HasExperienceSelectionMiddleware, BuildExperienceSelectionMiddleware } from '@ninetailed/experience.js';
|
|
3
3
|
import type { ExposedAudienceDefinition } from '@ninetailed/experience.js-preview-bridge';
|
|
4
|
+
import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
|
|
4
5
|
export declare const NINETAILED_PREVIEW_EVENTS: {
|
|
5
6
|
previewAudiences: string;
|
|
6
7
|
previewTraits: string;
|
|
@@ -17,7 +18,7 @@ type NinetailedPreviewPluginOptions = {
|
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
20
|
};
|
|
20
|
-
export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements HasExperienceSelectionMiddleware<Reference> {
|
|
21
|
+
export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements HasExperienceSelectionMiddleware<Reference, Reference> {
|
|
21
22
|
private readonly options;
|
|
22
23
|
name: string;
|
|
23
24
|
private isOpen;
|
|
@@ -51,7 +52,7 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
|
|
|
51
52
|
}): void;
|
|
52
53
|
resetExperience(experienceId: string): void;
|
|
53
54
|
reset(): void;
|
|
54
|
-
getExperienceSelectionMiddleware:
|
|
55
|
+
getExperienceSelectionMiddleware: BuildExperienceSelectionMiddleware<Reference, Reference>;
|
|
55
56
|
openExperienceEditor(experience: ExperienceConfiguration): void;
|
|
56
57
|
openExperienceAnalytics(experience: ExperienceConfiguration): void;
|
|
57
58
|
openAudienceEditor(audience: ExposedAudienceDefinition): void;
|