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..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 { @@ -124,13 +125,7 @@ export function checkoutSkill(named?: unknown, projectDir = process.cwd()): stri } 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.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`. */ @@ -289,7 +284,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..1e6e15c1ef0 100644 --- a/packages/cli/src/server/sharePresentation.ts +++ b/packages/cli/src/server/sharePresentation.ts @@ -1,5 +1,6 @@ import type { LocalShareSpace, LocalShareState } from "@hyperframes/studio-server"; 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"; @@ -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" + ? 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(); +}