Open source alternative to Semrush and Ahrefs
TypeScript backlink-analysisgoogle-search-console-mcpkeyword-researchmcpseoseo-agentseo-auditseo-automationseo-skillsseo-toolssite-audit
Detect paid plans from Autumn entitlement flags (#482)
Ben Senescu75aec8424f33
diff --git a/src/client/features/billing/plan-detection.test.ts b/src/client/features/billing/plan-detection.test.tsnew file mode 100644index 00000000..d8bc9d30--- /dev/null+++ b/src/client/features/billing/plan-detection.test.ts@@ -0,0 +1,22 @@+import { describe, expect, it } from "vitest";+import { AUTUMN_PAID_PLAN_FEATURE_ID } from "@/shared/billing";+import { getCustomerPlanStatus } from "./plan-detection";++describe("getCustomerPlanStatus", () => {+ it("treats a customer without the paid entitlement as free", () => {+ expect(getCustomerPlanStatus(undefined)).toBe("free");+ expect(getCustomerPlanStatus({ flags: {} })).toBe("free");+ });++ it("treats any plan granting the paid entitlement as paid", () => {+ expect(+ getCustomerPlanStatus({+ flags: {+ [AUTUMN_PAID_PLAN_FEATURE_ID]: {+ planId: "friends_and_family_2",+ },+ },+ }),+ ).toBe("paid");+ });+});diff --git a/src/client/features/billing/plan-detection.ts b/src/client/features/billing/plan-detection.tsindex f0b31991..668e68ed 100644--- a/src/client/features/billing/plan-detection.ts+++ b/src/client/features/billing/plan-detection.ts@@ -1,17 +1,9 @@-import { AUTUMN_PAID_PLAN_ID } from "@/shared/billing";+import { AUTUMN_PAID_PLAN_FEATURE_ID } from "@/shared/billing";export type PlanStatus = "free" | "paid";export function getCustomerPlanStatus(- customer:- | { subscriptions?: Array<{ planId: string; status: string }> }- | undefined,+ customer: { flags?: Record<string, unknown> } | undefined,): PlanStatus {- if (!customer?.subscriptions) return "free";-- const hasActivePaid = customer.subscriptions.some(- (sub) => sub.planId === AUTUMN_PAID_PLAN_ID && sub.status === "active",- );-- return hasActivePaid ? "paid" : "free";+ return customer?.flags?.[AUTUMN_PAID_PLAN_FEATURE_ID] ? "paid" : "free";}