@ninetailed/experience.js-plugin-preview 7.5.3-beta.2 → 7.5.3-beta.3

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.
@@ -1,31 +1,41 @@
1
1
  import { logger, unionBy } from '@ninetailed/experience.js-shared';
2
- import { NinetailedPlugin, OnChangeEmitter, PROFILE_CHANGE, isExperienceMatch, selectDistribution } from '@ninetailed/experience.js';
2
+ import { NinetailedPlugin, OnChangeEmitter, isExperienceMatch, selectDistribution, PROFILE_CHANGE } from '@ninetailed/experience.js';
3
3
 
4
- function _objectWithoutPropertiesLoose(source, excluded) {
5
- if (source == null) return {};
6
- var target = {};
7
- var sourceKeys = Object.keys(source);
8
- var key, i;
9
- for (i = 0; i < sourceKeys.length; i++) {
10
- key = sourceKeys[i];
11
- if (excluded.indexOf(key) >= 0) continue;
12
- target[key] = source[key];
13
- }
14
- return target;
15
- }
16
- function _toPrimitive(input, hint) {
17
- if (typeof input !== "object" || input === null) return input;
18
- var prim = input[Symbol.toPrimitive];
19
- if (prim !== undefined) {
20
- var res = prim.call(input, hint || "default");
21
- if (typeof res !== "object") return res;
22
- throw new TypeError("@@toPrimitive must return a primitive value.");
23
- }
24
- return (hint === "string" ? String : Number)(input);
25
- }
26
- function _toPropertyKey(arg) {
27
- var key = _toPrimitive(arg, "string");
28
- return typeof key === "symbol" ? key : String(key);
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+
19
+ function __rest(s, e) {
20
+ var t = {};
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
22
+ t[p] = s[p];
23
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
24
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
25
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
26
+ t[p[i]] = s[p[i]];
27
+ }
28
+ return t;
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
+ });
29
39
  }
30
40
 
31
41
  const CONTAINER_WIDTH = 432;
@@ -37,8 +47,7 @@ const TRANSFORM_CLOSED_HIDE = `translate(${CONTAINER_WIDTH}px, 0px)`;
37
47
  const TRANSFORM_OPEN = `translate(0px, 0px)`;
