@ninetailed/experience.js-plugin-preview 7.18.11 → 7.18.13

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
@@ -7,24 +7,6 @@ var experience_js = require('@ninetailed/experience.js');
7
7
  var experience_jsPluginAnalytics = require('@ninetailed/experience.js-plugin-analytics');
8
8
  var radash = require('radash');
9
9
 
10
- function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
22
- });
23
- }
24
- n["default"] = e;
25
- return Object.freeze(n);
26
- }
27
-
28
10
  /******************************************************************************
29
11
  Copyright (c) Microsoft Corporation.
30
12
 
@@ -39,6 +21,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
39
21
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40
22
  PERFORMANCE OF THIS SOFTWARE.
41
23
  ***************************************************************************** */
24
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
25
+
42
26
 
43
27
  function __rest(s, e) {
44
28
  var t = {};
@@ -60,7 +44,12 @@ function __awaiter(thisArg, _arguments, P, generator) {
60
44
  function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
61
45
  step((generator = generator.apply(thisArg, _arguments || [])).next());
62
46
  });
63
- }
47
+ }
48
+
49
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ };
64
53
 
65
54
  const CONTAINER_WIDTH = 432;
66
55
  const BUTTON_WIDTH = 48;
@@ -152,7 +141,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
152
141
  }
153
142
  const {
154
143
  PreviewBridge
155
- } = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@ninetailed/experience.js-preview-bridge')); });
144
+ } = yield import('@ninetailed/experience.js-preview-bridge');
156
145
  this.isActiveInstance = true;
