@uniformdev/context 19.135.1-alpha.10 → 19.135.1-alpha.12

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/dist/index.js CHANGED
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
8
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
12
  var __export = (target, all) => {
10
13
  for (var name in all)
@@ -27,32 +30,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  mod
28
31
  ));
29
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
33
- };
34
- var __accessCheck = (obj, member, msg) => {
35
- if (!member.has(obj))
36
- throw TypeError("Cannot " + msg);
37
- };
38
- var __privateGet = (obj, member, getter) => {
39
- __accessCheck(obj, member, "read from private field");
40
- return getter ? getter.call(obj) : member.get(obj);
41
- };
42
- var __privateAdd = (obj, member, value) => {
43
- if (member.has(obj))
44
- throw TypeError("Cannot add the same private member more than once");
45
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
46
- };
47
- var __privateSet = (obj, member, value, setter) => {
48
- __accessCheck(obj, member, "write to private field");
49
- setter ? setter.call(obj, value) : member.set(obj, value);
50
- return value;
51
- };
52
- var __privateMethod = (obj, member, method) => {
53
- __accessCheck(obj, member, "access private method");
54
- return method;
55
- };
33
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
35
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
36
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
37
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
38
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
56
39
 
57
40
  // src/index.ts
58
41
  var src_exports = {};
