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/lib/index.d.ts CHANGED
@@ -2,6 +2,9 @@
2
2
  import { SeverityLevel } from 'posthog-node/src/extensions/error-tracking/types';
3
3
  import * as http from 'node:http';
4
4
 
5
+ // Forces this file to be treated as a module
6
+
7
+
5
8
  interface SurveyAppearance {
6
9
  // keep in sync with frontend/src/types.ts -> SurveyAppearance
7
10
  backgroundColor?: string
package/lib/index.esm.js CHANGED
@@ -1,8 +1,6 @@
1
- import { createReadStream } from 'node:fs';
2
- import { createInterface } from 'node:readline';
3
1
  import { posix, dirname, sep } from 'node:path';
4
2
 
5
- var version = "4.11.2";
3
+ var version = "4.11.4";
6
4
 
7
5
  var PostHogPersistedProperty;
8
6
  (function (PostHogPersistedProperty) {
@@ -2404,6 +2402,8 @@ function relativeDateParseForFeatureFlagMatching(value) {
2404
2402
  }
2405
2403
  }
2406
2404
 
2405
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2406
+ // Licensed under the MIT License
2407
2407
  function makeUncaughtExceptionHandler(captureFn, onFatalFn) {
2408
2408
  let calledFatalError = false;
2409
2409
  return Object.assign(error => {
@@ -2450,6 +2450,8 @@ function addUnhandledRejectionListener(captureFn) {
2450
2450
  });
2451
2451
  }
2452
2452
 
2453
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2454
+ // Licensed under the MIT License
2453
2455
  function isEvent(candidate) {
2454
2456
  return typeof Event !== 'undefined' && isInstanceOf(candidate, Event);
2455
2457
  }
@@ -2481,6 +2483,8 @@ function isBuiltin(candidate, className) {
2481
2483
  return Object.prototype.toString.call(candidate) === `[object ${className}]`;
2482
2484
  }
2483
2485
 
2486
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2487
+ // Licensed under the MIT License
2484
2488
  /** A simple Least Recently Used map */
2485
2489
  class ReduceableCache {
2486
2490
  constructor(_maxSize) {
@@ -2514,6 +2518,27 @@ class ReduceableCache {
2514
2518
  }
2515
2519
  }
2516
2520
 
2521
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2522
+ const nodeFs = new Lazy(async () => {
2523
+ try {
2524
+ return await import('node:fs');
2525
+ } catch {
2526
+ return undefined;
2527
+ }
2528
+ });
2529
+ async function getNodeFs() {
2530
+ return await nodeFs.getValue();
2531
+ }
2532
+ const nodeReadline = new Lazy(async () => {
2533
+ try {
2534
+ return await import('node:readline');
2535
+ } catch {
2536
+ return undefined;
2537
+ }
2538
+ });
2539
+ async function getNodeReadline() {
2540
+ return await nodeReadline.getValue();
2541
+ }
2517
2542
  const LRU_FILE_CONTENTS_CACHE = new ReduceableCache(25);
2518
2543
  const LRU_FILE_CONTENTS_FS_READ_FAILED = new ReduceableCache(20);
2519
2544
  const DEFAULT_LINES_OF_CONTEXT = 7;
@@ -2581,70 +2606,79 @@ async function addSourceContext(frames) {
2581
2606
  */
2582
2607
  function getContextLinesFromFile(path, ranges, output) {
2583
2608
  return new Promise(resolve => {
2584
- // It is important *not* to have any async code between createInterface and the 'line' event listener
2585
- // as it will cause the 'line' event to
2586
- // be emitted before the listener is attached.
2587
- const stream = createReadStream(path);
2588
- const lineReaded = createInterface({
2589
- input: stream
2590
- });
2591
- // We need to explicitly destroy the stream to prevent memory leaks,
2592
- // removing the listeners on the readline interface is not enough.
2593
- // See: https://github.com/nodejs/node/issues/9002 and https://github.com/getsentry/sentry-javascript/issues/14892
2594
- function destroyStreamAndResolve() {
2595
- stream.destroy();
2596
- resolve();
2597
- }
2598
- // Init at zero and increment at the start of the loop because lines are 1 indexed.
2599
- let lineNumber = 0;
2600
- let currentRangeIndex = 0;
2601
- const range = ranges[currentRangeIndex];
2602
- if (range === undefined) {
2603
- // We should never reach this point, but if we do, we should resolve the promise to prevent it from hanging.
2604
- destroyStreamAndResolve();
2605
- return;
2606
- }
2607
- let rangeStart = range[0];
2608
- let rangeEnd = range[1];
2609
- // We use this inside Promise.all, so we need to resolve the promise even if there is an error
2610
- // to prevent Promise.all from short circuiting the rest.
2611
- function onStreamError() {
2612
- // Mark file path as failed to read and prevent multiple read attempts.
2613
- LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
2614
- lineReaded.close();
2615
- lineReaded.removeAllListeners();
2616
- destroyStreamAndResolve();
2617
- }
2618
- // We need to handle the error event to prevent the process from crashing in < Node 16
2619
- // https://github.com/nodejs/node/pull/31603
2620
- stream.on('error', onStreamError);
2621
- lineReaded.on('error', onStreamError);
2622
- lineReaded.on('close', destroyStreamAndResolve);
2623
- lineReaded.on('line', line => {
2624
- lineNumber++;
2625
- if (lineNumber < rangeStart) {
2609
+ // KLUDGE: edge runtimes do not support node:fs or node:readline
2610
+ // until we have separate packages for each environment this will skip
2611
+ // trying to access the filesystem when not accessible
2612
+ Promise.all([getNodeFs(), getNodeReadline()]).then(([nodeFs, nodeReadline]) => {
2613
+ if (!nodeFs || !nodeReadline) {
2614
+ resolve();
2626
2615
  return;
2627
2616
  }
2628
- // !Warning: This mutates the cache by storing the snipped line into the cache.
2629
- output[lineNumber] = snipLine(line, 0);
2630
- if (lineNumber >= rangeEnd) {
2631
- if (currentRangeIndex === ranges.length - 1) {
2632
- // We need to close the file stream and remove listeners, else the reader will continue to run our listener;
2633
- lineReaded.close();
2634
- lineReaded.removeAllListeners();
2617
+ // It is important *not* to have any async code between createInterface and the 'line' event listener
2618
+ // as it will cause the 'line' event to
2619
+ // be emitted before the listener is attached.
2620
+ const stream = nodeFs.createReadStream(path);
2621
+ const lineReaded = nodeReadline.createInterface({
2622
+ input: stream
2623
+ });
2624
+ // We need to explicitly destroy the stream to prevent memory leaks,
2625
+ // removing the listeners on the readline interface is not enough.
2626
+ // See: https://github.com/nodejs/node/issues/9002 and https://github.com/getsentry/sentry-javascript/issues/14892
2627
+ function destroyStreamAndResolve() {
2628
+ stream.destroy();
2629
+ resolve();
2630
+ }
2631
+ // Init at zero and increment at the start of the loop because lines are 1 indexed.
2632
+ let lineNumber = 0;
2633
+ let currentRangeIndex = 0;
2634
+ const range = ranges[currentRangeIndex];
2635
+ if (range === undefined) {
2636
+ // We should never reach this point, but if we do, we should resolve the promise to prevent it from hanging.
2637
+ destroyStreamAndResolve();
2638
+ return;
2639
+ }
2640
+ let rangeStart = range[0];
2641
+ let rangeEnd = range[1];
2642
+ // We use this inside Promise.all, so we need to resolve the promise even if there is an error
2643
+ // to prevent Promise.all from short circuiting the rest.
2644
+ function onStreamError() {
2645
+ // Mark file path as failed to read and prevent multiple read attempts.
2646
+ LRU_FILE_CONTENTS_FS_READ_FAILED.set(path, 1);
2647
+ lineReaded.close();
2648
+ lineReaded.removeAllListeners();
2649
+ destroyStreamAndResolve();
2650
+ }
2651
+ // We need to handle the error event to prevent the process from crashing in < Node 16
2652
+ // https://github.com/nodejs/node/pull/31603
2653
+ stream.on('error', onStreamError);
2654
+ lineReaded.on('error', onStreamError);
2655
+ lineReaded.on('close', destroyStreamAndResolve);
2656
+ lineReaded.on('line', line => {
2657
+ lineNumber++;
2658
+ if (lineNumber < rangeStart) {
2635
2659
  return;
2636
2660
  }
2637
- currentRangeIndex++;
2638
- const range = ranges[currentRangeIndex];
2639
- if (range === undefined) {
2640
- // This should never happen as it means we have a bug in the context.
2641
- lineReaded.close();
2642
- lineReaded.removeAllListeners();
2643
- return;
2661
+ // !Warning: This mutates the cache by storing the snipped line into the cache.
2662
+ output[lineNumber] = snipLine(line, 0);
2663
+ if (lineNumber >= rangeEnd) {
2664
+ if (currentRangeIndex === ranges.length - 1) {
2665
+ // We need to close the file stream and remove listeners, else the reader will continue to run our listener;
2666
+ lineReaded.close();
2667
+ lineReaded.removeAllListeners();
2668
+ return;
2669
+ }
2670
+ currentRangeIndex++;
2671
+ const range = ranges[currentRangeIndex];
2672
+ if (range === undefined) {
2673
+ // This should never happen as it means we have a bug in the context.
2674
+ lineReaded.close();
2675
+ lineReaded.removeAllListeners();
2676
+ return;
2677
+ }
2678
+ rangeStart = range[0];
2679
+ rangeEnd = range[1];
2644
2680
  }
2645
- rangeStart = range[0];
2646
- rangeEnd = range[1];
2647
- }
2681
+ });
2648
2682
  });
2649
2683
  });
2650
2684
  }
@@ -2835,9 +2869,7 @@ function snipLine(line, colno) {
2835
2869
  return newLine;
2836
2870
  }
2837
2871
 
2838
- /**
2839
- * based on the very wonderful MIT licensed Sentry SDK
2840
- */
2872
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
2841
2873
  async function propertiesFromUnknownInput(stackParser, input, hint) {
2842
2874
  const providedMechanism = hint && hint.mechanism;
2843
2875
  const mechanism = providedMechanism || {
@@ -3025,7 +3057,7 @@ function parseStackFrames(stackParser, error) {
3025
3057
  return stackParser(error.stack || '', 1);
3026
3058
  }
3027
3059
 
3028
- // copied and adapted from https://github.com/getsentry/sentry-javascript/blob/41fef4b10f3a644179b77985f00f8696c908539f/packages/browser/src/stack-parsers.ts
3060
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
3029
3061
  // This was originally forked from https://github.com/csnover/TraceKit, and was largely
3030
3062
  // re-written as part of raven - js.
3031
3063
  //