@uniformdev/context 20.3.1 → 20.4.1-alpha.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,4 +1,4 @@
1
- import { aC as paths$7, N as ManifestV2 } from '../types-EJl31yuP.mjs';
1
+ import { aD as paths$7, N as ManifestV2 } from '../types-C9cSPjHd.mjs';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
package/dist/api/api.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { aC as paths$7, N as ManifestV2 } from '../types-EJl31yuP.js';
1
+ import { aD as paths$7, N as ManifestV2 } from '../types-C9cSPjHd.js';
2
2
  import 'mitt';
3
3
 
4
4
  type LimitPolicy = <ReturnValue>(func: () => Promise<ReturnValue>) => Promise<ReturnValue>;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-EJl31yuP.mjs';
2
- export { $ as AggregateDimensionInput, a5 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, az as ContextState, aA as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ao as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a2 as DimensionMatch, Y as EnrichmentCategory, au as EnrichmentData, ax as EventData, aB as GoalStateUpdate, at as Goals, H as GroupCriteriaEvaluator, ah as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ac as ModifyScoreCommand, ad as ModifySessionScoreCommand, Z as NumberMatch, P as PersonalizationEvent, R as PersonalizationManifest, av as PersonalizeControlVariant, a3 as PersonalizeOptions, aw as PersonalizeVariants, a7 as PersonalizedResult, a6 as PersonalizedVariant, am as SERVER_STATE_ID, al as ServerToClientTransitionState, ae as SetConsentCommand, ai as SetControlGroupCommand, ab as SetGoalCommand, aj as SetPersonalizeVariantControlCommand, af as SetQuirkCommand, ag as SetTestCommand, z as Severity, U as Signal, X as SignalCriteria, W as SignalCriteriaGroup, K as SignalData, aa as StorageCommand, _ as TestDefinition, k as TestEvent, a0 as TestOptions, a9 as TestResult, a8 as TestVariant, as as Tests, an as TransitionDataStoreEvents, ar as VisitorDataStore, aq as VisitorDataStoreEvents, ap as VisitorDataStoreOptions, ak as areCommandsEqual, ay as emptyVisitorData, a4 as personalizeVariations, a1 as testVariations } from './types-EJl31yuP.mjs';
1
+ import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-C9cSPjHd.mjs';
2
+ export { a0 as AggregateDimensionInput, a6 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, aA as ContextState, aB as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ap as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a3 as DimensionMatch, Z as EnrichmentCategory, av as EnrichmentData, ay as EventData, aC as GoalStateUpdate, au as Goals, H as GroupCriteriaEvaluator, ai as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ad as ModifyScoreCommand, ae as ModifySessionScoreCommand, _ as NumberMatch, P as PersonalizationEvent, U as PersonalizationManifest, aw as PersonalizeControlVariant, a4 as PersonalizeOptions, ax as PersonalizeVariants, a8 as PersonalizedResult, a7 as PersonalizedVariant, R as RankPersonalizationVariantOptions, an as SERVER_STATE_ID, am as ServerToClientTransitionState, af as SetConsentCommand, aj as SetControlGroupCommand, ac as SetGoalCommand, ak as SetPersonalizeVariantControlCommand, ag as SetQuirkCommand, ah as SetTestCommand, z as Severity, W as Signal, Y as SignalCriteria, X as SignalCriteriaGroup, K as SignalData, ab as StorageCommand, $ as TestDefinition, k as TestEvent, a1 as TestOptions, aa as TestResult, a9 as TestVariant, at as Tests, ao as TransitionDataStoreEvents, as as VisitorDataStore, ar as VisitorDataStoreEvents, aq as VisitorDataStoreOptions, al as areCommandsEqual, az as emptyVisitorData, a5 as personalizeVariations, a2 as testVariations } from './types-C9cSPjHd.mjs';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-EJl31yuP.js';
2
- export { $ as AggregateDimensionInput, a5 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, az as ContextState, aA as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ao as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a2 as DimensionMatch, Y as EnrichmentCategory, au as EnrichmentData, ax as EventData, aB as GoalStateUpdate, at as Goals, H as GroupCriteriaEvaluator, ah as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ac as ModifyScoreCommand, ad as ModifySessionScoreCommand, Z as NumberMatch, P as PersonalizationEvent, R as PersonalizationManifest, av as PersonalizeControlVariant, a3 as PersonalizeOptions, aw as PersonalizeVariants, a7 as PersonalizedResult, a6 as PersonalizedVariant, am as SERVER_STATE_ID, al as ServerToClientTransitionState, ae as SetConsentCommand, ai as SetControlGroupCommand, ab as SetGoalCommand, aj as SetPersonalizeVariantControlCommand, af as SetQuirkCommand, ag as SetTestCommand, z as Severity, U as Signal, X as SignalCriteria, W as SignalCriteriaGroup, K as SignalData, aa as StorageCommand, _ as TestDefinition, k as TestEvent, a0 as TestOptions, a9 as TestResult, a8 as TestVariant, as as Tests, an as TransitionDataStoreEvents, ar as VisitorDataStore, aq as VisitorDataStoreEvents, ap as VisitorDataStoreOptions, ak as areCommandsEqual, ay as emptyVisitorData, a4 as personalizeVariations, a1 as testVariations } from './types-EJl31yuP.js';
1
+ import { O as OutputSeverity, L as LogDrain, C as ContextPlugin, S as ScoreVector, A as AggregateDimension, T as TransitionDataStore, a as StorageCommands, V as VisitorData, Q as Quirks, b as TransitionDataStoreOptions, D as DecayFunction, c as CriteriaEvaluator, d as StringMatch, e as VariantMatchCriteria, f as LogMessage, g as DevToolsEvents } from './types-C9cSPjHd.js';
2
+ export { a0 as AggregateDimensionInput, a6 as BehaviorTag, h as CONTEXTUAL_EDITING_TEST_NAME, i as CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID, n as Context, l as ContextEvents, m as ContextInstance, j as ContextOptions, aA as ContextState, aB as ContextStateUpdate, J as CriteriaEvaluatorParameters, I as CriteriaEvaluatorResult, ap as DecayOptions, q as DevToolsActions, t as DevToolsDataEvent, r as DevToolsEvent, x as DevToolsForgetEvent, u as DevToolsHelloEvent, s as DevToolsLogEvent, w as DevToolsRawCommandsEvent, p as DevToolsState, o as DevToolsUiVersion, v as DevToolsUpdateEvent, a3 as DimensionMatch, Z as EnrichmentCategory, av as EnrichmentData, ay as EventData, aC as GoalStateUpdate, au as Goals, H as GroupCriteriaEvaluator, ai as IdentifyCommand, F as LogMessageGroup, E as LogMessageSingle, y as LogMessages, G as ManifestInstance, N as ManifestV2, M as MessageCategory, B as MessageFunc, ad as ModifyScoreCommand, ae as ModifySessionScoreCommand, _ as NumberMatch, P as PersonalizationEvent, U as PersonalizationManifest, aw as PersonalizeControlVariant, a4 as PersonalizeOptions, ax as PersonalizeVariants, a8 as PersonalizedResult, a7 as PersonalizedVariant, R as RankPersonalizationVariantOptions, an as SERVER_STATE_ID, am as ServerToClientTransitionState, af as SetConsentCommand, aj as SetControlGroupCommand, ac as SetGoalCommand, ak as SetPersonalizeVariantControlCommand, ag as SetQuirkCommand, ah as SetTestCommand, z as Severity, W as Signal, Y as SignalCriteria, X as SignalCriteriaGroup, K as SignalData, ab as StorageCommand, $ as TestDefinition, k as TestEvent, a1 as TestOptions, aa as TestResult, a9 as TestVariant, at as Tests, ao as TransitionDataStoreEvents, as as VisitorDataStore, ar as VisitorDataStoreEvents, aq as VisitorDataStoreOptions, al as areCommandsEqual, az as emptyVisitorData, a5 as personalizeVariations, a2 as testVariations } from './types-C9cSPjHd.js';
3
3
  import Cookies from 'js-cookie';
