posthog-node 3.6.1 → 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,4 +1,12 @@
1
- ## 3.6.1 - 2024-01-26
1
+ # 3.6.3 - 2024-02-15
2
+
3
+ 1. fix: using `captureMode=form` won't throw an error and retry unnecessarily
4
+
5
+ # 3.6.2 - 2024-02-06
6
+
7
+ 1. Swapped to `uuidv7` for unique ID generation
8
+
9
+ # 3.6.1 - 2024-01-26
2
10
 
3
11
  1. Remove new relative date operators, combine into regular date operators
4
12
 
package/README.md CHANGED
@@ -6,4 +6,4 @@ Specifically, the [Node.js integration](https://posthog.com/docs/integrate/serve
6
6
 
7
7
  ## Questions?
8
8
 
9
- ### [Join our Slack community.](https://join.slack.com/t/posthogusers/shared_invite/enQtOTY0MzU5NjAwMDY3LTc2MWQ0OTZlNjhkODk3ZDI3NDVjMDE1YjgxY2I4ZjI4MzJhZmVmNjJkN2NmMGJmMzc2N2U3Yjc3ZjI5NGFlZDQ)
9
+ ### [Check out our community page.](https://posthog.com/posts)
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.1";
161
+ var version = "3.6.3";
162
162
 
163
163
  var PostHogPersistedProperty;
164
164
  (function (PostHogPersistedProperty) {
@@ -227,26 +227,6 @@ function retriable(fn, props) {
227
227
  });
228
228
  });
229
229
  }
230
- // https://stackoverflow.com/a/8809472
231
- function generateUUID(globalThis) {
232
- // Public Domain/MIT
233
- var d = new Date().getTime(); //Timestamp
234
- var d2 = (globalThis && globalThis.performance && globalThis.performance.now && globalThis.performance.now() * 1000) || 0; //Time in microseconds since page-load or 0 if unsupported
235
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
236
- var r = Math.random() * 16; //random number between 0 and 16
237
- if (d > 0) {
238
- //Use timestamp until depleted
239
- r = (d + r) % 16 | 0;
240
- d = Math.floor(d / 16);
241
- }
242
- else {
243
- //Use microseconds since page-load if supported
244
- r = (d2 + r) % 16 | 0;
245
- d2 = Math.floor(d2 / 16);
246
- }
247
- return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
248
- });
249
- }
250
230
  function currentTimestamp() {
251
231
  return new Date().getTime();
252
232
  }
@@ -721,6 +701,413 @@ var SimpleEventEmitter = /** @class */ (function () {
721
701
  return SimpleEventEmitter;
722
702
  }());
723
703
 
