@uniformdev/context 19.159.0 → 19.159.1-alpha.27
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.js +8 -19
- package/dist/api/api.mjs +8 -19
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +102 -137
- package/dist/index.js +102 -137
- package/dist/index.mjs +102 -137
- package/package.json +2 -2
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
var
|
35
|
-
|
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 = {};
|
@@ -152,8 +135,8 @@ var ENR_SEPARATOR = "_";
|
|
152
135
|
var _signal, _id;
|
153
136
|
var SignalGoalEvaluator = class {
|
154
137
|
constructor(options) {
|
155
|
-
__privateAdd(this, _signal
|
156
|
-
__privateAdd(this, _id
|
138
|
+
__privateAdd(this, _signal);
|
139
|
+
__privateAdd(this, _id);
|
157
140
|
__privateSet(this, _id, options.id);
|
158
141
|
__privateSet(this, _signal, options.signal);
|
159
142
|
}
|
@@ -177,8 +160,8 @@ _id = new WeakMap();
|
|
177
160
|
var _evaluator, _onLogMessage;
|
178
161
|
var SignalInstance = class {
|
179
162
|
constructor(data, evaluator, onLogMessage) {
|
180
|
-
__privateAdd(this, _evaluator
|
181
|
-
__privateAdd(this, _onLogMessage
|
163
|
+
__privateAdd(this, _evaluator);
|
164
|
+
__privateAdd(this, _onLogMessage);
|
182
165
|
__publicField(this, "signal");
|
183
166
|
this.signal = data;
|
184
167
|
__privateSet(this, _evaluator, evaluator);
|
@@ -240,10 +223,10 @@ var ManifestInstance = class {
|
|
240
223
|
}
|
241
224
|
}) {
|
242
225
|
__publicField(this, "data");
|
243
|
-
__privateAdd(this, _mf
|
244
|
-
__privateAdd(this, _signalInstances
|
226
|
+
__privateAdd(this, _mf);
|
227
|
+
__privateAdd(this, _signalInstances);
|
245
228
|
__privateAdd(this, _goalEvaluators, []);
|
246
|
-
__privateAdd(this, _onLogMessage2
|
229
|
+
__privateAdd(this, _onLogMessage2);
|
247
230
|
var _a, _b, _c, _d, _e;
|
248
231
|
__privateSet(this, _mf, (_a = manifest.project) != null ? _a : {});
|
249
232
|
this.data = manifest;
|
@@ -560,7 +543,7 @@ var quirkEvaluator = ({ update, criteria, signal, onLogMessage }) => {
|
|
560
543
|
var _evaluators;
|
561
544
|
var GroupCriteriaEvaluator = class {
|
562
545
|
constructor(criteriaEvaluators) {
|
563
|
-
__privateAdd(this, _evaluators
|
546
|
+
__privateAdd(this, _evaluators);
|
564
547
|
__privateSet(this, _evaluators, criteriaEvaluators);
|
565
548
|
}
|
566
549
|
evaluate(update, crit, commands, signal, onLogMessage) {
|
@@ -917,8 +900,8 @@ var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
|
917
900
|
var _data, _initialData, _mitt;
|
918
901
|
var TransitionDataStore = class {
|
919
902
|
constructor({ initialData }) {
|
920
|
-
__privateAdd(this, _data
|
921
|
-
__privateAdd(this, _initialData
|
903
|
+
__privateAdd(this, _data);
|
904
|
+
__privateAdd(this, _initialData);
|
922
905
|
__privateAdd(this, _mitt, (0, import_mitt.default)());
|
923
906
|
/**
|
924
907
|
* Subscribe to events from the transition storage
|
@@ -989,8 +972,7 @@ for (let i = 0; i < alphabet.length; i++) {
|
|
989
972
|
s2b[alphabet.charCodeAt(i)] = i;
|
990
973
|
}
|
991
974
|
var ntob = (number) => {
|
992
|
-
if (number < 0)
|
993
|
-
return `-${ntob(-number)}`;
|
975
|
+
if (number < 0) return `-${ntob(-number)}`;
|
994
976
|
let lo = number >>> 0;
|
995
977
|
let hi = number / 4294967296 >>> 0;
|
996
978
|
let right = "";
|
@@ -1029,20 +1011,18 @@ var CookieTransitionDataStore = class extends TransitionDataStore {
|
|
1029
1011
|
super({
|
1030
1012
|
initialData: ssr ? parseScoreCookie(serverCookieValue) : void 0
|
1031
1013
|
});
|
1032
|
-
__privateAdd(this, _cookieName
|
1033
|
-
__privateAdd(this, _cookieAttributes
|
1014
|
+
__privateAdd(this, _cookieName);
|
1015
|
+
__privateAdd(this, _cookieAttributes);
|
1034
1016
|
__privateSet(this, _cookieName, cookieName);
|
1035
1017
|
__privateSet(this, _cookieAttributes, cookieAttributes);
|
1036
1018
|
}
|
1037
1019
|
handleDelete() {
|
1038
|
-
if (ssr)
|
1039
|
-
return Promise.resolve();
|
1020
|
+
if (ssr) return Promise.resolve();
|
1040
1021
|
import_js_cookie.default.remove(__privateGet(this, _cookieName));
|
1041
1022
|
return Promise.resolve();
|
1042
1023
|
}
|
1043
1024
|
async handleUpdateData(_, computedValue) {
|
1044
|
-
if (ssr)
|
1045
|
-
return;
|
1025
|
+
if (ssr) return;
|
1046
1026
|
if (computedValue.consent) {
|
1047
1027
|
import_js_cookie.default.set(__privateGet(this, _cookieName), serializeCookie(computedValue), __privateGet(this, _cookieAttributes));
|
1048
1028
|
} else {
|
@@ -1056,11 +1036,9 @@ var TYPE_SEP = "~";
|
|
1056
1036
|
var PAIR_SEP = "!";
|
1057
1037
|
var KV_SEP = "-";
|
1058
1038
|
function parseScoreCookie(cookieValue) {
|
1059
|
-
if (!cookieValue)
|
1060
|
-
return;
|
1039
|
+
if (!cookieValue) return;
|
1061
1040
|
const types = cookieValue.split(TYPE_SEP);
|
1062
|
-
if (types.length > 5)
|
1063
|
-
return;
|
1041
|
+
if (types.length > 5) return;
|
1064
1042
|
const [abTestData, sessionScores, visitorScores, controlGroup, personalizeVariants] = types;
|
1065
1043
|
const data = {
|
1066
1044
|
// this is true since we're reading a cookie, which wouldn't exist if consent wasn't given
|
@@ -1079,8 +1057,7 @@ function parseCookieType(type) {
|
|
1079
1057
|
}
|
1080
1058
|
const pairs = type.split(PAIR_SEP).map((pair) => pair.split(KV_SEP));
|
1081
1059
|
return pairs.reduce((acc, cur) => {
|
1082
|
-
if (cur.length < 2)
|
1083
|
-
return acc;
|
1060
|
+
if (cur.length < 2) return acc;
|
1084
1061
|
acc[cur[0]] = cur.slice(1).join("-");
|
1085
1062
|
return acc;
|
1086
1063
|
}, {});
|
@@ -1148,13 +1125,13 @@ function serializeCookieType(type) {
|
|
1148
1125
|
}
|
1149
1126
|
|
1150
1127
|
// src/storage/EdgeTransitionDataStore.ts
|
1151
|
-
var
|
1128
|
+
var _EdgeTransitionDataStore_instances, fetchData_fn;
|
1152
1129
|
var EdgeTransitionDataStore = class extends TransitionDataStore {
|
1153
1130
|
constructor({ serverCookieValue, visitorIdCookieName = "ufvi", ...base }) {
|
1154
1131
|
super(base);
|
1155
|
-
__privateAdd(this,
|
1132
|
+
__privateAdd(this, _EdgeTransitionDataStore_instances);
|
1156
1133
|
if (!base.initialData) {
|
1157
|
-
__privateMethod(this,
|
1134
|
+
__privateMethod(this, _EdgeTransitionDataStore_instances, fetchData_fn).call(this).catch((err) => {
|
1158
1135
|
console.error(err);
|
1159
1136
|
});
|
1160
1137
|
}
|
@@ -1173,7 +1150,7 @@ var EdgeTransitionDataStore = class extends TransitionDataStore {
|
|
1173
1150
|
}
|
1174
1151
|
}
|
1175
1152
|
};
|
1176
|
-
|
1153
|
+
_EdgeTransitionDataStore_instances = new WeakSet();
|
1177
1154
|
fetchData_fn = async function() {
|
1178
1155
|
const serviceData = await new Promise((resolve) => {
|
1179
1156
|
setTimeout(() => {
|
@@ -1251,8 +1228,7 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1251
1228
|
newData.tests[command.data.test] = command.data.variant;
|
1252
1229
|
break;
|
1253
1230
|
case "modscore":
|
1254
|
-
if (inControlGroup)
|
1255
|
-
break;
|
1231
|
+
if (inControlGroup) break;
|
1256
1232
|
const delta = Number(command.data.delta);
|
1257
1233
|
if (isNaN(delta)) {
|
1258
1234
|
throw new Error("Non-number delta received");
|
@@ -1261,8 +1237,7 @@ function applyCommandsToData(commands, state, inControlGroup) {
|
|
1261
1237
|
newData.scores[command.data.dimension] = existing + delta;
|
1262
1238
|
break;
|
1263
1239
|
case "modscoreS":
|
1264
|
-
if (inControlGroup)
|
1265
|
-
break;
|
1240
|
+
if (inControlGroup) break;
|
1266
1241
|
const deltaS = Number(command.data.delta);
|
1267
1242
|
if (isNaN(deltaS)) {
|
1268
1243
|
throw new Error("Non-number delta received");
|
@@ -1347,30 +1322,14 @@ var LocalStorage = class {
|
|
1347
1322
|
|
1348
1323
|
// src/storage/VisitorDataStore.ts
|
1349
1324
|
var STORAGE_KEY = "ufvisitor";
|
1350
|
-
var _mitt2, _persist, _visitTimeout, _options,
|
1325
|
+
var _mitt2, _persist, _visitTimeout, _options, _VisitorDataStore_instances, currentData_get, replaceData_fn, setVisitTimeout_fn, isExpired_fn, handleCaps_fn, defaultData_fn;
|
1351
1326
|
var VisitorDataStore = class {
|
1352
1327
|
constructor(options) {
|
1353
|
-
|
1354
|
-
__privateAdd(this, _currentData);
|
1355
|
-
/**
|
1356
|
-
* IMPORTANT: This function mutates the input data. This is done,
|
1357
|
-
* because all the sources that call it have either already spread or cloned
|
1358
|
-
* the data, so we can safely mutate it for better perf.
|
1359
|
-
*/
|
1360
|
-
__privateAdd(this, _replaceData);
|
1361
|
-
__privateAdd(this, _setVisitTimeout);
|
1362
|
-
__privateAdd(this, _isExpired);
|
1363
|
-
/**
|
1364
|
-
* IMPORTANT: This function mutates the input data. This is done,
|
1365
|
-
* because all the sources that call it have either already spread or cloned
|
1366
|
-
* the data, so we can safely mutate it for better perf.
|
1367
|
-
*/
|
1368
|
-
__privateAdd(this, _handleCaps);
|
1369
|
-
__privateAdd(this, _defaultData);
|
1328
|
+
__privateAdd(this, _VisitorDataStore_instances);
|
1370
1329
|
__privateAdd(this, _mitt2, (0, import_mitt2.default)());
|
1371
1330
|
__privateAdd(this, _persist, new LocalStorage());
|
1372
|
-
__privateAdd(this, _visitTimeout
|
1373
|
-
__privateAdd(this, _options
|
1331
|
+
__privateAdd(this, _visitTimeout);
|
1332
|
+
__privateAdd(this, _options);
|
1374
1333
|
/**
|
1375
1334
|
* Subscribe to events from storage
|
1376
1335
|
*/
|
@@ -1379,8 +1338,8 @@ var VisitorDataStore = class {
|
|
1379
1338
|
off: __privateGet(this, _mitt2).off
|
1380
1339
|
});
|
1381
1340
|
__privateSet(this, _options, options);
|
1382
|
-
if (!__privateGet(this,
|
1383
|
-
__privateMethod(this,
|
1341
|
+
if (!__privateGet(this, _VisitorDataStore_instances, currentData_get)) {
|
1342
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this), true);
|
1384
1343
|
}
|
1385
1344
|
if (options.transitionStore) {
|
1386
1345
|
const serverToClientTransitionState = options.transitionStore.getClientTransitionState();
|
@@ -1388,17 +1347,17 @@ var VisitorDataStore = class {
|
|
1388
1347
|
options.onServerTransitionReceived(serverToClientTransitionState);
|
1389
1348
|
}
|
1390
1349
|
options.transitionStore.events.on("dataUpdatedAsync", (data) => {
|
1391
|
-
__privateMethod(this,
|
1392
|
-
...__privateGet(this,
|
1350
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, {
|
1351
|
+
...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData,
|
1393
1352
|
...data
|
1394
1353
|
});
|
1395
1354
|
});
|
1396
1355
|
const transitionData = options.transitionStore.data;
|
1397
1356
|
if (transitionData) {
|
1398
|
-
__privateMethod(this,
|
1357
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(
|
1399
1358
|
this,
|
1400
1359
|
// we know _currentData is not empty because we inited it above if it was
|
1401
|
-
{ ...__privateGet(this,
|
1360
|
+
{ ...__privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData, ...transitionData },
|
1402
1361
|
true
|
1403
1362
|
);
|
1404
1363
|
}
|
@@ -1407,12 +1366,12 @@ var VisitorDataStore = class {
|
|
1407
1366
|
/** Gets the current visitor data. This property is always up to date. */
|
1408
1367
|
get data() {
|
1409
1368
|
var _a, _b;
|
1410
|
-
const data = __privateGet(this,
|
1411
|
-
if (__privateMethod(this,
|
1369
|
+
const data = __privateGet(this, _VisitorDataStore_instances, currentData_get);
|
1370
|
+
if (__privateMethod(this, _VisitorDataStore_instances, isExpired_fn).call(this, data)) {
|
1412
1371
|
const { sessionScores, ...newData } = data.visitorData;
|
1413
|
-
__privateMethod(this,
|
1372
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, { ...newData, sessionScores: {} });
|
1414
1373
|
(_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["info", 120]);
|
1415
|
-
return __privateGet(this,
|
1374
|
+
return __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData;
|
1416
1375
|
}
|
1417
1376
|
return data.visitorData;
|
1418
1377
|
}
|
@@ -1429,12 +1388,12 @@ var VisitorDataStore = class {
|
|
1429
1388
|
return;
|
1430
1389
|
}
|
1431
1390
|
(_b = (_a = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _b.call(_a, ["debug", 101, commands]);
|
1432
|
-
const newData = applyCommandsToData(commands, this.data, (_c = __privateGet(this,
|
1391
|
+
const newData = applyCommandsToData(commands, this.data, (_c = __privateGet(this, _VisitorDataStore_instances, currentData_get)) == null ? void 0 : _c.visitorData.controlGroup);
|
1433
1392
|
if (commands.some((c) => c.type === "consent" && !c.data)) {
|
1434
1393
|
__privateGet(this, _persist).delete(STORAGE_KEY, true);
|
1435
1394
|
}
|
1436
|
-
__privateMethod(this,
|
1437
|
-
await ((_d = __privateGet(this, _options).transitionStore) == null ? void 0 : _d.updateData(commands, __privateGet(this,
|
1395
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, newData);
|
1396
|
+
await ((_d = __privateGet(this, _options).transitionStore) == null ? void 0 : _d.updateData(commands, __privateGet(this, _VisitorDataStore_instances, currentData_get).visitorData));
|
1438
1397
|
}
|
1439
1398
|
/**
|
1440
1399
|
* Deletes visitor data (forgetting them)
|
@@ -1447,7 +1406,7 @@ var VisitorDataStore = class {
|
|
1447
1406
|
try {
|
1448
1407
|
__privateGet(this, _persist).delete(STORAGE_KEY, false);
|
1449
1408
|
await ((_c = __privateGet(this, _options).transitionStore) == null ? void 0 : _c.delete(fromAllDevices));
|
1450
|
-
__privateMethod(this,
|
1409
|
+
__privateMethod(this, _VisitorDataStore_instances, replaceData_fn).call(this, __privateMethod(this, _VisitorDataStore_instances, defaultData_fn).call(this));
|
1451
1410
|
} finally {
|
1452
1411
|
(_e = (_d = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _e.call(_d, ["info", 103, "ENDGROUP"]);
|
1453
1412
|
}
|
@@ -1457,21 +1416,25 @@ _mitt2 = new WeakMap();
|
|
1457
1416
|
_persist = new WeakMap();
|
1458
1417
|
_visitTimeout = new WeakMap();
|
1459
1418
|
_options = new WeakMap();
|
1460
|
-
|
1419
|
+
_VisitorDataStore_instances = new WeakSet();
|
1461
1420
|
currentData_get = function() {
|
1462
1421
|
return __privateGet(this, _persist).get(STORAGE_KEY);
|
1463
1422
|
};
|
1464
|
-
|
1423
|
+
/**
|
1424
|
+
* IMPORTANT: This function mutates the input data. This is done,
|
1425
|
+
* because all the sources that call it have either already spread or cloned
|
1426
|
+
* the data, so we can safely mutate it for better perf.
|
1427
|
+
*/
|
1465
1428
|
replaceData_fn = function(data, quiet = false) {
|
1466
1429
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
1467
|
-
const oldData = __privateGet(this,
|
1430
|
+
const oldData = __privateGet(this, _VisitorDataStore_instances, currentData_get);
|
1468
1431
|
const now = Date.now();
|
1469
1432
|
if (data.controlGroup) {
|
1470
1433
|
data.scores = {};
|
1471
1434
|
data.sessionScores = {};
|
1472
1435
|
} else {
|
1473
|
-
__privateMethod(this,
|
1474
|
-
__privateMethod(this,
|
1436
|
+
__privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.scores);
|
1437
|
+
__privateMethod(this, _VisitorDataStore_instances, handleCaps_fn).call(this, data.sessionScores);
|
1475
1438
|
(_b = (_a = __privateGet(this, _options)).decay) == null ? void 0 : _b.call(_a, {
|
1476
1439
|
now,
|
1477
1440
|
lastUpd: oldData == null ? void 0 : oldData.updated,
|
@@ -1489,7 +1452,7 @@ replaceData_fn = function(data, quiet = false) {
|
|
1489
1452
|
updated: now,
|
1490
1453
|
visitorData: data
|
1491
1454
|
};
|
1492
|
-
__privateMethod(this,
|
1455
|
+
__privateMethod(this, _VisitorDataStore_instances, setVisitTimeout_fn).call(this);
|
1493
1456
|
__privateGet(this, _persist).set(STORAGE_KEY, updatedData, !!data.consent);
|
1494
1457
|
(_d = (_c = __privateGet(this, _options)).onLogMessage) == null ? void 0 : _d.call(_c, ["debug", 102, data]);
|
1495
1458
|
if (!quiet) {
|
@@ -1520,7 +1483,6 @@ replaceData_fn = function(data, quiet = false) {
|
|
1520
1483
|
}
|
1521
1484
|
}
|
1522
1485
|
};
|
1523
|
-
_setVisitTimeout = new WeakSet();
|
1524
1486
|
setVisitTimeout_fn = function() {
|
1525
1487
|
if (typeof document === "undefined" || !__privateGet(this, _options).visitLifespan) {
|
1526
1488
|
return;
|
@@ -1532,12 +1494,15 @@ setVisitTimeout_fn = function() {
|
|
1532
1494
|
this.data;
|
1533
1495
|
}, __privateGet(this, _options).visitLifespan + 50));
|
1534
1496
|
};
|
1535
|
-
_isExpired = new WeakSet();
|
1536
1497
|
isExpired_fn = function(data) {
|
1537
1498
|
const expires = __privateGet(this, _options).visitLifespan;
|
1538
1499
|
return expires ? data.updated + expires < Date.now() : false;
|
1539
1500
|
};
|
1540
|
-
|
1501
|
+
/**
|
1502
|
+
* IMPORTANT: This function mutates the input data. This is done,
|
1503
|
+
* because all the sources that call it have either already spread or cloned
|
1504
|
+
* the data, so we can safely mutate it for better perf.
|
1505
|
+
*/
|
1541
1506
|
handleCaps_fn = function(scores) {
|
1542
1507
|
var _a, _b;
|
1543
1508
|
if (!__privateGet(this, _options).manifest) {
|
@@ -1555,7 +1520,6 @@ handleCaps_fn = function(scores) {
|
|
1555
1520
|
}
|
1556
1521
|
}
|
1557
1522
|
};
|
1558
|
-
_defaultData = new WeakSet();
|
1559
1523
|
defaultData_fn = function() {
|
1560
1524
|
var _a, _b, _c;
|
1561
1525
|
return {
|
@@ -1570,20 +1534,17 @@ var import_lite5 = require("dequal/lite");
|
|
1570
1534
|
var import_mitt3 = __toESM(require("mitt"));
|
1571
1535
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1572
1536
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1573
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3,
|
1537
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _Context_instances, emitTest_fn, updateGoals_fn, updateComputedScores_fn, calculateScores_fn;
|
1574
1538
|
var Context = class {
|
1575
1539
|
constructor(options) {
|
1576
|
-
__privateAdd(this,
|
1577
|
-
__privateAdd(this, _updateGoals);
|
1578
|
-
__privateAdd(this, _updateComputedScores);
|
1579
|
-
__privateAdd(this, _calculateScores);
|
1540
|
+
__privateAdd(this, _Context_instances);
|
1580
1541
|
__publicField(this, "manifest");
|
1581
|
-
__privateAdd(this, _serverTransitionState
|
1542
|
+
__privateAdd(this, _serverTransitionState);
|
1582
1543
|
__privateAdd(this, _scores, {});
|
1583
|
-
__privateAdd(this, _state
|
1544
|
+
__privateAdd(this, _state);
|
1584
1545
|
__privateAdd(this, _pzCache, {});
|
1585
|
-
__privateAdd(this, _plugins
|
1586
|
-
__privateAdd(this, _commands
|
1546
|
+
__privateAdd(this, _plugins);
|
1547
|
+
__privateAdd(this, _commands);
|
1587
1548
|
__privateAdd(this, _mitt3, (0, import_mitt3.default)());
|
1588
1549
|
/**
|
1589
1550
|
* Subscribe to events
|
@@ -1632,9 +1593,9 @@ var Context = class {
|
|
1632
1593
|
},
|
1633
1594
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1634
1595
|
});
|
1635
|
-
this.storage.events.on("scoresUpdated", __privateMethod(this,
|
1596
|
+
this.storage.events.on("scoresUpdated", __privateMethod(this, _Context_instances, updateComputedScores_fn).bind(this));
|
1636
1597
|
if (!__privateGet(this, _serverTransitionState)) {
|
1637
|
-
__privateMethod(this,
|
1598
|
+
__privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
1638
1599
|
}
|
1639
1600
|
this.storage.events.on("quirksUpdated", (quirks) => {
|
1640
1601
|
const updates = this.manifest.computeSignals({
|
@@ -1643,7 +1604,7 @@ var Context = class {
|
|
1643
1604
|
previousState: __privateGet(this, _state),
|
1644
1605
|
visitor: this.storage.data
|
1645
1606
|
});
|
1646
|
-
__privateMethod(this,
|
1607
|
+
__privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
|
1647
1608
|
quirks: quirks.quirks,
|
1648
1609
|
scores: void 0
|
1649
1610
|
});
|
@@ -1766,7 +1727,7 @@ var Context = class {
|
|
1766
1727
|
// re-compute using scores from storage instead of the current scores since
|
1767
1728
|
// server transition scores might have adjusted values already integrated into them,
|
1768
1729
|
// which causes issues when you are near limits.
|
1769
|
-
scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this,
|
1730
|
+
scores: __privateGet(this, _serverTransitionState) ? __privateMethod(this, _Context_instances, calculateScores_fn).call(this, this.storage.data) : __privateGet(this, _scores)
|
1770
1731
|
})
|
1771
1732
|
);
|
1772
1733
|
__privateSet(this, _state, {
|
@@ -1779,9 +1740,9 @@ var Context = class {
|
|
1779
1740
|
serverCommands: __privateGet(this, _serverTransitionState).commands,
|
1780
1741
|
commands
|
1781
1742
|
});
|
1782
|
-
__privateMethod(this,
|
1743
|
+
__privateMethod(this, _Context_instances, updateComputedScores_fn).call(this, this.storage.data);
|
1783
1744
|
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
1784
|
-
__privateMethod(this,
|
1745
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
1785
1746
|
name: testName,
|
1786
1747
|
variantId: testVariantId,
|
1787
1748
|
variantAssigned: true
|
@@ -1878,7 +1839,7 @@ var Context = class {
|
|
1878
1839
|
context: this,
|
1879
1840
|
onLogMessage: (message) => __privateGet(this, _mitt3).emit("log", message)
|
1880
1841
|
});
|
1881
|
-
__privateMethod(this,
|
1842
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, {
|
1882
1843
|
name: options.name,
|
1883
1844
|
variantId: (_c = (_b = value.result) == null ? void 0 : _b.id) != null ? _c : void 0,
|
1884
1845
|
variantAssigned: value.variantAssigned
|
@@ -1952,7 +1913,7 @@ var Context = class {
|
|
1952
1913
|
internal_processTestEvent(event) {
|
1953
1914
|
if (event.variantId) {
|
1954
1915
|
this.setTestVariantId(event.name, event.variantId);
|
1955
|
-
__privateMethod(this,
|
1916
|
+
__privateMethod(this, _Context_instances, emitTest_fn).call(this, event);
|
1956
1917
|
}
|
1957
1918
|
}
|
1958
1919
|
/** @deprecated */
|
@@ -1968,24 +1929,22 @@ _pzCache = new WeakMap();
|
|
1968
1929
|
_plugins = new WeakMap();
|
1969
1930
|
_commands = new WeakMap();
|
1970
1931
|
_mitt3 = new WeakMap();
|
1971
|
-
|
1932
|
+
_Context_instances = new WeakSet();
|
1972
1933
|
emitTest_fn = function(event) {
|
1973
1934
|
__privateGet(this, _mitt3).emit("testResult", event);
|
1974
1935
|
};
|
1975
|
-
_updateGoals = new WeakSet();
|
1976
1936
|
updateGoals_fn = async function(data) {
|
1977
1937
|
const goalCommands = this.manifest.computeGoals(data);
|
1978
1938
|
if (goalCommands.length !== 0) {
|
1979
1939
|
await this.storage.updateData(goalCommands);
|
1980
1940
|
}
|
1981
1941
|
};
|
1982
|
-
_updateComputedScores = new WeakSet();
|
1983
1942
|
updateComputedScores_fn = function(newData) {
|
1984
|
-
const newScores = __privateMethod(this,
|
1943
|
+
const newScores = __privateMethod(this, _Context_instances, calculateScores_fn).call(this, newData);
|
1985
1944
|
const newScoresHaveChanged = !(0, import_lite5.dequal)(newScores, __privateGet(this, _scores));
|
1986
1945
|
if (newScoresHaveChanged) {
|
1987
1946
|
__privateSet(this, _scores, newScores);
|
1988
|
-
__privateMethod(this,
|
1947
|
+
__privateMethod(this, _Context_instances, updateGoals_fn).call(this, {
|
1989
1948
|
scores: __privateGet(this, _scores),
|
1990
1949
|
quirks: void 0
|
1991
1950
|
});
|
@@ -1993,7 +1952,6 @@ updateComputedScores_fn = function(newData) {
|
|
1993
1952
|
__privateGet(this, _mitt3).emit("log", ["info", 3, newScores]);
|
1994
1953
|
}
|
1995
1954
|
};
|
1996
|
-
_calculateScores = new WeakSet();
|
1997
1955
|
calculateScores_fn = function(newData) {
|
1998
1956
|
var _a;
|
1999
1957
|
let newScores = { ...newData.scores };
|
@@ -2042,13 +2000,11 @@ function enableContextDevTools(options) {
|
|
2042
2000
|
);
|
2043
2001
|
};
|
2044
2002
|
const onPersonalizationResult = (e) => {
|
2045
|
-
if (!e.changed)
|
2046
|
-
return;
|
2003
|
+
if (!e.changed) return;
|
2047
2004
|
personalizations.push(e);
|
2048
2005
|
};
|
2049
2006
|
const onTestResult = (e) => {
|
2050
|
-
if (!e.variantAssigned)
|
2051
|
-
return;
|
2007
|
+
if (!e.variantAssigned) return;
|
2052
2008
|
tests.push(e);
|
2053
2009
|
};
|
2054
2010
|
if (isBrowser) {
|
@@ -2142,10 +2098,16 @@ var getBasePayload = () => {
|
|
2142
2098
|
};
|
2143
2099
|
};
|
2144
2100
|
var createInsightsClient = ({ endpoint }) => {
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2101
|
+
let endpointUrl;
|
2102
|
+
const apiKey = endpoint.apiKey;
|
2103
|
+
if (endpoint.type === "api") {
|
2104
|
+
const url = new URL(endpoint.host);
|
2105
|
+
url.pathname = "/v0/events";
|
2106
|
+
url.searchParams.set("name", "analytics_events");
|
2107
|
+
endpointUrl = url.toString();
|
2108
|
+
} else {
|
2109
|
+
endpointUrl = endpoint.path;
|
2110
|
+
}
|
2149
2111
|
const sendMessage = async (message) => {
|
2150
2112
|
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2151
2113
|
return;
|
@@ -2154,12 +2116,15 @@ var createInsightsClient = ({ endpoint }) => {
|
|
2154
2116
|
...message,
|
2155
2117
|
payload: JSON.stringify(message.payload)
|
2156
2118
|
};
|
2119
|
+
const headers = {
|
2120
|
+
"Content-Type": "application/json"
|
2121
|
+
};
|
2122
|
+
if (apiKey) {
|
2123
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
2124
|
+
}
|
2157
2125
|
const response = await fetch(endpointUrl, {
|
2158
2126
|
method: "POST",
|
2159
|
-
headers
|
2160
|
-
"Content-Type": "application/json",
|
2161
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2162
|
-
},
|
2127
|
+
headers,
|
2163
2128
|
body: JSON.stringify(converted)
|
2164
2129
|
});
|
2165
2130
|
const json = await response.json();
|