-
Notifications
You must be signed in to change notification settings - Fork 38
fix: π only need one of amount or flat_amount or both #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,16 +234,35 @@ type PriceWithAmount = PriceBaseFields & { | |
| tiers?: never; | ||
| }; | ||
|
|
||
| // Price with tiered pricing (no flat amount) | ||
| type PriceWithTiers = PriceBaseFields & { | ||
| // Price with graduated tiered pricing (each tier's rate applies only to units within that tier) | ||
| type PriceWithGraduatedTiers = PriceBaseFields & { | ||
| /** Cannot have flat amount when using tiers */ | ||
| amount?: never; | ||
| /** Tiered pricing structure based on usage ranges */ | ||
| /** Graduated tiered pricing: each tier's amount applies only to units within that tier */ | ||
| tiers: Array<{ to: number | "inf"; amount: number }>; | ||
| /** Required when tiers is defined: how tiers are applied */ | ||
| tierBehaviour: "graduated" | "volume"; | ||
| /** Graduated: each tier's rate applies only to usage within that tier */ | ||
| tierBehavior: "graduated"; | ||
| }; | ||
|
|
||
| // Volume tier: at least one of amount or flatAmount must be present | ||
| type VolumeTier = | ||
| | { to: number | "inf"; amount: number; flatAmount?: number } | ||
| | { to: number | "inf"; amount?: number; flatAmount: number }; | ||
|
Comment on lines
+248
to
+250
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Since See the companion issue in Prompt To Fix With AIThis is a comment left during a code review.
Path: typegen/genUtils/atmnTypeHelpers.ts
Line: 248-250
Comment:
The `VolumeTier` type template (lines 248β250) correctly enforces that at least one of `amount` or `flatAmount` must be present. However, the Zod schema that backs runtime validation (`UsageTierSchema` in `planModels.ts` lines 7β10) does not reflect this constraint β it requires `amount` unconditionally and lacks `flatAmount` entirely.
Since `atmnTypeHelpers.ts` is the source template for the TypeScript type portion of `planModels.ts`, the corresponding Zod schema in the generator (`TypeGenerator.ts` line 334) must be updated in parallel to keep types and runtime validation in sync. Without this, consumers will write TypeScript code that passes the type checker but fails at runtime.
See the companion issue in `TypeGenerator.ts` line 334 for the schema update needed.
How can I resolve this? If you propose a fix, please make it concise. |
||
|
|
||
| // Price with volume tiered pricing (the tier the total usage falls into applies to all units) | ||
| type PriceWithVolumeTiers = Omit<PriceBaseFields, "billingMethod"> & { | ||
| /** Volume pricing does not support usage_based billing β use 'prepaid' */ | ||
| billingMethod: Exclude<BillingMethod, "usage_based">; | ||
| /** Cannot have flat amount when using tiers */ | ||
| amount?: never; | ||
| /** Volume tiered pricing: the tier the total usage falls into applies to all units */ | ||
| tiers: Array<VolumeTier>; | ||
| /** Volume: the rate of the tier the total usage falls into applies to all units */ | ||
| tierBehavior: "volume"; | ||
| }; | ||
|
|
||
| type PriceWithTiers = PriceWithGraduatedTiers | PriceWithVolumeTiers; | ||
|
|
||
| // Price must have either amount OR tiers (not both, not neither) | ||
| type PriceAmountOrTiers = PriceWithAmount | PriceWithTiers; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: The new
VolumeTiertype allowsflatAmount-only tiers, but runtime Zod schema still requiresamount, causing type-safe code to fail validation at runtime.Prompt for AI agents