posthog-node 3.4.0 → 3.6.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 +9 -0
- package/lib/index.cjs.js +187 -75
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +19 -13
- package/lib/index.esm.js +187 -75
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +13 -12
- package/lib/posthog-core/src/types.d.ts +4 -1
- package/lib/posthog-node/src/posthog-node.d.ts +4 -3
- package/lib/posthog-node/src/types.d.ts +5 -4
- package/package.json +1 -1
- package/src/feature-flags.ts +10 -6
- package/src/posthog-node.ts +113 -24
- package/src/types.ts +5 -4
- package/test/extensions/sentry-integration.spec.ts +3 -0
- package/test/feature-flags.spec.ts +17 -2
- package/test/posthog-node.spec.ts +427 -10
package/lib/index.d.ts
CHANGED
|
@@ -45,7 +45,10 @@ declare type PostHogFetchOptions = {
|
|
|
45
45
|
body?: string;
|
|
46
46
|
signal?: AbortSignal;
|
|
47
47
|
};
|
|
48
|
-
declare type
|
|
48
|
+
declare type PostHogCaptureOptions = {
|
|
49
|
+
/** If provided overrides the auto-generated event ID */
|
|
50
|
+
uuid?: string;
|
|
51
|
+
/** If provided overrides the auto-generated timestamp */
|
|
49
52
|
timestamp?: Date;
|
|
50
53
|
disableGeoip?: boolean;
|
|
51
54
|
};
|
|
@@ -108,9 +111,9 @@ declare abstract class PostHogCoreStateless {
|
|
|
108
111
|
private captureMode;
|
|
109
112
|
private removeDebugCallback?;
|
|
110
113
|
private debugMode;
|
|
111
|
-
private pendingPromises;
|
|
112
114
|
private disableGeoip;
|
|
113
115
|
private _optoutOverride;
|
|
116
|
+
private pendingPromises;
|
|
114
117
|
protected _events: SimpleEventEmitter;
|
|
115
118
|
protected _flushTimer?: any;
|
|
116
119
|
protected _retryOptions: RetriableOptions;
|
|
@@ -128,20 +131,21 @@ declare abstract class PostHogCoreStateless {
|
|
|
128
131
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
129
132
|
debug(enabled?: boolean): void;
|
|
130
133
|
private buildPayload;
|
|
134
|
+
protected addPendingPromise(promise: Promise<any>): void;
|
|
131
135
|
/***
|
|
132
136
|
*** TRACKING
|
|
133
137
|
***/
|
|
134
|
-
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?:
|
|
138
|
+
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
135
139
|
protected captureStateless(distinctId: string, event: string, properties?: {
|
|
136
140
|
[key: string]: any;
|
|
137
|
-
}, options?:
|
|
141
|
+
}, options?: PostHogCaptureOptions): this;
|
|
138
142
|
protected aliasStateless(alias: string, distinctId: string, properties?: {
|
|
139
143
|
[key: string]: any;
|
|
140
|
-
}, options?:
|
|
144
|
+
}, options?: PostHogCaptureOptions): this;
|
|
141
145
|
/***
|
|
142
146
|
*** GROUPS
|
|
143
147
|
***/
|
|
144
|
-
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?:
|
|
148
|
+
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
|
|
145
149
|
/***
|
|
146
150
|
*** FEATURE FLAGS
|
|
147
151
|
***/
|
|
@@ -158,7 +162,7 @@ declare abstract class PostHogCoreStateless {
|
|
|
158
162
|
/***
|
|
159
163
|
*** QUEUEING AND FLUSHING
|
|
160
164
|
***/
|
|
161
|
-
protected enqueue(type: string, _message: any, options?:
|
|
165
|
+
protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
|
|
162
166
|
flushAsync(): Promise<any>;
|
|
163
167
|
flush(callback?: (err?: any, data?: any) => void): void;
|
|
164
168
|
private fetchWithRetry;
|
|
@@ -166,16 +170,17 @@ declare abstract class PostHogCoreStateless {
|
|
|
166
170
|
shutdown(): void;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
interface
|
|
173
|
+
interface IdentifyMessage {
|
|
170
174
|
distinctId: string;
|
|
171
175
|
properties?: Record<string | number, any>;
|
|
172
176
|
disableGeoip?: boolean;
|
|
173
177
|
}
|
|
174
|
-
interface
|
|
178
|
+
interface EventMessage extends IdentifyMessage {
|
|
175
179
|
event: string;
|
|
176
180
|
groups?: Record<string, string | number>;
|
|
177
181
|
sendFeatureFlags?: boolean;
|
|
178
182
|
timestamp?: Date;
|
|
183
|
+
uuid?: string;
|
|
179
184
|
}
|
|
180
185
|
interface GroupIdentifyMessage {
|
|
181
186
|
groupType: string;
|
|
@@ -196,7 +201,7 @@ declare type PostHogNodeV1 = {
|
|
|
196
201
|
* @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
|
|
197
202
|
* @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
|
|
198
203
|
*/
|
|
199
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags }:
|
|
204
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
|
|
200
205
|
/**
|
|
201
206
|
* @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,
|
|
202
207
|
* and even do things like segment users by these properties.
|
|
@@ -204,7 +209,7 @@ declare type PostHogNodeV1 = {
|
|
|
204
209
|
* @param distinctId which uniquely identifies your user
|
|
205
210
|
* @param properties with a dict with any key: value pairs
|
|
206
211
|
*/
|
|
207
|
-
identify({ distinctId, properties }:
|
|
212
|
+
identify({ distinctId, properties }: IdentifyMessage): void;
|
|
208
213
|
/**
|
|
209
214
|
* @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
|
|
210
215
|
* This will allow you to answer questions like "Which marketing channels leads to users churning after a month?"
|
|
@@ -328,8 +333,8 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
328
333
|
enable(): void;
|
|
329
334
|
disable(): void;
|
|
330
335
|
debug(enabled?: boolean): void;
|
|
331
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }:
|
|
332
|
-
identify({ distinctId, properties, disableGeoip }:
|
|
336
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid, }: EventMessage): void;
|
|
337
|
+
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
|
|
333
338
|
alias(data: {
|
|
334
339
|
distinctId: string;
|
|
335
340
|
alias: string;
|
|
@@ -377,6 +382,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
377
382
|
reloadFeatureFlags(): Promise<void>;
|
|
378
383
|
shutdown(): void;
|
|
379
384
|
shutdownAsync(): Promise<void>;
|
|
385
|
+
private addLocalPersonAndGroupProperties;
|
|
380
386
|
}
|
|
381
387
|
|
|
382
388
|
/**
|
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.6.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
|
});
|
|
@@ -1003,7 +1012,7 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1003
1012
|
this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
1004
1013
|
return;
|
|
1005
1014
|
}
|
|
1006
|
-
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() });
|
|
1015
|
+
var message = __assign(__assign({}, _message), { type: type, library: this.getLibraryId(), library_version: this.getLibraryVersion(), timestamp: (options === null || options === void 0 ? void 0 : options.timestamp) ? options === null || options === void 0 ? void 0 : options.timestamp : currentISOTime(), uuid: (options === null || options === void 0 ? void 0 : options.uuid) ? options.uuid : generateUUID(globalThis) });
|
|
1007
1016
|
var addGeoipDisableProperty = (_a = options === null || options === void 0 ? void 0 : options.disableGeoip) !== null && _a !== void 0 ? _a : this.disableGeoip;
|
|
1008
1017
|
if (addGeoipDisableProperty) {
|
|
1009
1018
|
if (!message.properties) {
|
|
@@ -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
|
|
@@ -2720,48 +2746,103 @@ function (_super) {
|
|
|
2720
2746
|
groups = _a.groups,
|
|
2721
2747
|
sendFeatureFlags = _a.sendFeatureFlags,
|
|
2722
2748
|
timestamp = _a.timestamp,
|
|
2723
|
-
disableGeoip = _a.disableGeoip
|
|
2749
|
+
disableGeoip = _a.disableGeoip,
|
|
2750
|
+
uuid = _a.uuid;
|
|
2724
2751
|
|
|
2725
2752
|
var _capture = function (props) {
|
|
2726
2753
|
_super.prototype.captureStateless.call(_this, distinctId, event, props, {
|
|
2727
2754
|
timestamp: timestamp,
|
|
2728
|
-
disableGeoip: disableGeoip
|
|
2755
|
+
disableGeoip: disableGeoip,
|
|
2756
|
+
uuid: uuid
|
|
2729
2757
|
});
|
|
2730
|
-
};
|
|
2758
|
+
}; // :TRICKY: If we flush, or need to shut down, to not lose events we want this promise to resolve before we flush
|
|
2731
2759
|
|
|
2732
|
-
if (sendFeatureFlags) {
|
|
2733
|
-
_super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip).then(function (flags) {
|
|
2734
|
-
var featureVariantProperties = {};
|
|
2735
2760
|
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
feature = _b[0],
|
|
2740
|
-
variant = _b[1];
|
|
2761
|
+
var capturePromise = Promise.resolve().then(function () {
|
|
2762
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
2763
|
+
var groupsWithStringValues, _i, _a, _b, key, value;
|
|
2741
2764
|
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2765
|
+
var _c, _d;
|
|
2766
|
+
|
|
2767
|
+
return __generator(this, function (_e) {
|
|
2768
|
+
switch (_e.label) {
|
|
2769
|
+
case 0:
|
|
2770
|
+
if (!sendFeatureFlags) return [3
|
|
2771
|
+
/*break*/
|
|
2772
|
+
, 2];
|
|
2773
|
+
return [4
|
|
2774
|
+
/*yield*/
|
|
2775
|
+
, _super.prototype.getFeatureFlagsStateless.call(this, distinctId, groups, undefined, undefined, disableGeoip)];
|
|
2776
|
+
|
|
2777
|
+
case 1:
|
|
2778
|
+
// If we are sending feature flags, we need to make sure we have the latest flags
|
|
2779
|
+
return [2
|
|
2780
|
+
/*return*/
|
|
2781
|
+
, _e.sent()];
|
|
2782
|
+
|
|
2783
|
+
case 2:
|
|
2784
|
+
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
|
|
2785
|
+
/*break*/
|
|
2786
|
+
, 4];
|
|
2787
|
+
groupsWithStringValues = {};
|
|
2788
|
+
|
|
2789
|
+
for (_i = 0, _a = Object.entries(groups || {}); _i < _a.length; _i++) {
|
|
2790
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
2791
|
+
groupsWithStringValues[key] = String(value);
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
return [4
|
|
2795
|
+
/*yield*/
|
|
2796
|
+
, this.getAllFlags(distinctId, {
|
|
2797
|
+
groups: groupsWithStringValues,
|
|
2798
|
+
disableGeoip: disableGeoip,
|
|
2799
|
+
onlyEvaluateLocally: true
|
|
2800
|
+
})];
|
|
2801
|
+
|
|
2802
|
+
case 3:
|
|
2803
|
+
return [2
|
|
2804
|
+
/*return*/
|
|
2805
|
+
, _e.sent()];
|
|
2806
|
+
|
|
2807
|
+
case 4:
|
|
2808
|
+
return [2
|
|
2809
|
+
/*return*/
|
|
2810
|
+
, {}];
|
|
2745
2811
|
}
|
|
2812
|
+
});
|
|
2813
|
+
});
|
|
2814
|
+
}).then(function (flags) {
|
|
2815
|
+
// Derive the relevant flag properties to add
|
|
2816
|
+
var additionalProperties = {};
|
|
2817
|
+
|
|
2818
|
+
if (flags) {
|
|
2819
|
+
for (var _i = 0, _a = Object.entries(flags); _i < _a.length; _i++) {
|
|
2820
|
+
var _b = _a[_i],
|
|
2821
|
+
feature = _b[0],
|
|
2822
|
+
variant = _b[1];
|
|
2823
|
+
additionalProperties["$feature/".concat(feature)] = variant;
|
|
2746
2824
|
}
|
|
2825
|
+
}
|
|
2747
2826
|
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2827
|
+
var activeFlags = Object.keys(flags || {}).filter(function (flag) {
|
|
2828
|
+
return (flags === null || flags === void 0 ? void 0 : flags[flag]) !== false;
|
|
2829
|
+
});
|
|
2751
2830
|
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2831
|
+
if (activeFlags.length > 0) {
|
|
2832
|
+
additionalProperties['$active_feature_flags'] = activeFlags;
|
|
2833
|
+
}
|
|
2755
2834
|
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2835
|
+
return additionalProperties;
|
|
2836
|
+
}).catch(function () {
|
|
2837
|
+
// Something went wrong getting the flag info - we should capture the event anyways
|
|
2838
|
+
return {};
|
|
2839
|
+
}).then(function (additionalProperties) {
|
|
2840
|
+
// No matter what - capture the event
|
|
2841
|
+
_capture(__assign(__assign(__assign({}, additionalProperties), properties), {
|
|
2762
2842
|
$groups: groups
|
|
2763
2843
|
}));
|
|
2764
|
-
}
|
|
2844
|
+
});
|
|
2845
|
+
this.addPendingPromise(capturePromise);
|
|
2765
2846
|
};
|
|
2766
2847
|
|
|
2767
2848
|
PostHog.prototype.identify = function (_a) {
|
|
@@ -2788,15 +2869,18 @@ function (_super) {
|
|
|
2788
2869
|
var _a;
|
|
2789
2870
|
|
|
2790
2871
|
return __awaiter(this, void 0, void 0, function () {
|
|
2791
|
-
var _b, groups,
|
|
2872
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties, adjustedProperties, response, flagWasLocallyEvaluated, featureFlagReportedKey;
|
|
2792
2873
|
|
|
2793
2874
|
var _d;
|
|
2794
2875
|
|
|
2795
2876
|
return __generator(this, function (_e) {
|
|
2796
2877
|
switch (_e.label) {
|
|
2797
2878
|
case 0:
|
|
2798
|
-
_b = options || {}, groups = _b.groups,
|
|
2799
|
-
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents
|
|
2879
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
2880
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, sendFeatureFlagEvents = _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
2881
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
2882
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
2883
|
+
groupProperties = adjustedProperties.allGroupProperties; // set defaults
|
|
2800
2884
|
|
|
2801
2885
|
if (onlyEvaluateLocally == undefined) {
|
|
2802
2886
|
onlyEvaluateLocally = false;
|
|
@@ -2863,13 +2947,16 @@ function (_super) {
|
|
|
2863
2947
|
var _a;
|
|
2864
2948
|
|
|
2865
2949
|
return __awaiter(this, void 0, void 0, function () {
|
|
2866
|
-
var _b, groups,
|
|
2950
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, response, payloadWasLocallyEvaluated;
|
|
2867
2951
|
|
|
2868
2952
|
return __generator(this, function (_d) {
|
|
2869
2953
|
switch (_d.label) {
|
|
2870
2954
|
case 0:
|
|
2871
|
-
_b = options || {}, groups = _b.groups,
|
|
2872
|
-
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents;
|
|
2955
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
2956
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, _c.sendFeatureFlagEvents, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
2957
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
2958
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
2959
|
+
groupProperties = adjustedProperties.allGroupProperties;
|
|
2873
2960
|
response = undefined;
|
|
2874
2961
|
if (!!matchValue) return [3
|
|
2875
2962
|
/*break*/
|
|
@@ -2989,13 +3076,16 @@ function (_super) {
|
|
|
2989
3076
|
var _a;
|
|
2990
3077
|
|
|
2991
3078
|
return __awaiter(this, void 0, void 0, function () {
|
|
2992
|
-
var _b, groups, personProperties, groupProperties,
|
|
3079
|
+
var _b, groups, disableGeoip, _c, onlyEvaluateLocally, personProperties, groupProperties, adjustedProperties, localEvaluationResult, featureFlags, featureFlagPayloads, fallbackToDecide, remoteEvaluationResult;
|
|
2993
3080
|
|
|
2994
|
-
return __generator(this, function (
|
|
2995
|
-
switch (
|
|
3081
|
+
return __generator(this, function (_d) {
|
|
3082
|
+
switch (_d.label) {
|
|
2996
3083
|
case 0:
|
|
2997
|
-
_b = options || {}, groups = _b.groups,
|
|
2998
|
-
|
|
3084
|
+
_b = options || {}, groups = _b.groups, disableGeoip = _b.disableGeoip;
|
|
3085
|
+
_c = options || {}, onlyEvaluateLocally = _c.onlyEvaluateLocally, personProperties = _c.personProperties, groupProperties = _c.groupProperties;
|
|
3086
|
+
adjustedProperties = this.addLocalPersonAndGroupProperties(distinctId, groups, personProperties, groupProperties);
|
|
3087
|
+
personProperties = adjustedProperties.allPersonProperties;
|
|
3088
|
+
groupProperties = adjustedProperties.allGroupProperties; // set defaults
|
|
2999
3089
|
|
|
3000
3090
|
if (onlyEvaluateLocally == undefined) {
|
|
3001
3091
|
onlyEvaluateLocally = false;
|
|
@@ -3006,7 +3096,7 @@ function (_super) {
|
|
|
3006
3096
|
, (_a = this.featureFlagsPoller) === null || _a === void 0 ? void 0 : _a.getAllFlagsAndPayloads(distinctId, groups, personProperties, groupProperties)];
|
|
3007
3097
|
|
|
3008
3098
|
case 1:
|
|
3009
|
-
localEvaluationResult =
|
|
3099
|
+
localEvaluationResult = _d.sent();
|
|
3010
3100
|
featureFlags = {};
|
|
3011
3101
|
featureFlagPayloads = {};
|
|
3012
3102
|
fallbackToDecide = true;
|
|
@@ -3025,10 +3115,10 @@ function (_super) {
|
|
|
3025
3115
|
, _super.prototype.getFeatureFlagsAndPayloadsStateless.call(this, distinctId, groups, personProperties, groupProperties, disableGeoip)];
|
|
3026
3116
|
|
|
3027
3117
|
case 2:
|
|
3028
|
-
remoteEvaluationResult =
|
|
3118
|
+
remoteEvaluationResult = _d.sent();
|
|
3029
3119
|
featureFlags = __assign(__assign({}, featureFlags), remoteEvaluationResult.flags || {});
|
|
3030
3120
|
featureFlagPayloads = __assign(__assign({}, featureFlagPayloads), remoteEvaluationResult.payloads || {});
|
|
3031
|
-
|
|
3121
|
+
_d.label = 3;
|
|
3032
3122
|
|
|
3033
3123
|
case 3:
|
|
3034
3124
|
return [2
|
|
@@ -3093,6 +3183,28 @@ function (_super) {
|
|
|
3093
3183
|
});
|
|
3094
3184
|
};
|
|
3095
3185
|
|
|
3186
|
+
PostHog.prototype.addLocalPersonAndGroupProperties = function (distinctId, groups, personProperties, groupProperties) {
|
|
3187
|
+
var allPersonProperties = __assign({
|
|
3188
|
+
$current_distinct_id: distinctId
|
|
3189
|
+
}, personProperties || {});
|
|
3190
|
+
|
|
3191
|
+
var allGroupProperties = {};
|
|
3192
|
+
|
|
3193
|
+
if (groups) {
|
|
3194
|
+
for (var _i = 0, _a = Object.keys(groups); _i < _a.length; _i++) {
|
|
3195
|
+
var groupName = _a[_i];
|
|
3196
|
+
allGroupProperties[groupName] = __assign({
|
|
3197
|
+
$group_key: groups[groupName]
|
|
3198
|
+
}, (groupProperties === null || groupProperties === void 0 ? void 0 : groupProperties[groupName]) || {});
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
return {
|
|
3203
|
+
allPersonProperties: allPersonProperties,
|
|
3204
|
+
allGroupProperties: allGroupProperties
|
|
3205
|
+
};
|
|
3206
|
+
};
|
|
3207
|
+
|
|
3096
3208
|
return PostHog;
|
|
3097
3209
|
}(PostHogCoreStateless);
|
|
3098
3210
|
|