posthog-node 3.6.2 → 3.6.3

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 CHANGED
@@ -1,3 +1,7 @@
1
+ # 3.6.3 - 2024-02-15
2
+
3
+ 1. fix: using `captureMode=form` won't throw an error and retry unnecessarily
4
+
1
5
  # 3.6.2 - 2024-02-06
2
6
 
3
7
  1. Swapped to `uuidv7` for unique ID generation
package/lib/index.cjs.js CHANGED
@@ -158,7 +158,7 @@ function __spreadArray(to, from, pack) {
158
158
  return to.concat(ar || Array.prototype.slice.call(from));
159
159
  }
160
160
 
161
- var version = "3.6.2";
161
+ var version = "3.6.3";
162
162
 
163
163
  var PostHogPersistedProperty;
164
164
  (function (PostHogPersistedProperty) {
@@ -701,6 +701,8 @@ var SimpleEventEmitter = /** @class */ (function () {
701
701
  return SimpleEventEmitter;
702
702
  }());
703
703
 
704
+ // vendor from: https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
705
+ // https://github.com/LiosK/uuidv7#license
704
706
  /**
705
707
  * uuidv7: An experimental implementation of the proposed UUID Version 7
706
708
  *
@@ -1048,43 +1050,51 @@ var V7Generator = /** @class */ (function () {
1048
1050
  };
1049
1051
  return V7Generator;
1050
1052
  }());
1053
+ /** A global flag to force use of cryptographically strong RNG. */
1054
+ // declare const UUIDV7_DENY_WEAK_RNG: boolean;
1051
1055
  /** Returns the default random number generator available in the environment. */
1052
1056
  var getDefaultRandom = function () {
1053
- // detect Web Crypto API
1054
- if (typeof crypto !== "undefined" &&
1055
- typeof crypto.getRandomValues !== "undefined") {
1056
- return new BufferedCryptoRandom();
1057
- }
1058
- else {
1059
- // fall back on Math.random() unless the flag is set to true
1060
- if (typeof UUIDV7_DENY_WEAK_RNG !== "undefined" && UUIDV7_DENY_WEAK_RNG) {
1061
- throw new Error("no cryptographically strong RNG available");
1062
- }
1063
- return {
1064
- nextUint32: function () { return Math.trunc(Math.random() * 65536) * 65536 +
1065
- Math.trunc(Math.random() * 65536); },
1066
- };
1067
- }
1068
- };
1069
- /**
1070
- * Wraps `crypto.getRandomValues()` to enable buffering; this uses a small
1071
- * buffer by default to avoid both unbearable throughput decline in some
1072
- * environments and the waste of time and space for unused values.
1073
- */
1074
- var BufferedCryptoRandom = /** @class */ (function () {
1075
- function BufferedCryptoRandom() {
1076
- this.buffer = new Uint32Array(8);
1077
- this.cursor = 0xffff;
1078
- }
1079
- BufferedCryptoRandom.prototype.nextUint32 = function () {
1080
- if (this.cursor >= this.buffer.length) {
1081
- crypto.getRandomValues(this.buffer);
1082
- this.cursor = 0;
1083
- }
1084
- return this.buffer[this.cursor++];
1057
+ // fix: crypto isn't available in react-native, always use Math.random
1058
+ // // detect Web Crypto API
1059
+ // if (
1060
+ // typeof crypto !== "undefined" &&
1061
+ // typeof crypto.getRandomValues !== "undefined"
1062
+ // ) {
1063
+ // return new BufferedCryptoRandom();
1064
+ // } else {
1065
+ // // fall back on Math.random() unless the flag is set to true
1066
+ // if (typeof UUIDV7_DENY_WEAK_RNG !== "undefined" && UUIDV7_DENY_WEAK_RNG) {
1067
+ // throw new Error("no cryptographically strong RNG available");
1068
+ // }
1069
+ // return {
1070
+ // nextUint32: (): number =>
1071
+ // Math.trunc(Math.random() * 0x1_0000) * 0x1_0000 +
1072
+ // Math.trunc(Math.random() * 0x1_0000),
1073
+ // };
1074
+ // }
1075
+ return {
1076
+ nextUint32: function () {
1077
+ return Math.trunc(Math.random() * 65536) * 65536 +
1078
+ Math.trunc(Math.random() * 65536);
1079
+ },
1085
1080
  };
1086
- return BufferedCryptoRandom;
1087
- }());
1081
+ };
1082
+ // /**
1083
+ // * Wraps `crypto.getRandomValues()` to enable buffering; this uses a small
1084
+ // * buffer by default to avoid both unbearable throughput decline in some
1085
+ // * environments and the waste of time and space for unused values.
1086
+ // */
1087
+ // class BufferedCryptoRandom {
1088
+ // private readonly buffer = new Uint32Array(8);
1089
+ // private cursor = 0xffff;
1090
+ // nextUint32(): number {
1091
+ // if (this.cursor >= this.buffer.length) {
1092
+ // crypto.getRandomValues(this.buffer);
1093
+ // this.cursor = 0;
1094
+ // }
1095
+ // return this.buffer[this.cursor++];
1096
+ // }
1097
+ // }
1088
1098
  var defaultGenerator;
1089
1099
  /**
1090
1100
  * Generates a UUIDv7 string.
@@ -1094,7 +1104,9 @@ var defaultGenerator;
1094
1104
  */
1095
1105
  var uuidv7 = function () { return uuidv7obj().toString(); };
1096
1106
  /** Generates a UUIDv7 object. */
1097
- var uuidv7obj = function () { return (defaultGenerator || (defaultGenerator = new V7Generator())).generate(); };
1107
+ var uuidv7obj = function () {
1108
+ return (defaultGenerator || (defaultGenerator = new V7Generator())).generate();
1109
+ };
1098
1110
 
1099
1111
  var PostHogFetchHttpError = /** @class */ (function (_super) {
1100
1112
  __extends(PostHogFetchHttpError, _super);
@@ -1491,7 +1503,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1491
1503
  return ctrl.signal;
1492
1504
  });
1493
1505
  return [4 /*yield*/, retriable(function () { return __awaiter(_this, void 0, void 0, function () {
1494
- var res, e_1;
1506
+ var res, e_1, isNoCors;
1495
1507
  return __generator(this, function (_a) {
1496
1508
  switch (_a.label) {
1497
1509
  case 0:
@@ -1508,7 +1520,8 @@ var PostHogCoreStateless = /** @class */ (function () {
1508
1520
  // fetch will only throw on network errors or on timeouts
1509
1521
  throw new PostHogFetchNetworkError(e_1);
1510
1522
  case 4:
1511
- if (res.status < 200 || res.status >= 400) {
1523
+ isNoCors = options.mode === 'no-cors';
1524
+ if (!isNoCors && (res.status < 200 || res.status >= 400)) {
1512
1525
  throw new PostHogFetchHttpError(res);
1513
1526
  }
1514
1527
  return [2 /*return*/, res];