diff --git a/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts b/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts index 05f27bc1f..c74a323fb 100644 --- a/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts +++ b/server/src/internal/products/product-items/productItemUtils/itemToPriceAndEnt.ts @@ -20,16 +20,16 @@ import { UsageModel, type UsagePriceConfig, } from "@autumn/shared"; +import { + itemToBillingInterval, + itemToEntInterval, +} from "@shared/utils/productV2Utils/productItemUtils/itemIntervalUtils.js"; import { pricesAreSame } from "@/internal/products/prices/priceInitUtils.js"; import { getBillingType } from "@/internal/products/prices/priceUtils.js"; import RecaseError from "@/utils/errorUtils.js"; import { generateId, notNullish, nullish } from "@/utils/genUtils.js"; import { entsAreSame } from "../../entitlements/entitlementUtils.js"; import { shouldProrate } from "../../prices/priceUtils/prorationConfigUtils.js"; -import { - itemToBillingInterval, - itemToEntInterval, -} from "../itemIntervalUtils.js"; import { itemCanBeProrated } from "./classifyItem.js"; import { isFeatureItem, diff --git a/server/src/internal/products/product-items/validateProductItems.ts b/server/src/internal/products/product-items/validateProductItems.ts index 0452adead..b19c1c81f 100644 --- a/server/src/internal/products/product-items/validateProductItems.ts +++ b/server/src/internal/products/product-items/validateProductItems.ts @@ -11,11 +11,11 @@ import { ProductItemSchema, UsageModel, } from "@autumn/shared"; +import { itemToEntInterval } from "@shared/utils/productV2Utils/productItemUtils/itemIntervalUtils.js"; import { StatusCodes } from "http-status-codes"; import RecaseError from "@/utils/errorUtils.js"; import { notNullish, nullish } from "@/utils/genUtils.js"; import { createFeaturesFromItems } from "./createFeaturesFromItems.js"; -import { itemToEntInterval } from "./itemIntervalUtils.js"; import { isBooleanFeatureItem, isFeatureItem, @@ -362,12 +362,12 @@ export const validateProductItems = ({ const hasWeeklyPrice = newItems.some( (item) => (isPriceItem(item) || isFeaturePriceItem(item)) && - item.interval === ProductItemInterval.Week + item.interval === ProductItemInterval.Week, ); const hasMonthlyPrice = newItems.some( (item) => (isPriceItem(item) || isFeaturePriceItem(item)) && - item.interval === ProductItemInterval.Month + item.interval === ProductItemInterval.Month, ); if (hasWeeklyPrice && hasMonthlyPrice) { diff --git a/shared/api/customers/cusProducts/changes/V0_2_CusProductChange.ts b/shared/api/customers/cusProducts/changes/V0_2_CusProductChange.ts index 919752364..5a7773e33 100644 --- a/shared/api/customers/cusProducts/changes/V0_2_CusProductChange.ts +++ b/shared/api/customers/cusProducts/changes/V0_2_CusProductChange.ts @@ -8,7 +8,7 @@ import { TierInfinite } from "@models/productV2Models/productItemModels/productI import { isFeatureItem, isPriceItem, -} from "@utils/productDisplayUtils/getItemType.js"; +} from "@utils/productV2Utils/productItemUtils/getItemType.js"; import { notNullish } from "@utils/utils.js"; import { z } from "zod/v4"; import type { CusProductLegacyData } from "../cusProductLegacyData.js"; diff --git a/shared/models/productV2Models/productV2Models.ts b/shared/models/productV2Models/productV2Models.ts index 0b6ea7806..b9bdfda2e 100644 --- a/shared/models/productV2Models/productV2Models.ts +++ b/shared/models/productV2Models/productV2Models.ts @@ -1,4 +1,5 @@ import { z } from "zod/v4"; +import { AppEnv } from "../genModels/genEnums.js"; import { FreeTrialSchema } from "../productModels/freeTrialModels/freeTrialModels.js"; import { ProductItemSchema } from "./productItemModels/productItemModels.js"; diff --git a/shared/models/productV3Models/productV3Response.ts b/shared/models/productV3Models/productV3Response.ts index 514b8fa3d..90b714094 100644 --- a/shared/models/productV3Models/productV3Response.ts +++ b/shared/models/productV3Models/productV3Response.ts @@ -1,8 +1,8 @@ -import { z } from "zod"; +import { z } from "zod/v4"; +import { ApiProductPropertiesSchema } from "../../api/products/apiProduct.js"; import { AttachScenario } from "../checkModels/checkPreviewModels.js"; import { AppEnv } from "../genModels/genEnums.js"; import { ProductItemInterval } from "../productV2Models/productItemModels/productItemModels.js"; -import { ProductPropertiesSchema } from "../productV2Models/productResponseModels.js"; export const PlanResponseSchema = z.object({ id: z.string(), @@ -30,5 +30,5 @@ export const PlanResponseSchema = z.object({ // base_variant_id: z.string().nullable(), scenario: z.nativeEnum(AttachScenario).optional(), - properties: ProductPropertiesSchema.optional(), + properties: ApiProductPropertiesSchema.optional(), }); diff --git a/shared/utils/productUtils.ts b/shared/utils/productUtils.ts index 8c286594a..183e8ad67 100644 --- a/shared/utils/productUtils.ts +++ b/shared/utils/productUtils.ts @@ -3,7 +3,7 @@ import type { ProductItem, ProductV2 } from "../index.js"; import { isFeaturePriceItem, isPriceItem, -} from "./productDisplayUtils/getItemType.js"; +} from "./productV2Utils/productItemUtils/getItemType.js"; import { nullish } from "./utils.js"; export const isFreeProductV2 = ({ items }: { items: ProductItem[] }) => { diff --git a/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts b/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts index 3a4cefc4c..af0b35058 100644 --- a/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts +++ b/shared/utils/productV2Utils/productItemUtils/getProductItemRes.ts @@ -1,14 +1,15 @@ import { ApiProductItemSchema } from "@api/products/apiProductItem.js"; import { Decimal } from "decimal.js"; -import type { FeatureOptions } from "../../models/cusProductModels/cusProductModels.js"; -import type { Feature } from "../../models/featureModels/featureModels.js"; +import type { FeatureOptions } from "@models/cusProductModels/cusProductModels.js"; +import type { Feature } from "@models/featureModels/featureModels.js"; import { + type PriceTier, type ProductItem, UsageModel, -} from "../../models/productV2Models/productItemModels/productItemModels.js"; -import { toApiFeature } from "../featureUtils.js"; -import { getProductItemDisplay } from "../productDisplayUtils.js"; -import { notNullish } from "../utils.js"; +} from "@models/productV2Models/productItemModels/productItemModels.js"; +import { toApiFeature } from "@utils/featureUtils.js"; +import { getProductItemDisplay } from "@utils/productDisplayUtils.js"; +import { notNullish } from "@utils/utils.js"; import { getItemType } from "./getItemType.js"; export const calculateProrationAmount = ({ @@ -67,7 +68,7 @@ export const itemToPriceOrTiers = ({ if (item.tiers.length > 1) { return { price: undefined, - tiers: item.tiers.map((tier) => ({ + tiers: item.tiers.map((tier: PriceTier) => ({ ...tier, amount: proration ? calculateProrationAmount({ diff --git a/shared/utils/productV2Utils/productItemUtils/mapToItem.ts b/shared/utils/productV2Utils/productItemUtils/mapToItem.ts index 647e8d31c..eecc4afb7 100644 --- a/shared/utils/productV2Utils/productItemUtils/mapToItem.ts +++ b/shared/utils/productV2Utils/productItemUtils/mapToItem.ts @@ -12,6 +12,7 @@ import type { Price } from "../../../models/productModels/priceModels/priceModel import { Infinite } from "../../../models/productModels/productEnums.js"; import { type ProductItem, + type ProductItemConfig, ProductItemFeatureType, TierInfinite, UsageModel, diff --git a/shared/utils/productV3Utils/mapToProductV3.ts b/shared/utils/productV3Utils/mapToProductV3.ts index 0ec16d9b9..e72724b5d 100644 --- a/shared/utils/productV3Utils/mapToProductV3.ts +++ b/shared/utils/productV3Utils/mapToProductV3.ts @@ -1,4 +1,4 @@ -import type { z } from "zod"; +import type { z } from "zod/v4"; import type { ProductV2 } from "../../models/productV2Models/productV2Models.js"; import type { PlanResponseSchema } from "../../models/productV3Models/productV3Response.js"; import { productV2ToBasePrice } from "./productItemUtils/productV3ItemUtils.js";