Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
refactor(billing): remove local preview code and streamline billing page
Victor Hugo dos Santosc4ea1f3d9e4d
diff --git a/frontend/src/pages/organization/BillingPage/BillingPage.tsx b/frontend/src/pages/organization/BillingPage/BillingPage.tsxindex 733fa70904..276afc2269 100644--- a/frontend/src/pages/organization/BillingPage/BillingPage.tsx+++ b/frontend/src/pages/organization/BillingPage/BillingPage.tsx@@ -1,7 +1,6 @@import { useSubscription } from "@app/context";import { BillingV2Page } from "../BillingV2Page";-import { PREVIEW_MODE } from "../BillingV2Page/billing-v2-local-preview";import { OfflineBillingPage } from "./OfflineBillingPage";export const BillingPage = () => {@@ -9,8 +8,7 @@ export const BillingPage = () => {// Offline (air-gapped) licenses can't reach the license server, so the billing surface can't load;// short-circuit to the offline page (no API calls) before mounting it.- // LAYOUT PREVIEW — REMOVE BEFORE MERGE: lets the offline page be reviewed without an offline licence.- if (PREVIEW_MODE === "offline" || subscription?.isOffline) {+ if (subscription?.isOffline) {return <OfflineBillingPage />;}diff --git a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsxindex 0572837227..bd441cc5f8 100644--- a/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx+++ b/frontend/src/pages/organization/BillingV2Page/BillingV2Page.tsx@@ -28,18 +28,6 @@ import { RemoveProductModal } from "./components/RemoveProductModal";import { ALL_ORGS_VALUE } from "./components/RootOrgFilter";import { UsageBreakdownSheet } from "./components/UsageBreakdownSheet";import { catalogById } from "./billing-v2-format";-// LOCAL PREVIEW ONLY — DO NOT COMMIT (see billing-v2-local-preview.ts).-import {- asCloudOverview,- asManagedCloudOverview,- asTrialCloudOverview,- PREVIEW_CATALOG,- PREVIEW_MODE,- previewEntitlements,- TRIAL_CATALOG,- trialEntitlements,- usePreviewUsage-} from "./billing-v2-local-preview";import { BillingV2RenderState } from "./billing-v2-view-types";const CONTACT_SALES_URL = "https://infisical.com/talk-to-us";@@ -86,60 +74,21 @@ export const BillingV2Page = () => {useGetBillingV2Organizations(orgId, { limit: ORG_PAGE_SIZE });const {- data: serverOverview,+ data: overview,isPending,isPlaceholderData,isError,refetch} = useGetBillingV2Overview(selectedOrgId);- const { data: realCatalog = [] } = useGetBillingV2Catalog(selectedOrgId);+ const { data: catalog = [] } = useGetBillingV2Catalog(selectedOrgId);const createPortalSession = useCreateBillingV2PortalSession();const addPaymentMethod = useAddBillingV2PaymentMethod();- // ===== LAYOUT PREVIEW — REMOVE BEFORE MERGE (see billing-v2-local-preview.ts) =====- // A dev stack has no licence server, so the catalog is empty and no product cards render. This- // substitutes the licence server's half of the data so the layout is reviewable. Switch views with- // PREVIEW_MODE in billing-v2-local-preview.ts.- const usePreview = PREVIEW_MODE !== "off" && realCatalog.length === 0;- const isTrialPreview = PREVIEW_MODE === "cloud-trial";- const previewCatalog = isTrialPreview ? TRIAL_CATALOG : PREVIEW_CATALOG;- const catalog = usePreview ? previewCatalog : realCatalog;- // Real figures for the faked products, read off this instance's own database through the breakdown- // endpoint, so picking an organization moves the meters the way it will in production.- const previewUsage = usePreviewUsage(selectedOrgId, breakdownScope);- const previewedEntitlements = isTrialPreview- ? trialEntitlements(previewUsage)- : previewEntitlements(previewUsage);- // Shadows the real overview for the whole component, so every branch keyed off it (subState, the- // managed/self-serve copy, the payment and invoice cards) sees the faked shape too. Restore to- // `const { data: overview, ... } = useGetBillingV2Overview(selectedOrgId)` when removing the preview.- let overview = serverOverview;- if (usePreview && serverOverview) {- if (PREVIEW_MODE === "cloud") {- overview = asCloudOverview(serverOverview, previewedEntitlements);- } else if (isTrialPreview) {- overview = asTrialCloudOverview(serverOverview, previewedEntitlements);- } else if (PREVIEW_MODE === "cloud-managed") {- overview = asManagedCloudOverview(serverOverview, previewedEntitlements);- } else {- overview = { ...serverOverview, entitlements: previewedEntitlements };- }- }- // The preview fakes the deployment, so it has to fake this endpoint's answer too. A dev stack is- // self-hosted and the signed-in user is often an instance admin, so the server legitimately returns- // every root org on the box; left alone, the picker would appear while the page pretends to be cloud.- // Real cloud returns exactly one org, which is what makes the production rule (more than one entry- // means you may switch) correct without testing isCloud anywhere.- const pickerOrgs = usePreview && PREVIEW_MODE !== "self-hosted" ? rootOrgs.slice(0, 1) : rootOrgs;- // ===== END LAYOUT PREVIEW =====-// More than one organization means the server decided this caller may switch: an instance admin on// self-hosted, where one licence spans every org on the box. Cloud is bounded to the logged-in root// org and always counts one, so this needs no isCloud test, and not reading the overview keeps the// picker on screen while that request is loading or failing.- // LOCAL PREVIEW: drop the preview branch and use `unsearchedOrgPage?.totalCount` directly.- const rootOrgCount =- usePreview && PREVIEW_MODE !== "self-hosted" ? 1 : (unsearchedOrgPage?.totalCount ?? 0);+ const rootOrgCount = unsearchedOrgPage?.totalCount ?? 0;const showOrgFilter = rootOrgCount > 1;const [flow, setFlow] = useState<BillingV2Flow | null>(null);@@ -276,7 +225,7 @@ export const BillingV2Page = () => {onUpgrade={onUpgrade}onSetCommitment={onSetCommitment}onViewBreakdown={onViewBreakdown}- rootOrgs={pickerOrgs}+ rootOrgs={rootOrgs}rootOrgCount={orgPage?.totalCount ?? rootOrgCount}isRootOrgsLoading={isOrgSearchPending}isReloading={isReloading}diff --git a/frontend/src/pages/organization/BillingV2Page/billing-v2-local-preview.ts b/frontend/src/pages/organization/BillingV2Page/billing-v2-local-preview.tsdeleted file mode 100644index e22585c482..0000000000--- a/frontend/src/pages/organization/BillingV2Page/billing-v2-local-preview.ts+++ /dev/null@@ -1,408 +0,0 @@-/* eslint-disable */-// ----------------------------------------------------------------------------------------------//-// To remove: delete this file and the LOCAL_PREVIEW block in BillingV2Page.tsx.-// ----------------------------------------------------------------------------------------------// ONE SWITCH for reviewing the layout. Flip this, save, and the page re-renders:-//-// "cloud" paying cloud customer: header tiles, payment card, invoices, no org picker-// "cloud-trial" self-serve cloud mid-trial: one trialing product, a card on file but nothing-// billed yet, and an available row mixing a sales-led product with a trialable one-// "cloud-managed" enterprise-managed cloud: Managed Billing notice, no Stripe sections-// "self-hosted" licensed instance: managed copy, instance-admin org picker, no Stripe cards-// "offline" air-gapped licence: the standalone OfflineBillingPage (nothing from this feature)-// "off" no faking at all; on a dev stack this shows "No products available"-// The usage-export type PreviewMode = "cloud" | "cloud-trial" | "cloud-managed" | "self-hosted" | "offline" | "off";-export const PREVIEW_MODE: PreviewMode = "self-hosted";--import { useMemo } from "react";-import { keepPreviousData, useQueries } from "@tanstack/react-query";--import { apiRequest } from "@app/config/request";-import {- BillingV2BreakdownScopeKind,- BillingV2CatalogProduct,- BillingV2Entitlement,- BillingV2EntitlementDim,- BillingV2Overview,- BillingV2UsageBreakdown-} from "@app/hooks/api";--const dim = (- key: string,- label: string,- noun: string,- used: number,- rate?: number-): BillingV2EntitlementDim => ({- key,- label,- noun,- unit: noun,- metered: true,- cadence: "monthly",- used,- limit: null,- committed: null,- commitAvailable: false,- rate,- onDemandAmount: 0-});--// A dimension the customer is eligible to commit annually but has not: the shape commitSavingsNudge-// looks for (dimCommittable = commitAvailable && !metered, no commitment, used > 0, both rates set).-// Rates are chosen so the savings come out around a third, which is what the strip prints.-const commitDim = (- key: string,- label: string,- noun: string,- used: number-): BillingV2EntitlementDim => ({- key,- label,- noun,- unit: noun,- metered: false,- cadence: "monthly",- used,- limit: null,- committed: null,- commitAvailable: true,- committedRate: 40,- onDemandRate: 5,- onDemandAmount: 0-});--const product = (- id: string,- name: string,- icon: string,- color: string,- tagline: string-): BillingV2CatalogProduct => ({- id,- name,- icon,- color,- tagline,- // Sales-led, so an unentitled product renders "Contact sales" rather than an Activate button, which- // is what production shows for these.- plans: [- {- tier: "enterprise",- name: "Enterprise",- selfServe: false,- salesLed: true,- trialable: false,- upgradeable: false,- trialDays: 0,- dims: []- }- ]-});--// Icon tokens and colours are approximations taken from a production screenshot, not the real catalog:-// a dev stack has no licence server to read it from. Expect these to differ from production in detail.-export const PREVIEW_CATALOG: BillingV2CatalogProduct[] = [- product(- "legacy_secrets",- "Legacy Secret Management",- "key_round",- "#7d7f80",- "The original per-identity secret management plan."- ),- product(- "secrets",- "Secrets Management",- "key_round",- "#e0ed34",- "Store, manage, and sync secrets across your stack."- ),- product(- "pki",- "Certificate Management",- "file_check",- "#ed8c34",- "Issue and manage X.509 certificates and private CAs."- ),- product(- "pam",- "Privileged Access Management",- "user_round_plus",- "#ff3568",- "Secure, broker, and audit privileged access."- )-];--// The licence server is what a dev stack lacks; the breakdown endpoint is local, scope-aware and-// reads the same tables the meters do. Pointing the cards at it makes every figure real and makes the-// organization picker move them: "All organizations" counts the whole database, one organization-// counts its tree. The numbers below are the fallback for a dimension whose request has not landed.-export const PREVIEW_DIMENSION_KEYS = [- "identities",- "user_identities",- "secret_identities",- "pam_identities",- "internal_cas",- "active_certs",- "wildcard_certs"-] as const;--export type PreviewUsage = Partial<Record<(typeof PREVIEW_DIMENSION_KEYS)[number], number>>;--// Off and offline fake nothing, so nothing is fetched for them either.-const INERT_MODES: PreviewMode[] = ["off", "offline"];-const IS_PREVIEW_ACTIVE = !INERT_MODES.includes(PREVIEW_MODE);--export const previewEntitlements = (usage: PreviewUsage = {}): Record<string, BillingV2Entitlement> => ({- // Two dimensions, as production shows: the combined identity meter plus the human-seat one.- legacy_secrets: {- entitled: true,- planTier: "enterprise",- cadence: "annual",- renewsOn: "November 3, 2026",- dimensions: [- dim("identities", "Identities", "identity", usage.identities ?? 25),- dim("user_identities", "User Identities", "user identity", usage.user_identities ?? 10)- ]- },- secrets: {- entitled: true,- planTier: "enterprise",- cadence: "monthly",- dimensions: [dim("secret_identities", "Secret Identities", "secret identity", usage.secret_identities ?? 15)]- },- // Several breakdownable dimensions, so the sheet renders its unit tabs. internal_cas is committable- // here, which is also what makes this the card that shows the breakdown strip and the commit nudge- // at the same time — the two are independent, so review how they stack.- pki: {- entitled: true,- planTier: "enterprise",- cadence: "monthly",- dimensions: [- commitDim("internal_cas", "Internal CAs", "internal CA", usage.internal_cas ?? 23),- dim("active_certs", "Active Certificates", "active certificate", usage.active_certs ?? 134),- dim("wildcard_certs", "Wildcard Certificates", "wildcard certificate", usage.wildcard_certs ?? 23)- ]- },- pam: {- entitled: true,- planTier: "enterprise",- cadence: "monthly",- dimensions: [dim("pam_identities", "PAM Identities", "PAM identity", usage.pam_identities ?? 54)]- }-});--export const PREVIEW_ENTITLEMENTS = previewEntitlements();--// "cloud-trial" is a self-serve cloud account partway through a trial, which the other cloud shapes do-// not reach: the plan badge and the Trial badge on one card, "Included" where a price would be, a card-// on file with nothing yet to charge, and an available row carrying both CTAs at once. Its own catalog,-// because PREVIEW_CATALOG is enterprise-shaped and every tile there is sales-led.-const plan = (- tier: string,- name: string,- { selfServe = false, salesLed = false, trialDays = 0 } = {}-): BillingV2CatalogProduct["plans"][number] => ({- tier,- name,- selfServe,- salesLed,- trialable: trialDays > 0,- upgradeable: selfServe,- trialDays,- dims: []-});--export const TRIAL_CATALOG: BillingV2CatalogProduct[] = [- {- ...product(- "secrets",- "Secrets Management",- "key_round",- "#e0ed34",- "Store, manage, and sync secrets across your stack."- ),- plans: [plan("pro", "Pro", { selfServe: true }), plan("enterprise", "Enterprise", { salesLed: true })]- },- product(- "pki",- "Certificate Management",- "file_check",- "#ed8c34",- "Issue and manage X.509 certificates and private CAs."- ),- {- ...product(- "pam",- "Privileged Access Management",- "user_round_plus",- "#ff3568",- "Secure, broker, and audit privileged access."- ),- plans: [plan("pro", "Pro", { selfServe: true, trialDays: 14 })]- }-];--// Only secrets is entitled, so the other two fall to the available row: pki sales-led ("Contact-// sales"), pam trialable ("Try free for 14 days").-export const trialEntitlements = (usage: PreviewUsage = {}): Record<string, BillingV2Entitlement> => ({- secrets: {- entitled: true,- planTier: "pro",- cadence: "monthly",- isTrialing: true,- trialEndsAt: "October 1, 2026",- dimensions: [- dim("secret_identities", "Secret Identities", "identity", usage.secret_identities ?? 0, 23)- ]- }-});--// One request per previewed dimension, keyed on the picked organization and scope, so switching the-// picker refetches and the cards move with it.-export const usePreviewUsage = (orgId: string, scope: BillingV2BreakdownScopeKind): PreviewUsage => {- const results = useQueries({- queries: PREVIEW_DIMENSION_KEYS.map((key) => ({- queryKey: ["billing-v2-preview-usage", orgId, key, scope] as const,- queryFn: async () => {- const {- data: { breakdown }- } = await apiRequest.get<{ breakdown: BillingV2UsageBreakdown }>(- `/api/v1/organizations/${orgId}/billing/v2/breakdowns/${key}`,- { params: { scope } }- );- return breakdown.total;- },- enabled: Boolean(orgId) && IS_PREVIEW_ACTIVE,- placeholderData: keepPreviousData,- retry: false- }))- });-- const totals = results.map((result) => result.data);- return useMemo(- () =>- Object.fromEntries(- PREVIEW_DIMENSION_KEYS.map((key, index) => [key, totals[index]]).filter(- ([, total]) => total !== undefined- )- ),- // eslint-disable-next-line react-hooks/exhaustive-deps- totals- );-};--// Two real cloud shapes, because they render very differently and both are worth reviewing.-//-// "cloud" is a paying self-serve customer: an active Stripe subscription, so the page shows the header-// stat tiles, the payment method card, the billing details card and the invoice list.-const CLOUD_BASE = {- isCloud: true as const,- mode: "self-serve" as const,- checkoutFrozen: false,- planName: "Enterprise"-};--export const asCloudOverview = (- overview: BillingV2Overview,- entitlements: Record<string, BillingV2Entitlement>-): BillingV2Overview => ({- ...overview,- ...CLOUD_BASE,- entitlements,- subState: "active",- selfServe: true,- billing: {- monthlyRecurring: 1240,- annualCommitted: 18000,- activeProductCount: PREVIEW_CATALOG.length,- nextCharge: {- amount: 1240,- at: "October 1, 2026",- productKeys: ["secrets"],- cadence: "monthly",- hasUsage: true- }- },- onDemandAmount: 84,- payment: { brand: "visa", last4: "4242", expMonth: 11, expYear: 2028 },- billingDetails: {- name: "Admin Org",- email: "[email protected]",- address: {- line1: "1 Example Street",- city: "San Francisco",- state: "CA",- postalCode: "94105",- country: "US"- },- taxIds: []- },- invoices: [- {- id: "in_3",- number: "INV-0003",- date: "September 1, 2026",- amount: 1240,- paid: true,- pdfUrl: null- },- {- id: "in_2",- number: "INV-0002",- date: "August 1, 2026",- amount: 1240,- paid: true,- pdfUrl: null- },- { id: "in_1", number: "INV-0001", date: "July 1, 2026", amount: 1156, paid: true, pdfUrl: null }- ]-});--export const asTrialCloudOverview = (- overview: BillingV2Overview,- entitlements: Record<string, BillingV2Entitlement>-): BillingV2Overview => ({- ...overview,- ...CLOUD_BASE,- entitlements,- planName: "Pro",- subState: "trialing",- selfServe: true,- // A trial charges nothing yet, so every figure in the header is empty while the card is on file.- billing: { monthlyRecurring: 0, annualCommitted: 0, activeProductCount: 1, nextCharge: null },- onDemandAmount: 0,- payment: { brand: "mastercard", last4: "7002", expMonth: 2, expYear: 2029 },- billingDetails: {- name: "Personal Org",- email: "[email protected]",- address: null,- taxIds: []- },- invoices: []-});--// "cloud-managed" is an enterprise-managed cloud org, which is what a real production account looked-// like: contract-billed, so there is no Stripe subscription and none of those sections render. selfServe-// false is what raises the Managed Billing notice.-//-// One thing this cannot reproduce: production also shows a Manage button on the active product. On this-// branch that needs overview.selfServe true, the same flag the Managed Billing notice needs false, so-// the two cannot both render. Production is on an older build where they could.-export const asManagedCloudOverview = (- overview: BillingV2Overview,- entitlements: Record<string, BillingV2Entitlement>-): BillingV2Overview => ({- ...overview,- ...CLOUD_BASE,- entitlements,- subState: "no-subscription",- selfServe: false,- billing: { monthlyRecurring: 0, annualCommitted: 0, activeProductCount: 1, nextCharge: null },- onDemandAmount: 0,- payment: null,- billingDetails: null,- invoices: []-});