fix: renamed tier_behaviour to tier_behavior
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { BillingMethod } from "@api/products/components/billingMethod";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsageTierSchema,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { z } from "zod/v4";
|
||||
@@ -42,8 +42,9 @@ export const ApiBalanceBreakdownPriceSchema = z.object({
|
||||
tiers: z.array(UsageTierSchema).optional().meta({
|
||||
description: "Tiered pricing configuration if applicable.",
|
||||
}),
|
||||
tier_behaviour: z.enum(TierBehaviours).optional().meta({
|
||||
description: "How tiers are applied: graduated (split across bands) or volume (flat rate for the matched tier).",
|
||||
tier_behavior: z.enum(TierBehavior).optional().meta({
|
||||
description:
|
||||
"How tiers are applied: graduated (split across bands) or volume (flat rate for the matched tier).",
|
||||
}),
|
||||
billing_units: z.number().meta({
|
||||
description:
|
||||
|
||||
@@ -5,7 +5,7 @@ import { RolloverExpiryDurationType } from "@models/productModels/durationTypes/
|
||||
import { BillingInterval } from "@models/productModels/intervals/billingInterval.js";
|
||||
import { ResetInterval } from "@models/productModels/intervals/resetInterval.js";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsageTierSchema,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import {
|
||||
@@ -94,7 +94,7 @@ export const ApiPlanItemV1Schema = z
|
||||
description:
|
||||
"Tiered pricing configuration. Each tier's 'up_to' does NOT include the included amount. Either 'tiers' or 'amount' is required.",
|
||||
}),
|
||||
tier_behaviour: z.enum(TierBehaviours).optional(),
|
||||
tier_behavior: z.enum(TierBehavior).optional(),
|
||||
|
||||
interval: z.enum(BillingInterval).meta({
|
||||
description:
|
||||
|
||||
@@ -3,7 +3,7 @@ import { RolloverExpiryDurationType } from "@models/productModels/durationTypes/
|
||||
import { BillingInterval } from "@models/productModels/intervals/billingInterval";
|
||||
import { ResetInterval } from "@models/productModels/intervals/resetInterval";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsageTierSchema,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
|
||||
@@ -52,7 +52,7 @@ export const CreatePlanItemParamsV1Schema = z
|
||||
description:
|
||||
"Tiered pricing. Each tier's 'to' does NOT include included amount. Either 'amount' or 'tiers' is required.",
|
||||
}),
|
||||
tier_behaviour: z.enum(TierBehaviours).optional(),
|
||||
tier_behavior: z.enum(TierBehavior).optional(),
|
||||
|
||||
interval: z.enum(BillingInterval).meta({
|
||||
description:
|
||||
|
||||
@@ -41,7 +41,7 @@ export function planItemParamsV1ToPlanItemV0({
|
||||
? {
|
||||
amount: item.price.amount,
|
||||
tiers: item.price.tiers,
|
||||
tier_behaviour: item.price.tier_behaviour,
|
||||
tier_behavior: item.price.tier_behavior,
|
||||
interval: item.price.interval,
|
||||
interval_count: item.price.interval_count,
|
||||
billing_units: item.price.billing_units ?? 1,
|
||||
|
||||
@@ -146,7 +146,7 @@ export const planItemV0ToProductItem = ({
|
||||
amount: tier.amount,
|
||||
to: tier.to,
|
||||
})),
|
||||
tier_behaviour: planItem.price?.tier_behaviour,
|
||||
tier_behavior: planItem.price?.tier_behavior,
|
||||
|
||||
usage_model: planItem.price?.usage_model,
|
||||
billing_units: planItem.price?.billing_units,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { CreatePlanItemParamsV1 } from "@api/models";
|
||||
import { billingMethodToUsageModel } from "@api/products/components/mappers/billingMethodTousageModel";
|
||||
import type { ApiPlanItemV0 } from "@api/products/items/previousVersions/apiPlanItemV0";
|
||||
import { TierBehaviours } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { TierBehavior } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { featureUtils } from "@utils/featureUtils/index";
|
||||
import type { SharedContext } from "../../../../types/sharedContext";
|
||||
import type { ApiPlanItemV1 } from "../apiPlanItemV1";
|
||||
@@ -38,9 +38,9 @@ export function planItemV1ToV0({
|
||||
? {
|
||||
amount: price.amount,
|
||||
tiers: price.tiers,
|
||||
tier_behaviour: price.tiers?.length
|
||||
? (price.tier_behaviour ?? TierBehaviours.Graduated)
|
||||
: undefined,
|
||||
tier_behavior: price.tiers?.length
|
||||
? (price.tier_behavior ?? TierBehavior.Graduated)
|
||||
: undefined,
|
||||
interval: price.interval,
|
||||
interval_count: price.interval_count,
|
||||
billing_units: billingUnits,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { RolloverExpiryDurationType } from "@models/productModels/durationTypes/
|
||||
import { BillingInterval } from "@models/productModels/intervals/billingInterval.js";
|
||||
import { ResetInterval } from "@models/productModels/intervals/resetInterval.js";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsageTierSchema,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import {
|
||||
@@ -34,7 +34,7 @@ export const ApiPlanItemV0Schema = z
|
||||
.object({
|
||||
amount: z.number().optional(),
|
||||
tiers: z.array(UsageTierSchema).optional(),
|
||||
tier_behaviour: z.enum(TierBehaviours).optional(),
|
||||
tier_behavior: z.enum(TierBehavior).optional(),
|
||||
|
||||
interval: z.enum(BillingInterval),
|
||||
interval_count: z.number().optional(),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ApiFeatureV0Schema } from "@api/features/prevVersions/apiFeatureV0.js";
|
||||
import { ProductItemInterval } from "@models/productModels/intervals/productItemInterval.js";
|
||||
import { TierBehavior } from "@models/productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import { Infinite } from "@models/productModels/productEnums.js";
|
||||
import { TierBehaviours } from "@models/productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import {
|
||||
OnDecrease,
|
||||
OnIncrease,
|
||||
@@ -64,7 +64,7 @@ export const ApiProductItemV0Schema = z
|
||||
"Tiered pricing for the product item. Not applicable for fixed price items.",
|
||||
}),
|
||||
|
||||
tier_behaviour: z.enum(TierBehaviours).nullish().meta({
|
||||
tier_behavior: z.enum(TierBehavior).nullish().meta({
|
||||
description:
|
||||
"How tiers are applied: graduated (split across bands) or volume (flat rate for the matched tier). Defaults to graduated.",
|
||||
}),
|
||||
|
||||
@@ -8,7 +8,7 @@ export enum BillWhen {
|
||||
EndOfPeriod = "end_of_period",
|
||||
}
|
||||
|
||||
export enum TierBehaviours {
|
||||
export enum TierBehavior {
|
||||
Graduated = "graduated",
|
||||
VolumeBased = "volume",
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "../../productV2Models/productItemModels/productItemEnums.js";
|
||||
import { FixedPriceConfigSchema } from "./priceConfig/fixedPriceConfig.js";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsagePriceConfigSchema,
|
||||
} from "./priceConfig/usagePriceConfig.js";
|
||||
import { BillingType } from "./priceEnums.js";
|
||||
@@ -22,7 +22,7 @@ export const PriceSchema = z.object({
|
||||
org_id: z.string().optional(),
|
||||
created_at: z.number().optional(),
|
||||
billing_type: z.nativeEnum(BillingType).nullish(),
|
||||
tier_behaviour: z.nativeEnum(TierBehaviours).nullish(),
|
||||
tier_behavior: z.nativeEnum(TierBehavior).nullish(),
|
||||
is_custom: z.boolean().optional(),
|
||||
config: FixedPriceConfigSchema.or(UsagePriceConfigSchema),
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import { entitlements } from "../entModels/entTable.js";
|
||||
import { products } from "../productTable.js";
|
||||
import type { FixedPriceConfig } from "./priceConfig/fixedPriceConfig.js";
|
||||
import type {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
UsagePriceConfig,
|
||||
} from "./priceConfig/usagePriceConfig.js";
|
||||
import type { ProrationConfig } from "./priceModels.js";
|
||||
@@ -28,8 +28,8 @@ export const prices = pgTable(
|
||||
config: jsonb().$type<FixedPriceConfig | UsagePriceConfig>(),
|
||||
created_at: numeric({ mode: "number" }).notNull(),
|
||||
billing_type: text("billing_type"),
|
||||
tier_behaviour: text("tier_behaviour")
|
||||
.$type<TierBehaviours>()
|
||||
tier_behavior: text("tier_behavior")
|
||||
.$type<TierBehavior>()
|
||||
.default(sql`null`),
|
||||
is_custom: boolean("is_custom").default(false),
|
||||
entitlement_id: text("entitlement_id").default(sql`null`),
|
||||
|
||||
@@ -11,7 +11,7 @@ export const FeaturePriceItemSchema = ProductItemSchema.pick({
|
||||
|
||||
price: true,
|
||||
tiers: true,
|
||||
tier_behaviour: true,
|
||||
tier_behavior: true,
|
||||
billing_units: true,
|
||||
|
||||
reset_usage_when_enabled: true,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod/v4";
|
||||
import { ApiFeatureV0Schema } from "../../../api/features/prevVersions/apiFeatureV0.js";
|
||||
import { RolloverExpiryDurationType } from "../../productModels/durationTypes/rolloverExpiryDurationType.js";
|
||||
import { ProductItemInterval } from "../../productModels/intervals/productItemInterval.js";
|
||||
import { TierBehaviours } from "../../productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import { TierBehavior } from "../../productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import { Infinite } from "../../productModels/productEnums.js";
|
||||
import { OnDecrease, OnIncrease } from "./productItemEnums.js";
|
||||
|
||||
@@ -120,7 +120,7 @@ export const ProductItemSchema = z.object({
|
||||
"The billing units of the product item (eg $1 for 30 credits).",
|
||||
}),
|
||||
|
||||
tier_behaviour: z.enum(TierBehaviours).nullish().meta({
|
||||
tier_behavior: z.enum(TierBehavior).nullish().meta({
|
||||
description: "The type of tiered pricing: graduated or volume-based.",
|
||||
}),
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"@types/bun": "latest",
|
||||
"@types/node": "^24.0.3",
|
||||
"cross-env": "^7.0.3",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"private": true
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TierBehaviours } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { TierBehavior } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { volumeTiersToLineAmount } from "@utils/billingUtils/invoicingUtils/lineItemUtils/volumeTiersToLineAmount";
|
||||
import type { Price } from "../../../../models/productModels/priceModels/priceModels";
|
||||
import { nullish } from "../../../utils";
|
||||
@@ -34,7 +34,7 @@ export const tiersToLineAmount = ({
|
||||
billingUnits?: number;
|
||||
}): number => {
|
||||
const tiers = price.config.usage_tiers;
|
||||
const isVolume = price.tier_behaviour === TierBehaviours.VolumeBased;
|
||||
const isVolume = price.tier_behavior === TierBehavior.VolumeBased;
|
||||
|
||||
if (nullish(tiers)) {
|
||||
throw new Error(
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ApiBalanceBreakdownPrice } from "@api/customers/cusFeatures/apiBal
|
||||
import { BillingMethod } from "@api/products/components/billingMethod.js";
|
||||
import type { FullCusEntWithFullCusProduct } from "@models/cusProductModels/cusEntModels/cusEntWithProduct.js";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
type UsagePriceConfig,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig.js";
|
||||
import { cusEntsToMaxPurchase } from "@utils/cusEntUtils/convertCusEntUtils/cusEntsToMaxPurchase.js";
|
||||
@@ -36,7 +36,7 @@ export const customerEntitlementToBalancePrice = ({
|
||||
// If usage price with multiple tiers, use tiers array
|
||||
let amount: number | undefined;
|
||||
let tiers: UsagePriceConfig["usage_tiers"] | undefined;
|
||||
let tier_behaviour: TierBehaviours | undefined;
|
||||
let tier_behavior: TierBehavior | undefined;
|
||||
|
||||
if (isFixedPrice(price)) {
|
||||
amount = price.config.amount;
|
||||
@@ -46,14 +46,14 @@ export const customerEntitlementToBalancePrice = ({
|
||||
amount = usageTiers[0].amount;
|
||||
} else {
|
||||
tiers = usageTiers;
|
||||
tier_behaviour = price.tier_behaviour ?? TierBehaviours.Graduated;
|
||||
tier_behavior = price.tier_behavior ?? TierBehavior.Graduated;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
amount,
|
||||
tiers,
|
||||
tier_behaviour,
|
||||
tier_behavior,
|
||||
billing_units: billingUnits,
|
||||
billing_method: billingMethod,
|
||||
max_purchase: maxPurchase,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { FeatureOptions } from "@models/cusProductModels/cusProductModels";
|
||||
import type { EntitlementWithFeature } from "@models/productModels/entModels/entModels";
|
||||
import { TierBehaviours } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { TierBehavior } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import type { Price } from "@models/productModels/priceModels/priceModels";
|
||||
import { priceUtils } from "@utils/productUtils/priceUtils/index";
|
||||
import { Decimal } from "decimal.js";
|
||||
@@ -29,7 +29,7 @@ export const featureOptionsToV2StripeQuantity = ({
|
||||
const packsExcludingAllowance =
|
||||
featureOptions?.upcoming_quantity ?? featureOptions?.quantity;
|
||||
|
||||
const isVolume = price.tier_behaviour === TierBehaviours.VolumeBased;
|
||||
const isVolume = price.tier_behavior === TierBehavior.VolumeBased;
|
||||
|
||||
// Volume: the Stripe price has no free-tier offset, so only send purchased
|
||||
// packs. Autumn tracks the allowance internally.
|
||||
|
||||
@@ -76,7 +76,7 @@ export const itemToInvoiceAmount = ({
|
||||
}
|
||||
|
||||
const price = {
|
||||
tier_behaviour: item.tier_behaviour,
|
||||
tier_behavior: item.tier_behavior,
|
||||
config: {
|
||||
usage_tiers: item.tiers || [
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Organization } from "@models/orgModels/orgTable";
|
||||
import { TierBehaviours } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import { TierBehavior } from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import type { Price } from "@models/productModels/priceModels/priceModels";
|
||||
import type { FullProduct } from "@models/productModels/productModels";
|
||||
import { orgToCurrency } from "@utils/orgUtils/convertOrgUtils";
|
||||
@@ -43,9 +43,7 @@ export const priceToStripeCreatePriceParams = ({
|
||||
const tiers = priceToStripePrepaidV2Tiers({ price, entitlement, org });
|
||||
|
||||
const tiersMode =
|
||||
price.tier_behaviour === TierBehaviours.VolumeBased
|
||||
? "volume"
|
||||
: "graduated";
|
||||
price.tier_behavior === TierBehavior.VolumeBased ? "volume" : "graduated";
|
||||
|
||||
let priceAmountData = {};
|
||||
if (tiers.length === 1) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Organization } from "@models/orgModels/orgTable";
|
||||
import type { Entitlement } from "@models/productModels/entModels/entModels";
|
||||
import {
|
||||
TierBehaviours,
|
||||
TierBehavior,
|
||||
type UsagePriceConfig,
|
||||
} from "@models/productModels/priceModels/priceConfig/usagePriceConfig";
|
||||
import type { Price } from "@models/productModels/priceModels/priceModels";
|
||||
@@ -39,7 +39,7 @@ export const priceToStripePrepaidV2Tiers = ({
|
||||
org: Organization;
|
||||
}) => {
|
||||
const config = price.config as UsagePriceConfig;
|
||||
const isVolume = price.tier_behaviour === TierBehaviours.VolumeBased;
|
||||
const isVolume = price.tier_behavior === TierBehavior.VolumeBased;
|
||||
const tiers: Stripe.PriceCreateParams.Tier[] = [];
|
||||
|
||||
// Graduated + allowance: insert a free leading tier and shift paid-tier
|
||||
|
||||
@@ -306,9 +306,9 @@ export const featurePriceItemsAreSame = ({
|
||||
condition: tiersAreSame(item1.tiers || null, item2.tiers || null),
|
||||
message: `Tiers different`,
|
||||
},
|
||||
tier_behaviour: {
|
||||
condition: item1.tier_behaviour == item2.tier_behaviour,
|
||||
message: `Tiers type different: ${item1.tier_behaviour} != ${item2.tier_behaviour}`,
|
||||
tier_behavior: {
|
||||
condition: item1.tier_behavior == item2.tier_behavior,
|
||||
message: `Tiers type different: ${item1.tier_behavior} != ${item2.tier_behavior}`,
|
||||
},
|
||||
billing_units: {
|
||||
condition: item1.billing_units == item2.billing_units,
|
||||
|
||||
@@ -79,7 +79,7 @@ const itemToPlanFeaturePrice = ({
|
||||
return {
|
||||
amount: price ?? undefined,
|
||||
tiers: tiers,
|
||||
tier_behaviour: item.tier_behaviour ?? undefined,
|
||||
tier_behavior: item.tier_behavior ?? undefined,
|
||||
|
||||
interval: itemToBillingInterval({ item }),
|
||||
interval_count:
|
||||
|
||||
@@ -105,7 +105,7 @@ export const toFeaturePriceItem = ({
|
||||
price: null,
|
||||
tiers,
|
||||
billing_units: config.billing_units,
|
||||
tier_behaviour: price.tier_behaviour ?? null,
|
||||
tier_behavior: price.tier_behavior ?? null,
|
||||
|
||||
entity_feature_id: ent.entity_feature_id,
|
||||
reset_usage_when_enabled: !ent.carry_from_previous,
|
||||
|
||||
Reference in New Issue
Block a user