posthog-js-lite 2.6.1 → 2.6.2
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 +4 -0
- package/lib/index.cjs.js +51 -38
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +51 -38
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/vendor/uuidv7.d.ts +179 -0
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -681,6 +681,8 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
681
681
|
return SimpleEventEmitter;
|
|
682
682
|
}());
|
|
683
683
|
|
|
684
|
+
// vendor from: https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
|
|
685
|
+
// https://github.com/LiosK/uuidv7#license
|
|
684
686
|
/**
|
|
685
687
|
* uuidv7: An experimental implementation of the proposed UUID Version 7
|
|
686
688
|
*
|
|
@@ -1028,43 +1030,51 @@ var V7Generator = /** @class */ (function () {
|
|
|
1028
1030
|
};
|
|
1029
1031
|
return V7Generator;
|
|
1030
1032
|
}());
|
|
1033
|
+
/** A global flag to force use of cryptographically strong RNG. */
|
|
1034
|
+
// declare const UUIDV7_DENY_WEAK_RNG: boolean;
|
|
1031
1035
|
/** Returns the default random number generator available in the environment. */
|
|
1032
1036
|
var getDefaultRandom = function () {
|
|
1033
|
-
//
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
this.buffer = new Uint32Array(8);
|
|
1057
|
-
this.cursor = 0xffff;
|
|
1058
|
-
}
|
|
1059
|
-
BufferedCryptoRandom.prototype.nextUint32 = function () {
|
|
1060
|
-
if (this.cursor >= this.buffer.length) {
|
|
1061
|
-
crypto.getRandomValues(this.buffer);
|
|
1062
|
-
this.cursor = 0;
|
|
1063
|
-
}
|
|
1064
|
-
return this.buffer[this.cursor++];
|
|
1037
|
+
// fix: crypto isn't available in react-native, always use Math.random
|
|
1038
|
+
// // detect Web Crypto API
|
|
1039
|
+
// if (
|
|
1040
|
+
// typeof crypto !== "undefined" &&
|
|
1041
|
+
// typeof crypto.getRandomValues !== "undefined"
|
|
1042
|
+
// ) {
|
|
1043
|
+
// return new BufferedCryptoRandom();
|
|
1044
|
+
// } else {
|
|
1045
|
+
// // fall back on Math.random() unless the flag is set to true
|
|
1046
|
+
// if (typeof UUIDV7_DENY_WEAK_RNG !== "undefined" && UUIDV7_DENY_WEAK_RNG) {
|
|
1047
|
+
// throw new Error("no cryptographically strong RNG available");
|
|
1048
|
+
// }
|
|
1049
|
+
// return {
|
|
1050
|
+
// nextUint32: (): number =>
|
|
1051
|
+
// Math.trunc(Math.random() * 0x1_0000) * 0x1_0000 +
|
|
1052
|
+
// Math.trunc(Math.random() * 0x1_0000),
|
|
1053
|
+
// };
|
|
1054
|
+
// }
|
|
1055
|
+
return {
|
|
1056
|
+
nextUint32: function () {
|
|
1057
|
+
return Math.trunc(Math.random() * 65536) * 65536 +
|
|
1058
|
+
Math.trunc(Math.random() * 65536);
|
|
1059
|
+
},
|
|
1065
1060
|
};
|
|
1066
|
-
|
|
1067
|
-
|
|
1061
|
+
};
|
|
1062
|
+
// /**
|
|
1063
|
+
// * Wraps `crypto.getRandomValues()` to enable buffering; this uses a small
|
|
1064
|
+
// * buffer by default to avoid both unbearable throughput decline in some
|
|
1065
|
+
// * environments and the waste of time and space for unused values.
|
|
1066
|
+
// */
|
|
1067
|
+
// class BufferedCryptoRandom {
|
|
1068
|
+
// private readonly buffer = new Uint32Array(8);
|
|
1069
|
+
// private cursor = 0xffff;
|
|
1070
|
+
// nextUint32(): number {
|
|
1071
|
+
// if (this.cursor >= this.buffer.length) {
|
|
1072
|
+
// crypto.getRandomValues(this.buffer);
|
|
1073
|
+
// this.cursor = 0;
|
|
1074
|
+
// }
|
|
1075
|
+
// return this.buffer[this.cursor++];
|
|
1076
|
+
// }
|
|
1077
|
+
// }
|
|
1068
1078
|
var defaultGenerator;
|
|
1069
1079
|
/**
|
|
1070
1080
|
* Generates a UUIDv7 string.
|
|
@@ -1074,7 +1084,9 @@ var defaultGenerator;
|
|
|
1074
1084
|
*/
|
|
1075
1085
|
var uuidv7 = function () { return uuidv7obj().toString(); };
|
|
1076
1086
|
/** Generates a UUIDv7 object. */
|
|
1077
|
-
var uuidv7obj = function () {
|
|
1087
|
+
var uuidv7obj = function () {
|
|
1088
|
+
return (defaultGenerator || (defaultGenerator = new V7Generator())).generate();
|
|
1089
|
+
};
|
|
1078
1090
|
|
|
1079
1091
|
var PostHogFetchHttpError = /** @class */ (function (_super) {
|
|
1080
1092
|
__extends(PostHogFetchHttpError, _super);
|
|
@@ -1471,7 +1483,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1471
1483
|
return ctrl.signal;
|
|
1472
1484
|
});
|
|
1473
1485
|
return [4 /*yield*/, retriable(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1474
|
-
var res, e_1;
|
|
1486
|
+
var res, e_1, isNoCors;
|
|
1475
1487
|
return __generator(this, function (_a) {
|
|
1476
1488
|
switch (_a.label) {
|
|
1477
1489
|
case 0:
|
|
@@ -1488,7 +1500,8 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1488
1500
|
// fetch will only throw on network errors or on timeouts
|
|
1489
1501
|
throw new PostHogFetchNetworkError(e_1);
|
|
1490
1502
|
case 4:
|
|
1491
|
-
|
|
1503
|
+
isNoCors = options.mode === 'no-cors';
|
|
1504
|
+
if (!isNoCors && (res.status < 200 || res.status >= 400)) {
|
|
1492
1505
|
throw new PostHogFetchHttpError(res);
|
|
1493
1506
|
}
|
|
1494
1507
|
return [2 /*return*/, res];
|
|
@@ -1971,7 +1984,7 @@ var PostHogCore = /** @class */ (function (_super) {
|
|
|
1971
1984
|
return PostHogCore;
|
|
1972
1985
|
}(PostHogCoreStateless));
|
|
1973
1986
|
|
|
1974
|
-
var version = "2.6.
|
|
1987
|
+
var version = "2.6.2";
|
|
1975
1988
|
|
|
1976
1989
|
function getContext(window) {
|
|
1977
1990
|
var context = {};
|