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

Add a way to check feature flags with some type-safety #2704

Open
3 tasks done
ogzhanolguncu opened this issue Dec 4, 2024 · 2 comments
Open
3 tasks done

Add a way to check feature flags with some type-safety #2704

ogzhanolguncu opened this issue Dec 4, 2024 · 2 comments
Assignees
Labels
Feature New feature or request

Comments

@ogzhanolguncu
Copy link
Contributor

Preliminary Checks

Is your feature request related to a problem? Please describe.

Developers need to modify the database for feature flags during local development, which creates unnecessary friction. A type-safe checkFlag function could bypass this requirement in development mode while maintaining proper flag checking in production.

Example:

  if (!workspace.betaFeatures.logsPage) {
    return notFound();
  }

Describe the solution

We could create a checkFlag function that takes two parameters: a feature flag name and a workspace object. This would provide several things:

  1. Type safety - by using a type like:
type ConfigObject = Extract<typeof workspaces['betaFeatures']['default'], {
   rbac?: boolean;
   ratelimit?: boolean; 
   identities?: boolean;
   logsPage?: boolean;
}>;
  1. Easy bypassing of feature flags in development:
function checkFlag<T extends keyof ConfigObject>(
    flagName: T, 
    workspace
): boolean {
    if (process.env.NODE_ENV === "development") {
        return true
    }
    // Normal flag checking logic...
}

This pattern would help ensure we're only checking for flags that actually exist in our configuration, while making it simple to enable all features in development environments.

Describe alternatives you have considered (if any)

No response

Additional context

No response

@ogzhanolguncu ogzhanolguncu added Feature New feature or request Needs Approval Needs approval from Unkey labels Dec 4, 2024
Copy link

linear bot commented Dec 4, 2024

@chronark
Copy link
Collaborator

chronark commented Dec 4, 2024

bro just submit the PR instead of coding in issues :D

@chronark chronark removed the Needs Approval Needs approval from Unkey label Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants