posthog-node 4.2.1 → 4.2.3
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 +8 -0
- package/lib/index.cjs.js +46 -26
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -2
- package/lib/index.esm.js +46 -26
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +3 -2
- package/package.json +1 -1
- package/src/posthog-node.ts +9 -2
- package/test/posthog-node.spec.ts +29 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Next
|
|
2
2
|
|
|
3
|
+
# 4.2.3 - 2024-11-21
|
|
4
|
+
|
|
5
|
+
1. fix: identify method allows passing a $set_once object
|
|
6
|
+
|
|
7
|
+
# 4.2.2 - 2024-11-18
|
|
8
|
+
|
|
9
|
+
1. fix: Shutdown will now respect the timeout and forcefully return rather than returning after the next fetch.
|
|
10
|
+
|
|
3
11
|
# 4.2.1 - 2024-10-14
|
|
4
12
|
|
|
5
13
|
1. fix: only log messages if debug is enabled
|
package/lib/index.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var rusha = require('rusha');
|
|
6
6
|
|
|
7
|
-
var version = "4.2.
|
|
7
|
+
var version = "4.2.3";
|
|
8
8
|
|
|
9
9
|
var PostHogPersistedProperty;
|
|
10
10
|
(function (PostHogPersistedProperty) {
|
|
@@ -1035,6 +1035,9 @@ class PostHogCoreStateless {
|
|
|
1035
1035
|
get isDebug() {
|
|
1036
1036
|
return !!this.removeDebugCallback;
|
|
1037
1037
|
}
|
|
1038
|
+
get isDisabled() {
|
|
1039
|
+
return this.disabled;
|
|
1040
|
+
}
|
|
1038
1041
|
buildPayload(payload) {
|
|
1039
1042
|
return {
|
|
1040
1043
|
distinct_id: payload.distinct_id,
|
|
@@ -1061,7 +1064,7 @@ class PostHogCoreStateless {
|
|
|
1061
1064
|
identifyStateless(distinctId, properties, options) {
|
|
1062
1065
|
this.wrap(() => {
|
|
1063
1066
|
// The properties passed to identifyStateless are event properties.
|
|
1064
|
-
// To add person properties, pass in all person properties to the `$set`
|
|
1067
|
+
// To add person properties, pass in all person properties to the `$set` and `$set_once` keys.
|
|
1065
1068
|
const payload = {
|
|
1066
1069
|
...this.buildPayload({
|
|
1067
1070
|
distinct_id: distinctId,
|
|
@@ -1363,33 +1366,45 @@ class PostHogCoreStateless {
|
|
|
1363
1366
|
}, { ...this._retryOptions, ...retryOptions });
|
|
1364
1367
|
}
|
|
1365
1368
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
1369
|
+
// A little tricky - we want to have a max shutdown time and enforce it, even if that means we have some
|
|
1370
|
+
// dangling promises. We'll keep track of the timeout and resolve/reject based on that.
|
|
1366
1371
|
await this._initPromise;
|
|
1372
|
+
let hasTimedOut = false;
|
|
1367
1373
|
this.clearFlushTimer();
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
break;
|
|
1374
|
+
const doShutdown = async () => {
|
|
1375
|
+
try {
|
|
1376
|
+
await Promise.all(Object.values(this.pendingPromises));
|
|
1377
|
+
while (true) {
|
|
1378
|
+
const queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
|
|
1379
|
+
if (queue.length === 0) {
|
|
1380
|
+
break;
|
|
1381
|
+
}
|
|
1382
|
+
// flush again to make sure we send all events, some of which might've been added
|
|
1383
|
+
// while we were waiting for the pending promises to resolve
|
|
1384
|
+
// For example, see sendFeatureFlags in posthog-node/src/posthog-node.ts::capture
|
|
1385
|
+
await this.flush();
|
|
1386
|
+
if (hasTimedOut) {
|
|
1387
|
+
break;
|
|
1388
|
+
}
|
|
1384
1389
|
}
|
|
1385
1390
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1391
|
+
catch (e) {
|
|
1392
|
+
if (!isPostHogFetchError(e)) {
|
|
1393
|
+
throw e;
|
|
1394
|
+
}
|
|
1395
|
+
this.logMsgIfDebug(() => console.error('Error while shutting down PostHog', e));
|
|
1390
1396
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1397
|
+
};
|
|
1398
|
+
return Promise.race([
|
|
1399
|
+
new Promise((_, reject) => {
|
|
1400
|
+
safeSetTimeout(() => {
|
|
1401
|
+
this.logMsgIfDebug(() => console.error('Timed out while shutting down PostHog'));
|
|
1402
|
+
hasTimedOut = true;
|
|
1403
|
+
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
1404
|
+
}, shutdownTimeoutMs);
|
|
1405
|
+
}),
|
|
1406
|
+
doShutdown(),
|
|
1407
|
+
]);
|
|
1393
1408
|
}
|
|
1394
1409
|
}
|
|
1395
1410
|
|
|
@@ -2148,9 +2163,14 @@ class PostHog extends PostHogCoreStateless {
|
|
|
2148
2163
|
disableGeoip
|
|
2149
2164
|
}) {
|
|
2150
2165
|
// Catch properties passed as $set and move them to the top level
|
|
2151
|
-
|
|
2166
|
+
// promote $set and $set_once to top level
|
|
2167
|
+
const userPropsOnce = properties?.$set_once;
|
|
2168
|
+
delete properties?.$set_once;
|
|
2169
|
+
// if no $set is provided we assume all properties are $set
|
|
2170
|
+
const userProps = properties?.$set || properties;
|
|
2152
2171
|
super.identifyStateless(distinctId, {
|
|
2153
|
-
$set:
|
|
2172
|
+
$set: userProps,
|
|
2173
|
+
$set_once: userPropsOnce
|
|
2154
2174
|
}, {
|
|
2155
2175
|
disableGeoip
|
|
2156
2176
|
});
|