posthog-node 4.17.0 → 4.17.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 +11 -0
- package/lib/edge/{index.cjs.js → index.cjs} +43 -11
- package/lib/edge/index.cjs.map +1 -0
- package/lib/edge/{index.esm.js → index.mjs} +43 -11
- package/lib/edge/index.mjs.map +1 -0
- package/lib/index.d.ts +69 -57
- package/lib/node/{index.cjs.js → index.cjs} +43 -11
- package/lib/node/index.cjs.map +1 -0
- package/lib/node/{index.esm.js → index.mjs} +43 -11
- package/lib/node/index.mjs.map +1 -0
- package/package.json +17 -17
- package/lib/edge/index.cjs.js.map +0 -1
- package/lib/edge/index.esm.js.map +0 -1
- package/lib/node/index.cjs.js.map +0 -1
- package/lib/node/index.esm.js.map +0 -1
- package/src/client.ts +0 -650
- package/src/entrypoints/index.edge.ts +0 -15
- package/src/entrypoints/index.node.ts +0 -17
- package/src/exports.ts +0 -3
- package/src/extensions/error-tracking/autocapture.ts +0 -65
- package/src/extensions/error-tracking/context-lines.node.ts +0 -392
- package/src/extensions/error-tracking/error-conversion.ts +0 -279
- package/src/extensions/error-tracking/get-module.node.ts +0 -57
- package/src/extensions/error-tracking/index.ts +0 -69
- package/src/extensions/error-tracking/reduceable-cache.ts +0 -39
- package/src/extensions/error-tracking/stack-parser.ts +0 -212
- package/src/extensions/error-tracking/type-checking.ts +0 -40
- package/src/extensions/error-tracking/types.ts +0 -69
- package/src/extensions/express.ts +0 -37
- package/src/extensions/feature-flags/crypto-helpers.ts +0 -36
- package/src/extensions/feature-flags/crypto.ts +0 -22
- package/src/extensions/feature-flags/feature-flags.ts +0 -865
- package/src/extensions/feature-flags/lazy.ts +0 -55
- package/src/extensions/sentry-integration.ts +0 -204
- package/src/fetch.ts +0 -39
- package/src/storage-memory.ts +0 -13
- package/src/types.ts +0 -275
- package/test/crypto.spec.ts +0 -36
- package/test/extensions/error-conversion.spec.ts +0 -44
- package/test/extensions/sentry-integration.spec.ts +0 -163
- package/test/feature-flags.decide.spec.ts +0 -381
- package/test/feature-flags.spec.ts +0 -4686
- package/test/lazy.spec.ts +0 -71
- package/test/posthog-node.spec.ts +0 -1341
- package/test/test-utils.ts +0 -111
- package/tsconfig.json +0 -8
|
@@ -1268,7 +1268,7 @@ function snipLine(line, colno) {
|
|
|
1268
1268
|
return newLine;
|
|
1269
1269
|
}
|
|
1270
1270
|
|
|
1271
|
-
var version = "4.17.
|
|
1271
|
+
var version = "4.17.2";
|
|
1272
1272
|
|
|
1273
1273
|
var PostHogPersistedProperty;
|
|
1274
1274
|
(function (PostHogPersistedProperty) {
|
|
@@ -1599,6 +1599,9 @@ function isTokenInRollout(token, percentage = 0, excludedHashes) {
|
|
|
1599
1599
|
const hashInt = parseInt(tokenHash, 16);
|
|
1600
1600
|
const hashFloat = hashInt / 0xffffffff;
|
|
1601
1601
|
return hashFloat < percentage;
|
|
1602
|
+
}
|
|
1603
|
+
function allSettled(promises) {
|
|
1604
|
+
return Promise.all(promises.map((p) => (p ?? Promise.resolve()).then((value) => ({ status: 'fulfilled', value }), (reason) => ({ status: 'rejected', reason }))));
|
|
1602
1605
|
}
|
|
1603
1606
|
|
|
1604
1607
|
// Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
|
|
@@ -2343,6 +2346,7 @@ class PostHogCoreStateless {
|
|
|
2343
2346
|
...extraPayload,
|
|
2344
2347
|
}),
|
|
2345
2348
|
};
|
|
2349
|
+
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Decide URL', url));
|
|
2346
2350
|
// Don't retry /decide API calls
|
|
2347
2351
|
return this.fetchWithRetry(url, fetchOptions, { retryCount: 0 }, this.featureFlagsRequestTimeoutMs)
|
|
2348
2352
|
.then((response) => response.json())
|
|
@@ -2460,7 +2464,7 @@ class PostHogCoreStateless {
|
|
|
2460
2464
|
async getSurveysStateless() {
|
|
2461
2465
|
await this._initPromise;
|
|
2462
2466
|
if (this.disableSurveys === true) {
|
|
2463
|
-
this.logMsgIfDebug(() => console.log('Loading surveys is disabled.'));
|
|
2467
|
+
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Loading surveys is disabled.'));
|
|
2464
2468
|
return [];
|
|
2465
2469
|
}
|
|
2466
2470
|
const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
|
|
@@ -2583,7 +2587,6 @@ class PostHogCoreStateless {
|
|
|
2583
2587
|
}
|
|
2584
2588
|
catch (err) {
|
|
2585
2589
|
this._events.emit('error', err);
|
|
2586
|
-
throw err;
|
|
2587
2590
|
}
|
|
2588
2591
|
}
|
|
2589
2592
|
prepareMessage(type, _message, options) {
|
|
@@ -2623,15 +2626,38 @@ class PostHogCoreStateless {
|
|
|
2623
2626
|
await logFlushError(err);
|
|
2624
2627
|
});
|
|
2625
2628
|
}
|
|
2629
|
+
/**
|
|
2630
|
+
* Flushes the queue
|
|
2631
|
+
*
|
|
2632
|
+
* This function will return a promise that will resolve when the flush is complete,
|
|
2633
|
+
* or reject if there was an error (for example if the server or network is down).
|
|
2634
|
+
*
|
|
2635
|
+
* If there is already a flush in progress, this function will wait for that flush to complete.
|
|
2636
|
+
*
|
|
2637
|
+
* It's recommended to do error handling in the callback of the promise.
|
|
2638
|
+
*
|
|
2639
|
+
* @example
|
|
2640
|
+
* posthog.flush().then(() => {
|
|
2641
|
+
* console.log('Flush complete')
|
|
2642
|
+
* }).catch((err) => {
|
|
2643
|
+
* console.error('Flush failed', err)
|
|
2644
|
+
* })
|
|
2645
|
+
*
|
|
2646
|
+
*
|
|
2647
|
+
* @throws PostHogFetchHttpError
|
|
2648
|
+
* @throws PostHogFetchNetworkError
|
|
2649
|
+
* @throws Error
|
|
2650
|
+
*/
|
|
2626
2651
|
async flush() {
|
|
2627
2652
|
// Wait for the current flush operation to finish (regardless of success or failure), then try to flush again.
|
|
2628
2653
|
// Use allSettled instead of finally to be defensive around flush throwing errors immediately rather than rejecting.
|
|
2629
|
-
|
|
2654
|
+
// Use a custom allSettled implementation to avoid issues with patching Promise on RN
|
|
2655
|
+
const nextFlushPromise = allSettled([this.flushPromise]).then(() => {
|
|
2630
2656
|
return this._flush();
|
|
2631
2657
|
});
|
|
2632
2658
|
this.flushPromise = nextFlushPromise;
|
|
2633
2659
|
void this.addPendingPromise(nextFlushPromise);
|
|
2634
|
-
|
|
2660
|
+
allSettled([nextFlushPromise]).then(() => {
|
|
2635
2661
|
// If there are no others waiting to flush, clear the promise.
|
|
2636
2662
|
// We don't strictly need to do this, but it could make debugging easier
|
|
2637
2663
|
if (this.flushPromise === nextFlushPromise) {
|
|
@@ -2657,7 +2683,7 @@ class PostHogCoreStateless {
|
|
|
2657
2683
|
await this._initPromise;
|
|
2658
2684
|
let queue = this.getPersistedProperty(PostHogPersistedProperty.Queue) || [];
|
|
2659
2685
|
if (!queue.length) {
|
|
2660
|
-
return
|
|
2686
|
+
return;
|
|
2661
2687
|
}
|
|
2662
2688
|
const sentMessages = [];
|
|
2663
2689
|
const originalQueueLength = queue.length;
|
|
@@ -2728,7 +2754,6 @@ class PostHogCoreStateless {
|
|
|
2728
2754
|
sentMessages.push(...batchMessages);
|
|
2729
2755
|
}
|
|
2730
2756
|
this._events.emit('flush', sentMessages);
|
|
2731
|
-
return sentMessages;
|
|
2732
2757
|
}
|
|
2733
2758
|
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
2734
2759
|
var _a;
|
|
@@ -2738,7 +2763,14 @@ class PostHogCoreStateless {
|
|
|
2738
2763
|
return ctrl.signal;
|
|
2739
2764
|
});
|
|
2740
2765
|
const body = options.body ? options.body : '';
|
|
2741
|
-
|
|
2766
|
+
let reqByteLength = -1;
|
|
2767
|
+
try {
|
|
2768
|
+
reqByteLength = Buffer.byteLength(body, STRING_FORMAT);
|
|
2769
|
+
}
|
|
2770
|
+
catch {
|
|
2771
|
+
const encoded = new TextEncoder().encode(body);
|
|
2772
|
+
reqByteLength = encoded.length;
|
|
2773
|
+
}
|
|
2742
2774
|
return await retriable(async () => {
|
|
2743
2775
|
let res = null;
|
|
2744
2776
|
try {
|
|
@@ -3284,12 +3316,12 @@ class FeatureFlagsPoller {
|
|
|
3284
3316
|
case 200:
|
|
3285
3317
|
{
|
|
3286
3318
|
// Process successful response
|
|
3287
|
-
const responseJson = await res.json();
|
|
3319
|
+
const responseJson = (await res.json()) ?? {};
|
|
3288
3320
|
if (!('flags' in responseJson)) {
|
|
3289
3321
|
this.onError?.(new Error(`Invalid response when getting feature flags: ${JSON.stringify(responseJson)}`));
|
|
3290
3322
|
return;
|
|
3291
3323
|
}
|
|
3292
|
-
this.featureFlags = responseJson.flags
|
|
3324
|
+
this.featureFlags = responseJson.flags ?? [];
|
|
3293
3325
|
this.featureFlagsByKey = this.featureFlags.reduce((acc, curr) => (acc[curr.key] = curr, acc), {});
|
|
3294
3326
|
this.groupTypeMapping = responseJson.group_type_mapping || {};
|
|
3295
3327
|
this.cohorts = responseJson.cohorts || {};
|
|
@@ -4295,4 +4327,4 @@ class PostHog extends PostHogBackendClient {
|
|
|
4295
4327
|
}
|
|
4296
4328
|
|
|
4297
4329
|
export { PostHog, PostHogSentryIntegration, createEventProcessor, sentryIntegration, setupExpressErrorHandler };
|
|
4298
|
-
//# sourceMappingURL=index.
|
|
4330
|
+
//# sourceMappingURL=index.mjs.map
|