157
146
  this.container = new WidgetContainer({
158
147
  ui: this.options.ui
@@ -494,7 +483,6 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
494
483
  if (radash.isEqual((_b = this.variableOverwrites[overrideKey]) === null || _b === void 0 ? void 0 : _b.value, value)) {
495
484
  return; // No change needed
496
485
  }
497
-
498
486
  const change = {
499
487
  type: experience_jsShared.ChangeTypes.Variable,
500
488
  key,
@@ -528,7 +516,7 @@ class NinetailedPreviewPlugin extends experience_jsPluginAnalytics.NinetailedPlu
528
516
  get pluginApi() {
529
517
  var _b;
530
518
  return {
531
- version: "7.18.11" ,
519
+ version: "7.18.13",
532
520
  open: this.open.bind(this),
533
521
  close: this.close.bind(this),
534
522
  toggle: this.toggle.bind(this),
@@ -689,4 +677,4 @@ if (typeof window === 'object' && !('process' in window)) {
689
677
  }
690
678
 
691
679
  exports.NinetailedPreviewPlugin = NinetailedPreviewPlugin;
692
- exports["default"] = NinetailedPreviewPlugin;
680
+ exports.default = NinetailedPreviewPlugin;
package/index.esm.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./src/index";
2
+ export { default } from "./src/index";
package/index.esm.js CHANGED
@@ -1,34 +1,51 @@
1
- import { logger, ComponentTypeEnum, ChangeTypes, unionBy } from '@ninetailed/experience.js-shared';
2
- import { OnChangeEmitter, PROFILE_CHANGE, isExperienceMatch, selectDistribution } from '@ninetailed/experience.js';
1
+ import { ComponentTypeEnum, logger, ChangeTypes, unionBy } from '@ninetailed/experience.js-shared';
2
+ import { OnChangeEmitter, isExperienceMatch, selectDistribution, PROFILE_CHANGE } from '@ninetailed/experience.js';
3
3
  import { NinetailedPlugin } from '@ninetailed/experience.js-plugin-analytics';
4
4
  import { isEqual } from 'radash';
5
5
 
6
- function _objectWithoutPropertiesLoose(source, excluded) {
7
- if (source == null) return {};
8
- var target = {};
9
- var sourceKeys = Object.keys(source);
10
- var key, i;
11
- for (i = 0; i < sourceKeys.length; i++) {
12
- key = sourceKeys[i];
13
- if (excluded.indexOf(key) >= 0) continue;
14
- target[key] = source[key];
15
- }
16
- return target;
17
- }
18
- function _toPrimitive(input, hint) {
19
- if (typeof input !== "object" || input === null) return input;
20
- var prim = input[Symbol.toPrimitive];
21
- if (prim !== undefined) {
22
- var res = prim.call(input, hint || "default");
23
- if (typeof res !== "object") return res;
24
- throw new TypeError("@@toPrimitive must return a primitive value.");
25
- }
26
- return (hint === "string" ? String : Number)(input);
27
- }
28
- function _toPropertyKey(arg) {
29
- var key = _toPrimitive(arg, "string");
30
- return typeof key === "symbol" ? key : String(key);
31
- }
6
+ /******************************************************************************
7
+ Copyright (c) Microsoft Corporation.
8
+
9
+ Permission to use, copy, modify, and/or distribute this software for any
10
+ purpose with or without fee is hereby granted.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
13
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
14
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
15
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
16
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
17
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
18
+ PERFORMANCE OF THIS SOFTWARE.
19
+ ***************************************************************************** */
20
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
21
+
22
+
23
+ function __rest(s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ }
34
+
35
+ function __awaiter(thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ }
44
+
45
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
46
+ var e = new Error(message);
47
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
48
+ };
32
49
 
33
50
  const CONTAINER_WIDTH = 432;
34
51
  const BUTTON_WIDTH = 48;
@@ -39,8 +56,7 @@ const TRANSFORM_CLOSED_HIDE = `translate(${CONTAINER_WIDTH}px, 0px)`;
39
56
  const TRANSFORM_OPEN = `translate(0px, 0px)`;
40
57
  class WidgetContainer {
41
58
  constructor(options) {
42
- var _options$ui;
43
- this.container = void 0;
59
+ var _a, _b;
44
60
  this.options = options;
45
61
  this.container = document.createElement('div');
46
62
  this.container.classList.add(WidgetContainer.CONTAINER_CLASS);
@@ -51,7 +67,7 @@ class WidgetContainer {
51
67
  this.container.style.width = `${CONTAINER_WIDTH}px`;
52
68
  this.container.style.height = `${BUTTON_HEIGHT}px`;
53
69
  this.container.style.overflow = 'hidden';
54
- if ((_options$ui = options.ui) != null && (_options$ui = _options$ui.opener) != null && _options$ui.hide) {
70
+ if ((_b = (_a = options.ui) === null || _a === void 0 ? void 0 : _a.opener) === null || _b === void 0 ? void 0 : _b.hide) {
55
71
  this.container.style.transform = TRANSFORM_CLOSED_HIDE;
56
72
  } else {
57
73
  this.container.style.transform = TRANSFORM_CLOSED;
@@ -67,8 +83,8 @@ class WidgetContainer {
67
83
  this.container.style.bottom = `0px`;
68
84
  }
69
85
  close() {
70
- var _this$options$ui;
71
- if ((_this$options$ui = this.options.ui) != null && (_this$options$ui = _this$options$ui.opener) != null && _this$options$ui.hide) {
86
+ var _a, _b;
87
+ if ((_b = (_a = this.options.ui) === null || _a === void 0 ? void 0 : _a.opener) === null || _b === void 0 ? void 0 : _b.hide) {
72
88
  this.container.style.transform = TRANSFORM_CLOSED_HIDE;
73
89
  } else {
74
90
  this.container.style.transform = TRANSFORM_CLOSED;
@@ -87,11 +103,11 @@ class WidgetContainer {
87
103
  }
88
104
  WidgetContainer.CONTAINER_CLASS = 'nt-preview-widget-container';
89
105
 
106
+ var _a;
90
107
  class NinetailedPreviewPlugin extends NinetailedPlugin {
91
108
  constructor(options) {
92
- var _this;
93
109
  super();
94
- _this = this;
110
+ this.options = options;
95
111
  this.name = 'ninetailed:preview' + Math.random();
96
112
  this.isOpen = false;
97
113
  this.experiences = [];
@@ -104,62 +120,60 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
104
120
  this.container = null;
105
121
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
122
  this.bridge = null;
107
- /**
108
- * Since several instances of the plugin can be created, we need to make sure only one is marked as active.
123
+ /**
124
+ * Since several instances of the plugin can be created, we need to make sure only one is marked as active.
109
125
  */
110
126
  this.isActiveInstance = false;
111
127
  this.onChangeEmitter = new OnChangeEmitter();
112
- this.onOpenExperienceEditor = void 0;
113
- this.onOpenAudienceEditor = void 0;
114
128
  this.clientId = null;
115
129
  this.environment = null;
116
- this.initialize = async function () {
130
+ this.initialize = () => __awaiter(this, void 0, void 0, function* () {
131
+ var _b, _c;
117
132
  if (typeof window !== 'undefined') {
118
- var _window$ninetailed, _this$changes;
119
133
  if (WidgetContainer.isContainerAttached()) {
120
134
  logger.warn('Preview plugin is already attached.');
121
- _this.isActiveInstance = false;
135
+ this.isActiveInstance = false;
122
136
  return;
123
137
  }
124
138
  const {
125
139
  PreviewBridge
126
- } = await import('@ninetailed/experience.js-preview-bridge');
127
- _this.isActiveInstance = true;
128
- _this.container = new WidgetContainer({
129
- ui: _this.options.ui
140
+ } = yield import('@ninetailed/experience.js-preview-bridge');
141
+ this.isActiveInstance = true;
142
+ this.container = new WidgetContainer({
143
+ ui: this.options.ui
130
144
  });
131
- _this.bridge = PreviewBridge({
132
- url: _this.options.url,
133
- nonce: _this.options.nonce
145
+ this.bridge = PreviewBridge({
146
+ url: this.options.url,
147
+ nonce: this.options.nonce
134
148
  });
135
- _this.bridge.render(_this.container.element);
149
+ this.bridge.render(this.container.element);
136
150
  window.ninetailed = Object.assign({}, window.ninetailed, {
137
- plugins: Object.assign({}, (_window$ninetailed = window.ninetailed) == null ? void 0 : _window$ninetailed.plugins, {
138
- preview: _this.windowApi
151
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
152
+ preview: this.windowApi
139
153
  })
140
154
  });
141
- _this.bridge.updateProps({
142
- props: _this.pluginApi
155
+ this.bridge.updateProps({
156
+ props: this.pluginApi
143
157
  });
144
- if (!((_this$changes = _this.changes) != null && _this$changes.length)) {
145
- _this.onChange();
158
+ if (!((_c = this.changes) === null || _c === void 0 ? void 0 : _c.length)) {
159
+ this.onChange();
146
160
  }
147
161
  }
148
- };
162
+ });
149
163
  this.loaded = () => true;
150
- this[PROFILE_CHANGE] = ({
164
+ this[_a] = ({
151
165
  payload
152
166
  }) => {
153
167
  if (!this.isActiveInstance) {
154
168
  return;
155
169
  }
156
- if (payload != null && payload.profile) {
170
+ if (payload === null || payload === void 0 ? void 0 : payload.profile) {
157
171
  this.onProfileChange(payload.profile, payload.changes || []);
158
172
  }
159
173
  };
160
- /**
161
- * Implements the HasChangesModificationMiddleware interface
162
- * Returns a middleware function that applies variable overwrites to changes
174
+ /**
175
+ * Implements the HasChangesModificationMiddleware interface
176
+ * Returns a middleware function that applies variable overwrites to changes
163
177
  */
164
178
  this.getChangesModificationMiddleware = () => {
165
179
  if (!this.isActiveInstance || Object.keys(this.variableOverwrites).length === 0 && Object.keys(this.audienceOverwrites).length === 0) {
@@ -174,11 +188,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
174
188
  };
175
189
  }
176
190
  const filteredChanges = inputChanges.filter(change => {
177
- var _change$meta, _experience$audience;
178
- const experienceId = (_change$meta = change.meta) == null ? void 0 : _change$meta.experienceId;
191
+ var _b, _c;
192
+ const experienceId = (_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId;
179
193
  if (!experienceId) return true;
180
194
  const experience = this.experiences.find(e => e.id === experienceId);
181
- if (!(experience != null && (_experience$audience = experience.audience) != null && _experience$audience.id)) return true;
195
+ if (!((_c = experience === null || experience === void 0 ? void 0 : experience.audience) === null || _c === void 0 ? void 0 : _c.id)) return true;
182
196
  return this.audienceOverwrites[experience.audience.id] !== false;
183
197
  });
184
198
  return {
@@ -205,12 +219,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
205
219
  variantIndex: 0
206
220
  };
207
221
  }
208
-
209
222
  // Handle entry replacements as before
210
223
  const entryReplacementComponents = experience.components.filter(component => component.type === ComponentTypeEnum.EntryReplacement && 'id' in component.baseline);
211
224
  const baselineComponent = entryReplacementComponents.find(component => component.baseline.id === baseline.id);
212
225
  const variantIndex = this.pluginApi.experienceVariantIndexes[experience.id];
213
-
214
226
  // Continue with entry replacement handling
215
227
  if (!baselineComponent) {
216
228
  return {
@@ -243,11 +255,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
243
255
  };
244
256
  };
245
257
  this.onChange = () => {
258
+ var _b;
246
259
  logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
247
260
  if (typeof window !== 'undefined') {
248
- var _window$ninetailed2;
249
261
  window.ninetailed = Object.assign({}, window.ninetailed, {
250
- plugins: Object.assign({}, (_window$ninetailed2 = window.ninetailed) == null ? void 0 : _window$ninetailed2.plugins, {
262
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
251
263
  preview: this.windowApi
252
264
  })
253
265
  });
@@ -263,26 +275,23 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
263
275
  profile,
264
276
  changes
265
277
  });
266
-
267
278
  // If changes are provided, update them
268
279
  if (changes) {
269
280
  this.onChangesChange(changes);
270
281
  }
271
282
  this.onChange();
272
283
  };
273
- /**
274
- * Handles changes from the SDK and applies any variable overrides.
275
- * This should be called whenever the original changes are updated.
284
+ /**
285
+ * Handles changes from the SDK and applies any variable overrides.
286
+ * This should be called whenever the original changes are updated.
276
287
  */
277
288
  this.onChangesChange = incomingChanges => {
278
289
  if (!this.isActiveInstance) {
279
290
  return;
280
291
  }
281
292
  logger.debug('Received changes:', incomingChanges);
282
-
283
293
  // Store the original changes
284
294
  this.changes = incomingChanges;
285
-
286
295
  // Notify listeners and update UI
287
296
  this.onChange();
288
297
  };
@@ -293,27 +302,26 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
293
302
  this.clientId = clientId;
294
303
  this.environment = environment;
295
304
  };
296
- this.options = options;
297
305
  this.experiences = options.experiences || [];
298
306
  this.audienceDefinitions = options.audiences || [];
299
307
  this.onOpenExperienceEditor = options.onOpenExperienceEditor;
300
308
  this.onOpenAudienceEditor = options.onOpenAudienceEditor;
301
309
  }
302
310
  open() {
303
- var _this$container;
311
+ var _b;
304
312
  if (!this.isActiveInstance) {
305
313
  return;
306
314
  }
307
- (_this$container = this.container) == null || _this$container.open();
315
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.open();
308
316
  this.isOpen = true;
309
317
  this.onChange();
310
318
  }
311
319
  close() {
312
- var _this$container2;
320
+ var _b;
313
321
  if (!this.isActiveInstance) {
314
322
  return;
315
323
  }
316
- (_this$container2 = this.container) == null || _this$container2.close();
324
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.close();
317
325
  setTimeout(() => {
318
326
  this.isOpen = false;
319
327
  this.onChange();
@@ -337,23 +345,22 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
337
345
  logger.warn(`You cannot activate an unknown audience (id: ${id}).`);
338
346
  return;
339
347
  }
340
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
348
+ this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
341
349
  [id]: true
342
350
  });
343
- this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
344
- var _experience$audience2;
345
- return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
351
+ this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), this.experiences.filter(experience => {
352
+ var _b;
353
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
346
354
  }).map(experience => experience.id).reduce((acc, curr) => {
347
- return Object.assign({}, acc, {
355
+ return Object.assign(Object.assign({}, acc), {
348
356
  [curr]: this.experienceVariantIndexes[curr] || 0
349
357
  });
350
358
  }, {}));
351
359
  this.experiences.filter(experience => {
352
- var _experience$audience3;
353
- return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
360
+ var _b;
361
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
354
362
  }).forEach(experience => {
355
363
  const variantIndex = this.experienceVariantIndexOverwrites[experience.id] || 0;
356
-
357
364
  // Keep inline variable flags in sync when forcing an audience.
358
365
  this.applyInlineVariableOverridesForExperience(experience, variantIndex);
359
366
  });
@@ -367,7 +374,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
367
374
  logger.warn(`You cannot deactivate an unknown audience (id: ${id}). How did you get it in the first place?`);
368
375
  return;
369
376
  }
370
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
377
+ this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
371
378
  [id]: false
372
379
  });
373
380
  this.onChange();
@@ -380,32 +387,29 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
380
387
  logger.warn(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
381
388
  return;
382
389
  }
383
-
384
390
  // Identify all experiences that belong to this audience
385
391
  const experiencesToReset = this.experiences.filter(experience => {
386
- var _experience$audience4;
387
- return ((_experience$audience4 = experience.audience) == null ? void 0 : _experience$audience4.id) === id;
392
+ var _b;
393
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
388
394
  });
389
395
  if (experiencesToReset.length > 0) {
390
396
  const experienceIdsToReset = experiencesToReset.map(e => e.id);
391
-
392
397
  // 1. Clear any variable overwrites that were set for these experiences (allows natural evaluation)
393
398
  this.variableOverwrites = Object.fromEntries(Object.entries(this.variableOverwrites).filter(([, change]) => {
394
- var _change$meta2;
395
- return !((_change$meta2 = change.meta) != null && _change$meta2.experienceId && experienceIdsToReset.includes(change.meta.experienceId));
399
+ var _b;
400
+ return !(((_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId) && experienceIdsToReset.includes(change.meta.experienceId));
396
401
  }));
397
-
398
402
  // 2. Clear experience variant index overwrites for these experiences (allows natural variant selection)
399
403
  this.experienceVariantIndexOverwrites = Object.fromEntries(Object.entries(this.experienceVariantIndexOverwrites).filter(([key]) => !experienceIdsToReset.includes(key)));
400
404
  }
401
-
402
405
  // 3. Remove audience override (allows natural audience evaluation)
403
- const _this$audienceOverwri = this.audienceOverwrites,
404
- audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
406
+ const _b = this.audienceOverwrites,
407
+ _c = id;
408
+ _b[_c];
409
+ const audienceOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
405
410
  this.audienceOverwrites = audienceOverwrites;
406
411
  this.onChange();
407
412
  }
408
-
409
413
  // This is exposed to the window api but not used
410
414
  setExperienceVariant({
411
415
  experienceId,
@@ -420,8 +424,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
420
424
  return;
421
425
  }
422
426
  if (experience.audience && !this.activeAudiences.some(id => {
423
- var _experience$audience5;
424
- return id === ((_experience$audience5 = experience.audience) == null ? void 0 : _experience$audience5.id);
427
+ var _b;
428
+ return id === ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id);
425
429
  })) {
426
430
  logger.warn(`Cannot activate a variant for an experience (id: ${experienceId}) which is not in the active audiences.`);
427
431
  return;
@@ -430,13 +434,11 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
430
434
  if (!isValidIndex) {
431
435
  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.`);
432
436
  }
433
-
434
437
  // Update the experience variant index
435
- this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, {
438
+ this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), {
436
439
  [experienceId]: variantIndex
437
440
  });
438
441
  this.applyInlineVariableOverridesForExperience(experience, variantIndex);
439
-
440
442
  // Trigger change notification - this updates the middleware
441
443
  this.onChange();
442
444
  }
@@ -444,8 +446,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
444
446
  if (!this.isActiveInstance) {
445
447
  return;
446
448
  }
447
- const _this$experienceVaria = this.experienceVariantIndexOverwrites,
448
- experienceVariantIndexOverwrites = _objectWithoutPropertiesLoose(_this$experienceVaria, [experienceId].map(_toPropertyKey));
449
+ const _b = this.experienceVariantIndexOverwrites,
450
+ _c = experienceId;
451
+ _b[_c];
452
+ const experienceVariantIndexOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
449
453
  this.experienceVariantIndexOverwrites = experienceVariantIndexOverwrites;
450
454
  this.onChange();
451
455
  }
@@ -457,8 +461,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
457
461
  window.ninetailed.reset();
458
462
  }
459
463
  }
460
- /**
461
- * Sets a variable value override for preview
464
+ /**
465
+ * Sets a variable value override for preview
462
466
  */
463
467
  setVariableValue({
464
468
  experienceId,
@@ -466,17 +470,15 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
466
470
  value,
467
471
  variantIndex
468
472
  }) {
469
- var _this$variableOverwri;
473
+ var _b;
470
474
  if (!this.isActiveInstance) {
471
475
  return;
472
476
  }
473
477
  const overrideKey = `${experienceId}:${key}`;
474
-
475
478
  // Only create new object if actually changing
476
- if (isEqual((_this$variableOverwri = this.variableOverwrites[overrideKey]) == null ? void 0 : _this$variableOverwri.value, value)) {
479
+ if (isEqual((_b = this.variableOverwrites[overrideKey]) === null || _b === void 0 ? void 0 : _b.value, value)) {
477
480
  return; // No change needed
478
481
  }
479
-
480
482
  const change = {
481
483
  type: ChangeTypes.Variable,
482
484
  key,
@@ -486,12 +488,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
486
488
  variantIndex
487
489
  }
488
490
  };
489
-
490
491
  // Update variable overwrites
491
- this.variableOverwrites = Object.assign({}, this.variableOverwrites, {
492
+ this.variableOverwrites = Object.assign(Object.assign({}, this.variableOverwrites), {
492
493
  [overrideKey]: change
493
494
  });
494
-
495
495
  // Notify listeners
496
496
  this.onChangeEmitter.invokeListeners();
497
497
  this.onChange();
@@ -499,9 +499,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
499
499
  openExperienceEditor(experience) {
500
500
  if (this.onOpenExperienceEditor && typeof this.onOpenExperienceEditor === 'function') return this.onOpenExperienceEditor(experience);
501
501
  }
502
-
503
- /**
504
- * @deprecated This method will be removed in a future release. Use `openExperienceEditor` instead to see the experience insights.
502
+ /**
503
+ * @deprecated This method will be removed in a future release. Use `openExperienceEditor` instead to see the experience insights.
505
504
  */
506
505
  openExperienceAnalytics(experience) {
507
506
  logger.warn('The `openExperienceAnalytics` method is deprecated and will be removed in a future release. Use `openExperienceEditor` instead to see the experience insights.');
@@ -511,9 +510,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
511
510
  if (this.onOpenAudienceEditor && typeof this.onOpenAudienceEditor === 'function') return this.onOpenAudienceEditor(audience);
512
511
  }
513
512
  get pluginApi() {
514
- var _this$profile;
513
+ var _b;
515
514
  return {
516
- version: "7.18.11" ,
515
+ version: "7.18.13",
517
516
  open: this.open.bind(this),
518
517
  close: this.close.bind(this),
519
518
  toggle: this.toggle.bind(this),
@@ -521,14 +520,14 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
521
520
  activateAudience: this.activateAudience.bind(this),
522
521
  deactivateAudience: this.deactivateAudience.bind(this),
523
522
  resetAudience: this.resetAudience.bind(this),
524
- apiAudiences: ((_this$profile = this.profile) == null ? void 0 : _this$profile.audiences) || [],
523
+ apiAudiences: ((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || [],
525
524
  audienceOverwrites: this.audienceOverwrites,
526
525
  activeAudiences: this.activeAudiences,
527
526
  audienceDefinitions: this.audienceDefinitions,
528
527
  setExperienceVariant: this.setExperienceVariant.bind(this),
529
528
  resetExperience: this.resetExperience.bind(this),
530
529
  apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
531
- experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites),
530
+ experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
532
531
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
533
532
  reset: this.reset.bind(this),
534
533
  experiences: this.experiences,
@@ -549,7 +548,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
549
548
  activeAudiences: this.activeAudiences,
550
549
  setExperienceVariant: this.setExperienceVariant.bind(this),
551
550
  resetExperience: this.resetExperience.bind(this),
552
- experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites),
551
+ experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
553
552
  setVariableValue: this.setVariableValue.bind(this),
554
553
  variableOverwrites: this.variableOverwrites
555
554
  };
@@ -562,10 +561,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
562
561
  return unionBy(this.audienceDefinitions, audiencesFromExperiences, 'id');
563
562
  }
564
563
  get activeAudiences() {
565
- var _this$profile2;
564
+ var _b;
566
565
  const deactivatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => !active).map(([id]) => id);
567
566
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
568
- return [...(((_this$profile2 = this.profile) == null ? void 0 : _this$profile2.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
567
+ return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
569
568
  }
570
569
  calculateExperienceVariantIndexes(profile) {
571
570
  const matchedExperiences = this.experiences.filter(experience => isExperienceMatch({
@@ -577,7 +576,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
577
576
  experience,
578
577
  profile
579
578
  });
580
- return Object.assign({}, acc, {
579
+ return Object.assign(Object.assign({}, acc), {
581
580
  [experience.id]: distribution.index
582
581
  });
583
582
  }, {});
@@ -594,32 +593,30 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
594
593
  if (!profile) {
595
594
  return {};
596
595
  }
597
- return this.calculateExperienceVariantIndexes(Object.assign({}, profile, {
596
+ return this.calculateExperienceVariantIndexes(Object.assign(Object.assign({}, profile), {
598
597
  audiences: this.activeAudiences
599
598
  }));
600
599
  }
601
-
602
- /**
603
- * Get the override key for a variable
600
+ /**
601
+ * Get the override key for a variable
604
602
  */
605
603
  getOverrideKey(experienceId, key) {
606
604
  return `${experienceId}:${key}`;
607
605
  }
608
-
609
- /**
610
- * Ensure inline variables for a given experience reflect the selected variant
611
- * without triggering multiple onChange calls. Keeps custom flags in sync with forced variants.
606
+ /**
607
+ * Ensure inline variables for a given experience reflect the selected variant
608
+ * without triggering multiple onChange calls. Keeps custom flags in sync with forced variants.
612
609
  */
613
610
  applyInlineVariableOverridesForExperience(experience, variantIndex) {
614
611
  const {
615
612
  hasChanges,
616
613
  overrides
617
614
  } = experience.components.reduce((acc, component) => {
618
- var _component$variants$v, _component$variants, _currentOverride$meta;
615
+ var _b, _c, _d;
619
616
  if (component.type !== ComponentTypeEnum.InlineVariable) {
620
617
  return acc;
621
618
  }
622
- const value = variantIndex === 0 ? component.baseline.value : (_component$variants$v = (_component$variants = component.variants[variantIndex - 1]) == null ? void 0 : _component$variants.value) != null ? _component$variants$v : component.baseline.value;
619
+ const value = variantIndex === 0 ? component.baseline.value : (_c = (_b = component.variants[variantIndex - 1]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : component.baseline.value;
623
620
  const overrideKey = this.getOverrideKey(experience.id, component.key);
624
621
  const currentOverride = acc.overrides[overrideKey];
625
622
  const nextChange = {
@@ -631,12 +628,12 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
631
628
  variantIndex
632
629
  }
633
630
  };
634
- if (currentOverride && isEqual(currentOverride.value, value) && ((_currentOverride$meta = currentOverride.meta) == null ? void 0 : _currentOverride$meta.variantIndex) === variantIndex) {
631
+ if (currentOverride && isEqual(currentOverride.value, value) && ((_d = currentOverride.meta) === null || _d === void 0 ? void 0 : _d.variantIndex) === variantIndex) {
635
632
  return acc;
636
633
  }
637
634
  return {
638
635
  hasChanges: true,
639
- overrides: Object.assign({}, acc.overrides, {
636
+ overrides: Object.assign(Object.assign({}, acc.overrides), {
640
637
  [overrideKey]: nextChange
641
638
  })
642
639
  };
@@ -648,29 +645,27 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
648
645
  this.variableOverwrites = overrides;
649
646
  }
650
647
  }
651
-
652
- /**
653
- * Get effective changes by applying overwrites - compute on demand
648
+ /**
649
+ * Get effective changes by applying overwrites - compute on demand
654
650
  */
655
651
  getEffectiveChanges(inputChanges = this.changes) {
656
652
  if (!inputChanges || Object.keys(this.variableOverwrites).length === 0) {
657
653
  return inputChanges || [];
658
654
  }
659
-
660
655
  // Filter out changes that we're overriding
661
656
  const filteredChanges = inputChanges.filter(change => {
662
- var _change$meta3;
657
+ var _b;
663
658
  if (change.type !== ChangeTypes.Variable) return true;
664
- const changeKey = (_change$meta3 = change.meta) != null && _change$meta3.experienceId ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
659
+ const changeKey = ((_b = change.meta) === null || _b === void 0 ? void 0 : _b.experienceId) ? this.getOverrideKey(change.meta.experienceId, change.key) : change.key;
665
660
  return !this.variableOverwrites[changeKey];
666
661
  });
667
662
  const effectiveChanges = [...filteredChanges, ...Object.values(this.variableOverwrites)];
668
663
  logger.debug('Overridden changes after applying override:', effectiveChanges);
669
-
670
664
  // Add our overrides to create the final result
671
665
  return effectiveChanges;
672
666
  }
673
667
  }
668
+ _a = PROFILE_CHANGE;
674
669
 
675
670
  if (typeof window === 'object' && !('process' in window)) {
676
671
  // 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.18.11",
3
+ "version": "7.18.13",
4
4
  "description": "Ninetailed SDK plugin for preview",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
- "@ninetailed/experience.js-shared": "7.18.11",
32
- "@ninetailed/experience.js": "7.18.11",
33
- "@ninetailed/experience.js-preview-bridge": "7.18.11",
34
- "@ninetailed/experience.js-plugin-analytics": "7.18.11",
31
+ "@ninetailed/experience.js-shared": "7.18.13",
32
+ "@ninetailed/experience.js": "7.18.13",
33
+ "@ninetailed/experience.js-preview-bridge": "7.18.13",
34
+ "@ninetailed/experience.js-plugin-analytics": "7.18.13",
35
35
  "radash": "10.9.0"
36
36
  }
37
37
  }