posthog-node 2.4.0 → 2.5.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/lib/index.cjs.js CHANGED
@@ -163,7 +163,7 @@ function __spreadArray(to, from, pack) {
163
163
  return to.concat(ar || Array.prototype.slice.call(from));
164
164
  }
165
165
 
166
- var version = "2.4.0";
166
+ var version = "2.5.0";
167
167
 
168
168
  var PostHogPersistedProperty;
169
169
  (function (PostHogPersistedProperty) {
@@ -722,11 +722,9 @@ var SimpleEventEmitter = /** @class */ (function () {
722
722
  return SimpleEventEmitter;
723
723
  }());
724
724
 
725
- var PostHogCore = /** @class */ (function () {
726
- function PostHogCore(apiKey, options) {
727
- var _this = this;
728
- var _a, _b, _c, _d, _e, _f;
729
- this.flagCallReported = {};
725
+ var PostHogCoreStateless = /** @class */ (function () {
726
+ function PostHogCoreStateless(apiKey, options) {
727
+ var _a, _b, _c, _d;
730
728
  // internal
731
729
  this._events = new SimpleEventEmitter();
732
730
  assert(apiKey, "You must pass your PostHog project's api key.");
@@ -735,33 +733,375 @@ var PostHogCore = /** @class */ (function () {
735
733
  this.flushAt = (options === null || options === void 0 ? void 0 : options.flushAt) ? Math.max(options === null || options === void 0 ? void 0 : options.flushAt, 1) : 20;
736
734
  this.flushInterval = (_a = options === null || options === void 0 ? void 0 : options.flushInterval) !== null && _a !== void 0 ? _a : 10000;
737
735
  this.captureMode = (options === null || options === void 0 ? void 0 : options.captureMode) || 'form';
738
- this.sendFeatureFlagEvent = (_b = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _b !== void 0 ? _b : true;
739
736
  // If enable is explicitly set to false we override the optout
740
737
  this._optoutOverride = (options === null || options === void 0 ? void 0 : options.enable) === false;
741
738
  this._retryOptions = {
742
- retryCount: (_c = options === null || options === void 0 ? void 0 : options.fetchRetryCount) !== null && _c !== void 0 ? _c : 3,
743
- retryDelay: (_d = options === null || options === void 0 ? void 0 : options.fetchRetryDelay) !== null && _d !== void 0 ? _d : 3000,
739
+ retryCount: (_b = options === null || options === void 0 ? void 0 : options.fetchRetryCount) !== null && _b !== void 0 ? _b : 3,
740
+ retryDelay: (_c = options === null || options === void 0 ? void 0 : options.fetchRetryDelay) !== null && _c !== void 0 ? _c : 3000,
744
741
  };
745
- this.requestTimeout = (_e = options === null || options === void 0 ? void 0 : options.requestTimeout) !== null && _e !== void 0 ? _e : 10000; // 10 seconds
746
- this._sessionExpirationTimeSeconds = (_f = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _f !== void 0 ? _f : 1800; // 30 minutes
742
+ this.requestTimeout = (_d = options === null || options === void 0 ? void 0 : options.requestTimeout) !== null && _d !== void 0 ? _d : 10000; // 10 seconds
743
+ }
744
+ PostHogCoreStateless.prototype.getCommonEventProperties = function () {
745
+ return {
746
+ $lib: this.getLibraryId(),
747
+ $lib_version: this.getLibraryVersion(),
748
+ };
749
+ };
750
+ Object.defineProperty(PostHogCoreStateless.prototype, "optedOut", {
751
+ get: function () {
752
+ var _a, _b;
753
+ return (_b = (_a = this.getPersistedProperty(PostHogPersistedProperty.OptedOut)) !== null && _a !== void 0 ? _a : this._optoutOverride) !== null && _b !== void 0 ? _b : false;
754
+ },
755
+ enumerable: false,
756
+ configurable: true
757
+ });
758
+ PostHogCoreStateless.prototype.optIn = function () {
759
+ this.setPersistedProperty(PostHogPersistedProperty.OptedOut, false);
760
+ };
761
+ PostHogCoreStateless.prototype.optOut = function () {
762
+ this.setPersistedProperty(PostHogPersistedProperty.OptedOut, true);
763
+ };
764
+ PostHogCoreStateless.prototype.on = function (event, cb) {
765
+ return this._events.on(event, cb);
766
+ };
767
+ PostHogCoreStateless.prototype.debug = function (enabled) {
768
+ var _a;
769
+ if (enabled === void 0) { enabled = true; }
770
+ (_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
771
+ if (enabled) {
772
+ this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
773
+ }
774
+ };
775
+ PostHogCoreStateless.prototype.buildPayload = function (payload) {
776
+ return {
777
+ distinct_id: payload.distinct_id,
778
+ event: payload.event,
779
+ properties: __assign(__assign({}, (payload.properties || {})), this.getCommonEventProperties()),
780
+ };
781
+ };
782
+ /***
783
+ *** TRACKING
784
+ ***/
785
+ PostHogCoreStateless.prototype.identifyStateless = function (distinctId, properties, options) {
786
+ // The properties passed to identifyStateless are event properties.
787
+ // To add person properties, pass in all person properties to the `$set` key.
788
+ var payload = __assign({}, this.buildPayload({
789
+ distinct_id: distinctId,
790
+ event: '$identify',
791
+ properties: properties,
792
+ }));
793
+ this.enqueue('identify', payload, options);
794
+ return this;
795
+ };
796
+ PostHogCoreStateless.prototype.captureStateless = function (distinctId, event, properties, options) {
797
+ var payload = this.buildPayload({ distinct_id: distinctId, event: event, properties: properties });
798
+ this.enqueue('capture', payload, options);
799
+ return this;
800
+ };
801
+ PostHogCoreStateless.prototype.aliasStateless = function (alias, distinctId, properties) {
802
+ var payload = this.buildPayload({
803
+ event: '$create_alias',
804
+ distinct_id: distinctId,
805
+ properties: __assign(__assign({}, (properties || {})), { distinct_id: distinctId, alias: alias }),
806
+ });
807
+ this.enqueue('alias', payload);
808
+ return this;
809
+ };
810
+ /***
811
+ *** GROUPS
812
+ ***/
813
+ PostHogCoreStateless.prototype.groupIdentifyStateless = function (groupType, groupKey, groupProperties, options, distinctId, eventProperties) {
814
+ var payload = this.buildPayload({
815
+ distinct_id: distinctId || "$".concat(groupType, "_").concat(groupKey),
816
+ event: '$groupidentify',
817
+ properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, (eventProperties || {})),
818
+ });
819
+ this.enqueue('capture', payload, options);
820
+ return this;
821
+ };
822
+ /***
823
+ *** FEATURE FLAGS
824
+ ***/
825
+ PostHogCoreStateless.prototype.getDecide = function (distinctId, groups, personProperties, groupProperties, extraPayload) {
826
+ if (groups === void 0) { groups = {}; }
827
+ if (personProperties === void 0) { personProperties = {}; }
828
+ if (groupProperties === void 0) { groupProperties = {}; }
829
+ if (extraPayload === void 0) { extraPayload = {}; }
830
+ return __awaiter(this, void 0, void 0, function () {
831
+ var url, fetchOptions;
832
+ return __generator(this, function (_a) {
833
+ url = "".concat(this.host, "/decide/?v=3");
834
+ fetchOptions = {
835
+ method: 'POST',
836
+ headers: { 'Content-Type': 'application/json' },
837
+ body: JSON.stringify(__assign({ token: this.apiKey, distinct_id: distinctId, groups: groups, person_properties: personProperties, group_properties: groupProperties }, extraPayload)),
838
+ };
839
+ return [2 /*return*/, this.fetchWithRetry(url, fetchOptions)
840
+ .then(function (response) { return response.json(); })
841
+ .catch(function (error) {
842
+ console.error('Error fetching feature flags', error);
843
+ return undefined;
844
+ })];
845
+ });
846
+ });
847
+ };
848
+ PostHogCoreStateless.prototype.getFeatureFlagStateless = function (key, distinctId, groups, personProperties, groupProperties) {
849
+ if (groups === void 0) { groups = {}; }
850
+ if (personProperties === void 0) { personProperties = {}; }
851
+ if (groupProperties === void 0) { groupProperties = {}; }
852
+ return __awaiter(this, void 0, void 0, function () {
853
+ var featureFlags, response;
854
+ return __generator(this, function (_a) {
855
+ switch (_a.label) {
856
+ case 0: return [4 /*yield*/, this.getFeatureFlagsStateless(distinctId, groups, personProperties, groupProperties)];
857
+ case 1:
858
+ featureFlags = _a.sent();
859
+ if (!featureFlags) {
860
+ // If we haven't loaded flags yet, or errored out, we respond with undefined
861
+ return [2 /*return*/, undefined];
862
+ }
863
+ response = featureFlags[key];
864
+ // `/decide` v3 returns all flags
865
+ if (response === undefined) {
866
+ // For cases where the flag is unknown, return false
867
+ response = false;
868
+ }
869
+ // If we have flags we either return the value (true or string) or false
870
+ return [2 /*return*/, response];
871
+ }
872
+ });
873
+ });
874
+ };
875
+ PostHogCoreStateless.prototype.getFeatureFlagPayloadStateless = function (key, distinctId, groups, personProperties, groupProperties) {
876
+ if (groups === void 0) { groups = {}; }
877
+ if (personProperties === void 0) { personProperties = {}; }
878
+ if (groupProperties === void 0) { groupProperties = {}; }
879
+ return __awaiter(this, void 0, void 0, function () {
880
+ var payloads, response;
881
+ return __generator(this, function (_a) {
882
+ switch (_a.label) {
883
+ case 0: return [4 /*yield*/, this.getFeatureFlagPayloadsStateless(distinctId, groups, personProperties, groupProperties)];
884
+ case 1:
885
+ payloads = _a.sent();
886
+ if (!payloads) {
887
+ return [2 /*return*/, undefined];
888
+ }
889
+ response = payloads[key];
890
+ // Undefined means a loading or missing data issue. Null means evaluation happened and there was no match
891
+ if (response === undefined) {
892
+ return [2 /*return*/, null];
893
+ }
894
+ return [2 /*return*/, this._parsePayload(response)];
895
+ }
896
+ });
897
+ });
898
+ };
899
+ PostHogCoreStateless.prototype.getFeatureFlagPayloadsStateless = function (distinctId, groups, personProperties, groupProperties) {
900
+ if (groups === void 0) { groups = {}; }
901
+ if (personProperties === void 0) { personProperties = {}; }
902
+ if (groupProperties === void 0) { groupProperties = {}; }
903
+ return __awaiter(this, void 0, void 0, function () {
904
+ var payloads;
905
+ var _this = this;
906
+ return __generator(this, function (_a) {
907
+ switch (_a.label) {
908
+ case 0: return [4 /*yield*/, this.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties)];
909
+ case 1:
910
+ payloads = (_a.sent()).payloads;
911
+ if (payloads) {
912
+ return [2 /*return*/, Object.fromEntries(Object.entries(payloads).map(function (_a) {
913
+ var k = _a[0], v = _a[1];
914
+ return [k, _this._parsePayload(v)];
915
+ }))];
916
+ }
917
+ return [2 /*return*/, payloads];
918
+ }
919
+ });
920
+ });
921
+ };
922
+ PostHogCoreStateless.prototype._parsePayload = function (response) {
923
+ try {
924
+ return JSON.parse(response);
925
+ }
926
+ catch (_a) {
927
+ return response;
928
+ }
929
+ };
930
+ PostHogCoreStateless.prototype.getFeatureFlagsStateless = function (distinctId, groups, personProperties, groupProperties) {
931
+ if (groups === void 0) { groups = {}; }
932
+ if (personProperties === void 0) { personProperties = {}; }
933
+ if (groupProperties === void 0) { groupProperties = {}; }
934
+ return __awaiter(this, void 0, void 0, function () {
935
+ return __generator(this, function (_a) {
936
+ switch (_a.label) {
937
+ case 0: return [4 /*yield*/, this.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties)];
938
+ case 1: return [2 /*return*/, (_a.sent()).flags];
939
+ }
940
+ });
941
+ });
942
+ };
943
+ PostHogCoreStateless.prototype.getFeatureFlagsAndPayloadsStateless = function (distinctId, groups, personProperties, groupProperties) {
944
+ if (groups === void 0) { groups = {}; }
945
+ if (personProperties === void 0) { personProperties = {}; }
946
+ if (groupProperties === void 0) { groupProperties = {}; }
947
+ return __awaiter(this, void 0, void 0, function () {
948
+ var decideResponse, flags, payloads;
949
+ return __generator(this, function (_a) {
950
+ switch (_a.label) {
951
+ case 0: return [4 /*yield*/, this.getDecide(distinctId, groups, personProperties, groupProperties)];
952
+ case 1:
953
+ decideResponse = _a.sent();
954
+ flags = decideResponse === null || decideResponse === void 0 ? void 0 : decideResponse.featureFlags;
955
+ payloads = decideResponse === null || decideResponse === void 0 ? void 0 : decideResponse.featureFlagPayloads;
956
+ return [2 /*return*/, {
957
+ flags: flags,
958
+ payloads: payloads,
959
+ }];
960
+ }
961
+ });
962
+ });
963
+ };
964
+ /***
965
+ *** QUEUEING AND FLUSHING
966
+ ***/
967
+ PostHogCoreStateless.prototype.enqueue = function (type, _message, options) {
968
+ var _this = this;
969
+ if (this.optedOut) {
970
+ this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.enable()");
971
+ return;
972
+ }
973
+ 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() });
974
+ if (message.distinctId) {
975
+ message.distinct_id = message.distinctId;
976
+ delete message.distinctId;
977
+ }
978
+ var queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
979
+ queue.push({ message: message });
980
+ this.setPersistedProperty(PostHogPersistedProperty.Queue, queue);
981
+ this._events.emit(type, message);
982
+ // Flush queued events if we meet the flushAt length
983
+ if (queue.length >= this.flushAt) {
984
+ this.flush();
985
+ }
986
+ if (this.flushInterval && !this._flushTimer) {
987
+ this._flushTimer = safeSetTimeout(function () { return _this.flush(); }, this.flushInterval);
988
+ }
989
+ };
990
+ PostHogCoreStateless.prototype.flushAsync = function () {
991
+ var _this = this;
992
+ return new Promise(function (resolve, reject) {
993
+ _this.flush(function (err, data) {
994
+ return err ? reject(err) : resolve(data);
995
+ });
996
+ });
997
+ };
998
+ PostHogCoreStateless.prototype.flush = function (callback) {
999
+ var _this = this;
1000
+ if (this._flushTimer) {
1001
+ clearTimeout(this._flushTimer);
1002
+ this._flushTimer = null;
1003
+ }
1004
+ var queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
1005
+ if (!queue.length) {
1006
+ return callback === null || callback === void 0 ? void 0 : callback();
1007
+ }
1008
+ var items = queue.splice(0, this.flushAt);
1009
+ this.setPersistedProperty(PostHogPersistedProperty.Queue, queue);
1010
+ var messages = items.map(function (item) { return item.message; });
1011
+ var data = {
1012
+ api_key: this.apiKey,
1013
+ batch: messages,
1014
+ sent_at: currentISOTime(),
1015
+ };
1016
+ var done = function (err) {
1017
+ callback === null || callback === void 0 ? void 0 : callback(err, messages);
1018
+ _this._events.emit('flush', messages);
1019
+ };
1020
+ // Don't set the user agent if we're not on a browser. The latest spec allows
1021
+ // the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
1022
+ // and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
1023
+ // but browsers such as Chrome and Safari have not caught up.
1024
+ this.getCustomUserAgent();
1025
+ var payload = JSON.stringify(data);
1026
+ var url = this.captureMode === 'form'
1027
+ ? "".concat(this.host, "/e/?ip=1&_=").concat(currentTimestamp(), "&v=").concat(this.getLibraryVersion())
1028
+ : "".concat(this.host, "/batch/");
1029
+ var fetchOptions = this.captureMode === 'form'
1030
+ ? {
1031
+ method: 'POST',
1032
+ mode: 'no-cors',
1033
+ credentials: 'omit',
1034
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1035
+ body: "data=".concat(encodeURIComponent(LZString.compressToBase64(payload)), "&compression=lz64"),
1036
+ }
1037
+ : {
1038
+ method: 'POST',
1039
+ headers: { 'Content-Type': 'application/json' },
1040
+ body: payload,
1041
+ };
1042
+ this.fetchWithRetry(url, fetchOptions)
1043
+ .then(function () { return done(); })
1044
+ .catch(function (err) {
1045
+ if (err.response) {
1046
+ var error = new Error(err.response.statusText);
1047
+ return done(error);
1048
+ }
1049
+ done(err);
1050
+ });
1051
+ };
1052
+ PostHogCoreStateless.prototype.fetchWithRetry = function (url, options, retryOptions) {
1053
+ var _a;
1054
+ var _b;
1055
+ return __awaiter(this, void 0, void 0, function () {
1056
+ var _this = this;
1057
+ return __generator(this, function (_c) {
1058
+ (_a = (_b = AbortSignal).timeout) !== null && _a !== void 0 ? _a : (_b.timeout = function timeout(ms) {
1059
+ var ctrl = new AbortController();
1060
+ setTimeout(function () { return ctrl.abort(); }, ms);
1061
+ return ctrl.signal;
1062
+ });
1063
+ return [2 /*return*/, retriable(function () {
1064
+ return _this.fetch(url, __assign({ signal: AbortSignal.timeout(_this.requestTimeout) }, options));
1065
+ }, retryOptions || this._retryOptions)];
1066
+ });
1067
+ });
1068
+ };
1069
+ PostHogCoreStateless.prototype.shutdownAsync = function () {
1070
+ return __awaiter(this, void 0, void 0, function () {
1071
+ return __generator(this, function (_a) {
1072
+ switch (_a.label) {
1073
+ case 0:
1074
+ clearTimeout(this._flushTimer);
1075
+ return [4 /*yield*/, this.flushAsync()];
1076
+ case 1:
1077
+ _a.sent();
1078
+ return [2 /*return*/];
1079
+ }
1080
+ });
1081
+ });
1082
+ };
1083
+ PostHogCoreStateless.prototype.shutdown = function () {
1084
+ void this.shutdownAsync();
1085
+ };
1086
+ return PostHogCoreStateless;
1087
+ }());
1088
+ /** @class */ ((function (_super) {
1089
+ __extends(PostHogCore, _super);
1090
+ function PostHogCore(apiKey, options) {
1091
+ var _this = this;
1092
+ var _a, _b;
1093
+ _this = _super.call(this, apiKey, options) || this;
1094
+ _this.flagCallReported = {};
1095
+ _this.sendFeatureFlagEvent = (_a = options === null || options === void 0 ? void 0 : options.sendFeatureFlagEvent) !== null && _a !== void 0 ? _a : true;
1096
+ _this._sessionExpirationTimeSeconds = (_b = options === null || options === void 0 ? void 0 : options.sessionExpirationTimeSeconds) !== null && _b !== void 0 ? _b : 1800; // 30 minutes
747
1097
  // NOTE: It is important we don't initiate anything in the constructor as some async IO may still be underway on the parent
748
1098
  if ((options === null || options === void 0 ? void 0 : options.preloadFeatureFlags) !== false) {
749
1099
  safeSetTimeout(function () {
750
- void _this.reloadFeatureFlagsAsync();
1100
+ _this.reloadFeatureFlags();
751
1101
  }, 1);
752
1102
  }
1103
+ return _this;
753
1104
  }
754
- PostHogCore.prototype.getCommonEventProperties = function () {
755
- var featureFlags = this.getFeatureFlags();
756
- var featureVariantProperties = {};
757
- if (featureFlags) {
758
- for (var _i = 0, _a = Object.entries(featureFlags); _i < _a.length; _i++) {
759
- var _b = _a[_i], feature = _b[0], variant = _b[1];
760
- featureVariantProperties["$feature/".concat(feature)] = variant;
761
- }
762
- }
763
- return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
764
- };
765
1105
  PostHogCore.prototype.setupBootstrap = function (options) {
766
1106
  var _a, _b, _c, _d;
767
1107
  if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
@@ -800,20 +1140,6 @@ var PostHogCore = /** @class */ (function () {
800
1140
  PostHogCore.prototype.clearProps = function () {
801
1141
  this.props = undefined;
802
1142
  };
803
- Object.defineProperty(PostHogCore.prototype, "optedOut", {
804
- get: function () {
805
- var _a, _b;
806
- return (_b = (_a = this.getPersistedProperty(PostHogPersistedProperty.OptedOut)) !== null && _a !== void 0 ? _a : this._optoutOverride) !== null && _b !== void 0 ? _b : false;
807
- },
808
- enumerable: false,
809
- configurable: true
810
- });
811
- PostHogCore.prototype.optIn = function () {
812
- this.setPersistedProperty(PostHogPersistedProperty.OptedOut, false);
813
- };
814
- PostHogCore.prototype.optOut = function () {
815
- this.setPersistedProperty(PostHogPersistedProperty.OptedOut, true);
816
- };
817
1143
  PostHogCore.prototype.on = function (event, cb) {
818
1144
  return this._events.on(event, cb);
819
1145
  };
@@ -828,20 +1154,19 @@ var PostHogCore = /** @class */ (function () {
828
1154
  }
829
1155
  }
830
1156
  };
831
- PostHogCore.prototype.debug = function (enabled) {
832
- var _a;
833
- if (enabled === void 0) { enabled = true; }
834
- (_a = this.removeDebugCallback) === null || _a === void 0 ? void 0 : _a.call(this);
835
- if (enabled) {
836
- this.removeDebugCallback = this.on('*', function (event, payload) { return console.log('PostHog Debug', event, payload); });
1157
+ PostHogCore.prototype.getCommonEventProperties = function () {
1158
+ var featureFlags = this.getFeatureFlags();
1159
+ var featureVariantProperties = {};
1160
+ if (featureFlags) {
1161
+ for (var _i = 0, _a = Object.entries(featureFlags); _i < _a.length; _i++) {
1162
+ var _b = _a[_i], feature = _b[0], variant = _b[1];
1163
+ featureVariantProperties["$feature/".concat(feature)] = variant;
1164
+ }
837
1165
  }
1166
+ return __assign(__assign({ $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties), _super.prototype.getCommonEventProperties.call(this));
838
1167
  };
839
- PostHogCore.prototype.buildPayload = function (payload) {
840
- return {
841
- distinct_id: payload.distinct_id || this.getDistinctId(),
842
- event: payload.event,
843
- properties: __assign(__assign(__assign(__assign({}, this.props), (payload.properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() }),
844
- };
1168
+ PostHogCore.prototype.enrichProperties = function (properties) {
1169
+ return __assign(__assign(__assign(__assign({}, this.props), (properties || {})), this.getCommonEventProperties()), { $session_id: this.getSessionId() });
845
1170
  };
846
1171
  PostHogCore.prototype.getSessionId = function () {
847
1172
  var sessionId = this.getPersistedProperty(PostHogPersistedProperty.SessionId);
@@ -884,48 +1209,41 @@ var PostHogCore = /** @class */ (function () {
884
1209
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
885
1210
  this.groups(properties.$groups);
886
1211
  }
887
- var payload = __assign(__assign({}, this.buildPayload({
888
- distinct_id: distinctId,
889
- event: '$identify',
890
- properties: __assign(__assign({}, (properties || {})), { $anon_distinct_id: this.getAnonymousId() }),
891
- })), { $set: properties });
1212
+ var allProperties = this.enrichProperties(__assign(__assign({}, properties), { $anon_distinct_id: this.getAnonymousId(), $set: properties }));
892
1213
  if (distinctId !== previousDistinctId) {
893
1214
  // We keep the AnonymousId to be used by decide calls and identify to link the previousId
894
1215
  this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, previousDistinctId);
895
1216
  this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
896
1217
  if (this.getFeatureFlags()) {
897
- void this.reloadFeatureFlagsAsync();
1218
+ this.reloadFeatureFlags();
898
1219
  }
899
1220
  }
900
- this.enqueue('identify', payload, options);
1221
+ _super.prototype.identifyStateless.call(this, distinctId, allProperties, options);
901
1222
  return this;
902
1223
  };
903
1224
  PostHogCore.prototype.capture = function (event, properties, options) {
1225
+ var distinctId = this.getDistinctId();
904
1226
  if (properties === null || properties === void 0 ? void 0 : properties.$groups) {
905
1227
  this.groups(properties.$groups);
906
1228
  }
907
- var payload = this.buildPayload({ event: event, properties: properties });
908
- this.enqueue('capture', payload, options);
1229
+ var allProperties = this.enrichProperties(properties);
1230
+ _super.prototype.captureStateless.call(this, distinctId, event, allProperties, options);
909
1231
  return this;
910
1232
  };
911
1233
  PostHogCore.prototype.alias = function (alias) {
912
1234
  var distinctId = this.getDistinctId();
913
- var payload = this.buildPayload({
914
- event: '$create_alias',
915
- properties: {
916
- distinct_id: distinctId,
917
- alias: alias,
918
- },
919
- });
920
- this.enqueue('alias', payload);
1235
+ var allProperties = this.enrichProperties({});
1236
+ _super.prototype.aliasStateless.call(this, alias, distinctId, allProperties);
921
1237
  return this;
922
1238
  };
923
1239
  PostHogCore.prototype.autocapture = function (eventType, elements, properties, options) {
924
1240
  if (properties === void 0) { properties = {}; }
925
- var payload = this.buildPayload({
1241
+ var distinctId = this.getDistinctId();
1242
+ var payload = {
1243
+ distinct_id: distinctId,
926
1244
  event: '$autocapture',
927
- properties: __assign(__assign({}, properties), { $event_type: eventType, $elements: elements }),
928
- });
1245
+ properties: __assign(__assign({}, this.enrichProperties(properties)), { $event_type: eventType, $elements: elements }),
1246
+ };
929
1247
  this.enqueue('autocapture', payload, options);
930
1248
  return this;
931
1249
  };
@@ -939,7 +1257,7 @@ var PostHogCore = /** @class */ (function () {
939
1257
  $groups: __assign(__assign({}, existingGroups), groups),
940
1258
  });
941
1259
  if (Object.keys(groups).find(function (type) { return existingGroups[type] !== groups[type]; }) && this.getFeatureFlags()) {
942
- void this.reloadFeatureFlagsAsync();
1260
+ this.reloadFeatureFlags();
943
1261
  }
944
1262
  return this;
945
1263
  };
@@ -954,11 +1272,9 @@ var PostHogCore = /** @class */ (function () {
954
1272
  return this;
955
1273
  };
956
1274
  PostHogCore.prototype.groupIdentify = function (groupType, groupKey, groupProperties, options) {
957
- var payload = this.buildPayload({
958
- event: '$groupidentify',
959
- properties: __assign({ $group_type: groupType, $group_key: groupKey, $group_set: groupProperties || {} }, this.getCommonEventProperties()),
960
- });
961
- this.enqueue('capture', payload, options);
1275
+ var distinctId = this.getDistinctId();
1276
+ var eventProperties = this.enrichProperties({});
1277
+ _super.prototype.groupIdentifyStateless.call(this, groupType, groupKey, groupProperties, options, distinctId, eventProperties);
962
1278
  return this;
963
1279
  };
964
1280
  /***
@@ -995,30 +1311,19 @@ var PostHogCore = /** @class */ (function () {
995
1311
  PostHogCore.prototype._decideAsync = function (sendAnonDistinctId) {
996
1312
  if (sendAnonDistinctId === void 0) { sendAnonDistinctId = true; }
997
1313
  return __awaiter(this, void 0, void 0, function () {
998
- var url, distinctId, groups, personProperties, groupProperties, fetchOptions;
1314
+ var distinctId, groups, personProperties, groupProperties, extraProperties;
999
1315
  var _this = this;
1000
1316
  return __generator(this, function (_a) {
1001
- url = "".concat(this.host, "/decide/?v=3");
1002
1317
  distinctId = this.getDistinctId();
1003
1318
  groups = this.props.$groups || {};
1004
1319
  personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
1005
1320
  groupProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
1006
- fetchOptions = {
1007
- method: 'POST',
1008
- headers: { 'Content-Type': 'application/json' },
1009
- body: JSON.stringify({
1010
- token: this.apiKey,
1011
- distinct_id: distinctId,
1012
- $anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : undefined,
1013
- groups: groups,
1014
- person_properties: personProperties,
1015
- group_properties: groupProperties,
1016
- }),
1321
+ extraProperties = {
1322
+ $anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : undefined,
1017
1323
  };
1018
- this._decideResponsePromise = this.fetchWithRetry(url, fetchOptions)
1019
- .then(function (r) { return r.json(); })
1324
+ this._decideResponsePromise = _super.prototype.getDecide.call(this, distinctId, groups, personProperties, groupProperties, extraProperties)
1020
1325
  .then(function (res) {
1021
- if (res.featureFlags) {
1326
+ if (res === null || res === void 0 ? void 0 : res.featureFlags) {
1022
1327
  var newFeatureFlags = res.featureFlags;
1023
1328
  var newFeatureFlagPayloads = res.featureFlagPayloads;
1024
1329
  if (res.errorsWhileComputingFlags) {
@@ -1092,14 +1397,6 @@ var PostHogCore = /** @class */ (function () {
1092
1397
  }
1093
1398
  return payloads;
1094
1399
  };
1095
- PostHogCore.prototype._parsePayload = function (response) {
1096
- try {
1097
- return JSON.parse(response);
1098
- }
1099
- catch (_a) {
1100
- return response;
1101
- }
1102
- };
1103
1400
  PostHogCore.prototype.getFeatureFlags = function () {
1104
1401
  var flags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
1105
1402
  var overriddenFlags = this.getPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags);
@@ -1132,13 +1429,27 @@ var PostHogCore = /** @class */ (function () {
1132
1429
  }
1133
1430
  return !!response;
1134
1431
  };
1432
+ // Used when we want to trigger the reload but we don't care about the result
1433
+ PostHogCore.prototype.reloadFeatureFlags = function (cb) {
1434
+ this.decideAsync()
1435
+ .then(function (res) {
1436
+ cb === null || cb === void 0 ? void 0 : cb(undefined, res === null || res === void 0 ? void 0 : res.featureFlags);
1437
+ })
1438
+ .catch(function (e) {
1439
+ cb === null || cb === void 0 ? void 0 : cb(e, undefined);
1440
+ if (!cb) {
1441
+ console.log('[PostHog] Error reloading feature flags', e);
1442
+ }
1443
+ });
1444
+ };
1135
1445
  PostHogCore.prototype.reloadFeatureFlagsAsync = function (sendAnonDistinctId) {
1446
+ var _a;
1136
1447
  if (sendAnonDistinctId === void 0) { sendAnonDistinctId = true; }
1137
1448
  return __awaiter(this, void 0, void 0, function () {
1138
- return __generator(this, function (_a) {
1139
- switch (_a.label) {
1449
+ return __generator(this, function (_b) {
1450
+ switch (_b.label) {
1140
1451
  case 0: return [4 /*yield*/, this.decideAsync(sendAnonDistinctId)];
1141
- case 1: return [2 /*return*/, (_a.sent()).featureFlags];
1452
+ case 1: return [2 /*return*/, (_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.featureFlags];
1142
1453
  }
1143
1454
  });
1144
1455
  });
@@ -1175,132 +1486,8 @@ var PostHogCore = /** @class */ (function () {
1175
1486
  }
1176
1487
  return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1177
1488
  };
1178
- /***
1179
- *** QUEUEING AND FLUSHING
1180
- ***/
1181
- PostHogCore.prototype.enqueue = function (type, _message, options) {
1182
- var _this = this;
1183
- if (this.optedOut) {
1184
- return;
1185
- }
1186
- 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() });
1187
- if (message.distinctId) {
1188
- message.distinct_id = message.distinctId;
1189
- delete message.distinctId;
1190
- }
1191
- var queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
1192
- queue.push({ message: message });
1193
- this.setPersistedProperty(PostHogPersistedProperty.Queue, queue);
1194
- this._events.emit(type, message);
1195
- // Flush queued events if we meet the flushAt length
1196
- if (queue.length >= this.flushAt) {
1197
- this.flush();
1198
- }
1199
- if (this.flushInterval && !this._flushTimer) {
1200
- this._flushTimer = safeSetTimeout(function () { return _this.flush(); }, this.flushInterval);
1201
- }
1202
- };
1203
- PostHogCore.prototype.flushAsync = function () {
1204
- var _this = this;
1205
- return new Promise(function (resolve, reject) {
1206
- _this.flush(function (err, data) {
1207
- return err ? reject(err) : resolve(data);
1208
- });
1209
- });
1210
- };
1211
- PostHogCore.prototype.flush = function (callback) {
1212
- var _this = this;
1213
- if (this.optedOut) {
1214
- return callback === null || callback === void 0 ? void 0 : callback();
1215
- }
1216
- if (this._flushTimer) {
1217
- clearTimeout(this._flushTimer);
1218
- this._flushTimer = null;
1219
- }
1220
- var queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
1221
- if (!queue.length) {
1222
- return callback === null || callback === void 0 ? void 0 : callback();
1223
- }
1224
- var items = queue.splice(0, this.flushAt);
1225
- this.setPersistedProperty(PostHogPersistedProperty.Queue, queue);
1226
- var messages = items.map(function (item) { return item.message; });
1227
- var data = {
1228
- api_key: this.apiKey,
1229
- batch: messages,
1230
- sent_at: currentISOTime(),
1231
- };
1232
- var done = function (err) {
1233
- callback === null || callback === void 0 ? void 0 : callback(err, messages);
1234
- _this._events.emit('flush', messages);
1235
- };
1236
- // Don't set the user agent if we're not on a browser. The latest spec allows
1237
- // the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
1238
- // and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
1239
- // but browsers such as Chrome and Safari have not caught up.
1240
- this.getCustomUserAgent();
1241
- var payload = JSON.stringify(data);
1242
- var url = this.captureMode === 'form'
1243
- ? "".concat(this.host, "/e/?ip=1&_=").concat(currentTimestamp(), "&v=").concat(this.getLibraryVersion())
1244
- : "".concat(this.host, "/batch/");
1245
- var fetchOptions = this.captureMode === 'form'
1246
- ? {
1247
- method: 'POST',
1248
- mode: 'no-cors',
1249
- credentials: 'omit',
1250
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
1251
- body: "data=".concat(encodeURIComponent(LZString.compressToBase64(payload)), "&compression=lz64"),
1252
- }
1253
- : {
1254
- method: 'POST',
1255
- headers: { 'Content-Type': 'application/json' },
1256
- body: payload,
1257
- };
1258
- this.fetchWithRetry(url, fetchOptions)
1259
- .then(function () { return done(); })
1260
- .catch(function (err) {
1261
- if (err.response) {
1262
- var error = new Error(err.response.statusText);
1263
- return done(error);
1264
- }
1265
- done(err);
1266
- });
1267
- };
1268
- PostHogCore.prototype.fetchWithRetry = function (url, options, retryOptions) {
1269
- var _a;
1270
- var _b;
1271
- return __awaiter(this, void 0, void 0, function () {
1272
- var _this = this;
1273
- return __generator(this, function (_c) {
1274
- (_a = (_b = AbortSignal).timeout) !== null && _a !== void 0 ? _a : (_b.timeout = function timeout(ms) {
1275
- var ctrl = new AbortController();
1276
- setTimeout(function () { return ctrl.abort(); }, ms);
1277
- return ctrl.signal;
1278
- });
1279
- return [2 /*return*/, retriable(function () {
1280
- return _this.fetch(url, __assign({ signal: AbortSignal.timeout(_this.requestTimeout) }, options));
1281
- }, retryOptions || this._retryOptions)];
1282
- });
1283
- });
1284
- };
1285
- PostHogCore.prototype.shutdownAsync = function () {
1286
- return __awaiter(this, void 0, void 0, function () {
1287
- return __generator(this, function (_a) {
1288
- switch (_a.label) {
1289
- case 0:
1290
- clearTimeout(this._flushTimer);
1291
- return [4 /*yield*/, this.flushAsync()];
1292
- case 1:
1293
- _a.sent();
1294
- return [2 /*return*/];
1295
- }
1296
- });
1297
- });
1298
- };
1299
- PostHogCore.prototype.shutdown = function () {
1300
- void this.shutdownAsync();
1301
- };
1302
1489
  return PostHogCore;
1303
- }());
1490
+ })(PostHogCoreStateless));
1304
1491
 
1305
1492
  var PostHogMemoryStorage = /** @class */ (function () {
1306
1493
  function PostHogMemoryStorage() {
@@ -2065,104 +2252,73 @@ function convertToDateTime(value) {
2065
2252
  }
2066
2253
 
2067
2254
  var THIRTY_SECONDS = 30 * 1000;
2068
- var MAX_CACHE_SIZE = 50 * 1000;
2255
+ var MAX_CACHE_SIZE = 50 * 1000; // The actual exported Nodejs API.
2069
2256
 
2070
- var PostHogClient =
2257
+ var PostHog =
2071
2258
  /** @class */
2072
2259
  function (_super) {
2073
- __extends(PostHogClient, _super);
2260
+ __extends(PostHog, _super);
2074
2261
 
2075
- function PostHogClient(apiKey, options) {
2262
+ function PostHog(apiKey, options) {
2076
2263
  if (options === void 0) {
2077
2264
  options = {};
2078
2265
  }
2079
2266
 
2080
2267
  var _this = this;
2081
2268
 
2082
- options.captureMode = (options === null || options === void 0 ? void 0 : options.captureMode) || 'json';
2083
- options.preloadFeatureFlags = false; // Don't preload as this makes no sense without a distinctId
2084
-
2085
- options.sendFeatureFlagEvent = false; // Let `posthog-node` handle this on its own, since we're dealing with multiple distinctIDs
2269
+ var _a;
2086
2270
 
2271
+ options.captureMode = (options === null || options === void 0 ? void 0 : options.captureMode) || 'json';
2087
2272
  _this = _super.call(this, apiKey, options) || this;
2088
- _this.options = options;
2089
2273
  _this._memoryStorage = new PostHogMemoryStorage();
2274
+ _this.options = options;
2275
+
2276
+ if (options.personalApiKey) {
2277
+ _this.featureFlagsPoller = new FeatureFlagsPoller({
2278
+ pollingInterval: typeof options.featureFlagsPollingInterval === 'number' ? options.featureFlagsPollingInterval : THIRTY_SECONDS,
2279
+ personalApiKey: options.personalApiKey,
2280
+ projectApiKey: apiKey,
2281
+ timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10000,
2282
+ host: _this.host,
2283
+ fetch: options.fetch
2284
+ });
2285
+ }
2286
+
2287
+ _this.distinctIdHasSentFlagCalls = {};
2288
+ _this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE;
2090
2289
  return _this;
2091
2290
  }
2092
2291
 
2093
- PostHogClient.prototype.getPersistedProperty = function (key) {
2292
+ PostHog.prototype.getPersistedProperty = function (key) {
2094
2293
  return this._memoryStorage.getProperty(key);
2095
2294
  };
2096
2295
 
2097
- PostHogClient.prototype.setPersistedProperty = function (key, value) {
2296
+ PostHog.prototype.setPersistedProperty = function (key, value) {
2098
2297
  return this._memoryStorage.setProperty(key, value);
2099
2298
  };
2100
2299
 
2101
- PostHogClient.prototype.getSessionId = function () {
2102
- // Sessions don't make sense for Node
2103
- return undefined;
2104
- };
2105
-
2106
- PostHogClient.prototype.fetch = function (url, options) {
2300
+ PostHog.prototype.fetch = function (url, options) {
2107
2301
  return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
2108
2302
  };
2109
2303
 
2110
- PostHogClient.prototype.getLibraryId = function () {
2304
+ PostHog.prototype.getLibraryId = function () {
2111
2305
  return 'posthog-node';
2112
2306
  };
2113
2307
 
2114
- PostHogClient.prototype.getLibraryVersion = function () {
2308
+ PostHog.prototype.getLibraryVersion = function () {
2115
2309
  return version;
2116
2310
  };
2117
2311
 
2118
- PostHogClient.prototype.getCustomUserAgent = function () {
2312
+ PostHog.prototype.getCustomUserAgent = function () {
2119
2313
  return "posthog-node/".concat(version);
2120
2314
  };
2121
2315
 
2122
- return PostHogClient;
2123
- }(PostHogCore); // The actual exported Nodejs API.
2124
-
2125
-
2126
- var PostHog =
2127
- /** @class */
2128
- function () {
2129
- function PostHog(apiKey, options) {
2130
- if (options === void 0) {
2131
- options = {};
2132
- }
2133
-
2134
- var _a;
2135
-
2136
- this._sharedClient = new PostHogClient(apiKey, options);
2137
-
2138
- if (options.personalApiKey) {
2139
- this.featureFlagsPoller = new FeatureFlagsPoller({
2140
- pollingInterval: typeof options.featureFlagsPollingInterval === 'number' ? options.featureFlagsPollingInterval : THIRTY_SECONDS,
2141
- personalApiKey: options.personalApiKey,
2142
- projectApiKey: apiKey,
2143
- timeout: (_a = options.requestTimeout) !== null && _a !== void 0 ? _a : 10000,
2144
- host: this._sharedClient.host,
2145
- fetch: options.fetch
2146
- });
2147
- }
2148
-
2149
- this.distinctIdHasSentFlagCalls = {};
2150
- this.maxCacheSize = options.maxCacheSize || MAX_CACHE_SIZE;
2151
- }
2152
-
2153
- PostHog.prototype.reInit = function (distinctId) {
2154
- // Certain properties we want to persist. Queue is persisted always by default.
2155
- this._sharedClient.reset([PostHogPersistedProperty.OptedOut]);
2156
-
2157
- this._sharedClient.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
2158
- };
2159
-
2160
2316
  PostHog.prototype.enable = function () {
2161
- return this._sharedClient.optIn();
2317
+ return _super.prototype.optIn.call(this);
2162
2318
  };
2163
2319
 
2164
2320
  PostHog.prototype.disable = function () {
2165
- return this._sharedClient.optOut();
2321
+ return _super.prototype.optOut.call(this);
2166
2322
  };
2167
2323
 
2168
2324
  PostHog.prototype.capture = function (_a) {
@@ -2174,39 +2330,50 @@ function () {
2174
2330
  groups = _a.groups,
2175
2331
  sendFeatureFlags = _a.sendFeatureFlags,
2176
2332
  timestamp = _a.timestamp;
2177
- this.reInit(distinctId);
2178
-
2179
- if (groups) {
2180
- this._sharedClient.groups(groups);
2181
- }
2182
2333
 
2183
- var _capture = function () {
2184
- _this._sharedClient.capture(event, properties, {
2334
+ var _capture = function (props) {
2335
+ _super.prototype.captureStateless.call(_this, distinctId, event, props, {
2185
2336
  timestamp: timestamp
2186
2337
  });
2187
2338
  };
2188
2339
 
2189
2340
  if (sendFeatureFlags) {
2190
- this._sharedClient.reloadFeatureFlagsAsync(false).finally(function () {
2191
- _capture();
2341
+ _super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups).then(function (flags) {
2342
+ var featureVariantProperties = {};
2343
+
2344
+ if (flags) {
2345
+ for (var _i = 0, _a = Object.entries(flags); _i < _a.length; _i++) {
2346
+ var _b = _a[_i],
2347
+ feature = _b[0],
2348
+ variant = _b[1];
2349
+ featureVariantProperties["$feature/".concat(feature)] = variant;
2350
+ }
2351
+ }
2352
+
2353
+ var flagProperties = __assign({
2354
+ $active_feature_flags: flags ? Object.keys(flags) : undefined
2355
+ }, featureVariantProperties);
2356
+
2357
+ _capture(__assign(__assign(__assign({}, properties), {
2358
+ $groups: groups
2359
+ }), flagProperties));
2192
2360
  });
2193
2361
  } else {
2194
- _capture();
2362
+ _capture(__assign(__assign({}, properties), {
2363
+ $groups: groups
2364
+ }));
2195
2365
  }
2196
2366
  };
2197
2367
 
2198
2368
  PostHog.prototype.identify = function (_a) {
2199
2369
  var distinctId = _a.distinctId,
2200
2370
  properties = _a.properties;
2201
- this.reInit(distinctId);
2202
2371
 
2203
- this._sharedClient.identify(distinctId, properties);
2372
+ _super.prototype.identifyStateless.call(this, distinctId, properties);
2204
2373
  };
2205
2374
 
2206
2375
  PostHog.prototype.alias = function (data) {
2207
- this.reInit(data.distinctId);
2208
-
2209
- this._sharedClient.alias(data.alias);
2376
+ _super.prototype.aliasStateless.call(this, data.alias, data.distinctId);
2210
2377
  };
2211
2378
 
2212
2379
  PostHog.prototype.getFeatureFlag = function (key, distinctId, options) {
@@ -2239,28 +2406,12 @@ function () {
2239
2406
  if (!(!flagWasLocallyEvaluated && !onlyEvaluateLocally)) return [3
2240
2407
  /*break*/
2241
2408
  , 3];
2242
- this.reInit(distinctId);
2243
-
2244
- if (groups != undefined) {
2245
- this._sharedClient.groups(groups);
2246
- }
2247
-
2248
- if (personProperties) {
2249
- this._sharedClient.personProperties(personProperties);
2250
- }
2251
-
2252
- if (groupProperties) {
2253
- this._sharedClient.groupProperties(groupProperties);
2254
- }
2255
-
2256
2409
  return [4
2257
2410
  /*yield*/
2258
- , this._sharedClient.reloadFeatureFlagsAsync(false)];
2411
+ , _super.prototype.getFeatureFlagStateless.call(this, key, distinctId, groups, personProperties, groupProperties)];
2259
2412
 
2260
2413
  case 2:
2261
- _d.sent();
2262
-
2263
- response = this._sharedClient.getFeatureFlag(key);
2414
+ response = _d.sent();
2264
2415
  _d.label = 3;
2265
2416
 
2266
2417
  case 3:
@@ -2349,28 +2500,12 @@ function () {
2349
2500
  if (!(!payloadWasLocallyEvaluated && !onlyEvaluateLocally)) return [3
2350
2501
  /*break*/
2351
2502
  , 6];
2352
- this.reInit(distinctId);
2353
-
2354
- if (groups != undefined) {
2355
- this._sharedClient.groups(groups);
2356
- }
2357
-
2358
- if (personProperties) {
2359
- this._sharedClient.personProperties(personProperties);
2360
- }
2361
-
2362
- if (groupProperties) {
2363
- this._sharedClient.groupProperties(groupProperties);
2364
- }
2365
-
2366
2503
  return [4
2367
2504
  /*yield*/
2368
- , this._sharedClient.reloadFeatureFlagsAsync(false)];
2505
+ , _super.prototype.getFeatureFlagPayloadStateless.call(this, key, distinctId, groups, personProperties, groupProperties)];
2369
2506
 
2370
2507
  case 5:
2371
- _d.sent();
2372
-
2373
- response = this._sharedClient.getFeatureFlagPayload(key);
2508
+ response = _d.sent();
2374
2509
  _d.label = 6;
2375
2510
 
2376
2511
  case 6:
@@ -2474,28 +2609,12 @@ function () {
2474
2609
  if (!(fallbackToDecide && !onlyEvaluateLocally)) return [3
2475
2610
  /*break*/
2476
2611
  , 3];
2477
- this.reInit(distinctId);
2478
-
2479
- if (groups) {
2480
- this._sharedClient.groups(groups);
2481
- }
2482
-
2483
- if (personProperties) {
2484
- this._sharedClient.personProperties(personProperties);
2485
- }
2486
-
2487
- if (groupProperties) {
2488
- this._sharedClient.groupProperties(groupProperties);
2489
- }
2490
-
2491
2612
  return [4
2492
2613
  /*yield*/
2493
- , this._sharedClient.reloadFeatureFlagsAsync(false)];
2614
+ , _super.prototype.getFeatureFlagsAndPayloadsStateless.call(this, distinctId, groups, personProperties, groupProperties)];
2494
2615
 
2495
2616
  case 2:
2496
- _c.sent();
2497
-
2498
- remoteEvaluationResult = this._sharedClient.getFeatureFlagsAndPayloads();
2617
+ remoteEvaluationResult = _c.sent();
2499
2618
  featureFlags = __assign(__assign({}, featureFlags), remoteEvaluationResult.flags || {});
2500
2619
  featureFlagPayloads = __assign(__assign({}, featureFlagPayloads), remoteEvaluationResult.payloads || {});
2501
2620
  _c.label = 3;
@@ -2516,9 +2635,8 @@ function () {
2516
2635
  var groupType = _a.groupType,
2517
2636
  groupKey = _a.groupKey,
2518
2637
  properties = _a.properties;
2519
- this.reInit("$".concat(groupType, "_").concat(groupKey));
2520
2638
 
2521
- this._sharedClient.groupIdentify(groupType, groupKey, properties);
2639
+ _super.prototype.groupIdentifyStateless.call(this, groupType, groupKey, properties);
2522
2640
  };
2523
2641
 
2524
2642
  PostHog.prototype.reloadFeatureFlags = function () {
@@ -2543,10 +2661,6 @@ function () {
2543
2661
  });
2544
2662
  };
2545
2663
 
2546
- PostHog.prototype.flush = function () {
2547
- this._sharedClient.flush();
2548
- };
2549
-
2550
2664
  PostHog.prototype.shutdown = function () {
2551
2665
  void this.shutdownAsync();
2552
2666
  };
@@ -2559,17 +2673,13 @@ function () {
2559
2673
  (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.stopPoller();
2560
2674
  return [2
2561
2675
  /*return*/
2562
- , this._sharedClient.shutdownAsync()];
2676
+ , _super.prototype.shutdownAsync.call(this)];
2563
2677
  });
2564
2678
  });
2565
2679
  };
2566
2680
 
2567
- PostHog.prototype.debug = function (enabled) {
2568
- return this._sharedClient.debug(enabled);
2569
- };
2570
-
2571
2681
  return PostHog;
2572
- }();
2682
+ }(PostHogCoreStateless);
2573
2683
 
2574
2684
  exports.PostHog = PostHog;
2575
2685
  //# sourceMappingURL=index.cjs.js.map