posthog-node 3.6.0 → 3.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 CHANGED
@@ -1,3 +1,11 @@
1
+ # 3.6.2 - 2024-02-06
2
+
3
+ 1. Swapped to `uuidv7` for unique ID generation
4
+
5
+ # 3.6.1 - 2024-01-26
6
+
7
+ 1. Remove new relative date operators, combine into regular date operators
8
+
1
9
  # 3.6.0 - 2024-01-18
2
10
 
3
11
  1. Adds support for overriding the event `uuid`
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.0";
161
+ var version = "3.6.2";
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,401 @@ var SimpleEventEmitter = /** @class */ (function () {
721
701
  return SimpleEventEmitter;
722
702
  }());
723
703
 
704
+ /**
705
+ * uuidv7: An experimental implementation of the proposed UUID Version 7
706
+ *
707
+ * @license Apache-2.0
708
+ * @copyright 2021-2023 LiosK
709
+ * @packageDocumentation
710
+ */
711
+ var DIGITS = "0123456789abcdef";
712
+ /** Represents a UUID as a 16-byte byte array. */
713
+ var UUID = /** @class */ (function () {
714
+ /** @param bytes - The 16-byte byte array representation. */
715
+ function UUID(bytes) {
716
+ this.bytes = bytes;
717
+ }
718
+ /**
719
+ * Creates an object from the internal representation, a 16-byte byte array
720
+ * containing the binary UUID representation in the big-endian byte order.
721
+ *
722
+ * This method does NOT shallow-copy the argument, and thus the created object
723
+ * holds the reference to the underlying buffer.
724
+ *
725
+ * @throws TypeError if the length of the argument is not 16.
726
+ */
727
+ UUID.ofInner = function (bytes) {
728
+ if (bytes.length !== 16) {
729
+ throw new TypeError("not 128-bit length");
730
+ }
731
+ else {
732
+ return new UUID(bytes);
733
+ }
734
+ };
735
+ /**
736
+ * Builds a byte array from UUIDv7 field values.
737
+ *
738
+ * @param unixTsMs - A 48-bit `unix_ts_ms` field value.
739
+ * @param randA - A 12-bit `rand_a` field value.
740
+ * @param randBHi - The higher 30 bits of 62-bit `rand_b` field value.
741
+ * @param randBLo - The lower 32 bits of 62-bit `rand_b` field value.
742
+ * @throws RangeError if any field value is out of the specified range.
743
+ */
744
+ UUID.fromFieldsV7 = function (unixTsMs, randA, randBHi, randBLo) {
745
+ if (!Number.isInteger(unixTsMs) ||
746
+ !Number.isInteger(randA) ||
747
+ !Number.isInteger(randBHi) ||
748
+ !Number.isInteger(randBLo) ||
749
+ unixTsMs < 0 ||
750
+ randA < 0 ||
751
+ randBHi < 0 ||
752
+ randBLo < 0 ||
753
+ unixTsMs > 281474976710655 ||
754
+ randA > 0xfff ||
755
+ randBHi > 1073741823 ||
756
+ randBLo > 4294967295) {
757
+ throw new RangeError("invalid field value");
758
+ }
759
+ var bytes = new Uint8Array(16);
760
+ bytes[0] = unixTsMs / Math.pow(2, 40);
761
+ bytes[1] = unixTsMs / Math.pow(2, 32);
762
+ bytes[2] = unixTsMs / Math.pow(2, 24);
763
+ bytes[3] = unixTsMs / Math.pow(2, 16);
764
+ bytes[4] = unixTsMs / Math.pow(2, 8);
765
+ bytes[5] = unixTsMs;
766
+ bytes[6] = 0x70 | (randA >>> 8);
767
+ bytes[7] = randA;
768
+ bytes[8] = 0x80 | (randBHi >>> 24);
769
+ bytes[9] = randBHi >>> 16;
770
+ bytes[10] = randBHi >>> 8;
771
+ bytes[11] = randBHi;
772
+ bytes[12] = randBLo >>> 24;
773
+ bytes[13] = randBLo >>> 16;
774
+ bytes[14] = randBLo >>> 8;
775
+ bytes[15] = randBLo;
776
+ return new UUID(bytes);
777
+ };
778
+ /**
779
+ * Builds a byte array from a string representation.
780
+ *
781
+ * This method accepts the following formats:
782
+ *
783
+ * - 32-digit hexadecimal format without hyphens: `0189dcd553117d408db09496a2eef37b`
784
+ * - 8-4-4-4-12 hyphenated format: `0189dcd5-5311-7d40-8db0-9496a2eef37b`
785
+ * - Hyphenated format with surrounding braces: `{0189dcd5-5311-7d40-8db0-9496a2eef37b}`
786
+ * - RFC 4122 URN format: `urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b`
787
+ *
788
+ * Leading and trailing whitespaces represents an error.
789
+ *
790
+ * @throws SyntaxError if the argument could not parse as a valid UUID string.
791
+ */
792
+ UUID.parse = function (uuid) {
793
+ var _a, _b, _c, _d;
794
+ var hex = undefined;
795
+ switch (uuid.length) {
796
+ case 32:
797
+ hex = (_a = /^[0-9a-f]{32}$/i.exec(uuid)) === null || _a === void 0 ? void 0 : _a[0];
798
+ break;
799
+ case 36:
800
+ hex =
801
+ (_b = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
802
+ .exec(uuid)) === null || _b === void 0 ? void 0 : _b.slice(1, 6).join("");
803
+ break;
804
+ case 38:
805
+ hex =
806
+ (_c = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i
807
+ .exec(uuid)) === null || _c === void 0 ? void 0 : _c.slice(1, 6).join("");
808
+ break;
809
+ case 45:
810
+ hex =
811
+ (_d = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i
812
+ .exec(uuid)) === null || _d === void 0 ? void 0 : _d.slice(1, 6).join("");
813
+ break;
814
+ }
815
+ if (hex) {
816
+ var inner = new Uint8Array(16);
817
+ for (var i = 0; i < 16; i += 4) {
818
+ var n = parseInt(hex.substring(2 * i, 2 * i + 8), 16);
819
+ inner[i + 0] = n >>> 24;
820
+ inner[i + 1] = n >>> 16;
821
+ inner[i + 2] = n >>> 8;
822
+ inner[i + 3] = n;
823
+ }
824
+ return new UUID(inner);
825
+ }
826
+ else {
827
+ throw new SyntaxError("could not parse UUID string");
828
+ }
829
+ };
830
+ /**
831
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
832
+ * (`0189dcd5-5311-7d40-8db0-9496a2eef37b`).
833
+ */
834
+ UUID.prototype.toString = function () {
835
+ var text = "";
836
+ for (var i = 0; i < this.bytes.length; i++) {
837
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
838
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
839
+ if (i === 3 || i === 5 || i === 7 || i === 9) {
840
+ text += "-";
841
+ }
842
+ }
843
+ return text;
844
+ };
845
+ /**
846
+ * @returns The 32-digit hexadecimal representation without hyphens
847
+ * (`0189dcd553117d408db09496a2eef37b`).
848
+ */
849
+ UUID.prototype.toHex = function () {
850
+ var text = "";
851
+ for (var i = 0; i < this.bytes.length; i++) {
852
+ text += DIGITS.charAt(this.bytes[i] >>> 4);
853
+ text += DIGITS.charAt(this.bytes[i] & 0xf);
854
+ }
855
+ return text;
856
+ };
857
+ /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
858
+ UUID.prototype.toJSON = function () {
859
+ return this.toString();
860
+ };
861
+ /**
862
+ * Reports the variant field value of the UUID or, if appropriate, "NIL" or
863
+ * "MAX".
864
+ *
865
+ * For convenience, this method reports "NIL" or "MAX" if `this` represents
866
+ * the Nil or Max UUID, although the Nil and Max UUIDs are technically
867
+ * subsumed under the variants `0b0` and `0b111`, respectively.
868
+ */
869
+ UUID.prototype.getVariant = function () {
870
+ var n = this.bytes[8] >>> 4;
871
+ if (n < 0) {
872
+ throw new Error("unreachable");
873
+ }
874
+ else if (n <= 7) {
875
+ return this.bytes.every(function (e) { return e === 0; }) ? "NIL" : "VAR_0";
876
+ }
877
+ else if (n <= 11) {
878
+ return "VAR_10";
879
+ }
880
+ else if (n <= 13) {
881
+ return "VAR_110";
882
+ }
883
+ else if (n <= 15) {
884
+ return this.bytes.every(function (e) { return e === 0xff; }) ? "MAX" : "VAR_RESERVED";
885
+ }
886
+ else {
887
+ throw new Error("unreachable");
888
+ }
889
+ };
890
+ /**
891
+ * Returns the version field value of the UUID or `undefined` if the UUID does
892
+ * not have the variant field value of `0b10`.
893
+ */
894
+ UUID.prototype.getVersion = function () {
895
+ return this.getVariant() === "VAR_10" ? this.bytes[6] >>> 4 : undefined;
896
+ };
897
+ /** Creates an object from `this`. */
898
+ UUID.prototype.clone = function () {
899
+ return new UUID(this.bytes.slice(0));
900
+ };
901
+ /** Returns true if `this` is equivalent to `other`. */
902
+ UUID.prototype.equals = function (other) {
903
+ return this.compareTo(other) === 0;
904
+ };
905
+ /**
906
+ * Returns a negative integer, zero, or positive integer if `this` is less
907
+ * than, equal to, or greater than `other`, respectively.
908
+ */
909
+ UUID.prototype.compareTo = function (other) {
910
+ for (var i = 0; i < 16; i++) {
911
+ var diff = this.bytes[i] - other.bytes[i];
912
+ if (diff !== 0) {
913
+ return Math.sign(diff);
914
+ }
915
+ }
916
+ return 0;
917
+ };
918
+ return UUID;
919
+ }());
920
+ /**
921
+ * Encapsulates the monotonic counter state.
922
+ *
923
+ * This class provides APIs to utilize a separate counter state from that of the
924
+ * global generator used by {@link uuidv7} and {@link uuidv7obj}. In addition to
925
+ * the default {@link generate} method, this class has {@link generateOrAbort}
926
+ * that is useful to absolutely guarantee the monotonically increasing order of
927
+ * generated UUIDs. See their respective documentation for details.
928
+ */
929
+ var V7Generator = /** @class */ (function () {
930
+ /**
931
+ * Creates a generator object with the default random number generator, or
932
+ * with the specified one if passed as an argument. The specified random
933
+ * number generator should be cryptographically strong and securely seeded.
934
+ */
935
+ function V7Generator(randomNumberGenerator) {
936
+ this.timestamp = 0;
937
+ this.counter = 0;
938
+ this.random = randomNumberGenerator !== null && randomNumberGenerator !== void 0 ? randomNumberGenerator : getDefaultRandom();
939
+ }
940
+ /**
941
+ * Generates a new UUIDv7 object from the current timestamp, or resets the
942
+ * generator upon significant timestamp rollback.
943
+ *
944
+ * This method returns a monotonically increasing UUID by reusing the previous
945
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
946
+ * preceding UUID's. However, when such a clock rollback is considered
947
+ * significant (i.e., by more than ten seconds), this method resets the
948
+ * generator and returns a new UUID based on the given timestamp, breaking the
949
+ * increasing order of UUIDs.
950
+ *
951
+ * See {@link generateOrAbort} for the other mode of generation and
952
+ * {@link generateOrResetCore} for the low-level primitive.
953
+ */
954
+ V7Generator.prototype.generate = function () {
955
+ return this.generateOrResetCore(Date.now(), 10000);
956
+ };
957
+ /**
958
+ * Generates a new UUIDv7 object from the current timestamp, or returns
959
+ * `undefined` upon significant timestamp rollback.
960
+ *
961
+ * This method returns a monotonically increasing UUID by reusing the previous
962
+ * timestamp even if the up-to-date timestamp is smaller than the immediately
963
+ * preceding UUID's. However, when such a clock rollback is considered
964
+ * significant (i.e., by more than ten seconds), this method aborts and
965
+ * returns `undefined` immediately.
966
+ *
967
+ * See {@link generate} for the other mode of generation and
968
+ * {@link generateOrAbortCore} for the low-level primitive.
969
+ */
970
+ V7Generator.prototype.generateOrAbort = function () {
971
+ return this.generateOrAbortCore(Date.now(), 10000);
972
+ };
973
+ /**
974
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or resets the
975
+ * generator upon significant timestamp rollback.
976
+ *
977
+ * This method is equivalent to {@link generate} except that it takes a custom
978
+ * timestamp and clock rollback allowance.
979
+ *
980
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
981
+ * considered significant. A suggested value is `10_000` (milliseconds).
982
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
983
+ */
984
+ V7Generator.prototype.generateOrResetCore = function (unixTsMs, rollbackAllowance) {
985
+ var value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
986
+ if (value === undefined) {
987
+ // reset state and resume
988
+ this.timestamp = 0;
989
+ value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
990
+ }
991
+ return value;
992
+ };
993
+ /**
994
+ * Generates a new UUIDv7 object from the `unixTsMs` passed, or returns
995
+ * `undefined` upon significant timestamp rollback.
996
+ *
997
+ * This method is equivalent to {@link generateOrAbort} except that it takes a
998
+ * custom timestamp and clock rollback allowance.
999
+ *
1000
+ * @param rollbackAllowance - The amount of `unixTsMs` rollback that is
1001
+ * considered significant. A suggested value is `10_000` (milliseconds).
1002
+ * @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
1003
+ */
1004
+ V7Generator.prototype.generateOrAbortCore = function (unixTsMs, rollbackAllowance) {
1005
+ var MAX_COUNTER = 4398046511103;
1006
+ if (!Number.isInteger(unixTsMs) ||
1007
+ unixTsMs < 1 ||
1008
+ unixTsMs > 281474976710655) {
1009
+ throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
1010
+ }
1011
+ else if (rollbackAllowance < 0 || rollbackAllowance > 281474976710655) {
1012
+ throw new RangeError("`rollbackAllowance` out of reasonable range");
1013
+ }
1014
+ if (unixTsMs > this.timestamp) {
1015
+ this.timestamp = unixTsMs;
1016
+ this.resetCounter();
1017
+ }
1018
+ else if (unixTsMs + rollbackAllowance >= this.timestamp) {
1019
+ // go on with previous timestamp if new one is not much smaller
1020
+ this.counter++;
1021
+ if (this.counter > MAX_COUNTER) {
1022
+ // increment timestamp at counter overflow
1023
+ this.timestamp++;
1024
+ this.resetCounter();
1025
+ }
1026
+ }
1027
+ else {
1028
+ // abort if clock went backwards to unbearable extent
1029
+ return undefined;
1030
+ }
1031
+ return UUID.fromFieldsV7(this.timestamp, Math.trunc(this.counter / Math.pow(2, 30)), this.counter & (Math.pow(2, 30) - 1), this.random.nextUint32());
1032
+ };
1033
+ /** Initializes the counter at a 42-bit random integer. */
1034
+ V7Generator.prototype.resetCounter = function () {
1035
+ this.counter =
1036
+ this.random.nextUint32() * 0x400 + (this.random.nextUint32() & 0x3ff);
1037
+ };
1038
+ /**
1039
+ * Generates a new UUIDv4 object utilizing the random number generator inside.
1040
+ *
1041
+ * @internal
1042
+ */
1043
+ V7Generator.prototype.generateV4 = function () {
1044
+ var bytes = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
1045
+ bytes[6] = 0x40 | (bytes[6] >>> 4);
1046
+ bytes[8] = 0x80 | (bytes[8] >>> 2);
1047
+ return UUID.ofInner(bytes);
1048
+ };
1049
+ return V7Generator;
1050
+ }());
1051
+ /** Returns the default random number generator available in the environment. */
1052
+ 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++];
1085
+ };
1086
+ return BufferedCryptoRandom;
1087
+ }());
1088
+ var defaultGenerator;
1089
+ /**
1090
+ * Generates a UUIDv7 string.
1091
+ *
1092
+ * @returns The 8-4-4-4-12 canonical hexadecimal string representation
1093
+ * ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
1094
+ */
1095
+ var uuidv7 = function () { return uuidv7obj().toString(); };
1096
+ /** Generates a UUIDv7 object. */
1097
+ var uuidv7obj = function () { return (defaultGenerator || (defaultGenerator = new V7Generator())).generate(); };
1098
+
724
1099
  var PostHogFetchHttpError = /** @class */ (function (_super) {
725
1100
  __extends(PostHogFetchHttpError, _super);
726
1101
  function PostHogFetchHttpError(response) {
@@ -812,7 +1187,7 @@ var PostHogCoreStateless = /** @class */ (function () {
812
1187
  };
813
1188
  PostHogCoreStateless.prototype.addPendingPromise = function (promise) {
814
1189
  var _this = this;
815
- var promiseUUID = generateUUID();
1190
+ var promiseUUID = uuidv7();
816
1191
  this.pendingPromises[promiseUUID] = promise;
817
1192
  promise.finally(function () {
818
1193
  delete _this.pendingPromises[promiseUUID];
@@ -1016,7 +1391,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1016
1391
  this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
1017
1392
  return;
1018
1393
  }
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) });
1394
+ 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
1395
  var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
1021
1396
  if (addGeoipDisableProperty) {
1022
1397
  if (!message.properties) {
@@ -1281,7 +1656,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1281
1656
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
1282
1657
  var sessionTimestamp = this.getPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp) || 0;
1283
1658
  if (!sessionId || Date.now() - sessionTimestamp > this._sessionExpirationTimeSeconds * 1000) {
1284
- sessionId = generateUUID(globalThis);
1659
+ sessionId = uuidv7();
1285
1660
  this.setPersistedProperty(PostHogPersistedProperty.SessionId, sessionId);
1286
1661
  }
1287
1662
  this.setPersistedProperty(PostHogPersistedProperty.SessionLastTimestamp, Date.now());
@@ -1293,7 +1668,7 @@ var PostHogCoreStateless = /** @class */ (function () {
1293
1668
  PostHogCore.prototype.getAnonymousId = function () {
1294
1669
  var anonId = this.getPersistedProperty(PostHogPersistedProperty.AnonymousId);
1295
1670
  if (!anonId) {
1296
- anonId = generateUUID(globalThis);
1671
+ anonId = uuidv7();
1297
1672
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, anonId);
1298
1673
  }
1299
1674
  return anonId;
@@ -2450,14 +2825,10 @@ function matchProperty(property, propertyValues) {
2450
2825
 
2451
2826
  case 'is_date_after':
2452
2827
  case 'is_date_before':
2453
- case 'is_relative_date_before':
2454
- case 'is_relative_date_after':
2455
2828
  {
2456
- var parsedDate = null;
2829
+ var parsedDate = relativeDateParseForFeatureFlagMatching(String(value));
2457
2830
 
2458
- if (['is_relative_date_before', 'is_relative_date_after'].includes(operator)) {
2459
- parsedDate = relativeDateParseForFeatureFlagMatching(String(value));
2460
- } else {
2831
+ if (parsedDate == null) {
2461
2832
  parsedDate = convertToDateTime(value);
2462
2833
  }
2463
2834
 
@@ -2467,7 +2838,7 @@ function matchProperty(property, propertyValues) {
2467
2838
 
2468
2839
  var overrideDate = convertToDateTime(overrideValue);
2469
2840
 
2470
- if (['is_date_before', 'is_relative_date_before'].includes(operator)) {
2841
+ if (['is_date_before'].includes(operator)) {
2471
2842
  return overrideDate < parsedDate;
2472
2843
  }
2473
2844
 
@@ -2618,7 +2989,7 @@ function convertToDateTime(value) {
2618
2989
  }
2619
2990
 
2620
2991
  function relativeDateParseForFeatureFlagMatching(value) {
2621
- var regex = /^(?<number>[0-9]+)(?<interval>[a-z])$/;
2992
+ var regex = /^-?(?<number>[0-9]+)(?<interval>[a-z])$/;
2622
2993
  var match = value.match(regex);
2623
2994
  var parsedDt = new Date(new Date().toISOString());
2624
2995
 
@@ -3189,7 +3560,7 @@ function (_super) {
3189
3560
 
3190
3561
  PostHog.prototype.addLocalPersonAndGroupProperties = function (distinctId, groups, personProperties, groupProperties) {
3191
3562
  var allPersonProperties = __assign({
3192
- $current_distinct_id: distinctId
3563
+ distinct_id: distinctId
3193
3564
  }, personProperties || {});
3194
3565
 
3195
3566
  var allGroupProperties = {};