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,73 @@
import {
billingCadences,
calculateBillingCatalogPrice,
hiveGridBasePlans,
type BillingCatalogPriceBreakdown,
} from "./commercial-catalog.js";
import type { EntitlementPlanId } from "./plans.js";
export const REGISTRATION_MAX_SEAT_QUANTITY = 10_000;
export type RegistrationPlanAdviceOption = {
readonly planCode: EntitlementPlanId;
readonly publicName: "Core" | "Swarm" | "Colony";
readonly breakdown: BillingCatalogPriceBreakdown;
readonly recommended: boolean;
};
export type RegistrationPlanAdvice = {
readonly officeSeatQuantity: number;
readonly fieldSeatQuantity: number;
readonly recommendedPlanCode: EntitlementPlanId;
readonly options: readonly RegistrationPlanAdviceOption[];
};
function requireRegistrationSeatQuantity(value: number, label: string, minimum: number): number {
if (!Number.isSafeInteger(value) || value < minimum || value > REGISTRATION_MAX_SEAT_QUANTITY) {
throw new RangeError(`${label} must be a safe integer between ${minimum} and ${REGISTRATION_MAX_SEAT_QUANTITY}.`);
}
return value;
}
/**
* Recommends the cheapest monthly HiveGrid base-plan configuration for a team.
*
* The catalog order is the deterministic tie-breaker: Core, then Swarm, then
* Colony. This function deliberately compares the complete recurring net
* amount including extra seats instead of upgrading as soon as an included
* quantity is exceeded.
*/
export function adviseRegistrationPlan(input: {
readonly officeSeatQuantity: number;
readonly fieldSeatQuantity: number;
}): RegistrationPlanAdvice {
const officeSeatQuantity = requireRegistrationSeatQuantity(input.officeSeatQuantity, "officeSeatQuantity", 1);
const fieldSeatQuantity = requireRegistrationSeatQuantity(input.fieldSeatQuantity, "fieldSeatQuantity", 0);
const pricedOptions = hiveGridBasePlans.map((plan) => ({
planCode: plan.technicalCode,
publicName: plan.publicName,
breakdown: calculateBillingCatalogPrice({
planCode: plan.technicalCode,
cadence: billingCadences.monthly,
officeSeatQuantity,
fieldSeatQuantity,
}),
}));
const recommended = pricedOptions.reduce((cheapest, candidate) =>
candidate.breakdown.recurringNetAmountCents < cheapest.breakdown.recurringNetAmountCents ? candidate : cheapest
);
return Object.freeze({
officeSeatQuantity,
fieldSeatQuantity,
recommendedPlanCode: recommended.planCode,
options: Object.freeze(
pricedOptions.map((option) =>
Object.freeze({
...option,
recommended: option.planCode === recommended.planCode,
})
)
),
});
}