posthog-node 4.18.0 → 5.0.0
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/CHANGELOG.md +18 -0
- package/lib/edge/index.cjs +70 -505
- package/lib/edge/index.cjs.map +1 -1
- package/lib/edge/index.mjs +70 -505
- package/lib/edge/index.mjs.map +1 -1
- package/lib/index.d.ts +12 -8
- package/lib/node/index.cjs +70 -505
- package/lib/node/index.cjs.map +1 -1
- package/lib/node/index.mjs +70 -505
- package/lib/node/index.mjs.map +1 -1
- package/package.json +3 -6
package/lib/node/index.mjs
CHANGED
|
@@ -1318,7 +1318,7 @@ function snipLine(line, colno) {
|
|
|
1318
1318
|
return newLine;
|
|
1319
1319
|
}
|
|
1320
1320
|
|
|
1321
|
-
var version = "
|
|
1321
|
+
var version = "5.0.0";
|
|
1322
1322
|
|
|
1323
1323
|
var PostHogPersistedProperty;
|
|
1324
1324
|
(function (PostHogPersistedProperty) {
|
|
@@ -1348,6 +1348,12 @@ var PostHogPersistedProperty;
|
|
|
1348
1348
|
PostHogPersistedProperty["Surveys"] = "surveys";
|
|
1349
1349
|
PostHogPersistedProperty["RemoteConfig"] = "remote_config";
|
|
1350
1350
|
})(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
|
|
1351
|
+
// Any key prefixed with `attr__` can be added
|
|
1352
|
+
var Compression;
|
|
1353
|
+
(function (Compression) {
|
|
1354
|
+
Compression["GZipJS"] = "gzip-js";
|
|
1355
|
+
Compression["Base64"] = "base64";
|
|
1356
|
+
})(Compression || (Compression = {}));
|
|
1351
1357
|
var SurveyPosition;
|
|
1352
1358
|
(function (SurveyPosition) {
|
|
1353
1359
|
SurveyPosition["Left"] = "left";
|
|
@@ -1610,9 +1616,6 @@ async function retriable(fn, props) {
|
|
|
1610
1616
|
}
|
|
1611
1617
|
throw lastError;
|
|
1612
1618
|
}
|
|
1613
|
-
function currentTimestamp() {
|
|
1614
|
-
return new Date().getTime();
|
|
1615
|
-
}
|
|
1616
1619
|
function currentISOTime() {
|
|
1617
1620
|
return new Date().toISOString();
|
|
1618
1621
|
}
|
|
@@ -1624,9 +1627,6 @@ function safeSetTimeout(fn, timeout) {
|
|
|
1624
1627
|
t?.unref && t?.unref();
|
|
1625
1628
|
return t;
|
|
1626
1629
|
}
|
|
1627
|
-
function getFetch() {
|
|
1628
|
-
return typeof fetch !== 'undefined' ? fetch : typeof globalThis.fetch !== 'undefined' ? globalThis.fetch : undefined;
|
|
1629
|
-
}
|
|
1630
1630
|
// FNV-1a hash function
|
|
1631
1631
|
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
|
1632
1632
|
// I know, I know, I'm rolling my own hash function, but I didn't want to take on
|
|
@@ -1655,436 +1655,33 @@ function allSettled(promises) {
|
|
|
1655
1655
|
return Promise.all(promises.map((p) => (p ?? Promise.resolve()).then((value) => ({ status: 'fulfilled', value }), (reason) => ({ status: 'rejected', reason }))));
|
|
1656
1656
|
}
|
|
1657
1657
|
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
// http://pieroxy.net/blog/pages/lz-string/testing.html
|
|
1665
|
-
//
|
|
1666
|
-
// LZ-based compression algorithm, version 1.4.4
|
|
1667
|
-
// private property
|
|
1668
|
-
const f = String.fromCharCode;
|
|
1669
|
-
const keyStrBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
1670
|
-
const baseReverseDic = {};
|
|
1671
|
-
function getBaseValue(alphabet, character) {
|
|
1672
|
-
if (!baseReverseDic[alphabet]) {
|
|
1673
|
-
baseReverseDic[alphabet] = {};
|
|
1674
|
-
for (let i = 0; i < alphabet.length; i++) {
|
|
1675
|
-
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
return baseReverseDic[alphabet][character];
|
|
1658
|
+
/**
|
|
1659
|
+
* Older browsers and some runtimes don't support this yet
|
|
1660
|
+
* This API (as of 2025-05-07) is not available on React Native.
|
|
1661
|
+
*/
|
|
1662
|
+
function isGzipSupported() {
|
|
1663
|
+
return 'CompressionStream' in globalThis;
|
|
1679
1664
|
}
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
)
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
return res + '==';
|
|
1697
|
-
case 3:
|
|
1698
|
-
return res + '=';
|
|
1699
|
-
}
|
|
1700
|
-
},
|
|
1701
|
-
decompressFromBase64: function (input) {
|
|
1702
|
-
if (input == null) {
|
|
1703
|
-
return '';
|
|
1704
|
-
}
|
|
1705
|
-
if (input == '') {
|
|
1706
|
-
return null;
|
|
1707
|
-
}
|
|
1708
|
-
return LZString._decompress(input.length, 32, function (index) {
|
|
1709
|
-
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
1710
|
-
});
|
|
1711
|
-
},
|
|
1712
|
-
compress: function (uncompressed) {
|
|
1713
|
-
return LZString._compress(uncompressed, 16, function (a) {
|
|
1714
|
-
return f(a);
|
|
1715
|
-
});
|
|
1716
|
-
},
|
|
1717
|
-
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
1718
|
-
if (uncompressed == null) {
|
|
1719
|
-
return '';
|
|
1720
|
-
}
|
|
1721
|
-
const context_dictionary = {}, context_dictionaryToCreate = {}, context_data = [];
|
|
1722
|
-
let i, value, context_c = '', context_wc = '', context_w = '', context_enlargeIn = 2, // Compensate for the first entry which should not count
|
|
1723
|
-
context_dictSize = 3, context_numBits = 2, context_data_val = 0, context_data_position = 0, ii;
|
|
1724
|
-
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
1725
|
-
context_c = uncompressed.charAt(ii);
|
|
1726
|
-
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
1727
|
-
context_dictionary[context_c] = context_dictSize++;
|
|
1728
|
-
context_dictionaryToCreate[context_c] = true;
|
|
1729
|
-
}
|
|
1730
|
-
context_wc = context_w + context_c;
|
|
1731
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
|
|
1732
|
-
context_w = context_wc;
|
|
1733
|
-
}
|
|
1734
|
-
else {
|
|
1735
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
1736
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
1737
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1738
|
-
context_data_val = context_data_val << 1;
|
|
1739
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1740
|
-
context_data_position = 0;
|
|
1741
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1742
|
-
context_data_val = 0;
|
|
1743
|
-
}
|
|
1744
|
-
else {
|
|
1745
|
-
context_data_position++;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
value = context_w.charCodeAt(0);
|
|
1749
|
-
for (i = 0; i < 8; i++) {
|
|
1750
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1751
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1752
|
-
context_data_position = 0;
|
|
1753
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1754
|
-
context_data_val = 0;
|
|
1755
|
-
}
|
|
1756
|
-
else {
|
|
1757
|
-
context_data_position++;
|
|
1758
|
-
}
|
|
1759
|
-
value = value >> 1;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
else {
|
|
1763
|
-
value = 1;
|
|
1764
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1765
|
-
context_data_val = (context_data_val << 1) | value;
|
|
1766
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1767
|
-
context_data_position = 0;
|
|
1768
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1769
|
-
context_data_val = 0;
|
|
1770
|
-
}
|
|
1771
|
-
else {
|
|
1772
|
-
context_data_position++;
|
|
1773
|
-
}
|
|
1774
|
-
value = 0;
|
|
1775
|
-
}
|
|
1776
|
-
value = context_w.charCodeAt(0);
|
|
1777
|
-
for (i = 0; i < 16; i++) {
|
|
1778
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1779
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1780
|
-
context_data_position = 0;
|
|
1781
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1782
|
-
context_data_val = 0;
|
|
1783
|
-
}
|
|
1784
|
-
else {
|
|
1785
|
-
context_data_position++;
|
|
1786
|
-
}
|
|
1787
|
-
value = value >> 1;
|
|
1788
|
-
}
|
|
1789
|
-
}
|
|
1790
|
-
context_enlargeIn--;
|
|
1791
|
-
if (context_enlargeIn == 0) {
|
|
1792
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1793
|
-
context_numBits++;
|
|
1794
|
-
}
|
|
1795
|
-
delete context_dictionaryToCreate[context_w];
|
|
1796
|
-
}
|
|
1797
|
-
else {
|
|
1798
|
-
value = context_dictionary[context_w];
|
|
1799
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1800
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1801
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1802
|
-
context_data_position = 0;
|
|
1803
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1804
|
-
context_data_val = 0;
|
|
1805
|
-
}
|
|
1806
|
-
else {
|
|
1807
|
-
context_data_position++;
|
|
1808
|
-
}
|
|
1809
|
-
value = value >> 1;
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
context_enlargeIn--;
|
|
1813
|
-
if (context_enlargeIn == 0) {
|
|
1814
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1815
|
-
context_numBits++;
|
|
1816
|
-
}
|
|
1817
|
-
// Add wc to the dictionary.
|
|
1818
|
-
context_dictionary[context_wc] = context_dictSize++;
|
|
1819
|
-
context_w = String(context_c);
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
// Output the code for w.
|
|
1823
|
-
if (context_w !== '') {
|
|
1824
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
1825
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
1826
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1827
|
-
context_data_val = context_data_val << 1;
|
|
1828
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1829
|
-
context_data_position = 0;
|
|
1830
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1831
|
-
context_data_val = 0;
|
|
1832
|
-
}
|
|
1833
|
-
else {
|
|
1834
|
-
context_data_position++;
|
|
1835
|
-
}
|
|
1836
|
-
}
|
|
1837
|
-
value = context_w.charCodeAt(0);
|
|
1838
|
-
for (i = 0; i < 8; i++) {
|
|
1839
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1840
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1841
|
-
context_data_position = 0;
|
|
1842
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1843
|
-
context_data_val = 0;
|
|
1844
|
-
}
|
|
1845
|
-
else {
|
|
1846
|
-
context_data_position++;
|
|
1847
|
-
}
|
|
1848
|
-
value = value >> 1;
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
else {
|
|
1852
|
-
value = 1;
|
|
1853
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1854
|
-
context_data_val = (context_data_val << 1) | value;
|
|
1855
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1856
|
-
context_data_position = 0;
|
|
1857
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1858
|
-
context_data_val = 0;
|
|
1859
|
-
}
|
|
1860
|
-
else {
|
|
1861
|
-
context_data_position++;
|
|
1862
|
-
}
|
|
1863
|
-
value = 0;
|
|
1864
|
-
}
|
|
1865
|
-
value = context_w.charCodeAt(0);
|
|
1866
|
-
for (i = 0; i < 16; i++) {
|
|
1867
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1868
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1869
|
-
context_data_position = 0;
|
|
1870
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1871
|
-
context_data_val = 0;
|
|
1872
|
-
}
|
|
1873
|
-
else {
|
|
1874
|
-
context_data_position++;
|
|
1875
|
-
}
|
|
1876
|
-
value = value >> 1;
|
|
1877
|
-
}
|
|
1878
|
-
}
|
|
1879
|
-
context_enlargeIn--;
|
|
1880
|
-
if (context_enlargeIn == 0) {
|
|
1881
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1882
|
-
context_numBits++;
|
|
1883
|
-
}
|
|
1884
|
-
delete context_dictionaryToCreate[context_w];
|
|
1885
|
-
}
|
|
1886
|
-
else {
|
|
1887
|
-
value = context_dictionary[context_w];
|
|
1888
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1889
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1890
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1891
|
-
context_data_position = 0;
|
|
1892
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1893
|
-
context_data_val = 0;
|
|
1894
|
-
}
|
|
1895
|
-
else {
|
|
1896
|
-
context_data_position++;
|
|
1897
|
-
}
|
|
1898
|
-
value = value >> 1;
|
|
1899
|
-
}
|
|
1900
|
-
}
|
|
1901
|
-
context_enlargeIn--;
|
|
1902
|
-
if (context_enlargeIn == 0) {
|
|
1903
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1904
|
-
context_numBits++;
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
// Mark the end of the stream
|
|
1908
|
-
value = 2;
|
|
1909
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1910
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1911
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1912
|
-
context_data_position = 0;
|
|
1913
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1914
|
-
context_data_val = 0;
|
|
1915
|
-
}
|
|
1916
|
-
else {
|
|
1917
|
-
context_data_position++;
|
|
1918
|
-
}
|
|
1919
|
-
value = value >> 1;
|
|
1920
|
-
}
|
|
1921
|
-
// Flush the last char
|
|
1922
|
-
while (true) {
|
|
1923
|
-
context_data_val = context_data_val << 1;
|
|
1924
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1925
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1926
|
-
break;
|
|
1927
|
-
}
|
|
1928
|
-
else {
|
|
1929
|
-
context_data_position++;
|
|
1930
|
-
}
|
|
1931
|
-
}
|
|
1932
|
-
return context_data.join('');
|
|
1933
|
-
},
|
|
1934
|
-
decompress: function (compressed) {
|
|
1935
|
-
if (compressed == null) {
|
|
1936
|
-
return '';
|
|
1937
|
-
}
|
|
1938
|
-
if (compressed == '') {
|
|
1939
|
-
return null;
|
|
1940
|
-
}
|
|
1941
|
-
return LZString._decompress(compressed.length, 32768, function (index) {
|
|
1942
|
-
return compressed.charCodeAt(index);
|
|
1943
|
-
});
|
|
1944
|
-
},
|
|
1945
|
-
_decompress: function (length, resetValue, getNextValue) {
|
|
1946
|
-
const dictionary = [], result = [], data = { val: getNextValue(0), position: resetValue, index: 1 };
|
|
1947
|
-
let enlargeIn = 4, dictSize = 4, numBits = 3, entry = '', i, w, bits, resb, maxpower, power, c;
|
|
1948
|
-
for (i = 0; i < 3; i += 1) {
|
|
1949
|
-
dictionary[i] = i;
|
|
1950
|
-
}
|
|
1951
|
-
bits = 0;
|
|
1952
|
-
maxpower = Math.pow(2, 2);
|
|
1953
|
-
power = 1;
|
|
1954
|
-
while (power != maxpower) {
|
|
1955
|
-
resb = data.val & data.position;
|
|
1956
|
-
data.position >>= 1;
|
|
1957
|
-
if (data.position == 0) {
|
|
1958
|
-
data.position = resetValue;
|
|
1959
|
-
data.val = getNextValue(data.index++);
|
|
1960
|
-
}
|
|
1961
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1962
|
-
power <<= 1;
|
|
1963
|
-
}
|
|
1964
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1965
|
-
switch ((bits)) {
|
|
1966
|
-
case 0:
|
|
1967
|
-
bits = 0;
|
|
1968
|
-
maxpower = Math.pow(2, 8);
|
|
1969
|
-
power = 1;
|
|
1970
|
-
while (power != maxpower) {
|
|
1971
|
-
resb = data.val & data.position;
|
|
1972
|
-
data.position >>= 1;
|
|
1973
|
-
if (data.position == 0) {
|
|
1974
|
-
data.position = resetValue;
|
|
1975
|
-
data.val = getNextValue(data.index++);
|
|
1976
|
-
}
|
|
1977
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1978
|
-
power <<= 1;
|
|
1979
|
-
}
|
|
1980
|
-
c = f(bits);
|
|
1981
|
-
break;
|
|
1982
|
-
case 1:
|
|
1983
|
-
bits = 0;
|
|
1984
|
-
maxpower = Math.pow(2, 16);
|
|
1985
|
-
power = 1;
|
|
1986
|
-
while (power != maxpower) {
|
|
1987
|
-
resb = data.val & data.position;
|
|
1988
|
-
data.position >>= 1;
|
|
1989
|
-
if (data.position == 0) {
|
|
1990
|
-
data.position = resetValue;
|
|
1991
|
-
data.val = getNextValue(data.index++);
|
|
1992
|
-
}
|
|
1993
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1994
|
-
power <<= 1;
|
|
1995
|
-
}
|
|
1996
|
-
c = f(bits);
|
|
1997
|
-
break;
|
|
1998
|
-
case 2:
|
|
1999
|
-
return '';
|
|
2000
|
-
}
|
|
2001
|
-
dictionary[3] = c;
|
|
2002
|
-
w = c;
|
|
2003
|
-
result.push(c);
|
|
2004
|
-
while (true) {
|
|
2005
|
-
if (data.index > length) {
|
|
2006
|
-
return '';
|
|
2007
|
-
}
|
|
2008
|
-
bits = 0;
|
|
2009
|
-
maxpower = Math.pow(2, numBits);
|
|
2010
|
-
power = 1;
|
|
2011
|
-
while (power != maxpower) {
|
|
2012
|
-
resb = data.val & data.position;
|
|
2013
|
-
data.position >>= 1;
|
|
2014
|
-
if (data.position == 0) {
|
|
2015
|
-
data.position = resetValue;
|
|
2016
|
-
data.val = getNextValue(data.index++);
|
|
2017
|
-
}
|
|
2018
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2019
|
-
power <<= 1;
|
|
2020
|
-
}
|
|
2021
|
-
switch ((c = bits)) {
|
|
2022
|
-
case 0:
|
|
2023
|
-
bits = 0;
|
|
2024
|
-
maxpower = Math.pow(2, 8);
|
|
2025
|
-
power = 1;
|
|
2026
|
-
while (power != maxpower) {
|
|
2027
|
-
resb = data.val & data.position;
|
|
2028
|
-
data.position >>= 1;
|
|
2029
|
-
if (data.position == 0) {
|
|
2030
|
-
data.position = resetValue;
|
|
2031
|
-
data.val = getNextValue(data.index++);
|
|
2032
|
-
}
|
|
2033
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2034
|
-
power <<= 1;
|
|
2035
|
-
}
|
|
2036
|
-
dictionary[dictSize++] = f(bits);
|
|
2037
|
-
c = dictSize - 1;
|
|
2038
|
-
enlargeIn--;
|
|
2039
|
-
break;
|
|
2040
|
-
case 1:
|
|
2041
|
-
bits = 0;
|
|
2042
|
-
maxpower = Math.pow(2, 16);
|
|
2043
|
-
power = 1;
|
|
2044
|
-
while (power != maxpower) {
|
|
2045
|
-
resb = data.val & data.position;
|
|
2046
|
-
data.position >>= 1;
|
|
2047
|
-
if (data.position == 0) {
|
|
2048
|
-
data.position = resetValue;
|
|
2049
|
-
data.val = getNextValue(data.index++);
|
|
2050
|
-
}
|
|
2051
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
2052
|
-
power <<= 1;
|
|
2053
|
-
}
|
|
2054
|
-
dictionary[dictSize++] = f(bits);
|
|
2055
|
-
c = dictSize - 1;
|
|
2056
|
-
enlargeIn--;
|
|
2057
|
-
break;
|
|
2058
|
-
case 2:
|
|
2059
|
-
return result.join('');
|
|
2060
|
-
}
|
|
2061
|
-
if (enlargeIn == 0) {
|
|
2062
|
-
enlargeIn = Math.pow(2, numBits);
|
|
2063
|
-
numBits++;
|
|
2064
|
-
}
|
|
2065
|
-
if (dictionary[c]) {
|
|
2066
|
-
entry = dictionary[c];
|
|
2067
|
-
}
|
|
2068
|
-
else {
|
|
2069
|
-
if (c === dictSize) {
|
|
2070
|
-
entry = w + w.charAt(0);
|
|
2071
|
-
}
|
|
2072
|
-
else {
|
|
2073
|
-
return null;
|
|
2074
|
-
}
|
|
2075
|
-
}
|
|
2076
|
-
result.push(entry);
|
|
2077
|
-
// Add w+entry[0] to the dictionary.
|
|
2078
|
-
dictionary[dictSize++] = w + entry.charAt(0);
|
|
2079
|
-
enlargeIn--;
|
|
2080
|
-
w = entry;
|
|
2081
|
-
if (enlargeIn == 0) {
|
|
2082
|
-
enlargeIn = Math.pow(2, numBits);
|
|
2083
|
-
numBits++;
|
|
2084
|
-
}
|
|
1665
|
+
/**
|
|
1666
|
+
* Gzip a string using Compression Streams API if it's available
|
|
1667
|
+
*/
|
|
1668
|
+
async function gzipCompress(input, isDebug = true) {
|
|
1669
|
+
try {
|
|
1670
|
+
// Turn the string into a stream using a Blob, and then compress it
|
|
1671
|
+
const dataStream = new Blob([input], {
|
|
1672
|
+
type: 'text/plain',
|
|
1673
|
+
}).stream();
|
|
1674
|
+
const compressedStream = dataStream.pipeThrough(new CompressionStream('gzip'));
|
|
1675
|
+
// Using a Response to easily extract the readablestream value. Decoding into a string for fetch
|
|
1676
|
+
return await new Response(compressedStream).blob();
|
|
1677
|
+
}
|
|
1678
|
+
catch (error) {
|
|
1679
|
+
if (isDebug) {
|
|
1680
|
+
console.error('Failed to gzip compress data', error);
|
|
2085
1681
|
}
|
|
2086
|
-
|
|
2087
|
-
}
|
|
1682
|
+
return null;
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
2088
1685
|
|
|
2089
1686
|
class SimpleEventEmitter {
|
|
2090
1687
|
constructor() {
|
|
@@ -2177,7 +1774,6 @@ class PostHogCoreStateless {
|
|
|
2177
1774
|
this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100);
|
|
2178
1775
|
this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000);
|
|
2179
1776
|
this.flushInterval = options?.flushInterval ?? 10000;
|
|
2180
|
-
this.captureMode = options?.captureMode || 'json';
|
|
2181
1777
|
this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true;
|
|
2182
1778
|
// If enable is explicitly set to false we override the optout
|
|
2183
1779
|
this.defaultOptIn = options?.defaultOptIn ?? true;
|
|
@@ -2196,6 +1792,7 @@ class PostHogCoreStateless {
|
|
|
2196
1792
|
// Init promise allows the derived class to block calls until it is ready
|
|
2197
1793
|
this._initPromise = Promise.resolve();
|
|
2198
1794
|
this._isInitialized = true;
|
|
1795
|
+
this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false);
|
|
2199
1796
|
}
|
|
2200
1797
|
logMsgIfDebug(fn) {
|
|
2201
1798
|
if (this.isDebug) {
|
|
@@ -2617,22 +2214,17 @@ class PostHogCoreStateless {
|
|
|
2617
2214
|
data.historical_migration = true;
|
|
2618
2215
|
}
|
|
2619
2216
|
const payload = JSON.stringify(data);
|
|
2620
|
-
const url = this.
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
: {
|
|
2632
|
-
method: 'POST',
|
|
2633
|
-
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
2634
|
-
body: payload,
|
|
2635
|
-
};
|
|
2217
|
+
const url = `${this.host}/batch/`;
|
|
2218
|
+
const gzippedPayload = !this.disableCompression ? await gzipCompress(payload, this.isDebug) : null;
|
|
2219
|
+
const fetchOptions = {
|
|
2220
|
+
method: 'POST',
|
|
2221
|
+
headers: {
|
|
2222
|
+
...this.getCustomHeaders(),
|
|
2223
|
+
'Content-Type': 'application/json',
|
|
2224
|
+
...(gzippedPayload !== null && { 'Content-Encoding': 'gzip' }),
|
|
2225
|
+
},
|
|
2226
|
+
body: gzippedPayload || payload,
|
|
2227
|
+
};
|
|
2636
2228
|
try {
|
|
2637
2229
|
await this.fetchWithRetry(url, fetchOptions);
|
|
2638
2230
|
}
|
|
@@ -2756,22 +2348,17 @@ class PostHogCoreStateless {
|
|
|
2756
2348
|
data.historical_migration = true;
|
|
2757
2349
|
}
|
|
2758
2350
|
const payload = JSON.stringify(data);
|
|
2759
|
-
const url = this.
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
: {
|
|
2771
|
-
method: 'POST',
|
|
2772
|
-
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
2773
|
-
body: payload,
|
|
2774
|
-
};
|
|
2351
|
+
const url = `${this.host}/batch/`;
|
|
2352
|
+
const gzippedPayload = !this.disableCompression ? await gzipCompress(payload, this.isDebug) : null;
|
|
2353
|
+
const fetchOptions = {
|
|
2354
|
+
method: 'POST',
|
|
2355
|
+
headers: {
|
|
2356
|
+
...this.getCustomHeaders(),
|
|
2357
|
+
'Content-Type': 'application/json',
|
|
2358
|
+
...(gzippedPayload !== null && { 'Content-Encoding': 'gzip' }),
|
|
2359
|
+
},
|
|
2360
|
+
body: gzippedPayload || payload,
|
|
2361
|
+
};
|
|
2775
2362
|
const retryOptions = {
|
|
2776
2363
|
retryCheck: (err) => {
|
|
2777
2364
|
// don't automatically retry on 413 errors, we want to reduce the batch size first
|
|
@@ -2816,11 +2403,21 @@ class PostHogCoreStateless {
|
|
|
2816
2403
|
const body = options.body ? options.body : '';
|
|
2817
2404
|
let reqByteLength = -1;
|
|
2818
2405
|
try {
|
|
2819
|
-
|
|
2406
|
+
if (body instanceof Blob) {
|
|
2407
|
+
reqByteLength = body.size;
|
|
2408
|
+
}
|
|
2409
|
+
else {
|
|
2410
|
+
reqByteLength = Buffer.byteLength(body, STRING_FORMAT);
|
|
2411
|
+
}
|
|
2820
2412
|
}
|
|
2821
2413
|
catch {
|
|
2822
|
-
|
|
2823
|
-
|
|
2414
|
+
if (body instanceof Blob) {
|
|
2415
|
+
reqByteLength = body.size;
|
|
2416
|
+
}
|
|
2417
|
+
else {
|
|
2418
|
+
const encoded = new TextEncoder().encode(body);
|
|
2419
|
+
reqByteLength = encoded.length;
|
|
2420
|
+
}
|
|
2824
2421
|
}
|
|
2825
2422
|
return await retriable(async () => {
|
|
2826
2423
|
let res = null;
|
|
@@ -2903,38 +2500,6 @@ class PostHogCoreStateless {
|
|
|
2903
2500
|
}
|
|
2904
2501
|
}
|
|
2905
2502
|
|
|
2906
|
-
/**
|
|
2907
|
-
* Fetch wrapper
|
|
2908
|
-
*
|
|
2909
|
-
* We want to polyfill fetch when not available with axios but use it when it is.
|
|
2910
|
-
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
|
|
2911
|
-
* This is currently solved by using the global fetch if available instead.
|
|
2912
|
-
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
|
|
2913
|
-
*/
|
|
2914
|
-
let _fetch = getFetch();
|
|
2915
|
-
if (!_fetch) {
|
|
2916
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2917
|
-
const axios = require('axios');
|
|
2918
|
-
_fetch = async (url, options) => {
|
|
2919
|
-
const res = await axios.request({
|
|
2920
|
-
url,
|
|
2921
|
-
headers: options.headers,
|
|
2922
|
-
method: options.method.toLowerCase(),
|
|
2923
|
-
data: options.body,
|
|
2924
|
-
signal: options.signal,
|
|
2925
|
-
// fetch only throws on network errors, not on HTTP errors
|
|
2926
|
-
validateStatus: () => true
|
|
2927
|
-
});
|
|
2928
|
-
return {
|
|
2929
|
-
status: res.status,
|
|
2930
|
-
text: async () => res.data,
|
|
2931
|
-
json: async () => res.data
|
|
2932
|
-
};
|
|
2933
|
-
};
|
|
2934
|
-
}
|
|
2935
|
-
// NOTE: We have to export this as default, even though we prefer named exports as we are relying on detecting "fetch" in the global scope
|
|
2936
|
-
var fetch$1 = _fetch;
|
|
2937
|
-
|
|
2938
2503
|
/**
|
|
2939
2504
|
* A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
|
|
2940
2505
|
*/
|
|
@@ -3077,7 +2642,7 @@ class FeatureFlagsPoller {
|
|
|
3077
2642
|
this.projectApiKey = projectApiKey;
|
|
3078
2643
|
this.host = host;
|
|
3079
2644
|
this.poller = undefined;
|
|
3080
|
-
this.fetch = options.fetch || fetch
|
|
2645
|
+
this.fetch = options.fetch || fetch;
|
|
3081
2646
|
this.onError = options.onError;
|
|
3082
2647
|
this.customHeaders = customHeaders;
|
|
3083
2648
|
this.onLoad = options.onLoad;
|
|
@@ -3751,7 +3316,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3751
3316
|
return this._memoryStorage.setProperty(key, value);
|
|
3752
3317
|
}
|
|
3753
3318
|
fetch(url, options) {
|
|
3754
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch
|
|
3319
|
+
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
3755
3320
|
}
|
|
3756
3321
|
getLibraryVersion() {
|
|
3757
3322
|
return version;
|