posthog-node 5.1.0 → 5.1.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,9 @@
1
1
  # Next
2
2
 
3
+ # 5.1.1 - 2025-06-16
4
+
5
+ 1. fix: Handle double-encoded JSON payloads from the remote config endpoint
6
+
3
7
  # 5.1.0 - 2025-06-12
4
8
 
5
9
  1. chore: use `/flags?v=2&config=true` instead of `/decide?v=4` for the flag evaluation backend
@@ -935,7 +935,7 @@ function setupExpressErrorHandler(_posthog, app) {
935
935
  });
936
936
  }
937
937
 
938
- var version = "5.1.0";
938
+ var version = "5.1.1";
939
939
 
940
940
  var PostHogPersistedProperty;
941
941
  (function (PostHogPersistedProperty) {
@@ -3164,7 +3164,24 @@ class PostHogBackendClient extends PostHogCoreStateless {
3164
3164
  return response;
3165
3165
  }
3166
3166
  async getRemoteConfigPayload(flagKey) {
3167
- return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json();
3167
+ const response = await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey);
3168
+ if (!response) {
3169
+ return undefined;
3170
+ }
3171
+ const parsed = await response.json();
3172
+ // The payload from the endpoint is stored as a JSON encoded string. So when we return
3173
+ // it, it's effectively double encoded. As far as we know, we should never get single-encoded
3174
+ // JSON, but we'll be defensive here just in case.
3175
+ if (typeof parsed === 'string') {
3176
+ try {
3177
+ // If the parsed value is a string, try parsing it again to handle double-encoded JSON
3178
+ return JSON.parse(parsed);
3179
+ } catch (e) {
3180
+ // If second parse fails, return the string as is
3181
+ return parsed;
3182
+ }
3183
+ }
3184
+ return parsed;
3168
3185
  }
3169
3186
  async isFeatureEnabled(key, distinctId, options) {
3170
3187
  const feat = await this.getFeatureFlag(key, distinctId, options);