Files
cfw-autumn/shared/models/featureModels/featureModels.ts
John Yeo 272e61c712 refactor: migrate event names from config.filters to top-level field
This refactors the Feature data model to use a top-level `event_names`
array field instead of the nested `config.filters[0].value` structure.

**Backend Changes:**
- Updated event routing logic in eventRouter.ts to use event_names
- Updated analytics endpoints to check event_names field
- Simplified validateMeteredConfig to remove filters initialization
- Updated feature create/update handlers to handle event_names

**Frontend Changes:**
- Refactored FeatureConfig component to manage event_names directly
- Simplified FilterInput component to work with string array
- Updated CreateFeature and UpdateFeature to send event_names
- Updated analytics views and tables to display event_names

**Database:**
- event_names column already exists in features table

This is a critical change for billing/usage tracking. All event mapping
logic has been carefully preserved to ensure no disruption to existing
functionality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 15:03:08 +01:00

44 lines
998 B
TypeScript

import { z } from "zod/v4";
import { AppEnv } from "../genModels/genEnums.js";
import { FeatureType } from "./featureEnums.js";
export const FeatureSchema = z.object({
internal_id: z.string(),
org_id: z.string(),
created_at: z.number(),
env: z.nativeEnum(AppEnv),
id: z.string().nonempty(),
name: z.string().nonempty(),
type: z.nativeEnum(FeatureType),
config: z.any(),
display: z
.object({
singular: z.string().optional(),
plural: z.string().optional(),
})
.nullish(),
archived: z.boolean(),
event_names: z.array(z.string()).default([]),
});
export const CreateFeatureSchema = FeatureSchema.pick({
id: true,
name: true,
type: true,
config: true,
display: true,
event_names: true,
});
export const MinFeatureSchema = z.object({
internal_id: z.string(),
id: z.string(),
name: z.string(),
type: z.nativeEnum(FeatureType),
config: z.any(),
});
export type Feature = z.infer<typeof FeatureSchema>;
export type CreateFeature = z.infer<typeof CreateFeatureSchema>;