@ninetailed/experience.js-plugin-preview 4.2.0-beta.0 → 4.2.0-beta.10

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,14 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var omit = require('lodash/omit');
5
+ var experience_jsShared = require('@ninetailed/experience.js-shared');
6
6
  var experience_js = require('@ninetailed/experience.js');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var react = require('react');
9
- var uuid = require('uuid');
10
- var unionBy = require('lodash/unionBy');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
7
 
14
8
  function _interopNamespace(e) {
15
9
  if (e && e.__esModule) return e;
@@ -29,9 +23,6 @@ function _interopNamespace(e) {
29
23
  return Object.freeze(n);
30
24
  }
31
25
 
32
- var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
33
- var unionBy__default = /*#__PURE__*/_interopDefaultLegacy(unionBy);
34
-
35
26
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
36
27
 
37
28
  var check = function (it) {
@@ -3028,79 +3019,6 @@ class WidgetContainer {
3028
3019
  }
3029
3020
  }
3030
3021
 
3031
- const PreviewRenderPlugin = ctx => {
3032
- const PreviewRenderPlugin = props => {
3033
- const [pluginApi, setPluginApi] = react.useState(ctx.pluginApi);
3034
- const {
3035
- children,
3036
- setComponentProps,
3037
- experiences,
3038
- baseline
3039
- } = props;
3040
- const {
3041
- current: id
3042
- } = react.useRef(uuid.v4());
3043
- react.useEffect(() => {
3044
- ctx.registerSetPluginApi(id, setPluginApi);
3045
- return () => {
3046
- ctx.unregisterSetPluginApi(id);
3047
- };
3048
- }, [id]);
3049
- react.useEffect(() => {
3050
- const experienceIds = Object.keys(pluginApi.experienceVariantIndexes);
3051
- const experience = experiences.find(experience => {
3052
- const hasActiveAudience = pluginApi.activeAudiences.some(activeAudienceId => {
3053
- var _a;
3054
- return ((_a = experience.audience) === null || _a === void 0 ? void 0 : _a.id) === activeAudienceId;
3055
- });
3056
- return hasActiveAudience && experienceIds.includes(experience.id);
3057
- });
3058
- if (!experience) {
3059
- setComponentProps(baseline);
3060
- return;
3061
- }
3062
- const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
3063
- if (!baselineComponent) {
3064
- setComponentProps(baseline);
3065
- return;
3066
- }
3067
- const allVariants = [baseline, ...baselineComponent.variants];
3068
- const variantIndex = pluginApi.experienceVariantIndexes[experience.id];
3069
- if (allVariants.length <= variantIndex) {
3070
- setComponentProps(baseline);
3071
- return;
3072
- }
3073
- const variant = allVariants[variantIndex];
3074
- if (!variant) {
3075
- setComponentProps(baseline);
3076
- return;
3077
- }
3078
- setComponentProps(variant);
3079
- }, [experiences, baseline, setComponentProps, pluginApi.experienceVariantIndexes, pluginApi.activeAudiences]);
3080
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
3081
- children: children
3082
- });
3083
- };
3084
- return PreviewRenderPlugin;
3085
- };
3086
-
3087
- class PreviewRenderPluginContext {
3088
- constructor(pluginApi) {
3089
- this.pluginApi = pluginApi;
3090
- this.setPluginApiCallbacks = new Map();
3091
- this.registerSetPluginApi = (id, setPluginApi) => {
3092
- this.setPluginApiCallbacks.set(id, setPluginApi);
3093
- };
3094
- this.unregisterSetPluginApi = id => {
3095
- this.setPluginApiCallbacks.delete(id);
3096
- };
3097
- this.setPluginApi = pluginApi => {
3098
- this.pluginApi = pluginApi;
3099
- this.setPluginApiCallbacks.forEach(callback => callback(pluginApi));
3100
- };
3101
- }
3102
- }
3103
-
3104
3022
  var _a;
3105
3023
  class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3106
3024
  constructor(options) {
@@ -3115,8 +3033,9 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3115
3033
  this.profile = null;
3116
3034
  this.container = null;
3117
3035
  this.bridge = null;
3118
- this.renderPluginContext = new PreviewRenderPluginContext(this.pluginApi);
3119
3036
  this.onChangeEmitter = new experience_js.OnChangeEmitter();
3037
+ this.clientId = null;
3038
+ this.environment = null;
3120
3039
  this.initialize = () => __awaiter(this, void 0, void 0, function* () {
3121
3040
  var _b;
3122
3041
  if (typeof window !== 'undefined') {
@@ -3140,9 +3059,6 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3140
3059
  });
3141
3060
  }
3142
3061
  });
