Files
medusa-store/www/apps/docs/content/references/services/classes/FlagRouter.mdx
github-actions[bot] cdd42dbdcd chore(docs): Generated References (#5743)
Generated the following references:
- `entities`
- `inventory`
- `js-client`
- `pricing`
- `product`
- `services`
- `stock-location`
- `workflows`

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <27354907+shahednasser@users.noreply.github.com>
2023-11-27 18:58:52 +00:00

163 lines
3.1 KiB
Plaintext

---
displayed_sidebar: servicesSidebar
---
import ParameterTypes from "@site/src/components/ParameterTypes"
# FlagRouter
## Implements
- [IFlagRouter](../interfaces/IFlagRouter.mdx)
## Constructors
#### constructor
`**new FlagRouter**(flags)`
##### Parameters
<ParameterTypes parameters={[
{
"name": "flags",
"type": "`Record<string, boolean \\| Record&#60;string, boolean&#62;>`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Properties
<ParameterTypes parameters={[
{
"name": "flags",
"type": "`any`",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
## Methods
#### isFeatureEnabled
`**isFeatureEnabled**(flag): boolean`
Check if a feature flag is enabled.
There are two ways of using this method:
1. `isFeatureEnabled("myFeatureFlag")`
2. `isFeatureEnabled({ myNestedFeatureFlag: "someNestedFlag" })`
We use 1. for top-level feature flags and 2. for nested feature flags. Almost all flags are top-level.
An example of a nested flag is workflows. To use it, you would do:
`isFeatureEnabled({ workflows: Workflows.CreateCart })`
##### Parameters
<ParameterTypes parameters={[
{
"name": "flag",
"type": "`string` \\| `Record<string, string>`",
"description": "The flag to check",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
`boolean`
<ParameterTypes parameters={[
{
"name": "boolean",
"type": "`boolean`",
"optional": true,
"defaultValue": "",
"description": "- Whether the flag is enabled or not",
"expandable": false,
"children": []
}
]} />
___
#### listFlags
`**listFlags**(): [FeatureFlagsResponse](../types/FeatureFlagsResponse.mdx)`
##### Returns
[FeatureFlagsResponse](../types/FeatureFlagsResponse.mdx)
<ParameterTypes parameters={[
{
"name": "FeatureFlagsResponse",
"type": "``{ key: string ; value: boolean \\| Record&#60;string, boolean&#62; }``[]",
"description": "",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
___
#### setFlag
`**setFlag**(key, value): void`
Sets a feature flag.
Flags take two shapes:
`setFlag("myFeatureFlag", true)`
`setFlag("myFeatureFlag", { nestedFlag: true })`
These shapes are used for top-level and nested flags respectively, as explained in isFeatureEnabled.
##### Parameters
<ParameterTypes parameters={[
{
"name": "key",
"type": "`string`",
"description": "The key of the flag to set.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
},
{
"name": "value",
"type": "`boolean` \\| ``{ [key: string]: boolean; }``",
"description": "The value of the flag to set.",
"optional": false,
"defaultValue": "",
"expandable": false,
"children": []
}
]} />
##### Returns
`void`
<ParameterTypes parameters={[
{
"name": "void",
"type": "`void`",
"optional": true,
"defaultValue": "",
"description": "- void",
"expandable": false,
"children": []
}
]} />