1
0
Fork 0
mirror of synced 2024-07-02 21:10:43 +12:00

Quick PR comments.

This commit is contained in:
mike12345567 2023-08-17 17:44:59 +01:00
parent 4c6c0f3002
commit ba5e390b3f
6 changed files with 30 additions and 36 deletions

View file

@ -1,5 +1,6 @@
import env from "../environment"
import * as context from "../context"
export * from "./installation"
/**
* Read the TENANT_FEATURE_FLAGS env var and return an array of features flags for each tenant.

View file

@ -0,0 +1,17 @@
export function processFeatureEnvVar<T>(
fullList: string[],
featureList?: string
) {
let list
if (!featureList) {
list = fullList
} else {
list = featureList.split(",")
}
for (let feature of list) {
if (!fullList.includes(feature)) {
throw new Error(`Feature: ${feature} is not an allowed option`)
}
}
return list as unknown as T[]
}

View file

@ -6,7 +6,8 @@ export * as roles from "./security/roles"
export * as permissions from "./security/permissions"
export * as accounts from "./accounts"
export * as installation from "./installation"
export * as featureFlags from "./featureFlags"
export * as featureFlags from "./features"
export * as features from "./features/installation"
export * as sessions from "./security/sessions"
export * as platform from "./platform"
export * as auth from "./auth"

View file

@ -1,3 +1,4 @@
import { features } from "@budibase/backend-core"
import env from "./environment"
enum AppFeature {
@ -5,23 +6,10 @@ enum AppFeature {
AUTOMATIONS = "automations",
}
const featureList = processFeatureList()
function processFeatureList() {
const fullList = Object.values(AppFeature) as string[]
let list
if (!env.APP_FEATURES) {
list = fullList
} else {
list = env.APP_FEATURES.split(",")
}
for (let feature of list) {
if (!fullList.includes(feature)) {
throw new Error(`Feature: ${feature} is not an allowed option`)
}
}
return list
}
const featureList = features.processFeatureEnvVar<AppFeature>(
Object.keys(AppFeature),
env.APP_FEATURES
)
export function isFeatureEnabled(feature: AppFeature) {
return featureList.includes(feature)

View file

@ -1,25 +1,12 @@
import { features } from "@budibase/backend-core"
import env from "./environment"
enum WorkerFeature {}
const featureList: WorkerFeature[] = processFeatureList()
function processFeatureList() {
const fullList = Object.values(WorkerFeature) as string[]
let list
if (!env.WORKER_FEATURES) {
list = fullList
} else {
list = env.WORKER_FEATURES.split(",")
}
for (let feature of list) {
if (!fullList.includes(feature)) {
throw new Error(`Feature: ${feature} is not an allowed option`)
}
}
// casting ok - confirmed definitely is a list of worker features
return list as unknown as WorkerFeature[]
}
const featureList: WorkerFeature[] = features.processFeatureEnvVar(
Object.values(WorkerFeature),
env.WORKER_FEATURES
)
export function isFeatureEnabled(feature: WorkerFeature) {
return featureList.includes(feature)