posthog-node 4.17.2 → 4.18.0

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Next
2
2
 
3
+ ## Added
4
+
5
+ 1. rotate session id if expired after 24 hours
6
+
3
7
  # 4.17.2 - 2025-05-22
4
8
 
5
9
  1. chore: improve event prop types
@@ -589,6 +589,47 @@ function addUnhandledRejectionListener(captureFn) {
589
589
  });
590
590
  }
591
591
 
592
+ // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
593
+ // Licensed under the MIT License
594
+ let parsedStackResults;
595
+ let lastKeysCount;
596
+ let cachedFilenameChunkIds;
597
+ function getFilenameToChunkIdMap(stackParser) {
598
+ const chunkIdMap = globalThis._posthogChunkIds;
599
+ if (!chunkIdMap) {
600
+ console.error('No chunk id map found');
601
+ return {};
602
+ }
603
+ const chunkIdKeys = Object.keys(chunkIdMap);
604
+ if (cachedFilenameChunkIds && chunkIdKeys.length === lastKeysCount) {
605
+ return cachedFilenameChunkIds;
606
+ }
607
+ lastKeysCount = chunkIdKeys.length;
608
+ cachedFilenameChunkIds = chunkIdKeys.reduce((acc, stackKey) => {
609
+ if (!parsedStackResults) {
610
+ parsedStackResults = {};
611
+ }
612
+ const result = parsedStackResults[stackKey];
613
+ if (result) {
614
+ acc[result[0]] = result[1];
615
+ } else {
616
+ const parsedStack = stackParser(stackKey);
617
+ for (let i = parsedStack.length - 1; i >= 0; i--) {
618
+ const stackFrame = parsedStack[i];
619
+ const filename = stackFrame?.filename;
620
+ const chunkId = chunkIdMap[stackKey];
621
+ if (filename && chunkId) {
622
+ acc[filename] = chunkId;
623
+ parsedStackResults[stackKey] = [filename, chunkId];
624
+ break;
625
+ }
626
+ }
627
+ }
628
+ return acc;
629
+ }, {});
630
+ return cachedFilenameChunkIds;
631
+ }
632
+
592
633
  // Portions of this file are derived from getsentry/sentry-javascript by Software, Inc. dba Sentry
593
634
  // Licensed under the MIT License
594
635
  function isEvent(candidate) {
@@ -822,7 +863,16 @@ async function exceptionFromError(stackParser, frameModifiers, error) {
822
863
  * Extracts stack frames from the error.stack string
823
864
  */
824
865
  function parseStackFrames(stackParser, error) {
825
- return stackParser(error.stack || '', 1);
866
+ return applyChunkIds(stackParser(error.stack || '', 1), stackParser);
867
+ }
868
+ function applyChunkIds(frames, parser) {
869
+ const filenameChunkIdMap = getFilenameToChunkIdMap(parser);
870
+ frames.forEach(frame => {
871
+ if (frame.filename) {
872
+ frame.chunk_id = filenameChunkIdMap[frame.filename];
873
+ }
874
+ });
875
+ return frames;
826
876
  }
827
877
 
828
878
  const SHUTDOWN_TIMEOUT = 2000;
@@ -885,7 +935,7 @@ function setupExpressErrorHandler(_posthog, app) {
885
935
  });
886
936
  }
887
937
 
888
- var version = "4.17.2";
938
+ var version = "4.18.0";
889
939
 
890
940
  var PostHogPersistedProperty;
891
941
  (function (PostHogPersistedProperty) {
@@ -902,6 +952,7 @@ var PostHogPersistedProperty;
902
952
  PostHogPersistedProperty["Queue"] = "queue";
903
953
  PostHogPersistedProperty["OptedOut"] = "opted_out";
904
954
  PostHogPersistedProperty["SessionId"] = "session_id";
955
+ PostHogPersistedProperty["SessionStartTimestamp"] = "session_start_timestamp";
905
956
  PostHogPersistedProperty["SessionLastTimestamp"] = "session_timestamp";
906
957
  PostHogPersistedProperty["PersonProperties"] = "person_properties";
907
958
  PostHogPersistedProperty["GroupProperties"] = "group_properties";