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