Public: anyone can read this; the crew can change it.

/pricing is back within its SQL budget #16497

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

sold/pricing-budget → main 0 commits 2 threads · 2 unresolved

  • Merged. sold/pricing-budget was merged into main as ec183b6.

Review

Sign in to review this change.
3 files changed +25 −13
src/spawn/making.ts +2 −1
@@ -76,8 +76,9 @@ export function placeChoice(
7676 app: App,
7777 plan: Plan | undefined,
7878 dearer: boolean,
79 /** The paid placement, when the caller has read it already. */
80 at: Where = whereFor(app, plan),
7981 ): PlaceChoice | undefined {
80 const at = whereFor(app, plan);
8182 if (at.where === "hosted" || plan === undefined) return undefined;
8283 const size: PlanName = catalogPlan(plan.size);
8384 const chosen = defaultPlace(app, at.provider, size);
src/web/pages/pricing.ts +15 −12
@@ -10,9 +10,9 @@
1010 import { setCookie } from "../../auth/cookies.ts";
1111 import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts";
1212 import { cloudLapseWords, lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts";
13 import { getPaidPlacement } from "../../settings/paid_placement.ts";
1314 import { mailerOf } from "../../actions/verify.ts";
1415 import { getBaseDomain } from "../../settings/pinned_domain.ts";
15 import { getPaidPlacement } from "../../settings/paid_placement.ts";
1616 import { limitValue } from "../../settings/limits.ts";
1717 import { getPinned, urlOf } from "../../core/pinned.ts";
1818 import { openLink } from "../../spawn/making.ts";
@@ -53,13 +53,12 @@ interface Values {
5353 }
5454
5555 /** The lapse words: for a forge on its own machine (a paid placement on a cloud, or this order's own row), else the hosted ones. */
56 const lapseSays = (ctx: Ctx, cloud: boolean): string => (cloud ? cloudLapseWords(lapseRule(ctx.app.db), limitValue(ctx.app.db, "billing.retention_days")) : lapseRuleWords(lapseRule(ctx.app.db)));
57 const paidOnCloud = (ctx: Ctx): boolean => getPaidPlacement(ctx.app.db).where === "cloud";
56 const lapseSays = (ctx: Ctx, cloud: boolean, rule = lapseRule(ctx.app.db)): string => (cloud ? cloudLapseWords(rule, limitValue(ctx.app.db, "billing.retention_days")) : lapseRuleWords(rule));
5857 const mailOn = (ctx: Ctx): boolean => mailerOf(ctx.app, { id: "order" }) !== undefined;
5958
6059 const isBuyer = (ctx: Ctx): boolean => ctx.auth.user === undefined || ctx.auth.user.kind === "user";
6160
62 function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["field"], string>>): Html {
61 function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["field"], string>>, door = getDoorSettings(ctx.app.db)): Html {
6362 // The order this browser paid for, from its own cookie: the page that opens it needs the address
6463 // of the order.
6564 const held = (cookieValue(ctx.request, COOKIE) ?? "").split(".")[0] ?? "";
@@ -67,9 +66,12 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
6766 const selling = checkoutOf(ctx.app) !== undefined;
6867 // The plans and the home's buy links in one statement (`settings/door.ts`); without a provider,
6968 // those links (one source, `planWords`) are how a paid plan is bought.
70 const door = getDoorSettings(ctx.app.db);
7169 const plans = door.plans;
7270 const rule = lapseRule(ctx.app.db);
71 // The paid placement is read once: it says whether paid forges run on a cloud, and feeds the list.
72 const placement = getPaidPlacement(ctx.app.db);
outdated

Regression: when selling is false this is undefined, and it is also undefined when there is no non-free plan. cloud below then reads false even though paid placement is a cloud. Before the change paidOnCloud read the setting directly, so the cloud lapse words, the address hint and NO_MAIL_STEP showed with checkout off. Take cloud from the setting itself, not from whether a form is drawn.

73 const cloud = placement.where === "cloud";
outdated

cloud = choice !== undefined couples 'the forge runs on a cloud' to 'a place list is shown'. They are two facts. Derive cloud from the placement read and let choice be the list. A test with checkout off and a cloud placement should pin it.

74 const choice = selling ? placeChoice(ctx.app, plans.find((p) => p.key !== FREE), false, placement) : undefined;
7375 const links = selling ? {} : door.links;
7476 const buyable = selling || plans.some((p) => planWords(p, links, 0, door.askUsd).buy !== undefined);
7577 const rows = plans.map((p: Plan) => {
@@ -97,7 +99,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
9799 name: "name",
98100 value: values.name,
99101 required: true,
100 hint: paidOnCloud(ctx) ? `Its address: <name>.${getBaseDomain(ctx.app.db)} on its own machine (free: <name>--${childHost(ctx.app)}).` : `Its address: <name>--${childHost(ctx.app)}.`,
102 hint: cloud ? `Its address: <name>.${getBaseDomain(ctx.app.db)} on its own machine (free: <name>--${childHost(ctx.app)}).` : `Its address: <name>--${childHost(ctx.app)}.`,
101103 ...(errors["name"] ? { error: errors["name"] } : {}),
102104 })}
103105 ${selling
@@ -107,17 +109,17 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie
107109 type: "email",
108110 value: values.email,
109111 autocomplete: "email",
110 hint: mailOn(ctx) || !paidOnCloud(ctx) ? "The link to open your forge is shown after payment and sent here." : "The link to open your forge is shown after payment.",
112 hint: !cloud || mailOn(ctx) ? "The link to open your forge is shown after payment and sent here." : "The link to open your forge is shown after payment.",
111113 ...(errors["email"] ? { error: errors["email"] } : {}),
112114 })
113115 : null}
114 ${selling ? placeChoiceView(placeChoice(ctx.app, plans.find((p) => p.key !== FREE), false), values.place, errors["place"]) : null}
116 ${selling ? placeChoiceView(choice, values.place, errors["place"]) : null}
115117 <dl class="status-rows">${rows}</dl>
116118 </form>
117119 <div class="muted small" data-after-pay>
118120 <p>${buyable ? "After you pay:" : "How a paid plan is set up:"}</p>
119 <ol>${AFTER_PAYMENT_STEPS.map((l, i) => html`<li>${i === 2 && paidOnCloud(ctx) && !mailOn(ctx) ? NO_MAIL_STEP : l}</li>`)}</ol>
120 <p data-lapse="sleep" data-grace-days="${rule.graceDays}">${lapseSays(ctx, paidOnCloud(ctx))} <span data-legal><a href="/terms">Terms</a> · <a href="/privacy">Privacy</a></span></p>
121 <ol>${AFTER_PAYMENT_STEPS.map((l, i) => html`<li>${i === 2 && cloud && !mailOn(ctx) ? NO_MAIL_STEP : l}</li>`)}</ol>
122 <p data-lapse="sleep" data-grace-days="${rule.graceDays}">${lapseSays(ctx, cloud, rule)} <span data-legal><a href="/terms">Terms</a> · <a href="/privacy">Privacy</a></span></p>
121123 </div>
122124 <p class="muted small">Paid already? ${ordered === undefined ? null : html`<a href="/pricing/done?order=${ordered}">Open your order</a> · `}<a href="/pricing/resend">Lost your link?</a></p>
123125 </div>`;
@@ -128,14 +130,15 @@ export function pricingPage(ctx: Ctx): Response {
128130 if (!isBuyer(ctx)) return notFoundPage(ctx);
129131 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
130132 const rendering = performance.now();
131 const { plans, startUsd } = getDoorSettings(ctx.app.db);
133 const door = getDoorSettings(ctx.app.db);
134 const { plans, startUsd } = door;
132135 const response = page({
133136 ctx,
134137 title: "Pricing and your own forge",
135138 description: "What each forge plan costs and the CPU, memory, disk and crew credit it includes.",
136139 tight: true,
137140 jsonLd: safeJson({ "@context": "https://schema.org", "@type": "Product", name: "Open Platform Forge", url: `${ctx.url.origin}/`, additionalProperty: sharedProperties(lapseRule(ctx.app.db)), offers: offerData(plans, ctx.url.origin, lapseRule(ctx.app.db), true, startUsd) }),
138 body: plansView(ctx, { name: (ctx.url.searchParams.get("name") ?? "").slice(0, 38), email: "", place: "" }, {}),
141 body: plansView(ctx, { name: (ctx.url.searchParams.get("name") ?? "").slice(0, 38), email: "", place: "" }, {}, door),
139142 });
140143 notePhase(ctx.request, "render", performance.now() - rendering);
141144 return response;
test/order-cloud.test.ts +8
@@ -483,4 +483,12 @@ describe("a paid order on a cloud account", () => {
483483 expect(hosted).toContain("After that your forge sleeps and keeps its data");
484484 expect(changePaidPlacement(app, admin(), "digitalocean/main").ok).toBe(true);
485485 });
486
487 test("with checkout off and a cloud placement, /pricing still says the cloud words", async () => {
488 useCheckout(app, undefined);
489 const body = await (await pricingPage(ctxOf("/pricing"))).text();
490 useCheckout(app, fake);
491 expect(body).toContain("&lt;name&gt;.forges.test on its own machine");
492 expect(body).toContain("its machine is deleted and its data kept");
493 });
486494 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs