@uniformdev/context 19.154.1-alpha.22 → 19.154.1-alpha.26
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/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.esm.js +72 -22
- package/dist/index.js +73 -22
- package/dist/index.mjs +72 -22
- package/dist/{types-DqYG-dCc.d.mts → types-KWnn2ElZ.d.mts} +18 -9
- package/dist/{types-DqYG-dCc.d.ts → types-KWnn2ElZ.d.ts} +18 -9
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
@@ -826,11 +826,20 @@ var testVariations = ({
|
|
826
826
|
}
|
827
827
|
};
|
828
828
|
|
829
|
+
// src/storage/commands.ts
|
830
|
+
import { dequal as dequal2 } from "dequal/lite";
|
831
|
+
var areCommandsEqual = (a, b) => {
|
832
|
+
if (a.type !== b.type) {
|
833
|
+
return false;
|
834
|
+
}
|
835
|
+
return dequal2(a, b);
|
836
|
+
};
|
837
|
+
|
829
838
|
// src/storage/CookieTransitionDataStore.ts
|
830
839
|
import Cookies from "js-cookie";
|
831
840
|
|
832
841
|
// src/storage/TransitionDataStore.ts
|
833
|
-
import { dequal as
|
842
|
+
import { dequal as dequal3 } from "dequal/lite";
|
834
843
|
import mitt from "mitt";
|
835
844
|
var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
836
845
|
var _data, _initialData, _mitt;
|
@@ -876,7 +885,7 @@ var TransitionDataStore = class {
|
|
876
885
|
await this.handleDelete(fromAllDevices);
|
877
886
|
}
|
878
887
|
signalAsyncDataUpdate(newScores) {
|
879
|
-
if (
|
888
|
+
if (dequal3(this.data, newScores)) {
|
880
889
|
return;
|
881
890
|
}
|
882
891
|
__privateSet(this, _data, newScores);
|
@@ -1149,7 +1158,7 @@ var emptyVisitorData = () => ({
|
|
1149
1158
|
});
|
1150
1159
|
|
1151
1160
|
// src/storage/VisitorDataStore.ts
|
1152
|
-
import { dequal as
|
1161
|
+
import { dequal as dequal4 } from "dequal/lite";
|
1153
1162
|
import mitt2 from "mitt";
|
1154
1163
|
|
1155
1164
|
// src/storage/util/applyCommandsToData.ts
|
@@ -1399,11 +1408,11 @@ replaceData_fn = function(data, quiet = false) {
|
|
1399
1408
|
onLogMessage: __privateGet(this, _options).onLogMessage
|
1400
1409
|
});
|
1401
1410
|
}
|
1402
|
-
const haveScoresChanged = !
|
1403
|
-
const haveSessionScoresChanged = !
|
1404
|
-
const haveQuirksChanged = !
|
1405
|
-
const haveTestsChanged = !
|
1406
|
-
const haveGoalsChanged = !
|
1411
|
+
const haveScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
1412
|
+
const haveSessionScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1413
|
+
const haveQuirksChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1414
|
+
const haveTestsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1415
|
+
const haveGoalsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1407
1416
|
const updatedData = {
|
1408
1417
|
updated: now,
|
1409
1418
|
visitorData: data
|
@@ -1485,11 +1494,11 @@ defaultData_fn = function() {
|
|
1485
1494
|
};
|
1486
1495
|
|
1487
1496
|
// src/Context.ts
|
1488
|
-
import { dequal as
|
1497
|
+
import { dequal as dequal5 } from "dequal/lite";
|
1489
1498
|
import mitt3 from "mitt";
|
1490
1499
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1491
1500
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1492
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1501
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1493
1502
|
var Context = class {
|
1494
1503
|
constructor(options) {
|
1495
1504
|
__privateAdd(this, _emitTest);
|
@@ -1502,6 +1511,7 @@ var Context = class {
|
|
1502
1511
|
__privateAdd(this, _state, void 0);
|
1503
1512
|
__privateAdd(this, _pzCache, {});
|
1504
1513
|
__privateAdd(this, _plugins, void 0);
|
1514
|
+
__privateAdd(this, _commands, void 0);
|
1505
1515
|
__privateAdd(this, _mitt3, mitt3());
|
1506
1516
|
/**
|
1507
1517
|
* Subscribe to events
|
@@ -1515,6 +1525,9 @@ var Context = class {
|
|
1515
1525
|
const { manifest, ...storageOptions } = options;
|
1516
1526
|
__privateSet(this, _state, {});
|
1517
1527
|
__privateSet(this, _plugins, options.plugins);
|
1528
|
+
if (typeof options.transitionStore !== "undefined") {
|
1529
|
+
__privateSet(this, _commands, []);
|
1530
|
+
}
|
1518
1531
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1519
1532
|
if (!plugin.logDrain) {
|
1520
1533
|
return;
|
@@ -1595,7 +1608,7 @@ var Context = class {
|
|
1595
1608
|
* will NOT result in a recomputation of signal state.
|
1596
1609
|
*/
|
1597
1610
|
async update(newData) {
|
1598
|
-
var _a, _b, _c, _d;
|
1611
|
+
var _a, _b, _c, _d, _e;
|
1599
1612
|
const commands = [];
|
1600
1613
|
const newServerSideTests = {};
|
1601
1614
|
if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
@@ -1690,6 +1703,10 @@ var Context = class {
|
|
1690
1703
|
});
|
1691
1704
|
await this.storage.updateData(commands);
|
1692
1705
|
if (__privateGet(this, _serverTransitionState)) {
|
1706
|
+
await this.processServerCommands({
|
1707
|
+
serverCommands: __privateGet(this, _serverTransitionState).commands,
|
1708
|
+
commands
|
1709
|
+
});
|
1693
1710
|
__privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
|
1694
1711
|
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
1695
1712
|
__privateMethod(this, _emitTest, emitTest_fn).call(this, {
|
@@ -1710,10 +1727,31 @@ var Context = class {
|
|
1710
1727
|
await plugin.update(newData);
|
1711
1728
|
}
|
1712
1729
|
}
|
1730
|
+
(_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
|
1713
1731
|
} finally {
|
1714
1732
|
__privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
1715
1733
|
}
|
1716
1734
|
}
|
1735
|
+
async processServerCommands({
|
1736
|
+
serverCommands,
|
1737
|
+
commands
|
1738
|
+
}) {
|
1739
|
+
if (!(serverCommands == null ? void 0 : serverCommands.length)) {
|
1740
|
+
return;
|
1741
|
+
}
|
1742
|
+
const notExecutedCommands = [];
|
1743
|
+
serverCommands.forEach((serverCommand) => {
|
1744
|
+
const found = commands.find((command) => {
|
1745
|
+
return areCommandsEqual(command, serverCommand);
|
1746
|
+
});
|
1747
|
+
if (!found) {
|
1748
|
+
notExecutedCommands.push(serverCommand);
|
1749
|
+
}
|
1750
|
+
});
|
1751
|
+
if (notExecutedCommands.length > 0) {
|
1752
|
+
await this.storage.updateData(notExecutedCommands);
|
1753
|
+
}
|
1754
|
+
}
|
1717
1755
|
/** use test() instead */
|
1718
1756
|
getTestVariantId(testName) {
|
1719
1757
|
var _a, _b, _c, _d;
|
@@ -1792,7 +1830,7 @@ var Context = class {
|
|
1792
1830
|
control: this.storage.data.controlGroup,
|
1793
1831
|
changed: true
|
1794
1832
|
};
|
1795
|
-
if (previousPlacement &&
|
1833
|
+
if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
|
1796
1834
|
eventData.changed = false;
|
1797
1835
|
}
|
1798
1836
|
__privateGet(this, _mitt3).emit("personalizationResult", eventData);
|
@@ -1826,7 +1864,8 @@ var Context = class {
|
|
1826
1864
|
quirks: this.storage.data.quirks,
|
1827
1865
|
ssv: __privateGet(this, _scores),
|
1828
1866
|
tests: {},
|
1829
|
-
personalizeVariants: this.storage.data.personalizeVariants
|
1867
|
+
personalizeVariants: this.storage.data.personalizeVariants,
|
1868
|
+
commands: __privateGet(this, _commands)
|
1830
1869
|
};
|
1831
1870
|
const allTests = this.storage.data.tests;
|
1832
1871
|
Object.entries(allTests).map(([testName, testValue]) => {
|
@@ -1855,6 +1894,7 @@ _scores = new WeakMap();
|
|
1855
1894
|
_state = new WeakMap();
|
1856
1895
|
_pzCache = new WeakMap();
|
1857
1896
|
_plugins = new WeakMap();
|
1897
|
+
_commands = new WeakMap();
|
1858
1898
|
_mitt3 = new WeakMap();
|
1859
1899
|
_emitTest = new WeakSet();
|
1860
1900
|
emitTest_fn = function(event) {
|
@@ -1870,7 +1910,7 @@ updateGoals_fn = async function(data) {
|
|
1870
1910
|
_updateComputedScores = new WeakSet();
|
1871
1911
|
updateComputedScores_fn = function(newData) {
|
1872
1912
|
const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
|
1873
|
-
const newScoresHaveChanged = !
|
1913
|
+
const newScoresHaveChanged = !dequal5(newScores, __privateGet(this, _scores));
|
1874
1914
|
if (newScoresHaveChanged) {
|
1875
1915
|
__privateSet(this, _scores, newScores);
|
1876
1916
|
__privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
|
@@ -2030,10 +2070,16 @@ var getBasePayload = () => {
|
|
2030
2070
|
};
|
2031
2071
|
};
|
2032
2072
|
var createInsightsClient = ({ endpoint }) => {
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2073
|
+
let endpointUrl;
|
2074
|
+
const apiKey = endpoint.apiKey;
|
2075
|
+
if (endpoint.type === "api") {
|
2076
|
+
const url = new URL(endpoint.host);
|
2077
|
+
url.pathname = "/v0/events";
|
2078
|
+
url.searchParams.set("name", "analytics_events");
|
2079
|
+
endpointUrl = url.toString();
|
2080
|
+
} else {
|
2081
|
+
endpointUrl = endpoint.path;
|
2082
|
+
}
|
2037
2083
|
const sendMessage = async (message) => {
|
2038
2084
|
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2039
2085
|
return;
|
@@ -2042,12 +2088,15 @@ var createInsightsClient = ({ endpoint }) => {
|
|
2042
2088
|
...message,
|
2043
2089
|
payload: JSON.stringify(message.payload)
|
2044
2090
|
};
|
2091
|
+
const headers = {
|
2092
|
+
"Content-Type": "application/json"
|
2093
|
+
};
|
2094
|
+
if (apiKey) {
|
2095
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
2096
|
+
}
|
2045
2097
|
const response = await fetch(endpointUrl, {
|
2046
2098
|
method: "POST",
|
2047
|
-
headers
|
2048
|
-
"Content-Type": "application/json",
|
2049
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2050
|
-
},
|
2099
|
+
headers,
|
2051
2100
|
body: JSON.stringify(converted)
|
2052
2101
|
});
|
2053
2102
|
const json = await response.json();
|
@@ -2541,6 +2590,7 @@ export {
|
|
2541
2590
|
TransitionDataStore,
|
2542
2591
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
2543
2592
|
VisitorDataStore,
|
2593
|
+
areCommandsEqual,
|
2544
2594
|
computeAggregateDimensions,
|
2545
2595
|
cookieEvaluator,
|
2546
2596
|
createConsoleLogDrain,
|
package/dist/index.js
CHANGED
@@ -70,6 +70,7 @@ __export(src_exports, {
|
|
70
70
|
TransitionDataStore: () => TransitionDataStore,
|
71
71
|
UNIFORM_DEFAULT_COOKIE_NAME: () => UNIFORM_DEFAULT_COOKIE_NAME,
|
72
72
|
VisitorDataStore: () => VisitorDataStore,
|
73
|
+
areCommandsEqual: () => areCommandsEqual,
|
73
74
|
computeAggregateDimensions: () => computeAggregateDimensions,
|
74
75
|
cookieEvaluator: () => cookieEvaluator,
|
75
76
|
createConsoleLogDrain: () => createConsoleLogDrain,
|
@@ -897,11 +898,20 @@ var testVariations = ({
|
|
897
898
|
}
|
898
899
|
};
|
899
900
|
|
901
|
+
// src/storage/commands.ts
|
902
|
+
var import_lite2 = require("dequal/lite");
|
903
|
+
var areCommandsEqual = (a, b) => {
|
904
|
+
if (a.type !== b.type) {
|
905
|
+
return false;
|
906
|
+
}
|
907
|
+
return (0, import_lite2.dequal)(a, b);
|
908
|
+
};
|
909
|
+
|
900
910
|
// src/storage/CookieTransitionDataStore.ts
|
901
911
|
var import_js_cookie = __toESM(require("js-cookie"));
|
902
912
|
|
903
913
|
// src/storage/TransitionDataStore.ts
|
904
|
-
var
|
914
|
+
var import_lite3 = require("dequal/lite");
|
905
915
|
var import_mitt = __toESM(require("mitt"));
|
906
916
|
var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
907
917
|
var _data, _initialData, _mitt;
|
@@ -947,7 +957,7 @@ var TransitionDataStore = class {
|
|
947
957
|
await this.handleDelete(fromAllDevices);
|
948
958
|
}
|
949
959
|
signalAsyncDataUpdate(newScores) {
|
950
|
-
if ((0,
|
960
|
+
if ((0, import_lite3.dequal)(this.data, newScores)) {
|
951
961
|
return;
|
952
962
|
}
|
953
963
|
__privateSet(this, _data, newScores);
|
@@ -1220,7 +1230,7 @@ var emptyVisitorData = () => ({
|
|
1220
1230
|
});
|
1221
1231
|
|
1222
1232
|
// src/storage/VisitorDataStore.ts
|
1223
|
-
var
|
1233
|
+
var import_lite4 = require("dequal/lite");
|
1224
1234
|
var import_mitt2 = __toESM(require("mitt"));
|
1225
1235
|
|
1226
1236
|
// src/storage/util/applyCommandsToData.ts
|
@@ -1470,11 +1480,11 @@ replaceData_fn = function(data, quiet = false) {
|
|
1470
1480
|
onLogMessage: __privateGet(this, _options).onLogMessage
|
1471
1481
|
});
|
1472
1482
|
}
|
1473
|
-
const haveScoresChanged = !(0,
|
1474
|
-
const haveSessionScoresChanged = !(0,
|
1475
|
-
const haveQuirksChanged = !(0,
|
1476
|
-
const haveTestsChanged = !(0,
|
1477
|
-
const haveGoalsChanged = !(0,
|
1483
|
+
const haveScoresChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
1484
|
+
const haveSessionScoresChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1485
|
+
const haveQuirksChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1486
|
+
const haveTestsChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1487
|
+
const haveGoalsChanged = !(0, import_lite4.dequal)(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1478
1488
|
const updatedData = {
|
1479
1489
|
updated: now,
|
1480
1490
|
visitorData: data
|
@@ -1556,11 +1566,11 @@ defaultData_fn = function() {
|
|
1556
1566
|
};
|
1557
1567
|
|
1558
1568
|
// src/Context.ts
|
1559
|
-
var
|
1569
|
+
var import_lite5 = require("dequal/lite");
|
1560
1570
|
var import_mitt3 = __toESM(require("mitt"));
|
1561
1571
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1562
1572
|
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;
|
1573
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1564
1574
|
var Context = class {
|
1565
1575
|
constructor(options) {
|
1566
1576
|
__privateAdd(this, _emitTest);
|
@@ -1573,6 +1583,7 @@ var Context = class {
|
|
1573
1583
|
__privateAdd(this, _state, void 0);
|
1574
1584
|
__privateAdd(this, _pzCache, {});
|
1575
1585
|
__privateAdd(this, _plugins, void 0);
|
1586
|
+
__privateAdd(this, _commands, void 0);
|
1576
1587
|
__privateAdd(this, _mitt3, (0, import_mitt3.default)());
|
1577
1588
|
/**
|
1578
1589
|
* Subscribe to events
|
@@ -1586,6 +1597,9 @@ var Context = class {
|
|
1586
1597
|
const { manifest, ...storageOptions } = options;
|
1587
1598
|
__privateSet(this, _state, {});
|
1588
1599
|
__privateSet(this, _plugins, options.plugins);
|
1600
|
+
if (typeof options.transitionStore !== "undefined") {
|
1601
|
+
__privateSet(this, _commands, []);
|
1602
|
+
}
|
1589
1603
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1590
1604
|
if (!plugin.logDrain) {
|
1591
1605
|
return;
|
@@ -1666,7 +1680,7 @@ var Context = class {
|
|
1666
1680
|
* will NOT result in a recomputation of signal state.
|
1667
1681
|
*/
|
1668
1682
|
async update(newData) {
|
1669
|
-
var _a, _b, _c, _d;
|
1683
|
+
var _a, _b, _c, _d, _e;
|
1670
1684
|
const commands = [];
|
1671
1685
|
const newServerSideTests = {};
|
1672
1686
|
if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
@@ -1761,6 +1775,10 @@ var Context = class {
|
|
1761
1775
|
});
|
1762
1776
|
await this.storage.updateData(commands);
|
1763
1777
|
if (__privateGet(this, _serverTransitionState)) {
|
1778
|
+
await this.processServerCommands({
|
1779
|
+
serverCommands: __privateGet(this, _serverTransitionState).commands,
|
1780
|
+
commands
|
1781
|
+
});
|
1764
1782
|
__privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
|
1765
1783
|
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
1766
1784
|
__privateMethod(this, _emitTest, emitTest_fn).call(this, {
|
@@ -1781,10 +1799,31 @@ var Context = class {
|
|
1781
1799
|
await plugin.update(newData);
|
1782
1800
|
}
|
1783
1801
|
}
|
1802
|
+
(_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
|
1784
1803
|
} finally {
|
1785
1804
|
__privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
1786
1805
|
}
|
1787
1806
|
}
|
1807
|
+
async processServerCommands({
|
1808
|
+
serverCommands,
|
1809
|
+
commands
|
1810
|
+
}) {
|
1811
|
+
if (!(serverCommands == null ? void 0 : serverCommands.length)) {
|
1812
|
+
return;
|
1813
|
+
}
|
1814
|
+
const notExecutedCommands = [];
|
1815
|
+
serverCommands.forEach((serverCommand) => {
|
1816
|
+
const found = commands.find((command) => {
|
1817
|
+
return areCommandsEqual(command, serverCommand);
|
1818
|
+
});
|
1819
|
+
if (!found) {
|
1820
|
+
notExecutedCommands.push(serverCommand);
|
1821
|
+
}
|
1822
|
+
});
|
1823
|
+
if (notExecutedCommands.length > 0) {
|
1824
|
+
await this.storage.updateData(notExecutedCommands);
|
1825
|
+
}
|
1826
|
+
}
|
1788
1827
|
/** use test() instead */
|
1789
1828
|
getTestVariantId(testName) {
|
1790
1829
|
var _a, _b, _c, _d;
|
@@ -1863,7 +1902,7 @@ var Context = class {
|
|
1863
1902
|
control: this.storage.data.controlGroup,
|
1864
1903
|
changed: true
|
1865
1904
|
};
|
1866
|
-
if (previousPlacement && (0,
|
1905
|
+
if (previousPlacement && (0, import_lite5.dequal)(eventData.variantIds, previousPlacement)) {
|
1867
1906
|
eventData.changed = false;
|
1868
1907
|
}
|
1869
1908
|
__privateGet(this, _mitt3).emit("personalizationResult", eventData);
|
@@ -1897,7 +1936,8 @@ var Context = class {
|
|
1897
1936
|
quirks: this.storage.data.quirks,
|
1898
1937
|
ssv: __privateGet(this, _scores),
|
1899
1938
|
tests: {},
|
1900
|
-
personalizeVariants: this.storage.data.personalizeVariants
|
1939
|
+
personalizeVariants: this.storage.data.personalizeVariants,
|
1940
|
+
commands: __privateGet(this, _commands)
|
1901
1941
|
};
|
1902
1942
|
const allTests = this.storage.data.tests;
|
1903
1943
|
Object.entries(allTests).map(([testName, testValue]) => {
|
@@ -1926,6 +1966,7 @@ _scores = new WeakMap();
|
|
1926
1966
|
_state = new WeakMap();
|
1927
1967
|
_pzCache = new WeakMap();
|
1928
1968
|
_plugins = new WeakMap();
|
1969
|
+
_commands = new WeakMap();
|
1929
1970
|
_mitt3 = new WeakMap();
|
1930
1971
|
_emitTest = new WeakSet();
|
1931
1972
|
emitTest_fn = function(event) {
|
@@ -1941,7 +1982,7 @@ updateGoals_fn = async function(data) {
|
|
1941
1982
|
_updateComputedScores = new WeakSet();
|
1942
1983
|
updateComputedScores_fn = function(newData) {
|
1943
1984
|
const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
|
1944
|
-
const newScoresHaveChanged = !(0,
|
1985
|
+
const newScoresHaveChanged = !(0, import_lite5.dequal)(newScores, __privateGet(this, _scores));
|
1945
1986
|
if (newScoresHaveChanged) {
|
1946
1987
|
__privateSet(this, _scores, newScores);
|
1947
1988
|
__privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
|
@@ -2101,10 +2142,16 @@ var getBasePayload = () => {
|
|
2101
2142
|
};
|
2102
2143
|
};
|
2103
2144
|
var createInsightsClient = ({ endpoint }) => {
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2145
|
+
let endpointUrl;
|
2146
|
+
const apiKey = endpoint.apiKey;
|
2147
|
+
if (endpoint.type === "api") {
|
2148
|
+
const url = new URL(endpoint.host);
|
2149
|
+
url.pathname = "/v0/events";
|
2150
|
+
url.searchParams.set("name", "analytics_events");
|
2151
|
+
endpointUrl = url.toString();
|
2152
|
+
} else {
|
2153
|
+
endpointUrl = endpoint.path;
|
2154
|
+
}
|
2108
2155
|
const sendMessage = async (message) => {
|
2109
2156
|
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2110
2157
|
return;
|
@@ -2113,12 +2160,15 @@ var createInsightsClient = ({ endpoint }) => {
|
|
2113
2160
|
...message,
|
2114
2161
|
payload: JSON.stringify(message.payload)
|
2115
2162
|
};
|
2163
|
+
const headers = {
|
2164
|
+
"Content-Type": "application/json"
|
2165
|
+
};
|
2166
|
+
if (apiKey) {
|
2167
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
2168
|
+
}
|
2116
2169
|
const response = await fetch(endpointUrl, {
|
2117
2170
|
method: "POST",
|
2118
|
-
headers
|
2119
|
-
"Content-Type": "application/json",
|
2120
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2121
|
-
},
|
2171
|
+
headers,
|
2122
2172
|
body: JSON.stringify(converted)
|
2123
2173
|
});
|
2124
2174
|
const json = await response.json();
|
@@ -2613,6 +2663,7 @@ function parseQuickConnect(serialized) {
|
|
2613
2663
|
TransitionDataStore,
|
2614
2664
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
2615
2665
|
VisitorDataStore,
|
2666
|
+
areCommandsEqual,
|
2616
2667
|
computeAggregateDimensions,
|
2617
2668
|
cookieEvaluator,
|
2618
2669
|
createConsoleLogDrain,
|
package/dist/index.mjs
CHANGED
@@ -826,11 +826,20 @@ var testVariations = ({
|
|
826
826
|
}
|
827
827
|
};
|
828
828
|
|
829
|
+
// src/storage/commands.ts
|
830
|
+
import { dequal as dequal2 } from "dequal/lite";
|
831
|
+
var areCommandsEqual = (a, b) => {
|
832
|
+
if (a.type !== b.type) {
|
833
|
+
return false;
|
834
|
+
}
|
835
|
+
return dequal2(a, b);
|
836
|
+
};
|
837
|
+
|
829
838
|
// src/storage/CookieTransitionDataStore.ts
|
830
839
|
import Cookies from "js-cookie";
|
831
840
|
|
832
841
|
// src/storage/TransitionDataStore.ts
|
833
|
-
import { dequal as
|
842
|
+
import { dequal as dequal3 } from "dequal/lite";
|
834
843
|
import mitt from "mitt";
|
835
844
|
var SERVER_STATE_ID = "__UNIFORM_DATA__";
|
836
845
|
var _data, _initialData, _mitt;
|
@@ -876,7 +885,7 @@ var TransitionDataStore = class {
|
|
876
885
|
await this.handleDelete(fromAllDevices);
|
877
886
|
}
|
878
887
|
signalAsyncDataUpdate(newScores) {
|
879
|
-
if (
|
888
|
+
if (dequal3(this.data, newScores)) {
|
880
889
|
return;
|
881
890
|
}
|
882
891
|
__privateSet(this, _data, newScores);
|
@@ -1149,7 +1158,7 @@ var emptyVisitorData = () => ({
|
|
1149
1158
|
});
|
1150
1159
|
|
1151
1160
|
// src/storage/VisitorDataStore.ts
|
1152
|
-
import { dequal as
|
1161
|
+
import { dequal as dequal4 } from "dequal/lite";
|
1153
1162
|
import mitt2 from "mitt";
|
1154
1163
|
|
1155
1164
|
// src/storage/util/applyCommandsToData.ts
|
@@ -1399,11 +1408,11 @@ replaceData_fn = function(data, quiet = false) {
|
|
1399
1408
|
onLogMessage: __privateGet(this, _options).onLogMessage
|
1400
1409
|
});
|
1401
1410
|
}
|
1402
|
-
const haveScoresChanged = !
|
1403
|
-
const haveSessionScoresChanged = !
|
1404
|
-
const haveQuirksChanged = !
|
1405
|
-
const haveTestsChanged = !
|
1406
|
-
const haveGoalsChanged = !
|
1411
|
+
const haveScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.scores, data.scores);
|
1412
|
+
const haveSessionScoresChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.sessionScores, data.sessionScores);
|
1413
|
+
const haveQuirksChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.quirks, data.quirks);
|
1414
|
+
const haveTestsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.tests, data.tests);
|
1415
|
+
const haveGoalsChanged = !dequal4(oldData == null ? void 0 : oldData.visitorData.goals, data.goals);
|
1407
1416
|
const updatedData = {
|
1408
1417
|
updated: now,
|
1409
1418
|
visitorData: data
|
@@ -1485,11 +1494,11 @@ defaultData_fn = function() {
|
|
1485
1494
|
};
|
1486
1495
|
|
1487
1496
|
// src/Context.ts
|
1488
|
-
import { dequal as
|
1497
|
+
import { dequal as dequal5 } from "dequal/lite";
|
1489
1498
|
import mitt3 from "mitt";
|
1490
1499
|
var CONTEXTUAL_EDITING_TEST_NAME = "contextual_editing_test";
|
1491
1500
|
var CONTEXTUAL_EDITING_TEST_SELECTED_VARIANT_ID = "contextual_editing_test_selected_variant";
|
1492
|
-
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1501
|
+
var _serverTransitionState, _scores, _state, _pzCache, _plugins, _commands, _mitt3, _emitTest, emitTest_fn, _updateGoals, updateGoals_fn, _updateComputedScores, updateComputedScores_fn, _calculateScores, calculateScores_fn;
|
1493
1502
|
var Context = class {
|
1494
1503
|
constructor(options) {
|
1495
1504
|
__privateAdd(this, _emitTest);
|
@@ -1502,6 +1511,7 @@ var Context = class {
|
|
1502
1511
|
__privateAdd(this, _state, void 0);
|
1503
1512
|
__privateAdd(this, _pzCache, {});
|
1504
1513
|
__privateAdd(this, _plugins, void 0);
|
1514
|
+
__privateAdd(this, _commands, void 0);
|
1505
1515
|
__privateAdd(this, _mitt3, mitt3());
|
1506
1516
|
/**
|
1507
1517
|
* Subscribe to events
|
@@ -1515,6 +1525,9 @@ var Context = class {
|
|
1515
1525
|
const { manifest, ...storageOptions } = options;
|
1516
1526
|
__privateSet(this, _state, {});
|
1517
1527
|
__privateSet(this, _plugins, options.plugins);
|
1528
|
+
if (typeof options.transitionStore !== "undefined") {
|
1529
|
+
__privateSet(this, _commands, []);
|
1530
|
+
}
|
1518
1531
|
(_a = __privateGet(this, _plugins)) == null ? void 0 : _a.forEach((plugin) => {
|
1519
1532
|
if (!plugin.logDrain) {
|
1520
1533
|
return;
|
@@ -1595,7 +1608,7 @@ var Context = class {
|
|
1595
1608
|
* will NOT result in a recomputation of signal state.
|
1596
1609
|
*/
|
1597
1610
|
async update(newData) {
|
1598
|
-
var _a, _b, _c, _d;
|
1611
|
+
var _a, _b, _c, _d, _e;
|
1599
1612
|
const commands = [];
|
1600
1613
|
const newServerSideTests = {};
|
1601
1614
|
if ((_a = __privateGet(this, _serverTransitionState)) == null ? void 0 : _a.quirks) {
|
@@ -1690,6 +1703,10 @@ var Context = class {
|
|
1690
1703
|
});
|
1691
1704
|
await this.storage.updateData(commands);
|
1692
1705
|
if (__privateGet(this, _serverTransitionState)) {
|
1706
|
+
await this.processServerCommands({
|
1707
|
+
serverCommands: __privateGet(this, _serverTransitionState).commands,
|
1708
|
+
commands
|
1709
|
+
});
|
1693
1710
|
__privateMethod(this, _updateComputedScores, updateComputedScores_fn).call(this, this.storage.data);
|
1694
1711
|
Object.entries(newServerSideTests).forEach(([testName, testVariantId]) => {
|
1695
1712
|
__privateMethod(this, _emitTest, emitTest_fn).call(this, {
|
@@ -1710,10 +1727,31 @@ var Context = class {
|
|
1710
1727
|
await plugin.update(newData);
|
1711
1728
|
}
|
1712
1729
|
}
|
1730
|
+
(_e = __privateGet(this, _commands)) == null ? void 0 : _e.push(...commands);
|
1713
1731
|
} finally {
|
1714
1732
|
__privateGet(this, _mitt3).emit("log", ["info", 2, "ENDGROUP"]);
|
1715
1733
|
}
|
1716
1734
|
}
|
1735
|
+
async processServerCommands({
|
1736
|
+
serverCommands,
|
1737
|
+
commands
|
1738
|
+
}) {
|
1739
|
+
if (!(serverCommands == null ? void 0 : serverCommands.length)) {
|
1740
|
+
return;
|
1741
|
+
}
|
1742
|
+
const notExecutedCommands = [];
|
1743
|
+
serverCommands.forEach((serverCommand) => {
|
1744
|
+
const found = commands.find((command) => {
|
1745
|
+
return areCommandsEqual(command, serverCommand);
|
1746
|
+
});
|
1747
|
+
if (!found) {
|
1748
|
+
notExecutedCommands.push(serverCommand);
|
1749
|
+
}
|
1750
|
+
});
|
1751
|
+
if (notExecutedCommands.length > 0) {
|
1752
|
+
await this.storage.updateData(notExecutedCommands);
|
1753
|
+
}
|
1754
|
+
}
|
1717
1755
|
/** use test() instead */
|
1718
1756
|
getTestVariantId(testName) {
|
1719
1757
|
var _a, _b, _c, _d;
|
@@ -1792,7 +1830,7 @@ var Context = class {
|
|
1792
1830
|
control: this.storage.data.controlGroup,
|
1793
1831
|
changed: true
|
1794
1832
|
};
|
1795
|
-
if (previousPlacement &&
|
1833
|
+
if (previousPlacement && dequal5(eventData.variantIds, previousPlacement)) {
|
1796
1834
|
eventData.changed = false;
|
1797
1835
|
}
|
1798
1836
|
__privateGet(this, _mitt3).emit("personalizationResult", eventData);
|
@@ -1826,7 +1864,8 @@ var Context = class {
|
|
1826
1864
|
quirks: this.storage.data.quirks,
|
1827
1865
|
ssv: __privateGet(this, _scores),
|
1828
1866
|
tests: {},
|
1829
|
-
personalizeVariants: this.storage.data.personalizeVariants
|
1867
|
+
personalizeVariants: this.storage.data.personalizeVariants,
|
1868
|
+
commands: __privateGet(this, _commands)
|
1830
1869
|
};
|
1831
1870
|
const allTests = this.storage.data.tests;
|
1832
1871
|
Object.entries(allTests).map(([testName, testValue]) => {
|
@@ -1855,6 +1894,7 @@ _scores = new WeakMap();
|
|
1855
1894
|
_state = new WeakMap();
|
1856
1895
|
_pzCache = new WeakMap();
|
1857
1896
|
_plugins = new WeakMap();
|
1897
|
+
_commands = new WeakMap();
|
1858
1898
|
_mitt3 = new WeakMap();
|
1859
1899
|
_emitTest = new WeakSet();
|
1860
1900
|
emitTest_fn = function(event) {
|
@@ -1870,7 +1910,7 @@ updateGoals_fn = async function(data) {
|
|
1870
1910
|
_updateComputedScores = new WeakSet();
|
1871
1911
|
updateComputedScores_fn = function(newData) {
|
1872
1912
|
const newScores = __privateMethod(this, _calculateScores, calculateScores_fn).call(this, newData);
|
1873
|
-
const newScoresHaveChanged = !
|
1913
|
+
const newScoresHaveChanged = !dequal5(newScores, __privateGet(this, _scores));
|
1874
1914
|
if (newScoresHaveChanged) {
|
1875
1915
|
__privateSet(this, _scores, newScores);
|
1876
1916
|
__privateMethod(this, _updateGoals, updateGoals_fn).call(this, {
|
@@ -2030,10 +2070,16 @@ var getBasePayload = () => {
|
|
2030
2070
|
};
|
2031
2071
|
};
|
2032
2072
|
var createInsightsClient = ({ endpoint }) => {
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2073
|
+
let endpointUrl;
|
2074
|
+
const apiKey = endpoint.apiKey;
|
2075
|
+
if (endpoint.type === "api") {
|
2076
|
+
const url = new URL(endpoint.host);
|
2077
|
+
url.pathname = "/v0/events";
|
2078
|
+
url.searchParams.set("name", "analytics_events");
|
2079
|
+
endpointUrl = url.toString();
|
2080
|
+
} else {
|
2081
|
+
endpointUrl = endpoint.path;
|
2082
|
+
}
|
2037
2083
|
const sendMessage = async (message) => {
|
2038
2084
|
if (typeof window.__UNIFORM_CONTEXTUAL_EDITING__ !== "undefined") {
|
2039
2085
|
return;
|
@@ -2042,12 +2088,15 @@ var createInsightsClient = ({ endpoint }) => {
|
|
2042
2088
|
...message,
|
2043
2089
|
payload: JSON.stringify(message.payload)
|
2044
2090
|
};
|
2091
|
+
const headers = {
|
2092
|
+
"Content-Type": "application/json"
|
2093
|
+
};
|
2094
|
+
if (apiKey) {
|
2095
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
2096
|
+
}
|
2045
2097
|
const response = await fetch(endpointUrl, {
|
2046
2098
|
method: "POST",
|
2047
|
-
headers
|
2048
|
-
"Content-Type": "application/json",
|
2049
|
-
Authorization: `Bearer ${endpoint.apiKey}`
|
2050
|
-
},
|
2099
|
+
headers,
|
2051
2100
|
body: JSON.stringify(converted)
|
2052
2101
|
});
|
2053
2102
|
const json = await response.json();
|
@@ -2541,6 +2590,7 @@ export {
|
|
2541
2590
|
TransitionDataStore,
|
2542
2591
|
UNIFORM_DEFAULT_COOKIE_NAME,
|
2543
2592
|
VisitorDataStore,
|
2593
|
+
areCommandsEqual,
|
2544
2594
|
computeAggregateDimensions,
|
2545
2595
|
cookieEvaluator,
|
2546
2596
|
createConsoleLogDrain,
|