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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Next
2
2
 
3
+ # 5.2.1 - 2025-07-07
4
+
5
+ 1. feat: add captureExceptionImmediate method on posthog client
6
+
7
+ # 5.1.1 - 2025-06-16
8
+
9
+ 1. fix: Handle double-encoded JSON payloads from the remote config endpoint
10
+
3
11
  # 5.1.0 - 2025-06-12
4
12
 
5
13
  1. chore: use `/flags?v=2&config=true` instead of `/decide?v=4` for the flag evaluation backend
@@ -877,7 +877,7 @@ function applyChunkIds(frames, parser) {
877
877
 
878
878
  const SHUTDOWN_TIMEOUT = 2000;
879
879
  class ErrorTracking {
880
- static async captureException(client, error, hint, distinctId, additionalProperties) {
880
+ static async buildEventMessage(error, hint, distinctId, additionalProperties) {
881
881
  const properties = {
882
882
  ...additionalProperties
883
883
  };
@@ -887,14 +887,14 @@ class ErrorTracking {
887
887
  properties.$process_person_profile = false;
888
888
  }
889
889
  const exceptionProperties = await propertiesFromUnknownInput(this.stackParser, this.frameModifiers, error, hint);
890
- client.capture({
890
+ return {
891
891
  event: '$exception',
892
892
  distinctId: distinctId || uuidv7(),
893
893
  properties: {
894
894
  ...exceptionProperties,
895
895
  ...properties
896
896
  }
897
- });
897
+ };
898
898
  }
899
899
  constructor(client, options) {
900
900
  this.client = client;
@@ -908,7 +908,9 @@ class ErrorTracking {
908
908
  }
909
909
  }
910
910
  onException(exception, hint) {
911
- ErrorTracking.captureException(this.client, exception, hint);
911
+ void ErrorTracking.buildEventMessage(exception, hint).then(msg => {
912
+ this.client.capture(msg);
913
+ });
912
914
  }
913
915
  async onFatalError() {
914
916
  await this.client.shutdown(SHUTDOWN_TIMEOUT);
@@ -928,14 +930,14 @@ function setupExpressErrorHandler(_posthog, app) {
928
930
  };
929
931
  // Given stateless nature of Node SDK we capture exceptions using personless processing
930
932
  // when no user can be determined e.g. in the case of exception autocapture
931
- ErrorTracking.captureException(_posthog, error, hint, uuidv7(), {
933
+ ErrorTracking.buildEventMessage(error, hint, uuidv7(), {
932
934
  $process_person_profile: false
933
- });
935
+ }).then(msg => _posthog.capture(msg));
934
936
  next(error);
935
937
  });
936
938
  }
937
939
 
938
- var version = "5.1.0";
940
+ var version = "5.2.1";
939
941
 
940
942
  var PostHogPersistedProperty;
941
943
  (function (PostHogPersistedProperty) {
@@ -973,6 +975,12 @@ var Compression;
973
975
  })(Compression || (Compression = {}));
974
976
  var SurveyPosition;
975
977
  (function (SurveyPosition) {
978
+ SurveyPosition["TopLeft"] = "top_left";
979
+ SurveyPosition["TopCenter"] = "top_center";
980
+ SurveyPosition["TopRight"] = "top_right";
981
+ SurveyPosition["MiddleLeft"] = "middle_left";
982
+ SurveyPosition["MiddleCenter"] = "middle_center";
983
+ SurveyPosition["MiddleRight"] = "middle_right";
976
984
  SurveyPosition["Left"] = "left";
977
985
  SurveyPosition["Right"] = "right";
978
986
  SurveyPosition["Center"] = "center";
@@ -3164,7 +3172,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
3164
3172
  return response;
3165
3173
  }
3166
3174
  async getRemoteConfigPayload(flagKey) {
3167
- return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json();
3175
+ const response = await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey);
3176
+ if (!response) {
3177
+ return undefined;
3178
+ }
3179
+ const parsed = await response.json();
3180
+ // The payload from the endpoint is stored as a JSON encoded string. So when we return
3181
+ // it, it's effectively double encoded. As far as we know, we should never get single-encoded
3182
+ // JSON, but we'll be defensive here just in case.
3183
+ if (typeof parsed === 'string') {
3184
+ try {
3185
+ // If the parsed value is a string, try parsing it again to handle double-encoded JSON
3186
+ return JSON.parse(parsed);
3187
+ } catch (e) {
3188
+ // If second parse fails, return the string as is
3189
+ return parsed;
3190
+ }
3191
+ }
3192
+ return parsed;
3168
3193
  }
3169
3194
  async isFeatureEnabled(key, distinctId, options) {
3170
3195
  const feat = await this.getFeatureFlag(key, distinctId, options);
@@ -3262,9 +3287,18 @@ class PostHogBackendClient extends PostHogCoreStateless {
3262
3287
  }
3263
3288
  captureException(error, distinctId, additionalProperties) {
3264
3289
  const syntheticException = new Error('PostHog syntheticException');
3265
- ErrorTracking.captureException(this, error, {
3290
+ ErrorTracking.buildEventMessage(error, {
3291
+ syntheticException
3292
+ }, distinctId, additionalProperties).then(msg => {
3293
+ this.capture(msg);
3294
+ });
3295
+ }
3296
+ async captureExceptionImmediate(error, distinctId, additionalProperties) {
3297
+ const syntheticException = new Error('PostHog syntheticException');
3298
+ const evtMsg = await ErrorTracking.buildEventMessage(error, {
3266
3299
  syntheticException
3267
3300
  }, distinctId, additionalProperties);
3301
+ return await this.captureImmediate(evtMsg);
3268
3302
  }
3269
3303
  }
3270
3304