37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import type { CreditBalance } from "$lib/types";
|
|||
|
|
import {
|
||
|
|
canFeatureFromCredits,
|
||
|
|
type CapabilitiesStatus
|
||
|
|
} from "$lib/plan-capabilities";
|
||
|
|
import {
|
||
|
|
isFreePlan as isFreePlanFromBilling,
|
||
|
|
planDisplayName as planDisplayNameFromBilling,
|
||
|
|
type PlanLike
|
||
|
|
} from "$lib/billing-display";
|
||
|
|
|
||
|
|
/** True when the company is on Free / no paid plan (AI campaign features gated). */
|
||
|
|
export function isFreePlan(credits?: CreditBalance | null): boolean {
|
||
|
|
const plan =
|
||
|
|
credits?.plan && typeof credits.plan === "object"
|
||
|
|
? (credits.plan as PlanLike)
|
||
|
|
: null;
|
||
|
|
return isFreePlanFromBilling(plan, credits);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Display label — same contract as billing-display (never invent "Free" for missing plans). */
|
||
|
|
export function planDisplayName(credits?: CreditBalance | null): string {
|
||
|
|
const plan =
|
||
|
|
credits?.plan && typeof credits.plan === "object"
|
||
|
|
? (credits.plan as PlanLike)
|
||
|
|
: null;
|
||
|
|
return planDisplayNameFromBilling(plan, credits);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** Contract helper: effective feature from credits.features (see plan-capabilities). */
|
||
|
|
export function canFeature(
|
||
|
|
credits: CreditBalance | null | undefined,
|
||
|
|
key: string,
|
||
|
|
status: CapabilitiesStatus = "missing"
|
||
|
|
): boolean {
|
||
|
|
return canFeatureFromCredits(credits, key, status);
|
||
|
|
}
|