Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -0,0 +1,49 @@
import { describe, expect, it } from "vitest";
import { SubscriptionBillingPeriod } from "~/application/enums/subscriptions/SubscriptionBillingPeriod";
import {
deriveAdminCatalogProductKind,
isManagedBillingCatalogProduct,
} from "./adminCatalogPolicy";
describe("admin billing catalog policy", () => {
it("protects every canonical base-plan identity and every base-plan row", () => {
for (const code of [
"starter",
"starter_annual_sepa",
"pro",
"pro_annual_sepa",
"business",
"business_annual_sepa",
]) {
expect(isManagedBillingCatalogProduct({ code })).toBe(true);
}
expect(isManagedBillingCatalogProduct({ kind: "base_plan", code: "legacy" })).toBe(true);
expect(
isManagedBillingCatalogProduct({
kind: "recurring_add_on",
code: "customer_portal_monthly",
}),
).toBe(false);
});
it("creates only separate recurring add-ons or one-time setup products", () => {
expect(
deriveAdminCatalogProductKind([
{ billingPeriod: SubscriptionBillingPeriod.MONTHLY },
]),
).toBe("recurring_add_on");
expect(
deriveAdminCatalogProductKind([
{ billingPeriod: SubscriptionBillingPeriod.ONCE },
]),
).toBe("one_time_setup");
expect(
deriveAdminCatalogProductKind([
{ billingPeriod: SubscriptionBillingPeriod.ONCE },
{ billingPeriod: SubscriptionBillingPeriod.MONTHLY },
]),
).toBeNull();
expect(deriveAdminCatalogProductKind([])).toBeNull();
});
});
@@ -0,0 +1,43 @@
import { hiveGridBasePlans } from "@hivegrid/entitlements";
import { SubscriptionBillingPeriod } from "~/application/enums/subscriptions/SubscriptionBillingPeriod";
export type AdminCatalogProductKind =
| "base_plan"
| "recurring_add_on"
| "one_time_setup"
| "contract_override";
type AdminCatalogProductIdentity = {
readonly kind?: AdminCatalogProductKind | null;
readonly code?: string | null;
readonly lagoPlanCode?: string | null;
};
const managedBasePlanCodes = new Set(
hiveGridBasePlans.flatMap((plan) => [
plan.technicalCode,
...plan.variants.map((variant) => variant.code),
]),
);
export function isManagedBillingCatalogProduct(
product: AdminCatalogProductIdentity,
): boolean {
if (product.kind === "base_plan") return true;
return [product.code, product.lagoPlanCode].some(
(code) => Boolean(code?.trim() && managedBasePlanCodes.has(code.trim())),
);
}
export function deriveAdminCatalogProductKind(
prices: readonly { readonly billingPeriod: SubscriptionBillingPeriod }[],
): Exclude<AdminCatalogProductKind, "base_plan" | "contract_override"> | null {
if (prices.length === 0) return null;
const oneTimeCount = prices.filter(
(price) => price.billingPeriod === SubscriptionBillingPeriod.ONCE,
).length;
if (oneTimeCount === prices.length) return "one_time_setup";
if (oneTimeCount === 0) return "recurring_add_on";
return null;
}
@@ -1,325 +0,0 @@
import { SubscriptionBillingPeriod } from "~/application/enums/subscriptions/SubscriptionBillingPeriod";
import { SubscriptionPriceType } from "~/application/enums/subscriptions/SubscriptionPriceType";
import { DefaultFeatures } from "../dtos/shared/DefaultFeatures";
import { SubscriptionPriceDto } from "../dtos/subscriptions/SubscriptionPriceDto";
import { SubscriptionProductDto } from "../dtos/subscriptions/SubscriptionProductDto";
import { SubscriptionUsageBasedPriceDto } from "../dtos/subscriptions/SubscriptionUsageBasedPriceDto";
import { SubscriptionUsageBasedTierDto } from "../dtos/subscriptions/SubscriptionUsageBasedTierDto";
import { PricingModel } from "../enums/subscriptions/PricingModel";
import { SubscriptionFeatureLimitType } from "../enums/subscriptions/SubscriptionFeatureLimitType";
const UNIT_API_CALL = {
name: "api",
title: "API Call",
titlePlural: "API Calls",
};
function generatePrice(currency: string, price: number, billingPeriod: SubscriptionBillingPeriod): SubscriptionPriceDto {
return {
billingProviderId: "",
subscriptionProductId: "",
type: billingPeriod === SubscriptionBillingPeriod.ONCE ? SubscriptionPriceType.ONE_TIME : SubscriptionPriceType.RECURRING,
billingPeriod,
price: Math.round(price * 100) / 100,
currency,
trialDays: 0,
active: true,
usageBasedPrices: [],
};
}
function generateUsageBasedPrice(
currency: string,
unit: {
name: string;
title: string;
titlePlural: string;
},
usageType: "licensed" | "metered",
aggregateUsage: "last_during_period" | "last_ever" | "max" | "sum",
tiersMode: "graduated" | "volume",
billingScheme: "per_unit" | "tiered",
tiers: {
from: number;
to: undefined | number;
perUnitPrice: number | undefined;
flatFeePrice: number | undefined;
}[]
): SubscriptionUsageBasedPriceDto {
const usageBasedPriceTiers: SubscriptionUsageBasedTierDto[] = [];
tiers.forEach((tier) => {
usageBasedPriceTiers.push({
id: "",
subscriptionUsageBasedPriceId: "",
...tier,
});
});
return {
id: "",
billingProviderId: "",
subscriptionProductId: "",
billingPeriod: SubscriptionBillingPeriod.MONTHLY,
currency,
unit: unit.name,
unitTitle: unit.title,
unitTitlePlural: unit.titlePlural,
usageType,
aggregateUsage,
tiersMode,
billingScheme,
tiers: usageBasedPriceTiers,
};
}
function generateCommonPlan(order: number, model: PricingModel) {
if (order === 1) {
return {
billingProviderId: "",
order,
title: "pricing.products.plan1.title",
description: "pricing.products.plan1.description",
model,
public: true,
features: [
{
order: 1,
title: "pricing.features.users.max",
name: DefaultFeatures.Users,
value: 2,
type: SubscriptionFeatureLimitType.MAX,
accumulate: false,
},
{
order: 3,
title: "pricing.features.apiCalls.units",
name: DefaultFeatures.API,
value: 0,
type: SubscriptionFeatureLimitType.NOT_INCLUDED,
accumulate: false,
},
{
order: 4,
title: "pricing.features.prioritySupport.none",
name: DefaultFeatures.PrioritySupport,
value: 0,
type: SubscriptionFeatureLimitType.NOT_INCLUDED,
accumulate: false,
},
],
badge: "",
active: true,
prices: [],
};
} else if (order === 2) {
return {
billingProviderId: "",
order,
title: "pricing.products.plan2.title",
description: "pricing.products.plan2.description",
public: true,
model,
features: [
{
order: 1,
title: "pricing.features.users.max",
name: DefaultFeatures.Users,
value: 5,
type: SubscriptionFeatureLimitType.MAX,
accumulate: false,
},
{
order: 3,
title: "pricing.features.apiCalls.monthly",
name: DefaultFeatures.API,
value: 100,
type: SubscriptionFeatureLimitType.MONTHLY,
accumulate: false,
},
{
order: 4,
title: "pricing.features.prioritySupport.basic",
name: DefaultFeatures.PrioritySupport,
value: 0,
type: SubscriptionFeatureLimitType.INCLUDED,
accumulate: false,
},
],
badge: "pricing.recommended",
active: true,
};
} else if (order === 3) {
return {
billingProviderId: "",
order,
title: "pricing.products.plan3.title",
description: "pricing.products.plan3.description",
public: true,
model,
features: [
{
order: 1,
title: "pricing.features.users.max",
name: DefaultFeatures.Users,
value: 12,
type: SubscriptionFeatureLimitType.MAX,
accumulate: false,
},
{
order: 3,
title: "pricing.features.apiCalls.unlimited",
name: DefaultFeatures.API,
value: 0,
type: SubscriptionFeatureLimitType.UNLIMITED,
accumulate: false,
},
{
order: 4,
title: "pricing.features.prioritySupport.priority",
name: DefaultFeatures.PrioritySupport,
value: 0,
type: SubscriptionFeatureLimitType.INCLUDED,
accumulate: false,
},
],
badge: "",
active: true,
};
}
return {
billingProviderId: "",
order,
title: "pricing.products.plan1.title",
description: "pricing.products.plan1.description",
model,
public: true,
features: [
{
order: 1,
title: "pricing.features.users.one",
name: DefaultFeatures.Users,
value: 1,
type: SubscriptionFeatureLimitType.MAX,
accumulate: false,
},
],
badge: "",
active: true,
};
}
const FLAT_RATE_PRICES: SubscriptionProductDto[] = [
{
...generateCommonPlan(1, PricingModel.FLAT_RATE),
prices: [
generatePrice("usd", 9, SubscriptionBillingPeriod.MONTHLY),
generatePrice("usd", 90, SubscriptionBillingPeriod.YEARLY),
generatePrice("mxn", 199, SubscriptionBillingPeriod.MONTHLY),
generatePrice("mxn", 1990, SubscriptionBillingPeriod.YEARLY),
],
usageBasedPrices: [],
},
{
...generateCommonPlan(2, PricingModel.FLAT_RATE),
prices: [
generatePrice("usd", 199, SubscriptionBillingPeriod.MONTHLY),
generatePrice("usd", 1990, SubscriptionBillingPeriod.YEARLY),
generatePrice("mxn", 3999, SubscriptionBillingPeriod.MONTHLY),
generatePrice("mxn", 39990, SubscriptionBillingPeriod.YEARLY),
],
usageBasedPrices: [],
},
{
...generateCommonPlan(3, PricingModel.FLAT_RATE),
prices: [
generatePrice("usd", 399, SubscriptionBillingPeriod.MONTHLY),
generatePrice("usd", 3990, SubscriptionBillingPeriod.YEARLY),
generatePrice("mxn", 7999, SubscriptionBillingPeriod.MONTHLY),
generatePrice("mxn", 79990, SubscriptionBillingPeriod.YEARLY),
],
usageBasedPrices: [],
},
];
const USAGE_BASED_PRICES: SubscriptionProductDto[] = [
{
...generateCommonPlan(1, PricingModel.USAGE_BASED),
prices: [],
usageBasedPrices: [
generateUsageBasedPrice("usd", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 0.02, flatFeePrice: 5 },
{ from: 21, to: undefined, perUnitPrice: 0.01, flatFeePrice: 10 },
]),
generateUsageBasedPrice("mxn", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 0.4, flatFeePrice: 100 },
{ from: 21, to: undefined, perUnitPrice: 0.2, flatFeePrice: 200 },
]),
],
},
{
...generateCommonPlan(2, PricingModel.USAGE_BASED),
prices: [],
usageBasedPrices: [
generateUsageBasedPrice("usd", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 0.04, flatFeePrice: 10 },
{ from: 21, to: undefined, perUnitPrice: 0.02, flatFeePrice: 20 },
]),
generateUsageBasedPrice("mxn", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 0.8, flatFeePrice: 200 },
{ from: 21, to: undefined, perUnitPrice: 0.4, flatFeePrice: 400 },
]),
],
},
{
...generateCommonPlan(3, PricingModel.USAGE_BASED),
prices: [],
usageBasedPrices: [
generateUsageBasedPrice("usd", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 0.06, flatFeePrice: 15 },
{ from: 21, to: undefined, perUnitPrice: 0.03, flatFeePrice: 30 },
]),
generateUsageBasedPrice("mxn", UNIT_API_CALL, "metered", "sum", "volume", "tiered", [
{ from: 0, to: 10, perUnitPrice: 0.0, flatFeePrice: undefined },
{ from: 11, to: 20, perUnitPrice: 1.2, flatFeePrice: 300 },
{ from: 21, to: undefined, perUnitPrice: 0.6, flatFeePrice: 600 },
]),
],
},
];
const FLAT_RATE_PLUS_USAGE_BASED_PRICES: SubscriptionProductDto[] = [
...FLAT_RATE_PRICES.map((flatRate) => {
const usageBasedPrices = USAGE_BASED_PRICES.find((f) => f.order === flatRate.order)?.usageBasedPrices ?? [];
return {
...flatRate,
usageBasedPrices,
model: PricingModel.FLAT_RATE_USAGE_BASED,
};
}),
];
const ONE_TIME_PRICES: SubscriptionProductDto[] = [
{
...generateCommonPlan(1, PricingModel.ONCE),
prices: [generatePrice("usd", 99 * 2, SubscriptionBillingPeriod.ONCE), generatePrice("mxn", 1999 * 2, SubscriptionBillingPeriod.ONCE)],
usageBasedPrices: [],
},
{
...generateCommonPlan(2, PricingModel.ONCE),
prices: [generatePrice("usd", 499 * 2, SubscriptionBillingPeriod.ONCE), generatePrice("mxn", 9999 * 2, SubscriptionBillingPeriod.ONCE)],
usageBasedPrices: [],
},
{
...generateCommonPlan(3, PricingModel.ONCE),
prices: [generatePrice("usd", 1999 * 2, SubscriptionBillingPeriod.ONCE), generatePrice("mxn", 4999 * 2, SubscriptionBillingPeriod.ONCE)],
usageBasedPrices: [],
},
];
const plans = [...FLAT_RATE_PRICES, ...USAGE_BASED_PRICES, ...FLAT_RATE_PLUS_USAGE_BASED_PRICES, ...ONE_TIME_PRICES];
export default plans;
@@ -1,17 +1,27 @@
import fs from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
import plans from "~/application/pricing/plans.server";
import { PricingModel } from "~/application/enums/subscriptions/PricingModel";
import { HIVEGRID_SUBSCRIPTION_PRICING_MODELS, isHiveGridSubscriptionPricingModel } from "./pricingModelPolicy";
describe("HiveGrid subscription pricing model policy", () => {
it("does not allow seat-type pricing models", () => {
it("allows only fixed recurring and one-time products", () => {
expect(HIVEGRID_SUBSCRIPTION_PRICING_MODELS).toEqual([PricingModel.FLAT_RATE, PricingModel.ONCE]);
expect(HIVEGRID_SUBSCRIPTION_PRICING_MODELS).not.toContain(PricingModel.PER_SEAT);
expect(HIVEGRID_SUBSCRIPTION_PRICING_MODELS).not.toContain(PricingModel.USAGE_BASED);
expect(HIVEGRID_SUBSCRIPTION_PRICING_MODELS).not.toContain(PricingModel.FLAT_RATE_USAGE_BASED);
expect(isHiveGridSubscriptionPricingModel(PricingModel.PER_SEAT)).toBe(false);
expect(isHiveGridSubscriptionPricingModel(PricingModel.USAGE_BASED)).toBe(false);
expect(isHiveGridSubscriptionPricingModel(PricingModel.FLAT_RATE_USAGE_BASED)).toBe(false);
});
it("keeps generated admin pricing seeds free of seat-type plans", () => {
expect(plans).not.toHaveLength(0);
expect(plans.map((plan) => plan.model)).not.toContain(PricingModel.PER_SEAT);
it("does not expose the removed demo-plan generator from the admin route", () => {
const route = fs.readFileSync(path.join(process.cwd(), "apps/web/app/routes/admin/settings/pricing.tsx"), "utf8");
expect(route).not.toContain("plans.server");
expect(route).not.toContain("create-all-plans");
expect(route).not.toContain("generateFromFiles");
expect(route).toContain("admin.pricing.catalogManaged");
});
});
@@ -1,13 +1,7 @@
import { PricingModel } from "~/application/enums/subscriptions/PricingModel";
export const HIVEGRID_SUBSCRIPTION_PRICING_MODELS = [
PricingModel.FLAT_RATE,
PricingModel.USAGE_BASED,
PricingModel.FLAT_RATE_USAGE_BASED,
PricingModel.ONCE,
] as const;
export const HIVEGRID_SUBSCRIPTION_PRICING_MODELS = [PricingModel.FLAT_RATE, PricingModel.ONCE] as const;
export function isHiveGridSubscriptionPricingModel(model: PricingModel) {
return HIVEGRID_SUBSCRIPTION_PRICING_MODELS.includes(model as (typeof HIVEGRID_SUBSCRIPTION_PRICING_MODELS)[number]);
}