704
+ // vendor from: https://github.com/LiosK/uuidv7/blob/f30b7a7faff73afbce0b27a46c638310f96912ba/src/index.ts
705
+ // https://github.com/LiosK/uuidv7#license
706
+ /**
707
+ * uuidv7: An experimental implementation of the proposed UUID Version 7
708
+ *
709
+ * @license Apache-2.0
710
+ * @copyright 2021-2023 LiosK
711
+ * @packageDocumentation
712
+ */
713
+ var DIGITS = "0123456789abcdef";
714
+ /** Represents a UUID as a 16-byte byte array. */
715
+ var UUID = /** @class */ (function () {
716
+ /** @param bytes - The 16-byte byte array representation. */
717
+ function UUID(bytes) {
718
+ this.bytes = bytes;
719
+ }
720
+ /**
721
+ * Creates an object from the internal representation, a 16-byte byte array
722
+ * containing the binary UUID representation in the big-endian byte order.
723
+ *
724
+ * This method does NOT shallow-copy the argument, and thus the created object
725
+ * holds the reference to the underlying buffer.
726
+ *
727
+ * @throws TypeError if the length of the argument is not 16.
728
+ */
729
+ UUID.ofInner = function (bytes) {
730
+ if (bytes.length !== 16) {
731
+ throw new TypeError("not 128-bit length");
732
+ }
733
+ else {
734
+ return new UUID(bytes);
735
+ }
736
+ };
737
+ /**
738
+ * Builds a byte array from UUIDv7 field values.
739
+ *
740
+ * @param unixTsMs - A 48-bit `unix_ts_ms` field value.
741
+ * @param randA - A 12-bit `rand_a` field value.
742
+ * @param randBHi - The higher 30 bits of 62-bit `rand_b` field value.
743
+ * @param randBLo - The lower 32 bits of 62-bit `rand_b` field value.
744
+ * @throws RangeError if any field value is out of the specified range.
745
+ */
746
+ UUID.fromFieldsV7 = function (unixTsMs, randA, randBHi, randBLo) {
747
+ if (!Number.isInteger(unixTsMs) ||
748
+ !Number.isInteger(randA) ||
749
+ !Number.isInteger(randBHi) ||
750
+ !Number.isInteger(randBLo) ||
751
+ unixTsMs < 0 ||
752
+ randA < 0 ||
753
+ randBHi < 0 ||
754
+ randBLo < 0 ||
755
+ unixTsMs > 281474976710655 ||
756
+ randA > 0xfff ||
757
+ randBHi > 1073741823 ||
758
+ randBLo > 4294967295) {
759
+ throw new RangeError("invalid field value");
760
+ }
761
+ var bytes = new Uint8Array(16);
762
+ bytes[0] = unixTsMs / Math.pow(2, 40);
763
+ bytes[1] = unixTsMs / Math.pow(2, 32);
764
+ bytes[2] = unixTsMs / Math.pow(2, 24);
765
+ bytes[3] = unixTsMs / Math.pow(2, 16);
766
+ bytes[4] = unixTsMs / Math.pow(2, 8);
767
+ bytes[5] = unixTsMs;
768
+ bytes[6] = 0x70 | (randA >>> 8);
769
+ bytes[7] = randA;
770
+ bytes[8] = 0x80 | (randBHi >>> 24);
771
+ bytes[9] = randBHi >>> 16;
772
+ bytes[10] = randBHi >>> 8;
773
+ bytes[11] = randBHi;
774
+ bytes[12] = randBLo >>> 24;
775
+ bytes[13] = randBLo >>> 16;
776
+ bytes[14] = randBLo >>> 8;
777
+ bytes[15] = randBLo;
778
+ return new UUID(bytes);
779
+ };
780
+ /**
781
+ * Builds a byte array from a string representation.
782
+ *
783
+ * This method accepts the following formats:
784
+ *
785
+ * - 32-digit hexadecimal format without hyphens: `0189dcd553117d408db09496a2eef37b`
786
+ * - 8-4-4-4-12 hyphenated format: `0189dcd5-5311-7d40-8db0-9496a2eef37b`
787
+ * - Hyphenated format with surrounding braces: `{0189dcd5-5311-7d40-8db0-9496a2eef37b}`
788
+ * - RFC 4122 URN format: `urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b`
789
+ *
790
+ * Leading and trailing whitespaces represents an error.
791
+ *
792
+ * @throws SyntaxError if the argument could not parse as a valid UUID string.
793
+ */
794
+ UUID.parse = function (uuid) {
795
+ var _a, _b, _c, _d;
796
+ var hex = undefined;
797
+ switch (uuid.length) {
798
+ case 32:
799
+ hex = (_a = /^[0-9a-f]{32}$/i.exec(uuid)) === null || _a === void 0 ? void 0 : _a[0];
800
+ break;
801
+ case 36:
802
+ hex =
803
+ (_b = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
804
+ .exec(uuid)) === null || _b === void 0 ? void 0 : _b.slice(1, 6).join("");
805
+ break;
806
+ case 38:
807
+ hex =
808
+ (_c = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i
809
+ .exec(uuid)) === null || _c === void 0 ? void 0 : _c.slice(1, 6).join("");
810
+ break;
811
+ case 45:
812
+ hex =
813
+ (_d = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
814
+ .exec(uuid)) === null || _d === void 0 ? void 0 : _d.slice(1, 6).join("");
815
+ break;
816
+ }
817
+ if (hex) {
818
+ var inner = new Uint8Array(16);
819
+ for (var i = 0; i < 16; i += 4) {
820
+ var n = parseInt(hex.substring(2 * i, 2 * i + 8), 16);
821
+ inner[i + 0] = n >>> 24;
822
+ inner[i + 1] = n >>> 16;
823
+ inner[i + 2] = n >>> 8;
824
+ inner[i + 3] = n;
825
+ }
826
+ return new UUID(inner);
827
+ }
828
+ else {
829
+ throw new SyntaxError("could not parse UUID string");
830
+ }
831
+ };
832
+ /**
833
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
834
+ * (`0189dcd5-5311-7d40-8db0-9496a2eef37b`).
835
+ */
836
+ UUID.prototype.toString = function () {
837
+ var text = "";
838
+ for (var i = 0; i < this.bytes.length; i++) {
839
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
840
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
841
+ if (i === 3 || i === 5 || i === 7 || i === 9) {
842
+ text += "-";
843
+ }
844
+ }
845
+ return text;
846
+ };
847
+ /**
848
+ * @returns The 32-digit hexadecimal representation without hyphens
849
+ * (`0189dcd553117d408db09496a2eef37b`).
850
+ */
851
+ UUID.prototype.toHex = function () {
852
+ var text = "";
853
+ for (var i = 0; i < this.bytes.length; i++) {
854
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
855
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
856
+ }
857
+ return text;
858
+ };
859
+ /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
860
+ UUID.prototype.toJSON = function () {
861
+ return this.toString();
862
+ };
863
+ /**
864
+ * Reports the variant field value of the UUID or, if appropriate, "NIL" or
865
+ * "MAX".
866
+ *
867
+ * For convenience, this method reports "NIL" or "MAX" if `this` represents
868
+ * the Nil or Max UUID, although the Nil and Max UUIDs are technically
869
+ * subsumed under the variants `0b0` and `0b111`, respectively.
870
+ */
871
+ UUID.prototype.getVariant = function () {
872
+ var n = this.bytes[8] >>> 4;
873
+ if (n < 0) {
874
+ throw new Error("unreachable");
875
+ }
876
+ else if (n <= 7) {
877
+ return this.bytes.every(function (e) { return e === 0; }) ? "NIL" : "VAR_0";
878
+ }
879
+ else if (n <= 11) {
880
+ return "VAR_10";
881
+ }
882
+ else if (n <= 13) {
883
+ return "VAR_110";
884
+ }
885
+ else if (n <= 15) {
886
+ return this.bytes.every(function (e) { return e === 0xff; }) ? "MAX" : "VAR_RESERVED";
887
+ }
888
+ else {
889
+ throw new Error("unreachable");
890
+ }
891
+ };
892
+ /**
893
+ * Returns the version field value of the UUID or `undefined` if the UUID does
894
+ * not have the variant field value of `0b10`.
895
+ */
896
+ UUID.prototype.getVersion = function () {
897
+ return this.getVariant() === "VAR_10" ? this.bytes[6] >>> 4 : undefined;
898
+ };
899
+ /** Creates an object from `this`. */
900
+ UUID.prototype.clone = function () {
901
+ return new UUID(this.bytes.slice(0));
902
+ };
903
+ /** Returns true if `this` is equivalent to `other`. */
904
+ UUID.prototype.equals = function (other) {
905
+ return this.compareTo(other) === 0;
906
+ };
907
+ /**
908
+ * Returns a negative integer, zero, or positive integer if `this` is less
909
+ * than, equal to, or greater than `other`, respectively.
910
+ */
911
+ UUID.prototype.compareTo = function (other) {
912
+ for (var i = 0; i < 16; i++) {
913
+ var diff = this.bytes[i] - other.bytes[i];
914
+ if (diff !== 0) {
915
+ return Math.sign(diff);
916
+ }
917
+ }
918
+ return 0;
919
+ };
920
+ return UUID;
921
+ }());
922
+ /**
923
+ * Encapsulates the monotonic counter state.
924
+ *
925
+ * This class provides APIs to utilize a separate counter state from that of the
926
+ * global generator used by {@link uuidv7} and {@link uuidv7obj}. In addition to
927
+ * the default {@link generate} method, this class has {@link generateOrAbort}
928
+ * that is useful to absolutely guarantee the monotonically increasing order of
929
+ * generated UUIDs. See their respective documentation for details.
930
+ */
931
+ var V7Generator = /** @class */ (function () {
932
+ /**
933
+ * Creates a generator object with the default random number generator, or
934
+ * with the specified one if passed as an argument. The specified random
935
+ * number generator should be cryptographically strong and securely seeded.
936
+ */
937
+ function V7Generator(randomNumberGenerator) {
938
+ this.timestamp = 0;
939
+ this.counter = 0;
940
+ this.random = randomNumberGenerator !== null && randomNumberGenerator !== void 0 ? randomNumberGenerator : getDefaultRandom();
941
+ }
942
+ /**
943
+ * Generates a new UUIDv7 object from the current timestamp, or resets the
944
+ * generator upon significant timestamp rollback.
945
+ *
946
+ * This method returns a monotonically increasing UUID by reusing the previous
947
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
948
+ * preceding UUID's. However, when such a clock rollback is considered
949
+ * significant (i.e., by more than ten seconds), this method resets the
950
+ * generator and returns a new UUID based on the given timestamp, breaking the
951
+ * increasing order of UUIDs.
952
+ *
953
+ * See {@link generateOrAbort} for the other mode of generation and
954
+ * {@link generateOrResetCore} for the low-level primitive.
955
+ */
956
+ V7Generator.prototype.generate = function () {
957
+ return this.generateOrResetCore(Date.now(), 10000);
958
+ };
959
+ /**
960
+ * Generates a new UUIDv7 object from the current timestamp, or returns
961
+ * `undefined` upon significant timestamp rollback.
962
+ *
963
+ * This method returns a monotonically increasing UUID by reusing the previous
964
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
965
+ * preceding UUID's. However, when such a clock rollback is considered
966
+ * significant (i.e., by more than ten seconds), this method aborts and
967
+ * returns `undefined` immediately.
968
+ *
969
+ * See {@link generate} for the other mode of generation and
970
+ * {@link generateOrAbortCore} for the low-level primitive.
971
+ */
972
+ V7Generator.prototype.generateOrAbort = function () {
973
+ return this.generateOrAbortCore(Date.now(), 10000);
974
+ };
975
+ /**
976
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or resets the
977
+ * generator upon significant timestamp rollback.
978
+ *
979
+ * This method is equivalent to {@link generate} except that it takes a custom
980
+ * timestamp and clock rollback allowance.
981
+ *
982
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
983
+ * considered significant. A suggested value is `10_000` (milliseconds).
984
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
985
+ */
986
+ V7Generator.prototype.generateOrResetCore = function (unixTsMs, rollbackAllowance) {
987
+ var value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
988
+ if (value === undefined) {
989
+ // reset state and resume
990
+ this.timestamp = 0;
991
+ value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
992
+ }
993
+ return value;
994
+ };
995
+ /**
996
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or returns
997
+ * `undefined` upon significant timestamp rollback.
998
+ *
999
+ * This method is equivalent to {@link generateOrAbort} except that it takes a
1000
+ * custom timestamp and clock rollback allowance.
1001
+ *
1002
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
1003
+ * considered significant. A suggested value is `10_000` (milliseconds).
1004
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
1005
+ */
1006
+ V7Generator.prototype.generateOrAbortCore = function (unixTsMs, rollbackAllowance) {
1007
+ var MAX_COUNTER = 4398046511103;
1008
+ if (!Number.isInteger(unixTsMs) ||
1009
+ unixTsMs < 1 ||
1010
+ unixTsMs > 281474976710655) {
1011
+ throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
1012
+ }
1013
+ else if (rollbackAllowance < 0 || rollbackAllowance > 281474976710655) {
1014
+ throw new RangeError("`rollbackAllowance` out of reasonable range");
1015
+ }
1016
+ if (unixTsMs > this.timestamp) {
1017
+ this.timestamp = unixTsMs;
1018
+ this.resetCounter();
1019
+ }
1020
+ else if (unixTsMs + rollbackAllowance >= this.timestamp) {
1021
+ // go on with previous timestamp if new one is not much smaller
1022
+ this.counter++;
1023
+ if (this.counter > MAX_COUNTER) {
1024
+ // increment timestamp at counter overflow
1025
+ this.timestamp++;
1026
+ this.resetCounter();
1027
+ }
1028
+ }
1029
+ else {
1030
+ // abort if clock went backwards to unbearable extent
1031
+ return undefined;
1032
+ }
1033
+ return UUID.fromFieldsV7(this.timestamp, Math.trunc(this.counter / Math.pow(2, 30)), this.counter & (Math.pow(2, 30) - 1), this.random.nextUint32());
1034
+ };
1035
+ /** Initializes the counter at a 42-bit random integer. */
1036
+ V7Generator.prototype.resetCounter = function () {
1037
+ this.counter =
1038
+ this.random.nextUint32() * 0x400 + (this.random.nextUint32() & 0x3ff);
1039
+ };
1040
+ /**
1041
+ * Generates a new UUIDv4 object utilizing the random number generator inside.
1042
+ *
1043
+ * @internal
1044
+ */
1045
+ V7Generator.prototype.generateV4 = function () {
1046
+ var bytes = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
1047
+ bytes[6] = 0x40 | (bytes[6] >>> 4);
1048
+ bytes[8] = 0x80 | (bytes[8] >>> 2);
1049
+ return UUID.ofInner(bytes);
1050
+ };
1051
+ return V7Generator;
1052
+ }());
1053
+ /** A global flag to force use of cryptographically strong RNG. */
1054
+ // declare const UUIDV7_DENY_WEAK_RNG: boolean;
1055
+ /** Returns the default random number generator available in the environment. */
1056
+ var getDefaultRandom = function () {
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
+ },
1080
+ };
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
+ // }
1098
+ var defaultGenerator;
1099
+ /**
1100
+ * Generates a UUIDv7 string.
1101
+ *
1102
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
1103
+ * ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
1104
+ */
1105
+ var uuidv7 = function () { return uuidv7obj().toString(); };
1106
+ /** Generates a UUIDv7 object. */
1107
+ var uuidv7obj = function () {
1108
+ return (defaultGenerator || (defaultGenerator = new V7Generator())).generate();
1109
+ };
1110
+
724
1111
  var PostHogFetchHttpError = /** @class */ (function (_super) {
725
1112
  __extends(PostHogFetchHttpError, _super);
726
1113
  function PostHogFetchHttpError(response) {
@@ -812,7 +1199,7 @@ var PostHogCoreStateless = /** @class */ (function () {
812
1199
  };
813
1200
  PostHogCoreStateless.prototype.addPendingPromise = function (promise) {
814
1201
  var _this = this;
815
- var promiseUUID = generateUUID();
1202
+ var promiseUUID = uuidv7();
816
1203
  this.pendingPromises[promiseUUID] = promise;
817
1204
  promise.finally(function () {
818
1205
  delete _this.pendingPromises[promiseUUID];
@@ -1016,7 +1403,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1016
1403
  this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1017
1404
  return;
1018
1405
  }
1019
- var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : generateUUID(globalThis) });
1406
+ var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : uuidv7() });
1020
1407
  var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
1021
1408
  if (addGeoipDisableProperty) {
1022
1409
  if (!message.properties) {
@@ -1116,7 +1503,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1116
1503
  return ctrl.signal;
1117
1504
  });
1118
1505
  return [4 /*yield*/, retriable(function () { return __awaiter(_this, void 0, void 0, function () {
1119
- var res, e_1;
1506
+ var res, e_1, isNoCors;
1120
1507
  return __generator(this, function (_a) {
1121
1508
  switch (_a.label) {
1122
1509
  case 0:
@@ -1133,7 +1520,8 @@ var PostHogCoreStateless = /** @class */ (function () {
1133
1520
  // fetch will only throw on network errors or on timeouts
1134
1521
  throw new PostHogFetchNetworkError(e_1);
1135
1522
  case 4:
1136
- if (res.status < 200 || res.status >= 400) {
1523
+ isNoCors = options.mode === 'no-cors';
1524
+ if (!isNoCors && (res.status < 200 || res.status >= 400)) {
1137
1525
  throw new PostHogFetchHttpError(res);
1138
1526
  }
1139
1527
  return [2 /*return*/, res];
@@ -1281,7 +1669,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1281
1669
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
1282
1670
  var sessionTimestamp = this.getPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp) || 0;
1283
1671
  if (!sessionId || Date.now() - sessionTimestamp > this._sessionExpirationTimeSeconds * 1000) {
1284
- sessionId = generateUUID(globalThis);
1672
+ sessionId = uuidv7();
1285
1673
  this.setPersistedProperty(PostHogPersistedProperty.SessionId, sessionId);
1286
1674
  }
1287
1675
  this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
@@ -1293,7 +1681,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1293
1681
  PostHogCore.prototype.getAnonymousId = function () {
1294
1682
  var anonId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
1295
1683
  if (!anonId) {
1296
- anonId = generateUUID(globalThis);
1684
+ anonId = uuidv7();
1297
1685
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, anonId);
1298
1686
  }
1299
1687
  return anonId;