@ninetailed/experience.js-plugin-preview 4.2.0-beta.3 → 4.2.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -2,12 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var omit = require('lodash/omit');
6
- var unionBy = require('lodash/unionBy');
5
+ var experience_jsShared = require('@ninetailed/experience.js-shared');
7
6
  var experience_js = require('@ninetailed/experience.js');
8
7
 
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
8
  function _interopNamespace(e) {
12
9
  if (e && e.__esModule) return e;
13
10
  var n = Object.create(null);
@@ -26,9 +23,6 @@ function _interopNamespace(e) {
26
23
  return Object.freeze(n);
27
24
  }
28
25
 
29
- var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
30
- var unionBy__default = /*#__PURE__*/_interopDefaultLegacy(unionBy);
31
-
32
26
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
33
27
 
34
28
  var check = function (it) {
@@ -3122,7 +3116,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3122
3116
  };
3123
3117
  this.onChange = () => {
3124
3118
  var _b;
3125
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3119
+ experience_jsShared.logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3126
3120
  Object.assign({}, window.ninetailed, {
3127
3121
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3128
3122
  preview: this.windowApi
@@ -3171,7 +3165,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3171
3165
  }
3172
3166
  activateAudience(id) {
3173
3167
  if (!this.isKnownAudience(id)) {
3174
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3168
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3175
3169
  return;
3176
3170
  }
3177
3171
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -3201,10 +3195,16 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3201
3195
  // variantIndex: 0,
3202
3196
  // });
3203
3197
  // });
3204
- this.experienceVariantIndexOverwrites = omit__default["default"](this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
3205
- var _b;
3206
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3207
- }).map(experience => experience.id));
3198
+ this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
3199
+ return !this.experiences.filter(experience => {
3200
+ var _b;
3201
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3202
+ }).map(experience => experience.id).includes(key);
3203
+ }).reduce((acc, [key, value]) => {
3204
+ return Object.assign(Object.assign({}, acc), {
3205
+ [key]: value
3206
+ });
3207
+ }, {});
3208
3208
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
3209
3209
  [id]: false
3210
3210
  });
@@ -3212,7 +3212,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3212
3212
  }
