diff --git a/packages/taco/src/conditions/schemas/if-then-else.ts b/packages/taco/src/conditions/schemas/if-then-else.ts index cbe35fc5..dc90ee99 100644 --- a/packages/taco/src/conditions/schemas/if-then-else.ts +++ b/packages/taco/src/conditions/schemas/if-then-else.ts @@ -18,9 +18,32 @@ export const ifThenElseConditionSchema: z.ZodSchema = z.lazy(() => elseCondition: z.union([anyConditionSchema, z.boolean()]), }) .refine( - (condition) => maxNestedDepth(2)(condition), + // already at 2nd level since checking member condition + (condition) => maxNestedDepth(2)(condition.ifCondition, 2), { message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['ifCondition'], + }, // Max nested depth of 2 + ) + .refine( + // already at 2nd level since checking member condition + (condition) => maxNestedDepth(2)(condition.thenCondition, 2), + { + message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['thenCondition'], + }, // Max nested depth of 2 + ) + .refine( + (condition) => { + if (typeof condition.elseCondition !== 'boolean') { + // already at 2nd level since checking member condition + return maxNestedDepth(2)(condition.elseCondition, 2); + } + return true; + }, + { + message: 'Exceeded max nested depth of 2 for multi-condition type', + path: ['elseCondition'], }, // Max nested depth of 2 ), );