From 442c797d3a58fb1bab2d0f2072e6056a5f454cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 18:16:05 +0000 Subject: [PATCH 1/2] fix(cli): carry from=cli on every HyperFrames pricing and upgrade link --- packages/cli/src/heygen/plan.test.ts | 25 ++++++++++++++++++- packages/cli/src/heygen/plan.ts | 15 +++++++++-- .../cli/src/server/sharePresentation.test.ts | 4 ++- packages/cli/src/server/sharePresentation.ts | 6 ++++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/heygen/plan.test.ts b/packages/cli/src/heygen/plan.test.ts index 11edeb64105..c969ce6dd03 100644 --- a/packages/cli/src/heygen/plan.test.ts +++ b/packages/cli/src/heygen/plan.test.ts @@ -313,14 +313,37 @@ describe("where a purchase came from", () => { ); }); - it("marks the server's own pricing link as the CLI's, keeping what it already says", () => { + it("marks any HyperFrames pricing link as the CLI's, keeping what it already says", () => { expect(cliCheckoutLink("https://hyperframes.studio/pricing?feature=reverse&rs=1", "x")).toBe( "https://hyperframes.studio/pricing?feature=reverse&rs=1&from=cli&skill=x&utm_source=cli", ); + expect( + cliCheckoutLink("https://dev.hyperframes.studio/pricing?feature=reverse&rs=1", "x"), + ).toBe( + "https://dev.hyperframes.studio/pricing?feature=reverse&rs=1&from=cli&skill=x&utm_source=cli", + ); + expect(cliCheckoutLink("https://hyperframes.dev/pricing?entry=local_studio_share", "")).toBe( + "https://hyperframes.dev/pricing?entry=local_studio_share&from=cli&utm_source=cli", + ); + expect(cliCheckoutLink("https://dev.hyperframes.dev/pricing", "")).toBe( + "https://dev.hyperframes.dev/pricing?from=cli&utm_source=cli", + ); + expect(cliCheckoutLink("https://hyperframes.heygen.com/pricing", "")).toBe( + "https://hyperframes.heygen.com/pricing?from=cli&utm_source=cli", + ); expect(cliCheckoutLink("https://hyperframes.studio/pricing?from=desktop&skill=y", "x")).toBe( "https://hyperframes.studio/pricing?from=desktop&skill=y&utm_source=cli", ); expect(cliCheckoutLink("https://pay.test/credits", "x")).toBe("https://pay.test/credits"); + expect(cliCheckoutLink("https://evil-hyperframes.studio/pricing", "x")).toBe( + "https://evil-hyperframes.studio/pricing", + ); + expect(cliCheckoutLink("https://hyperframes.dev.evil.test/pricing", "x")).toBe( + "https://hyperframes.dev.evil.test/pricing", + ); + expect(cliCheckoutLink("http://hyperframes.studio/pricing", "x")).toBe( + "http://hyperframes.studio/pricing", + ); }); it("sends a terminal Pro checkout back to the plans page marked as the CLI's, with the skill", async () => { diff --git a/packages/cli/src/heygen/plan.ts b/packages/cli/src/heygen/plan.ts index 072fcdfdc8b..2b87ca374d1 100644 --- a/packages/cli/src/heygen/plan.ts +++ b/packages/cli/src/heygen/plan.ts @@ -123,10 +123,21 @@ export function checkoutSkill(named?: unknown, projectDir = process.cwd()): stri return normalizeSkillSlug(named) ?? readProjectConfig(projectDir)?.authoringSkill; } +function isHyperFramesHost(hostname: string): boolean { + const host = hostname.toLowerCase(); + return ( + host === "hyperframes.studio" || + host.endsWith(".hyperframes.studio") || + host === "hyperframes.dev" || + host.endsWith(".hyperframes.dev") || + host === "hyperframes.heygen.com" + ); +} + export function cliCheckoutLink(link: string, skill = checkoutSkill()): string { if (!URL.canParse(link)) return link; const url = new URL(link); - if (url.hostname !== new URL(webBase()).hostname) return link; + if (url.protocol !== "https:" || !isHyperFramesHost(url.hostname)) return link; if (!url.searchParams.has("from")) url.searchParams.set("from", "cli"); if (skill && !url.searchParams.has("skill")) url.searchParams.set("skill", skill); if (!url.searchParams.has("utm_source")) url.searchParams.set("utm_source", "cli"); @@ -289,7 +300,7 @@ export async function createCheckout( try { return await postCheckout("checkout", { ...pro(), return_url: returnUrl }, source.stop); } catch (error) { - // A server whose allow-list lacks the plans page still sells Pro, only without the CLI's origin. + // A server whose allow-list lacks the plans page still sells Pro; X-HeyGen-Source still names the CLI. const refused = error instanceof CheckoutError && error.reason === "checkout_rejected"; if (!refused || !RETURN_REFUSED.test(error.message)) throw error; trackBillingCheckoutReturnRefused(); diff --git a/packages/cli/src/server/sharePresentation.test.ts b/packages/cli/src/server/sharePresentation.test.ts index 9b406c419dc..2d6f9b0a5cb 100644 --- a/packages/cli/src/server/sharePresentation.test.ts +++ b/packages/cli/src/server/sharePresentation.test.ts @@ -18,7 +18,9 @@ it.each(["free", "subscribed", undefined] as const)( const [result] = presentSpaces([space]); expect(result?.plan).toBe(plan ?? null); expect(result?.upgradeUrl).toBe( - plan === "free" ? "https://hyperframes.dev/pricing?entry=local_studio_share" : null, + plan === "free" + ? "https://hyperframes.dev/pricing?entry=local_studio_share&from=cli&utm_source=cli" + : null, ); }, ); diff --git a/packages/cli/src/server/sharePresentation.ts b/packages/cli/src/server/sharePresentation.ts index 16d3bad30a2..f7efc88dd43 100644 --- a/packages/cli/src/server/sharePresentation.ts +++ b/packages/cli/src/server/sharePresentation.ts @@ -1,4 +1,5 @@ import type { LocalShareSpace, LocalShareState } from "@hyperframes/studio-server"; +import { cliCheckoutLink } from "../heygen/plan.js"; import { shareSite } from "../share/auth.js"; import { namedWorkspace } from "../share/workspace.js"; import type { ShareService, ShareState } from "../share/service.js"; @@ -54,7 +55,10 @@ function planOffer( const plan = entitlements?.plan ?? null; return { plan, - upgradeUrl: plan === "free" ? `${shareSite()}/pricing?entry=local_studio_share` : null, + upgradeUrl: + plan === "free" + ? cliCheckoutLink(`${shareSite()}/pricing?entry=local_studio_share`, "") + : null, }; } From 10bd4f4c466824370afb648a7ac042952eb5cc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 18:35:23 +0000 Subject: [PATCH 2/2] refactor(cli): move pure checkout link helper into utils/checkoutLink --- packages/cli/src/heygen/plan.ts | 20 ++----------------- packages/cli/src/server/sharePresentation.ts | 4 ++-- packages/cli/src/utils/checkoutLink.ts | 21 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 packages/cli/src/utils/checkoutLink.ts diff --git a/packages/cli/src/heygen/plan.ts b/packages/cli/src/heygen/plan.ts index 2b87ca374d1..e6b89f47d3e 100644 --- a/packages/cli/src/heygen/plan.ts +++ b/packages/cli/src/heygen/plan.ts @@ -6,6 +6,7 @@ import { envCredentialVar, resolveCredential } from "../auth/resolver.js"; import { refreshIfNeeded, resolveCloudAuthHeaders, resolveCloudBaseUrl } from "../cloud/auth.js"; import { trackBillingCheckoutReturnRefused } from "../telemetry/events.js"; import { normalizeSkillSlug } from "../telemetry/skill.js"; +import { markCliCheckoutLink } from "../utils/checkoutLink.js"; import { readProjectConfig } from "../utils/projectConfig.js"; export interface Plan { @@ -123,25 +124,8 @@ export function checkoutSkill(named?: unknown, projectDir = process.cwd()): stri return normalizeSkillSlug(named) ?? readProjectConfig(projectDir)?.authoringSkill; } -function isHyperFramesHost(hostname: string): boolean { - const host = hostname.toLowerCase(); - return ( - host === "hyperframes.studio" || - host.endsWith(".hyperframes.studio") || - host === "hyperframes.dev" || - host.endsWith(".hyperframes.dev") || - host === "hyperframes.heygen.com" - ); -} - export function cliCheckoutLink(link: string, skill = checkoutSkill()): string { - if (!URL.canParse(link)) return link; - const url = new URL(link); - if (url.protocol !== "https:" || !isHyperFramesHost(url.hostname)) return link; - if (!url.searchParams.has("from")) url.searchParams.set("from", "cli"); - if (skill && !url.searchParams.has("skill")) url.searchParams.set("skill", skill); - if (!url.searchParams.has("utm_source")) url.searchParams.set("utm_source", "cli"); - return url.toString(); + return markCliCheckoutLink(link, skill); } /** A plans, credits or plan-management page link with what the web side reads, incl. the signed-in `workspace_hint`. */ diff --git a/packages/cli/src/server/sharePresentation.ts b/packages/cli/src/server/sharePresentation.ts index f7efc88dd43..1e6e15c1ef0 100644 --- a/packages/cli/src/server/sharePresentation.ts +++ b/packages/cli/src/server/sharePresentation.ts @@ -1,6 +1,6 @@ import type { LocalShareSpace, LocalShareState } from "@hyperframes/studio-server"; -import { cliCheckoutLink } from "../heygen/plan.js"; import { shareSite } from "../share/auth.js"; +import { markCliCheckoutLink } from "../utils/checkoutLink.js"; import { namedWorkspace } from "../share/workspace.js"; import type { ShareService, ShareState } from "../share/service.js"; @@ -57,7 +57,7 @@ function planOffer( plan, upgradeUrl: plan === "free" - ? cliCheckoutLink(`${shareSite()}/pricing?entry=local_studio_share`, "") + ? markCliCheckoutLink(`${shareSite()}/pricing?entry=local_studio_share`) : null, }; } diff --git a/packages/cli/src/utils/checkoutLink.ts b/packages/cli/src/utils/checkoutLink.ts new file mode 100644 index 00000000000..c46c107f485 --- /dev/null +++ b/packages/cli/src/utils/checkoutLink.ts @@ -0,0 +1,21 @@ +function isHyperFramesHost(hostname: string): boolean { + const host = hostname.toLowerCase(); + return ( + host === "hyperframes.studio" || + host.endsWith(".hyperframes.studio") || + host === "hyperframes.dev" || + host.endsWith(".hyperframes.dev") || + host === "hyperframes.heygen.com" + ); +} + +/** Marks an HTTPS HyperFrames link with `from=cli`, `utm_source=cli`, and an optional `skill`. */ +export function markCliCheckoutLink(link: string, skill?: string): string { + if (!URL.canParse(link)) return link; + const url = new URL(link); + if (url.protocol !== "https:" || !isHyperFramesHost(url.hostname)) return link; + if (!url.searchParams.has("from")) url.searchParams.set("from", "cli"); + if (skill && !url.searchParams.has("skill")) url.searchParams.set("skill", skill); + if (!url.searchParams.has("utm_source")) url.searchParams.set("utm_source", "cli"); + return url.toString(); +}