3143
- this.getRenderWrapper = () => {
3144
- return this.renderPluginComponent;
3145
- };
3146
3062
  this.loaded = () => true;
3147
3063
  this[_a] = ({
3148
3064
  payload
@@ -3200,7 +3116,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3200
3116
  };
3201
3117
  this.onChange = () => {
3202
3118
  var _b;
3203
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3119
+ experience_jsShared.logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3204
3120
  Object.assign({}, window.ninetailed, {
3205
3121
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3206
3122
  preview: this.windowApi
@@ -3215,9 +3131,16 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3215
3131
  this.profile = profile;
3216
3132
  this.onChange();
3217
3133
  };
3134
+ this.setCredentials = ({
3135
+ clientId,
3136
+ environment
3137
+ }) => {
3138
+ this.clientId = clientId;
3139
+ this.environment = environment;
3140
+ };
3218
3141
  this.experiences = options.experiences || [];
3219
3142
  this.audienceDefinitions = options.audiences || [];
3220
- this.renderPluginComponent = PreviewRenderPlugin(this.renderPluginContext);
3143
+ this.onOpenExperienceEditor = options.onOpenExperienceEditor;
3221
3144
  }
3222
3145
  open() {
3223
3146
  var _b;
@@ -3242,7 +3165,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3242
3165
  }
3243
3166
  activateAudience(id) {
3244
3167
  if (!this.isKnownAudience(id)) {
3245
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3168
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3246
3169
  return;
3247
3170
  }
3248
3171
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -3272,10 +3195,16 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3272
3195
  // variantIndex: 0,
3273
3196
  // });
3274
3197
  // });
3275
- this.experienceVariantIndexOverwrites = omit__default["default"](this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
3276
- var _b;
3277
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3278
- }).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
+ }, {});
3279
3208
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
3280
3209
  [id]: false
3281
3210
  });
@@ -3283,7 +3212,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3283
3212
  }
