@uniformdev/context 19.135.1-alpha.10 → 19.135.1-alpha.11
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/api/api.d.mts +25 -25
- package/dist/api/api.d.ts +25 -25
- package/dist/api/api.js +8 -19
- package/dist/api/api.mjs +8 -19
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.esm.js +261 -239
- package/dist/index.js +274 -239
- package/dist/index.mjs +261 -239
- package/dist/{types-DqYG-dCc.d.mts → types-o4ZU_qKY.d.mts} +39 -13
- package/dist/{types-DqYG-dCc.d.ts → types-o4ZU_qKY.d.ts} +39 -13
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
@@ -1,31 +1,14 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
-
var
|
3
|
-
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
5
|
-
return value;
|
6
|
-
};
|
7
|
-
var __accessCheck = (obj, member, msg) => {
|
8
|
-
if (!member.has(obj))
|
9
|
-
throw TypeError("Cannot " + msg);
|
10
|
-
};
|
11
|
-
var __privateGet = (obj, member, getter) => {
|
12
|
-
__accessCheck(obj, member, "read from private field");
|
13
|
-
return getter ? getter.call(obj) : member.get(obj);
|
14
|
-
};
|
15
|
-
var __privateAdd = (obj, member, value) => {
|
16
|
-
if (member.has(obj))
|
17
|
-
throw TypeError("Cannot add the same private member more than once");
|
18
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
19
|
-
};
|
20
|
-
var __privateSet = (obj, member, value, setter) => {
|
21
|
-
__accessCheck(obj, member, "write to private field");
|
22
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
23
|
-
return value;
|
24
|
-
};
|
25
|
-
var __privateMethod = (obj, member, method) => {
|
26
|
-
__accessCheck(obj, member, "access private method");
|
27
|
-
return method;
|
2
|
+
var __typeError = (msg) => {
|
3
|
+
throw TypeError(msg);
|
28
4
|
};
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
7
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
8
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
9
|
+
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);
|
10
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
11
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
29
12
|
|
30
13
|
// src/manifest/aggregates/computeAggregateDimensions.ts
|
31
14
|
function computeAggregateDimensions(primitiveScores, aggregates) {
|
@@ -77,13 +60,11 @@ function computeAggregateDimension(primitiveScores, aggregateDimension, allAggre
|
|
77
60
|
var ENR_SEPARATOR = "_";
|
78
61
|
|
79
62
|
// src/manifest/goals/evaluators/SignalGoalEvaluator.ts
|
80
|
-
var
|
63
|
+
var _id;
|
81
64
|
var SignalGoalEvaluator = class {
|
82
65
|
constructor(options) {
|
83
|
-
__privateAdd(this,
|
84
|
-
__privateAdd(this, _id, void 0);
|
66
|
+
__privateAdd(this, _id);
|
85
67
|
__privateSet(this, _id, options.id);
|
86
|
-
__privateSet(this, _signal, options.signal);
|
87
68
|
}
|
88
69
|
get id() {
|
89
70
|
return __privateGet(this, _id);
|
@@ -98,15 +79,14 @@ var SignalGoalEvaluator = class {
|
|
98
79
|
};
|
99
80
|
}
|
100
81
|
};
|
101
|
-
_signal = new WeakMap();
|
102
82
|
_id = new WeakMap();
|
103
83
|
|
104
84
|
// src/manifest/signals/SignalInstance.ts
|
105
85
|
var _evaluator, _onLogMessage;
|
106
86
|
var SignalInstance = class {
|
107
87
|
constructor(data, evaluator, onLogMessage) {
|
108
|
-
__privateAdd(this, _evaluator
|
109
|
-
__privateAdd(this, _onLogMessage
|
88
|
+
__privateAdd(this, _evaluator);
|
89
|
+
__privateAdd(this, _onLogMessage);
|
110
90
|
__publicField(this, "signal");
|
111
91
|
this.signal = data;
|
112
92
|
__privateSet(this, _evaluator, evaluator);
|
@@ -168,10 +148,10 @@ var ManifestInstance = class {
|
|
168
148
|
}
|
169
149
|
}) {
|
170
150
|
__publicField(this, "data");
|
171
|
-
__privateAdd(this, _mf
|
172
|
-
__privateAdd(this, _signalInstances
|
151
|
+
__privateAdd(this, _mf);
|
152
|
+
__privateAdd(this, _signalInstances);
|
173
153
|
__privateAdd(this, _goalEvaluators, []);
|
174
|
-
__privateAdd(this, _onLogMessage2
|
154
|
+
__privateAdd(this, _onLogMessage2);
|
175
155
|
var _a, _b, _c, _d, _e;
|
176
156
|
__privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
|
177
157
|
this.data = manifest;
|
@@ -488,7 +468,7 @@ var quirkEvaluator = ({ update, criteria, signal, onLogMessage }) => {
|
|
488
468
|
var _evaluators;
|
489
469
|
var GroupCriteriaEvaluator = class {
|
490
470
|
constructor(criteriaEvaluators) {
|
491
|
-
__privateAdd(this, _evaluators
|
471
|
+
__privateAdd(this, _evaluators);
|
492
472
|
__privateSet(this, _evaluators, criteriaEvaluators);
|
493
473
|
}
|
494
474
|
evaluate(update, crit, commands, signal, onLogMessage) {
|
@@ -668,75 +648,66 @@ function personalizeVariations({
|
|
668
648
|
take = 1,
|
669
649
|
onLogMessage
|
670
650
|
}) {
|
671
|
-
var _a, _b, _c
|
651
|
+
var _a, _b, _c;
|
672
652
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "GROUP", { name, take }]);
|
673
653
|
try {
|
674
|
-
const
|
675
|
-
const results = [];
|
676
|
-
let personalized = false;
|
677
|
-
const scores = context.scores;
|
678
|
-
let index = 0;
|
654
|
+
const variantMatches = [];
|
679
655
|
const defaultVariants = [];
|
680
656
|
for (const variant of variations) {
|
681
|
-
if (
|
657
|
+
if ((_a = variant.pz) == null ? void 0 : _a.crit.length) {
|
658
|
+
if (variantMatches.length !== take && evaluateVariantMatch(variant.id, variant.pz, context.scores, onLogMessage)) {
|
659
|
+
variantMatches.push(variant);
|
660
|
+
}
|
661
|
+
} else {
|
682
662
|
defaultVariants.push(variant);
|
683
663
|
}
|
684
664
|
}
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
}
|
701
|
-
if (control) {
|
702
|
-
continue;
|
703
|
-
}
|
704
|
-
if (evaluateVariantMatch(variant.id, variant.pz, scores, onLogMessage)) {
|
705
|
-
let variantToAdd = variant;
|
706
|
-
let isControl = false;
|
707
|
-
const isDefault = defaultVariants.find((v) => v.id === variant.id);
|
708
|
-
if (take === 1 && !isDefault && defaultVariants.length && typeof variant.pz.control === "number") {
|
709
|
-
isControl = context.getPersonalizeVariantControl(name, currentIndex);
|
710
|
-
if (typeof isControl === "undefined") {
|
711
|
-
isControl = rollForControlGroup(variant.pz.control);
|
712
|
-
context.storage.updateData([
|
713
|
-
{
|
714
|
-
type: "setpersonalizecontrol",
|
715
|
-
data: {
|
716
|
-
personlizationName: name,
|
717
|
-
index: currentIndex,
|
718
|
-
control: isControl
|
719
|
-
}
|
665
|
+
const result = [];
|
666
|
+
for (let i = 0; i < variantMatches.length; i++) {
|
667
|
+
let isControl = (_b = context.storage.data.controlGroup) != null ? _b : false;
|
668
|
+
const variant = variantMatches[i];
|
669
|
+
if (!isControl && typeof ((_c = variant.pz) == null ? void 0 : _c.control) === "number") {
|
670
|
+
isControl = context.getPersonalizeVariantControl(name, i);
|
671
|
+
if (typeof isControl === "undefined") {
|
672
|
+
isControl = rollForControlGroup(variant.pz.control);
|
673
|
+
context.storage.updateData([
|
674
|
+
{
|
675
|
+
type: "setpersonalizecontrol",
|
676
|
+
data: {
|
677
|
+
personlizationName: name,
|
678
|
+
index: i,
|
679
|
+
control: isControl
|
720
680
|
}
|
721
|
-
|
722
|
-
|
723
|
-
if (isControl) {
|
724
|
-
variantToAdd = {
|
725
|
-
...defaultVariants[0],
|
726
|
-
id: variant.id
|
727
|
-
};
|
728
|
-
}
|
681
|
+
}
|
682
|
+
]);
|
729
683
|
}
|
730
|
-
personalized = personalized || typeof variantToAdd.pz !== "undefined";
|
731
|
-
results.push({
|
732
|
-
...variantToAdd,
|
733
|
-
control: isControl
|
734
|
-
});
|
735
684
|
}
|
685
|
+
let variantToAdd = variant;
|
686
|
+
if (isControl) {
|
687
|
+
const defaultReplacement = defaultVariants.shift();
|
688
|
+
if (defaultReplacement) {
|
689
|
+
variantToAdd = {
|
690
|
+
...defaultReplacement,
|
691
|
+
id: variant.id
|
692
|
+
};
|
693
|
+
} else {
|
694
|
+
variantToAdd = void 0;
|
695
|
+
}
|
696
|
+
}
|
697
|
+
if (variantToAdd) {
|
698
|
+
result.push({ ...variantToAdd, control: isControl });
|
699
|
+
}
|
700
|
+
}
|
701
|
+
while (result.length < take && defaultVariants.length) {
|
702
|
+
result.push({ ...defaultVariants.shift(), control: false });
|
736
703
|
}
|
704
|
+
const personalized = result.some((v) => {
|
705
|
+
var _a2;
|
706
|
+
return (_a2 = v.pz) == null ? void 0 : _a2.crit.length;
|
707
|
+
});
|
737
708
|
return {
|
738
709
|
personalized,
|
739
|
-
variations:
|
710
|
+
variations: result
|
740
711
|
};
|
741
712
|
} finally {
|
742
713
|
onLogMessage == null ? void 0 : onLogMessage(["info", 300, "ENDGROUP"]);
|
@@ -804,7 +775,7 @@ var testVariations = ({
|
|
804
775
|
let distributionOffset = 0;
|
805
776
|
selectedVariant = variations.find((variant, index) => {
|
806
777
|
const distribution = distributions[index];
|
807
|
-
if (random > distributionOffset && random <= distributionOffset + distribution) {
|
778
|
+
if ((random > distributionOffset || random === 0) && random <= distributionOffset + distribution) {
|
808
779
|
return variant;
|
809
780
|
}
|
810
781
|
distributionOffset += distribution;
|
@@ -826,18 +797,27 @@ var testVariations = ({
|
|
826
797
|
}
|
827
798
|
};
|
828
799
|
|
800
|
+
// src/storage/commands.ts
|
801
|
+
import { dequal as dequal2 } from "dequal/lite";
|
802
|
+
var areCommandsEqual = (a, b) => {
|
803
|
+
if (a.type !== b.type) {
|
804
|
+
return false;
|
805
|
+
}
|
806
|
+
return dequal2(a, b);
|
807
|
+
};
|
808
|
+
|
829
809
|
// src/storage/CookieTransitionDataStore.ts
|
830
810
|
import Cookies from "js-cookie";
|
831
811
|
|
832
812
|
// src/storage/TransitionDataStore.ts
|
833
|
-
import { dequal as
|
813
|
+
import { dequal as dequal3 } from "dequal/lite";
|
834
814
|
import mitt from "mitt";
|
835
815
|
var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
836
816
|
var _data, _initialData, _mitt;
|
837
817
|
var TransitionDataStore = class {
|
838
818
|
constructor({ initialData }) {
|
839
|
-
__privateAdd(this, _data
|
840
|
-
__privateAdd(this, _initialData
|
819
|
+
__privateAdd(this, _data);
|
820
|
+
__privateAdd(this, _initialData);
|
841
821
|
__privateAdd(this, _mitt, mitt());
|
842
822
|
/**
|
843
823
|
* Subscribe to events from the transition storage
|
@@ -876,7 +856,7 @@ var TransitionDataStore = class {
|
|
876
856
|
await this.handleDelete(fromAllDevices);
|
877
857
|
}
|
878
858
|
signalAsyncDataUpdate(newScores) {
|
879
|
-
if (
|
859
|
+
if (dequal3(this.data, newScores)) {
|
880
860
|
return;
|
881
861
|
}
|
882
862
|
__privateSet(this, _data, newScores);
|
@@ -908,8 +888,7 @@ for (let i = 0; i < alphabet.length; i++) {
|
|
908
888
|
s2b[alphabet.charCodeAt(i)] = i;
|
909
889
|
}
|
910
890
|
var ntob = (number) => {
|
911
|
-
if (number < 0)
|
912
|
-
return `-${ntob(-number)}`;
|
891
|
+
if (number < 0) return `-${ntob(-number)}`;
|
913
892
|
let lo = number >>> 0;
|
914
893
|
let hi = number / 4294967296 >>> 0;
|
915
894
|
let right = "";
|
@@ -948,20 +927,18 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
|
|
948
927
|
super({
|
949
928
|
initialData: ssr ? parseScoreCookie(serverCookieValue) : void 0
|
950
929
|
});
|
951
|
-
__privateAdd(this, _cookieName
|
952
|
-
__privateAdd(this, _cookieAttributes
|
930
|
+
__privateAdd(this, _cookieName);
|
931
|
+
__privateAdd(this, _cookieAttributes);
|
953
932
|
__privateSet(this, _cookieName, cookieName);
|
954
933
|
__privateSet(this, _cookieAttributes, cookieAttributes);
|
955
934
|
}
|
956
935
|
handleDelete() {
|
957
|
-
if (ssr)
|
958
|
-
return Promise.resolve();
|
936
|
+
if (ssr) return Promise.resolve();
|
959
937
|
Cookies.remove(__privateGet(this, _cookieName));
|
960
938
|
return Promise.resolve();
|
961
939
|
}
|
962
940
|
async handleUpdateData(_, computedValue) {
|
963
|
-
if (ssr)
|
964
|
-
return;
|
941
|
+
if (ssr) return;
|
965
942
|
if (computedValue.consent) {
|
966
943
|
Cookies.set(__privateGet(this, _cookieName), serializeCookie(computedValue), __privateGet(this, _cookieAttributes));
|
967
944
|
} else {
|
@@ -975,31 +952,40 @@ var TYPE_SEP = "~";
|
|
975
952
|
var PAIR_SEP = "!";
|
976
953
|
var KV_SEP = "-";
|
977
954
|
function parseScoreCookie(cookieValue) {
|
978
|
-
if (!cookieValue)
|
979
|
-
return;
|
955
|
+
if (!cookieValue) return;
|
980
956
|
const types = cookieValue.split(TYPE_SEP);
|
981
|
-
if (types.length > 5)
|
982
|
-
return;
|
957
|
+
if (types.length > 5) return;
|
983
958
|
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
984
959
|
const data = {
|
985
960
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
986
961
|
consent: true,
|
987
|
-
sessionScores: decodeCookieType(
|
988
|
-
scores: decodeCookieType(
|
962
|
+
sessionScores: decodeCookieType(parseCookieScores(sessionScores)),
|
963
|
+
scores: decodeCookieType(parseCookieScores(visitorScores)),
|
989
964
|
tests: parseCookieType(abTestData),
|
990
965
|
controlGroup: controlGroup === "1",
|
991
966
|
personalizeVariants: decodePersonalizeVariants(personalizeVariants)
|
992
967
|
};
|
993
968
|
return data;
|
994
969
|
}
|
970
|
+
function parseCookieScores(type) {
|
971
|
+
if (!type) {
|
972
|
+
return {};
|
973
|
+
}
|
974
|
+
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
975
|
+
return pairs.reduce((acc, cur) => {
|
976
|
+
if (cur.length < 2) return acc;
|
977
|
+
const key = cur.slice(0, -1).join(KV_SEP);
|
978
|
+
acc[key] = cur[cur.length - 1];
|
979
|
+
return acc;
|
980
|
+
}, {});
|
981
|
+
}
|
995
982
|
function parseCookieType(type) {
|
996
983
|
if (!type) {
|
997
984
|
return {};
|
998
985
|
}
|
999
986
|
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
1000
987
|
return pairs.reduce((acc, cur) => {
|
1001
|
-
if (cur.length < 2)
|
1002
|
-
return acc;
|
988
|
+
if (cur.length < 2) return acc;
|
1003
989
|
acc[cur[0]] = cur.slice(1).join("-");
|
1004
990
|
return acc;
|
1005
991
|
}, {});
|
@@ -1067,13 +1053,13 @@ function serializeCookieType(type) {
|
|
1067
1053
|
}
|
1068
1054
|
|
1069
1055
|
// src/storage/EdgeTransitionDataStore.ts
|
1070
|
-
var
|
1056
|
+
var _EdgeTransitionDataStore_instances, fetchData_fn;
|
1071
1057
|
var EdgeTransitionDataStore = class extends TransitionDataStore {
|
1072
1058
|
constructor({ serverCookieValue, visitorIdCookieName = "ufvi", ...base }) {
|
1073
1059
|
super(base);
|
1074
|
-
__privateAdd(this,
|
1060
|
+
__privateAdd(this, _EdgeTransitionDataStore_instances);
|
1075
1061
|
if (!base.initialData) {
|
1076
|
-
__privateMethod(this,
|
1062
|
+
__privateMethod(this, _EdgeTransitionDataStore_instances, fetchData_fn).call(this).catch((err) => {
|
1077
1063
|
console.error(err);
|
1078
1064
|
});
|
1079
1065
|
}
|
@@ -1092,7 +1078,7 @@ var EdgeTransitionDataStore = class extends TransitionDataStore {
|
|
1092
1078
|
}
|
1093
1079
|
}
|
1094
1080
|
};
|
1095
|
-
|
1081
|
+
_EdgeTransitionDataStore_instances = new WeakSet();
|
1096
1082
|
fetchData_fn = async function() {
|
1097
1083
|
const serviceData = await new Promise((resolve) => {
|
1098
1084
|
setTimeout(() => {
|
@@ -1149,13 +1135,13 @@ var emptyVisitorData = () => ({
|
|
1149
1135
|
});
|
1150
1136
|
|
1151
1137
|
// src/storage/VisitorDataStore.ts
|
1152
|
-
import { dequal as
|
1138
|
+
import { dequal as dequal4 } from "dequal/lite";
|
1153
1139
|
import mitt2 from "mitt";
|
1154
1140
|
|
1155
1141
|
// src/storage/util/applyCommandsToData.ts
|
1156
1142
|
import rfdc from "rfdc";
|
1157
1143
|
var clone = rfdc();
|
1158
|
-
function applyCommandsToData(commands, state
|
1144
|
+
function applyCommandsToData(commands, state) {
|
1159
1145
|
const newData = state ? clone(state) : emptyVisitorData();
|
1160
1146
|
commands.forEach((command) => {
|
1161
1147
|
var _a, _b, _c;
|
@@ -1170,8 +1156,6 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1170
1156
|
newData.tests[command.data.test] = command.data.variant;
|
1171
1157
|
break;
|
1172
1158
|
case "modscore":
|
1173
|
-
if (inControlGroup)
|
1174
|
-
break;
|
1175
1159
|
const delta = Number(command.data.delta);
|
1176
1160
|
if (isNaN(delta)) {
|
1177
1161
|
throw new Error("Non-number delta received");
|
@@ -1180,8 +1164,6 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1180
1164
|
newData.scores[command.data.dimension] = existing + delta;
|
1181
1165
|
break;
|
1182
1166
|
case "modscoreS":
|
1183
|
-
if (inControlGroup)
|
1184
|
-
break;
|
1185
1167
|
const deltaS = Number(command.data.delta);
|
1186
1168
|
if (isNaN(deltaS)) {
|
1187
1169
|
throw new Error("Non-number delta received");
|
@@ -1225,71 +1207,65 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1225
1207
|
}
|
1226
1208
|
|
1227
1209
|
// src/storage/util/LocalStorage.ts
|
1210
|
+
var _LocalStorage_instances, key_fn;
|
1228
1211
|
var LocalStorage = class {
|
1229
|
-
constructor() {
|
1212
|
+
constructor(partitionKey) {
|
1213
|
+
this.partitionKey = partitionKey;
|
1214
|
+
__privateAdd(this, _LocalStorage_instances);
|
1230
1215
|
__publicField(this, "inMemoryFallback", {});
|
1231
1216
|
__publicField(this, "hasLocalStorageObject", typeof localStorage !== "undefined");
|
1232
1217
|
}
|
1233
1218
|
get(key) {
|
1234
|
-
const
|
1219
|
+
const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
|
1220
|
+
const fallbackValue = this.inMemoryFallback[keyValue];
|
1235
1221
|
if (!this.hasLocalStorageObject || fallbackValue) {
|
1236
1222
|
return fallbackValue;
|
1237
1223
|
}
|
1238
1224
|
try {
|
1239
|
-
const value = localStorage.getItem(
|
1225
|
+
const value = localStorage.getItem(keyValue);
|
1240
1226
|
return value ? JSON.parse(value) : void 0;
|
1241
1227
|
} catch (e) {
|
1242
1228
|
return fallbackValue;
|
1243
1229
|
}
|
1244
1230
|
}
|
1245
1231
|
set(key, value, storageConsent) {
|
1246
|
-
this.
|
1232
|
+
const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
|
1233
|
+
this.inMemoryFallback[keyValue] = value;
|
1247
1234
|
if (!this.hasLocalStorageObject || !storageConsent) {
|
1248
1235
|
return;
|
1249
1236
|
}
|
1250
1237
|
try {
|
1251
|
-
localStorage.setItem(
|
1238
|
+
localStorage.setItem(keyValue, JSON.stringify(value));
|
1252
1239
|
} catch (e) {
|
1253
1240
|
console.warn(e);
|
1254
1241
|
}
|
1255
1242
|
}
|
1256
1243
|
delete(key, leaveInMemory) {
|
1244
|
+
const keyValue = __privateMethod(this, _LocalStorage_instances, key_fn).call(this, key);
|
1257
1245
|
if (!leaveInMemory) {
|
1258
|
-
delete this.inMemoryFallback[
|
1246
|
+
delete this.inMemoryFallback[keyValue];
|
1259
1247
|
}
|
1260
1248
|
try {
|
1261
|
-
localStorage.removeItem(
|
1249
|
+
localStorage.removeItem(keyValue);
|
1262
1250
|
} catch (e) {
|
1263
1251
|
}
|
1264
1252
|
}
|
1265
1253
|
};
|
1254
|
+
_LocalStorage_instances = new WeakSet();
|
1255
|
+
key_fn = function(key) {
|
1256
|
+
return this.partitionKey ? `${this.partitionKey}.${key}` : key;
|
1257
|
+
};
|
1266
1258
|
|
1267
1259
|
// src/storage/VisitorDataStore.ts
|
1268
1260
|
var STORAGE_KEY = "ufvisitor";
|
1269
|
-
var _mitt2, _persist, _visitTimeout, _options,
|
1261
|
+
var _mitt2, _persist, _visitTimeout, _options, _VisitorDataStore_instances, currentData_get, replaceData_fn, setVisitTimeout_fn, isExpired_fn, handleCaps_fn, defaultData_fn;
|
1270
1262
|
var VisitorDataStore = class {
|
1271
1263
|
constructor(options) {
|
1272
|
-
|
1273
|
-
__privateAdd(this, _currentData);
|
1274
|
-
/**
|
1275
|
-
* IMPORTANT: This function mutates the input data. This is done,
|
1276
|
-
* because all the sources that call it have either already spread or cloned
|
1277
|
-
* the data, so we can safely mutate it for better perf.
|
1278
|
-
*/
|
1279
|
-
__privateAdd(this, _replaceData);
|
1280
|
-
__privateAdd(this, _setVisitTimeout);
|
1281
|
-
__privateAdd(this, _isExpired);
|
1282
|
-
/**
|
1283
|
-
* IMPORTANT: This function mutates the input data. This is done,
|
1284
|
-
* because all the sources that call it have either already spread or cloned
|
1285
|
-
* the data, so we can safely mutate it for better perf.
|
1286
|
-
*/
|
1287
|
-
__privateAdd(this, _handleCaps);
|
1288
|
-
__privateAdd(this, _defaultData);
|
1264
|
+
__privateAdd(this, _VisitorDataStore_instances);
|
1289
1265
|
__privateAdd(this, _mitt2, mitt2());
|
1290
|
-
__privateAdd(this, _persist
|
1291
|
-
__privateAdd(this, _visitTimeout
|
1292
|
-
__privateAdd(this, _options
|
1266
|
+
__privateAdd(this, _persist);
|
1267
|
+
__privateAdd(this, _visitTimeout);
|
1268
|
+
__privateAdd(this, _options);
|
1293
1269
|
/**
|
1294
1270
|
* Subscribe to events from storage
|
1295
1271
|
*/
|
@@ -1298,8 +1274,9 @@ var VisitorDataStore = class {
|
|
1298
1274
|
off: __privateGet(this, _mitt2).off
|
1299
1275
|
});
|
1300
1276
|
__privateSet(this, _options, options);
|
1301
|
-
|
1302
|
-
|
1277
|
+
__privateSet(this, _persist, new LocalStorage(options.partitionKey));
|
1278
|
+
if (!__privateGet(this, _VisitorDataStore_instances, currentData_get)) {
|
1279
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this), true);
|
1303
1280
|
}
|
1304
1281
|
if (options.transitionStore) {
|
1305
1282
|
const serverToClientTransitionState = options.transitionStore.getClientTransitionState();
|
@@ -1307,17 +1284,17 @@ var VisitorDataStore = class {
|
|
1307
1284
|
options.onServerTransitionReceived(serverToClientTransitionState);
|
1308
1285
|
}
|
1309
1286
|
options.transitionStore.events.on("dataUpdatedAsync", (data) => {
|
1310
|
-
__privateMethod(this,
|
1311
|
-
...__privateGet(this,
|
1287
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, {
|
1288
|
+
...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData,
|
1312
1289
|
...data
|
1313
1290
|
});
|
1314
1291
|
});
|
1315
1292
|
const transitionData = options.transitionStore.data;
|
1316
1293
|
if (transitionData) {
|
1317
|
-
__privateMethod(this,
|
1294
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(
|
1318
1295
|
this,
|
1319
1296
|
// we know _currentData is not empty because we inited it above if it was
|
1320
|
-
{ ...__privateGet(this,
|
1297
|
+
{ ...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData, ...transitionData },
|
1321
1298
|
true
|
1322
1299
|
);
|
1323
1300
|
}
|
@@ -1325,13 +1302,13 @@ var VisitorDataStore = class {
|
|
1325
1302
|
}
|
1326
1303
|
/** Gets the current visitor data. This property is always up to date. */
|
1327
1304
|
get data() {
|
1328
|
-
var _a, _b;
|
1329
|
-
const data = __privateGet(this,
|
1330
|
-
if (__privateMethod(this,
|
1305
|
+
var _a, _b, _c;
|
1306
|
+
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() };
|
1307
|
+
if (__privateMethod(this, _VisitorDataStore_instances, isExpired_fn).call(this, data)) {
|
1331
1308
|
const { sessionScores, ...newData } = data.visitorData;
|
1332
|
-
__privateMethod(this,
|
1333
|
-
(
|
1334
|
-
return __privateGet(this,
|
1309
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, { ...newData, sessionScores: {} });
|
1310
|
+
(_c = (_b = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _c.call(_b, ["info", 120]);
|
1311
|
+
return __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData;
|
1335
1312
|
}
|
1336
1313
|
return data.visitorData;
|
1337
1314
|
}
|
@@ -1343,17 +1320,18 @@ var VisitorDataStore = class {
|
|
1343
1320
|
}
|
1344
1321
|
/** Push data update command(s) into the visitor data */
|
1345
1322
|
async updateData(commands) {
|
1346
|
-
var _a, _b, _c
|
1323
|
+
var _a, _b, _c;
|
1347
1324
|
if (commands.length === 0) {
|
1348
1325
|
return;
|
1349
1326
|
}
|
1350
1327
|
(_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 101, commands]);
|
1351
|
-
const newData = applyCommandsToData(commands, this.data
|
1328
|
+
const newData = applyCommandsToData(commands, this.data);
|
1352
1329
|
if (commands.some((c) => c.type === "consent" && !c.data)) {
|
1353
1330
|
__privateGet(this, _persist).delete(STORAGE_KEY, true);
|
1354
1331
|
}
|
1355
|
-
__privateMethod(this,
|
1356
|
-
await ((
|
1332
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, newData);
|
1333
|
+
await ((_c = __privateGet(this, _options).transitionStore) == null ? void 0 : _c.updateData(commands, __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData));
|
1334
|
+
__privateGet(this, _mitt2).emit("commandsExecuted", commands);
|
1357
1335
|
}
|
1358
1336
|
/**
|
1359
1337
|
* Deletes visitor data (forgetting them)
|
@@ -1366,7 +1344,7 @@ var VisitorDataStore = class {
|
|
1366
1344
|
try {
|
1367
1345
|
__privateGet(this, _persist).delete(STORAGE_KEY, false);
|
1368
1346
|
await ((_c = __privateGet(this, _options).transitionStore) == null ? void 0 : _c.delete(fromAllDevices));
|
1369
|
-
__privateMethod(this,
|
1347
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this));
|
1370
1348
|
} finally {
|
1371
1349
|
(_e = (_d = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _e.call(_d, ["info", 103, "ENDGROUP"]);
|
1372
1350
|
}
|
@@ -1376,39 +1354,38 @@ _mitt2 = new WeakMap();
|
|
1376
1354
|
_persist = new WeakMap();
|
1377
1355
|
_visitTimeout = new WeakMap();
|
1378
1356
|
_options = new WeakMap();
|
1379
|
-
|
1357
|
+
_VisitorDataStore_instances = new WeakSet();
|
1380
1358
|
currentData_get = function() {
|
1381
1359
|
return __privateGet(this, _persist).get(STORAGE_KEY);
|
1382
1360
|
};
|
1383
|
-
|
1361
|
+
/**
|
1362
|
+
* IMPORTANT: This function mutates the input data. This is done,
|
1363
|
+
* because all the sources that call it have either already spread or cloned
|
1364
|
+
* the data, so we can safely mutate it for better perf.
|
1365
|
+
*/
|
1384
1366
|
replaceData_fn = function(data, quiet = false) {
|
1385
1367
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
1386
|
-
const oldData = __privateGet(this,
|
1368
|
+
const oldData = __privateGet(this, _VisitorDataStore_instances, currentData_get);
|
1387
1369
|
const now = Date.now();
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
const haveScoresChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
1403
|
-
const haveSessionScoresChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1404
|
-
const haveQuirksChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1405
|
-
const haveTestsChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1406
|
-
const haveGoalsChanged = !dequal3(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1370
|
+
__privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.scores);
|
1371
|
+
__privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.sessionScores);
|
1372
|
+
(_b = (_a = __privateGet(this, _options)).decay) == null ? void 0 : _b.call(_a, {
|
1373
|
+
now,
|
1374
|
+
lastUpd: oldData == null ? void 0 : oldData.updated,
|
1375
|
+
scores: data.scores,
|
1376
|
+
sessionScores: data.sessionScores,
|
1377
|
+
onLogMessage: __privateGet(this, _options).onLogMessage
|
1378
|
+
});
|
1379
|
+
const haveScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
1380
|
+
const haveSessionScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1381
|
+
const haveQuirksChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1382
|
+
const haveTestsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1383
|
+
const haveGoalsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1407
1384
|
const updatedData = {
|
1408
1385
|
updated: now,
|
1409
1386
|
visitorData: data
|
1410
1387
|
};
|
1411
|
-
__privateMethod(this,
|
1388
|
+
__privateMethod(this, _VisitorDataStore_instances, setVisitTimeout_fn).call(this);
|
1412
1389
|
__privateGet(this, _persist).set(STORAGE_KEY, updatedData, !!data.consent);
|
1413
1390
|
(_d = (_c = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _d.call(_c, ["debug", 102, data]);
|
1414
1391
|
if (!quiet) {
|
@@ -1439,7 +1416,6 @@ replaceData_fn = function(data, quiet = false) {
|
|
1439
1416
|
}
|
1440
1417
|
}
|
1441
1418
|
};
|
1442
|
-
_setVisitTimeout = new WeakSet();
|
1443
1419
|
setVisitTimeout_fn = function() {
|
1444
1420
|
if (typeof document === "undefined" || !__privateGet(this, _options).visitLifespan) {
|
1445
1421
|
return;
|
@@ -1451,12 +1427,15 @@ setVisitTimeout_fn = function() {
|
|
1451
1427
|
this.data;
|
1452
1428
|
}, __privateGet(this, _options).visitLifespan + 50));
|
1453
1429
|
};
|
1454
|
-
_isExpired = new WeakSet();
|
1455
1430
|
isExpired_fn = function(data) {
|
1456
1431
|
const expires = __privateGet(this, _options).visitLifespan;
|
1457
1432
|
return expires ? data.updated + expires < Date.now() : false;
|
1458
1433
|
};
|
1459
|
-
|
1434
|
+
/**
|
1435
|
+
* IMPORTANT: This function mutates the input data. This is done,
|
1436
|
+
* because all the sources that call it have either already spread or cloned
|
1437
|
+
* the data, so we can safely mutate it for better perf.
|
1438
|
+
*/
|
1460
1439
|
handleCaps_fn = function(scores) {
|
1461
1440
|
var _a, _b;
|
1462
1441
|
if (!__privateGet(this, _options).manifest) {
|
@@ -1474,7 +1453,6 @@ handleCaps_fn = function(scores) {
|
|
1474
1453
|
}
|
1475
1454
|
}
|
1476
1455
|
};
|
1477
|
-
_defaultData = new WeakSet();
|
1478
1456
|
defaultData_fn = function() {
|
1479
1457
|
var _a, _b, _c;
|
1480
1458
|
return {
|
@@ -1485,23 +1463,21 @@ defaultData_fn = function() {
|
|
1485
1463
|
};
|
1486
1464
|
|
1487
1465
|
// src/Context.ts
|
1488
|
-
import { dequal as
|
1466
|
+
import { dequal as dequal5 } from "dequal/lite";
|
1489
1467
|
import mitt3 from "mitt";
|
1490
1468
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1491
1469
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1492
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3,
|
1470
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1493
1471
|
var Context = class {
|
1494
1472
|
constructor(options) {
|
1495
|
-
__privateAdd(this,
|
1496
|
-
__privateAdd(this, _updateGoals);
|
1497
|
-
__privateAdd(this, _updateComputedScores);
|
1498
|
-
__privateAdd(this, _calculateScores);
|
1473
|
+
__privateAdd(this, _Context_instances);
|
1499
1474
|
__publicField(this, "manifest");
|
1500
|
-
__privateAdd(this, _serverTransitionState
|
1475
|
+
__privateAdd(this, _serverTransitionState);
|
1501
1476
|
__privateAdd(this, _scores, {});
|
1502
|
-
__privateAdd(this, _state
|
1477
|
+
__privateAdd(this, _state);
|
1503
1478
|
__privateAdd(this, _pzCache, {});
|
1504
|
-
__privateAdd(this, _plugins
|
1479
|
+
__privateAdd(this, _plugins);
|
1480
|
+
__privateAdd(this, _commands);
|
1505
1481
|
__privateAdd(this, _mitt3, mitt3());
|
1506
1482
|
/**
|
1507
1483
|
* Subscribe to events
|
@@ -1515,6 +1491,9 @@ var Context = class {
|
|
1515
1491
|
const { manifest, ...storageOptions } = options;
|
1516
1492
|
__privateSet(this, _state, {});
|
1517
1493
|
__privateSet(this, _plugins, options.plugins);
|
1494
|
+
if (typeof options.transitionStore !== "undefined") {
|
1495
|
+
__privateSet(this, _commands, []);
|
1496
|
+
}
|
1518
1497
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1519
1498
|
if (!plugin.logDrain) {
|
1520
1499
|
return;
|
@@ -1547,9 +1526,9 @@ var Context = class {
|
|
1547
1526
|
},
|
1548
1527
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1549
1528
|
});
|
1550
|
-
this.storage.events.on("scoresUpdated", __privateMethod(this,
|
1529
|
+
this.storage.events.on("scoresUpdated", __privateMethod(this, _Context_instances, updateComputedScores_fn).bind(this));
|
1551
1530
|
if (!__privateGet(this, _serverTransitionState)) {
|
1552
|
-
__privateMethod(this,
|
1531
|
+
__privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
1553
1532
|
}
|
1554
1533
|
this.storage.events.on("quirksUpdated", (quirks) => {
|
1555
1534
|
const updates = this.manifest.computeSignals({
|
@@ -1558,7 +1537,7 @@ var Context = class {
|
|
1558
1537
|
previousState: __privateGet(this, _state),
|
1559
1538
|
visitor: this.storage.data
|
1560
1539
|
});
|
1561
|
-
__privateMethod(this,
|
1540
|
+
__privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
|
1562
1541
|
quirks: quirks.quirks,
|
1563
1542
|
scores: void 0
|
1564
1543
|
});
|
@@ -1575,6 +1554,9 @@ var Context = class {
|
|
1575
1554
|
} finally {
|
1576
1555
|
__privateGet(this, _mitt3).emit("log", ["info", 1, "ENDGROUP"]);
|
1577
1556
|
}
|
1557
|
+
if (typeof window !== "undefined") {
|
1558
|
+
window.__UNIFORM_CONTEXTUAL_EDITING_CONTEXT__ = this;
|
1559
|
+
}
|
1578
1560
|
}
|
1579
1561
|
/** Gets the current visitor's dimension score vector. */
|
1580
1562
|
get scores() {
|
@@ -1595,7 +1577,7 @@ var Context = class {
|
|
1595
1577
|
* will NOT result in a recomputation of signal state.
|
1596
1578
|
*/
|
1597
1579
|
async update(newData) {
|
1598
|
-
var _a, _b, _c, _d;
|
1580
|
+
var _a, _b, _c, _d, _e;
|
1599
1581
|
const commands = [];
|
1600
1582
|
const newServerSideTests = {};
|
1601
1583
|
if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
@@ -1681,7 +1663,7 @@ var Context = class {
|
|
1681
1663
|
// re-compute using scores from storage instead of the current scores since
|
1682
1664
|
// server transition scores might have adjusted values already integrated into them,
|
1683
1665
|
// which causes issues when you are near limits.
|
1684
|
-
scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this,
|
1666
|
+
scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
|
1685
1667
|
})
|
1686
1668
|
);
|
1687
1669
|
__privateSet(this, _state, {
|
@@ -1690,9 +1672,13 @@ var Context = class {
|
|
1690
1672
|
});
|
1691
1673
|
await this.storage.updateData(commands);
|
1692
1674
|
if (__privateGet(this, _serverTransitionState)) {
|
1693
|
-
|
1675
|
+
await this.processServerCommands({
|
1676
|
+
serverCommands: __privateGet(this, _serverTransitionState).commands,
|
1677
|
+
commands
|
1678
|
+
});
|
1679
|
+
__privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
1694
1680
|
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
1695
|
-
__privateMethod(this,
|
1681
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
1696
1682
|
name: testName,
|
1697
1683
|
variantId: testVariantId,
|
1698
1684
|
variantAssigned: true
|
@@ -1710,10 +1696,31 @@ var Context = class {
|
|
1710
1696
|
await plugin.update(newData);
|
1711
1697
|
}
|
1712
1698
|
}
|
1699
|
+
(_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
|
1713
1700
|
} finally {
|
1714
1701
|
__privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
1715
1702
|
}
|
1716
1703
|
}
|
1704
|
+
async processServerCommands({
|
1705
|
+
serverCommands,
|
1706
|
+
commands
|
1707
|
+
}) {
|
1708
|
+
if (!(serverCommands == null ? void 0 : serverCommands.length)) {
|
1709
|
+
return;
|
1710
|
+
}
|
1711
|
+
const notExecutedCommands = [];
|
1712
|
+
serverCommands.forEach((serverCommand) => {
|
1713
|
+
const found = commands.find((command) => {
|
1714
|
+
return areCommandsEqual(command, serverCommand);
|
1715
|
+
});
|
1716
|
+
if (!found) {
|
1717
|
+
notExecutedCommands.push(serverCommand);
|
1718
|
+
}
|
1719
|
+
});
|
1720
|
+
if (notExecutedCommands.length > 0) {
|
1721
|
+
await this.storage.updateData(notExecutedCommands);
|
1722
|
+
}
|
1723
|
+
}
|
1717
1724
|
/** use test() instead */
|
1718
1725
|
getTestVariantId(testName) {
|
1719
1726
|
var _a, _b, _c, _d;
|
@@ -1768,7 +1775,7 @@ var Context = class {
|
|
1768
1775
|
context: this,
|
1769
1776
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1770
1777
|
});
|
1771
|
-
__privateMethod(this,
|
1778
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
1772
1779
|
name: options.name,
|
1773
1780
|
variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
|
1774
1781
|
variantAssigned: value.variantAssigned
|
@@ -1792,7 +1799,7 @@ var Context = class {
|
|
1792
1799
|
control: this.storage.data.controlGroup,
|
1793
1800
|
changed: true
|
1794
1801
|
};
|
1795
|
-
if (previousPlacement &&
|
1802
|
+
if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
|
1796
1803
|
eventData.changed = false;
|
1797
1804
|
}
|
1798
1805
|
__privateGet(this, _mitt3).emit("personalizationResult", eventData);
|
@@ -1826,7 +1833,8 @@ var Context = class {
|
|
1826
1833
|
quirks: this.storage.data.quirks,
|
1827
1834
|
ssv: __privateGet(this, _scores),
|
1828
1835
|
tests: {},
|
1829
|
-
personalizeVariants: this.storage.data.personalizeVariants
|
1836
|
+
personalizeVariants: this.storage.data.personalizeVariants,
|
1837
|
+
commands: __privateGet(this, _commands)
|
1830
1838
|
};
|
1831
1839
|
const allTests = this.storage.data.tests;
|
1832
1840
|
Object.entries(allTests).map(([testName, testValue]) => {
|
@@ -1841,7 +1849,7 @@ var Context = class {
|
|
1841
1849
|
internal_processTestEvent(event) {
|
1842
1850
|
if (event.variantId) {
|
1843
1851
|
this.setTestVariantId(event.name, event.variantId);
|
1844
|
-
__privateMethod(this,
|
1852
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, event);
|
1845
1853
|
}
|
1846
1854
|
}
|
1847
1855
|
/** @deprecated */
|
@@ -1855,25 +1863,24 @@ _scores = new WeakMap();
|
|
1855
1863
|
_state = new WeakMap();
|
1856
1864
|
_pzCache = new WeakMap();
|
1857
1865
|
_plugins = new WeakMap();
|
1866
|
+
_commands = new WeakMap();
|
1858
1867
|
_mitt3 = new WeakMap();
|
1859
|
-
|
1868
|
+
_Context_instances = new WeakSet();
|
1860
1869
|
emitTest_fn = function(event) {
|
1861
1870
|
__privateGet(this, _mitt3).emit("testResult", event);
|
1862
1871
|
};
|
1863
|
-
_updateGoals = new WeakSet();
|
1864
1872
|
updateGoals_fn = async function(data) {
|
1865
1873
|
const goalCommands = this.manifest.computeGoals(data);
|
1866
1874
|
if (goalCommands.length !== 0) {
|
1867
1875
|
await this.storage.updateData(goalCommands);
|
1868
1876
|
}
|
1869
1877
|
};
|
1870
|
-
_updateComputedScores = new WeakSet();
|
1871
1878
|
updateComputedScores_fn = function(newData) {
|
1872
|
-
const newScores = __privateMethod(this,
|
1873
|
-
const newScoresHaveChanged = !
|
1879
|
+
const newScores = __privateMethod(this, _Context_instances, calculateScores_fn).call(this, newData);
|
1880
|
+
const newScoresHaveChanged = !dequal5(newScores, __privateGet(this, _scores));
|
1874
1881
|
if (newScoresHaveChanged) {
|
1875
1882
|
__privateSet(this, _scores, newScores);
|
1876
|
-
__privateMethod(this,
|
1883
|
+
__privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
|
1877
1884
|
scores: __privateGet(this, _scores),
|
1878
1885
|
quirks: void 0
|
1879
1886
|
});
|
@@ -1881,7 +1888,6 @@ updateComputedScores_fn = function(newData) {
|
|
1881
1888
|
__privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
|
1882
1889
|
}
|
1883
1890
|
};
|
1884
|
-
_calculateScores = new WeakSet();
|
1885
1891
|
calculateScores_fn = function(newData) {
|
1886
1892
|
var _a;
|
1887
1893
|
let newScores = { ...newData.scores };
|
@@ -1930,13 +1936,11 @@ function enableContextDevTools(options) {
|
|
1930
1936
|
);
|
1931
1937
|
};
|
1932
1938
|
const onPersonalizationResult = (e) => {
|
1933
|
-
if (!e.changed)
|
1934
|
-
return;
|
1939
|
+
if (!e.changed) return;
|
1935
1940
|
personalizations.push(e);
|
1936
1941
|
};
|
1937
1942
|
const onTestResult = (e) => {
|
1938
|
-
if (!e.variantAssigned)
|
1939
|
-
return;
|
1943
|
+
if (!e.variantAssigned) return;
|
1940
1944
|
tests.push(e);
|
1941
1945
|
};
|
1942
1946
|
if (isBrowser) {
|
@@ -2030,10 +2034,16 @@ var getBasePayload = () => {
|
|
2030
2034
|
};
|
2031
2035
|
};
|
2032
2036
|
var createInsightsClient = ({ endpoint }) => {
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
+
let endpointUrl;
|
2038
|
+
const apiKey = endpoint.apiKey;
|
2039
|
+
if (endpoint.type === "api") {
|
2040
|
+
const url = new URL(endpoint.host);
|
2041
|
+
url.pathname = "/v0/events";
|
2042
|
+
url.searchParams.set("name", "analytics_events");
|
2043
|
+
endpointUrl = url.toString();
|
2044
|
+
} else {
|
2045
|
+
endpointUrl = endpoint.path;
|
2046
|
+
}
|
2037
2047
|
const sendMessage = async (message) => {
|
2038
2048
|
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2039
2049
|
return;
|
@@ -2042,12 +2052,15 @@ var createInsightsClient = ({ endpoint }) => {
|
|
2042
2052
|
...message,
|
2043
2053
|
payload: JSON.stringify(message.payload)
|
2044
2054
|
};
|
2055
|
+
const headers = {
|
2056
|
+
"Content-Type": "application/json"
|
2057
|
+
};
|
2058
|
+
if (apiKey) {
|
2059
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
2060
|
+
}
|
2045
2061
|
const response = await fetch(endpointUrl, {
|
2046
2062
|
method: "POST",
|
2047
|
-
headers
|
2048
|
-
"Content-Type": "application/json",
|
2049
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2050
|
-
},
|
2063
|
+
headers,
|
2051
2064
|
body: JSON.stringify(converted)
|
2052
2065
|
});
|
2053
2066
|
const json = await response.json();
|
@@ -2215,7 +2228,6 @@ var createInsights = ({
|
|
2215
2228
|
},
|
2216
2229
|
pageHit: () => {
|
2217
2230
|
if (!storageData) {
|
2218
|
-
console.error("Insights not initialized");
|
2219
2231
|
return;
|
2220
2232
|
}
|
2221
2233
|
if (previousUrl === window.location.href) {
|
@@ -2243,7 +2255,6 @@ var createInsights = ({
|
|
2243
2255
|
},
|
2244
2256
|
personalizationResult: (result) => {
|
2245
2257
|
if (!storageData) {
|
2246
|
-
console.error("Insights not initialized");
|
2247
2258
|
return;
|
2248
2259
|
}
|
2249
2260
|
client.personalizationResult({
|
@@ -2255,7 +2266,6 @@ var createInsights = ({
|
|
2255
2266
|
},
|
2256
2267
|
goalConvert: (goalId) => {
|
2257
2268
|
if (!storageData) {
|
2258
|
-
console.error("Insights not initialized");
|
2259
2269
|
return;
|
2260
2270
|
}
|
2261
2271
|
client.goalConvert({
|
@@ -2267,7 +2277,6 @@ var createInsights = ({
|
|
2267
2277
|
},
|
2268
2278
|
scoresChange: (scores) => {
|
2269
2279
|
if (!storageData) {
|
2270
|
-
console.error("Insights not initialized");
|
2271
2280
|
return;
|
2272
2281
|
}
|
2273
2282
|
client.scoresChange({
|
@@ -2535,23 +2544,30 @@ export {
|
|
2535
2544
|
EdgeNodeTagName,
|
2536
2545
|
EdgeTransitionDataStore,
|
2537
2546
|
GroupCriteriaEvaluator,
|
2547
|
+
KV_SEP,
|
2538
2548
|
ManifestInstance,
|
2549
|
+
PAIR_SEP,
|
2539
2550
|
SERVER_STATE_ID,
|
2540
2551
|
ScriptType,
|
2552
|
+
TYPE_SEP,
|
2541
2553
|
TransitionDataStore,
|
2542
2554
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
2543
2555
|
VisitorDataStore,
|
2556
|
+
areCommandsEqual,
|
2544
2557
|
computeAggregateDimensions,
|
2545
2558
|
cookieEvaluator,
|
2546
2559
|
createConsoleLogDrain,
|
2547
2560
|
createDebugConsoleLogDrain,
|
2548
2561
|
createLinearDecay,
|
2549
2562
|
currentPageEvaluator,
|
2563
|
+
decodeCookieType,
|
2564
|
+
decodePersonalizeVariants,
|
2550
2565
|
emptyVisitorData,
|
2551
2566
|
enableConsoleLogDrain,
|
2552
2567
|
enableContextDevTools,
|
2553
2568
|
enableDebugConsoleLogDrain,
|
2554
2569
|
enableUniformInsights,
|
2570
|
+
encodeCookieType,
|
2555
2571
|
evaluateVariantMatch,
|
2556
2572
|
eventEvaluator,
|
2557
2573
|
explainStringMatch,
|
@@ -2560,10 +2576,16 @@ export {
|
|
2560
2576
|
isStringMatch,
|
2561
2577
|
pageViewCountDimension,
|
2562
2578
|
pageViewCountEvaluator,
|
2579
|
+
parseCookieScores,
|
2580
|
+
parseCookieType,
|
2563
2581
|
parseQuickConnect,
|
2582
|
+
parseScoreCookie,
|
2564
2583
|
personalizeVariations,
|
2565
2584
|
queryStringEvaluator,
|
2566
2585
|
quirkEvaluator,
|
2586
|
+
serializeCookie,
|
2587
|
+
serializeCookieType,
|
2588
|
+
serializePersonalizeVariants,
|
2567
2589
|
serializeQuickConnect,
|
2568
2590
|
testVariations
|
2569
2591
|
};
|