Skip to content

Commit 2a203cc

Browse files
committed
feat: add flag catalog introspection utilities for UI rendering
1 parent 2366b21 commit 2a203cc

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

apps/webapp/app/v3/featureFlags.server.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,34 @@ export function validatePartialFeatureFlags(values: Record<string, unknown>) {
162162
return FeatureFlagCatalogSchema.partial().safeParse(values);
163163
}
164164

165+
// Utility types for catalog-driven UI rendering
166+
export type FlagControlType =
167+
| { type: "boolean" }
168+
| { type: "enum"; options: string[] }
169+
| { type: "string" };
170+
171+
export function getFlagControlType(schema: z.ZodTypeAny): FlagControlType {
172+
const typeName = schema._def.typeName;
173+
174+
if (typeName === "ZodBoolean") {
175+
return { type: "boolean" };
176+
}
177+
178+
if (typeName === "ZodEnum") {
179+
return { type: "enum", options: schema._def.values as string[] };
180+
}
181+
182+
return { type: "string" };
183+
}
184+
185+
export function getAllFlagControlTypes(): Record<string, FlagControlType> {
186+
const result: Record<string, FlagControlType> = {};
187+
for (const [key, schema] of Object.entries(FeatureFlagCatalog)) {
188+
result[key] = getFlagControlType(schema);
189+
}
190+
return result;
191+
}
192+
165193
// Utility function to set multiple feature flags at once
166194
export function makeSetMultipleFlags(_prisma: PrismaClientOrTransaction = prisma) {
167195
return async function setMultipleFlags(

0 commit comments

Comments
 (0)