@ninetailed/experience.js-plugin-preview 4.2.0-beta.4 → 4.2.0-beta.6

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
@@ -3116,7 +3116,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3116
3116
  };
3117
3117
  this.onChange = () => {
3118
3118
  var _b;
3119
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3119
+ experience_jsShared.logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3120
3120
  Object.assign({}, window.ninetailed, {
3121
3121
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3122
3122
  preview: this.windowApi
@@ -3165,7 +3165,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3165
3165
  }
3166
3166
  activateAudience(id) {
3167
3167
  if (!this.isKnownAudience(id)) {
3168
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3168
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3169
3169
  return;
3170
3170
  }
3171
3171
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -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),
@@ -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,4 +1,4 @@
1
- import { unionBy } from '@ninetailed/experience.js-shared';
1
+ import { logger, unionBy } from '@ninetailed/experience.js-shared';
2
2
  import { NinetailedPlugin, OnChangeEmitter, selectActiveExperiments, selectEligibleExperiences, isExperienceMatch, selectDistribution, PROFILE_CHANGE } from '@ninetailed/experience.js';
3
3
 
4
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -3094,7 +3094,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3094
3094
  };
3095
3095
  this.onChange = () => {
3096
3096
  var _b;
3097
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3097
+ logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3098
3098
  Object.assign({}, window.ninetailed, {
3099
3099
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3100
3100
  preview: this.windowApi
@@ -3143,7 +3143,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3143
3143
  }
3144
3144
  activateAudience(id) {
3145
3145
  if (!this.isKnownAudience(id)) {
3146
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3146
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3147
3147
  return;
3148
3148
  }
3149
3149
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -3190,7 +3190,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3190
3190
  }
3191
3191
  resetAudience(id) {
3192
3192
  if (!this.isKnownAudience(id)) {
3193
- 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?`);
3194
3194
  return;
3195
3195
  }
3196
3196
  const _b = this.audienceOverwrites,
@@ -3263,6 +3263,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3263
3263
  audienceDefinitions: this.audienceDefinitions,
3264
3264
  setExperienceVariant: this.setExperienceVariant.bind(this),
3265
3265
  resetExperience: this.resetExperience.bind(this),
3266
+ apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
3266
3267
  experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
3267
3268
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
3268
3269
  reset: this.reset.bind(this),
@@ -3299,15 +3300,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3299
3300
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
3300
3301
  return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
3301
3302
  }
3302
- get experienceVariantIndexes() {
3303
- const profile = this.profile;
3304
- if (!profile) {
3305
- return {};
3306
- }
3303
+ calculateExperienceVariantIndexes(profile) {
3307
3304
  const experiments = this.experiences.filter(experience => experience.type === 'nt_experiment');
3308
- const activeExperiments = selectActiveExperiments(experiments, Object.assign(Object.assign({}, profile), {
3309
- audiences: this.activeAudiences
3310
- }));
3305
+ const activeExperiments = selectActiveExperiments(experiments, profile);
3311
3306
  const eligibleExperiences = selectEligibleExperiences({
3312
3307
  experiences: this.experiences,
3313
3308
  activeExperiments
@@ -3315,22 +3310,34 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3315
3310
  const matchedExperiences = eligibleExperiences.filter(experience => isExperienceMatch({
3316
3311
  experience,
3317
3312
  activeExperiments,
3318
- profile: Object.assign(Object.assign({}, profile), {
3319
- audiences: this.activeAudiences
3320
- })
3313
+ profile
3321
3314
  }));
3322
3315
  return matchedExperiences.reduce((acc, experience) => {
3323
3316
  const distribution = selectDistribution({
3324
3317
  experience,
3325
- profile: Object.assign(Object.assign({}, profile), {
3326
- audiences: this.activeAudiences
3327
- })
3318
+ profile
3328
3319
  });
3329
3320
  return Object.assign(Object.assign({}, acc), {
3330
3321
  [experience.id]: distribution.index
3331
3322
  });
3332
3323
  }, {});
3333
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
+ }
3334
3341
  }
3335
3342
  _a = PROFILE_CHANGE;
3336
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,15 +1,15 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "4.2.0-beta.4",
3
+ "version": "4.2.0-beta.6",
4
4
  "module": "./index.js",
5
5
  "main": "./index.cjs",
6
6
  "type": "module",
7
7
  "types": "./index.d.ts",
8
8
  "dependencies": {
9
- "@ninetailed/experience.js-shared": "4.2.0-beta.4",
10
- "@ninetailed/experience.js": "4.2.0-beta.4",
11
- "@ninetailed/experience.js-utils": "4.2.0-beta.3",
12
- "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.4"
9
+ "@ninetailed/experience.js-shared": "4.2.0-beta.6",
10
+ "@ninetailed/experience.js": "4.2.0-beta.6",
11
+ "@ninetailed/experience.js-utils": "4.2.0-beta.5",
12
+ "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.6"
13
13
  },
14
14
  "peerDependencies": {}
15
15
  }