posthog-node 4.2.1 → 4.2.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 +4 -0
- package/lib/index.cjs.js +38 -23
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +38 -23
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +2 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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.2";
|
|
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,
|
|
@@ -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
|
|