Public: anyone can read this; the crew can change it.
/pricing is back within its SQL budget #16497
Check · Review · Land · Live done — Landed and live in production.
sold/pricing-budget → main 0 commits 2 threads · 2 unresolved
3 files
changed +25
−13
src/spawn/making.ts +2 −1
| @@ -76,8 +76,9 @@ export function placeChoice( | ||
| 76 | 76 | app: App, |
| 77 | 77 | plan: Plan | undefined, |
| 78 | 78 | dearer: boolean, |
| 79 | /** The paid placement, when the caller has read it already. */ | |
| 80 | at: Where = whereFor(app, plan), | |
| 79 | 81 | ): PlaceChoice | undefined { |
| 80 | const at = whereFor(app, plan); | |
| 81 | 82 | if (at.where === "hosted" || plan === undefined) return undefined; |
| 82 | 83 | const size: PlanName = catalogPlan(plan.size); |
| 83 | 84 | const chosen = defaultPlace(app, at.provider, size); |
src/web/pages/pricing.ts +15 −12
| @@ -10,9 +10,9 @@ | ||
| 10 | 10 | import { setCookie } from "../../auth/cookies.ts"; |
| 11 | 11 | import { deliverLink, mayView, NO_PROVIDER, placeOrder, reconcileOrder, resendLink, type Refusal } from "../../actions/order.ts"; |
| 12 | 12 | import { cloudLapseWords, lapseRule, lapseRuleWords } from "../../billing/lapse_rule.ts"; |
| 13 | import { getPaidPlacement } from "../../settings/paid_placement.ts"; | |
| 13 | 14 | import { mailerOf } from "../../actions/verify.ts"; |
| 14 | 15 | import { getBaseDomain } from "../../settings/pinned_domain.ts"; |
| 15 | import { getPaidPlacement } from "../../settings/paid_placement.ts"; | |
| 16 | 16 | import { limitValue } from "../../settings/limits.ts"; |
| 17 | 17 | import { getPinned, urlOf } from "../../core/pinned.ts"; |
| 18 | 18 | import { openLink } from "../../spawn/making.ts"; |
| @@ -53,13 +53,12 @@ interface Values { | ||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** 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)); | |
| 58 | 57 | const mailOn = (ctx: Ctx): boolean => mailerOf(ctx.app, { id: "order" }) !== undefined; |
| 59 | 58 | |
| 60 | 59 | const isBuyer = (ctx: Ctx): boolean => ctx.auth.user === undefined || ctx.auth.user.kind === "user"; |
| 61 | 60 | |
| 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 { | |
| 63 | 62 | // The order this browser paid for, from its own cookie: the page that opens it needs the address |
| 64 | 63 | // of the order. |
| 65 | 64 | const held = (cookieValue(ctx.request, COOKIE) ?? "").split(".")[0] ?? ""; |
| @@ -67,9 +66,12 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 67 | 66 | const selling = checkoutOf(ctx.app) !== undefined; |
| 68 | 67 | // The plans and the home's buy links in one statement (`settings/door.ts`); without a provider, |
| 69 | 68 | // those links (one source, `planWords`) are how a paid plan is bought. |
| 70 | const door = getDoorSettings(ctx.app.db); | |
| 71 | 69 | const plans = door.plans; |
| 72 | 70 | 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); | |
| 73 | const cloud = placement.where === "cloud"; | |
outdated
|
||
| 74 | const choice = selling ? placeChoice(ctx.app, plans.find((p) => p.key !== FREE), false, placement) : undefined; | |
| 73 | 75 | const links = selling ? {} : door.links; |
| 74 | 76 | const buyable = selling || plans.some((p) => planWords(p, links, 0, door.askUsd).buy !== undefined); |
| 75 | 77 | const rows = plans.map((p: Plan) => { |
| @@ -97,7 +99,7 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 97 | 99 | name: "name", |
| 98 | 100 | value: values.name, |
| 99 | 101 | 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)}.`, | |
| 101 | 103 | ...(errors["name"] ? { error: errors["name"] } : {}), |
| 102 | 104 | })} |
| 103 | 105 | ${selling |
| @@ -107,17 +109,17 @@ function plansView(ctx: Ctx, values: Values, errors: Partial<Record<Refusal["fie | ||
| 107 | 109 | type: "email", |
| 108 | 110 | value: values.email, |
| 109 | 111 | 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.", | |
| 111 | 113 | ...(errors["email"] ? { error: errors["email"] } : {}), |
| 112 | 114 | }) |
| 113 | 115 | : 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} | |
| 115 | 117 | <dl class="status-rows">${rows}</dl> |
| 116 | 118 | </form> |
| 117 | 119 | <div class="muted small" data-after-pay> |
| 118 | 120 | <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> | |
| 121 | 123 | </div> |
| 122 | 124 | <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> |
| 123 | 125 | </div>`; |
| @@ -128,14 +130,15 @@ export function pricingPage(ctx: Ctx): Response { | ||
| 128 | 130 | if (!isBuyer(ctx)) return notFoundPage(ctx); |
| 129 | 131 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 130 | 132 | const rendering = performance.now(); |
| 131 | const { plans, startUsd } = getDoorSettings(ctx.app.db); | |
| 133 | const door = getDoorSettings(ctx.app.db); | |
| 134 | const { plans, startUsd } = door; | |
| 132 | 135 | const response = page({ |
| 133 | 136 | ctx, |
| 134 | 137 | title: "Pricing and your own forge", |
| 135 | 138 | description: "What each forge plan costs and the CPU, memory, disk and crew credit it includes.", |
| 136 | 139 | tight: true, |
| 137 | 140 | 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), | |
| 139 | 142 | }); |
| 140 | 143 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 141 | 144 | return response; |
test/order-cloud.test.ts +8
| @@ -483,4 +483,12 @@ describe("a paid order on a cloud account", () => { | ||
| 483 | 483 | expect(hosted).toContain("After that your forge sleeps and keeps its data"); |
| 484 | 484 | expect(changePaidPlacement(app, admin(), "digitalocean/main").ok).toBe(true); |
| 485 | 485 | }); |
| 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("<name>.forges.test on its own machine"); | |
| 492 | expect(body).toContain("its machine is deleted and its data kept"); | |
| 493 | }); | |
| 486 | 494 | }); |
new above
offline
Regression: when
sellingis false this isundefined, and it is alsoundefinedwhen there is no non-free plan.cloudbelow then reads false even though paid placement is a cloud. Before the changepaidOnCloudread the setting directly, so the cloud lapse words, the address hint and NO_MAIL_STEP showed with checkout off. Takecloudfrom the setting itself, not from whether a form is drawn.