posthog-node 3.4.0 → 3.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/CHANGELOG.md +5 -0
- package/lib/index.cjs.js +182 -72
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +182 -72
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +2 -1
- package/lib/posthog-node/src/posthog-node.d.ts +1 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +10 -6
- package/src/posthog-node.ts +99 -19
- package/test/extensions/sentry-integration.spec.ts +2 -0
- package/test/feature-flags.spec.ts +17 -2
- package/test/posthog-node.spec.ts +407 -10
package/lib/index.d.ts
CHANGED
|
@@ -108,9 +108,9 @@ declare abstract class PostHogCoreStateless {
|
|
|
108
108
|
private captureMode;
|
|
109
109
|
private removeDebugCallback?;
|
|
110
110
|
private debugMode;
|
|
111
|
-
private pendingPromises;
|
|
112
111
|
private disableGeoip;
|
|
113
112
|
private _optoutOverride;
|
|
113
|
+
private pendingPromises;
|
|
114
114
|
protected _events: SimpleEventEmitter;
|
|
115
115
|
protected _flushTimer?: any;
|
|
116
116
|
protected _retryOptions: RetriableOptions;
|
|
@@ -128,6 +128,7 @@ declare abstract class PostHogCoreStateless {
|
|
|
128
128
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
129
129
|
debug(enabled?: boolean): void;
|
|
130
130
|
private buildPayload;
|
|
131
|
+
protected addPendingPromise(promise: Promise<any>): void;
|
|
131
132
|
/***
|
|
132
133
|
*** TRACKING
|
|
133
134
|
***/
|
|
@@ -377,6 +378,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
377
378
|
reloadFeatureFlags(): Promise<void>;
|
|
378
379
|
shutdown(): void;
|
|
379
380
|
shutdownAsync(): Promise<void>;
|
|
381
|
+
private addLocalPersonAndGroupProperties;
|
|
380
382
|
}
|
|
381
383
|
|
|
382
384
|
/**
|
package/lib/index.esm.js
CHANGED
|
@@ -154,7 +154,7 @@ function __spreadArray(to, from, pack) {
|
|
|
154
154
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
-
var version = "3.
|
|
157
|
+
var version = "3.5.0";
|
|
158
158
|
|
|
159
159
|
var PostHogPersistedProperty;
|
|
160
160
|
(function (PostHogPersistedProperty) {
|
|
@@ -747,8 +747,8 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
747
747
|
function PostHogCoreStateless(apiKey, options) {
|
|
748
748
|
var _a, _b, _c, _d, _e;
|
|
749
749
|
this.debugMode = false;
|
|
750
|
-
this.pendingPromises = {};
|
|
751
750
|
this.disableGeoip = true;
|
|
751
|
+
this.pendingPromises = {};
|
|
752
752
|
// internal
|
|
753
753
|
this._events = new SimpleEventEmitter();
|
|
754
754
|
assert(apiKey, "You must pass your PostHog project's api key.");
|
|
@@ -806,6 +806,14 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
806
806
|
properties: __assign(__assign({}, (payload.properties || {})), this.getCommonEventProperties()),
|
|
807
807
|
};
|
|
808
808
|
};
|
|
809
|
+
PostHogCoreStateless.prototype.addPendingPromise = function (promise) {
|
|
810
|
+
var _this = this;
|
|
811
|
+
var promiseUUID = generateUUID();
|
|
812
|
+
this.pendingPromises[promiseUUID] = promise;
|
|
813
|
+
promise.finally(function () {
|
|
814
|
+
delete _this.pendingPromises[promiseUUID];
|
|
815
|
+
});
|
|
816
|
+
};
|
|
809
817
|
/***
|
|
810
818
|
*** TRACKING
|
|
811
819
|
***/
|
|
@@ -856,6 +864,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
856
864
|
if (extraPayload === void 0) { extraPayload = {}; }
|
|
857
865
|
return __awaiter(this, void 0, void 0, function () {
|
|
858
866
|
var url, fetchOptions;
|
|
867
|
+
var _this = this;
|
|
859
868
|
return __generator(this, function (_a) {
|
|
860
869
|
url = "".concat(this.host, "/decide/?v=3");
|
|
861
870
|
fetchOptions = {
|
|
@@ -866,7 +875,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
866
875
|
return [2 /*return*/, this.fetchWithRetry(url, fetchOptions)
|
|
867
876
|
.then(function (response) { return response.json(); })
|
|
868
877
|
.catch(function (error) {
|
|
869
|
-
|
|
878
|
+
_this._events.emit('error', error);
|
|
870
879
|
return undefined;
|
|
871
880
|
})];
|
|
872
881
|
});
|
|
@@ -1053,14 +1062,11 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1053
1062
|
batch: messages,
|
|
1054
1063
|
sent_at: currentISOTime(),
|
|
1055
1064
|
};
|
|
1056
|
-
var promiseUUID = generateUUID();
|
|
1057
1065
|
var done = function (err) {
|
|
1058
1066
|
if (err) {
|
|
1059
1067
|
_this._events.emit('error', err);
|
|
1060
1068
|
}
|
|
1061
1069
|
callback === null || callback === void 0 ? void 0 : callback(err, messages);
|
|
1062
|
-
// remove promise from pendingPromises
|
|
1063
|
-
delete _this.pendingPromises[promiseUUID];
|
|
1064
1070
|
_this._events.emit('flush', messages);
|
|
1065
1071
|
};
|
|
1066
1072
|
// Don't set the user agent if we're not on a browser. The latest spec allows
|
|
@@ -1086,12 +1092,11 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1086
1092
|
body: payload,
|
|
1087
1093
|
};
|
|
1088
1094
|
var requestPromise = this.fetchWithRetry(url, fetchOptions);
|
|
1089
|
-
this.
|
|
1090
|
-
requestPromise
|
|
1095
|
+
this.addPendingPromise(requestPromise
|
|
1091
1096
|
.then(function () { return done(); })
|
|
1092
1097
|
.catch(function (err) {
|
|
1093
1098
|
done(err);
|
|
1094
|
-
});
|
|
1099
|
+
}));
|
|
1095
1100
|
};
|
|
1096
1101
|
PostHogCoreStateless.prototype.fetchWithRetry = function (url, options, retryOptions) {
|
|
1097
1102
|
var _a;
|
|
@@ -1145,7 +1150,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1145
1150
|
clearTimeout(this._flushTimer);
|
|
1146
1151
|
_a.label = 1;
|
|
1147
1152
|
case 1:
|
|
1148
|
-
_a.trys.push([1,
|
|
1153
|
+
_a.trys.push([1, 5, , 6]);
|
|
1149
1154
|
return [4 /*yield*/, this.flushAsync()];
|
|
1150
1155
|
case 2:
|
|
1151
1156
|
_a.sent();
|
|
@@ -1153,18 +1158,31 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1153
1158
|
return x.catch(function () {
|
|
1154
1159
|
// ignore errors as we are shutting down and can't deal with them anyways.
|
|
1155
1160
|
});
|
|
1156
|
-
}))
|
|
1161
|
+
}))
|
|
1162
|
+
// flush again to make sure we send all events, some of which might've been added
|
|
1163
|
+
// while we were waiting for the pending promises to resolve
|
|
1164
|
+
// For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
|
|
1165
|
+
];
|
|
1157
1166
|
case 3:
|
|
1158
1167
|
_a.sent();
|
|
1159
|
-
|
|
1168
|
+
// flush again to make sure we send all events, some of which might've been added
|
|
1169
|
+
// while we were waiting for the pending promises to resolve
|
|
1170
|
+
// For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
|
|
1171
|
+
return [4 /*yield*/, this.flushAsync()];
|
|
1160
1172
|
case 4:
|
|
1173
|
+
// flush again to make sure we send all events, some of which might've been added
|
|
1174
|
+
// while we were waiting for the pending promises to resolve
|
|
1175
|
+
// For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
|
|
1176
|
+
_a.sent();
|
|
1177
|
+
return [3 /*break*/, 6];
|
|
1178
|
+
case 5:
|
|
1161
1179
|
e_2 = _a.sent();
|
|
1162
1180
|
if (!isPostHogFetchError(e_2)) {
|
|
1163
1181
|
throw e_2;
|
|
1164
1182
|
}
|
|
1165
1183
|
console.error('Error while shutting down PostHog', e_2);
|
|
1166
|
-
return [3 /*break*/,
|
|
1167
|
-
case
|
|
1184
|
+
return [3 /*break*/, 6];
|
|
1185
|
+
case 6: return [2 /*return*/];
|
|
1168
1186
|
}
|
|
1169
1187
|
});
|
|
1170
1188
|
});
|
|
@@ -1756,6 +1774,8 @@ function () {
|
|
|
1756
1774
|
};
|
|
1757
1775
|
|
|
1758
1776
|
FeatureFlagsPoller.prototype.getFeatureFlag = function (key, distinctId, groups, personProperties, groupProperties) {
|
|
1777
|
+
var _a;
|
|
1778
|
+
|
|
1759
1779
|
if (groups === void 0) {
|
|
1760
1780
|
groups = {};
|
|
1761
1781
|
}
|
|
@@ -1769,17 +1789,17 @@ function () {
|
|
|
1769
1789
|
}
|
|
1770
1790
|
|
|
1771
1791
|
return __awaiter(this, void 0, void 0, function () {
|
|
1772
|
-
var response, featureFlag, _i,
|
|
1792
|
+
var response, featureFlag, _i, _b, flag;
|
|
1773
1793
|
|
|
1774
|
-
return __generator(this, function (
|
|
1775
|
-
switch (
|
|
1794
|
+
return __generator(this, function (_c) {
|
|
1795
|
+
switch (_c.label) {
|
|
1776
1796
|
case 0:
|
|
1777
1797
|
return [4
|
|
1778
1798
|
/*yield*/
|
|
1779
1799
|
, this.loadFeatureFlags()];
|
|
1780
1800
|
|
|
1781
1801
|
case 1:
|
|
1782
|
-
|
|
1802
|
+
_c.sent();
|
|
1783
1803
|
|
|
1784
1804
|
response = undefined;
|
|
1785
1805
|
featureFlag = undefined;
|
|
@@ -1790,8 +1810,8 @@ function () {
|
|
|
1790
1810
|
, response];
|
|
1791
1811
|
}
|
|
1792
1812
|
|
|
1793
|
-
for (_i = 0,
|
|
1794
|
-
flag =
|
|
1813
|
+
for (_i = 0, _b = this.featureFlags; _i < _b.length; _i++) {
|
|
1814
|
+
flag = _b[_i];
|
|
1795
1815
|
|
|
1796
1816
|
if (key === flag.key) {
|
|
1797
1817
|
featureFlag = flag;
|
|
@@ -1812,7 +1832,7 @@ function () {
|
|
|
1812
1832
|
console.debug("InconclusiveMatchError when computing flag locally: ".concat(key, ": ").concat(e));
|
|
1813
1833
|
}
|
|
1814
1834
|
} else if (e instanceof Error) {
|
|
1815
|
-
|
|
1835
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Error computing flag locally: ".concat(key, ": ").concat(e)));
|
|
1816
1836
|
}
|
|
1817
1837
|
}
|
|
1818
1838
|
}
|
|
@@ -1988,12 +2008,18 @@ function () {
|
|
|
1988
2008
|
var groupName = this.groupTypeMapping[String(aggregation_group_type_index)];
|
|
1989
2009
|
|
|
1990
2010
|
if (!groupName) {
|
|
1991
|
-
|
|
2011
|
+
if (this.debugMode) {
|
|
2012
|
+
console.warn("[FEATURE FLAGS] Unknown group type index ".concat(aggregation_group_type_index, " for feature flag ").concat(flag.key));
|
|
2013
|
+
}
|
|
2014
|
+
|
|
1992
2015
|
throw new InconclusiveMatchError('Flag has unknown group type index');
|
|
1993
2016
|
}
|
|
1994
2017
|
|
|
1995
2018
|
if (!(groupName in groups)) {
|
|
1996
|
-
|
|
2019
|
+
if (this.debugMode) {
|
|
2020
|
+
console.warn("[FEATURE FLAGS] Can't compute group feature flag: ".concat(flag.key, " without group names passed in"));
|
|
2021
|
+
}
|
|
2022
|
+
|
|
1997
2023
|
return false;
|
|
1998
2024
|
}
|
|
1999
2025
|
|
|
@@ -2170,15 +2196,15 @@ function () {
|
|
|
2170
2196
|
};
|
|
2171
2197
|
|
|
2172
2198
|
FeatureFlagsPoller.prototype._loadFeatureFlags = function () {
|
|
2173
|
-
var _a;
|
|
2199
|
+
var _a, _b;
|
|
2174
2200
|
|
|
2175
2201
|
return __awaiter(this, void 0, void 0, function () {
|
|
2176
2202
|
var res, responseJson, err_1;
|
|
2177
2203
|
|
|
2178
2204
|
var _this = this;
|
|
2179
2205
|
|
|
2180
|
-
return __generator(this, function (
|
|
2181
|
-
switch (
|
|
2206
|
+
return __generator(this, function (_c) {
|
|
2207
|
+
switch (_c.label) {
|
|
2182
2208
|
case 0:
|
|
2183
2209
|
if (this.poller) {
|
|
2184
2210
|
clearTimeout(this.poller);
|
|
@@ -2188,17 +2214,17 @@ function () {
|
|
|
2188
2214
|
this.poller = setTimeout(function () {
|
|
2189
2215
|
return _this._loadFeatureFlags();
|
|
2190
2216
|
}, this.pollingInterval);
|
|
2191
|
-
|
|
2217
|
+
_c.label = 1;
|
|
2192
2218
|
|
|
2193
2219
|
case 1:
|
|
2194
|
-
|
|
2220
|
+
_c.trys.push([1, 4,, 5]);
|
|
2195
2221
|
|
|
2196
2222
|
return [4
|
|
2197
2223
|
/*yield*/
|
|
2198
2224
|
, this._requestFeatureFlagDefinitions()];
|
|
2199
2225
|
|
|
2200
2226
|
case 2:
|
|
2201
|
-
res =
|
|
2227
|
+
res = _c.sent();
|
|
2202
2228
|
|
|
2203
2229
|
if (res && res.status === 401) {
|
|
2204
2230
|
throw new ClientError("Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview");
|
|
@@ -2217,10 +2243,10 @@ function () {
|
|
|
2217
2243
|
, res.json()];
|
|
2218
2244
|
|
|
2219
2245
|
case 3:
|
|
2220
|
-
responseJson =
|
|
2246
|
+
responseJson = _c.sent();
|
|
2221
2247
|
|
|
2222
2248
|
if (!('flags' in responseJson)) {
|
|
2223
|
-
|
|
2249
|
+
(_a = this.onError) === null || _a === void 0 ? void 0 : _a.call(this, new Error("Invalid response when getting feature flags: ".concat(JSON.stringify(responseJson))));
|
|
2224
2250
|
}
|
|
2225
2251
|
|
|
2226
2252
|
this.featureFlags = responseJson.flags || [];
|
|
@@ -2235,11 +2261,11 @@ function () {
|
|
|
2235
2261
|
, 5];
|
|
2236
2262
|
|
|
2237
2263
|
case 4:
|
|
2238
|
-
err_1 =
|
|
2264
|
+
err_1 = _c.sent(); // if an error that is not an instance of ClientError is thrown
|
|
2239
2265
|
// we silently ignore the error when reloading feature flags
|
|
2240
2266
|
|
|
2241
2267
|
if (err_1 instanceof ClientError) {
|
|
2242
|
-
(
|
|
2268
|
+
(_b = this.onError) === null || _b === void 0 ? void 0 : _b.call(this, err_1);
|
|
2243
2269
|
}
|
|
2244
2270
|
|
|
2245
2271
|
return [3
|
|
@@ -2727,41 +2753,94 @@ function (_super) {
|
|
|
2727
2753
|
timestamp: timestamp,
|
|
2728
2754
|
disableGeoip: disableGeoip
|
|
2729
2755
|
});
|
|
2730
|
-
};
|
|
2756
|
+
}; // :TRICKY: If we flush, or need to shut down, to not lose events we want this promise to resolve before we flush
|
|
2731
2757
|
|
|
2732
|
-
if (sendFeatureFlags) {
|
|
2733
|
-
_super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip).then(function (flags) {
|
|
2734
|
-
var featureVariantProperties = {};
|
|
2735
2758
|
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
feature = _b[0],
|
|
2740
|
-
variant = _b[1];
|
|
2759
|
+
var capturePromise = Promise.resolve().then(function () {
|
|
2760
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2761
|
+
var groupsWithStringValues, _i, _a, _b, key, value;
|
|
2741
2762
|
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2763
|
+
var _c, _d;
|
|
2764
|
+
|
|
2765
|
+
return __generator(this, function (_e) {
|
|
2766
|
+
switch (_e.label) {
|
|
2767
|
+
case 0:
|
|
2768
|
+
if (!sendFeatureFlags) return [3
|
|
2769
|
+
/*break*/
|
|
2770
|
+
, 2];
|
|
2771
|
+
return [4
|
|
2772
|
+
/*yield*/
|
|
2773
|
+
, _super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip)];
|
|
2774
|
+
|
|
2775
|
+
case 1:
|
|
2776
|
+
// If we are sending feature flags, we need to make sure we have the latest flags
|
|
2777
|
+
return [2
|
|
2778
|
+
/*return*/
|
|
2779
|
+
, _e.sent()];
|
|
2780
|
+
|
|
2781
|
+
case 2:
|
|
2782
|
+
if (!((((_d = (_c = this.featureFlagsPoller) === null || _c === void 0 ? void 0 : _c.featureFlags) === null || _d === void 0 ? void 0 : _d.length) || 0) > 0)) return [3
|
|
2783
|
+
/*break*/
|
|
2784
|
+
, 4];
|
|
2785
|
+
groupsWithStringValues = {};
|
|
2786
|
+
|
|
2787
|
+
for (_i = 0, _a = Object.entries(groups || {}); _i < _a.length; _i++) {
|
|
2788
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
2789
|
+
groupsWithStringValues[key] = String(value);
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
return [4
|
|
2793
|
+
/*yield*/
|
|
2794
|
+
, this.getAllFlags(distinctId, {
|
|
2795
|
+
groups: groupsWithStringValues,
|
|
2796
|
+
disableGeoip: disableGeoip,
|
|
2797
|
+
onlyEvaluateLocally: true
|
|
2798
|
+
})];
|
|
2799
|
+
|
|
2800
|
+
case 3:
|
|
2801
|
+
return [2
|
|
2802
|
+
/*return*/
|
|
2803
|
+
, _e.sent()];
|
|
2804
|
+
|
|
2805
|
+
case 4:
|
|
2806
|
+
return [2
|
|
2807
|
+
/*return*/
|
|
2808
|
+
, {}];
|
|
2745
2809
|
}
|
|
2810
|
+
});
|
|
2811
|
+
});
|
|
2812
|
+
}).then(function (flags) {
|
|
2813
|
+
// Derive the relevant flag properties to add
|
|
2814
|
+
var additionalProperties = {};
|
|
2815
|
+
|
|
2816
|
+
if (flags) {
|
|
2817
|
+
for (var _i = 0, _a = Object.entries(flags); _i < _a.length; _i++) {
|
|
2818
|
+
var _b = _a[_i],
|
|
2819
|
+
feature = _b[0],
|
|
2820
|
+
variant = _b[1];
|
|
2821
|
+
additionalProperties["$feature/".concat(feature)] = variant;
|
|
2746
2822
|
}
|
|
2823
|
+
}
|
|
2747
2824
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2825
|
+
var activeFlags = Object.keys(flags || {}).filter(function (flag) {
|
|
2826
|
+
return (flags === null || flags === void 0 ? void 0 : flags[flag]) !== false;
|
|
2827
|
+
});
|
|
2751
2828
|
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2829
|
+
if (activeFlags.length > 0) {
|
|
2830
|
+
additionalProperties['$active_feature_flags'] = activeFlags;
|
|
2831
|
+
}
|
|
2755
2832
|
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2833
|
+
return additionalProperties;
|
|
2834
|
+
}).catch(function () {
|
|
2835
|
+
// Something went wrong getting the flag info - we should capture the event anyways
|
|
2836
|
+
return {};
|
|
2837
|
+
}).then(function (additionalProperties) {
|
|
2838
|
+
// No matter what - capture the event
|
|
2839
|
+
_capture(__assign(__assign(__assign({}, additionalProperties), properties), {
|
|
2762
2840
|
$groups: groups
|
|
2763
2841
|
}));
|
|
2764
|
-
}
|
|
2842
|
+
});
|
|
2843
|
+
this.addPendingPromise(capturePromise);
|
|
2765
2844
|
};
|
|
2766
2845
|
|
|
2767
2846
|
PostHog.prototype.identify = function (_a) {
|
|
@@ -2788,15 +2867,18 @@ function (_super) {
|
|
|
2788
2867
|
var _a;
|
|
2789
2868
|
|
|
2790
2869
|
return __awaiter(this, void 0, void 0, function () {
|
|
2791
|
-
var _b, groups,
|
|
2870
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties, adjustedProperties, response, flagWasLocallyEvaluated, featureFlagReportedKey;
|
|
2792
2871
|
|
|
2793
2872
|
var _d;
|
|
2794
2873
|
|
|
2795
2874
|
return __generator(this, function (_e) {
|
|
2796
2875
|
switch (_e.label) {
|
|
2797
2876
|
case 0:
|
|
2798
|
-
_b = options || {}, groups = _b.groups,
|
|
2799
|
-
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents
|
|
2877
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
2878
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
2879
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
2880
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
2881
|
+
groupProperties = adjustedProperties.allGroupProperties; // set defaults
|
|
2800
2882
|
|
|
2801
2883
|
if (onlyEvaluateLocally == undefined) {
|
|
2802
2884
|
onlyEvaluateLocally = false;
|
|
@@ -2863,13 +2945,16 @@ function (_super) {
|
|
|
2863
2945
|
var _a;
|
|
2864
2946
|
|
|
2865
2947
|
return __awaiter(this, void 0, void 0, function () {
|
|
2866
|
-
var _b, groups,
|
|
2948
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, response, payloadWasLocallyEvaluated;
|
|
2867
2949
|
|
|
2868
2950
|
return __generator(this, function (_d) {
|
|
2869
2951
|
switch (_d.label) {
|
|
2870
2952
|
case 0:
|
|
2871
|
-
_b = options || {}, groups = _b.groups,
|
|
2872
|
-
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents;
|
|
2953
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
2954
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
2955
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
2956
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
2957
|
+
groupProperties = adjustedProperties.allGroupProperties;
|
|
2873
2958
|
response = undefined;
|
|
2874
2959
|
if (!!matchValue) return [3
|
|
2875
2960
|
/*break*/
|
|
@@ -2989,13 +3074,16 @@ function (_super) {
|
|
|
2989
3074
|
var _a;
|
|
2990
3075
|
|
|
2991
3076
|
return __awaiter(this, void 0, void 0, function () {
|
|
2992
|
-
var _b, groups, personProperties, groupProperties,
|
|
3077
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, localEvaluationResult, featureFlags, featureFlagPayloads, fallbackToDecide, remoteEvaluationResult;
|
|
2993
3078
|
|
|
2994
|
-
return __generator(this, function (
|
|
2995
|
-
switch (
|
|
3079
|
+
return __generator(this, function (_d) {
|
|
3080
|
+
switch (_d.label) {
|
|
2996
3081
|
case 0:
|
|
2997
|
-
_b = options || {}, groups = _b.groups,
|
|
2998
|
-
|
|
3082
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
3083
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
3084
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
3085
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
3086
|
+
groupProperties = adjustedProperties.allGroupProperties; // set defaults
|
|
2999
3087
|
|
|
3000
3088
|
if (onlyEvaluateLocally == undefined) {
|
|
3001
3089
|
onlyEvaluateLocally = false;
|
|
@@ -3006,7 +3094,7 @@ function (_super) {
|
|
|
3006
3094
|
, (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties)];
|
|
3007
3095
|
|
|
3008
3096
|
case 1:
|
|
3009
|
-
localEvaluationResult =
|
|
3097
|
+
localEvaluationResult = _d.sent();
|
|
3010
3098
|
featureFlags = {};
|
|
3011
3099
|
featureFlagPayloads = {};
|
|
3012
3100
|
fallbackToDecide = true;
|
|
@@ -3025,10 +3113,10 @@ function (_super) {
|
|
|
3025
3113
|
, _super.prototype.getFeatureFlagsAndPayloadsStateless.call(this, distinctId, groups, personProperties, groupProperties, disableGeoip)];
|
|
3026
3114
|
|
|
3027
3115
|
case 2:
|
|
3028
|
-
remoteEvaluationResult =
|
|
3116
|
+
remoteEvaluationResult = _d.sent();
|
|
3029
3117
|
featureFlags = __assign(__assign({}, featureFlags), remoteEvaluationResult.flags || {});
|
|
3030
3118
|
featureFlagPayloads = __assign(__assign({}, featureFlagPayloads), remoteEvaluationResult.payloads || {});
|
|
3031
|
-
|
|
3119
|
+
_d.label = 3;
|
|
3032
3120
|
|
|
3033
3121
|
case 3:
|
|
3034
3122
|
return [2
|
|
@@ -3093,6 +3181,28 @@ function (_super) {
|
|
|
3093
3181
|
});
|
|
3094
3182
|
};
|
|
3095
3183
|
|
|
3184
|
+
PostHog.prototype.addLocalPersonAndGroupProperties = function (distinctId, groups, personProperties, groupProperties) {
|
|
3185
|
+
var allPersonProperties = __assign({
|
|
3186
|
+
$current_distinct_id: distinctId
|
|
3187
|
+
}, personProperties || {});
|
|
3188
|
+
|
|
3189
|
+
var allGroupProperties = {};
|
|
3190
|
+
|
|
3191
|
+
if (groups) {
|
|
3192
|
+
for (var _i = 0, _a = Object.keys(groups); _i < _a.length; _i++) {
|
|
3193
|
+
var groupName = _a[_i];
|
|
3194
|
+
allGroupProperties[groupName] = __assign({
|
|
3195
|
+
$group_key: groups[groupName]
|
|
3196
|
+
}, (groupProperties === null || groupProperties === void 0 ? void 0 : groupProperties[groupName]) || {});
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
return {
|
|
3201
|
+
allPersonProperties: allPersonProperties,
|
|
3202
|
+
allGroupProperties: allGroupProperties
|
|
3203
|
+
};
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3096
3206
|
return PostHog;
|
|
3097
3207
|
}(PostHogCoreStateless);
|
|
3098
3208
|
|