3284
3213
  resetAudience(id) {
3285
3214
  if (!this.isKnownAudience(id)) {
3286
- 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?`);
3287
3216
  return;
3288
3217
  }
3289
3218
  const _b = this.audienceOverwrites,
@@ -3333,6 +3262,12 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3333
3262
  window.ninetailed.reset();
3334
3263
  }
3335
3264
  }
3265
+ openExperienceEditor(experience) {
3266
+ if (this.onOpenExperienceEditor && typeof this.onOpenExperienceEditor === 'function') return this.onOpenExperienceEditor(experience);
3267
+ }
3268
+ openExperienceAnalytics(experience) {
3269
+ window.open(`https://app.ninetailed.io/${this.clientId}/${this.environment}/experiences/${experience.id}`, '_blank');
3270
+ }
3336
3271
  get pluginApi() {
3337
3272
  var _b;
3338
3273
  return {
@@ -3350,10 +3285,13 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3350
3285
  audienceDefinitions: this.audienceDefinitions,
3351
3286
  setExperienceVariant: this.setExperienceVariant.bind(this),
3352
3287
  resetExperience: this.resetExperience.bind(this),
3288
+ apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
3353
3289
  experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
3354
3290
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
3355
3291
  reset: this.reset.bind(this),
3356
- experiences: this.experiences
3292
+ experiences: this.experiences,
3293
+ openExperienceEditor: this.onOpenExperienceEditor ? this.openExperienceEditor.bind(this) : undefined,
3294
+ openExperienceAnalytics: this.openExperienceAnalytics.bind(this)
3357
3295
  };
3358
3296
  }
3359
3297
  get windowApi() {
@@ -3376,7 +3314,7 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3376
3314
  }
3377
3315
  get potentialAudiences() {
3378
3316
  const audiencesFromExperiences = this.experiences.map(experience => experience.audience).filter(audience => !!audience);
3379
- return unionBy__default["default"](this.audienceDefinitions, audiencesFromExperiences, 'id');
3317
+ return experience_jsShared.unionBy(this.audienceDefinitions, audiencesFromExperiences, 'id');
3380
3318
  }
3381
3319
  get activeAudiences() {
3382
3320
  var _b;
@@ -3384,15 +3322,9 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3384
3322
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
3385
3323
  return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
3386
3324
  }
3387
- get experienceVariantIndexes() {
3388
- const profile = this.profile;
3389
- if (!profile) {
3390
- return {};
3391
- }
3325
+ calculateExperienceVariantIndexes(profile) {
3392
3326
  const experiments = this.experiences.filter(experience => experience.type === 'nt_experiment');
3393
- const activeExperiments = experience_js.selectActiveExperiments(experiments, Object.assign(Object.assign({}, profile), {
3394
- audiences: this.activeAudiences
3395
- }));
3327
+ const activeExperiments = experience_js.selectActiveExperiments(experiments, profile);
3396
3328
  const eligibleExperiences = experience_js.selectEligibleExperiences({
3397
3329
  experiences: this.experiences,
3398
3330
  activeExperiments
@@ -3400,22 +3332,34 @@ class NinetailedPreviewPlugin extends experience_js.NinetailedPlugin {
3400
3332
  const matchedExperiences = eligibleExperiences.filter(experience => experience_js.isExperienceMatch({
3401
3333
  experience,
3402
3334
  activeExperiments,
3403
- profile: Object.assign(Object.assign({}, profile), {
3404
- audiences: this.activeAudiences
3405
- })
3335
+ profile
3406
3336
  }));
3407
3337
  return matchedExperiences.reduce((acc, experience) => {
3408
3338
  const distribution = experience_js.selectDistribution({
3409
3339
  experience,
3410
- profile: Object.assign(Object.assign({}, profile), {
3411
- audiences: this.activeAudiences
3412
- })
3340
+ profile
3413
3341
  });
3414
3342
  return Object.assign(Object.assign({}, acc), {
3415
3343
  [experience.id]: distribution.index
3416
3344
  });
3417
3345
  }, {});
3418
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
+ }
3419
3363
  }
3420
3364
  _a = experience_js.PROFILE_CHANGE;
3421
3365
 
package/index.js CHANGED
@@ -1,9 +1,5 @@
1
- import omit from 'lodash/omit';
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
- import { jsx, Fragment } from 'react/jsx-runtime';
4
- import { useState, useRef, useEffect } from 'react';
5
- import { v4 } from 'uuid';
6
- import unionBy from 'lodash/unionBy';
7
3
 
8
4
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
9
5
 
@@ -3001,79 +2997,6 @@ class WidgetContainer {
3001
2997
  }
3002
2998
  }
3003
2999
 
3004
- const PreviewRenderPlugin = ctx => {
3005
- const PreviewRenderPlugin = props => {
3006
- const [pluginApi, setPluginApi] = useState(ctx.pluginApi);
3007
- const {
3008
- children,
3009
- setComponentProps,
3010
- experiences,
3011
- baseline
3012
- } = props;
3013
- const {
3014
- current: id
3015
- } = useRef(v4());
3016
- useEffect(() => {
3017
- ctx.registerSetPluginApi(id, setPluginApi);
3018
- return () => {
3019
- ctx.unregisterSetPluginApi(id);
3020
- };
3021
- }, [id]);
3022
- useEffect(() => {
3023
- const experienceIds = Object.keys(pluginApi.experienceVariantIndexes);
3024
- const experience = experiences.find(experience => {
3025
- const hasActiveAudience = pluginApi.activeAudiences.some(activeAudienceId => {
3026
- var _a;
3027
- return ((_a = experience.audience) === null || _a === void 0 ? void 0 : _a.id) === activeAudienceId;
3028
- });
3029
- return hasActiveAudience && experienceIds.includes(experience.id);
3030
- });
3031
- if (!experience) {
3032
- setComponentProps(baseline);
3033
- return;
3034
- }
3035
- const baselineComponent = experience.components.find(component => component.baseline.id === baseline.id);
3036
- if (!baselineComponent) {
3037
- setComponentProps(baseline);
3038
- return;
3039
- }
3040
- const allVariants = [baseline, ...baselineComponent.variants];
3041
- const variantIndex = pluginApi.experienceVariantIndexes[experience.id];
3042
- if (allVariants.length <= variantIndex) {
3043
- setComponentProps(baseline);
3044
- return;
3045
- }
3046
- const variant = allVariants[variantIndex];
3047
- if (!variant) {
3048
- setComponentProps(baseline);
3049
- return;
3050
- }
3051
- setComponentProps(variant);
3052
- }, [experiences, baseline, setComponentProps, pluginApi.experienceVariantIndexes, pluginApi.activeAudiences]);
3053
- return jsx(Fragment, {
3054
- children: children
3055
- });
3056
- };
3057
- return PreviewRenderPlugin;
3058
- };
3059
-
3060
- class PreviewRenderPluginContext {
3061
- constructor(pluginApi) {
3062
- this.pluginApi = pluginApi;
3063
- this.setPluginApiCallbacks = new Map();
3064
- this.registerSetPluginApi = (id, setPluginApi) => {
3065
- this.setPluginApiCallbacks.set(id, setPluginApi);
3066
- };
3067
- this.unregisterSetPluginApi = id => {
3068
- this.setPluginApiCallbacks.delete(id);
3069
- };
3070
- this.setPluginApi = pluginApi => {
3071
- this.pluginApi = pluginApi;
3072
- this.setPluginApiCallbacks.forEach(callback => callback(pluginApi));
3073
- };
3074
- }
3075
- }
3076
-
3077
3000
  var _a;
3078
3001
  class NinetailedPreviewPlugin extends NinetailedPlugin {
3079
3002
  constructor(options) {
@@ -3088,8 +3011,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3088
3011
  this.profile = null;
3089
3012
  this.container = null;
3090
3013
  this.bridge = null;
3091
- this.renderPluginContext = new PreviewRenderPluginContext(this.pluginApi);
3092
3014
  this.onChangeEmitter = new OnChangeEmitter();
3015
+ this.clientId = null;
3016
+ this.environment = null;
3093
3017
  this.initialize = () => __awaiter(this, void 0, void 0, function* () {
3094
3018
  var _b;
3095
3019
  if (typeof window !== 'undefined') {
@@ -3113,9 +3037,6 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3113
3037
  });
3114
3038
  }
3115
3039
  });
3116
- this.getRenderWrapper = () => {
3117
- return this.renderPluginComponent;
3118
- };
3119
3040
  this.loaded = () => true;
3120
3041
  this[_a] = ({
3121
3042
  payload
@@ -3173,7 +3094,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3173
3094
  };
3174
3095
  this.onChange = () => {
3175
3096
  var _b;
3176
- console.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3097
+ logger.debug('Ninetailed Preview Plugin onChange pluginApi:', this.pluginApi);
3177
3098
  Object.assign({}, window.ninetailed, {
3178
3099
  plugins: Object.assign(Object.assign({}, (_b = window.ninetailed) === null || _b === void 0 ? void 0 : _b.plugins), {
3179
3100
  preview: this.windowApi
@@ -3188,9 +3109,16 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3188
3109
  this.profile = profile;
3189
3110
  this.onChange();
3190
3111
  };
3112
+ this.setCredentials = ({
3113
+ clientId,
3114
+ environment
3115
+ }) => {
3116
+ this.clientId = clientId;
3117
+ this.environment = environment;
3118
+ };
3191
3119
  this.experiences = options.experiences || [];
3192
3120
  this.audienceDefinitions = options.audiences || [];
3193
- this.renderPluginComponent = PreviewRenderPlugin(this.renderPluginContext);
3121
+ this.onOpenExperienceEditor = options.onOpenExperienceEditor;
3194
3122
  }
3195
3123
  open() {
3196
3124
  var _b;
@@ -3215,7 +3143,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3215
3143
  }
3216
3144
  activateAudience(id) {
3217
3145
  if (!this.isKnownAudience(id)) {
3218
- console.log(`You cannot activate an unkown audience (id: ${id}).`);
3146
+ console.log(`You cannot activate an unknown audience (id: ${id}).`);
3219
3147
  return;
3220
3148
  }
3221
3149
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
@@ -3245,10 +3173,16 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3245
3173
  // variantIndex: 0,
3246
3174
  // });
3247
3175
  // });
3248
- this.experienceVariantIndexOverwrites = omit(this.experienceVariantIndexOverwrites, this.experiences.filter(experience => {
3249
- var _b;
3250
- return ((_b = experience.audience) === null || _b === void 0 ? void 0 : _b.id) === id;
3251
- }).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
+ }, {});
3252
3186
  this.audienceOverwrites = Object.assign(Object.assign({}, this.audienceOverwrites), {
3253
3187
  [id]: false
3254
3188
  });
@@ -3256,7 +3190,7 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3256
3190
  }
3257
3191
  resetAudience(id) {
3258
3192
  if (!this.isKnownAudience(id)) {
3259
- 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?`);
3260
3194
  return;
3261
3195
  }
3262
3196
  const _b = this.audienceOverwrites,
@@ -3306,6 +3240,12 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3306
3240
  window.ninetailed.reset();
3307
3241
  }
3308
3242
  }
3243
+ openExperienceEditor(experience) {
3244
+ if (this.onOpenExperienceEditor && typeof this.onOpenExperienceEditor === 'function') return this.onOpenExperienceEditor(experience);
3245
+ }
3246
+ openExperienceAnalytics(experience) {
3247
+ window.open(`https://app.ninetailed.io/${this.clientId}/${this.environment}/experiences/${experience.id}`, '_blank');
3248
+ }
3309
3249
  get pluginApi() {
3310
3250
  var _b;
3311
3251
  return {
@@ -3323,10 +3263,13 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3323
3263
  audienceDefinitions: this.audienceDefinitions,
3324
3264
  setExperienceVariant: this.setExperienceVariant.bind(this),
3325
3265
  resetExperience: this.resetExperience.bind(this),
3266
+ apiExperienceVariantIndexes: this.apiExperienceVariantIndexes,
3326
3267
  experienceVariantIndexes: Object.assign(Object.assign({}, this.experienceVariantIndexes), this.experienceVariantIndexOverwrites),
3327
3268
  experienceVariantIndexOverwrites: this.experienceVariantIndexOverwrites,
3328
3269
  reset: this.reset.bind(this),
3329
- experiences: this.experiences
3270
+ experiences: this.experiences,
3271
+ openExperienceEditor: this.onOpenExperienceEditor ? this.openExperienceEditor.bind(this) : undefined,
3272
+ openExperienceAnalytics: this.openExperienceAnalytics.bind(this)
3330
3273
  };
3331
3274
  }
3332
3275
  get windowApi() {
@@ -3357,15 +3300,9 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3357
3300
  const activatedAudiences = Object.entries(this.audienceOverwrites).filter(([id, active]) => active).map(([id]) => id);
3358
3301
  return [...(((_b = this.profile) === null || _b === void 0 ? void 0 : _b.audiences) || []), ...activatedAudiences].filter(id => !deactivatedAudiences.includes(id));
3359
3302
  }
3360
- get experienceVariantIndexes() {
3361
- const profile = this.profile;
3362
- if (!profile) {
3363
- return {};
3364
- }
3303
+ calculateExperienceVariantIndexes(profile) {
3365
3304
  const experiments = this.experiences.filter(experience => experience.type === 'nt_experiment');
3366
- const activeExperiments = selectActiveExperiments(experiments, Object.assign(Object.assign({}, profile), {
3367
- audiences: this.activeAudiences
3368
- }));
3305
+ const activeExperiments = selectActiveExperiments(experiments, profile);
3369
3306
  const eligibleExperiences = selectEligibleExperiences({
3370
3307
  experiences: this.experiences,
3371
3308
  activeExperiments
@@ -3373,22 +3310,34 @@ class NinetailedPreviewPlugin extends NinetailedPlugin {
3373
3310
  const matchedExperiences = eligibleExperiences.filter(experience => isExperienceMatch({
3374
3311
  experience,
3375
3312
  activeExperiments,
3376
- profile: Object.assign(Object.assign({}, profile), {
3377
- audiences: this.activeAudiences
3378
- })
3313
+ profile
3379
3314
  }));
3380
3315
  return matchedExperiences.reduce((acc, experience) => {
3381
3316
  const distribution = selectDistribution({
3382
3317
  experience,
3383
- profile: Object.assign(Object.assign({}, profile), {
3384
- audiences: this.activeAudiences
3385
- })
3318
+ profile
3386
3319
  });
3387
3320
  return Object.assign(Object.assign({}, acc), {
3388
3321
  [experience.id]: distribution.index
3389
3322
  });
3390
3323
  }, {});
3391
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
+ }
3392
3341
  }
3393
3342
  _a = PROFILE_CHANGE;
3394
3343
 
@@ -1,16 +1,15 @@
1
1
  import { Reference } from '@ninetailed/experience.js-shared';
2
- import { ExperienceConfiguration, PROFILE_CHANGE, NinetailedPlugin, HasExperienceSelectionMiddleware, ExperienceSelectionMiddleware } from '@ninetailed/experience.js';
2
+ import { ExperienceConfiguration, PROFILE_CHANGE, HasExperienceSelectionMiddleware, ExperienceSelectionMiddleware, NinetailedPlugin } from '@ninetailed/experience.js';
3
3
  import { Audience } from '@ninetailed/experience.js-utils';
4
- import { RenderPluginWrapperComponent } from '@ninetailed/experience.js-react';
5
4
  export declare const NINETAILED_PREVIEW_EVENTS: {
6
5
  previewAudiences: string;
7
6
  previewTraits: string;
8
7
  };
9
8
  type NinetailedPreviewPluginOptions = {
10
9
  url?: string;
11
- environment?: string;
12
10
  experiences: ExperienceConfiguration[];
13
11
  audiences: Audience[];
12
+ onOpenExperienceEditor?: (experience: ExperienceConfiguration) => void;
14
13
  ui?: {
15
14
  opener?: {
16
15
  hide: boolean;
@@ -28,12 +27,12 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
28
27
  private profile;
29
28
  private container;
30
29
  private bridge;
31
- private renderPluginContext;
32
- private renderPluginComponent;
33
30
  private onChangeEmitter;
31
+ private readonly onOpenExperienceEditor;
32
+ private clientId;
33
+ private environment;
34
34
  constructor(options: NinetailedPreviewPluginOptions);
35
35
  initialize: () => Promise<void>;
36
- getRenderWrapper: () => RenderPluginWrapperComponent;
37
36
  loaded: () => boolean;
38
37
  [PROFILE_CHANGE]: ({ payload }: {
39
38
  payload: any;
@@ -51,13 +50,18 @@ export declare class NinetailedPreviewPlugin extends NinetailedPlugin implements
51
50
  resetExperience(experienceId: string): void;
52
51
  reset(): void;
53
52
  getExperienceSelectionMiddleware: ExperienceSelectionMiddleware<Reference>;
53
+ openExperienceEditor(experience: ExperienceConfiguration): void;
54
+ openExperienceAnalytics(experience: ExperienceConfiguration): void;
54
55
  private get pluginApi();
55
56
  private get windowApi();
56
57
  private isKnownAudience;
57
58
  private get potentialAudiences();
58
59
  private get activeAudiences();
60
+ private calculateExperienceVariantIndexes;
61
+ private get apiExperienceVariantIndexes();
59
62
  private get experienceVariantIndexes();
60
63
  private onChange;
61
64
  private onProfileChange;
65
+ private setCredentials;
62
66
  }
63
67
  export {};
package/package.json CHANGED
@@ -1,20 +1,15 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-preview",
3
- "version": "4.2.0-beta.0",
3
+ "version": "4.2.0-beta.10",
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.0",
11
- "@ninetailed/experience.js": "4.2.0-beta.0",
12
- "@ninetailed/experience.js-utils": "4.1.0-beta.3",
13
- "@ninetailed/experience.js-react": "4.2.0-beta.0",
14
- "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.0",
15
- "react": "18.2.0",
16
- "uuid": "9.0.0",
17
- "ts-toolbelt": "9.6.0"
9
+ "@ninetailed/experience.js-shared": "4.2.0-beta.10",
10
+ "@ninetailed/experience.js": "4.2.0-beta.10",
11
+ "@ninetailed/experience.js-utils": "4.2.0-beta.9",
12
+ "@ninetailed/experience.js-preview-bridge": "4.2.0-beta.10"
18
13
  },
19
14
  "peerDependencies": {}
20
15
  }
@@ -1,5 +0,0 @@
1
- import { RenderPluginWrapperComponent } from '@ninetailed/experience.js-react';
2
- import { PreviewRenderPluginContext } from './PreviewRenderPluginContext';
3
- type PreviewRenderPlugin = (ctx: PreviewRenderPluginContext) => RenderPluginWrapperComponent;
4
- export declare const PreviewRenderPlugin: PreviewRenderPlugin;
5
- export {};
@@ -1,9 +0,0 @@
1
- import { PreviewPluginApi } from '@ninetailed/experience.js-preview-bridge';
2
- export declare class PreviewRenderPluginContext {
3
- pluginApi: PreviewPluginApi;
4
- private setPluginApiCallbacks;
5
- constructor(pluginApi: PreviewPluginApi);
6
- registerSetPluginApi: (id: string, setPluginApi: (luginApi: PreviewPluginApi) => void) => void;
7
- unregisterSetPluginApi: (id: string) => void;
8
- setPluginApi: (pluginApi: PreviewPluginApi) => void;
9
- }