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

fix: return flag state after evaluation #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

reinvanhaaren
Copy link

When no percentage or rule is applied during evaluation, return the state of the flag instead of a fixed false.

Problem

When using the getFlag method on the Client class, the flag is evaluated. If no percentage or rules are present on the flag, a fixed false is returned instead of the enabled property of the flag.

Example:

import { Client, type Environment } from "@upstash/edge-flags";

const client = new Client({
  redis: Redis.fromEnv(),
  environment: (process.env.VERCEL_ENV as Environment) ?? "development",
});

const flag = await client.getFlag("flag-name", {});
//      ^ Returns false if no percentage or rules are defined

Solution

Return flag.enabled instead of false at the end of the evaluation.

When no percentage or rule is applied during evaluation, return the state of the flag instead of a fixed false.
Copy link

vercel bot commented Mar 2, 2024

@reinvanhaaren is attempting to deploy a commit to the Upstash Team on Vercel.

A member of the Team first needs to authorize it.

@reinvanhaaren
Copy link
Author

@chronark hi Andreas. Is it possible to take a look at my pull request? I think many will benefit from this small change.

@chronark
Copy link
Contributor

chronark commented Mar 15, 2024

I no longer work for Upstash but it looks good

cc @enesakar

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.

None yet

2 participants