feat(medusa): Add feature flags to store response (#1819)
**What** - Add `feature_flags` string array to store response **Why** - to provide conditional ui in admin corresponding to enabled features Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Oliver Windall Juhl
parent
02967f95b1
commit
3e197e3adf
@@ -0,0 +1,30 @@
|
||||
import { FlagRouter } from "../flag-router"
|
||||
|
||||
describe("Flag Router", () => {
|
||||
describe("listFlags", () => {
|
||||
it("should list all feature flags", () => {
|
||||
const flagRouter = new FlagRouter({})
|
||||
|
||||
flagRouter.setFlag("test", false)
|
||||
flagRouter.setFlag("test2", true)
|
||||
flagRouter.setFlag("test3", false)
|
||||
|
||||
const listOfFlags = flagRouter.listFlags()
|
||||
|
||||
expect(listOfFlags).toEqual([
|
||||
{
|
||||
key: "test",
|
||||
value: false,
|
||||
},
|
||||
{
|
||||
key: "test2",
|
||||
value: true,
|
||||
},
|
||||
{
|
||||
key: "test3",
|
||||
value: false,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IFlagRouter } from "../types/feature-flags"
|
||||
import { FeatureFlagsResponse, IFlagRouter } from "../types/feature-flags"
|
||||
|
||||
export class FlagRouter implements IFlagRouter {
|
||||
private flags: Record<string, boolean> = {}
|
||||
@@ -14,4 +14,11 @@ export class FlagRouter implements IFlagRouter {
|
||||
public setFlag(key: string, value = true): void {
|
||||
this.flags[key] = value
|
||||
}
|
||||
|
||||
public listFlags(): FeatureFlagsResponse {
|
||||
return Object.entries(this.flags || {}).map(([key, value]) => ({
|
||||
key,
|
||||
value,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user