diff --git a/packages/backend-core/src/features/features.ts b/packages/backend-core/src/features/features.ts index b3f016e88a..650254fcb2 100644 --- a/packages/backend-core/src/features/features.ts +++ b/packages/backend-core/src/features/features.ts @@ -266,12 +266,14 @@ export class FlagSet, T extends { [key: string]: V }> { // new flag, add it here and use the `fetch` and `get` functions to access it. // All of the machinery in this file is to make sure that flags have their // default values set correctly and their types flow through the system. -export const flags = new FlagSet({ +const flagsConfig: Record> = { [FeatureFlag.DEFAULT_VALUES]: Flag.boolean(true), [FeatureFlag.AUTOMATION_BRANCHING]: Flag.boolean(true), [FeatureFlag.AI_CUSTOM_CONFIGS]: Flag.boolean(true), [FeatureFlag.BUDIBASE_AI]: Flag.boolean(true), -}) + [FeatureFlag.USE_ZOD_VALIDATOR]: Flag.boolean(env.isDev()), +} +export const flags = new FlagSet(flagsConfig) type UnwrapPromise = T extends Promise ? U : T export type FeatureFlags = UnwrapPromise> diff --git a/packages/server/src/middleware/zod-validator.ts b/packages/server/src/middleware/zod-validator.ts index 0ad346afc3..e8cc2c470a 100644 --- a/packages/server/src/middleware/zod-validator.ts +++ b/packages/server/src/middleware/zod-validator.ts @@ -1,11 +1,16 @@ -import { Ctx } from "@budibase/types" +import { features } from "@budibase/backend-core" +import { Ctx, FeatureFlag } from "@budibase/types" import { AnyZodObject } from "zod" import { fromZodError } from "zod-validation-error" function validate(schema: AnyZodObject, property: "body" | "params") { // Return a Koa middleware function - return (ctx: Ctx, next: any) => { + return async (ctx: Ctx, next: any) => { + if (!(await features.flags.isEnabled(FeatureFlag.USE_ZOD_VALIDATOR))) { + return next() + } + if (!schema) { return next() } diff --git a/packages/types/src/sdk/featureFlag.ts b/packages/types/src/sdk/featureFlag.ts index 64a7362e9f..98e744324c 100644 --- a/packages/types/src/sdk/featureFlag.ts +++ b/packages/types/src/sdk/featureFlag.ts @@ -1,11 +1,9 @@ export enum FeatureFlag { - PER_CREATOR_PER_USER_PRICE = "PER_CREATOR_PER_USER_PRICE", - PER_CREATOR_PER_USER_PRICE_ALERT = "PER_CREATOR_PER_USER_PRICE_ALERT", AUTOMATION_BRANCHING = "AUTOMATION_BRANCHING", AI_CUSTOM_CONFIGS = "AI_CUSTOM_CONFIGS", DEFAULT_VALUES = "DEFAULT_VALUES", - BUDIBASE_AI = "BUDIBASE_AI", + USE_ZOD_VALIDATOR = "USE_ZOD_VALIDATOR", } export interface TenantFeatureFlags {