Open axelcedercreutz opened 4 months ago
Hey @axelcedercreutz,
I started to think of a solution for this, as I recently worked on extending the posthog-java
project with feature flags support. I'd like to know what would be the best API from a node developer perspective:
Create a custom type for all the feature flags in a project:
type Flag = 'node-flag-1' | 'node-flag-2' | 'node-flag-3';
Create a FeatureFlag
type, where the key would be an enum
:
enum Flag {
NEW_FEATURE = 'node-new-feature',
EXPERIMENT = 'node-experiment',
EXPERIMENT_WITH_GROUPS = 'node-experiment-with-groups',
EXPERIMENT_WITH_MULTIVARIATE = 'node-experiment-with-multivariate',
}
enum FlagVariants { VARIANT_A = 'node-variant-a', VARIANT_B = 'node-variant-b', VARIANT_C = 'node-variant-c', }
type FeatureFlag = { key: Flag rollout_percentage: number groups: Array<{ properties: Array<{ key: string value: string operator: string }> }> multivariate: { variants: Array<{ key: FlagVariants rollout_percentage: number }> } }
My heart tells me is option number 2, or another option I haven't thought of π
Let me know your thoughts!
Hey @axelcedercreutz ,
Thanks for adding the feature request!
For retrieving a list of feature flag keys and values for a project, have you already checked out the feature flag endpoints for our API?
@miguelhrocha awesome stuff! Personally I'd also lean towards option 2 with a general FeatureFlag
-type that connects the key and values. Not sure how required e.g. the rollout information is (atm at least we don't have a need for that), so a simpler version could be something like
type FeatureFlag = 'node-new-feature' |Β 'node-experiment' |Β 'node-experiment-with-groups' |Β 'node-experiment-with-multivariate'
type NodeNewFeature = boolean;
type NodeExperiment = 'control' | 'new';
interface NodeExperimentWithGroups {
group1: boolean;
group2: 'control' | 'new';
}
interface NodeExperimentWithMultivariate {
foo: 'value';
bar: 'other value';
}
interface FeatureFlags: Record<FeatureFlag, FeatureDefinition> {
'node-new-feature': NodeNewFeature;
'node-experiment': NodeExperiment;
'node-experiment-with-groups': NodeExperimentWithGroups;
'node-experiment-with-multivariate': NodeExperimentWithMultivariate;
}
Not yet sure how to define the suggested FeatureDefinition
yet, but should be doable I think.
@slshults thanks for adding the link to the API documentation. I think writing the script based on the API could definitely be an option for us π However, the feature request is more because I believe that there could be a way supported by Posthog to do the same π
Feature request
Is your feature request related to a problem?
Currently, when using the
posthog-js
orposthog-node
-packages, there's no way for us to know if a specific feature flag key/value is correctly spelled. This can lead to unwanted consequences due to typos and create friction in the development process as developers have to ensure manually.Describe the solution you'd like
We'd love to have a way to have a script for generating the feature flag key/value pairs based on a project. It can be either a CLI tool (like e.g. Supabase does) or even just an endpoint that returns the types in some deconstructable manner.
Describe alternatives you've considered
Haven't figured out any other ways than the current manual process of checking the values from Posthog and replicating the types locally.
Additional context
We have a multi-project setup for two different products + 2 environments for each product. The lack of environment support makes things unfortunately even harder π
Debug info