posthog-node 5.1.0 → 5.2.1

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.
@@ -859,7 +859,7 @@ function applyChunkIds(frames, parser) {
859
859
 
860
860
  const SHUTDOWN_TIMEOUT = 2000;
861
861
  class ErrorTracking {
862
- static async captureException(client, error, hint, distinctId, additionalProperties) {
862
+ static async buildEventMessage(error, hint, distinctId, additionalProperties) {
863
863
  const properties = {
864
864
  ...additionalProperties
865
865
  };
@@ -869,14 +869,14 @@ class ErrorTracking {
869
869
  properties.$process_person_profile = false;
870
870
  }
871
871
  const exceptionProperties = await propertiesFromUnknownInput(this.stackParser, this.frameModifiers, error, hint);
872
- client.capture({
872
+ return {
873
873
  event: '$exception',
874
874
  distinctId: distinctId || uuidv7(),
875
875
  properties: {
876
876
  ...exceptionProperties,
877
877
  ...properties
878
878
  }
879
- });
879
+ };
880
880
  }
881
881
  constructor(client, options) {
882
882
  this.client = client;
@@ -890,7 +890,9 @@ class ErrorTracking {
890
890
  }
891
891
  }
892
892
  onException(exception, hint) {
893
- ErrorTracking.captureException(this.client, exception, hint);
893
+ void ErrorTracking.buildEventMessage(exception, hint).then(msg => {
894
+ this.client.capture(msg);
895
+ });
894
896
  }
895
897
  async onFatalError() {
896
898
  await this.client.shutdown(SHUTDOWN_TIMEOUT);
@@ -910,9 +912,9 @@ function setupExpressErrorHandler(_posthog, app) {
910
912
  };
911
913
  // Given stateless nature of Node SDK we capture exceptions using personless processing
912
914
  // when no user can be determined e.g. in the case of exception autocapture
913
- ErrorTracking.captureException(_posthog, error, hint, uuidv7(), {
915
+ ErrorTracking.buildEventMessage(error, hint, uuidv7(), {
914
916
  $process_person_profile: false
915
- });
917
+ }).then(msg => _posthog.capture(msg));
916
918
  next(error);
917
919
  });
918
920
  }
@@ -1318,7 +1320,7 @@ function snipLine(line, colno) {
1318
1320
  return newLine;
1319
1321
  }
1320
1322
 
1321
- var version = "5.1.0";
1323
+ var version = "5.2.1";
1322
1324
 
1323
1325
  var PostHogPersistedProperty;
1324
1326
  (function (PostHogPersistedProperty) {
@@ -1356,6 +1358,12 @@ var Compression;
1356
1358
  })(Compression || (Compression = {}));
1357
1359
  var SurveyPosition;
1358
1360
  (function (SurveyPosition) {
1361
+ SurveyPosition["TopLeft"] = "top_left";
1362
+ SurveyPosition["TopCenter"] = "top_center";
1363
+ SurveyPosition["TopRight"] = "top_right";
1364
+ SurveyPosition["MiddleLeft"] = "middle_left";
1365
+ SurveyPosition["MiddleCenter"] = "middle_center";
1366
+ SurveyPosition["MiddleRight"] = "middle_right";
1359
1367
  SurveyPosition["Left"] = "left";
1360
1368
  SurveyPosition["Right"] = "right";
1361
1369
  SurveyPosition["Center"] = "center";
@@ -3547,7 +3555,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
3547
3555
  return response;
3548
3556
  }
3549
3557
  async getRemoteConfigPayload(flagKey) {
3550
- return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json();
3558
+ const response = await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey);
3559
+ if (!response) {
3560
+ return undefined;
3561
+ }
3562
+ const parsed = await response.json();
3563
+ // The payload from the endpoint is stored as a JSON encoded string. So when we return
3564
+ // it, it's effectively double encoded. As far as we know, we should never get single-encoded
3565
+ // JSON, but we'll be defensive here just in case.
3566
+ if (typeof parsed === 'string') {
3567
+ try {
3568
+ // If the parsed value is a string, try parsing it again to handle double-encoded JSON
3569
+ return JSON.parse(parsed);
3570
+ } catch (e) {
3571
+ // If second parse fails, return the string as is
3572
+ return parsed;
3573
+ }
3574
+ }
3575
+ return parsed;
3551
3576
  }
3552
3577
  async isFeatureEnabled(key, distinctId, options) {
3553
3578
  const feat = await this.getFeatureFlag(key, distinctId, options);
@@ -3645,9 +3670,18 @@ class PostHogBackendClient extends PostHogCoreStateless {
3645
3670
  }
3646
3671
  captureException(error, distinctId, additionalProperties) {
3647
3672
  const syntheticException = new Error('PostHog syntheticException');
3648
- ErrorTracking.captureException(this, error, {
3673
+ ErrorTracking.buildEventMessage(error, {
3674
+ syntheticException
3675
+ }, distinctId, additionalProperties).then(msg => {
3676
+ this.capture(msg);
3677
+ });
3678
+ }
3679
+ async captureExceptionImmediate(error, distinctId, additionalProperties) {
3680
+ const syntheticException = new Error('PostHog syntheticException');
3681
+ const evtMsg = await ErrorTracking.buildEventMessage(error, {
3649
3682
  syntheticException
3650
3683
  }, distinctId, additionalProperties);
3684
+ return await this.captureImmediate(evtMsg);
3651
3685
  }
3652
3686
  }
3653
3687