38
48
  class WidgetContainer {
39
49
  constructor(options) {
40
- var _options$ui;
41
- this.container = void 0;
50
+ var _a, _b;
42
51
  this.options = options;
43
52
  this.container = document.createElement('div');
44
53
  this.container.style.position = 'fixed';
@@ -47,7 +56,7 @@ class WidgetContainer {
47
56
  this.container.style.bottom = `${BUTTON_BOTTOM_POSITION}px`;
48
57
  this.container.style.width = `${CONTAINER_WIDTH}px`;
49
58
  this.container.style.height = `${BUTTON_HEIGHT}px`;
50
- if ((_options$ui = options.ui) != null && (_options$ui = _options$ui.opener) != null && _options$ui.hide) {
59
+ if ((_b = (_a = options.ui) === null || _a === void 0 ? void 0 : _a.opener) === null || _b === void 0 ? void 0 : _b.hide) {
51
60
  this.container.style.transform = TRANSFORM_CLOSED_HIDE;
52
61
  } else {
53
62
  this.container.style.transform = TRANSFORM_CLOSED;
@@ -63,8 +72,8 @@ class WidgetContainer {
63
72
  this.container.style.bottom = `0px`;
64
73
  }
65
74
  close() {
66
- var _this$options$ui;
67
- if ((_this$options$ui = this.options.ui) != null && (_this$options$ui = _this$options$ui.opener) != null && _this$options$ui.hide) {
75
+ var _a, _b;
76
+ if ((_b = (_a = this.options.ui) === null || _a === void 0 ? void 0 : _a.opener) === null || _b === void 0 ? void 0 : _b.hide) {
68
77
  this.container.style.transform = TRANSFORM_CLOSED_HIDE;
69
78
  } else {
70
79
  this.container.style.transform = TRANSFORM_CLOSED;
@@ -79,11 +88,11 @@ class WidgetContainer {
79
88
  }
80
89
  }
81
90
 
91
+ var _a;
82
92
  class NinetailedPreviewPlugin extends NinetailedPlugin {
83
93
  constructor(options) {
84
- var _this;
85
94
  super();
86
- _this = this;
95
+ this.options = options;
87
96
  this.name = 'ninetailed:preview' + Math.random();
88
97
  this.isOpen = false;
89
98
  this.experiences = [];
@@ -94,38 +103,36 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
94
103
  this.container = null;
95
104
  this.bridge = null;
96
105
  this.onChangeEmitter = new OnChangeEmitter();
97
- this.onOpenExperienceEditor = void 0;
98
- this.onOpenAudienceEditor = void 0;
99
106
  this.clientId = null;
100
107
  this.environment = null;
101
- this.initialize = async function () {
108
+ this.initialize = () => __awaiter(this, void 0, void 0, function* () {
109
+ var _b;
102
110
  if (typeof window !== 'undefined') {
103
- var _window$ninetailed;
104
111
  const {
105
112
  PreviewBridge
106
- } = await import('@ninetailed/experience.js-preview-bridge');
107
- _this.container = new WidgetContainer({
108
- ui: _this.options.ui
113
+ } = yield import('@ninetailed/experience.js-preview-bridge');
114
+ this.container = new WidgetContainer({
115
+ ui: this.options.ui
109
116
  });
110
- _this.bridge = PreviewBridge({
111
- url: _this.options.url
117
+ this.bridge = PreviewBridge({
118
+ url: this.options.url
112
119
  });
113
- _this.bridge.render(_this.container.element);
120
+ this.bridge.render(this.container.element);
114
121
  window.ninetailed = Object.assign({}, window.ninetailed, {
115
- plugins: Object.assign({}, (_window$ninetailed = window.ninetailed) == null ? void 0 : _window$ninetailed.plugins, {
116
- preview: _this.windowApi
122
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
123
+ preview: this.windowApi
117
124
  })
118
125
  });
119
- _this.bridge.updateProps({
120
- props: _this.pluginApi
126
+ this.bridge.updateProps({
127
+ props: this.pluginApi
121
128
  });
122
129
  }
123
- };
130
+ });
124
131
  this.loaded = () => true;
125
- this[PROFILE_CHANGE] = ({
132
+ this[_a] = ({
126
133
  payload
127
134
  }) => {
128
- if (payload != null && payload.profile) {
135
+ if (payload === null || payload === void 0 ? void 0 : payload.profile) {
129
136
  this.onProfileChange(payload.profile);
130
137
  }
131
138
  };
@@ -137,8 +144,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
137
144
  const experienceIds = Object.keys(this.pluginApi.experienceVariantIndexes);
138
145
  const experience = experiences.find(experience => {
139
146
  const hasActiveAudience = this.pluginApi.activeAudiences.some(activeAudienceId => {
140
- var _experience$audience;
141
- return ((_experience$audience = experience.audience) == null ? void 0 : _experience$audience.id) === activeAudienceId;
147
+ var _b;
148
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === activeAudienceId;
142
149
  });
143
150
  return hasActiveAudience && experienceIds.includes(experience.id);
144
151
  });
@@ -182,10 +189,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
182
189
  };
183
190
  };
184
191
  this.onChange = () => {
185
- var _window$ninetailed2;
192
+ var _b;
186
193
  logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
187
194
  Object.assign({}, window.ninetailed, {
188
- plugins: Object.assign({}, (_window$ninetailed2 = window.ninetailed) == null ? void 0 : _window$ninetailed2.plugins, {
195
+ plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
189
196
  preview: this.windowApi
190
197
  })
191
198
  });
@@ -205,21 +212,20 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
205
212
  this.clientId = clientId;
206
213
  this.environment = environment;
207
214
  };
208
- this.options = options;
209
215
  this.experiences = options.experiences || [];
210
216
  this.audienceDefinitions = options.audiences || [];
211
217
  this.onOpenExperienceEditor = options.onOpenExperienceEditor;
212
218
  this.onOpenAudienceEditor = options.onOpenAudienceEditor;
213
219
  }
214
220
  open() {
215
- var _this$container;
216
- (_this$container = this.container) == null || _this$container.open();
221
+ var _b;
222
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.open();
217
223
  this.isOpen = true;
218
224
  this.onChange();
219
225
  }
220
226
  close() {
221
- var _this$container2;
222
- (_this$container2 = this.container) == null || _this$container2.close();
227
+ var _b;
228
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.close();
223
229
  setTimeout(() => {
224
230
  this.isOpen = false;
225
231
  this.onChange();
@@ -237,14 +243,14 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
237
243
  console.log(`You cannot activate an unknown audience (id: ${id}).`);
238
244
  return;
239
245
  }
240
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
246
+ this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
241
247
  [id]: true
242
248
  });
243
- this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
244
- var _experience$audience2;
245
- return ((_experience$audience2 = experience.audience) == null ? void 0 : _experience$audience2.id) === id;
249
+ this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), this.experiences.filter(experience => {
250
+ var _b;
251
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
246
252
  }).map(experience => experience.id).reduce((acc, curr) => {
247
- return Object.assign({}, acc, {
253
+ return Object.assign(Object.assign({}, acc), {
248
254
  [curr]: this.experienceVariantIndexes[curr] || 0
249
255
  });
250
256
  }, {}));
@@ -257,28 +263,28 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
257
263
  }
258
264
  this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
259
265
  return !this.experiences.filter(experience => {
260
- var _experience$audience3;
261
- return ((_experience$audience3 = experience.audience) == null ? void 0 : _experience$audience3.id) === id;
266
+ var _b;
267
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
262
268
  }).map(experience => experience.id).includes(key);
263
269
  }).reduce((acc, [key, value]) => {
264
- return Object.assign({}, acc, {
270
+ return Object.assign(Object.assign({}, acc), {
265
271
  [key]: value
266
272
  });
267
273
  }, {});
268
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
274
+ this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
269
275
  [id]: false
270
276
  });
271
277
  this.onChange();
272
278
  this.experiences.filter(experience => {
273
- var _experience$audience4;
274
- return ((_experience$audience4 = experience.audience) == null ? void 0 : _experience$audience4.id) === id;
279
+ var _b;
280
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
275
281
  }).forEach(experience => {
276
282
  this.setExperienceVariant({
277
283
  experienceId: experience.id,
278
284
  variantIndex: 0
279
285
  });
280
286
  });
281
- this.audienceOverwrites = Object.assign({}, this.audienceOverwrites, {
287
+ this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
282
288
  [id]: false
283
289
  });
284
290
  this.onChange();
@@ -288,8 +294,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
288
294
  console.log(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
289
295
  return;
290
296
  }
291
- const _this$audienceOverwri = this.audienceOverwrites,
292
- audienceOverwrites = _objectWithoutPropertiesLoose(_this$audienceOverwri, [id].map(_toPropertyKey));
297
+ const _b = this.audienceOverwrites,
298
+ _c = id;
299
+ _b[_c];
300
+ const audienceOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
293
301
  this.audienceOverwrites = audienceOverwrites;
294
302
  this.onChange();
295
303
  }
@@ -303,8 +311,8 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
303
311
  return;
304
312
  }
305
313
  if (experience.audience && !this.activeAudiences.some(id => {
306
- var _experience$audience5;
307
- return id === ((_experience$audience5 = experience.audience) == null ? void 0 : _experience$audience5.id);
314
+ var _b;
315
+ return id === ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id);
308
316
  })) {
309
317
  console.log(`You cannot active a variant for an experience (id: ${experienceId}), which is not in the active audiences.`);
310
318
  return;
@@ -313,14 +321,16 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
313
321
  if (!isValidIndex) {
314
322
  console.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.`);
315
323
  }
316
- this.experienceVariantIndexOverwrites = Object.assign({}, this.experienceVariantIndexOverwrites, {
324
+ this.experienceVariantIndexOverwrites = Object.assign(Object.assign({}, this.experienceVariantIndexOverwrites), {
317
325
  [experienceId]: variantIndex
318
326
  });
319
327
  this.onChange();
320
328
  }
321
329
  resetExperience(experienceId) {
322
- const _this$experienceVaria = this.experienceVariantIndexOverwrites,
323
- experienceVariantIndexOverwrites = _objectWithoutPropertiesLoose(_this$experienceVaria, [experienceId].map(_toPropertyKey));
330
+ const _b = this.experienceVariantIndexOverwrites,
331
+ _c = experienceId;
332
+ _b[_c];
333
+ const experienceVariantIndexOverwrites = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
324
334
  this.experienceVariantIndexOverwrites = experienceVariantIndexOverwrites;
325
335
  this.onChange();
326
336
  }
@@ -339,7 +349,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
339
349
  if (this.onOpenAudienceEditor && typeof this.onOpenAudienceEditor === 'function') return this.onOpenAudienceEditor(audience);
340
350
  }
341
351
  get pluginApi() {
342
- var _this$profile;
352
+ var _b;
343
353
  return {
344
354
  version: '2.0.0',
345
355
  open: this.open.bind(this),
@@ -349,14 +359,14 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
349
359
  activateAudience: this.activateAudience.bind(this),
350
360
  deactivateAudience: this.deactivateAudience.bind(this),
351
361
  resetAudience: this.resetAudience.bind(this),
352
- apiAudiences: ((_this$profile = this.profile) == null ? void 0 : _this$profile.audiences) || [],
362
+ apiAudiences: ((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || [],
353
363
  audienceOverwrites: this.audienceOverwrites,
354
364
  activeAudiences: this.activeAudiences,
355
365
  audienceDefinitions: this.audienceDefinitions,
356
366
  setExperienceVariant: this.setExperienceVariant.bind(this),
357
367
  resetExperience: this.resetExperience.bind(this),
358
368
  apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
359
- experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites),
369
+ experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
360
370
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
361
371
  reset: this.reset.bind(this),
362
372
  experiences: this.experiences,
@@ -377,7 +387,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
377
387
  activeAudiences: this.activeAudiences,
378
388
  setExperienceVariant: this.setExperienceVariant.bind(this),
379
389
  resetExperience: this.resetExperience.bind(this),
380
- experienceVariantIndexes: Object.assign({}, this.experienceVariantIndexes, this.experienceVariantIndexOverwrites)
390
+ experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites)
381
391
  };
382
392
  }
383
393
  isKnownAudience(id) {
@@ -388,10 +398,10 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
388
398
  return unionBy(this.audienceDefinitions, audiencesFromExperiences, 'id');
389
399
  }
390
400
  get activeAudiences() {
391
- var _this$profile2;
401
+ var _b;
392
402
  const deactivatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => !active).map(([id]) => id);
393
403
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
394
- return [...(((_this$profile2 = this.profile) == null ? void 0 : _this$profile2.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
404
+ return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
395
405
  }
396
406
  calculateExperienceVariantIndexes(profile) {
397
407
  const matchedExperiences = this.experiences.filter(experience => isExperienceMatch({
@@ -403,7 +413,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
403
413
  experience,
404
414
  profile
405
415
  });
406
- return Object.assign({}, acc, {
416
+ return Object.assign(Object.assign({}, acc), {
407
417
  [experience.id]: distribution.index
408
418
  });
409
419
  }, {});
@@ -420,11 +430,12 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
420
430
  if (!profile) {
421
431
  return {};
422
432
  }
423
- return this.calculateExperienceVariantIndexes(Object.assign({}, profile, {
433
+ return this.calculateExperienceVariantIndexes(Object.assign(Object.assign({}, profile), {
424
434
  audiences: this.activeAudiences
425
435
  }));
426
436
  }
427
437
  }
438
+ _a = PROFILE_CHANGE;
428
439
 
429
440
  if (typeof window === 'object' && !('process' in window)) {
430
441
  // 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.5.3-beta.2",
3
+ "version": "7.5.3-beta.3",
4
4
  "description": "Ninetailed SDK plugin for preview",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,17 +8,14 @@
8
8
  "url": "https://github.com/ninetailed-inc/experience.js.git",
9
9
  "directory": "packages/plugins/preview"
10
10
  },
11
- "keywords": [
12
- "preview",
13
- "ninetailed",
14
- "personalization",
15
- "a/b testing"
16
- ],
11
+ "module": "./index.js",
12
+ "main": "./index.cjs",
13
+ "type": "module",
14
+ "types": "./src/index.d.ts",
17
15
  "dependencies": {
18
- "@ninetailed/experience.js-shared": "*",
19
- "@ninetailed/experience.js": "*",
20
- "@ninetailed/experience.js-preview-bridge": "*"
16
+ "@ninetailed/experience.js": "7.5.3-beta.3",
17
+ "@ninetailed/experience.js-preview-bridge": "7.5.3-beta.3",
18
+ "@ninetailed/experience.js-shared": "7.5.3-beta.3"
21
19
  },
22
- "module": "./index.esm.js",
23
- "main": "./index.cjs.js"
20
+ "peerDependencies": {}
24
21
  }
package/index.cjs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./src/index";
2
- export { default } from "./src/index";
File without changes