4
4
  import 'mitt';
5
5
 
package/dist/index.esm.js CHANGED
@@ -641,12 +641,34 @@ function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
641
641
  }
642
642
 
643
643
  // src/placement/personalize.ts
644
+ var sortVariations = ({
645
+ variations,
646
+ rankVariant
647
+ }) => {
648
+ const variationsWithScores = Array.from(variations).map((variant) => {
649
+ const score = rankVariant == null ? void 0 : rankVariant(variant);
650
+ return {
651
+ variant,
652
+ score
653
+ };
654
+ });
655
+ const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
656
+ const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
657
+ return [
658
+ ...variantsWithDefinedScores.sort((a, b) => {
659
+ var _a, _b;
660
+ return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
661
+ }).map((v) => v.variant),
662
+ ...variantsWithUndefinedScores.map((v) => v.variant)
663
+ ];
664
+ };
644
665
  function personalizeVariations({
645
666
  name,
646
667
  context,
647
- variations,
668
+ variations: providedVariations,
648
669
  take = 1,
649
- onLogMessage
670
+ onLogMessage,
671
+ rankVariant
650
672
  }) {
651
673
  var _a, _b, _c;
652
674
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
@@ -655,6 +677,7 @@ function personalizeVariations({
655
677
  const defaultVariants = [];
656
678
  const needsConsent = context.requireConsentForPersonalization;
657
679
  const canEvaluate = !needsConsent || context.storage.data.consent;
680
+ const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
658
681
  for (const variant of variations) {
659
682
  if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
660
683
  if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
@@ -1513,7 +1536,7 @@ import { dequal as dequal5 } from "dequal/lite";
1513
1536
  import mitt3 from "mitt";
1514
1537
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1515
1538
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1516
- var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1539
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1517
1540
  var Context = class {
1518
1541
  constructor(options) {
1519
1542
  __privateAdd(this, _Context_instances);
@@ -1525,6 +1548,7 @@ var Context = class {
1525
1548
  __privateAdd(this, _plugins);
1526
1549
  __privateAdd(this, _commands);
1527
1550
  __privateAdd(this, _requireConsentForPersonalization);
1551
+ __privateAdd(this, _rankPersonalizationVariant);
1528
1552
  __privateAdd(this, _mitt3, mitt3());
1529
1553
  /**
1530
1554
  * Subscribe to events
@@ -1539,6 +1563,7 @@ var Context = class {
1539
1563
  __privateSet(this, _state, {});
1540
1564
  __privateSet(this, _plugins, options.plugins);
1541
1565
  __privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
1566
+ __privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
1542
1567
  if (typeof options.transitionStore !== "undefined") {
1543
1568
  __privateSet(this, _commands, []);
1544
1569
  }
@@ -1846,7 +1871,13 @@ var Context = class {
1846
1871
  const value = personalizeVariations({
1847
1872
  ...options,
1848
1873
  context: this,
1849
- onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1874
+ onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
1875
+ rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
1876
+ placementName: options.name,
1877
+ variant,
1878
+ scores: __privateGet(this, _scores),
1879
+ quirks: this.storage.data.quirks
1880
+ }) : void 0
1850
1881
  });
1851
1882
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1852
1883
  const eventData = {
@@ -1924,6 +1955,7 @@ _pzCache = new WeakMap();
1924
1955
  _plugins = new WeakMap();
1925
1956
  _commands = new WeakMap();
1926
1957
  _requireConsentForPersonalization = new WeakMap();
1958
+ _rankPersonalizationVariant = new WeakMap();
1927
1959
  _mitt3 = new WeakMap();
1928
1960
  _Context_instances = new WeakSet();
1929
1961
  emitTest_fn = function(event) {
package/dist/index.js CHANGED
@@ -730,12 +730,34 @@ function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
730
730
  }
731
731
 
732
732
  // src/placement/personalize.ts
733
+ var sortVariations = ({
734
+ variations,
735
+ rankVariant
736
+ }) => {
737
+ const variationsWithScores = Array.from(variations).map((variant) => {
738
+ const score = rankVariant == null ? void 0 : rankVariant(variant);
739
+ return {
740
+ variant,
741
+ score
742
+ };
743
+ });
744
+ const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
745
+ const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
746
+ return [
747
+ ...variantsWithDefinedScores.sort((a, b) => {
748
+ var _a, _b;
749
+ return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
750
+ }).map((v) => v.variant),
751
+ ...variantsWithUndefinedScores.map((v) => v.variant)
752
+ ];
753
+ };
733
754
  function personalizeVariations({
734
755
  name,
735
756
  context,
736
- variations,
757
+ variations: providedVariations,
737
758
  take = 1,
738
- onLogMessage
759
+ onLogMessage,
760
+ rankVariant
739
761
  }) {
740
762
  var _a, _b, _c;
741
763
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
@@ -744,6 +766,7 @@ function personalizeVariations({
744
766
  const defaultVariants = [];
745
767
  const needsConsent = context.requireConsentForPersonalization;
746
768
  const canEvaluate = !needsConsent || context.storage.data.consent;
769
+ const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
747
770
  for (const variant of variations) {
748
771
  if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
749
772
  if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
@@ -1602,7 +1625,7 @@ var import_lite5 = require("dequal/lite");
1602
1625
  var import_mitt3 = __toESM(require("mitt"));
1603
1626
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1604
1627
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1605
- var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1628
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1606
1629
  var Context = class {
1607
1630
  constructor(options) {
1608
1631
  __privateAdd(this, _Context_instances);
@@ -1614,6 +1637,7 @@ var Context = class {
1614
1637
  __privateAdd(this, _plugins);
1615
1638
  __privateAdd(this, _commands);
1616
1639
  __privateAdd(this, _requireConsentForPersonalization);
1640
+ __privateAdd(this, _rankPersonalizationVariant);
1617
1641
  __privateAdd(this, _mitt3, (0, import_mitt3.default)());
1618
1642
  /**
1619
1643
  * Subscribe to events
@@ -1628,6 +1652,7 @@ var Context = class {
1628
1652
  __privateSet(this, _state, {});
1629
1653
  __privateSet(this, _plugins, options.plugins);
1630
1654
  __privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
1655
+ __privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
1631
1656
  if (typeof options.transitionStore !== "undefined") {
1632
1657
  __privateSet(this, _commands, []);
1633
1658
  }
@@ -1935,7 +1960,13 @@ var Context = class {
1935
1960
  const value = personalizeVariations({
1936
1961
  ...options,
1937
1962
  context: this,
1938
- onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1963
+ onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
1964
+ rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
1965
+ placementName: options.name,
1966
+ variant,
1967
+ scores: __privateGet(this, _scores),
1968
+ quirks: this.storage.data.quirks
1969
+ }) : void 0
1939
1970
  });
1940
1971
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1941
1972
  const eventData = {
@@ -2013,6 +2044,7 @@ _pzCache = new WeakMap();
2013
2044
  _plugins = new WeakMap();
2014
2045
  _commands = new WeakMap();
2015
2046
  _requireConsentForPersonalization = new WeakMap();
2047
+ _rankPersonalizationVariant = new WeakMap();
2016
2048
  _mitt3 = new WeakMap();
2017
2049
  _Context_instances = new WeakSet();
2018
2050
  emitTest_fn = function(event) {
package/dist/index.mjs CHANGED
@@ -641,12 +641,34 @@ function explain(onLogMessage, result, crit, lhsScore, rhsScore) {
641
641
  }
642
642
 
643
643
  // src/placement/personalize.ts
644
+ var sortVariations = ({
645
+ variations,
646
+ rankVariant
647
+ }) => {
648
+ const variationsWithScores = Array.from(variations).map((variant) => {
649
+ const score = rankVariant == null ? void 0 : rankVariant(variant);
650
+ return {
651
+ variant,
652
+ score
653
+ };
654
+ });
655
+ const variantsWithDefinedScores = variationsWithScores.filter((v) => v.score !== void 0);
656
+ const variantsWithUndefinedScores = variationsWithScores.filter((v) => v.score === void 0);
657
+ return [
658
+ ...variantsWithDefinedScores.sort((a, b) => {
659
+ var _a, _b;
660
+ return ((_a = b.score) != null ? _a : 0) - ((_b = a.score) != null ? _b : 0);
661
+ }).map((v) => v.variant),
662
+ ...variantsWithUndefinedScores.map((v) => v.variant)
663
+ ];
664
+ };
644
665
  function personalizeVariations({
645
666
  name,
646
667
  context,
647
- variations,
668
+ variations: providedVariations,
648
669
  take = 1,
649
- onLogMessage
670
+ onLogMessage,
671
+ rankVariant
650
672
  }) {
651
673
  var _a, _b, _c;
652
674
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
@@ -655,6 +677,7 @@ function personalizeVariations({
655
677
  const defaultVariants = [];
656
678
  const needsConsent = context.requireConsentForPersonalization;
657
679
  const canEvaluate = !needsConsent || context.storage.data.consent;
680
+ const variations = rankVariant ? sortVariations({ variations: providedVariations, rankVariant }) : providedVariations;
658
681
  for (const variant of variations) {
659
682
  if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
660
683
  if (canEvaluate && variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
@@ -1513,7 +1536,7 @@ import { dequal as dequal5 } from "dequal/lite";
1513
1536
  import mitt3 from "mitt";
1514
1537
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1515
1538
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1516
- var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1539
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _requireConsentForPersonalization, _rankPersonalizationVariant, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1517
1540
  var Context = class {
1518
1541
  constructor(options) {
1519
1542
  __privateAdd(this, _Context_instances);
@@ -1525,6 +1548,7 @@ var Context = class {
1525
1548
  __privateAdd(this, _plugins);
1526
1549
  __privateAdd(this, _commands);
1527
1550
  __privateAdd(this, _requireConsentForPersonalization);
1551
+ __privateAdd(this, _rankPersonalizationVariant);
1528
1552
  __privateAdd(this, _mitt3, mitt3());
1529
1553
  /**
1530
1554
  * Subscribe to events
@@ -1539,6 +1563,7 @@ var Context = class {
1539
1563
  __privateSet(this, _state, {});
1540
1564
  __privateSet(this, _plugins, options.plugins);
1541
1565
  __privateSet(this, _requireConsentForPersonalization, options.requireConsentForPersonalization);
1566
+ __privateSet(this, _rankPersonalizationVariant, options.rankPersonalizationVariant);
1542
1567
  if (typeof options.transitionStore !== "undefined") {
1543
1568
  __privateSet(this, _commands, []);
1544
1569
  }
@@ -1846,7 +1871,13 @@ var Context = class {
1846
1871
  const value = personalizeVariations({
1847
1872
  ...options,
1848
1873
  context: this,
1849
- onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1874
+ onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message),
1875
+ rankVariant: __privateGet(this, _rankPersonalizationVariant) ? (variant) => __privateGet(this, _rankPersonalizationVariant).call(this, {
1876
+ placementName: options.name,
1877
+ variant,
1878
+ scores: __privateGet(this, _scores),
1879
+ quirks: this.storage.data.quirks
1880
+ }) : void 0
1850
1881
  });
1851
1882
  const previousPlacement = __privateGet(this, _pzCache)[options.name];
1852
1883
  const eventData = {
@@ -1924,6 +1955,7 @@ _pzCache = new WeakMap();
1924
1955
  _plugins = new WeakMap();
1925
1956
  _commands = new WeakMap();
1926
1957
  _requireConsentForPersonalization = new WeakMap();
1958
+ _rankPersonalizationVariant = new WeakMap();
1927
1959
  _mitt3 = new WeakMap();
1928
1960
  _Context_instances = new WeakSet();
1929
1961
  emitTest_fn = function(event) {
@@ -1004,8 +1004,9 @@ type PersonalizeOptions<TVariant> = {
1004
1004
  /** Maximum number of variants to place (default: 1) */
1005
1005
  take?: number;
1006
1006
  onLogMessage?: (message: LogMessage) => void;
1007
+ rankVariant?: (variant: TVariant) => number | undefined;
1007
1008
  };
1008
- declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
1009
+ declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations: providedVariations, take, onLogMessage, rankVariant, }: PersonalizeOptions<TVariant> & {
1009
1010
  context: Context;
1010
1011
  }): PersonalizedResult<TVariant>;
1011
1012
 
@@ -1050,7 +1051,32 @@ type ContextOptions = {
1050
1051
  * `true`: personalization is not run at all unless storage consent is given
1051
1052
  */
1052
1053
  requireConsentForPersonalization?: boolean;
1054
+ /**
1055
+ * Specify a rank for a personalized variant, controlling the order in which variants are considered.
1056
+ * @param placementName The name of the personalized placement
1057
+ * @param variant The variant to rank
1058
+ * @returns A number representing the rank of the variant, where higher numbers are considered first
1059
+ */
1060
+ rankPersonalizationVariant?: (options: RankPersonalizationVariantOptions) => number | undefined;
1053
1061
  } & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
1062
+ type RankPersonalizationVariantOptions = {
1063
+ /**
1064
+ * The name of the personalized placement
1065
+ */
1066
+ placementName: string;
1067
+ /**
1068
+ * The variant to rank
1069
+ */
1070
+ variant: PersonalizedVariant;
1071
+ /**
1072
+ * The current scores of the visitor
1073
+ */
1074
+ scores: Readonly<ScoreVector>;
1075
+ /**
1076
+ * The current quirks of the visitor
1077
+ */
1078
+ quirks: Readonly<Quirks>;
1079
+ };
1054
1080
  /** Emitted when a personalization runs */
1055
1081
  type PersonalizationEvent = {
1056
1082
  /** Name of the personalized placement */
@@ -1265,4 +1291,4 @@ declare global {
1265
1291
  }
1266
1292
  }
1267
1293
 
1268
- export { type AggregateDimensionInput as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type Quirks as Q, type PersonalizationManifest as R, type ScoreVector as S, TransitionDataStore as T, type Signal as U, type VisitorData as V, type SignalCriteriaGroup as W, type SignalCriteria as X, type EnrichmentCategory as Y, type NumberMatch as Z, type TestDefinition as _, type StorageCommands as a, type TestOptions as a0, testVariations as a1, type DimensionMatch as a2, type PersonalizeOptions as a3, personalizeVariations as a4, type BehaviorTag as a5, type PersonalizedVariant as a6, type PersonalizedResult as a7, type TestVariant as a8, type TestResult as a9, type ContextStateUpdate as aA, type GoalStateUpdate as aB, type paths as aC, type StorageCommand as aa, type SetGoalCommand as ab, type ModifyScoreCommand as ac, type ModifySessionScoreCommand as ad, type SetConsentCommand as ae, type SetQuirkCommand as af, type SetTestCommand as ag, type IdentifyCommand as ah, type SetControlGroupCommand as ai, type SetPersonalizeVariantControlCommand as aj, areCommandsEqual as ak, type ServerToClientTransitionState as al, SERVER_STATE_ID as am, type TransitionDataStoreEvents as an, type DecayOptions as ao, type VisitorDataStoreOptions as ap, type VisitorDataStoreEvents as aq, VisitorDataStore as ar, type Tests as as, type Goals as at, type EnrichmentData as au, type PersonalizeControlVariant as av, type PersonalizeVariants as aw, type EventData as ax, emptyVisitorData as ay, type ContextState as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
1294
+ export { type TestDefinition as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type Quirks as Q, type RankPersonalizationVariantOptions as R, type ScoreVector as S, TransitionDataStore as T, type PersonalizationManifest as U, type VisitorData as V, type Signal as W, type SignalCriteriaGroup as X, type SignalCriteria as Y, type EnrichmentCategory as Z, type NumberMatch as _, type StorageCommands as a, type AggregateDimensionInput as a0, type TestOptions as a1, testVariations as a2, type DimensionMatch as a3, type PersonalizeOptions as a4, personalizeVariations as a5, type BehaviorTag as a6, type PersonalizedVariant as a7, type PersonalizedResult as a8, type TestVariant as a9, type ContextState as aA, type ContextStateUpdate as aB, type GoalStateUpdate as aC, type paths as aD, type TestResult as aa, type StorageCommand as ab, type SetGoalCommand as ac, type ModifyScoreCommand as ad, type ModifySessionScoreCommand as ae, type SetConsentCommand as af, type SetQuirkCommand as ag, type SetTestCommand as ah, type IdentifyCommand as ai, type SetControlGroupCommand as aj, type SetPersonalizeVariantControlCommand as ak, areCommandsEqual as al, type ServerToClientTransitionState as am, SERVER_STATE_ID as an, type TransitionDataStoreEvents as ao, type DecayOptions as ap, type VisitorDataStoreOptions as aq, type VisitorDataStoreEvents as ar, VisitorDataStore as as, type Tests as at, type Goals as au, type EnrichmentData as av, type PersonalizeControlVariant as aw, type PersonalizeVariants as ax, type EventData as ay, emptyVisitorData as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
@@ -1004,8 +1004,9 @@ type PersonalizeOptions<TVariant> = {
1004
1004
  /** Maximum number of variants to place (default: 1) */
1005
1005
  take?: number;
1006
1006
  onLogMessage?: (message: LogMessage) => void;
1007
+ rankVariant?: (variant: TVariant) => number | undefined;
1007
1008
  };
1008
- declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations, take, onLogMessage, }: PersonalizeOptions<TVariant> & {
1009
+ declare function personalizeVariations<TVariant extends PersonalizedVariant>({ name, context, variations: providedVariations, take, onLogMessage, rankVariant, }: PersonalizeOptions<TVariant> & {
1009
1010
  context: Context;
1010
1011
  }): PersonalizedResult<TVariant>;
1011
1012
 
@@ -1050,7 +1051,32 @@ type ContextOptions = {
1050
1051
  * `true`: personalization is not run at all unless storage consent is given
1051
1052
  */
1052
1053
  requireConsentForPersonalization?: boolean;
1054
+ /**
1055
+ * Specify a rank for a personalized variant, controlling the order in which variants are considered.
1056
+ * @param placementName The name of the personalized placement
1057
+ * @param variant The variant to rank
1058
+ * @returns A number representing the rank of the variant, where higher numbers are considered first
1059
+ */
1060
+ rankPersonalizationVariant?: (options: RankPersonalizationVariantOptions) => number | undefined;
1053
1061
  } & Omit<VisitorDataStoreOptions, 'manifest' | 'onServerTransitionScoresReceived'>;
1062
+ type RankPersonalizationVariantOptions = {
1063
+ /**
1064
+ * The name of the personalized placement
1065
+ */
1066
+ placementName: string;
1067
+ /**
1068
+ * The variant to rank
1069
+ */
1070
+ variant: PersonalizedVariant;
1071
+ /**
1072
+ * The current scores of the visitor
1073
+ */
1074
+ scores: Readonly<ScoreVector>;
1075
+ /**
1076
+ * The current quirks of the visitor
1077
+ */
1078
+ quirks: Readonly<Quirks>;
1079
+ };
1054
1080
  /** Emitted when a personalization runs */
1055
1081
  type PersonalizationEvent = {
1056
1082
  /** Name of the personalized placement */
@@ -1265,4 +1291,4 @@ declare global {
1265
1291
  }
1266
1292
  }
1267
1293
 
1268
- export { type AggregateDimensionInput as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type Quirks as Q, type PersonalizationManifest as R, type ScoreVector as S, TransitionDataStore as T, type Signal as U, type VisitorData as V, type SignalCriteriaGroup as W, type SignalCriteria as X, type EnrichmentCategory as Y, type NumberMatch as Z, type TestDefinition as _, type StorageCommands as a, type TestOptions as a0, testVariations as a1, type DimensionMatch as a2, type PersonalizeOptions as a3, personalizeVariations as a4, type BehaviorTag as a5, type PersonalizedVariant as a6, type PersonalizedResult as a7, type TestVariant as a8, type TestResult as a9, type ContextStateUpdate as aA, type GoalStateUpdate as aB, type paths as aC, type StorageCommand as aa, type SetGoalCommand as ab, type ModifyScoreCommand as ac, type ModifySessionScoreCommand as ad, type SetConsentCommand as ae, type SetQuirkCommand as af, type SetTestCommand as ag, type IdentifyCommand as ah, type SetControlGroupCommand as ai, type SetPersonalizeVariantControlCommand as aj, areCommandsEqual as ak, type ServerToClientTransitionState as al, SERVER_STATE_ID as am, type TransitionDataStoreEvents as an, type DecayOptions as ao, type VisitorDataStoreOptions as ap, type VisitorDataStoreEvents as aq, VisitorDataStore as ar, type Tests as as, type Goals as at, type EnrichmentData as au, type PersonalizeControlVariant as av, type PersonalizeVariants as aw, type EventData as ax, emptyVisitorData as ay, type ContextState as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
1294
+ export { type TestDefinition as $, type AggregateDimension as A, type MessageFunc as B, type ContextPlugin as C, type DecayFunction as D, type LogMessageSingle as E, type LogMessageGroup as F, ManifestInstance as G, GroupCriteriaEvaluator as H, type CriteriaEvaluatorResult as I, type CriteriaEvaluatorParameters as J, type SignalData as K, type LogDrain as L, type MessageCategory as M, type ManifestV2 as N, type OutputSeverity as O, type PersonalizationEvent as P, type Quirks as Q, type RankPersonalizationVariantOptions as R, type ScoreVector as S, TransitionDataStore as T, type PersonalizationManifest as U, type VisitorData as V, type Signal as W, type SignalCriteriaGroup as X, type SignalCriteria as Y, type EnrichmentCategory as Z, type NumberMatch as _, type StorageCommands as a, type AggregateDimensionInput as a0, type TestOptions as a1, testVariations as a2, type DimensionMatch as a3, type PersonalizeOptions as a4, personalizeVariations as a5, type BehaviorTag as a6, type PersonalizedVariant as a7, type PersonalizedResult as a8, type TestVariant as a9, type ContextState as aA, type ContextStateUpdate as aB, type GoalStateUpdate as aC, type paths as aD, type TestResult as aa, type StorageCommand as ab, type SetGoalCommand as ac, type ModifyScoreCommand as ad, type ModifySessionScoreCommand as ae, type SetConsentCommand as af, type SetQuirkCommand as ag, type SetTestCommand as ah, type IdentifyCommand as ai, type SetControlGroupCommand as aj, type SetPersonalizeVariantControlCommand as ak, areCommandsEqual as al, type ServerToClientTransitionState as am, SERVER_STATE_ID as an, type TransitionDataStoreEvents as ao, type DecayOptions as ap, type VisitorDataStoreOptions as aq, type VisitorDataStoreEvents as ar, VisitorDataStore as as, type Tests as at, type Goals as au, type EnrichmentData as av, type PersonalizeControlVariant as aw, type PersonalizeVariants as ax, type EventData as ay, emptyVisitorData as az, type TransitionDataStoreOptions as b, type CriteriaEvaluator as c, type StringMatch as d, type VariantMatchCriteria as e, type LogMessage as f, type DevToolsEvents as g, CONTEXTUAL_EDITING_TEST_NAME as h, CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID as i, type ContextOptions as j, type TestEvent as k, type ContextEvents as l, type ContextInstance as m, Context as n, type DevToolsUiVersion as o, type DevToolsState as p, type DevToolsActions as q, type DevToolsEvent as r, type DevToolsLogEvent as s, type DevToolsDataEvent as t, type DevToolsHelloEvent as u, type DevToolsUpdateEvent as v, type DevToolsRawCommandsEvent as w, type DevToolsForgetEvent as x, type LogMessages as y, type Severity as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/context",
3
- "version": "20.3.1",
3
+ "version": "20.4.1-alpha.3+bc2e6fc5f7",
4
4
  "description": "Uniform Context core package",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "4f5ad4dc937cd01f9f288d1d292bd4c7c226240b"
71
+ "gitHead": "bc2e6fc5f7d2920e46605385db043782f023bbbb"
72
72
  }