3213
3213
  resetAudience(id) {
3214
3214
  if (!this.isKnownAudience(id)) {
3215
- console.log(`You cannot reset an unkown audience (id: ${id}). How did you get it in the first place?`);
3215
+ console.log(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
3216
3216
  return;
3217
3217
  }
3218
3218
  const _b = this.audienceOverwrites,
@@ -3285,6 +3285,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3285
3285
  audienceDefinitions: this.audienceDefinitions,
3286
3286
  setExperienceVariant: this.setExperienceVariant.bind(this),
3287
3287
  resetExperience: this.resetExperience.bind(this),
3288
+ apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
3288
3289
  experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
3289
3290
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
3290
3291
  reset: this.reset.bind(this),
@@ -3313,7 +3314,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3313
3314
  }
3314
3315
  get potentialAudiences() {
3315
3316
  const audiencesFromExperiences = this.experiences.map(experience => experience.audience).filter(audience => !!audience);
3316
- return unionBy__default["default"](this.audienceDefinitions, audiencesFromExperiences, 'id');
3317
+ return experience_jsShared.unionBy(this.audienceDefinitions, audiencesFromExperiences, 'id');
3317
3318
  }
3318
3319
  get activeAudiences() {
3319
3320
  var _b;
@@ -3321,15 +3322,9 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3321
3322
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
3322
3323
  return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
3323
3324
  }
3324
- get experienceVariantIndexes() {
3325
- const profile = this.profile;
3326
- if (!profile) {
3327
- return {};
3328
- }
3325
+ calculateExperienceVariantIndexes(profile) {
3329
3326
  const experiments = this.experiences.filter(experience => experience.type === 'nt_experiment');
3330
- const activeExperiments = experience_js.selectActiveExperiments(experiments, Object.assign(Object.assign({}, profile), {
3331
- audiences: this.activeAudiences
3332
- }));
3327
+ const activeExperiments = experience_js.selectActiveExperiments(experiments, profile);
3333
3328
  const eligibleExperiences = experience_js.selectEligibleExperiences({
3334
3329
  experiences: this.experiences,
3335
3330
  activeExperiments
@@ -3337,22 +3332,34 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3337
3332
  const matchedExperiences = eligibleExperiences.filter(experience => experience_js.isExperienceMatch({
3338
3333
  experience,
3339
3334
  activeExperiments,
3340
- profile: Object.assign(Object.assign({}, profile), {
3341
- audiences: this.activeAudiences
3342
- })
3335
+ profile
3343
3336
  }));
3344
3337
  return matchedExperiences.reduce((acc, experience) => {
3345
3338
  const distribution = experience_js.selectDistribution({
3346
3339
  experience,
3347
- profile: Object.assign(Object.assign({}, profile), {
3348
- audiences: this.activeAudiences
3349
- })
3340
+ profile
3350
3341
  });
3351
3342
  return Object.assign(Object.assign({}, acc), {
3352
3343
  [experience.id]: distribution.index
3353
3344
  });
3354
3345
  }, {});
3355
3346
  }
3347
+ get apiExperienceVariantIndexes() {
3348
+ const profile = this.profile;
3349
+ if (!profile) {
3350
+ return {};
3351
+ }
3352
+ return this.calculateExperienceVariantIndexes(profile);
3353
+ }
3354
+ get experienceVariantIndexes() {
3355
+ const profile = this.profile;
3356
+ if (!profile) {
3357
+ return {};
3358
+ }
3359
+ return this.calculateExperienceVariantIndexes(Object.assign(Object.assign({}, profile), {
3360
+ audiences: this.activeAudiences
3361
+ }));
3362
+ }
3356
3363
  }
3357
3364
  _a = experience_js.PROFILE_CHANGE;
3358
3365
 
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import omit from 'lodash/omit';
2
- import unionBy from 'lodash/unionBy';
1
+ import { logger, unionBy } from '@ninetailed/experience.js-shared';
3
2
  import { NinetailedPlugin, OnChangeEmitter, selectActiveExperiments, selectEligibleExperiences, isExperienceMatch, selectDistribution, PROFILE_CHANGE } from '@ninetailed/experience.js';
4
3
 
5
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -3095,7 +3094,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3095
3094
  };
3096
3095
  this.onChange = () => {
3097
3096
  var _b;
3098
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3097
+ logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3099
3098
  Object.assign({}, window.ninetailed, {
3100
3099
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3101
3100
  preview: this.windowApi
@@ -3144,7 +3143,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3144
3143
  }
3145
3144
  activateAudience(id) {
3146
3145
  if (!this.isKnownAudience(id)) {
3147
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3146
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3148
3147
  return;
3149
3148
  }
3150
3149
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -3174,10 +3173,16 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3174
3173
  // variantIndex: 0,
3175
3174
  // });
3176
3175
  // });
3177
- this.experienceVariantIndexOverwrites = omit(this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
3178
- var _b;
3179
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3180
- }).map(experience => experience.id));
3176
+ this.experienceVariantIndexOverwrites = Object.entries(this.experienceVariantIndexOverwrites).filter(([key, _]) => {
3177
+ return !this.experiences.filter(experience => {
3178
+ var _b;
3179
+ return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3180
+ }).map(experience => experience.id).includes(key);
3181
+ }).reduce((acc, [key, value]) => {
3182
+ return Object.assign(Object.assign({}, acc), {
3183
+ [key]: value
3184
+ });
3185
+ }, {});
3181
3186
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
3182
3187
  [id]: false
3183
3188
  });
@@ -3185,7 +3190,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3185
3190
  }
