Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feature-flags): support quota limiting for feature flags #403

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dmarticus
Copy link
Contributor

@dmarticus dmarticus commented Feb 21, 2025

with this PR, we now start to respond different with the /decide and /local_evaluation APIs if users have gone over their quota limit. Now we need to change the SDKs to handle these new responses.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds quota limiting support for feature flags in the PostHog JS Lite library, handling scenarios where users exceed their API usage limits.

  • Added quotaLimited property to PostHogDecideResponse type in posthog-core/src/types.ts to track which features are quota-limited
  • Implemented handling of 402 status codes in posthog-node/src/feature-flags.ts to clear all local flags when quota is exceeded
  • Added test coverage in posthog-core/test/posthog.featureflags.spec.ts to verify feature flags return undefined when quotaLimited includes 'feature_flags'
  • Modified apiImplementation in posthog-node/test/test-utils.ts to support simulating quota limit responses with localFlagsStatus parameter

6 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link

github-actions bot commented Feb 21, 2025

Size Change: +992 B (+0.76%)

Total Size: 132 kB

Filename Size Change
posthog-node/lib/index.cjs.js 31.2 kB +202 B (+0.65%)
posthog-node/lib/index.esm.js 31.2 kB +202 B (+0.65%)
posthog-react-native/lib/posthog-core/src/index.js 10.5 kB +152 B (+1.47%)
posthog-web/lib/index.cjs.js 18.5 kB +218 B (+1.19%)
posthog-web/lib/index.esm.js 18.5 kB +218 B (+1.19%)
ℹ️ View Unchanged
Filename Size
posthog-react-native/lib/posthog-core/src/eventemitter.js 1.08 kB
posthog-react-native/lib/posthog-core/src/lz-string.js 1.42 kB
posthog-react-native/lib/posthog-core/src/types.js 420 B
posthog-react-native/lib/posthog-core/src/utils.js 901 B
posthog-react-native/lib/posthog-core/src/vendor/uuidv7.js 2.04 kB
posthog-react-native/lib/posthog-react-native/index.js 454 B
posthog-react-native/lib/posthog-react-native/src/autocapture.js 1.8 kB
posthog-react-native/lib/posthog-react-native/src/frameworks/wix-navigation.js 505 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlag.js 437 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlags.js 362 B
posthog-react-native/lib/posthog-react-native/src/hooks/useNavigationTracker.js 628 B
posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog.js 249 B
posthog-react-native/lib/posthog-react-native/src/legacy.js 810 B
posthog-react-native/lib/posthog-react-native/src/native-deps.js 1.31 kB
posthog-react-native/lib/posthog-react-native/src/optional/OptionalAsyncStorage.js 183 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoApplication.js 215 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoDevice.js 211 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.js 224 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoLocalization.js 216 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.js 220 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeLocalize.js 169 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigation.js 218 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.js 222 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalSessionReplay.js 231 B
posthog-react-native/lib/posthog-react-native/src/posthog-rn.js 4.46 kB
posthog-react-native/lib/posthog-react-native/src/PostHogContext.js 210 B
posthog-react-native/lib/posthog-react-native/src/PostHogProvider.js 1.74 kB
posthog-react-native/lib/posthog-react-native/src/storage.js 1.09 kB
posthog-react-native/lib/posthog-react-native/src/types.js 90 B
posthog-react-native/lib/posthog-react-native/src/version.js 123 B

compressed-size-action

@@ -1225,7 +1249,7 @@ export abstract class PostHogCore extends PostHogCoreStateless {
return this._decideResponsePromise
}

private setKnownFeatureFlags(featureFlags: PostHogDecideResponse['featureFlags']): void {
private setKnownFeatureFlags(featureFlags: PostHogDecideResponse['featureFlags'] | null): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this and setKnownFeatureFlagPayloads accept null now, we can change the other places from:

this.setKnownFeatureFlags({})
this.setKnownFeatureFlagPayloads({})

to null values as well.

Copy link
Member

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a comment but otherwise LGTM

@marandaneto
Copy link
Member

before merging, lets figure this out PostHog/posthog-android#228 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants