posthog-node 4.11.2 → 4.11.4
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 +15 -3
- package/lib/index.cjs.js +98 -66
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +98 -66
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/utils.d.ts +1 -0
- package/lib/posthog-node/src/extensions/error-tracking/context-lines.d.ts +2 -0
- package/lib/posthog-node/src/extensions/error-tracking/error-conversion.d.ts +0 -3
- package/package.json +1 -1
- package/src/extensions/error-tracking/autocapture.ts +3 -0
- package/src/extensions/error-tracking/context-lines.ts +100 -64
- package/src/extensions/error-tracking/error-conversion.ts +3 -4
- package/src/extensions/error-tracking/reduceable-cache.ts +3 -0
- package/src/extensions/error-tracking/stack-trace.ts +2 -2
- package/src/extensions/error-tracking/type-checking.ts +3 -0
- package/src/extensions/error-tracking/types.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
# 4.11.4 - 2025-04-14
|
|
2
|
+
|
|
3
|
+
## Fixed
|
|
4
|
+
|
|
5
|
+
1. export top-level declarations for surveys
|
|
6
|
+
|
|
7
|
+
# 4.11.3 - 2025-04-08
|
|
8
|
+
|
|
9
|
+
## Fixed
|
|
10
|
+
|
|
11
|
+
1. do not access `fs` or `readline` in when not available e.g. edge environments
|
|
12
|
+
|
|
1
13
|
# 4.11.2 - 2025-04-07
|
|
2
14
|
|
|
3
|
-
|
|
15
|
+
## Fixed
|
|
4
16
|
|
|
17
|
+
1. chore: bump axios to 1.8.2 (fixes [CVE-2025-27152](https://github.com/advisories/GHSA-jr5f-v2jv-69x6))
|
|
5
18
|
|
|
6
19
|
# 4.11.1 - 2025-03-28
|
|
7
20
|
|
|
@@ -28,7 +41,6 @@
|
|
|
28
41
|
1. Fix: only set `platform` on PostHog exception frame properties
|
|
29
42
|
1. Fix: prevent fetch floods when rate-limited.
|
|
30
43
|
|
|
31
|
-
|
|
32
44
|
# 4.10.0 – 2025-03-06
|
|
33
45
|
|
|
34
46
|
1. Attach requestId to $feature_flag_called if present in /decide response
|
|
@@ -320,4 +332,4 @@ Breaking changes:
|
|
|
320
332
|
What's new:
|
|
321
333
|
|
|
322
334
|
1. You can now evaluate feature flags locally (i.e. without sending a request to your PostHog servers) by setting a personal API key, and passing in groups and person properties to `isFeatureEnabled` and `getFeatureFlag` calls.
|
|
323
|
-
2. Introduces a `getAllFlags` method that returns all feature flags. This is useful for when you want to seed your frontend with some initial flags, given a user ID.
|
|
335
|
+
2. Introduces a `getAllFlags` method that returns all feature flags. This is useful for when you want to seed your frontend with some initial flags, given a user ID.
|
package/lib/index.cjs.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var node_fs = require('node:fs');
|
|
6
|
-
var node_readline = require('node:readline');
|
|
7
5
|
var node_path = require('node:path');
|
|
8
6
|
|
|
9
7
|
function _interopNamespace(e) {
|
|
@@ -24,7 +22,7 @@ function _interopNamespace(e) {
|
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
|
-
var version = "4.11.
|
|
25
|
+
var version = "4.11.4";
|
|
28
26
|
|
|
29
27
|
var PostHogPersistedProperty;
|
|
30
28
|
(function (PostHogPersistedProperty) {
|
|
@@ -2426,6 +2424,8 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
2426
2424
|
}
|
|
2427
2425
|
}
|
|
2428
2426
|
|
|
2427
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
2428
|
+
// Licensed under the MIT License
|
|
2429
2429
|
function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
|
|
2430
2430
|
let calledFatalError = false;
|
|
2431
2431
|
return Object.assign(error => {
|
|
@@ -2472,6 +2472,8 @@ function addUnhandledRejectionListener(captureFn) {
|
|
|
2472
2472
|
});
|
|
2473
2473
|
}
|
|
2474
2474
|
|
|
2475
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
2476
|
+
// Licensed under the MIT License
|
|
2475
2477
|
function isEvent(candidate) {
|
|
2476
2478
|
return typeof Event !== 'undefined' && isInstanceOf(candidate, Event);
|
|
2477
2479
|
}
|
|
@@ -2503,6 +2505,8 @@ function isBuiltin(candidate, className) {
|
|
|
2503
2505
|
return Object.prototype.toString.call(candidate) === `[object ${className}]`;
|
|
2504
2506
|
}
|
|
2505
2507
|
|
|
2508
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
2509
|
+
// Licensed under the MIT License
|
|
2506
2510
|
/** A simple Least Recently Used map */
|
|
2507
2511
|
class ReduceableCache {
|
|
2508
2512
|
constructor(_maxSize) {
|
|
@@ -2536,6 +2540,27 @@ class ReduceableCache {
|
|
|
2536
2540
|
}
|
|
2537
2541
|
}
|
|
2538
2542
|
|
|
2543
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
2544
|
+
const nodeFs = new Lazy(async () => {
|
|
2545
|
+
try {
|
|
2546
|
+
return await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('node:fs')); });
|
|
2547
|
+
} catch {
|
|
2548
|
+
return undefined;
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2551
|
+
async function getNodeFs() {
|
|
2552
|
+
return await nodeFs.getValue();
|
|
2553
|
+
}
|
|
2554
|
+
const nodeReadline = new Lazy(async () => {
|
|
2555
|
+
try {
|
|
2556
|
+
return await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('node:readline')); });
|
|
2557
|
+
} catch {
|
|
2558
|
+
return undefined;
|
|
2559
|
+
}
|
|
2560
|
+
});
|
|
2561
|
+
async function getNodeReadline() {
|
|
2562
|
+
return await nodeReadline.getValue();
|
|
2563
|
+
}
|
|
2539
2564
|
const LRU_FILE_CONTENTS_CACHE = new ReduceableCache(25);
|
|
2540
2565
|
const LRU_FILE_CONTENTS_FS_READ_FAILED = new ReduceableCache(20);
|
|
2541
2566
|
const DEFAULT_LINES_OF_CONTEXT = 7;
|
|
@@ -2603,70 +2628,79 @@ async function addSourceContext(frames) {
|
|
|
2603
2628
|
*/
|
|
2604
2629
|
function getContextLinesFromFile(path, ranges, output) {
|
|
2605
2630
|
return new Promise(resolve => {
|
|
2606
|
-
//
|
|
2607
|
-
//
|
|
2608
|
-
//
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
});
|
|
2613
|
-
// We need to explicitly destroy the stream to prevent memory leaks,
|
|
2614
|
-
// removing the listeners on the readline interface is not enough.
|
|
2615
|
-
// See: https://github.com/nodejs/node/issues/9002 and https://github.com/getsentry/sentry-javascript/issues/14892
|
|
2616
|
-
function destroyStreamAndResolve() {
|
|
2617
|
-
stream.destroy();
|
|
2618
|
-
resolve();
|
|
2619
|
-
}
|
|
2620
|
-
// Init at zero and increment at the start of the loop because lines are 1 indexed.
|
|
2621
|
-
let lineNumber = 0;
|
|
2622
|
-
let currentRangeIndex = 0;
|
|
2623
|
-
const range = ranges[currentRangeIndex];
|
|
2624
|
-
if (range === undefined) {
|
|
2625
|
-
// We should never reach this point, but if we do, we should resolve the promise to prevent it from hanging.
|
|
2626
|
-
destroyStreamAndResolve();
|
|
2627
|
-
return;
|
|
2628
|
-
}
|
|
2629
|
-
let rangeStart = range[0];
|
|
2630
|
-
let rangeEnd = range[1];
|
|
2631
|
-
// We use this inside Promise.all, so we need to resolve the promise even if there is an error
|
|
2632
|
-
// to prevent Promise.all from short circuiting the rest.
|
|
2633
|
-
function onStreamError() {
|
|
2634
|
-
// Mark file path as failed to read and prevent multiple read attempts.
|
|
2635
|
-
LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
|
|
2636
|
-
lineReaded.close();
|
|
2637
|
-
lineReaded.removeAllListeners();
|
|
2638
|
-
destroyStreamAndResolve();
|
|
2639
|
-
}
|
|
2640
|
-
// We need to handle the error event to prevent the process from crashing in < Node 16
|
|
2641
|
-
// https://github.com/nodejs/node/pull/31603
|
|
2642
|
-
stream.on('error', onStreamError);
|
|
2643
|
-
lineReaded.on('error', onStreamError);
|
|
2644
|
-
lineReaded.on('close', destroyStreamAndResolve);
|
|
2645
|
-
lineReaded.on('line', line => {
|
|
2646
|
-
lineNumber++;
|
|
2647
|
-
if (lineNumber < rangeStart) {
|
|
2631
|
+
// KLUDGE: edge runtimes do not support node:fs or node:readline
|
|
2632
|
+
// until we have separate packages for each environment this will skip
|
|
2633
|
+
// trying to access the filesystem when not accessible
|
|
2634
|
+
Promise.all([getNodeFs(), getNodeReadline()]).then(([nodeFs, nodeReadline]) => {
|
|
2635
|
+
if (!nodeFs || !nodeReadline) {
|
|
2636
|
+
resolve();
|
|
2648
2637
|
return;
|
|
2649
2638
|
}
|
|
2650
|
-
//
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2639
|
+
// It is important *not* to have any async code between createInterface and the 'line' event listener
|
|
2640
|
+
// as it will cause the 'line' event to
|
|
2641
|
+
// be emitted before the listener is attached.
|
|
2642
|
+
const stream = nodeFs.createReadStream(path);
|
|
2643
|
+
const lineReaded = nodeReadline.createInterface({
|
|
2644
|
+
input: stream
|
|
2645
|
+
});
|
|
2646
|
+
// We need to explicitly destroy the stream to prevent memory leaks,
|
|
2647
|
+
// removing the listeners on the readline interface is not enough.
|
|
2648
|
+
// See: https://github.com/nodejs/node/issues/9002 and https://github.com/getsentry/sentry-javascript/issues/14892
|
|
2649
|
+
function destroyStreamAndResolve() {
|
|
2650
|
+
stream.destroy();
|
|
2651
|
+
resolve();
|
|
2652
|
+
}
|
|
2653
|
+
// Init at zero and increment at the start of the loop because lines are 1 indexed.
|
|
2654
|
+
let lineNumber = 0;
|
|
2655
|
+
let currentRangeIndex = 0;
|
|
2656
|
+
const range = ranges[currentRangeIndex];
|
|
2657
|
+
if (range === undefined) {
|
|
2658
|
+
// We should never reach this point, but if we do, we should resolve the promise to prevent it from hanging.
|
|
2659
|
+
destroyStreamAndResolve();
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
let rangeStart = range[0];
|
|
2663
|
+
let rangeEnd = range[1];
|
|
2664
|
+
// We use this inside Promise.all, so we need to resolve the promise even if there is an error
|
|
2665
|
+
// to prevent Promise.all from short circuiting the rest.
|
|
2666
|
+
function onStreamError() {
|
|
2667
|
+
// Mark file path as failed to read and prevent multiple read attempts.
|
|
2668
|
+
LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
|
|
2669
|
+
lineReaded.close();
|
|
2670
|
+
lineReaded.removeAllListeners();
|
|
2671
|
+
destroyStreamAndResolve();
|
|
2672
|
+
}
|
|
2673
|
+
// We need to handle the error event to prevent the process from crashing in < Node 16
|
|
2674
|
+
// https://github.com/nodejs/node/pull/31603
|
|
2675
|
+
stream.on('error', onStreamError);
|
|
2676
|
+
lineReaded.on('error', onStreamError);
|
|
2677
|
+
lineReaded.on('close', destroyStreamAndResolve);
|
|
2678
|
+
lineReaded.on('line', line => {
|
|
2679
|
+
lineNumber++;
|
|
2680
|
+
if (lineNumber < rangeStart) {
|
|
2657
2681
|
return;
|
|
2658
2682
|
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
if (
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2683
|
+
// !Warning: This mutates the cache by storing the snipped line into the cache.
|
|
2684
|
+
output[lineNumber] = snipLine(line, 0);
|
|
2685
|
+
if (lineNumber >= rangeEnd) {
|
|
2686
|
+
if (currentRangeIndex === ranges.length - 1) {
|
|
2687
|
+
// We need to close the file stream and remove listeners, else the reader will continue to run our listener;
|
|
2688
|
+
lineReaded.close();
|
|
2689
|
+
lineReaded.removeAllListeners();
|
|
2690
|
+
return;
|
|
2691
|
+
}
|
|
2692
|
+
currentRangeIndex++;
|
|
2693
|
+
const range = ranges[currentRangeIndex];
|
|
2694
|
+
if (range === undefined) {
|
|
2695
|
+
// This should never happen as it means we have a bug in the context.
|
|
2696
|
+
lineReaded.close();
|
|
2697
|
+
lineReaded.removeAllListeners();
|
|
2698
|
+
return;
|
|
2699
|
+
}
|
|
2700
|
+
rangeStart = range[0];
|
|
2701
|
+
rangeEnd = range[1];
|
|
2666
2702
|
}
|
|
2667
|
-
|
|
2668
|
-
rangeEnd = range[1];
|
|
2669
|
-
}
|
|
2703
|
+
});
|
|
2670
2704
|
});
|
|
2671
2705
|
});
|
|
2672
2706
|
}
|
|
@@ -2857,9 +2891,7 @@ function snipLine(line, colno) {
|
|
|
2857
2891
|
return newLine;
|
|
2858
2892
|
}
|
|
2859
2893
|
|
|
2860
|
-
|
|
2861
|
-
* based on the very wonderful MIT licensed Sentry SDK
|
|
2862
|
-
*/
|
|
2894
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
2863
2895
|
async function propertiesFromUnknownInput(stackParser, input, hint) {
|
|
2864
2896
|
const providedMechanism = hint && hint.mechanism;
|
|
2865
2897
|
const mechanism = providedMechanism || {
|
|
@@ -3047,7 +3079,7 @@ function parseStackFrames(stackParser, error) {
|
|
|
3047
3079
|
return stackParser(error.stack || '', 1);
|
|
3048
3080
|
}
|
|
3049
3081
|
|
|
3050
|
-
//
|
|
3082
|
+
// Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
|
|
3051
3083
|
// This was originally forked from https://github.com/csnover/TraceKit, and was largely
|
|
3052
3084
|
// re-written as part of raven - js.
|
|
3053
3085
|
//
|