Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/cli/src/heygen/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
11 changes: 3 additions & 8 deletions packages/cli/src/heygen/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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`. */
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/server/sharePresentation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
},
);
6 changes: 5 additions & 1 deletion packages/cli/src/server/sharePresentation.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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,
};
}

Expand Down
21 changes: 21 additions & 0 deletions packages/cli/src/utils/checkoutLink.ts
Original file line number Diff line number Diff line change
@@ -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();
}
Loading