posthog-node 4.8.0 → 4.8.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
+ # 4.8.1 – 2025-02-26
4
+
5
+ 1. Supports gracefully handling quotaLimited responses from the PostHog API for feature flag evaluation
6
+
3
7
  # 4.8.0 - 2025-02-26
4
8
 
5
9
  1. Add guardrails and exponential error backoff in the feature flag local evaluation poller to prevent high rates of 401/403 traffic towards `/local_evaluation`
package/lib/index.cjs.js CHANGED
@@ -7,7 +7,7 @@ var node_fs = require('node:fs');
7
7
  var node_readline = require('node:readline');
8
8
  var node_path = require('node:path');
9
9
 
10
- var version = "4.8.0";
10
+ var version = "4.8.1";
11
11
 
12
12
  var PostHogPersistedProperty;
13
13
  (function (PostHogPersistedProperty) {
@@ -958,6 +958,11 @@ class PostHogFetchNetworkError extends Error {
958
958
  function isPostHogFetchError(err) {
959
959
  return typeof err === 'object' && (err instanceof PostHogFetchHttpError || err instanceof PostHogFetchNetworkError);
960
960
  }
961
+ var QuotaLimitedFeature;
962
+ (function (QuotaLimitedFeature) {
963
+ QuotaLimitedFeature["FeatureFlags"] = "feature_flags";
964
+ QuotaLimitedFeature["Recordings"] = "recordings";
965
+ })(QuotaLimitedFeature || (QuotaLimitedFeature = {}));
961
966
  class PostHogCoreStateless {
962
967
  constructor(apiKey, options) {
963
968
  this.flushPromise = null;
@@ -1201,6 +1206,14 @@ class PostHogCoreStateless {
1201
1206
  extraPayload['geoip_disable'] = true;
1202
1207
  }
1203
1208
  const decideResponse = await this.getDecide(distinctId, groups, personProperties, groupProperties, extraPayload);
1209
+ // Add check for quota limitation on feature flags
1210
+ if (decideResponse?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
1211
+ console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - feature flags unavailable. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
1212
+ return {
1213
+ flags: undefined,
1214
+ payloads: undefined,
1215
+ };
1216
+ }
1204
1217
  const flags = decideResponse?.featureFlags;
1205
1218
  const payloads = decideResponse?.featureFlagPayloads;
1206
1219
  let parsedPayloads = payloads;
@@ -1757,6 +1770,16 @@ class FeatureFlagsPoller {
1757
1770
  this.authenticationErrorCount += 1;
1758
1771
  throw new ClientError(`Your personal API key does not have permission to fetch feature flag definitions for local evaluation. Setting next polling interval to ${this.getPollingInterval()}ms. Are you sure you're using the correct personal and Project API key pair? More information: https://posthog.com/docs/api/overview`);
1759
1772
  }
1773
+ if (res && res.status === 402) {
1774
+ // Quota limited - clear all flags
1775
+ console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - unsetting all local flags. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
1776
+ this.featureFlags = [];
1777
+ this.featureFlagsByKey = {};
1778
+ this.groupTypeMapping = {};
1779
+ this.cohorts = {};
1780
+ this.loadedSuccessfullyOnce = false;
1781
+ return;
1782
+ }
1760
1783
  if (res && res.status !== 200) {
1761
1784
  // something else went wrong, or the server is down.
1762
1785
  // In this case, don't override existing flags