posthog-node 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/lib/index.cjs.js +17 -4
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +17 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/posthog-node.ts +6 -1
- package/test/posthog-node.spec.ts +79 -2
package/lib/index.d.ts
CHANGED
|
@@ -103,6 +103,7 @@ declare abstract class PostHogCoreStateless {
|
|
|
103
103
|
private requestTimeout;
|
|
104
104
|
private captureMode;
|
|
105
105
|
private removeDebugCallback?;
|
|
106
|
+
private pendingPromises;
|
|
106
107
|
private _optoutOverride;
|
|
107
108
|
protected _events: SimpleEventEmitter;
|
|
108
109
|
protected _flushTimer?: any;
|
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.5.
|
|
158
|
+
var version = "2.5.2";
|
|
159
159
|
|
|
160
160
|
var PostHogPersistedProperty;
|
|
161
161
|
(function (PostHogPersistedProperty) {
|
|
@@ -717,6 +717,7 @@ var SimpleEventEmitter = /** @class */ (function () {
|
|
|
717
717
|
var PostHogCoreStateless = /** @class */ (function () {
|
|
718
718
|
function PostHogCoreStateless(apiKey, options) {
|
|
719
719
|
var _a, _b, _c, _d;
|
|
720
|
+
this.pendingPromises = {};
|
|
720
721
|
// internal
|
|
721
722
|
this._events = new SimpleEventEmitter();
|
|
722
723
|
assert(apiKey, "You must pass your PostHog project's api key.");
|
|
@@ -1005,8 +1006,11 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1005
1006
|
batch: messages,
|
|
1006
1007
|
sent_at: currentISOTime(),
|
|
1007
1008
|
};
|
|
1009
|
+
var promiseUUID = generateUUID();
|
|
1008
1010
|
var done = function (err) {
|
|
1009
1011
|
callback === null || callback === void 0 ? void 0 : callback(err, messages);
|
|
1012
|
+
// remove promise from pendingPromises
|
|
1013
|
+
delete _this.pendingPromises[promiseUUID];
|
|
1010
1014
|
_this._events.emit('flush', messages);
|
|
1011
1015
|
};
|
|
1012
1016
|
// Don't set the user agent if we're not on a browser. The latest spec allows
|
|
@@ -1031,7 +1035,9 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1031
1035
|
headers: { 'Content-Type': 'application/json' },
|
|
1032
1036
|
body: payload,
|
|
1033
1037
|
};
|
|
1034
|
-
this.fetchWithRetry(url, fetchOptions)
|
|
1038
|
+
var requestPromise = this.fetchWithRetry(url, fetchOptions);
|
|
1039
|
+
this.pendingPromises[promiseUUID] = requestPromise;
|
|
1040
|
+
requestPromise
|
|
1035
1041
|
.then(function () { return done(); })
|
|
1036
1042
|
.catch(function (err) {
|
|
1037
1043
|
if (err.response) {
|
|
@@ -1066,6 +1072,9 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1066
1072
|
clearTimeout(this._flushTimer);
|
|
1067
1073
|
return [4 /*yield*/, this.flushAsync()];
|
|
1068
1074
|
case 1:
|
|
1075
|
+
_a.sent();
|
|
1076
|
+
return [4 /*yield*/, Promise.allSettled(Object.values(this.pendingPromises))];
|
|
1077
|
+
case 2:
|
|
1069
1078
|
_a.sent();
|
|
1070
1079
|
return [2 /*return*/];
|
|
1071
1080
|
}
|
|
@@ -2359,9 +2368,13 @@ function (_super) {
|
|
|
2359
2368
|
|
|
2360
2369
|
PostHog.prototype.identify = function (_a) {
|
|
2361
2370
|
var distinctId = _a.distinctId,
|
|
2362
|
-
properties = _a.properties;
|
|
2371
|
+
properties = _a.properties; // Catch properties passed as $set and move them to the top level
|
|
2363
2372
|
|
|
2364
|
-
|
|
2373
|
+
var personProperties = (properties === null || properties === void 0 ? void 0 : properties.$set) || properties;
|
|
2374
|
+
|
|
2375
|
+
_super.prototype.identifyStateless.call(this, distinctId, {
|
|
2376
|
+
$set: personProperties
|
|
2377
|
+
});
|
|
2365
2378
|
};
|
|
2366
2379
|
|
|
2367
2380
|
PostHog.prototype.alias = function (data) {
|