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/edge/index.mjs
CHANGED
|
@@ -913,7 +913,7 @@ function setupExpressErrorHandler(_posthog, app) {
|
|
|
913
913
|
});
|
|
914
914
|
}
|
|
915
915
|
|
|
916
|
-
var version = "
|
|
916
|
+
var version = "5.0.0";
|
|
917
917
|
|
|
918
918
|
var PostHogPersistedProperty;
|
|
919
919
|
(function (PostHogPersistedProperty) {
|
|
@@ -943,6 +943,12 @@ var PostHogPersistedProperty;
|
|
|
943
943
|
PostHogPersistedProperty["Surveys"] = "surveys";
|
|
944
944
|
PostHogPersistedProperty["RemoteConfig"] = "remote_config";
|
|
945
945
|
})(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
|
|
946
|
+
// Any key prefixed with `attr__` can be added
|
|
947
|
+
var Compression;
|
|
948
|
+
(function (Compression) {
|
|
949
|
+
Compression["GZipJS"] = "gzip-js";
|
|
950
|
+
Compression["Base64"] = "base64";
|
|
951
|
+
})(Compression || (Compression = {}));
|
|
946
952
|
var SurveyPosition;
|
|
947
953
|
(function (SurveyPosition) {
|
|
948
954
|
SurveyPosition["Left"] = "left";
|
|
@@ -1205,9 +1211,6 @@ async function retriable(fn, props) {
|
|
|
1205
1211
|
}
|
|
1206
1212
|
throw lastError;
|
|
1207
1213
|
}
|
|
1208
|
-
function currentTimestamp() {
|
|
1209
|
-
return new Date().getTime();
|
|
1210
|
-
}
|
|
1211
1214
|
function currentISOTime() {
|
|
1212
1215
|
return new Date().toISOString();
|
|
1213
1216
|
}
|
|
@@ -1219,9 +1222,6 @@ function safeSetTimeout(fn, timeout) {
|
|
|
1219
1222
|
t?.unref && t?.unref();
|
|
1220
1223
|
return t;
|
|
1221
1224
|
}
|
|
1222
|
-
function getFetch() {
|
|
1223
|
-
return typeof fetch !== 'undefined' ? fetch : typeof globalThis.fetch !== 'undefined' ? globalThis.fetch : undefined;
|
|
1224
|
-
}
|
|
1225
1225
|
// FNV-1a hash function
|
|
1226
1226
|
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
|
1227
1227
|
// I know, I know, I'm rolling my own hash function, but I didn't want to take on
|
|
@@ -1250,436 +1250,33 @@ function allSettled(promises) {
|
|
|
1250
1250
|
return Promise.all(promises.map((p) => (p ?? Promise.resolve()).then((value) => ({ status: 'fulfilled', value }), (reason) => ({ status: 'rejected', reason }))));
|
|
1251
1251
|
}
|
|
1252
1252
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
// http://pieroxy.net/blog/pages/lz-string/testing.html
|
|
1260
|
-
//
|
|
1261
|
-
// LZ-based compression algorithm, version 1.4.4
|
|
1262
|
-
// private property
|
|
1263
|
-
const f = String.fromCharCode;
|
|
1264
|
-
const keyStrBase64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
1265
|
-
const baseReverseDic = {};
|
|
1266
|
-
function getBaseValue(alphabet, character) {
|
|
1267
|
-
if (!baseReverseDic[alphabet]) {
|
|
1268
|
-
baseReverseDic[alphabet] = {};
|
|
1269
|
-
for (let i = 0; i < alphabet.length; i++) {
|
|
1270
|
-
baseReverseDic[alphabet][alphabet.charAt(i)] = i;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return baseReverseDic[alphabet][character];
|
|
1253
|
+
/**
|
|
1254
|
+
* Older browsers and some runtimes don't support this yet
|
|
1255
|
+
* This API (as of 2025-05-07) is not available on React Native.
|
|
1256
|
+
*/
|
|
1257
|
+
function isGzipSupported() {
|
|
1258
|
+
return 'CompressionStream' in globalThis;
|
|
1274
1259
|
}
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
)
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
return res + '==';
|
|
1292
|
-
case 3:
|
|
1293
|
-
return res + '=';
|
|
1294
|
-
}
|
|
1295
|
-
},
|
|
1296
|
-
decompressFromBase64: function (input) {
|
|
1297
|
-
if (input == null) {
|
|
1298
|
-
return '';
|
|
1299
|
-
}
|
|
1300
|
-
if (input == '') {
|
|
1301
|
-
return null;
|
|
1302
|
-
}
|
|
1303
|
-
return LZString._decompress(input.length, 32, function (index) {
|
|
1304
|
-
return getBaseValue(keyStrBase64, input.charAt(index));
|
|
1305
|
-
});
|
|
1306
|
-
},
|
|
1307
|
-
compress: function (uncompressed) {
|
|
1308
|
-
return LZString._compress(uncompressed, 16, function (a) {
|
|
1309
|
-
return f(a);
|
|
1310
|
-
});
|
|
1311
|
-
},
|
|
1312
|
-
_compress: function (uncompressed, bitsPerChar, getCharFromInt) {
|
|
1313
|
-
if (uncompressed == null) {
|
|
1314
|
-
return '';
|
|
1315
|
-
}
|
|
1316
|
-
const context_dictionary = {}, context_dictionaryToCreate = {}, context_data = [];
|
|
1317
|
-
let i, value, context_c = '', context_wc = '', context_w = '', context_enlargeIn = 2, // Compensate for the first entry which should not count
|
|
1318
|
-
context_dictSize = 3, context_numBits = 2, context_data_val = 0, context_data_position = 0, ii;
|
|
1319
|
-
for (ii = 0; ii < uncompressed.length; ii += 1) {
|
|
1320
|
-
context_c = uncompressed.charAt(ii);
|
|
1321
|
-
if (!Object.prototype.hasOwnProperty.call(context_dictionary, context_c)) {
|
|
1322
|
-
context_dictionary[context_c] = context_dictSize++;
|
|
1323
|
-
context_dictionaryToCreate[context_c] = true;
|
|
1324
|
-
}
|
|
1325
|
-
context_wc = context_w + context_c;
|
|
1326
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionary, context_wc)) {
|
|
1327
|
-
context_w = context_wc;
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
1331
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
1332
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1333
|
-
context_data_val = context_data_val << 1;
|
|
1334
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1335
|
-
context_data_position = 0;
|
|
1336
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1337
|
-
context_data_val = 0;
|
|
1338
|
-
}
|
|
1339
|
-
else {
|
|
1340
|
-
context_data_position++;
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
value = context_w.charCodeAt(0);
|
|
1344
|
-
for (i = 0; i < 8; i++) {
|
|
1345
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1346
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1347
|
-
context_data_position = 0;
|
|
1348
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1349
|
-
context_data_val = 0;
|
|
1350
|
-
}
|
|
1351
|
-
else {
|
|
1352
|
-
context_data_position++;
|
|
1353
|
-
}
|
|
1354
|
-
value = value >> 1;
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
else {
|
|
1358
|
-
value = 1;
|
|
1359
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1360
|
-
context_data_val = (context_data_val << 1) | value;
|
|
1361
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1362
|
-
context_data_position = 0;
|
|
1363
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1364
|
-
context_data_val = 0;
|
|
1365
|
-
}
|
|
1366
|
-
else {
|
|
1367
|
-
context_data_position++;
|
|
1368
|
-
}
|
|
1369
|
-
value = 0;
|
|
1370
|
-
}
|
|
1371
|
-
value = context_w.charCodeAt(0);
|
|
1372
|
-
for (i = 0; i < 16; i++) {
|
|
1373
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1374
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1375
|
-
context_data_position = 0;
|
|
1376
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1377
|
-
context_data_val = 0;
|
|
1378
|
-
}
|
|
1379
|
-
else {
|
|
1380
|
-
context_data_position++;
|
|
1381
|
-
}
|
|
1382
|
-
value = value >> 1;
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
context_enlargeIn--;
|
|
1386
|
-
if (context_enlargeIn == 0) {
|
|
1387
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1388
|
-
context_numBits++;
|
|
1389
|
-
}
|
|
1390
|
-
delete context_dictionaryToCreate[context_w];
|
|
1391
|
-
}
|
|
1392
|
-
else {
|
|
1393
|
-
value = context_dictionary[context_w];
|
|
1394
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1395
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1396
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1397
|
-
context_data_position = 0;
|
|
1398
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1399
|
-
context_data_val = 0;
|
|
1400
|
-
}
|
|
1401
|
-
else {
|
|
1402
|
-
context_data_position++;
|
|
1403
|
-
}
|
|
1404
|
-
value = value >> 1;
|
|
1405
|
-
}
|
|
1406
|
-
}
|
|
1407
|
-
context_enlargeIn--;
|
|
1408
|
-
if (context_enlargeIn == 0) {
|
|
1409
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1410
|
-
context_numBits++;
|
|
1411
|
-
}
|
|
1412
|
-
// Add wc to the dictionary.
|
|
1413
|
-
context_dictionary[context_wc] = context_dictSize++;
|
|
1414
|
-
context_w = String(context_c);
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
// Output the code for w.
|
|
1418
|
-
if (context_w !== '') {
|
|
1419
|
-
if (Object.prototype.hasOwnProperty.call(context_dictionaryToCreate, context_w)) {
|
|
1420
|
-
if (context_w.charCodeAt(0) < 256) {
|
|
1421
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1422
|
-
context_data_val = context_data_val << 1;
|
|
1423
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1424
|
-
context_data_position = 0;
|
|
1425
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1426
|
-
context_data_val = 0;
|
|
1427
|
-
}
|
|
1428
|
-
else {
|
|
1429
|
-
context_data_position++;
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
value = context_w.charCodeAt(0);
|
|
1433
|
-
for (i = 0; i < 8; i++) {
|
|
1434
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1435
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1436
|
-
context_data_position = 0;
|
|
1437
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1438
|
-
context_data_val = 0;
|
|
1439
|
-
}
|
|
1440
|
-
else {
|
|
1441
|
-
context_data_position++;
|
|
1442
|
-
}
|
|
1443
|
-
value = value >> 1;
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
else {
|
|
1447
|
-
value = 1;
|
|
1448
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1449
|
-
context_data_val = (context_data_val << 1) | value;
|
|
1450
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1451
|
-
context_data_position = 0;
|
|
1452
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1453
|
-
context_data_val = 0;
|
|
1454
|
-
}
|
|
1455
|
-
else {
|
|
1456
|
-
context_data_position++;
|
|
1457
|
-
}
|
|
1458
|
-
value = 0;
|
|
1459
|
-
}
|
|
1460
|
-
value = context_w.charCodeAt(0);
|
|
1461
|
-
for (i = 0; i < 16; i++) {
|
|
1462
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1463
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1464
|
-
context_data_position = 0;
|
|
1465
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1466
|
-
context_data_val = 0;
|
|
1467
|
-
}
|
|
1468
|
-
else {
|
|
1469
|
-
context_data_position++;
|
|
1470
|
-
}
|
|
1471
|
-
value = value >> 1;
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
context_enlargeIn--;
|
|
1475
|
-
if (context_enlargeIn == 0) {
|
|
1476
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1477
|
-
context_numBits++;
|
|
1478
|
-
}
|
|
1479
|
-
delete context_dictionaryToCreate[context_w];
|
|
1480
|
-
}
|
|
1481
|
-
else {
|
|
1482
|
-
value = context_dictionary[context_w];
|
|
1483
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1484
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1485
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1486
|
-
context_data_position = 0;
|
|
1487
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1488
|
-
context_data_val = 0;
|
|
1489
|
-
}
|
|
1490
|
-
else {
|
|
1491
|
-
context_data_position++;
|
|
1492
|
-
}
|
|
1493
|
-
value = value >> 1;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
context_enlargeIn--;
|
|
1497
|
-
if (context_enlargeIn == 0) {
|
|
1498
|
-
context_enlargeIn = Math.pow(2, context_numBits);
|
|
1499
|
-
context_numBits++;
|
|
1500
|
-
}
|
|
1501
|
-
}
|
|
1502
|
-
// Mark the end of the stream
|
|
1503
|
-
value = 2;
|
|
1504
|
-
for (i = 0; i < context_numBits; i++) {
|
|
1505
|
-
context_data_val = (context_data_val << 1) | (value & 1);
|
|
1506
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1507
|
-
context_data_position = 0;
|
|
1508
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1509
|
-
context_data_val = 0;
|
|
1510
|
-
}
|
|
1511
|
-
else {
|
|
1512
|
-
context_data_position++;
|
|
1513
|
-
}
|
|
1514
|
-
value = value >> 1;
|
|
1515
|
-
}
|
|
1516
|
-
// Flush the last char
|
|
1517
|
-
while (true) {
|
|
1518
|
-
context_data_val = context_data_val << 1;
|
|
1519
|
-
if (context_data_position == bitsPerChar - 1) {
|
|
1520
|
-
context_data.push(getCharFromInt(context_data_val));
|
|
1521
|
-
break;
|
|
1522
|
-
}
|
|
1523
|
-
else {
|
|
1524
|
-
context_data_position++;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
return context_data.join('');
|
|
1528
|
-
},
|
|
1529
|
-
decompress: function (compressed) {
|
|
1530
|
-
if (compressed == null) {
|
|
1531
|
-
return '';
|
|
1532
|
-
}
|
|
1533
|
-
if (compressed == '') {
|
|
1534
|
-
return null;
|
|
1535
|
-
}
|
|
1536
|
-
return LZString._decompress(compressed.length, 32768, function (index) {
|
|
1537
|
-
return compressed.charCodeAt(index);
|
|
1538
|
-
});
|
|
1539
|
-
},
|
|
1540
|
-
_decompress: function (length, resetValue, getNextValue) {
|
|
1541
|
-
const dictionary = [], result = [], data = { val: getNextValue(0), position: resetValue, index: 1 };
|
|
1542
|
-
let enlargeIn = 4, dictSize = 4, numBits = 3, entry = '', i, w, bits, resb, maxpower, power, c;
|
|
1543
|
-
for (i = 0; i < 3; i += 1) {
|
|
1544
|
-
dictionary[i] = i;
|
|
1545
|
-
}
|
|
1546
|
-
bits = 0;
|
|
1547
|
-
maxpower = Math.pow(2, 2);
|
|
1548
|
-
power = 1;
|
|
1549
|
-
while (power != maxpower) {
|
|
1550
|
-
resb = data.val & data.position;
|
|
1551
|
-
data.position >>= 1;
|
|
1552
|
-
if (data.position == 0) {
|
|
1553
|
-
data.position = resetValue;
|
|
1554
|
-
data.val = getNextValue(data.index++);
|
|
1555
|
-
}
|
|
1556
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1557
|
-
power <<= 1;
|
|
1558
|
-
}
|
|
1559
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
1560
|
-
switch ((bits)) {
|
|
1561
|
-
case 0:
|
|
1562
|
-
bits = 0;
|
|
1563
|
-
maxpower = Math.pow(2, 8);
|
|
1564
|
-
power = 1;
|
|
1565
|
-
while (power != maxpower) {
|
|
1566
|
-
resb = data.val & data.position;
|
|
1567
|
-
data.position >>= 1;
|
|
1568
|
-
if (data.position == 0) {
|
|
1569
|
-
data.position = resetValue;
|
|
1570
|
-
data.val = getNextValue(data.index++);
|
|
1571
|
-
}
|
|
1572
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1573
|
-
power <<= 1;
|
|
1574
|
-
}
|
|
1575
|
-
c = f(bits);
|
|
1576
|
-
break;
|
|
1577
|
-
case 1:
|
|
1578
|
-
bits = 0;
|
|
1579
|
-
maxpower = Math.pow(2, 16);
|
|
1580
|
-
power = 1;
|
|
1581
|
-
while (power != maxpower) {
|
|
1582
|
-
resb = data.val & data.position;
|
|
1583
|
-
data.position >>= 1;
|
|
1584
|
-
if (data.position == 0) {
|
|
1585
|
-
data.position = resetValue;
|
|
1586
|
-
data.val = getNextValue(data.index++);
|
|
1587
|
-
}
|
|
1588
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1589
|
-
power <<= 1;
|
|
1590
|
-
}
|
|
1591
|
-
c = f(bits);
|
|
1592
|
-
break;
|
|
1593
|
-
case 2:
|
|
1594
|
-
return '';
|
|
1595
|
-
}
|
|
1596
|
-
dictionary[3] = c;
|
|
1597
|
-
w = c;
|
|
1598
|
-
result.push(c);
|
|
1599
|
-
while (true) {
|
|
1600
|
-
if (data.index > length) {
|
|
1601
|
-
return '';
|
|
1602
|
-
}
|
|
1603
|
-
bits = 0;
|
|
1604
|
-
maxpower = Math.pow(2, numBits);
|
|
1605
|
-
power = 1;
|
|
1606
|
-
while (power != maxpower) {
|
|
1607
|
-
resb = data.val & data.position;
|
|
1608
|
-
data.position >>= 1;
|
|
1609
|
-
if (data.position == 0) {
|
|
1610
|
-
data.position = resetValue;
|
|
1611
|
-
data.val = getNextValue(data.index++);
|
|
1612
|
-
}
|
|
1613
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1614
|
-
power <<= 1;
|
|
1615
|
-
}
|
|
1616
|
-
switch ((c = bits)) {
|
|
1617
|
-
case 0:
|
|
1618
|
-
bits = 0;
|
|
1619
|
-
maxpower = Math.pow(2, 8);
|
|
1620
|
-
power = 1;
|
|
1621
|
-
while (power != maxpower) {
|
|
1622
|
-
resb = data.val & data.position;
|
|
1623
|
-
data.position >>= 1;
|
|
1624
|
-
if (data.position == 0) {
|
|
1625
|
-
data.position = resetValue;
|
|
1626
|
-
data.val = getNextValue(data.index++);
|
|
1627
|
-
}
|
|
1628
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1629
|
-
power <<= 1;
|
|
1630
|
-
}
|
|
1631
|
-
dictionary[dictSize++] = f(bits);
|
|
1632
|
-
c = dictSize - 1;
|
|
1633
|
-
enlargeIn--;
|
|
1634
|
-
break;
|
|
1635
|
-
case 1:
|
|
1636
|
-
bits = 0;
|
|
1637
|
-
maxpower = Math.pow(2, 16);
|
|
1638
|
-
power = 1;
|
|
1639
|
-
while (power != maxpower) {
|
|
1640
|
-
resb = data.val & data.position;
|
|
1641
|
-
data.position >>= 1;
|
|
1642
|
-
if (data.position == 0) {
|
|
1643
|
-
data.position = resetValue;
|
|
1644
|
-
data.val = getNextValue(data.index++);
|
|
1645
|
-
}
|
|
1646
|
-
bits |= (resb > 0 ? 1 : 0) * power;
|
|
1647
|
-
power <<= 1;
|
|
1648
|
-
}
|
|
1649
|
-
dictionary[dictSize++] = f(bits);
|
|
1650
|
-
c = dictSize - 1;
|
|
1651
|
-
enlargeIn--;
|
|
1652
|
-
break;
|
|
1653
|
-
case 2:
|
|
1654
|
-
return result.join('');
|
|
1655
|
-
}
|
|
1656
|
-
if (enlargeIn == 0) {
|
|
1657
|
-
enlargeIn = Math.pow(2, numBits);
|
|
1658
|
-
numBits++;
|
|
1659
|
-
}
|
|
1660
|
-
if (dictionary[c]) {
|
|
1661
|
-
entry = dictionary[c];
|
|
1662
|
-
}
|
|
1663
|
-
else {
|
|
1664
|
-
if (c === dictSize) {
|
|
1665
|
-
entry = w + w.charAt(0);
|
|
1666
|
-
}
|
|
1667
|
-
else {
|
|
1668
|
-
return null;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
result.push(entry);
|
|
1672
|
-
// Add w+entry[0] to the dictionary.
|
|
1673
|
-
dictionary[dictSize++] = w + entry.charAt(0);
|
|
1674
|
-
enlargeIn--;
|
|
1675
|
-
w = entry;
|
|
1676
|
-
if (enlargeIn == 0) {
|
|
1677
|
-
enlargeIn = Math.pow(2, numBits);
|
|
1678
|
-
numBits++;
|
|
1679
|
-
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Gzip a string using Compression Streams API if it's available
|
|
1262
|
+
*/
|
|
1263
|
+
async function gzipCompress(input, isDebug = true) {
|
|
1264
|
+
try {
|
|
1265
|
+
// Turn the string into a stream using a Blob, and then compress it
|
|
1266
|
+
const dataStream = new Blob([input], {
|
|
1267
|
+
type: 'text/plain',
|
|
1268
|
+
}).stream();
|
|
1269
|
+
const compressedStream = dataStream.pipeThrough(new CompressionStream('gzip'));
|
|
1270
|
+
// Using a Response to easily extract the readablestream value. Decoding into a string for fetch
|
|
1271
|
+
return await new Response(compressedStream).blob();
|
|
1272
|
+
}
|
|
1273
|
+
catch (error) {
|
|
1274
|
+
if (isDebug) {
|
|
1275
|
+
console.error('Failed to gzip compress data', error);
|
|
1680
1276
|
}
|
|
1681
|
-
|
|
1682
|
-
}
|
|
1277
|
+
return null;
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1683
1280
|
|
|
1684
1281
|
class SimpleEventEmitter {
|
|
1685
1282
|
constructor() {
|
|
@@ -1772,7 +1369,6 @@ class PostHogCoreStateless {
|
|
|
1772
1369
|
this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100);
|
|
1773
1370
|
this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000);
|
|
1774
1371
|
this.flushInterval = options?.flushInterval ?? 10000;
|
|
1775
|
-
this.captureMode = options?.captureMode || 'json';
|
|
1776
1372
|
this.preloadFeatureFlags = options?.preloadFeatureFlags ?? true;
|
|
1777
1373
|
// If enable is explicitly set to false we override the optout
|
|
1778
1374
|
this.defaultOptIn = options?.defaultOptIn ?? true;
|
|
@@ -1791,6 +1387,7 @@ class PostHogCoreStateless {
|
|
|
1791
1387
|
// Init promise allows the derived class to block calls until it is ready
|
|
1792
1388
|
this._initPromise = Promise.resolve();
|
|
1793
1389
|
this._isInitialized = true;
|
|
1390
|
+
this.disableCompression = !isGzipSupported() || (options?.disableCompression ?? false);
|
|
1794
1391
|
}
|
|
1795
1392
|
logMsgIfDebug(fn) {
|
|
1796
1393
|
if (this.isDebug) {
|
|
@@ -2212,22 +1809,17 @@ class PostHogCoreStateless {
|
|
|
2212
1809
|
data.historical_migration = true;
|
|
2213
1810
|
}
|
|
2214
1811
|
const payload = JSON.stringify(data);
|
|
2215
|
-
const url = this.
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
: {
|
|
2227
|
-
method: 'POST',
|
|
2228
|
-
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
2229
|
-
body: payload,
|
|
2230
|
-
};
|
|
1812
|
+
const url = `${this.host}/batch/`;
|
|
1813
|
+
const gzippedPayload = !this.disableCompression ? await gzipCompress(payload, this.isDebug) : null;
|
|
1814
|
+
const fetchOptions = {
|
|
1815
|
+
method: 'POST',
|
|
1816
|
+
headers: {
|
|
1817
|
+
...this.getCustomHeaders(),
|
|
1818
|
+
'Content-Type': 'application/json',
|
|
1819
|
+
...(gzippedPayload !== null && { 'Content-Encoding': 'gzip' }),
|
|
1820
|
+
},
|
|
1821
|
+
body: gzippedPayload || payload,
|
|
1822
|
+
};
|
|
2231
1823
|
try {
|
|
2232
1824
|
await this.fetchWithRetry(url, fetchOptions);
|
|
2233
1825
|
}
|
|
@@ -2351,22 +1943,17 @@ class PostHogCoreStateless {
|
|
|
2351
1943
|
data.historical_migration = true;
|
|
2352
1944
|
}
|
|
2353
1945
|
const payload = JSON.stringify(data);
|
|
2354
|
-
const url = this.
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
: {
|
|
2366
|
-
method: 'POST',
|
|
2367
|
-
headers: { ...this.getCustomHeaders(), 'Content-Type': 'application/json' },
|
|
2368
|
-
body: payload,
|
|
2369
|
-
};
|
|
1946
|
+
const url = `${this.host}/batch/`;
|
|
1947
|
+
const gzippedPayload = !this.disableCompression ? await gzipCompress(payload, this.isDebug) : null;
|
|
1948
|
+
const fetchOptions = {
|
|
1949
|
+
method: 'POST',
|
|
1950
|
+
headers: {
|
|
1951
|
+
...this.getCustomHeaders(),
|
|
1952
|
+
'Content-Type': 'application/json',
|
|
1953
|
+
...(gzippedPayload !== null && { 'Content-Encoding': 'gzip' }),
|
|
1954
|
+
},
|
|
1955
|
+
body: gzippedPayload || payload,
|
|
1956
|
+
};
|
|
2370
1957
|
const retryOptions = {
|
|
2371
1958
|
retryCheck: (err) => {
|
|
2372
1959
|
// don't automatically retry on 413 errors, we want to reduce the batch size first
|
|
@@ -2411,11 +1998,21 @@ class PostHogCoreStateless {
|
|
|
2411
1998
|
const body = options.body ? options.body : '';
|
|
2412
1999
|
let reqByteLength = -1;
|
|
2413
2000
|
try {
|
|
2414
|
-
|
|
2001
|
+
if (body instanceof Blob) {
|
|
2002
|
+
reqByteLength = body.size;
|
|
2003
|
+
}
|
|
2004
|
+
else {
|
|
2005
|
+
reqByteLength = Buffer.byteLength(body, STRING_FORMAT);
|
|
2006
|
+
}
|
|
2415
2007
|
}
|
|
2416
2008
|
catch {
|
|
2417
|
-
|
|
2418
|
-
|
|
2009
|
+
if (body instanceof Blob) {
|
|
2010
|
+
reqByteLength = body.size;
|
|
2011
|
+
}
|
|
2012
|
+
else {
|
|
2013
|
+
const encoded = new TextEncoder().encode(body);
|
|
2014
|
+
reqByteLength = encoded.length;
|
|
2015
|
+
}
|
|
2419
2016
|
}
|
|
2420
2017
|
return await retriable(async () => {
|
|
2421
2018
|
let res = null;
|
|
@@ -2498,38 +2095,6 @@ class PostHogCoreStateless {
|
|
|
2498
2095
|
}
|
|
2499
2096
|
}
|
|
2500
2097
|
|
|
2501
|
-
/**
|
|
2502
|
-
* Fetch wrapper
|
|
2503
|
-
*
|
|
2504
|
-
* We want to polyfill fetch when not available with axios but use it when it is.
|
|
2505
|
-
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
|
|
2506
|
-
* This is currently solved by using the global fetch if available instead.
|
|
2507
|
-
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
|
|
2508
|
-
*/
|
|
2509
|
-
let _fetch = getFetch();
|
|
2510
|
-
if (!_fetch) {
|
|
2511
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
2512
|
-
const axios = require('axios');
|
|
2513
|
-
_fetch = async (url, options) => {
|
|
2514
|
-
const res = await axios.request({
|
|
2515
|
-
url,
|
|
2516
|
-
headers: options.headers,
|
|
2517
|
-
method: options.method.toLowerCase(),
|
|
2518
|
-
data: options.body,
|
|
2519
|
-
signal: options.signal,
|
|
2520
|
-
// fetch only throws on network errors, not on HTTP errors
|
|
2521
|
-
validateStatus: () => true
|
|
2522
|
-
});
|
|
2523
|
-
return {
|
|
2524
|
-
status: res.status,
|
|
2525
|
-
text: async () => res.data,
|
|
2526
|
-
json: async () => res.data
|
|
2527
|
-
};
|
|
2528
|
-
};
|
|
2529
|
-
}
|
|
2530
|
-
// 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
|
|
2531
|
-
var fetch$1 = _fetch;
|
|
2532
|
-
|
|
2533
2098
|
/**
|
|
2534
2099
|
* A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
|
|
2535
2100
|
*/
|
|
@@ -2672,7 +2237,7 @@ class FeatureFlagsPoller {
|
|
|
2672
2237
|
this.projectApiKey = projectApiKey;
|
|
2673
2238
|
this.host = host;
|
|
2674
2239
|
this.poller = undefined;
|
|
2675
|
-
this.fetch = options.fetch || fetch
|
|
2240
|
+
this.fetch = options.fetch || fetch;
|
|
2676
2241
|
this.onError = options.onError;
|
|
2677
2242
|
this.customHeaders = customHeaders;
|
|
2678
2243
|
this.onLoad = options.onLoad;
|
|
@@ -3346,7 +2911,7 @@ class PostHogBackendClient extends PostHogCoreStateless {
|
|
|
3346
2911
|
return this._memoryStorage.setProperty(key, value);
|
|
3347
2912
|
}
|
|
3348
2913
|
fetch(url, options) {
|
|
3349
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch
|
|
2914
|
+
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
3350
2915
|
}
|
|
3351
2916
|
getLibraryVersion() {
|
|
3352
2917
|
return version;
|