3186
3191
  resetAudience(id) {
3187
3192
  if (!this.isKnownAudience(id)) {
3188
- console.log(`You cannot reset an unkown audience (id: ${id}). How did you get it in the first place?`);
3193
+ console.log(`You cannot reset an unknown audience (id: ${id}). How did you get it in the first place?`);
3189
3194
  return;
3190
3195
  }
3191
3196
  const _b = this.audienceOverwrites,
@@ -3258,6 +3263,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3258
3263
  audienceDefinitions: this.audienceDefinitions,
3259
3264
  setExperienceVariant: this.setExperienceVariant.bind(this),
3260
3265
  resetExperience: this.resetExperience.bind(this),
3266
+ apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
3261
3267
  experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
3262
3268
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
3263
3269
  reset: this.reset.bind(this),
@@ -3294,15 +3300,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3294
3300
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
3295
3301
  return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
3296
3302
  }
3297
- get experienceVariantIndexes() {
3298
- const profile = this.profile;
3299
- if (!profile) {
3300
- return {};
3301
- }
3303
+ calculateExperienceVariantIndexes(profile) {
3302
3304
  const experiments = this.experiences.filter(experience => experience.type === 'nt_experiment');
3303
- const activeExperiments = selectActiveExperiments(experiments, Object.assign(Object.assign({}, profile), {
3304
- audiences: this.activeAudiences
3305
- }));
3305
+ const activeExperiments = selectActiveExperiments(experiments, profile);
3306
3306
  const eligibleExperiences = selectEligibleExperiences({
3307
3307
  experiences: this.experiences,
3308
3308
  activeExperiments
@@ -3310,22 +3310,34 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3310
3310
  const matchedExperiences = eligibleExperiences.filter(experience => isExperienceMatch({
3311
3311
  experience,
3312
3312
  activeExperiments,
3313
- profile: Object.assign(Object.assign({}, profile), {
3314
- audiences: this.activeAudiences
3315
- })
3313
+ profile
3316
3314
  }));
3317
3315
  return matchedExperiences.reduce((acc, experience) => {
3318
3316
  const distribution = selectDistribution({
3319
3317
  experience,
3320
- profile: Object.assign(Object.assign({}, profile), {
3321
- audiences: this.activeAudiences
3322
- })
3318
+ profile
3323
3319
  });
3324
3320
  return Object.assign(Object.assign({}, acc), {
3325
3321
  [experience.id]: distribution.index
3326
3322
  });
3327
3323
  }, {});
3328
3324
  }
3325
+ get apiExperienceVariantIndexes() {
3326
+ const profile = this.profile;
3327
+ if (!profile) {
3328
+ return {};
3329
+ }
3330
+ return this.calculateExperienceVariantIndexes(profile);
3331
+ }
3332
+ get experienceVariantIndexes() {
3333
+ const profile = this.profile;
3334
+ if (!profile) {
3335
+ return {};
3336
+ }
3337
+ return this.calculateExperienceVariantIndexes(Object.assign(Object.assign({}, profile), {
3338
+ audiences: this.activeAudiences
3339
+ }));
3340
+ }
3329
3341
  }
3330
3342
  _a = PROFILE_CHANGE;
3331
3343
 
@@ -57,6 +57,8 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
57
57
  private isKnownAudience;
58
58
  private get potentialAudiences();
59
59
  private get activeAudiences();
60
+ private calculateExperienceVariantIndexes;
61
+ private get apiExperienceVariantIndexes();
60
62
  private get experienceVariantIndexes();
61
63
  private onChange;
62
64
  private onProfileChange;
package/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "4.2.0-beta.3",
3
+ "version": "4.2.0-beta.5",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "lodash": "4.17.21",
10
- "@ninetailed/experience.js-shared": "4.2.0-beta.3",
11
- "@ninetailed/experience.js": "4.2.0-beta.3",
12
- "@ninetailed/experience.js-utils": "4.2.0-beta.2",
13
- "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.3"
9
+ "@ninetailed/experience.js-shared": "4.2.0-beta.5",
10
+ "@ninetailed/experience.js": "4.2.0-beta.5",
11
+ "@ninetailed/experience.js-utils": "4.2.0-beta.4",
12
+ "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.5"
14
13
  },
15
14
  "peerDependencies": {}
16
15
  }