@@ -64,23 +47,30 @@ __export(src_exports, {
64
47
  EdgeNodeTagName: () => EdgeNodeTagName,
65
48
  EdgeTransitionDataStore: () => EdgeTransitionDataStore,
66
49
  GroupCriteriaEvaluator: () => GroupCriteriaEvaluator,
50
+ KV_SEP: () => KV_SEP,
67
51
  ManifestInstance: () => ManifestInstance,
52
+ PAIR_SEP: () => PAIR_SEP,
68
53
  SERVER_STATE_ID: () => SERVER_STATE_ID,
69
54
  ScriptType: () => ScriptType,
55
+ TYPE_SEP: () => TYPE_SEP,
70
56
  TransitionDataStore: () => TransitionDataStore,
71
57
  UNIFORM_DEFAULT_COOKIE_NAME: () => UNIFORM_DEFAULT_COOKIE_NAME,
72
58
  VisitorDataStore: () => VisitorDataStore,
59
+ areCommandsEqual: () => areCommandsEqual,
73
60
  computeAggregateDimensions: () => computeAggregateDimensions,
74
61
  cookieEvaluator: () => cookieEvaluator,
75
62
  createConsoleLogDrain: () => createConsoleLogDrain,
76
63
  createDebugConsoleLogDrain: () => createDebugConsoleLogDrain,
77
64
  createLinearDecay: () => createLinearDecay,
78
65
  currentPageEvaluator: () => currentPageEvaluator,
66
+ decodeCookieType: () => decodeCookieType,
67
+ decodePersonalizeVariants: () => decodePersonalizeVariants,
79
68
  emptyVisitorData: () => emptyVisitorData,
80
69
  enableConsoleLogDrain: () => enableConsoleLogDrain,
81
70
  enableContextDevTools: () => enableContextDevTools,
82
71
  enableDebugConsoleLogDrain: () => enableDebugConsoleLogDrain,
83
72
  enableUniformInsights: () => enableUniformInsights,
73
+ encodeCookieType: () => encodeCookieType,
84
74
  evaluateVariantMatch: () => evaluateVariantMatch,
85
75
  eventEvaluator: () => eventEvaluator,
86
76
  explainStringMatch: () => explainStringMatch,
@@ -89,10 +79,16 @@ __export(src_exports, {
89
79
  isStringMatch: () => isStringMatch,
90
80
  pageViewCountDimension: () => pageViewCountDimension,
91
81
  pageViewCountEvaluator: () => pageViewCountEvaluator,
82
+ parseCookieScores: () => parseCookieScores,
83
+ parseCookieType: () => parseCookieType,
92
84
  parseQuickConnect: () => parseQuickConnect,
85
+ parseScoreCookie: () => parseScoreCookie,
93
86
  personalizeVariations: () => personalizeVariations,
94
87
  queryStringEvaluator: () => queryStringEvaluator,
95
88
  quirkEvaluator: () => quirkEvaluator,
89
+ serializeCookie: () => serializeCookie,
90
+ serializeCookieType: () => serializeCookieType,
91
+ serializePersonalizeVariants: () => serializePersonalizeVariants,
96
92
  serializeQuickConnect: () => serializeQuickConnect,
97
93
  testVariations: () => testVariations
98
94
  });
@@ -148,13 +144,11 @@ function computeAggregateDimension(primitiveScores, aggregateDimension, allAggre
148
144
  var ENR_SEPARATOR = "_";
149
145
 
150
146
  // src/manifest/goals/evaluators/SignalGoalEvaluator.ts
151
- var _signal, _id;
147
+ var _id;
152
148
  var SignalGoalEvaluator = class {
153
149
  constructor(options) {
154
- __privateAdd(this, _signal, void 0);
155
- __privateAdd(this, _id, void 0);
150
+ __privateAdd(this, _id);
156
151
  __privateSet(this, _id, options.id);
157
- __privateSet(this, _signal, options.signal);
158
152
  }
159
153
  get id() {
160
154
  return __privateGet(this, _id);
@@ -169,15 +163,14 @@ var SignalGoalEvaluator = class {
169
163
  };
170
164
  }
171
165
  };
172
- _signal = new WeakMap();
173
166
  _id = new WeakMap();
174
167
 
175
168
  // src/manifest/signals/SignalInstance.ts
176
169
  var _evaluator, _onLogMessage;
177
170
  var SignalInstance = class {
178
171
  constructor(data, evaluator, onLogMessage) {
179
- __privateAdd(this, _evaluator, void 0);
180
- __privateAdd(this, _onLogMessage, void 0);
172
+ __privateAdd(this, _evaluator);
173
+ __privateAdd(this, _onLogMessage);
181
174
  __publicField(this, "signal");
182
175
  this.signal = data;
183
176
  __privateSet(this, _evaluator, evaluator);
@@ -239,10 +232,10 @@ var ManifestInstance = class {
239
232
  }
240
233
  }) {
241
234
  __publicField(this, "data");
242
- __privateAdd(this, _mf, void 0);
243
- __privateAdd(this, _signalInstances, void 0);
235
+ __privateAdd(this, _mf);
236
+ __privateAdd(this, _signalInstances);
244
237
  __privateAdd(this, _goalEvaluators, []);
245
- __privateAdd(this, _onLogMessage2, void 0);
238
+ __privateAdd(this, _onLogMessage2);
246
239
  var _a, _b, _c, _d, _e;
247
240
  __privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
248
241
  this.data = manifest;
@@ -559,7 +552,7 @@ var quirkEvaluator = ({ update, criteria, signal, onLogMessage }) => {
559
552
  var _evaluators;
560
553
  var GroupCriteriaEvaluator = class {
561
554
  constructor(criteriaEvaluators) {
562
- __privateAdd(this, _evaluators, void 0);
555
+ __privateAdd(this, _evaluators);
563
556
  __privateSet(this, _evaluators, criteriaEvaluators);
564
557
  }
565
558
  evaluate(update, crit, commands, signal, onLogMessage) {
@@ -739,75 +732,66 @@ function personalizeVariations({
739
732
  take = 1,
740
733
  onLogMessage
741
734
  }) {
742
- var _a, _b, _c, _d;
735
+ var _a, _b, _c;
743
736
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
744
737
  try {
745
- const control = (_a = context.storage.data.controlGroup) != null ? _a : false;
746
- const results = [];
747
- let personalized = false;
748
- const scores = context.scores;
749
- let index = 0;
738
+ const variantMatches = [];
750
739
  const defaultVariants = [];
751
740
  for (const variant of variations) {
752
- if (!((_b = variant.pz) == null ? void 0 : _b.crit.length)) {
741
+ if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
742
+ if (variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
743
+ variantMatches.push(variant);
744
+ }
745
+ } else {
753
746
  defaultVariants.push(variant);
754
747
  }
755
748
  }
756
- for (const variant of variations) {
757
- const currentIndex = index++;
758
- if (results.length === take) {
759
- break;
760
- }
761
- if (!((_c = variant.pz) == null ? void 0 : _c.crit.length)) {
762
- onLogMessage == null ? void 0 : onLogMessage(["info", 301, "GROUP", { id: variant.id, op: (_d = variant.pz) == null ? void 0 : _d.op }]);
763
- onLogMessage == null ? void 0 : onLogMessage(["info", 302, { matched: true, description: "default variation" }]);
764
- onLogMessage == null ? void 0 : onLogMessage(["info", 303, true]);
765
- onLogMessage == null ? void 0 : onLogMessage(["info", 301, "ENDGROUP"]);
766
- results.push({
767
- ...variant,
768
- control: false
769
- });
770
- continue;
771
- }
772
- if (control) {
773
- continue;
774
- }
775
- if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
776
- let variantToAdd = variant;
777
- let isControl = false;
778
- const isDefault = defaultVariants.find((v) => v.id === variant.id);
779
- if (take === 1 && !isDefault && defaultVariants.length && typeof variant.pz.control === "number") {
780
- isControl = context.getPersonalizeVariantControl(name, currentIndex);
781
- if (typeof isControl === "undefined") {
782
- isControl = rollForControlGroup(variant.pz.control);
783
- context.storage.updateData([
784
- {
785
- type: "setpersonalizecontrol",
786
- data: {
787
- personlizationName: name,
788
- index: currentIndex,
789
- control: isControl
790
- }
749
+ const result = [];
750
+ for (let i = 0; i < variantMatches.length; i++) {
751
+ let isControl = (_b = context.storage.data.controlGroup) != null ? _b : false;
752
+ const variant = variantMatches[i];
753
+ if (!isControl && typeof ((_c = variant.pz) == null ? void 0 : _c.control) === "number") {
754
+ isControl = context.getPersonalizeVariantControl(name, i);
755
+ if (typeof isControl === "undefined") {
756
+ isControl = rollForControlGroup(variant.pz.control);
757
+ context.storage.updateData([
758
+ {
759
+ type: "setpersonalizecontrol",
760
+ data: {
761
+ personlizationName: name,
762
+ index: i,
763
+ control: isControl
791
764
  }
792
- ]);
793
- }
794
- if (isControl) {
795
- variantToAdd = {
796
- ...defaultVariants[0],
797
- id: variant.id
798
- };
799
- }
765
+ }
766
+ ]);
800
767
  }
801
- personalized = personalized || typeof variantToAdd.pz !== "undefined";
802
- results.push({
803
- ...variantToAdd,
804
- control: isControl
805
- });
806
768
  }
769
+ let variantToAdd = variant;
770
+ if (isControl) {
771
+ const defaultReplacement = defaultVariants.shift();
772
+ if (defaultReplacement) {
773
+ variantToAdd = {
774
+ ...defaultReplacement,
775
+ id: variant.id
776
+ };
777
+ } else {
778
+ variantToAdd = void 0;
779
+ }
780
+ }
781
+ if (variantToAdd) {
782
+ result.push({ ...variantToAdd, control: isControl });
783
+ }
784
+ }
785
+ while (result.length < take && defaultVariants.length) {
786
+ result.push({ ...defaultVariants.shift(), control: false });
807
787
  }
788
+ const personalized = result.some((v) => {
789
+ var _a2;
790
+ return (_a2 = v.pz) == null ? void 0 : _a2.crit.length;
791
+ });
808
792
  return {
809
793
  personalized,
810
- variations: results
794
+ variations: result
811
795
  };
812
796
  } finally {
813
797
  onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
@@ -875,7 +859,7 @@ var testVariations = ({
875
859
  let distributionOffset = 0;
876
860
  selectedVariant = variations.find((variant, index) => {
877
861
  const distribution = distributions[index];
878
- if (random > distributionOffset && random <= distributionOffset + distribution) {
862
+ if ((random > distributionOffset || random === 0) && random <= distributionOffset + distribution) {
879
863
  return variant;
880
864
  }
881
865
  distributionOffset += distribution;
@@ -897,18 +881,27 @@ var testVariations = ({
897
881
  }
898
882
  };
899
883
 
884
+ // src/storage/commands.ts
885
+ var import_lite2 = require("dequal/lite");
886
+ var areCommandsEqual = (a, b) => {
887
+ if (a.type !== b.type) {
888
+ return false;
889
+ }
890
+ return (0, import_lite2.dequal)(a, b);
891
+ };
892
+
900
893
  // src/storage/CookieTransitionDataStore.ts
901
894
  var import_js_cookie = __toESM(require("js-cookie"));
902
895
 
903
896
  // src/storage/TransitionDataStore.ts
904
- var import_lite2 = require("dequal/lite");
897
+ var import_lite3 = require("dequal/lite");
905
898
  var import_mitt = __toESM(require("mitt"));
906
899
  var SERVER_STATE_ID = "__UNIFORM_DATA__";
907
900
  var _data, _initialData, _mitt;
908
901
  var TransitionDataStore = class {
909
902
  constructor({ initialData }) {
910
- __privateAdd(this, _data, void 0);
911
- __privateAdd(this, _initialData, void 0);
903
+ __privateAdd(this, _data);
904
+ __privateAdd(this, _initialData);
912
905
  __privateAdd(this, _mitt, (0, import_mitt.default)());
913
906
  /**
914
907
  * Subscribe to events from the transition storage
@@ -947,7 +940,7 @@ var TransitionDataStore = class {
947
940
  await this.handleDelete(fromAllDevices);
948
941
  }
949
942
  signalAsyncDataUpdate(newScores) {
950
- if ((0, import_lite2.dequal)(this.data, newScores)) {
943
+ if ((0, import_lite3.dequal)(this.data, newScores)) {
951
944
  return;
952
945
  }
953
946
  __privateSet(this, _data, newScores);
@@ -979,8 +972,7 @@ for (let i = 0; i < alphabet.length; i++) {
979
972
  s2b[alphabet.charCodeAt(i)] = i;
980
973
  }
981
974
  var ntob = (number) => {
982
- if (number < 0)
983
- return `-${ntob(-number)}`;
975
+ if (number < 0) return `-${ntob(-number)}`;
984
976
  let lo = number >>> 0;
985
977
  let hi = number / 4294967296 >>> 0;
986
978
  let right = "";
@@ -1019,20 +1011,18 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
1019
1011
  super({
1020
1012
  initialData: ssr ? parseScoreCookie(serverCookieValue) : void 0
1021
1013
  });
1022
- __privateAdd(this, _cookieName, void 0);
1023
- __privateAdd(this, _cookieAttributes, void 0);
1014
+ __privateAdd(this, _cookieName);
1015
+ __privateAdd(this, _cookieAttributes);
1024
1016
  __privateSet(this, _cookieName, cookieName);
1025
1017
  __privateSet(this, _cookieAttributes, cookieAttributes);
1026
1018
  }
1027
1019
  handleDelete() {
1028
- if (ssr)
1029
- return Promise.resolve();
1020
+ if (ssr) return Promise.resolve();
1030
1021
  import_js_cookie.default.remove(__privateGet(this, _cookieName));
1031
1022
  return Promise.resolve();
1032
1023
  }
1033
1024
  async handleUpdateData(_, computedValue) {
1034
- if (ssr)
1035
- return;
1025
+ if (ssr) return;
1036
1026
  if (computedValue.consent) {
1037
1027
  import_js_cookie.default.set(__privateGet(this, _cookieName), serializeCookie(computedValue), __privateGet(this, _cookieAttributes));
1038
1028
  } else {
@@ -1046,31 +1036,40 @@ var TYPE_SEP = "~";
1046
1036
  var PAIR_SEP = "!";
1047
1037
  var KV_SEP = "-";
1048
1038
  function parseScoreCookie(cookieValue) {
1049
- if (!cookieValue)
1050
- return;
1039
+ if (!cookieValue) return;
1051
1040
  const types = cookieValue.split(TYPE_SEP);
1052
- if (types.length > 5)
1053
- return;
1041
+ if (types.length > 5) return;
1054
1042
  const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
1055
1043
  const data = {
1056
1044
  // this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
1057
1045
  consent: true,
1058
- sessionScores: decodeCookieType(parseCookieType(sessionScores)),
1059
- scores: decodeCookieType(parseCookieType(visitorScores)),
1046
+ sessionScores: decodeCookieType(parseCookieScores(sessionScores)),
1047
+ scores: decodeCookieType(parseCookieScores(visitorScores)),
1060
1048
  tests: parseCookieType(abTestData),
1061
1049
  controlGroup: controlGroup === "1",
1062
1050
  personalizeVariants: decodePersonalizeVariants(personalizeVariants)
1063
1051
  };
1064
1052
  return data;
1065
1053
  }
1054
+ function parseCookieScores(type) {
1055
+ if (!type) {
1056
+ return {};
1057
+ }
1058
+ const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
1059
+ return pairs.reduce((acc, cur) => {
1060
+ if (cur.length < 2) return acc;
1061
+ const key = cur.slice(0, -1).join(KV_SEP);
1062
+ acc[key] = cur[cur.length - 1];
1063
+ return acc;
1064
+ }, {});
1065
+ }
1066
1066
  function parseCookieType(type) {
1067
1067
  if (!type) {
1068
1068
  return {};
1069
1069
  }
1070
1070
  const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
1071
1071
  return pairs.reduce((acc, cur) => {
1072
- if (cur.length < 2)
1073
- return acc;
1072
+ if (cur.length < 2) return acc;
1074
1073
  acc[cur[0]] = cur.slice(1).join("-");
1075
1074
  return acc;
1076
1075
  }, {});
@@ -1138,13 +1137,13 @@ function serializeCookieType(type) {
1138
1137
  }
1139
1138
 
1140
1139
  // src/storage/EdgeTransitionDataStore.ts
1141
- var _fetchData, fetchData_fn;
1140
+ var _EdgeTransitionDataStore_instances, fetchData_fn;
1142
1141
  var EdgeTransitionDataStore = class extends TransitionDataStore {
1143
1142
  constructor({ serverCookieValue, visitorIdCookieName = "ufvi", ...base }) {
1144
1143
  super(base);
1145
- __privateAdd(this, _fetchData);
1144
+ __privateAdd(this, _EdgeTransitionDataStore_instances);
1146
1145
  if (!base.initialData) {
1147
- __privateMethod(this, _fetchData, fetchData_fn).call(this).catch((err) => {
1146
+ __privateMethod(this, _EdgeTransitionDataStore_instances, fetchData_fn).call(this).catch((err) => {
1148
1147
  console.error(err);
1149
1148
  });
1150
1149
  }
@@ -1163,7 +1162,7 @@ var EdgeTransitionDataStore = class extends TransitionDataStore {
1163
1162
  }
1164
1163
  }
1165
1164
  };
1166
- _fetchData = new WeakSet();
1165
+ _EdgeTransitionDataStore_instances = new WeakSet();
1167
1166
  fetchData_fn = async function() {
1168
1167
  const serviceData = await new Promise((resolve) => {
1169
1168
  setTimeout(() => {
@@ -1220,13 +1219,13 @@ var emptyVisitorData = () => ({
1220
1219
  });
1221
1220
 
1222
1221
  // src/storage/VisitorDataStore.ts
1223
- var import_lite3 = require("dequal/lite");
1222
+ var import_lite4 = require("dequal/lite");
1224
1223
  var import_mitt2 = __toESM(require("mitt"));
1225
1224
 
1226
1225
  // src/storage/util/applyCommandsToData.ts
1227
1226
  var import_rfdc = __toESM(require("rfdc"));
1228
1227
  var clone = (0, import_rfdc.default)();
1229
- function applyCommandsToData(commands, state, inControlGroup) {
1228
+ function applyCommandsToData(commands, state) {
1230
1229
  const newData = state ? clone(state) : emptyVisitorData();
1231
1230
  commands.forEach((command) => {
1232
1231
  var _a, _b, _c;
@@ -1241,8 +1240,6 @@ function applyCommandsToData(commands, state, inControlGroup) {
1241
1240
  newData.tests[command.data.test] = command.data.variant;
1242
1241
  break;
1243
1242
  case "modscore":
1244
- if (inControlGroup)
1245
- break;
1246
1243
  const delta = Number(command.data.delta);
1247
1244
  if (isNaN(delta)) {
1248
1245
  throw new Error("Non-number delta received");
@@ -1251,8 +1248,6 @@ function applyCommandsToData(commands, state, inControlGroup) {
1251
1248
  newData.scores[command.data.dimension] = existing + delta;
1252
1249
  break;
1253
1250
  case "modscoreS":
1254
- if (inControlGroup)
1255
- break;
1256
1251
  const deltaS = Number(command.data.delta);
1257
1252
  if (isNaN(deltaS)) {
1258
1253
  throw new Error("Non-number delta received");
@@ -1296,71 +1291,65 @@ function applyCommandsToData(commands, state, inControlGroup) {
1296
1291
  }
1297
1292
 
1298
1293
  // src/storage/util/LocalStorage.ts
1294
+ var _LocalStorage_instances, key_fn;
1299
1295
  var LocalStorage = class {
1300
- constructor() {
1296
+ constructor(partitionKey) {
1297
+ this.partitionKey = partitionKey;
1298
+ __privateAdd(this, _LocalStorage_instances);
1301
1299
  __publicField(this, "inMemoryFallback", {});
1302
1300
  __publicField(this, "hasLocalStorageObject", typeof localStorage !== "undefined");
1303
1301
  }
1304
1302
  get(key) {
1305
- const fallbackValue = this.inMemoryFallback[key];
1303
+ const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
1304
+ const fallbackValue = this.inMemoryFallback[keyValue];
1306
1305
  if (!this.hasLocalStorageObject || fallbackValue) {
1307
1306
  return fallbackValue;
1308
1307
  }
1309
1308
  try {
1310
- const value = localStorage.getItem(key);
1309
+ const value = localStorage.getItem(keyValue);
1311
1310
  return value ? JSON.parse(value) : void 0;
1312
1311
  } catch (e) {
1313
1312
  return fallbackValue;
1314
1313
  }
1315
1314
  }
1316
1315
  set(key, value, storageConsent) {
1317
- this.inMemoryFallback[key] = value;
1316
+ const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
1317
+ this.inMemoryFallback[keyValue] = value;
1318
1318
  if (!this.hasLocalStorageObject || !storageConsent) {
1319
1319
  return;
1320
1320
  }
1321
1321
  try {
1322
- localStorage.setItem(key, JSON.stringify(value));
1322
+ localStorage.setItem(keyValue, JSON.stringify(value));
1323
1323
  } catch (e) {
1324
1324
  console.warn(e);
1325
1325
  }
1326
1326
  }
1327
1327
  delete(key, leaveInMemory) {
1328
+ const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
1328
1329
  if (!leaveInMemory) {
1329
- delete this.inMemoryFallback[key];
1330
+ delete this.inMemoryFallback[keyValue];
1330
1331
  }
1331
1332
  try {
1332
- localStorage.removeItem(key);
1333
+ localStorage.removeItem(keyValue);
1333
1334
  } catch (e) {
1334
1335
  }
1335
1336
  }
1336
1337
  };
1338
+ _LocalStorage_instances = new WeakSet();
1339
+ key_fn = function(key) {
1340
+ return this.partitionKey ? `${this.partitionKey}.${key}` : key;
1341
+ };
1337
1342
 
1338
1343
  // src/storage/VisitorDataStore.ts
1339
1344
  var STORAGE_KEY = "ufvisitor";
1340
- var _mitt2, _persist, _visitTimeout, _options, _currentData, currentData_get, _replaceData, replaceData_fn, _setVisitTimeout, setVisitTimeout_fn, _isExpired, isExpired_fn, _handleCaps, handleCaps_fn, _defaultData, defaultData_fn;
1345
+ var _mitt2, _persist, _visitTimeout, _options, _VisitorDataStore_instances, currentData_get, replaceData_fn, setVisitTimeout_fn, isExpired_fn, handleCaps_fn, defaultData_fn;
1341
1346
  var VisitorDataStore = class {
1342
1347
  constructor(options) {
1343
- /** Gets the current client-side storage data. This property is always up to date. */
1344
- __privateAdd(this, _currentData);
1345
- /**
1346
- * IMPORTANT: This function mutates the input data. This is done,
1347
- * because all the sources that call it have either already spread or cloned
1348
- * the data, so we can safely mutate it for better perf.
1349
- */
1350
- __privateAdd(this, _replaceData);
1351
- __privateAdd(this, _setVisitTimeout);
1352
- __privateAdd(this, _isExpired);
1353
- /**
1354
- * IMPORTANT: This function mutates the input data. This is done,
1355
- * because all the sources that call it have either already spread or cloned
1356
- * the data, so we can safely mutate it for better perf.
1357
- */
1358
- __privateAdd(this, _handleCaps);
1359
- __privateAdd(this, _defaultData);
1348
+ __privateAdd(this, _VisitorDataStore_instances);
1360
1349
  __privateAdd(this, _mitt2, (0, import_mitt2.default)());
1361
- __privateAdd(this, _persist, new LocalStorage());
1362
- __privateAdd(this, _visitTimeout, void 0);
1363
- __privateAdd(this, _options, void 0);
1350
+ __privateAdd(this, _persist);
1351
+ __privateAdd(this, _visitTimeout);
1352
+ __privateAdd(this, _options);
1364
1353
  /**
1365
1354
  * Subscribe to events from storage
1366
1355
  */
@@ -1369,8 +1358,9 @@ var VisitorDataStore = class {
1369
1358
  off: __privateGet(this, _mitt2).off
1370
1359
  });
1371
1360
  __privateSet(this, _options, options);
1372
- if (!__privateGet(this, _currentData, currentData_get)) {
1373
- __privateMethod(this, _replaceData, replaceData_fn).call(this, __privateMethod(this, _defaultData, defaultData_fn).call(this), true);
1361
+ __privateSet(this, _persist, new LocalStorage(options.partitionKey));
1362
+ if (!__privateGet(this, _VisitorDataStore_instances, currentData_get)) {
1363
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this), true);
1374
1364
  }
1375
1365
  if (options.transitionStore) {
1376
1366
  const serverToClientTransitionState = options.transitionStore.getClientTransitionState();
@@ -1378,17 +1368,17 @@ var VisitorDataStore = class {
1378
1368
  options.onServerTransitionReceived(serverToClientTransitionState);
1379
1369
  }
1380
1370
  options.transitionStore.events.on("dataUpdatedAsync", (data) => {
1381
- __privateMethod(this, _replaceData, replaceData_fn).call(this, {
1382
- ...__privateGet(this, _currentData, currentData_get).visitorData,
1371
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, {
1372
+ ...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData,
1383
1373
  ...data
1384
1374
  });
1385
1375
  });
1386
1376
  const transitionData = options.transitionStore.data;
1387
1377
  if (transitionData) {
1388
- __privateMethod(this, _replaceData, replaceData_fn).call(
1378
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(
1389
1379
  this,
1390
1380
  // we know _currentData is not empty because we inited it above if it was
1391
- { ...__privateGet(this, _currentData, currentData_get).visitorData, ...transitionData },
1381
+ { ...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData, ...transitionData },
1392
1382
  true
1393
1383
  );
1394
1384
  }
@@ -1396,13 +1386,13 @@ var VisitorDataStore = class {
1396
1386
  }
1397
1387
  /** Gets the current visitor data. This property is always up to date. */
1398
1388
  get data() {
1399
- var _a, _b;
1400
- const data = __privateGet(this, _currentData, currentData_get);
1401
- if (__privateMethod(this, _isExpired, isExpired_fn).call(this, data)) {
1389
+ var _a, _b, _c;
1390
+ const data = (_a = __privateGet(this, _VisitorDataStore_instances, currentData_get)) != null ? _a : { visitorData: __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this), updated: (/* @__PURE__ */ new Date()).getTime() };
1391
+ if (__privateMethod(this, _VisitorDataStore_instances, isExpired_fn).call(this, data)) {
1402
1392
  const { sessionScores, ...newData } = data.visitorData;
1403
- __privateMethod(this, _replaceData, replaceData_fn).call(this, { ...newData, sessionScores: {} });
1404
- (_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["info", 120]);
1405
- return __privateGet(this, _currentData, currentData_get).visitorData;
1393
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, { ...newData, sessionScores: {} });
1394
+ (_c = (_b = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _c.call(_b, ["info", 120]);
1395
+ return __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData;
1406
1396
  }
1407
1397
  return data.visitorData;
1408
1398
  }
@@ -1414,17 +1404,18 @@ var VisitorDataStore = class {
1414
1404
  }
1415
1405
  /** Push data update command(s) into the visitor data */
1416
1406
  async updateData(commands) {
1417
- var _a, _b, _c, _d;
1407
+ var _a, _b, _c;
1418
1408
  if (commands.length === 0) {
1419
1409
  return;
1420
1410
  }
1421
1411
  (_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 101, commands]);
1422
- const newData = applyCommandsToData(commands, this.data, (_c = __privateGet(this, _currentData, currentData_get)) == null ? void 0 : _c.visitorData.controlGroup);
1412
+ const newData = applyCommandsToData(commands, this.data);
1423
1413
  if (commands.some((c) => c.type === "consent" && !c.data)) {
1424
1414
  __privateGet(this, _persist).delete(STORAGE_KEY, true);
1425
1415
  }
1426
- __privateMethod(this, _replaceData, replaceData_fn).call(this, newData);
1427
- await ((_d = __privateGet(this, _options).transitionStore) == null ? void 0 : _d.updateData(commands, __privateGet(this, _currentData, currentData_get).visitorData));
1416
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, newData);
1417
+ await ((_c = __privateGet(this, _options).transitionStore) == null ? void 0 : _c.updateData(commands, __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData));
1418
+ __privateGet(this, _mitt2).emit("commandsExecuted", commands);
1428
1419
  }
1429
1420
  /**
1430
1421
  * Deletes visitor data (forgetting them)
@@ -1437,7 +1428,7 @@ var VisitorDataStore = class {
1437
1428
  try {
1438
1429
  __privateGet(this, _persist).delete(STORAGE_KEY, false);
1439
1430
  await ((_c = __privateGet(this, _options).transitionStore) == null ? void 0 : _c.delete(fromAllDevices));
1440
- __privateMethod(this, _replaceData, replaceData_fn).call(this, __privateMethod(this, _defaultData, defaultData_fn).call(this));
1431
+ __privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this));
1441
1432
  } finally {
1442
1433
  (_e = (_d = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _e.call(_d, ["info", 103, "ENDGROUP"]);
1443
1434
  }
@@ -1447,39 +1438,38 @@ _mitt2 = new WeakMap();
1447
1438
  _persist = new WeakMap();
1448
1439
  _visitTimeout = new WeakMap();
1449
1440
  _options = new WeakMap();
1450
- _currentData = new WeakSet();
1441
+ _VisitorDataStore_instances = new WeakSet();
1451
1442
  currentData_get = function() {
1452
1443
  return __privateGet(this, _persist).get(STORAGE_KEY);
1453
1444
  };
1454
- _replaceData = new WeakSet();
1445
+ /**
1446
+ * IMPORTANT: This function mutates the input data. This is done,
1447
+ * because all the sources that call it have either already spread or cloned
1448
+ * the data, so we can safely mutate it for better perf.
1449
+ */
1455
1450
  replaceData_fn = function(data, quiet = false) {
1456
1451
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1457
- const oldData = __privateGet(this, _currentData, currentData_get);
1452
+ const oldData = __privateGet(this, _VisitorDataStore_instances, currentData_get);
1458
1453
  const now = Date.now();
1459
- if (data.controlGroup) {
1460
- data.scores = {};
1461
- data.sessionScores = {};
1462
- } else {
1463
- __privateMethod(this, _handleCaps, handleCaps_fn).call(this, data.scores);
1464
- __privateMethod(this, _handleCaps, handleCaps_fn).call(this, data.sessionScores);
1465
- (_b = (_a = __privateGet(this, _options)).decay) == null ? void 0 : _b.call(_a, {
1466
- now,
1467
- lastUpd: oldData == null ? void 0 : oldData.updated,
1468
- scores: data.scores,
1469
- sessionScores: data.sessionScores,
1470
- onLogMessage: __privateGet(this, _options).onLogMessage
1471
- });
1472
- }
1473
- const haveScoresChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
1474
- const haveSessionScoresChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
1475
- const haveQuirksChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
1476
- const haveTestsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
1477
- const haveGoalsChanged = !(0, import_lite3.dequal)(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
1454
+ __privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.scores);
1455
+ __privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.sessionScores);
1456
+ (_b = (_a = __privateGet(this, _options)).decay) == null ? void 0 : _b.call(_a, {
1457
+ now,
1458
+ lastUpd: oldData == null ? void 0 : oldData.updated,
1459
+ scores: data.scores,
1460
+ sessionScores: data.sessionScores,
1461
+ onLogMessage: __privateGet(this, _options).onLogMessage
1462
+ });
1463
+ const haveScoresChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
1464
+ const haveSessionScoresChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
1465
+ const haveQuirksChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
1466
+ const haveTestsChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
1467
+ const haveGoalsChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
1478
1468
  const updatedData = {
1479
1469
  updated: now,
1480
1470
  visitorData: data
1481
1471
  };
1482
- __privateMethod(this, _setVisitTimeout, setVisitTimeout_fn).call(this);
1472
+ __privateMethod(this, _VisitorDataStore_instances, setVisitTimeout_fn).call(this);
1483
1473
  __privateGet(this, _persist).set(STORAGE_KEY, updatedData, !!data.consent);
1484
1474
  (_d = (_c = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _d.call(_c, ["debug", 102, data]);
1485
1475
  if (!quiet) {
@@ -1510,7 +1500,6 @@ replaceData_fn = function(data, quiet = false) {
1510
1500
  }
1511
1501
  }
1512
1502
  };
1513
- _setVisitTimeout = new WeakSet();
1514
1503
  setVisitTimeout_fn = function() {
1515
1504
  if (typeof document === "undefined" || !__privateGet(this, _options).visitLifespan) {
1516
1505
  return;
@@ -1522,12 +1511,15 @@ setVisitTimeout_fn = function() {
1522
1511
  this.data;
1523
1512
  }, __privateGet(this, _options).visitLifespan + 50));
1524
1513
  };
1525
- _isExpired = new WeakSet();
1526
1514
  isExpired_fn = function(data) {
1527
1515
  const expires = __privateGet(this, _options).visitLifespan;
1528
1516
  return expires ? data.updated + expires < Date.now() : false;
1529
1517
  };
1530
- _handleCaps = new WeakSet();
1518
+ /**
1519
+ * IMPORTANT: This function mutates the input data. This is done,
1520
+ * because all the sources that call it have either already spread or cloned
1521
+ * the data, so we can safely mutate it for better perf.
1522
+ */
1531
1523
  handleCaps_fn = function(scores) {
1532
1524
  var _a, _b;
1533
1525
  if (!__privateGet(this, _options).manifest) {
@@ -1545,7 +1537,6 @@ handleCaps_fn = function(scores) {
1545
1537
  }
1546
1538
  }
1547
1539
  };
1548
- _defaultData = new WeakSet();
1549
1540
  defaultData_fn = function() {
1550
1541
  var _a, _b, _c;
1551
1542
  return {
@@ -1556,23 +1547,21 @@ defaultData_fn = function() {
1556
1547
  };
1557
1548
 
1558
1549
  // src/Context.ts
1559
- var import_lite4 = require("dequal/lite");
1550
+ var import_lite5 = require("dequal/lite");
1560
1551
  var import_mitt3 = __toESM(require("mitt"));
1561
1552
  var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
1562
1553
  var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
1563
- var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
1554
+ var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
1564
1555
  var Context = class {
1565
1556
  constructor(options) {
1566
- __privateAdd(this, _emitTest);
1567
- __privateAdd(this, _updateGoals);
1568
- __privateAdd(this, _updateComputedScores);
1569
- __privateAdd(this, _calculateScores);
1557
+ __privateAdd(this, _Context_instances);
1570
1558
  __publicField(this, "manifest");
1571
- __privateAdd(this, _serverTransitionState, void 0);
1559
+ __privateAdd(this, _serverTransitionState);
1572
1560
  __privateAdd(this, _scores, {});
1573
- __privateAdd(this, _state, void 0);
1561
+ __privateAdd(this, _state);
1574
1562
  __privateAdd(this, _pzCache, {});
1575
- __privateAdd(this, _plugins, void 0);
1563
+ __privateAdd(this, _plugins);
1564
+ __privateAdd(this, _commands);
1576
1565
  __privateAdd(this, _mitt3, (0, import_mitt3.default)());
1577
1566
  /**
1578
1567
  * Subscribe to events
@@ -1586,6 +1575,9 @@ var Context = class {
1586
1575
  const { manifest, ...storageOptions } = options;
1587
1576
  __privateSet(this, _state, {});
1588
1577
  __privateSet(this, _plugins, options.plugins);
1578
+ if (typeof options.transitionStore !== "undefined") {
1579
+ __privateSet(this, _commands, []);
1580
+ }
1589
1581
  (_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
1590
1582
  if (!plugin.logDrain) {
1591
1583
  return;
@@ -1618,9 +1610,9 @@ var Context = class {
1618
1610
  },
1619
1611
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1620
1612
  });
1621
- this.storage.events.on("scoresUpdated", __privateMethod(this, _updateComputedScores, updateComputedScores_fn).bind(this));
1613
+ this.storage.events.on("scoresUpdated", __privateMethod(this, _Context_instances, updateComputedScores_fn).bind(this));
1622
1614
  if (!__privateGet(this, _serverTransitionState)) {
1623
- __privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
1615
+ __privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
1624
1616
  }
1625
1617
  this.storage.events.on("quirksUpdated", (quirks) => {
1626
1618
  const updates = this.manifest.computeSignals({
@@ -1629,7 +1621,7 @@ var Context = class {
1629
1621
  previousState: __privateGet(this, _state),
1630
1622
  visitor: this.storage.data
1631
1623
  });
1632
- __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1624
+ __privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
1633
1625
  quirks: quirks.quirks,
1634
1626
  scores: void 0
1635
1627
  });
@@ -1646,6 +1638,9 @@ var Context = class {
1646
1638
  } finally {
1647
1639
  __privateGet(this, _mitt3).emit("log", ["info", 1, "ENDGROUP"]);
1648
1640
  }
1641
+ if (typeof window !== "undefined") {
1642
+ window.__UNIFORM_CONTEXTUAL_EDITING_CONTEXT__ = this;
1643
+ }
1649
1644
  }
1650
1645
  /** Gets the current visitor's dimension score vector. */
1651
1646
  get scores() {
@@ -1666,7 +1661,7 @@ var Context = class {
1666
1661
  * will NOT result in a recomputation of signal state.
1667
1662
  */
1668
1663
  async update(newData) {
1669
- var _a, _b, _c, _d;
1664
+ var _a, _b, _c, _d, _e;
1670
1665
  const commands = [];
1671
1666
  const newServerSideTests = {};
1672
1667
  if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
@@ -1752,7 +1747,7 @@ var Context = class {
1752
1747
  // re-compute using scores from storage instead of the current scores since
1753
1748
  // server transition scores might have adjusted values already integrated into them,
1754
1749
  // which causes issues when you are near limits.
1755
- scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _calculateScores, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
1750
+ scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
1756
1751
  })
1757
1752
  );
1758
1753
  __privateSet(this, _state, {
@@ -1761,9 +1756,13 @@ var Context = class {
1761
1756
  });
1762
1757
  await this.storage.updateData(commands);
1763
1758
  if (__privateGet(this, _serverTransitionState)) {
1764
- __privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
1759
+ await this.processServerCommands({
1760
+ serverCommands: __privateGet(this, _serverTransitionState).commands,
1761
+ commands
1762
+ });
1763
+ __privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
1765
1764
  Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
1766
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1765
+ __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1767
1766
  name: testName,
1768
1767
  variantId: testVariantId,
1769
1768
  variantAssigned: true
@@ -1781,10 +1780,31 @@ var Context = class {
1781
1780
  await plugin.update(newData);
1782
1781
  }
1783
1782
  }
1783
+ (_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
1784
1784
  } finally {
1785
1785
  __privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
1786
1786
  }
1787
1787
  }
1788
+ async processServerCommands({
1789
+ serverCommands,
1790
+ commands
1791
+ }) {
1792
+ if (!(serverCommands == null ? void 0 : serverCommands.length)) {
1793
+ return;
1794
+ }
1795
+ const notExecutedCommands = [];
1796
+ serverCommands.forEach((serverCommand) => {
1797
+ const found = commands.find((command) => {
1798
+ return areCommandsEqual(command, serverCommand);
1799
+ });
1800
+ if (!found) {
1801
+ notExecutedCommands.push(serverCommand);
1802
+ }
1803
+ });
1804
+ if (notExecutedCommands.length > 0) {
1805
+ await this.storage.updateData(notExecutedCommands);
1806
+ }
1807
+ }
1788
1808
  /** use test() instead */
1789
1809
  getTestVariantId(testName) {
1790
1810
  var _a, _b, _c, _d;
@@ -1839,7 +1859,7 @@ var Context = class {
1839
1859
  context: this,
1840
1860
  onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
1841
1861
  });
1842
- __privateMethod(this, _emitTest, emitTest_fn).call(this, {
1862
+ __privateMethod(this, _Context_instances, emitTest_fn).call(this, {
1843
1863
  name: options.name,
1844
1864
  variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
1845
1865
  variantAssigned: value.variantAssigned
@@ -1863,7 +1883,7 @@ var Context = class {
1863
1883
  control: this.storage.data.controlGroup,
1864
1884
  changed: true
1865
1885
  };
1866
- if (previousPlacement && (0, import_lite4.dequal)(eventData.variantIds, previousPlacement)) {
1886
+ if (previousPlacement && (0, import_lite5.dequal)(eventData.variantIds, previousPlacement)) {
1867
1887
  eventData.changed = false;
1868
1888
  }
1869
1889
  __privateGet(this, _mitt3).emit("personalizationResult", eventData);
@@ -1897,7 +1917,8 @@ var Context = class {
1897
1917
  quirks: this.storage.data.quirks,
1898
1918
  ssv: __privateGet(this, _scores),
1899
1919
  tests: {},
1900
- personalizeVariants: this.storage.data.personalizeVariants
1920
+ personalizeVariants: this.storage.data.personalizeVariants,
1921
+ commands: __privateGet(this, _commands)
1901
1922
  };
1902
1923
  const allTests = this.storage.data.tests;
1903
1924
  Object.entries(allTests).map(([testName, testValue]) => {
@@ -1912,7 +1933,7 @@ var Context = class {
1912
1933
  internal_processTestEvent(event) {
1913
1934
  if (event.variantId) {
1914
1935
  this.setTestVariantId(event.name, event.variantId);
1915
- __privateMethod(this, _emitTest, emitTest_fn).call(this, event);
1936
+ __privateMethod(this, _Context_instances, emitTest_fn).call(this, event);
1916
1937
  }
1917
1938
  }
1918
1939
  /** @deprecated */
@@ -1926,25 +1947,24 @@ _scores = new WeakMap();
1926
1947
  _state = new WeakMap();
1927
1948
  _pzCache = new WeakMap();
1928
1949
  _plugins = new WeakMap();
1950
+ _commands = new WeakMap();
1929
1951
  _mitt3 = new WeakMap();
1930
- _emitTest = new WeakSet();
1952
+ _Context_instances = new WeakSet();
1931
1953
  emitTest_fn = function(event) {
1932
1954
  __privateGet(this, _mitt3).emit("testResult", event);
1933
1955
  };
1934
- _updateGoals = new WeakSet();
1935
1956
  updateGoals_fn = async function(data) {
1936
1957
  const goalCommands = this.manifest.computeGoals(data);
1937
1958
  if (goalCommands.length !== 0) {
1938
1959
  await this.storage.updateData(goalCommands);
1939
1960
  }
1940
1961
  };
1941
- _updateComputedScores = new WeakSet();
1942
1962
  updateComputedScores_fn = function(newData) {
1943
- const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
1944
- const newScoresHaveChanged = !(0, import_lite4.dequal)(newScores, __privateGet(this, _scores));
1963
+ const newScores = __privateMethod(this, _Context_instances, calculateScores_fn).call(this, newData);
1964
+ const newScoresHaveChanged = !(0, import_lite5.dequal)(newScores, __privateGet(this, _scores));
1945
1965
  if (newScoresHaveChanged) {
1946
1966
  __privateSet(this, _scores, newScores);
1947
- __privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
1967
+ __privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
1948
1968
  scores: __privateGet(this, _scores),
1949
1969
  quirks: void 0
1950
1970
  });
@@ -1952,7 +1972,6 @@ updateComputedScores_fn = function(newData) {
1952
1972
  __privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
1953
1973
  }
1954
1974
  };
1955
- _calculateScores = new WeakSet();
1956
1975
  calculateScores_fn = function(newData) {
1957
1976
  var _a;
1958
1977
  let newScores = { ...newData.scores };
@@ -2001,13 +2020,11 @@ function enableContextDevTools(options) {
2001
2020
  );
2002
2021
  };
2003
2022
  const onPersonalizationResult = (e) => {
2004
- if (!e.changed)
2005
- return;
2023
+ if (!e.changed) return;
2006
2024
  personalizations.push(e);
2007
2025
  };
2008
2026
  const onTestResult = (e) => {
2009
- if (!e.variantAssigned)
2010
- return;
2027
+ if (!e.variantAssigned) return;
2011
2028
  tests.push(e);
2012
2029
  };
2013
2030
  if (isBrowser) {
@@ -2101,10 +2118,16 @@ var getBasePayload = () => {
2101
2118
  };
2102
2119
  };
2103
2120
  var createInsightsClient = ({ endpoint }) => {
2104
- const url = new URL(endpoint.host);
2105
- url.pathname = "/v0/events";
2106
- url.searchParams.set("name", "analytics_events");
2107
- const endpointUrl = url.toString();
2121
+ let endpointUrl;
2122
+ const apiKey = endpoint.apiKey;
2123
+ if (endpoint.type === "api") {
2124
+ const url = new URL(endpoint.host);
2125
+ url.pathname = "/v0/events";
2126
+ url.searchParams.set("name", "analytics_events");
2127
+ endpointUrl = url.toString();
2128
+ } else {
2129
+ endpointUrl = endpoint.path;
2130
+ }
2108
2131
  const sendMessage = async (message) => {
2109
2132
  if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
2110
2133
  return;
@@ -2113,12 +2136,15 @@ var createInsightsClient = ({ endpoint }) => {
2113
2136
  ...message,
2114
2137
  payload: JSON.stringify(message.payload)
2115
2138
  };
2139
+ const headers = {
2140
+ "Content-Type": "application/json"
2141
+ };
2142
+ if (apiKey) {
2143
+ headers.Authorization = `Bearer ${apiKey}`;
2144
+ }
2116
2145
  const response = await fetch(endpointUrl, {
2117
2146
  method: "POST",
2118
- headers: {
2119
- "Content-Type": "application/json",
2120
- Authorization: `Bearer ${endpoint.apiKey}`
2121
- },
2147
+ headers,
2122
2148
  body: JSON.stringify(converted)
2123
2149
  });
2124
2150
  const json = await response.json();
@@ -2286,7 +2312,6 @@ var createInsights = ({
2286
2312
  },
2287
2313
  pageHit: () => {
2288
2314
  if (!storageData) {
2289
- console.error("Insights not initialized");
2290
2315
  return;
2291
2316
  }
2292
2317
  if (previousUrl === window.location.href) {
@@ -2314,7 +2339,6 @@ var createInsights = ({
2314
2339
  },
2315
2340
  personalizationResult: (result) => {
2316
2341
  if (!storageData) {
2317
- console.error("Insights not initialized");
2318
2342
  return;
2319
2343
  }
2320
2344
  client.personalizationResult({
@@ -2326,7 +2350,6 @@ var createInsights = ({
2326
2350
  },
2327
2351
  goalConvert: (goalId) => {
2328
2352
  if (!storageData) {
2329
- console.error("Insights not initialized");
2330
2353
  return;
2331
2354
  }
2332
2355
  client.goalConvert({
@@ -2338,7 +2361,6 @@ var createInsights = ({
2338
2361
  },
2339
2362
  scoresChange: (scores) => {
2340
2363
  if (!storageData) {
2341
- console.error("Insights not initialized");
2342
2364
  return;
2343
2365
  }
2344
2366
  client.scoresChange({
@@ -2607,23 +2629,30 @@ function parseQuickConnect(serialized) {
2607
2629
  EdgeNodeTagName,
2608
2630
  EdgeTransitionDataStore,
2609
2631
  GroupCriteriaEvaluator,
2632
+ KV_SEP,
2610
2633
  ManifestInstance,
2634
+ PAIR_SEP,
2611
2635
  SERVER_STATE_ID,
2612
2636
  ScriptType,
2637
+ TYPE_SEP,
2613
2638
  TransitionDataStore,
2614
2639
  UNIFORM_DEFAULT_COOKIE_NAME,
2615
2640
  VisitorDataStore,
2641
+ areCommandsEqual,
2616
2642
  computeAggregateDimensions,
2617
2643
  cookieEvaluator,
2618
2644
  createConsoleLogDrain,
2619
2645
  createDebugConsoleLogDrain,
2620
2646
  createLinearDecay,
2621
2647
  currentPageEvaluator,
2648
+ decodeCookieType,
2649
+ decodePersonalizeVariants,
2622
2650
  emptyVisitorData,
2623
2651
  enableConsoleLogDrain,
2624
2652
  enableContextDevTools,
2625
2653
  enableDebugConsoleLogDrain,
2626
2654
  enableUniformInsights,
2655
+ encodeCookieType,
2627
2656
  evaluateVariantMatch,
2628
2657
  eventEvaluator,
2629
2658
  explainStringMatch,
@@ -2632,10 +2661,16 @@ function parseQuickConnect(serialized) {
2632
2661
  isStringMatch,
2633
2662
  pageViewCountDimension,
2634
2663
  pageViewCountEvaluator,
2664
+ parseCookieScores,
2665
+ parseCookieType,
2635
2666
  parseQuickConnect,
2667
+ parseScoreCookie,
2636
2668
  personalizeVariations,
2637
2669
  queryStringEvaluator,
2638
2670
  quirkEvaluator,
2671
+ serializeCookie,
2672
+ serializeCookieType,
2673
+ serializePersonalizeVariants,
2639
2674
  serializeQuickConnect,
2640
2675
  testVariations
2641
2676
  });