@ninetailed/experience.js 2.0.0-beta.22 → 2.0.0-beta.23

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.esm.js CHANGED
@@ -3887,7 +3887,7 @@ const isExperienceMatch = ({
3887
3887
  log(`The traffic random factor for experience ${experience.id} is ${trafficRandom}. It's traffic allocation is set to ${experience.trafficAllocation}.`);
3888
3888
  const isInTrafficRange = experience.trafficAllocation > trafficRandom;
3889
3889
  const matchesAudience = !experience.audience || includes(profile.audiences, experience.audience.id);
3890
- const hasActiveExperiment = find(activeExperiments, {
3890
+ const hasActiveExperiment = !!find(activeExperiments, {
3891
3891
  id: experience.id
3892
3892
  });
3893
3893
  log(`Is the profile in traffic allocation range? ${isInTrafficRange ? 'yes' : 'no'}.\n
@@ -3914,6 +3914,20 @@ const selectExperience = ({
3914
3914
  return selectedExperience;
3915
3915
  };
3916
3916
 
3917
+ const selectDistribution = ({
3918
+ experience,
3919
+ profile
3920
+ }) => {
3921
+ const distributionRandom = getDistributionRandom(profile, experience);
3922
+ log(`The distribution random factor for experience ${experience.id} is ${distributionRandom}. It's distribution is set to ${JSON.stringify(experience.distribution, null, 2)}.`);
3923
+ const distribution = find(experience.distribution, ({
3924
+ start,
3925
+ end
3926
+ }) => distributionRandom >= start && distributionRandom <= end // this overlaps on one value for each boundary but we just find the first match
3927
+ );
3928
+ return distribution;
3929
+ };
3930
+
3917
3931
  const selectVariant = ({
3918
3932
  baseline,
3919
3933
  experience,
@@ -3930,13 +3944,10 @@ const selectVariant = ({
3930
3944
  return variants[0];
3931
3945
  }
3932
3946
 
3933
- const distributionRandom = getDistributionRandom(profile, experience);
3934
- log(`The distribution random factor for experience ${experience.id} is ${distributionRandom}. It's distribution is set to ${JSON.stringify(experience.distribution, null, 2)}.`); // Experiment
3935
-
3936
- const distribution = find(experience.distribution, ({
3937
- start,
3938
- end
3939
- }) => distributionRandom > start && distributionRandom < end);
3947
+ const distribution = selectDistribution({
3948
+ experience,
3949
+ profile
3950
+ });
3940
3951
 
3941
3952
  if (!distribution) {
3942
3953
  return null;
@@ -3965,4 +3976,4 @@ const selectVariant = ({
3965
3976
  return variant;
3966
3977
  };
3967
3978
 
3968
- export { NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, isExperienceMatch, ninetailedPlugin, selectActiveExperiments, selectEligibleExperiences, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants, selectVariant$1 as selectVariant };
3979
+ export { NINETAILED_TRACKER_EVENTS, Ninetailed, PLUGIN_NAME, isExperienceMatch, ninetailedPlugin, selectActiveExperiments, selectDistribution, selectEligibleExperiences, selectExperience, selectBaselineWithVariants as selectExperienceBaselineWithVariants, selectVariant as selectExperienceVariant, selectVariants as selectExperienceVariants, selectHasVariants as selectHasExperienceVariants, selectVariant$1 as selectVariant };
package/index.umd.js CHANGED
@@ -3813,7 +3813,7 @@
3813
3813
  log("The traffic random factor for experience ".concat(experience.id, " is ").concat(trafficRandom, ". It's traffic allocation is set to ").concat(experience.trafficAllocation, "."));
3814
3814
  var isInTrafficRange = experience.trafficAllocation > trafficRandom;
3815
3815
  var matchesAudience = !experience.audience || includes__default["default"](profile.audiences, experience.audience.id);
3816
- var hasActiveExperiment = find__default["default"](activeExperiments, {
3816
+ var hasActiveExperiment = !!find__default["default"](activeExperiments, {
3817
3817
  id: experience.id
3818
3818
  });
3819
3819
  log("Is the profile in traffic allocation range? ".concat(isInTrafficRange ? 'yes' : 'no', ".\n\n Does the profile match the audience of the experience? ").concat(matchesAudience ? 'yes' : 'no', ".\n\n Is there an active experiment for this profile? ").concat(hasActiveExperiment ? 'yes' : 'no', "."));
@@ -3839,6 +3839,20 @@
3839
3839
  return selectedExperience;
3840
3840
  };
3841
3841
 
3842
+ var selectDistribution = function selectDistribution(_a) {
3843
+ var experience = _a.experience,
3844
+ profile = _a.profile;
3845
+ var distributionRandom = getDistributionRandom(profile, experience);
3846
+ log("The distribution random factor for experience ".concat(experience.id, " is ").concat(distributionRandom, ". It's distribution is set to ").concat(JSON.stringify(experience.distribution, null, 2), "."));
3847
+ var distribution = find__default["default"](experience.distribution, function (_a) {
3848
+ var start = _a.start,
3849
+ end = _a.end;
3850
+ return distributionRandom >= start && distributionRandom <= end;
3851
+ } // this overlaps on one value for each boundary but we just find the first match
3852
+ );
3853
+ return distribution;
3854
+ };
3855
+
3842
3856
  var selectVariant = function selectVariant(_a) {
3843
3857
  var baseline = _a.baseline,
3844
3858
  experience = _a.experience,
@@ -3854,13 +3868,9 @@
3854
3868
  return variants[0];
3855
3869
  }
3856
3870
 
3857
- var distributionRandom = getDistributionRandom(profile, experience);
3858
- log("The distribution random factor for experience ".concat(experience.id, " is ").concat(distributionRandom, ". It's distribution is set to ").concat(JSON.stringify(experience.distribution, null, 2), ".")); // Experiment
3859
-
3860
- var distribution = find__default["default"](experience.distribution, function (_a) {
3861
- var start = _a.start,
3862
- end = _a.end;
3863
- return distributionRandom > start && distributionRandom < end;
3871
+ var distribution = selectDistribution({
3872
+ experience: experience,
3873
+ profile: profile
3864
3874
  });
3865
3875
 
3866
3876
  if (!distribution) {
@@ -3896,6 +3906,7 @@
3896
3906
  exports.isExperienceMatch = isExperienceMatch;
3897
3907
  exports.ninetailedPlugin = ninetailedPlugin;
3898
3908
  exports.selectActiveExperiments = selectActiveExperiments;
3909
+ exports.selectDistribution = selectDistribution;
3899
3910
  exports.selectEligibleExperiences = selectEligibleExperiences;
3900
3911
  exports.selectExperience = selectExperience;
3901
3912
  exports.selectExperienceBaselineWithVariants = selectBaselineWithVariants;
@@ -7,3 +7,4 @@ export { selectEligibleExperiences } from './selectEligibleExperiences';
7
7
  export { selectExperience } from './selectExperience';
8
8
  export { selectVariant as selectExperienceVariant } from './selectVariant';
9
9
  export { isExperienceMatch } from './isExperienceMatch';
10
+ export { selectDistribution } from './selectDistribution';
@@ -5,5 +5,5 @@ declare type IsExperienceMatchArgs = {
5
5
  activeExperiments: ExperienceConfiguration[];
6
6
  profile: Profile;
7
7
  };
8
- export declare const isExperienceMatch: ({ experience, activeExperiments, profile }: IsExperienceMatchArgs) => boolean | ExperienceConfiguration;
8
+ export declare const isExperienceMatch: ({ experience, activeExperiments, profile }: IsExperienceMatchArgs) => boolean;
9
9
  export {};
@@ -0,0 +1,8 @@
1
+ import { Profile } from '@ninetailed/experience.js-shared';
2
+ import { Distribution, ExperienceConfiguration } from './types';
3
+ declare type SelectDistributionArgs = {
4
+ experience: ExperienceConfiguration;
5
+ profile: Profile;
6
+ };
7
+ export declare const selectDistribution: ({ experience, profile, }: SelectDistributionArgs) => Distribution;
8
+ export {};
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js",
3
- "version": "2.0.0-beta.22",
3
+ "version": "2.0.0-beta.23",
4
4
  "main": "./index.umd.js",
5
5
  "module": "./index.esm.js",
6
6
  "typings": "./index.d.ts",
7
7
  "dependencies": {
8
8
  "analytics": "^0.8.0",
9
- "@ninetailed/experience.js-shared": "2.0.0-beta.22",
9
+ "@ninetailed/experience.js-shared": "2.0.0-beta.23",
10
10
  "uuid": "^8.3.2",
11
11
  "ts-toolbelt": "^9.6.0",
12
12
  "locale-enum": "^1.1.1",