feat(admin): implement pricing overrides for plans and update pricing logic
This commit is contained in:
@@ -33,7 +33,24 @@ export const planRulesV1Schema = z.object({
|
||||
}),
|
||||
})
|
||||
|
||||
export const planRulesSchema = z.discriminatedUnion('version', [planRulesV1Schema])
|
||||
export const planPriceOverrideSchema = z.object({
|
||||
amount: z.number().nonnegative(),
|
||||
currency: z.string().length(3),
|
||||
})
|
||||
|
||||
export const planRulesV2Schema = planRulesV1Schema.extend({
|
||||
version: z.literal('v2'),
|
||||
pricing: z
|
||||
.object({
|
||||
overrides: z.record(z.string(), planPriceOverrideSchema),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
|
||||
export const planRulesSchema = z.discriminatedUnion('version', [
|
||||
planRulesV1Schema,
|
||||
planRulesV2Schema,
|
||||
])
|
||||
|
||||
export const planSchema = z.object({
|
||||
code: z.string().trim().min(1).max(10),
|
||||
@@ -60,12 +77,14 @@ export const planWithFeaturesSchema = z.object({
|
||||
code: z.string().trim().min(1).max(10),
|
||||
name: z.string().trim().min(1).max(30),
|
||||
price: z.number().nonnegative(),
|
||||
currency: z.string().length(3),
|
||||
features: planFeatureFlagsSchema,
|
||||
limits: planLimitsSchema,
|
||||
})
|
||||
|
||||
export type PlanFeatureFlags = z.infer<typeof planFeatureFlagsSchema>
|
||||
export type PlanRulesV1 = z.infer<typeof planRulesV1Schema>
|
||||
export type PlanRulesV2 = z.infer<typeof planRulesV2Schema>
|
||||
export type PlanRules = z.infer<typeof planRulesSchema>
|
||||
export type Plan = z.infer<typeof planSchema>
|
||||
export type PlanSummary = z.infer<typeof planSummarySchema>
|
||||
|
||||
Reference in New Issue
Block a user