Files
descrybe/apps/web/src/lib/plan-gates.ts
T
greeneclipse 8580c996c3 Initial commit of Descrybe v2 without local scratch artifacts.
Drop one-shot tmp/axe scripts and agent i18n scratch so the Gitea tree is deployable.
2026-08-09 22:47:43 +02:00

38 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);
}