Public: anyone can read this; the crew can change it.
The signed-out /pricing page names what a forge costs per month in one line above the plans and links checkout #13084
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13045-the-signed-out-pricing-page-names-what-a → main 10 commits fork 4 threads · 4 unresolved
7 files
changed +111
−10
docs/features/README.md +1
| @@ -453,3 +453,4 @@ Read with the guide page [When something is wrong](../guide-when-wrong.md). | ||
| 453 | 453 | - [](rule-watcher.md) |
| 454 | 454 | - [](crew-try-again.md) |
| 455 | 455 | - [](map-held.md) |
| 456 | - [](pricing-price-line.md) |
docs/features/pricing-price-line.md added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | # The price of a forge, first on /pricing | |
| 2 | ||
| 3 | The signed-out `/pricing` page and the terminal's **Get a forge** screen open with the price of a forge: "A forge is $19 a month." (#13045). It is the cheapest paid plan, read from the plans setting (`/admin/limits`), so a change of price changes the line; with no paid plan it says "A forge is free". | |
| 4 | ||
| 5 | - Web: it is the page head's one sub, the only sentence under the title. Signed-in buyers keep "Pick a plan, name it, pay." | |
| 6 | - Terminal: the first line of the screen. | |
| 7 | - It shows only where a checkout is connected; without one, the paid plans say "Ask the operator" and no price is promised. Previews and fresh installs have no provider, so they show that page instead. | |
| 8 | - To see it: sign in as an admin, open Settings → Billing → Provider and paste a Stripe key (a test-mode `sk_test_…` key is enough; `docs/PROFIT.md` says how), then open `/pricing` signed out. | |
| 9 | - There is no separate checkout address to open: checkout starts when the order form on the page is sent. |
src/billing/plan_words.ts +10 −1
| @@ -13,7 +13,10 @@ export interface PlanWords { | ||
| 13 | 13 | readonly name: string; |
| 14 | 14 | /** "Free" or "$19 a month". */ |
| 15 | 15 | readonly price: string; |
| 16 | /** The machine, the plan's own line, then a paid plan's credit: "1 CPU, 2 GB memory, 2 GB disk. A small forge… $5 of crew credit each month." */ | |
| 16 | /** | |
| 17 | * The machine, the plan's own line, then a paid plan's credit: "1 CPU, 2 GB memory, 2 GB disk. A | |
| 18 | * small forge… $5 of crew credit each month." | |
| 19 | */ | |
| 17 | 20 | readonly is: string; |
| 18 | 21 | /** The https buy link for the plan's size, only on a paid plan and only when set. */ |
| 19 | 22 | readonly buy: string | undefined; |
| @@ -34,5 +37,11 @@ export function planWords(p: Plan, links: BillingLinks = {}): PlanWords { | ||
| 34 | 37 | /** Said under the plans, on the web and in the terminal, whenever a plan carries a buy link. */ |
| 35 | 38 | export const AFTER_PAYMENT = "Your forge is made after payment; an email with the link to open it arrives."; |
outdated
"first build free" is fixed text that nothing in Plan expresses; it is a promise the data does not back. Derive it or drop it. The all-free branch repeats "free" twice and reads oddly. |
||
| 36 | 39 | |
| 40 | /** What a stranger reads first: the cheapest paid plan, priced from the plans, never typed. */ | |
| 41 | export function priceLine(plans: readonly Plan[]): string { | |
| 42 | const paid = plans.filter((p) => p.priceUsd > 0).map((p) => p.priceUsd); | |
| 43 | return paid.length === 0 ? "A forge is free" : `A forge is $${Math.min(...paid)} a month`; | |
| 44 | } | |
| 45 | ||
| 37 | 46 | /** Where the home's one button and the terminal's pointer send a person for a hosted forge. */ |
| 38 | 47 | export const GET_A_FORGE_PATH = "/forges/new"; |
src/tui/screens/pricing.ts +5 −2
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder } from "../../actions/order.ts"; |
| 13 | import { priceLine } from "../../billing/plan_words.ts"; | |
| 13 | 14 | import { checkoutOf } from "../../billing/checkout.ts"; |
| 14 | 15 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 15 | 16 | import { bucketOf } from "../../http/peer.ts"; |
| @@ -145,7 +146,7 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen { | ||
| 145 | 146 | return; |
| 146 | 147 | } |
| 147 | 148 | const selling = checkoutOf(f.app) !== undefined; |
| 148 | line(selling ? "Get your own forge: pick a plan, name it, pay. Free: use Start my forge." : "Plans. Paid plans are not on sale here yet: ask the operator.", c.mutedFg); | |
| 149 | line(selling ? `${priceLine(plans())}. Pick a plan, name it, pay. Free: use Start my forge.` : "Plans. Paid plans are not on sale here yet: ask the operator.", c.mutedFg); | |
| 149 | 150 | y++; |
| 150 | 151 | const list = paid(); |
| 151 | 152 | for (const p of plans()) { |
| @@ -213,7 +214,9 @@ export function pricingScreen(f: Session, ctx: Ctx): Screen { | ||
| 213 | 214 | }; |
| 214 | 215 | } |
| 215 | 216 | |
| 216 | /** Offered to everyone: the sale is open to a guest and to a signed-in person alike, as on the web. */ | |
| 217 | /** | |
| 218 | * Offered to everyone: the sale is open to a guest and to a signed-in person alike, as on the web. | |
| 219 | */ | |
| 217 | 220 | export const pricingCommand = (session: Session, ctx: Ctx) => ({ |
| 218 | 221 | id: "pricing", |
| 219 | 222 | title: "Get a forge (plans)", |
src/web/pages/pricing.ts +10 −5
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | import { setCookie } from "../../auth/cookies.ts"; |
| 10 | 10 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts"; |
| 11 | 11 | import { lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; |
| 12 | import { priceLine } from "../../billing/plan_words.ts"; | |
| 12 | 13 | import { checkoutOf } from "../../billing/checkout.ts"; |
| 13 | 14 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| 14 | 15 | import { cookieValue, type Ctx } from "../../http/context.ts"; |
| @@ -40,7 +41,8 @@ interface Values { | ||
| 40 | 41 | const isBuyer = (ctx: Ctx): boolean => ctx.auth.user === undefined || ctx.auth.user.kind === "user"; |
| 41 | 42 | |
| 42 | 43 | function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["field"], string>>): Html { |
| 43 | // The order this browser paid for, from its own cookie: the page that opens it needs the address of the order. | |
| 44 | // The order this browser paid for, from its own cookie: the page that opens it needs the address | |
| 45 | // of the order. | |
| 44 | 46 | const held = (cookieValue(ctx.request, COOKIE) ?? "").split(".")[0] ?? ""; |
| 45 | 47 | const ordered = /^ord_[0-9a-f]{32}$/.test(held) ? held : undefined; |
| 46 | 48 | const selling = checkoutOf(ctx.app) !== undefined; |
| @@ -55,7 +57,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 55 | 57 | return planOfferRow({ key: p.key, name: p.name, says: `${sizeWords(p.size)}. ${p.says}${credit}`, price, action: act }); |
| 56 | 58 | }); |
| 57 | 59 | return html`<div class="narrow-wide" id="pricing" data-pricing> |
| 58 | ${pageHead("Get your own forge", { sub: selling ? "Pick a plan, name it, pay. Your forge is ready a minute later." : "Pick a size and name it." })} | |
| 60 | ${pageHead("Get your own forge", { sub: !selling ? "Pick a size and name it." : ctx.auth.user === undefined ? `${priceLine(plans)}.` : "Pick a plan, name it, pay. Your forge is ready a minute later." })} | |
Non-blocking: three-way nested ternary inside the pageHead call; lift it into a named const above so the page head reads at a glance. |
||
| 59 | 61 | ${errors["form"] ? html`<p class="error" role="alert">${errors["form"]}</p>` : null} |
| 60 | 62 | <form method="post" action="/pricing/order" class="stack" id="order"> |
| 61 | 63 | ${formField({ |
| @@ -105,7 +107,8 @@ export function pricingPage(ctx: Ctx): Response { | ||
| 105 | 107 | const cookieFor = (ctx: Ctx, value: string, maxAge: number): string => |
| 106 | 108 | setCookie(COOKIE, value, { path: "/pricing", maxAge, secure: secureFor(ctx.url, ctx.app.config.url) }); |
| 107 | 109 | |
| 108 | // POST /pricing/order — free goes on to the free path; a paid plan holds the name and goes to checkout. | |
| 110 | // POST /pricing/order — free goes on to the free path; a paid plan holds the name and goes to | |
| 111 | // checkout. | |
| 109 | 112 | export async function pricingOrder(ctx: Ctx): Promise<Response> { |
| 110 | 113 | if (!isBuyer(ctx)) return notFoundPage(ctx); |
| 111 | 114 | const form = await readForm(ctx, ctx.auth.user === undefined ? undefined : "admin"); |
| @@ -144,7 +147,8 @@ const waiting = (ctx: Ctx, says: string): Response => { | ||
| 144 | 147 | return res; |
| 145 | 148 | }; |
| 146 | 149 | |
| 147 | // GET /pricing/done?order= — reconciles the order with the provider, waits for the forge, shows the link once. | |
| 150 | // GET /pricing/done?order= — reconciles the order with the provider, waits for the forge, shows the | |
| 151 | // link once. | |
| 148 | 152 | export async function pricingDone(ctx: Ctx): Promise<Response> { |
| 149 | 153 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 150 | 154 | const rendering = performance.now(); |
| @@ -198,7 +202,8 @@ export function resendPage(ctx: Ctx): Response { | ||
| 198 | 202 | return response; |
| 199 | 203 | } |
| 200 | 204 | |
| 201 | // POST /pricing/resend — the link goes to the order's own email; the answer is the same whether or not an order matched. | |
| 205 | // POST /pricing/resend — the link goes to the order's own email; the answer is the same whether or | |
| 206 | // not an order matched. | |
| 202 | 207 | export async function resendSubmit(ctx: Ctx): Promise<Response> { |
| 203 | 208 | if (!isBuyer(ctx)) return notFoundPage(ctx); |
| 204 | 209 | const form = await readForm(ctx, ctx.auth.user === undefined ? undefined : "admin"); |
test/pricing-line.test.ts added +56
| @@ -0,0 +1,56 @@ | ||
| 1 | /** The signed-out /pricing first line names the cheapest paid plan, from the plans (#13045). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { priceLine } from "../src/billing/plan_words.ts"; | |
| 8 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { useCheckout } from "../src/billing/checkout.ts"; | |
| 11 | import { ok } from "../src/kernel/result.ts"; | |
| 12 | import { DEFAULT_PLANS, getPlans, setPlans } from "../src/settings/plans.ts"; | |
| 13 | ||
| 14 | let dir: string; | |
| 15 | let app: App; | |
| 16 | let servers: Servers; | |
| 17 | let actor: string; | |
| 18 | ||
| 19 | beforeAll(async () => { | |
| 20 | dir = await mkdtemp(join(tmpdir(), "forge-priceline-")); | |
| 21 | app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/forge-code" }); | |
| 22 | servers = await serve(app); | |
| 23 | const a = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 24 | if (!a.ok) throw new Error("user"); | |
| 25 | actor = a.value.id; | |
| 26 | useCheckout(app, { name: "fake", create: async () => ok({ id: "cs_x", url: "https://pay.fake.test/x" }), state: async () => ok({ paid: false, customer: "c", subscription: "s" }) }); | |
| 27 | }); | |
| 28 | afterAll(async () => { | |
| 29 | await servers.stop?.(); | |
| 30 | await rm(dir, { recursive: true, force: true }); | |
| 31 | }); | |
| 32 | ||
| 33 | const firstLine = async (): Promise<{ body: string; line: string }> => { | |
| 34 | const body = await (await fetch(`${servers.url}/pricing`)).text(); | |
| 35 | const line = /<span class="page-head-sub muted small">([^<]*)/.exec(body)?.[1] ?? ""; | |
| 36 | return { body, line }; | |
| 37 | }; | |
| 38 | ||
| 39 | test("the line is the cheapest paid plan's price, in the head's one sub, above the order form", async () => { | |
| 40 | const { body, line } = await firstLine(); | |
| 41 | const lowest = Math.min(...getPlans(app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd)); | |
| 42 | expect(line).toBe(`A forge is $${lowest} a month.`); | |
| 43 | expect(body).not.toContain('class="lead"'); | |
| 44 | expect(body.indexOf("page-head-sub")).toBeLessThan(body.indexOf('id="order"')); | |
| 45 | }); | |
| 46 | ||
| 47 | test("when the plans change the line follows", async () => { | |
| 48 | setPlans(app.db, DEFAULT_PLANS.map((p) => (p.priceUsd === 19 ? { ...p, priceUsd: 23 } : p)), actor); | |
| 49 | expect((await firstLine()).line).toContain("A forge is $23 a month"); | |
| 50 | expect(priceLine([])).toBe("A forge is free"); | |
| 51 | }); | |
| 52 | ||
| 53 | test("with no provider connected there is no price line, since the paid plans say ask the operator", async () => { | |
| 54 | useCheckout(app, undefined); | |
| 55 | expect((await firstLine()).line).toBe("Pick a size and name it."); | |
| 56 | }); |
test/tui-pricing.test.ts +20 −2
| @@ -1,4 +1,7 @@ | ||
| 1 | /** /pricing in the terminal (#11369): plans, an order through placeOrder, the checkout address as text, the claim link by the same ticket. */ | |
| 1 | /** | |
| 2 | * /pricing in the terminal (#11369): plans, an order through placeOrder, the checkout address as | |
| 3 | * text, the claim link by the same ticket. | |
| 4 | */ | |
| 2 | 5 | import { afterEach, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -59,7 +62,10 @@ async function fixture(opts: { sell?: boolean; placement?: "ok" | "full" } = {}) | ||
| 59 | 62 | tui.ctx.push(pricingScreen(session, tui.ctx)); |
| 60 | 63 | return { tui, terminal, session }; |
| 61 | 64 | }; |
| 62 | /** Press keys and wait until the terminal is quiet: the placement and the provider are awaited by the app's own tracking. */ | |
| 65 | /** | |
| 66 | * Press keys and wait until the terminal is quiet: the placement and the provider are awaited by | |
| 67 | * the app's own tracking. | |
| 68 | */ | |
| 63 | 69 | const press = async (h: ReturnType<typeof open>, keys: string) => { |
| 64 | 70 | h.terminal.feed(keys); |
| 65 | 71 | await settleApp(h.tui); |
| @@ -95,6 +101,18 @@ test("the plans are listed with their prices", async () => { | ||
| 95 | 101 | for (const p of getPlans(f.app.db)) if (p.key !== FREE && p.priceUsd > 0) expect(text).toContain(`$${p.priceUsd} a month`); |
| 96 | 102 | }); |
| 97 | 103 | |
| 104 | test("the screen opens with the cheapest paid plan's price, and says none where nothing is on sale", async () => { | |
| 105 | const f = await fixture(); | |
| 106 | const lowest = Math.min(...getPlans(f.app.db).filter((p) => p.priceUsd > 0).map((p) => p.priceUsd)); | |
| 107 | const h = f.open("203.0.113.7"); | |
| 108 | await settleApp(h.tui); | |
| 109 | expect(flat(h)).toContain(`A forge is $${lowest} a month.`); | |
| 110 | const g = await fixture({ sell: false }); | |
| 111 | const k = g.open("203.0.113.8"); | |
| 112 | await settleApp(k.tui); | |
| 113 | expect(flat(k)).not.toContain("A forge is $"); | |
| 114 | }); | |
| 115 | ||
| 98 | 116 | test("a bad email is refused in the web's words and holds nothing", async () => { |
| 99 | 117 | const f = await fixture(); |
| 100 | 118 | const h = f.open("203.0.113.2"); |
new above
offline
Docs say the line shows only where checkout is connected; the preview has none, so this is invisible there. Say how a person turns on a checkout to see it.