edge-flags icon indicating copy to clipboard operation
edge-flags copied to clipboard

fix: return flag state after evaluation

Open reinvanhaaren opened this issue 1 year ago • 3 comments

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.

reinvanhaaren avatar Mar 02 '24 07:03 reinvanhaaren

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

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 02 '24 07:03 vercel[bot]

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

reinvanhaaren avatar Mar 14 '24 20:03 reinvanhaaren

I no longer work for Upstash but it looks good

cc @enesakar

chronark avatar Mar 15 '24 11:03 chronark

Hey @reinvanhaaren, sorry about missing your PR in this repo. Thanks a lot for the contribution 🙏

ytkimirti avatar Jun 26 '24 15:06 ytkimirti