Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat: offer annual savings to monthly desktop subscribers (#7231)

Louis Beaumont50906fcff4af
diff --git a/.github/pr-assets/annual-plan-savings/README.md b/.github/pr-assets/annual-plan-savings/README.md
new file mode 100644
index 000000000..89e84b56a
--- /dev/null
+++ b/.github/pr-assets/annual-plan-savings/README.md
@@ -0,0 +1,26 @@
+# Annual billing banner evidence
+
+Actual Screenpipe frontend rendered in its browser-mock app shell with fictional account, billing, chat, and meeting fixtures. No customer data or live billing changes.
+
+- Product source: `34bd92a90`.
+- Before: recreated from base `91e37b48e` using the same account fixture, viewport, theme, and app route.
+- Desktop: 1440 × 960. Compact: 760 × 820, sidebar collapsed with the app shortcut.
+- Production fonts and theme styles loaded. Reduced motion enabled.
+- Native HTTP and browser-opening boundaries were mocked. No native build or real Stripe change was performed.
+- Temporary account seed, browser transport adapter, and capture configuration were removed before committing.
+
+| Screenshot | State |
+| --- | --- |
+| before.png | Baseline, no annual offer |
+| after.png | Monthly subscriber, light mode |
+| dark.png | Monthly subscriber, dark mode |
+| compact.png | Compact window with collapsed navigation |
+| keyboard-focus.png | Keyboard focus on Switch to annual |
+| opening.png | Browser opening, action disabled |
+| error.png | Browser launch failed, retry available |
+| opened.png | Browser opened, explicit confirmation still required |
+| dismissed.png | Keep monthly, persisted across reload |
+| already-annual.png | Annual subscriber, offer hidden |
+| meetings.png | Placement in the Meetings section |
+
+Browser assertions passed for the same-plan annual review URL, opening/error/retry states, persisted dismissal, hidden annual offer, and compact banner bounds. Final images were inspected at full size.
diff --git a/.github/pr-assets/annual-plan-savings/after.png b/.github/pr-assets/annual-plan-savings/after.png
new file mode 100644
index 000000000..7361085bd
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/after.png differ
diff --git a/.github/pr-assets/annual-plan-savings/already-annual.png b/.github/pr-assets/annual-plan-savings/already-annual.png
new file mode 100644
index 000000000..fd2c3270a
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/already-annual.png differ
diff --git a/.github/pr-assets/annual-plan-savings/before.png b/.github/pr-assets/annual-plan-savings/before.png
new file mode 100644
index 000000000..0dd40d535
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/before.png differ
diff --git a/.github/pr-assets/annual-plan-savings/compact.png b/.github/pr-assets/annual-plan-savings/compact.png
new file mode 100644
index 000000000..4704c6c69
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/compact.png differ
diff --git a/.github/pr-assets/annual-plan-savings/dark.png b/.github/pr-assets/annual-plan-savings/dark.png
new file mode 100644
index 000000000..5dc4e455e
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/dark.png differ
diff --git a/.github/pr-assets/annual-plan-savings/dismissed.png b/.github/pr-assets/annual-plan-savings/dismissed.png
new file mode 100644
index 000000000..aaee3b92c
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/dismissed.png differ
diff --git a/.github/pr-assets/annual-plan-savings/error.png b/.github/pr-assets/annual-plan-savings/error.png
new file mode 100644
index 000000000..429d5ed78
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/error.png differ
diff --git a/.github/pr-assets/annual-plan-savings/keyboard-focus.png b/.github/pr-assets/annual-plan-savings/keyboard-focus.png
new file mode 100644
index 000000000..5559df56a
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/keyboard-focus.png differ
diff --git a/.github/pr-assets/annual-plan-savings/meetings.png b/.github/pr-assets/annual-plan-savings/meetings.png
new file mode 100644
index 000000000..d90388502
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/meetings.png differ
diff --git a/.github/pr-assets/annual-plan-savings/opened.png b/.github/pr-assets/annual-plan-savings/opened.png
new file mode 100644
index 000000000..8ff3d6c83
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/opened.png differ
diff --git a/.github/pr-assets/annual-plan-savings/opening.png b/.github/pr-assets/annual-plan-savings/opening.png
new file mode 100644
index 000000000..ce9c4f701
Binary files /dev/null and b/.github/pr-assets/annual-plan-savings/opening.png differ
diff --git a/apps/screenpipe-app-tauri/app/(main)/home/page.tsx b/apps/screenpipe-app-tauri/app/(main)/home/page.tsx
index 5095367b7..cb5d77e33 100644
--- a/apps/screenpipe-app-tauri/app/(main)/home/page.tsx
+++ b/apps/screenpipe-app-tauri/app/(main)/home/page.tsx
@@ -55,6 +55,7 @@ import { useToast } from "@/components/ui/use-toast";
import { ToastAction } from "@/components/ui/toast";
import { Button } from "@/components/ui/button";
import { AppSidebar, useSidebarContext } from "@/components/app-sidebar";
+import { AnnualPlanBanner } from "@/components/annual-plan-banner";
import { UpdateBanner } from "@/components/update-banner";
import { usePlatform } from "@/lib/hooks/use-platform";
import { useIsFullscreen } from "@/lib/hooks/use-is-fullscreen";
@@ -1652,6 +1653,7 @@ function HomeContent() {
narrow window with the sidebar open the whole pane gets
clipped at the right window edge instead of truncating. */}
<div className={cn("flex-1 min-w-0 flex flex-col h-full bg-background min-h-0 relative", workflowsActive && "hidden", isTranslucent ? "rounded-none" : "rounded-tr-lg")} data-testid="home-page">
+ <AnnualPlanBanner />
{/* ALWAYS-MOUNTED chat layer.
Hidden via CSS (display:none) when the user is on a non-chat
section, so the StandaloneChat component never unmounts. This
diff --git a/apps/screenpipe-app-tauri/components/annual-plan-banner.test.tsx b/apps/screenpipe-app-tauri/components/annual-plan-banner.test.tsx
new file mode 100644
index 000000000..91ea4fed5
--- /dev/null
+++ b/apps/screenpipe-app-tauri/components/annual-plan-banner.test.tsx
@@ -0,0 +1,123 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
+import { AnnualPlanBanner } from "./annual-plan-banner";
+
+const mocks = vi.hoisted(() => ({
+ open: vi.fn(), fetch: vi.fn(),
+ user: { id: "fixture", token: "fixture-token", subscription_plan: "pro" } as any,
+ managed: false,
+}));
+vi.mock("@/lib/open-external-url", () => ({ openExternalUrl: mocks.open }));
+vi.mock("@/lib/http/tauri-fetch", () => ({ tauriFetchWithDeadline: mocks.fetch }));
+vi.mock("@/lib/hooks/use-settings", () => ({ useSettings: () => ({ settings: { user: mocks.user } }) }));
+vi.mock("@/lib/hooks/use-managed-policy", () => ({ useManagedPolicy: () => ({ isManagedDeployment: mocks.managed, isManagedDeploymentResolved: true }) }));
+const billing = { subscription_scope: "personal", subscription_status: "active", subscription_id: "sub-fixture", plan: "pro", active_subscription: { interval: "month", amount_cents: 5000, cancel_at_period_end: false, lifetime: false } };
+const options = { current: { tier: "pro", interval: "month", seats: 1 }, targets: [{ plan: "pro", tier: "pro", interval: "year", unitAmount: 500, perSeat: false, requiresSeats: false }] };
+const findSwitch = () => screen.findByRole("button", { name: "Switch to annual" });
+beforeEach(() => {
+ localStorage.clear();
+ mocks.user = { id: "fixture", token: "fixture-token", subscription_plan: "pro" };
+ mocks.managed = false;
+ mocks.open.mockResolvedValue(undefined);
+ mocks.fetch.mockImplementation(async (url: string) => new Response(JSON.stringify(url.includes("change-plan") ? options : billing)));
+});
+afterEach(() => { cleanup(); vi.resetAllMocks(); });
+
+describe("annual billing banner", () => {
+ it("opens a same-plan annual review without writing billing", async () => {
+ render(<AnnualPlanBanner />);
+ fireEvent.click(await findSwitch());
+ await screen.findByText(/Billing opened in your browser/);
+ expect(mocks.open).toHaveBeenCalledWith("https://screenpipe.com/account/billing?target_plan=pro&interval=year");
+ expect(mocks.fetch).toHaveBeenCalledTimes(2);
+ for (const [, init] of mocks.fetch.mock.calls) {
+ expect(init.method).toBeUndefined();
+ expect(init.headers.Authorization).toBe("Bearer fixture-token");
+ }
+ expect(screen.getByText(/Before discounts and taxes/)).toBeInTheDocument();
+ });
+ it("keeps the decline across remounts and scopes it to the account", async () => {
+ const first = render(<AnnualPlanBanner />);
+ await findSwitch();
+ fireEvent.click(screen.getByRole("button", { name: "Keep monthly" }));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ first.unmount();
+ const second = render(<AnnualPlanBanner />);
+ await waitFor(() => expect(mocks.fetch).toHaveBeenCalledTimes(4));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ mocks.user = { ...mocks.user, id: "other" };
+ second.rerender(<AnnualPlanBanner />);
+ await findSwitch();
+ expect(mocks.open).not.toHaveBeenCalled();
+ });
+ it("shows pending, suppresses repeated clicks, and recovers from an opening error", async () => {
+ let reject!: (reason: Error) => void;
+ mocks.open.mockImplementationOnce(() => new Promise((_, no) => { reject = no; }));
+ render(<AnnualPlanBanner />);
+ fireEvent.click(await findSwitch());
+ const pending = screen.getByRole("button", { name: "Opening billing…" });
+ expect(pending).toBeDisabled();
+ fireEvent.click(pending);
+ expect(mocks.open).toHaveBeenCalledTimes(1);
+ reject(new Error("browser unavailable"));
+ await screen.findByRole("alert");
+ fireEvent.click(screen.getByRole("button", { name: "Try again" }));
+ await screen.findByText(/Billing opened in your browser/);
+ });
+ it("fails quietly when billing cannot be verified", async () => {
+ mocks.fetch.mockRejectedValue(new Error("offline"));
+ render(<AnnualPlanBanner />);
+ await waitFor(() => expect(mocks.fetch).toHaveBeenCalledTimes(2));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ });
+ it.each(["annual", "workspace", "trial"])("hides live %s status", async state => {
+ mocks.fetch.mockImplementation(async (url: string) => new Response(JSON.stringify(url.includes("change-plan") ? options : { ...billing, ...(state === "workspace" ? { subscription_scope: "workspace" } : state === "trial" ? { subscription_status: "trialing" } : { active_subscription: { ...billing.active_subscription, interval: "year" } }) })));
+ render(<AnnualPlanBanner />);
+ await waitFor(() => expect(mocks.fetch).toHaveBeenCalledTimes(2));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ });
+ it("does not request billing for managed deployments or signed-out users", () => {
+ mocks.managed = true;
+ const view = render(<AnnualPlanBanner />);
+ mocks.managed = false; mocks.user = null;
+ view.rerender(<AnnualPlanBanner />);
+ expect(mocks.fetch).not.toHaveBeenCalled();
+ });
+ it("does not show an old account's delayed offer after sign-out", async () => {
+ let resolve!: (value: Response) => void;
+ mocks.fetch.mockImplementationOnce(() => new Promise(yes => { resolve = yes; }));
+ const view = render(<AnnualPlanBanner />);
+ mocks.user = null; view.rerender(<AnnualPlanBanner />);
+ resolve(new Response(JSON.stringify(billing)));
+ await waitFor(() => expect(screen.queryByTestId("annual-plan-banner")).toBeNull());
+ });
+});
+
+describe("annual offer revalidation", () => {
+ it("rechecks on return from billing even inside the focus throttle", async () => {
+ render(<AnnualPlanBanner />);
+ fireEvent.click(await findSwitch());
+ await screen.findByText(/Billing opened in your browser/);
+ mocks.fetch.mockImplementation(async (url: string) => new Response(JSON.stringify(url.includes("change-plan") ? options : { ...billing, active_subscription: { ...billing.active_subscription, interval: "year" } })));
+ fireEvent.focus(window);
+ await waitFor(() => expect(mocks.fetch).toHaveBeenCalledTimes(4));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ });
+ it("still dismisses when local storage is unavailable", async () => {
+ const set = vi.spyOn(Storage.prototype, "setItem").mockImplementation(() => { throw new Error("blocked"); });
+ try {
+ render(<AnnualPlanBanner />);
+ await findSwitch();
+ fireEvent.click(screen.getByRole("button", { name: "Keep monthly" }));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ } finally { set.mockRestore(); }
+ });
+ it("never presents fallback prices for malformed or rejected responses", async () => {
+ mocks.fetch.mockResolvedValue(new Response("{}", { status: 503 }));
+ render(<AnnualPlanBanner />);
+ await waitFor(() => expect(mocks.fetch).toHaveBeenCalledTimes(2));
+ expect(screen.queryByTestId("annual-plan-banner")).toBeNull();
+ });
+});
diff --git a/apps/screenpipe-app-tauri/components/annual-plan-banner.tsx b/apps/screenpipe-app-tauri/components/annual-plan-banner.tsx
new file mode 100644
index 000000000..9c5e6cca9
--- /dev/null
+++ b/apps/screenpipe-app-tauri/components/annual-plan-banner.tsx
@@ -0,0 +1,156 @@
+"use client";
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+import { useEffect, useRef, useState } from "react";
+import { ArrowUpRight, Loader2 } from "lucide-react";
+import { useGT } from "gt-react";
+import { Button } from "@/components/ui/button";
+import { useSettings } from "@/lib/hooks/use-settings";
+import { useManagedPolicy } from "@/lib/hooks/use-managed-policy";
+import { openExternalUrl } from "@/lib/open-external-url";
+import { tauriFetchWithDeadline } from "@/lib/http/tauri-fetch";
+import { screenpipeWebUrl } from "@/lib/web-url";
+import { annualOfferDismissalKey, getAnnualPlanOffer, type AnnualPlanOffer } from "@/lib/annual-plan-offer";
+
+const money = (amount: number) => new Intl.NumberFormat(undefined, {
+ style: "currency", currency: "USD", maximumFractionDigits: 2,
+ minimumFractionDigits: Number.isInteger(amount) ? 0 : 2,
+}).format(amount);
+
+export function AnnualPlanBannerView({ offer, onDismiss, onOpened }: {
+ offer: AnnualPlanOffer;
+ onDismiss: () => void;
+ onOpened?: () => void;
+}) {
+ const ui = useGT();
+ const [state, setState] = useState<"idle" | "opening" | "opened" | "error">("idle");
+ const opening = useRef(false);
+
+ const reviewAnnual = async () => {
+ if (opening.current) return;
+ opening.current = true;
+ setState("opening");
+ try {
+ const url = new URL(screenpipeWebUrl("/account/billing", "https://screenpipe.com"));
+ url.searchParams.set("target_plan", offer.plan);
+ url.searchParams.set("interval", "year");
+ await openExternalUrl(url.toString());
+ setState("opened");
+ onOpened?.();
+ } catch {
+ setState("error");
+ } finally {
+ opening.current = false;
+ }
+ };
+
+ return (
+ <section aria-label={ui("Annual billing option")} data-testid="annual-plan-banner"
+ className="shrink-0 border-b border-border bg-muted/40 px-5 pb-4 pt-9 text-foreground">
+ <div className="flex flex-wrap items-center justify-between gap-x-6 gap-y-3">
+ <div className="min-w-0">
+ <p style={{ fontFamily: "var(--font-workflow-heading), system-ui, sans-serif" }} className="text-sm font-semibold">
+ {ui("Save {savings} a year with annual billing", { savings: money(offer.savingsAmount) })}
+ </p>
+ <p className="mt-1 text-xs leading-relaxed text-muted-foreground">
+ {ui("{amount} billed yearly. Before discounts and taxes. Review before confirming.", { amount: money(offer.annualAmount) })}
+ </p>
+ </div>
+ <div className="flex shrink-0 flex-wrap items-center gap-2">
+ <Button size="sm" onClick={reviewAnnual} disabled={state === "opening"}
+ className="gap-1.5" aria-describedby="annual-billing-status">
+ {state === "opening" ? <Loader2 aria-hidden="true" className="h-3.5 w-3.5 animate-spin motion-reduce:animate-none" /> : <ArrowUpRight aria-hidden="true" className="h-3.5 w-3.5" />}
+ {state === "opening" ? ui("Opening billing…") : state === "error" ? ui("Try again") : state === "opened" ? ui("Reopen billing") : ui("Switch to annual")}
+ </Button>
+ <Button size="sm" variant="ghost" onClick={onDismiss}>{ui("Keep monthly")}</Button>
+ </div>
+ </div>
+ <p id="annual-billing-status" role={state === "error" ? "alert" : "status"}
+ className={state === "idle" || state === "opening" ? "sr-only" : `mt-2 text-xs leading-relaxed ${state === "error" ? "text-destructive" : "text-muted-foreground"}`}>
+ {state === "error" ? ui("Couldn’t open billing. Try again. Your plan hasn’t changed.")
+ : state === "opened" ? ui("Billing opened in your browser. Your plan changes only after you confirm there.")
+ : ui("Review the final price in your browser before confirming.")}
+ </p>
+ </section>
+ );
+}
+
+function EligibleAnnualPlanBanner({ userId, token }: { userId: string; token: string }) {
+ const [offer, setOffer] = useState<AnnualPlanOffer | null>(null);
+ const [dismissed, setDismissed] = useState(false);
+ const refreshOnFocus = useRef(false);
+
+ useEffect(() => {
+ let active = true;
+ let inFlight = false;
+ let lastChecked = 0;
+ const controller = new AbortController();
+ const check = async () => {
+ if (inFlight || (!refreshOnFocus.current && Date.now() - lastChecked < 30_000)) return;
+ refreshOnFocus.current = false;
+ inFlight = true;
+ // Hide stale pricing while revalidating after returning from billing.
+ setOffer(null);
+ const deadline = new AbortController();
+ const abort = () => deadline.abort();
+ controller.signal.addEventListener("abort", abort);
+ const timeout = setTimeout(abort, 8_000);
+ try {
+ const read = async (path: string) => {
+ const response = await tauriFetchWithDeadline(screenpipeWebUrl(path, "https://screenpipe.com"), {
+ headers: { Authorization: `Bearer ${token}` }, signal: deadline.signal,
+ cache: "no-store",
+ }, { timeoutMs: 8_000 });
+ if (!response.ok) throw new Error("Billing unavailable");
+ return response.json();
+ };
+ const [billing, options] = await Promise.all([
+ read("/api/billing"), read("/api/subscription/change-plan"),
+ ]);
+ const next = getAnnualPlanOffer(billing, options);
+ if (!active) return;
+ let hidden = false;
+ if (next) {
+ try { hidden = localStorage.getItem(annualOfferDismissalKey(userId, next.subscriptionId)) === "true"; }
+ catch { /* A blocked store must not break the app. */ }
+ }
+ setDismissed(hidden);
+ setOffer(next);
+ } catch {
+ if (active) setOffer(null); // Optional offer: fail quietly, never invent a price.
+ } finally {
+ clearTimeout(timeout);
+ controller.signal.removeEventListener("abort", abort);
+ lastChecked = Date.now();
+ inFlight = false;
+ }
+ };
+ const onVisible = () => { if (document.visibilityState === "visible") void check(); };
+ void check();
+ window.addEventListener("focus", check);
+ document.addEventListener("visibilitychange", onVisible);
+ return () => {
+ active = false;
+ controller.abort();
+ window.removeEventListener("focus", check);
+ document.removeEventListener("visibilitychange", onVisible);
+ };
+ }, [userId, token]);
+
+ if (!offer || dismissed) return null;
+ return <AnnualPlanBannerView offer={offer} onOpened={() => { refreshOnFocus.current = true; }} onDismiss={() => {
+ setDismissed(true);
+ try { localStorage.setItem(annualOfferDismissalKey(userId, offer.subscriptionId), "true"); }
+ catch { /* Still honor the choice for this session. */ }
+ }} />;
+}
+
+export function AnnualPlanBanner() {
+ const { settings } = useSettings();
+ const { isManagedDeployment, isManagedDeploymentResolved } = useManagedPolicy();
+ const user = settings.user;
+ if (!isManagedDeploymentResolved || isManagedDeployment || !user?.id || !user.token ||
+ !["standard", "pro"].includes(user.subscription_plan ?? "")) return null;
+ return <EligibleAnnualPlanBanner key={`${user.id}:${user.token}`} userId={user.id} token={user.token} />;
+}
diff --git a/apps/screenpipe-app-tauri/lib/annual-plan-offer.test.ts b/apps/screenpipe-app-tauri/lib/annual-plan-offer.test.ts
new file mode 100644
index 000000000..2dcafb570
--- /dev/null
+++ b/apps/screenpipe-app-tauri/lib/annual-plan-offer.test.ts
@@ -0,0 +1,41 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import { describe, expect, it } from "vitest";
+import { annualOfferDismissalKey, getAnnualPlanOffer } from "./annual-plan-offer";
+
+export const billing = {
+ subscription_scope: "personal", subscription_status: "active", subscription_id: "sub-fixture",
+ plan: "pro", active_subscription: { interval: "month", amount_cents: 5000, cancel_at_period_end: false, lifetime: false },
+};
+export const options = {
+ current: { tier: "pro", interval: "month", seats: 1 },
+ targets: [{ plan: "pro", tier: "pro", interval: "year", unitAmount: 500, perSeat: false, requiresSeats: false }],
+};
+describe("annual plan eligibility", () => {
+ it("uses the live same-tier annual target and converts cents once", () => {
+ expect(getAnnualPlanOffer(billing, options)).toEqual({ subscriptionId: "sub-fixture", plan: "pro", annualAmount: 500, savingsAmount: 100 });
+ expect(getAnnualPlanOffer({ ...billing, plan: "standard", active_subscription: { ...billing.active_subscription, amount_cents: 2500 } }, { current: { tier: "standard", interval: "month", seats: 1 }, targets: [{ ...options.targets[0], plan: "standard", tier: "standard", unitAmount: 250 }] })?.savingsAmount).toBe(50);
+ });
+ it.each(["trialing", "past_due", "unpaid", "canceled", "incomplete"])("hides %s accounts", status => {
+ expect(getAnnualPlanOffer({ ...billing, subscription_status: status }, options)).toBeNull();
+ });
+ it.each([
+ { interval: "year" }, { interval: null }, { cancel_at_period_end: true }, { lifetime: true },
+ { amount_cents: null }, { amount_cents: 0 }, { amount_cents: 1000 },
+ ])("hides ineligible billing snapshots %j", active => {
+ expect(getAnnualPlanOffer({ ...billing, active_subscription: { ...billing.active_subscription, ...active } }, options)).toBeNull();
+ });
+ it.each(["workspace", "grant", null])("hides scope %s", scope => {
+ expect(getAnnualPlanOffer({ ...billing, subscription_scope: scope }, options)).toBeNull();
+ });
+ it("does not invent prices or upsell a different tier", () => {
+ for (const data of [null, {}, { ...options, targets: [] }, { ...options, current: { ...options.current, interval: "year" } }, { ...options, current: { ...options.current, seats: 5 } }, { ...options, targets: [{ ...options.targets[0], tier: "standard" }] }, { ...options, targets: [{ ...options.targets[0], unitAmount: "500" }] }]) {
+ expect(getAnnualPlanOffer(billing, data)).toBeNull();
+ }
+ expect(getAnnualPlanOffer(null, options)).toBeNull();
+ });
+ it("scopes dismissal to the account and subscription, not the price", () => {
+ expect(annualOfferDismissalKey("a", "one")).not.toBe(annualOfferDismissalKey("b", "one"));
+ expect(annualOfferDismissalKey("a", "one")).not.toBe(annualOfferDismissalKey("a", "two"));
+ });
+});
diff --git a/apps/screenpipe-app-tauri/lib/annual-plan-offer.ts b/apps/screenpipe-app-tauri/lib/annual-plan-offer.ts
new file mode 100644
index 000000000..70875c307
--- /dev/null
+++ b/apps/screenpipe-app-tauri/lib/annual-plan-offer.ts
@@ -0,0 +1,51 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+
+export type AnnualPlanOffer = {
+ subscriptionId: string;
+ plan: "standard" | "pro";
+ annualAmount: number;
+ savingsAmount: number;
+};
+
+/** Both responses are live, authenticated reads. Never infer cadence from the
+ * entitlement's plan label, which is identical for monthly and annual users.
+ * change-plan's unitAmount is in USD dollars; billing's amount_cents is cents.
+ * These are base rates, before customer discounts and taxes. */
+export function getAnnualPlanOffer(billing: any, options: any): AnnualPlanOffer | null {
+ const active = billing?.active_subscription;
+ const current = options?.current;
+ if (
+ billing?.subscription_scope !== "personal" ||
+ billing?.subscription_status !== "active" ||
+ typeof billing?.subscription_id !== "string" ||
+ !billing.subscription_id ||
+ active?.interval !== "month" ||
+ active?.cancel_at_period_end !== false ||
+ active?.lifetime !== false ||
+ !Number.isSafeInteger(active?.amount_cents) || active.amount_cents <= 0 ||
+ current?.interval !== "month" || current?.seats !== 1 ||
+ !["standard", "pro"].includes(current?.tier) ||
+ billing?.plan !== current.tier ||
+ !Array.isArray(options?.targets)
+ ) return null;
+
+ const target = options.targets.find((candidate: any) =>
+ candidate?.tier === current.tier && candidate?.plan === current.tier &&
+ candidate?.interval === "year" && candidate?.perSeat === false &&
+ candidate?.requiresSeats === false,
+ );
+ if (!Number.isFinite(target?.unitAmount) || target.unitAmount <= 0) return null;
+ const savingsAmount = Math.round((active.amount_cents * 12 - target.unitAmount * 100)) / 100;
+ if (savingsAmount <= 0) return null;
+ return {
+ subscriptionId: billing.subscription_id,
+ plan: current.tier,
+ annualAmount: target.unitAmount,
+ savingsAmount,
+ };
+}
+
+export function annualOfferDismissalKey(userId: string, subscriptionId: string) {
+ return `screenpipe:annual-plan-dismissed:v1:${userId}:${subscriptionId}`;
+}